/**
  * Validate files by checking:
  *  - Model requirement
  *  - Existing as file or alias
  *
  * @param PortableElementObject $object
  * @param string $source Temporary directory source
  * @param array $files Array of file relative path
  * @return bool
  * @throws PortableElementInvalidAssetException
  * @throws PortableElementInvalidModelException
  * @throws PortableElementParserException
  * @throws \common_exception_Error
  */
 public function validateAssets(PortableElementObject $object, $source, array $files = [])
 {
     if (empty($files)) {
         $files = $this->getAssets($object, $files);
     }
     if (empty($files)) {
         return false;
     }
     $errorReport = \common_report_Report::createFailure('Portable element validation has failed.');
     foreach ($files as $key => $file) {
         try {
             $this->validFile($source, $file);
         } catch (PortableElementInvalidAssetException $e) {
             $subReport = \common_report_Report::createFailure(__('Cannot locate the file "%s"', $file));
             $errorReport->add($subReport);
         }
     }
     if ($errorReport->containsError()) {
         $exception = new PortableElementInvalidModelException();
         $exception->setReport($errorReport);
         throw $exception;
     }
     return true;
 }
 /**
  * @param PortableElementObject $object
  * @param Validatable $validatable
  * @param array $validationGroup
  * @return bool
  * @throws PortableElementInconsistencyModelException
  * @throws PortableElementInvalidModelException
  * @throws \common_exception_Error
  */
 public static function validate(PortableElementObject $object, Validatable $validatable, $validationGroup = array())
 {
     $constraints = self::getValidConstraints($validatable->getConstraints(), $validationGroup);
     $errorReport = \common_report_Report::createFailure('Portable element validation has failed.');
     foreach ($constraints as $field => $constraint) {
         foreach ($constraint as $validator) {
             $getter = 'get' . ucfirst($field);
             if (!method_exists($object, $getter)) {
                 throw new PortableElementInconsistencyModelException('Validator is not correctly set for model ' . get_class($object));
             }
             $value = $object->{$getter}();
             if ($validator instanceof \tao_helpers_form_Validator) {
                 if (!$validator->evaluate($value)) {
                     $subReport = \common_report_Report::createFailure(__("Unable to validate %s: %s", $field, $validator->getMessage()));
                     $errorReport->add($subReport);
                 }
                 continue;
             }
             if (is_string($validator)) {
                 if (array_key_exists($validator, self::$customValidators)) {
                     $callable = self::$customValidators[$validator];
                     try {
                         self::$callable($value);
                     } catch (PortableElementInvalidFieldException $e) {
                         $subReport = \common_report_Report::createFailure(__("Unable to validate %s: %s", $field, $e->getMessage()));
                         $errorReport->add($subReport);
                     }
                 }
                 continue;
             }
             return false;
         }
     }
     if ($errorReport->containsError()) {
         $exception = new PortableElementInvalidModelException();
         $exception->setReport($errorReport);
         throw $exception;
     }
     return true;
 }