本文整理汇总了PHP中iterator_to_array函数的典型用法代码示例。如果您正苦于以下问题:PHP iterator_to_array函数的具体用法?PHP iterator_to_array怎么用?PHP iterator_to_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iterator_to_array函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction(ServerRequestInterface $Request, ResponseInterface $Response, callable $Next = null)
{
$data = [];
// $path = $Request->getOriginalRequest()->getUri()->getPath();
$pagdata = $this->getPaginationDataFromRequest($Request);
$entities = $this->storage->fetchAll('page_templates');
$cnt = count($entities);
// If the requested page is later than the last, redirect to the last
/*if ($cnt && $pagdata['page'] > $cnt) {
return $Response
->withStatus(302)
->withHeader('Location', sprintf('%s?page-categories=%d', $path, $cnt));
}*/
$entities->setItemCountPerPage($pagdata['size']);
$entities->setCurrentPageNumber($pagdata['page']);
$data['page_templates'] = iterator_to_array($entities->getCurrentItems());
// pagination data
$data['pagination'] = [];
$data['pagination']['page'] = $pagdata['page'];
$data['pagination']['size'] = $pagdata['size'];
$data['pagination']['count'] = $cnt;
// return new JsonResponse($data);
return new HtmlResponse($this->template->render('page/template::list', $data));
// return new HtmlResponse($this->template->render('page::category-list', $data));
}
开发者ID:Repkit,项目名称:rpkcms,代码行数:25,代码来源:TemplateAction.php
示例2: testIterator
public function testIterator()
{
$violations = array(10 => $this->getViolation('Error 1'), 20 => $this->getViolation('Error 2'), 30 => $this->getViolation('Error 3'));
$this->list = new ConstraintViolationList($violations);
// indices are reset upon adding -> array_values()
$this->assertSame(array_values($violations), iterator_to_array($this->list));
}
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:ConstraintViolationListTest.php
示例3: findSources
/**
* Create array of Sources from the given input directory.
*
* @param string $searchIn
* @param string $outputTo
* @return array
*/
protected function findSources($searchIn, $outputTo)
{
$files = iterator_to_array(new FilesystemIterator($searchIn));
return array_map(function (SplFileInfo $file) use($outputTo) {
return $this->makeSource($file, $outputTo);
}, $files);
}
开发者ID:parsnick,项目名称:steak,代码行数:14,代码来源:Builder.php
示例4: attributes
public function attributes($attributes)
{
if ($attributes instanceof \Traversable) {
$attributes = iterator_to_array($attributes);
}
return implode('', array_map(array($this, 'attributesCallback'), array_keys($attributes), array_values($attributes)));
}
开发者ID:rooster,项目名称:symfony,代码行数:7,代码来源:FormHelper.php
示例5: metaform
public function metaform()
{
$value = $this->getValue();
$data = $this->getData();
$attributes = $this->getAttr();
$form = array();
$options = array();
if (isset($data['options'])) {
if (!is_admin()) {
$new_options = array();
foreach ($data['options'] as $key => $option) {
$tmp = $option['value'];
$option['value'] = $option['types-value'];
$option['types-value'] = $tmp;
$new_options[$key] = $option;
unset($tmp);
}
$data['options'] = $new_options;
}
foreach ($data['options'] as $key => $option) {
$one_option_data = array('#value' => $option['value'], '#title' => stripslashes($option['title']));
/**
* add default value if needed
* issue: frontend, multiforms CRED
*/
// if (array_key_exists('types-value', $option)) {
// $one_option_data['#types-value'] = $option['types-value'];
// }
$options[] = $one_option_data;
}
}
/**
* for user fields we reset title and description to avoid double
* display
*/
$title = $this->getTitle();
if (empty($title)) {
$title = $this->getTitle(true);
}
$options = apply_filters('wpt_field_options', $options, $title, 'select');
/**
* default_value
*/
if (!empty($value) || $value == '0') {
$data['default_value'] = $value;
}
$is_multiselect = array_key_exists('multiple', $attributes) && 'multiple' == $attributes['multiple'];
$default_value = isset($data['default_value']) ? $data['default_value'] : null;
//Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/189219391/comments
if ($is_multiselect) {
$default_value = new RecursiveIteratorIterator(new RecursiveArrayIterator($default_value));
$default_value = iterator_to_array($default_value, false);
}
//##############################################################################################
/**
* metaform
*/
$form[] = array('#type' => 'select', '#title' => $this->getTitle(), '#description' => $this->getDescription(), '#name' => $this->getName(), '#options' => $options, '#default_value' => $default_value, '#multiple' => $is_multiselect, '#validate' => $this->getValidationData(), '#class' => 'form-inline', '#repetitive' => $this->isRepetitive());
return $form;
}
开发者ID:zoran180,项目名称:wp_szf,代码行数:60,代码来源:class.select.php
示例6: process
public function process($args)
{
$answer = "";
$args = trim($args);
if (strlen($args) > 0) {
$entrada = urlencode($args);
$url = "https://www.google.com.mx/search?q={$entrada}&oq=200&aqs=chrome.1.69i57j69i59j69i65l2j0l2.3015j0j8&client=ubuntu-browser&sourceid=chrome&es_sm=122&ie=UTF-8";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36');
$html = curl_exec($ch);
$web = new DomDocument();
@$web->loadHTML($html);
$nodos = @$web->getElementById('topstuff')->getElementsByTagName('div');
$answer = "No pude convertir lo que me pides.";
if ($nodos) {
$nodos = iterator_to_array($nodos);
if (count($nodos) === 6) {
$answer = utf8_decode($nodos[3]->nodeValue . " " . $nodos[4]->nodeValue);
}
}
} else {
$answer = "Ingresa una expresion.";
}
$this->reply($answer, $this->currentchannel, $this->nick);
}
开发者ID:jahrmando,项目名称:botijon,代码行数:27,代码来源:convertir.php
示例7: toStringRow
private function toStringRow($cells)
{
if ($cells instanceof \Traversable) {
$cells = iterator_to_array($cells);
}
return implode($this->separator, $cells);
}
开发者ID:adambisek,项目名称:io-table,代码行数:7,代码来源:CsvParser.php
示例8: testItMapsTheConfigArrayToInflectorDefinitions
public function testItMapsTheConfigArrayToInflectorDefinitions()
{
$interface = 'example_interface';
$methods = ['method1' => ['arg1', 'arg2']];
$subject = new InflectorConfig([$interface => $methods]);
assertEquals([new InflectorDefinition($interface, $methods)], iterator_to_array($subject));
}
开发者ID:tomphp,项目名称:config-service-provider,代码行数:7,代码来源:InflectorConfigTest.php
示例9: normalize
/**
* Normalize all non-scalar data types (except null) in a string value
*
* @param mixed $value
* @return mixed
*/
protected function normalize($value)
{
if (is_scalar($value) || null === $value) {
return $value;
}
// better readable JSON
static $jsonFlags;
if ($jsonFlags === null) {
$jsonFlags = 0;
$jsonFlags |= defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0;
$jsonFlags |= defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0;
}
// Error suppression is used in several of these cases as a fix for each of
// #5383 and #4616. Without it, #4616 fails whenever recursion occurs during
// json_encode() operations; usage of a dedicated error handler callback
// causes #5383 to fail when the Logger is being used as an error handler.
// The only viable solution here is error suppression, ugly as it may be.
if ($value instanceof DateTime) {
$value = $value->format($this->getDateTimeFormat());
} elseif ($value instanceof Traversable) {
$value = @json_encode(iterator_to_array($value), $jsonFlags);
} elseif (is_array($value)) {
$value = @json_encode($value, $jsonFlags);
} elseif (is_object($value) && !method_exists($value, '__toString')) {
$value = sprintf('object(%s) %s', get_class($value), @json_encode($value));
} elseif (is_resource($value)) {
$value = sprintf('resource(%s)', get_resource_type($value));
} elseif (!is_object($value)) {
$value = gettype($value);
}
return (string) $value;
}
开发者ID:Nurik4249,项目名称:torrentpier,代码行数:38,代码来源:Base.php
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("Fill...");
$minCard = $input->getArgument('min');
$maxCard = $input->getArgument('max');
$seed = sha1(microtime() . rand() . $minCard . $maxCard);
/* @var $progressBar \Symfony\Component\Console\Helper\ProgressHelper */
$progressBar = $this->getHelper('progress');
/* @var $repo \Trismegiste\Yuurei\Persistence\RepositoryInterface */
$repo = $this->getContainer()->get('dokudoki.repository');
$netizenList = iterator_to_array($repo->find(['-class' => 'netizen']), false);
$netizenCount = count($netizenList);
$query = ['-class' => ['$in' => ['small', 'picture', 'video', 'repeat', 'status']]];
$pubCount = $repo->getCursor($query)->count();
$progressBar->start($output, $pubCount);
$cursor = $repo->find($query);
/* @var $publish \Trismegiste\Socialist\Publishing */
foreach ($cursor as $publish) {
$commentaryCount = rand($minCard, $maxCard);
for ($k = 0; $k < $commentaryCount; $k++) {
/* @var $picked \Trismegiste\SocialBundle\Security\Netizen */
$picked = $netizenList[rand(0, $netizenCount - 1)];
$comment = new \Trismegiste\Socialist\Commentary($picked->getAuthor());
$comment->setMessage("This is a commentary ({$seed}) to fill the database for benchmark purpose");
foreach ($picked->getFanIterator() as $fan => $dummy) {
$tmpAuth = new \Trismegiste\Socialist\Author($fan);
$comment->addFan($tmpAuth);
}
$publish->attachCommentary($comment);
}
$repo->persist($publish);
$progressBar->advance();
}
$progressBar->finish();
}
开发者ID:xtrasmal,项目名称:iinano,代码行数:35,代码来源:Commentary.php
示例11: getWordsTw
public function getWordsTw()
{
//$tweetSearch=$this->barredoraTw->tweetSearch;
$db = $this->database;
$tags = iterator_to_array($db->selectCollection('tweetSearch')->find()->sort(array('UScreatedAt' => -1))->limit(50));
return $tags;
}
开发者ID:brm-sanabrias,项目名称:nemo,代码行数:7,代码来源:class.MongoNemo.inc.php
示例12: renameDirectory
/**
* Emulates changing of directory name.
*
* @param string $path
* @param string $newPath
*
* @return bool
*/
public function renameDirectory($path, $newPath)
{
$sourcePath = $this->applyPathPrefix(rtrim($path, '/') . '/');
$objectsIterator = $this->client->getIterator('listObjects', ['Bucket' => $this->bucket, 'Prefix' => $sourcePath]);
$objects = array_filter(iterator_to_array($objectsIterator), function ($v) {
return isset($v['Key']);
});
if (!empty($objects)) {
/* @var OperationManager $operation */
$operation = $this->app['operation'];
$operation->start();
$total = count($objects);
$current = 0;
foreach ($objects as $entry) {
$this->client->copyObject(array('Bucket' => $this->bucket, 'Key' => $this->replacePath($entry['Key'], $path, $newPath), 'CopySource' => urlencode($this->bucket . '/' . $entry['Key'])));
if ($operation->isAborted()) {
// Delete target folder in case if operation was aborted
$targetPath = $this->applyPathPrefix(rtrim($newPath, '/') . '/');
$this->client->deleteMatchingObjects($this->bucket, $targetPath);
return true;
}
$operation->updateStatus(array('total' => $total, 'current' => ++$current));
}
$this->client->deleteMatchingObjects($this->bucket, $sourcePath);
}
return true;
}
开发者ID:mat33470,项目名称:PFA,代码行数:35,代码来源:AwsS3.php
示例13: testMustNotTerminateWithTraversable
public function testMustNotTerminateWithTraversable()
{
$traversable = simplexml_load_string('<root><foo/><foo/><foo/></root>')->foo;
$chunked = new ChunkedIterator($traversable, 2);
$actual = iterator_to_array($chunked, false);
$this->assertCount(2, $actual);
}
开发者ID:jorjoh,项目名称:Varden,代码行数:7,代码来源:ChunkedIteratorTest.php
示例14: flatten
/**
* Normalize all non-scalar data types (except null) in a string value
*
* @param mixed $value
* @return mixed
*/
protected function flatten($value)
{
if (is_scalar($value) || null === $value) {
return $value;
}
// better readable JSON
static $jsonFlags;
if ($jsonFlags === null) {
$jsonFlags = 0;
$jsonFlags |= defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0;
$jsonFlags |= defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0;
}
if ($value instanceof \DateTime) {
$value = $value->format($this->getDateTimeFormat());
} elseif ($value instanceof \Traversable) {
$value = json_encode(iterator_to_array($value), $jsonFlags);
} elseif (is_array($value)) {
$value = json_encode($value, $jsonFlags);
} elseif (is_object($value) && !method_exists($value, '__toString')) {
$value = sprintf('object(%s) %s', get_class($value), json_encode($value));
} elseif (is_resource($value)) {
$value = sprintf('resource(%s)', get_resource_type($value));
} elseif (!is_object($value)) {
$value = gettype($value);
}
return (string) $value;
}
开发者ID:phPoirot,项目名称:Logger,代码行数:33,代码来源:AbstractFormatter.php
示例15: __construct
/**
* Sets default option values for this instance
*
* @param array|\Traversable $options
*/
public function __construct($options = array())
{
if ($options instanceof Traversable) {
$options = iterator_to_array($options);
} elseif (!is_array($options)) {
$options = func_get_args();
$temp['uriHandler'] = array_shift($options);
if (!empty($options)) {
$temp['allowRelative'] = array_shift($options);
}
if (!empty($options)) {
$temp['allowAbsolute'] = array_shift($options);
}
$options = $temp;
}
if (isset($options['uriHandler'])) {
$this->setUriHandler($options['uriHandler']);
}
if (isset($options['allowRelative'])) {
$this->setAllowRelative($options['allowRelative']);
}
if (isset($options['allowAbsolute'])) {
$this->setAllowAbsolute($options['allowAbsolute']);
}
parent::__construct($options);
}
开发者ID:Baft,项目名称:Zend-Form,代码行数:31,代码来源:Uri.php
示例16: __construct
/**
* __construct(): defined by Route interface.
*
* @see Route::__construct()
* @param mixed $options
* @return void
*/
public function __construct($options = null)
{
parent::__construct($options);
if ($options instanceof Config) {
$options = $options->toArray();
} elseif ($options instanceof Traversable) {
$options = iterator_to_array($options);
}
if (!is_array($options)) {
throw new Exception\InvalidArgumentException(sprintf(
'Expected an array or Traversable; received "%s"',
(is_object($options) ? get_class($options) : gettype($options))
));
}
if (!isset($options['route']) || !$options['route'] instanceof Route) {
throw new Exception\InvalidArgumentException('Route not defined or not an instance of Route');
}
$this->route = $options['route'];
$this->mayTerminate = (isset($options['may_terminate']) && $options['may_terminate']);
if (isset($options['child_routes'])) {
$this->childRoutes = $options['child_routes'];
}
}
开发者ID:rickogden,项目名称:zf2,代码行数:35,代码来源:Part.php
示例17: assertOrderedIterator
protected function assertOrderedIterator($expected, \Traversable $iterator)
{
$values = array_map(function (HandlerInterface $handler) {
return $handler->getPath();
}, iterator_to_array($iterator));
$this->assertEquals($expected, array_values($values));
}
开发者ID:pkdevboxy,项目名称:filesystem,代码行数:7,代码来源:IteratorTestCase.php
示例18: iteratorToArray
/**
* @static
* @param $iterator
* @param bool $recursive
* @return array
* @throws Exception
*/
public static function iteratorToArray($iterator, $recursive = true)
{
if (!is_array($iterator) && !$iterator instanceof Traversable) {
throw new Exception(__METHOD__ . ' expects an array or Traversable object');
}
if (!$recursive) {
if (is_array($iterator)) {
return $iterator;
}
return iterator_to_array($iterator);
}
if (method_exists($iterator, 'toArray')) {
return $iterator->toArray();
}
$array = array();
foreach ($iterator as $key => $value) {
if (is_scalar($value)) {
$array[$key] = $value;
continue;
}
if ($value instanceof Traversable) {
$array[$key] = static::iteratorToArray($value, $recursive);
continue;
}
if (is_array($value)) {
$array[$key] = static::iteratorToArray($value, $recursive);
continue;
}
$array[$key] = $value;
}
return $array;
}
开发者ID:magix-cms,项目名称:magixcms-3,代码行数:39,代码来源:ArrayTools.php
示例19: __construct
/**
* Constructor
*
* We used the Adapter instead of Zend\Db for a performance reason.
*
* @param Adapter|array|Traversable $db
* @param string $tableName
* @param array $columnMap
* @param string $separator
* @throws Exception\InvalidArgumentException
*/
public function __construct($db, $tableName = null, array $columnMap = null, $separator = null)
{
if ($db instanceof Traversable) {
$db = iterator_to_array($db);
}
if (is_array($db)) {
parent::__construct($db);
$separator = isset($db['separator']) ? $db['separator'] : null;
$columnMap = isset($db['column']) ? $db['column'] : null;
$tableName = isset($db['table']) ? $db['table'] : null;
$db = isset($db['db']) ? $db['db'] : null;
}
if (!$db instanceof Adapter) {
throw new Exception\InvalidArgumentException('You must pass a valid Zend\\Db\\Adapter\\Adapter');
}
$tableName = (string) $tableName;
if ('' === $tableName) {
throw new Exception\InvalidArgumentException('You must specify a table name. Either directly in the constructor, or via options');
}
$this->db = $db;
$this->tableName = $tableName;
$this->columnMap = $columnMap;
if (!empty($separator)) {
$this->separator = $separator;
}
$this->setFormatter(new DbFormatter());
}
开发者ID:eltonoliveira,项目名称:jenkins,代码行数:38,代码来源:Db.php
示例20: __construct
/**
* Constructor
*
* @param array $data
* @param object $adapter
*/
public function __construct($data, $adapter = null)
{
if (is_object($data)) {
if (method_exists($data, 'toArray')) {
$data= $data->toArray();
} elseif ($data instanceof \Traversable) {
$data = iterator_to_array($data);
}
}
if (empty($data) || !is_array($data)) {
throw new Exception\InvalidArgumentException('You must pass an array of parameters');
}
foreach ($this->attributeRequired as $key) {
if (empty($data[$key])) {
throw new Exception\InvalidArgumentException(sprintf(
'The param "%s" is a required parameter for class %s',
$key,
__CLASS__
));
}
}
$this->attributes = $data;
$this->adapter = $adapter;
}
开发者ID:necrogami,项目名称:zf2,代码行数:33,代码来源:Image.php
注:本文中的iterator_to_array函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论