Skip to content

Rewrite static access to Inflector as it has been deprecated#3560

Closed
jnugh wants to merge 1 commit into
api-platform:masterfrom
jnugh:inflector-deprecation
Closed

Rewrite static access to Inflector as it has been deprecated#3560
jnugh wants to merge 1 commit into
api-platform:masterfrom
jnugh:inflector-deprecation

Conversation

@jnugh

@jnugh jnugh commented May 15, 2020

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? no
BC breaks? doctrine/inflector raised to ^1.4 || ^2.0
Deprecations? no
Tickets fixes #2626
License MIT
Doc PR none

doctrine/inflector deprecated the use of Doctrine\Common\Inflector\Inflector when they released version 2.0 (where the class has been removed).
They suggest to use a factory pattern like this: https://github.com/doctrine/inflector/blob/master/docs/en/index.rst#usage

@jnugh jnugh changed the title Rewrite static access to Inflector as it has been deprecated. Rewrite static access to Inflector as it has been deprecated May 15, 2020
@jnugh
jnugh force-pushed the inflector-deprecation branch from 3fd10ff to 4d8bda6 Compare May 15, 2020 13:22
@alanpoulain

alanpoulain commented May 15, 2020

Copy link
Copy Markdown
Member

Thank you for your PR.
However we still maintain PHP 7.1 for API Platform and Doctrine Inflector 1.4 doesn't allow it.
There are two choices:

  • not supporting PHP 7.1 anymore (@api-platform/core-team)
  • not bumping to 1.4 but handling both API (legacy + new)

@jnugh

jnugh commented May 15, 2020

Copy link
Copy Markdown
Contributor Author

not bumping to 1.4 but handling both API (legacy + new)

I could do that by detecting if Doctrine\Inflector\InflectorFactory exists and build an abstraction for this, if 7.1 wouldn't be an option.

@derrabus

derrabus commented May 16, 2020

Copy link
Copy Markdown
Contributor

This PR recreates the inflector everytime it's used while the library's own compat layer maintains an instance for subsequent calls. I haven't measured how expensive the new factory logic actually is but I don't think we should call it everytime we want to inflect something.

I had to fix this issue for one of my projects as well, so I c&p'ed my solution to #3564. Here I'm using a static facade to switch between old and new implementation.

@jnugh

jnugh commented May 17, 2020

Copy link
Copy Markdown
Contributor Author

The factory has an internal cache as well, so likely very little overhead.
But as your PR could be adopted to work with both inflector versions more easily I'll close my PR 😄

@jnugh jnugh closed this May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doctrine\Common\Util\Inflector is deprecated

3 participants