protected function _parseIncludes($includes, $blacklist, $whitelist, Table $repository = null, $path = [])
    {
        $wildcard = implode('.', array_merge($path, ['*']));
        $wildcardWhitelist = Hash::get((array)$whitelist, $wildcard);
        $wildcardBlacklist = Hash::get((array)$blacklist, $wildcard);
        $contains = [];

        foreach ($includes as $include => $nestedIncludes) {
            $nestedContains = [];
            $includePath = array_merge($path, [$include]);
            $includeDotPath = implode('.', $includePath);

            if ($blacklist === true || ($blacklist !== false && ($wildcardBlacklist === true || Hash::get($blacklist, $includeDotPath) === true))) {
                continue;
            }

            if ($whitelist === false || (
                $whitelist !== true &&
                !$wildcardWhitelist &&
                Hash::get($whitelist, $includeDotPath) === null
            )) {
                continue;
            }

            $association = null;

            if ($repository !== null) {
                $association = $this->_getAssociation($repository, $include);
                if ($association === null) {
                    throw new BadRequestException("Invalid relationship path '{$includeDotPath}' supplied in include parameter");
                }
            }

            if (!empty($nestedIncludes)) {
                $nestedContains = $this->_parseIncludes($nestedIncludes, $blacklist, $whitelist, $association ? $association->getTarget() : null, $includePath);
            }

            if (!empty($nestedContains)) {
                if (!empty($association)) {
                    $contains[$association->getAlias()] = $nestedContains;
                }
            } else {
                if (!empty($association)) {
                    $contains[] = $association->getAlias();
                }
            }
        }

        return $contains;
    }
protected function _parseIncludes($includes, $blacklist, $whitelist, Table $repository = null, $path = [])
    {
        $wildcard = implode('.', array_merge($path, ['*']));
        $wildcardWhitelist = Hash::get((array)$whitelist, $wildcard);
        $wildcardBlacklist = Hash::get((array)$blacklist, $wildcard);
        $contains = [];

        foreach ($includes as $include => $nestedIncludes) {
            $nestedContains = [];
            $includePath = array_merge($path, [$include]);
            $includeDotPath = implode('.', $includePath);

            if ($blacklist === true || ($blacklist !== false && ($wildcardBlacklist === true || Hash::get($blacklist, $includeDotPath) === true))) {
                continue;
            }

            if ($whitelist === false || (
                $whitelist !== true &&
                !$wildcardWhitelist &&
                Hash::get($whitelist, $includeDotPath) === null
            )) {
                continue;
            }

            $association = null;

            if ($repository !== null) {
                $association = $this->_getAssociation($repository, $include);
                if ($association === null) {
                    throw new BadRequestException("Invalid relationship path '{$includeDotPath}' supplied in include parameter");
                }
            }

            if (!empty($nestedIncludes)) {
                $nestedContains = $this->_parseIncludes($nestedIncludes, $blacklist, $whitelist, $association ? $association->getTarget() : null, $includePath);
            }

            if (!empty($nestedContains)) {
                if (!empty($association)) {
                    $contains[$association->getAlias()] = $nestedContains;
                }
            } else {
                if (!empty($association)) {
                    $contains[] = $association->getAlias();
                }
            }
        }

        return $contains;
    }
protected function _parseIncludes ( $ includes , $ blacklist , $ whitelist , Table $ repository = null , $ path = [ ] ) { $ wildcard = implode ( '.' , array_merge ( $ path , [ '*' ] ) ) ; $ wildcardWhitelist = Hash :: get ( ( array ) $ whitelist , $ wildcard ) ; $ wildcardBlacklist = Hash :: get ( ( array ) $ blacklist , $ wildcard ) ; $ contains = [ ] ; foreach ( $ includes as $ include => $ nestedIncludes ) { $ nestedContains = [ ] ; $ includePath = array_merge ( $ path , [ $ include ] ) ; $ includeDotPath = implode ( '.' , $ includePath ) ; if ( $ blacklist === true || ( $ blacklist !== false && ( $ wildcardBlacklist === true || Hash :: get ( $ blacklist , $ includeDotPath ) === true ) ) ) { continue ; } if ( $ whitelist === false || ( $ whitelist !== true && ! $ wildcardWhitelist && Hash :: get ( $ whitelist , $ includeDotPath ) === null ) ) { continue ; } $ association = null ; if ( $ repository !== null ) { $ association = $ this -> _getAssociation ( $ repository , $ include ) ; if ( $ association === null ) { throw new BadRequestException ( "Invalid relationship path '{$includeDotPath}' supplied in include parameter" ) ; } } if ( ! empty ( $ nestedIncludes ) ) { $ nestedContains = $ this -> _parseIncludes ( $ nestedIncludes , $ blacklist , $ whitelist , $ association ? $ association -> getTarget ( ) : null , $ includePath ) ; } if ( ! empty ( $ nestedContains ) ) { if ( ! empty ( $ association ) ) { $ contains [ $ association -> getAlias ( ) ] = $ nestedContains ; } } else { if ( ! empty ( $ association ) ) { $ contains [ ] = $ association -> getAlias ( ) ; } } } return $ contains ; }
Takes a "include" string and converts it into a correct CakePHP ORM association alias

@param array $includes The relationships to include
@param array|bool $blacklist Blacklisted includes
@param array|bool $whitelist Whitelisted options
@param \Cake\ORM\Table|null $repository The repository
@param array $path Include path
@return array
@throws \Cake\Http\Exception\BadRequestException
Takes a include string and converts it into a correct CakePHP ORM association alias