Ejemplo n.º 1
0
 /**
  * @param mixed $comparison
  * @return bool
  */
 public function isComparison($comparison)
 {
     if (!is_array($comparison)) {
         return false;
     }
     if (ArrayUtils::hasStringKeys($comparison) || count($comparison) < 2) {
         return false;
     }
     if (!is_string($comparison[0]) || !is_string($comparison[1])) {
         return false;
     }
     if (!$this->isOperator($comparison[1])) {
         return false;
     }
     $comparison[1] = $this->normalizeOperator($comparison[1]);
     return in_array($comparison[1], $this->comparisonOperators);
 }
Ejemplo n.º 2
0
 /**
  * @param AdapterInterface $ea
  * @param array $config
  * @param object $object
  * @throws \RuntimeException
  * @return array
  */
 protected function processFileUploads(AdapterInterface $ea, array &$config, $meta, $object)
 {
     $files = [];
     if (empty($config['uploadable'])) {
         return $files;
     }
     $uploads = $this->getPropertyValueFromObject($meta, $config['fileInfoField'], $object);
     if (!is_array($uploads) || !ArrayUtils::filterRecursive($uploads, null, true)) {
         // No uploaded files
         return $files;
     }
     if (ArrayUtils::hasStringKeys($uploads)) {
         $uploads = [$uploads];
     }
     $pathGenerator = null;
     if (!empty($config['pathGenerator'])) {
         $pathGenerator = $config['pathGenerator'];
     }
     if (empty($config['fileField']) || !$meta->hasAssociation($config['fileField'])) {
         $fileClass = $this->getFileClass();
     } else {
         $fileClass = $meta->getAssociationTargetClass($config['fileField']);
     }
     if (!$fileClass) {
         throw new \RuntimeException('Target file class cannot be found.');
     }
     $uploadableSubscriber = $this->getUploadableSubscriber();
     $fileInfoClass = $uploadableSubscriber->getDefaultFileInfoClass();
     foreach ($uploads as $fileInfoArray) {
         $file = $this->createFile($fileClass, $fileInfoArray, $pathGenerator);
         $fileInfo = $this->createFileInfo($fileInfoClass, $fileInfoArray);
         $uploadableSubscriber->addEntityFileInfo($file, $fileInfo);
         $files[] = $file;
     }
     $om = $ea->getObjectManager();
     if ($meta->hasAssociation($config['fileField'])) {
         $uow = $om->getUnitOfWork();
         $value = $meta->isCollectionValuedAssociation($config['fileField']) ? $files : $file;
         $this->updateField($object, $uow, $ea, $meta, $config['fileField'], $value);
         if ($meta->isCollectionValuedAssociation($config['fileField'])) {
             $uow->computeChangeSet($meta, $object);
         } else {
             $ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
         }
     }
     $this->getEventManager()->trigger(__FUNCTION__, $this, $files);
     foreach ($files as $file) {
         $om->persist($file);
     }
     return $files;
 }