PHP code example of phramz / doctrine-annotation-scanner

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

    

phramz / doctrine-annotation-scanner example snippets

 php


use Phramz\Doctrine\Annotation\Scanner\Finder;
use Doctrine\Common\Annotations\AnnotationReader;

$reader = new AnnotationReader(); // get an instance of the doctrine annotation reader
$finder = new Finder();
$finder->containsAtLeastOneOf('Phramz\Doctrine\Annotation\Fixtures\Annotations\Foo')
    ->containsAtLeastOneOf('Phramz\Doctrine\Annotation\Fixtures\Annotations\Bar')
    ->setReader($reader)
    ->in('/tests');

/** @var Symfony\Component\Finder\SplFileInfo $file */
foreach ($finder as $file) {
    echo "Found: " . $file->getFilename(); // will output for example "Found: AnnotatedClass.php"
}
 php


use Phramz\Doctrine\Annotation\Scanner\Scanner;
use Doctrine\Common\Annotations\AnnotationReader;

$reader = new AnnotationReader(); // get an instance of the doctrine annotation reader
$scanner = new Scanner($reader);

$scanner->scan(array(
        'Phramz\Doctrine\Annotation\Fixtures\Annotations\Foo',
        'Phramz\Doctrine\Annotation\Fixtures\Annotations\Bar'
    ))
    ->in('/tests');

/** @var Phramz\Doctrine\Annotation\Scanner\ClassFileInfo $file */
foreach ($scanner as $file) {
    echo "Found: " . $file->getFilename();    // will output for example "Found: AnnotatedClass.php"
    echo "Class: " . $file->getClassName();   // will output for example
                                              // "Class: Phramz\Annotation\AnnotatedClass"
    print_r($file->getClassAnnotations());    // will give you an array of all annotations
                                              // in the class-docblock
    print_r($file->getMethodAnnotations());   // will give you an array of all methods and
                                              // annotationss in the method-docblocks
    print_r($file->getPropertyAnnotations()); // will give you an array of all properties and
                                              // annotation in the method-docblocks
}