コード例 #1
0
ファイル: mixin.php プロジェクト: daodaoliang/nooku-framework
 /**
  * Object constructor
  *
  * @param   KObjectConfig $config Configuration options
  * @throws InvalidArgumentException
  */
 public function __construct(KObjectConfig $config)
 {
     parent::__construct($config);
     if (is_null($config->command_chain)) {
         throw new InvalidArgumentException('command_chain [KCommandChainInterface] config option is required');
     }
     //Create a command chain object
     $this->__command_chain = $config->command_chain;
     //Add the event subscribers
     $handlers = (array) KObjectConfig::unbox($config->command_handlers);
     foreach ($handlers as $key => $value) {
         if (is_numeric($key)) {
             $this->addCommandHandler($value);
         } else {
             $this->addCommandHandler($key, $value);
         }
     }
     //Add the command callbacks
     foreach ($this->getMixer()->getMethods() as $method) {
         $match = array();
         if (preg_match('/_(after|before)([A-Z]\\S*)/', $method, $match)) {
             $this->addCommandCallback($match[1] . '.' . strtolower($match[2]), $method);
         }
     }
 }
コード例 #2
0
 /**
  * Constructor.
  *
  * @param  KObjectConfig $config A ObjectConfig object with configuration options
  * @throws InvalidArgumentException
  */
 public function __construct(KObjectConfig $config)
 {
     //Set the object manager
     if (!$config->object_manager instanceof KObjectManagerInterface) {
         throw new InvalidArgumentException('object_manager [ObjectManagerInterface] config option is required, "' . gettype($config->object_manager) . '" given.');
     } else {
         $this->__object_manager = $config->object_manager;
     }
     //Set the object identifier
     if (!$config->object_identifier instanceof KObjectIdentifierInterface) {
         throw new InvalidArgumentException('object_identifier [ObjectIdentifierInterface] config option is required, "' . gettype($config->object_identifier) . '" given.');
     } else {
         $this->__object_identifier = $config->object_identifier;
     }
     parent::__construct($config);
     //Set the object config
     $this->__object_config = $config;
     //Set the command priority
     $this->_priority = $config->priority;
     //Add the command callbacks
     foreach ($this->getMethods() as $method) {
         $matches = array();
         if (preg_match('/_(after|before)([A-Z]\\S*)/', $method, $matches)) {
             $this->addCommandCallback($matches[1] . '.' . strtolower($matches[2]), $method);
         }
     }
 }