PHP code example of larachimp / pine-annotations

1. Go to this page and download the library: Download larachimp/pine-annotations 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/ */

    

larachimp / pine-annotations example snippets


'providers' => [
    ...
    LaraChimp\PineAnnotations\PineAnnotationsServiceProvider::class,
],

'aliases' => [
    ...
    'AnnotationsReader' => LaraChimp\PineAnnotations\Facades\Reader::class,
]

'autoload_files' => [
    app_path('Annotations/FooAnnotation.php'),
],

'autoload_namespaces' => [
    'App\Annotations',
],

// Adding files manually to the Registry.
AnnotationsReader::addFilesToRegistry($filesPaths);

// Adding namespaces manually to the Registry.
AnnotationsReader::addNamespacesToRegistry($namespaces);



use LaraChimp\PineAnnotations\Support\Reader\AnnotationsReader;

class MyService 
{
    /**
     * AnnotationsReader instance.
     * 
     * @var AnnotationsReader
     */
    protected $annotationsReader;
   
    /**
     * Constructor.
     * 
     * @var AnnotationsReader $annotationsReader
     */
    public function __construct(AnnotationsReader $annotationsReader) 
    {
        $this->annotationsReader = $annotationsReader;
    }
}

$annotationsReader = app(\LaraChimp\PineAnnotations\Support\Reader\AnnotationsReader::class);



/**
 * Class Baz.
 *
 * @FooAnnotation(bar="Percy")
 */
class Baz
{
    //
}

// Read all class annotations on class.
$annotations = AnnotationsReader::target('class')->read(Baz::class);

Illuminate\Support\Collection {
  #items: array:1 [
    0 => FooAnnotation {
      +bar: "Percy"
    }
  ]
}



/**
 * Class Baz.
 *
 * @FooAnnotation(bar="Percy")
 * @FooDoubleAnnotation(bar="Mamedy")
 */
class Baz
{
    //
}

// Read specific class annotations on class.
$annotations = AnnotationsReader::target('class')->only(FooDoubleAnnotation::class)->read(Baz::class);

Illuminate\Support\Collection {
  #items: array:1 [
    "bar" => "Mamedy"
  ]
}



class Baz
{
    /**
     * Name.
     *
     * @PropertyAnnotation(bar="Jeffrey")
     * @PropertyDoubleAnnotation(bar="Way")
     *
     * @var string
     */
    protected $name = '';
    
    //
}

// Read all class annotations on property.
$annotations = AnnotationsReader::target('property', 'name')->read(Baz::class);

Illuminate\Support\Collection {
  #items: array:2 [
    0 => PropertyAnnotation {
      +bar: "Jeffrey"
    }
    1 => PropertyDoubleAnnotation {
      +bar: "Way"
    }
  ]
}



class Baz
{
    /**
     * Name.
     *
     * @PropertyAnnotation(bar="Jeffrey")
     * @PropertyDoubleAnnotation(bar="Way")
     *
     * @var string
     */
    protected $name = '';
    
    //
}

// Read all class annotations on property.
$annotations = AnnotationsReader::target('property', 'name')->only(PropertyDoubleAnnotation::class)
                                                            ->read(Baz::class);

Illuminate\Support\Collection {
  #items: array:1 [
    "bar" => "Way"
  ]
}



class Baz
{  
    /**
     * Some method that does somethin.
     *
     * @MethodAnnotation(bar="Way")
     * @MethodDoubleAnnotation(bar="Otwell")
     *
     * @return string
     */
     public function someMethod()
     {
        return 'I did something.';
     }
}

// Read all class annotations on property.
$annotations = AnnotationsReader::target('method', 'someMethod')->read(Baz::class);

Illuminate\Support\Collection {
  #items: array:2 [
    0 => MethodAnnotation {
      +bar: "Way"
    }
    1 => MethodDoubleAnnotation {
      +bar: "Otwell"
    }
  ]
}



class Baz
{  
    /**
     * Some method that does somethin.
     *
     * @MethodAnnotation(bar="Way")
     * @MethodDoubleAnnotation(bar="Otwell")
     *
     * @return string
     */
     public function someMethod()
     {
        return 'I did something.';
     }
}

// Read all class annotations on property.
$annotations = AnnotationsReader::target('method', 'someMethod')->only(MethodDoubleAnnotation::class)
                                                                ->read(Baz::class);

Illuminate\Support\Collection {
  #items: array:1 [
    "bar" => "Otwell"
  ]
}
bash
$ php artisan vendor:publish
pine-annotations.php
pine-annotations.php
autoload_files