本文整理汇总了PHP中iterator_count函数的典型用法代码示例。如果您正苦于以下问题:PHP iterator_count函数的具体用法?PHP iterator_count怎么用?PHP iterator_count使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iterator_count函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attached
/**
* This method will be called when the component (or component's parent)
* becomes attached to a monitored object. Do not call this method yourself.
* @param Nette\ComponentModel\IComponent
* @return void
*/
protected function attached($presenter)
{
if ($presenter instanceof Presenter) {
$name = $this->lookupPath('Nette\Application\UI\Presenter');
if (!isset($this->getElementPrototype()->id)) {
$this->getElementPrototype()->id = 'frm-' . $name;
}
if (iterator_count($this->getControls()) && $this->isSubmitted()) {
foreach ($this->getControls() as $control) {
if (!$control->isDisabled()) {
$control->loadHttpData();
}
}
}
if (!$this->getAction()) {
$this->setAction(new Link($presenter, 'this', array()));
$signal = new Nette\Forms\Controls\HiddenField($name . self::NAME_SEPARATOR . 'submit');
$signal->setOmitted()->setHtmlId(FALSE);
$this[Presenter::SIGNAL_KEY] = $signal;
}
}
parent::attached($presenter);
}
示例2: count
/**
* Recreates the command cursor and counts its results.
*
* @see http://php.net/manual/en/countable.count.php
* @return integer
*/
public function count()
{
$cursor = $this;
return $this->retry(function () use($cursor) {
return iterator_count($cursor);
});
}
示例3: attached
/**
* This method will be called when the component (or component's parent)
* becomes attached to a monitored object. Do not call this method yourself.
* @param IComponent
* @return void
*/
protected function attached($presenter)
{
if ($presenter instanceof NPresenter) {
$name = $this->lookupPath('NPresenter');
if (!isset($this->getElementPrototype()->id)) {
$this->getElementPrototype()->id = 'frm-' . $name;
}
$this->setAction(new NLink(
$presenter,
$name . self::NAME_SEPARATOR . 'submit!',
array()
));
if (iterator_count($this->getControls()) && $this->isSubmitted()) {
foreach ($this->getControls() as $control) {
if (!$control->isDisabled()) {
$control->loadHttpData();
}
}
}
}
parent::attached($presenter);
}
示例4: send
/**
* Envia a notificação para dispositivos Android
*
* @param Device[] $devices
* Dispositivos
* @param Message $message
* Notificação
* @param NotificationResult $notificationResult
* Resultado do envio da notificação
* @param PushManager $pushManager
* Gerenciador de push
*/
public static function send($devices, $message, $notificationResult, $pushManager)
{
if (iterator_count($devices->getIterator()) > 0) {
try {
$gcmAdapter = new GcmAdapter(array('apiKey' => ANDROID_API_KEY));
// envia as notificações
$push = new Push($gcmAdapter, $devices, $message);
$pushManager->add($push);
$pushManager->push();
// obtém a resposta do envio do envio
$response = $gcmAdapter->getResponse();
// dispositivo que não receberam as notificações e motivo
$failureResults = $response->getResult(Response::RESULT_ERROR);
$failureDevices = AndroidPushController::handleFailureResult($failureResults);
// dispositivo que tiveram seus identificadores modificados
$canonicalResults = $response->getResult(Response::RESULT_CANONICAL);
AndroidPushController::handleCanonicalResult($canonicalResults);
$notificationResult->addDevicesNotNotified($failureDevices);
} catch (\Exception $e) {
global $log;
$log->Error($e);
$notificationResult->setAndroidFailed(true);
$notificationResult->setAndroidFailureReason($e->getMessage());
}
}
}
示例5: GetPath
function GetPath($path)
{
$fullPath = system\Helper::arcGetPath(true) . "assets/" . $path . "/";
$webPath = system\Helper::arcGetPath() . "assets" . $path;
$files = scandir($fullPath);
$html = "";
foreach ($files as $file) {
if ($file != "." && $file != "..") {
$html .= "<tr>" . "<td style=\"width: 10px;\"><input type=\"checkbox\" id=\"{$file}\" onchange=\"mark('{$path}/{$file}')\"><label for=\"{$file}\"></label></td>";
if (is_dir($fullPath . $file)) {
// folder
$fi = new FilesystemIterator($fullPath . $file, FilesystemIterator::SKIP_DOTS);
$html .= "<td><i class=\"fa fa-folder-o\"></i> <a class=\"clickable\" onclick=\"getFolderPath('{$path}/{$file}')\">{$file}</a></td>" . "<td style=\"width: 10px;\">folder</td>" . "<td style=\"width: 10px;\">-</td>" . "<td style=\"width: 100px;\">" . iterator_count($fi) . ngettext(" item", " items", iterator_count($fi)) . "</td>" . "<td style=\"width: 100px;\">" . date("d M Y", filectime($fullPath . $file)) . "</td>";
} else {
// get file type
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$filetype = finfo_file($finfo, $fullPath . $file);
finfo_close($finfo);
// file
$html .= "<td><i class=\"" . GetFileTypeIcon($filetype) . "\"></i> <a class=\"clickable\" onclick=\"viewFile('{$webPath}/{$file}', '{$filetype}', '" . FileSizeConvert(filesize($fullPath . $file)) . "', '" . date("d M Y", filectime($fullPath . $file)) . "')\">{$file}<a/></td>" . "<td style=\"width: 10px;\">{$filetype}</td>" . "<td style=\"width: 10px;\"><a alt=\"Copy link to clipboard\" class=\"clickable\" onclick=\"copyToClipboard('{$webPath}/{$file}')\"><i class=\"fa fa-link\"></i></a></td>" . "<td style=\"width: 100px;\">" . FileSizeConvert(filesize($fullPath . $file)) . "</td>" . "<td style=\"width: 100px;\">" . date("d M Y", filectime($fullPath . $file)) . "</td>";
}
$html .= "</tr>";
}
}
// no files
if (count($files) == 2) {
$html .= "<tr><td colspan=\"4\" class=\"text-center\">Folder is empty.</td></tr>";
}
return $html;
}
示例6: flushProcessedFilesCommand
/**
* Flush all processed files to be used for debugging mainly.
*
* @return void
*/
public function flushProcessedFilesCommand()
{
foreach ($this->getStorageRepository()->findAll() as $storage) {
// This only works for local driver
if ($storage->getDriverType() === 'Local') {
$this->outputLine();
$this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid()));
$this->outputLine('--------------------------------------------');
$this->outputLine();
#$storage->getProcessingFolder()->delete(TRUE); // will not work
// Well... not really FAL friendly but straightforward for Local drivers.
$processedDirectoryPath = PATH_site . $storage->getProcessingFolder()->getPublicUrl();
$fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS);
$numberOfProcessedFiles = iterator_count($fileIterator);
GeneralUtility::rmdir($processedDirectoryPath, TRUE);
GeneralUtility::mkdir($processedDirectoryPath);
// recreate the directory.
$message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles);
$this->outputLine($message);
// Remove the record as well.
$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS numberOfProcessedFiles', 'sys_file_processedfile', 'storage = ' . $storage->getUid());
$this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'storage = ' . $storage->getUid());
$message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $record['numberOfProcessedFiles']);
$this->outputLine($message);
}
}
// Remove possible remaining "sys_file_processedfile"
$query = 'TRUNCATE sys_file_processedfile';
$this->getDatabaseConnection()->sql_query($query);
}
示例7: process
public function process()
{
$crawler = $this->client->request($this->plan['method'], $this->plan['uri']);
if (isset($this->plan['selector'])) {
$selection = $crawler->filter($this->plan['selector']);
} elseif (isset($this->plan['xpath'])) {
$selection = $crawler->filterXPath($this->plan['path']);
}
if ($this->plan['images']) {
$images = $selection->filterXPath('//img');
if (iterator_count($images) > 1) {
foreach ($images as $image) {
$crawler = new Crawler($image);
$info = parse_url($this->plan['uri']);
$url = $info['scheme'] . '://' . $info['host'] . '/' . $crawler->attr('src');
if (strpos($crawler->attr('src'), 'http') === 0) {
$url = $info['scheme'] . '://' . $info['host'] . '/' . $this->plan['path'] . $crawler->attr('src');
}
copy($url, SCRYPHP_STORAGE_PATH_IMG . DIRECTORY_SEPARATOR . substr(strrchr($url, "/"), 1));
}
}
}
file_put_contents(SCRYPHP_STORAGE_PATH_TXT . DIRECTORY_SEPARATOR . time() . uniqid(time(), true) . '.txt', $selection->text());
return $selection->text();
}
示例8: count
/**
* @param array|\Traversable $array
* @return int
*/
public static function count($array)
{
if (!is_array($array) && !$array instanceof \Traversable) {
throw new InvalidArgumentException(sprintf('Parameter must be an array or class implements Traversable, %s given.', gettype($array)));
}
return $array instanceof \Traversable ? iterator_count($array) : count($array);
}
示例9: parse
public function parse($output)
{
$trlElements = array();
$fileCount = iterator_count($this->_fileFinder);
$output->writeln('Twig-Files:');
$progress = new ProgressBar($output, $fileCount);
$twig = $this->_createKwfTwigEnvironment();
foreach ($this->_fileFinder as $file) {
$nodes = $twig->parse($twig->tokenize(file_get_contents($file->getRealpath()), $file->getRealpath()));
$trlElementsFromFile = array();
//Recursively loop through the AST
foreach ($nodes as $child) {
if ($child instanceof \Twig_Node) {
$trlElementsFromFile = $this->_process($child, $trlElementsFromFile);
}
}
foreach ($trlElementsFromFile as $trlElement) {
$trlElement['file'] = $file->getRealpath();
$trlElements[] = $trlElement;
}
$progress->advance();
}
$progress->finish();
$output->writeln('');
return $trlElements;
}
示例10: count
public function count()
{
if ($this->getInnerIterator() instanceof Countable) {
return count($this->getInnerIterator());
}
return iterator_count($this->getInnerIterator());
}
示例11: testCases
/**
* @dataProvider provideCases
*/
function testCases(array $insert, array $params, array $expect)
{
$iterator = new ArrayIterator($insert);
$slice = call_user_func_array([$iterator, 'slice'], $params);
$this->assertEquals(count($expect), iterator_count($slice));
$this->assertEquals($expect, $slice->values()->toArray());
}
示例12: getIterator
/**
* Index the all the files in the directory and sub directories
*
* @param string|null $directory
* @return RecursiveDirectoryIterator
*/
protected function getIterator($directory = null)
{
$directories = $this->config['content_directories'];
// some flags to filter . and .. and follow symlinks
$flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS;
if ($directory) {
//Iterate only this directory
return new \RecursiveDirectoryIterator($directory, $flags);
}
if ($directories) {
$directoryIterators = [];
foreach ($directories as $directory) {
//Create an array of the paths
$directoryIterators[] = new \RecursiveDirectoryIterator(each($directory)[1], $flags);
}
$iterator = new \AppendIterator();
foreach ($directoryIterators as $directoryIterator) {
//Append the directory iterator to the iterator
$iterator->append(new \RecursiveIteratorIterator($directoryIterator));
}
} else {
throw new Exception("Unable to read the content path, check the configuration file.");
}
if (iterator_count($iterator) == 0) {
throw new Exception("The content directory is empty.");
}
return $iterator;
}
示例13: info
/**
* @param strin|null $url
* @return void
*/
public function info($url = null)
{
$folder = CACHE . 'views' . DS;
if (!is_dir($folder)) {
mkdir($folder, 0770, true);
}
if (!$url) {
$fi = new \FilesystemIterator($folder, \FilesystemIterator::SKIP_DOTS);
$count = iterator_count($fi);
$this->out($count . ' cache files found.');
return;
}
$cache = new CacheFilter();
$file = $cache->getFile($url);
if (!$file) {
$this->out('No cache file found');
return;
}
$content = file_get_contents($file);
$cacheInfo = $cache->extractCacheInfo($content);
$time = $cacheInfo['time'];
if ($time) {
$time = date(FORMAT_DB_DATETIME, $time);
} else {
$time = '(unlimited)';
}
$this->out('Cache File: ' . basename($file));
$this->out('URL ext: ' . $cacheInfo['ext']);
$this->out('Cached until: ' . $time);
}
示例14: assertContainsType
protected function assertContainsType($type, $expectedCount)
{
$it = new \CallbackFilterIterator(new \ArrayIterator($this->types), function ($item) use($type) {
return $item === $type;
});
return $this->assertSame($expectedCount, iterator_count($it));
}
示例15: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Start up application with supplied config...');
$config = $input->getArgument('applicationConfig');
$path = stream_resolve_include_path($config);
if (!is_readable($path)) {
throw new \InvalidArgumentException("Invalid loader path: {$config}");
}
// Init the application once using given config
// This way the late static binding on the AspectKernel
// will be on the goaop-zf2-module kernel
\Zend\Mvc\Application::init(include $path);
if (!class_exists(AspectKernel::class, false)) {
$message = "Kernel was not initialized yet. Maybe missing module Go\\ZF2\\GoAopModule in config {$path}";
throw new \InvalidArgumentException($message);
}
$kernel = AspectKernel::getInstance();
$options = $kernel->getOptions();
if (empty($options['cacheDir'])) {
throw new \InvalidArgumentException('Cache warmer require the `cacheDir` options to be configured');
}
$enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']);
$iterator = $enumerator->enumerate();
$totalFiles = iterator_count($iterator);
$output->writeln("Total <info>{$totalFiles}</info> files to process.");
$iterator->rewind();
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
});
$index = 0;
$errors = [];
foreach ($iterator as $file) {
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln("Processing file <info>{$file->getRealPath()}</info>");
}
$isSuccess = null;
try {
// This will trigger creation of cache
file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . '/resource=' . $file->getRealPath());
$isSuccess = true;
} catch (\Exception $e) {
$isSuccess = false;
$errors[$file->getRealPath()] = $e;
}
if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) {
$output->write($isSuccess ? '.' : '<error>E</error>');
if (++$index % 50 == 0) {
$output->writeln("({$index}/{$totalFiles})");
}
}
}
restore_error_handler();
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
foreach ($errors as $file => $error) {
$message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}";
$output->writeln($message);
}
}
$output->writeln('<info>Done</info>');
}