Chris@0: render(); Chris@0: } Chris@0: catch (\Exception $e) { Chris@0: // User errors in __toString() methods are considered fatal in the Drupal Chris@0: // error handler. Chris@0: trigger_error(get_class($e) . ' thrown while calling __toString on a ' . get_class($this) . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_ERROR); Chris@0: // In case we are using another error handler that did not fatal on the Chris@0: // E_USER_ERROR, we terminate execution. However, for test purposes allow Chris@0: // a return value. Chris@0: return $this->_die(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * For test purposes, wrap die() in an overridable method. Chris@0: */ Chris@0: protected function _die() { Chris@0: die(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renders the object as a string. Chris@0: * Chris@0: * @return string|object Chris@0: * The rendered string or an object implementing __toString(). Chris@0: */ Chris@0: abstract public function render(); Chris@0: Chris@0: }