From de8e0de3c38e08c54c0cdd6efaeb70ac26dd1bd2 Mon Sep 17 00:00:00 2001 From: Zizaco Date: Fri, 27 Mar 2015 17:12:06 -0300 Subject: [PATCH 1/4] Updated Inflect methods to be non-static --- src/Inflect/Inflect.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Inflect/Inflect.php b/src/Inflect/Inflect.php index cfe998a..cf395ce 100644 --- a/src/Inflect/Inflect.php +++ b/src/Inflect/Inflect.php @@ -2,6 +2,11 @@ namespace Inflect; +/** + * Handle words in Portuguese + * + * @package Inflect + */ class Inflect { @@ -86,7 +91,7 @@ class Inflect * @param string * @return string **/ - public static function pluralize($string) + public function pluralize($string) { if (in_array(strtolower($string), self::$uncountable)) { return $string; @@ -115,7 +120,7 @@ public static function pluralize($string) * @param string * @return string **/ - public static function singularize($string) + public function singularize($string) { if (in_array(strtolower($string), self::$uncountable)) { return $string; @@ -144,7 +149,7 @@ public static function singularize($string) * @param string * @return string **/ - public static function camelize($string, $uppercase_first_letter = false) + public function camelize($string, $uppercase_first_letter = false) { if ($uppercase_first_letter) { return str_replace(' ', '', ucwords(strtr($string, '_-', ' '))); From ddc09cd9c8a60f79b23a04340d2c1f46640bc89b Mon Sep 17 00:00:00 2001 From: Zizaco Date: Fri, 27 Mar 2015 17:13:07 -0300 Subject: [PATCH 2/4] Added Facade class to allow static calls --- src/Inflect/Facade.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Inflect/Facade.php diff --git a/src/Inflect/Facade.php b/src/Inflect/Facade.php new file mode 100644 index 0000000..85702f4 --- /dev/null +++ b/src/Inflect/Facade.php @@ -0,0 +1,56 @@ +getInflector(); + + switch (count($args)) + { + case 0: + return $instance->$method(); + + case 1: + return $instance->$method($args[0]); + + default: + return call_user_func_array(array($instance, $method), $args); + } + } +} From e24f6ee901ce78fe722d632c289509faf0542614 Mon Sep 17 00:00:00 2001 From: Zizaco Date: Fri, 27 Mar 2015 17:13:26 -0300 Subject: [PATCH 3/4] Updated README.md with how to do static calls now --- README.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 076bf81..2d7430f 100644 --- a/README.md +++ b/README.md @@ -17,16 +17,30 @@ Examples of usage of the Inflect(i.e portuguese). ```php pluralize('pão'); // pães +$inflector->pluralize('carro'); // carros -Inflect::camelize('tablename'); // TableName -Inflect::camelize('tablename', true); // tableName +$inflector->singularize('carros'); // carro +$inflector->singularize('pães'); // pão + +$inflector->camelize('tablename'); // TableName +$inflector->camelize('tablename', true); // tableName +``` + +You can also use it without instantiating the object trought the `Facade` class + +```php + Date: Fri, 27 Mar 2015 17:20:02 -0300 Subject: [PATCH 4/4] Updated Inflect\Facade getInflector to static, since there should be no need to instantiate the facade --- src/Inflect/Facade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Inflect/Facade.php b/src/Inflect/Facade.php index 85702f4..d7b5a16 100644 --- a/src/Inflect/Facade.php +++ b/src/Inflect/Facade.php @@ -3,7 +3,7 @@ namespace Inflect; /** - * This is a helper class that allows the usage of the Inflect\Inflect trought + * This is a helper class that allows the usag of the Inflect\Inflect trought * static calls * * @example @@ -21,7 +21,7 @@ class Facade * * @return Inflect */ - protected function getInflector() + protected static function getInflector() { if (!self::$inflector) { self::$inflector = new Inflect; @@ -39,7 +39,7 @@ protected function getInflector() */ public static function __callStatic($method, $args) { - $instance = $this->getInflector(); + $instance = self::getInflector(); switch (count($args)) {