public function testOneAggregate()
 {
     $josh = new User('2131293jq', 'Josh Di Fabio');
     $catalog = new Catalog('uk2015', 'UK 2015', $josh);
     $catalog->addProduct(new Product('S9123', 'T-Shirt'));
     $catalog->addProduct(new Product('S9124', 'Jumper'));
     $normalizer = new \AggregatePersistence\Serialization\GenericNormalizer();
     $serializer = new \AggregatePersistence\Serialization\JsonSerializer($normalizer);
     $aggregateContainerSet = new \AggregatePersistence\Doctrine\AggregateContainerSet();
     $aggregateContainerSet->add(new \AggregatePersistence\Doctrine\AggregateContainer($catalog->id(), $catalog));
     $aggregateContainerSet->add(new \AggregatePersistence\Doctrine\AggregateContainer($josh->id(), $josh));
     $serialization1 = $serializer->serialize($catalog, $aggregateContainerSet);
     $repository = new class([$josh->id() => $josh]) implements \AggregatePersistence\AggregateRepository
     {
         private $aggregates;
         public function __construct(array $aggregates)
         {
             $this->aggregates = $aggregates;
         }
         public function find(string $aggregateRootId)
         {
             return $this->aggregates[$aggregateRootId];
         }
     };
     $deserialization = $serializer->deserialize($serialization1, $repository);
     $serialization2 = $serializer->serialize($deserialization, $aggregateContainerSet);
     $this->assertSame($serialization1, $serialization2);
 }
Esempio n. 2
0
        foreach ($dom->getElementsByTagName('img') as $img) {
            if ($img->getAttribute('id') == "productImg") {
                $image = trim($img->getAttribute('src'));
                if (!in_array($image, $seen)) {
                    array_push($seen, $image);
                    $map["image"] = "http://www.ikea.com" . $image;
                }
            }
        }
        foreach ($dom->getElementsByTagName('a') as $cat) {
            if ($cat->getAttribute('id') == "gotoSims_lnk1") {
                $category = preg_replace("/&#?[a-z0-9]{2,8};/i", "", trim($cat->nodeValue));
                if (!in_array($category, $seen)) {
                    array_push($seen, $category);
                    $map["category"] = trim($category);
                }
            }
        }
        $prod = new Product($map);
        $catalog->addProduct($prod);
    }
    // Save the products in the database */
    $catalog->persist();
    //var_dump($productLinksArray);
} catch (Exception $e) {
    echo "Exception raised : ";
    echo $e->getMessage();
}
?>