getValueFromPath example

$idFields = $definition->getPrimaryKeys()->filter(fn (Field $field) => $field instanceof IdField);
        $idField = $idFields->first();

        if ($idFields->count() !== 1 || !$idField) {
            return $record;
        }

        $primaryKeyProperty = $idField->getPropertyName();

        $updateByFieldPath = explode('.', $updateByField);
        $record = \is_array($record) ? $record : iterator_to_array($record);
        $updateByValue = $this->getValueFromPath($record$updateByFieldPath);

        if ($updateByValue === null) {
            $record['_error'] = new UpdatedByValueNotFoundException($definition->getEntityName()$updateByField);

            return $record;
        }

        $criteria = new Criteria();
        $criteria->setLimit(1);

        $updateByField = $this->handleTranslationsAssociation(
            

    private const FOREACH_REGEX = '/{foreach\s+\w+=[a-zA-Z0-9\$](.*)}/m';
    private const ATTR_REGEX = '/(\s*(?<key>\w+)=(?<value>[a-zA-Z0-9\$]+)\s*)/';

    public function completer(array $context, string $smartyCode): array
    {
        foreach ($this->getMatches($smartyCode) as $match) {
            if (!isset($match['from']$match['item'])) {
                continue;
            }

            $value = $this->getValueFromPath($context$match['from']);

            if ($value === null) {
                continue;
            }

            $count = \count($value);

            if ($count) {
                $key = array_keys($value)[0];
                $context[$match['item']] = $value[$key];
                if (isset($match['key'])) {
                    
public function completer(array $context, string $smartyCode): array
    {
        preg_match_all(self::REGEX, $smartyCode$matches, PREG_SET_ORDER, 0);

        if (!empty($matches)) {
            foreach ($matches as $match) {
                if (!isset($match['arrayName']$match['value'])) {
                    continue;
                }

                $value = $this->getValueFromPath($context$match['arrayName']);

                if ($value === null) {
                    continue;
                }

                if (\count($value)) {
                    $key = array_keys($value)[0];
                    $context[$match['value']] = $value[$key];
                    if (isset($match['key'])) {
                        $context[$match['key']] = $key;
                    }
                }
Home | Imprint | This part of the site doesn't use cookies.