toArray example

$this->expectException(LogicException::class);
        $serializer = new Serializer([]['json' => new JsonEncoder()]);
        $data = ['title' => 'foo', 'numbers' => [5, 3]];
        $serializer->serialize(Model::fromArray($data), 'json');
    }

    public function testDeserialize()
    {
        $serializer = new Serializer([new GetSetMethodNormalizer()]['json' => new JsonEncoder()]);
        $data = ['title' => 'foo', 'numbers' => [5, 3]];
        $result = $serializer->deserialize(json_encode($data), Model::class, 'json');
        $this->assertEquals($data$result->toArray());
    }

    public function testDeserializeUseCache()
    {
        $serializer = new Serializer([new GetSetMethodNormalizer()]['json' => new JsonEncoder()]);
        $data = ['title' => 'foo', 'numbers' => [5, 3]];
        $serializer->deserialize(json_encode($data), Model::class, 'json');
        $data = ['title' => 'bar', 'numbers' => [2, 8]];
        $result = $serializer->deserialize(json_encode($data), Model::class, 'json');
        $this->assertEquals($data$result->toArray());
    }

    
yield ['user:password', 'user', 'password'];
        yield ['user:password', 'user:password'];
        yield ['user', 'user'];
        yield ['user:0', 'user', '0'];
    }

    /** * @dataProvider provideSetAuthBasic */
    public function testSetAuthBasic(string $expected, string $user, string $password = '')
    {
        $this->assertSame($expected(new HttpOptions())->setAuthBasic($user$password)->toArray()['auth_basic']);
    }

    public function testSetAuthBearer()
    {
        $this->assertSame('foobar', (new HttpOptions())->setAuthBearer('foobar')->toArray()['auth_bearer']);
    }
}
public function sGetSupplierById($id)
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.8. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        $id = (int) $id;
        $categoryId = (int) $this->frontController->Request()->getQuery('sCategory');

        $supplier = Shopware()->Models()->getRepository(Supplier::class)->find($id);
        if (!($supplier instanceof Supplier)) {
            return [];
        }
        $supplier = Shopware()->Models()->toArray($supplier);
        if (!Shopware()->Shop()->getDefault()) {
            $supplier = $this->sGetTranslation($supplier$supplier['id'], 'supplier');
        }
        $supplier['link'] = $this->config['sBASEFILE'];
        $supplier['link'] .= '?sViewport=cat&sCategory=' . $categoryId . '&sPage=1&sSupplier=0';

        return $supplier;
    }

    /** * Product price calculation * * @param float $price * @param float $tax * @param int $taxId * @param array $article product data as an array * * @throws Enlight_Exception * * @return string $price formatted price */


        if ([] !== $value) {
            throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
        }
    }

    public function toArray(): array
    {
        $output = [];
        if (isset($this->_usedProperties['page'])) {
            $output['page'] = array_map(fn ($v) => $v->toArray()$this->page);
        }

        return $output;
    }

}
protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface
    {
        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/smtp/email', [
            'json' => $this->getPayload($email$envelope),
            'headers' => [
                'api-key' => $this->key,
            ],
        ]);

        try {
            $statusCode = $response->getStatusCode();
            $result = $response->toArray(false);
        } catch (DecodingExceptionInterface) {
            throw new HttpTransportException('Unable to send an email: '.$response->getContent(false).sprintf(' (code %d).', $statusCode)$response);
        } catch (TransportExceptionInterface $e) {
            throw new HttpTransportException('Could not reach the remote Sendinblue server.', $response, 0, $e);
        }

        if (201 !== $statusCode) {
            throw new HttpTransportException('Unable to send an email: '.$result['message'].sprintf(' (code %d).', $statusCode)$response);
        }

        $sentMessage->setMessageId($result['messageId']);

        
$endpoint = sprintf('https://%s/v1/rooms/%s/chatMessages', $this->getEndpoint()$this->roomId);

        $response = $this->client->request('POST', $endpoint[
            'auth_bearer' => $this->token,
            'json' => [
                'text' => $message->getSubject(),
            ],
        ]);

        try {
            $result = $response->toArray(false);
        } catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote Gitter server.', $response, 0, $e);
        }

        if (200 !== $response->getStatusCode()) {
            throw new TransportException(sprintf('Unable to post the Gitter message: "%s".', $result['error'])$response);
        }

        $sentMessage = new SentMessage($message(string) $this);
        $sentMessage->setMessageId($result['id']);

        
$this->assertSame('config_test.validation', $typed_config->getName());
    $this->assertSame('config_test.validation', $typed_config->getPropertyPath());
    $this->assertSame('config_test.validation.llama', $typed_config->get('llama')->getPropertyPath());

    $config_test_entity = \Drupal::entityTypeManager()->getStorage('config_test')->create([
      'id' => 'asterix',
      'label' => 'Asterix',
      'weight' => 11,
      'style' => 'test_style',
    ]);

    $typed_config = $typed_config_manager->createFromNameAndData($config_test_entity->getConfigDependencyName()$config_test_entity->toArray());
    $this->assertInstanceOf(TypedConfigInterface::class$typed_config);
    $this->assertEquals(['uuid', 'langcode', 'status', 'dependencies', 'id', 'label', 'weight', 'style', 'size', 'size_value', 'protected_property']array_keys($typed_config->getElements()));
  }

  /** * Tests config validation via the Typed Data API. */
  public function testSimpleConfigValidation() {
    $config = \Drupal::configFactory()->getEditable('config_test.validation');
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager */
    $typed_config_manager = \Drupal::service('config.typed');
    
public function supports(MessageInterface $message): bool
    {
        return $message instanceof PushMessage && (null === $message->getOptions() || $message->getOptions() instanceof NovuOptions);
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof PushMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, PushMessage::class$message);
        }

        $options = $message->getOptions()?->toArray() ?? [];

        $body = [
            'name' => $message->getSubject(),
            'to' => [
                'subscriberId' => $message->getRecipientId(),
                'firstName' => $options['firstName'],
                'lastName' => $options['lastName'],
                'email' => $options['email'],
                'phone' => $options['phone'],
                'avatar' => $options['avatar'],
                'locale' => $options['locale'],
            ],
$this->setAdditionalAddressLine1((string) $address->getAdditionalAddressLine1());
        $this->setAdditionalAddressLine2((string) $address->getAdditionalAddressLine2());
        $this->setCountry($address->getCountry());
        $this->setPhone($address->getPhone());
        $this->setTitle($address->getTitle());
        if ($address->getState()) {
            $this->setState($address->getState());
        } else {
            $this->setState(null);
        }

        $attributeData = Shopware()->Models()->toArray($address->getAttribute());
        $this->setAttribute($attributeData);
    }

    /** * @return string|null */
    public function getTitle()
    {
        return $this->title;
    }

    
