rudra/container

Rudra framework

v2.0.0 2018-06-05 12:17 UTC

This package is auto-updated.

Last update: 2024-11-26 10:20:21 UTC


README

Build Status Scrutinizer Code Quality Code Climate CodeFactor

Code Intelligence Status Latest Stable Version Total Downloads GitHub

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)