-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.php
More file actions
135 lines (121 loc) · 3.69 KB
/
Copy pathShape.php
File metadata and controls
135 lines (121 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class ShapeException extends Exception{}
class DataShape{
private $data_per_shape = [];
private $data = [];
private $shapes;
private $CI;
private $current;
public function __construct($data_per_shape, $global, $shapes, $current){
$this->data = $global;
$this->data_per_shape = $data_per_shape;
$this->shapes = $shapes;
$this->CI =& get_instance();
$this->current = $current;
}
public function _data($key){
if(isset($this->data[$key])){
return $this->data[$key];
} else {
$ea = false;
if(!isset($this->CI->config->config['shape-debug'])){
$ea = true;
} else {
if(!$this->CI->config->config['shape-debug']){
$ea=true;
}
}
if($ea) throw new ShapeException("<text> Data Global with key <strong>".$key."</strong> not exist You can disable this message with add 'shape-debug' True at config.php</text>");
}
}
public function data($key){
if(isset($this->data_per_shape[$this->current][$key])){
return $this->data_per_shape[$this->current][$key];
} else {
$ea = false;
if(!isset($this->CI->config->config['shape-debug'])){
$ea = true;
} else {
if(!$this->CI->config->config['shape-debug']){
$ea=true;
}
}
if($ea) throw new ShapeException("<text> Data Shape in ".$this->current." with key <strong>".$key."</strong> not exist. You can disable this message with add 'shape-debug' True at config.php</text>");
}
}
public function render($key, $debug=true){
if($key == $this->current){
$ea = false;
if(!isset($this->CI->config->config['shape-debug'])){
$ea = true;
} else {
if(!$this->CI->config->config['shape-debug']){
$ea=true;
}
}
if($ea) throw new ShapeException("<text> You can't render <strong>".$key."</strong> becase you are currently in this shape. You can disable this message with add 'shape-debug' True at config.php</text>");
return;
}
if(array_key_exists($key, $this->shapes)){
$test = clone($this);
$test->current = $key;
return $this->CI->load->view($this->shapes[$key], ['shape'=>$test], TRUE);
} else {
$ea = false;
if(!isset($this->CI->config->config['shape-debug'])){
$ea = true;
} else {
if(!$this->CI->config->config['shape-debug']){
$ea=true;
}
}
if($ea) throw new ShapeException("<text> Shape with key <strong>".$key."</strong> not exist. You can disable this message with add 'shape-debug' True at config.php</text>");
}
}
}
class Shape{
private $data_global;
private $data_shape;
private $shape;
private $key_extend;
private $extend;
private $CI;
public function __construct(){
$this->CI =& get_instance();
}
public function extend($key, $extend, $value){
$this->extend = $extend;
$this->key_extend = $key;
$this->addShape($key, $extend, $value);
return $this;
}
public function addShape($key, $url, $data=NULL){
$this->shape[$key] = $url;
if($data != NULL){
$this->setShapeData($key, $data);
}
return $this;
}
public function setGlobalData($value, $key = NULL){
if($key == NULL){
$this->data_global = $value;
} else {
$this->data_global[$key] = $value;
}
return $this;
}
public function setShapeData($shape, $value, $key = NULL){
if($key == NULL){
$this->data_shape[$shape] = $value;
} else {
$this->data_shape[$shape][$key] = $value;
}
return $this;
}
public function render($key=NULL, $extend=NULL, $value=NULL, $data = NULL){
$this->data_global = $data != NULL ? $data : $this->data_global;
$dataShape = new DataShape($this->data_shape, $this->data_global, $this->shape, $extend != NULL ? $key : $this->key_extend);
$this->CI->load->view($extend != NULL ? $extend : $this->extend, ['shape'=>$dataShape]);
}
}