clean() public static method

Function to strip additional / or \ in a path name.
public static clean ( string $path, string $dirSep = DIRECTORY_SEPARATOR ) : string
$path string The path to clean.
$dirSep string Directory separator (optional).
return string
Exemplo n.º 1
0
 public function setUp()
 {
     $root = FS::clean(__DIR__ . '/test', '/');
     FS::rmdir($root);
     mkdir($root, 0777, true);
     $this->_root = $root;
 }
Exemplo n.º 2
0
 /**
  * Check action by path.
  *
  * @param string $path
  * @return bool
  */
 public function hasAction($path)
 {
     $action = explode('/', $path);
     $action = end($action);
     $details = explode('/', $path, 3);
     if (count($details) <= 2) {
         return false;
     }
     list($type, $vendor, $ns) = $details;
     if (Plugin::loaded($vendor) === true) {
         $vendor = FS::clean($vendor, '/');
         $nsDetails = explode('/', $ns);
         $type = $this->_currentType($type);
         unset($nsDetails[count($nsDetails) - 1]);
         $namespace = implode('/', $nsDetails);
         $namespace = FS::clean(implode('\\', [$vendor, $type, $namespace . $type]), '\\');
         return method_exists($namespace, $action);
     }
     $details = explode('/', $path, 2);
     list($type, $vendor) = $details;
     $type = $this->_currentType($type);
     $nsDetails = explode('/', FS::clean($vendor, '/'));
     unset($nsDetails[count($nsDetails) - 1]);
     $defVendor = Configure::read('App.namespace');
     $namespace = implode('/', $nsDetails);
     $namespace = FS::clean(implode('\\', [$defVendor, $type, $namespace . $type]), '\\');
     return method_exists($namespace, $action);
 }
Exemplo n.º 3
0
 /**
  * @return string
  */
 protected function _getResultFile()
 {
     // Normalize relative path
     $relPath = Slug::filter($this->_hash, '_');
     $relPath = Str::low($relPath);
     // Gett full clean path
     $fullPath = FS::real($this->_options->get('cache_path')) . '/' . $relPath . '.css';
     $fullPath = FS::clean($fullPath);
     return $fullPath;
 }
Exemplo n.º 4
0
 /**
  * Get current plugin name.
  *
  * @param string $plugin
  * @return string
  */
 public static function getName($plugin = 'Union/Core')
 {
     $plugin = FS::clean($plugin, '/');
     $name = $plugin;
     if (strpos($plugin, '/')) {
         list(, $name) = explode('/', $plugin);
         if (Str::low($name) == 'core') {
             $name = 'union';
         }
     }
     return Inflector::camelize($name);
 }
Exemplo n.º 5
0
Arquivo: Image.php Projeto: JBZoo/Html
 /**
  * Create img tag.
  *
  * @param string $src
  * @param string|array $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($src, $class = '', $id = '', array $attrs = array())
 {
     $attrs['class'] = false;
     $attrs = array_merge(array('fullUrl' => true), $attrs);
     $attrs['id'] = $id;
     $attrs = $this->_normalizeClassAttr($attrs, $this->_jbSrt('image'));
     if ($class !== '') {
         $attrs = $this->_normalizeClassAttr($attrs, $class);
     }
     $attrs['class'] = Str::clean($attrs['class']);
     $isFull = $attrs['fullUrl'];
     unset($attrs['fullUrl']);
     $src = FS::clean($src, '/');
     $attrs['src'] = $isFull ? Url::root() . '/' . $src : $src;
     return '<img ' . $this->buildAttrs($attrs) . ' />';
 }
Exemplo n.º 6
0
 /**
  * Find theme path.
  *
  * @param string $name
  * @return null|string
  */
 protected static function _find($name)
 {
     $paths = App::path('Plugin');
     foreach ($paths as $path) {
         $path = FS::clean($path . '/', DS);
         $details = explode(DS, rtrim($path, DS));
         $folder = Str::trim(array_pop($details));
         $themeFolder = $path . $name;
         if (Arr::in($folder, self::$_skipFolder) || !FS::isDir($themeFolder)) {
             $themeFolder .= self::POSTFIX;
         }
         if (FS::isDir($themeFolder)) {
             return $themeFolder;
         }
     }
     return null;
 }
