本文整理汇总了PHP中Folder::findRecursive方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::findRecursive方法的具体用法?PHP Folder::findRecursive怎么用?PHP Folder::findRecursive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::findRecursive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Find all defined callbacks in the app or other plugins
*
* @param undefined $cached
* @return void
* @access public
*/
public function load()
{
$cached = Cache::read('_plugin_callbacks_', '_cake_models_');
if ($cached !== false) {
$this->settings = $cached;
return $cached;
}
App::import('Folder');
$Folder = new Folder($this->path . 'plugins');
$folders = current($Folder->ls());
$files = array();
foreach ($folders as $folder) {
if ($Folder->cd($this->path . 'models' . DS . 'callbacks')) {
$files = $Folder->findRecursive('([a-z_]+)_' . $folder . '.php');
}
$files = array_flip($files);
foreach ($folders as $_folder) {
if ($Folder->cd($this->path . 'plugins' . DS . $_folder . DS . 'models' . DS . 'callbacks')) {
$files = array_merge($files, array_flip($Folder->findRecursive('([a-z_]+)_' . $folder . '.php')));
}
}
foreach (array_keys($files) as $k => $file) {
if (!preg_match_all('/models\\/callbacks\\/([a-z_]+)_' . $folder . '\\.php/i', $file, $matches)) {
continue;
}
$plugin = current($matches[1]);
if (empty($plugin)) {
$plugin = 'app';
}
$callbackName = Inflector::camelize(sprintf('%s_%s', $plugin, $folder));
$this->settings[$folder][$plugin] = $callbackName;
}
}
Cache::write('_plugin_callbacks_', $this->settings, '_cake_models_');
}
示例2: read
function read($dir = null, $recursive = false)
{
$notes = array();
$path = CORE_PATH . APP_PATH . $dir;
$folder = new Folder(APP_PATH . $dir);
$fold = $recursive ? $folder->findRecursive('.*\\.php') : $folder->find('.*\\.php');
foreach ($fold as $file) {
$file = $recursive ? $file : $path . $file;
$file_path = r(CORE_PATH . APP_PATH, '', $file);
$handle = new File($file_path);
$content = $handle->read();
$lines = explode(PHP_EOL, $content);
//$lines = file($file);
$ln = 1;
if (!empty($lines)) {
foreach ($lines as $line) {
if ((is_null($this->type) || $this->type == 'TODO') && preg_match("/[#\\*\\/\\/]\\s*TODO\\s*(.*)/", $line, $match)) {
$this->notes[$file_path]['TODO'][$ln] = $match[1];
}
if ((is_null($this->type) || $this->type == 'OPTIMIZE') && preg_match("/[#\\*\\/\\/]\\s*OPTIMIZE|OPTIMISE\\s*(.*)/", $line, $match)) {
$this->notes[$file_path]['OPTIMIZE'][$ln] = $match[1];
}
if ((is_null($this->type) || $this->type == 'FIXME') && preg_match("/[#\\*\\/\\/]\\s*FIXME|BUG\\s*(.*)/", $line, $match)) {
$this->notes[$file_path]['FIXME'][$ln] = $match[1];
}
$ln++;
}
}
}
return $this->notes;
}
示例3: create
function create()
{
$dir = new Folder(APP);
$files = $dir->findRecursive('.*');
$data_array = array();
foreach ($files as $file) {
$file_parts = pathinfo($file);
if (isset($file_parts['extension']) && ($file_parts['extension'] == "php" || $file_parts['extension'] == "ctp")) {
$data = file_get_contents($file);
$pattern = "~(__\\('|__\\(\")(.*?)(\\'\\)|\",|\\',|\"\\)|\" \\)|\\' \\))~";
preg_match_all($pattern, $data, $matches);
$data_array = array_filter(array_merge($data_array, $matches[2]));
}
}
$data_array = array_unique($data_array);
pr($data_array);
$filename = 'adefault.po';
$file = new File(APP . "/Locale" . DS . $filename);
foreach ($data_array as $string) {
$file->write('msgid "' . $string . '"' . "\n");
$file->write('msgstr "' . $string . '"' . "\n\n");
echo $string;
}
$file->close();
die;
}
示例4: main
/**
* Truncates all tables and loads fixtures into db
*
* @return void
* @access public
*/
function main()
{
if (!empty($this->args)) {
if ($this->args[0] == 'chmod') {
return $this->chmod();
}
$fixtures = $this->args;
foreach ($fixtures as $i => $fixture) {
$fixtures[$i] = APP . 'tests/fixtures/' . $fixture . '_fixture.php';
}
} else {
App::import('Folder');
$Folder = new Folder(APP . 'tests/fixtures');
$fixtures = $Folder->findRecursive('.+_fixture\\.php');
}
$db = ConnectionManager::getDataSource('default');
$records = 0;
foreach ($fixtures as $path) {
require_once $path;
$name = str_replace('_fixture.php', '', basename($path));
$class = Inflector::camelize($name) . 'Fixture';
$Fixture =& new $class($db);
$this->out('-> Truncating table "' . $Fixture->table . '"');
$db->truncate($Fixture->table);
$Fixture->insert($db);
$fixtureRecords = count($Fixture->records);
$records += $fixtureRecords;
$this->out('-> Inserting ' . $fixtureRecords . ' records for "' . $Fixture->table . '"');
}
$this->out(sprintf('-> Done inserting %d records for %d tables', $records, count($fixtures)));
}
示例5: main
public function main()
{
$App = new Folder(APP);
$r = $App->findRecursive('.*\\.php');
$this->out("Checking *.php in " . APP);
$folders = array();
foreach ($r as $file) {
$error = '';
$action = '';
$c = file_get_contents($file);
if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c)) {
$error = 'leading';
}
if (preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) {
$error = 'trailing';
}
if (!empty($error)) {
$this->report[$error][0]++;
$this->out('');
$this->out('contains ' . $error . ' whitespaces: ' . $this->shortPath($file));
if (!$this->autoCorrectAll) {
$dirname = dirname($file);
if (in_array($dirname, $folders)) {
$action = 'y';
}
while (empty($action)) {
//TODO: [r]!
$action = $this->in(__('Remove? [y]/[n], [a] for all in this folder, [r] for all below, [*] for all files(!), [q] to quit'), array('y', 'n', 'r', 'a', 'q', '*'), 'q');
}
} else {
$action = 'y';
}
if ($action == '*') {
$action = 'y';
$this->autoCorrectAll = true;
} elseif ($action == 'a') {
$action = 'y';
$folders[] = $dirname;
$this->out('All: ' . $dirname);
}
if ($action == 'q') {
die('Abort... Done');
} elseif ($action == 'y') {
if ($error == 'leading') {
$res = preg_replace('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', '<?php', $c);
} else {
//trailing
$res = preg_replace('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', '?>', $c);
}
file_put_contents($file, $res);
$this->report[$error][1]++;
$this->out('fixed ' . $error . ' whitespaces: ' . $this->shortPath($file));
}
}
}
# report
$this->out('--------');
$this->out('found ' . $this->report['leading'][0] . ' leading, ' . $this->report['trailing'][0] . ' trailing ws');
$this->out('fixed ' . $this->report['leading'][1] . ' leading, ' . $this->report['trailing'][1] . ' trailing ws');
}
示例6: main
/**
* Main worker
*
* @return void
*/
public function main()
{
if (empty($this->args)) {
$this->error("Require at least one file path");
die;
}
foreach ($this->args as $input) {
$path = $this->getPath($input);
if (empty($path)) {
$this->error("Unable to find {$input}");
die;
}
if (is_file($path)) {
$files = array($path);
}
if (is_dir($path)) {
$dir = new Folder($path);
$files = $dir->findRecursive('.*\\.php$');
}
if (empty($files)) {
$this->error("Invalid file type {$path}");
die;
}
foreach ($files as $file) {
$this->out($file);
PhpTidy::file($file);
}
}
}
示例7: upload
function upload()
{
$directory = $this->getNextParam(null, 'path');
$container = $this->getNextParam(null, 'container');
if (empty($directory) || empty($container)) {
$this->errorAndExit('Directory and Container required');
}
$Folder = new Folder($directory);
if ($this->params['recursive']) {
$files = $Folder->findRecursive();
} else {
$single_files = $Folder->find();
$files = array();
foreach ($single_files as $file) {
$files[] = $Folder->pwd() . DS . $file;
}
}
$this->ProgressBar->start(count($files));
foreach ($files as $file) {
CloudFiles::upload($file, $container);
$this->ProgressBar->next();
}
$this->out();
$this->out("Finished.");
}
示例8: execute
public function execute()
{
// I18nProfile class: http://stackoverflow.com/questions/8433686/is-there-a-php-library-for-parsing-gettext-po-pot-files
App::import('Lib', 'I18nJs.PoParser');
$dir = new Folder(APP . 'Locale');
$locales = $dir->read();
foreach ($locales[0] as $localeDir) {
$msgids = array();
$language = $localeDir;
$localeDir = new Folder(APP . 'Locale' . DS . $localeDir);
$files = $localeDir->findRecursive('i18n_js.*\\.po');
// Loop over PO i18n_js PO files
foreach ($files as $file) {
$file = new File($file);
// Get language
if (preg_match('%Locale/(.*?)/LC_MESSAGES%', $file->path, $regs)) {
$language = $regs[1];
} else {
// todo return
$this->out(__d('i18n_js', '<error>Unable to determine language of PO file:</error>') . $file->path);
return;
}
// Get context, domain
$context = '';
if (strpos($file->name(), '.')) {
$context = explode('.', $file->name());
$context = $context[1];
}
// Parse PO file
$poparser = new \Sepia\PoParser();
$translations = $poparser->parse($file->path);
foreach ($translations as $key => $translation) {
if (empty($key)) {
continue;
}
if (is_array($translation['msgid'])) {
$translation['msgid'] = implode('', $translation['msgid']);
}
if (is_array($translation['msgstr'])) {
$translation['msgstr'] = implode('', $translation['msgstr']);
}
$msgids[$context][$translation['msgid']] = $translation['msgstr'];
}
}
if (empty($msgids)) {
continue;
}
// Write JS file
$outputFile = new File(WWW_ROOT . 'js' . DS . 'Locale' . DS . 'i18n_js.' . $language . '.js', true);
$data = "I18nJs.locale = { ";
$data .= "'pluralFormula': function (\$n) { return Number((\$n != 1)); }, ";
$data .= "'strings': " . json_encode($msgids, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) . " };";
if ($outputFile->write($data)) {
$this->out(__d('i18n_js', '<info>%s created</info>', $outputFile->path));
} else {
$this->out(__d('i18n_js', '<error>Unable to write: %s</error>', $outputFile->path));
}
}
}
示例9: _collectFiles
/**
* Collects the files to scan and generate build files for.
*
* @param array $paths
*/
protected function _collectFiles($paths)
{
foreach ($paths as $path) {
$Folder = new Folder($path);
$files = $Folder->findRecursive('.*\\.(ctp|thtml|inc|tpl)', true);
$this->_files = array_merge($this->_files, $files);
}
}
示例10: testRunAllTests
/**
* testRunAllTests method
*
* @return void
* @access public
*/
function testRunAllTests()
{
$folder = new Folder($this->Sut->_getTestsPath());
$extension = str_replace('.', '\\.', TestManager::getExtension('test'));
$out = $folder->findRecursive('.*' . $extension);
$reporter = new CakeHtmlReporter();
$list = TestManager::runAllTests($reporter, true);
$this->assertEqual(count($out), count($list));
}
示例11: fileList
/**
* Recursive Read a path and return files and folders not in the excluded Folder list
*
* @param string $path The path you wish to read.
* @return array
**/
public function fileList($path)
{
$this->_Folder->cd($path);
$filePattern = $this->fileRegExp . '\\.' . implode('|', $this->allowedExtensions);
$contents = $this->_Folder->findRecursive($filePattern);
$this->_filterFolders($contents);
$this->_filterFiles($contents);
return $contents;
}
示例12: getPrototypes
public function getPrototypes()
{
$searchdirs['App'] = APP . 'View';
$searchdirs['Basic'] = CakePlugin::path('Muffin');
foreach (CakePlugin::loaded() as $plugin) {
if ($plugin != 'Muffin') {
$searchdirs[$plugin] = CakePlugin::path($plugin) . 'View';
}
}
$configs = array();
foreach ($searchdirs as $plugin => $searchdir) {
$dir = new Folder($searchdir, false);
if ($files = $dir->findRecursive('config.xml')) {
$configs = Hash::merge($configs, array($plugin => $files));
}
}
$prototypes = array();
foreach ($configs as $plugin => $configFiles) {
$i = 0;
foreach ($configFiles as $configFile) {
$xml = Xml::build($configFile);
$items = $xml->xpath('menu/item');
if (!is_array($items) || empty($items)) {
continue;
}
foreach ($items as $item) {
$item = Xml::toArray($item);
if (empty($item['item']['@label'])) {
continue;
}
if (!isset($item['item']['@id']) || empty($item['item']['@id'])) {
$id = ucfirst(Inflector::variable($item['item']['@label']));
} else {
$id = $item['item']['@id'];
}
$fields = array();
foreach ($item['item']['field'] as $key => $field) {
foreach ($field as $name => $value) {
$name = str_replace('@', '', $name);
$fields[$key][$name] = $value;
}
}
$prototypes[$plugin][$i]['Link']['id'] = $id;
$prototypes[$plugin][$i]['Link']['priority'] = !empty($item['item']['@priority']) ? $item['item']['@priority'] : '10';
$prototypes[$plugin][$i]['Link']['model'] = !empty($item['item']['@model']) ? $item['item']['@model'] : '';
$prototypes[$plugin][$i]['Link']['label'] = $item['item']['@label'];
$prototypes[$plugin][$i]['Field'] = $fields;
$i++;
}
}
}
foreach ($prototypes as $plugin => $section) {
$prototypes[$plugin] = Hash::sort($section, '{n}.Link.priority', 'asc');
}
return $prototypes;
}
示例13: NoCrossContaminationGroupTest
/**
* NoCrossContaminationGroupTest method
*
* @access public
* @return void
*/
function NoCrossContaminationGroupTest()
{
App::import('Core', 'Folder');
$Folder = new Folder(CORE_TEST_CASES);
foreach ($Folder->findRecursive('.*\\.test\\.php', true) as $file) {
if (in_array(basename($file), $this->blacklist)) {
continue;
}
TestManager::addTestFile($this, $file);
}
}
示例14: tests
function tests()
{
$path = TESTS . 'cases';
$Folder = new Folder($path);
$cases = $Folder->findRecursive('.*\\.test\\.php');
foreach ($cases as $i => $case) {
$case = str_replace($path, '', $case);
$case = str_replace('.test.php', '', $case);
$cases[$i] = trim($case, DS);
}
return array('cases' => $cases);
}
示例15: trim
/**
* Much like main() except files are modified. Be sure to have
* backups or use version control.
*
* @return void
*/
function trim()
{
$siteRoot = new Folder(ROOT);
$r = $siteRoot->findRecursive('.*\\.php');
$this->out("Checking *.php in " . ROOT);
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);
}
}
}