Cast array to entity

@param   array  $matches     The records
@param   string $entityClass The entity name

@return array
176726
public function castToEntity($matches, $entityClass)
    {
        $entityRegistry = $this->repositoryFactory->getEntityRegistry();

        $result = [];

        $meta        = $this->getMeta($entityClass);
        $entityClass = $meta->class;
        $reflection  = new \ReflectionClass($entityClass);

        foreach ($matches as $match) {
            $entity = new $entityClass;

            foreach ($meta->fields as $key => $definition) {
                /** @var Element $definition */
                $varName = $definition->propertyName($key);
                $colName = $definition->columnName($key);

                $value = isset($definition->default) ? $definition->default : null;

                if (array_key_exists($colName, $match)) {
                    // @todo Apply validation according to definition
                    $value = $match[$colName];

                    if ($definition instanceof Field) {
                        switch ($definition->type) {
                            case 'int':
                            case 'integer':
                                $value = (integer)$value;
                                break;

                            case 'json':
                                $value = json_decode($value);
                                break;

                            default:
                                // Leave the value alone
                                break;
                        }
                    }
                }

                if ($reflection->hasProperty($varName)) {
                    $property = $reflection->getProperty($varName);
                    $property->setAccessible(true);
                    $property->setValue($entity, is_null($value) ? $entity->{$varName} : $value);
                } else {
                    /** @noinspection PhpVariableVariableInspection */
                    $entity->{$varName} = $value;
                }
            }

            $entityRegistry->stashEntity($entity);
            $this->resolveRelations($entity, $meta);
            $entityRegistry->registerEntity($entity);

            $result[] = $entity;

            unset($entity);
        }

        return $result;
    }
1092193
public static function getAllEntityClassNames(EntityManager $entityManager)
    {
        $classes = [];

        foreach ($entityManager->getMetadataFactory()->getAllMetadata() as $meta) {
            $classes[] = $meta->getName();
        }

        return $classes;
    }
1305322
public function getMatcherConfiguration($matcherClass)
    {
        if ( ! array_key_exists($matcherClass, $this->configuration["matcher_settings"])) {
            return null;
        }

        $configuration = $this->configuration["matcher_settings"][$matcherClass];

        unset($this->configuration["matcher_settings"][$matcherClass]);

        return $configuration;
    }
1262637
public function entityFactory($entityClass, $data = array())
    {
        $fqcn = $this->getEntityClass($entityClass);
        $reflection = new \ReflectionClass($fqcn);

        $arguments = array($this->dispatcher, $data);
        if (isset($this->entityArguments[$fqcn])) {
            $arguments = array_merge($arguments, $this->entityArguments[$fqcn]);
        }

        $document = $reflection->newInstanceArgs($arguments);
        if (!$document instanceof EntityInterface) {
            throw new \UnexpectedValueException('Expecting document to be an instance of \Cpliakas\DynamoDb\ODM\EntityInterface');
        }
        return $document;
    }
756012
public function getIds($entityType, array $selector = [], array $params = [])
    {
        $params['fields'] = '_id';

        return array_column($this->search($entityType, $selector, $params), '_id');
    }
686604
public function findByIds($class, array $ids)
    {
        if (count($ids) === 0) {
            return array();
        }

        $dql = "SELECT object FROM {$class} object WHERE object.id IN (:ids)";
        $query = $this->wrapped->createQuery($dql);
        $query->setParameter('ids', $ids);
        $objects = $query->getResult();

        if (($entityCount = count($objects)) !== ($idCount = count($ids))) {
            throw new MissingObjectException(
                "{$entityCount} out of {$idCount} ids don't match any existing object"
            );
        }

        return $objects;
    }
16622
public String[] getEntityClass(Object obj, String name, Siren4JEntity entityAnno) {
        Class<?> clazz = obj.getClass();
        String[] compClass = entityAnno == null ? null : entityAnno.entityClass();
        //If entity class specified then use it.
        if (compClass != null && !ArrayUtils.isEmpty(compClass)) {
            return compClass;
        }
        //Else use name or class.
        List<String> entityClass = new ArrayList<String>();
        entityClass.add(StringUtils.defaultString(name, clazz.getName()));
        if (obj instanceof CollectionResource) {
            String tag = getCollectionClassTag();
            if (StringUtils.isNotBlank(tag)) {
                entityClass.add(tag);
            }
        }
        return entityClass.toArray(new String[]{});
    }
