Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1645

Paths to Annotations classes are not considered

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Description

      Hi, my battle is described here: http://groups.google.com/group/doctrine-user/browse_thread/thread/db9c77b6bc000f13

      When I follow bugtracker tutorial I think that there is an error when working with Annotations, see these examples:

      Start a new bugtracker project as described in tutorial from scratch, create folders and files as tutorial expose, then do following changes:

      1) put Product, Bug, User class files at root level, same level as bootstraps files and create_xxxxx files
      2) Create 'entities' folder, but leave it empty.
      3) Create 'yaml' and 'xml' at root level too and add related files.
      4) Open bootstrap and edit paths to Product, Bug and User class files to read from root files as in 1) so they can be read from scripts.

      1) YAML
      a) When using YAML as mapping driver you need a path to Setup::createYAMLMetadataConfiguration( ) method, I use this
      Setup::createYAMLMetadataConfiguration(array(_DIR_."/yaml"), $isDevMode);
      where "yaml" directory is same level as bootstraps and create_xxxxx files are. When executing script to create a product
      Doctrine work as expected, creating a row inside table correctly.
      b) If you comment line where class Product is included, the object can't be found at runtime and will throw an exception as expected.
      c) With uncommented require Product line, change yaml name folder to anything, and Doctrine throw an exception (MappingException) as expected

      so Setup method path argument is considered correctly, Doctrine engine must know where yaml files for classes are.

      2) XML
      a) When using XML as mapping driver you need a path to Setup::createXMLMetadataConfiguration( ) method, I use this
      Setup::createXMLMetadataConfiguration(array(_DIR_."/xml"), $isDevMode);
      where "xml" directory is same level as bootstraps and create_xxxxx files are. When executing script to create a product
      Doctrine work as expected, creating a row inside table correctly.
      b) If you comment line where class Product is included, the object can't be found at runtime and will throw an exception as expected.
      c) With uncommented require Product line, change xml name folder to anything, and Doctrine throw an exception (MappingException) as expected

      so Setup method path argument is considered correctly again, Doctrine engine must know where xml files for classes are.

      3) Annotations
      a) When using Annotations as mapping driver you need a path to Setup::createAnnotationsMetadataConfiguration( ) method, I use this
      Setup::createAnnotationsMetadataConfiguration(array(_DIR_."/entities"), $isDevMode);
      where "entities" directory is same level as bootstraps and create_xxxxx files are (but remember THEY ARE EMPTY). When executing script to create a product
      Doctrine WORK AS EXPECTED, creating a row inside table correctly and still I don't know how if THERE IS NO Annotations files.
      b) If you comment line where class Product is included, the object can't be found at runtime and will throw an exception as expected.
      c) With uncommented require Product line, change name folder to anything, and Doctrine WILL NOT throw an exception, continue with execution.
      d) Copy /Product.php to /entities/Product.php, then comment docblocks from /Product class (using // or delete them). When running script Doctrine throw a MappingException with message: "Class Product is not a valid entity or mapped super class", when as follow concepts from 1) (yaml) and 2) (xml) it should search docblocks from /entities/Product.php file (path argument from Setup), right?

      so Setup method path argument IS NOT CONSIDERED, Doctrine engine use already defined classes to get Annotations docblocks using php reflexion classes, methods and functions.

      How to deal with this? I mean...

      a) Erase path argument from Setup::createAnnotationMetadataConfiguration methos (and similar functions for Annotations) because is not needed, classes and annotations must be defined before.
      b) Add support to find docblocks from path argument when no valid dockblock is found from class definition, so entities classes can live without docblocks because they are found inside Setup path function argument, as YAML and XML do.

      I know that is easy to follow tutorial guidelines to develop applications in Annotations point of view, load them before Doctrine script start (with require/include or autoloaders, etc) and will work, but I think that is wrong how tutorial and functional logic are given, so a) and b) are my proposed solutions. I think b) should be right, get dockblocks from a class already defined and if are not defined it follow XML and YAML logic: read metadata from other files.

      Attachment: My bugtracker Netbeans project.

      Sorry by my english

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            feathers and down
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: