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

How to get a named instance from the container? #199

Open
adjenks opened this issue Mar 16, 2022 · 1 comment
Open

How to get a named instance from the container? #199

adjenks opened this issue Mar 16, 2022 · 1 comment

Comments

@adjenks
Copy link

adjenks commented Mar 16, 2022

I created a named instance like so:

$rules = [
	'$logger2' => [
		Dice::INSTANCE => function () use ($config) {
			//do stuff;
			return $thing;
		}
	]
];
$dice = $dice->addRules($rules);

And I tried to get it like so:

$logger2 = $dice->create('$logger2');

But it did not work because create() only expects class names. It throws:

PHP Fatal error: Uncaught ReflectionException: Class $logger2 does not exist in //vendor/level-2/dice/Dice.php:107

I understand I can make it a dependency of a class and then create the class, but what if I just want to access it as is?

@cseufert
Copy link

cseufert commented Oct 3, 2022

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

No branches or pull requests

2 participants