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); } }