Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] deprecate most characters in service ids #18028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Mar 6, 2016

Q A
Branch master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #17801
License MIT
Doc PR TODO

@@ -601,6 +601,10 @@ public function setAliases(array $aliases)
*/
public function setAlias($alias, $id)
{
if (preg_match('/[^a-z0-9\._]/i', $alias)) {
trigger_error(sprintf('Using characters other than A-Z, 0-9, ., and _ in service ids ("%s" given) is deprecated since Symfony 3.1 and will throw an exception in 4.0.', $alias), E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be silenced

@xabbuh
Copy link
Member Author

xabbuh commented Mar 7, 2016

Comments addressed, tests fixed.

Status: Needs Review

@@ -163,6 +163,10 @@ public function setParameter($name, $value)
*/
public function set($id, $service)
{
if (preg_match('/[^a-z0-9\._%]/i', $id)) {
@trigger_error(sprintf('Using characters other than A-Z, 0-9, ., and _ in service ids ("%s" given) is deprecated since Symfony 3.1 and will throw an exception in 4.0.', $id), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of:

... and will throw an exception in 4.0.

We use this other wording in most deprecation notices:

... and will be removed in 4.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that sounds really weird in this context (for example, in the Yaml component we used "will throw a ParseException" too).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. It makes sense. Thanks.

@javiereguiluz
Copy link
Member

👍

Status: Reviewed

@nicolas-grekas
Copy link
Member

should we allow non western users to use utf8 to name their services? I'm sure some do and I don't see anything wrong. wdyt?

@xabbuh
Copy link
Member Author

xabbuh commented Mar 10, 2016

Can we make sure that non of them will cause trouble in the future?

@GuilhemN
Copy link
Contributor

What do you think about allowing / and \?
I already faced cases where it is useful to have different separator for clarity. (in case you have a lazy wrapper for a service you may want to name it @lazy/vendor.service_id)

@javiereguiluz
Copy link
Member

@xabbuh given the comments made by some reviewers (support non-English UTF8 chars, support slashes and backslashes, etc.) what do you think about switching to a blacklist filter instead of the current whitelist filter? Let's ban some concrete chars (@, dashes, ASCII control chars, etc.) and let's allow everything else.

@xabbuh
Copy link
Member Author

xabbuh commented Mar 14, 2016

@javiereguiluz We could do that too. The list should then probably contain whitespace characters, control sequences, !, ?, @, quote characters, backticks, dashes. Anything else of importance?

@javiereguiluz
Copy link
Member

@xabbuh I can't think of anything else. Your list looks comprehensive. Thanks!

@xabbuh xabbuh force-pushed the deprecate-special-chars-service-ids branch 2 times, most recently from 1e1f353 to 097ae80 Compare March 14, 2016 18:09
@xabbuh
Copy link
Member Author

xabbuh commented Mar 14, 2016

changed the PR to use a blacklist instead of a whitelist

@stof
Copy link
Member

stof commented Mar 14, 2016

the whitelist should be built in a way where the generated method names for the dumping of the container generates a valid name (which means adding more stuff to the allowed whitelist).
Building a real blacklist may be much harder, as we have a whitelist for PHP method names

@GuilhemN
Copy link
Contributor

@stof isn't it possible to convert the services' id to another base to have only supported characters (maybe using base_convert and ord) ?

Edit: at worst, if we really want to keep descriptive name as much as possible, we could solve the actual limitation of the dumper by having a counter which would be incremented each time a new unsupported service id is camelized.

@GuilhemN
Copy link
Contributor

Can you take a look at #18167 please?
This should fix the initial issue with the PhpDumper and allow you to use a black list.

@fabpot
Copy link
Member

fabpot commented Apr 1, 2016

#18167 has been merged now

@xabbuh xabbuh force-pushed the deprecate-special-chars-service-ids branch from 8bbb655 to d06bb91 Compare April 6, 2016 18:44
@xabbuh
Copy link
Member Author

xabbuh commented Apr 6, 2016

rebased here

ping @symfony/deciders

@GuilhemN
Copy link
Contributor

GuilhemN commented Apr 6, 2016

What about deprecating an empty string as service id at the same time ? (see #18265 (comment))

@@ -31,13 +31,14 @@ public function testProcess($public)
$definition = new Definition('%my-command.class%');
$definition->setPublic($public);
$definition->addTag('console.command');
$container->setDefinition('my-command', $definition);
$container->setDefinition('app.command', $definition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why we need to reject -? Could we allow it?

@stof
Copy link
Member

stof commented Apr 8, 2016

Do we actually still need this ?

@fabpot
Copy link
Member

fabpot commented Apr 28, 2016

Indeed, let's close this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants