Converts the model validation errors to a readable format an throws it as an exception

@param ActiveRecord $model

@throws Exception
559286
protected function throwInvalidModelException($model)
    {
        $errorMessage = Yii::t('language', 'Invalid model "{model}":', ['model' => $model->className()]);
        foreach ($model->getErrors() as $attribute => $errors) {
            $errorMessage .= "\n $attribute: " . join(', ', $errors);
        }
        throw new Exception($errorMessage);
    }
293808
private function isTranslationActive($model)
    {
        if (!$model) {
            return false;
        }
        if (is_array($this->requiredAttributes) && !empty($this->requiredAttributes)) {
            foreach ($this->requiredAttributes as $attribute) {
                if ($model->{$attribute} && !empty($model->{$attribute})) {
                    return true;
                }
            }
        } else {
            return true;
        }
        return false;
    }
1161842
public function validate($model)
    {
        $validator = Validation::createValidator();
        $errors = $validator->validate($model);
        if (($errors->count() > 0)) {
            $this->errors = array_merge($this->errors, $errors);

            return false;
        }

        return true;
    }
1365203
public function validateAttribute($model, $attribute)
    {
        $this->_model = $model;
        $this->_attributeName = $attribute;
        $result = $this->validateValue($model->$attribute);
        if (!empty($result)) {
            $this->addError($model, $attribute, $result[0], $result[1]);
        }
    }
720650
protected function performAjaxValidation($model)
    {
        $result = ($model instanceof Model)
            ? ActiveForm::validate($model)
            : ActiveForm::validateMultiple($model);

        $response = Yii::$app->getResponse();

        if (!empty($result) && $ajaxRedirect = Yii::$app->getSession()->get('site_ajax_redirect')) {
            $response = $response->redirect($ajaxRedirect);
            Yii::$app->getSession()->remove('site_ajax_redirect');
        } else {
            $response->format = Response::FORMAT_JSON;
            $response->data = $result;
        }

        return $response;
    }
276100
public function deleted(Model $model)
    {
        try {
            Croppa::delete('storage/'.$model->getOriginal('path'));
        } catch (Exception $e) {
            Log::error($e->getMessage());
        }
    }
60434
public function validateAttribute($model, $attribute)
    {
        $value = $model->$attribute;
        $result = $this->validateValue($value);

        if (!empty($result)) {
            $this->addError($model, $attribute, $this->renderMessage($model, $attribute));
        }
    }
961206
public function register(ActiveRecord $model)
    {
        /* @var $seo Seo */
        $seo = $model->seo;
        if ($seo->title) {
            Yii::$app->seo->setTitle($seo->title);
        }
        if ($seo->h1) {
            Yii::$app->seo->setH1($seo->h1);
        }
        if ($seo->description) {
            Yii::$app->seo->setDescription($seo->description);
        }
        if ($seo->keywords) {
            Yii::$app->seo->setKeywords($seo->keywords);
        }
        if ($seo->text) {
            Yii::$app->seo->setText($seo->text);
        }
        if ($seo->og_image) {
            Yii::$app->seo->setOgImage($seo->og_image);
        }
        if (Yii::$app->has('openGraph')) {
            Yii::$app->openGraph->title = Yii::$app->seo->getTitle();
            if (Yii::$app->seo->getDescription()) {
                Yii::$app->openGraph->description = Yii::$app->seo->getDescription();
            }
            if (Yii::$app->seo->getOgImage()) {
                $image = Module::twigCompile($seo->og_image, [
                    'model' => $model
                ]);
                Yii::$app->openGraph->image = Url::to($image, true);
            }
        }
    }
296940
public function prepareIterator(Model $m)
    {
        if (!$this->mode) {
            $this->mode = 'r';
        } elseif ($this->mode == 'w') {
            throw new Exception(['Currently writing records, so loading is not possible.']);
        }

        if (!$this->handle) {
            $this->loadHeader();
        }

        while (true) {
            $data = $this->getLine();
            if (!$data) {
                break;
            }
            $data = $this->typecastLoadRow($m, $data);
            $data[$m->id_field] = $this->line;

            yield $data;
        }
    }
901330
protected function validColumns(Memory $meta, array $columns, $table, $model)
    {
        if (empty($not = array_diff($columns, $meta->getAttributes($model))) === false) {
            throw new ExceptionFactory('Column', ['COLUMN_DOES_NOT_EXISTS', $not, $table, $meta->getAttributes($model)]);
        }

        return true;

    }
558319
public function afterValidate(Model $model) {
		if (!empty($model->validationErrors)){
			$model->data[$model->alias] = $this->runtime[$model->alias]['data'];
		}
		
		return true;
	}
