예제 #1
0
 /**
  * @param \SplObjectStorage $storage
  */
 public function addAll($storage)
 {
     parent::addAll($storage);
     if ($storage instanceof self) {
         $this->unreferenced->addAll($storage->unreferenced);
     }
 }
예제 #2
0
 /**
  * Merge storages
  *
  * @param self $storage
  *
  * @return self
  */
 public function merge(self $storage) : self
 {
     $objects = new \SplObjectStorage();
     $objects->addAll($this->objects);
     $objects->addAll($storage->objects);
     return new self($objects);
 }
예제 #3
0
파일: CDataSet.php 프로젝트: Broncko/Savant
 /**
  * assign data
  * @param mixed $pData
  */
 public function assign($pData)
 {
     switch (true) {
         case $pData instanceof \SplObjectStorage:
             $this->data->addAll($pData);
             break;
         case \is_array($pData):
             foreach ($pData as $row) {
                 $this->data->attach((object) $row);
             }
             break;
     }
 }
예제 #4
0
 /**
  * @param \SplObjectStorage $object
  * @throws Exception\WrongArgument
  */
 public function addAll($object)
 {
     if (!$object instanceof SMSCollection) {
         throw new Exception\WrongArgument();
     }
     parent::addAll($object);
 }
예제 #5
0
 /**
  * @param \SplObjectStorage $storage
  */
 public function addAll($storage)
 {
     if (!$storage instanceof \SplObjectStorage) {
         throw new \InvalidArgumentException("DateObjectStorage can be merge only with \\SplObjectStorage object.");
     }
     foreach ($storage as $element) {
         if (!$element instanceof Date) {
             throw new \InvalidArgumentException("DateObjectStorage can store only date objects");
         }
     }
     parent::addAll($storage);
     // TODO: Change the autogenerated stub
 }
예제 #6
0
 /**
  * Calculate the losers and return an splStorageObject of them.
  * @param  splStprageObject $clients
  * @param  RoundHelper $helper  A helper class with utility functions.
  * @return SplStorageObject The losers.
  */
 private function getLosers($clients, $helper)
 {
     $losers = new \SplObjectStorage();
     $a1 = $helper->generateAnswerObject(1, $clients);
     $a2 = $helper->generateAnswerObject(2, $clients);
     $a3 = $helper->generateAnswerObject(3, $clients);
     $count = $helper->minCount($a1, $a2, $a3);
     foreach ([$a1, $a2, $a3] as $spl) {
         if ($spl->count() !== $count) {
             $losers->addAll($spl);
         }
     }
     return $losers;
 }
예제 #7
0
파일: Parser.php 프로젝트: kpocha/Sami
 public function parse(Project $project, $callback = null)
 {
     $step = 0;
     $steps = iterator_count($this->iterator);
     $context = $this->parser->getContext();
     $transaction = new Transaction($project);
     $toStore = new \SplObjectStorage();
     foreach ($this->iterator as $file) {
         ++$step;
         $code = file_get_contents($file);
         $hash = sha1($code);
         if ($transaction->hasHash($hash)) {
             continue;
         }
         $context->enterFile((string) $file, $hash);
         $this->parser->parse($code);
         if (null !== $callback) {
             call_user_func($callback, Message::PARSE_ERROR, $context->getErrors());
         }
         foreach ($context->leaveFile() as $class) {
             if (null !== $callback) {
                 call_user_func($callback, Message::PARSE_CLASS, array(floor($step / $steps * 100), $class));
             }
             $project->addClass($class);
             $transaction->addClass($class);
             $toStore->attach($class);
             $class->notFromCache();
         }
     }
     // cleanup
     foreach ($transaction->getRemovedClasses() as $class) {
         $project->removeClass(new LazyClassReflection($class));
         $this->store->removeClass($project, $class);
     }
     // visit each class for stuff that can only be done when all classes are parsed
     $toStore->addAll($this->traverser->traverse($project));
     foreach ($toStore as $class) {
         $this->store->writeClass($project, $class);
     }
     return $transaction;
 }
 public function addAll($storage)
 {
     $this->initialize();
     parent::addAll($storage);
 }
