当前位置: 首页>>代码示例>>PHP>>正文


PHP Catalog::addProduct方法代码示例

本文整理汇总了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);
 }
开发者ID:joshdifabio,项目名称:aggregate-persistence,代码行数:28,代码来源:SerializationTest.php

示例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();
}
?>

开发者ID:mahaidong,项目名称:ikea,代码行数:29,代码来源:crawler.php


注:本文中的Catalog::addProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。