Browse code

ViewEngine configs + viewFileExtension fix

Rafał Szklarczyk authored on 17/06/2019 12:33:37
Showing 1 changed files
... ...
@@ -10,7 +10,7 @@ class ViewEngine{
10 10
         $this->viewengines = array(); 
11 11
     }
12 12
 
13
-    public function register($fileExtension, $viewEngine){
13
+    public function register($fileExtension, $viewEngine, $config = null){
14 14
         if(!class_exists($viewEngine,true)){
15 15
             throw new \Exception("Class \"$viewEngine\" not found!");
16 16
         }
... ...
@@ -18,7 +18,9 @@ class ViewEngine{
18 18
             throw new \Exception("Class \"$viewEngine\" does not implement IViewEngine interface!");
19 19
         }
20 20
 
21
-        $this->viewengines[$fileExtension] = $viewEngine;
21
+        $vn = new ViewEngineInfo($fileExtension, $viewEngine, $config);
22
+
23
+        $this->viewengines[$fileExtension] = $vn;
22 24
     }
23 25
 
24 26
     public function get($fileExtension){
Browse code

namespace fixes in interface check

Rafał Szklarczyk authored on 12/06/2019 11:39:10
Showing 1 changed files
... ...
@@ -14,7 +14,7 @@ class ViewEngine{
14 14
         if(!class_exists($viewEngine,true)){
15 15
             throw new \Exception("Class \"$viewEngine\" not found!");
16 16
         }
17
-        if(!isset(class_implements($viewEngine, true)['IViewEngine'])){
17
+        if(!isset(class_implements($viewEngine, true)['elanpl\\L3\\IViewEngine'])){
18 18
             throw new \Exception("Class \"$viewEngine\" does not implement IViewEngine interface!");
19 19
         }
20 20
 
Browse code

ViewEngine check if registered class exists

Rafał Szklarczyk authored on 12/06/2019 11:32:30
Showing 1 changed files
... ...
@@ -11,6 +11,9 @@ class ViewEngine{
11 11
     }
12 12
 
13 13
     public function register($fileExtension, $viewEngine){
14
+        if(!class_exists($viewEngine,true)){
15
+            throw new \Exception("Class \"$viewEngine\" not found!");
16
+        }
14 17
         if(!isset(class_implements($viewEngine, true)['IViewEngine'])){
15 18
             throw new \Exception("Class \"$viewEngine\" does not implement IViewEngine interface!");
16 19
         }
Browse code

Serialization and ViewEngines basics

Rafał Szklarczyk authored on 06/06/2019 20:03:48
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,34 @@
1
+<?php
2
+
3
+namespace elanpl\L3;
4
+
5
+class ViewEngine{
6
+    protected $viewengines; //registered view engines dictionary
7
+
8
+    public function __construct()
9
+    {
10
+        $this->viewengines = array(); 
11
+    }
12
+
13
+    public function register($fileExtension, $viewEngine){
14
+        if(!isset(class_implements($viewEngine, true)['IViewEngine'])){
15
+            throw new \Exception("Class \"$viewEngine\" does not implement IViewEngine interface!");
16
+        }
17
+
18
+        $this->viewengines[$fileExtension] = $viewEngine;
19
+    }
20
+
21
+    public function get($fileExtension){
22
+        if(array_key_exists($fileExtension, $this->viewengines)){
23
+            return $this->viewengines[$fileExtension];
24
+        }
25
+        else{
26
+            return null;
27
+        }
28
+    }
29
+
30
+    public function getRegisteredFileExtensions(){
31
+        return array_keys($this->viewengines);
32
+    }
33
+
34
+}
0 35
\ No newline at end of file