Exemplo n.º 7
0
Arquivo: Less.php Projeto: jbzoo/less
 /**
  * @param array $options
  * @return Data
  * @throws Exception
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 protected function _prepareOptions(array $options)
 {
     // Default data for current system
     $this->_default['root_url'] = Url::root();
     $this->_default['root_path'] = Sys::getDocRoot();
     $options = array_merge($this->_default, $options);
     // Check cache directory
     $cachePath = FS::clean($options['cache_path']);
     if (!$cachePath) {
         throw new Exception('Option "cache_path" is empty!');
     }
     if (!FS::isDir($cachePath)) {
         mkdir($cachePath, 0755, true);
     }
     $options['cache_path'] = FS::real($cachePath);
     $options['root_url'] = rtrim($options['root_url'], '/');
     $options['root_path'] = FS::real($options['root_path']);
     $options['driver'] = ucfirst(strtolower(trim($options['driver'])));
     // Check mixin paths
     $lessFile = (array) $options['autoload'];
     foreach ($lessFile as $key => $mixin) {
         $lessFile[$key] = FS::real($mixin);
     }
     $options['autoload'] = array_filter($lessFile);
     // Check imported paths
     $importPaths = [];
     foreach ((array) $options['import_paths'] as $path => $uri) {
         if ($cleanPath = FS::real($path)) {
             $importPaths[$cleanPath] = $uri;
         }
     }
     $importPaths[$options['root_path']] = $options['root_url'];
     // Forced add root path in the end of list!
     $options['import_paths'] = array_filter($importPaths);
     return new Data($options);
 }
Exemplo n.º 8
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_executePrepare($input, $output);
     $this->_init();
     $this->_setupConfigure();
     $this->_jbyml->init();
     $totalItems = $this->_jbyml->getTotal();
     $filePath = $this->_getFilePath() . '/' . $this->_getProfFileName() . '.xml';
     $fullPath = FS::clean(JBZOO_CLI_JOOMLA_ROOT . '/' . $filePath);
     $stepMode = $this->_getOpt('stepmode');
     $stepSize = $this->_config->find('params.step_size', 25);
     $this->_showProfiler('YML Export - prepared');
     $this->_('YML File: ' . $fullPath, 'Info');
     $this->_('Total items: ' . $totalItems, 'Info');
     $this->_('Step size: ' . $stepSize, 'Info');
     $this->_('Step mode: ' . ($stepMode ? 'on' : 'off'), 'Info');
     $this->_progressWrap($this->_commandName, $totalItems, $stepSize, function () use($totalItems, $stepSize) {
         $this->_jbyml->renderStart();
         $this->_progressBar('yml-export', $totalItems, $stepSize, function ($currentStep, $stepSize) {
             $offset = $stepSize * $currentStep;
             $this->_jbyml->exportItems($offset, $stepSize);
         });
         return true;
     }, function ($step) use($stepSize) {
         $offset = $stepSize * $step;
         if ($step == 0) {
             $this->_jbyml->renderStart();
         }
         $this->_jbyml->exportItems($offset, $stepSize);
     }, function ($isFinished) {
         if ($isFinished) {
             $this->_jbyml->renderFinish();
             $this->_showProfiler('Import - finished');
         }
     });
 }
Exemplo n.º 9
0
Arquivo: Text.php Projeto: JBZoo/Image
 /**
  * Determine textbox size
  *
  * @param string $fontSize
  * @param int    $angle
  * @param string $fontFile
  * @param string $text
  * @return array
  *
  * @throws Exception
  */
 protected static function _getTextboxSize($fontSize, $angle, $fontFile, $text)
 {
     // Determine textbox size
     $fontPath = FS::clean($fontFile);
     if (!FS::isFile($fontPath)) {
         throw new Exception('Unable to load font: ' . $fontFile);
     }
     $box = imagettfbbox($fontSize, $angle, $fontFile, $text);
     $boxWidth = abs($box[6] - $box[2]);
     $boxHeight = abs($box[7] - $box[1]);
     return array($boxWidth, $boxHeight);
 }
Exemplo n.º 10
0
/**
 * Normilize paths and compare them
 *
 * @param string $expected
 * @param string $actual
 * @param string $message
 * @throws Exception
 */
