Skip to content

Instantly share code, notes, and snippets.

@phalcon
Last active December 11, 2015 01:19
Show Gist options
  • Select an option

  • Save phalcon/4522325 to your computer and use it in GitHub Desktop.

Select an option

Save phalcon/4522325 to your computer and use it in GitHub Desktop.
RoutePrefix: /posts
Route: Array
(
[0] => /edit/{id}
[methods] => Array
(
[0] => GET
[1] => POST
)
[name] => edit-product
[paths] => Array
(
[module] => frontend
)
)
param
<?php
/**
* @RoutePrefix("/posts")
*/
class ProductsController
{
/**
* Edits a product
*
* @Route("/edit/{id}", methods={"GET", "POST"},
* name="edit-product", paths={module=frontend})
* @param int $id
*/
public function editAction($id)
{
}
}
//Create a memory annotations manager
$annotations = new Phalcon\Annotations\Adapter\Memory();
//Get the annotations refactor for ProductsController
$refactor = $annotations->get('ProductsController');
//Get the class' annotations
$annotations = $refactor->getClassAnnotations();
//Iterate over them
foreach ($annotations as $annotation) {
echo $annotation->getName(), ': ', join(', ', $annotation->getArguments()), PHP_EOL;
}
//Get the method's annotations
$annotations = $refactor->getMethodAnnotations();
//Iterate over them
foreach ($annotations as $method => $methodAnnotations) {
foreach ($methodAnnotations as $annotation) {
if ($annotation->numberArguments()) {
echo $annotation->getName(), ': ';
print_r($annotation->getArguments());
echo PHP_EOL;
} else {
echo $annotation->getName(), PHP_EOL;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment