本文整理汇总了PHP中SplObjectStorage::count方法的典型用法代码示例。如果您正苦于以下问题:PHP SplObjectStorage::count方法的具体用法?PHP SplObjectStorage::count怎么用?PHP SplObjectStorage::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplObjectStorage
的用法示例。
在下文中一共展示了SplObjectStorage::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeHandler
/**
* Remove the given log message handler if it is registered.
*
* @param LogHandler $handler
*/
public function removeHandler(LogHandler $handler)
{
if ($this->handlers->contains($handler)) {
$this->handlers->detach($handler);
$this->enabled = $this->handlers->count() ? true : false;
}
}
示例2: shouldShutDownMessenger
protected function shouldShutDownMessenger(Messenger $messenger)
{
if ($this->callQueue->count() == 0 && $this->pool->count() > $this->options['min_size']) {
unset($this->coreMessengerMapping[spl_object_hash($messenger)]);
$this->pool->detach($messenger);
$messenger->softTerminate();
return;
}
$this->readyPool->enqueue($messenger);
}
示例3: getConnectionByPosition
/**
* @param $pos
*
* @return null|AbstractSQLConnection
*/
public function getConnectionByPosition($pos)
{
$pos = (int) $pos;
$this->storage->rewind();
for ($i = 0; $this->storage->count() > $i; $i++) {
if ($i === $pos) {
return $this->storage->current();
}
$this->storage->next();
}
return null;
}
示例4: offsetExists
/**
* @see ArrayAccess::offsetExists()
*/
public function offsetExists($offset)
{
if ($this->container->count()) {
$result = true;
/* @var $keyValue \ArrayAccess */
foreach ($this->container as $keyValue) {
$result = $result && $keyValue->offsetExists($offset);
}
return $result;
} else {
return false;
}
}
示例5: getLink
/**
* @inheritDoc
*/
public function getLink(Driver $driver, Query $query)
{
if (!$this->idle->isEmpty()) {
return $this->idle->dequeue();
}
if ($this->pool->count() >= $this->params['max_connections']) {
$this->waiting->enqueue($query);
return false;
}
$link = $driver->connect($this->params, $this->params['username'], $this->params['passwd']);
$this->pool->attach($link);
return $link;
}
示例6: pop
/**
* @coroutine
*
* @return \Generator
*
* @resolve \Icicle\Postgres\Connection
*/
private function pop() : \Generator
{
while (null !== $this->awaitable) {
try {
(yield $this->awaitable);
// Prevent simultaneous connection creation.
} catch (\Throwable $exception) {
// Ignore failure or cancellation of other operations.
}
}
if ($this->idle->isEmpty()) {
try {
if ($this->connections->count() >= $this->getMaxConnections()) {
// All possible connections busy, so wait until one becomes available.
$this->awaitable = new Delayed();
(yield $this->awaitable);
} else {
// Max connection count has not been reached, so open another connection.
$this->awaitable = new Coroutine($this->createConnection());
$this->addConnection((yield $this->awaitable));
}
} finally {
$this->awaitable = null;
}
}
// Shift a connection off the idle queue.
return $this->idle->shift();
}
示例7: getVarId
protected function getVarId(Operand $var)
{
if (isset($this->varIds[$var])) {
return $this->varIds[$var];
} else {
return $this->varIds[$var] = $this->varIds->count() + 1;
}
}
示例8: withConnection
public function withConnection($cb)
{
// First check idle connections.
if ($this->available->count() > 0) {
$connection = $this->available->dequeue();
$cb($connection);
return;
}
// Check if we have max connections
if ($this->pool->count() >= $this->maxConnections) {
$this->waiting->enqueue($cb);
}
// Otherwise, create a new connection
$connection = ConnectionFactory::createConnection();
$this->pool->attach($connection);
$cb($connection);
}
示例9: invoke
/**
* @return ResourceObject|mixed
*/
private function invoke()
{
if ($this->requests->count() === 0) {
return $this->invoker->invoke($this->request);
}
$this->requests->attach($this->request);
return $this->invoker->invokeSync($this->requests);
}
示例10: addSitemap
/**
* @param \Sitemapper\SitemapInterface $sitemap
*/
public function addSitemap(SitemapInterface $sitemap)
{
$this->boot();
$this->sitemaps->attach($sitemap);
$index = $this->sitemaps->count();
$sitemap->setLocation($this->getLocation($index));
$this->sitemaps->offsetSet($sitemap, $index);
$this->indexSitemap->addSitemap($sitemap);
}
示例11: findReturnBlocks
protected function findReturnBlocks(Block $block, $result = [])
{
$toProcess = new \SplObjectStorage();
$processed = new \SplObjectStorage();
$results = new \SplObjectStorage();
$addNull = false;
$toProcess->attach($block);
while ($toProcess->count() > 0) {
foreach ($toProcess as $block) {
$toProcess->detach($block);
$processed->attach($block);
foreach ($block->children as $op) {
if ($op instanceof Op\Terminal\Return_) {
$results->attach($op);
continue 2;
// Prevent dead code from executing
} elseif ($op instanceof Op\Terminal\Throw_) {
// throws are ok
continue 2;
} elseif ($op instanceof Op\Stmt\Jump) {
if (!$processed->contains($op->target)) {
$toProcess->attach($op->target);
}
continue 2;
} elseif ($op instanceof Op\Stmt\JumpIf) {
if (!$processed->contains($op->if)) {
$toProcess->attach($op->if);
}
if (!$processed->contains($op->else)) {
$toProcess->attach($op->else);
}
continue 2;
} elseif ($op instanceof Op\Stmt\Switch_) {
foreach ($op->targets as $target) {
if (!is_array($target)) {
// TODO FIX THIS
$target = [$target];
}
foreach ($target as $t) {
if (!$processed->contains($t)) {
$toProcess->attach($t);
}
}
}
continue 2;
}
}
// If we reach here, we have an empty return default block, add it to the result
$addNull = true;
}
}
$results = iterator_to_array($results);
if ($addNull) {
$results[] = null;
}
return $results;
}
示例12: commit
/**
* @param null|mixed|array $models (optional)
*/
public function commit($models = null)
{
$pool = $this->manager->getPool();
/** @var ObjectManager[] $managers */
$managers = $pool->getIterator();
if (null === $models) {
foreach ($managers as $manager) {
$manager->flush();
}
if (!$this->models->count()) {
return;
}
$this->models->rewind();
while ($this->models->valid()) {
$model = $this->models->current();
$class = $this->manager->getClassMetadata(get_class($model));
$managerName = $class->getManagerReferenceGenerator();
$ref = call_user_func(array($model, 'get' . ucfirst($managerName)));
$id = call_user_func(array($ref, 'get' . ucfirst($class->getIdentifierReference($managerName)->referenceField)));
foreach ($this->models->getInfo() as $managerName) {
$this->saveSpecificModel($model, $managerName, $id);
}
$this->models->next();
}
// clear list
$this->models = new \SplObjectStorage();
} else {
if (!is_array($models)) {
$models = array($models);
}
foreach ($models as $model) {
$class = $this->manager->getClassMetadata(get_class($model));
$managerName = $class->getManagerReferenceGenerator();
$ref = call_user_func(array($model, 'get' . ucfirst($managerName)));
$pool->getManager($managerName)->flush($ref);
$id = call_user_func(array($ref, 'get' . ucfirst($class->getIdentifierReference($managerName)->referenceField)));
foreach ($class->getFieldManagerNames() as $managerName) {
$this->saveSpecificModel($model, $managerName, $id);
}
}
}
}
示例13: createRelationsContent
public function createRelationsContent(ClassMetadataInterface $classMetadata, $object)
{
$relationsContent = new \SplObjectStorage();
foreach ($classMetadata->getRelations() as $relationMetadata) {
if (null === $relationMetadata->getContent()) {
continue;
}
$relationsContent->attach($relationMetadata, $this->getContent($relationMetadata, $object));
}
return $relationsContent->count() === 0 ? null : $relationsContent;
}
示例14: run
/**
* {@inheritdoc}
*/
public function run()
{
$this->running = true;
while ($this->running) {
$this->nextTickQueue->tick();
$this->futureTickQueue->tick();
$flags = \Ev::RUN_ONCE;
if (!$this->running || !$this->nextTickQueue->isEmpty() || !$this->futureTickQueue->isEmpty()) {
$flags |= \Ev::RUN_NOWAIT;
} elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count()) {
break;
}
$this->loop->run($flags);
}
}
示例15: applyTo
/**
* Performs the pipeline of callbacks to initial data.
* It is possible to set an starting value, and to specify if that starting value has to be
* casted (only has effect if a caster is set).
*
* @param mixed $initial
* @param \Toobo\PipePie\DTO $dto
* @param mixed $cursor
* @return mixed
*/
public function applyTo($initial, DTO $dto = null, $cursor = null)
{
if ($this->working) {
throw new LogicException("It is not possible run a Pipeline that is already working.");
}
if ($this->pipeline->count() === 0) {
return $initial;
}
$this->DTOs->push($this->init($dto, $initial));
$carry = $this->initialValue($initial, $cursor);
while ($this->pipeline->valid()) {
$carry = $this->run($initial, $carry);
$this->pipeline->next();
}
$this->working = false;
return $carry;
}