Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Feature/doctrine annotations#1681

Merged
akrabat merged 12 commits into
zendframework:masterfrom
weierophinney:feature/doctrine-annotations
Jun 30, 2012
Merged

Feature/doctrine annotations#1681
akrabat merged 12 commits into
zendframework:masterfrom
weierophinney:feature/doctrine-annotations

Conversation

@weierophinney

Copy link
Copy Markdown
Member

This PR does several things:

  • Introduces a dependency on doctrine/common for Zend\Code\Annotation
  • Refactors Zend\Code\Annotation to create an AnnotationManager that can attach many annotation parsers.
  • Introduces a DoctrineAnnotationParser that delegates to Doctrine\Common\Annotations\DocParser in order to parse and return an annotation
  • Introduces GenericAnnotationParser, which handles annotations as was done previously in ZF2
  • Refactors Zend\Code and Zend\Form to follow the new annotation manager changes.

- Added doctrine/common dependency to composer.json
- Updated travis configuration to ensure dependencies from composer are
  installed before running tests (suggested by ocramius)
- Modified test autoloader to use composer + StandardAutoloader
- Listener that receives an event with:
  - class
  - content
  - raw
- If class is registered with this parser, passes the raw string to the
  Doctrine\Common DocParser in order to retrieve an annotation object
- AnnotationManager now:
  - Composes an EventManager
  - createAnnotation() triggers the createAnnotation event, passing an
    event with "class", "content", and "raw" parameters representing the
    annotation requested. First listener to return an object halts the
    event, and that object is returned.
- AnnotationScanner adds a third element to the $annotation array
  representing the "raw" annotation. This array is then passed to
  createAnnotation(), and if a non-false value is returned, appended to
  the collection.
- Added GenericAnnotationParser, which operates in the style originally
  posited by Ralph.
- Created ParserInterface
  - defines onCreateAnnotation(), registerAnnotation(), and
    registerAnnotations()
  - refactored GenericAnnotationParser and DoctrineAnnotationParser to
    follow above interface; removed constructor from
    GenericAnnotationParser, and made registerAnnotation accept string
    class names.
- Added attach() method to AnnotationManager; allows attaching a parser
  instance to the createAnnotation event.
- Added tests for GenericAnnotationParser and DoctrineAnnotationParser
- Modified AnnotationManager tests to test a mixed annotation situation
- Discovered an issue with DoctrineAnnotationParser; needed to provide a
  loader to AnnotationRegistry that attempts to autoload an annotation
  class in order for the functionality to work with namespaced
  annotation classes.
- Modified setAnnotationManager() to create a DoctrineAnnotationParser
  instance and seed it with the ZF form annotation classes
- Removed AbstractAnnotation
- Created AbstractStringAnnotation and AbstractArrayAnnotation to handle
  basic validation of annotation values
- Refactored all annotation classes to use constructor-based
  initialization
- Fixed tests to demonstrate Doctrine-style annotation syntax
…tions

- Modified createDefaultAnnotationManager()
  - creates a GenericAnnotationParser instance, and seeds it with the
    Inject annotation
  - attaches the GenericAnnotationParser to the created
    AnnotationManager
- AnnotationScanner test was refactored to follow new
  AnnotationManger+Parser API
- PropertyReflection test was refactored to follow new
  AnnotationManger+Parser API
- If composer autoloader is missing, simply use the standard autoloader
- Abstract annotation implementations needed to import the Zend\Form\Exception
  namespace in order for exception classes to resolve
@weierophinney

Copy link
Copy Markdown
Member Author

Current build status: http://travis-ci.org/#!/weierophinney/zf2/builds/1738713 -- passing.

Comment thread composer.json Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that after the meeting and the discussions doctrine/commont won't be a requirement for zf2

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to put it here for the repo itself, as it's a dependency for one of the components. For the packages we build, it will be a requirement on packages for Zend\Code only (and by extension, and components depending on it).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that "suggest" is enough

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to add "suggests" and "require-dev", and to move the dep out of "require".

- Marked doctrine/common via require-dev and suggests in composer.json
- Updated travis config to pass --dev flag to composer
- Added test constant flags to test configuration to skip annotation
  tests unless flag is true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $annotation is a string you already know the $class. I suggest treat this as an else of the first if

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion; fixed now.

@Maks3w

Maks3w commented Jun 29, 2012

Copy link
Copy Markdown
Member

How is resolved when exists two annotations with the same name but provided by different applications?

- Made CS changes suggested by Maks3w
@weierophinney

Copy link
Copy Markdown
Member Author

@Maks3w re: 2 annotations with same name, provided by different applications -- not an issue. Annotations always are resolved to a fully qualified class name; within ZF2, we do this by expanding the annotation name based on the import statements and namespace defined in the class file. Doctrine does similarly, but has additional mechanisms.

@akrabat

akrabat commented Jun 30, 2012

Copy link
Copy Markdown
Contributor

Any hints on how to install the Doctrine dependency, so that I can run the unit tests?

@Maks3w

Maks3w commented Jun 30, 2012

Copy link
Copy Markdown
Member

@akrabat Using composer run "php composer.phar install --dev"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants