SplObjectStorage example


    private \SplObjectStorage $lastModified;

    /** * @var \SplObjectStorage<Request, string> */
    private \SplObjectStorage $etags;

    public function __construct(
        private ?ExpressionLanguage $expressionLanguage = null,
    ) {
        $this->lastModified = new \SplObjectStorage();
        $this->etags = new \SplObjectStorage();
    }

    /** * Handles HTTP validation headers. * * @return void */
    public function onKernelControllerArguments(ControllerArgumentsEvent $event)
    {
        $request = $event->getRequest();

        
private WorkflowExtension $extension;
    private Transition $t1;

    protected function setUp(): void
    {
        $places = ['ordered', 'waiting_for_payment', 'processed'];
        $transitions = [
            $this->t1 = new Transition('t1', 'ordered', 'waiting_for_payment'),
            new Transition('t2', 'waiting_for_payment', 'processed'),
        ];

        $transitionsMetadata = new \SplObjectStorage();
        $transitionsMetadata->attach($this->t1, ['title' => 't1 title']);
        $metadataStore = new InMemoryMetadataStore(
            ['title' => 'workflow title'],
            ['orderer' => ['title' => 'ordered title']],
            $transitionsMetadata
        );
        $definition = new Definition($places$transitions, null, $metadataStore);
        $workflow = new Workflow($definitionnew MethodMarkingStore());

        $registry = new Registry();
        $supportStrategy = new InstanceOfSupportStrategy(Subject::class);
        
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0])$callable[1]$variableName);
            }

            return sprintf(" [%s, '%s'](\$%s);\n", $this->dumpValue($callable[0])$callable[1]$variableName);
        }

        return sprintf(" %s(\$%s);\n", $callable$variableName);
    }

    private function addService(string $id, Definition $definition): array
    {
        $this->definitionVariables = new \SplObjectStorage();
        $this->referenceVariables = [];
        $this->variableCount = 0;
        $this->referenceVariables[$id] = new Variable('instance');

        $return = [];

        if ($class = $definition->getClass()) {
            $class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class);
            $return[] = sprintf(str_starts_with($class, '%') ? '@return object A %1$s instance' : '@return \%s', ltrim($class, '\\'));
        } elseif ($definition->getFactory()) {
            $factory = $definition->getFactory();
            

        return [
            [\SplDoublyLinkedList::IT_MODE_FIFO, 'IT_MODE_FIFO | IT_MODE_KEEP'],
            [\SplDoublyLinkedList::IT_MODE_LIFO, 'IT_MODE_LIFO | IT_MODE_KEEP'],
            [\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_FIFO | IT_MODE_DELETE'],
            [\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_LIFO | IT_MODE_DELETE'],
        ];
    }

    public function testCastObjectStorageIsntModified()
    {
        $var = new \SplObjectStorage();
        $var->attach(new \stdClass());
        $var->rewind();
        $current = $var->current();

        $this->assertDumpMatchesFormat('%A', $var);
        $this->assertSame($current$var->current());
    }

    public function testCastObjectStorageDumpsInfo()
    {
        $var = new \SplObjectStorage();
        
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
{
    /** * @var \SplObjectStorage<Request, callable> */
    private \SplObjectStorage $controllers;
    private array $sessionUsages = [];
    private ?RequestStack $requestStack;

    public function __construct(RequestStack $requestStack = null)
    {
        $this->controllers = new \SplObjectStorage();
        $this->requestStack = $requestStack;
    }

    public function collect(Request $request, Response $response, \Throwable $exception = null): void
    {
        // attributes are serialized and as they can be anything, they need to be converted to strings.         $attributes = [];
        $route = '';
        foreach ($request->attributes->all() as $key => $value) {
            if ('_route' === $key) {
                $route = \is_object($value) ? $value->getPath() : $value;
                
throw $httpException;
        }
    }

    /** * @internal */
    public static function stream(iterable $responses, float $timeout = null, string $class = null): \Generator
    {
        while ($responses) {
            $wrappedResponses = [];
            $asyncMap = new \SplObjectStorage();
            $client = null;

            foreach ($responses as $r) {
                if (!$r instanceof self) {
                    throw new \TypeError(sprintf('"%s::stream()" expects parameter 1 to be an iterable of AsyncResponse objects, "%s" given.', $class ?? static::classget_debug_type($r)));
                }

                if (null !== $e = $r->info['error'] ?? null) {
                    yield $r => $chunk = new ErrorChunk($r->offset, new TransportException($e));
                    $chunk->didThrow() ?: $chunk->getContent();
                    continue;
                }
private array $workflowMetadata;
    private array $placesMetadata;
    private \SplObjectStorage $transitionsMetadata;

    /** * @param \SplObjectStorage<Transition, array>|null $transitionsMetadata */
    public function __construct(array $workflowMetadata = [], array $placesMetadata = [], \SplObjectStorage $transitionsMetadata = null)
    {
        $this->workflowMetadata = $workflowMetadata;
        $this->placesMetadata = $placesMetadata;
        $this->transitionsMetadata = $transitionsMetadata ?? new \SplObjectStorage();
    }

    public function getWorkflowMetadata(): array
    {
        return $this->workflowMetadata;
    }

    public function getPlaceMetadata(string $place): array
    {
        return $this->placesMetadata[$place] ?? [];
    }

    
$this->elementInfo = $element_info;
    $this->placeholderGenerator = $placeholder_generator;
    $this->renderCache = $render_cache;
    if (!isset($renderer_config['debug'])) {
      $renderer_config['debug'] = FALSE;
    }
    $this->rendererConfig = $renderer_config;
    $this->requestStack = $request_stack;

    // Initialize the context collection if needed.     if (!isset(static::$contextCollection)) {
      static::$contextCollection = new \SplObjectStorage();
    }
  }

  /** * {@inheritdoc} */
  public function renderRoot(&$elements) {
    // Disallow calling ::renderRoot() from within another ::renderRoot() call.     if ($this->isRenderingRoot) {
      $this->isRenderingRoot = FALSE;
      throw new \LogicException('A stray renderRoot() invocation is causing bubbling of attached assets to break.');
    }
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0])$callable[1]$variableName);
            }

            return sprintf(" [%s, '%s'](\$%s);\n", $this->dumpValue($callable[0])$callable[1]$variableName);
        }

        return sprintf(" %s(\$%s);\n", $callable$variableName);
    }

    private function addService(string $id, Definition $definition): array
    {
        $this->definitionVariables = new \SplObjectStorage();
        $this->referenceVariables = [];
        $this->variableCount = 0;
        $this->referenceVariables[$id] = new Variable('instance');

        $return = [];

        if ($class = $definition->getClass()) {
            $class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class);
            $return[] = sprintf(str_starts_with($class, '%') ? '@return object A %1$s instance' : '@return \%s', ltrim($class, '\\'));
        } elseif ($definition->getFactory()) {
            $factory = $definition->getFactory();
            
$places = range('a', 'g');

        $transitions = [];
        $transitions[] = new Transition('t1', 'a', ['b', 'c']);
        $transitions[] = new Transition('t2', ['b', 'c'], 'd');
        $transitionWithMetadataDumpStyle = new Transition('t3', 'd', 'e');
        $transitions[] = $transitionWithMetadataDumpStyle;
        $transitions[] = new Transition('t4', 'd', 'f');
        $transitions[] = new Transition('t5', 'e', 'g');
        $transitions[] = new Transition('t6', 'f', 'g');

        $transitionsMetadata = new \SplObjectStorage();
        $transitionsMetadata[$transitionWithMetadataDumpStyle] = [
            'label' => 'My custom transition label 1',
            'color' => 'Red',
            'arrow_color' => 'Green',
        ];
        $inMemoryMetadataStore = new InMemoryMetadataStore([][]$transitionsMetadata);

        return new Definition($places$transitions, null, $inMemoryMetadataStore);

        // The graph looks like:         // +---+ +----+ +---+ +----+ +----+ +----+ +----+ +----+ +---+
/** * @param TransportInterface[] $transports */
    public function __construct(array $transports, int $retryPeriod = 60)
    {
        if (!$transports) {
            throw new TransportException(sprintf('"%s" must have at least one transport configured.', static::class));
        }

        $this->transports = $transports;
        $this->deadTransports = new \SplObjectStorage();
        $this->retryPeriod = $retryPeriod;
    }

    public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
    {
        $exception = null;

        while ($transport = $this->getNextTransport()) {
            try {
                return $transport->send($message$envelope);
            } catch (TransportExceptionInterface $e) {
                

        }

        unset($this->controllers[$request]);
    }

    /** * @return void */
    public function reset()
    {
        $this->controllers = new \SplObjectStorage();

        $this->data = [
            'redirect' => false,
            'url' => null,
            'route' => null,
        ];
    }

    /** * @return string */
    

    public static function export(mixed $value, bool &$isStaticValue = null, array &$foundClasses = []): string
    {
        $isStaticValue = true;

        if (!\is_object($value) && !(\is_array($value) && $value) && !\is_resource($value) || $value instanceof \UnitEnum) {
            return Exporter::export($value);
        }

        $objectsPool = new \SplObjectStorage();
        $refsPool = [];
        $objectsCount = 0;

        try {
            $value = Exporter::prepare([$value]$objectsPool$refsPool$objectsCount$isStaticValue)[0];
        } finally {
            $references = [];
            foreach ($refsPool as $i => $v) {
                if ($v[0]->count) {
                    $references[1 + $i] = $v[2];
                }
                
protected function setUp(): void
    {
        $workflowMetadata = [
            'title' => 'workflow title',
        ];
        $placesMetadata = [
            'place_a' => [
                'title' => 'place_a title',
            ],
        ];
        $transitionsMetadata = new \SplObjectStorage();
        $this->transition = new Transition('transition_1', [][]);
        $transitionsMetadata[$this->transition] = [
            'title' => 'transition_1 title',
        ];

        $this->store = new InMemoryMetadataStore($workflowMetadata$placesMetadata$transitionsMetadata);
    }

    public function testGetWorkflowMetadata()
    {
        $metadataBag = $this->store->getWorkflowMetadata();
        

  protected $entityTypeManager;

  /** * Constructs a new LanguageNegotiationContentEntity instance. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->paths = new \SplObjectStorage();
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition) {
    return new static($container->get('entity_type.manager'));
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.