Ejemplo n.º 1
0
 /**
  * Validator to ensure proper data for the file fields
  *
  * @param Asset                     $object  Entity object to validate
  * @param ExecutionContextInterface $context Context object
  */
 public static function validateFile($object, ExecutionContextInterface $context)
 {
     if ($object->getStorageLocation() == 'local') {
         $tempName = $object->getTempName();
         // If the object is stored locally, we should have file data
         if ($object->isNew() && $tempName === null) {
             $context->buildViolation('mautic.asset.asset.error.missing.file')->atPath('tempName')->setTranslationDomain('validators')->addViolation();
         }
         if ($object->getTitle() === null) {
             $context->buildViolation('mautic.asset.asset.error.missing.title')->atPath('title')->setTranslationDomain('validators')->addViolation();
         }
         // Unset any remote file data
         $object->setRemotePath(null);
     } elseif ($object->getStorageLocation() == 'remote') {
         // If the object is stored remotely, we should have a remote path
         if ($object->getRemotePath() === null) {
             $context->buildViolation('mautic.asset.asset.error.missing.remote.path')->atPath('remotePath')->setTranslationDomain('validators')->addViolation();
         }
         // Unset any local file data
         $object->setPath(null);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getTempName()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getTempName', array());
     return parent::getTempName();
 }