Skip to content

Commit

Permalink
update doctrine common
Browse files Browse the repository at this point in the history
  • Loading branch information
rafrsr committed Jan 31, 2021
1 parent b769875 commit aab7278
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 10 deletions.
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -23,11 +23,12 @@
"require": {
"php": ">=5.4",
"symfony/property-access": "^2.8|^3.4|^4.0|^5.0",
"doctrine/common": "^2.6"
"doctrine/common": "^2.6|^3.0",
"doctrine/inflector": "^1.0|^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"satooshi/php-coveralls": "^1.0"
"phpunit/phpunit": "^5.7.27",
"satooshi/php-coveralls": "^1.1"
},
"extra": {
"branch-alias": {
Expand Down
105 changes: 105 additions & 0 deletions src/Inflector.php
@@ -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);
}
}
8 changes: 2 additions & 6 deletions src/Naming/CamelCaseNamingStrategy.php
Expand Up @@ -10,7 +10,7 @@
*/
namespace Rafrsr\LibArray2Object\Naming;

use Doctrine\Common\Util\Inflector;
use Rafrsr\LibArray2Object\Inflector;

/**
* Transform property name from "property_name" -> "propertyName".
Expand All @@ -37,10 +37,6 @@ public function __construct($ucFirst = false)
*/
public function transformName($name)
{
if ($this->ucFirst) {
return Inflector::classify($name);
} else {
return Inflector::camelize($name);
}
return $this->ucFirst ? Inflector::classify($name) : Inflector::camelize($name);
}
}
2 changes: 1 addition & 1 deletion src/Naming/UnderscoreNamingStrategy.php
Expand Up @@ -10,7 +10,7 @@
*/
namespace Rafrsr\LibArray2Object\Naming;

use Doctrine\Common\Inflector\Inflector;
use Rafrsr\LibArray2Object\Inflector;

/**
* Transform property name from "propertyName" -> "property_name".
Expand Down

0 comments on commit aab7278

Please sign in to comment.