Raw plain text action of a path

@param string $path
@return array
@throws \WebDocBook\Exception\NotFoundException
777618
public function plainTextAction($path)
    {
        try {
            $this->setPath($path);
        } catch (NotFoundException $e) {
            throw $e;
        }

        $dbfile = new WDBFile($this->getpath());
        if (!$dbfile->isFile()) {
            throw new NotFoundException(
                'Can not send raw content of a directory!',
                0, null, TemplateHelper::getRoute($dbfile->getWDBPath())
            );
        }

        $response = $this->wdb->getResponse();

        // mime header
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($finfo, $this->getPath());
        if ( ! in_array($mime, $response::$content_types)) {
            $mime = 'text/plain';
        }
        finfo_close($finfo);

        // content
        $ctt = $response->flush(file_get_contents($this->getPath()), $mime);
        return array('layout_empty_txt', $ctt);
    }
408279
public static function parsePath($path)
    {
        $components = pathinfo($path);

        return [
            'directory' => isset($components['dirname']) ? self::fixPath($components['dirname']) : null,
            'filename' => isset($components['filename']) ? $components['filename'] : null,
            'extension' => isset($components['extension']) ? $components['extension'] : null,
        ];
    }
656641
private function parseFile(string $path): array
    {
        $json = json_decode(file_get_contents($path), true);
        $root = dirname($path);

        $namespaces = array_merge(
            iterator_to_array($this->parseNamespaces($json['autoload']['psr-4'] ?: [], $root)),
            iterator_to_array($this->parseNamespaces($json['autoload-dev']['psr-4'] ?: [], $root))
        );
        return $namespaces;
    }
32572
public function readDir(string $path): array
    {
        $path = $this->sanitizeDirPath($path);

        if (!$this->dirExists($path)) {
            throw new DirNotFoundException("Dir not found: '$path'");
        }

        $result = $this->readDirRaw($path);

        sort($result);

        return $result;
    }
949276
public function get(string $path): SplFileInfo
    {
        $path = ltrim($path, '\\/');
        foreach ($this->assets as $asset) {
            if ($asset->getRelativePathname() === $path) {
                return $asset;
            }
        }
        throw new NotFoundHttpException(sprintf('Unknown asset: %s', $path));
    }
1043881
protected function findText($path)
    {
        foreach ($this->localeSequence() as $locale) {
            $arrayKey = "$locale.$path";
            if (isset($this->data[$arrayKey])) {
                return $this->data[$arrayKey];
            }
        }
        return $path;
    }
1160430
private function parsePath($path)
    {
        if (empty($path)) {
            $path = Map::DEFAULT_URL_DELIMITER;
        }

        // get the clean path
        return $this->urlParser->parse($path);
    }
942980
public function read($path)
    {
        $location = $this->applyPathPrefix($path);
        return [
            'contents' => $this->ossClient->getObject($this->bucket, $location)
        ];
    }
1223807
private static function splitPath(string $path): array
    {
        if ($path === '') {
            return [];
        }

        $result = explode('/', $path);

        foreach ($result as $pathPart) {
            if ($pathPart === '') {
                throw new InvalidRoutePathException('Path "' . $path . '" contains empty part.');
            }
            if (preg_match('/[^a-zA-Z0-9._-]/', $pathPart, $matches)) {
                throw new InvalidRoutePathException('Path "' . $path . '" contains invalid character "' . $matches[0] . '".');
            }
        }

        return $result;
    }
1302272
public function realpath($path)
    {
        $path = str_replace('\\', '/', rtrim($path, '/'));
        if ($path[0] != '/' && (strlen($path) < 2 || $path[1] != ':')) {
            $path = getcwd() . '/' . $path;
        }
        $parts = explode('/', $path);
        $path = [];
        foreach ($parts as $part) {
            if ($part == '..') {
                array_pop($path);
            } else if ($part != '.') {
                array_push($path, $part);
            }
        }
        return implode('/', $path);
    }
3073
public function cat($path)
    {
        if (!$this->hasCheckout) {
            $this->checkout();
        }

        if (false === file_exists($this->cwd . '/' . $path)) {
            throw new NotFoundException(sprintf('The path \'%s\' is not found', $path));
        }

        return file_get_contents($this->cwd . '/' . $path);
    }
902984
public function getMetaData(string $path): array
    {
        $path = $this->normalizePath($path);
        $this->assertPresent($path);

        return $this->getAdapter()->getMetaData($path);
    }
414260
private function extractWebspaceFromPath($path)
    {
        $match = preg_match(
            sprintf(
                '/^\/%s\/([\w\.-]*?)\/.*$/',
                $this->pathSegmentRegistry->getPathSegment('base')
            ),
            $path,
            $matches
        );

        if ($match) {
            return $matches[1];
        }

        return;
    }
566975
public static function normalizePath($path)
    {
        if (is_string($path)) {
            return explode('.', $path);
        }

        if (!is_array($path)) {
            return [$path];
        }

        return $path;
    }
490892
private function _list(string $path): array {
        $result = [];
        $scan = glob($path . '/*');
        foreach ($scan as $item) {
            if (is_dir($item)) {
                $result[basename($item)] = $this->_list($item);
            } else {
                $result[] = basename($item);
            }
        }
        return $result;
    }
470826
public function ls(string $path = '') : array
    {
        return version_compare(PHP_VERSION, '7.2.0', '>=')
            ? $this->ls72($path)
            : $this->lsLegacy($path);

    }
1021491
public function match(string $path): array
    {
        $path = $path === '/' ? $path : \rtrim($path, '/ ');

        if (!isset($this->routes[$path])) {
            return [self::NOT_FOUND, $path];
        }

        return [self::FOUND, $this->routes[$path]];
    }