Giter VIP home page Giter VIP logo

inflector's Introduction

Doctrine Inflector

Doctrine Inflector is a small library that can perform string manipulations with regard to uppercase/lowercase and singular/plural forms of words.

Build Status Code Coverage

inflector's People

Contributors

alcaeus avatar beberlei avatar carusogabriel avatar danjfletcher avatar dependabot[bot] avatar derrabus avatar grahamcampbell avatar greg0ire avatar guilhermeblanco avatar jasny avatar jbergler avatar judaschwartz avatar jwage avatar lcobucci avatar majkl578 avatar malarzm avatar mathieutu avatar naurojunior avatar nschoellhorn avatar ntzm avatar ocramius avatar powellblyth avatar rdohms avatar seanbright avatar senseexception avatar slamdunk avatar stof avatar sunspikes avatar theojlab avatar tiger-seo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inflector's Issues

Singularizing 'skus' should return 'sku'

Currently Doctrine\Common\Inflector\Inflector::singularize('skus'); will return skus when it should actually return sku.

This was noticed while trying to create a resource controller that uses route-model binding in Laravel. The route:

Route::resource('skus', 'SkusController');

will generate URI's that use {skus} instead of {sku} as a route parameter, but the auto-generated type-hinted controller methods, created via php artisan make:controller SkusController --resource --model=Sku, will have a $sku variable. This results in route-model binding not working.

I believe the cause is that this library is not correctly singularizing skus to sku.

Pluralization of word `research`

During the update from 1.3.1 to 1.4.3 pluralization of word research to researches was ruined. Now it's research for both conditions

Error unexpected 'const'

Please, help me:

ERROR: Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) at vendor/doctrine/inflector/lib/Doctrine/Inflector/Language.php:9)

How can i fix this?

My php -v:

PHP 7.3.21-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Aug  7 2020 14:44:10) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.21, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.21-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

My composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "automattic/woocommerce": "^1.3",
        "canducci/cep": "^3.1",
        "cpliakas/magento-client-php": "^0.1.1",
        "dsc/mercado-livre": "^1.6",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "^5.4.0",
        "monolog/monolog": "^1.24",
        "nesbot/carbon": "1.29.*",
        "pixelpeter/laravel5-woocommerce-api-client": "^3.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~6.0",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

Thanks

Pluralisation of words that are both countable and uncountable

A few words in the English language can both be countable and uncountable at the same time. Amongst these, we have:

  • homework
  • research
  • weather
  • travel

and potentially more. In Inflector 1.3, many of these words were pluralised, even though the common plural for the words is the word itself. In Inflector 1.4, this was rectified, as we want to make the library more grammatically correct. As such, we will not be fixing these inflections.

If you need to pluralise such words differently, you can use custom rules. Please follow the instructions below depending on the Inflector API you are using. Note that due to a bug these custom rules will only work reliably in 1.4.3 and 2.0.3 and newer.

Legacy API (Inflector <= 1.4)

In the legacy API, use Inflector::rules to add a custom rule:

Inflector::rules('plural', ['/travel/i' => 'travels']);

New API (Inflector >= 1.4)

In the new API, custom rules must be added to the factory before creating the inflector:

$customPluralizations = new Ruleset(
    new Transformations(new Transformation(new Pattern('travel'), 'travels')),
    new Patterns(),
    new Substitutions()
);

$factory = InflectorFactory::create();
$factory->withPluralRules($customPluralizations);
$inflector = $factory->build();

Fresh tag

There have been several additions to the list of words that should not be inflected. Can we get a fresh tag so that these updates are available on a stable release? Thanks.

Minor version breaks backwards compatibility

From the Semver spec:

Given a version number MAJOR.MINOR.PATCH, increment the:

1. MAJOR version when you make incompatible API changes,
2. MINOR version when you add functionality in a backwards-compatible manner, and
3. PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

The change from PHP requirements of >=5.3.2 to ^7.0 is in breach of this spec.

Can I suggest a point release version which fixes this minimum requirement? Or that the software be repaired on all 1.x tags, and have a MAJOR release update for the PHP requirement.

The reasoning is this breaks automatic deployments on legacy systems.

Pluralize Error

Str::pluralStudly('Travel') return "travel" and not "travels"

pluralizing foot becoming teet.

I have checked the rules and its okay. But why its returning I can't understand. Can someone explain or give me a solution?

Weird string replacement on Laravel

Hello there devs, today i found out an annoying problem with routing:

Route::resource('dentista', DentistaController::class);

please note the 'ta' at the end of the word

