protected function registerAspectClasses(ApplicationInterface $application)
{
// check directory for PHP files with classes we want to register
/** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */
$service = $application->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService');
// iterate over the directories and try to find aspects
$aspectDirectories = $service->globDir($this->getWebappPath() . DIRECTORY_SEPARATOR . '{WEB-INF,META-INF,common}' . DIRECTORY_SEPARATOR . 'classes', GLOB_BRACE);
foreach ($aspectDirectories as $aspectDirectory) {
// iterate all PHP files found in the directory
foreach ($service->globDir($aspectDirectory . DIRECTORY_SEPARATOR . '*.php') as $phpFile) {
try {
// cut off the META-INF directory and replace OS specific directory separators
$relativePathToPhpFile = str_replace(DIRECTORY_SEPARATOR, '\\', str_replace($aspectDirectory, '', $phpFile));
// now cut off the .php extension
$className = substr($relativePathToPhpFile, 0, -4);
// we need a reflection class to read the annotations
$reflectionClass = $this->getReflectionClass($className);
// if we found an aspect we have to register it using our aspect register class
if ($reflectionClass->hasAnnotation(AspectAnnotation::ANNOTATION)) {
$parser = new AspectParser($phpFile, new Config());
$this->aspectRegister->register($parser->getDefinition($reflectionClass->getShortName(), false));
}
// if class can not be reflected continue with next class
} catch (\Exception $e) {
// log an error message
$application->getInitialContext()->getSystemLogger()->error($e->__toString());
// proceed with the next class
continue;
}
}
}
}