本文整理汇总了PHP中RecursiveIteratorIterator类的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator类的具体用法?PHP RecursiveIteratorIterator怎么用?PHP RecursiveIteratorIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RecursiveIteratorIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* Executes this task.
*/
public function main()
{
if ($this->path === null) {
throw new BuildException('The path attribute must be specified');
}
$check = new AgaviModuleFilesystemCheck();
$check->setConfigDirectory($this->project->getProperty('module.config.directory'));
$check->setPath($this->path->getAbsolutePath());
if (!$check->check()) {
throw new BuildException('The path attribute must be a valid module base directory');
}
/* We don't know whether the module is configured or not here, so load the
* values we want properly. */
$this->tryLoadAgavi();
$this->tryBootstrapAgavi();
require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/module.xml', $this->path->getAbsolutePath(), (string) $this->project->getProperty('module.config.directory')));
$actionPath = AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.agavi.action.path', strtolower($this->path->getName())), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php')), array('moduleName' => $this->path->getName()));
$pattern = '#^' . AgaviToolkit::expandVariables(str_replace('\\$\\{actionName\\}', '${actionName}', preg_quote($actionPath, '#')), array('actionName' => '(?P<action_name>.*?)')) . '$#';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath()));
for (; $iterator->valid(); $iterator->next()) {
$rdi = $iterator->getInnerIterator();
if ($rdi->isDot() || !$rdi->isFile()) {
continue;
}
$file = $rdi->getPathname();
if (preg_match($pattern, $file, $matches)) {
$this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['action_name']));
}
}
}
示例2: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
$behaviors = ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]);
if (isset(\Yii::$app->params['httpCacheActive']) and \Yii::$app->params['httpCacheActive']) {
$params = \Yii::$app->getRequest()->getQueryParams();
unset($params['accessToken']);
$behaviors['httpCache'] = ['class' => HttpCache::className(), 'params' => $params, 'lastModified' => function ($action, $params) {
$q = new \yii\db\Query();
$class = $this->modelClass;
if (in_array('updated_at', $class::getTableSchema()->getColumnNames())) {
return strtotime($q->from($class::tableName())->max('updated_at'));
}
if (in_array('modified', $class::getTableSchema()->getColumnNames())) {
return strtotime($q->from($class::tableName())->max('modified'));
}
return null;
}, 'etagSeed' => function (Action $action, $params) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($params));
$keys = array();
foreach ($iterator as $key => $value) {
// Build long key name based on parent keys
for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
$key = $iterator->getSubIterator($i)->key() . '_' . $key;
if (!is_array($iterator->getSubIterator($i)->current())) {
$value = $iterator->getSubIterator($i)->current() . '_' . $value;
}
}
$keys[] = $key . '-' . $value;
}
$uniqueId = implode('-', $keys);
return $uniqueId;
}];
}
return $behaviors;
}
示例3: arrayToXml
/**
* <pre>Converts a Doctrine array graph of the form:
* .array
* . 0 =>
* . array
* . 'id' => '1'
* . 'PersonaDomicilio' =>
* . array
* . 0 =>
* . array
* . 'id' => '1'
* To a XML representation.
*
* @param array $array The array to convert to XML
*
* @return DOMDocument <pre> The XML with following structure:
* . <result>
* . <rootTable_Collection>
* . <rootTable>
* . <id></id>
* . <field1></field1>
* . <relatedTable_Collection>
* . <relatedTable>
* . </relatedTable>
* . <relatedTable>
* . </relatedTable>
* . ::
* . </relatedTable_Collection>
* . </rootTable>
* . <rootTable>
* . ::
* . </rootTable>
* . ::
* . </rootTable_Collection>
* . <result>
* </pre>
*/
public function arrayToXml(array $array)
{
$result = new DOMDocument();
$rootNode = $result->createElement('result');
$result->appendChild($rootNode);
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST);
$prevLvl = 0;
$component[$prevLvl] = $this->_queryComponents[$this->_rootAlias]['table']->getComponentName();
$obj = $result->createElement($component[$prevLvl] . '_Collection');
$rootNode->appendChild($obj);
foreach ($iterator as $k => $val) {
$depth = $iterator->getDepth();
if ($depth < $prevLvl) {
for ($i = 0; $i < $prevLvl - $depth; $i++) {
$obj = $obj->parentNode;
}
}
if (!is_array($val)) {
$son = $result->createElement($k, $val);
$obj->appendChild($son);
} else {
if (is_numeric($k)) {
$son = $result->createElement($component[$depth]);
} else {
$component[$depth + 1] = $k;
$son = $result->createElement($k . '_Collection');
}
$obj->appendChild($son);
!empty($val) && ($obj = $son);
}
$prevLvl = $depth;
}
return $result;
}
示例4: get_directory_list
function get_directory_list($settings = false)
{
$directory = !empty($settings['dir']) ? $settings['dir'] : CLIENT_DIR . "/";
$array = array();
$array['dirs'] = array();
$array['host'] = array();
$array['root'] = array();
if (!is_dir($directory)) {
return false;
}
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
// Loop through directories
while ($dir->valid()) {
try {
$file = $dir->current();
ob_start();
echo $file;
$data = ob_get_contents();
ob_end_clean();
$data = trim($data);
if (basename($data) != '.' && basename($data) != '..') {
$array['host'][] = $data;
$array['root'][] = str_replace(ROOT_DIR, "", $data);
if (is_dir($data) && !in_array($data . "/", $array['dirs'])) {
$array['dirs'][] = $data . "/";
}
}
unset($data);
$dir->next();
} catch (UnexpectedValueException $e) {
continue;
}
}
return isset($array) ? $array : false;
}
示例5: 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());
}
}
}
}
示例6: getTestFiles
/**
* Get Test Files
*
* @param null $directory
* @param null $excludes
* @return array
*/
public static function getTestFiles($directory = null, $excludes = null)
{
if (is_array($directory)) {
$files = array();
foreach ($directory as $d) {
$files = array_merge($files, self::getTestFiles($d, $excludes));
}
return array_unique($files);
}
if ($excludes !== null) {
$excludes = self::getTestFiles((array) $excludes);
}
if ($directory === null || $directory !== realpath($directory)) {
$basePath = App::pluginPath('DebugKit') . 'Test' . DS . 'Case' . DS;
$directory = str_replace(DS . DS, DS, $basePath . $directory);
}
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
$files = array();
while ($it->valid()) {
if (!$it->isDot()) {
$file = $it->key();
if (preg_match('|Test\\.php$|', $file) && $file !== __FILE__ && !preg_match('|^All.+?\\.php$|', basename($file)) && ($excludes === null || !in_array($file, $excludes))) {
$files[] = $file;
}
}
$it->next();
}
return $files;
}
示例7: locate
/**
* @param $target
* @return array
*/
public function locate($target)
{
$paths = [];
$target = sprintf("%s/%s", self::RESOURCE_SUFFIX, $target);
foreach ($this->locations as $location) {
if (!is_dir($location)) {
continue;
}
$location = realpath($location);
$dir = new \RecursiveDirectoryIterator($location, \FilesystemIterator::FOLLOW_SYMLINKS);
$filter = new \RecursiveCallbackFilterIterator($dir, function (\SplFileInfo $current) use(&$paths, $target) {
$fileName = strtolower($current->getFilename());
if ($this->isExcluded($fileName) || $current->isFile()) {
return false;
}
if (!is_dir($current->getPathname() . '/Resources')) {
return true;
} else {
$file = $current->getPathname() . sprintf("/Resources/%s", $target);
if (is_file($file)) {
$paths[] = $file;
}
return false;
}
});
$iterator = new \RecursiveIteratorIterator($filter);
$iterator->rewind();
}
return $paths;
}
示例8: assertDirContentsEquals
protected function assertDirContentsEquals($expDir, $actDir)
{
if (!file_exists($expDir)) {
throw new RuntimeException("Expected dir not found: " . $expDir);
}
if (!file_exists($actDir)) {
throw new RuntimeException("Actual dir not found: " . $actDir);
}
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($expDir));
$expFiles = array();
while ($dir->valid()) {
if (!$dir->isDot()) {
array_push($expFiles, $dir->getSubPathName());
}
$dir->next();
}
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($actDir));
$actFiles = array();
while ($dir->valid()) {
if (!$dir->isDot()) {
array_push($actFiles, $dir->getSubPathName());
}
$dir->next();
}
$this->assertEquals($expFiles, $actFiles);
foreach ($expFiles as $key => $value) {
$expFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $value);
$actFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $actFiles[$key]);
$this->assertEquals($expFile, $actFile);
}
}
示例9: parseCfg
protected function parseCfg()
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data));
$cfg = array();
foreach ($iterator as $key => $value) {
for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
$key = $iterator->getSubIterator($i)->key() . '.' . $key;
}
$cfg[$key] = $value;
}
foreach ($cfg as $key => $value) {
if (is_string($value)) {
if ($count = preg_match_all('({{(.*?)}})', $value, $matches)) {
for ($i = 0; $i < $count; $i++) {
$cfg[$key] = str_replace($matches[0][$i], $cfg[$matches[1][$i]], $value);
}
}
foreach ($this->valueParsers as $valueParser) {
$cfg[$key] = $valueParser($cfg[$key]);
}
$temp =& $this->data;
$exploded = explode('.', $key);
foreach ($exploded as $segment) {
$temp =& $temp[$segment];
}
$temp = $cfg[$key];
unset($temp);
}
}
}
示例10: copyAssets
/**
* Recursively copy assets from the source directory to the destination
* directory in the web space, omitting source files.
*
* @param Filesystem $fs
* @param string $from_directory the source
* @param string $to_directory the destination
* @throws \RuntimeException if a problem occurs.
*/
protected function copyAssets(Filesystem $fs, $from_directory, $to_directory)
{
Tlog::getInstance()->addDebug("Copying assets from {$from_directory} to {$to_directory}");
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($from_directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
$fs->mkdir($to_directory, 0777);
/** @var \RecursiveDirectoryIterator $iterator */
foreach ($iterator as $item) {
if ($item->isDir()) {
$dest_dir = $to_directory . DS . $iterator->getSubPathName();
if (!is_dir($dest_dir)) {
if ($fs->exists($dest_dir)) {
$fs->remove($dest_dir);
}
$fs->mkdir($dest_dir, 0777);
}
} elseif (!$this->isSourceFile($item)) {
// We don't copy source files
$dest_file = $to_directory . DS . $iterator->getSubPathName();
if ($fs->exists($dest_file)) {
$fs->remove($dest_file);
}
$fs->copy($item, $dest_file);
}
}
}
示例11: testBuildPhar
public function testBuildPhar()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Building the phar does not work on HHVM.');
}
$target = dirname(self::$pharPath);
$fs = new Filesystem();
$fs->removeDirectory($target);
$fs->ensureDirectoryExists($target);
chdir($target);
$it = new \RecursiveDirectoryIterator(__DIR__ . '/../../../', \RecursiveDirectoryIterator::SKIP_DOTS);
$ri = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($ri as $file) {
$targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
if ($file->isDir()) {
$fs->ensureDirectoryExists($targetPath);
} else {
copy($file->getPathname(), $targetPath);
}
}
$proc = new Process('php ' . escapeshellarg('./bin/compile'), $target);
$exitcode = $proc->run();
if ($exitcode !== 0 || trim($proc->getOutput())) {
$this->fail($proc->getOutput());
}
$this->assertTrue(file_exists(self::$pharPath));
}
示例12: copyOldVersion
function copyOldVersion()
{
if (!is_dir(PATH)) {
echo 'Creating new oldVersion dir...<br>';
mkdir(PATH);
}
$source = "../";
$dest = PATH;
// Set a stream context timeout for file reading
$context = stream_context_create(array('http' => array('timeout' => 60)));
echo 'Moving current ICEcoder files...<br>';
foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
if (strpos($source . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), "oldVersion") == false) {
// Don't move backups, plugins or .git away
$testPath = $source . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
$testPath = str_replace("\\", "/", $testPath);
if (strpos($testPath, "/backups/") == false && strpos($testPath, "/plugins/") == false && strpos($testPath, "/.git/") == false) {
if ($item->isDir()) {
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755);
} else {
rename($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}
}
}
$icv_url = "https://icecoder.net/latest-version.txt";
echo 'Detecting current version of ICEcoder...<br>';
$icvInfo = getData($icv_url, 'curl', 'Sorry, couldn\'t figure out latest version.');
echo 'Latest version of ICEcoder is ' . $icvInfo . '<br>';
openZipNew($icvInfo);
}
示例13: rmdir
public function rmdir($path) {
if (!$this->isDeletable($path)) {
return false;
}
try {
$it = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->getSourcePath($path)),
\RecursiveIteratorIterator::CHILD_FIRST
);
/**
* RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
* This bug is fixed in PHP 5.5.9 or before
* See #8376
*/
$it->rewind();
while ($it->valid()) {
/**
* @var \SplFileInfo $file
*/
$file = $it->current();
if (in_array($file->getBasename(), array('.', '..'))) {
$it->next();
continue;
} elseif ($file->isDir()) {
rmdir($file->getPathname());
} elseif ($file->isFile() || $file->isLink()) {
unlink($file->getPathname());
}
$it->next();
}
return rmdir($this->getSourcePath($path));
} catch (\UnexpectedValueException $e) {
return false;
}
}
示例14: __construct
/**
* Constructor.
*
* @param \RecursiveIteratorIterator $iterator The Iterator to filter
* @param int $minDepth The min depth
* @param int $maxDepth The max depth
*/
public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = INF)
{
$this->minDepth = $minDepth;
$iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth);
parent::__construct($iterator);
}
示例15: execute
/**
* {@inheritdoc}
*
* @see \Symfony\Component\Console\Command\Command::execute()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$assets = $this->getContainer()->getParameter('asf_layout.assets');
$this->tinymce_config = $assets['tinymce'];
$dest_dir = $input->getArgument('target_dir') ? $input->getArgument('target_dir') : null;
if (is_null($dest_dir) && isset($this->tinymce_config['customize']['dest_dir'])) {
$dest_dir = $this->tinymce_config['customize']['dest_dir'];
}
$exclude_files = $input->getOption('exclude_files') ? $input->getOption('exclude_files') : $this->tinymce_config['customize']['exclude_files'];
$src_dir = sprintf('%s', $this->tinymce_config['tinymce_dir']);
$fs = new Filesystem();
try {
if (!$fs->exists($dest_dir)) {
$fs->mkdir($dest_dir);
}
} catch (IOException $e) {
$output->writeln(sprintf('<error>Could not create directory %s.</error>', $dest_dir));
return;
}
if (false === file_exists($src_dir)) {
$output->writeln(sprintf('<error>Source directory "%s" does not exist. Did you install TinyMCE ? ' . 'Don\'t forget to specify the path to TinyMCE folder in ' . '"asf_layout.assets.tinymce.tinymce_dir".</error>', $src_dir));
return;
}
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($src_dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir() && !in_array($item->getBasename(), $exclude_files)) {
$fs->mkdir($dest_dir . '/' . $iterator->getSubPathName());
} elseif (!in_array($item->getBasename(), $exclude_files)) {
$fs->copy($item, $dest_dir . '/' . $iterator->getSubPathName());
}
}
$output->writeln(sprintf('[OK] TinyMCE files was successfully copied in "%s".', $dest_dir));
}