예제 #1
0
 /**
  * Get service from DI container
  *
  * @param $name
  * @return mixed
  * @throws \OutOfBoundsException
  */
 public function get($name)
 {
     if (!$this->container->offsetExists($name)) {
         throw new OutOfBoundsException('Service - "' . $name . '" doesn\'t esist.');
     }
     return $this->container[$name];
 }
 /**
  * @param \Exception $e
  */
 public function handle(\Exception $e)
 {
     $code = $e->getCode();
     // if there is no handler for this do nothing
     if (!$this->_handlers->offsetExists($code)) {
         return;
     }
     return $this->_handlers[$code]($e);
 }
 public function it_normalizes_expressions($parser, \Pimple $container)
 {
     $container->offsetExists('_normalize')->willReturn(true);
     $container->offsetGet('_normalize')->willReturn(array('foo' => 'bar'));
     $parser->evaluate('foo', array('foo' => 'bar'))->willReturn('bar')->shouldBeCalled();
     $this->normalize('?foo', $container)->shouldReturn('bar');
 }
예제 #4
0
 public function it_creates_a_array_parameter_and_merges_existing_data(Parameter $parameterConf, \Pimple $container)
 {
     $parameterConf->getParameterName()->willReturn('db.options');
     $parameterConf->getParameterValue()->willReturn(array('host' => 'example.org'));
     $parameterConf->getMergeStrategy(Argument::type('array'))->willReturn('array_replace_recursive');
     $parameterConf->mergeExisting()->willReturn(true);
     $container->offsetExists('db.options')->willReturn(true);
     $container->offsetGet('db.options')->willReturn(array('host' => 'localhost', 'user' => 'root', 'password' => 'test'));
     $container->offsetSet('db.options', array('host' => 'example.org', 'user' => 'root', 'password' => 'test'))->shouldBeCalled();
     $container = $this->create($parameterConf, $container);
 }
예제 #5
0
 /**
  * Checks if a parameter or an object is set.
  *
  * @param string $id The unique identifier for the parameter or object
  *
  * @return Boolean
  */
 public function offsetExists($id)
 {
     if (!$this->fallbackContainer || $this->mode == self::MODE_STANDARD_COMPLIANT) {
         return parent::offsetExists($id);
     } elseif ($this->mode == self::MODE_ACT_AS_MASTER) {
         if ($this->nbLoops != 0) {
             return parent::offsetExists($id);
         } else {
             $this->nbLoops++;
             $has = $this->fallbackContainer->has($id);
             $this->nbLoops--;
             return $has;
         }
     } else {
         throw new \Exception("Invalid mode set");
     }
 }
예제 #6
0
 /**
  * @param \Pimple $app
  *
  * @throws \Doctrine\DBAL\DBALException
  *
  * @api
  *
  * @quality:method [B]
  */
 public function setup(\Pimple $app)
 {
     if (!$app->offsetExists('config') || !isset($app->offsetGet('config')['doctrine'])) {
         return;
     }
     $config = $app->offsetGet('config');
     ConfigResolver::resolve((array) $config['doctrine:dbal']);
     $app['connections'] = $app::share(function () use($config) {
         $connections = new \Pimple();
         foreach ((array) $config['doctrine:dbal:connections'] as $id => $params) {
             $connections->offsetSet($id, DriverManager::getConnection($params));
         }
         return $connections;
     });
     $app['connection'] = $app::share(function (\Pimple $app) use($config) {
         $ids = $app['connections']->keys();
         $default = $config['doctrine:dbal:default_connection'] ?: current($ids);
         return $app['connections'][$default];
     });
 }
예제 #7
0
 /**
  * @param \Pimple $app
  *
  * @throws \InvalidArgumentException
  *
  * @api
  *
  * @quality:method [B]
  */
 public function setup(\Pimple $app)
 {
     if (!$app->offsetExists('config') || !isset($app->offsetGet('config')['monolog'])) {
         return;
     }
     $config = $app->offsetGet('config');
     $app['loggers'] = $app::share(function (\Pimple $app) use($config) {
         return new LoggerLocator((array) $config['monolog'], $app['app.name']);
     });
     $app['logger'] = $app::share(function (\Pimple $app) {
         return $app['loggers']->getDefaultChannel();
     });
     $app['monolog.bridge'] = $app::share(function (\Pimple $app) {
         return function (OutputInterface $output) use($app) {
             if (class_exists('Symfony\\Bridge\\Monolog\\Handler\\ConsoleHandler') && interface_exists('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface')) {
                 $consoleHandler = new ConsoleHandler($output);
                 /** @var \Monolog\Logger $logger */
                 foreach ($app['loggers'] as $logger) {
                     $logger->pushHandler($consoleHandler);
                 }
             }
         };
     });
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function offsetExists($id)
 {
     return $this->container->offsetExists($id);
 }
예제 #9
0
 public function it_can_normalize_array_access_style(\Pimple $container)
 {
     $container->offsetExists('foo')->willReturn(true);
     $container->offsetGet('foo')->willReturn(array('bar' => 'Hello World'));
     $this->normalize('%foo..bar%', $container)->shouldBe('Hello World');
 }
예제 #10
0
 function it_delegates_has(\Pimple $pimple)
 {
     $pimple->offsetExists('foo')->shouldBeCalled();
     $this->has('foo');
 }
예제 #11
0
 /**
  * Returns true if the service id is defined.
  *
  * @param string $id The service id
  *
  * @return Boolean true if the service id is defined, false otherwise
  */
 public static function has($id)
 {
     return self::$pimple->offsetExists($id);
 }
 /**
  * @param Pimple $pimple
  */
 function let($pimple)
 {
     $pimple->offsetExists(Argument::any())->willReturn(true);
     $this->beConstructedWith($pimple);
 }
예제 #13
0
 public function has($id)
 {
     return parent::offsetExists($id);
 }
예제 #14
0
 /**
  * Returns true if the given service is defined.
  *
  * @param string $id The service identifier
  *
  * @return Boolean true if the service is defined, false otherwise
  *
  * @api
  */
 public function has($id)
 {
     return $this->pimple->offsetExists($id);
 }
 public function offsetExists($id)
 {
     $this->assertSetUpHasBeenCalled();
     return parent::offsetExists($id);
 }