Giter VIP home page Giter VIP logo

Comments (7)

samdark avatar samdark commented on August 18, 2024 3

Here you go: yiisoft/demo@af88e0b

from di.

samdark avatar samdark commented on August 18, 2024 2

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.

samdark avatar samdark commented on August 18, 2024

That would result in using it as service locator and that is exactly what we've tried to avoid.

from di.

terabytesoftw avatar terabytesoftw commented on August 18, 2024

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.

samdark avatar samdark commented on August 18, 2024

@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.

rustamwin avatar rustamwin commented on August 18, 2024

@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.

rustamwin avatar rustamwin commented on August 18, 2024

Is this a temporary solution?

from di.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.