Giter Club home page Giter Club logo

Comments (6)

philipobenito avatar philipobenito commented on September 2, 2024

The container retrieves items based on key name, if you add a key twice, one will override the other. It is down to your application to handle your key names.

from container.

Zyles avatar Zyles commented on September 2, 2024

Well, is it possible to get a list of registered key names then so I can throw an exception?

from container.

philipobenito avatar philipobenito commented on September 2, 2024

No that's not something you can do, keys are stored in several different ways and are also skewed if any delegate containers are enabled so it's impossible to give an accurate representation.

The container is aimed at storing and wiring together objects and services, it doesn't sound like this is what you're using it for?

from container.

Zyles avatar Zyles commented on September 2, 2024

I believe I am.

My architecture looks like this:

The main bot is running very bare bones with a DI and some basic functionality, and there are modules to extend the bot. Think composer packages.

When you install a module you register the ServiceProvider with the main $bot object. This serviceprovider can typically host a number of different classes such as commands or services.

Then you will be able to access the modules through $bot->mymodule->command()

But what if two packages happen to register two keys with the same names? Then it will break.

I guess I can create a function to look at the DI object or something before running addServiceProvider()

from container.

philipobenito avatar philipobenito commented on September 2, 2024

You can run the has method to check a specific key, you just can't get a full list.

from container.

Zyles avatar Zyles commented on September 2, 2024

I had to drop the whole key idea, couldn't get a good design going. Since I ran into catch 22 because I could not get the key names.

Is there at least a function that can check if a serviceprovider is already registered?

Couldn't find any. And I can not access $this->bot->providers->registered since it is protected...

Or maybe I can just register the same provider multiple times, since it seems it does it for every class. Maybe it doesn't matter.

from container.

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.