本文整理汇总了PHP中find_files函数的典型用法代码示例。如果您正苦于以下问题:PHP find_files函数的具体用法?PHP find_files怎么用?PHP find_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_files函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
function execute()
{
echo "search class files...";
$files = find_files($this->_source_dir, array('extnames' => array('.php'), 'excludes' => array('_config')));
echo "ok\n\n";
$this->_files = $files;
spl_autoload_register(array($this, 'autoload'));
$classes = get_declared_classes();
$classes = array_merge($classes, get_declared_interfaces());
foreach ($files as $path) {
require_once $path;
}
$new_classes = get_declared_classes();
$new_classes = array_merge($new_classes, get_declared_interfaces());
$found = array_diff($new_classes, $classes);
$files = array();
foreach ($found as $class) {
$r = new ReflectionClass($class);
$files[$class] = $r->getFileName();
}
$arr = array();
$len = strlen($this->_source_dir);
foreach ($files as $class => $path) {
$filename = str_replace(array('/', '\\'), '/', substr($path, $len + 1));
$class = strtolower($class);
$arr[$class] = $filename;
}
$output = "<?php global \$G_CLASS_FILES;\$G_CLASS_FILES = ";
$output .= str_replace(array(' ', "\n"), '', var_export($arr, true));
$output .= ";\n";
file_put_contents($this->_output_file, $output, LOCK_EX);
echo "ok\n";
}
示例2: find_files
function find_files($path, $pattern)
{
$path = rtrim(str_replace("\\", "/", $path), '/') . '/';
$entries = array();
$matches = array();
$dir = dir($path);
while (false !== ($entry = $dir->read())) {
$entries[] = $entry;
}
$dir->close();
foreach ($entries as $entry) {
$fullname = $path . $entry;
if ($entry != '.' && $entry != '..' && is_dir($fullname)) {
$merge = array_merge($matches, find_files($fullname, $pattern));
foreach ($merge as $m) {
array_push($matches, $m);
}
} else {
if (is_file($fullname) && preg_match($pattern, $fullname)) {
array_push($matches, $fullname);
}
}
}
return array_unique($matches);
}
示例3: find_files
function find_files($path, $pattern, $callback)
{
$path = rtrim(str_replace("\\", "/", $path), '/') . '/*';
foreach (glob($path) as $fullname) {
if (is_dir($fullname)) {
find_files($fullname, $pattern, $callback);
} else {
if (preg_match($pattern, $fullname)) {
$fullname = str_replace('bin/', '', $fullname);
call_user_func($callback, $fullname);
}
}
}
}
示例4: installed
/**
* Indexes the install module files
*
* @since 1.1
*
* @return void
**/
function installed () {
if (!is_dir($this->path)) return false;
$path = $this->path;
$files = array();
find_files(".php",$path,$path,$files);
if (empty($files)) return $files;
foreach ($files as $file) {
// Skip if the file can't be read or isn't a real file at all
if (!is_readable($path.$file) && !is_dir($path.$file)) continue;
// Add the module file to the registry
$module = new ModuleFile($path,$file);
if ($module->addon) $this->modules[$module->subpackage] = $module;
else $this->legacy[] = md5_file($path.$file);
}
}
示例5: scanmodules
function scanmodules($path = false)
{
global $Shopp;
if (!$path) {
$path = $this->path;
}
$modfilescan = array();
find_files(".php", $path, $path, $modfilescan);
if (empty($modfilescan)) {
return $modfilescan;
}
foreach ($modfilescan as $file) {
if (!is_readable($path . $file)) {
continue;
}
$ShipCalcClass = substr(basename($file), 0, -4);
$modfiles[$ShipCalcClass] = $file;
}
$Shopp->Settings->save('shipcalc_modules', addslashes(serialize($modfiles)));
$Shopp->Settings->save('shipcalc_lastscan', mktime());
return $modfiles;
}
示例6: find_files_with_dir
function find_files_with_dir($dir, &$dir_array)
{
// Create array of current directory
$files = scandir($dir);
if (is_array($files)) {
foreach ($files as $val) {
// Skip home and previous listings
if ($val == '.' || $val == '..') {
continue;
}
// If directory then dive deeper, else add file to directory key
if (is_dir($dir . '/' . $val)) {
// Add value to current array, dir or file
$dir_array[$dir][] = $val;
find_files($dir . '/' . $val, $dir_array);
} else {
$dir_array[$dir][] = $val;
}
}
}
ksort($dir_array);
}
示例7: find_files
function find_files($base, $needle, $function, $userdata = NULL, $depth = 1)
{
// Do not set $depth by hand! It is used for internal depth checking only!
$dir = dir($base);
while ($file = $dir->read()) {
if ($file != "." && $file != "..") {
$path = sprintf("%s/%s", $base, $file);
if (is_dir($path)) {
find_files($path, $needle, $function, $userdata, $depth + 1);
} else {
if (preg_match($needle, $file)) {
if (empty($userdata)) {
$function($path, $file);
} else {
$function($path, $file, $userdata);
}
}
}
}
}
$dir->close();
}
示例8: find_files
function find_files($path, $pattern, $callback)
{
global $texts;
global $xml;
$path = rtrim(str_replace("\\", "/", $path), '/') . '/';
$matches = array();
$entries = array();
$dir = dir($path);
while (false !== ($entry = $dir->read())) {
$entries[] = $entry;
}
$dir->close();
foreach ($entries as $entry) {
$fullname = $path . $entry;
if ($entry != '.' && $entry != '..' && is_dir($fullname)) {
find_files($fullname, $pattern, $callback);
} else {
if (is_file($fullname) && preg_match($pattern, $entry)) {
call_user_func($callback, $fullname);
}
}
}
}
示例9: testFindFiles
public function testFindFiles()
{
$this->createTempFiles();
$path = $this->path;
$filesFound = find_files($path, 0, '*');
$this->assertSame(7, count($filesFound));
$jsFilesFound = find_js_files($path);
$this->assertSame(2, count($jsFilesFound));
$htmlFilesFound = find_html_files($path);
$this->assertSame(2, count($htmlFilesFound));
$phpFilesFound = find_php_files($path);
$this->assertSame(2, count($phpFilesFound));
// Including subdirectories
$filesFound = find_files($path, 0, '*', true);
$this->assertSame(10, count($filesFound));
$jsFilesFound = find_js_files($path, true);
$this->assertSame(3, count($jsFilesFound));
$htmlFilesFound = find_html_files($path, true);
$this->assertSame(3, count($htmlFilesFound));
$phpFilesFound = find_php_files($path, true);
$this->assertSame(3, count($phpFilesFound));
$this->assertInternalType('array', find_templates());
$this->removeTempFiles();
}
示例10: copy_content
/**
* Moves files or complete directories
*
* @param $from string Can be a file or a directory. Will move either the file or all files within the directory
* @param $to string Where to move the file(s) to. If not specified then will get moved to the root folder
* @param $strip Used for FTP only
* @return mixed: Bool true on success, error string on failure, NULL if no action was taken
*
* NOTE: function should preferably not return in case of failure on only one file.
* The current method makes error handling difficult
*/
function copy_content($from, $to = '', $strip = '')
{
global $phpbb_root_path, $user;
if (strpos($from, $phpbb_root_path) !== 0) {
$from = $phpbb_root_path . $from;
}
// When installing a MODX 1.2.0 MOD, this happens once in a long while.
// Not sure why yet.
if (is_array($to)) {
return NULL;
}
if (strpos($to, $phpbb_root_path) !== 0) {
$to = $phpbb_root_path . $to;
}
$files = array();
if (is_dir($from)) {
// get all of the files within the directory
$files = find_files($from, '.*');
} else {
if (is_file($from)) {
$files = array($from);
}
}
if (empty($files)) {
return false;
}
// ftp
foreach ($files as $file) {
if (is_dir($to)) {
$to_file = str_replace(array($phpbb_root_path, $strip), '', $file);
} else {
$to_file = str_replace($phpbb_root_path, '', $to);
}
$this->recursive_mkdir(dirname($to_file));
if (!$this->transfer->overwrite_file($file, $to_file)) {
// may as well return ... the MOD is likely dependent upon
// the file that is being copied
return sprintf($user->lang['MODS_FTP_FAILURE'], $to_file);
}
}
return true;
}
示例11: find_files
/**
* List files matching specified PCRE pattern.
*
* @access public
* @param string Relative or absolute path to the directory to be scanned.
* @param string Search pattern (perl compatible regular expression).
* @param integer Number of subdirectory levels to scan (set to 1 to scan only current).
* @param integer This one is used internally to control recursion level.
* @return array List of all files found matching the specified pattern.
*/
function find_files($directory, $pattern, $max_levels = 20, $_current_level = 1)
{
if ($_current_level <= 1) {
if (strpos($directory, '\\') !== false) {
$directory = str_replace('\\', '/', $directory);
}
if (empty($directory)) {
$directory = './';
} else {
if (substr($directory, -1) != '/') {
$directory .= '/';
}
}
}
$files = array();
$subdir = array();
if (is_dir($directory)) {
$handle = @opendir($directory);
while (($file = @readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$fullname = $directory . $file;
if (is_dir($fullname)) {
if ($_current_level < $max_levels) {
$subdir = array_merge($subdir, find_files($fullname . '/', $pattern, $max_levels, $_current_level + 1));
}
} else {
if (preg_match('/^' . $pattern . '$/i', $file)) {
$files[] = $fullname;
}
}
}
@closedir($handle);
sort($files);
}
return array_merge($files, $subdir);
}
示例12: recursive_unlink
/**
* Recursively delete a directory
*
* @param string $path (required) Directory path to recursively delete
* @author jasmineaura
*/
function recursive_unlink($path)
{
global $phpbb_root_path, $phpEx, $user;
// Insurance - this should never really happen
if ($path == $phpbb_root_path || is_file("{$path}/common.{$phpEx}")) {
return false;
}
// Get all of the files in the source directory
$files = find_files($path, '.*');
// Get all of the sub-directories in the source directory
$subdirs = find_files($path, '.*', 20, true);
// Delete all the files
foreach ($files as $file) {
if (!unlink($file)) {
return sprintf($user->lang['MODS_RMFILE_FAILURE'], $file);
}
}
// Delete all the sub-directories, in _reverse_ order (array_pop)
for ($i = 0, $cnt = count($subdirs); $i < $cnt; $i++) {
$subdir = array_pop($subdirs);
if (!rmdir($subdir)) {
return sprintf($user->lang['MODS_RMDIR_FAILURE'], $subdir);
}
}
// Finally, delete the directory itself
if (!rmdir($path)) {
return sprintf($user->lang['MODS_RMDIR_FAILURE'], $path);
}
return true;
}
示例13: find_files
function find_files($dir, $is_ext_dir = FALSE, $ignore = FALSE)
{
global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped, $exts_tested;
$o = opendir($dir) or error("cannot open directory: {$dir}");
while (($name = readdir($o)) !== FALSE) {
if (is_dir("{$dir}/{$name}") && !in_array($name, array('.', '..', 'CVS'))) {
$skip_ext = $is_ext_dir && !in_array($name, $exts_to_test);
if ($skip_ext) {
$exts_skipped++;
}
find_files("{$dir}/{$name}", FALSE, $ignore || $skip_ext);
}
// Cleanup any left-over tmp files from last run.
if (substr($name, -4) == '.tmp') {
@unlink("{$dir}/{$name}");
continue;
}
// Otherwise we're only interested in *.phpt files.
if (substr($name, -5) == '.phpt') {
if ($ignore) {
$ignored_by_ext++;
} else {
$testfile = realpath("{$dir}/{$name}");
$test_files[] = $testfile;
}
}
}
closedir($o);
}
示例14: run_test
//.........这里部分代码省略.........
if (isset($old_php)) {
$php = $old_php;
}
if (!$cfg['keep']['skip']) {
@unlink($test_skipif);
}
return 'SKIPPED';
}
if (!strncasecmp('info', ltrim($output), 4)) {
if (preg_match('/^\\s*info\\s*(.+)\\s*/i', $output, $m)) {
$info = " (info: {$m['1']})";
}
}
if (!strncasecmp('warn', ltrim($output), 4)) {
if (preg_match('/^\\s*warn\\s*(.+)\\s*/i', $output, $m)) {
$warn = true;
/* only if there is a reason */
$info = " (warn: {$m['1']})";
}
}
}
}
if (@count($section_text['REDIRECTTEST']) == 1) {
$test_files = array();
$IN_REDIRECT = eval($section_text['REDIRECTTEST']);
$IN_REDIRECT['via'] = "via [{$shortname}]\n\t";
$IN_REDIRECT['dir'] = realpath(dirname($file));
$IN_REDIRECT['prefix'] = trim($section_text['TEST']);
if (count($IN_REDIRECT['TESTS']) == 1) {
if (is_array($org_file)) {
$test_files[] = $org_file[1];
} else {
$GLOBALS['test_files'] = $test_files;
find_files($IN_REDIRECT['TESTS']);
foreach ($GLOBALS['test_files'] as $f) {
$test_files[] = array($f, $file);
}
}
$test_cnt += @count($test_files) - 1;
$test_idx--;
show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file);
// set up environment
$redirenv = array_merge($environment, $IN_REDIRECT['ENV']);
$redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR;
usort($test_files, "test_sort");
run_all_tests($test_files, $redirenv, $tested);
show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file);
// a redirected test never fails
$IN_REDIRECT = false;
return 'REDIR';
} else {
$bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory.";
show_result("BORK", $bork_info, '', $temp_filenames);
$PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]");
}
}
if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) {
if (is_array($org_file)) {
$file = $org_file[0];
}
$bork_info = "Redirected test did not contain redirection info";
show_result("BORK", $bork_info, '', $temp_filenames);
$PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]");
return 'BORKED';
}
// We've satisfied the preconditions - run the test!
示例15: copy_content
function copy_content($from, $to = '', $strip = '')
{
global $phpbb_root_path, $user;
if (strpos($from, $phpbb_root_path) !== 0) {
$from = $phpbb_root_path . $from;
}
if (strpos($to, $phpbb_root_path) !== 0) {
$to = $phpbb_root_path . $to;
}
// Note: phpBB's compression class does support adding a whole directory at a time.
// However, I chose not to use that function because it would not allow AutoMOD's
// error handling to work the same as for FTP & Direct methods.
$files = array();
if (is_dir($from)) {
// get all of the files within the directory
$files = find_files($from, '.*');
} else {
if (is_file($from)) {
$files = array($from);
}
}
if (empty($files)) {
return false;
}
foreach ($files as $file) {
if (is_dir($to)) {
// this would find the directory part specified in MODX
$to_file = str_replace(array($phpbb_root_path, $strip), '', $to);
// and this fetches any subdirectories and the filename of the destination file
$to_file .= substr($file, strpos($file, $to_file) + strlen($to_file));
} else {
$to_file = str_replace($phpbb_root_path, '', $to);
}
// filename calculation is involved here:
// and prepend the "files" directory
if (!$this->compress->add_custom_file($file, 'files/' . $to_file)) {
return sprintf($user->lang['WRITE_MANUAL_FAIL'], $to_file);
}
}
// return true since we are now taking an action - NULL implies no action
return true;
}