doing a php artisan route:list i get:

GET|HEAD | dentista | dentista.index | App\Http\Controllers\DentistaController@index | web
POST | dentista | dentista.store | App\Http\Controllers\DentistaController@store | web
GET|HEAD | dentista/create | dentista.create | App\Http\Controllers\DentistaController@create | web
GET|HEAD | dentista/{dentistum} | dentista.show | App\Http\Controllers\DentistaController@show | web
PUT|PATCH | dentista/{dentistum} | dentista.update | App\Http\Controllers\DentistaController@update | web
DELETE | dentista/{dentistum} | dentista.destroy | App\Http\Controllers\DentistaController@destroy | web
GET|HEAD | dentista/{dentistum}/edit | dentista.edit | App\Http\Controllers\DentistaController@edit | web

notice the replacing of 'ta' with 'um'. That happens with any word that ends in 'ta'

Plural form of "media" word

$plural = \Doctrine\Common\Inflector\Inflector::pluralize("media");
echo $plural; // medias

I think its mistake, couse "media" could be used as singular and plural form

Singular of "abuses" should become "abuse" but not "abus" (OS dependent?)

Hi there and Happy New Year :)

on my setup

  • PHP 7.1.11
  • macOS High Sierra 10.13.1
  • doctrine/inflector v1.2.0

Inflector::singularize('abuses') returns "abus" instead of "abuse". The weird thing is that it is returning the correct singular "abuse" on our Linux (Debian Jessie) build servers. Might this be an OS issue?

I found this thread: https://superuser.com/questions/482933/bash-regex-on-osx-vs-linux-oddities.
Also, when I comment https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Common/Inflector/Inflector.php#L167 then it works fine on my Mac.

Any help appreciated, Patrick

Taxon resolution ruleset change

Hey folks ๐Ÿ‘‹

First of all, thanks for all the work you've put into all doctrine repositories.

Recently, you've published version 1.4, which fixed how taxon is pluralized, however, this fix fails a lot of Sylius builds. Even tho, proper plural form of a taxon is taxa, for the last few years, we were using taxons (and TBH no one spotted a problem with it. I guess it is due to not the common usage of this word and not too much of native speakers in our community). We are using an inflector to dynamically create routes, which blocked part of our admin panel after the update (admin/taxons became admin/taxa).

Nonetheless, we had to conflict with the newest inflector to make our builds pass. Not sure, if there is anything to fix on your side, as you in the core of the problem improved this library, but your fix broke backward compatibility at least for our project. I'm posting it here, so maybe some of you would have some recommendations for us, how to fix it on our side. Also, maybe this issue will be useful for some other folks out there.

As a ref. Sylius/Sylius#11441

social media singularized as social sedium

