Comments (7)
Here you go: yiisoft/demo@af88e0b
from di.
No, why? I want to make accessing container globally (except maybe these functions) a hard enough task so people won't abuse it without thinking.
from di.
That would result in using it as service locator and that is exactly what we've tried to avoid.
from di.
Hi, why not use delegate with a reflection class instead of injecting the entire container.
Example:
<?php declare(strict_types=1);
$container = new League\Container\Container;
// register the reflection container as a delegate to enable auto wiring
$container->delegate(
new League\Container\ReflectionContainer
);
$foo = $container->get(Acme\Foo::class);
var_dump($foo instanceof Acme\Foo); // true
var_dump($foo->bar instanceof Acme\Bar); // true
var_dump($foo->baz instanceof Acme\Baz); // true
var_dump($foo->bar->bam instanceof Acme\Bam); // true
from di.
@rustamwin I think it's better to get container instance to where functions are declared and pass it there via use ($container)
. Is it possible?
from di.
@samdark I mean something else, global functions are declared here. I want declare new function something like this:
if (!function_exists('alert_success')) {
function alert_success($message, $remove = false) {
Container::getInstance()->get(FlashInterface)->add('success', $message, $remove)
}
}
from di.
Is this a temporary solution?
from di.
Related Issues (20)
- Suggestion of small optimization for container methods (get, has) HOT 4
- Introduce parameter bag for container configuration
- New in initializers in PHP 8.1 HOT 7
- Container doesn't resolve properties of already built instances after their state reset HOT 2
- Add Attributes to inject scalar definitions & tags HOT 1
- Change syntax for get services by tag to `#tag-name` HOT 6
- Check tag services array in `Container::setTags()` on empty HOT 4
- Improve UX adding short syntax passing string reference to methods' calls
- Incorrect parameter reference in error message
- Add ability to set classes when resolving which an exception should be thrown HOT 5
- Make `BuildingException` friendly
- Dynamic bindings HOT 2
- Proposal to Add Reference::tag Method HOT 4
- Add debug commands
- update irc link
- update src folder links
- update root folder links
- Need update documentation
- Prevent run GitHub Actions when change non-code files
- Factory call from container config HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from di.