Gc\Mvc\Listener\DocumentListener::findDocument PHP Method

findDocument() protected method

Find document from request uri
protected findDocument ( string $path, boolean $isPreview ) : Model
$path string Path from request uri
$isPreview boolean Is the current page is a preview
return Gc\Document\Model
    protected function findDocument($path, $isPreview)
    {
        $explodePath = $this->explodePath($path);
        $documentTmp = null;
        $children = null;
        $hasDocument = false;
        $parentId = null;
        foreach ($explodePath as $urlKey) {
            if ($hasDocument === false) {
                $documentTmp = Document\Model::fromUrlKey($urlKey, $parentId);
                if (empty($documentTmp) and $parentId === null and ($homeDocument = Document\Model::fromUrlKey('')) !== false) {
                    $documentTmp = Document\Model::fromUrlKey($urlKey, $homeDocument->getId());
                }
            }
            if (is_array($children) and !in_array($documentTmp, $children)) {
                $hasDocument = true;
            } else {
                if (!empty($documentTmp) and ($documentTmp->isPublished() or $isPreview)) {
                    $parentId = $documentTmp->getId();
                    $children = $documentTmp->getChildren();
                }
            }
        }
        return $documentTmp;
    }