PHP code example of jmacedo / php-simple-annotation
1. Go to this page and download the library: Download jmacedo/php-simple-annotation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jmacedo / php-simple-annotation example snippets
namespace Examples;
/**
* Class MyAnnotatedClass
*
* @package Examples
* @metadata {"PI": 3.14, "name": "The name", "genre": "The genre", "age": "The age"}
* @PI 3.14
* @list ['item 1', 'item 2', 'item 3']
* @uselessClass true
*/
class MyAnnotatedClass
{
/**
* @value 3.14
* @var double
* @description Math constant
*/
const PI = 3.14;
/** @var string */
public $name;
/** @var string */
protected $genre;
/** @var int */
private $age;
/**
* MyAnnotatedClass constructor.
*
* @param string $name
* @param string $genre
* @param int $age
*/
public function __construct(string $name = '', string $genre = '', int $age = 0)
{
$this->name = $name;
$this->genre = $genre;
$this->age = $age;
}
/**
* A method that says "Hello!".
*
* @methodName sayHello
* @emptyAnnotation
*/
public function sayHello()
{
echo 'Hello!';
}
}
use SimpleAnnotation\Annotation;
use Examples\MyAnnotatedClass;
$annotation = new Annotation(MyAnnotatedClass::class);
// Or
$annotation = new Annotation('Examples\MyAnnotatedClass');
use SimpleAnnotation\Annotation;
use Examples\MyAnnotatedClass;
$myAnnotatedClass = new MyAnnotatedClass();
$annotation = new Annotation($myAnnotatedClass);