Esempio n. 1
0
 /**
  * @param HandlerInterface $handler
  * @param array            $categories
  */
 public function attach(HandlerInterface $handler, array $categories = array())
 {
     if ($this->handlers->contains($handler)) {
         $handlerCategories = $this->handlers->offsetGet($handler);
         $this->handlers->offsetSet($handler, array_merge((array) $handlerCategories, $categories));
     } else {
         $this->handlers->attach($handler, $categories);
     }
 }
 /**
  * Returns list of observers for subject
  *
  * @param SubjectInterface $s
  *
  * @return \SplObjectStorage|ObserverInterface[]
  */
 protected function getObservers(SubjectInterface $s)
 {
     if ($this->perSubjectObservers === null) {
         $this->perSubjectObservers = new \SplObjectStorage();
     }
     if (!isset($this->perSubjectObservers[$s])) {
         $observers = new \SplObjectStorage();
         $this->perSubjectObservers->offsetSet($s, $observers);
     } else {
         $observers = $this->perSubjectObservers->offsetGet($s);
     }
     return $observers;
 }
Esempio n. 3
0
 public function offsetSet($index, $testResult)
 {
     $indexObj = $index;
     $this->validateIndex($index);
     $this->validateValue($testResult);
     // Decrement counters when replacing existing item
     if (parent::offsetExists($index)) {
         $oldResult = parent::offsetGet($index);
         if ($oldResult instanceof Success) {
             $this->countSuccess--;
         } elseif ($oldResult instanceof Failure) {
             $this->countFailure--;
         } elseif ($oldResult instanceof Warning) {
             $this->countWarning--;
         } else {
             $this->countUnknown--;
         }
     }
     parent::offsetSet($index, $testResult);
     // Increment counters
     if ($testResult instanceof Success) {
         $this->countSuccess++;
     } elseif ($testResult instanceof Failure) {
         $this->countFailure++;
     } elseif ($testResult instanceof Warning) {
         $this->countWarning++;
     } else {
         $this->countUnknown++;
     }
 }
Esempio n. 4
0
 /**
  * @param object $object
  * @param null $data
  */
 public function offsetSet($object, $data = null)
 {
     if (!$object instanceof Date) {
         throw new \InvalidArgumentException("DateObjectStorage can store only date objects");
     }
     parent::offsetSet($object, $data);
     // TODO: Change the autogenerated stub
 }
Esempio n. 5
0
 /**
  * setData()
  *
  * sets the data set of a given route
  * 
  * @param \Naquadria\Components\Routing\Route $route
  * @param mixed $data
  * @throws \Naquadria\Components\Routing\Exceptions\RouteNotFoundException
  */
 public function setData(Route $route, $data)
 {
     if (!parent::contains($route)) {
         throw new RouteNotFoundException('Unknown route instance');
     }
     $current = parent::offsetGet($route);
     $current['data'] = $data;
     parent::offsetSet($route, $current);
 }
Esempio n. 6
0
 /**
  * @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);
 }
 private function eventsToPublishOn(EventMessageInterface $event, EventBusInterface $eventBus)
 {
     if (!$this->eventsToPublish->contains($eventBus)) {
         $this->eventsToPublish->attach($eventBus, array($event));
         return;
     }
     $events = $this->eventsToPublish->offsetGet($eventBus);
     $events[] = $event;
     $this->eventsToPublish->offsetSet($eventBus, $events);
 }
 private function unsubscribe(WebSocketConnection $connection)
 {
     /** @var WebSocketObservableTable $table */
     $table = $this->connectionTableMap->offsetGet($connection);
     $table->removeConnection($connection);
     $this->connectionTableMap->offsetUnset($connection);
     $connections = $this->getConnectionsSubscribedToTable($table)->filter(function (WebSocketConnection $c) use($connection) {
         return $c !== $connection;
     });
     if (count($connections)) {
         $this->tableConnectionMap->offsetSet($table, $connections);
     } else {
         $this->tableConnectionMap->offsetUnset($table);
     }
 }
Esempio n. 9
0
 /**
  * Sets the value for the passed offset.
  *
  * @param int   $offset The offset to set value for
  * @param mixed $value  The value to write
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return mixed The result of the operation
  */
 public function offsetSet($offset, $value)
 {
     foreach ($this->observer as $observer) {
         if (strtolower($observer->getName()) === strtolower($offset)) {
             $this->observer->offsetSet($value);
         }
     }
 }
Esempio n. 10
0
    /**
     * Generates the inline definition setup.
     *
     * @param string     $id
     * @param Definition $definition
     *
     * @return string
     *
     * @throws ServiceCircularReferenceException when the container contains a circular reference
     */
    private function addServiceInlinedDefinitionsSetup($id, $definition)
    {
        $this->referenceVariables[$id] = new Variable('instance');

        $code = '';
        $processed = new \SplObjectStorage();
        foreach ($this->getInlinedDefinitions($definition) as $iDefinition) {
            if ($processed->contains($iDefinition)) {
                continue;
            }
            $processed->offsetSet($iDefinition);

            if (!$this->hasReference($id, $iDefinition->getMethodCalls(), true) && !$this->hasReference($id, $iDefinition->getProperties(), true)) {
                continue;
            }

            // if the instance is simple, the return statement has already been generated
            // so, the only possible way to get there is because of a circular reference
            if ($this->isSimpleInstance($id, $definition)) {
                throw new ServiceCircularReferenceException($id, array($id));
            }

            $name = (string) $this->definitionVariables->offsetGet($iDefinition);
            $code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
            $code .= $this->addServiceProperties(null, $iDefinition, $name);
            $code .= $this->addServiceConfigurator(null, $iDefinition, $name);
        }

        if ('' !== $code) {
            $code .= "\n";
        }

        return $code;
    }
 public function offsetSet($object, $info)
 {
     $this->initialize();
     parent::offsetSet($object, $info);
 }
Esempio n. 12
0
 /**
  * @deprecated Using the SplObjectStorage API on the Crawler is deprecated as of 2.8 and will be removed in 3.0.
  */
 public function offsetSet($object, $data = null)
 {
     @trigger_error('The ' . __METHOD__ . ' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
     parent::offsetSet($object, $data);
 }
Esempio n. 13
0
 /**
  * Generates the inline definition setup.
  *
  * @param string     $id
  * @param Definition $definition
  * @return string
  */
 private function addServiceInlinedDefinitionsSetup($id, $definition)
 {
     $this->referenceVariables[$id] = new Variable('instance');
     $code = '';
     $processed = new \SplObjectStorage();
     foreach ($this->getInlinedDefinitions($definition) as $iDefinition) {
         if ($processed->contains($iDefinition)) {
             continue;
         }
         $processed->offsetSet($iDefinition);
         if (!$this->hasReference($id, $iDefinition->getMethodCalls())) {
             continue;
         }
         if ($iDefinition->getMethodCalls()) {
             $code .= $this->addServiceMethodCalls(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
         }
         if ($iDefinition->getConfigurator()) {
             $code .= $this->addServiceConfigurator(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
         }
     }
     if ('' !== $code) {
         $code .= "\n";
     }
     return $code;
 }
Esempio n. 14
0
 /**
  * @deprecated Using the SplObjectStorage API on the Crawler is deprecated as of 2.8 and will be removed in 3.0.
  */
 public function offsetSet($object, $data = null)
 {
     $this->triggerDeprecation(__METHOD__);
     parent::offsetSet($object, $data);
 }
Esempio n. 15
0
 /**
  * @param object     $index
  * @param mixed|null $checkResult
  * @link http://php.net/manual/en/splobjectstorage.offsetset.php
  */
 public function offsetSet($index, $checkResult)
 {
     $this->validateIndex($index);
     $this->validateValue($checkResult);
     // Decrement counters when replacing existing item
     if (parent::offsetExists($index)) {
         $this->updateCounters(parent::offsetGet($index), -1);
     }
     // Store the new instance
     parent::offsetSet($index, $checkResult);
     // Increment counters
     $this->updateCounters($checkResult, 1);
 }
 /**
  * @test
  */
 public function keyContainsTheNumericalIndexWhenIteratingThroughElementsOfObjectsOfTyeSplObjectStorage()
 {
     $viewHelper = new \TYPO3\Fluid\ViewHelpers\ForViewHelper();
     $viewHelperNode = new \TYPO3\Fluid\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
     $splObjectStorageObject = new \SplObjectStorage();
     $object1 = new \stdClass();
     $splObjectStorageObject->attach($object1);
     $object2 = new \stdClass();
     $splObjectStorageObject->attach($object2, 'foo');
     $object3 = new \stdClass();
     $splObjectStorageObject->offsetSet($object3, 'bar');
     $this->arguments['each'] = $splObjectStorageObject;
     $this->arguments['as'] = 'innerVariable';
     $this->arguments['key'] = 'someKey';
     $this->injectDependenciesIntoViewHelper($viewHelper);
     $viewHelper->setViewHelperNode($viewHelperNode);
     $viewHelper->render($this->arguments['each'], $this->arguments['as'], $this->arguments['key']);
     $expectedCallProtocol = array(array('innerVariable' => $object1, 'someKey' => 0), array('innerVariable' => $object2, 'someKey' => 1), array('innerVariable' => $object3, 'someKey' => 2));
     $this->assertSame($expectedCallProtocol, $viewHelperNode->callProtocol, 'The call protocol differs -> The for loop does not work as it should!');
 }
Esempio n. 17
0
 protected function prepareEntities($addWithoutOwner = true)
 {
     $map = new \SplObjectStorage();
     $map->offsetSet(new \ArrayObject(array('Trixie', 'Blum')), array('Red', 'Green'));
     $map->offsetSet(new \ArrayObject(array('Blum')), array('Yellow'));
     $map->offsetSet(new \ArrayObject(array('Pixie')), array());
     $map->offsetSet(new \ArrayObject(array()), array('Purple'));
     $instances = array();
     $flowerMap = array();
     foreach ($map as $fairyNames) {
         $fairies = array();
         foreach ($fairyNames as $name) {
             if (!array_key_exists($name, $flowerMap)) {
                 $flowerMap[$name] = array();
             }
             $flowerMap[$name] = array_merge($flowerMap[$name], $map[$fairyNames]);
             if (!array_key_exists($name, $instances)) {
                 $instances[$name] = $this->createEntity('fairy', array('name' => $name));
             }
             $fairies[] = $instances[$name];
         }
         foreach ($map[$fairyNames] as $name) {
             if (!array_key_exists($name, $instances)) {
                 $instances[$name] = $this->createEntity('flower', array('name' => $name));
             }
             $instances[$name]->fairies->add($fairies);
         }
     }
     return array($map, $flowerMap, $instances);
 }
Esempio n. 18
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;
 }
Esempio n. 19
0
 /**
  * @param object $offset
  * @param mixed $value
  */
 public function offsetSet($offset, $value)
 {
     $this->list->offsetSet($offset, $value);
 }
Esempio n. 20
0
// 获得当前节点的值。也必须是调用rewind后,才可以调用getInfo。
$obj->getInfo();
// current()
// 获得当前节点对象
$obj->current();
// getHash()
// 获得参数的hash值
$obj->getHash($a2);
// next()
// 指针移到下一个节点
$obj->next();
// offsetExists
// 判断对象容器中是否存在该对象
$obj->offsetExists($a2);
// offsetSet()
// 给对象容器中的某个对象设置值
$obj->offsetSet($a2, 'BBB');
// offsetGet()
// 获得对象容器中的某个针对象对应的值
$obj->offsetGet($a2);
// offsetUnset()
// 将某节点删除
//$obj->offsetUnset($a1);
// serialize()
// 将对象容器序列化
$serialize_obj = $obj->serialize();
// unserialize()
// 将对象容器反序列化
$obj_2 = new SplObjectStorage();
$obj_2->unserialize($serialize_obj);
var_dump($obj_2);