-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhpPath.min.php
1 lines (1 loc) · 1.85 KB
/
PhpPath.min.php
1
<?php /** PhpPath-0.2.1, Minified version of PhpPath. @link https://github.com/masicek/PhpPath @author Viktor Mašíček <[email protected]> @license "New" BSD License */ namespace PhpPath; class Path { const VERSION = '0.2.1'; static public function checkDirectory($path) { $pathFiltered = self::make($path); if (!is_dir($pathFiltered)) { throw new NotExistsPathException('Directory "' . $path . '" not exists.'); } return $path; } static public function checkFile($path) { $pathFiltered = self::make($path); if (!is_file($pathFiltered)) { throw new NotExistsPathException('File "' . $path . '" not exists.'); } return $path; } static public function make() { $pathParts = func_get_args(); $ds = DIRECTORY_SEPARATOR; $path = implode($ds, $pathParts); $path = str_replace('/', $ds, $path); $path = str_replace('\\', $ds, $path); $path = str_replace($ds . $ds, $ds, $path); $path = str_replace($ds . '.' . $ds, $ds, $path); return $path; } static public function makeAndCheckDirectory() { $args = func_get_args(); $path = call_user_func_array('self::make', $args); self::checkDirectory($path); return $path; } static public function makeAndCheckFile() { $args = func_get_args(); $path = call_user_func_array('self::make', $args); self::checkFile($path); return $path; } } namespace PhpPath; use PhpPath\Path; class P { static public function cd($path) { return Path::checkDirectory($path); } static public function cf($path) { return Path::checkFile($path); } static public function m() { return call_user_func_array(__NAMESPACE__ . '\Path::make', func_get_args()); } static public function mcd() { return call_user_func_array(__NAMESPACE__ . '\Path::makeAndCheckDirectory', func_get_args()); } static public function mcf() { return call_user_func_array(__NAMESPACE__ . '\Path::makeAndCheckFile', func_get_args()); } } namespace PhpPath; class NotExistsPathException extends \Exception { }