Annotation parser
This component reads and extract information from your comment annotation in your PHP Class. This is simple and useful.
List of supported annotation:
- Route
- Service
- Hook
- Command
- Inject
- Expose
Use by the Router Service, this annotation declare a new route to your Controller method.
<?php
/**
* @Route('/notifications')
*/
public function getNotifications($request, $response)
{
return $this->container->getNotificationService()->getNotificationsByUser($this->authenticatedUserId);
}
This declare the route "/notifications" and will call getNotifications method.
To declare a Service, used by the Container:
<?php
namespace Kinou\Common\Service;
/**
* @Service('notification', 'configuration_node_name')
*/
class NotificationService
{
public function initialize($configuration)
{
}
}
This will create the Notification service, available on $this->container->getNotificationService(). The parameter configuration_node_name is optional.
To declare a Hook, used by the Hook Service:
<?php
namespace Kinou\Common\Service;
/**
* @Service('notification', 'configuration_node_name')
*/
class NotificationService
{
/**
* @Hook("ebuildy.request.ready")
*/
public function onRequestReady($data)
{
}
}
The method onRequestReady will be called when the Request will be ready.
To declare a Command, with its name.
<?php
namespace Kinou\Process\Command;
use eBuildy\Component\Command;
/**
* @Command("kinou:album:cover")
*/
class BuildAlbumCoverCommand extends Command
{
public function run($input, $output)
{
$albums = $this->container->getDataService()->find('SELECT id, cover_url FROM album');
foreach($albums as $album)
{
$res = $this->container->getTaskManagerService()->run('album.cover.build', array('album' => $album['id']));
var_dump($res);
echo PHP_EOL;
}
}
}
If you type "php ./console dev kinou:album:cover" this will call the run method.
To use inside a Service, this allows to "inject" a dependency.
<?php
namespace Kinou\Common\Service;
class NotificationService
{
/**
* @Inject("data")
*/
public $dataService;
/**
* @Inject("logger")
*/
public $loggerService;
}
This will produce the following method in the Container:
<?php
/**
* @return Kinou\Common\Service\NotificationService
*/
public function getNotificationService() {
if ($this->__notificationService === null) {
$this->__notificationService = new Kinou\Common\Service\NotificationService();
$this->__notificationService->container = $this;
$this->__notificationService->dataService = $this->getDataService();
$this->__notificationService->loggerService = $this->getLoggerService();
}
return $this->__notificationService;
}
Where "data" and "logger" are 2 other services.
Use for templating, this declare a Service method to be available for a template engine (PHP or Twig).
<?php
/**
* @Expose("getCss")
*/
public function css($source, $options = array())
{
return '<link href="' . $source. '" rel="stylesheet" type="text/css" />';
}
In PHP templating engine, you can call "$this->getCss" In Twig, just call {{ getCss() }}