[cmclasses] r1233 committed - Check nested object on HTML Tag rendering.

0 views
Skip to first unread message

cmcl...@googlecode.com

unread,
Jun 30, 2015, 1:57:30 PM6/30/15
to cmcl...@googlegroups.com
Revision: 1233
Author: christian.wuerker
Date: Tue Jun 30 17:57:07 2015 UTC
Log: Check nested object on HTML Tag rendering.

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

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

=======================================
--- /trunk/src/UI/HTML/Tag.php Sat May 23 06:45:51 2015 UTC
+++ /trunk/src/UI/HTML/Tag.php Tue Jun 30 17:57:07 2015 UTC
@@ -77,6 +77,16 @@
foreach( $data as $key => $value )
$this->setData( $key, $value );
}
+
+ /**
+ * String Representation.
+ * @access public
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->build();
+ }

/**
* Builds HTML tags as string.
@@ -119,8 +129,17 @@
$content = self::flattenArray( $content );
if( is_numeric( $content ) )
$content = (string) $content;
- if( !is_null( $content ) && !is_string( $content ) ) //
content is neither NULL nor string so far
- throw new InvalidArgumentException( 'Content is not a string' );
// which is not acceptable
+ 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
+ }
+ if( !is_null( $content ) && !is_string( $content ) ){ //
content is neither NULL nor string so far
+ $message = 'Content type "'.gettype( $content ).'" is not supported';
// prepare message about wrong content data type
+ throw new InvalidArgumentException( $message ); // break
with error message
+ }
return "<".$name.$attributes.$data.">".$content."</".$name.">";
// build and return full tag
}

@@ -166,6 +185,10 @@
return NULL;
return $this->data[$key];
}
+
+ public function render(){
+ return $this->build();
+ }

protected static function renderData( $data = array() ){
$list = array();
@@ -295,16 +318,5 @@
{
$this->content = $content;
}
-
- /**
- * String Representation.
- * @access public
- * @return string
- */
- public function __toString()
- {
-// return $this->create( $this->name, $this->content, $this->attributes,
$this->data );
- return $this->build();
- }
}
?>
Reply all
Reply to author
Forward
0 new messages