Type cast the results and wrap each result in an entity after a find operation.

@param \Titon\Event\Event $event
@param array $results
@param string $finder
171534
public function castResults(Event $event, array &$results, $finder) {
        $columns = $this->getSchema()->getColumns();
        $driver = $this->getDriver();
        $entityClass = $this->getEntity();

        foreach ($results as $i => $result) {
            foreach ($result as $field => $value) {
                if (isset($columns[$field])) {
                    $result[$field] = $driver->getType($columns[$field]['type'])->from($value);
                }

                if (!is_array($value)) {
                    continue;
                }

                $result[$field] = new Entity($value);
            }

            $results[$i] = new $entityClass($result);
        }
    }
775055
private function updateParseResult(array $result, string $option, string $value) : array
    {
        $option_type = $this->options[$option]['type'] ?? self::OPTION_TYPE_OPTIONAL;
        if ($option_type === self::OPTION_TYPE_MULTIPLE){
            $result['named'][$option][] = $value;
        }
        else{
            $result['named'][$option] = $value;
        }
        return $result;
    }
364788
protected function determineMatches(Matcher $matcher, Result $control, array $trials = [])
    {
        foreach ($trials as $trial) {
            if ($matcher->match($control->getValue(), $trial->getValue())) {
                $trial->setMatch(true);
            }
        }
    }
181009
protected function processFields(array $fields, array $results = [])
    {
        $input = $this->input;
        $output = $this->output;
        $helper = $this->helperSet->get('question');

        foreach ($fields as $field) {
            if (!$field instanceof FieldDefinitionInterface) {
                continue;
            }
            $field_name = $field->getName();

            if (isset($results[$field_name])) {
                continue;
            }

            if (!$field instanceof FieldGroup) {
                if ($field->hasCondition()
                    && !$this->fieldConditionMet($field, $results)) {
                    continue;
                }

                if ($field->hasFieldCallback()) {
                    $field->onFieldCallback($results);
                }

                if ($input->isInteractive()) {
                    try {
                        $value = $helper->ask($input, $output, $field->asQuestion());

                        if ($field->hasSubform()) {
                            $subform = new static();
                            $field->onSubformProcess($subform, $value);

                            $results[$field_name] = $subform
                                ->setInput($input)
                                ->setOutput($output)
                                ->setHelperSet($this->helperSet)
                                ->process()
                                ->getResults();
                        } else {
                            $results[$field_name] = $field->formattedValue($value);
                        }
                    } catch (\Exception $e) {
                        throw new FormException(trim($e->getMessage()));
                    }
                }
            } else {
                $groups = [];

                do {
                    $result = $this->processFields(
                        $field->getGroupFields()
                    );
                    $continue = false;

                    if ($field->hasLoopUntil()) {
                        $continue = $field->loopUntil([$result]);
                        if ($continue) {
                            $groups[] = $result;
                        }
                    } else {
                        $groups[] = $result;
                    }
                } while ($continue);

                $results[$field_name] = $groups;
            }
        }

        return $results;
    }
375110
public function push(array $results, $name = false)
    {
        $this->event_results = array_merge($this->event_results, $results);

        if ($name) {
            $this->event_names[] = $name;
        }

        return $this;
    }
488244
public function mapResult(ResultIterator $result, $resultType = ArrayType::BOTH) {
		//check numer of rows returned
		if ($result->countRows() == 0)
			return null;

		//get result column types
		$this->columnTypes = $result->getColumnTypes($resultType);
		
		//validate result map (if any)
		if (isset($this->resultMap))
			$this->buildTypeHandlerList();

		//map row
		return $this->map($result->fetchArray($resultType));
	}
1166224
protected function prepareResults(array &$results, array $options)
    {
        $reindexed = array();

        foreach ($results as &$result) {
            $this->prepareResult($result, $options);
            if (!empty($options['index'])) {
                $reindexed[$result[$options['index']]] = $result;
            }
        }

        if (!empty($options['index'])) {
            $results = $reindexed;
        }
    }
1062769
protected function loadIncludes(array $results): void
	{
		$includes = $this->parseIncludes();

		foreach($includes['this'] as $include => $criteria)
		{
			$forward = $includes['forward'][$include] ?? [];

			$results[0]->$include()->eagerLoad($results, $include, $criteria, $forward);
		}
	}
149756
protected function from_db_records(array $results) {
        $entityfactory = $this->get_entity_factory();

        return array_map(function(array $result) use ($entityfactory) {
            [
                'discussion' => $discussion,
                'firstpost' => $firstpost,
                'firstpostauthor' => $firstpostauthor,
                'latestpostauthor' => $latestpostauthor,
            ] = $result;
            return $entityfactory->get_discussion_summary_from_stdclass(
                $discussion,
                $firstpost,
                $firstpostauthor,
                $latestpostauthor
            );
        }, $results);
    }
682097
public function afterFind(Model $model, $results, $primary = true) {
        if ($results) {
            foreach ($results as $index => $result) {
                $results[$index] = $this->convert($model, $result, self::FROM);
            }
        }

        return $results;
    }
1110305
private function handleResult($result): void
    {
        if ($result instanceof ActionResultInterface) {
            $result->updateResponse($this->getApplication(), $this->getRequest(), $this->getResponse());

            return;
        }

        if ($result === null) {
            return;
        }

        $this->getResponse()->setContent(json_encode($result));
        $this->getResponse()->setHeader('Content-Type', 'application/json');
    }
443505
public function createSearchResults(array $results)
    {
        $created = array();
        foreach ($results as $key => $result) {
            $created[$key] = $this->createResult('Packagist\Api\Result\Result', $result);
        }

        return $created;
    }
479174
protected function result(&$result)
    {
        if (!empty($this->options['json'])) {
            $this->jsonResult($result, $this->options['json'], true);
        }

        if (!empty($this->options['with_attr'])) {
            $this->getResultAttr($result, $this->options['with_attr']);
        }
    }
504492
protected function loadEvents(array $events = array())
    {
        foreach ($events as $event) {
            $method = 'set'.$event['type'].'s';
            $this->$method($event);
        }
    }
362012
public function addEagerConstraints(array $results)
    {
        $table = $this->parentMap->getTable();

        $this->query->whereIn($table.'.'.$this->firstKey, $this->getKeysFromResults($results));
    }
219297
protected function transformResultsToRoutes(array $results)
    {
        $routes = [];
        foreach ($results as $result) {
            $name = $result['route'];
            if (array_key_exists($name, $routes)) {
                /** @var Route $route */
                $route = $routes[$name];
                $paths = $route->getOption('i18n_paths');
                $paths[$result['locale']] = $result['path'];
                $route->setOption('i18n_paths', $paths);
            } else {
                $route = new Route($result['path']);
                if (!array_key_exists($result['controller'], $this->config['controllers'])) {
                    throw new \RuntimeException(sprintf('Undefined controller "%s".', $result['controller']));
                }
                $paths = [$result['locale'] => $result['path']];
                $route
                    ->setDefault('_controller', $this->config['controllers'][$result['controller']]['value'])
                    ->setMethods(['GET'])
                    ->setOption('i18n_paths', $paths)
                ;
                $routes[$name] = $route;
            }
        }
        // TODO check that i18n_paths are set for all locales ?
        return $routes;
    }
233773
public function add_analysable_results(array $results): bool {

        $any = false;

        // Process all provided time splitting methods.
        foreach ($results as $timesplittingid => $result) {
            if (!empty($result->result)) {
                $this->filesbytimesplitting[$timesplittingid][] = $result->result;
                $any = true;
            }
        }

        if (empty($any)) {
            return false;
        }
        return true;
    }