[cmclasses] r1247 committed - Allow HTML tag to get stringable object as content.

0 views
Skip to first unread message

cmcl...@googlecode.com

unread,
Aug 18, 2015, 4:00:51 PM8/18/15
to cmcl...@googlegroups.com
Revision: 1247
Author: christian.wuerker
Date: Tue Aug 18 20:00:34 2015 UTC
Log: Allow HTML tag to get stringable object as content.

https://code.google.com/p/cmclasses/source/detail?r=1247

Modified:
/trunk/src/UI/HTML/Tag.php

=======================================
--- /trunk/src/UI/HTML/Tag.php Tue Jun 30 18:40:06 2015 UTC
+++ /trunk/src/UI/HTML/Tag.php Tue Aug 18 20:00:34 2015 UTC
@@ -311,11 +311,19 @@
/**
* Sets Content of Tag.
* @access public
- * @param string $content Content of Tag
+ * @param string|object $content Content of Tag or stringable object
* @return void
+ * @throws InvalidArgumentException if given object has no __toString
method
*/
public function setContent( $content = NULL )
{
+ if( is_object( $content ) ){
+ if( !method_exists( $content, '__toString' ) ){ // content
is not a renderable object
+ $message = 'Object of class "'.get_class( $content ).'" cannot be
rendered'; // prepare message about not renderable object
+ throw new InvalidArgumentException( $message ); // break
with error message
+ }
+ $content = (string) $content; // render object to string
+ }
$this->content = $content;
}
}
Reply all
Reply to author
Forward
0 new messages