648603
public static function errorCheck($model)
    {
        $className = self::getCleanClassName($model);

        if (strpos($className, 'Search') !== false) {
            if (strlen($model->_query) < 3) {
                $model->_error = 400;
            }
        }

        if (!$model->_error) {
            $header = self::getHeader($model->_url);
            if ($header == 200) {
                if ($className != 'UserListModel') {
                    $additionalSetting = ($className == 'CharacterPeoplePictureModel');
                    $model->_parser = self::getParser($model->_url, $model->_parserArea, $additionalSetting);
                }
            } else {
                $model->_error = $header;
            }
        }
    }
1251456
public static function checkModel($errors, Model $model) : array
    {
        $output = [];
        if (!is_array($errors)) {
            return $output;
        }
        foreach ($errors as $attribute => $message) {
            $obj = $model;
            if (strpos($attribute, '.') !== false) {
                list($nested, $attr) = explode('.', $attribute);
                if (isset($obj->{$nested}) && $obj->{$nested} instanceof Model) {
                    $obj       = $obj->{$nested};
                    $attribute = $attr;
                }
            }
            if ($obj->hasProperty($attribute)) {
                $output[Html::getInputId($obj, $attribute)] = $message;
            } else {
                $output[] = $message;
            }
        }
        return $output;
    }
1359351
protected function validateModel()
    {
        parent::validateModel();

        $table = $this->getTable();

        // Check to see whether any generated foreign key names
        // will conflict with column names.

        $colPhpNames = array();
        $fkPhpNames = array();

        foreach ($table->getColumns() as $col) {
            $colPhpNames[] = $col->getPhpName();
        }

        foreach ($table->getForeignKeys() as $fk) {
            $fkPhpNames[] = $this->getFKPhpNameAffix($fk, $plural = false);
        }

        $intersect = array_intersect($colPhpNames, $fkPhpNames);
        if (!empty($intersect)) {
            throw new EngineException("One or more of your column names for [" . $table->getName() . "] table conflict with foreign key names (" . implode(", ", $intersect) . ")");
        }

        // Check foreign keys to see if there are any foreign keys that
        // are also matched with an inversed referencing foreign key
        // (this is currently unsupported behavior)
        // see: http://trac.propelorm.org/ticket/549

        foreach ($table->getForeignKeys() as $fk) {
            if ($fk->isMatchedByInverseFK()) {
                throw new EngineException("The 1:1 relationship expressed by foreign key " . $fk->getName() . " is defined in both directions; Propel does not currently support this (if you must have both foreign key constraints, consider adding this constraint with a custom SQL file.)");
            }
        }
    }
1224071
public function validateAttribute($model, $attribute)
    {
        $countries = [];
        if ($this->country !== null) {
            $countries = [$this->country];
        } elseif ($this->countryAttribute !== null) {
            $countries = [$model->{$this->countryAttribute}];
        } elseif (is_array($this->countries) && count($this->countries) > 0) {
            $countries = $this->countries;
        }

        if (count($countries) <= 0) {
            $countries = self::getPhoneUtil()->getSupportedRegions();
        }

        foreach ($countries as $country) {
            try {
                $number = self::getPhoneUtil()->parse($model->$attribute, $country);

                if (self::getPhoneUtil()->isValidNumberForRegion($number, $country)) {
                    if ($this->format) {
                        $model->$attribute = self::getPhoneUtil()->format($number, PhoneNumberFormat::INTERNATIONAL);
                    }

                    $this->_successValidation = true;
                    break;
                }
            } catch (NumberParseException $e) {
                $this->addError($model, $attribute, $this->numberParseExceptionMessage);
            }
        }

        if (!$this->_successValidation) {
            $this->addError($model, $attribute, $this->notValidPhoneNumberMessage);
        }

        return $this->_successValidation;
    }
708721
public function extractEntityName($model)
    {
        $classNames = (array) explode('\\', $model);

        $entityName = end($classNames);

        if ($this->entityHasTranslation($entityName)) {
            return __('exception::exceptions.models.'.$entityName);
        }

        return $entityName;
    }
1363220
public function validate(Model $obj)
	{
		$fieldset = static::set_fields($obj);
		$val = $fieldset->validation();

		$is_new = $obj->is_new();

		// only allow partial validation on updates, specify the fields for updates to allow null
		$allow_partial = $is_new ? false : array();

		$input = array();
		foreach (array_keys($obj->properties()) as $p)
		{
			if ( ! in_array($p, $obj->primary_key()) and ($is_new or $obj->is_changed($p)))
			{
				$input[$p] = $obj->{$p};
				is_array($allow_partial) and $allow_partial[] = $p;
			}
		}

		if ( ! empty($input) and $val->run($input, $allow_partial, array($obj)) === false)
		{
			throw new ValidationFailed($val->show_errors(), 0, null, $fieldset);
		}
		else
		{
			foreach ($input as $k => $v)
			{
				$obj->{$k} = $val->validated($k);
			}
		}
	}