Example #1
0
 public function makeProducts(AbstractFactory $factory)
 {
     $productA = $factory->createProductA();
     $productB = $factory->createProductB();
     $stdObject = new \stdClass();
     $stdObject->attributeA = $this->getAttributeA($productA);
     $stdObject->attributeB = $this->getAttributeB($productB);
     return $stdObject;
 }
Example #2
0
 /**
  * 创建action并返回
  * @param $fields
  */
 public static function Create($className)
 {
     $controller = AbstractFactory::create(Config::CONTROLLER(), $className);
     if (!$controller instanceof Controller) {
         throw new CheckedException("Class '{$className}' is not extends Controller !", CheckedException::CLASS_NOT_FOUND, null);
     }
     return $controller;
 }
Example #3
0
 private function excuteResult(array $resultMap)
 {
     $result = null;
     try {
         $result = AbstractFactory::create(Config::RESULT(), "Result" . $resultMap['type']);
     } catch (FileException $fe) {
         if ($fe->getCode() == FileException::CLASS_FILE_NOT_FOUND) {
             throw new CheckedException("Rresult type  " . "Result" . $resultMap['type'] . " is undefined", CheckedException::RESULT_UNDEFINED, $fe);
         }
     } catch (CheckedException $ce) {
         if ($ce->getCode() == CheckedException::RESULT_UNDEFINED) {
             throw new CheckedException("Rresult type  " . "Result" . $resultMap['type'] . " is undefined", CheckedException::RESULT_UNDEFINED, $fe);
         }
     }
     $result->createResult($resultMap);
 }
Example #4
0
 protected function __construct()
 {
     parent::__construct();
     $this->initializeMessageListeners();
 }
 protected function __construct()
 {
     parent::__construct();
     $this->instance = $this->prepareProxiedInstance();
 }
 protected function __construct()
 {
     parent::__construct();
     $this->extensionConfigurations = module_invoke_all('dc_datasource');
     $this->handlerConfigurations = module_invoke_all($this->getHookName());
 }
Example #7
0
    {
        return new FooTypeA();
    }
}
class FactoryTypeB extends AbstractFactory
{
    public function createFoo()
    {
        return new FooTypeB();
    }
}
abstract class Foo
{
    public abstract function doStuff();
}
class FooTypeA extends Foo
{
    public function doStuff()
    {
        return "FooTypeA";
    }
}
class FooTypeB extends Foo
{
    public function doStuff()
    {
        return "FooTypeB";
    }
}
echo AbstractFactory::obtainFactory()->createFoo()->doStuff();
    protected function __construct() {
        parent::__construct();
        $this->cache = $this->initializeCache('metadata');

        $this->initiateLoaders();
    }
Example #9
0
        return new FirstProduct();
    }
}
class FirstProduct implements Product
{
    public function getName()
    {
        return 'The product from the first factory';
    }
}
class SecondFactory extends AbstractFactory
{
    public function getProduct()
    {
        return new SecondProduct();
    }
}
class SecondProduct implements Product
{
    public function getName()
    {
        return 'The product from second factory';
    }
}
$firstProduct = AbstractFactory::getFactory()->getProduct();
Config::$factory = 2;
$secondProduct = AbstractFactory::getFactory()->getProduct();
print_r($firstProduct->getName());
// The first product from the first factory
print_r($secondProduct->getName());
// Second product from second factory
Example #10
0
 /**
  * 调用工厂实例生成产品,输出产品名
  * @param   $factory    AbstractFactory     工厂实例
  */
 public static function run(AbstractFactory $factory)
 {
     $productA = $factory->createProductA();
     $productB = $factory->createProductB();
     printf("%s\n%s\n", $productA->getName(), $productB->getName());
 }
Example #11
0
 /**
  * @param callable $callback
  * @param string $name
  * @param bool $singleton
  * @param bool $cloneable
  */
 public function __construct(callable $callback, $name = null, $singleton = true, $cloneable = false)
 {
     parent::__construct($name, $singleton, $cloneable);
     $this->callback = $callback;
 }
 protected function __construct()
 {
     parent::__construct();
     $this->initiateLoaders();
 }
Example #13
0
 /**
  * @param string $class
  * @param string $name
  * @param bool $singleton
  * @param bool $cloneable
  */
 public function __construct($class, $name = null, $singleton = true, $cloneable = false)
 {
     parent::__construct($name, $singleton, $cloneable);
     $this->class = $class;
 }