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

[6.x] Fixed deprecated "Doctrine/Common/Inflector/Inflector" class #32734

Merged
merged 5 commits into from
May 11, 2020
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"doctrine/inflector": "^1.1",
"doctrine/inflector": "^1.4|^2.0",
"dragonmantank/cron-expression": "^2.0",
"egulias/email-validator": "^2.1.10",
"league/commonmark": "^1.3",
Expand Down
32 changes: 29 additions & 3 deletions src/Illuminate/Support/Pluralizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Illuminate\Support;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\CachedWordInflector;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English;
use Doctrine\Inflector\RulesetInflector;

class Pluralizer
{
Expand Down Expand Up @@ -70,7 +73,7 @@ public static function plural($value, $count = 2)
return $value;
}

$plural = Inflector::pluralize($value);
$plural = static::inflector()->pluralize($value);

return static::matchCase($plural, $value);
}
Expand All @@ -83,7 +86,7 @@ public static function plural($value, $count = 2)
*/
public static function singular($value)
{
$singular = Inflector::singularize($value);
$singular = static::inflector()->singularize($value);

return static::matchCase($singular, $value);
}
Expand Down Expand Up @@ -118,4 +121,27 @@ protected static function matchCase($value, $comparison)

return $value;
}

/**
* Get the inflector instance.
*
* @return \Doctrine\Inflector\Inflector
*/
public static function inflector()
{
static $inflector;

if (is_null($inflector)) {
$inflector = new Inflector(
new CachedWordInflector(new RulesetInflector(
English\Rules::getSingularRuleset()
)),
new CachedWordInflector(new RulesetInflector(
English\Rules::getPluralRuleset()
))
);
}

return $inflector;
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": "^7.2",
"ext-json": "*",
"ext-mbstring": "*",
"doctrine/inflector": "^1.1",
"doctrine/inflector": "^1.4|^2.0",
"illuminate/contracts": "^6.0",
"nesbot/carbon": "^2.0"
},
Expand Down