-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The extension should be extensible by other extensions using IAspects…
…Provider
- Loading branch information
1 parent
48ba2ba
commit 1a502bf
Showing
4 changed files
with
190 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Kdyby (http://www.kdyby.org) | ||
* | ||
* Copyright (c) 2008 Filip Procházka ([email protected]) | ||
* | ||
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Aop\DI; | ||
|
||
use Kdyby; | ||
use Nette; | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
class AspectsConfig extends Nette\Object | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $aspectsList; | ||
|
||
/** | ||
* @var \Nette\DI\CompilerExtension | ||
*/ | ||
private $extension; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $prefix = TRUE; | ||
|
||
|
||
|
||
public function __construct(array $aspectsList, Nette\DI\CompilerExtension $extension) | ||
{ | ||
$this->aspectsList = $aspectsList; | ||
$this->extension = $extension; | ||
} | ||
|
||
|
||
|
||
public function disablePrefixing() | ||
{ | ||
$this->prefix = FALSE; | ||
|
||
return $this; | ||
} | ||
|
||
|
||
|
||
public function load(Nette\DI\Compiler $compiler, Nette\DI\ContainerBuilder $containerBuilder) | ||
{ | ||
$aspects = array(); | ||
foreach ($this->aspectsList as $def) { | ||
if (!is_array($def)) { | ||
if (!$def instanceof \stdClass || empty($def->entity)) { | ||
$serialised = Nette\Utils\Json::encode($def); | ||
throw new Kdyby\Aop\UnexpectedValueException("The service definition $serialised is expected to be an array or Neon entity."); | ||
} | ||
$def = array('factory' => $def); | ||
} | ||
$def['tags'][] = AopExtension::ASPECT_TAG; | ||
$aspects[] = $def; | ||
} | ||
|
||
$compiler->parseServices($containerBuilder, $aspects, $this->prefix ? substr($this->extension->prefix('self'), 0, -5) : NULL); | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Kdyby (http://www.kdyby.org) | ||
* | ||
* Copyright (c) 2008 Filip Procházka ([email protected]) | ||
* | ||
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kdyby\Aop\DI; | ||
|
||
use Kdyby; | ||
use Nette; | ||
|
||
|
||
|
||
/** | ||
* Implement this interface to your CompilerExtension if you want it to provide aspects. | ||
* | ||
* Example: | ||
* <code> | ||
* class AclExtension extends Nette\DI\CompilerExtension implements \Kdyby\Aop\DI\IAspectsProvider | ||
* { | ||
* public function getAspectsConfiguration() | ||
* { | ||
* return \Kdyby\Aop\DI\AopExtension::loadAspects(__DIR__ . '/aspects.neon', $this); | ||
* } | ||
* } | ||
* </code> | ||
* | ||
* The `aspects.neon` file should be list of unnamed services | ||
* | ||
* | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
interface IAspectsProvider | ||
{ | ||
|
||
/** | ||
* @return AspectsConfig | ||
*/ | ||
function getAspectsConfiguration(); | ||
|
||
} |
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 |
---|---|---|
|
@@ -29,3 +29,33 @@ class InvalidStateException extends \RuntimeException implements Exception | |
{ | ||
|
||
} | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
class InvalidArgumentException extends \InvalidArgumentException implements Exception | ||
{ | ||
|
||
} | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
class UnexpectedValueException extends \UnexpectedValueException | ||
{ | ||
|
||
} | ||
|
||
|
||
|
||
/** | ||
* @author Filip Procházka <[email protected]> | ||
*/ | ||
class InvalidAspectExceptions extends \LogicException implements Exception | ||
{ | ||
|
||
} |