예제 #1
0
 /**
  * @param BaseModel $model
  * @param $valuesModel
  * @throws Exception
  */
 protected function writeModel(BaseModel $model, $valuesModel)
 {
     if (method_exists($valuesModel, 'getParams')) {
         $model->setParams($valuesModel->getParams());
     }
     if (method_exists($valuesModel, 'getPictures')) {
         $model->setPictures($valuesModel->getPictures());
     }
     if (method_exists($valuesModel, 'getDeliveryOptions')) {
         $model->setDeliveryOptions($valuesModel->getDeliveryOptions());
     }
     if ($model->loadModel($valuesModel, $this->onValidationError)) {
         $string = $model->getYml();
         $this->write($string);
     }
 }
예제 #2
0
 /**
  * @param BaseModel $model model
  * @param $valuesModel
  * @throws Exception
  */
 protected function writeModel(BaseModel $model, $valuesModel)
 {
     $attributes = [];
     foreach ($model->attributes() as $attribute) {
         $methodName = 'get' . ucfirst($attribute);
         $attributeValue = $valuesModel->{$methodName}();
         $attributes[$attribute] = $attributeValue;
     }
     $model->load($attributes, '');
     if (!$model->validate()) {
         throw new Exception('Model values is invalid ' . serialize($model->getErrors()));
     }
     $string = $model->getYml();
     $this->write($string);
 }
예제 #3
0
 /**
  * @param BaseModel $model model
  * @param $valuesModel
  * @throws Exception
  */
 protected function writeModel(BaseModel $model, $valuesModel)
 {
     $attributes = [];
     foreach ($model->attributes() as $attribute) {
         $methodName = 'get' . ucfirst($attribute);
         $attributeValue = $valuesModel->{$methodName}();
         $attributes[$attribute] = $attributeValue;
     }
     $model->load($attributes, '');
     if (method_exists($valuesModel, 'getParams')) {
         $model->setParams($valuesModel->getParams());
     }
     if (method_exists($valuesModel, 'getPictures')) {
         $model->setPictures($valuesModel->getPictures());
     }
     if (!$model->validate()) {
         if (is_callable($onValidationError = $this->onValidationError)) {
             $onValidationError($model);
         } else {
             throw new Exception('Model values is invalid ' . serialize($model->getErrors()));
         }
     } else {
         $string = $model->getYml();
         $this->write($string);
     }
 }