Hi,
I'm trying to use annotations on an Mvc\Micro
app, but getClassAnnotations()
always return me False
.
Are the annotation working also with Mvc\Micro
or do I have to use Mvc\Application
?
My current testing code is:
// Loading Configs
$config = require__DIR__.'/../app/config/config.php';
// Autoloading classes
require __DIR__.'/../app/config/loader.php';
// Initializing DI container
/** @var \Phalcon\DI\FactoryDefault $di */
$di = require __DIR__.'/../app/config/di.php';
// Initializing application
$app = new \Phalcon\Mvc\Micro();
// Setting DI container
$app->setDI($di);
// Setting up routing
require __DIR__.'/../app/config/routes.php';
// TEST Annotations
$reader = new MemoryAdapter();
$reflector = $reader->get(\App\Controllers\UsersController::class);
$annotations = $reflector->getClassAnnotations();
echo gettype($annotations);
print_r($annotations);
// Traverse the annotations
foreach ($annotations as $annotation) {
// Print the annotation name
echo $annotation->getName(), PHP_EOL;
// Print the number of arguments
echo $annotation->numberArguments(), PHP_EOL;
// Print the arguments
print_r($annotation->getArguments());
}
// Processing request
$app->handle();
[...]
Excerpt of \App\Controllers\UsersController::class
/**
* Returns user list
*
* @return array
*
* @Authentication(true)
*/
public function getUserListAction()
{
try {
$userList = $this->usersService->getUserList();
} catch (ServiceException $e) {
throw new Http500Exception(_('Internal Server Error'), $e->getCode(), $e);
}
return $userList;
}
Which results as:
boolean
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in
<b>/var/www/public/index.php</b> on line
<b>61</b>
<br />
I expect to see a key for Authentication
.
Thanks Kumy
PS: I'm using Phalcon 3.2.1