本文整理汇总了PHP中iterator_to_array函数的典型用法代码示例。如果您正苦于以下问题:PHP iterator_to_array函数的具体用法?PHP iterator_to_array怎么用?PHP iterator_to_array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iterator_to_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例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));
}
示例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);
}
示例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)));
}
示例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;
}
示例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);
}
示例7: toStringRow
private function toStringRow($cells)
{
if ($cells instanceof \Traversable) {
$cells = iterator_to_array($cells);
}
return implode($this->separator, $cells);
}
示例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));
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}