diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b7952a..45d93ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # CHANGELOG +## 2.x to 3.0 + +### New requirements + +None + +### New features + +None + +### Backward Incompatible Changes + +The file with the helper functions is no longer included in the autoload. You +need to include the file `vendor/icanboogie/inflector/lib/helpers.php` in your +`composer.json` if you want to continue using these functions. + +### Deprecated Features + +None + +### Other Changes + +None + + + ## 1.x to 2.0 ### New requirements diff --git a/README.md b/README.md index 55bf8e1..0083713 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ $inflector->is_uncountable("weather"); // true $inflector->is_uncountable("cat"); // false ``` -Helpers makes it easy to use default locale inflections. +Helpers make it easy to use default locale inflections. ```php [!WARNING] +> Since v3.0 the file with the helper functions is no longer included in the +> autoload. +> You need to include the file `vendor/icanboogie/inflector/lib/helpers.php` +> in your `composer.json` if you want to continue using these functions. + ## About inflections diff --git a/composer.json b/composer.json index 02d3d72..db2f068 100644 --- a/composer.json +++ b/composer.json @@ -1,46 +1,53 @@ { - "name": "icanboogie/inflector", - "type": "library", - "description": "Multilingual inflector that transforms words from singular to plural, underscore to camel case, and more.", - "keywords": [ "inflect", "pluralize", "singularize", "camelize", "underscore", "hyphenate", "multilingual" ], - "homepage": "http://icanboogie.org/", - "license": "BSD-3-Clause", - "authors": [ - { - "name": "Olivier Laviale", - "email": "olivier.laviale@gmail.com", - "homepage": "http://www.weirdog.com/", - "role" : "Developer" - } - ], - "support": { - "issues": "https://github.com/ICanBoogie/Inflector/issues", - "source": "https://github.com/ICanBoogie/Inflector" - }, - "config": { - "sort-packages": true - }, - "require": { - "php": ">=7.1", - "ext-mbstring": "*" - }, - "require-dev": { - "icanboogie/common": "^2.1", - "phpstan/phpstan": "^0.12.100|^2.0", - "phpunit/phpunit": "^7.5.20|^11.4" - }, - "conflict": { - "icanboogie/common": "<2.0" - }, - "autoload": { - "psr-4": { - "ICanBoogie\\": "lib/" - }, - "files": [ "lib/helpers.php" ] - }, - "autoload-dev": { - "psr-4": { - "Tests\\ICanBoogie\\": "tests" - } + "name": "icanboogie/inflector", + "type": "library", + "description": "Multilingual inflector that transforms words from singular to plural, underscore to camel case, and more.", + "keywords": [ + "inflect", + "pluralize", + "singularize", + "camelize", + "underscore", + "hyphenate", + "multilingual" + ], + "homepage": "https://icanboogie.org/", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Olivier Laviale", + "email": "olivier.laviale@gmail.com", + "homepage": "https://olvlvl.com/", + "role": "Developer" } + ], + "support": { + "issues": "https://github.com/ICanBoogie/Inflector/issues", + "source": "https://github.com/ICanBoogie/Inflector" + }, + "config": { + "sort-packages": true + }, + "require": { + "php": ">=7.1", + "ext-mbstring": "*" + }, + "require-dev": { + "icanboogie/common": "^2.1", + "phpstan/phpstan": "^1.4|^2.0", + "phpunit/phpunit": "^7.5.20|^11.4" + }, + "conflict": { + "icanboogie/common": "<2.0" + }, + "autoload": { + "psr-4": { + "ICanBoogie\\": "lib/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\ICanBoogie\\": "tests" + } + } } diff --git a/lib/Inflections.php b/lib/Inflections.php index bb78f8a..2c15adc 100644 --- a/lib/Inflections.php +++ b/lib/Inflections.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use InvalidArgumentException; @@ -38,7 +29,7 @@ final class Inflections * Note: Inflections are shared for the same locale. If you need to alter an instance you * MUST clone it first, otherwise your changes will affect others. */ - public static function get(string $locale = INFLECTOR_DEFAULT_LOCALE): Inflections + public static function get(string $locale = Inflector::DEFAULT_LOCALE): Inflections { if (isset(self::$inflections[$locale])) { return self::$inflections[$locale]; diff --git a/lib/Inflector.php b/lib/Inflector.php index 386c26e..e3b963e 100644 --- a/lib/Inflector.php +++ b/lib/Inflector.php @@ -28,10 +28,8 @@ class Inflector { /** * Default inflector locale. - * - * Alias to {@see INFLECTOR_DEFAULT_LOCALE}. */ - public const DEFAULT_LOCALE = INFLECTOR_DEFAULT_LOCALE; + public const DEFAULT_LOCALE = 'en'; /** * {@see camelize()} option to downcase the first letter. diff --git a/lib/helpers.php b/lib/helpers.php index be624f9..aca95b0 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -1,25 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; -/** - * Default inflector locale. - */ -const INFLECTOR_DEFAULT_LOCALE = 'en'; - // Avoid conflicts with ICanBoogie/Common if (!function_exists(__NAMESPACE__ . '\downcase')) { /** - * Returns an lowercase string. + * Returns a lowercase string. */ function downcase(string $str): string { @@ -61,7 +47,7 @@ function capitalize(string $str, bool $preserve_str_end = false): string /** * Forwards calls to `Inflector::get()->pluralize()`. */ -function pluralize(string $word, string $locale = INFLECTOR_DEFAULT_LOCALE): string +function pluralize(string $word, string $locale = Inflector::DEFAULT_LOCALE): string { return Inflector::get($locale)->pluralize($word); } @@ -69,7 +55,7 @@ function pluralize(string $word, string $locale = INFLECTOR_DEFAULT_LOCALE): str /** * Forwards calls to `Inflector::get()->singularize()`. */ -function singularize(string $word, string $locale = INFLECTOR_DEFAULT_LOCALE): string +function singularize(string $word, string $locale = Inflector::DEFAULT_LOCALE): string { return Inflector::get($locale)->singularize($word); } @@ -77,15 +63,18 @@ function singularize(string $word, string $locale = INFLECTOR_DEFAULT_LOCALE): s /** * Forwards calls to `Inflector::get()->camelize()`. */ -function camelize(string $str, bool $uppercase_first_letter = false, string $locale = INFLECTOR_DEFAULT_LOCALE): string -{ +function camelize( + string $str, + bool $uppercase_first_letter = false, + string $locale = Inflector::DEFAULT_LOCALE +): string { return Inflector::get($locale)->camelize($str, $uppercase_first_letter); } /** * Forwards calls to `Inflector::get()->underscore()`. */ -function underscore(string $camel_cased_word, string $locale = INFLECTOR_DEFAULT_LOCALE): string +function underscore(string $camel_cased_word, string $locale = Inflector::DEFAULT_LOCALE): string { return Inflector::get($locale)->underscore($camel_cased_word); } @@ -93,7 +82,7 @@ function underscore(string $camel_cased_word, string $locale = INFLECTOR_DEFAULT /** * Forwards calls to `Inflector::get()->hyphenate()`. */ -function hyphenate(string $str, string $locale = INFLECTOR_DEFAULT_LOCALE): string +function hyphenate(string $str, string $locale = Inflector::DEFAULT_LOCALE): string { return Inflector::get($locale)->hyphenate($str); } @@ -101,7 +90,7 @@ function hyphenate(string $str, string $locale = INFLECTOR_DEFAULT_LOCALE): stri /** * Forwards calls to `Inflector::get()->humanize()`. */ -function humanize(string $lower_case_and_underscored_word, string $locale = INFLECTOR_DEFAULT_LOCALE): string +function humanize(string $lower_case_and_underscored_word, string $locale = Inflector::DEFAULT_LOCALE): string { return Inflector::get($locale)->humanize($lower_case_and_underscored_word); } @@ -109,7 +98,7 @@ function humanize(string $lower_case_and_underscored_word, string $locale = INFL /** * Forwards calls to `Inflector::get()->titleize()`. */ -function titleize(string $str, string $locale = INFLECTOR_DEFAULT_LOCALE): string +function titleize(string $str, string $locale = Inflector::DEFAULT_LOCALE): string { return Inflector::get($locale)->titleize($str); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 523d28e..86b8736 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,14 +1,4 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - require __DIR__ . '/../vendor/autoload.php'; - -mb_internal_encoding('UTF-8'); +require __DIR__ . '/../lib/helpers.php';