Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/* | ||
* This file is part of the rafrsr/lib-array2object package. | ||
* | ||
* (c) Rafael SR <https://github.com/rafrsr> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Rafrsr\LibArray2Object; | ||
|
||
use Doctrine\Inflector\InflectorFactory; | ||
|
||
/** | ||
* Class Inflector | ||
* | ||
* @package Ynlo\GraphQLBundle\Util | ||
*/ | ||
class Inflector | ||
{ | ||
/** | ||
* Convert word in to the format for a Doctrine table name. Converts 'ModelName' to 'model_name' | ||
* | ||
* @param string $word Word to tableize | ||
* | ||
* @return string $word Tableized word | ||
*/ | ||
public static function tableize($word) | ||
{ | ||
// BC with doctrine inflector ^1.0 | ||
if (!class_exists('Doctrine\Inflector\InflectorFactory')) { | ||
return \Doctrine\Common\Inflector\Inflector::tableize($word); | ||
} | ||
|
||
return InflectorFactory::create()->build()->tableize($word); | ||
} | ||
|
||
/** | ||
* Convert a word in to the format for a Doctrine class name. Converts 'table_name' to 'TableName' | ||
* | ||
* @param string $word Word to classify | ||
* | ||
* @return string $word Classified word | ||
*/ | ||
public static function classify($word) | ||
{ | ||
// BC with doctrine inflector ^1.0 | ||
if (!class_exists('Doctrine\Inflector\InflectorFactory')) { | ||
return \Doctrine\Common\Inflector\Inflector::classify($word); | ||
} | ||
|
||
return InflectorFactory::create()->build()->classify($word); | ||
} | ||
|
||
/** | ||
* Camelize a word. This uses the classify() method and turns the first character to lowercase | ||
* | ||
* @param string $word | ||
* | ||
* @return string $word | ||
*/ | ||
public static function camelize($word) | ||
{ | ||
// BC with doctrine inflector ^1.0 | ||
if (!class_exists('Doctrine\Inflector\InflectorFactory')) { | ||
return \Doctrine\Common\Inflector\Inflector::camelize($word); | ||
} | ||
|
||
return InflectorFactory::create()->build()->camelize($word); | ||
} | ||
|
||
/** | ||
* Return $word in plural form. | ||
* | ||
* @param string $word Word in singular | ||
* | ||
* @return string Word in plural | ||
*/ | ||
public static function pluralize($word) | ||
{ | ||
// BC with doctrine inflector ^1.0 | ||
if (!class_exists('Doctrine\Inflector\InflectorFactory')) { | ||
return \Doctrine\Common\Inflector\Inflector::pluralize($word); | ||
} | ||
|
||
return InflectorFactory::create()->build()->pluralize($word); | ||
} | ||
|
||
/** | ||
* Return $word in singular form. | ||
* | ||
* @param string $word Word in plural | ||
* | ||
* @return string Word in singular | ||
*/ | ||
public static function singularize($word) | ||
{ | ||
// BC with doctrine inflector ^1.0 | ||
if (!class_exists('Doctrine\Inflector\InflectorFactory')) { | ||
return \Doctrine\Common\Inflector\Inflector::singularize($word); | ||
} | ||
|
||
return InflectorFactory::create()->build()->singularize($word); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters