Make sure view filename is OK. Same as in twig.

@param string $path
@throws PathException
6944
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
                ));
            }
        }
    }
1131603
public static function setClassIndexMap($path)
    {
        if (is_array($path)) {
            self::$resultClassIndexMap = $path;
        } elseif (file_exists($path) && is_readable($path)) {
            self::$resultClassIndexMap = require_once($path);
        } else {
            throw new RuntimeException("Path $path does not exists or is not readable.");
        }
    }
752423
public function parse(string $path): ?ViewPath
    {
        $this->validatePath($path);

        //Cutting extra symbols (see Twig)
        $filename = preg_replace(
            '#/{2,}#',
            '/',
            str_replace('\\', '/', (string)$path)
        );

        $namespace = $this->defaultNamespace;
        if (strpos($filename, '.') === false) {
            //Force default extension
            $filename .= '.' . $this->extension;
        } elseif (!$this->match($filename)) {
            return null;
        }

        if (strpos($filename, LoaderInterface::NS_SEPARATOR) !== false) {
            list($namespace, $filename) = explode(LoaderInterface::NS_SEPARATOR, $filename);
        }

        //Twig like namespaces
        if (isset($filename[0]) && $filename[0] == '@') {
            $separator = strpos($filename, '/');
            if ($separator === false) {
                throw new PathException(sprintf('Malformed view path"%s" (expecting "@namespace/name").', $path));
            }

            $namespace = substr($filename, 1, $separator - 1);
            $filename = substr($filename, $separator + 1);
        }

        return new ViewPath(
            $namespace,
            $this->fetchName($filename),
            $filename
        );
    }
1084821
public function checkDirectory($path)
    {
        $dir = dirname($path);
        if (!is_dir($dir)) {
            if (false === @mkdir($dir, 0777, true)) {
                throw new RuntimeException(sprintf('Unable to create the "%s" directory', $dir));
            }
        }
    }
326481
protected function setPath($path)
    {
        if ($path !== '' && !$this->isValidPath($path)) {
            throw new \InvalidArgumentException("Invalid path '$path'");
        }
        
        $this->path = (string)$path;
    }
827467
public function setPath($path)
	{
		$path = trim($path, '/');

		if (strlen($path) > 0)
		{
			$this->_path = '/' . $path . '/';
		}
		else
		{
			$this->_path = '/';
		}

		if ($this->_urlsInited)
		{
			$this->_initUrls();
		}
	}
498272
public static function addPath($path)
    {
        if ( ! isset(self::$_i18nPaths[$path]))
        {
            self::$_i18nPaths[$path] = $path;
        }
    }
578599
private function loadFromFile($path)
    {
        if ( ! is_file($path)) {
            return;
        }
        
        $config = require_once $path;
        
        if (is_array($config)) {
            $this->config = $config;
        }
    }
148085
public function addPath($path)
    {
        if (!is_string($path)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid path provided; must be a string, received %s',
                gettype($path)
            ));
        }

        $this->paths[] = $this->normalizePath($path);
    }
766166
public function mkdir( $path )
	{
		try {
			$this->fs->makeDirectory( $path );
		} catch( \Exception $e ) {
			throw new Exception( $e->getMessage(), 0, $e );
		}
	}
1007742
public function setPath(string $path) : void
    {
        if (!is_writable($path)) {
            throw new Exception("The path to the cache is not writable.");
        }

        $this->cachePath = $path;
    }
1257321
protected function checkPath(/*# string */$path)
    {
        // get the directory
        $dir = dirname(realpath($path));

        if (!is_dir($dir)) {
            mkdir($dir, 0777, true);
        }

        if (!is_dir($dir) || !is_writable($dir)) {
            throw new LogicException(
                Message::get(Message::MSG_PATH_NONWRITABLE, $dir),
                Message::MSG_PATH_NONWRITABLE
            );
        }
    }
620156
public function setPath($path)
	{
		if (is_dir($path) && is_writable($path)) {
			$this->path = substr($path, -1) == DIRECTORY_SEPARATOR ? $path : $path . DIRECTORY_SEPARATOR;
			return true;
		}
		throw new Exception('"Path" must be a writable directory.');
	}
266556
public function setPath(string $path): void
    {
        if (!file_exists($path) || !is_dir($path)) {
            throw new InvalidArgumentException(
                'Expected the template path to be an existing directory, received: ' . $path
            );
        }

        $this->path = $path;
    }
1080072
public function setPath(?string $path) : void
    {
        if (strpos($path, "/") !== 0) {
            $path = "/" . $path;
        }
        $this->path = $path;
    }
872908
private function viewNameFromSource(string $path) :string {
    return str_replace('/', '.',
      str_replace($this->buildContext->getPath('source') . '/' , '',
        str_replace($this->sourceExtension, '', $path)));
  }
1014131
public function setIncludePath($path)
    {
        if (file_exists($path)) {
            array_push($this->include_paths, $path);
            return $this;
        } else {
            throw new TemplateEngineException(
                sprintf('Directory "%s" defined as views path can\'t be found!', $path)
            );
        }
    }