getOrigin example

$data['country'] = $data['countryId'];
        $data['state'] = $data['stateId'] ?? null;

        $form = $this->get('shopware.form.factory')->create(AddressFormType::class$model);
        $form->submit($data);

        if ($form->isSubmitted() && !$form->isValid()) {
            $errors = [];
            foreach ($form->getErrors(true) as $violation) {
                $errors[] = [
                    'message' => $violation->getMessage(),
                    'property' => $violation->getOrigin()->getName(),
                ];
            }

            return ['success' => false, 'violations' => $errors];
        }

        $model = $form->getData();

        if ($model->getId()) {
            $this->addressService->update($model);
        } else {
            
/** * Gets the request elapsed time. */
    public function getDuration(): float
    {
        if (!isset($this->data['events']['__section__'])) {
            return 0;
        }

        $lastEvent = $this->data['events']['__section__'];

        return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
    }

    /** * Gets the initialization time. * * This is the time spent until the beginning of the request handling. */
    public function getInitTime(): float
    {
        if (!isset($this->data['events']['__section__'])) {
            return 0;
        }
return null;
        }

        return new ApiClient($clientIdentifier, true, $values['label'] ?? Uuid::fromBytesToHex((string) $values['user_id']));
    }

    /** * @return array<string, string|null>|null */
    private function getByAccessKey(string $clientIdentifier): ?array
    {
        $origin = AccessKeyHelper::getOrigin($clientIdentifier);

        if ($origin === 'user') {
            return $this->getUserByAccessKey($clientIdentifier);
        }

        if ($origin === 'integration') {
            return $this->getIntegrationByAccessKey($clientIdentifier);
        }

        return null;
    }

    


            $this->handleExtraData($extraData$address);

            $addressView = $this->get(ModelManager::class)->toArray($address);
            $addressView['country'] = $this->get(ModelManager::class)->toArray($address->getCountry());
            $addressView['state'] = $this->get(ModelManager::class)->toArray($address->getState());
            $addressView['attribute'] = $this->get(ModelManager::class)->toArray($address->getAttribute());
            $response['data'] = $addressView;
        } else {
            foreach ($form->getErrors(true) as $error) {
                $response['errors'][$error->getOrigin()->getName()] = $error->getMessage();
            }
        }

        $response['success'] = empty($response['errors']);

        $this->Response()->headers->set('content-type', 'application/json', true);
        $this->Response()->setContent(json_encode($response));
    }

    /** * Do various actions based on extraData[] parameters */
return;
        }

        $accessKey = $request->headers->get(PlatformRequest::HEADER_ACCESS_KEY);
        if (!$accessKey) {
            throw ApiException::unauthorized(
                'header',
                sprintf('Header "%s" is required.', PlatformRequest::HEADER_ACCESS_KEY)
            );
        }

        $origin = AccessKeyHelper::getOrigin($accessKey);
        if ($origin !== 'sales-channel') {
            throw ApiException::salesChannelNotFound();
        }

        $salesChannelData = $this->getSalesChannelData($accessKey);

        $this->handleMaintenanceMode($request$salesChannelData);

        $request->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID, $salesChannelData['id']);
    }

    
/** * Gets the request elapsed time. */
    public function getDuration(): float
    {
        if (!isset($this->data['events']['__section__'])) {
            return 0;
        }

        $lastEvent = $this->data['events']['__section__'];

        return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
    }

    /** * Gets the initialization time. * * This is the time spent until the beginning of the request handling. */
    public function getInitTime(): float
    {
        if (!isset($this->data['events']['__section__'])) {
            return 0;
        }
if ($dispatcher->hasListeners(FormEvents::POST_SUBMIT)) {
            $event = new PostSubmitEvent($this$viewData);
            $dispatcher->dispatch($event, FormEvents::POST_SUBMIT);
        }

        return $this;
    }

    public function addError(FormError $error)static
    {
        if (null === $error->getOrigin()) {
            $error->setOrigin($this);
        }

        if ($this->parent && $this->config->getErrorBubbling()) {
            $this->parent->addError($error);
        } else {
            $this->errors[] = $error;
        }

        return $this;
    }

    