static::assertEquals(
            $context,
            $mediaUploadEvent->getContext()
        );
    }

    public function testGetAvailableData(): void
    {
        $eventDataCollection = MediaUploadedEvent::getAvailableData();

        static::assertInstanceOf(EventDataCollection::class$eventDataCollection);
        static::assertCount(1, $eventDataCollection->toArray());
        static::assertEquals(
            (new EventDataCollection())->add('mediaId', new ScalarValueType(ScalarValueType::TYPE_STRING)),
            $eventDataCollection
        );
    }

    public function testRestoreScalarValuesCorrectly(): void
    {
        $event = new MediaUploadedEvent('media-id', Context::createDefaultContext());

        $storer = new ScalarValuesStorer();

        
protected $_locale;

    /** * Constructor for the integer validator * * @param string|Zend_Config|Zend_Locale $locale */
    public function __construct($locale = null)
    {
        if ($locale instanceof Zend_Config) {
            $locale = $locale->toArray();
        }

        if (is_array($locale)) {
            if (array_key_exists('locale', $locale)) {
                $locale = $locale['locale'];
            } else {
                $locale = null;
            }
        }

        if ($locale !== null) {
            
$this->action = new Action([
            'meta' => $meta,
            'headers' => $this->headers,
            'parameters' => $this->parameters,
            'config' => $this->config,
        ]);
    }

    public function testToArray(): void
    {
        $result = $this->action->toArray('en-GB');
        static::assertArrayHasKey('name', $result);
        static::assertArrayHasKey('swIcon', $result);
        static::assertArrayHasKey('url', $result);
        static::assertArrayHasKey('delayable', $result);
        static::assertArrayHasKey('parameters', $result);
        static::assertArrayHasKey('config', $result);
        static::assertArrayHasKey('headers', $result);
        static::assertArrayHasKey('requirements', $result);
        static::assertArrayHasKey('label', $result);
        static::assertArrayHasKey('description', $result);
        static::assertArrayHasKey('headline', $result);
    }
    $this->setUntranslatableFieldWidgetsDisplay(TRUE);
    $entity = $this->saveNewEntity();
    $entity_id = $entity->id();
    $this->assertLatestRevisionFieldValues($entity_id[1, 1, 1, 'Alt 1 EN']);

    /** @var \Drupal\Core\Entity\ContentEntityInterface $en_revision */
    $en_revision = $this->createRevision($entity, FALSE);
    $en_revision->get($this->fieldName)->target_id = 2;
    $violations = $en_revision->validate();
    $this->assertViolations($violations);

    $it_translation = $entity->addTranslation('it', $entity->toArray());
    /** @var \Drupal\Core\Entity\ContentEntityInterface $it_revision */
    $it_revision = $this->createRevision($it_translation, FALSE);
    $metadata = $this->contentTranslationManager->getTranslationMetadata($it_revision);
    $metadata->setSource('en');
    $it_revision->get($this->fieldName)->target_id = 2;
    $it_revision->get($this->fieldName)->alt = 'Alt 2 IT';
    $violations = $it_revision->validate();
    $this->assertViolations($violations);
    $it_revision->isDefaultRevision(TRUE);
    $violations = $it_revision->validate();
    $this->assertEmpty($violations);
    

    public function setOptions($options = null)
    {
        if ($options === null) {
            return $this;
        }

        if ($options instanceof Enlight_Config) {
            $options = $options->toArray();
        }

        foreach ($options as $key => $option) {
            $key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
            $this->{'set' . $key}($option);
        }

        return $this;
    }

    /** * Set template directory * * @param string|array $template_dir directory(s) of template sources * * @return Smarty current Smarty instance for chaining */
public function getConfig(): Config
    {
        return $this->config;
    }

    /** * @return array<string, mixed> */
    public function toArray(string $defaultLocale): array
    {
        $data = parent::toArray($defaultLocale);

        return array_merge($data[
            'name' => $this->meta->getName(),
            'swIcon' => $this->meta->getSwIcon(),
            'url' => $this->meta->getUrl(),
            'delayable' => $this->meta->getDelayable(),
            'parameters' => $this->normalizeParameters(),
            'config' => array_map(fn ($config) => $config->jsonSerialize()$this->config->getConfig()),
            'headers' => array_map(fn ($header) => $header->jsonSerialize()$this->headers->getParameters()),
            'requirements' => $this->meta->getRequirements(),
            'label' => $this->meta->getLabel(),
            
Home | Imprint | This part of the site doesn't use cookies.