Пример #1
0
 private function _registerIocCompilerPasses(tubepress_internal_ioc_ContainerBuilder $container, array $addons)
 {
     $count = count($addons);
     $compilerPassArray = array();
     /**
      * @var $addon tubepress_api_contrib_AddonInterface
      */
     for ($index = 1; $index <= $count; $index++) {
         $addon = $addons[$index - 1];
         $compilerPasses = $addon->getMapOfCompilerPassClassNamesToPriorities();
         if (count($compilerPasses) === 0) {
             if ($this->_shouldLog) {
                 $this->_logDebug(sprintf('(Add-on <code>%d</code> of <code>%d</code>: <code>%s</code>) Did not register any compiler passes', $index, $count, $addon->getName()));
             }
             continue;
         }
         if ($this->_shouldLog) {
             $this->_logDebug(sprintf('(Add-on <code>%d</code> of <code>%d</code>: <code>%s</code>) <code>%d</code> compiler pass(es) registered:', $index, $count, $addon->getName(), count($compilerPasses)));
             foreach ($compilerPasses as $class => $priority) {
                 $this->_logDebug(sprintf('&nbsp;&nbsp;&nbsp;<code>%s</code> at priority <code>%s</code>', $class, $priority));
             }
         }
         $compilerPassArray = array_merge($compilerPassArray, $compilerPasses);
     }
     arsort($compilerPassArray, SORT_NUMERIC);
     if ($this->_shouldLog) {
         $this->_logDebug('Final compiler pass order:');
         foreach ($compilerPassArray as $class => $priority) {
             $this->_logDebug(sprintf('&nbsp;&nbsp;&nbsp;<code>%s</code> at priority <code>%s</code>', $class, $priority));
         }
     }
     foreach (array_keys($compilerPassArray) as $compilerPass) {
         try {
             $ref = new ReflectionClass($compilerPass);
             /** @noinspection PhpParamsInspection */
             $container->addCompilerPass($ref->newInstance());
             if ($this->_shouldLog) {
                 $this->_logDebug(sprintf('Successfully loaded <code>%s</code> as a compiler pass', $compilerPass));
             }
         } catch (Exception $e) {
             if ($this->_shouldLog) {
                 $this->_logger->error(sprintf('Failed to load <code>%s</code> as a compiler pass: <code>%s</code>', $compilerPass, $e->getMessage()));
             }
         }
     }
 }