PHP code example of gabrielfs7 / annotation
1. Go to this page and download the library: Download gabrielfs7/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/ */
gabrielfs7 / annotation example snippets
namespace GSoares\Annotation\Sample;
/**
* @package GSoares\Annotation\Sample
* @myAnnotationBoolean(true)
* @myAnnotationString('String name')
* @myAnnotationString2(String name)
* @myAnnotationNumber(123)
* @myAnnotationNumber2(-123.84)
* @myAnnotationNumber3(123.456)
* @myAnnotationArray(
* [
* 'a' => 'b',
* 'c' => 'c',
* [
* 'd' => ['e', 'f']
* ]
* ]
* )
* @myAnnotationArray2(
* 'a' => 'b',
* 'c' => 'c',
* [
* 'd' => ['e', 'f']
* ]
* )
*/
class SampleClass
{
/**
* @myAnnotationBoolean(true)
* @myAnnotationString('String name')
* @myAnnotationString2(String name)
* @myAnnotationNumber(123)
* @myAnnotationNumber2(-123.84)
* @myAnnotationNumber3(123.456)
* @myAnnotationArray(
* [
* 'a' => 'b',
* 'c' => 'c',
* [
* 'd' => ['e', 'f']
* ]
* ]
* )
* @myAnnotationArray2(
* 'a' => 'b',
* 'c' => 'c',
* [
* 'd' => ['e', 'f']
* ]
* )
* @var teste
*/
private $mySampleProperty;
/**
* @myAnnotationBoolean(true)
* @myAnnotationString('String name')
* @myAnnotationString2(String name)
* @myAnnotationNumber(123)
* @myAnnotationNumber2(-123.84)
* @myAnnotationNumber3(123.456)
* @myAnnotationArray(
* [
* 'a' => 'b',
* 'c' => 'c',
* [
* 'd' => ['e', 'f']
* ]
* ]
* )
* @myAnnotationArray2(
* 'a' => 'b',
* 'c' => 'c',
* [
* 'd' => ['e', 'f']
* ]
* )
*/
public function mySampleMethod()
{
}
}
$reader = new GSoares\Annotation\Reader();
$annotationBag = $reader->readClass('GSoares\Annotation\Sample\SampleClass');
$annotationBag->get('myAnnotationBoolean'); //(boolean) true
$annotationBag->get('myAnnotationString'); //(string) String name
$annotationBag->get('myAnnotationString2'); //(string) String name
$annotationBag->get('myAnnotationNumber'); //(int) 123
$annotationBag->get('myAnnotationNumber2'); //(int) -123.84
$annotationBag->get('myAnnotationNumber3'); //(float) 123.456
$annotationBag->get('myAnnotationArray'); //(Array) ['a' => 'b', 'c' => 'c', ['d' => ['e', 'f']]]
$annotationBag->get('myAnnotationArray2'); //(Array) ['a' => 'b', 'c' => 'c', ['d' => ['e', 'f']]]
$reader = new GSoares\Annotation\Reader();
$annotationBag = $reader->readProperty(
'GSoares\Annotation\Sample\SampleClass',
'mySampleProperty'
);
$annotationBag->get('myAnnotationBoolean'); //(boolean) true
$annotationBag->get('myAnnotationString'); //(string) String name
$annotationBag->get('myAnnotationString2'); //(string) String name
$annotationBag->get('myAnnotationNumber'); //(int) 123
$annotationBag->get('myAnnotationNumber2'); //(int) -123.84
$annotationBag->get('myAnnotationNumber3'); //(float) 123.456
$annotationBag->get('myAnnotationArray'); //(Array) ['a' => 'b', 'c' => 'c', ['d' => ['e', 'f']]]
$annotationBag->get('myAnnotationArray2'); //(Array) ['a' => 'b', 'c' => 'c', ['d' => ['e', 'f']]]
$reader = new GSoares\Annotation\Reader();
$annotationBag = $reader->readMethod(
'GSoares\Annotation\Sample\SampleClass',
'mySampleMethod'
);
$annotationBag->get('myAnnotationBoolean'); //(boolean) true
$annotationBag->get('myAnnotationString'); //(string) String name
$annotationBag->get('myAnnotationString2'); //(string) String name
$annotationBag->get('myAnnotationNumber'); //(int) 123
$annotationBag->get('myAnnotationNumber2'); //(int) -123.84
$annotationBag->get('myAnnotationNumber3'); //(float) 123.456
$annotationBag->get('myAnnotationArray'); //(Array) ['a' => 'b', 'c' => 'c', ['d' => ['e', 'f']]]
$annotationBag->get('myAnnotationArray2'); //(Array) ['a' => 'b', 'c' => 'c', ['d' => ['e', 'f']]]