本文整理汇总了PHP中Cake\Filesystem\Folder::findRecursive方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::findRecursive方法的具体用法?PHP Folder::findRecursive怎么用?PHP Folder::findRecursive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\Folder
的用法示例。
在下文中一共展示了Folder::findRecursive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clean
/**
* @return int|null
*/
public function clean()
{
if (!empty($this->args[0])) {
$folder = realpath($this->args[0]);
} else {
$folder = APP;
}
$App = new Folder($folder);
$this->out('Cleaning copyright notices in ' . $folder);
$ext = '.*';
if (!empty($this->params['ext'])) {
$ext = $this->params['ext'];
}
$files = $App->findRecursive('.*\\.' . $ext);
$this->out('Found ' . count($files) . ' files.');
$count = 0;
foreach ($files as $file) {
$this->out('Processing ' . $file, 1, Shell::VERBOSE);
$content = $original = file_get_contents($file);
$content = preg_replace('/\\<\\?php\\s*\\s+\\/\\*\\*\\s*\\s+\\* CakePHP.*\\*\\//msUi', '<?php', $content);
if ($content === $original) {
continue;
}
$count++;
if (empty($this->params['dry-run'])) {
file_put_contents($file, $content);
}
}
$this->out('--------');
$this->out($count . ' files fixed.');
}
示例2: getTemplatesList
public function getTemplatesList($dir)
{
$basicDir = $dir . $this->subDir;
$dir = new Folder($basicDir);
$templatesList = array_map(function ($dirAddr) use($basicDir) {
return str_replace($basicDir . '/', '', $dirAddr);
}, $dir->findRecursive('.*\\.html'));
return array_combine($templatesList, $templatesList);
}
示例3: startCaching
/**
* startCaching method
*
* Cache\[optimize] images in cache folder
*
* @param string $optimization 'true' or 'false'
* @param string $srcPath folder name for source images
* @return void
*/
public function startCaching($optimization = 'true', $srcPath = 'src_images')
{
$dir = new Folder(WWW_ROOT . 'img' . DS . $srcPath);
$files = $dir->findRecursive('.*\\.(jpg|jpeg|png|gif|svg)');
/*
* Error handler
*/
if (is_null($dir->path)) {
$this->error('<red_text>Source folder not exists!</red_text>');
}
if ($optimization != 'true' && $optimization != 'false') {
$this->error('<red_text>Arguments \'optimization\' should equal \'true\' or \'false\'</red_text>');
}
/*
* Caching
*/
$counter = 1;
$countFiles = count($files);
$this->out('<info>Images caching</info>');
foreach ($files as $file) {
$file = new File($file);
$semanticType = explode(DS, $file->Folder()->path);
$semanticType = $semanticType[count($semanticType) - 1];
//get semantic type name
$this->adaptiveImagesController->passiveCaching($file->path, $semanticType);
$this->_io->overwrite($this->progressBar($counter, $countFiles), 0, 50);
$counter++;
}
/*
* Optimization
*/
if ($optimization == 'true') {
$cachePath = $this->adaptiveImagesController->getCachePath();
$pluginPath = Plugin::path('AdaptiveImages');
$cacheDir = new Folder($pluginPath . 'webroot' . DS . $cachePath);
$files = $cacheDir->findRecursive('.*\\.(jpg|jpeg|png|gif|svg)');
$counter = 1;
$countFiles = count($files);
$this->out('');
$this->out('<info>Images optimization</info>');
foreach ($files as $file) {
$this->_optimizeImage($file);
$this->_io->overwrite($this->progressBar($counter, $countFiles), 0, 50);
$counter++;
}
$this->hr();
$this->out('<green_text>Caching and optimization completed!</green_text>');
} elseif ($optimization == 'false') {
$this->hr();
$this->out('<green_text>Caching completed!</green_text>');
}
}
示例4: deleteFile
private function deleteFile(Attachment $attachment, $recursive = false)
{
$return = true;
$dir = new Folder(Configure::read('Upload.path') . $attachment->get('file_path'));
if ($recursive) {
$files = $dir->findRecursive($attachment->get('file_name') . '.*', true);
} else {
$files = $dir->find($attachment->get('file_name') . '.*');
}
foreach ($files as $file) {
$fileTmp = new File($file);
if ($fileTmp->exists()) {
if (!$fileTmp->delete()) {
$return = false;
}
} else {
$return = false;
}
}
return $return;
}
示例5: trim
/**
* Much like main() except files are modified. Be sure to have
* backups or use version control.
*
* @return void
*/
public function trim()
{
$path = APP;
if (!empty($this->params['path']) && strpos($this->params['path'], '/') === 0) {
$path = $this->params['path'];
} elseif (!empty($this->params['path'])) {
$path .= $this->params['path'];
}
$folder = new Folder($path);
$r = $folder->findRecursive('.*\\.php');
$this->out("Checking *.php in " . $path);
foreach ($r as $file) {
$c = file_get_contents($file);
if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c) || preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) {
$this->out('trimming' . $this->shortPath($file));
$c = preg_replace('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', '<?php', $c);
$c = preg_replace('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', '?>', $c);
file_put_contents($file, $c);
}
}
}
示例6: main
/**
* main method
*
* @param string $tempDir an other directory to clear of all folders and files, if desired
* @return void
*/
public function main($tempDir = null)
{
if (empty($tempDir)) {
$tempDir = Configure::read('Attachments.tmpUploadsPath');
}
if (!Folder::isAbsolute($tempDir)) {
$this->out('The path must be absolute, "' . $tempDir . '" given.');
exit;
}
$Folder = new Folder();
if ($Folder->cd($tempDir) === false) {
$this->out('Path "' . $tempDir . '" doesn\'t seem to exist.');
exit;
}
$dir = new Folder($tempDir);
$folders = $dir->read();
$files = $dir->findRecursive();
$deletedFiles = 0;
$deletedFolders = 0;
$this->out('Found ' . count($folders[0]) . ' folders and ' . count($files) . ' files');
foreach ($files as $filePath) {
$file = new File($filePath);
// only delete if last change is longer than 24 hours ago
if ($file->lastChange() < time() - 24 * 60 * 60 && $file->delete()) {
$deletedFiles++;
}
$file->close();
}
foreach ($folders[0] as $folderName) {
$folder = new Folder($dir->pwd() . $folderName);
// only delete if folder is empty
if ($folder->dirsize() === 0 && $folder->delete()) {
$deletedFolders++;
}
}
$this->out('Deleted ' . $deletedFolders . ' folders and ' . $deletedFiles . ' files.');
}
示例7: _generateFiles
/**
* Generate all files for a plugin
*
* Find the first path which contains `src/Template/Bake/Plugin` that contains
* something, and use that as the template to recursively render a plugin's
* contents. Allows the creation of a bake them containing a `Plugin` folder
* to provide customized bake output for plugins.
*
* @param string $pluginName the CamelCase name of the plugin
* @param string $path the path to the plugins dir (the containing folder)
* @return void
*/
protected function _generateFiles($pluginName, $path)
{
$namespace = str_replace('/', '\\', $pluginName);
$name = $pluginName;
$vendor = 'your-name-here';
if (strpos($pluginName, '/') !== false) {
list($vendor, $name) = explode('/', $pluginName);
}
$package = $vendor . '/' . $name;
$this->BakeTemplate->set(['package' => $package, 'namespace' => $namespace, 'plugin' => $pluginName, 'routePath' => Inflector::dasherize($pluginName), 'path' => $path, 'root' => ROOT]);
$root = $path . $pluginName . DS;
$paths = [];
if (!empty($this->params['theme'])) {
$paths[] = Plugin::path($this->params['theme']) . 'src/Template/';
}
$paths = array_merge($paths, Configure::read('App.paths.templates'));
$paths[] = Plugin::path('Bake') . 'src/Template/';
do {
$templatesPath = array_shift($paths) . 'Bake/Plugin';
$templatesDir = new Folder($templatesPath);
$templates = $templatesDir->findRecursive('.*\\.ctp');
} while (!$templates);
sort($templates);
foreach ($templates as $template) {
$template = substr($template, strrpos($template, 'Plugin') + 7, -4);
$this->_generateFile($template, $root);
}
}
示例8: _searchFiles
/**
* Search files that may contain translatable strings
*
* @return void
*/
protected function _searchFiles()
{
$pattern = false;
if (!empty($this->_exclude)) {
$exclude = [];
foreach ($this->_exclude as $e) {
if (DIRECTORY_SEPARATOR !== '\\' && $e[0] !== DIRECTORY_SEPARATOR) {
$e = DIRECTORY_SEPARATOR . $e;
}
$exclude[] = preg_quote($e, '/');
}
$pattern = '/' . implode('|', $exclude) . '/';
}
foreach ($this->_paths as $path) {
$path = realpath($path) . DIRECTORY_SEPARATOR;
$Folder = new Folder($path);
$files = $Folder->findRecursive('.*\\.(php|ctp|thtml|inc|tpl)', true);
if (!empty($pattern)) {
$files = preg_grep($pattern, $files, PREG_GREP_INVERT);
$files = array_values($files);
}
$this->_files = array_merge($this->_files, $files);
}
$this->_files = array_unique($this->_files);
}
示例9: buildAcos
/**
* This method should never be used unless you know what are you doing.
*
* Populates the "acos" DB with information of every installed plugin, or
* for the given plugin. It will automatically extracts plugin's controllers
* and actions for creating a tree structure as follow:
*
* - PluginName
* - Admin
* - PrivateController
* - index
* - some_action
* - ControllerName
* - index
* - another_action
*
* After tree is created you should be able to change permissions using
* User's permissions section in backend.
*
* @param string $for Optional, build ACOs for the given plugin, or all plugins
* if not given
* @param bool $sync Whether to sync the tree or not. When syncing all invalid
* ACO entries will be removed from the tree, also new ones will be added. When
* syn is set to false only new ACO entries will be added, any invalid entry
* will remain in the tree. Defaults to false
* @return bool True on success, false otherwise
*/
public static function buildAcos($for = null, $sync = false)
{
if (function_exists('ini_set')) {
ini_set('max_execution_time', 300);
} elseif (function_exists('set_time_limit')) {
set_time_limit(300);
}
if ($for === null) {
$plugins = plugin()->toArray();
} else {
try {
$plugins = [plugin($for)];
} catch (\Exception $e) {
return false;
}
}
$added = [];
foreach ($plugins as $plugin) {
if (!Plugin::exists($plugin->name)) {
continue;
}
$aco = new AcoManager($plugin->name);
$controllerDir = normalizePath("{$plugin->path}/src/Controller/");
$folder = new Folder($controllerDir);
$controllers = $folder->findRecursive('.*Controller\\.php');
foreach ($controllers as $controller) {
$controller = str_replace([$controllerDir, '.php'], '', $controller);
$className = $plugin->name . '\\' . 'Controller\\' . str_replace(DS, '\\', $controller);
$methods = static::_controllerMethods($className);
if (!empty($methods)) {
$path = explode('Controller\\', $className)[1];
$path = str_replace_last('Controller', '', $path);
$path = str_replace('\\', '/', $path);
foreach ($methods as $method) {
if ($aco->add("{$path}/{$method}")) {
$added[] = "{$plugin->name}/{$path}/{$method}";
}
}
}
}
}
if ($sync && isset($aco)) {
$aco->Acos->recover();
$existingPaths = static::paths($for);
foreach ($existingPaths as $exists) {
if (!in_array($exists, $added)) {
$aco->remove($exists);
}
}
$validLeafs = $aco->Acos->find()->select(['id'])->where(['id NOT IN' => $aco->Acos->find()->select(['parent_id'])->where(['parent_id IS NOT' => null])]);
$aco->Acos->Permissions->deleteAll(['aco_id NOT IN' => $validLeafs]);
}
return true;
}
示例10: listAvailibleTasksFiles
private function listAvailibleTasksFiles()
{
$dir = new Folder(ROOT . '/scripts');
$files = $dir->findRecursive('.*\\.kjb');
return array_combine($files, $files);
}
示例11: __getControllers
/**
* Get all controllers only from "Controller path only"
* TO DO: Implements Plugin path
*
* @return array return a list of all controllers
*/
private function __getControllers()
{
$path = App::path('Controller');
$dir = new Folder($path[0]);
$files = $dir->findRecursive('.*Controller\\.php');
$results = [];
foreach ($files as $file) {
$controller = str_replace(App::path('Controller'), '', $file);
$controller = explode('.', $controller)[0];
$controller = str_replace('Controller', '', $controller);
array_push($results, $controller);
}
return $results;
}
示例12: __getPluginsControllers
/**
* Get all controllers in Plugins only from "Controller path only"
* TO DO: Implements Plugin path
*
* @return array return a list of all controllers
*/
private function __getPluginsControllers()
{
$path = App::path('Controller');
$plugins = Plugin::loaded();
$dir = new Folder(ROOT . DS . "Plugins" . DS);
$files = $dir->findRecursive('.*Controller\\.php');
$results = [];
foreach ($files as $file) {
$controller = str_replace(ROOT . DS . "Plugins" . DS, '', $file);
$controller = explode('.', $controller)[0];
$controller = str_replace('Controller', '', $controller);
$controller = str_replace('src' . DS . DS, '', $controller);
array_push($results, $controller);
}
return $results;
}
示例13: eof
/**
* Whitespaces at the end of the file
* If PHP file with trailing ?> that will be removed as per coding standards.
*
* @return void
*/
public function eof()
{
if (!empty($this->args[0])) {
$folder = realpath($this->args[0]);
} else {
$folder = APP;
}
$App = new Folder($folder);
$this->out('Checking *.php in ' . $folder);
$files = $App->findRecursive('.*\\.php');
$this->out('Found ' . count($files) . ' files.');
$action = $this->in('Continue? [y]/[n]', ['y', 'n'], 'n');
if ($action !== 'y') {
return $this->error('Aborted');
}
foreach ($files as $file) {
$this->out('Processing ' . $file, 1, Shell::VERBOSE);
$content = $store = file_get_contents($file);
$content = trim($content);
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($ext === 'php' && substr($content, -2, 2) === '?>') {
$content = substr($content, 0, -2);
}
$newline = PHP_EOL;
$x = substr_count($content, "\r\n");
if ($x > 0) {
$newline = "\r\n";
} else {
$newline = "\n";
}
// add one new line at the end
$content = trim($content) . $newline;
if ($content !== $store) {
file_put_contents($file, $content);
}
}
$this->out('Done');
}
示例14: addAllControllers
/**
* Adds all controllers in app/controllers to the dependencies.
*
* Please use only in development mode!
*
* @return void
*/
public function addAllControllers()
{
$controllers = [];
// app/controllers/posts/*_controller.js
$folder = new \Cake\Filesystem\Folder(WWW_ROOT . 'js/app/controllers');
foreach ($folder->findRecursive('.*\\.js') as $file) {
$jsFile = '/' . str_replace(WWW_ROOT, '', $file);
$controllers[] = $jsFile;
}
// Add All Plugin Controllers
foreach (Plugin::loaded() as $pluginName) {
$pluginPath = Plugin::path($pluginName);
$pluginJsControllersFolder = $pluginPath . (substr($pluginPath, -1) === '/' ? '' : '/') . 'webroot/js/app/controllers/';
$pluginJsControllersFolder = str_replace('\\', '/', $pluginJsControllersFolder);
if (is_dir($pluginJsControllersFolder)) {
$this->_pluginJsNamespaces[] = $pluginName;
$folder = new \Cake\Filesystem\Folder($pluginJsControllersFolder);
$files = $folder->findRecursive('.*\\.js');
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
$file = str_replace($pluginJsControllersFolder, '', $file);
if ($this->_assetCompressMode) {
$controllers[] = 'plugin:' . $pluginName . ':js/app/controllers/' . $file;
} else {
$controllers[] = '/' . Inflector::underscore($pluginName) . '/js/app/controllers/' . $file;
}
}
}
}
// Move all controllers with base_ prefix to the top, so other controllers
// can inherit from them
foreach ($controllers as $n => $file) {
if (substr(basename($file), 0, 5) == 'base_') {
unset($controllers[$n]);
array_unshift($controllers, $file);
}
}
foreach ($controllers as $file) {
$this->_addDependency($file);
}
}
示例15: assertPluginContents
/**
* Check the baked plugin matches the expected output
*
* Compare to a static copy of the plugin in the comparison folder
*
* @param string $pluginName the name of the plugin to compare to
* @return void
*/
public function assertPluginContents($pluginName)
{
$pluginName = str_replace('/', DS, $pluginName);
$comparisonRoot = $this->_compareBasePath . $pluginName . DS;
$comparisonDir = new Folder($comparisonRoot);
$comparisonFiles = $comparisonDir->findRecursive();
$bakedRoot = $this->Task->path . $pluginName . DS;
$bakedDir = new Folder($bakedRoot);
$bakedFiles = $comparisonDir->findRecursive();
$this->assertSame(count($comparisonFiles), count($bakedFiles), 'A different number of files were created than expected');
foreach ($comparisonFiles as $file) {
$file = substr($file, strlen($comparisonRoot));
$result = file_get_contents($bakedRoot . $file);
$this->assertSameAsFile($pluginName . DS . $file, $result);
}
}