hydrate example

<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
    $o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([][
        'C:60:"Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooSerializable":20:{a:1:{i:0;s:3:"bar";}}',
    ]),
    null,
    [],
    $o[0],
    []
);

    public function getList(array $ids, ShopContextInterface $context)
    {
        $ids = array_keys(array_flip($ids));
        $query = $this->createQuery($context);
        $query->andWhere('customFacet.id IN (:ids)');
        $query->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY);

        $facets = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        $facets = $this->hydrate($facets);

        return $this->getAndSortElementsByIds($ids$facets);
    }

    /** * {@inheritdoc} */
    public function getFacetsOfCategories(array $categoryIds, ShopContextInterface $context)
    {
        $mapping = $this->getCategoryMapping($categoryIds);

        
$customerData = $data[$customerId];
            }

            if (\array_key_exists($customerId$products)) {
                $customerData = array_merge($customerData$products[$customerId]);
            }

            if (\array_key_exists($customerId$amount)) {
                $customerData = array_merge($customerData$amount[$customerId]);
            }

            $struct = $this->hydrator->hydrate($customerData);

            $struct->setHasCanceledOrders(\in_array($customerId$canceled));

            $structs[$customerId] = $struct;
        }

        return $structs;
    }

    /** * @param int[] $ids * * @return array */


        // always add the criteria fields to the collection, otherwise we have conflicts between criteria.fields and criteria.association logic         $fields = $this->addAssociationFieldsToCriteria($criteria$definition$fields);

        if ($definition->isInheritanceAware() && $criteria->hasAssociation('parent')) {
            throw new ParentAssociationCanNotBeFetched();
        }

        $rows = $this->fetch($criteria$definition$context$fields$partial);

        $collection = $this->hydrator->hydrate($collection$definition->getEntityClass()$definition$rows$definition->getEntityName()$context$partial);

        $collection = $this->fetchAssociations($criteria$definition$context$collection$fields$partial);

        $hasIds = !empty($criteria->getIds());
        if ($hasIds && empty($criteria->getSorting())) {
            $collection->sortByIdArray($criteria->getIds());
        }

        return $collection;
    }

    
->addOrderBy('position', 'ASC')
            ->addOrderBy('name', 'ASC')
            ->setParameter(':ids', $paymentIds, Connection::PARAM_INT_ARRAY);

        $this->fieldHelper->addPaymentTranslation($query$context);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        $payments = [];
        foreach ($data as $row) {
            $id = (int) $row['__payment_id'];
            $payments[$id] = $this->paymentHydrator->hydrate($row);
        }

        return $payments;
    }
}
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
    $o = [
        clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooReadonly'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooReadonly')),
    ],
    null,
    [
        'Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooReadonly' => [
            'name' => [
                'k',
            ],
            'value' => [
                'v',
            ],

        $query = $this->buildQuery($criteria);

        $customers = $this->fetchCustomers($criteria$query);

        $total = \count($customers);
        if ($criteria->fetchCount()) {
            $total = $this->fetchTotal($query);
        }

        return new CustomerNumberSearchResult(
            $this->hydrate($customers),
            (int) $total
        );
    }

    /** * @param array[] $result * * @return array */
    private function hydrate(array $result)
    {
        
$ids = array_keys(array_flip($ids));

        $query = $this->createQuery();

        $query->where('address.id IN (:ids)');
        $query->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
        $addresses = [];
        foreach ($data as $row) {
            $id = $row['__address_id'];
            $addresses[$id] = $this->hydrator->hydrate($row);
        }

        return $addresses;
    }

    private function createQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->addSelect($this->fieldHelper->getAddressFields());
        $query->addSelect($this->fieldHelper->getCountryFields());
        $query->addSelect($this->fieldHelper->getStateFields());

        
->execute()
            ->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_COLUMN);

        $medias = $this->getMediaQuery(array_column($data, '__blog_id'))
            ->execute()
            ->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_COLUMN);

        $blogs = [];
        foreach ($data as $row) {
            $id = (int) $row['__blog_id'];

            $blog = $this->blogHydrator->hydrate($row);

            if (\array_key_exists($id$articles)) {
                $blog->setProductNumbers($articles[$id]);
            }

            if (\array_key_exists($id$medias)) {
                $blog->setMediaIds($medias[$id]);
            }

            $blogs[$id] = $blog;
        }

        
$id = $row['__shop_id'];
            $mainId = $row['__shop_main_id'];

            if ($mainId && isset($parents[$mainId])) {
                $row['parent'] = $parents[$mainId];
            } elseif ($mainId && isset($shops[$mainId])) {
                $row['parent'] = $shops[$mainId];
            } else {
                $row['parent'] = null;
            }

            $result[$id] = $this->hydrator->hydrate($row);
        }

        return $result;
    }

    /** * @param int[] $ids * * @return array<array<string, mixed>> */
    private function getShops(array $ids): array
    {
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
    $o = [
        clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\Php74Serializable'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Php74Serializable')),
        clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
    ],
    null,
    [],
    $o[0],
    [
        [
            $o[1],
        ],
    ]
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
    $o = [
        clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue')),
        clone ($p['Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue')),
    ],
    null,
    [
        'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [
            'prot' => [
                123,
                123,
            ],
            
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
    $o = [
        clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['SplObjectStorage'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('SplObjectStorage')),
        clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
    ],
    null,
    [],
    $o[0],
    [
        [
            [
                $o[1],
                
$option->setId((int) $data['__propertyOption_id']);
        $option->setName($data['__propertyOption_value']);
        $option->setPosition((int) $data['__propertyOption_position']);

        if ($data['__propertyOptionAttribute_id']) {
            $this->attributeHydrator->addAttribute($option$data, 'propertyOptionAttribute', 'core', 'propertyOption');
        }

        if (isset($data['__media_id']) && $data['__media_id']) {
            $option->setMedia(
                $this->mediaHydrator->hydrate($data)
            );
        }

        return $option;
    }

    /** * @param array<string, mixed> $data */
    private function hydrateSet(array $data): Set
    {
        
$instance = clone Registry::$prototypes[$class];
        } elseif (Registry::$instantiableWithoutConstructor[$class]) {
            $instance = $reflector->newInstanceWithoutConstructor();
        } elseif (null === Registry::$prototypes[$class]) {
            throw new NotInstantiableTypeException($class);
        } elseif ($reflector->implementsInterface('Serializable') && !method_exists($class, '__unserialize')) {
            $instance = unserialize('C:'.\strlen($class).':"'.$class.'":0:{}');
        } else {
            $instance = unserialize('O:'.\strlen($class).':"'.$class.'":0:{}');
        }

        return $properties || $scopedProperties ? Hydrator::hydrate($instance$properties$scopedProperties) : $instance;
    }
}
Home | Imprint | This part of the site doesn't use cookies.