public function testBuilder() { $expect = "<header>Header</header>\n" + "<article>Content</article>\n" + "<footer>Footer</footer>\n"; $product = new Product(); $director = new Director(new ConcreteBuilder($product)); $director->construct(); $result = $product->show(); $this->assertEquals($result, $expect); }
public static function photo($reference, $maxWidth = 0) { if ((int) $maxWidth === 0) { $maxWidth = \App\Lib\Api\GooglePlace\Config::radius(); } $photoBuilder = new BuilderPhoto(); $photoBuilder->setupMaxWidth($maxWidth); $photoBuilder->setupPhotoReference($reference); $photoBuilder->setupDataType(); $director = new Director($photoBuilder); $director->construct(); $request = $director->getResult(); $response = $request->send(); return $response; }
public function buildPartA() { $this->result->add("Part X"); } public function buildPartB() { $this->result->add("Part Y"); } public function getResult() : Product { return $this->result; } } class Director { public function construct(IBuilder $builder) { $builder->buildPartA(); $builder->buildPartB(); $builder->buildPartB(); } } $director = new Director(); $b1 = new Builder1(); $b2 = new Builder2(); $director->construct($b1); $product1 = $b1->getResult(); $product1->display(); $director->construct($b2); $product2 = $b2->getResult(); $product2->display();
<?php header('Content-Type: text/html; charset=utf-8'); ini_set('display_errors', '1'); function __autoload($class_name) { set_include_path('class'); include $class_name . '.php'; } $Builder = new Builder(); $Director = new Director($Builder); $Director->construct(); $Product = $Builder->getResult(); print_r($Product); writeln(''); writeln(''); $SuperBuilder = new SuperBuilder(); $Director->setBuilder($SuperBuilder); $Director->construct(); $Product = $SuperBuilder->getResult(); print_r($Product); function writeln($line_in) { echo $line_in . "<br><br>"; }
<?php require_once './Builder.php'; require_once './TextBuilder.php'; require_once './XmlBuilder.php'; require_once './Director.php'; $header = "title->test"; $body = "test builder"; $footer = "end"; $text_builder = new TextBuilder(); $text_director = new Director($text_builder); $text_director->construct($header, $body, $footer); $xml_builder = new XmlBuilder(); $xml_director = new Director($xml_builder); $xml_director->construct($header, $body, $footer); echo $text_builder->getResult(); echo $xml_builder->getResult();