FieldVisibility example


    public function getInput(): EntityCollection|Entity
    {
        $ruleCollection = new RuleCollection();

        $rule = new RuleEntity();
        $rule->setId('f343a3c119cf42a7841aa0ac5094908c');
        $rule->setName('Test rule');
        $rule->setDescription('Test description');
        $rule->setPayload(new AndRule([new TrueRule()new FalseRule()]));
        $rule->internalSetEntityData('rule', new FieldVisibility([]));
        $ruleCollection->add($rule);

        return $ruleCollection;
    }

    /** * @return array<string, mixed> */
    protected function getJsonApiFixtures(string $baseUrl): array
    {
        return [
            
$user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        $media = new MediaEntity();
        $media->setId('3e352be2d85846dd97529c0f6b544870');
        $media->setUser(clone $user);
        $media->setUserId($userId);
        $media->setMimeType('image/jpg');
        $media->setFileExtension('jpg');
        $media->setFileSize(18921);
        $media->setCreatedAt(new \DateTime('2012-08-15T00:00:00.000+00:00'));
        $media->setUpdatedAt(new \DateTime('2017-11-21T11:25:34.000+00:00'));
        $media->setTitle('Lagerkorn-5,0klein');
        
/** @var array<string> $internalProperties */
        $internalProperties = $this->getFields()
            ->fmap(function DField $field): ?string {
                if ($field->is(ApiAware::class)) {
                    return null;
                }

                return $field->getPropertyName();
            });

        return $this->fieldVisibility = new FieldVisibility(array_values($internalProperties));
    }

    /** * PHPStan will complain that we should specify the generic type if we hint that class strings * of EntityCollection should be returned. * * @return class-string */
    public function getCollectionClass(): string
    {
        return EntityCollection::class;
    }

