1: <?php
 2: 
 3: /**
 4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
 5:  */
 6: class Quform_View
 7: {
 8:     /**
 9:      * Path to the view template
10:      * @var string
11:      */
12:     protected $template;
13: 
14:     /**
15:      * Data to be extracted and available within the view template
16:      * @var array
17:      */
18:     protected $data = array();
19: 
20:     /**
21:      * @param  string  $template
22:      * @param  array   $data
23:      */
24:     public function __construct($template, array $data = array())
25:     {
26:         $this->template = $template;
27:         $this->data = $data;
28:     }
29: 
30:     /**
31:      * Render the view and return the output
32:      *
33:      * @return string
34:      */
35:     public function render()
36:     {
37:         extract($this->data);
38: 
39:         ob_start();
40: 
41:         include $this->template;
42: 
43:         return ob_get_clean();
44:     }
45: 
46:     /**
47:      * Add a piece of data to the view.
48:      *
49:      * @param   string|array  $key
50:      * @param   mixed         $value
51:      * @return  Quform_View   $this
52:      */
53:     public function with($key, $value = null)
54:     {
55:         if (is_array($key)) {
56:             $this->data = array_merge($this->data, $key);
57:         } else {
58:             $this->data[$key] = $value;
59:         }
60: 
61:         return $this;
62:     }
63: }
64: