setSingleton() public method

This method is similar to Container::set except that classes registered via this method will only have one instance. Each time Container::get is called, the same instance of the specified class will be returned.
See also: set()
public setSingleton ( string $class, mixed $definition = [], array $params = [] )
$class string class name, interface name or alias name
$definition mixed the definition associated with `$class`. See [[set()]] for more details.
$params array the list of constructor parameters. The parameters will be passed to the class constructor when [[get()]] is called.
Ejemplo n.º 1
0
 /**
  * @return Container
  */
 private static function getIoc()
 {
     $diConfig = (include 'di.php');
     $container = new Container();
     $container->setSingleton('workerMapper', $diConfig['workerMapper']);
     $container->setSingleton('entityfx\\utils\\workers\\contracts\\repositories\\WorkerRepositoryInterface', function ($container, $params, $config) use($diConfig) {
         return $container->get($diConfig['workerRepository'], [$container->get('workerMapper')]);
     });
     $container->set('entityfx\\utils\\workers\\contracts\\WorkerInterceptorInterface', function ($container, $params, $config) use($diConfig) {
         return $container->get($diConfig['workerInterceptor'], [$params['worker'], $container->get('entityfx\\utils\\workers\\contracts\\repositories\\WorkerRepositoryInterface')]);
     });
     return $container;
 }
Ejemplo n.º 2
0
 public function init()
 {
     $diConfig = (include 'di.php');
     $container = new Container();
     $container->setSingleton('ObjectHistoryMapper', $diConfig['mapper']);
     $container->setSingleton('entityfx\\utils\\objectHistory\\contracts\\repositories\\ObjectHistoryRepositoryInterface', function ($container, $params, $config) use($diConfig) {
         return $container->get($diConfig['repository'], [$container->get('ObjectHistoryMapper')]);
     });
     $container->set('entityfx\\utils\\objectHistory\\contracts\\ObjectHistoryManagerInterface', function ($container, $params, $config) use($diConfig) {
         return $container->get($diConfig['manager'], [$container->get('entityfx\\utils\\objectHistory\\contracts\\repositories\\ObjectHistoryRepositoryInterface')]);
     });
     $this->initEventHandlers($container);
     parent::init();
 }
Ejemplo n.º 3
0
 /**
  * @return Container
  */
 private static function getIoc()
 {
     //$diConfig = include('di.php');
     $diConfig = [];
     $container = new Container();
     $container->setSingleton('clientProxyMapper', 'app\\utils\\webService\\implementation\\clientProxies\\mapper\\ClientProxyMapper');
     $container->setSingleton('app\\utils\\webService\\contracts\\clientProxies\\repositories\\WebClientProxyRepositoryInterface', function ($container, $params, $config) use($diConfig) {
         return $container->get('app\\utils\\webService\\implementation\\clientProxies\\repositories\\WebClientProxyRepository', [$container->get('clientProxyMapper')]);
     });
     /*$container->set('app\utils\workers\contracts\WorkerInterceptorInterface',
       function($container, $params, $config) use ($diConfig) {
           return  $container->get(
               $diConfig['workerInterceptor'],
               [$params['worker'], $container->get('app\utils\workers\contracts\repositories\WorkerRepositoryInterface')]
           );
       });*/
     return $container;
 }