File manager - Edit - /home/autoph/public_html/projects/Rating-AutoHub/public/css/doctrine.tar
Back
deprecations/phpcs.xml 0000644 00000001212 15024770424 0011064 0 ustar 00 <?xml version="1.0"?> <ruleset> <arg name="basepath" value="."/> <arg name="extensions" value="php"/> <arg name="parallel" value="80"/> <arg name="cache" value=".phpcs-cache"/> <arg name="colors"/> <!-- Ignore warnings, show progress of the run and show sniff names --> <arg value="nps"/> <config name="php_version" value="70100"/> <!-- Directories to be checked --> <file>lib</file> <file>tests</file> <!-- Include full Doctrine Coding Standard --> <rule ref="Doctrine"> <exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" /> </rule> </ruleset> deprecations/composer.json 0000644 00000001764 15024770424 0011763 0 ustar 00 { "name": "doctrine/deprecations", "type": "library", "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", "homepage": "https://www.doctrine-project.org/", "license": "MIT", "require": { "php": "^7.1|^8.0" }, "require-dev": { "phpunit/phpunit": "^7.5|^8.5|^9.5", "psr/log": "^1|^2|^3", "doctrine/coding-standard": "^9" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" }, "autoload": { "psr-4": {"Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations"} }, "autoload-dev": { "psr-4": { "DeprecationTests\\": "test_fixtures/src", "Doctrine\\Foo\\": "test_fixtures/vendor/doctrine/foo" } }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } } } deprecations/lib/Doctrine/Deprecations/Deprecation.php 0000644 00000017355 15024770424 0017147 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Deprecations; use Psr\Log\LoggerInterface; use function array_key_exists; use function array_reduce; use function debug_backtrace; use function sprintf; use function strpos; use function strrpos; use function substr; use function trigger_error; use const DEBUG_BACKTRACE_IGNORE_ARGS; use const DIRECTORY_SEPARATOR; use const E_USER_DEPRECATED; /** * Manages Deprecation logging in different ways. * * By default triggered exceptions are not logged. * * To enable different deprecation logging mechanisms you can call the * following methods: * * - Minimal collection of deprecations via getTriggeredDeprecations() * \Doctrine\Deprecations\Deprecation::enableTrackingDeprecations(); * * - Uses @trigger_error with E_USER_DEPRECATED * \Doctrine\Deprecations\Deprecation::enableWithTriggerError(); * * - Sends deprecation messages via a PSR-3 logger * \Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger); * * Packages that trigger deprecations should use the `trigger()` or * `triggerIfCalledFromOutside()` methods. */ class Deprecation { private const TYPE_NONE = 0; private const TYPE_TRACK_DEPRECATIONS = 1; private const TYPE_TRIGGER_ERROR = 2; private const TYPE_PSR_LOGGER = 4; /** @var int */ private static $type = self::TYPE_NONE; /** @var LoggerInterface|null */ private static $logger; /** @var array<string,bool> */ private static $ignoredPackages = []; /** @var array<string,int> */ private static $ignoredLinks = []; /** @var bool */ private static $deduplication = true; /** * Trigger a deprecation for the given package and identfier. * * The link should point to a Github issue or Wiki entry detailing the * deprecation. It is additionally used to de-duplicate the trigger of the * same deprecation during a request. * * @param mixed $args */ public static function trigger(string $package, string $link, string $message, ...$args): void { if (self::$type === self::TYPE_NONE) { return; } if (array_key_exists($link, self::$ignoredLinks)) { self::$ignoredLinks[$link]++; } else { self::$ignoredLinks[$link] = 1; } if (self::$deduplication === true && self::$ignoredLinks[$link] > 1) { return; } if (isset(self::$ignoredPackages[$package])) { return; } $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $message = sprintf($message, ...$args); self::delegateTriggerToBackend($message, $backtrace, $link, $package); } /** * Trigger a deprecation for the given package and identifier when called from outside. * * "Outside" means we assume that $package is currently installed as a * dependency and the caller is not a file in that package. When $package * is installed as a root package then deprecations triggered from the * tests folder are also considered "outside". * * This deprecation method assumes that you are using Composer to install * the dependency and are using the default /vendor/ folder and not a * Composer plugin to change the install location. The assumption is also * that $package is the exact composer packge name. * * Compared to {@link trigger()} this method causes some overhead when * deprecation tracking is enabled even during deduplication, because it * needs to call {@link debug_backtrace()} * * @param mixed $args */ public static function triggerIfCalledFromOutside(string $package, string $link, string $message, ...$args): void { if (self::$type === self::TYPE_NONE) { return; } $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); // first check that the caller is not from a tests folder, in which case we always let deprecations pass if (strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) { $path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR; if (strpos($backtrace[0]['file'], $path) === false) { return; } if (strpos($backtrace[1]['file'], $path) !== false) { return; } } if (array_key_exists($link, self::$ignoredLinks)) { self::$ignoredLinks[$link]++; } else { self::$ignoredLinks[$link] = 1; } if (self::$deduplication === true && self::$ignoredLinks[$link] > 1) { return; } if (isset(self::$ignoredPackages[$package])) { return; } $message = sprintf($message, ...$args); self::delegateTriggerToBackend($message, $backtrace, $link, $package); } /** * @param array<mixed> $backtrace */ private static function delegateTriggerToBackend(string $message, array $backtrace, string $link, string $package): void { if ((self::$type & self::TYPE_PSR_LOGGER) > 0) { $context = [ 'file' => $backtrace[0]['file'], 'line' => $backtrace[0]['line'], 'package' => $package, 'link' => $link, ]; self::$logger->notice($message, $context); } if (! ((self::$type & self::TYPE_TRIGGER_ERROR) > 0)) { return; } $message .= sprintf( ' (%s:%d called by %s:%d, %s, package %s)', self::basename($backtrace[0]['file']), $backtrace[0]['line'], self::basename($backtrace[1]['file']), $backtrace[1]['line'], $link, $package ); @trigger_error($message, E_USER_DEPRECATED); } /** * A non-local-aware version of PHPs basename function. */ private static function basename(string $filename): string { $pos = strrpos($filename, DIRECTORY_SEPARATOR); if ($pos === false) { return $filename; } return substr($filename, $pos + 1); } public static function enableTrackingDeprecations(): void { self::$type |= self::TYPE_TRACK_DEPRECATIONS; } public static function enableWithTriggerError(): void { self::$type |= self::TYPE_TRIGGER_ERROR; } public static function enableWithPsrLogger(LoggerInterface $logger): void { self::$type |= self::TYPE_PSR_LOGGER; self::$logger = $logger; } public static function withoutDeduplication(): void { self::$deduplication = false; } public static function disable(): void { self::$type = self::TYPE_NONE; self::$logger = null; self::$deduplication = true; foreach (self::$ignoredLinks as $link => $count) { self::$ignoredLinks[$link] = 0; } } public static function ignorePackage(string $packageName): void { self::$ignoredPackages[$packageName] = true; } public static function ignoreDeprecations(string ...$links): void { foreach ($links as $link) { self::$ignoredLinks[$link] = 0; } } public static function getUniqueTriggeredDeprecationsCount(): int { return array_reduce(self::$ignoredLinks, static function (int $carry, int $count) { return $carry + $count; }, 0); } /** * Returns each triggered deprecation link identifier and the amount of occurrences. * * @return array<string,int> */ public static function getTriggeredDeprecations(): array { return self::$ignoredLinks; } } deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php 0000644 00000003663 15024770424 0022003 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Deprecations\PHPUnit; use Doctrine\Deprecations\Deprecation; use function sprintf; trait VerifyDeprecations { /** @var array<string,int> */ private $doctrineDeprecationsExpectations = []; /** @var array<string,int> */ private $doctrineNoDeprecationsExpectations = []; public function expectDeprecationWithIdentifier(string $identifier): void { $this->doctrineDeprecationsExpectations[$identifier] = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0; } public function expectNoDeprecationWithIdentifier(string $identifier): void { $this->doctrineNoDeprecationsExpectations[$identifier] = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0; } /** * @before */ public function enableDeprecationTracking(): void { Deprecation::enableTrackingDeprecations(); } /** * @after */ public function verifyDeprecationsAreTriggered(): void { foreach ($this->doctrineDeprecationsExpectations as $identifier => $expectation) { $actualCount = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0; $this->assertTrue( $actualCount > $expectation, sprintf( "Expected deprecation with identifier '%s' was not triggered by code executed in test.", $identifier ) ); } foreach ($this->doctrineNoDeprecationsExpectations as $identifier => $expectation) { $actualCount = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0; $this->assertTrue( $actualCount === $expectation, sprintf( "Expected deprecation with identifier '%s' was triggered by code executed in test, but expected not to.", $identifier ) ); } } } deprecations/README.md 0000644 00000010166 15024770424 0010514 0 ustar 00 # Doctrine Deprecations A small (side-effect free by default) layer on top of `trigger_error(E_USER_DEPRECATED)` or PSR-3 logging. - no side-effects by default, making it a perfect fit for libraries that don't know how the error handler works they operate under - options to avoid having to rely on error handlers global state by using PSR-3 logging - deduplicate deprecation messages to avoid excessive triggering and reduce overhead We recommend to collect Deprecations using a PSR logger instead of relying on the global error handler. ## Usage from consumer perspective: Enable Doctrine deprecations to be sent to a PSR3 logger: ```php \Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger); ``` Enable Doctrine deprecations to be sent as `@trigger_error($message, E_USER_DEPRECATED)` messages. ```php \Doctrine\Deprecations\Deprecation::enableWithTriggerError(); ``` If you only want to enable deprecation tracking, without logging or calling `trigger_error` then call: ```php \Doctrine\Deprecations\Deprecation::enableTrackingDeprecations(); ``` Tracking is enabled with all three modes and provides access to all triggered deprecations and their individual count: ```php $deprecations = \Doctrine\Deprecations\Deprecation::getTriggeredDeprecations(); foreach ($deprecations as $identifier => $count) { echo $identifier . " was triggered " . $count . " times\n"; } ``` ### Suppressing Specific Deprecations Disable triggering about specific deprecations: ```php \Doctrine\Deprecations\Deprecation::ignoreDeprecations("https://link/to/deprecations-description-identifier"); ``` Disable all deprecations from a package ```php \Doctrine\Deprecations\Deprecation::ignorePackage("doctrine/orm"); ``` ### Other Operations When used within PHPUnit or other tools that could collect multiple instances of the same deprecations the deduplication can be disabled: ```php \Doctrine\Deprecations\Deprecation::withoutDeduplication(); ``` Disable deprecation tracking again: ```php \Doctrine\Deprecations\Deprecation::disable(); ``` ## Usage from a library/producer perspective: When you want to unconditionally trigger a deprecation even when called from the library itself then the `trigger` method is the way to go: ```php \Doctrine\Deprecations\Deprecation::trigger( "doctrine/orm", "https://link/to/deprecations-description", "message" ); ``` If variable arguments are provided at the end, they are used with `sprintf` on the message. ```php \Doctrine\Deprecations\Deprecation::trigger( "doctrine/orm", "https://github.com/doctrine/orm/issue/1234", "message %s %d", "foo", 1234 ); ``` When you want to trigger a deprecation only when it is called by a function outside of the current package, but not trigger when the package itself is the cause, then use: ```php \Doctrine\Deprecations\Deprecation::triggerIfCalledFromOutside( "doctrine/orm", "https://link/to/deprecations-description", "message" ); ``` Based on the issue link each deprecation message is only triggered once per request. A limited stacktrace is included in the deprecation message to find the offending location. Note: A producer/library should never call `Deprecation::enableWith` methods and leave the decision how to handle deprecations to application and frameworks. ## Usage in PHPUnit tests There is a `VerifyDeprecations` trait that you can use to make assertions on the occurrence of deprecations within a test. ```php use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; class MyTest extends TestCase { use VerifyDeprecations; public function testSomethingDeprecation() { $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issue/1234'); triggerTheCodeWithDeprecation(); } public function testSomethingDeprecationFixed() { $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/issue/1234'); triggerTheCodeWithoutDeprecation(); } } ``` ## What is a deprecation identifier? An identifier for deprecations is just a link to any resource, most often a Github Issue or Pull Request explaining the deprecation and potentially its alternative. deprecations/LICENSE 0000644 00000002051 15024770424 0010234 0 ustar 00 Copyright (c) 2020-2021 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. inflector/composer.json 0000644 00000003006 15024770424 0011257 0 ustar 00 { "name": "doctrine/inflector", "type": "library", "description": "PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.", "keywords": ["php", "strings", "words", "manipulation", "inflector", "inflection", "uppercase", "lowercase", "singular", "plural"], "homepage": "https://www.doctrine-project.org/projects/inflector.html", "license": "MIT", "authors": [ {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"}, {"name": "Roman Borschel", "email": "roman@code-factory.org"}, {"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"}, {"name": "Jonathan Wage", "email": "jonwage@gmail.com"}, {"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"} ], "require": { "php": "^7.2 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^10", "phpstan/phpstan": "^1.8", "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-strict-rules": "^1.3", "phpunit/phpunit": "^8.5 || ^9.5", "vimeo/psalm": "^4.25" }, "autoload": { "psr-4": { "Doctrine\\Inflector\\": "lib/Doctrine/Inflector" } }, "autoload-dev": { "psr-4": { "Doctrine\\Tests\\Inflector\\": "tests/Doctrine/Tests/Inflector" } }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } } } inflector/lib/Doctrine/Inflector/WordInflector.php 0000644 00000000217 15024770424 0016272 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; interface WordInflector { public function inflect(string $word): string; } inflector/lib/Doctrine/Inflector/RulesetInflector.php 0000644 00000002513 15024770424 0017003 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; use Doctrine\Inflector\Rules\Ruleset; use function array_merge; /** * Inflects based on multiple rulesets. * * Rules: * - If the word matches any uninflected word pattern, it is not inflected * - The first ruleset that returns a different value for an irregular word wins * - The first ruleset that returns a different value for a regular word wins * - If none of the above match, the word is left as-is */ class RulesetInflector implements WordInflector { /** @var Ruleset[] */ private $rulesets; public function __construct(Ruleset $ruleset, Ruleset ...$rulesets) { $this->rulesets = array_merge([$ruleset], $rulesets); } public function inflect(string $word): string { if ($word === '') { return ''; } foreach ($this->rulesets as $ruleset) { if ($ruleset->getUninflected()->matches($word)) { return $word; } $inflected = $ruleset->getIrregular()->inflect($word); if ($inflected !== $word) { return $inflected; } $inflected = $ruleset->getRegular()->inflect($word); if ($inflected !== $word) { return $inflected; } } return $word; } } inflector/lib/Doctrine/Inflector/Inflector.php 0000644 00000031060 15024770424 0015436 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; use RuntimeException; use function chr; use function function_exists; use function lcfirst; use function mb_strtolower; use function ord; use function preg_match; use function preg_replace; use function sprintf; use function str_replace; use function strlen; use function strtolower; use function strtr; use function trim; use function ucwords; class Inflector { private const ACCENTED_CHARACTERS = [ 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'Ae', 'Æ' => 'Ae', 'Å' => 'Aa', 'æ' => 'a', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'Oe', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'Ue', 'Ý' => 'Y', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'ae', 'å' => 'aa', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'oe', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'ue', 'ý' => 'y', 'ÿ' => 'y', 'Ā' => 'A', 'ā' => 'a', 'Ă' => 'A', 'ă' => 'a', 'Ą' => 'A', 'ą' => 'a', 'Ć' => 'C', 'ć' => 'c', 'Ĉ' => 'C', 'ĉ' => 'c', 'Ċ' => 'C', 'ċ' => 'c', 'Č' => 'C', 'č' => 'c', 'Ď' => 'D', 'ď' => 'd', 'Đ' => 'D', 'đ' => 'd', 'Ē' => 'E', 'ē' => 'e', 'Ĕ' => 'E', 'ĕ' => 'e', 'Ė' => 'E', 'ė' => 'e', 'Ę' => 'E', 'ę' => 'e', 'Ě' => 'E', 'ě' => 'e', 'Ĝ' => 'G', 'ĝ' => 'g', 'Ğ' => 'G', 'ğ' => 'g', 'Ġ' => 'G', 'ġ' => 'g', 'Ģ' => 'G', 'ģ' => 'g', 'Ĥ' => 'H', 'ĥ' => 'h', 'Ħ' => 'H', 'ħ' => 'h', 'Ĩ' => 'I', 'ĩ' => 'i', 'Ī' => 'I', 'ī' => 'i', 'Ĭ' => 'I', 'ĭ' => 'i', 'Į' => 'I', 'į' => 'i', 'İ' => 'I', 'ı' => 'i', 'IJ' => 'IJ', 'ij' => 'ij', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'ĸ' => 'k', 'Ĺ' => 'L', 'ĺ' => 'l', 'Ļ' => 'L', 'ļ' => 'l', 'Ľ' => 'L', 'ľ' => 'l', 'Ŀ' => 'L', 'ŀ' => 'l', 'Ł' => 'L', 'ł' => 'l', 'Ń' => 'N', 'ń' => 'n', 'Ņ' => 'N', 'ņ' => 'n', 'Ň' => 'N', 'ň' => 'n', 'ʼn' => 'N', 'Ŋ' => 'n', 'ŋ' => 'N', 'Ō' => 'O', 'ō' => 'o', 'Ŏ' => 'O', 'ŏ' => 'o', 'Ő' => 'O', 'ő' => 'o', 'Œ' => 'OE', 'œ' => 'oe', 'Ø' => 'O', 'ø' => 'o', 'Ŕ' => 'R', 'ŕ' => 'r', 'Ŗ' => 'R', 'ŗ' => 'r', 'Ř' => 'R', 'ř' => 'r', 'Ś' => 'S', 'ś' => 's', 'Ŝ' => 'S', 'ŝ' => 's', 'Ş' => 'S', 'ş' => 's', 'Š' => 'S', 'š' => 's', 'Ţ' => 'T', 'ţ' => 't', 'Ť' => 'T', 'ť' => 't', 'Ŧ' => 'T', 'ŧ' => 't', 'Ũ' => 'U', 'ũ' => 'u', 'Ū' => 'U', 'ū' => 'u', 'Ŭ' => 'U', 'ŭ' => 'u', 'Ů' => 'U', 'ů' => 'u', 'Ű' => 'U', 'ű' => 'u', 'Ų' => 'U', 'ų' => 'u', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ŷ' => 'Y', 'ŷ' => 'y', 'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z', 'ſ' => 's', '€' => 'E', '£' => '', ]; /** @var WordInflector */ private $singularizer; /** @var WordInflector */ private $pluralizer; public function __construct(WordInflector $singularizer, WordInflector $pluralizer) { $this->singularizer = $singularizer; $this->pluralizer = $pluralizer; } /** * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. */ public function tableize(string $word): string { $tableized = preg_replace('~(?<=\\w)([A-Z])~u', '_$1', $word); if ($tableized === null) { throw new RuntimeException(sprintf( 'preg_replace returned null for value "%s"', $word )); } return mb_strtolower($tableized); } /** * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. */ public function classify(string $word): string { return str_replace([' ', '_', '-'], '', ucwords($word, ' _-')); } /** * Camelizes a word. This uses the classify() method and turns the first character to lowercase. */ public function camelize(string $word): string { return lcfirst($this->classify($word)); } /** * Uppercases words with configurable delimiters between words. * * Takes a string and capitalizes all of the words, like PHP's built-in * ucwords function. This extends that behavior, however, by allowing the * word delimiters to be configured, rather than only separating on * whitespace. * * Here is an example: * <code> * <?php * $string = 'top-o-the-morning to all_of_you!'; * echo $inflector->capitalize($string); * // Top-O-The-Morning To All_of_you! * * echo $inflector->capitalize($string, '-_ '); * // Top-O-The-Morning To All_Of_You! * ?> * </code> * * @param string $string The string to operate on. * @param string $delimiters A list of word separators. * * @return string The string with all delimiter-separated words capitalized. */ public function capitalize(string $string, string $delimiters = " \n\t\r\0\x0B-"): string { return ucwords($string, $delimiters); } /** * Checks if the given string seems like it has utf8 characters in it. * * @param string $string The string to check for utf8 characters in. */ public function seemsUtf8(string $string): bool { for ($i = 0; $i < strlen($string); $i++) { if (ord($string[$i]) < 0x80) { continue; // 0bbbbbbb } if ((ord($string[$i]) & 0xE0) === 0xC0) { $n = 1; // 110bbbbb } elseif ((ord($string[$i]) & 0xF0) === 0xE0) { $n = 2; // 1110bbbb } elseif ((ord($string[$i]) & 0xF8) === 0xF0) { $n = 3; // 11110bbb } elseif ((ord($string[$i]) & 0xFC) === 0xF8) { $n = 4; // 111110bb } elseif ((ord($string[$i]) & 0xFE) === 0xFC) { $n = 5; // 1111110b } else { return false; // Does not match any model } for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ? if (++$i === strlen($string) || ((ord($string[$i]) & 0xC0) !== 0x80)) { return false; } } } return true; } /** * Remove any illegal characters, accents, etc. * * @param string $string String to unaccent * * @return string Unaccented string */ public function unaccent(string $string): string { if (preg_match('/[\x80-\xff]/', $string) === false) { return $string; } if ($this->seemsUtf8($string)) { $string = strtr($string, self::ACCENTED_CHARACTERS); } else { $characters = []; // Assume ISO-8859-1 if not UTF-8 $characters['in'] = chr(128) . chr(131) . chr(138) . chr(142) . chr(154) . chr(158) . chr(159) . chr(162) . chr(165) . chr(181) . chr(192) . chr(193) . chr(194) . chr(195) . chr(196) . chr(197) . chr(199) . chr(200) . chr(201) . chr(202) . chr(203) . chr(204) . chr(205) . chr(206) . chr(207) . chr(209) . chr(210) . chr(211) . chr(212) . chr(213) . chr(214) . chr(216) . chr(217) . chr(218) . chr(219) . chr(220) . chr(221) . chr(224) . chr(225) . chr(226) . chr(227) . chr(228) . chr(229) . chr(231) . chr(232) . chr(233) . chr(234) . chr(235) . chr(236) . chr(237) . chr(238) . chr(239) . chr(241) . chr(242) . chr(243) . chr(244) . chr(245) . chr(246) . chr(248) . chr(249) . chr(250) . chr(251) . chr(252) . chr(253) . chr(255); $characters['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'; $string = strtr($string, $characters['in'], $characters['out']); $doubleChars = []; $doubleChars['in'] = [ chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254), ]; $doubleChars['out'] = ['OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th']; $string = str_replace($doubleChars['in'], $doubleChars['out'], $string); } return $string; } /** * Convert any passed string to a url friendly string. * Converts 'My first blog post' to 'my-first-blog-post' * * @param string $string String to urlize. * * @return string Urlized string. */ public function urlize(string $string): string { // Remove all non url friendly characters with the unaccent function $unaccented = $this->unaccent($string); if (function_exists('mb_strtolower')) { $lowered = mb_strtolower($unaccented); } else { $lowered = strtolower($unaccented); } $replacements = [ '/\W/' => ' ', '/([A-Z]+)([A-Z][a-z])/' => '\1_\2', '/([a-z\d])([A-Z])/' => '\1_\2', '/[^A-Z^a-z^0-9^\/]+/' => '-', ]; $urlized = $lowered; foreach ($replacements as $pattern => $replacement) { $replaced = preg_replace($pattern, $replacement, $urlized); if ($replaced === null) { throw new RuntimeException(sprintf( 'preg_replace returned null for value "%s"', $urlized )); } $urlized = $replaced; } return trim($urlized, '-'); } /** * Returns a word in singular form. * * @param string $word The word in plural form. * * @return string The word in singular form. */ public function singularize(string $word): string { return $this->singularizer->inflect($word); } /** * Returns a word in plural form. * * @param string $word The word in singular form. * * @return string The word in plural form. */ public function pluralize(string $word): string { return $this->pluralizer->inflect($word); } } inflector/lib/Doctrine/Inflector/Rules/Portuguese/InflectorFactory.php 0000644 00000000720 15024770424 0022221 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Portuguese; use Doctrine\Inflector\GenericLanguageInflectorFactory; use Doctrine\Inflector\Rules\Ruleset; final class InflectorFactory extends GenericLanguageInflectorFactory { protected function getSingularRuleset(): Ruleset { return Rules::getSingularRuleset(); } protected function getPluralRuleset(): Ruleset { return Rules::getPluralRuleset(); } } inflector/lib/Doctrine/Inflector/Rules/Portuguese/Uninflected.php 0000644 00000001260 15024770424 0021204 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Portuguese; use Doctrine\Inflector\Rules\Pattern; final class Uninflected { /** @return Pattern[] */ public static function getSingular(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ public static function getPlural(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ private static function getDefault(): iterable { yield new Pattern('tórax'); yield new Pattern('tênis'); yield new Pattern('ônibus'); yield new Pattern('lápis'); yield new Pattern('fênix'); } } inflector/lib/Doctrine/Inflector/Rules/Portuguese/Rules.php 0000644 00000001555 15024770424 0020045 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Portuguese; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformations; final class Rules { public static function getSingularRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getSingular()), new Patterns(...Uninflected::getSingular()), (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() ); } public static function getPluralRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getPlural()), new Patterns(...Uninflected::getPlural()), new Substitutions(...Inflectible::getIrregular()) ); } } inflector/lib/Doctrine/Inflector/Rules/Portuguese/Inflectible.php 0000644 00000013020 15024770424 0021161 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Portuguese; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Word; class Inflectible { /** @return Transformation[] */ public static function getSingular(): iterable { yield new Transformation(new Pattern('/^(g|)ases$/i'), '\1ás'); yield new Transformation(new Pattern('/(japon|escoc|ingl|dinamarqu|fregu|portugu)eses$/i'), '\1ês'); yield new Transformation(new Pattern('/(ae|ao|oe)s$/'), 'ao'); yield new Transformation(new Pattern('/(ãe|ão|õe)s$/'), 'ão'); yield new Transformation(new Pattern('/^(.*[^s]s)es$/i'), '\1'); yield new Transformation(new Pattern('/sses$/i'), 'sse'); yield new Transformation(new Pattern('/ns$/i'), 'm'); yield new Transformation(new Pattern('/(r|t|f|v)is$/i'), '\1il'); yield new Transformation(new Pattern('/uis$/i'), 'ul'); yield new Transformation(new Pattern('/ois$/i'), 'ol'); yield new Transformation(new Pattern('/eis$/i'), 'ei'); yield new Transformation(new Pattern('/éis$/i'), 'el'); yield new Transformation(new Pattern('/([^p])ais$/i'), '\1al'); yield new Transformation(new Pattern('/(r|z)es$/i'), '\1'); yield new Transformation(new Pattern('/^(á|gá)s$/i'), '\1s'); yield new Transformation(new Pattern('/([^ê])s$/i'), '\1'); } /** @return Transformation[] */ public static function getPlural(): iterable { yield new Transformation(new Pattern('/^(alem|c|p)ao$/i'), '\1aes'); yield new Transformation(new Pattern('/^(irm|m)ao$/i'), '\1aos'); yield new Transformation(new Pattern('/ao$/i'), 'oes'); yield new Transformation(new Pattern('/^(alem|c|p)ão$/i'), '\1ães'); yield new Transformation(new Pattern('/^(irm|m)ão$/i'), '\1ãos'); yield new Transformation(new Pattern('/ão$/i'), 'ões'); yield new Transformation(new Pattern('/^(|g)ás$/i'), '\1ases'); yield new Transformation(new Pattern('/^(japon|escoc|ingl|dinamarqu|fregu|portugu)ês$/i'), '\1eses'); yield new Transformation(new Pattern('/m$/i'), 'ns'); yield new Transformation(new Pattern('/([^aeou])il$/i'), '\1is'); yield new Transformation(new Pattern('/ul$/i'), 'uis'); yield new Transformation(new Pattern('/ol$/i'), 'ois'); yield new Transformation(new Pattern('/el$/i'), 'eis'); yield new Transformation(new Pattern('/al$/i'), 'ais'); yield new Transformation(new Pattern('/(z|r)$/i'), '\1es'); yield new Transformation(new Pattern('/(s)$/i'), '\1'); yield new Transformation(new Pattern('/$/'), 's'); } /** @return Substitution[] */ public static function getIrregular(): iterable { yield new Substitution(new Word('abdomen'), new Word('abdomens')); yield new Substitution(new Word('alemão'), new Word('alemães')); yield new Substitution(new Word('artesã'), new Word('artesãos')); yield new Substitution(new Word('álcool'), new Word('álcoois')); yield new Substitution(new Word('árvore'), new Word('árvores')); yield new Substitution(new Word('bencão'), new Word('bencãos')); yield new Substitution(new Word('cão'), new Word('cães')); yield new Substitution(new Word('campus'), new Word('campi')); yield new Substitution(new Word('cadáver'), new Word('cadáveres')); yield new Substitution(new Word('capelão'), new Word('capelães')); yield new Substitution(new Word('capitão'), new Word('capitães')); yield new Substitution(new Word('chão'), new Word('chãos')); yield new Substitution(new Word('charlatão'), new Word('charlatães')); yield new Substitution(new Word('cidadão'), new Word('cidadãos')); yield new Substitution(new Word('consul'), new Word('consules')); yield new Substitution(new Word('cristão'), new Word('cristãos')); yield new Substitution(new Word('difícil'), new Word('difíceis')); yield new Substitution(new Word('email'), new Word('emails')); yield new Substitution(new Word('escrivão'), new Word('escrivães')); yield new Substitution(new Word('fóssil'), new Word('fósseis')); yield new Substitution(new Word('gás'), new Word('gases')); yield new Substitution(new Word('germens'), new Word('germen')); yield new Substitution(new Word('grão'), new Word('grãos')); yield new Substitution(new Word('hífen'), new Word('hífens')); yield new Substitution(new Word('irmão'), new Word('irmãos')); yield new Substitution(new Word('liquens'), new Word('liquen')); yield new Substitution(new Word('mal'), new Word('males')); yield new Substitution(new Word('mão'), new Word('mãos')); yield new Substitution(new Word('orfão'), new Word('orfãos')); yield new Substitution(new Word('país'), new Word('países')); yield new Substitution(new Word('pai'), new Word('pais')); yield new Substitution(new Word('pão'), new Word('pães')); yield new Substitution(new Word('projétil'), new Word('projéteis')); yield new Substitution(new Word('réptil'), new Word('répteis')); yield new Substitution(new Word('sacristão'), new Word('sacristães')); yield new Substitution(new Word('sotão'), new Word('sotãos')); yield new Substitution(new Word('tabelião'), new Word('tabeliães')); } } inflector/lib/Doctrine/Inflector/Rules/Transformation.php 0000644 00000001426 15024770424 0017614 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; use Doctrine\Inflector\WordInflector; use function preg_replace; final class Transformation implements WordInflector { /** @var Pattern */ private $pattern; /** @var string */ private $replacement; public function __construct(Pattern $pattern, string $replacement) { $this->pattern = $pattern; $this->replacement = $replacement; } public function getPattern(): Pattern { return $this->pattern; } public function getReplacement(): string { return $this->replacement; } public function inflect(string $word): string { return (string) preg_replace($this->pattern->getRegex(), $this->replacement, $word); } } inflector/lib/Doctrine/Inflector/Rules/Pattern.php 0000644 00000001424 15024770424 0016221 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; use function preg_match; final class Pattern { /** @var string */ private $pattern; /** @var string */ private $regex; public function __construct(string $pattern) { $this->pattern = $pattern; if (isset($this->pattern[0]) && $this->pattern[0] === '/') { $this->regex = $this->pattern; } else { $this->regex = '/' . $this->pattern . '/i'; } } public function getPattern(): string { return $this->pattern; } public function getRegex(): string { return $this->regex; } public function matches(string $word): bool { return preg_match($this->getRegex(), $word) === 1; } } inflector/lib/Doctrine/Inflector/Rules/Spanish/InflectorFactory.php 0000644 00000000715 15024770424 0021470 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Spanish; use Doctrine\Inflector\GenericLanguageInflectorFactory; use Doctrine\Inflector\Rules\Ruleset; final class InflectorFactory extends GenericLanguageInflectorFactory { protected function getSingularRuleset(): Ruleset { return Rules::getSingularRuleset(); } protected function getPluralRuleset(): Ruleset { return Rules::getPluralRuleset(); } } inflector/lib/Doctrine/Inflector/Rules/Spanish/Uninflected.php 0000644 00000001147 15024770424 0020453 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Spanish; use Doctrine\Inflector\Rules\Pattern; final class Uninflected { /** @return Pattern[] */ public static function getSingular(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ public static function getPlural(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ private static function getDefault(): iterable { yield new Pattern('lunes'); yield new Pattern('rompecabezas'); yield new Pattern('crisis'); } } inflector/lib/Doctrine/Inflector/Rules/Spanish/Rules.php 0000644 00000001552 15024770424 0017305 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Spanish; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformations; final class Rules { public static function getSingularRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getSingular()), new Patterns(...Uninflected::getSingular()), (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() ); } public static function getPluralRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getPlural()), new Patterns(...Uninflected::getPlural()), new Substitutions(...Inflectible::getIrregular()) ); } } inflector/lib/Doctrine/Inflector/Rules/Spanish/Inflectible.php 0000644 00000003471 15024770424 0020435 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Spanish; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Word; class Inflectible { /** @return Transformation[] */ public static function getSingular(): iterable { yield new Transformation(new Pattern('/ereses$/'), 'erés'); yield new Transformation(new Pattern('/iones$/'), 'ión'); yield new Transformation(new Pattern('/ces$/'), 'z'); yield new Transformation(new Pattern('/es$/'), ''); yield new Transformation(new Pattern('/s$/'), ''); } /** @return Transformation[] */ public static function getPlural(): iterable { yield new Transformation(new Pattern('/ú([sn])$/i'), 'u\1es'); yield new Transformation(new Pattern('/ó([sn])$/i'), 'o\1es'); yield new Transformation(new Pattern('/í([sn])$/i'), 'i\1es'); yield new Transformation(new Pattern('/é([sn])$/i'), 'e\1es'); yield new Transformation(new Pattern('/á([sn])$/i'), 'a\1es'); yield new Transformation(new Pattern('/z$/i'), 'ces'); yield new Transformation(new Pattern('/([aeiou]s)$/i'), '\1'); yield new Transformation(new Pattern('/([^aeéiou])$/i'), '\1es'); yield new Transformation(new Pattern('/$/'), 's'); } /** @return Substitution[] */ public static function getIrregular(): iterable { yield new Substitution(new Word('el'), new Word('los')); yield new Substitution(new Word('papá'), new Word('papás')); yield new Substitution(new Word('mamá'), new Word('mamás')); yield new Substitution(new Word('sofá'), new Word('sofás')); yield new Substitution(new Word('mes'), new Word('meses')); } } inflector/lib/Doctrine/Inflector/Rules/NorwegianBokmal/InflectorFactory.php 0000644 00000000725 15024770424 0023143 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\NorwegianBokmal; use Doctrine\Inflector\GenericLanguageInflectorFactory; use Doctrine\Inflector\Rules\Ruleset; final class InflectorFactory extends GenericLanguageInflectorFactory { protected function getSingularRuleset(): Ruleset { return Rules::getSingularRuleset(); } protected function getPluralRuleset(): Ruleset { return Rules::getPluralRuleset(); } } inflector/lib/Doctrine/Inflector/Rules/NorwegianBokmal/Uninflected.php 0000644 00000001144 15024770424 0022122 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\NorwegianBokmal; use Doctrine\Inflector\Rules\Pattern; final class Uninflected { /** @return Pattern[] */ public static function getSingular(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ public static function getPlural(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ private static function getDefault(): iterable { yield new Pattern('barn'); yield new Pattern('fjell'); yield new Pattern('hus'); } } inflector/lib/Doctrine/Inflector/Rules/NorwegianBokmal/Rules.php 0000644 00000001562 15024770424 0020760 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\NorwegianBokmal; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformations; final class Rules { public static function getSingularRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getSingular()), new Patterns(...Uninflected::getSingular()), (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() ); } public static function getPluralRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getPlural()), new Patterns(...Uninflected::getPlural()), new Substitutions(...Inflectible::getIrregular()) ); } } inflector/lib/Doctrine/Inflector/Rules/NorwegianBokmal/Inflectible.php 0000644 00000001657 15024770424 0022113 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\NorwegianBokmal; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Word; class Inflectible { /** @return Transformation[] */ public static function getSingular(): iterable { yield new Transformation(new Pattern('/re$/i'), 'r'); yield new Transformation(new Pattern('/er$/i'), ''); } /** @return Transformation[] */ public static function getPlural(): iterable { yield new Transformation(new Pattern('/e$/i'), 'er'); yield new Transformation(new Pattern('/r$/i'), 're'); yield new Transformation(new Pattern('/$/'), 'er'); } /** @return Substitution[] */ public static function getIrregular(): iterable { yield new Substitution(new Word('konto'), new Word('konti')); } } inflector/lib/Doctrine/Inflector/Rules/Substitution.php 0000644 00000000703 15024770424 0017317 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; final class Substitution { /** @var Word */ private $from; /** @var Word */ private $to; public function __construct(Word $from, Word $to) { $this->from = $from; $this->to = $to; } public function getFrom(): Word { return $this->from; } public function getTo(): Word { return $this->to; } } inflector/lib/Doctrine/Inflector/Rules/English/InflectorFactory.php 0000644 00000000715 15024770424 0021454 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\English; use Doctrine\Inflector\GenericLanguageInflectorFactory; use Doctrine\Inflector\Rules\Ruleset; final class InflectorFactory extends GenericLanguageInflectorFactory { protected function getSingularRuleset(): Ruleset { return Rules::getSingularRuleset(); } protected function getPluralRuleset(): Ruleset { return Rules::getPluralRuleset(); } } inflector/lib/Doctrine/Inflector/Rules/English/Uninflected.php 0000644 00000014617 15024770424 0020445 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\English; use Doctrine\Inflector\Rules\Pattern; final class Uninflected { /** @return Pattern[] */ public static function getSingular(): iterable { yield from self::getDefault(); yield new Pattern('.*ss'); yield new Pattern('clothes'); yield new Pattern('data'); yield new Pattern('fascia'); yield new Pattern('fuchsia'); yield new Pattern('galleria'); yield new Pattern('mafia'); yield new Pattern('militia'); yield new Pattern('pants'); yield new Pattern('petunia'); yield new Pattern('sepia'); yield new Pattern('trivia'); yield new Pattern('utopia'); } /** @return Pattern[] */ public static function getPlural(): iterable { yield from self::getDefault(); yield new Pattern('people'); yield new Pattern('trivia'); yield new Pattern('\w+ware$'); yield new Pattern('media'); } /** @return Pattern[] */ private static function getDefault(): iterable { yield new Pattern('\w+media'); yield new Pattern('advice'); yield new Pattern('aircraft'); yield new Pattern('amoyese'); yield new Pattern('art'); yield new Pattern('audio'); yield new Pattern('baggage'); yield new Pattern('bison'); yield new Pattern('borghese'); yield new Pattern('bream'); yield new Pattern('breeches'); yield new Pattern('britches'); yield new Pattern('buffalo'); yield new Pattern('butter'); yield new Pattern('cantus'); yield new Pattern('carp'); yield new Pattern('cattle'); yield new Pattern('chassis'); yield new Pattern('clippers'); yield new Pattern('clothing'); yield new Pattern('coal'); yield new Pattern('cod'); yield new Pattern('coitus'); yield new Pattern('compensation'); yield new Pattern('congoese'); yield new Pattern('contretemps'); yield new Pattern('coreopsis'); yield new Pattern('corps'); yield new Pattern('cotton'); yield new Pattern('data'); yield new Pattern('debris'); yield new Pattern('deer'); yield new Pattern('diabetes'); yield new Pattern('djinn'); yield new Pattern('education'); yield new Pattern('eland'); yield new Pattern('elk'); yield new Pattern('emoji'); yield new Pattern('equipment'); yield new Pattern('evidence'); yield new Pattern('faroese'); yield new Pattern('feedback'); yield new Pattern('fish'); yield new Pattern('flounder'); yield new Pattern('flour'); yield new Pattern('foochowese'); yield new Pattern('food'); yield new Pattern('furniture'); yield new Pattern('gallows'); yield new Pattern('genevese'); yield new Pattern('genoese'); yield new Pattern('gilbertese'); yield new Pattern('gold'); yield new Pattern('headquarters'); yield new Pattern('herpes'); yield new Pattern('hijinks'); yield new Pattern('homework'); yield new Pattern('hottentotese'); yield new Pattern('impatience'); yield new Pattern('information'); yield new Pattern('innings'); yield new Pattern('jackanapes'); yield new Pattern('jeans'); yield new Pattern('jedi'); yield new Pattern('kin'); yield new Pattern('kiplingese'); yield new Pattern('knowledge'); yield new Pattern('kongoese'); yield new Pattern('leather'); yield new Pattern('love'); yield new Pattern('lucchese'); yield new Pattern('luggage'); yield new Pattern('mackerel'); yield new Pattern('Maltese'); yield new Pattern('management'); yield new Pattern('metadata'); yield new Pattern('mews'); yield new Pattern('money'); yield new Pattern('moose'); yield new Pattern('mumps'); yield new Pattern('music'); yield new Pattern('nankingese'); yield new Pattern('news'); yield new Pattern('nexus'); yield new Pattern('niasese'); yield new Pattern('nutrition'); yield new Pattern('offspring'); yield new Pattern('oil'); yield new Pattern('patience'); yield new Pattern('pekingese'); yield new Pattern('piedmontese'); yield new Pattern('pincers'); yield new Pattern('pistoiese'); yield new Pattern('plankton'); yield new Pattern('pliers'); yield new Pattern('pokemon'); yield new Pattern('police'); yield new Pattern('polish'); yield new Pattern('portuguese'); yield new Pattern('proceedings'); yield new Pattern('progress'); yield new Pattern('rabies'); yield new Pattern('rain'); yield new Pattern('research'); yield new Pattern('rhinoceros'); yield new Pattern('rice'); yield new Pattern('salmon'); yield new Pattern('sand'); yield new Pattern('sarawakese'); yield new Pattern('scissors'); yield new Pattern('sea[- ]bass'); yield new Pattern('series'); yield new Pattern('shavese'); yield new Pattern('shears'); yield new Pattern('sheep'); yield new Pattern('siemens'); yield new Pattern('silk'); yield new Pattern('sms'); yield new Pattern('soap'); yield new Pattern('social media'); yield new Pattern('spam'); yield new Pattern('species'); yield new Pattern('staff'); yield new Pattern('sugar'); yield new Pattern('swine'); yield new Pattern('talent'); yield new Pattern('toothpaste'); yield new Pattern('traffic'); yield new Pattern('travel'); yield new Pattern('trousers'); yield new Pattern('trout'); yield new Pattern('tuna'); yield new Pattern('us'); yield new Pattern('vermontese'); yield new Pattern('vinegar'); yield new Pattern('weather'); yield new Pattern('wenchowese'); yield new Pattern('wheat'); yield new Pattern('whiting'); yield new Pattern('wildebeest'); yield new Pattern('wood'); yield new Pattern('wool'); yield new Pattern('yengeese'); } } inflector/lib/Doctrine/Inflector/Rules/English/Rules.php 0000644 00000001552 15024770424 0017271 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\English; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformations; final class Rules { public static function getSingularRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getSingular()), new Patterns(...Uninflected::getSingular()), (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() ); } public static function getPluralRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getPlural()), new Patterns(...Uninflected::getPlural()), new Substitutions(...Inflectible::getIrregular()) ); } } inflector/lib/Doctrine/Inflector/Rules/English/Inflectible.php 0000644 00000026470 15024770424 0020425 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\English; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Word; class Inflectible { /** @return Transformation[] */ public static function getSingular(): iterable { yield new Transformation(new Pattern('(s)tatuses$'), '\1\2tatus'); yield new Transformation(new Pattern('(s)tatus$'), '\1\2tatus'); yield new Transformation(new Pattern('(c)ampus$'), '\1\2ampus'); yield new Transformation(new Pattern('^(.*)(menu)s$'), '\1\2'); yield new Transformation(new Pattern('(quiz)zes$'), '\\1'); yield new Transformation(new Pattern('(matr)ices$'), '\1ix'); yield new Transformation(new Pattern('(vert|ind)ices$'), '\1ex'); yield new Transformation(new Pattern('^(ox)en'), '\1'); yield new Transformation(new Pattern('(alias)(es)*$'), '\1'); yield new Transformation(new Pattern('(buffal|her|potat|tomat|volcan)oes$'), '\1o'); yield new Transformation(new Pattern('(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$'), '\1us'); yield new Transformation(new Pattern('([ftw]ax)es'), '\1'); yield new Transformation(new Pattern('(analys|ax|cris|test|thes)es$'), '\1is'); yield new Transformation(new Pattern('(shoe|slave)s$'), '\1'); yield new Transformation(new Pattern('(o)es$'), '\1'); yield new Transformation(new Pattern('ouses$'), 'ouse'); yield new Transformation(new Pattern('([^a])uses$'), '\1us'); yield new Transformation(new Pattern('([m|l])ice$'), '\1ouse'); yield new Transformation(new Pattern('(x|ch|ss|sh)es$'), '\1'); yield new Transformation(new Pattern('(m)ovies$'), '\1\2ovie'); yield new Transformation(new Pattern('(s)eries$'), '\1\2eries'); yield new Transformation(new Pattern('([^aeiouy]|qu)ies$'), '\1y'); yield new Transformation(new Pattern('([lr])ves$'), '\1f'); yield new Transformation(new Pattern('(tive)s$'), '\1'); yield new Transformation(new Pattern('(hive)s$'), '\1'); yield new Transformation(new Pattern('(drive)s$'), '\1'); yield new Transformation(new Pattern('(dive)s$'), '\1'); yield new Transformation(new Pattern('(olive)s$'), '\1'); yield new Transformation(new Pattern('([^fo])ves$'), '\1fe'); yield new Transformation(new Pattern('(^analy)ses$'), '\1sis'); yield new Transformation(new Pattern('(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$'), '\1\2sis'); yield new Transformation(new Pattern('(tax)a$'), '\1on'); yield new Transformation(new Pattern('(c)riteria$'), '\1riterion'); yield new Transformation(new Pattern('([ti])a$'), '\1um'); yield new Transformation(new Pattern('(p)eople$'), '\1\2erson'); yield new Transformation(new Pattern('(m)en$'), '\1an'); yield new Transformation(new Pattern('(c)hildren$'), '\1\2hild'); yield new Transformation(new Pattern('(f)eet$'), '\1oot'); yield new Transformation(new Pattern('(n)ews$'), '\1\2ews'); yield new Transformation(new Pattern('eaus$'), 'eau'); yield new Transformation(new Pattern('^tights$'), 'tights'); yield new Transformation(new Pattern('^shorts$'), 'shorts'); yield new Transformation(new Pattern('s$'), ''); } /** @return Transformation[] */ public static function getPlural(): iterable { yield new Transformation(new Pattern('(s)tatus$'), '\1\2tatuses'); yield new Transformation(new Pattern('(quiz)$'), '\1zes'); yield new Transformation(new Pattern('^(ox)$'), '\1\2en'); yield new Transformation(new Pattern('([m|l])ouse$'), '\1ice'); yield new Transformation(new Pattern('(matr|vert|ind)(ix|ex)$'), '\1ices'); yield new Transformation(new Pattern('(x|ch|ss|sh)$'), '\1es'); yield new Transformation(new Pattern('([^aeiouy]|qu)y$'), '\1ies'); yield new Transformation(new Pattern('(hive|gulf)$'), '\1s'); yield new Transformation(new Pattern('(?:([^f])fe|([lr])f)$'), '\1\2ves'); yield new Transformation(new Pattern('sis$'), 'ses'); yield new Transformation(new Pattern('([ti])um$'), '\1a'); yield new Transformation(new Pattern('(tax)on$'), '\1a'); yield new Transformation(new Pattern('(c)riterion$'), '\1riteria'); yield new Transformation(new Pattern('(p)erson$'), '\1eople'); yield new Transformation(new Pattern('(m)an$'), '\1en'); yield new Transformation(new Pattern('(c)hild$'), '\1hildren'); yield new Transformation(new Pattern('(f)oot$'), '\1eet'); yield new Transformation(new Pattern('(buffal|her|potat|tomat|volcan)o$'), '\1\2oes'); yield new Transformation(new Pattern('(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$'), '\1i'); yield new Transformation(new Pattern('us$'), 'uses'); yield new Transformation(new Pattern('(alias)$'), '\1es'); yield new Transformation(new Pattern('(analys|ax|cris|test|thes)is$'), '\1es'); yield new Transformation(new Pattern('s$'), 's'); yield new Transformation(new Pattern('^$'), ''); yield new Transformation(new Pattern('$'), 's'); } /** @return Substitution[] */ public static function getIrregular(): iterable { yield new Substitution(new Word('atlas'), new Word('atlases')); yield new Substitution(new Word('axe'), new Word('axes')); yield new Substitution(new Word('beef'), new Word('beefs')); yield new Substitution(new Word('blouse'), new Word('blouses')); yield new Substitution(new Word('brother'), new Word('brothers')); yield new Substitution(new Word('cafe'), new Word('cafes')); yield new Substitution(new Word('chateau'), new Word('chateaux')); yield new Substitution(new Word('niveau'), new Word('niveaux')); yield new Substitution(new Word('child'), new Word('children')); yield new Substitution(new Word('canvas'), new Word('canvases')); yield new Substitution(new Word('cookie'), new Word('cookies')); yield new Substitution(new Word('corpus'), new Word('corpuses')); yield new Substitution(new Word('cow'), new Word('cows')); yield new Substitution(new Word('criterion'), new Word('criteria')); yield new Substitution(new Word('curriculum'), new Word('curricula')); yield new Substitution(new Word('demo'), new Word('demos')); yield new Substitution(new Word('domino'), new Word('dominoes')); yield new Substitution(new Word('echo'), new Word('echoes')); yield new Substitution(new Word('foot'), new Word('feet')); yield new Substitution(new Word('fungus'), new Word('fungi')); yield new Substitution(new Word('ganglion'), new Word('ganglions')); yield new Substitution(new Word('gas'), new Word('gases')); yield new Substitution(new Word('genie'), new Word('genies')); yield new Substitution(new Word('genus'), new Word('genera')); yield new Substitution(new Word('goose'), new Word('geese')); yield new Substitution(new Word('graffito'), new Word('graffiti')); yield new Substitution(new Word('hippopotamus'), new Word('hippopotami')); yield new Substitution(new Word('hoof'), new Word('hoofs')); yield new Substitution(new Word('human'), new Word('humans')); yield new Substitution(new Word('iris'), new Word('irises')); yield new Substitution(new Word('larva'), new Word('larvae')); yield new Substitution(new Word('leaf'), new Word('leaves')); yield new Substitution(new Word('lens'), new Word('lenses')); yield new Substitution(new Word('loaf'), new Word('loaves')); yield new Substitution(new Word('man'), new Word('men')); yield new Substitution(new Word('medium'), new Word('media')); yield new Substitution(new Word('memorandum'), new Word('memoranda')); yield new Substitution(new Word('money'), new Word('monies')); yield new Substitution(new Word('mongoose'), new Word('mongooses')); yield new Substitution(new Word('motto'), new Word('mottoes')); yield new Substitution(new Word('move'), new Word('moves')); yield new Substitution(new Word('mythos'), new Word('mythoi')); yield new Substitution(new Word('niche'), new Word('niches')); yield new Substitution(new Word('nucleus'), new Word('nuclei')); yield new Substitution(new Word('numen'), new Word('numina')); yield new Substitution(new Word('occiput'), new Word('occiputs')); yield new Substitution(new Word('octopus'), new Word('octopuses')); yield new Substitution(new Word('opus'), new Word('opuses')); yield new Substitution(new Word('ox'), new Word('oxen')); yield new Substitution(new Word('passerby'), new Word('passersby')); yield new Substitution(new Word('penis'), new Word('penises')); yield new Substitution(new Word('person'), new Word('people')); yield new Substitution(new Word('plateau'), new Word('plateaux')); yield new Substitution(new Word('runner-up'), new Word('runners-up')); yield new Substitution(new Word('safe'), new Word('safes')); yield new Substitution(new Word('sex'), new Word('sexes')); yield new Substitution(new Word('sieve'), new Word('sieves')); yield new Substitution(new Word('soliloquy'), new Word('soliloquies')); yield new Substitution(new Word('son-in-law'), new Word('sons-in-law')); yield new Substitution(new Word('syllabus'), new Word('syllabi')); yield new Substitution(new Word('testis'), new Word('testes')); yield new Substitution(new Word('thief'), new Word('thieves')); yield new Substitution(new Word('tooth'), new Word('teeth')); yield new Substitution(new Word('tornado'), new Word('tornadoes')); yield new Substitution(new Word('trilby'), new Word('trilbys')); yield new Substitution(new Word('turf'), new Word('turfs')); yield new Substitution(new Word('valve'), new Word('valves')); yield new Substitution(new Word('volcano'), new Word('volcanoes')); yield new Substitution(new Word('abuse'), new Word('abuses')); yield new Substitution(new Word('avalanche'), new Word('avalanches')); yield new Substitution(new Word('cache'), new Word('caches')); yield new Substitution(new Word('criterion'), new Word('criteria')); yield new Substitution(new Word('curve'), new Word('curves')); yield new Substitution(new Word('emphasis'), new Word('emphases')); yield new Substitution(new Word('foe'), new Word('foes')); yield new Substitution(new Word('grave'), new Word('graves')); yield new Substitution(new Word('hoax'), new Word('hoaxes')); yield new Substitution(new Word('medium'), new Word('media')); yield new Substitution(new Word('neurosis'), new Word('neuroses')); yield new Substitution(new Word('save'), new Word('saves')); yield new Substitution(new Word('wave'), new Word('waves')); yield new Substitution(new Word('oasis'), new Word('oases')); yield new Substitution(new Word('valve'), new Word('valves')); yield new Substitution(new Word('zombie'), new Word('zombies')); } } inflector/lib/Doctrine/Inflector/Rules/Substitutions.php 0000644 00000002534 15024770424 0017506 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; use Doctrine\Inflector\WordInflector; use function strtolower; use function strtoupper; use function substr; class Substitutions implements WordInflector { /** @var Substitution[] */ private $substitutions; public function __construct(Substitution ...$substitutions) { foreach ($substitutions as $substitution) { $this->substitutions[$substitution->getFrom()->getWord()] = $substitution; } } public function getFlippedSubstitutions(): Substitutions { $substitutions = []; foreach ($this->substitutions as $substitution) { $substitutions[] = new Substitution( $substitution->getTo(), $substitution->getFrom() ); } return new Substitutions(...$substitutions); } public function inflect(string $word): string { $lowerWord = strtolower($word); if (isset($this->substitutions[$lowerWord])) { $firstLetterUppercase = $lowerWord[0] !== $word[0]; $toWord = $this->substitutions[$lowerWord]->getTo()->getWord(); if ($firstLetterUppercase) { return strtoupper($toWord[0]) . substr($toWord, 1); } return $toWord; } return $word; } } inflector/lib/Doctrine/Inflector/Rules/French/InflectorFactory.php 0000644 00000000714 15024770424 0021267 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\French; use Doctrine\Inflector\GenericLanguageInflectorFactory; use Doctrine\Inflector\Rules\Ruleset; final class InflectorFactory extends GenericLanguageInflectorFactory { protected function getSingularRuleset(): Ruleset { return Rules::getSingularRuleset(); } protected function getPluralRuleset(): Ruleset { return Rules::getPluralRuleset(); } } inflector/lib/Doctrine/Inflector/Rules/French/Uninflected.php 0000644 00000001021 15024770424 0020242 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\French; use Doctrine\Inflector\Rules\Pattern; final class Uninflected { /** @return Pattern[] */ public static function getSingular(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ public static function getPlural(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ private static function getDefault(): iterable { yield new Pattern(''); } } inflector/lib/Doctrine/Inflector/Rules/French/Rules.php 0000644 00000001551 15024770424 0017104 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\French; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformations; final class Rules { public static function getSingularRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getSingular()), new Patterns(...Uninflected::getSingular()), (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() ); } public static function getPluralRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getPlural()), new Patterns(...Uninflected::getPlural()), new Substitutions(...Inflectible::getIrregular()) ); } } inflector/lib/Doctrine/Inflector/Rules/French/Inflectible.php 0000644 00000003526 15024770424 0020236 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\French; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Word; class Inflectible { /** @return Transformation[] */ public static function getSingular(): iterable { yield new Transformation(new Pattern('/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/'), '\1ail'); yield new Transformation(new Pattern('/ails$/'), 'ail'); yield new Transformation(new Pattern('/(journ|chev)aux$/'), '\1al'); yield new Transformation(new Pattern('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)x$/'), '\1'); yield new Transformation(new Pattern('/s$/'), ''); } /** @return Transformation[] */ public static function getPlural(): iterable { yield new Transformation(new Pattern('/(s|x|z)$/'), '\1'); yield new Transformation(new Pattern('/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/'), '\1aux'); yield new Transformation(new Pattern('/ail$/'), 'ails'); yield new Transformation(new Pattern('/(chacal|carnaval|festival|récital)$/'), '\1s'); yield new Transformation(new Pattern('/al$/'), 'aux'); yield new Transformation(new Pattern('/(bleu|émeu|landau|pneu|sarrau)$/'), '\1s'); yield new Transformation(new Pattern('/(bijou|caillou|chou|genou|hibou|joujou|lieu|pou|au|eu|eau)$/'), '\1x'); yield new Transformation(new Pattern('/$/'), 's'); } /** @return Substitution[] */ public static function getIrregular(): iterable { yield new Substitution(new Word('monsieur'), new Word('messieurs')); yield new Substitution(new Word('madame'), new Word('mesdames')); yield new Substitution(new Word('mademoiselle'), new Word('mesdemoiselles')); } } inflector/lib/Doctrine/Inflector/Rules/Patterns.php 0000644 00000001270 15024770424 0016403 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; use function array_map; use function implode; use function preg_match; class Patterns { /** @var Pattern[] */ private $patterns; /** @var string */ private $regex; public function __construct(Pattern ...$patterns) { $this->patterns = $patterns; $patterns = array_map(static function (Pattern $pattern): string { return $pattern->getPattern(); }, $this->patterns); $this->regex = '/^(?:' . implode('|', $patterns) . ')$/i'; } public function matches(string $word): bool { return preg_match($this->regex, $word, $regs) === 1; } } inflector/lib/Doctrine/Inflector/Rules/Word.php 0000644 00000000446 15024770424 0015522 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; class Word { /** @var string */ private $word; public function __construct(string $word) { $this->word = $word; } public function getWord(): string { return $this->word; } } inflector/lib/Doctrine/Inflector/Rules/Turkish/InflectorFactory.php 0000644 00000000715 15024770424 0021514 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Turkish; use Doctrine\Inflector\GenericLanguageInflectorFactory; use Doctrine\Inflector\Rules\Ruleset; final class InflectorFactory extends GenericLanguageInflectorFactory { protected function getSingularRuleset(): Ruleset { return Rules::getSingularRuleset(); } protected function getPluralRuleset(): Ruleset { return Rules::getPluralRuleset(); } } inflector/lib/Doctrine/Inflector/Rules/Turkish/Uninflected.php 0000644 00000001147 15024770424 0020477 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Turkish; use Doctrine\Inflector\Rules\Pattern; final class Uninflected { /** @return Pattern[] */ public static function getSingular(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ public static function getPlural(): iterable { yield from self::getDefault(); } /** @return Pattern[] */ private static function getDefault(): iterable { yield new Pattern('lunes'); yield new Pattern('rompecabezas'); yield new Pattern('crisis'); } } inflector/lib/Doctrine/Inflector/Rules/Turkish/Rules.php 0000644 00000001552 15024770424 0017331 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Turkish; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformations; final class Rules { public static function getSingularRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getSingular()), new Patterns(...Uninflected::getSingular()), (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() ); } public static function getPluralRuleset(): Ruleset { return new Ruleset( new Transformations(...Inflectible::getPlural()), new Patterns(...Uninflected::getPlural()), new Substitutions(...Inflectible::getIrregular()) ); } } inflector/lib/Doctrine/Inflector/Rules/Turkish/Inflectible.php 0000644 00000001756 15024770424 0020465 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules\Turkish; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Word; class Inflectible { /** @return Transformation[] */ public static function getSingular(): iterable { yield new Transformation(new Pattern('/l[ae]r$/i'), ''); } /** @return Transformation[] */ public static function getPlural(): iterable { yield new Transformation(new Pattern('/([eöiü][^aoıueöiü]{0,6})$/u'), '\1ler'); yield new Transformation(new Pattern('/([aoıu][^aoıueöiü]{0,6})$/u'), '\1lar'); } /** @return Substitution[] */ public static function getIrregular(): iterable { yield new Substitution(new Word('ben'), new Word('biz')); yield new Substitution(new Word('sen'), new Word('siz')); yield new Substitution(new Word('o'), new Word('onlar')); } } inflector/lib/Doctrine/Inflector/Rules/Transformations.php 0000644 00000001210 15024770424 0017766 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; use Doctrine\Inflector\WordInflector; class Transformations implements WordInflector { /** @var Transformation[] */ private $transformations; public function __construct(Transformation ...$transformations) { $this->transformations = $transformations; } public function inflect(string $word): string { foreach ($this->transformations as $transformation) { if ($transformation->getPattern()->matches($word)) { return $transformation->inflect($word); } } return $word; } } inflector/lib/Doctrine/Inflector/Rules/Ruleset.php 0000644 00000001411 15024770424 0016223 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector\Rules; class Ruleset { /** @var Transformations */ private $regular; /** @var Patterns */ private $uninflected; /** @var Substitutions */ private $irregular; public function __construct(Transformations $regular, Patterns $uninflected, Substitutions $irregular) { $this->regular = $regular; $this->uninflected = $uninflected; $this->irregular = $irregular; } public function getRegular(): Transformations { return $this->regular; } public function getUninflected(): Patterns { return $this->uninflected; } public function getIrregular(): Substitutions { return $this->irregular; } } inflector/lib/Doctrine/Inflector/CachedWordInflector.php 0000644 00000000777 15024770424 0017375 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; class CachedWordInflector implements WordInflector { /** @var WordInflector */ private $wordInflector; /** @var string[] */ private $cache = []; public function __construct(WordInflector $wordInflector) { $this->wordInflector = $wordInflector; } public function inflect(string $word): string { return $this->cache[$word] ?? $this->cache[$word] = $this->wordInflector->inflect($word); } } inflector/lib/Doctrine/Inflector/GenericLanguageInflectorFactory.php 0000644 00000003213 15024770424 0021726 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; use Doctrine\Inflector\Rules\Ruleset; use function array_unshift; abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory { /** @var Ruleset[] */ private $singularRulesets = []; /** @var Ruleset[] */ private $pluralRulesets = []; final public function __construct() { $this->singularRulesets[] = $this->getSingularRuleset(); $this->pluralRulesets[] = $this->getPluralRuleset(); } final public function build(): Inflector { return new Inflector( new CachedWordInflector(new RulesetInflector( ...$this->singularRulesets )), new CachedWordInflector(new RulesetInflector( ...$this->pluralRulesets )) ); } final public function withSingularRules(?Ruleset $singularRules, bool $reset = false): LanguageInflectorFactory { if ($reset) { $this->singularRulesets = []; } if ($singularRules instanceof Ruleset) { array_unshift($this->singularRulesets, $singularRules); } return $this; } final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): LanguageInflectorFactory { if ($reset) { $this->pluralRulesets = []; } if ($pluralRules instanceof Ruleset) { array_unshift($this->pluralRulesets, $pluralRules); } return $this; } abstract protected function getSingularRuleset(): Ruleset; abstract protected function getPluralRuleset(): Ruleset; } inflector/lib/Doctrine/Inflector/InflectorFactory.php 0000644 00000002616 15024770424 0016773 0 ustar 00 <?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 static function create(): LanguageInflectorFactory { return self::createForLanguage(Language::ENGLISH); } public static function createForLanguage(string $language): LanguageInflectorFactory { 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 )); } } } inflector/lib/Doctrine/Inflector/NoopWordInflector.php 0000644 00000000311 15024770424 0017121 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; class NoopWordInflector implements WordInflector { public function inflect(string $word): string { return $word; } } inflector/lib/Doctrine/Inflector/Language.php 0000644 00000000656 15024770424 0015243 0 ustar 00 <?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() { } } inflector/lib/Doctrine/Inflector/LanguageInflectorFactory.php 0000644 00000001445 15024770424 0020436 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Inflector; use Doctrine\Inflector\Rules\Ruleset; interface LanguageInflectorFactory { /** * Applies custom rules for singularisation * * @param bool $reset If true, will unset default inflections for all new rules * * @return $this */ public function withSingularRules(?Ruleset $singularRules, bool $reset = false): self; /** * Applies custom rules for pluralisation * * @param bool $reset If true, will unset default inflections for all new rules * * @return $this */ public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): self; /** * Builds the inflector instance with all applicable rules */ public function build(): Inflector; } inflector/README.md 0000644 00000001015 15024770424 0010012 0 ustar 00 # Doctrine Inflector Doctrine Inflector is a small library that can perform string manipulations with regard to uppercase/lowercase and singular/plural forms of words. [](https://github.com/doctrine/inflector/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.0.x) [](https://codecov.io/gh/doctrine/inflector/branch/2.0.x) inflector/LICENSE 0000644 00000002051 15024770424 0007541 0 ustar 00 Copyright (c) 2006-2015 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. inflector/docs/en/index.rst 0000644 00000014574 15024770424 0011744 0 ustar 00 Introduction ============ The Doctrine Inflector has methods for inflecting text. The features include pluralization, singularization, converting between camelCase and under_score and capitalizing words. Installation ============ You can install the Inflector with composer: .. code-block:: console $ composer require doctrine/inflector Usage ===== Using the inflector is easy, you can create a new ``Doctrine\Inflector\Inflector`` instance by using the ``Doctrine\Inflector\InflectorFactory`` class: .. code-block:: php use Doctrine\Inflector\InflectorFactory; $inflector = InflectorFactory::create()->build(); By default it will create an English inflector. If you want to use another language, just pass the language you want to create an inflector for to the ``createForLanguage()`` method: .. code-block:: php use Doctrine\Inflector\InflectorFactory; use Doctrine\Inflector\Language; $inflector = InflectorFactory::createForLanguage(Language::SPANISH)->build(); The supported languages are as follows: - ``Language::ENGLISH`` - ``Language::FRENCH`` - ``Language::NORWEGIAN_BOKMAL`` - ``Language::PORTUGUESE`` - ``Language::SPANISH`` - ``Language::TURKISH`` If you want to manually construct the inflector instead of using a factory, you can do so like this: .. code-block:: php use Doctrine\Inflector\CachedWordInflector; use Doctrine\Inflector\RulesetInflector; use Doctrine\Inflector\Rules\English; $inflector = new Inflector( new CachedWordInflector(new RulesetInflector( English\Rules::getSingularRuleset() )), new CachedWordInflector(new RulesetInflector( English\Rules::getPluralRuleset() )) ); Adding Languages ---------------- If you are interested in adding support for your language, take a look at the other languages defined in the ``Doctrine\Inflector\Rules`` namespace and the tests located in ``Doctrine\Tests\Inflector\Rules``. You can copy one of the languages and update the rules for your language. Once you have done this, send a pull request to the ``doctrine/inflector`` repository with the additions. Custom Setup ============ If you want to setup custom singular and plural rules, you can configure these in the factory: .. code-block:: php use Doctrine\Inflector\InflectorFactory; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Transformations; use Doctrine\Inflector\Rules\Word; $inflector = InflectorFactory::create() ->withSingularRules( new Ruleset( new Transformations( new Transformation(new Pattern('/^(bil)er$/i'), '\1'), new Transformation(new Pattern('/^(inflec|contribu)tors$/i'), '\1ta') ), new Patterns(new Pattern('singulars')), new Substitutions(new Substitution(new Word('spins'), new Word('spinor'))) ) ) ->withPluralRules( new Ruleset( new Transformations( new Transformation(new Pattern('^(bil)er$'), '\1'), new Transformation(new Pattern('^(inflec|contribu)tors$'), '\1ta') ), new Patterns(new Pattern('noflect'), new Pattern('abtuse')), new Substitutions( new Substitution(new Word('amaze'), new Word('amazable')), new Substitution(new Word('phone'), new Word('phonezes')) ) ) ) ->build(); No operation inflector ---------------------- The ``Doctrine\Inflector\NoopWordInflector`` may be used to configure an inflector that doesn't perform any operation for pluralization and/or singularization. If will simply return the input as output. This is an implementation of the `Null Object design pattern <https://sourcemaking.com/design_patterns/null_object>`_. .. code-block:: php use Doctrine\Inflector\Inflector; use Doctrine\Inflector\NoopWordInflector; $inflector = new Inflector(new NoopWordInflector(), new NoopWordInflector()); Tableize ======== Converts ``ModelName`` to ``model_name``: .. code-block:: php echo $inflector->tableize('ModelName'); // model_name Classify ======== Converts ``model_name`` to ``ModelName``: .. code-block:: php echo $inflector->classify('model_name'); // ModelName Camelize ======== This method uses `Classify`_ and then converts the first character to lowercase: .. code-block:: php echo $inflector->camelize('model_name'); // modelName Capitalize ========== Takes a string and capitalizes all of the words, like PHP's built-in ``ucwords`` function. This extends that behavior, however, by allowing the word delimiters to be configured, rather than only separating on whitespace. Here is an example: .. code-block:: php $string = 'top-o-the-morning to all_of_you!'; echo $inflector->capitalize($string); // Top-O-The-Morning To All_of_you! echo $inflector->capitalize($string, '-_ '); // Top-O-The-Morning To All_Of_You! Pluralize ========= Returns a word in plural form. .. code-block:: php echo $inflector->pluralize('browser'); // browsers Singularize =========== Returns a word in singular form. .. code-block:: php echo $inflector->singularize('browsers'); // browser Urlize ====== Generate a URL friendly string from a string of text: .. code-block:: php echo $inflector->urlize('My first blog post'); // my-first-blog-post Unaccent ======== You can unaccent a string of text using the ``unaccent()`` method: .. code-block:: php echo $inflector->unaccent('año'); // ano Legacy API ========== The API present in Inflector 1.x is still available, but will be deprecated in a future release and dropped for 3.0. Support for languages other than English is available in the 2.0 API only. Acknowledgements ================ The language rules in this library have been adapted from several different sources, including but not limited to: - `Ruby On Rails Inflector <http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html>`_ - `ICanBoogie Inflector <https://github.com/ICanBoogie/Inflector>`_ - `CakePHP Inflector <https://book.cakephp.org/3.0/en/core-libraries/inflector.html>`_ instantiator/composer.json 0000644 00000003006 15024770424 0012011 0 ustar 00 { "name": "doctrine/instantiator", "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", "type": "library", "license": "MIT", "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "instantiate", "constructor" ], "authors": [ { "name": "Marco Pivetta", "email": "ocramius@gmail.com", "homepage": "https://ocramius.github.io/" } ], "require": { "php": "^7.1 || ^8.0" }, "require-dev": { "ext-phar": "*", "ext-pdo": "*", "doctrine/coding-standard": "^9 || ^11", "phpbench/phpbench": "^0.16 || ^1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "vimeo/psalm": "^4.30 || ^5.4" }, "autoload": { "psr-4": { "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" } }, "autoload-dev": { "psr-0": { "DoctrineTest\\InstantiatorPerformance\\": "tests", "DoctrineTest\\InstantiatorTest\\": "tests", "DoctrineTest\\InstantiatorTestAsset\\": "tests" } }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } } } instantiator/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php 0000644 00000003127 15024770424 0023737 0 ustar 00 <?php namespace Doctrine\Instantiator\Exception; use Exception; use ReflectionClass; use UnexpectedValueException as BaseUnexpectedValueException; use function sprintf; /** * Exception for given parameters causing invalid/unexpected state on instantiation */ class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface { /** * @phpstan-param ReflectionClass<T> $reflectionClass * * @template T of object */ public static function fromSerializationTriggeredException( ReflectionClass $reflectionClass, Exception $exception ): self { return new self( sprintf( 'An exception was raised while trying to instantiate an instance of "%s" via un-serialization', $reflectionClass->getName() ), 0, $exception ); } /** * @phpstan-param ReflectionClass<T> $reflectionClass * * @template T of object */ public static function fromUncleanUnSerialization( ReflectionClass $reflectionClass, string $errorString, int $errorCode, string $errorFile, int $errorLine ): self { return new self( sprintf( 'Could not produce an instance of "%s" via un-serialization, since an error was triggered ' . 'in file "%s" at line "%d"', $reflectionClass->getName(), $errorFile, $errorLine ), 0, new Exception($errorString, $errorCode) ); } } instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php 0000644 00000002730 15024770424 0023726 0 ustar 00 <?php namespace Doctrine\Instantiator\Exception; use InvalidArgumentException as BaseInvalidArgumentException; use ReflectionClass; use function interface_exists; use function sprintf; use function trait_exists; /** * Exception for invalid arguments provided to the instantiator */ class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface { public static function fromNonExistingClass(string $className): self { if (interface_exists($className)) { return new self(sprintf('The provided type "%s" is an interface, and cannot be instantiated', $className)); } if (trait_exists($className)) { return new self(sprintf('The provided type "%s" is a trait, and cannot be instantiated', $className)); } return new self(sprintf('The provided class "%s" does not exist', $className)); } /** * @phpstan-param ReflectionClass<T> $reflectionClass * * @template T of object */ public static function fromAbstractClass(ReflectionClass $reflectionClass): self { return new self(sprintf( 'The provided class "%s" is abstract, and cannot be instantiated', $reflectionClass->getName() )); } public static function fromEnum(string $className): self { return new self(sprintf( 'The provided class "%s" is an enum, and cannot be instantiated', $className )); } } instantiator/src/Doctrine/Instantiator/Exception/ExceptionInterface.php 0000644 00000000300 15024770424 0022524 0 ustar 00 <?php namespace Doctrine\Instantiator\Exception; use Throwable; /** * Base exception marker interface for the instantiator component */ interface ExceptionInterface extends Throwable { } instantiator/src/Doctrine/Instantiator/Instantiator.php 0000644 00000016622 15024770424 0017504 0 ustar 00 <?php namespace Doctrine\Instantiator; use ArrayIterator; use Doctrine\Instantiator\Exception\ExceptionInterface; use Doctrine\Instantiator\Exception\InvalidArgumentException; use Doctrine\Instantiator\Exception\UnexpectedValueException; use Exception; use ReflectionClass; use ReflectionException; use Serializable; use function class_exists; use function enum_exists; use function is_subclass_of; use function restore_error_handler; use function set_error_handler; use function sprintf; use function strlen; use function unserialize; use const PHP_VERSION_ID; final class Instantiator implements InstantiatorInterface { /** * Markers used internally by PHP to define whether {@see \unserialize} should invoke * the method {@see \Serializable::unserialize()} when dealing with classes implementing * the {@see \Serializable} interface. * * @deprecated This constant will be private in 2.0 */ public const SERIALIZATION_FORMAT_USE_UNSERIALIZER = 'C'; /** @deprecated This constant will be private in 2.0 */ public const SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O'; /** * Used to instantiate specific classes, indexed by class name. * * @var callable[] */ private static $cachedInstantiators = []; /** * Array of objects that can directly be cloned, indexed by class name. * * @var object[] */ private static $cachedCloneables = []; /** * @param string $className * @phpstan-param class-string<T> $className * * @return object * @phpstan-return T * * @throws ExceptionInterface * * @template T of object */ public function instantiate($className) { if (isset(self::$cachedCloneables[$className])) { /** @phpstan-var T */ $cachedCloneable = self::$cachedCloneables[$className]; return clone $cachedCloneable; } if (isset(self::$cachedInstantiators[$className])) { $factory = self::$cachedInstantiators[$className]; return $factory(); } return $this->buildAndCacheFromFactory($className); } /** * Builds the requested object and caches it in static properties for performance * * @phpstan-param class-string<T> $className * * @return object * @phpstan-return T * * @template T of object */ private function buildAndCacheFromFactory(string $className) { $factory = self::$cachedInstantiators[$className] = $this->buildFactory($className); $instance = $factory(); if ($this->isSafeToClone(new ReflectionClass($instance))) { self::$cachedCloneables[$className] = clone $instance; } return $instance; } /** * Builds a callable capable of instantiating the given $className without * invoking its constructor. * * @phpstan-param class-string<T> $className * * @phpstan-return callable(): T * * @throws InvalidArgumentException * @throws UnexpectedValueException * @throws ReflectionException * * @template T of object */ private function buildFactory(string $className): callable { $reflectionClass = $this->getReflectionClass($className); if ($this->isInstantiableViaReflection($reflectionClass)) { return [$reflectionClass, 'newInstanceWithoutConstructor']; } $serializedString = sprintf( '%s:%d:"%s":0:{}', is_subclass_of($className, Serializable::class) ? self::SERIALIZATION_FORMAT_USE_UNSERIALIZER : self::SERIALIZATION_FORMAT_AVOID_UNSERIALIZER, strlen($className), $className ); $this->checkIfUnSerializationIsSupported($reflectionClass, $serializedString); return static function () use ($serializedString) { return unserialize($serializedString); }; } /** * @phpstan-param class-string<T> $className * * @phpstan-return ReflectionClass<T> * * @throws InvalidArgumentException * @throws ReflectionException * * @template T of object */ private function getReflectionClass(string $className): ReflectionClass { if (! class_exists($className)) { throw InvalidArgumentException::fromNonExistingClass($className); } if (PHP_VERSION_ID >= 80100 && enum_exists($className, false)) { throw InvalidArgumentException::fromEnum($className); } $reflection = new ReflectionClass($className); if ($reflection->isAbstract()) { throw InvalidArgumentException::fromAbstractClass($reflection); } return $reflection; } /** * @phpstan-param ReflectionClass<T> $reflectionClass * * @throws UnexpectedValueException * * @template T of object */ private function checkIfUnSerializationIsSupported(ReflectionClass $reflectionClass, string $serializedString): void { set_error_handler(static function (int $code, string $message, string $file, int $line) use ($reflectionClass, &$error): bool { $error = UnexpectedValueException::fromUncleanUnSerialization( $reflectionClass, $message, $code, $file, $line ); return true; }); try { $this->attemptInstantiationViaUnSerialization($reflectionClass, $serializedString); } finally { restore_error_handler(); } if ($error) { throw $error; } } /** * @phpstan-param ReflectionClass<T> $reflectionClass * * @throws UnexpectedValueException * * @template T of object */ private function attemptInstantiationViaUnSerialization(ReflectionClass $reflectionClass, string $serializedString): void { try { unserialize($serializedString); } catch (Exception $exception) { throw UnexpectedValueException::fromSerializationTriggeredException($reflectionClass, $exception); } } /** * @phpstan-param ReflectionClass<T> $reflectionClass * * @template T of object */ private function isInstantiableViaReflection(ReflectionClass $reflectionClass): bool { return ! ($this->hasInternalAncestors($reflectionClass) && $reflectionClass->isFinal()); } /** * Verifies whether the given class is to be considered internal * * @phpstan-param ReflectionClass<T> $reflectionClass * * @template T of object */ private function hasInternalAncestors(ReflectionClass $reflectionClass): bool { do { if ($reflectionClass->isInternal()) { return true; } $reflectionClass = $reflectionClass->getParentClass(); } while ($reflectionClass); return false; } /** * Checks if a class is cloneable * * Classes implementing `__clone` cannot be safely cloned, as that may cause side-effects. * * @phpstan-param ReflectionClass<T> $reflectionClass * * @template T of object */ private function isSafeToClone(ReflectionClass $reflectionClass): bool { return $reflectionClass->isCloneable() && ! $reflectionClass->hasMethod('__clone') && ! $reflectionClass->isSubclassOf(ArrayIterator::class); } } instantiator/src/Doctrine/Instantiator/InstantiatorInterface.php 0000644 00000000775 15024770424 0021327 0 ustar 00 <?php namespace Doctrine\Instantiator; use Doctrine\Instantiator\Exception\ExceptionInterface; /** * Instantiator provides utility methods to build objects without invoking their constructors */ interface InstantiatorInterface { /** * @param string $className * @phpstan-param class-string<T> $className * * @return object * @phpstan-return T * * @throws ExceptionInterface * * @template T of object */ public function instantiate($className); } instantiator/.doctrine-project.json 0000644 00000002021 15024770424 0013507 0 ustar 00 { "active": true, "name": "Instantiator", "slug": "instantiator", "docsSlug": "doctrine-instantiator", "codePath": "/src", "versions": [ { "name": "1.5", "branchName": "1.5.x", "slug": "latest", "upcoming": true }, { "name": "1.4", "branchName": "1.4.x", "slug": "1.4", "aliases": [ "current", "stable" ], "maintained": true, "current": true }, { "name": "1.3", "branchName": "1.3.x", "slug": "1.3", "maintained": false }, { "name": "1.2", "branchName": "1.2.x", "slug": "1.2" }, { "name": "1.1", "branchName": "1.1.x", "slug": "1.1" }, { "name": "1.0", "branchName": "1.0.x", "slug": "1.0" } ] } instantiator/README.md 0000644 00000003053 15024770424 0010550 0 ustar 00 # Instantiator This library provides a way of avoiding usage of constructors when instantiating PHP classes. [](https://travis-ci.org/doctrine/instantiator) [](https://codecov.io/gh/doctrine/instantiator/branch/master) [](https://www.versioneye.com/package/php--doctrine--instantiator) [](https://packagist.org/packages/doctrine/instantiator) [](https://packagist.org/packages/doctrine/instantiator) ## Installation The suggested installation method is via [composer](https://getcomposer.org/): ```sh composer require doctrine/instantiator ``` ## Usage The instantiator is able to create new instances of any class without using the constructor or any API of the class itself: ```php $instantiator = new \Doctrine\Instantiator\Instantiator(); $instance = $instantiator->instantiate(\My\ClassName\Here::class); ``` ## Contributing Please read the [CONTRIBUTING.md](CONTRIBUTING.md) contents if you wish to help out! ## Credits This library was migrated from [ocramius/instantiator](https://github.com/Ocramius/Instantiator), which has been donated to the doctrine organization, and which is now deprecated in favour of this package. instantiator/LICENSE 0000644 00000002044 15024770424 0010275 0 ustar 00 Copyright (c) 2014 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. instantiator/docs/en/sidebar.rst 0000644 00000000046 15024770424 0012765 0 ustar 00 .. toctree:: :depth: 3 index instantiator/docs/en/index.rst 0000644 00000003337 15024770424 0012471 0 ustar 00 Introduction ============ This library provides a way of avoiding usage of constructors when instantiating PHP classes. Installation ============ The suggested installation method is via `composer`_: .. code-block:: console $ composer require doctrine/instantiator Usage ===== The instantiator is able to create new instances of any class without using the constructor or any API of the class itself: .. code-block:: php <?php use Doctrine\Instantiator\Instantiator; use App\Entities\User; $instantiator = new Instantiator(); $user = $instantiator->instantiate(User::class); Contributing ============ - Follow the `Doctrine Coding Standard`_ - The project will follow strict `object calisthenics`_ - Any contribution must provide tests for additional introduced conditions - Any un-confirmed issue needs a failing test case before being accepted - Pull requests must be sent from a new hotfix/feature branch, not from ``master``. Testing ======= The PHPUnit version to be used is the one installed as a dev- dependency via composer: .. code-block:: console $ ./vendor/bin/phpunit Accepted coverage for new contributions is 80%. Any contribution not satisfying this requirement won’t be merged. Credits ======= This library was migrated from `ocramius/instantiator`_, which has been donated to the doctrine organization, and which is now deprecated in favour of this package. .. _composer: https://getcomposer.org/ .. _CONTRIBUTING.md: CONTRIBUTING.md .. _ocramius/instantiator: https://github.com/Ocramius/Instantiator .. _Doctrine Coding Standard: https://github.com/doctrine/coding-standard .. _object calisthenics: http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php instantiator/psalm.xml 0000644 00000000721 15024770424 0011126 0 ustar 00 <?xml version="1.0"?> <psalm errorLevel="7" phpVersion="8.2" resolveFromConfigFile="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" > <projectFiles> <directory name="src" /> <ignoreFiles> <directory name="vendor" /> </ignoreFiles> </projectFiles> </psalm> instantiator/CONTRIBUTING.md 0000644 00000002010 15024770424 0011512 0 ustar 00 # Contributing * Follow the [Doctrine Coding Standard](https://github.com/doctrine/coding-standard) * The project will follow strict [object calisthenics](http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php) * Any contribution must provide tests for additional introduced conditions * Any un-confirmed issue needs a failing test case before being accepted * Pull requests must be sent from a new hotfix/feature branch, not from `master`. ## Installation To install the project and run the tests, you need to clone it first: ```sh $ git clone git://github.com/doctrine/instantiator.git ``` You will then need to run a composer installation: ```sh $ cd Instantiator $ curl -s https://getcomposer.org/installer | php $ php composer.phar update ``` ## Testing The PHPUnit version to be used is the one installed as a dev- dependency via composer: ```sh $ ./vendor/bin/phpunit ``` Accepted coverage for new contributions is 80%. Any contribution not satisfying this requirement won't be merged. lexer/composer.json 0000644 00000002726 15024770424 0010421 0 ustar 00 { "name": "doctrine/lexer", "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", "license": "MIT", "type": "library", "keywords": [ "php", "parser", "lexer", "annotations", "docblock" ], "authors": [ { "name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com" }, { "name": "Roman Borschel", "email": "roman@code-factory.org" }, { "name": "Johannes Schmitt", "email": "schmittjoh@gmail.com" } ], "homepage": "https://www.doctrine-project.org/projects/lexer.html", "require": { "php": "^7.1 || ^8.0", "doctrine/deprecations": "^1.0" }, "require-dev": { "doctrine/coding-standard": "^9 || ^10", "phpstan/phpstan": "^1.3", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "psalm/plugin-phpunit": "^0.18.3", "vimeo/psalm": "^4.11 || ^5.0" }, "autoload": { "psr-4": { "Doctrine\\Common\\Lexer\\": "src" } }, "autoload-dev": { "psr-4": { "Doctrine\\Tests\\Common\\Lexer\\": "tests" } }, "config": { "allow-plugins": { "composer/package-versions-deprecated": true, "dealerdirect/phpcodesniffer-composer-installer": true }, "sort-packages": true } } lexer/src/Token.php 0000644 00000006361 15024770424 0010256 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Common\Lexer; use ArrayAccess; use Doctrine\Deprecations\Deprecation; use ReturnTypeWillChange; use UnitEnum; use function in_array; /** * @template T of UnitEnum|string|int * @template V of string|int * @implements ArrayAccess<string,mixed> */ final class Token implements ArrayAccess { /** * The string value of the token in the input string * * @readonly * @var V */ public $value; /** * The type of the token (identifier, numeric, string, input parameter, none) * * @readonly * @var T|null */ public $type; /** * The position of the token in the input string * * @readonly * @var int */ public $position; /** * @param V $value * @param T|null $type */ public function __construct($value, $type, int $position) { $this->value = $value; $this->type = $type; $this->position = $position; } /** @param T ...$types */ public function isA(...$types): bool { return in_array($this->type, $types, true); } /** * @deprecated Use the value, type or position property instead * {@inheritDoc} */ public function offsetExists($offset): bool { Deprecation::trigger( 'doctrine/lexer', 'https://github.com/doctrine/lexer/pull/79', 'Accessing %s properties via ArrayAccess is deprecated, use the value, type or position property instead', self::class ); return in_array($offset, ['value', 'type', 'position'], true); } /** * @deprecated Use the value, type or position property instead * {@inheritDoc} * * @param O $offset * * @return mixed * @psalm-return ( * O is 'value' * ? V * : ( * O is 'type' * ? T|null * : ( * O is 'position' * ? int * : mixed * ) * ) * ) * * @template O of array-key */ #[ReturnTypeWillChange] public function offsetGet($offset) { Deprecation::trigger( 'doctrine/lexer', 'https://github.com/doctrine/lexer/pull/79', 'Accessing %s properties via ArrayAccess is deprecated, use the value, type or position property instead', self::class ); return $this->$offset; } /** * @deprecated no replacement planned * {@inheritDoc} */ public function offsetSet($offset, $value): void { Deprecation::trigger( 'doctrine/lexer', 'https://github.com/doctrine/lexer/pull/79', 'Setting %s properties via ArrayAccess is deprecated', self::class ); $this->$offset = $value; } /** * @deprecated no replacement planned * {@inheritDoc} */ public function offsetUnset($offset): void { Deprecation::trigger( 'doctrine/lexer', 'https://github.com/doctrine/lexer/pull/79', 'Setting %s properties via ArrayAccess is deprecated', self::class ); $this->$offset = null; } } lexer/src/AbstractLexer.php 0000644 00000016713 15024770424 0011743 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\Common\Lexer; use ReflectionClass; use UnitEnum; use function get_class; use function implode; use function preg_split; use function sprintf; use function substr; use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_NO_EMPTY; use const PREG_SPLIT_OFFSET_CAPTURE; /** * Base class for writing simple lexers, i.e. for creating small DSLs. * * @template T of UnitEnum|string|int * @template V of string|int */ abstract class AbstractLexer { /** * Lexer original input string. * * @var string */ private $input; /** * Array of scanned tokens. * * @var list<Token<T, V>> */ private $tokens = []; /** * Current lexer position in input string. * * @var int */ private $position = 0; /** * Current peek of current lexer position. * * @var int */ private $peek = 0; /** * The next token in the input. * * @var mixed[]|null * @psalm-var Token<T, V>|null */ public $lookahead; /** * The last matched/seen token. * * @var mixed[]|null * @psalm-var Token<T, V>|null */ public $token; /** * Composed regex for input parsing. * * @var string|null */ private $regex; /** * Sets the input data to be tokenized. * * The Lexer is immediately reset and the new input tokenized. * Any unprocessed tokens from any previous input are lost. * * @param string $input The input to be tokenized. * * @return void */ public function setInput($input) { $this->input = $input; $this->tokens = []; $this->reset(); $this->scan($input); } /** * Resets the lexer. * * @return void */ public function reset() { $this->lookahead = null; $this->token = null; $this->peek = 0; $this->position = 0; } /** * Resets the peek pointer to 0. * * @return void */ public function resetPeek() { $this->peek = 0; } /** * Resets the lexer position on the input to the given position. * * @param int $position Position to place the lexical scanner. * * @return void */ public function resetPosition($position = 0) { $this->position = $position; } /** * Retrieve the original lexer's input until a given position. * * @param int $position * * @return string */ public function getInputUntilPosition($position) { return substr($this->input, 0, $position); } /** * Checks whether a given token matches the current lookahead. * * @param T $type * * @return bool * * @psalm-assert-if-true !=null $this->lookahead */ public function isNextToken($type) { return $this->lookahead !== null && $this->lookahead->isA($type); } /** * Checks whether any of the given tokens matches the current lookahead. * * @param list<T> $types * * @return bool * * @psalm-assert-if-true !=null $this->lookahead */ public function isNextTokenAny(array $types) { return $this->lookahead !== null && $this->lookahead->isA(...$types); } /** * Moves to the next token in the input string. * * @return bool * * @psalm-assert-if-true !null $this->lookahead */ public function moveNext() { $this->peek = 0; $this->token = $this->lookahead; $this->lookahead = isset($this->tokens[$this->position]) ? $this->tokens[$this->position++] : null; return $this->lookahead !== null; } /** * Tells the lexer to skip input tokens until it sees a token with the given value. * * @param T $type The token type to skip until. * * @return void */ public function skipUntil($type) { while ($this->lookahead !== null && ! $this->lookahead->isA($type)) { $this->moveNext(); } } /** * Checks if given value is identical to the given token. * * @param string $value * @param int|string $token * * @return bool */ public function isA($value, $token) { return $this->getType($value) === $token; } /** * Moves the lookahead token forward. * * @return mixed[]|null The next token or NULL if there are no more tokens ahead. * @psalm-return Token<T, V>|null */ public function peek() { if (isset($this->tokens[$this->position + $this->peek])) { return $this->tokens[$this->position + $this->peek++]; } return null; } /** * Peeks at the next token, returns it and immediately resets the peek. * * @return mixed[]|null The next token or NULL if there are no more tokens ahead. * @psalm-return Token<T, V>|null */ public function glimpse() { $peek = $this->peek(); $this->peek = 0; return $peek; } /** * Scans the input string for tokens. * * @param string $input A query string. * * @return void */ protected function scan($input) { if (! isset($this->regex)) { $this->regex = sprintf( '/(%s)|%s/%s', implode(')|(', $this->getCatchablePatterns()), implode('|', $this->getNonCatchablePatterns()), $this->getModifiers() ); } $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE; $matches = preg_split($this->regex, $input, -1, $flags); if ($matches === false) { // Work around https://bugs.php.net/78122 $matches = [[$input, 0]]; } foreach ($matches as $match) { // Must remain before 'value' assignment since it can change content $firstMatch = $match[0]; $type = $this->getType($firstMatch); $this->tokens[] = new Token( $firstMatch, $type, $match[1] ); } } /** * Gets the literal for a given token. * * @param T $token * * @return int|string */ public function getLiteral($token) { if ($token instanceof UnitEnum) { return get_class($token) . '::' . $token->name; } $className = static::class; $reflClass = new ReflectionClass($className); $constants = $reflClass->getConstants(); foreach ($constants as $name => $value) { if ($value === $token) { return $className . '::' . $name; } } return $token; } /** * Regex modifiers * * @return string */ protected function getModifiers() { return 'iu'; } /** * Lexical catchable patterns. * * @return string[] */ abstract protected function getCatchablePatterns(); /** * Lexical non-catchable patterns. * * @return string[] */ abstract protected function getNonCatchablePatterns(); /** * Retrieve token type. Also processes the token value if necessary. * * @param string $value * * @return T|null * * @param-out V $value */ abstract protected function getType(&$value); } lexer/README.md 0000644 00000000557 15024770424 0007156 0 ustar 00 # Doctrine Lexer [](https://github.com/doctrine/lexer/actions) Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers. This lexer is used in Doctrine Annotations and in Doctrine ORM (DQL). https://www.doctrine-project.org/projects/lexer.html lexer/LICENSE 0000644 00000002051 15024770424 0006673 0 ustar 00 Copyright (c) 2006-2018 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. lexer/UPGRADE.md 0000644 00000001167 15024770424 0007306 0 ustar 00 Note about upgrading: Doctrine uses static and runtime mechanisms to raise awareness about deprecated code. - Use of `@deprecated` docblock that is detected by IDEs (like PHPStorm) or Static Analysis tools (like Psalm, phpstan) - Use of our low-overhead runtime deprecation API, details: https://github.com/doctrine/deprecations/ # Upgrade to 2.0.0 `AbstractLexer::glimpse()` and `AbstractLexer::peek()` now return instances of `Doctrine\Common\Lexer\Token`, which is an array-like class Using it as an array is deprecated in favor of using properties of that class. Using `count()` on it is deprecated with no replacement.
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings