Exemple #1
0
 public function __construct($args = null, $options = array())
 {
     $this->email = new Email();
     if ($this->template) {
         # XXX: check template file
         $this->email->template($this->template);
     }
     return parent::__construct($args, $options);
 }
 /**
  * Construct an action object.
  *
  *    $action = new UpdateProductAction(array( ... ), new Product, $options);
  *
  *
  * Here we override the default __construct from Action class.
  *
  * The initialize flow here is:
  *
  *    BaseRecordAction::__construct
  *    BaseRecordAction::setRecord
  *      Action::__construct
  *      Action::init
  *      Action::schema
  *    BaseRecordAction::loadRecordValuesToParams
  *
  *
  * @param array                $args
  * @param LazyRecord\BaseModel $record
  */
 public function __construct(array $args = array(), $options = array())
 {
     $record = null;
     if (isset($options['record'])) {
         $record = $options['record'];
     } else {
         if ($options instanceof BaseModel) {
             $record = $options;
             $options = array();
             // reassign $options as array
         }
     }
     if (isset($options['record_class'])) {
         $this->recordClass = $options['record_class'];
     } else {
         if (!$this->recordClass && $record) {
             $this->recordClass = get_class($record);
         }
     }
     if (!$this->recordClass) {
         throw new ActionException(sprintf('recordClass is not defined.'), $this);
     }
     if ($record === null) {
         $record = new $this->recordClass();
     }
     $this->setRecord($record);
     // CreateRecordAction doesn't require primary key to be existed.
     if (!$record->id && !$this instanceof CreateRecordAction && $this->enableLoadRecord) {
         // for create action, we don't need to create record
         if (!$this->loadRecordFromArguments($args)) {
             throw new ActionException(get_class($this) . " Record action can not load record from {$this->recordClass}", $this);
         }
     }
     // initialize schema , init base action stuff
     parent::__construct($args, $options);
 }