Beispiel #1
0
 /**
  * Object constructor
  *
  * @param   ObjectConfig $config Configuration options
  * @throws \InvalidArgumentException
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     if (is_null($config->command_chain)) {
         throw new \InvalidArgumentException('command_chain [CommandChainInterface] config option is required');
     }
     //Create a command chain object
     $this->__command_chain = $config->command_chain;
     //Set the command priority
     $this->_priority = $config->priority;
     //Add the event subscribers
     $handlers = (array) ObjectConfig::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);
         }
     }
 }
Beispiel #2
0
 /**
  * Constructor.
  *
  * @param  ObjectConfig $config A ObjectConfig object with configuration options
  * @throws \InvalidArgumentException
  */
 public function __construct(ObjectConfig $config)
 {
     //Set the object manager
     if (!$config->object_manager instanceof ObjectManagerInterface) {
         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 ObjectIdentifierInterface) {
         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);
         }
     }
 }