Расширение позволяет использовать кастомные аннотации для классов, свойств и методов(как в Java)
jppm add jphp-annotations-ext
namespace test\annotations;
class Route{
public $path;
private $methods = ['GET'];
public function getMethods(): array{
return $this->methods;
}
public function setMethods(array $methods){
$this->methods = $methods;
}
}
namespace test\controllers;
use test\annotations\Route;
class SampleController{
private $path;
/**
* @Route(path='/')
*/
public function index(): void{
echo "Hello, world!";
}
/**
* @Route(path='/about')
*/
public function about(): void{
echo "http://vk.com/dn_extension";
}
/**
* @Route(path='/login', methods=['GET', 'POST'])
*/
public function login(): void{
echo "he-he, not implemented :)";
}
}
use test\controllers\SampleController;
use test\annotations\Route;
use annotations\AnnotatedReflectionClass;
$class = new AnnotatedReflectionClass(SampleController::class);
foreach($class->getMethods() as $method){
/** @var Route $route */
$route = $class->getMethodAnnotationByClass($method->getName(), Route::class);
if($route){
echo "{$route->path} - ".str::join($route->getMethods(), ', ')."\n";
}
}
/ - GET
/about - GET
/login - GET, POST