/**
  * Triggers PERSIST_INPUT_ERROR events for all currently active inputs
  */
 public function onSubscriptionStateChange()
 {
     foreach ($this->_inputErrorCollection as $input) {
         /* @var Input $input */
         $this->handleInputErrors($input, $this->_inputErrorCollection->getInfo());
     }
 }
Exemplo n.º 2
0
 /**
  * 刷新监听者队列
  */
 protected function refreshQueue()
 {
     $this->storage->rewind();
     $this->queue = new \SplPriorityQueue();
     foreach ($this->storage as $listener) {
         $priority = $this->storage->getInfo();
         $this->queue->insert($listener, $priority);
     }
 }
Exemplo n.º 3
0
 /**
  * @return RangeFile[]
  */
 private function getAllFiles()
 {
     $all = [];
     $this->map->rewind();
     while ($this->map->valid() === true) {
         array_push($all, $this->map->getInfo());
         $this->map->next();
     }
     return $all;
 }
Exemplo n.º 4
0
 /**
  * @param   string    $name
  * @return  bool|ConfigurationInterface
  */
 protected function findByName($name)
 {
     $this->connections->rewind();
     while ($this->connections->valid()) {
         if ($this->connections->getInfo() === $name) {
             return $this->connections->current();
         }
         $this->connections->next();
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * @param array $categories
  *
  * @return HandlerInterface[]
  */
 public function all(array $categories = array())
 {
     $handlers = array();
     foreach ($this->handlers as $handler) {
         $handlerCategories = $this->handlers->getInfo();
         if (array() === $categories || array() !== array_intersect($handlerCategories, $categories)) {
             $handlers[] = $handler;
         }
     }
     return $handlers;
 }
Exemplo n.º 6
0
 /**
  * 删除一个监听器
  * @param $listener
  * @return $this
  */
 public function remove($listener)
 {
     if ($this->has($listener)) {
         $this->store->detach($listener);
         $this->store->rewind();
         $queue = new \SplPriorityQueue();
         foreach ($this->store as $listener) {
             // 优先级
             $priority = $this->store->getInfo();
             $queue->insert($listener, $priority);
         }
         $this->queue = $queue;
     }
     return $this;
 }
Exemplo n.º 7
0
 /**
  * @param \Nette\Forms\IControl|\Nette\Forms\Controls\BaseControl $control
  *
  * @return object
  */
 protected function getControlEntityClass(Nette\Forms\IControl $control)
 {
     foreach ($this->entities as $entity) {
         if ($this->entities->getInfo() === $control->getParent()) {
             return $this->getTargetClassName($entity, $this->getControlField($control));
         }
     }
     return NULL;
 }
Exemplo n.º 8
0
 private function eventsToPublish()
 {
     $events = array();
     $this->eventsToPublish->rewind();
     while ($this->eventsToPublish->valid()) {
         $events = array_merge($events, $this->eventsToPublish->getInfo());
         $this->eventsToPublish->next();
     }
     return $events;
 }
Exemplo n.º 9
0
 /**
  * @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);
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * Run current callback in the pipeline.
  *
  * @param $initial
  * @param $carry
  * @return mixed
  */
 private function run($initial, $carry)
 {
     /** @var callable $callback */
     $callback = $this->pipeline->current();
     /** @var array $args */
     $args = $this->pipeline->getInfo();
     array_unshift($args, $this->DTOs->top());
     array_unshift($args, $initial);
     array_unshift($args, $carry);
     return $this->maybeCast(call_user_func_array($callback, $args));
 }
Exemplo n.º 11
0
 /**
  * Get the edges set
  *
  * @return Edge[]
  */
 public function getEdgeSet()
 {
     $set = array();
     foreach ($this->adjacency as $vertex) {
         $edgeList = $this->adjacency->getInfo();
         foreach ($edgeList as $item) {
             $set[] = $edgeList->getInfo();
         }
     }
     return $set;
 }
Exemplo n.º 12
0
 public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested)
 {
     $storage = array();
     unset($a[Caster::PREFIX_DYNAMIC . "gcdata"]);
     // Don't hit https://bugs.php.net/65967
     foreach ($c as $obj) {
         $storage[spl_object_hash($obj)] = array('object' => $obj, 'info' => $c->getInfo());
     }
     $a += array(Caster::PREFIX_VIRTUAL . 'storage' => $storage);
     return $a;
 }
Exemplo n.º 13
0
 public function createParser($name)
 {
     $signatures =& self::$signatures;
     $signatures = new \SplObjectStorage();
     $class = "class {$name} {\n" . "public \$length;\n" . 'public function parse($input) {' . '$this -> length = strlen($input);' . '$input .= "\\0";' . '$pos = 0;' . 'return [' . $this . ', $pos, $this -> length];' . "}\n";
     foreach ($signatures as $signature) {
         list($id, $code) = $signatures->getInfo();
         $class .= 'public function _' . $id . '($input, &$pos) {' . $code . '}' . "\n";
     }
     $class .= '}';
     return $class;
 }
Exemplo n.º 14
0
 /**
  * Return the dominant eigenvector of the adjacency matrix of
  * this graph
  *
  * @param float $precision
  * @return \SplObjectStorage
  */
 public function getEigenVectorSparse($precision = 0.001)
 {
     $vertex = $this->getVertexSet();
     $dimension = count($vertex);
     $approx = new \SplObjectStorage();
     foreach ($vertex as $v) {
         $approx[$v] = 1 / sqrt($dimension);
     }
     $iter = 0;
     do {
         // result = M . approx
         $result = new \SplObjectStorage();
         foreach ($vertex as $v) {
             $result[$v] = 0;
         }
         foreach ($vertex as $v) {
             foreach ($this->graph->getSuccessor($v) as $succ) {
                 $result[$v] += $approx[$succ];
                 // very suspicious
                 // what if we invert $v and $succ, isn't the reversed digraph ?
             }
         }
         // calc the norm
         $sum = 0;
         foreach ($result as $v) {
             $sum += $result->getInfo() * $result->getInfo();
         }
         $norm = sqrt($sum);
         $delta = 0;
         // normalize
         foreach ($result as $v) {
             $newVal = $norm > 0 ? $result->getInfo() / $norm : 0;
             $delta += abs($newVal - $approx[$v]);
             $approx[$v] = $newVal;
         }
         $iter++;
     } while ($delta > $precision && $iter < 2 * $dimension);
     return array('value' => $norm, 'vector' => $approx);
 }
Exemplo n.º 15
0
 /**
  * Get session by session ID
  *
  * @param int $sessionId
  * @return \Thruway\Session|boolean
  */
 public function getSessionBySessionId($sessionId)
 {
     /** @var Session $session */
     $this->sessions->rewind();
     while ($this->sessions->valid()) {
         $session = $this->sessions->getInfo();
         if ($session->getSessionId() == $sessionId) {
             return $session;
         }
         $this->sessions->next();
     }
     return false;
 }
Exemplo n.º 16
0
 /**
  * Remove a listener from the queue.
  *
  * @param   \Closure|object  $listener  The listener.
  *
  * @return  ListenersQueue  This method is chainable.
  *
  * @since   2.0
  */
 public function remove($listener)
 {
     if ($this->storage->contains($listener)) {
         $this->storage->detach($listener);
         $this->storage->rewind();
         $this->queue = new \SplPriorityQueue();
         foreach ($this->storage as $listener) {
             $priority = $this->storage->getInfo();
             $this->queue->insert($listener, $priority);
         }
     }
     return $this;
 }
Exemplo n.º 17
0
 function it_should_attach_custom_data_to_my_spl()
 {
     $o1 = new \StdClass();
     Object::set($o1, 'name', 'Alan');
     $o2 = new \StdClass();
     Object::set($o2, 'name', 'John');
     $o3 = new \StdClass();
     Object::set($o3, 'name', 'Ringo');
     $spl = new \SplObjectStorage();
     $spl->attach($o1, "I am DATA 1");
     $spl->attach($o2, "I am DATA 2");
     $spl->attach($o3, "I am DATA 3");
     foreach ($spl as $value) {
         $spl->getInfo();
     }
 }
Exemplo n.º 18
0
 /**
  * Completes all the named entities' data accumulated before (plus some
  * additional data, such as some context string) to the database.
  */
 protected function save()
 {
     $this->entities->rewind();
     while ($this->entities->valid()) {
         $entity = $this->entities->current();
         $containerindex = $this->entities->getInfo();
         // Get the text context.
         list($entity->contextstart, $entity->notation, $entity->contextend) = $this->extractText($entity->xmlid, $containerindex);
         foreach (explode(' ', $entity->identifier) as $identifier) {
             // Each entry in array $tag['key'] points to a different target. If
             // there are multiple entries, we have to add multiple records to
             // support links with multiple targets. Note: save() below will
             // always insert a new record, therefore it doesn't matter that
             // we pass the same object several times.
             $entity->identifier = $identifier;
             $this->entityGateway->save($entity);
         }
         $this->entities->detach($entity);
         unset($entity);
     }
 }
Exemplo n.º 19
0
 /**
  * @deprecated Using the SplObjectStorage API on the Crawler is deprecated as of 2.8 and will be removed in 3.0.
  */
 public function getInfo()
 {
     $this->triggerDeprecation(__METHOD__);
     return parent::getInfo();
 }
Exemplo n.º 20
0
 /**
  *
  * Decodes geoJson file, converts to string, sifts through the string and inserts the data into the database
  *
  * @param string $url
  * @throws PDOException PDO related errors
  * @throws Exception catch-all exception
  **/
 public static function readTrailSegmentsGeoJson($url)
 {
     $context = stream_context_create(array("http" => array("ignore_errors" => true, "method" => "GET")));
     try {
         $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
         if (($jsonData = file_get_contents($url, null, $context)) !== false) {
             if (($jsonFd = @fopen("php://memory", "wb+")) === false) {
                 throw new RuntimeException("Memory Error: I can't remember");
             }
             //decode the geoJson file
             $jsonConverted = json_decode($jsonData);
             $jsonFeatures = $jsonConverted->features;
             // create array from converted geoJson file
             $properties = new SplFixedArray(count($jsonFeatures));
             //loop through array to get to json properties
             foreach ($jsonFeatures as $jsonFeature) {
                 $properties[$properties->key()] = $jsonFeature->properties;
                 $properties->next();
             }
             //create an array of trails and a SplObjectStorage for the trail guide
             $trails = [];
             $trailGuide = new SplObjectStorage();
             //loop through array to get trail name and trail use
             foreach ($properties as $property) {
                 $trailName = $property->name;
                 $trailUse = "";
                 //set $trailUse string based on information in geoJson properties field.
                 if ($property->bicycle === "yes") {
                     $trailUse = $trailUse . "bicycle: yes, ";
                 } else {
                     $trailUse = $trailUse . "bicycle: no, ";
                 }
                 if ($property->foot === "yes") {
                     $trailUse = $trailUse . "foot: yes, ";
                 } else {
                     $trailUse = $trailUse . "foot: no, ";
                 }
                 if ($property->wheelchair === "yes") {
                     $trailUse = $trailUse . "wheelchair: yes ";
                 } else {
                     $trailUse = $trailUse . "wheelchair: no ";
                 }
                 //get the trail by name and set the trail use
                 try {
                     $candidateTrails = Trail::getTrailByTrailName($pdo, $trailName);
                     foreach ($candidateTrails as $trail) {
                         $trail->setTrailUse($trailUse);
                         $trail->update($pdo);
                         $trails[] = $trail;
                     }
                 } catch (PDOException $pdoException) {
                     $sqlStateCode = "23000";
                     $errorInfo = $pdoException->errorInfo;
                     if ($errorInfo[0] === $sqlStateCode) {
                     } else {
                         throw new PDOException($pdoException->getMessage(), 0, $pdoException);
                     }
                 } catch (Exception $exception) {
                     throw new Exception($exception->getMessage(), 0, $exception);
                 }
             }
             try {
                 $trailIndex = 0;
                 foreach ($jsonFeatures as $jsonFeature) {
                     $jsonCoordinates = $jsonFeature->geometry->coordinates;
                     if ($jsonFeature->geometry->type === "LineString") {
                         $coordinates = new SplFixedArray(count($jsonCoordinates));
                         foreach ($jsonCoordinates as $coordinate) {
                             $coordinates[$coordinates->key()] = $coordinate;
                             $coordinates->next();
                         }
                         $trailGuide[$trails[$trailIndex]] = $coordinates;
                         $trailIndex++;
                     } else {
                         if ($jsonFeature->geometry->type === "MultiLineString") {
                             $trailClones = [];
                             $trails[$trailIndex]->delete($pdo);
                             for ($i = 1; $i <= count($jsonCoordinates); $i++) {
                                 $trail = clone $trails[$trailIndex];
                                 $trail->setTrailId(null);
                                 $trail->setTrailName($trail->getTrailName() . " {$i}");
                                 $trail->insert($pdo);
                                 $trailClones[] = $trail;
                             }
                             array_splice($trails, $trailIndex, 1, $trailClones);
                             foreach ($jsonCoordinates as $lineCoordinates) {
                                 $trailGuide[$trails[$trailIndex]] = $lineCoordinates;
                                 $trailIndex++;
                             }
                         }
                     }
                 }
                 $trailGuide->rewind();
                 foreach ($trailGuide as $map) {
                     $trail = $trailGuide->current();
                     $geo = $trailGuide->getInfo();
                     for ($indexTwo = 0; $indexTwo < count($geo) - 1; $indexTwo++) {
                         $segmentStartX = $geo[$indexTwo][0];
                         $segmentStartY = $geo[$indexTwo][1];
                         //							$segmentStartElevation = $geo[$indexTwo][2];
                         $segmentStopX = $geo[$indexTwo + 1][0];
                         $segmentStopY = $geo[$indexTwo + 1][1];
                         //							$segmentStopElevation = $geo[$indexTwo + 1][2];
                         $segmentStart = new Point($segmentStartX, $segmentStartY);
                         $segmentStop = new Point($segmentStopX, $segmentStopY);
                         try {
                             $segment = new Segment(null, $segmentStart, $segmentStop, 0, 0);
                             $segment->insert($pdo);
                             $relationship = new TrailRelationship($segment->getSegmentId(), $trail->getTrailId(), "T");
                             $relationship->insert($pdo);
                         } catch (PDOException $pdoException) {
                             $sqlStateCode = "23000";
                             $errorInfo = $pdoException->errorInfo;
                             if ($errorInfo[0] === $sqlStateCode) {
                             } else {
                                 throw new PDOException($pdoException->getMessage(), 0, $pdoException);
                             }
                         } catch (Exception $exception) {
                             throw new Exception($exception->getMessage(), 0, $exception);
                         }
                     }
                 }
             } catch (PDOException $pdoException) {
                 $sqlStateCode = "23000";
                 $errorInfo = $pdoException->errorInfo;
                 if ($errorInfo[0] === $sqlStateCode) {
                 } else {
                     throw new PDOException($pdoException->getMessage(), 0, $pdoException);
                 }
             } catch (Exception $exception) {
                 throw new Exception($exception->getMessage(), 0, $exception);
             }
         }
         fclose($jsonFd);
     } catch (PDOException $pdoException) {
         throw new PDOException($pdoException->getMessage(), 0, $pdoException);
     } catch (Exception $exception) {
         throw new Exception($exception->getMessage(), 0, $exception);
     }
 }
Exemplo n.º 21
0
$obj->count();
// valid()
// 判断对象容器当前指针后面是否有值
$obj->valid();
// key()
// 返回对象容器当前节点的索引
$obj->key();
// rewind()
// 返回并指向第一个节点元素
$obj->rewind();
// setInfo(mixed $data)
// 给当前节点赋值。必须是调用rewind后,才可以用setInfo赋值,否则找不到对象。
$obj->setInfo('AAA');
// getInfo()
// 获得当前节点的值。也必须是调用rewind后,才可以调用getInfo。
$obj->getInfo();
// current()
// 获得当前节点对象
$obj->current();
// getHash()
// 获得参数的hash值
$obj->getHash($a2);
// next()
// 指针移到下一个节点
$obj->next();
// offsetExists
// 判断对象容器中是否存在该对象
$obj->offsetExists($a2);
// offsetSet()
// 给对象容器中的某个对象设置值
$obj->offsetSet($a2, 'BBB');
Exemplo n.º 22
0
 protected function dumpSplStorage(\SplObjectStorage $arr)
 {
     $contentKey = array();
     $contentVal = array();
     foreach ($arr as $idx => $val) {
         $contentKey[$idx] = $this->mediator->recursivDesegregate($val);
         $contentVal[$idx] = $this->mediator->recursivDesegregate($arr->getInfo());
     }
     return array(self::SPL_KEY => $contentKey, self::SPL_VALUE => $contentVal);
 }
Exemplo n.º 23
0
 /**
  * Creates and returns list of all file attributes validators.
  * @return Validator[] list validators.
  * @throws InvalidValueException if the behavior has invalid owner.
  */
 public function createValidators()
 {
     if (!($owner = $this->owner) || !$owner instanceof Model) {
         throw new InvalidValueException(get_class($this) . ' must be attached to an instance of ' . Model::className() . '.');
     }
     $contexts = new \SplObjectStorage();
     foreach ($this->fileAttributes() as $fileAttribute) {
         $context = $this->getFileContext($fileAttribute);
         $fileAttributes = $contexts->offsetExists($context) ? $contexts->offsetGet($context) : [];
         $fileAttributes[] = $fileAttribute;
         $contexts->offsetSet($context, $fileAttributes);
     }
     $result = [];
     $contexts->rewind();
     while ($contexts->valid()) {
         $context = $contexts->current();
         $fileAttributes = $contexts->getInfo();
         foreach ($context->getValidators() as $validator) {
             $validator = Validator::createValidator($validator[0], $owner, $fileAttributes, array_slice($validator, 1, null, true));
             $result[] = $validator;
         }
         $contexts->next();
     }
     return $result;
 }
Exemplo n.º 24
0
 /**
  * Prints the results of a particular type
  * 
  * @param string            $type
  * @param \SplObjectStorage $items
  * @param integer           $space
  */
 protected function printIncrementalResult($type, $items, $space = 2)
 {
     $this->put("{$type}:");
     $this->printLines($space);
     $increment = 1;
     $items->rewind();
     while ($items->valid()) {
         $item = $items->current();
         $example = $items->getInfo();
         $method = "getMessageFor{$type}";
         $message = $this->{$method}($increment, $item, $example, $this->_enableBacktrace);
         $this->putln($message);
         $items->next();
         $increment++;
     }
 }
Exemplo n.º 25
0
 /**
  * @deprecated Using the SplObjectStorage API on the Crawler is deprecated as of 2.8 and will be removed in 3.0.
  */
 public function getInfo()
 {
     @trigger_error('The ' . __METHOD__ . ' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
     return parent::getInfo();
 }
Exemplo n.º 26
0
<?php

// Test code from: http://www.php.net/manual/en/splobjectstorage.getinfo.php
$s = new SplObjectStorage();
$o1 = new StdClass();
$o2 = new StdClass();
$s->attach($o1, "d1");
$s->attach($o2, "d2");
$s->rewind();
while ($s->valid()) {
    $index = $s->key();
    $object = $s->current();
    // similar to current($s)
    $data = $s->getInfo();
    var_dump($object);
    var_dump($data);
    $s->next();
}
// now mutate $o2 and ensure it sticks
$s->attach($o2, "mutated");
var_dump($s[$o2]);
 public function getInfo()
 {
     $this->initialize();
     return parent::getInfo();
 }
Exemplo n.º 28
0
 /**
  * create XPath
  *
  * @param \DOMDocument $document
  * @param array        $cssRules
  *
  * @return \DOMXPath
  */
 private function createXPath(\DOMDocument $document, array $cssRules)
 {
     $propertyStorage = new \SplObjectStorage();
     $xPath = new \DOMXPath($document);
     // any rules?
     if (0 !== count($cssRules)) {
         // loop rules
         foreach ($cssRules as $rule) {
             $ruleSelector = $rule['selector'];
             $ruleProperties = $rule['properties'];
             if (!$ruleSelector || !$ruleProperties) {
                 continue;
             }
             try {
                 $query = $this->cssConverter->toXPath($ruleSelector);
             } catch (ExceptionInterface $e) {
                 $query = null;
             }
             // validate query
             if (null === $query) {
                 continue;
             }
             // search elements
             $elements = $xPath->query($query);
             // validate elements
             if (false === $elements) {
                 continue;
             }
             // loop found elements
             foreach ($elements as $element) {
                 /**
                  * @var $element \DOMElement
                  */
                 if ($ruleSelector == '*' && ($element->tagName == 'html' || $element->tagName === 'title' || $element->tagName == 'meta' || $element->tagName == 'head' || $element->tagName == 'style' || $element->tagName == 'script' || $element->tagName == 'link')) {
                     continue;
                 }
                 // no styles stored?
                 if (!isset($propertyStorage[$element])) {
                     // init var
                     $originalStyle = $element->attributes->getNamedItem('style');
                     if ($originalStyle) {
                         $originalStyle = $originalStyle->value;
                     } else {
                         $originalStyle = '';
                     }
                     // store original styles
                     $propertyStorage->attach($element, $originalStyle);
                     // clear the styles
                     $element->setAttribute('style', '');
                 }
                 // set attribute
                 $propertiesString = $this->createPropertyChunks($element, $ruleProperties);
                 if ($propertiesString) {
                     $element->setAttribute('style', $propertiesString);
                 }
             }
         }
         foreach ($propertyStorage as $element) {
             $originalStyle = $propertyStorage->getInfo();
             if ($originalStyle) {
                 $originalStyles = $this->splitIntoProperties($originalStyle);
                 $originalProperties = $this->splitStyleIntoChunks($originalStyles);
                 // set attribute
                 $propertiesString = $this->createPropertyChunks($element, $originalProperties);
                 if ($propertiesString) {
                     $element->setAttribute('style', $propertiesString);
                 }
             }
         }
     }
     return $xPath;
 }
Exemplo n.º 29
0
[expect php]
[file]
<?php 
// As a map from objects to data
$s = new SplObjectStorage();
$o1 = new StdClass();
$o2 = new StdClass();
$o3 = new StdClass();
$s[$o1] = "data for object 1";
$s[$o2] = "two";
$s[$o3] = 3;
$s->detach($o2);
foreach ($s as $k => $v) {
    var_dump($k, $s->getInfo());
}
Exemplo n.º 30
0
 /**
  * Select the object identified by its attached info
  * In case of many identical infos, the first attached object is selected
  * @param mixed $info
  * @return bool false if the object doesn't exist
  */
 public function selectObjectByInfo($info)
 {
     parent::rewind();
     while (parent::valid()) {
         if (parent::getInfo() === $info) {
             return true;
         }
         parent::next();
     }
     return false;
 }