예제 #9
0
파일: Crawler.php 프로젝트: 0mars/symfony
 /**
  * @deprecated Using the SplObjectStorage API on the Crawler is deprecated as of 2.8 and will be removed in 3.0.
  */
 public function addAll($storage)
 {
     @trigger_error('The ' . __METHOD__ . ' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
     parent::addAll($storage);
 }
예제 #10
0
 /**
  * Recursively goes through an array and makes neat HTML out of it.
  *
  * @param mixed $values Array to make pretty.
  * @param int $openDepth Depth to add open class
  * @param int $currentDepth current depth.
  * @param bool $doubleEncode Whether or not to double encode.
  * @param \SplObjectStorage $currentAncestors Object references found down
  * the path.
  * @return string
  */
 public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubleEncode = false, \SplObjectStorage $currentAncestors = null)
 {
     if ($currentAncestors === null) {
         $ancestors = new \SplObjectStorage();
     } elseif (is_object($values)) {
         $ancestors = new \SplObjectStorage();
         $ancestors->addAll($currentAncestors);
         $ancestors->attach($values);
     } else {
         $ancestors = $currentAncestors;
     }
     $className = "neat-array depth-{$currentDepth}";
     if ($openDepth > $currentDepth) {
         $className .= ' expanded';
     }
     $nextDepth = $currentDepth + 1;
     $out = "<ul class=\"{$className}\">";
     if (!is_array($values)) {
         if (is_bool($values)) {
             $values = [$values];
         }
         if ($values === null) {
             $values = [null];
         }
         if (is_object($values) && method_exists($values, 'toArray')) {
             $values = $values->toArray();
         }
     }
     if (empty($values)) {
         $values[] = '(empty)';
     }
     if ($this->sort && is_array($values) && $currentDepth === 0) {
         ksort($values);
     }
     foreach ($values as $key => $value) {
         $out .= '<li><strong>' . h($key, $doubleEncode) . '</strong>';
         if (is_array($value) && count($value) > 0) {
             $out .= '(array)';
         } elseif (is_object($value)) {
             $out .= '(object)';
         }
         if ($value === null) {
             $value = '(null)';
         }
         if ($value === false) {
             $value = '(false)';
         }
         if ($value === true) {
             $value = '(true)';
         }
         if (empty($value) && $value != 0) {
             $value = '(empty)';
         }
         if ($value instanceof Closure) {
             $value = 'function';
         }
         $isObject = is_object($value);
         if ($isObject && $ancestors->contains($value)) {
             $isObject = false;
             $value = ' - recursion';
         }
         if (($value instanceof ArrayAccess || $value instanceof Iterator || is_array($value) || $isObject) && !empty($value)) {
             $out .= $this->makeNeatArray($value, $openDepth, $nextDepth, $doubleEncode, $ancestors);
         } else {
             $out .= h($value, $doubleEncode);
         }
         $out .= '</li>';
     }
     $out .= '</ul>';
     return $out;
 }
예제 #11
0
 /**
  * @deprecated Using the SplObjectStorage API on the Crawler is deprecated as of 2.8 and will be removed in 3.0.
  */
 public function addAll($storage)
 {
     $this->triggerDeprecation(__METHOD__);
     parent::addAll($storage);
 }
 private function insert($breadcrumb, $position)
 {
     if ($position < 0) {
         $position += $this->breadcrumbs->count();
     } else {
         // $position >= 1
         $position--;
     }
     $breadcrumbs = new \SplObjectStorage();
     $breadcrumbs->addAll($this->breadcrumbs);
     $this->breadcrumbs->removeAll($this->breadcrumbs);
     $breadcrumbs->rewind();
     while ($breadcrumbs->valid()) {
         if (max(0, $position) == $breadcrumbs->key()) {
             $this->breadcrumbs->attach($breadcrumb);
         }
         $this->breadcrumbs->attach($breadcrumbs->current());
         $breadcrumbs->next();
     }
 }
<?php

$data_provider = array(array(), true, "string", 12345, 1.2345, NULL);
foreach ($data_provider as $input) {
    $s = new SplObjectStorage();
    var_dump($s->addAll($input));
}
예제 #14
0
파일: ixml.php 프로젝트: dapepe/tymio
 protected function _CLASS($elem)
 {
     if ($var = $elem['VAR']) {
         $extends = [];
         $parents = new \SplObjectStorage();
         $constructors = [];
         $prototype = [];
         if (isset($elem['EXTENDS'])) {
             foreach ($elem['EXTENDS'] as $child) {
                 isset($child[SIGN_MAP]) and $child = $this->map($child);
                 if ($parents->contains($class = $this->getVarClass($child['CLASS']))) {
                     throw new iXmlException("Class '" . $this->getVarDebug($var) . "' cannot extend '" . $this->getVarDebug($child['CLASS']) . "' repeatedly");
                 }
                 $extends[] = $class;
                 $parents->attach($class);
                 $parents->addAll($class->parents);
                 $constructors = array_merge($constructors, $class->constructors);
                 $prototype = $class->prototype + $prototype;
             }
         }
         if (isset($elem['PROPERTY'])) {
             foreach ($elem['PROPERTY'] as $child) {
                 isset($child[SIGN_MAP]) and $child = $this->map($child);
                 $property_var = $child['VAR'];
                 $prototype[($name = $child['NAME']) === '' && $property_var ? isset($property_var[1]) ? end($property_var[1]) : $property_var[0] : $name] = $property_var ? $this->getVar($property_var) : $child[SIGN_CDATA];
             }
         }
         isset($elem['CONSTRUCTOR']) and $constructors[] = $elem['CONSTRUCTOR'][0][SIGN_CHILD];
         if (isset($elem['METHOD'])) {
             foreach ($elem['METHOD'] as $child) {
                 isset($child[SIGN_MAP]) and $child = $this->map($child);
                 $prototype[$child['NAME']] = new iXmlFunctionSimple(isset($child[SIGN_CHILD]) ? $child[SIGN_CHILD] : []);
             }
         }
         $this->setVar($var, new iXmlClass($extends, $parents, $constructors, $prototype));
     }
 }
예제 #15
0
<?php

/**
 * spl数据结构demo
 * 对象容器 SplObjectStorage
 *
 */
// 实例化
$obj = new SplObjectStorage();
// addAll(SplObjectStorage $storage)
// 将另一个对象容器的对象数据全部加入到自己的对象中
$o = new StdClass();
$obj_1 = new SplObjectStorage();
$obj_1[$o] = 'hello';
$obj->addAll($obj_1);
//echo $obj[$o]; // hello
// attach(object $object[, mixed $data=null])
// 往对象容器中添加对象
$a1 = new StdClass();
$a2 = new StdClass();
$obj->attach($a1);
$obj->attach($a2, 'class 2');
$obj->attach($a2, array('k1' => 'class 2'));
// detach(object $object)
// 将参数对象从对象容器中分离
$obj->detach($o);
// $obj[$o] 报错,找不到对象
// contains(object $object)
// 判断对象容器是否存在该对象
$obj->contains($o);
// false
 /**
  * Commits new objects and changes to objects in the current persistence
  * session into the backend
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  * @author Karsten Dambekalns <*****@*****.**>
  * @api
  */
 public function persistAll()
 {
     $aggregateRootObjects = new \SplObjectStorage();
     $deletedEntities = new \SplObjectStorage();
     // fetch and inspect objects from all known repositories
     $repositoryClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface('F3\\FLOW3\\Persistence\\RepositoryInterface');
     foreach ($repositoryClassNames as $repositoryClassName) {
         $repository = $this->objectManager->getObject($repositoryClassName);
         $aggregateRootObjects->addAll($repository->getAddedObjects());
         $deletedEntities->addAll($repository->getRemovedObjects());
     }
     $aggregateRootObjects->addAll($this->persistenceSession->getReconstitutedObjects());
     // hand in only aggregate roots, leaving handling of subobjects to
     // the underlying storage layer
     $this->backend->setAggregateRootObjects($aggregateRootObjects);
     $this->backend->setDeletedEntities($deletedEntities);
     $this->backend->commit();
     // this needs to unregister more than just those, as at least some of
     // the subobjects are supposed to go away as well...
     // OTOH those do no harm, changes to the unused ones should not happen,
     // so all they do is eat some memory.
     foreach ($deletedEntities as $deletedEntity) {
         $this->persistenceSession->unregisterReconstitutedObject($deletedEntity);
     }
 }