Jarves\Objects::parseUrl PHP Метод

parseUrl() публичный Метод

Pattern: object://[/][/][/?] Examples: 1. object://news/1 => returns the object news with primary value equal 1 2. object://news/id=1 => equal as 1. 3. object://news/1/2 => returns a list of the objects with primary value equal 1 or 2 4. object://news/id=1/id=2 => equal as 3. 5. object://object_with_multiple_primary/2,54 => returns the object with the first primary field equal 2 and second primary field equal 54 6. object://object_with_multiple_primary/2,54/34,55 => returns a list of the objects 7. object://object_with_multiple_primary/id=2,parent_id=54/id=34,parent_id=55 => equal as 6 if the first defined primary is 'id' and the second 'parent_id' 8. object://news/1?fields=title => equal as 1. but returns only the field title 9. object://news/1?fields=title,category_id => equal as 1. but returns only the field title and category_id 10. object://news?fields=title => returns all objects from type news 11. object://news?fields=title&limit=5 => returns first 5 objects from type news
public parseUrl ( string $internalUrl ) : array
$internalUrl string
Результат array [object_key, object_id/s, queryParams]
    public function parseUrl($internalUrl)
    {
        $internalUrl = trim($internalUrl);
        $list = false;
        $catch = 'object://';
        if (substr(strtolower($internalUrl), 0, strlen($catch)) == $catch) {
            $internalUrl = substr($internalUrl, strlen($catch));
        }
        $catch = 'objects://';
        if (substr(strtolower($internalUrl), 0, strlen($catch)) == $catch) {
            $list = true;
            $internalUrl = substr($internalUrl, strlen($catch));
        }
        $firstSlashPos = strpos($internalUrl, '/');
        $questionPos = strpos($internalUrl, '?');
        if ($firstSlashPos === false && $questionPos === false) {
            return array($internalUrl, false, array(), $list);
        }
        if ($firstSlashPos === false && $questionPos != false) {
            $objectKey = substr($internalUrl, 0, $questionPos);
        } else {
            $objectKey = $this->getObjectKey($internalUrl);
        }
        if (strpos($objectKey, '%')) {
            $objectKey = Tools::urlDecode($objectKey);
        }
        if (!$objectKey) {
            throw new \LogicException(sprintf('The url `%s` does not contain a object key.', $internalUrl));
        }
        $params = array();
        $objectIds = null;
        if ($questionPos !== false) {
            parse_str(substr($internalUrl, $questionPos + 1), $params);
            if ($firstSlashPos !== false) {
                $objectIds = substr($internalUrl, $firstSlashPos + 1, $questionPos - ($firstSlashPos + 1));
            }
        } else {
            $objectIds = substr($internalUrl, strlen($objectKey) + 1);
        }
        $objectIds = $this->parsePk($objectKey, $objectIds);
        if ($params && isset($params['condition'])) {
            $params['condition'] = json_decode($params['condition'], true);
        }
        return array($objectKey, !$objectIds ? false : $objectIds, $params, $list);
    }