Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
    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();
Ejemplo n.º 4
0
<?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>";
}
Ejemplo n.º 5
0
<?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();