In Inflector.php

    private static $uninflected = array(
        '.*?media',
        ...

In InflectorTest.php / dataSampleWords() adding

    array("social media", "social media"),

Gives

'social media' should be singularized to 'social media'
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'social media'
+'social sedium'

Pluralizer problem

Laravel Version: 7.11.0

PHP Version: 7.2.24

Description:
The output of the following code is incorrect
Str::plural('Research')

Output code: Research
The output it has to give: Researches

Singularize and Pluralize of 'lens' needs support

Currently:
Doctrine\Common\Inflector\Inflector::singularize('lenses') returns lense
Doctrine\Common\Inflector\Inflector::pluralize('lens') returns lens

Doctrine\Common\Inflector\Inflector::singularize('lenses') should return lens
Doctrine\Common\Inflector\Inflector::pluralize('lens') should return lenses

Table name not found after upgrade - Plural issue

Not sure if I should report this here or in laravel/framework, but I'm pretty sure that doctrine/inflector is causing the issue so here it is.

upgrading from 1.3.1 to 1.4.2 my app fails at retrieving a table in my DB.

The table name is project_progresses which is working fine in 1.3.1 but in 1.4.2 is looking for project_progress.

The issue is also present in 2.0.2

Composer issue for legacy framework versions

  [Composer\DependencyResolver\SolverProblemsException]                                                            
    Problem 1                                                                                                      
      - The requested package doctrine/inflector could not be found in any version, there may be a typo in the pa  
  ckage name.                                                                                                      
    Problem 2                                                                                                      
      - Installation request for laravel/framework 5.0 -> satisfiable by laravel/framework[v5.0.0].                
      - laravel/framework v5.0.0 requires doctrine/inflector ~1.0 -> no matching package found.    

When doing a composer update or composer install with the composer.lock file removed the error above appears on php version 5.6.24 laravel 5.0 and composer 1.5.2. This is a huge problem for legacy software.

Meta is always 'singularized' to Metum.

Preface: I explain this a little more in laravel/framework#26657

When using the Inflector::singular method on the string 'Meta', it is singularized into 'Metum'.

According to Wiktionary, this behaviour is incorrect and Meta is actually the singular of Metas.

Could I request that a new Rule is added to catch this behaviour?

I am unsure if the word 'Meta' should be added to the English Uninflected Rule Set or handled inside the English Inflectible Rule Set - however if guidance is given I am happy to raise a PR to address.

Class 'Doctrine\Common\Inflector\Inflector' not found while testing

For testing this package I assumed the following commands would suffice:

git clone doctrine/inflector
composer install
phpunit

It does test, but all tests fail with trace:

Error: Class 'Doctrine\Common\Inflector\Inflector' not found

But I see it should be loaded with prf-4 from the libs folder according to composer.json.
Was there some step I missed? I am new to phpunit so this probably an error on my side.

The pluralization does not work with multi-word terms

Cases:

  1. License to practice dentistry should be Licenses to practice dentistry, not License to practice dentistries.
  2. Transcript of record should be Transcripts of records .
  3. Proof of payment of registration fee should be Proofs of payment of registration fees.

Documentation Depreciation Statement not Correct

The documentation for both 1.4.3 and for 2.0.3/2.1 both state:

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.

However this statement seems to have been written for the 1.x branch, and at a time at which removal was planned for a "3.0" release rather than 2.0.

Could the documentation for both releases be updated to clarify the reality of the situation, that the old API is deprecated as of 1.4.x, and is dropped in 2.0?

Composer version issue

I think maybe you should update your main version number when updating php requirement from >=5.3.2 to ^7.0.
Now there is a problem when i was installing requirements by using composer install because illuminate/support requires doctrine/inflector ~1.0, and the php version requirement is >=5.3.2 in version 1.1.0 while php: ^7.0 in version 1.2.0.
So i can not install the requirements properly.

Rule for "software"

I just noticed that ApiPlatform generates /softwares from an entity called Software. I might be wrong but imho this is an irregular one and uncountable, so plural of software should remain software. Or am I wrong here? (not native English) Haven't had the time to look into the lib in detail so just leaving this here before I forget about it instead of submitting a PR ๐Ÿ˜„

Pluralization of 'weather'

The word weather has 2 valid plurals weather|weathers depending on context.

<1.4.0 returns weathers whereas >=1.4.0 returns weather.

This BC break broke something in an app, however I have worked around it for now.

More generally a decision would need to be made on which to use in this package.

Singularization problem (receives)

Hi all,

Just found a problem when I use Laravel:

Str::singular('receives') ==> receife

And the library use 'doctrine/inflector' so sumit an issue here.

Sorry that I am not family with submit issues, please correct me if my format is not good.

Thanks

Other language inflector

It would be nice customize the inflector at specific langauge like Spanish there are several differences with this:

Example:
Singular -> Plural
Persona -> Persona(s) . ( It works with english too!)
Pais -> Pais(es)

Other langauges like Portugues, Italian, etc has different rules with singular and plural.

Incompatibility with php 7.0

Hello, this morning, when I was running the composer install command on my php server, I had the following error:

`Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for doctrine/inflector v1.3.0 -> satisfiable by doctrine/inflector[v1.3.0].
- doctrine/inflector v1.3.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
Problem 2
- Installation request for symfony/css-selector v4.0.4 -> satisfiable by symfony/css-selector[v4.0.4].
- symfony/css-selector v4.0.4 requires php ^7.1.3 -> your PHP version (7.0.25) does not satisfy that requirement.
Problem 3
- Installation request for symfony/event-dispatcher v4.0.4 -> satisfiable by symfony/event-dispatcher[v4.0.4].
- symfony/event-dispatcher v4.0.4 requires php ^7.1.3 -> your PHP version (7.0.25) does not satisfy that requirement.
Problem 4
- Installation request for doctrine/instantiator 1.1.0 -> satisfiable by doctrine/instantiator[1.1.0].
- doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
Problem 5
- doctrine/inflector v1.3.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
- laravel/framework v5.5.35 requires doctrine/inflector ~1.1 -> satisfiable by doctrine/inflector[v1.3.0].
- Installation request for laravel/framework v5.5.35 -> satisfiable by laravel/framework[v5.5.35].
`
At some point these packages worked on my php 7.0.25 and now they no longer run, just with php 7.1, how can I fix this, knowing that I only have php 7.0.25 support on my server?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.