コード例 #1
0
ファイル: Logger.php プロジェクト: koolkode/async
 /**
  * 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;
     }
 }
 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
0
 /**
  * @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
0
 /**
  * @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
0
 /**
  * @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
0
ファイル: AbstractPool.php プロジェクト: icicleio/postgres
 /**
  * @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
0
ファイル: Printer.php プロジェクト: ircmaxell/php-cfg
 protected function getVarId(Operand $var)
 {
     if (isset($this->varIds[$var])) {
         return $this->varIds[$var];
     } else {
         return $this->varIds[$var] = $this->varIds->count() + 1;
     }
 }
コード例 #8
0
 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
0
ファイル: Resource.php プロジェクト: mackstar/spout
 /**
  * @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
0
ファイル: Generator.php プロジェクト: marcelomx/sitemapper
 /**
  * @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
0
ファイル: ReturnType.php プロジェクト: ircmaxell/tuli
 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
0
ファイル: UnitOfWork.php プロジェクト: pokap/pool-dbm
 /**
  * @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
0
 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
0
ファイル: LibEvLoop.php プロジェクト: domraider/rxnet
 /**
  * {@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
0
ファイル: Pipeline.php プロジェクト: toobo/pipepie
 /**
  * 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;
 }
コード例 #16
0
ファイル: RobotSwarm.php プロジェクト: stil/curl-robot
 /**
  * @return RequestHandler
  */
 protected function nextRequest()
 {
     if ($this->pendingRequests->count() > 0) {
         $this->pendingRequests->rewind();
         $handler = $this->pendingRequests->current();
         $handler->incrementAttempts();
         $this->pendingRequests->detach($handler);
     } else {
         $request = $this->requestProvider->nextRequest();
         if ($request instanceof Request) {
             $handler = new RequestHandler($request);
         } else {
             $this->requestProviderEmpty = true;
             $handler = null;
         }
     }
     return $handler;
 }
コード例 #17
0
 /**
  * @param \SplObjectStorage $param
  *
  * @return \SplObjectStorage
  */
 public function filter($param = null) : \SplObjectStorage
 {
     if (!$param) {
         return new \SplObjectStorage();
     }
     if ($param->count() === 1) {
         return $param;
     }
     $idValue = $returnNode = null;
     $returnCollection = new \SplObjectStorage();
     foreach ($param as $node) {
         if (!$idValue || $this->compare($node->getId(), $idValue)) {
             $idValue = $node->getId();
             $returnNode = $node;
         }
     }
     $returnCollection->attach($returnNode);
     return $returnCollection;
 }
コード例 #18
0
ファイル: core.php プロジェクト: jerfowler/yada
 /**
  * Attach a new Model Object by storing a new Meta ArrayObject
  *
  * @param Yada_Model $model
  * @param mixed $values
  * @return Yada_Model
  */
 public function attach(Yada_Model $model, $values = NULL)
 {
     // Get the class and common name of the Model
     $class = get_class($model);
     $name = Yada::common_name('model', $class);
     $plural = inflector::plural($name);
     $index = $this->_models->count();
     // Create a new ArrayObject to act as the Meta Object and initialize some properties
     $this->_meta = new ArrayObject(array('name' => $name, 'class' => $class, 'plural' => $plural, 'index' => $index, 'alias' => $index . '_' . $name, 'fields' => array(), 'clauses' => array(), 'select' => array(), 'exclude' => array(), 'mapper' => NULL, 'collect' => NULL), ArrayObject::ARRAY_AS_PROPS);
     // Initialize objects of derived Meta classes
     $this->_attach($this->_meta, $values);
     // Attach the model and meta data, set the focus
     $this->_models->attach($model, $this->_meta);
     $this->_current = $model;
     // Initialize the Model
     $model::initialize($model, $this);
     // Initialize the Mapper Object
     $this->_meta['mapper'] = Yada::mapper($this, $model, $values);
     // Register aggregate methods
     $this->export($model);
     // return the model
     return $model;
 }
