Permalink
Browse files

Merge pull request #6 from EvolutionSDK/dev

Dev
  • Loading branch information...
KellyLSB committed Jun 26, 2012
2 parents 27ea995 + fa072e4 commit 29e159b00b4ecf027a77a8cb047629a4d986fdd6
View
@@ -97,7 +97,7 @@ require(EvolutionSDK . '/kernel/startup.php');
/**
* Use the evolution router
*/
-e::$router->route($_SERVER['REDIRECT_URL']);
+e::$router->__routeBundle($_SERVER['REDIRECT_URL']);
```
Then create `./runtime/environment.php` with the contents.
@@ -27,15 +27,15 @@ class Bundle {
public function _on_framework_loaded() {
if(isset($_GET['--docs'])) {
$this->root = '?--docs=';
- $this->route($_GET['--docs']);
+ $this->__routeBundle($_GET['--docs']);
}
}
/**
* Show documentation page
* @author Nate Ferrero
*/
- public function route($path) {
+ public function __routeBundle($path) {
/**
* Allow multiple routing methods
@@ -141,7 +141,7 @@ public function _require($var, $format = '/.+/', $why = 'Not Set', $new = false,
exit;
}
- public function route($path) {
+ public function __routeBundle($path) {
/**
* Security access for development
View
@@ -219,5 +219,19 @@ public function __call($event, $args) {
return $results;
}
+
+ public function __get($var) {
+ switch($var) {
+ case 'first':
+ case 'last':
+ case 'all':
+ case 'single':
+ return new Result($var);
+ break;
+ default:
+ throw new Exception('Trying to access event results with an invalid accessor.');
+ break;
+ }
+ }
}
@@ -0,0 +1,39 @@
+<?php
+
+namespace Bundles\Events;
+use Exception;
+use stack;
+use e;
+
+class Result {
+ private $type;
+ public function __construct($type) {
+ $this->type = $type;
+ }
+
+ public function __call($method, $args) {
+ $result = call_user_func_array(array(e::$events,$method), $args);
+ switch($this->type) {
+ case 'first':
+ if(empty($result))
+ return null;
+ return current($result);
+ break;
+ case 'last':
+ if(empty($result))
+ return null;
+ return end($result);
+ break;
+ case 'single':
+ if(empty($result))
+ return null;
+ elseif(count($result) > 1)
+ throw new Exception("You are running an event that only wants one result, multiple bundles are responding.");
+ return current($result);
+ break;
+ case 'all':
+ return $result;
+ break;
+ }
+ }
+}
@@ -13,7 +13,7 @@ public function _on_framework_loaded() {
e::configure('manage')->activeAddKey('bundle', __NAMESPACE__, 'manage');
}
- public function route($path) {
+ public function __routeBundle($path) {
/**
* Security access for development
View
@@ -35,7 +35,7 @@ public function __initBundle() {
* Router bundle access
*/
if(substr($url, 0, 2) == '/@')
- $this->route($url);
+ $this->__routeBundle($url);
}
public function domainSegment($id = 0) {
@@ -60,6 +60,10 @@ public function urlPath($id = 0) {
}
public function route($url, $special = false) {
+ return call_user_func_array(array($this, '__routeBundle'), func_get_args());
+ }
+
+ public function __routeBundle($url, $special = false) {
try {
$this->_route($url, $special);
} catch(Exception $e) {
@@ -184,12 +188,27 @@ public function route_bundle() {
switch($realm) {
case 'api':
+ /**
+ * Api Routing
+ */
$this->route_bundle_api($bundle, $path);
- break;
+ break;
default:
array_unshift($path, $realm);
- e::$$bundle->route($path, true);
- break;
+
+ /**
+ * Route Bundle
+ */
+ if(e::$$bundle->__method_exists('__routeBundle'))
+ e::$$bundle->__routeBundle($path, true);
+
+ /**
+ * Old Code
+ * @todo @KellyLSB @dbokovic Deprecate this
+ */
+ else if(e::$$bundle->__method_exists('route'))
+ e::$$bundle->route($path, true);
+ break;
}
throw new Exception("Bundle `@$bundle` routing did not complete");
@@ -112,7 +112,7 @@ public function getPOSTKey() {
return isset($_POST['e-developer-credentials']) ? explode('.', $_POST['e-developer-credentials'], 2) : null;
}
- public function route() {
+ public function __routeBundle() {
$key = $this->getPOSTKey();
if(!is_null($key)) {
$name = $key[0];
View
No changes.
Oops, something went wrong.

0 comments on commit 29e159b

Please sign in to comment.