if ($form->getViewData() !== $form->getNormData()) {
            $data['submitted_data']['view'] = $form->getViewData();
        }

        if ($form->getData() !== $form->getNormData()) {
            $data['submitted_data']['model'] = $form->getData();
        }

        foreach ($form->getErrors() as $error) {
            $errorData = [
                'message' => $error->getMessage(),
                'origin' => \is_object($error->getOrigin())
                    ? spl_object_hash($error->getOrigin())
                    : null,
                'trace' => [],
            ];

            $cause = $error->getCause();

            while (null !== $cause) {
                if ($cause instanceof ConstraintViolationInterface) {
                    $errorData['trace'][] = $cause;
                    $cause = method_exists($cause, 'getCause') ? $cause->getCause() : null;

                    

        if ($form->isSubmitted() && $form->isValid()) {
            return [];
        }
        $errors = [
            '' => $this->get('snippets')
                ->getNamespace('frontend/account/internalMessages')
                ->get('ErrorFillIn', 'Please fill in all red fields'),
        ];

        foreach ($form->getErrors(true) as $error) {
            $errors[$error->getOrigin()->getName()] = $this->View()->fetch('string:' . $error->getMessage());
        }

        return $errors;
    }

    private function isShippingProvided(array $data): bool
    {
        return \array_key_exists('shippingAddress', $data['register']['billing']);
    }

    private function getPostData(): array
    {
public function testGenerateAccessKeyWithInvalidIdentifier(): void
    {
        static::expectException(ApiException::class);
        static::expectExceptionMessage('Given identifier for access key is invalid.');
        AccessKeyHelper::generateAccessKey('invalid_identifier');
    }

    public function testGenerateOriginWithIntegrationIdentifier(): void
    {
        $accessKey = AccessKeyHelper::generateAccessKey('integration');
        $origin = AccessKeyHelper::getOrigin($accessKey);
        static::assertSame('integration', $origin);
    }

    public function testGenerateOriginWithInvalidAccessKey(): void
    {
        static::expectExceptionMessage('Access key is invalid and could not be identified.');
        static::expectException(ApiException::class);
        AccessKeyHelper::getOrigin('invalid_access_key');
    }

    /** * @return array<int, array<int, string>> */
$form->submit([
            'year' => '2020',
            'month' => '13',
            'day' => '13',
        ]);

        $this->assertTrue($form->isSubmitted());
        $this->assertFalse($form->isValid());
        $this->assertCount(2, $form->getErrors());
        $this->assertSame('Please enter a valid date.', $form->getErrors()[0]->getMessage());
        $this->assertSame($form->get('year')$form->getErrors()[0]->getOrigin());
        $this->assertSame('Please enter a valid date.', $form->getErrors()[1]->getMessage());
        $this->assertSame($form->get('month')$form->getErrors()[1]->getOrigin());
    }

    public function testDoNotAddInvalidMessageIfChildFormIsAlreadyNotSynchronized()
    {
        $formBuilder = $this->formFactory->createBuilder()
            ->add('field1')
            ->add('field2')
            ->addModelTransformer(new CallbackTransformer(
                function D) {
                },

    public static function createFromFormError(FormErrorIterator $errors)
    {
        $violations = [];

        foreach ($errors as $error) {
            if (!$error instanceof FormError) {
                continue;
            }
            $message = Shopware()->Template()->fetch('string:' . $error->getMessage());

            $origin = $error->getOrigin();
            $violations[] = new ConstraintViolation(
                $message,
                $error->getMessageTemplate(),
                $error->getMessageParameters(),
                $origin ? $origin->getRoot() : null,
                $origin ? (string) $origin->getPropertyPath() : null,
                $origin ? $origin->getData() : null,
                $error->getMessagePluralization(),
                null,
                null,
                $error->getCause()
            );
$appIntegrationId = null;
            }

            return $this->getAdminApiSource($userId$appIntegrationId);
        }

        if (!$request->attributes->has(PlatformRequest::ATTRIBUTE_OAUTH_ACCESS_TOKEN_ID)) {
            return new SystemSource();
        }

        $clientId = $request->attributes->get(PlatformRequest::ATTRIBUTE_OAUTH_CLIENT_ID);
        $keyOrigin = AccessKeyHelper::getOrigin($clientId);

        if ($keyOrigin === 'user') {
            $userId = $this->getUserIdByAccessKey($clientId);

            return $this->getAdminApiSource($userId);
        }

        if ($keyOrigin === 'integration') {
            $integrationId = $this->getIntegrationIdByAccessKey($clientId);

            return $this->getAdminApiSource(null, $integrationId);
        }
static::assertSame(200, $response->getStatusCode()print_r($body, true));
        static::assertIsArray($body);
        static::assertArrayHasKey('accessKey', $body);
        static::assertArrayHasKey('secretAccessKey', $body);
        static::assertNotEmpty($body['secretAccessKey']);
        static::assertNotEmpty($body['accessKey']);

        $e = null;

        try {
            AccessKeyHelper::getOrigin($body['accessKey']);
        } catch (\Exception $e) {
        }
        static::assertTrue($e === null);
    }

    public function testUserAccessKey(): void
    {
        $url = '/api/_action/access-key/user';
        $this->getBrowser()->request('GET', $url);

        $response = $this->getBrowser()->getResponse();
        

class StopwatchEventTest extends TestCase
{
    private const DELTA = 37;

    public function testGetOrigin()
    {
        $event = new StopwatchEvent(12);
        $this->assertEquals(12, $event->getOrigin());
    }

    public function testGetCategory()
    {
        $event = new StopwatchEvent(microtime(true) * 1000);
        $this->assertEquals('default', $event->getCategory());

        $event = new StopwatchEvent(microtime(true) * 1000, 'cat');
        $this->assertEquals('cat', $event->getCategory());
    }

    
Home | Imprint | This part of the site doesn't use cookies.