Cascade\Config\Loader\ClassLoader\LoggerLoader::resolveProcessors PHP Метод

resolveProcessors() публичный Метод

Resolve processors for that Logger (if any provided) against an array of previously set up processors.
public resolveProcessors ( array $loggerOptions, callable[] $processors ) : callable[]
$loggerOptions array Array of logger options
$processors callable[] Available Processors to resolve against
Результат callable[] Array of Monolog processors
    public function resolveProcessors(array $loggerOptions, $processors)
    {
        $processorArray = array();
        if (isset($loggerOptions['processors'])) {
            // If processors have been specified and, they do exist in the provided processors array
            // We return an array of processor objects
            foreach ($loggerOptions['processors'] as $processorId) {
                if (isset($processors[$processorId])) {
                    $processorArray[] = $processors[$processorId];
                } else {
                    throw new \InvalidArgumentException(sprintf('Cannot add processor "%s" to the logger "%s". Processor not found.', $processorId, $this->logger->getName()));
                }
            }
        }
        // If nothing is set there is nothing to resolve, Processors will be Monolog's default
        return $processorArray;
    }

Usage Example

 /**
  * @expectedException InvalidArgumentException
  */
 public function testResolveProcessorsWithMismatch()
 {
     $dummyClosure = function () {
         // Empty function
     };
     $options = array('processors' => array('unexisting_processor', 'test_processor_2'));
     $processors = array('test_processor_1' => $dummyClosure, 'test_processor_2' => $dummyClosure);
     $loader = new LoggerLoader('testLogger', $options, array(), $processors);
     // This should throw an InvalidArgumentException
     $loader->resolveProcessors($options, $processors);
 }