-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The annotation reader is activated by config.
- Loading branch information
Showing
9 changed files
with
124 additions
and
55 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,64 @@ | ||
<?php | ||
|
||
namespace Jaxon\Di\Traits; | ||
|
||
use Jaxon\Annotations\AnnotationReader; | ||
use Jaxon\App\Config\ConfigEventManager; | ||
use Jaxon\App\Config\ConfigListenerInterface; | ||
use Jaxon\Plugin\AnnotationReaderInterface; | ||
use Jaxon\Utils\Config\Config; | ||
|
||
use function class_exists; | ||
|
||
trait AnnotationTrait | ||
{ | ||
/** | ||
* Register the values into the container | ||
* | ||
* @return void | ||
*/ | ||
private function registerAnnotations() | ||
{ | ||
// By default, register a fake annotation reader. | ||
$this->set(AnnotationReaderInterface::class, function() { | ||
return new class implements AnnotationReaderInterface | ||
{ | ||
public function getAttributes(string $sClass, array $aMethods): array | ||
{ | ||
return [false, [], []]; | ||
} | ||
}; | ||
}); | ||
|
||
if(class_exists(AnnotationReader::class)) | ||
{ | ||
$sEventListenerKey = AnnotationReader::class . '\\ConfigListener'; | ||
// The annotation package is installed, register the real annotation reader, | ||
// but only if the feature is activated in the config. | ||
$this->set($sEventListenerKey, function() { | ||
return new class implements ConfigListenerInterface | ||
{ | ||
public function onChanges(Config $xConfig) | ||
{ | ||
if($xConfig->getOption('core.annotations.on')) | ||
{ | ||
AnnotationReader::register(jaxon()->di()); | ||
} | ||
} | ||
|
||
public function onChange(Config $xConfig, string $sName) | ||
{ | ||
if($sName === 'core.annotations.on' && $xConfig->getOption('core.annotations.on')) | ||
{ | ||
AnnotationReader::register(jaxon()->di()); | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
// Register the event listener | ||
$xEventManager = $this->g(ConfigEventManager::class); | ||
$xEventManager->addListener($sEventListenerKey); | ||
} | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
return [ | ||
'core' => [ | ||
'prefix' => [ | ||
'class' => '', | ||
], | ||
'request' => [ | ||
'uri' => 'http://example.test/path', | ||
], | ||
'annotations' => [ | ||
'on' => true, | ||
], | ||
], | ||
]; |
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