Skip to content

Commit

Permalink
Merge pull request #33 from lisachenko/refactoring
Browse files Browse the repository at this point in the history
Refactoring of className property for invocations, some cleaning and improvements
  • Loading branch information
lisachenko committed Jan 19, 2013
2 parents 0bb2c82 + 8f74206 commit 3ba1fd8
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 230 deletions.
139 changes: 0 additions & 139 deletions src/Go/Aop/Framework/AbstractConstructorInvocation.php

This file was deleted.

23 changes: 17 additions & 6 deletions src/Go/Aop/Framework/AbstractJoinpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@
*/
abstract class AbstractJoinpoint implements Joinpoint
{
/** @var array|Advice[] */
/**
* List of advices
*
* @var array|Advice[]
*/
protected $advices = array();

/**
* Initializes list of advices for current joinpoint
* Name of the invocation class
*
* @param array $advices
* @var string
*/
protected $className = '';

/**
* Initializes list of advices for current joinpoint
*
* @return AbstractJoinpoint
* @param string $className Name of the class
* @param array $advices List of advices
*/
protected function __construct(array $advices)
protected function __construct($className, array $advices)
{
$this->advices = static::sortAdvices($advices);
$this->className = $className;
$this->advices = static::sortAdvices($advices);
}

/**
Expand Down
17 changes: 4 additions & 13 deletions src/Go/Aop/Framework/AbstractMethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ abstract class AbstractMethodInvocation extends AbstractInvocation implements Me
*/
protected $instance = null;

/**
* Name of the parent class
*
* @var string
*/
protected $parentClass = '';

/**
* Instance of reflection method for class
*
Expand All @@ -46,21 +39,19 @@ abstract class AbstractMethodInvocation extends AbstractInvocation implements Me
/**
* Constructor for method invocation
*
* @param string|object $classNameOrObject Class name or object instance
* @param string $className Class name
* @param string $methodName Method to invoke
* @param $advices array List of advices for this invocation
*/
public function __construct($classNameOrObject, $methodName, array $advices)
public function __construct($className, $methodName, array $advices)
{
$this->parentClass = get_parent_class($classNameOrObject);
$this->reflectionMethod = $method = new ReflectionMethod($this->parentClass, $methodName);
parent::__construct($className, $advices);
$this->reflectionMethod = $method = new ReflectionMethod($this->className, $methodName);

// Give an access to call protected method
if ($method->isProtected()) {
$method->setAccessible(true);
}

parent::__construct($advices);
}

/**
Expand Down
18 changes: 5 additions & 13 deletions src/Go/Aop/Framework/ClassFieldAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ class ClassFieldAccess extends AbstractJoinpoint implements FieldAccess
self::WRITE => 'set'
);

/**
* Name of the class
*
* @var object|string
*/
protected $classOrObject = null;

/**
* Name of the field
*
Expand Down Expand Up @@ -81,15 +74,14 @@ class ClassFieldAccess extends AbstractJoinpoint implements FieldAccess
/**
* Constructor for field access
*
* @param string|object $classNameOrObject Class name or object instance
* @param string $className Class name
* @param string $fieldName Field name
* @param $advices array List of advices for this invocation
*/
public function __construct($classNameOrObject, $fieldName, array $advices)
public function __construct($className, $fieldName, array $advices)
{
$this->classOrObject = $classNameOrObject;
$this->fieldName = $fieldName;
parent::__construct($advices);
parent::__construct($className, $advices);
$this->fieldName = $fieldName;
}

/**
Expand All @@ -113,7 +105,7 @@ public function getAccessType()
public function getField()
{
if (!$this->reflectionProperty) {
$this->reflectionProperty = new ReflectionProperty($this->classOrObject, $this->fieldName);
$this->reflectionProperty = new ReflectionProperty($this->className, $this->fieldName);
// Give an access to protected field
if ($this->reflectionProperty->isProtected()) {
$this->reflectionProperty->setAccessible(true);
Expand Down
18 changes: 1 addition & 17 deletions src/Go/Aop/Framework/ClosureDynamicMethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ class ClosureDynamicMethodInvocation extends AbstractMethodInvocation
*/
private $previousInstance = null;

/**
* Shortcut for ReflectionMethod->name
*
* @var string
*/
private $methodName = '';

/**
* {@inheritdoc}
*/
public function __construct($classNameOrObject, $methodName, array $advices)
{
parent::__construct($classNameOrObject, $methodName, $advices);
$this->methodName = $methodName;
}

/**
* Invokes original method and return result from it
*
Expand All @@ -67,7 +51,7 @@ public function proceed()

// Rebind the closure if instance was changed since last time
if ($this->previousInstance !== $this->instance) {
$this->closureToCall = $this->closureToCall->bindTo($this->instance, $this->parentClass);
$this->closureToCall = $this->closureToCall->bindTo($this->instance, $this->className);
$this->previousInstance = $this->instance;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Go/Aop/Framework/ClosureStaticMethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class ClosureStaticMethodInvocation extends AbstractMethodInvocation
/**
* {@inheritdoc}
*/
public function __construct($classNameOrObject, $methodName, array $advices)
public function __construct($className, $methodName, array $advices)
{
parent::__construct($classNameOrObject, $methodName, $advices);
$this->closureToCall = $this->getStaticInvoker($this->parentClass, $methodName);
parent::__construct($className, $methodName, $advices);
$this->closureToCall = $this->getStaticInvoker($this->className, $methodName);
}

/**
Expand Down Expand Up @@ -68,15 +68,15 @@ public function proceed()
/**
* Returns static method invoker
*
* @param string $parent Parent class name to forward request
* @param string $className Class name to forward request
* @param string $method Method name to call
*
* @return callable
* @return \Closure
*/
protected static function getStaticInvoker($parent, $method)
protected static function getStaticInvoker($className, $method)
{
return function (array $args) use ($parent, $method) {
return forward_static_call_array(array($parent, $method), $args);
return function (array $args) use ($className, $method) {
return forward_static_call_array(array($className, $method), $args);
};
}
}
Loading

0 comments on commit 3ba1fd8

Please sign in to comment.