private function validatePath(string $path)
    {
        if (empty($path)) {
            throw new PathException('A view path is empty');
        }

        if (false !== strpos($path, "\0")) {
            throw new PathException('A view path cannot contain NUL bytes');
        }

        $path = ltrim($path, '/');
        $parts = explode('/', $path);
        $level = 0;

        foreach ($parts as $part) {
            if ('..' === $part) {
                --$level;
            } elseif ('.' !== $part) {
                ++$level;
            }

            if ($level < 0) {
                throw new PathException(sprintf(
                    'Looks like you try to load a view outside configured directories (%s)',
                    $path
                ));
            }
        }
    }