コード例 #1
0
ファイル: ContainerImpl.php プロジェクト: marcelog/ding
 /**
  * Constructor.
  *
  * @param array $options options.
  *
  * @return void
  */
 protected function __construct(array $options)
 {
     // Setup logger.
     $this->_logger = \Logger::getLogger(get_class($this));
     $this->_logDebugEnabled = $this->_logger->isDebugEnabled();
     $soullessArray = array();
     $this->_beanAliases = $soullessArray;
     $this->_beanDefs = $soullessArray;
     $this->_beans = $soullessArray;
     $this->_shutdowners = $soullessArray;
     $this->_resources = $soullessArray;
     $this->_eventListeners = $soullessArray;
     $this->_properties = $soullessArray;
     // Merge options with our defaults.
     self::$_options = array_replace_recursive(self::$_options, $options);
     $this->registerProperties(self::$_options['properties']);
     $sapi = php_sapi_name();
     if (function_exists('pcntl_signal')) {
         if ($sapi == 'cgi' || $sapi == 'cli') {
             $signals = array(SIGQUIT, SIGHUP, SIGINT, SIGCHLD, SIGTERM, SIGUSR1, SIGUSR2);
             $handler = array($this, 'signalHandler');
             foreach ($signals as $signal) {
                 pcntl_signal($signal, $handler);
             }
             pcntl_sigprocmask(SIG_UNBLOCK, $signals);
         }
     }
     set_error_handler(array($this, 'errorHandler'));
     register_shutdown_function(array($this, 'shutdownHandler'));
     $this->_lifecycleManager = new BeanLifecycleManager();
     $this->_dispatcherTemplate = new DispatcherImpl();
     $this->_aspectManager = new AspectManager();
     $this->_aspectManager->setCache(DummyCacheImpl::getInstance());
     $this->_beanDefCache = DummyCacheImpl::getInstance();
     $this->_beanCache = DummyCacheImpl::getInstance();
     $this->registerBeanDefinitionProvider(new Core(self::$_options));
     $this->_reflectionFactory = $this;
     $this->_reflectionFactory = $this->getBean('dingReflectionFactory');
     $this->_proxyFactory = $this->getBean('dingProxyFactory');
     $this->_beanDefCache = $this->getBean('dingDefinitionsCache');
     $this->_beanCache = $this->getBean('dingBeanCache');
     $this->_lifecycleManager = $this->getBean('dingLifecycleManager');
     $this->_aspectManager = $this->getBean('dingAspectManager');
     $this->_dispatcherTemplate = $this->getBean('dingAspectCallDispatcher');
     // Set drivers
     if (isset(self::$_options['bdef']['xml'])) {
         $xmlDriver = $this->getBean('dingXmlBeanDefinitionProvider');
     }
     if (isset(self::$_options['bdef']['yaml'])) {
         $yamlDriver = $this->getBean('dingYamlBeanDefinitionProvider');
     }
     $this->getBean('dingPropertiesDriver');
     $this->getBean('dingMessageSourceDriver');
     $this->getBean('dingMethodInjectionDriver');
     // All set, continue.
     if (isset(self::$_options['bdef']['annotation'])) {
         $this->getBean('dingAnnotationDiscovererDriver');
         $this->getBean('dingAnnotationBeanDefinitionProvider');
         $this->getBean('dingAnnotationValueDriver');
         $this->getBean('dingAnnotationResourceDriver');
         $this->getBean('dingAnnotationInjectDriver');
         $this->getBean('dingAnnotationInitDestroyMethodDriver');
         $this->getBean('dingAnnotationRequiredDriver');
         $this->getBean('dingMvcAnnotationDriver');
     }
     $this->_lifecycleManager->afterConfig();
 }
コード例 #2
0
ファイル: Xml.php プロジェクト: im286er/Ding
 /**
  * Returns an aspect definition.
  *
  * @param SimpleXML $simpleXmlAspect Aspect node.
  *
  * @throws BeanFactoryException
  * @return AspectDefinition
  */
 private function _loadAspect($simpleXmlAspect)
 {
     $aspects = array();
     $atts = $simpleXmlAspect->attributes();
     if (isset($atts->id)) {
         $name = (string) $atts->id;
     } else {
         $name = BeanDefinition::generateName('AspectXML');
     }
     if (isset($atts->expression)) {
         $expression = (string) $atts->expression;
     } else {
         $expression = '';
     }
     $aspectBean = (string) $atts->ref;
     $type = (string) $atts->type;
     if ($type == 'method') {
         $type = AspectDefinition::ASPECT_METHOD;
     } else {
         if ($type == 'exception') {
             $type = AspectDefinition::ASPECT_EXCEPTION;
         } else {
             throw new BeanFactoryException('Invalid aspect type');
         }
     }
     $pointcuts = array();
     foreach ($simpleXmlAspect->pointcut as $pointcut) {
         $pointcutAtts = $pointcut->attributes();
         if (isset($pointcutAtts->id)) {
             $pointcutName = (string) $pointcutAtts->id;
         } else {
             $pointcutName = BeanDefinition::generateName('PointcutXML');
         }
         if (isset($pointcutAtts->expression)) {
             $pointcut = clone $this->_templatePointcutDef;
             $pointcut->setName($pointcutName);
             $pointcut->setExpression((string) $pointcutAtts->expression);
             $pointcut->setMethod((string) $pointcutAtts->method);
             $this->_aspectManager->setPointcut($pointcut);
             $pointcuts[] = $pointcutName;
         } else {
             if (isset($pointcutAtts->{'pointcut-ref'})) {
                 $pointcuts[] = (string) $pointcutAtts->{'pointcut-ref'};
             }
         }
     }
     $aspect = new AspectDefinition($name, $pointcuts, $type, $aspectBean, $expression);
     return $aspect;
 }
コード例 #3
0
ファイル: Yaml.php プロジェクト: im286er/Ding
 /**
  * Returns an aspect definition.
  *
  * @param mixed[] $aspect Aspect data.
  *
  * @throws BeanFactoryException
  * @return AspectDefinition
  */
 private function _loadAspect($aspect)
 {
     $aspects = array();
     if (isset($aspect['id'])) {
         $name = $aspect['id'];
     } else {
         $name = BeanDefinition::generateName('AspectYAML');
     }
     if (isset($aspect['expression'])) {
         $expression = $aspect['expression'];
     } else {
         $expression = '';
     }
     $aspectBean = $aspect['ref'];
     $type = $aspect['type'];
     if ($type == 'method') {
         $type = AspectDefinition::ASPECT_METHOD;
     } else {
         if ($type == 'exception') {
             $type = AspectDefinition::ASPECT_EXCEPTION;
         } else {
             throw new BeanFactoryException('Invalid aspect type');
         }
     }
     $pointcuts = array();
     foreach ($aspect['pointcuts'] as $pointcut) {
         if (isset($pointcut['id'])) {
             $pointcutName = $pointcut['id'];
         } else {
             $pointcutName = BeanDefinition::generateName('PointcutYAML');
         }
         if (isset($pointcut['expression'])) {
             $pointcutDef = clone $this->_templatePointcutDef;
             $pointcutDef->setName($pointcutName);
             $pointcutDef->setExpression($pointcut['expression']);
             $pointcutDef->setMethod($pointcut['method']);
             $this->_aspectManager->setPointcut($pointcutDef);
             $pointcuts[] = $pointcutName;
         } else {
             if (isset($pointcut['pointcut-ref'])) {
                 $pointcuts[] = $pointcut['pointcut-ref'];
             }
         }
     }
     return new AspectDefinition($name, $pointcuts, $type, $aspectBean, $expression);
 }