rudra / container
Rudra framework
Installs: 1 860
Dependents: 11
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-10-26 10:12:28 UTC
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)