src/Component/Json.php
/**
     * Finds a specific element using $keys and calls a function on it.
     *
     * @param array $keys The keys to be followed recursively.
     * @param array $data The data. It must be a recursive array or you may encounter errors.
     * @return array{0:array|mixed,1:array|array[],2:mixed}|array{0:array|array[],1:null,2:null}
     * @see Json::do()
     */
Finds a specific element using $keys and calls a function on it.
@param array $keys The keys to be followed recursively.
@param array $data The data. It must be a recursive array or you may encounter errors.
Finds a specific element using $keys and calls a function on it . @param array $keys The keys to be followed recursively . @param array $data The data . It must be a recursive array or you may encounter errors .
protected function &findElementRecursive(
        array $keys,
        &$data,
        bool $forceCountableValue = false,
        int $indexingType = Indexing::STRICT
    ): array {
        $keysCount = count($keys);
        if ($keysCount > 1) {
            $curKey = array_shift($keys);
            if (isset($data[$curKey])) {
                $childData = &$data[$curKey];
                if (is_object($childData)) {
                    $childData = (array)($childData);
                }
                if (!is_array($childData) && $indexingType >= Indexing::SAFE) {
                    throw new UncountableValueException("The key '$curKey' has uncountable value");
                }
            } else {
                if ($indexingType === Indexing::STRICT) {
                    throw new Exception("The key '$curKey' does not exist");
                }
                $data[$curKey] = [];
            }
            return $this->findElementRecursive(
                $keys,
                $data[$curKey],
                $forceCountableValue,
                $indexingType
            );
        }
        else {
            if ($keysCount === 1) {
                $lastKey = $keys[0];
                if (isset($data[$lastKey])) {
                    $childData = &$data[$lastKey];
                    if (is_object($childData)) {
                        $childData = (array)($childData);
                    }
                    if ($forceCountableValue && !is_array($childData)) {
                        throw new UncountableValueException("Cannot use the method on uncountable");
                    }
                } else {
                    if ($indexingType === Indexing::STRICT) {
                        throw new Exception("The key '$lastKey' does not exist");
                    }
                    $data[$lastKey] = null;
                }
                $returnValue = [
                    &$data[$lastKey],
                    &$data,
                    $lastKey,
                ];
            }
            else {
                if ($forceCountableValue && self::isScalar($data)) {
                    throw new UncountableValueException("Cannot use the method on uncountable");
                }
                $returnValue = [
                    &$data,
                    null,
                    null,
                ];
            }
            $value = &$returnValue[0];
            $value = self::isScalar($value) ? $value : $this->normalize($value);
            return $returnValue;
        }
    }
protected function & findElementRecursive ( array $ keys , & $ data , bool $ forceCountableValue = false , int $ indexingType = Indexing :: STRICT ) : array { $ keysCount = count ( $ keys ) ; if ( $ keysCount > 1 ) { $ curKey = array_shift ( $ keys ) ; if ( isset ( $ data [ $ curKey ] ) ) { $ childData = & $ data [ $ curKey ] ; if ( is_object ( $ childData ) ) { $ childData = ( array ) ( $ childData ) ; } if ( ! is_array ( $ childData ) && $ indexingType >= Indexing :: SAFE ) { throw new UncountableValueException ( " The key ' $ curKey ' has uncountable value " ) ; } } else { if ( $ indexingType === Indexing :: STRICT ) { throw new Exception ( " The key ' $ curKey ' does not exist " ) ; } $ data [ $ curKey ] = [ ] ; } return $ this -> findElementRecursive ( $ keys , $ data [ $ curKey ] , $ forceCountableValue , $ indexingType ) ; } else { if ( $ keysCount === 1 ) { $ lastKey = $ keys [ 0 ] ; if ( isset ( $ data [ $ lastKey ] ) ) { $ childData = & $ data [ $ lastKey ] ; if ( is_object ( $ childData ) ) { $ childData = ( array ) ( $ childData ) ; } if ( $ forceCountableValue && ! is_array ( $ childData ) ) { throw new UncountableValueException ( " Cannot use the method on uncountable " ) ; } } else { if ( $ indexingType === Indexing :: STRICT ) { throw new Exception ( " The key ' $ lastKey ' does not exist " ) ; } $ data [ $ lastKey ] = null ; } $ returnValue = [ & $ data [ $ lastKey ] , & $ data , $ lastKey , ] ; } else { if ( $ forceCountableValue && self :: isScalar ( $ data ) ) { throw new UncountableValueException ( " Cannot use the method on uncountable " ) ; } $ returnValue = [ & $ data , null , null , ] ; } $ value = & $ returnValue [ 0 ] ; $ value = self :: isScalar ( $ value ) ? $ value : $ this -> normalize ( $ value ) ; return $ returnValue ; } }
Finds a specific element using $keys and calls a function on it.
Finds a specific element using $keys and calls a function on it .
// Get the current key, and remove it from keys array // Recursion // End of recursion // If $keysCount is 0 /*
             * For sure, $returnValue[1] is an array or null. Just we must make sure that
             * $returnValue[0] is an array, for further operations. So:
             */