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.
Проект распространяется под лицензией Mozilla Public License 2.0 (MPL-2.0). Это означает:
- Вы можете свободно использовать, изменять и распространять код.
- При изменении файлов, содержащих исходный код из этого репозитория, вы обязаны оставить их открытыми под той же лицензией.
- Вы обязаны сохранять уведомления об авторстве и ссылку на оригинал.
- Вы можете встраивать код в проприетарные проекты, если исходные файлы остаются под MPL.