예제 #1
0
 private function addProperties(Query $query, string $name, MapInterface $mapping) : Query
 {
     if ($mapping->contains($name)) {
         $query = $query->withProperties($mapping->get($name)->get(0)->toPrimitive())->withParameters($mapping->get($name)->get(1)->toPrimitive());
     }
     return $query;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public static function fromConfig(MapInterface $config, Types $types) : TypeInterface
 {
     if ((string) $config->keyType() !== 'scalar' || (string) $config->valueType() !== 'variable') {
         throw new InvalidArgumentException();
     }
     $type = new self();
     $type->innerKey = $config->get('inner');
     $type->inner = $types->build($config->get('inner'), $config->remove('inner'));
     return $type;
 }
예제 #3
0
 private function merge(MapInterface $left, MapInterface $right) : MapInterface
 {
     $map = $left;
     $right->foreach(function (string $var, SequenceInterface $data) use(&$map, $left) {
         if (!$map->contains($var)) {
             $map = $map->put($var, $data);
             return;
         }
         $map = $map->put($var, new Sequence($data->get(0)->merge($left->get($var)->get(0)), $data->get(1)->merge($left->get($var)->get(1))));
     });
     return $map;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public static function fromConfig(MapInterface $config, Types $types) : TypeInterface
 {
     if ((string) $config->keyType() !== 'scalar' || (string) $config->valueType() !== 'variable') {
         throw new InvalidArgumentException();
     }
     $type = new self();
     if ($config->contains('format')) {
         $type->format = (string) $config->get('format');
     }
     return $type;
 }
예제 #5
0
 /**
  * Build the query to update all entities at once
  *
  * @param MapInterface<IdentityInterface, CollectionInterface> $changesets
  * @param MapInterface<IdentityInterface, object> $entities
  *
  * @return QueryInterface
  */
 private function queryFor(MapInterface $changesets, MapInterface $entities) : QueryInterface
 {
     $query = new Query();
     $this->variables = new Map(Str::class, CollectionInterface::class);
     $changesets->foreach(function (IdentityInterface $identity, CollectionInterface $changeset) use(&$query, $entities) {
         $entity = $entities->get($identity);
         $meta = $this->metadatas->get(get_class($entity));
         if ($meta instanceof Aggregate) {
             $query = $this->matchAggregate($identity, $entity, $meta, $changeset, $query);
         } else {
             if ($meta instanceof Relationship) {
                 $query = $this->matchRelationship($identity, $entity, $meta, $changeset, $query);
             }
         }
     });
     $this->variables->foreach(function (Str $variable, CollectionInterface $changeset) use(&$query) {
         $query = $this->update($variable, $changeset, $query);
     });
     $this->variables = null;
     return $query;
 }