Source
Source Code of This Project
Source Code of This Project
/lib/model/DFactory.php
<?php
/*
* This file is part of the pwp package.
* (c) 2009-2010 Victor Rad' <victor.v.rad[at]gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Doctrine abstract factory
*
* A purpose of this class is in creation of objects of Doctrine class.
* The factory of Doctrine does not give possibility to build hierarchical models,
* it is even impossible to take advantage of constructor of the created class.
* This a class is wraper above factory Doctrine
*
* @package pwp
* @subpackage DFactory
* @author Victor Rad'
*/
abstract class DFactory
{
public function __construct($nameInstance)
{
$this->setNameInstance($nameInstance);
}
/**
* Getter name of instance
*
* @return string e.g. "News"
*/
protected function getNameInstance()
{
if (empty($this->nameInstance)){
throw new Exception('Property "nameInstance" is not set');
}
else{
return $this->nameInstance;
}
}
/**
* Set name of instance
*
* @param string $name e.g. "News"
* @return void
*/
protected function setNameInstance($name)
{
$this->nameInstance = $name;
}
/**
* Factory method
* e.g. DFactory::get('News')->getBuilder()->joinProvides()...
*
* @param <type> $reqInstance
* @return reqInstance
*/
public static function get($reqInstance)
{
$factoryInstance = 'DFactory_' . $reqInstance;
return new $factoryInstance($reqInstance);
}
/**
* Get the Doctrine_Table object for the passed model
*
* @return Doctrine_Table
*/
public function getTable()
{
return Doctrine::getTable($this->getNameInstance());
}
/**
* Get the Doctrine_Record object for the passed model
*
* @return Doctrine_Record
*/
public function getRecord()
{
$nameInstance = $this->getNameInstance();
return new $nameInstance;
}
/**
* Get the represent of DBuilder object for the passed model
*
* @return DBuilder
*/
abstract protected function getBuilder();
}