eZ\Publish\Core\FieldType\RichText\RichTextStorage\Gateway\LegacyStorage::setConnection PHP Method

setConnection() public method

Set database handler for this gateway.
public setConnection ( mixed $dbHandler )
$dbHandler mixed
    public function setConnection($dbHandler)
    {
        // This obviously violates the Liskov substitution Principle, but with
        // the given class design there is no sane other option. Actually the
        // dbHandler *should* be passed to the constructor, and there should
        // not be the need to post-inject it.
        if (!$dbHandler instanceof DatabaseHandler) {
            throw new RuntimeException('Invalid dbHandler passed');
        }
        $this->urlGateway->setConnection($dbHandler);
        $this->dbHandler = $dbHandler;
    }

Usage Example

 /**
  * Returns a ready to test LegacyStorage gateway
  *
  * @return \eZ\Publish\Core\FieldType\RichText\RichTextStorage\Gateway\LegacyStorage
  */
 protected function getStorageGateway()
 {
     if (!isset($this->storageGateway)) {
         $this->storageGateway = new LegacyStorage(new UrlStorage());
         $this->storageGateway->setConnection($this->getDatabaseHandler());
     }
     return $this->storageGateway;
 }