Beispiel #1
0
 /**
  * Returns the content of this template as a string
  *
  * @return Mixed
  */
 public function render()
 {
     // This allows a toString method to return a non-string without throwing an error
     if (is_object($this->content) && \r8\respondTo($this->content, "__toString")) {
         return (string) $this->content->__toString();
     } else {
         return (string) $this->content;
     }
 }
Beispiel #2
0
 /**
  * Recursively builds an XML tree
  *
  * @param \DOMDocument $doc The document being built
  * @param String $parent The tag name of the parent element
  * @param Mixed $data The data being pieced together
  * @param Boolean $root Whether the data being parsed is at the root level
  *      This is used during iteration, for example, to ensure lists are
  *      created properly
  * @return DOMNode Returns the built node
  */
 protected function build(\DOMDocument $doc, $parent, &$data, $root = FALSE)
 {
     if (\r8\isEmpty($data)) {
         return $this->createElement($doc, $parent);
     } else {
         if (\r8\isBasic($data) && $data !== NULL) {
             $node = $this->createElement($doc, $parent);
             $node->appendChild($doc->createTextNode((string) $data));
         } else {
             if (is_array($data) || $data instanceof \Traversable) {
                 $node = $this->iterate($doc, $parent, $data, $root);
             } else {
                 if ($data instanceof \r8\iface\XMLBuilder) {
                     $node = $this->createElement($doc, $parent);
                     $node->appendChild(\r8\XMLBuilder::buildNode($data, $doc));
                 } else {
                     if (is_object($data)) {
                         // If it is an object that supports "toString"
                         if (\r8\respondTo($data, "__toString")) {
                             $node = $this->createElement($doc, $parent);
                             $node->appendChild($doc->createTextNode($data->__toString()));
                         } else {
                             $props = get_object_vars($data);
                             $node = $this->iterate($doc, $parent, $props, $root);
                         }
                     }
                 }
             }
         }
     }
     return $node;
 }
Beispiel #3
0
/**
 * Calls the given method for all objects that respond to it
 *
 * @param Array $array The array to iterate over
 * @param String $func The name of the method to invoke
 * @param mixed $args... Any arguments to pass to the method
 * @return Array Returns the resulting array
 */
function invoke(array $array, $func)
{
    $func = (string) $func;
    $out = array();
    $args = func_get_args();
    array_shift($args);
    array_shift($args);
    foreach ($array as $key => $val) {
        if (is_object($val) && \r8\respondTo($val, $func)) {
            $out[$key] = call_user_func_array(array($val, $func), $args);
        }
    }
    return $out;
}
Beispiel #4
0
 public function testRespondTo()
 {
     $this->assertFalse(\r8\respondTo(505, 'method'));
     $this->assertFalse(\r8\respondTo(50.5, 'method'));
     $this->assertFalse(\r8\respondTo(NULL, 'method'));
     $this->assertFalse(\r8\respondTo(TRUE, 'method'));
     $this->assertFalse(\r8\respondTo(FALSE, 'method'));
     $this->assertFalse(\r8\respondTo('string', 'method'));
     $this->assertFalse(\r8\respondTo(array(), 'method'));
     $this->assertFalse(\r8\respondTo(new stdClass(), 'method'));
     $test = $this->getMock('stdClass', array('testFunc'));
     $this->assertTrue(\r8\respondTo($test, 'testFunc'));
     $this->assertFalse(\r8\respondTo($test, 'Not A Valid Method Name'));
 }