-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.x'
* origin/1.x: Fix spacing Rewrote property interceptors to be by reference and use trait for general logic, resolves #54, #232
- Loading branch information
Showing
6 changed files
with
178 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/* | ||
* Go! AOP framework | ||
* | ||
* @copyright Copyright 2016, Lisachenko Alexander <[email protected]> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\Proxy; | ||
|
||
use Go\Aop\Framework\ClassFieldAccess; | ||
use Go\Aop\Intercept\FieldAccess; | ||
|
||
/** | ||
* Trait that holds all general logic for working with intercepted properties | ||
*/ | ||
trait PropertyInterceptionTrait | ||
{ | ||
/** | ||
* Holds a collection of current values for intercepted properties | ||
* | ||
* @var array | ||
*/ | ||
private $__properties = []; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function &__get($name) | ||
{ | ||
if (\array_key_exists($name, $this->__properties)) { | ||
/** @var ClassFieldAccess $fieldAccess */ | ||
$fieldAccess = self::$__joinPoints["prop:$name"]; | ||
$fieldAccess->ensureScopeRule(); | ||
|
||
$value = &$fieldAccess->__invoke($this, FieldAccess::READ, $this->__properties[$name]); | ||
} elseif (\method_exists(\get_parent_class(), __FUNCTION__)) { | ||
$value = parent::__get($name); | ||
} else { | ||
trigger_error("Trying to access undeclared property {$name}"); | ||
|
||
$value = null; | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __set($name, $value) | ||
{ | ||
if (\array_key_exists($name, $this->__properties)) { | ||
/** @var ClassFieldAccess $fieldAccess */ | ||
$fieldAccess = self::$__joinPoints["prop:$name"]; | ||
$fieldAccess->ensureScopeRule(); | ||
|
||
$this->__properties[$name] = $fieldAccess->__invoke( | ||
$this, | ||
FieldAccess::WRITE, | ||
$this->__properties[$name], | ||
$value | ||
); | ||
} elseif (\method_exists(\get_parent_class(), __FUNCTION__)) { | ||
parent::__set($name, $value); | ||
} else { | ||
$this->$name = $value; | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __isset($name) | ||
{ | ||
return isset($this->__properties[$name]); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __unset($name) | ||
{ | ||
$this->__properties[$name] = null; | ||
} | ||
} |