예제 #1
0
 /**
  * Converts this data to a string that can output. This is not a hash
  * key or a serialization, but an actual render for humans.
  *
  * @throws Exceptions\NotCachedException
  */
 public function stringify(CacheAbstract $c, $recurse = true)
 {
     $retval = [];
     foreach ($this->data as $item) {
         if ($item['type'] == self::CACHEDATA_TYPE_CALLBACK) {
             $callback = $item['data'];
             if (is_callable($callback)) {
                 $retval[] = call_user_func($callback);
             } else {
                 // throw?
             }
         } else {
             if ($item['type'] == self::CACHEDATA_TYPE_RECURSION) {
                 if ($recurse) {
                     $retval[] = $c->get($item['data']);
                 }
             } else {
                 if ($item['type'] == self::CACHEDATA_TYPE_RECURSION_DATA) {
                     if ($recurse) {
                         $data = $c->getData($item['data']);
                         $retval[] = $data->stringify($c);
                     }
                 } else {
                     $retval[] = $item['data'];
                 }
             }
         }
     }
     return implode('', $retval);
 }