@param EventStreamObject $eventStreamObject

@return EventInterface
334083
public static function buildEventFromEventStreamObject(EventStreamObject $eventStreamObject): EventInterface
    {
        /** @var EventInterface $eventClass */
        $eventClass = $eventStreamObject->getEvent();
        /** @var \RevisionTen\CQRS\Interfaces\CommandInterface $commandClass */
        $commandClass = $eventClass::getCommandClass();

        $user = $eventStreamObject->getUser();
        $commandUuid = $eventStreamObject->getCommandUuid();
        $uuid = $eventStreamObject->getUuid();
        // Its safe to assume the command was created on the previous version, it would have failed otherwise.
        $onVersion = $eventStreamObject->getVersion() - 1;
        $payload = $eventStreamObject->getPayload();

        /** @var \RevisionTen\CQRS\Interfaces\CommandInterface $command */
        $command = new $commandClass($user, $commandUuid, $uuid, $onVersion, $payload);

        return new $eventClass($command);
    }
1131386
public static function newStream($body = null): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (is_resource($body)) {
            return new Stream($body);
        }

        $stream = new Stream(fopen('php://temp', 'w+'));
        ! empty($body) && $stream->write($body);

        return $stream;
    }
453166
protected function getListeners(Event $eventObject) {
        $listeners = $this->getOption(self::OPTION_LISTENERS);
        return isset($listeners[$eventObject->getName()])
            ? $listeners[$eventObject->getName()]
            : array();
    }
582070
public function banProductPageCacheCheckStock($eventObject) {
        if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) {
            $item = $eventObject->getItem();
            if ($item->getStockStatusChangedAutomatically() ||
                    ($item->getOriginalInventoryQty() <= 0 &&
                        $item->getQty() > 0 &&
                        $item->getQtyCorrection() > 0)) {
                $banHelper = Mage::helper('turpentine/ban');
                $cronHelper = Mage::helper('turpentine/cron');
                $product = Mage::getModel('catalog/product')
                    ->load($item->getProductId());
                $urlPattern = $banHelper->getProductBanRegex($product);
                $result = $this->_getVarnishAdmin()->flushUrl($urlPattern);
                Mage::dispatchEvent('turpentine_ban_product_cache_check_stock',
                    $result);
                if ($this->_checkResult($result) &&
                        $cronHelper->getCrawlerEnabled()) {
                    $cronHelper->addProductToCrawlerQueue($product);
                    foreach ($banHelper->getParentProducts($product)
                            as $parentProduct) {
                        $cronHelper->addProductToCrawlerQueue($parentProduct);
                    }
                }
            }
        }
    }
115095
public function applyBehaviourOnFormInstance(FormObject $formObject)
    {
        if ($formObject->hasForm()) {
            $formInstance = $formObject->getForm();

            foreach ($formObject->getConfiguration()->getFields() as $fieldName => $field) {
                if (ObjectAccess::isPropertyGettable($formInstance, $fieldName)
                    && ObjectAccess::isPropertySettable($formInstance, $fieldName)
                ) {
                    $propertyValue = ObjectAccess::getProperty($formInstance, $fieldName);

                    foreach ($field->getBehaviours() as $behaviour) {
                        /** @var AbstractBehaviour $behaviourInstance */
                        $behaviourInstance = GeneralUtility::makeInstance($behaviour->getClassName());

                        // Applying the behaviour on the field's value.
                        $propertyValue = $behaviourInstance->applyBehaviour($propertyValue);
                    }

                    ObjectAccess::setProperty($formInstance, $fieldName, $propertyValue);
                }
            }
        }
    }
652715
public function dispatch(string $eventCode, EventInterface $event)
    {
        $this->assertValidEventCode($eventCode);
        if (true === isset($this->eventListeners[$eventCode])) {
            foreach ($this->eventListeners[$eventCode] as $listener) {
                $listener($event);
            }
        }

        return $this;
    }
804697
public function replaceFormKeyPlaceholder($eventObject) {
        if (Mage::registry('replace_form_key')) {
            $esiHelper = Mage::helper('turpentine/esi');
            $response = $eventObject->getResponse();
            $responseBody = $response->getBody();
            $responseBody = str_replace('{{form_key_esi_placeholder}}',
                $esiHelper->buildEsiIncludeFragment(
                    $esiHelper->getFormKeyEsiUrl() ),
                $responseBody);
            $response->setBody($responseBody);
        }
    }
1019281
public function inspect(Interfaces\JavaObject $javaObject): string
    {
        try {
            $inspect = $this->pjbProxyClient->inspect($javaObject);
        } catch (Pjb62BrokenConnectionException | Exception\InvalidUsageException $e) {
            PjbProxyClient::unregisterInstance();
            throw new BrokenConnectionException($e->getMessage(), $e->getCode(), $e);
        }

        return $inspect;
    }
