Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to doctrine/inflector 1.4 #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions ORM/NamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace WMC\DoctrineNamingStrategyBundle\ORM;

use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Doctrine\Common\Inflector\Inflector;

class NamingStrategy extends UnderscoreNamingStrategy
{
/**
* @var \Doctrine\Inflector\Inflector
*/
static private $inflector;

/**
* {@inheritdoc}
*/
Expand All @@ -17,12 +21,25 @@ public function classToTableName($className, $includePrefix = true)
$parts = explode('_', $table_name);
$last = array_pop($parts);

$last = Inflector::pluralize($last);
$last = $this->pluralize($last);
$parts[] = $last;

return implode('_', $parts);
}

private function pluralize($toPluralize)
{
if (class_exists('\Doctrine\Inflector\InflectorFactory')) {
if (!static::$inflector) {
static::$inflector = \Doctrine\Inflector\InflectorFactory::create()->build();
}

return static::$inflector->pluralize($toPluralize);
} else {
return \Doctrine\Common\Inflector\Inflector::pluralize($toPluralize);
}
}

/**
* {@inheritdoc}
*/
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
{
"name": "Mathieu Lemoine",
"email": "[email protected]"
},
{
"name": "Virgile Vivier",
"email": "[email protected]"
}

],
"description": "WeMakeCustom Doctrine Naming Strategy",
"autoload": {
Expand All @@ -22,7 +27,7 @@
"doctrine/orm": "^2.3",
"doctrine/inflector": "^1.0"
},
"suggests": {
"suggest": {
"symfony/framework-bundle": "To integrate with full stack Symfony"
},
"extra": {
Expand Down