rudra / container
Rudra framework
v26.7
2026-06-23 11:52 UTC
Requires
- php: ^8.3
- psr/container: ^2.0@dev
- rudra/docs: v26.7
- rudra/exception: v26.7
README
Rudra-Container | API
Installation
composer require rudra/container
Using
use Rudra\Container\Rudra; Rudra::run();
using Facade:
use Rudra\Container\Facades\Rudra;
Setting:
Bind an interface to an implementation or pre-arranged factory:
Rudra::run()->binding([ SomeInterface::class => SomeClass::class ... SomeInterface::class => SomeFactory::class ... SomeInterface::class => 'service-name' ... SomeInterface::class => function (){ return new SomeClass(); } ... SomeInterface::class => function (){ return (new SomeFactory)->create(); } ]);
using Facade:
Rudra::binding([ SomeInterface::class => SomeClass::class ... SomeInterface::class => SomeFactory::class ... SomeInterface::class => 'service-name' ... SomeInterface::class => function (){ return new SomeClass(); } ... SomeInterface::class => function (){ return (new SomeFactory)->create(); } ]);
Installs services into a waiting container to be initialized when called:
Rudra::run()->waiting([ 'service-name' => [SomeClass::class, ['param-1', 'param-2']] ... 'service-name' => SomeFactory::class ... 'service-name' => function (){ return new SomeClass(); } ... 'service-name' => function (){ return (new SomeFactory)->create(); } } ])
using Facade:
Rudra::waiting([ 'service-name' => [SomeClass::class, ['param-1', 'param-2']] ... 'service-name' => SomeFactory::class ... 'service-name' => function (){ return new SomeClass(); } ... 'service-name' => function (){ return (new SomeFactory)->create(); } } ])
Add a bind to previously established ones:
Rudra::run()->binding()->set([SomeInterface::class => SomeClass::class])
using Facade:
Rudra::binding()->set([SomeClass::class, ['param-1', 'param-2']);
Add the service to the previously installed ones:
Rudra::run()->waiting()->set([ 'service-name' => [SomeClass::class, ['param-1', 'param-2']] ... 'service-name' => SomeFactory::class ])
using Facade:
Rudra::waiting()->set([ 'service-name' => [SomeClass::class, ['param-1', 'param-2']] ... 'service-name' => SomeFactory::class ])
Call the created service:
Rudra::run()->get('service-name')
using Facade:
Rudra::get('service-name')
If the service does not have parameters, or the parameters are in the binding, then the service will be created automatically when calling
Rudra::run()->get(Service::class)
using Facade:
Rudra::get(Service::class)
License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0) — a free, open-source license that:
- Requires preservation of copyright and license notices,
- Allows commercial and non-commercial use,
- Requires that any modifications to the original files remain open under MPL-2.0,
- Permits combining with proprietary code in larger works.
📄 Full license text: LICENSE
🌐 Official MPL-2.0 page: https://mozilla.org/MPL/2.0/