Skip to content

Commit

Permalink
eigenclass stores object reference
Browse files Browse the repository at this point in the history
  • Loading branch information
shuber committed Mar 1, 2011
1 parent c5bfd14 commit c596621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/eigenclass.php
Expand Up @@ -2,9 +2,11 @@

class Eigenclass extends Klass {

function __construct($class) {
if (is_object($class)) $class = get_class($class);
parent::__construct($class, null, false);
protected $_object;

function __construct(&$object) {
$this->_object = $object;
parent::__construct(get_class($object), null, false);
}

function __include($modules, $instance = false) {
Expand All @@ -23,6 +25,10 @@ function callee($method, &$caller = null) {
}
}

function object() {
return $this->_object;
}

function reference() {
return parent::instance($this->_name);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/eigenclass_test.php
Expand Up @@ -47,8 +47,8 @@ function test_should_return_class_reference() {
assert_identical($this->user_class, $this->user->__class()->reference());
}

function test_should_not_create_class() {
assert_throws('InvalidArgumentException', function() { new Eigenclass('InvalidClass'); });
function test_should_return_object() {
assert_identical($this->user_class, $this->user_class->__class()->object());
}

}
Expand Down

0 comments on commit c596621

Please sign in to comment.