860673
protected function createEventObject($eventName, array $data)
    {
        if (!array_key_exists($eventName, $this->options['events'])) {
            throw new \InvalidArgumentException('Event is not defined.');
        }

        $namespace = $this->options['events'][$eventName]['object'];
        $instance = new $namespace($eventName, $data);

        if (!($instance instanceof EventInterface)) {
            throw new \LogicException('Invalid interface of event object');
        }

        return $instance;
    }
221731
public function asObject($asObject = null)
    {
        if ($asObject === null)
        {
            return $this->_asObject;
        }
        $this->_asObject = $asObject;

        return $this;
    }
469740
public static function createFromMutable(\ArrayObject $arrayObject) : ImmutableArrayObject
    {
        return new static($arrayObject->getArrayCopy(), $arrayObject->getFlags(), $arrayObject->getIteratorClass());
    }
961074
public function values(Interfaces\JavaObject $javaObject)
    {
        try {
            return $this->pjbProxyClient->getValues($javaObject);
        } catch (Pjb62BrokenConnectionException | Exception\InvalidUsageException $e) {
            PjbProxyClient::unregisterInstance();
            throw new BrokenConnectionException($e->getMessage(), $e->getCode(), $e);
        }
    }
913994
public function append(Contract $aggregateRootType, EventStream $eventStream)
    {
        $statement = $this->insertQuery->prepare();

        try {
            while ($eventStream->hasNext()) {
                $event = $eventStream->next();

                $statement->bindValue(':aggregate_id', $event->aggregateRootIdentifier()->toString());
                $statement->bindValue(':aggregate_type', $aggregateRootType->toString());
                $statement->bindValue(':aggregate_version', $event->sequenceNumber());
                $statement->bindValue(':event_id', $event->identifier()->toString());
                $statement->bindValue(':event_payload', $this->eventSerializer->serializePayload($event));
                $statement->bindValue(':event_payload_type', $event->payloadType()->toString());
                $statement->bindValue(':event_metadata', $this->eventSerializer->serializeMetadata($event));
                $statement->bindValue(':event_metadata_type', $event->metadataType()->toString());

                $statement->execute();
                $statement->closeCursor();
            }
        } catch (\PDOException $exception) {
            // 23000 being the primary key duplicate entry error code.
            if ($exception->errorInfo[0] === '23000') {
                throw new ConcurrencyException('Concurrent modification detected.');
            }

            throw $exception;
        }
    }
294344
private function appendToEventsForStream(&$eventsForStream, $serializedEvents)
    {
        // TODO: remove support of non array values by upcasters in next major release
        if (!is_array($serializedEvents)) {
            @trigger_error(
                'Upcasters need to return an array collection of upcasted events, ' .
                'non array return values are deprecated and support will be removed in the next major release',
                E_USER_DEPRECATED
            );

            $serializedEvents = [$serializedEvents];
        }

        foreach ($serializedEvents as $serializedEvent) {
            $eventsForStream[] = $this->eventFactory->createFromSerializedEvent($serializedEvent);
        }
    }
932054
public static function create($body = ''): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_string($body)) {
            $resource = \fopen('php://temp', 'rw+');
            \fwrite($resource, $body);
            $body = $resource;
        }

        if (\is_resource($body)) {
            $new = new self();
            $new->stream = $body;
            $meta = \stream_get_meta_data($new->stream);
            $new->seekable = $meta['seekable'];
            $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
            $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
            $new->uri = $new->getMetadata('uri');

            return $new;
        }

        throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
    }
181321
public static function fromDomainObject($domainObject)
    {
        if (!is_object($domainObject)) {
            throw new InvalidDomainObjectException('$domainObject must be an object.');
        }

        try {
            if ($domainObject instanceof HierarchicalDomainObjectInterface) {
                return new self(
                    $domainObject->getHierarchicalObjectIdentifiers(),
                    $domainObject->getObjectIdentifier(),
                    ClassUtils::getRealClass($domainObject)
                );
            }

            return parent::fromDomainObject($domainObject);
        } catch (\InvalidArgumentException $invalid) {
            throw new InvalidDomainObjectException($invalid->getMessage(), 0, $invalid);
        }

        throw new InvalidDomainObjectException('$domainObject must either implement the HierarchicalDomainObjectInterface, DomainObjectInterface, or have a method named "getId".');
    }
194774
public function append(EventStreamInterface $eventStream)
    {
        /** @var $event Event */
        foreach ($eventStream as $event) {
            $version = $event->getVersion();
            $id = $event->getId();

            if (!isset($this->store[$id])) {
                $this->store[$id] = [];
            }

            if (isset($this->store[$id][$version])) {
                throw new DuplicateVersionException($version);
            }

            $this->store[$id][$version] = $event;
        }
    }