Skip to content
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

Bug with class_alias #156

Closed
enumag opened this issue Jul 6, 2017 · 4 comments
Closed

Bug with class_alias #156

enumag opened this issue Jul 6, 2017 · 4 comments

Comments

@enumag
Copy link
Contributor

@enumag enumag commented Jul 6, 2017

  • bug report? yes
  • feature request? no
  • version: 2.4.8

Description

Nette/DI seems to be incompatible with class aliases. My tests are failing with this error:

[Nette\DI\ServiceCreationException] Service 'arachne.forms.twig.extension.translation': Case mismatch on class name 'Twig\NodeVisitor\NodeVisitorInterface', correct name is 'Twig_NodeVisitorInterface'.

Obviously there is no case mismatch. It's just that Twig\NodeVisitor\NodeVisitorInterface is an alias of Twig_NodeVisitorInterface which confuses ContainerBuilder::checkCase().

Steps To Reproduce

Create a class and an alias to that class. Add it to DIC as service. Try to autowire it into another service using the alias instead of the base class. EDIT: See the test case in my PR.

@enumag

This comment has been minimized.

Copy link
Contributor Author

@enumag enumag commented Jul 6, 2017

Not sure if it's possible to fix it otherwise than ignoring it with

	private function checkCase($class)
	{
		if (class_exists($class) || interface_exists($class)) {
			$name = (new ReflectionClass($class))->getName();
			if ($class !== $name && strtolower($class) === strtolower($name)) {
				throw new ServiceCreationException("Case mismatch on class name '$class', correct name is '$name'.");
			}
		}
	}

EDIT: It seems there is no way to get the defined class alias so I guess there is no better fix.

@dg dg closed this in 2feee10 Jul 8, 2017
dg added a commit that referenced this issue Jul 8, 2017
also removes case sensitive class name checking
@enumag

This comment has been minimized.

Copy link
Contributor Author

@enumag enumag commented Jul 13, 2017

@dg Any estimate 2.4.9 with this fix could be available? This bug is blocking some of my open-source projects.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jul 14, 2017

@enumag done

@enumag

This comment has been minimized.

Copy link
Contributor Author

@enumag enumag commented Jul 14, 2017

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.