{ echo "set product size<br/>"; $this->_size = $size; } public function setColor($color) { echo "set product color<br/>"; $this->_color = $color; } } $config = array("type" => "shirt", "size" => "xl", "color" => "red"); // 没有使用bulider以前的处理 $oProduct = new Product(); $oProduct->setType($config['type']); $oProduct->setSize($config['size']); $oProduct->setColor($config['color']); // 创建一个builder类 class ProductBuilder { var $_config = null; var $_object = null; public function ProductBuilder($config) { $this->_object = new Product(); $this->_config = $config; } public function build() { echo "--- in builder---<br/>"; $this->_object->setType($this->_config['type']); $this->_object->setSize($this->_config['size']);
<?php //This is a test case script for testing the functionality. include 'BestBuyProcessor/BB_MinPriceCalculator.php'; include 'Product.php'; // We actually provide array of prices to _comparePricesForLeast() from E-commerce APIs. //There will be separate code to group all prices into a single array from different API providers $MinPriceObj = new BB_MinPriceCalculator(); $prices = array(5, 2, 3, 1, 6, 7); $min = $MinPriceObj->_compareForLeast($prices); echo $min; //This is for product class functions test. $product = new Product(); $disc = 5; echo $product->setDiscOnMinPurchase($disc); echo $product->getDiscOnMinPurchase(); // _hasCashBack function test..Currently this is failing but will correct soon. $cashback = 8; echo $product->setCashback($cashback); echo $product->_hasCashback(); //Array of colours of product test $array_of_color = array(5, 2, 1); $product->setColor($array_of_color); $arry = $product->getColor(); foreach ($arry as $colr) { printf("{$colr}\n"); } ?>
* `-- Shirts */ $rootCategory = new Category('Collection'); $pantsCategory = new Category('Pants'); $jacketsCategory = new Category('Jackets'); $blousesCategory = new Category('Blouses'); $shirtsCategory = new Category('Shirts'); $rootCategory->addChild($pantsCategory); $rootCategory->addChild($jacketsCategory); $rootCategory->addChild($blousesCategory); $rootCategory->addChild($shirtsCategory); // Создаем пару брендов $adidas = new Brand('Adidas'); $nike = new Brand('Nike'); // Создаем продукты... $pants = new Product('Jogging Pants', 79.95); $pants->setColor('black'); $pants->setBrand($adidas); $jeans = new Product('Midi - handcrafted - Jeans', 129.95); $jeans->setColor('blue'); $jeans->setImage('http://example.com/some-iamge.jpg'); $jeans->setBrand($nike); $leggings = new Product('Leggings', 99.95); // ... и добавляем их в категории $pantsCategory->addProduct($pants); $pantsCategory->addProduct($jeans); $pantsCategory->addProduct($leggings); // Меняем категорию одному из продуктов. $leggings->setCategory($blousesCategory); // Подключаем шаблон include 'view.php';