Issue #2501735 by snehi, lokapujya, malavya, priya.chat, sdstyles, ChuChuNaKu, er.manojsharma, mglaman, joelpittet: Add throws to Twig extension comments

8.1.x
Nathaniel Catchpole 2016-02-26 22:26:17 +09:00
parent 39c9d54a60
commit 6e3370b782
1 changed files with 15 additions and 6 deletions

View File

@ -401,6 +401,10 @@ class TwigExtension extends \Twig_Extension {
* @return string|null * @return string|null
* The escaped, rendered output, or NULL if there is no valid output. * The escaped, rendered output, or NULL if there is no valid output.
* *
* @throws \Exception
* When $arg is passed as an object which does not implement __toString(),
* RenderableInterface or toString().
*
* @todo Refactor this to keep it in sync with theme_render_and_autoescape() * @todo Refactor this to keep it in sync with theme_render_and_autoescape()
* in https://www.drupal.org/node/2575065 * in https://www.drupal.org/node/2575065
*/ */
@ -432,7 +436,7 @@ class TwigExtension extends \Twig_Extension {
elseif (method_exists($arg, '__toString')) { elseif (method_exists($arg, '__toString')) {
$return = (string) $arg; $return = (string) $arg;
} }
// You can't throw exceptions in the magic PHP __toString methods, see // You can't throw exceptions in the magic PHP __toString() methods, see
// http://php.net/manual/language.oop5.magic.php#object.tostring so // http://php.net/manual/language.oop5.magic.php#object.tostring so
// we also support a toString method. // we also support a toString method.
elseif (method_exists($arg, 'toString')) { elseif (method_exists($arg, 'toString')) {
@ -470,10 +474,11 @@ class TwigExtension extends \Twig_Extension {
/** /**
* Wrapper around render() for twig printed output. * Wrapper around render() for twig printed output.
* *
* If an object is passed that has no __toString method an exception is thrown; * If an object is passed which does not implement __toString(),
* other objects are casted to string. However in the case that the object is an * RenderableInterface or toString() then an exception is thrown;
* instance of a Twig_Markup object it is returned directly to support auto * Other objects are casted to string. However in the case that the
* escaping. * object is an instance of a Twig_Markup object it is returned directly
* to support auto escaping.
* *
* If an array is passed it is rendered via render() and scalar values are * If an array is passed it is rendered via render() and scalar values are
* returned directly. * returned directly.
@ -481,6 +486,10 @@ class TwigExtension extends \Twig_Extension {
* @param mixed $arg * @param mixed $arg
* String, Object or Render Array. * String, Object or Render Array.
* *
* @throws \Exception
* When $arg is passed as an object which does not implement __toString(),
* RenderableInterface or toString().
*
* @return mixed * @return mixed
* The rendered output or an Twig_Markup object. * The rendered output or an Twig_Markup object.
* *
@ -510,7 +519,7 @@ class TwigExtension extends \Twig_Extension {
elseif (method_exists($arg, '__toString')) { elseif (method_exists($arg, '__toString')) {
return (string) $arg; return (string) $arg;
} }
// You can't throw exceptions in the magic PHP __toString methods, see // You can't throw exceptions in the magic PHP __toString() methods, see
// http://php.net/manual/language.oop5.magic.php#object.tostring so // http://php.net/manual/language.oop5.magic.php#object.tostring so
// we also support a toString method. // we also support a toString method.
elseif (method_exists($arg, 'toString')) { elseif (method_exists($arg, 'toString')) {