本文整理汇总了PHP中RecursiveIteratorIterator::getSubPath方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::getSubPath方法的具体用法?PHP RecursiveIteratorIterator::getSubPath怎么用?PHP RecursiveIteratorIterator::getSubPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::getSubPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMedia
/**
* Media files are just copied over w/o any additional processing
*
* @return \Phrozn\Site
*/
private function processMedia()
{
$projectDir = $this->getProjectDir();
$outputDir = $this->getOutputDir();
$dir = new \RecursiveDirectoryIterator($projectDir . '/media');
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($it as $item) {
$baseName = $item->getBaseName();
if ($item->isFile()) {
$inputFile = $item->getRealPath();
$path = $it->getSubPath();
$outputFile = $outputDir . '/media/' . $path . (!empty($path) ? '/' : '') . basename($inputFile);
// copy media files
try {
$destinationDir = dirname($outputFile);
if (!is_dir($destinationDir)) {
mkdir($destinationDir, 0777, true);
}
if (!copy($inputFile, $outputFile)) {
throw new \Exception(sprintf('Failed transfering "%s" from media folder', $inputFile));
}
$inputFile = str_replace(getcwd(), '.', $inputFile);
$outputFile = str_replace(getcwd(), '.', realpath($outputFile));
$this->getOutputter()->stdout('%b' . $outputFile . '%n copied');
} catch (\Exception $e) {
$this->getOutputter()->stderr($inputFile . ': ' . $e->getMessage());
}
}
}
}
示例2: execute
/**
* Execute the command.
*
* @return void
*
* @since 1.0
*/
public function execute()
{
$this->getApplication()->outputTitle('Make Documentation');
$this->usePBar = $this->getApplication()->get('cli-application.progress-bar');
if ($this->getApplication()->input->get('noprogress')) {
$this->usePBar = false;
}
$this->github = $this->getContainer()->get('gitHub');
$this->getApplication()->displayGitHubRateLimit();
/* @type \Joomla\Database\DatabaseDriver $db */
$db = $this->getContainer()->get('db');
$docuBase = JPATH_ROOT . '/Documentation';
/* @type \RecursiveDirectoryIterator $it */
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($docuBase, \FilesystemIterator::SKIP_DOTS));
$this->out('Compiling documentation in: ' . $docuBase)->out();
$table = new ArticlesTable($db);
// @todo compile the md text here.
$table->setGitHub($this->github);
while ($it->valid()) {
if ($it->isDir()) {
$it->next();
continue;
}
$file = new \stdClass();
$file->filename = $it->getFilename();
$path = $it->getSubPath();
$page = substr($it->getFilename(), 0, strrpos($it->getFilename(), '.'));
$this->debugOut('Compiling: ' . $page);
$table->reset();
$table->{$table->getKeyName()} = null;
try {
$table->load(array('alias' => $page, 'path' => $path));
} catch (\RuntimeException $e) {
// New item
}
$table->is_file = '1';
$table->path = $it->getSubPath();
$table->alias = $page;
$table->text_md = file_get_contents($it->key());
$table->store();
$this->out('.', false);
$it->next();
}
$this->out()->out('Finished =;)');
}
示例3: process
/**
*## Iterate and Process
* All the magic happens here, whils it looks complicated this is essentially a directory iterator
* that creates an array of filenames, with a corresponding Phrocco object that can look after rendering itself.
*
**/
public function process()
{
$dir_iterator = new PhroccoIterator($this->options["i"]);
$iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
if (!$iterator->isDot() && in_array($iterator->getExtension(), $this->extensions[$this->options["l"]])) {
$base_path = $this->options["i"];
$rpath = str_replace($base_path, "", $file->getPath());
$phrocco = new Phrocco($this->options["l"], $file);
if (!$this->options["o"]) {
$output_dir = $file->getPath();
} else {
$output_dir = $this->options["o"];
}
if ($rpath != $file->getPath()) {
$output_dir .= "/" . $rpath;
}
/**
*### Check that we can write
* This block ensures that the output directory exists. If it doesn't we'll try and create it before giving up.
**/
if (!is_writable($output_dir)) {
try {
mkdir($output_dir, 0777, true);
} catch (Exception $e) {
if (!is_writable($output_dir)) {
throw new \Exception("Invalid Output Directory - Couldn't Create Because of Permissions");
}
}
}
/**
*### Build the documentation tree
* This block builds the documentation file layout to mirror the code files scanned.
**/
$file_out = $output_dir . "/" . $file->getBasename($iterator->getExtension()) . "html";
$phrocco->output_file = $file_out;
$subpath = $iterator->getSubPath();
$phrocco->path = (!empty($subpath) ? "./" : '') . $subpath;
$this->group[$file->getBasename()] = $phrocco;
$subpath .= !empty($subpath) ? '/' : '';
$this->sources[] = array("url" => $subpath . $file->getBasename($iterator->getExtension()) . "html", "name" => $file->getBasename(), "level" => $iterator->getDepth(), "folder" => $iterator->getSubPath());
}
}
}
示例4: buildTree
public function buildTree($last_created = '')
{
$dir = new RecursiveDirectoryIterator($this->root_dir, FilesystemIterator::SKIP_DOTS);
$this->filter($dir);
$it = new RecursiveIteratorIterator($this->filter, RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
$tree = array();
foreach ($it as $fileinfo) {
$name = $fileinfo->getFilename();
$sub_path_name = $it->getSubPathName();
$parts = explode(DIRECTORY_SEPARATOR, $sub_path_name);
array_pop($parts);
$parentArr =& $tree;
//go deep in the file|dir path
foreach ($parts as $part) {
$parentArr =& $parentArr['dirs'][$part];
}
if ($fileinfo->isDir()) {
//statistics
$statistics = $this->countChildren($it->key());
$total_files = round($statistics['files'] / $this->count_suffix);
// Add the final part to the structure
if (!empty($last_created) && $it->key() == $last_created) {
$parentArr['dirs'][$name] = array('f' => $name, 'c-folders' => $statistics['folders'], 'c-files' => $total_files, 'last' => true);
} else {
$parentArr['dirs'][$name] = array('f' => $name, 'c-folders' => $statistics['folders'], 'c-files' => $total_files, 'ffff' => $statistics['files'] . '..' . $this->count_suffix);
}
} else {
// Add some file info to the structure
if ($fileinfo->isLink()) {
$realpath = $fileinfo->getRealPath();
$filesize = filesize($realpath);
$filemtime = filemtime($realpath);
} else {
$filesize = $fileinfo->getSize();
$filemtime = $fileinfo->getMTime();
}
$file_path = $it->getSubPath() == '' ? '/' : '/' . $it->getSubPath() . '/';
$parentArr['files'][] = array('filename' => $name, 'filesize' => $this->fileSizeConvert($filesize), 'date' => date("d-m-Y H:i", $filemtime), 'relative_path' => $file_path);
}
}
unset($parentArr);
$this->sortArray($tree);
return $tree;
}
示例5: get_all_files
private function get_all_files()
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->input_dir));
$result = array();
while ($iterator->valid()) {
if (!$iterator->isDot()) {
$result[$iterator->getSubPath()][] = $iterator->key();
}
$iterator->next();
}
return $result;
}
示例6: execute
/**
* Executes the transformation process.
*
* @throws Zend_Console_Getopt_Exception
*
* @return void
*/
public function execute()
{
$results = array();
$longest_name = 0;
/** @var RecursiveDirectoryIterator $files */
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/../'));
while ($files->valid()) {
// skip abstract files
if (!$files->isFile() || $files->getBasename() == 'Abstract.php') {
$files->next();
continue;
}
// convert the filename to a class
$class_name = 'DocBlox_Task_' . str_replace(DIRECTORY_SEPARATOR, '_', $files->getSubPath()) . '_' . $files->getBasename('.php');
// check if the class exists, if so: add it to the list
if (class_exists($class_name)) {
$name = $files->getBasename('.php');
$longest_name = max(strlen($name), $longest_name);
$results[strtolower($files->getSubPath())][strtolower($name)] = $files->getRealPath();
}
$files->next();
}
// echo the list of namespaces with their tasks
ksort($results, SORT_STRING);
foreach ($results as $namespace => $tasks) {
echo $namespace . PHP_EOL;
asort($tasks, SORT_STRING);
foreach ($tasks as $task => $filename) {
// get the short description by reflecting the file.
$refl = new DocBlox_Reflection_File($filename, false);
$refl->setLogLevel(DocBlox_Core_Log::QUIET);
$refl->process();
/** @var DocBlox_Reflection_Class $class */
$class = current($refl->getClasses());
echo ' :' . str_pad($task, $longest_name + 2) . $class->getDocBlock()->getShortDescription() . PHP_EOL;
}
}
echo PHP_EOL;
}
示例7: _checkCoreCodePool
/**
* Looks for files in "core" code pool
*/
protected function _checkCoreCodePool()
{
$files = array();
/** @var \RecursiveDirectoryIterator $dir */
$dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->_extensionPath));
while ($dir->valid()) {
if (!$dir->isDot() && strpos($dir->getSubPath(), 'app/code/core') !== false) {
$files[] = $dir->getSubPathname();
}
$dir->next();
}
if (!empty($files)) {
$this->_addIssue(array('type' => 'corehack', 'comment' => 'Usage of "core" code pool', 'files' => $files, 'occurrences' => count($files)));
}
}
示例8: RecursiveDirectoryIterator
<?php
require_once 'files/phar_oo_test.inc';
$fname = str_replace('\\', '/', $fname);
$it = new RecursiveDirectoryIterator('phar://' . $fname);
$it = new RecursiveIteratorIterator($it);
foreach ($it as $name => $ent) {
var_dump(str_replace(array('\\', $fname), array('/', '*'), $name));
var_dump(str_replace(array('\\', $fname), array('/', '*'), $ent->getPathname()));
var_dump(str_replace('\\', '/', $it->getSubPath()));
var_dump(str_replace('\\', '/', $it->getSubPathName()));
$sub = $it->getPathInfo();
var_dump(str_replace('\\', '/', $sub->getFilename()));
}
?>
===DONE===
<?php
unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
__halt_compiler();
?>
示例9: buildFileIntegrity
/**
* Builds the file integrity table
*
*/
public static function buildFileIntegrity()
{
$files = array();
// Extensions to fetch, an empty array will return all extensions
$ext = array("php", "html");
// Directories to ignore, an empty array will check all directories
$skip = array();
// Build profile
$dir = new RecursiveDirectoryIterator(FROOT);
$iter = new RecursiveIteratorIterator($dir);
while ($iter->valid()) {
// Skip unwanted directories
if (!$iter->isDot() && !in_array($iter->getSubPath(), $skip)) {
// get specific file extensions
if (!empty($ext)) {
// PHP 5.3.4: if (in_array($iter->getExtension(), $ext)) {
if (in_array(pathinfo($iter->key(), PATHINFO_EXTENSION), $ext)) {
$files[$iter->key()] = hash_file("sha1", $iter->key());
}
} else {
// ignore file extensions
$files[$iter->key()] = hash_file("sha1", $iter->key());
}
}
$iter->next();
}
// Add hashes to databases
openRailwayCore::logEvent(time(), openRailwayCore::createInteractionIdentifier(), null, 5, 1, "File integrity hash table built");
foreach ($files as $k => $v) {
$sql = "INSERT INTO integrity_hashes (file_path,file_hash) VALUES ('" . $k . "','" . $v . "')";
openRailwayCore::dbQuery($sql);
}
}
示例10: run
/**
* run() method load specified directory
*
* @param array params
* @return array
*/
public function run(array $aParams)
{
// test of obligatory validated path
if (isset($aParams['path']) && is_dir($aParams['path']) && (isset($aParams['pattern']) || isset($aParams['extension']))) {
// init object
$oDirRecIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($aParams['path']));
// case of not recursive
if (isset($aParams['recursive']) === false || isset($aParams['recursive']) === true && $aParams['recursive'] === false) {
$oDirRecIterator->setMaxDepth(1);
}
// clear array
$this->_aFiles = array();
// rewind
$this->rewind();
$iCount = 0;
// loop on object result
while ($oDirRecIterator->valid()) {
if ($oDirRecIterator->isDot() === false) {
// get file name
$sFileName = $oDirRecIterator->getFilename();
if (isset($aParams['pattern']) && preg_match($aParams['pattern'], $sFileName) || isset($aParams['extension']) && substr(strtolower($sFileName), strrpos($sFileName, '.') + 1) == $aParams['extension']) {
$this->_aFiles[$iCount]['path'] = $oDirRecIterator->key();
$this->_aFiles[$iCount]['filename'] = $sFileName;
// case of subpath
if (isset($aParams['subpath']) && $aParams['subpath']) {
$this->_aFiles[$iCount]['subpath'] = $oDirRecIterator->getSubPath();
}
// case of subpathname
if (isset($aParams['subpathname']) && $aParams['subpathname']) {
$this->_aFiles[$iCount]['subpathname'] = $oDirRecIterator->getSubPathname();
}
// case of size
if (isset($aParams['size']) && $aParams['size']) {
$this->_aFiles[$iCount]['size'] = $oDirRecIterator->getSize();
}
// case of type
if (isset($aParams['type']) && $aParams['type']) {
$this->_aFiles[$iCount]['type'] = $oDirRecIterator->getType();
}
// case of owner
if (isset($aParams['owner']) && $aParams['owner']) {
$this->_aFiles[$iCount]['owner'] = $oDirRecIterator->getOwner();
}
// case of group
if (isset($aParams['group']) && $aParams['group']) {
$this->_aFiles[$iCount]['group'] = $oDirRecIterator->getGroup();
}
// case of time
if (isset($aParams['time']) && $aParams['time']) {
$this->_aFiles[$iCount]['time'] = $oDirRecIterator->getCTime();
}
// case of verbose
if (isset($aParams['verbose']) && $aParams['verbose']) {
echo '[ ', isset($aParams['service']) ? $aParams['service'] : 'FILE', ' ] ', date("d-m-Y à H:i:s"), ' => matched file : ', $sFileName, "\n";
}
++$iCount;
}
}
$oDirRecIterator->next();
}
// destruct object
unset($oDirRecIterator);
// return
return $this->_aFiles;
} else {
// throw exception if specified directory is not declared
throw new Exception('Specified path or extension or pattern are not declared or is not a valid path');
}
}
示例11: process
/**
* @param array $preprocvars list of key/value representing variables for the preprocessor
* @param bool $preprocmanifest if true, the manifest file is preprocessed then the manifest
* reader will used the generated manifest file instead of the given manifest file.
*/
public function process($preprocvars, $preprocmanifest = false)
{
$this->preprocvars = $preprocvars;
if ($preprocmanifest) {
$this->preproc->setVars($preprocvars);
try {
$content = $this->preproc->parseFile($this->ficlist);
} catch (\Exception $e) {
throw new \Exception('cannot preprocess the manifest file ' . $this->ficlist . ' (' . $e . ")\n");
}
$script = explode("\n", $content);
} else {
$script = file($this->ficlist);
}
$currentdestdir = '';
$currentsrcdir = '';
foreach ($script as $nbline => $line) {
++$nbline;
if (preg_match(';^(cd|sd|dd|\\*|!|\\*!|c|\\*c|cch)?\\s+([a-zA-Z0-9\\/.\\-_]+)\\s*(?:\\(([a-zA-Z0-9\\%\\/.\\-_]*)\\))?\\s*$;m', $line, $m)) {
if ($m[1] == 'dd') {
// set destination dir
$currentdestdir = DirUtils::normalizeDir($m[2]);
$this->fs->createDir($currentdestdir);
} elseif ($m[1] == 'sd') {
// set source dir
$currentsrcdir = DirUtils::normalizeDir($m[2]);
} elseif ($m[1] == 'cd') {
// set source dir and destination dir (same sub path)
$currentsrcdir = DirUtils::normalizeDir($m[2]);
$currentdestdir = DirUtils::normalizeDir($m[2]);
$this->fs->createDir($currentdestdir);
} else {
// copy a file
// should we do processing on the file?
$doPreprocessing = strpos($m[1], '*') !== false;
// should we compress files or generate encoded files?
$doCompression = strpos($m[1], 'c') !== false && $m[1] != 'cch' || $this->stripComment && strpos($m[1], '!') === false;
if ($m[2] == '') {
throw new \Exception($this->ficlist . ": file required on line {$nbline} \n");
}
if (!isset($m[3]) || $m[3] == '') {
$m[3] = $m[2];
}
if ($m[2] == '__ALL__') {
$dir = new \DirectoryIterator($this->sourcedir . $currentsrcdir);
foreach ($dir as $dirContent) {
if (!$dirContent->isFile()) {
continue;
}
$m[2] = $m[3] = $dirContent->getFileName();
$destfile = $currentdestdir . $m[3];
$sourcefile = $this->sourcedir . $currentsrcdir . $m[2];
$this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression);
}
} elseif ($m[2] == '__ALL_RECURSIVELY__') {
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sourcedir . $currentsrcdir));
$it->rewind();
while ($it->valid()) {
if (!$it->isDot()) {
$this->fs->createDir($currentdestdir . $it->getSubPath());
$sourcefile = $this->sourcedir . $currentsrcdir . $it->getSubPath() . '/' . $it->getBaseName();
$destfile = $currentdestdir . $it->getSubPath() . '/' . $it->getBaseName();
$this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression);
}
$it->next();
}
} else {
$destfile = $currentdestdir . $m[3];
$sourcefile = $this->sourcedir . $currentsrcdir . $m[2];
$this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression);
}
}
} elseif (preg_match("!^\\s*(\\#.*)?\$!", $line)) {
// we ignore comments
} else {
throw new \Exception($this->ficlist . ": syntax error on line {$nbline} \n");
}
}
}
示例12: cloneDirectory
/**
* Clones a directory.
*
* @param string $buildDirectory
* @param string $path
*/
protected function cloneDirectory($buildDirectory, $path)
{
$path = FileUtil::addTrailingSlash($path);
// ensure source directory exists
if (!is_dir($this->resourceDirectory . $path)) {
throw new SystemException("Required path '" . $path . "' within resource directory is not available.");
}
// create path
if (!is_dir($buildDirectory . $path)) {
FileUtil::makePath($buildDirectory . $path);
}
// copy files recursively
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->resourceDirectory . $path));
while ($it->valid()) {
if (!$it->isDot()) {
// ignore .svn directories
$tmp = explode('/', FileUtil::unifyDirSeperator($it->getSubPath()));
if (in_array('.svn', $tmp)) {
$it->next();
continue;
}
$subPath = FileUtil::addTrailingSlash($it->getSubPath());
if (!is_dir($buildDirectory . $path . $subPath)) {
FileUtil::makePath($buildDirectory . $path . $subPath);
}
copy($it->key(), $buildDirectory . $path . $it->getSubPathName());
}
$it->next();
}
}
示例13: createBuildZip
/**
* @param string $websiteId
* @param string $name Zip name
* @param \Cms\Data\Build $build
*
* @return string Name of the export zip file
*/
private function createBuildZip($websiteId, $name, BuildData $build)
{
$zipFile = FS::joinPath($this->getWebsiteBuildsDirectory($websiteId), $name . self::BUILD_FILE_EXTENSION);
$websiteCreatorDirectory = $this->getLastCreatorDirectory();
$zip = new \ZipArchive();
$zip->open($zipFile, \ZipArchive::CREATE);
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($websiteCreatorDirectory), \RecursiveIteratorIterator::SELF_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if ($iterator->isDir()) {
$zip->addEmptyDir(str_replace('\\', '/', $iterator->getSubPathName()));
} else {
$zip->addEmptyDir(str_replace('\\', '/', $iterator->getSubPath()));
$zip->addFile($iterator->key(), str_replace('\\', '/', $iterator->getSubPathName()));
}
}
$iterator->next();
}
$zip->setArchiveComment($this->getBuiltArchiveComment($build));
$zip->close();
return $zipFile;
}
示例14: exec
exec('/usr/bin/gzip -f -k -9 ' . escapeshellarg($uniFile));
}
// Javascript template
$smarty->assignByRef('SCRIPTS', $scriptFiles);
Log::debug('Copying static files/directories: ' . Config::read('pwd') . '/static');
// Copy static files/directories
exec('/usr/bin/cp -R ' . escapeshellarg(Config::read('pwd') . '/static/.') . ' ' . escapeshellarg(Config::read('pwd') . '/www/'));
Log::debug('Searching for content: ' . Config::read('pwd') . '/content');
// Template loop
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(Config::read('pwd') . '/content', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $s) {
// Skip directories
if ($s->isDir()) {
continue;
}
// Load URL
$url = $iterator->getSubPath();
if ($url !== '') {
$url = '/' . $url;
}
// Update base path for subdirectories
if (Config::read('production') === 'true' && Config::read('forcerelativepaths') === 'false') {
// Assign full URL
$smarty->assign('BASEURL', Config::read('baseurl'));
} else {
// Assign relative path
// Count path depth
$rc = substr_count($url, '/');
if ($rc > 0) {
$smarty->assign('BASEURL', str_repeat('../', $rc));
} else {
$smarty->assign('BASEURL', '.');
示例15: endsWith
return $defaultValue;
}
$url = parseUrlVar("path", "");
$ext = parseUrlVar("ext", ".json");
$depth = parseUrlVar("depth", 1);
$url = $_SERVER['DOCUMENT_ROOT'] . "/" . $url;
// Create recursive dir iterator which skips dot folders
$dir = new RecursiveDirectoryIterator($url, FilesystemIterator::SKIP_DOTS);
// Flatten the recursive iterator, folders come before their files
$it = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
// Maximum depth is 1 level deeper than the base folder
$it->setMaxDepth($depth);
function endsWith($str, $sub)
{
return substr($str, strlen($str) - strlen($sub)) === $sub;
}
$res = array();
foreach ($it as $fileinfo) {
//if ($fileinfo->isDir()) {
if ($fileinfo->isFile()) {
$filename = $fileinfo->getFilename();
if (endsWith($filename, $ext)) {
array_push($res, $it->getSubPath() . "/" . $filename);
}
}
}
//array_push($res, "יא€");
//echo utf8_encode("יא€");
//echo json_encode(array(["יא€"]))
echo json_encode($res);
//echo json_last_error_msg;