Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. class View implements \Countable, \Iterator
  2. {
  3.     use MagicTrait;
  4.  
  5.     protected $data = [];
  6.  
  7.     public function display($template)
  8.     {
  9.         foreach ($this->data as $name => $value) {
  10.             $$name = $value;
  11.         }
  12.         include $template;
  13.     }
  14.  
  15.     public function render($template)
  16.     {
  17.         ob_start();
  18.         $this->display($template);
  19.         $contents = ob_get_contents();
  20.         ob_end_clean();
  21.         return $contents;
  22.     }
  23.  
  24.  
  25.     public function count()
  26.     {
  27.         return count($this->data);
  28.     }
  29.  
  30.     public function current()
  31.     {
  32.         return current($this->data);
  33.     }
  34.  
  35.     public function next()
  36.     {
  37.         return next($this->data);
  38.     }
  39.  
  40.     public function key()
  41.     {
  42.         return key($this->data);
  43.     }
  44.  
  45.     public function valid()
  46.     {
  47.         $key = key($this->data);
  48.         return ($key !== null && $key !== false);
  49.     }
  50.  
  51.     public function rewind()
  52.     {
  53.         reset($this->data);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement