示例#1
0
 /**
  * Iterate collection and apply decorators based on action.
  *
  * @param \Percy\Entity\Collection $collection
  * @param integer                  $action
  *
  * @return boolean
  */
 protected function decorate(Collection $collection, $action)
 {
     foreach ($collection->getIterator() as $entity) {
         $decorators = $entity->getDecorators($action);
         array_walk($decorators, [$this, 'invokeDecorators'], $entity);
     }
 }
示例#2
0
 /**
  * Iterate collection and validate data.
  *
  * @param \Percy\Entity\Collection $collection
  *
  * @throws \Percy\Exception\ValidationException when first validation failure occurs
  *
  * @return boolean
  */
 public function validate(Collection $collection)
 {
     foreach ($collection->getIterator() as $entity) {
         if (is_null($entity->getValidator())) {
             continue;
         }
         $filter = $this->filter->newSubjectFilter($entity->getValidator());
         try {
             $data = $entity->getData([], false);
             foreach (array_keys($entity->getMapping()) as $property) {
                 $data[$property] = array_key_exists($property, $data) ? $data[$property] : null;
             }
             $filter($data);
         } catch (FilterFailed $e) {
             throw new ValidationException($e->getMessage());
         }
     }
     return true;
 }
示例#3
0
 /**
  * Return relationship bind conditional.
  *
  * @param \Percy\Entity\Collection $collection
  * @param string                   $relationship
  * @param string                   $key
  *
  * @return string
  */
 protected function getRelationshipBinds(Collection $collection, $relationship, $key)
 {
     $primaries = [];
     foreach ($collection->getIterator() as $entity) {
         if (!array_key_exists($relationship, $entity->getRelationshipMap())) {
             continue;
         }
         $primaries[] = $entity[$key];
     }
     return $primaries;
 }
示例#4
0
 /**
  * Iterate a collection with the correct callback.
  *
  * @param \Percy\Entity\Collection $collection
  * @param string                   $callable
  *
  * @return boolean
  */
 protected function collectionIterator(Collection $collection, $callable, array $scopes = [])
 {
     $this->dbal->beginTransaction();
     try {
         foreach ($collection->getIterator() as $entity) {
             call_user_func_array([$this, $callable], [$entity, $scopes]);
         }
     } catch (PDOException $e) {
         $this->dbal->rollBack();
         return false;
     }
     $this->dbal->commit();
     return true;
 }