Source of file AbstractPlatform.php
Size: 3,660 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Db/Sql/Platform/AbstractPlatform.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\Sql\Platform; use Zend\Db\Adapter\AdapterInterface; use Zend\Db\Adapter\Platform\PlatformInterface; use Zend\Db\Adapter\StatementContainerInterface; use Zend\Db\Sql\Exception; use Zend\Db\Sql\PreparableSqlInterface; use Zend\Db\Sql\SqlInterface; class AbstractPlatform implements PlatformDecoratorInterface, PreparableSqlInterface, SqlInterface { /** * @var object */ protected $subject = null; /** * @var PlatformDecoratorInterface[] */ protected $decorators = array(); /** * @param $subject */ public function setSubject($subject) { $this->subject = $subject; } /** * @param $type * @param PlatformDecoratorInterface $decorator */ public function setTypeDecorator($type, PlatformDecoratorInterface $decorator) { $this->decorators[$type] = $decorator; } /** * @return array|PlatformDecoratorInterface[] */ public function getDecorators() { return $this->decorators; } /** * @param AdapterInterface $adapter * @param StatementContainerInterface $statementContainer * @throws Exception\RuntimeException * @return void */ public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) { if (!$this->subject instanceof PreparableSqlInterface) { throw new Exception\RuntimeException('The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling prepareStatement() has no effect'); } $decoratorForType = false; foreach ($this->decorators as $type => $decorator) { if ($this->subject instanceof $type && $decorator instanceof PreparableSqlInterface) { /** @var $decoratorForType PreparableSqlInterface|PlatformDecoratorInterface */ $decoratorForType = $decorator; break; } } if ($decoratorForType) { $decoratorForType->setSubject($this->subject); $decoratorForType->prepareStatement($adapter, $statementContainer); } else { $this->subject->prepareStatement($adapter, $statementContainer); } } /** * @param null|\Zend\Db\Adapter\Platform\PlatformInterface $adapterPlatform * @return mixed * @throws Exception\RuntimeException */ public function getSqlString(PlatformInterface $adapterPlatform = null) { if (!$this->subject instanceof SqlInterface) { throw new Exception\RuntimeException('The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling prepareStatement() has no effect'); } $decoratorForType = false; foreach ($this->decorators as $type => $decorator) { if ($this->subject instanceof $type && $decorator instanceof SqlInterface) { /** @var $decoratorForType SqlInterface|PlatformDecoratorInterface */ $decoratorForType = $decorator; break; } } if ($decoratorForType) { $decoratorForType->setSubject($this->subject); return $decoratorForType->getSqlString($adapterPlatform); } return $this->subject->getSqlString($adapterPlatform); } } |