protected function _populateModelsFromArray(array $array)
 {
     $models = array();
     foreach ($array as $row) {
         $model = json_decode($row['model'], true);
         $model = ModelHelper::expandModelsInArray($model);
         $class = $model['service']['__class__'];
         $model->service = new $class($model->service);
         $model->queueId = $row['id'];
         $models[] = new Postmaster_TransportModel($model);
     }
     return $models;
 }
Exemplo n.º 2
0
 /**
  * Sets an attribute's value.
  *
  * @param string $name
  * @param mixed  $value
  *
  * @return bool
  */
 public function setAttribute($name, $value)
 {
     if (!$this->strictAttributes || in_array($name, $this->attributeNames())) {
         // Is this a normal attribute?
         if (array_key_exists($name, $this->_attributeConfigs)) {
             $attributes = $this->getAttributeConfigs();
             $config = $attributes[$name];
             // Handle special case attribute types
             switch ($config['type']) {
                 case AttributeType::DateTime:
                     if ($value) {
                         if (!$value instanceof \DateTime) {
                             if (DateTimeHelper::isValidTimeStamp($value)) {
                                 $value = new DateTime('@' . $value);
                             } else {
                                 $value = DateTime::createFromString($value);
                             }
                         }
                     } else {
                         // No empty strings allowed!
                         $value = null;
                     }
                     break;
                 case AttributeType::Mixed:
                     if ($value && is_string($value) && mb_strpos('{[', $value[0]) !== false) {
                         // Presumably this is JSON.
                         $value = JsonHelper::decode($value);
                     }
                     if (is_array($value)) {
                         if ($config['model']) {
                             $class = __NAMESPACE__ . '\\' . $config['model'];
                             $value = $class::populateModel($value);
                         } else {
                             $value = ModelHelper::expandModelsInArray($value);
                         }
                     }
                     break;
             }
         } else {
             if (!array_key_exists($name, $this->_extraAttributeNames)) {
                 $this->_extraAttributeNames[] = $name;
             }
         }
         $this->_attributes[$name] = $value;
         return true;
     } else {
         return false;
     }
 }