Annotations Docblock Parser

Overview
Comments
  • Annotations 2.0

    Annotations 2.0

    • Move namespace to Doctrine\Annotations (Removing Common)
    • Uses hoa/compiler instead of doctrine/lexer ( see : grammar )
    • Drop AnnotationRegistry and all autoload magic
    • Drop Attribute/Attributes annotations
    • Drop SimpleAnnotationReader
    • Drop FileCacheReader
    • Drop IndexedReader
    • Requires php 7

    TODO:

    Local reviews (checkout + run locally):

    • [ ] @guilhermeblanco
    • [ ] @beberlei
    • [ ] @Hywan
    • [ ] @ocramius
    • [ ] @asm89
    • [ ] @deeky666
    • [ ] @alcaeus
    • [ ] run it against the doctrine/doctrine2 test-suite
    • [ ] run it against the doctrine/mongodb-odm test-suite
    opened by FabioBatSilva 31
  • PHP7 Grouped Use Statements ignored

    PHP7 Grouped Use Statements ignored

    When I use the new PHP7 grouped use statements feature, Doctrine doesn't use the namespace to import the annotation.

    For example, this works:

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
    
    class MyController
    {
    
        /**
         * @Route("/example")
         * @Method("GET")
         */     
        public function exampleAction() {...}
    
    }
    

    But changing the namespaces to this fails:

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\{
        Route, Method
    }
    

    I'm using Doctrine Annotations 1.2.7

    enhancement 
    opened by blowski 20
  • allow for dangling comma

    allow for dangling comma

    Drupal developers are much to used to the PHP array syntax which allows a dangling comma:

    array(
      'foo' => 'bar',
    );
    

    Doctrine doesn't allow for this and this causes a lot of grief. This PR fixes this. It seems {} arrays already support this.

    opened by chx 20
  • Annotation parameters

    Annotation parameters

    Don't know if I do not understand correctly how annotation parameters work, but given the following annotation definition:

    /**
     * Class Parameter
     *
     * @Annotation
     * @Target("METHOD")
     */
    class Parameter
    {
        /**
         * @var string
         */
        public $name;
    
        /**
         * @var array<Symfony\Component\Validator\Constraint>
         */
        public $constraints = array();
    
        /**
         * @var string
         */
        public $validationGroup;
    
        /**
         * @param array $data
         */
        public function __construct(array $data)
        {
            // constructor logic
        }
    }
    

    Why doesn't the following work:

    @Direct\Parameter("a", { @Assert\NotNull() }, "myGroup")
    

    I'm getting a Expected Value, got 'myGroup' at position 70 in method... exception.

    This however works:

    @Direct\Parameter("a", { @Assert\NotNull() }, validationGroup="myGroup")
    

    as does this:

    @Direct\Parameter(name="a", constraints={ @Assert\NotNull() }, validationGroup="myGroup")
    

    and this:

    @Direct\Parameter("a", { @Assert\NotNull() })
    
    bug 
    opened by sgehrig 17
  • Trigger the standard autoloader as the last resort

    Trigger the standard autoloader as the last resort

    As v2 isn't here yet, and looking at #232 it is unclear if it will be coming anytime soon, and as we have to put up with annoying deprecated functions, here I propose to fall back to the standard autoloader if nothing else worked, and if there's no custom loader defined.

    Fixes #270

    I intentionally did not add any tests as this is a PoC. Please tell me if this makes any sence, and then I'll make a try with tests.

    Improvement 
    opened by sanmai 16
  • opcache.load_comments has been removed from PHP 7

    opcache.load_comments has been removed from PHP 7

    When building a very fresh php7 version from source this morning, it appeared that one of my projects using doctrine/annotations didn't work anymore.

    It seems that the support of this option has been removed from php7, see https://github.com/php/php-src/commit/0a21a0c752a06d25704e04c15464700f75164849

    I don't know if this will be backported to php5.6 and/or 5.5 for the moment.

    This PR simply checks the php version before checking the value of opcache.load_comments.

    bug 
    opened by mpalourdio 16
  • Deprecate AnnotationRegistry in favor of class_exists()

    Deprecate AnnotationRegistry in favor of class_exists()

    See also: https://github.com/doctrine/common/issues/321

    Actually it looks like there is no benefit in using a separate autoloading mechanism, which itself only makes (manual) use of "real" autoloaders. Instead class_exists() serves the same purpose and prevents one from the need to manually add an autoloader for every loader, that should load annotations.

    This is especially interesting now, that composer took over most of the autoloading related issues in many projects.

    I don't know, which deprecation-rules apply here, so I just added the tag and kept the class as it is, but remove the use wherever useful.

    enhancement 
    opened by KingCrunch 14
  • optimized FileCacheReader

    optimized FileCacheReader

    In our project we strongly use annotations and almost 4000 cache file has been generated using FileCacheReader.

    In this implementation one cache file contains all related annotation for a class, which means huge reduction of file touching/writing/reading.

    As i see the access patterns of mongo odm, every method and property annotation will be read for a class, so this could be a performance upgrade too.

    enhancement wontfix 
    opened by tgabi333 14
  • Memory leak in AnnotationRegistry::registerLoader() when called multiple times

    Memory leak in AnnotationRegistry::registerLoader() when called multiple times

    If we call AnnotationRegistry::registerLoader() multiple times we've got an self::$loaders array growing indefinitely.

    Consider to append self::$loaders with a keyed value.

    A key for callable can be determined by spl_object_hash() for anonymous functions and by a combination of md5() and spl_object_hash() for other types of callable.

    I can provide a non BC breaking PR for this issue if interested.

    bug 
    opened by TriAnMan 13
  • DCOM-207: Add AnnotationReader::getFunctionAnnotations()

    DCOM-207: Add AnnotationReader::getFunctionAnnotations()

    From @doctrinebot on July 9, 2013 14:26

    Jira issue originally created by user benjamin:

    Currently, the annotation reader supports reading annotations on class, method and property. This could be extended to read annotations on any kind of function, by adding the following methods:

    public function getFunctionAnnotations(\ReflectionFunctionAbstract $function);
    public function getFunctionAnnotation(\ReflectionFunctionAbstract $function, $annotationName);
    

    This could be done without breaking BC in the following ways:

    • Keep the Reader interface as it is
    • Add a new interface, for example FullReader, that would extend Reader to add these two methods
    • Add the new methods to AnnotationReader, CachedReader, etc.
    • Update these classes to implement FullReader; thus they would still implement Reader and stay compatible.

    Then, on the next major release (3.0.0), we could:

    • Add the two methods to Reader
    • Remove FullReader
    • Add a note to the UPGRADE file to rename FullReader to Reader in application code.

    In case you're wondering why I'm proposing this feature, I'm developing a lightweight framework, which allows any method, function, or closure to be used as a controller. I can currently parse annotations when using a class method, but cannot provide support for annotations on the others.

    That would be a great addition. I've checked the code, and it looks like the only difficulty would be to parse "use" statements for the file where the function is declared, whereas for now it is always assumed that there is a class, and that the file name will be inferred from there. But as ReflectionFunctionAbstract provides a getFileName() method, it's technically feasible as well.

    Let me know what you think! If you have no objection to the concept, I can start working on a PR for this feature.

    Copied from original issue: doctrine/common#512

    New Feature 
    opened by guilhermeblanco 13
  • Fix token parsing on latest PHP 8 version, fixes #339

    Fix token parsing on latest PHP 8 version, fixes #339

    This fixes the failing tests from TokenParser on PHP 8.

    There are 10 left Failing tests. But it should be fixed by an PHPUnit Update

    PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
    
    .........................................................E....E  63 / 456 ( 13%)
    EEEEEEE........................................................ 126 / 456 ( 27%)
    ............................................................... 189 / 456 ( 41%)
    ............................................................... 252 / 456 ( 55%)
    ............................................................... 315 / 456 ( 69%)
    ......................................S........................ 378 / 456 ( 82%)
    ..................E.....................S...................... 441 / 456 ( 96%)
    ...............                                                 456 / 456 (100%)
    
    Time: 812 ms, Memory: 10.00 MB
    
    There were 10 errors:
    
    1) Doctrine\Tests\Common\Annotations\AnnotationRegistryTest::testRegisterLoaderIfNotExistsOnlyRegisteresSameLoaderOnce
    ParseError: syntax error, unexpected token "match", expecting variable
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/AnnotationRegistryTest.php:183
    
    2) Doctrine\Tests\Common\Annotations\CachedReaderTest::testIgnoresStaleCache
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:228
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:22
    
    3) Doctrine\Tests\Common\Annotations\CachedReaderTest::testIgnoresStaleCacheWithParentClass
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:228
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:34
    
    4) Doctrine\Tests\Common\Annotations\CachedReaderTest::testIgnoresStaleCacheWithTraits
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:228
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:46
    
    5) Doctrine\Tests\Common\Annotations\CachedReaderTest::testIgnoresStaleCacheWithTraitsThatUseOtherTraits
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:228
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:60
    
    6) Doctrine\Tests\Common\Annotations\CachedReaderTest::testIgnoresStaleCacheWithInterfacesThatExtendOtherInterfaces
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:228
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:76
    
    7) Doctrine\Tests\Common\Annotations\CachedReaderTest::testUsesFreshCacheWithTraitsThatUseOtherTraits
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:268
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:93
    
    8) Doctrine\Tests\Common\Annotations\CachedReaderTest::testPurgeLoadedAnnotations
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:228
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:109
    
    9) Doctrine\Tests\Common\Annotations\CachedReaderTest::testAvoidCallingFilemtimeTooMuch
    Method ReflectionParameter::getClass() is deprecated
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php:157
    
    10) Doctrine\Tests\Common\Annotations\PhpParserTest::testClassFileDoesNotExist
    Error: Call to undefined method ReflectionUnionType::getName()
    
    /var/www/html/annotations/tests/Doctrine/Tests/Common/Annotations/PhpParserTest.php:63
    
    ERRORS!
    Tests: 456, Assertions: 1049, Errors: 10, Skipped: 2.
    

    fixes #339

    opened by shyim 12
  • PsrCachedReader::fetchFromCache might return null instead of array under high request rate

    PsrCachedReader::fetchFromCache might return null instead of array under high request rate

    Hi everyone.

    We are fandom and very rare error request.CRITICAL: Uncaught PHP Exception TypeError: "Doctrine\Common\Annotations\PsrCachedReader::fetchFromCache(): Return value must be of type array, bool returned" at ...

    This usually happens on applications with the high request rate and some of such caches are empty. The working scenario - new code release which requires to flush caches in order to new changes took in place. When we debug the problem - it is appeared, when some of the requests hit that method and retrieve CacheItem, it has isHit property "true" but value "null". Obviously, we made sure nothing overrides this cache items with null values. Therefore we made conclusion this is "race condition" problem

    We tried different approaches as a hotfix:

    1. Allowing null values in this method doesn't work for us because it triggers error in some other vendor code
    2. Using CacheInterface::get instead of CacheItemPoolInterface makes hit rate better but not ideal and still got small % of errors during load testing
    3. The only working variant we had giving us 100% rate looks quite strange but anyway
            $cacheKey = rawurlencode($cacheKey);
    
            $item = $this->cache->getItem($cacheKey);
            $raceConditionHit = $item->isHit() && !\is_array($item->get());
    
            if (($this->debug && ! $this->refresh($cacheKey, $class)) || ! $item->isHit() || $raceConditionHit) {
                if ($raceConditionHit) {
                    usleep(100);
                }
                $this->cache->save($item->set($this->delegate->{$method}($reflector)));
            }
    
            return $item->get();
    

    We understand that problem is quite unique and the package is not actively maintained, but since this class is final, it is hard to override this code and it would be great to have working solution in one of the next releases.

    Thank you

    opened by dshatovskiy 6
  • Convert ini_get result to bool before evaluating

    Convert ini_get result to bool before evaluating

    ini_get returns a string, so checking === 0 won't work. Convert ini_get result to bool before evaluating. FILTER_VALIDATE_BOOLEAN will return true for ["1", "true", "on" and "yes"] and false for ["0", "false", "off" and "no"]

    bug 
    opened by 74656c 0
  • #186 check if file exists before asking for mtime

    #186 check if file exists before asking for mtime

    doctrine/annotations handles reading annotations from eval’ed code (as in mock objects) just fine, except that it attempts to determine the modification time via ReflectionClass::getFile() which will return the file and line where the eval() happened. This change adds fix and test for the PsrCachedReader and also fixes CachedReader but without a tests since it’s deprecated.

    Fixes #186

    opened by lstrojny 0
  • Add @type to ignored list

    Add @type to ignored list

    Protobuf protoc compiler generates classes with @type annotation, and parser throw exception on this annotation.

    Use case:

    Framework: Symfony Component: symfony/messenger

    Dispatch protobuf-generated message class through messenger and get exception on message validation step (when validator parse class through doctrine/annotation)

    bug 
    opened by max-petrovich 0
  • Add support for function annotations in PsrCachedReader.

    Add support for function annotations in PsrCachedReader.

    Working on a project which uses functions and I want to add annotations to the functions and have them cached. Am aware I could just create my own cached reader and do it that way, but thought it might be nice to have support in the library itself.

    One thing, I wasn't sure on is if it should throw an exception if attempt is made to call getFunctionAnnotations on the cached reader when the delegate doesn't support it (as it's not on the interface)? Any thoughts?

    New Feature 
    opened by jenkoian 0
Releases(2.0.0)
Owner
Doctrine
The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping.
Doctrine
Add scalar type hints and return types to existing PHP projects using PHPDoc annotations

PHPDoc to Type Hint Archived! This repository is now archived. Consider using PHP CS Fixer (and especially the phpdoc_to_param_type and phpdoc_to_retu

Kévin Dunglas 228 May 22, 2022
SilverStripe Model Annotations Task

A SilverStripe Task to generate data object model annotations for defined db fields. Also for configs from data extensions.

CSoellinger 2 Apr 21, 2022
A proof-of-concept parser for the SMART Health Cards format.

SMART Health Cards parser A proof-of-concept parser for the SMART Health Cards format. This is not intended for production use. I just hacked this tog

Mikkel Paulson 55 Jul 31, 2022
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.

Parsica The easiest way to build robust parsers in PHP. composer require parsica-php/parsica Documentation & API: parsica-php.github.io <?php $parser

null 350 Dec 27, 2022
PHP Simple M3U Parser, it clean the playlist and remove duplicate

SimpleM3UParser PHP Simple M3U Playlist Parser, it clean, remove duplicate, and group the playlist. Usage see example.php <?php require_once "M3UPars

erwin solihin 3 May 30, 2022
uaDetect – A multi-language port of Browserscope's user agent parser

uaDetect is a lightweight for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

Fadjrir Herlambang 1 Jan 7, 2022
Referer-parser PHP library

referer-parser PHP library This is the PHP implementation of referer-parser, the library for extracting search marketing data from referer (sic) URLs.

null 4 Sep 3, 2022
Golang 1.18 parser written in PHP 8.1

GoParser Golang (1.18) parser written in PHP 8.1 Installation To install this package, run: composer require tuqqu/go-parser Example $parser = new \G

Arthur Kurbidaev 37 Nov 2, 2022
A PHP parser written in PHP

PHP Parser This is a PHP 5.2 to PHP 8.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation. Documentation for ver

Nikita Popov 15.9k Jan 8, 2023
JsonCollectionParser - Event-based parser for large JSON collections (consumes small amount of memory)

Event-based parser for large JSON collections (consumes small amount of memory). Built on top of JSON Streaming Parser This packa

Max Grigorian 113 Dec 6, 2022
Lightning Fast, Minimalist PHP User Agent String Parser.

Lightning Fast, Minimalist PHP User Agent String Parser.

Jesse Donat 523 Dec 21, 2022
A PHP package for MRZ (Machine Readable Zones) code parser for Passport, Visa & Travel Document (TD1 & TD2).

MRZ (Machine Readable Zones) Parser for PHP A PHP package for MRZ (Machine Readable Zones) code parser for Passport, Visa & Travel Document (TD1 & TD2

Md. Rakibul Islam 25 Aug 24, 2022
MySQL parser for free-id/core package

MySQL parser Installation You can install the package via composer: composer require free-id/mysql Usage use FreeId\Mysql\Parser; $parser = new Parse

Free ID 0 Jul 27, 2022
Documentation generator for PHP Code using standard technology (SRC, DOCBLOCK, XML and XSLT)

phpDox phpDox is a documentation generator for PHP projects. This includes, but is not limited to, API documentation. The main focus is on enriching t

Arne Blankerts 588 Dec 22, 2022
Simplifies writing DocBlock comments in Javascript, PHP, CoffeeScript, Actionscript, C & C++

DocBlockr DocBlockr is a package for Sublime Text 2 & 3 which makes writing documentation a breeze. DocBlockr supports JavaScript (including ES6), PHP

Nick Fisher 3.1k Nov 25, 2022
phpDocumentor is an application that is capable of analyzing your PHP source code and DocBlock comments to generate a complete set of API Documentation

phpDocumentor What is phpDocumentor? phpDocumentor is an application that is capable of analyzing your PHP source code and DocBlock comments to genera

phpDocumentor 3.7k Jan 3, 2023
DBML parser for PHP8. It's a PHP parser for DBML syntax.

DBML parser written on PHP8 DBML (database markup language) is a simple, readable DSL language designed to define database structures. This page outli

Pavel Buchnev 32 Dec 29, 2022
php html parser,类似与PHP Simple HTML DOM Parser,但是比它快好几倍

HtmlParser php html解析工具,类似与PHP Simple HTML DOM Parser。 由于基于php模块dom,所以在解析html时的效率比 PHP Simple HTML DOM Parser 快好几倍。 注意:html代码必须是utf-8编码字符,如果不是请转成utf-8

俊杰jerry 522 Dec 29, 2022
Quickly and easily expose Doctrine entities as REST resource endpoints with the use of simple configuration with annotations, yaml, json or a PHP array.

Drest Dress up doctrine entities and expose them as REST resources This library allows you to quickly annotate your doctrine entities into restful res

Lee Davis 88 Nov 5, 2022
Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.

DMS Filter Component This library provides a service that can be used to filter object values based on annotations Install Use composer to add DMS\Fil

Rafael Dohms 89 Nov 28, 2022