コード例 #19
0
ファイル: CssEventHandler.php プロジェクト: nikosv/openeclass
 public function __construct($dom)
 {
     $this->alreadyMatched = new SplObjectStorage();
     $matches = new SplObjectStorage();
     if (is_array($dom) || $dom instanceof SplObjectStorage) {
         foreach ($dom as $item) {
             if ($item instanceof DOMNode && $item->nodeType == XML_ELEMENT_NODE) {
                 $matches->attach($item);
             }
         }
         if ($matches->count() > 0) {
             $matches->rewind();
             $this->dom = $matches->current();
         } else {
             $this->dom = NULL;
         }
         $this->matches = $matches;
     } elseif ($dom instanceof DOMDocument) {
         $this->dom = $dom->documentElement;
         $matches->attach($dom->documentElement);
     } elseif ($dom instanceof DOMElement) {
         $this->dom = $dom;
         $matches->attach($dom);
     } elseif ($dom instanceof DOMNodeList) {
         $a = array();
         foreach ($dom as $item) {
             if ($item->nodeType == XML_ELEMENT_NODE) {
                 $matches->attach($item);
                 $a[] = $item;
             }
         }
         $this->dom = $a;
     } else {
         throw new Exception("Unhandled type: " . get_class($dom));
     }
     $this->matches = $matches;
 }
コード例 #20
0
ファイル: serialize_bad.php プロジェクト: badlamer/hhvm
<?php

try {
    $s = new SplObjectStorage();
    $s->unserialize('s:31:"something which is not an array";');
} catch (UnexpectedValueException $e) {
    var_dump($e->getMessage());
}
var_dump($s->count() == 0);
echo "===RUN2===\n";
try {
    $s = new SplObjectStorage();
    $s->unserialize('s:60:"something broken";');
} catch (UnexpectedValueException $e) {
    var_dump($e->getMessage());
}
var_dump($s->count() == 0);
コード例 #21
0
ファイル: Region.php プロジェクト: mastercoding/conquest-php
 /**
  * Check if object has neighbors
  *
  * @return bool
  */
 public function hasNeighbors()
 {
     return $this->neighbors->count() > 0;
 }
コード例 #22
0
 /**
  * @return boolean
  */
 public function hasChildren()
 {
     return 0 < $this->children->count();
 }
コード例 #23
0
ファイル: Rows.php プロジェクト: radmar/APYDataGridBundle
 /**
  * (non-PHPdoc)
  * @see Countable::count()
  */
 public function count()
 {
     return $this->rows->count();
 }
コード例 #24
0
ファイル: AdjacencyList.php プロジェクト: sdboyer/gliph
 /**
  * {@inheritdoc}
  */
 public function order()
 {
     return $this->vertices->count();
 }
コード例 #25
0
 public function count()
 {
     if (is_array($this->objectIdentifiers)) {
         return count($this->objectIdentifiers);
     } else {
         return parent::count();
     }
 }
コード例 #26
0
 /**
  * Checks if there are any unsuccessful requests at all.
  *
  * @return bool
  */
 public function hasExceptions()
 {
     return $this->exceptions->count() > 0;
 }
コード例 #27
0
 /**
  * Count elements of an object
  *
  * @link http://php.net/manual/en/countable.count.php
  * @return int The custom count as an integer.
  * </p>
  * <p>
  * The return value is cast to an integer.
  * @since 5.1.0
  */
 public function count()
 {
     return $this->collection->count();
 }
コード例 #28
0
ファイル: CookieJar.php プロジェクト: php-http/message
 /**
  * {@inheritdoc}
  */
 public function count()
 {
     return $this->cookies->count();
 }
コード例 #29
0
 /**
  * Create a new event handler.
  */
 public function __construct($dom)
 {
     $this->alreadyMatched = new \SplObjectStorage();
     $matches = new \SplObjectStorage();
     // Array of DOMElements
     if (is_array($dom) || $dom instanceof \SplObjectStorage) {
         //$matches = array();
         foreach ($dom as $item) {
             if ($item instanceof \DOMNode && $item->nodeType == XML_ELEMENT_NODE) {
                 //$matches[] = $item;
                 $matches->attach($item);
             }
         }
         //$this->dom = count($matches) > 0 ? $matches[0] : NULL;
         if ($matches->count() > 0) {
             $matches->rewind();
             $this->dom = $matches->current();
         } else {
             //throw new Exception("Setting DOM to Null");
             $this->dom = NULL;
         }
         $this->matches = $matches;
     } elseif ($dom instanceof \DOMDocument) {
         $this->dom = $dom->documentElement;
         $matches->attach($dom->documentElement);
     } elseif ($dom instanceof \DOMElement) {
         $this->dom = $dom;
         $matches->attach($dom);
     } elseif ($dom instanceof \DOMNodeList) {
         $a = array();
         // Not sure why we are doing this....
         foreach ($dom as $item) {
             if ($item->nodeType == XML_ELEMENT_NODE) {
                 $matches->attach($item);
                 $a[] = $item;
             }
         }
         $this->dom = $a;
     } else {
         throw new \QueryPath\Exception("Unhandled type: " . get_class($dom));
     }
     $this->matches = $matches;
 }
