Skip to content

Commit

Permalink
Changes made.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Boskovic committed Jun 25, 2012
1 parent 1de176c commit fa072e4
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 119 deletions.
14 changes: 14 additions & 0 deletions bundles/events/_bundle.php
Expand Up @@ -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;
}
}

}
39 changes: 39 additions & 0 deletions bundles/events/library/result.php
@@ -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;
}
}
}

0 comments on commit fa072e4

Please sign in to comment.