Skip to content

Commit

Permalink
The helper file is no longer autoloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 16, 2024
1 parent ac253d9 commit e542742
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 91 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
Expand All @@ -133,6 +133,12 @@ echo singularize('lærere', 'nb'); // "lærer"
echo pluralize('üçgen', 'tr'); // "üçgenler"
```

> [!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

Expand Down
93 changes: 50 additions & 43 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
11 changes: 1 addition & 10 deletions lib/Inflections.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use InvalidArgumentException;
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 1 addition & 3 deletions lib/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 12 additions & 23 deletions lib/helpers.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* 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
{
Expand Down Expand Up @@ -61,55 +47,58 @@ 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);
}

/**
* 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);
}

/**
* 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);
}

/**
* 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);
}

/**
* 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);
}

/**
* 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);
}
12 changes: 1 addition & 11 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* 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';

0 comments on commit e542742

Please sign in to comment.