Example #1
0
 /**
  * Initializes config processors.
  *
  * @throws InvalidConfigException
  *
  * @return void
  */
 protected function initializeConfigProcessors()
 {
     if ($this->_configProcessorsByComponent === null) {
         $this->_configProcessorsByComponent = [];
         $this->_configProcessorsByPriority = [];
         $processorsOrderedByPriority = [];
         $componentsNames = $this->getInstalledComponentsNames();
         foreach ($componentsNames as $componentName) {
             if (!$this->hasComponentConfigParam($componentName, 'components.ironedge/kernel.config.processor.class')) {
                 continue;
             }
             $processorClass = $this->getComponentConfigParam($componentName, 'components.ironedge/kernel.config.processor.class');
             if (!is_string($processorClass)) {
                 throw InvalidConfigException::create('Error in configuration of component "' . $componentName . '": ' . 'Configuration "components.ironedge/kernel.config.processor.class" must be a string. Received: ' . print_r($processorClass, true));
             }
             $processor = new $processorClass();
             if (!$processor instanceof ProcessorInterface) {
                 throw InvalidConfigException::create('Error in configuration of component "' . $componentName . '": ' . 'Configuration "components.ironedge/kernel.config.processor.class" must be a class of instance ' . '"IronEdge\\Component\\Kernel\\Config\\ProcessorInterface".');
             }
             $processorPriority = (int) $this->getComponentConfigParam($componentName, 'components.ironedge/kernel.config.processor.priority', 0);
             if (!isset($processorsOrderedByPriority[$processorPriority])) {
                 $processorsOrderedByPriority[$processorPriority] = [];
             }
             $processorsOrderedByPriority[$processorPriority][] = $processor;
             $this->_configProcessorsByComponent[$componentName] = $processor;
         }
         // Order by priority. The greater the number, the higher is the priority.
         krsort($processorsOrderedByPriority, SORT_NUMERIC);
         foreach ($processorsOrderedByPriority as $priority => $processors) {
             $this->_configProcessorsByPriority = array_merge($this->_configProcessorsByPriority, $processors);
         }
     }
 }
Example #2
0
 /**
  * Registers logger formatter.
  *
  * @param string $sourceComponentName - Component who wants to register the formatters.
  * @param array  $formatters          - Formatters.
  *
  * @throws InvalidConfigException
  * @throws \IronEdge\Component\Logger\Exception\InvalidConfigException
  *
  * @return void
  */
 protected function registerLoggerFormatters($sourceComponentName, $formatters)
 {
     if (!is_array($formatters)) {
         throw InvalidConfigException::create('Parameter "logger.formatters" must be an array.');
     }
     foreach ($formatters as $formatterId => $formatterConfig) {
         if (!is_array($formatterConfig)) {
             throw InvalidConfigException::create('Parameter "logger.formatters.' . $formatterId . '" must be an array.');
         }
         if (isset($this->_loggerFormattersComponentById[$formatterId])) {
             throw InvalidConfigException::create('Component "' . $sourceComponentName . '" wants to register a logger formatter "' . $formatterId . '", but component "' . $this->_loggerFormattersComponentById[$formatterId] . '" already registered it.');
         }
         if (isset($formatterConfig['serviceId'])) {
             if (!is_string($formatterConfig['serviceId'])) {
                 throw InvalidConfigException::create('A logger formatter with ID "' . $formatterConfig . '" must have its "serviceId" parameter with a ' . 'string value.');
             }
             $this->_loggerFormattersServicesById[$formatterId] = $formatterConfig['serviceId'];
         } else {
             if (!isset($formatterConfig['type'])) {
                 throw InvalidConfigException::create('Formatter "' . $formatterId . '" must set the "type" parameter.');
             }
             $definition = new Definition();
             $definition->setFactory([new Reference('logger.factory'), 'createFormatter']);
             $definition->setArguments([$formatterId, $formatterConfig['type'], $formatterConfig]);
             $definition->setClass('\\Monolog\\Formatter\\FormatterInterface');
             $this->_loggerFormattersServicesById[$formatterId] = $definition;
         }
         $this->_loggerFormattersComponentById[$formatterId] = $sourceComponentName;
     }
 }