PHP code example of larammerce / annotation-parser

1. Go to this page and download the library: Download larammerce/annotation-parser 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/ */

    

larammerce / annotation-parser example snippets




/**
 * Class FakerClassWithAnnotation
 * @role(enabled=true)
 * @package Larammerce\AnnotationParser\Tests\Faker
 */
class FakeClassWithAnnotation
{
    /**
     * @annotation(name="Ali", username="Ali".fake_helper_function(), roles=['salams', "ali goft: \"che khabar\""],
     *      another_attr=array(1, 2, 3), extras=["role_1" => "role_2"], some_special_id, manager, super_user,
     *      this.is.*="another hard system.")
     * @param string $param1
     * @param bool $param2
     * @return string
     */
    public function fakeMethodWithAnnotation($param1, $param2)
    {
        return "I am fake";
    }
}



function fake_helper_function()
{
    return "this is fake helper function";
}


use Larammerce\AnnotationParser\ReflectiveClass;
use Larammerce\AnnotationParser\ReflectiveMethod;
use Larammerce\AnnotationParser\Tests\Faker\FakeClassWithAnnotation;

        
$class_name = FakeClassWithAnnotation::class;
$function_name = "fakeMethodWithAnnotation";

$reflective_class = new ReflectiveClass($class_name); //construct the Reflective class.
$reflective_method = new ReflectiveMethod($class_name, $function_name); //construct the reflective method.


$reflective_class->getComment(); //returns the phpdoc on top of class.
$reflective_method->getComment(); //returns the phpdoc on top of method.

$reflective_class->getAnnotations(); //returns a list of annotations.
$reflective_class->hasAnnotation("specific_annotation"); //checks if specific annotations exists or not.
$reflective_class->getAnnotation(("specific_annotation")); //returns the specific annotation with passed title.