Skip to content

Commit

Permalink
[6.x] Fixed deprecated "Doctrine/Common/Inflector/Inflector" class (#…
Browse files Browse the repository at this point in the history
…32734)

* [6.x] Fixed deprecated "Doctrine/Common/Inflector/Inflector::pluralize" method

* Cache the inflector properly

* Added missing phpdoc

* Update composer.json

* Update Pluralizer.php

Co-authored-by: Graham Campbell <GrahamCampbell@users.noreply.github.com>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
3 people committed May 11, 2020
1 parent a71964c commit 95b34d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
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

0 comments on commit 95b34d4

Please sign in to comment.