#[Package('buyers-experience')] class StructEncoderTest extends TestCase
{
    /** * Regression test where the cheapest price and cheapest price container were exposed because the StructEncoder did not consider sales channel definitions */
    public function testCheapestPricesAreNotExposed(): void
    {
        $product = new SalesChannelProductEntity();
        $product->internalSetEntityData('product', new FieldVisibility([]));

        $product->setName('test');
        $product->setCheapestPrice(
            (new CheapestPrice())->assign([
                'hasRange' => false,
                'variantId' => Uuid::randomHex(),
                'parentId' => Uuid::randomHex(),
                'ruleId' => Uuid::randomHex(),
                'purchase' => 1.0,
                'reference' => 1.0,
                'price' => new PriceCollection(),
            ])
$user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        $media = new MediaEntity();
        $media->setId('548faa1f7846436c85944f4aea792d96');
        $media->setUserId($userId);
        $media->setMimeType('image/jpg');
        $media->setFileExtension('jpg');
        $media->setFileSize(93889);
        $media->setTitle('2');
        $media->setCreatedAt(new \DateTime('2012-08-31T00:00:00.000+00:00'));
        $media->setUpdatedAt(new \DateTime('2017-11-21T11:25:34.000+00:00'));
        $media->setUser(clone $user);
        
public function testApiAlias(string $class, string $expected): void
    {
        /** @var Entity $entity */
        $entity = new $class();

        static::assertSame($expected$entity->getApiAlias());
    }

    public function testCustomApiAliasHasPrecedence(): void
    {
        $entity = new FooBarEntity();
        $entity->internalSetEntityData('custom_entity_name', new FieldVisibility([]));

        static::assertSame('custom_entity_name', $entity->getApiAlias());
    }
}

/** * @internal */
class FooEntity extends Entity
{
}

$user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        $media1 = new MediaEntity();
        $media1->setId('3e352be2d85846dd97529c0f6b544870');
        $media1->setUser($user);
        $media1->setUserId($userId);
        $media1->setMimeType('image/jpg');
        $media1->setFileExtension('jpg');
        $media1->setFileSize(18921);
        $media1->setCreatedAt(new \DateTime('2012-08-15T00:00:00.000+00:00'));
        $media1->setUpdatedAt(new \DateTime('2017-11-21T11:25:34.000+00:00'));
        $media1->setTitle('Lagerkorn-5,0klein');
        
/** * @return MediaFolderCollection|MediaFolderEntity */
    public function getInput(): EntityCollection|Entity
    {
        $parent = new MediaFolderEntity();
        $parent->setId('3e352be2d85846dd97529c0f6b544870');
        $parent->setChildCount(1);
        $parent->setUseParentConfiguration(false);
        $parent->setCreatedAt(new \DateTime('2012-08-15T00:00:00.000+00:00'));
        $parent->setUpdatedAt(new \DateTime('2017-11-21T11:25:34.000+00:00'));
        $parent->internalSetEntityData('media_folder', new FieldVisibility([]));

        $child = new MediaFolderEntity();
        $child->setId('5846dd97529c0f6b5448713e352be2d8');
        $child->setChildCount(1);
        $child->setUseParentConfiguration(true);
        $child->setParentId('3e352be2d85846dd97529c0f6b544870');
        $child->setCreatedAt(new \DateTime('2012-08-15T00:00:00.000+00:00'));
        $child->setUpdatedAt(new \DateTime('2017-11-21T11:25:34.000+00:00'));
        $child->internalSetEntityData('media_folder', new FieldVisibility([]));
        $parent->setChildren(new MediaFolderCollection([$child]));

        
$response = $this->encoder->encode($structnew ResponseFields(null));

        static::assertNull($response['customFields']);
        static::assertSame(['test']$response['translated']['customFields']);
    }

    public function testApiAwareWorksWithPartialEntity(): void
    {
        $entity = new PartialEntity();
        $entity->set('id', Uuid::randomHex());
        $entity->internalSetEntityData('my_entity', new FieldVisibility([]));
        $entity->set('name', 'test');
        $entity->set('description', 'test');
        $entity->set('translated', [
            'name' => 'test',
            'description' => 'test',
        ]);

        $registry = $this->createMock(DefinitionRegistryChain::class);
        $registry->method('has')
            ->willReturn(true);

        
$request = Request::create($path, 'GET', [][][]['HTTP_ACCEPT' => $accept]);
        $this->setOrigin($request$context);

        return $this->getFactory($request)->createListingResponse($criteria$searchResult$definition$request$context);
    }

    private function getTestCategory(string $id): CategoryEntity
    {
        $category = new CategoryEntity();
        $category->setId($id);
        $category->setName($id);
        $category->internalSetEntityData('category', new FieldVisibility([]));

        return $category;
    }

    private function setOrigin(Request $request, Context $context): void
    {
        $this->setRequestAttributeHack($request, PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT, $context);
    }

    private function setRequestAttributeHack(Request $request, string $key, Context|int $value): void
    {
        

    public function getInput(): EntityCollection|Entity
    {
        $media = new MediaEntity();
        $media->setId('1d23c1b015bf43fb97e89008cf42d6fe');
        $media->setTitle('Manufacturer');
        $media->setMimeType('image/png');
        $media->setFileExtension('png');
        $media->setFileSize(310818);
        $media->setAlt('A media object description');
        $media->setCreatedAt(new \DateTime('2018-01-15T08:01:16.432+00:00'));
        $media->internalSetEntityData('media', new FieldVisibility([]));

        return $media;
    }

    /** * @return array<string, mixed> */
    protected function getJsonApiFixtures(string $baseUrl): array
    {
        return [
            'data' => [
                
$user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        $media = new MediaEntity();
        $media->setId('548faa1f7846436c85944f4aea792d96');
        $media->setUserId($userId);
        $media->setMimeType('image/jpg');
        $media->setFileExtension('jpg');
        $media->setFileSize(93889);
        $media->setTitle('2');
        $media->setCreatedAt(new \DateTime('2012-08-31T00:00:00.000+00:00'));
        $media->setUpdatedAt(new \DateTime('2017-11-21T11:25:34.000+00:00'));
        $media->setUser($user);
        
Home | Imprint | This part of the site doesn't use cookies.