public
Description: A lightweight MVC framework on top of Grok-PHP
Homepage: http://chippino.googlecode.com
Clone URL: git://github.com/Jakobo/chippino.git
added privlaged / protected support through items starting with _

Signed-off-by: Jakob Heuser <jakob@felocity.org>
Jakobo (author)
Fri Jul 04 09:36:53 -0700 2008
commit  c9650b37ef9ba2d0a2bbb3c2b5cc3f5e4ee29724
tree    2e3e1e9a10d8f6a2fd4f5e35ddcbd474116871d4
parent  06763113b720075f892460c584a5a8255d3f2379
...
5
6
7
 
 
 
8
9
10
...
12
13
14
 
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
19
...
45
46
47
 
48
49
50
51
 
52
53
54
...
64
65
66
 
 
 
 
 
 
 
 
67
68
69
...
140
141
142
 
 
 
 
 
 
 
 
 
143
144
145
...
5
6
7
8
9
10
11
12
13
...
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
...
84
85
86
87
88
89
90
91
92
93
94
95
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
0
@@ -5,6 +5,9 @@
0
  * @author Jakob Heuser <jakob@felocity.org>
0
  */
0
 
0
+define('CHIPPINO_LOCATION', dirname(__FILE__) . DIRECTORY_SEPARATOR);
0
+define('CHIPPINO_LIBRARY_LOCATION', CHIPPINO_LOCATION . 'library' . DIRECTORY_SEPARATOR . 'chippino' . DIRECTORY_SEPARATOR);
0
+
0
 /**
0
  * Chippino initiator. used to create the chain
0
  * @return Chippino_Dispatcher
0
@@ -12,8 +15,44 @@
0
  **/
0
 function chip($file = NULL) {
0
     $chip = new Chippino_Dispatcher();
0
+ $file = strtolower($file);
0
     $chip->setPath($file);
0
- return $chip;
0
+
0
+ $backtrace = debug_backtrace();
0
+
0
+ // find a valid file
0
+ foreach ($backtrace as $bk => $trace) {
0
+ $origin = $trace['file'];
0
+ if (strpos($origin, 'chippino.php') !== FALSE || strpos($origin, 'chippino_core.php') !== FALSE || strpos($origin, 'grok.php') !== FALSE) {
0
+ continue;
0
+ }
0
+ $chip->setOrigin($origin);
0
+ break;
0
+ }
0
+
0
+ // does file's last segment begin with _
0
+ if (strpos(substr($file, strrpos($file, '/') + 1), '_') !== 0) {
0
+ return $chip;
0
+ }
0
+
0
+ // check access, must be same dir. Start by removing all absolute path matches
0
+ // that could happen when people symlink. This shouldn't cause problems for
0
+ // anyone, but anything is possible.
0
+ $normalize = array(
0
+ CHIPPINO_LIBRARY_LOCATION,
0
+ strtolower(CHIPPINO_LIBRARY_LOCATION),
0
+ chippino_config()->base_path . 'chippino' . DIRECTORY_SEPARATOR,
0
+ strtolower(chippino_config()->base_path . 'chippino' . DIRECTORY_SEPARATOR),
0
+ );
0
+
0
+ $caller = dirname(str_replace($normalize, '', $chip->getFilePath()));
0
+ $callee = dirname(str_replace($normalize, '', $chip->getOrigin()));
0
+
0
+ if ($caller != $callee) {
0
+ throw new Chippino_Access_Exception($callee, $caller);
0
+ }
0
+
0
+ return $chip;
0
 }
0
 
0
 /**
0
@@ -45,10 +84,12 @@ class Chippino_Dispatcher {
0
   
0
   private $as_singleton;
0
   private $file_path;
0
+ private $origin_path;
0
   
0
   public function __construct() {
0
     $this->as_singleton = FALSE;
0
     $this->file_path = NULL;
0
+ $this->origin_path = NULL;
0
   }
0
   
0
     /**
0
@@ -64,6 +105,14 @@ class Chippino_Dispatcher {
0
   public function getSingleton() {
0
     return ($this->as_singleton) ? $this->as_singleton : FALSE;
0
   }
0
+
0
+ public function setOrigin($path) {
0
+ $this->origin_path = $path;
0
+ }
0
+
0
+ public function getOrigin() {
0
+ return $this->origin_path;
0
+ }
0
 
0
   public function setPath($file = NULL) {
0
     $this->file_path = $file;
0
@@ -140,6 +189,15 @@ class Chippino_Factory {
0
     }
0
 }
0
 
0
+class Chippino_Access_Exception extends Exception {
0
+ public function __construct($caller, $callee) {
0
+ // strip base path from both
0
+ $caller = strtolower(str_replace(array(chippino_config()->base_path, '.php'), '', $caller));
0
+ $callee = strtolower(str_replace(array(chippino_config()->base_path, '.php'), '', $callee));
0
+ parent::__construct('Access error: Attempt to call '.$caller.' from '.$callee);
0
+ }
0
+}
0
+
0
 
0
 // default Chippino Config Values
0
 chippino_config()->base_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;

Comments

    No one has commented yet.