本文整理汇总了PHP中RecursiveDirectoryIterator::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator::getChildren方法的具体用法?PHP RecursiveDirectoryIterator::getChildren怎么用?PHP RecursiveDirectoryIterator::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveDirectoryIterator
的用法示例。
在下文中一共展示了RecursiveDirectoryIterator::getChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCallableModules
/**
* get callable module list
*
* @return array
*/
public function getCallableModules()
{
$dirIterator = new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::SKIP_DOTS);
$modules = array();
foreach ($dirIterator as $k => $v) {
$doVotedModule = false;
if ($dirIterator->hasChildren()) {
foreach ($dirIterator->getChildren() as $key => $value) {
$entension = $value->getExtension();
if (!$entension || 'php' !== $entension) {
continue;
}
$fileBasename = $value->getBasename('.php');
$module_to_be = $v->getBasename();
$expectedClassName = $this->baseNamespace . NAMESPACE_SEPARATOR . $module_to_be . NAMESPACE_SEPARATOR . $fileBasename;
Loader::getInstance()->import($value->__toString());
if (!class_exists($expectedClassName, false)) {
// not a standard class file!
continue;
}
if (!$doVotedModule) {
$modules[] = $module_to_be;
$doVotedModule = true;
}
}
}
}
return $modules;
}
示例2: getChildren
/**
* @return mixed object
*
* @throws AccessDeniedException
*/
public function getChildren()
{
try {
return parent::getChildren();
} catch (\UnexpectedValueException $e) {
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
}
示例3: getChildren
/** Override of getChildren in \RecursiveDirectoryIterator, to skip directories with insufficient rights to access
* @internal
*/
function getChildren()
{
try {
return parent::getChildren();
} catch (\UnexpectedValueException $e) {
return new \RecursiveArrayIterator(array());
}
}
示例4: getChildren
public function getChildren()
{
$children = parent::getChildren();
if (is_object($children)) {
echo get_class($children) . " {$children}\n";
} else {
echo gettype($children) . " {$children}\n";
}
return $children;
}
示例5: getChildren
/**
* @return \RecursiveIterator
*
* @throws AccessDeniedException
*/
public function getChildren()
{
try {
return parent::getChildren();
} catch (\UnexpectedValueException $e) {
if ($this->ignoreUnreadableDirs) {
// If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
return new \RecursiveArrayIterator(array());
} else {
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
}
}
示例6: getChildren
public function getChildren()
{
try {
$children = parent::getChildren();
if ($children instanceof self) {
$children->skipUnreadable = $this->skipUnreadable;
}
return $children;
} catch (\UnexpectedValueException $e) {
if ($this->skipUnreadable) {
return new \RecursiveArrayIterator(array());
} else {
throw new \Reea\FileSearcher\Bundle\Exceptions\AccessDeniedException();
}
}
}
示例7: getChildren
public function getChildren()
{
try {
$children = parent::getChildren();
if ($children instanceof self) {
$children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
}
return $children;
} catch (\UnexpectedValueException $e) {
if ($this->ignoreUnreadableDirs) {
return new \RecursiveArrayIterator(array());
} else {
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
}
}
示例8: import
/**
* import
*
* @param string $tsvDirPath
* @access public
* @return void
*/
public function import($tsvDirPath = null)
{
if (is_null($tsvDirPath)) {
$tsvDirPath = realpath(__DIR__ . '/../../../../../../masterData');
}
$iterator = new \RecursiveDirectoryIterator($tsvDirPath);
foreach ($iterator as $file) {
if (!$iterator->hasChildren()) {
continue;
}
$databaseName = $file->getFileName();
$con = $this->getConnection($databaseName);
$con->exec('set foreign_key_checks = 0');
$this->importFromTsvInDir($iterator->getChildren(), $con);
$con->exec('set foreign_key_checks = 1');
}
}
示例9: getChildren
/**
* @return \RecursiveIterator
*
* @throws AccessDeniedException
*/
public function getChildren()
{
try {
$children = parent::getChildren();
if ($children instanceof self) {
// parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore
$children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
}
return $children;
} catch (\UnexpectedValueException $e) {
if ($this->ignoreUnreadableDirs) {
// If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
return new \RecursiveArrayIterator(array());
} else {
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
}
}
示例10: load_tests
private function load_tests(RecursiveDirectoryIterator $dir)
{
while ($dir->valid()) {
$current = $dir->current();
if ($dir->isFile() && preg_match("/(.)Test\\.php\$/", $current->getFilename(), $matches)) {
// XXX: handle errors
include $current->getPathname();
$x = explode('.', $current->getFilename());
$class = $x[0];
$rclass = new ReflectionClass($class);
if ($rclass->getParentClass()->getName() == 'UnitTest') {
$this->cases[] = $rclass;
}
} elseif ($dir->hasChildren() && preg_match("/^\\./", $current->getFilename(), $matches) == 0) {
$this->load_tests($dir->getChildren());
}
$dir->next();
}
}
示例11: getChildren
/**
* @return RecursiveIterator
*
* @throws (ehough_finder_exception_AccessDeniedException
*/
public function getChildren()
{
try {
$children = parent::getChildren();
if ($children instanceof self) {
// parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore
$children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
// performance optimization to avoid redoing the same work in all children
$children->rewindable =& $this->rewindable;
$children->rootPath = $this->rootPath;
}
return $children;
} catch (UnexpectedValueException $e) {
if ($this->ignoreUnreadableDirs) {
// If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
return new RecursiveArrayIterator(array());
} else {
if (version_compare(PHP_VERSION, '5.3') >= 0) {
throw new ehough_finder_exception_AccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
throw new ehough_finder_exception_AccessDeniedException($e->getMessage(), $e->getCode());
}
}
}
示例12: getExamples
/**
* Data provider for testExamples method.
*
* Assumes that an `examples` directory exists inside parent directory.
* This examples directory should contain any number of subdirectories, each of which contains
* three files: one Mustache class (.php), one Mustache template (.mustache), and one output file
* (.txt).
*
* This whole mess will be refined later to be more intuitive and less prescriptive, but it'll
* do for now. Especially since it means we can have unit tests :)
*
* @access public
* @return array
*/
public function getExamples()
{
$basedir = dirname(__FILE__) . '/../examples/';
$ret = array();
$files = new RecursiveDirectoryIterator($basedir);
while ($files->valid()) {
if ($files->hasChildren() && ($children = $files->getChildren())) {
$example = $files->getSubPathname();
$class = null;
$template = null;
$output = null;
foreach ($children as $file) {
if (!$file->isFile()) {
continue;
}
$filename = $file->getPathInfo();
$info = pathinfo($filename);
switch ($info['extension']) {
case 'php':
$class = $info['filename'];
include_once $filename;
break;
case 'mustache':
$template = file_get_contents($filename);
break;
case 'txt':
$output = file_get_contents($filename);
break;
}
}
$ret[$example] = array($class, $template, $output);
}
$files->next();
}
return $ret;
}
示例13: loadCommands
/**
* Load all Command files from $path directory.
*
* Traverse all files inside specified directory, but loads only those files with suffix 'Command.php'.
*
* @param string $path Directory with Command files
* @param string|null $prefix Commands namespace
*
* @return void
*/
public function loadCommands($path, $prefix = null)
{
// load commands
try {
$iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO);
/** @var \RecursiveDirectoryIterator $child */
foreach ($iterator->getChildren() as $child) {
if ($child->isFile() && \preg_match('/Command.php$/', $child->getBasename())) {
$namespace = $class = "";
$gettingNamespace = $gettingClass = false;
foreach (\token_get_all(\file_get_contents($child->getRealPath())) as $token) {
if (\is_array($token) && ($token[0] === T_ABSTRACT || $token[0] === T_INTERFACE)) {
$namespace = $class = '';
break;
}
if (\is_array($token) && $token[0] === T_NAMESPACE) {
$gettingNamespace = true;
}
if (\is_array($token) && $token[0] === T_CLASS) {
$gettingClass = true;
}
if ($gettingNamespace === true) {
if (\is_array($token) && \in_array($token[0], [T_STRING, T_NS_SEPARATOR])) {
$namespace .= $token[1];
} else {
if ($token === ';') {
$gettingNamespace = false;
}
}
}
if ($gettingClass === true) {
if (\is_array($token) && $token[0] === T_STRING) {
$class = $token[1];
break;
}
}
}
$className = $namespace ? $namespace . '\\' . $class : $class;
if (\preg_match('/Command$/', $className) > 0) {
// make sure file with class is loaded
require_once $child->getRealPath();
/** @var Command $command */
$command = new $className();
if ($prefix !== null) {
$command->setName($prefix . ':' . $command->getName());
}
$this['console']->add($command);
}
}
}
} catch (\UnexpectedValueException $ex) {
// do nothing - no commands to load
}
}
示例14: getChildren
/**
* (PHP 5 >= 5.1.0)<br/>
* Return the inner iterator's children contained in a RecursiveFilterIterator
*
* @link http://php.net/manual/en/recursivefilteriterator.getchildren.php
* @return \RecursiveFilterIterator containing the inner iterator's children.
*/
public function getChildren()
{
return new self($this->iterator->getChildren(), $this->excluded);
}
示例15: toArray
/**
* Recursively convert RecursiveDirectoryIterator to array
*
* @param \RecursiveDirectoryIterator $tree
* @param string $path
* @return array
*/
protected function toArray(\RecursiveDirectoryIterator $tree, $path)
{
$array = array();
$types = array();
$names = array();
foreach ($tree as $file) {
if (strpos($file->getFileName(), '.') === 0) {
continue;
}
$types[] = (int) $file->isDir();
$names[] = $file->getFileName();
$array[] = $entry = array('type' => $file->isDir() ? 'folder' : 'file', 'name' => $file->getFileName(), 'path' => $localPath = str_replace($this->source, '', $file->getPath() . '/' . $file->getFileName()), 'children' => $tree->hasChildren() ? $this->toArray($tree->getChildren(), $path) : array(), 'state' => strpos($path, $localPath) === 0 ? 'open' : 'close');
}
array_multisort($types, SORT_NUMERIC, SORT_DESC, $names, SORT_STRING, SORT_ASC, $array);
return $array;
}