本文整理汇总了PHP中Catalog::addProduct方法的典型用法代码示例。如果您正苦于以下问题:PHP Catalog::addProduct方法的具体用法?PHP Catalog::addProduct怎么用?PHP Catalog::addProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Catalog
的用法示例。
在下文中一共展示了Catalog::addProduct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testOneAggregate
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);
}
示例2: foreach
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();
}
?>