public function _write($file, $text) { $text = implode(PHP_EOL, $text); if ($this->settings['outputToTmp']) { $filename = extractPathInfo('file', $file); if (mb_substr($filename, -1, 1) == '_') { return; } $file = extractPathInfo('dir', $file) . DS . $filename . '_.' . extractPathInfo('ext', $file); } return file_put_contents($file, $text); }
/** * @deprecated * now use: Configure::listObjects() */ function __getFiles($folder) { $handle = new Folder($folder); $handleFiles = $handle->read(true, true); $files = $handleFiles[1]; foreach ($files as $key => $file) { $file = extractPathInfo('file', $file); if (mb_strrpos($file, '_') === mb_strlen($file) - 1) { # ending with _ like test_.php unset($files[$key]); } else { $files[$key] = Inflector::camelize($file); } } return $files; }
function main() { $this->out('Install/Manage Tools'); $this->out(''); $this->out('Usage:'); $this->out('- cake install Tool {params}'); $this->out('- cake uninstall Tool {params}'); $this->out(''); $this->out('Tools:'); $this->_getFiles(); foreach ($this->files as $file) { $this->out('- ' . Inflector::camelize(extractPathInfo('file', $file))); } $this->out(''); $this->out('Params:'); $this->out('-f => Force Reinstall (Drop + Create)'); $this->out('-s => Status (TODO!)'); }
protected function _icons() { $useCache = true; if (!empty($this->request->params['named']['reset'])) { $useCache = false; } if ($useCache && ($iconNames = Cache::read('country_icon_names')) !== false) { $this->Flash->info('Cache Used'); return $iconNames; } $handle = new Folder($this->imageFolder); $icons = $handle->read(true, true); $iconNames = []; foreach ($icons[1] as $icon) { # only use files (not folders) $iconNames[] = strtoupper(extractPathInfo('filename', $icon)); } Cache::write('country_icon_names', $iconNames); return $iconNames; }
/** * Focus is on the filename (without path) * * @deprecated Use native method instead * * @param string $filename to check on * @param string|null $type (extension/ext, filename/file, basename/base, dirname/dir) * @return mixed */ function extractFileInfo($filename, $type = null) { $info = extractPathInfo($filename, $type); if ($info) { return $info; } $pos = strrpos($filename, '.'); $res = ''; switch ($type) { case 'extension': case 'ext': $res = $pos !== false ? substr($filename, $pos + 1) : ''; break; case 'filename': case 'file': $res = $pos !== false ? substr($filename, 0, $pos) : ''; break; default: break; } return $res; }
/** * Custom Icons * * @param string $icon (constant or filename) * @param array $options: * - translate, ... * @param array $attributes: * - title, alt, ... * THE REST IS DEPRECATED * @return string */ public function cIcon($icon, $t = null, $a = null, $translate = true, $options = array()) { if (is_array($t)) { $translate = isset($t['translate']) ? $t['translate'] : true; $options = (array) $a; $a = isset($t['alt']) ? $t['alt'] : null; // deprecated $t = isset($t['title']) ? $t['title'] : null; // deprecated } $type = extractPathInfo('filename', $icon); if (!$this->settings['fontIcons'] || !isset($this->settings['fontIcons'][$type])) { $title = isset($t) ? $t : ucfirst($type); $alt = isset($a) ? $a : Inflector::slug($title, '-'); if ($translate !== false) { $title = __($title); $alt = __($alt); } $alt = '[' . $alt . ']'; $defaults = array('title' => $title, 'alt' => $alt, 'class' => 'icon'); $options += $defaults; if (substr($icon, 0, 1) !== '/') { $icon = 'icons/' . $icon; } return $this->Html->image($icon, $options); } $options['title'] = $t; $options['translate'] = $translate; return $this->_fontIcon($type, $options); }
/** * custom Icons * @param string $icon (constant or filename) * @param array $options: * - translate, ... * @param array $attributes: * - title, alt, ... * THE REST IS DEPRECATED * 2010-03-04 ms */ public function cIcon($icon, $t = null, $a = null, $translate = true, $options = array()) { if (is_array($t)) { $translate = isset($t['translate']) ? $t['translate'] : true; $options = (array) $a; $a = isset($t['alt']) ? $t['alt'] : null; # deprecated $t = isset($t['title']) ? $t['title'] : null; # deprecated } $title = isset($t) ? $t : ucfirst(extractPathInfo('filename', $icon)); //$alt = (isset($a)?$a:preg_replace('/[^a-zA-Z0-9]/', '', $title)); $alt = isset($a) ? $a : Inflector::slug($title, '-'); if ($translate !== false) { $title = __($title); $alt = __($alt); } $alt = '[' . $alt . ']'; $defaultOptions = array('title' => $title, 'alt' => $alt, 'class' => 'icon'); $options = array_merge($defaultOptions, $options); if (substr($icon, 0, 1) !== '/') { $icon = 'icons/' . $icon; } return $this->Html->image($icon, $options); }
/** * BootstrapTest::testExtractPathInfo() * * @return void */ public function testExtractPathInfo() { $result = extractPathInfo('somefile.jpg', 'ext'); $this->assertEquals('jpg', $result); $result = extractPathInfo('somefile.jpg', 'base'); $this->assertEquals('somefile.jpg', $result); $result = extractPathInfo('somefile.jpg', 'file'); $this->assertEquals('somefile', $result); $result = extractPathInfo('somefile.jpg?foo=bar#something', 'ext', true); $this->assertEquals('jpg', $result); }
/** * Tokenize a specific file like `/path/to/file.ext`. * Creates a file `/path/to/file.ext.token` with all token names * added in comment lines. * * @return void */ public function tokenize() { if (!empty($this->args)) { $path = $this->args[0]; $path = realpath($path); } if (empty($path) || !is_file($path)) { $this->error('Please select a path to a file'); } $_SERVER['argv'] = []; $_SERVER['argv'][] = '--encoding=utf8'; $standard = $this->standard; if ($this->params['standard']) { $standard = $this->params['standard']; } $_SERVER['argv'][] = '--standard=' . $standard; $_SERVER['argv'][] = $path; $_SERVER['argc'] = count($_SERVER['argv']); $res = []; $tokens = $this->_getTokens($path); $array = file($path); foreach ($array as $key => $row) { $res[] = rtrim($row); if ($tokenStrings = $this->_tokenize($key + 1, $tokens)) { foreach ($tokenStrings as $string) { $res[] = '// ' . $string; } } } $content = implode(PHP_EOL, $res); $this->out('Tokenizing: ' . $path); $newPath = dirname($path) . DS . extractPathInfo('basename', $path) . '.token'; file_put_contents($newPath, $content); $this->out('Filename: ' . $newPath); }