-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from kitsunet/gerrit-34903
FEATURE: Trait introduction via AOP This allows to introduce traits in generated proxy classes via AOP. You can use the Introduce annotation with the argument traitName to introdue the given trait into generated proxy classes matching the pointcut. For example:: @flow\Introduce( traitName="Vendor\Package\Service\Traits\ExampleTrait" pointcutExpression="class(TYPO3\Flow\Mvc\Controller\ActionController)" ) Would introduce the trait \Vendor\Package\Service\Traits\ExampleTrait into all proxies that either are the class or extend the class TYPO3\Flow\Mvc\Controller\ActionController. Resolves: FLOW-123
- Loading branch information
Showing
7 changed files
with
253 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
namespace TYPO3\Flow\Aop; | ||
|
||
/* | ||
* This file is part of the TYPO3.Flow package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
|
||
/** | ||
* Implementation of the trait introduction declaration. | ||
* | ||
*/ | ||
class TraitIntroduction | ||
{ | ||
/** | ||
* Name of the aspect declaring this introduction | ||
* @var string | ||
*/ | ||
protected $declaringAspectClassName; | ||
|
||
/** | ||
* Name of the introduced trait | ||
* @var string | ||
*/ | ||
protected $traitName; | ||
|
||
/** | ||
* The pointcut this introduction applies to | ||
* @var \TYPO3\Flow\Aop\Pointcut\Pointcut | ||
*/ | ||
protected $pointcut; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $declaringAspectClassName Name of the aspect containing the declaration for this introduction | ||
* @param string $traitName Name of the trait to introduce | ||
* @param \TYPO3\Flow\Aop\Pointcut\Pointcut $pointcut The pointcut for this introduction | ||
*/ | ||
public function __construct($declaringAspectClassName, $traitName, \TYPO3\Flow\Aop\Pointcut\Pointcut $pointcut) | ||
{ | ||
$this->declaringAspectClassName = $declaringAspectClassName; | ||
$this->traitName = $traitName; | ||
$this->pointcut = $pointcut; | ||
} | ||
|
||
/** | ||
* Returns the name of the introduced trait | ||
* | ||
* @return string Name of the introduced trait | ||
*/ | ||
public function getTraitName() | ||
{ | ||
return $this->traitName; | ||
} | ||
|
||
/** | ||
* Returns the pointcut this introduction applies to | ||
* | ||
* @return \TYPO3\Flow\Aop\Pointcut\Pointcut The pointcut | ||
*/ | ||
public function getPointcut() | ||
{ | ||
return $this->pointcut; | ||
} | ||
|
||
/** | ||
* Returns the object name of the aspect which declared this introduction | ||
* | ||
* @return string The aspect object name | ||
*/ | ||
public function getDeclaringAspectClassName() | ||
{ | ||
return $this->declaringAspectClassName; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
TYPO3.Flow/Tests/Functional/Aop/Fixtures/Introduced01Trait.php
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,34 @@ | ||
<?php | ||
namespace TYPO3\Flow\Tests\Functional\Aop\Fixtures; | ||
|
||
/* | ||
* This file is part of the TYPO3.Flow package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
/** | ||
* A trait which is introduced into TargetClass01 | ||
*/ | ||
trait Introduced01Trait | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function sayHello() | ||
{ | ||
return 'Hello from trait'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function introducedTraitMethod() | ||
{ | ||
return 'I\'m the traitor'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
TYPO3.Flow/Tests/Functional/Aop/Fixtures/TraitIntroductionTestingAspect.php
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,24 @@ | ||
<?php | ||
namespace TYPO3\Flow\Tests\Functional\Aop\Fixtures; | ||
|
||
/* | ||
* This file is part of the TYPO3.Flow package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use TYPO3\Flow\Annotations as Flow; | ||
|
||
/** | ||
* An aspect for testing trait introduction | ||
* | ||
* @Flow\Introduce("class(TYPO3\Flow\Tests\Functional\Aop\Fixtures\TargetClass01)", traitName="TYPO3\Flow\Tests\Functional\Aop\Fixtures\Introduced01Trait") | ||
* @Flow\Aspect | ||
*/ | ||
class TraitIntroductionTestingAspect | ||
{ | ||
} |
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