function isSamePath($expected, $actual, $message = null)
{
    if (!class_exists('\\JBZoo\\Utils\\Filter')) {
        throw new Exception('jbzoo/utils required for isSamePath() function');
    }
    $cleanFunc = function ($paths) {
        $return = array();
        $paths = (array) $paths;
        foreach ($paths as $key => $path) {
            $return[$key] = FS::clean($path, '/');
        }
        return $return;
    };
    $expected = Filter::_($expected, $cleanFunc);
    $actual = Filter::_($actual, $cleanFunc);
    isSame($expected, $actual, $message);
}
Exemplo n.º 11
0
 /**
  * Auto include plugin assets.
  *
  * @return void
  */
 protected function _autoAssets()
 {
     $path = 'assets';
     $request = $this->request;
     $prefix = $request->param('prefix') ? $request->param('prefix') . '/' : null;
     if ($plugin = (string) $request->param('plugin')) {
         $path = $plugin . ':assets';
     }
     $this->Html->less(FS::clean($path . '/less/' . $prefix . '/styles.less'), ['block' => 'css_bottom']);
     $this->Html->css(FS::clean($path . '/css/' . $prefix . '/styles.css'), ['fullBase' => true, 'block' => 'css_bottom']);
     $this->Html->script(FS::clean($path . '/js/' . $prefix . '/scripts.js'), ['fullBase' => true, 'block' => 'script_bottom']);
 }
Exemplo n.º 12
0
 public function testHasCDBack()
 {
     $path = Path::getInstance(__METHOD__);
     $paths = array($this->_root, $this->_root . '/..', $this->_root . '/../../');
     $path->set('default', $paths);
     list($path1, $path2, $path3) = $paths;
     $expected = array(realpath(FS::clean($path3)), realpath(FS::clean($path2)), FS::clean($path1, '/'));
     $this->_is($expected, $path->getPaths('default'));
 }
Exemplo n.º 13
0
 /**
  * Preg replace callback url.
  *
  * @param $match
  * @return null|string
  */
 protected function _replaceUrlCallback($match)
 {
     $path = FS::clean($match[2], '/');
     if (isset($path[2]) && $path[2] == ':') {
         $path = ltrim($match[2], '/');
     }
     $url = null;
     if (FS::isFile($path)) {
         $url = $this->_path->url($path);
     }
     return $this->_getAssetUrl($url);
 }
Exemplo n.º 14
0
 /**
  * @param $filename
  * @return string
  */
 public static function getOrig($filename)
 {
     return FS::clean(PROJECT_TESTS . '/resources/' . $filename);
 }
Exemplo n.º 15
0
 /**
  * Get node ref path by request.
  *
  * @return string
  */
 protected function _getNodeRef()
 {
     $ref = ['type' => 'controllers', 'plugin' => null, 'prefix' => Inflector::camelize($this->_request->param('prefix')), 'controller' => $this->_request->param('controller')];
     if ($this->_request->param('plugin') !== false) {
         $ref['plugin'] = FS::clean($this->_request->param('plugin'), '\\');
         return implode('/', $ref);
     }
     return FS::clean(implode('/', $ref), '/');
 }
Exemplo n.º 16
0
 /**
  * Return all possible paths to find view files in order.
  *
  * @param null|string $plugin
  * @param bool $cached
  * @return array
  */
 protected function _paths($plugin = null, $cached = true)
 {
     $paths = [];
     $arrayPaths = parent::_paths($plugin, $cached);
     foreach ($arrayPaths as $_path) {
         $paths[] = FS::clean($_path);
     }
     if ($plugin !== null) {
         return $this->_pathsForPlugin[$plugin] = $paths;
     }
     return $this->_paths = $paths;
 }
Exemplo n.º 17
0
 public function testGetRoot()
 {
     $dir = __DIR__;
     $path = new Path();
     $path->setRoot($dir);
     $manager = new Manager($path);
     isSame(FS::clean($dir), FS::clean($manager->getPath()->getRoot()));
 }
Exemplo n.º 18
0
 /**
  * Load an image
  *
  * @param string $filename Path to image file
  * @return $this
  *
  * @throws Exception
  */
 public function loadFile($filename)
 {
     $cleanFilename = FS::clean($filename);
     if (!FS::isFile($cleanFilename)) {
         throw new Exception('Image file not forund: ' . $filename);
     }
     $this->cleanup();
     $this->_filename = $cleanFilename;
     $this->_loadMeta();
     return $this;
 }
Exemplo n.º 19
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_executePrepare($input, $output);
     $this->_init();
     $this->_setupConfigure();
     $stepMode = $this->_getOpt('stepmode');
     $profileName = $this->_getOpt('profile');
     $config = $this->_jbconfig->getList('export.items');
     $stepSize = (int) $this->_config->find('params.step_limit', '100');
     $totalItems = $this->_getTotal();
     $this->_showProfiler('CSV Export - prepared');
     $this->_('Step size: ' . $stepSize, 'Info');
     $this->_('Total items: ' . $totalItems, 'Info');
     $this->_('Step mode: ' . ($stepMode ? 'on' : 'off'), 'Info');
     $this->_progressWrap($this->_commandName, $totalItems, $stepSize, function () use($config, $totalItems, $stepSize) {
         $this->_jbexport->clean();
         $this->_progressBar($this->_commandName, $totalItems, $stepSize, function ($currentStep) use($config) {
             $this->_toCSV($currentStep);
         });
         return true;
     }, function ($step) use($config) {
         $this->_toCSV($step);
     }, function ($isFinished) use($config, $profileName) {
         if ($isFinished && ($compressFiles = $this->_jbexport->splitFiles())) {
             $exportPath = $this->_jbpath->sysPath('tmp', '/' . \JBExportHelper::EXPORT_PATH);
             //  Move CSV file to config path.
             foreach ($compressFiles as $file) {
                 $fileName = basename($file);
                 $dir = JBZOO_CLI_JOOMLA_ROOT . '/' . $config->get('file_path');
                 $newFile = FS::clean($dir . '/' . $profileName . '-' . $fileName, '/');
                 \JFile::move($file, $newFile);
                 $this->_('CSV File: ' . $newFile, 'Info');
             }
             //  Delete export tmp folder.
             if (\JFolder::exists($exportPath)) {
                 \JFolder::delete($exportPath);
             }
         }
         $this->_showProfiler('Export - finished');
     });
 }
Exemplo n.º 20
0
Arquivo: Path.php Projeto: JBZoo/Path
 /**
  * Forced clean path with linux-like sleshes
  *
  * @param string $path
  * @return string
  */
 protected function _clean($path)
 {
     return FS::clean($path, '/');
 }
Exemplo n.º 21
0
 public function testClean()
 {
     $dirSep = DIRECTORY_SEPARATOR;
     $empty = Vars::get($_SERVER['DOCUMENT_ROOT'], '');
     isSame($empty, FS::clean(''));
     isSame($empty, FS::clean(false));
     isSame($empty, FS::clean(null));
     isSame('path', FS::clean('path'));
     isSame("{$dirSep}path", FS::clean('/path'));
     isSame("{$dirSep}path", FS::clean(' /path '));
     isSame("{$dirSep}path{$dirSep}", FS::clean('/path/'));
     isSame("{$dirSep}path{$dirSep}", FS::clean('///path///'));
     isSame("{$dirSep}path{$dirSep}path", FS::clean('///path///path'));
     isSame("{$dirSep}path{$dirSep}path{$dirSep}path", FS::clean('///path///path/path'));
     isSame("{$dirSep}path{$dirSep}path{$dirSep}path{$dirSep}", FS::clean('\\path\\path\\path\\\\\\\\'));
     isSame('\\path\\path\\path\\', FS::clean('\\path\\path\\path\\\\\\\\', '\\'));
     isSame('\\path\\path\\path\\', FS::clean('\\path\\path\\path\\\\\\\\', '\\'));
     isSame('\\\\path\\path\\path\\', FS::clean('\\\\path\\path\\path\\\\\\\\', '\\'));
     isSame('../../path/', FS::clean('..///..///path/', '/'));
     isSame('./../path/', FS::clean('.///..///path/', '/'));
     isSame('/../../path/', FS::clean('/..///..///path/', '/'));
 }