本文整理汇总了PHP中RecursiveIteratorIterator::getDepth方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::getDepth方法的具体用法?PHP RecursiveIteratorIterator::getDepth怎么用?PHP RecursiveIteratorIterator::getDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::getDepth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reorder
public function reorder(Request $req, Response $res)
{
if (!$req->isPost()) {
throw new \Chalk\Exception("Reorder action only accepts POST requests");
}
if (!$req->nodeData) {
return $res->redirect($this->url(array('action' => 'index')));
}
$data = json_decode($req->nodeData);
$structure = $this->em('Chalk\\Core\\Structure')->id($req->structure);
$nodes = $this->em('Chalk\\Core\\Structure\\Node')->all(['structure' => $structure]);
$map = [];
foreach ($nodes as $node) {
$map[$node->id] = $node;
}
$it = new \RecursiveIteratorIterator(new Iterator($data), \RecursiveIteratorIterator::SELF_FIRST);
$stack = [];
foreach ($it as $i => $value) {
array_splice($stack, $it->getDepth(), count($stack), array($value));
$depth = $it->getDepth();
$parent = $depth > 0 ? $stack[$depth - 1] : $structure->root;
$node = $map[$value->id];
$node->parent->children->removeElement($node);
$node->parent = $map[$parent->id];
$node->sort = $i;
}
$this->em->flush();
$this->notify("Content was moved successfully", 'positive');
if (isset($req->redirect)) {
return $res->redirect($req->redirect);
} else {
return $res->redirect($this->url(array('action' => 'index')));
}
}
示例2: buildArray
public function buildArray()
{
$directory = new \RecursiveDirectoryIterator('assets');
$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::CHILD_FIRST);
$tree = [];
foreach ($iterator as $info) {
//if (in_array($info->getFilename(), ['.', '..'])) continue;
if ($iterator->getDepth() >= 2 || !$iterator->isDir() || $iterator->isDot()) {
continue;
}
if ($iterator->getDepth() == 1) {
$path = $info->isDir() ? [$iterator->getDepth() - 1 => $info->getFilename()] : [$info->getFilename()];
} else {
$path = $info->isDir() ? [$info->getFilename() => []] : [$info->getFilename()];
}
for ($depth = $iterator->getDepth() - 1; $depth >= 0; $depth--) {
$path = [$iterator->getSubIterator($depth)->current()->getFilename() => $path];
}
$tree = array_merge_recursive($tree, $path);
}
$data = array();
foreach ($tree as $category => $children) {
foreach ($children as $index => $value) {
$data[$category][] = $value;
}
}
foreach ($data as $category => $children) {
$parentId = $this->addEntry($category, '0');
foreach ($children as $index => $value) {
$this->addEntry($value, $parentId);
}
}
return $data;
}
示例3: _convertToDotNotation
private function _convertToDotNotation()
{
foreach ($this->_iterator as $leafValue) {
$keys = [];
foreach (range(0, $this->_iterator->getDepth()) as $depth) {
$keys[] = $this->_iterator->getSubIterator($depth)->key();
}
$key = join(self::DELIMITER, $keys);
$this->_result[$key] = $leafValue;
}
}
示例4: createResources
public static function createResources(ProjectProfile $profile, $moduleName, Resource $targetModuleResource = null)
{
// find the appliction directory, it will serve as our module skeleton
if ($targetModuleResource == null) {
$targetModuleResource = $profile->search('applicationDirectory');
$targetModuleEnabledResources = array('ControllersDirectory', 'ModelsDirectory', 'ViewsDirectory', 'ViewScriptsDirectory', 'ViewHelpersDirectory', 'ViewFiltersDirectory');
}
// find the actual modules directory we will use to house our module
$modulesDirectory = $profile->search('modulesDirectory');
// if there is a module directory already, except
if ($modulesDirectory->search(array('moduleDirectory' => array('moduleName' => $moduleName)))) {
throw new Exception\RuntimeException('A module named "' . $moduleName . '" already exists.');
}
// create the module directory
$moduleDirectory = $modulesDirectory->createResource('moduleDirectory', array('moduleName' => $moduleName));
// create a context filter so that we can pull out only what we need from the module skeleton
$moduleContextFilterIterator = new ContextFilter($targetModuleResource, array('denyNames' => array('ModulesDirectory', 'ViewControllerScriptsDirectory'), 'denyType' => 'Zend\\Tool\\Project\\Context\\Filesystem\\File'));
// the iterator for the module skeleton
$targetIterator = new \RecursiveIteratorIterator($moduleContextFilterIterator, \RecursiveIteratorIterator::SELF_FIRST);
// initialize some loop state information
$currentDepth = 0;
$parentResources = array();
$currentResource = $moduleDirectory;
$currentChildResource = null;
// loop through the target module skeleton
foreach ($targetIterator as $targetSubResource) {
$depthDifference = $targetIterator->getDepth() - $currentDepth;
$currentDepth = $targetIterator->getDepth();
if ($depthDifference === 1) {
// if we went down into a child, make note
array_push($parentResources, $currentResource);
// this will have always been set previously by another loop
$currentResource = $currentChildResource;
} elseif ($depthDifference < 0) {
// if we went up to a parent, make note
$i = $depthDifference;
do {
// if we went out more than 1 parent, get to the correct parent
$currentResource = array_pop($parentResources);
} while ($i-- > 0);
}
// get parameters for the newly created module resource
$params = $targetSubResource->getAttributes();
$currentChildResource = $currentResource->createResource($targetSubResource->getName(), $params);
// based of the provided list (Currently up top), enable specific resources
if (isset($targetModuleEnabledResources)) {
$currentChildResource->setEnabled(in_array($targetSubResource->getName(), $targetModuleEnabledResources));
} else {
$currentChildResource->setEnabled($targetSubResource->isEnabled());
}
}
return $moduleDirectory;
}
示例5: parents
public function parents($config = array())
{
$config = new KConfig($config);
$config->append(array(
'name' => 'parent_id'
));
$query = KFactory::get('koowa:database.query')
->where('pages_menu_id', '=', $config->pages_menu_id)
->where('enabled', '<>', -2)
->order(array('parent_id', 'ordering'))
->limit(0);
$pages = KFactory::get('com://admin/pages.database.table.pages')
->select($query);
if($config->pages_page_id)
{
if($row = $pages->find($config->pages_page_id)) {
$pages->removeRow($row);
}
}
$html = array();
$selected = $config->selected == 0 ? 'checked="checked"' : '';
$html[] = '<input type="radio" name="'.$config->name.'" id="'.$config->name.'0" value="0" '.$selected.' />';
$html[] = '<label for="'.$config->name.'0">'.JText::_('Top').'</label>';
$html[] = '<br />';
$iterator = new RecursiveIteratorIterator($pages, RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $page)
{
$selected = $config->selected == $page->id ? 'checked="checked"' : '';
if($iterator->getDepth() + 1) {
$html[] = str_repeat('. ', $iterator->getDepth());
$html[] = '<sup>|_</sup> ';
}
$html[] = '<input type="radio" name="'.$config->name.'" id="'.$config->name.$page->id.'" value="'.$page->id.'" '.$selected.' />';
$html[] = '<label for="'.$config->name.$page->id.'">'.$page->title.'</label>';
$html[] = '<br />';
}
return implode(PHP_EOL, $html);
}
示例6: 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);
}
}
}
示例7: 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;
}
示例8: 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;
}
示例9: array_flatten
function array_flatten(array $array, $key_separator = '/')
{
$result = array();
// a stack of strings
$keys = array();
$prev_depth = -1;
$iter = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST);
// rewind() is necessary
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$curr_depth = $iter->getDepth();
$diff_depth = $prev_depth - $curr_depth + 1;
//##### TODO: It would be nice to do this with a single function.
while ($diff_depth > 0) {
array_pop($keys);
--$diff_depth;
}
/*
Note:
http://bugs.php.net/bug.php?id=52425
array_shift/array_pop: add parameter that tells how many to elements to pop
*/
array_push($keys, $iter->key());
if (is_scalar($iter->current())) {
$result[implode($key_separator, $keys)] = $iter->current();
}
$prev_depth = $curr_depth;
}
return $result;
}
示例10: showPageItems
/**
* A convenience method to dump the page rows.
*/
private function showPageItems()
{
$tree = PagePeer::retrieveTree();
$iterator = new RecursiveIteratorIterator($tree, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $item) {
/* @var $item Page */
echo str_repeat('- ', $iterator->getDepth()), $item->getId(), ': ', $item->getTitle(), ' [', $item->getLeftValue(), ':', $item->getRightValue(), ']' . "\n";
}
}
示例11: categories
public function categories($config = array())
{
$config = new Library\ObjectConfig($config);
$config->append(array('name' => 'category', 'deselect' => true, 'selected' => $config->category, 'prompt' => '- Select -', 'table' => '', 'parent' => '', 'max_depth' => 9));
if ($config->deselect) {
$options[] = $this->option(array('text' => \JText::_($config->prompt), 'value' => 0));
}
$list = $this->getObject('com:categories.model.categories')->table($config->table)->parent($config->parent)->sort('title')->getRowset();
$iterator = new \RecursiveIteratorIterator($list, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $item) {
if ($iterator->getDepth() > $config->max_depth) {
break;
}
$title = substr('---------', 0, $iterator->getDepth()) . $item->title;
$options[] = $this->option(array('text' => $title, 'value' => $item->id));
}
$config->options = $options;
return $this->optionlist($config);
}
示例12: testRecursiveTreeItarator
function testRecursiveTreeItarator()
{
$structHolder = $this->getTestStructure();
$pathBuilder = new pathBuilder('/index.html');
$sectionData = $structHolder->getPageSection($pathBuilder, 'current');
$section = $sectionData['curSection'];
$level = $sectionData['level'];
$iterator = new RecursiveIteratorIterator(new contentTreeRecursiveIterator($section), RecursiveIteratorIterator::SELF_FIRST);
$tocItems = array();
foreach ($iterator as $topic) {
if ($level != -1 && $iterator->getDepth() > $level - 1) {
continue;
}
$topic['href'] = ltrim($iterator->getPath() . '/' . $topic['href'], '\\/');
$topic['level'] = $iterator->getDepth();
$tocItems[] = $topic;
}
$this->assertEqual($tocItems, array(array('href' => 'introduction.html', 'title' => 'Введение', 'level' => 0), array('href' => 'installation.html', 'title' => 'Установка', 'level' => 0), array('href' => 'quickstart.html', 'title' => 'Простой пример', 'level' => 0), array('href' => 'content/index.html', 'title' => 'Книга', 'level' => 0), array('href' => 'content/bookshelf.html', 'title' => 'Книжная полка', 'level' => 1), array('href' => 'content/toc.html', 'title' => 'Структура', 'level' => 1), array('href' => 'content/text.html', 'title' => 'Текст', 'level' => 1), array('href' => 'layout/index.html', 'title' => 'Оформление', 'level' => 0), array('href' => 'layout/theme.html', 'title' => 'Темы', 'level' => 1), array('href' => 'layout/system_settings.html', 'title' => 'Системные настройки', 'level' => 1), array('href' => 'export.html', 'title' => 'Экспорт', 'level' => 0), array('href' => 'appendix/index.html', 'title' => 'Приложения', 'level' => 0), array('href' => 'appendix/topic_index.html', 'title' => 'Предметный указатель', 'level' => 1), array('href' => 'appendix/authors.html', 'title' => 'Авторы', 'level' => 1), array('href' => 'appendix/license.html', 'title' => 'Лицензия', 'level' => 1), array('href' => 'appendix/similar.html', 'title' => 'Аналоги', 'level' => 1), array('href' => 'appendix/roadmap.html', 'title' => 'Планы по развитию', 'level' => 1)), 'Correct data obtained');
}
示例13: _findLoop
/**
* Main lookup loop
*
* @param \RecursiveIteratorIterator $items
* @param scalar $needle
* @param const $findBy mode to find by
*
* @return array
*/
protected function _findLoop(\RecursiveIteratorIterator $items, $needle, $findBy)
{
$result = [];
foreach ($items as $key => $value) {
$iter_keys = [];
for ($i = $items->getDepth() - 1; $i > 0; $i--) {
$iter_keys[] = $items->getSubIterator($i)->key();
}
// Value Search
if ($findBy === parent::FIND_BY_VALUE && $value === $needle) {
$result[] = ['key' => $key, 'value' => $value, 'depth' => $items->getDepth(), 'parent_keys' => $iter_keys];
} else {
if ($findBy === parent::FIND_BY_KEY && $key === $needle) {
$result[] = ['key' => $key, 'value' => $value, 'depth' => $items->getDepth(), 'parent_keys' => $iter_keys];
}
}
}
return $result;
}
示例14: __construct
/**
* Liste le répertoire
* @param string $pPath
*/
public function __construct($pPath)
{
$this->_directory = $pPath;
$ritit = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pPath), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ritit as $splFileInfo) {
$path = $splFileInfo->isDir() ? array($splFileInfo->getFilename() => array()) : array($splFileInfo->getFilename());
for ($depth = $ritit->getDepth() - 1; $depth >= 0; $depth--) {
$path = array($ritit->getSubIterator($depth)->current()->getFilename() => $path);
}
$this->_files = array_merge_recursive($this->_files, $path);
}
}
示例15: findActive
/**
* Copy from Zend View Helper Navigation AbstractHelper
*
* @see \Zend\View\Helper\Navigation\AbstractHelper::findActive()
*/
public function findActive($container, $minDepth = null, $maxDepth = -1)
{
$this->parseContainer($container);
if (!is_int($minDepth)) {
$minDepth = $this->getMinDepth();
}
if ((!is_int($maxDepth) || $maxDepth < 0) && null !== $maxDepth) {
$maxDepth = $this->getMaxDepth();
}
$found = null;
$foundDepth = -1;
$iterator = new \RecursiveIteratorIterator($container, \RecursiveIteratorIterator::CHILD_FIRST);
if ('index' === $this->view->url) {
$url = '/';
} else {
$url = '/' . $this->view->url;
}
/**
* @var \Zend\Navigation\Page\AbstractPage $page
*/
foreach ($iterator as $page) {
if ($url === $page->uri) {
$page->active = 1;
}
$currDepth = $iterator->getDepth();
if ($currDepth < $minDepth || !$this->accept($page)) {
// page is not accepted
continue;
}
if ($page->isActive(false) && $currDepth > $foundDepth) {
// found an active page at a deeper level than before
$found = $page;
$foundDepth = $currDepth;
}
}
if (is_int($maxDepth) && $foundDepth > $maxDepth) {
while ($foundDepth > $maxDepth) {
if (--$foundDepth < $minDepth) {
$found = null;
break;
}
$found = $found->getParent();
if (!$found instanceof AbstractPage) {
$found = null;
break;
}
}
}
if ($found) {
return array('page' => $found, 'depth' => $foundDepth);
}
return array();
}