1 <?php
 2 /**
 3  * ViewPlugin.php
 4  *
 5  * @author  Elvyrra SAS
 6  * @license http://rem.mit-license.org/ MIT
 7  */
 8 
 9 namespace Hawk;
10 
11 /**
12  * This abstract class defines the view plugins. It must be inherited by any class that defines any view plugin.
13  * This class is called when, in a view, you write something like that :
14  * {pluginName param="value1" param2="{$variable}" }
15  *
16  * @package View\Plugins
17  */
18 abstract class ViewPlugin{
19     use Utils;
20 
21     /**
22      * The filename of the view that calls the plugin
23      *
24      * @var string
25      */
26     protected $viewFile,
27 
28     /**
29      * The data in the parent view that calls the plugin
30      *
31      * @var array
32      */
33     $viewData,
34 
35     /**
36      * The plugin instance parameters
37      *
38      * @var array
39      */
40     $params;
41 
42     /**
43      * Contructor
44      *
45      * @param string $viewFile The view file that instances this plugin
46      * @param array  $viewData The data injected in the view
47      * @param array  $params   The instance parameters
48      */
49     public function __construct($viewFile, $viewData = array(), $params = array()){
50         $this->viewFile = $viewFile;
51         $this->viewData = $viewData;
52 
53         if(isset($params['_attrs'])) {
54             $params = $params['_attrs'];
55         }
56 
57         $this->params = $params;
58         $this->map($params);
59     }
60 
61     /**
62      * Display the plugin. This abstract method must be overriden in each inherited class and return the HTML content corresponding to the instance
63      *
64      * @return string The HTML result to display
65      */
66     abstract public function display();
67 
68     /**
69      * Display the plugin. This abstract method must be overriden in each inherited class and return the HTML content corresponding to the instance
70      *
71      * @return string The HTML result to display
72      */
73     public function __toString(){
74         return $this->display();
75     }
76 }
77