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; }
/** * 创建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; }
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); }
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()); }
{ 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(); }
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
/** * 调用工厂实例生成产品,输出产品名 * @param $factory AbstractFactory 工厂实例 */ public static function run(AbstractFactory $factory) { $productA = $factory->createProductA(); $productB = $factory->createProductB(); printf("%s\n%s\n", $productA->getName(), $productB->getName()); }
/** * @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(); }
/** * @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; }