/**
  * @param ServiceLocatorInterface|ContainerInterface $container
  * @param MonologOptions $options
  * @param string|array $handler
  * @throws \RuntimeException
  * @return HandlerInterface
  *
  */
 public function createHandler($container, MonologOptions $options, $handler)
 {
     if (is_string($handler) && $container->has($handler)) {
         return $container->get($handler);
     } else {
         if (!isset($handler['name'])) {
             throw new RuntimeException('Cannot create logger handler');
         }
         if (!class_exists($handler['name'])) {
             throw new RuntimeException('Cannot create logger handler (' . $handler['name'] . ')');
         }
         if (isset($handler['args'])) {
             if (!is_array($handler['args'])) {
                 throw new RuntimeException('Arguments of handler(' . $handler['name'] . ') must be array');
             }
             $reflection = new \ReflectionClass($handler['name']);
             if (isset($handler['args']['handler'])) {
                 foreach ($options->getHandlers() as $key => $option) {
                     if ($handler['args']['handler'] == $key) {
                         $handler['args']['handler'] = $this->createHandler($container, $options, $option);
                         break;
                     }
                 }
             }
             $parameters = array();
             $handlerOptions = $handler['args'];
             $requiredArgsCount = $reflection->getConstructor()->getNumberOfRequiredParameters();
             if ($requiredArgsCount > sizeof($handlerOptions)) {
                 throw new RuntimeException(sprintf('Handler(%s) requires at least %d params. Only %d passed.', $handler['name'], $requiredArgsCount, sizeof($handlerOptions)));
             }
             foreach ($reflection->getConstructor()->getParameters() as $parameter) {
                 if (!$parameter->isOptional() && !isset($handlerOptions[$parameter->getName()])) {
                     $argumentValue = array_shift($handlerOptions);
                 } elseif (isset($handlerOptions[$parameter->getName()])) {
                     $argumentValue = $handlerOptions[$parameter->getName()];
                     unset($handlerOptions[$parameter->getName()]);
                 } else {
                     $argumentValue = $parameter->getDefaultValue();
                 }
                 $parameters[$parameter->getPosition()] = $argumentValue;
             }
             $instance = $reflection->newInstanceArgs($parameters);
         } else {
             $class = $handler['name'];
             $instance = new $class();
         }
         if (isset($handler['formatter'])) {
             $formatter = $this->createFormatter($container, $handler['formatter']);
             $instance->setFormatter($formatter);
         }
         return $instance;
     }
 }
 public function testSetHandlers()
 {
     $this->sut->setHandlers(array($expected = 'MyHandlerService'));
     self::assertInternalType('array', $this->sut->getHandlers());
     self::assertContains($expected, $this->sut->getHandlers());
 }