@param DataInterface[] $entities

@throws \InvalidArgumentException

@return DataInterface[][]
353870
protected function sortEntitiesByValueClass($entities)
    {
        $entitiesByValueClassByIds = [];
        foreach ($entities as $entity) {
            if (null === $entity) {
                continue;
            }
            if (!$entity instanceof DataInterface) {
                throw new \InvalidArgumentException(self::E_MSG);
            }
            $entitiesByValueClassByIds[$entity->getFamily()->getValueClass()][$entity->getId()] = $entity;
        }

        return $entitiesByValueClassByIds;
    }
813939
public function getManagerForEntity($entity): EntityManagerInterface
    {
        $class = ClassUtils::getClass($entity);
        $entityManager = $this->doctrine->getManagerForClass($class);
        if (!$entityManager instanceof EntityManagerInterface) {
            throw new \InvalidArgumentException("No manager found for class {$class}");
        }

        return $entityManager;
    }
166444
public function entityByResult(string $entity): array
    {
        $result = array_get($this->response, "data.result", '');

        return array_get($this->response, "data.entities.$entity.$result", []);
    }
331804
protected function getEntityDataArray(EntityInterface $entity)
    {
        $metadata = $this->getEntityMetadata();
        $array = [];
        
        foreach ($this->getHydrator()->extract($entity) as $sqlName => $value) {
            if ($sqlName !== $metadata->getIdentifier() && null !== $value) {
                $array[$metadata->getRawSQLName($metadata->getName($sqlName))] = $value;
            }
        }
        
        return $array;
    }
481813
protected function storeCollection($entities)
    {
        $this->adapter->beginTransaction();

        foreach ($entities as $entity) {
            $this->storeEntity($entity);
        }

        $this->adapter->commit();

        return $entities;
    }
660364
public function toDbTableRows($entities)
    {
        $collection = new Collection();
        foreach ($entities as $entity) {
            $collection->push($this->toDbTableRow($entity));
        }

        return $collection;
    }
900303
protected function getModelKeysFromCollection(EntityCollection $entities)
    {
        $keyName = $this->relatedMap->getKeyName();

        return array_map(function ($m) use ($keyName) {
            return $m->$keyName;
        }, $entities);
    }
237642
private function queryFor(MapInterface $entities): Query
    {
        $query = new Query\Query;
        $this->variables = new Stream('string');

        $partitions = $entities->partition(function(Identity $identity, object $entity): bool {
            $meta = ($this->metadata)(\get_class($entity));

            return $meta instanceof Aggregate;
        });
        $query = $partitions
            ->get(true)
            ->reduce(
                $query,
                function(Query $carry, Identity $identity, object $entity): Query {
                    return $this->createAggregate($identity, $entity, $carry);
                }
            );
        $query = $partitions
            ->get(false)
            ->reduce(
                $query,
                function(Query $carry, Identity $identity, object $entity): Query {
                    return $this->createRelationship($identity, $entity, $carry);
                }
            );
        $this->variables = null;

        return $query;
    }
833563
public function transform($entities)
    {
        if (is_null($entities) || count($entities) === 0) {
            return [];
        }

        $data = [];
        $accessor = PropertyAccess::createPropertyAccessor();

        foreach ($entities as $entity) {
            $text = is_null($this->textProperty)
                ? (string)$entity
                : $accessor->getValue($entity, $this->textProperty);
            $data[$accessor->getValue($entity, $this->primaryKey)] = [
                'text' => $text
            ];
        }

        return $data;
    }
906917
public static function buildMultiply($entities)
    {
        $templates = [];

        foreach ($entities as $entity) {
            $templates[$entity->language] = static::buildFromEntity($entity);
        }

        return $templates;
    }
177713
private function pullFromEntities(array $entities)
    {
        $events = [];
        foreach ($entities as $entity) {
            // ignore Doctrine not initialized proxy classes
            // proxy class can't have a domain events
            if ((!($entity instanceof Proxy) || $entity->__isInitialized()) && $entity instanceof AggregateEvents) {
                $events = array_merge($events, $entity->pullEvents());
            }
        }

        return $events;
    }
795144
protected function getTableColumns($entity)
    {
        $columnClause = [];

        // Get all columns for insertion
        $allColumns = array_merge($this->requiredTableColumns($entity), $this->columns);

        // Set values for columns
        foreach ($allColumns as $col => $type) {
            $columnClause[$col] = isset($this->columns[$col]) ?
                $this->quoteOrNot($this->columns[$col]) :
                $this->sampleData($type);
        }

        $columnNames = implode(', ', array_keys($columnClause));
        $columnValues = implode(', ', $columnClause);

        return [$columnNames, $columnValues];
    }
129586
public function saveEvent(EntityInterface $entity): array
    {
        $response = [
            'status' => false,
            'errors' => [],
            'entity' => null,
        ];

        if ($entity instanceof EntityInterface) {
            $entity = $entity->toArray();
        }

        if (empty($entity['id'])) {
            unset($entity['id']);
        }

        $query = $this->find()
            ->where([
                //'source' => empty($entity['source']) ? null : $entity['source'],
                'source_id' => $entity['source_id'],
                'calendar_id' => $entity['calendar_id'],
            ]);

        $query->execute();

        /** @var EntityInterface $event */
        $event = (!$query->count()) ? $this->newEntity() : $query->first();
        $event = $this->patchEntity($event, $entity);

        $saved = $this->save($event);

        if ($saved) {
            $response['status'] = true;
            $response['entity'] = $saved;
        } else {
            $response['errors'] = $event->getErrors();
        }

        return $response;
    }
311338
final public static function fromArrays(array $inputs) : array
    {
        Util::throwIfNotType(['array' => $inputs]);

        $entities = [];
        foreach ($inputs as $key => $input) {
            $entities[$key] = new static($input);
        }

        return $entities;
    }
1136374
protected function eagerLoadRelations(array $entities)
    {
        if (empty($entities)) {
            return;
        }

        if ($this->class === null) {
            throw new LogicException('A class must be specified for Eager Loading using the `asClass` method.');
        }

        foreach ($this->with as $method) {
            $relation = $this->getRelation($entities[0], $method);
            $relation->addEagerConstraints($entities);
            $relationEntities = $relation->getEager();
            /** @var Model $entity */
            foreach ($entities as $entity) {
                $id = $entity->getId();
                $entity->setRelationEntities($method, isset($relationEntities[$id]) ? $relationEntities[$id] : null);
            }
        }
    }
941459
private function getAdapterAlias($entity)
    {
        $descriptor = EntityDescriptorRegistry::getInstance()
            ->getDescriptorFor($entity);
        return $descriptor->getAdapterAlias()
            ? $descriptor->getAdapterAlias()
            : 'default';
    }
1039748
private function getAggregatorsFromEntities(ObjectManager $objectManager, array $entities)
    {
        $aggregators = [];

        foreach ($entities as $entity) {
            $entityClassName = ClassUtils::getClass($entity);
            if (array_key_exists($entityClassName, $this->entitiesAggregators)) {
                foreach ($this->entitiesAggregators[$entityClassName] as $aggregator) {
                    $aggregators[] = new $aggregator($entity, $objectManager->getClassMetadata($entityClassName)->getIdentifierValues($entity));
                }
            }
        }

        return $aggregators;
    }