Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from doctrine/improve-dx
Improve developer experience and make it easier to create an Inflector instance.
- Loading branch information
Showing
17 changed files
with
283 additions
and
178 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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector; | ||
|
||
use Doctrine\Inflector\Rules\English; | ||
use Doctrine\Inflector\Rules\French; | ||
use Doctrine\Inflector\Rules\NorwegianBokmal; | ||
use Doctrine\Inflector\Rules\Portuguese; | ||
use Doctrine\Inflector\Rules\Spanish; | ||
use Doctrine\Inflector\Rules\Turkish; | ||
use InvalidArgumentException; | ||
use function sprintf; | ||
|
||
final class InflectorFactory | ||
{ | ||
public function __invoke(string $language = Language::ENGLISH) : Inflector | ||
{ | ||
switch ($language) { | ||
case Language::ENGLISH: | ||
return (new English\InflectorFactory())(); | ||
|
||
case Language::FRENCH: | ||
return (new French\InflectorFactory())(); | ||
|
||
case Language::NORWEGIAN_BOKMAL: | ||
return (new NorwegianBokmal\InflectorFactory())(); | ||
|
||
case Language::PORTUGUESE: | ||
return (new Portuguese\InflectorFactory())(); | ||
|
||
case Language::SPANISH: | ||
return (new Spanish\InflectorFactory())(); | ||
|
||
case Language::TURKISH: | ||
return (new Turkish\InflectorFactory())(); | ||
|
||
default: | ||
throw new InvalidArgumentException(sprintf( | ||
'Language "%s" is not supported.', | ||
$language | ||
)); | ||
} | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector; | ||
|
||
final class Language | ||
{ | ||
public const ENGLISH = 'english'; | ||
public const FRENCH = 'french'; | ||
public const NORWEGIAN_BOKMAL = 'norwegian-bokmal'; | ||
public const PORTUGUESE = 'portuguese'; | ||
public const SPANISH = 'spanish'; | ||
public const TURKISH = 'turkish'; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector\Rules\English; | ||
|
||
use Doctrine\Inflector\CachedWordInflector; | ||
use Doctrine\Inflector\Inflector; | ||
use Doctrine\Inflector\RulesetInflector; | ||
|
||
final class InflectorFactory | ||
{ | ||
public function __invoke() : Inflector | ||
{ | ||
return new Inflector( | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getSingularRuleset() | ||
)), | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getPluralRuleset() | ||
)) | ||
); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector\Rules\French; | ||
|
||
use Doctrine\Inflector\CachedWordInflector; | ||
use Doctrine\Inflector\Inflector; | ||
use Doctrine\Inflector\RulesetInflector; | ||
|
||
final class InflectorFactory | ||
{ | ||
public function __invoke() : Inflector | ||
{ | ||
return new Inflector( | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getSingularRuleset() | ||
)), | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getPluralRuleset() | ||
)) | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/Doctrine/Inflector/Rules/NorwegianBokmal/InflectorFactory.php
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector\Rules\NorwegianBokmal; | ||
|
||
use Doctrine\Inflector\CachedWordInflector; | ||
use Doctrine\Inflector\Inflector; | ||
use Doctrine\Inflector\RulesetInflector; | ||
|
||
final class InflectorFactory | ||
{ | ||
public function __invoke() : Inflector | ||
{ | ||
return new Inflector( | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getSingularRuleset() | ||
)), | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getPluralRuleset() | ||
)) | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/Doctrine/Inflector/Rules/Portuguese/InflectorFactory.php
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector\Rules\Portuguese; | ||
|
||
use Doctrine\Inflector\CachedWordInflector; | ||
use Doctrine\Inflector\Inflector; | ||
use Doctrine\Inflector\RulesetInflector; | ||
|
||
final class InflectorFactory | ||
{ | ||
public function __invoke() : Inflector | ||
{ | ||
return new Inflector( | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getSingularRuleset() | ||
)), | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getPluralRuleset() | ||
)) | ||
); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Inflector\Rules\Spanish; | ||
|
||
use Doctrine\Inflector\CachedWordInflector; | ||
use Doctrine\Inflector\Inflector; | ||
use Doctrine\Inflector\RulesetInflector; | ||
|
||
final class InflectorFactory | ||
{ | ||
public function __invoke() : Inflector | ||
{ | ||
return new Inflector( | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getSingularRuleset() | ||
)), | ||
new CachedWordInflector(new RulesetInflector( | ||
Rules::getPluralRuleset() | ||
)) | ||
); | ||
} | ||
} |
Oops, something went wrong.