0
* @author Jakob Heuser <jakob@felocity.org>
0
+define('CHIPPINO_LOCATION', dirname(__FILE__) . DIRECTORY_SEPARATOR);
0
+define('CHIPPINO_LIBRARY_LOCATION', CHIPPINO_LOCATION . 'library' . DIRECTORY_SEPARATOR . 'chippino' . DIRECTORY_SEPARATOR);
0
* Chippino initiator. used to create the chain
0
* @return Chippino_Dispatcher
0
function chip($file = NULL) {
0
$chip = new Chippino_Dispatcher();
0
+ $file = strtolower($file);
0
+ $backtrace = debug_backtrace();
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
+ $chip->setOrigin($origin);
0
+ // does file's last segment begin with _
0
+ if (strpos(substr($file, strrpos($file, '/') + 1), '_') !== 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
+ 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
+ $caller = dirname(str_replace($normalize, '', $chip->getFilePath()));
0
+ $callee = dirname(str_replace($normalize, '', $chip->getOrigin()));
0
+ if ($caller != $callee) {
0
+ throw new Chippino_Access_Exception($callee, $caller);
0
@@ -45,10 +84,12 @@ class Chippino_Dispatcher {
0
public function __construct() {
0
$this->as_singleton = FALSE;
0
$this->file_path = NULL;
0
+ $this->origin_path = NULL;
0
@@ -64,6 +105,14 @@ class Chippino_Dispatcher {
0
public function getSingleton() {
0
return ($this->as_singleton) ? $this->as_singleton : FALSE;
0
+ public function setOrigin($path) {
0
+ $this->origin_path = $path;
0
+ public function getOrigin() {
0
+ return $this->origin_path;
0
public function setPath($file = NULL) {
0
$this->file_path = $file;
0
@@ -140,6 +189,15 @@ class Chippino_Factory {
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
// default Chippino Config Values
0
chippino_config()->base_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
Comments
No one has commented yet.