示例#1
0
 public function setUp()
 {
     $container['encryptionKey'] = '123456';
     $container['stdObj'] = function ($c) {
         $obj = new \stdClass();
         $obj->encryptionKey = $c['encryptionKey'];
         return $obj;
     };
     $self = $this;
     $sharedContainer['sharedObj'] = function ($c) use($self) {
         $obj = new \stdClass();
         $obj->encryptionKey = $c['encryptionKey'];
         $self->sharedObjHash = spl_object_hash($obj);
         return $obj;
     };
     $this->container = new \Dispatcher\Common\DIContainer();
     foreach ($container as $k => $v) {
         $this->container[$k] = $v;
     }
     foreach ($sharedContainer as $k => $v) {
         $this->container->share($k, $v);
     }
     if ($this->container === NULL) {
         $this->fail('Unable to create DI Container');
     }
 }
 /**
  * Creates the DIContainer with the given configuration.
  * @param  array $config The dependency configuration
  * @return \Dispatcher\Common\DIContainer
  */
 protected function createContainer(array $config = array())
 {
     $container = new DIContainer();
     $containerCfg = getattr($config['container'], array());
     foreach ($containerCfg as $k => $v) {
         $container[$k] = $v;
     }
     $sharedContainerCfg = getattr($config['sharedContainer'], array());
     foreach ($sharedContainerCfg as $k => $v) {
         $container->share($k, $v);
     }
     return $container;
 }