本文整理汇总了PHP中RecursiveIteratorIterator::getSubIterator方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::getSubIterator方法的具体用法?PHP RecursiveIteratorIterator::getSubIterator怎么用?PHP RecursiveIteratorIterator::getSubIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::getSubIterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: _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;
}
}
示例3: 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);
}
}
}
示例4: 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;
}
示例5: setup
/**
* [setup description]
* @param Array $array
* @return void
* @link http://stackoverflow.com/a/10424516
*/
protected function setup(array $array)
{
$ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));
$this->arr = array();
foreach ($ritit as $leafValue) {
$keys = array();
foreach (range(0, $ritit->getDepth()) as $depth) {
$keys[] = $ritit->getSubIterator($depth)->key();
}
$this->set(join('.', $keys), $leafValue);
}
}
示例6: __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);
}
}
示例7: registerContainerParametersRecursive
protected function registerContainerParametersRecursive(ContainerBuilder $container, $alias, $config)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($config), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $value) {
$path = array();
for ($i = 0; $i <= $iterator->getDepth(); $i++) {
$path[] = $iterator->getSubIterator($i)->key();
}
$key = $alias . '.' . implode(".", $path);
$container->setParameter($key, $value);
}
}
示例8: extractRepositoriesUrls
private function extractRepositoriesUrls(array $repositories)
{
$urls = array();
$recursiveIteratorRepositories = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($repositories));
foreach ($recursiveIteratorRepositories as $key => $leaf) {
if ('url' === $key) {
$repositoryPosition = $recursiveIteratorRepositories->getSubIterator(0)->key();
$urls[$repositoryPosition][] = $leaf;
}
}
return $urls;
}
示例9: getNavBar
/**
* Get the wiki root directory files tree
* @param string wiki root directory
* @return array
*/
public function getNavBar($navPath)
{
$recursiveIteratorIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($navPath, \FilesystemIterator::SKIP_DOTS));
$filesTree = [];
foreach ($recursiveIteratorIterator as $splFileInfo) {
$path = $splFileInfo->isDir() ? array($splFileInfo->getFilename() => []) : array($splFileInfo->getFilename());
for ($depth = $recursiveIteratorIterator->getDepth() - 1; $depth >= 0; $depth--) {
$path = [$recursiveIteratorIterator->getSubIterator($depth)->current()->getFilename() => $path];
}
$filesTree = array_merge_recursive($filesTree, $path);
}
return $filesTree;
}
示例10: arrayKeyToStringPath
/**
* Converts a multi-dimensional array to dot-notation single dimensional strings
* Convert:
* [
* 'foo' => [
* 'bar' => 'baz
* ],
* 'baa' => 'sheep'
* ]
*
* TO
* [
* 'foo.bar' => 'baz',
* 'baa' => 'sheep'
* ]
*
* @param $arrayContents
*
* @return array
*/
public function arrayKeyToStringPath($arrayContents)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrayContents));
$result = [];
foreach ($iterator as $leafValue) {
$keys = [];
foreach (range(0, $iterator->getDepth()) as $depth) {
$keys[] = $iterator->getSubIterator($depth)->key();
}
$result[join(self::SEPARATOR, $keys)] = $leafValue;
}
return $result;
}
示例11: extractKeys
public function extractKeys($array, $prefix = null)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));
$keys = [];
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;
}
$keys[] = $prefix . "." . $key;
}
return $keys;
}
示例12: flatten
public function flatten()
{
$ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->config));
$result = array();
foreach ($ritit as $leafValue) {
$keys = array();
foreach (range(0, $ritit->getDepth()) as $depth) {
$keys[] = $ritit->getSubIterator($depth)->key();
}
$result[join('.', $keys)] = $leafValue;
}
return $result;
}
示例13: handleResponse
/**
* Override response handler to flatten array
*/
protected function handleResponse($response, OutputInterface $output)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($response));
$result = [];
foreach ($iterator as $leafValue) {
$keys = [];
foreach (range(0, $iterator->getDepth()) as $depth) {
$keys[] = $iterator->getSubIterator($depth)->key();
}
$result[join('.', $keys)] = $leafValue;
}
return parent::handleResponse($result, $output);
}
示例14: compact
/**
* Convert a php nested array to mongo like dot notation
* @see http://stackoverflow.com/questions/10424335/php-convert-multidimensional-array-to-2d-array-with-dot-notation-keys
* @param array $array
* @return array
*/
public static function compact(array $array)
{
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
$rVal = [];
foreach ($iterator as $leafValue) {
$keys = array();
foreach (range(0, $iterator->getDepth()) as $depth) {
$keys[] = $iterator->getSubIterator($depth)->key();
}
$rVal[join('.', $keys)] = $leafValue;
}
return $rVal;
}
示例15: getRecursive
/**
* @param string $directory
*/
public static function getRecursive($directory)
{
$recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
$r = array();
foreach ($recursiveIterator as $splFileInfo) {
$path = array('children' => array($splFileInfo->getFilename() => array('type' => $splFileInfo->getType())));
for ($depth = $recursiveIterator->getDepth() - 1; $depth >= 0; $depth--) {
$path = array('children' => array($recursiveIterator->getSubIterator($depth)->current()->getFilename() => $path));
}
$r = array_merge_recursive($r, $path);
}
self::deep_ksort($r);
return $r;
}