@param array $entities

@return Event[]
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;
    }
574482
public function delete($entities)
    {
        if($entities instanceof Entity) {
            $entities = [$entities];
        }
        return $this->obj_gateway
            ->withSchema($this->obj_schema)
            ->withTransaction($this->consumeTransaction())
            ->deleteMulti($entities);
    }
462649
public function resetStats(array $entities)
    {
        foreach ($entities as $entity) {
            $entity->set('numOfComments', $entity->comments->getTotal());
            $last_comment = $entity->comments
                                   ->reset()
                                   ->order('creationTime', 'DESC')
                                   ->fetch();
            $entity->set('lastComment', $last_comment);

            if ($last_comment) {
                $entity->set('lastCommenter', $last_comment->author);
                $entity->set('lastCommentTime', $last_comment->creationTime);
            } else {
                $entity->set('lastCommenter', null);
                $entity->set('lastCommentTime', null);
            }
        }
    }
1011776
public function excludeEntities($entities)
    {
        assert('is_array($entities) || is_null($entities)');

        if ($entities === null) {
            return;
        }
        $this->excluded = $entities;
        sort($this->excluded);
        $this->cacheId = sha1($this->cacheId.serialize($this->excluded));
    }
337551
private function encapsulate($entities)
	{
		$items = [];

		foreach ($entities as $entity)
		{
			$items[] = Entity::fromMetadata($entity, $this);
		}

		return new Collection($items);
	}
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;
    }
982005
public function addEntities($entities) {
    foreach ($entities as $entity) {
      $row = array();
      foreach ($this->columns as $columnName => $column) {
        $converter = $column->getConverter();
        $row[] = $converter($entity, $column);
      }
      $this->addRow($row);
    }
    return $this;
  }
854391
public function getByIds(array $ids): array
    {

        $entities = $this->getRepository()->findByIds($ids);

        $this->prepareEntitesForGet($entities);

        return $entities;
    }
1318454
public function createSuccess(array $events = []): EventCollection
    {
        Assert::assertThat(true, Assert::isTrue());

        return new EventSequence($events, $this->callVerifierFactory);
    }
796220
public function createEvents(array $events) {
        $statements = [];
        foreach ($events as $index => $opts) {
            $route = isset($opts['recipe']) ? $opts['recipe'] : '';
            if (isset(static::$routes[$route])) {
                $event = '\XREmitter\Events\\'.static::$routes[$route];
                $service = new $event();
                $opts['context_lang'] = $opts['context_lang'] ?: 'en';
                array_push($statements, $service->read($opts));
            }
        }
        return $this->repo->createEvents($statements);
    }
906917
public static function buildMultiply($entities)
    {
        $templates = [];

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

        return $templates;
    }
369056
protected function generateMethods(Entity $entity)
    {
        $result     = [];
        $descriptor = $entity->getDescriptor();
        $methods    = $descriptor->getMethodList() ?: [];

        foreach ($methods as $method) {
            $result[] = $this->generateMethod($entity, $method);
        }

        return $result;
    }
387775
private function handleEntities($entities, callable $callback)
    {
        if ($this->promise) {
            return $entities->then($callback);
        }

        return \call_user_func($callback, $entities);
    }
150137
public function saveKeyValues(Entity $entity, array $keys)
    {
        $event = $this->_table->dispatchEvent('Model.beforeSaveKeyValues', compact('entity'));

        if ($event->isStopped()) {
            return $event->result;
        }

        if (!empty($event->result)) {
            $entity = $event->result;
        }

        $fields = $this->config('fields');

        if ($entity->has($fields['key']) && $entity->has($fields['value'])) {
            return true;
        }

        $mappedIds = $this->_getFieldToIdMapping($keys);

        $entities = [];
        foreach ($entity->toArray() as $key => $value) {
            if ($this->_table->hasField($key)) {
                continue;
            }

            $serialized = false;
            if (in_array($key, $this->config('serializeFields'))) {
                $value = serialize($value);
                $serialized = true;
            }

            /** @var Setting $kvEntity */
            $kvEntity = $this->_table->newEntity([
                'scope' => $this->config('scope'),
                $this->config('fields.key') => $key,
                $this->config('fields.value') => $value,
                'serialized' => $serialized
            ]);

            if (($existingId = Hash::get($mappedIds, $key)) !== null) {
                $kvEntity->id = $existingId;
            }

            $entities[] = $kvEntity;
        }

        $result = $this->_table->connection()->transactional(function () use ($entities) {
            foreach ($entities as $e) {
                $this->_table->save($e);
            }
        });

        return ($result !== false);
    }
1303929
protected function getImportErrors(EntityInterface $entity): array
    {
        $result = [];

        /**
         * @var array $errors
         */
        $errors = $entity->errors();

        if (empty($errors)) {
            return $result;
        }

        foreach ($errors as $field => $error) {
            $msg = "[$field] ";
            $msg .= is_array($error) ? implode(', ', $error) : $error;
            $result[] = $msg;
        }

        return $result;
    }
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);
            }
        }
    }
121575
public function sortTree(array $entities)
    {
        if (empty($entities)) {
            return $entities;
        }

        $class = ClassUtils::getClass(reset($entities));

        $config = $this->treeListener->getConfiguration($this->em, $class);

        if (empty($config)) {
            throw new ClassIsNotTreeException($class);
        }

        $children = [];

        foreach ($entities as $entity) {
            $parent = $this->propertyAccessor->getValue($entity, $config['parent']);

            if (empty($parent)) {
                continue;
            }

            $parentPath = $this->propertyAccessor->getValue($parent, $config['path_source']);

            if (!isset($children[$parentPath])) {
                $children[$parentPath] = [];
            }

            $children[$parentPath][$this->propertyAccessor->getValue($entity, $config['path_source'])] = $entity;
        }

        $sorted = [];

        foreach ($entities as $entity) {
            $this->addEntity($sorted, $entity, $children, $config);
        }

        return array_values($sorted);
    }