コード例 #30
0
 /**
  * {@inheritdoc}
  */
 public function findAcls(array $oids, array $sids = array())
 {
     $result = new \SplObjectStorage();
     $currentBatch = array();
     $oidLookup = array();
     for ($i = 0, $c = count($oids); $i < $c; $i++) {
         $oid = $oids[$i];
         $oidLookupKey = $oid->getIdentifier() . $oid->getType();
         $oidLookup[$oidLookupKey] = $oid;
         $aclFound = false;
         // check if result already contains an ACL
         if ($result->contains($oid)) {
             $aclFound = true;
         }
         // check if this ACL has already been hydrated
         if (!$aclFound && isset($this->loadedAcls[$oid->getType()][$oid->getIdentifier()])) {
             $acl = $this->loadedAcls[$oid->getType()][$oid->getIdentifier()];
             if (!$acl->isSidLoaded($sids)) {
                 // FIXME: we need to load ACEs for the missing SIDs. This is never
                 //        reached by the default implementation, since we do not
                 //        filter by SID
                 throw new \RuntimeException('This is not supported by the default implementation.');
             } else {
                 $result->attach($oid, $acl);
                 $aclFound = true;
             }
         }
         // check if we can locate the ACL in the cache
         if (!$aclFound && null !== $this->cache) {
             $acl = $this->cache->getFromCacheByIdentity($oid);
             if (null !== $acl) {
                 if ($acl->isSidLoaded($sids)) {
                     // check if any of the parents has been loaded since we need to
                     // ensure that there is only ever one ACL per object identity
                     $parentAcl = $acl->getParentAcl();
                     while (null !== $parentAcl) {
                         $parentOid = $parentAcl->getObjectIdentity();
                         if (isset($this->loadedAcls[$parentOid->getType()][$parentOid->getIdentifier()])) {
                             $acl->setParentAcl($this->loadedAcls[$parentOid->getType()][$parentOid->getIdentifier()]);
                             break;
                         } else {
                             $this->loadedAcls[$parentOid->getType()][$parentOid->getIdentifier()] = $parentAcl;
                             $this->updateAceIdentityMap($parentAcl);
                         }
                         $parentAcl = $parentAcl->getParentAcl();
                     }
                     $this->loadedAcls[$oid->getType()][$oid->getIdentifier()] = $acl;
                     $this->updateAceIdentityMap($acl);
                     $result->attach($oid, $acl);
                     $aclFound = true;
                 } else {
                     $this->cache->evictFromCacheByIdentity($oid);
                     foreach ($this->findChildren($oid) as $childOid) {
                         $this->cache->evictFromCacheByIdentity($childOid);
                     }
                 }
             }
         }
         // looks like we have to load the ACL from the database
         if (!$aclFound) {
             $currentBatch[] = $oid;
         }
         // Is it time to load the current batch?
         $currentBatchesCount = count($currentBatch);
         if ($currentBatchesCount > 0 && (self::MAX_BATCH_SIZE === $currentBatchesCount || $i + 1 === $c)) {
             try {
                 $loadedBatch = $this->lookupObjectIdentities($currentBatch, $sids, $oidLookup);
             } catch (AclNotFoundException $aclNotFoundException) {
                 if ($result->count()) {
                     $partialResultException = new NotAllAclsFoundException('The provider could not find ACLs for all object identities.');
                     $partialResultException->setPartialResult($result);
                     throw $partialResultException;
                 } else {
                     throw $aclNotFoundException;
                 }
             }
             foreach ($loadedBatch as $loadedOid) {
                 $loadedAcl = $loadedBatch->offsetGet($loadedOid);
                 if (null !== $this->cache) {
                     $this->cache->putInCache($loadedAcl);
                 }
                 if (isset($oidLookup[$loadedOid->getIdentifier() . $loadedOid->getType()])) {
                     $result->attach($loadedOid, $loadedAcl);
                 }
             }
             $currentBatch = array();
         }
     }
     // check that we got ACLs for all the identities
     foreach ($oids as $oid) {
         if (!$result->contains($oid)) {
             if (1 === count($oids)) {
                 $objectName = method_exists($oid, '__toString') ? $oid : get_class($oid);
                 throw new AclNotFoundException(sprintf('No ACL found for %s.', $objectName));
             }
             $partialResultException = new NotAllAclsFoundException('The provider could not find ACLs for all object identities.');
             $partialResultException->setPartialResult($result);
             throw $partialResultException;
         }
     }
     return $result;
 }