224960
protected function createEntities(array $rows, $entityClass = null, $table = null)
    {
        if ($table === null) {
            $table = $this->getTable();
        }
        $entities = [];
        $collection = Result::createInstance($rows, $table, $this->connection, $this->mapper);
        $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
        if ($entityClass !== null) {
            foreach ($rows as $dibiRow) {
                $entity = $this->entityFactory->createEntity(
                    $entityClass,
                    $collection->getRow($dibiRow->$primaryKey)
                );
                $entity->makeAlive($this->entityFactory);
                $entities[$dibiRow->$primaryKey] = $entity;
            }
        } else {
            foreach ($rows as $dibiRow) {
                $row = $collection->getRow($dibiRow->$primaryKey);
                $entityClass = $this->mapper->getEntityClass($this->getTable(), $row);
                $entity = $this->entityFactory->createEntity($entityClass, $row);
                $entity->makeAlive($this->entityFactory);
                $entities[$dibiRow->$primaryKey] = $entity;
            }
        }
        return $this->entityFactory->createCollection($entities);
    }
816663
public function getRepository($entityClass)
    {
        $container = $this->getContainer();

        $em = $container->get('doctrine')->getManager();

        /* @var EntityRepository $repository */
        return $em->getRepository($entityClass);
    }
279054
protected function loadResource(string $entityClass, string $url)
    {
        $resource = $this->restClient->getResource($entityClass, $url);

        return $resource->getEntity();
    }
236406
public function entity(string $entityClass) : EntityMapperDefiner
    {
        return new EntityMapperDefiner($this->iocContainer, function (callable $entityMapperFactory) use ($entityClass) {
            $this->entityMapperFactories[] = $entityMapperFactory;
        });
    }
1157953
@SuppressWarnings("unchecked")
  @Override
  public <T> List<T> getCollection(Class<T> entityClass) {
    String collectionName = Util.determineCollectionName(entityClass);
    Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
    if (null == collection) {
      createCollection(collectionName);
      collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
    }

    CollectionMetaData cmd = cmdMap.get(collectionName);
    List<T> newCollection = new ArrayList<T>();
    try {
      for (T document : collection.values()) {
        Object obj = Util.deepCopy(document);
        if(encrypted && cmd.hasSecret() && null != obj) {
          CryptoUtil.decryptFields(obj, cmd, dbConfig.getCipher());
        }
        newCollection.add((T) obj);
      }
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
      logger.error("Error when decrypting value for a @Secret annotated field for entity: " + collectionName, e);
      throw new JsonDBException("Error when decrypting value for a @Secret annotated field for entity: " + collectionName, e);
    }
    return newCollection;
  }
507154
protected function loadResources(string $entityClass, string $rel): Collection
    {
        $uri = $this->resource->getLinks()->getHref($rel);
        $resources = $this->restClient->getResources($entityClass, $rel, $uri);

        $entities = $resources->map(function (HalResource $resource) {
            return $resource->getEntity();
        });

        return new Collection($entities);
    }
379476
public List<ENTITY> find(Match... matches) {
        return find(Arrays.asList(matches), new ArrayList<Order>(0));
    }
1228742
private function getEntityFilterSets($class)
    {
        $filterSetNames = [];

        foreach ($this->entityConfig as $filterSetName => $params) {
            if (isset($params['entities']) && in_array($class, $params['entities'])) {
                $filterSetNames[] = $filterSetName;
            }
        }

        return $filterSetNames;
    }
740726
protected function makeSchema(string $class): array
    {
        //Using as basement
        $schema = $this->schema;
        unset($schema[Record::MORPHED_ALIASES]);

        //We do not have this information in morphed relation but it's required for ManyToMany
        $schema[Record::WHERE] = [];

        //This must be unified in future, for now we can fetch columns directly from there
        $recordSchema = $this->orm->define($class, ORMInterface::R_SCHEMA);
        $schema[Record::RELATION_COLUMNS] = array_keys($recordSchema[Record::SH_DEFAULTS]);

        return $schema;
    }
336747
function html_entity_replace($matches)
    {
        if ($matches[2])
        {
            return self::chr_utf8(hexdec($matches[3]));
        }
        elseif ($matches[1])
        {
            return self::chr_utf8($matches[3]);
        }
        elseif ($matches[3])
        {
        	// return "((&" . $matches[3] . ";))";
        	// return mb_convert_encoding('&'.$matches[3].';', 'UTF-8', 'HTML-ENTITIES');
        	return html_entity_decode('&'.$matches[3].';');
        }

        return false;
    }