Doctrine Common
  1. Doctrine Common
  2. DCOM-165

Entities seems not be recognized by AnnotationDriver

    Details

    • Type: Bug Bug
    • Status: Awaiting Feedback
    • Priority: Trivial Trivial
    • Resolution: Unresolved
    • Affects Version/s: 2.2, 2.3
    • Fix Version/s: None
    • Component/s: Annotations
    • Environment:
      Windows 7 Profesional, Enterprise and Windows Server 2003 and 2008; Common: 2.2.3 DBAL: 2.2.2 ORM: 2.2.3; PHP 5.4.5 and 5.3.5

      Description

      Problem:
      --------
      "$em->getMetadataFactory()->getAllMetadata()"
      Will result in an empty array. The entitiy manager is correctly configured and the entities files are loaded (echo's in the files will be displayed).

      Debug steps:
      ------------
      Looking in the code for the problem I created the following debug points first:

      file AnnotationDriver.php method getAllClassNames()
      after the line: "$includedFiles[] = $sourceFile;"
      add: "echo $sourceFile . ' is loaded' . PHP_EOL;"

      file AnnotationDriver.php method getAllClassNames()
      after the line: "$sourceFile = $rc->getFileName();"
      add: "echo $className . ' is loaded from: ' . $sourceFile . ' in the includedFiles array? ' . (in_array($sourceFile, $includedFiles) ? 'YES' : 'not found ') . PHP_EOL;"

      the following output will be displayed:
      ...
      f:\workspace\nl.markei.posto-2.3\lib\relaties\Contact.php is loaded
      ...
      nl\markei\posto\relaties\Contact is loaded from: F:\workspace\nl.markei.posto-2.3\lib\relaties\Contact.php in the includedFiles array? not found

      It seems that Doctrine includes the file from f: but ReflectionClass say it is loaded from F:. The in_array() will fail and Doctrine will not recognized the entity.

      But this is not the full problem. I created a new debug point:

      file AnnotationDriver.php method getAllClassNames()
      after the line: "foreach ($this->_paths as $path) {"
      add: "echo 'path: ' . $path . ' after realpath: ' . realpath($path) . PHP_EOL;"

      This will result in the following output:
      "path: F:\domains\markei.nl\lib\nl.markei.posto\ after realpath: f:\workspace\nl.markei.posto-2.3\lib"

      So the conversion of the F: to f: is done by realpath; its look like

      A simple fix should be in AnnotationDriver.php / getAllClassNames()
      replace: "$sourceFile = $rc->getFileName();"
      by: "$sourceFile = realpath($rc->getFileName());"

      After I did that, the problem still exists. So I add to echo's (one with realpath and one without at the part of the code). And both echo's result in a path starting with "F:".

      So my first reaction was freaky!

      After some frustrating hours I found the problem in the symlink I used.
      "F:\domains\markei.nl\lib\nl.markei.posto" was a symlink to "f:\workspace\nl.markei.posto-2.3\lib" and realpath will not convert the driver char in the target of the symlink for some freaky reason. After changing the symlink target to "F:\workspace...." everything works fine.

      Summary:
      --------
      realpath results are not consistent on Windows. This will resulting in problems under Windows.

      Possible solutions:
      -------------------
      Saying "this is a PHP bug".
      It is possible that there are more case sensitive problems hidding here on Windows. Maybe it is better to use (for Windows only!) a case insensitive in_array-alternative in AnnotationDriver.php getAllClassNames() (or convert all paths for to lowercase for Windows)

        Activity

        Maarten de Keizer created issue -
        Maarten de Keizer made changes -
        Field Original Value New Value
        Description Problem:
        --------
        "$em->getMetadataFactory()->getAllMetadata()"
        Will result in an empty array. The entitiy manager is correctly configured and the entities files are loaded (echo's in the files will be displayed).


        Debug steps:
        ------------
        Looking in the code for the problem I created the following debug points first:

        file AnnotationDriver.php method getAllClassNames()
        after the line: "$includedFiles[] = $sourceFile;"
        add: "echo $sourceFile . ' is loaded' . PHP_EOL;"

        file AnnotationDriver.php method getAllClassNames()
        after the line: "$sourceFile = $rc->getFileName();"
        add: "echo $className . ' is loaded from: ' . $sourceFile . ' in the includedFiles array? ' . (in_array($sourceFile, $includedFiles) ? 'YES' : 'not found :-(') . PHP_EOL;"


        the following output will be displayed:
        ...
        f:\workspace\nl.markei.posto-2.3\lib\relaties\Contact.php is loaded
        ...
        nl\markei\posto\relaties\Contact is loaded from: F:\workspace\nl.markei.posto-2.3\lib\relaties\Contact.php in the includedFiles array? not found :-(

        It seems that Doctrine includes the file from f: but ReflectionClass say it is loaded from F:. The in_array() will fail and Doctrine will not recognized the entity.

        But this is not the full problem. I created a new debug point:

        file AnnotationDriver.php method getAllClassNames()
        after the line: "foreach ($this->_paths as $path) {"
        add: "echo 'path: ' . $path . ' after realpath: ' . realpath($path) . PHP_EOL;"

        This will result in the following output:
        "path: F:\domains\markei.nl\lib\nl.markei.posto\ after realpath: f:\workspace\nl.markei.posto-2.3\lib"

        So the conversion of the F: to f: is done by realpath; its look like :-)

        A simple fix should be in AnnotationDriver.php / getAllClassNames()
        replace: "$sourceFile = $rc->getFileName();"
        by: "$sourceFile = realpath($rc->getFileName());"

        After I did that, the problem still exists. So I add to echo's (one with realpath and one without at the part of the code). And both echo's result in a path starting with "F:".

        So my first reaction was freaky!

        After some frustrating hours I found the problem in the symlink I used.
        "F:\domains\markei.nl\lib\nl.markei.posto" was a symlink to "f:\workspace\nl.markei.posto-2.3\lib" and realpath will not convert the driver char in the target of the symlink for some freaky reason. After changing the symlink target to "F:\workspace...." everything works fine.


        Summary:
        --------
        realpath results are not consistent on Windows. This will resulting in problems under Windows.


        Possible solutions:
        -------------------
        Saying "this is a PHP bug".
        But it is possible that there are more case sensitive problems hidding here on Windows. Maybe it is better to use (for Windows only!) a case insensitive in_array-alternative in AnnotationDriver.php getAllClassNames() (or convert all paths for to lowercase for Windows)
        Problem:
        --------
        "$em->getMetadataFactory()->getAllMetadata()"
        Will result in an empty array. The entitiy manager is correctly configured and the entities files are loaded (echo's in the files will be displayed).


        Debug steps:
        ------------
        Looking in the code for the problem I created the following debug points first:

        file AnnotationDriver.php method getAllClassNames()
        after the line: "$includedFiles[] = $sourceFile;"
        add: "echo $sourceFile . ' is loaded' . PHP_EOL;"

        file AnnotationDriver.php method getAllClassNames()
        after the line: "$sourceFile = $rc->getFileName();"
        add: "echo $className . ' is loaded from: ' . $sourceFile . ' in the includedFiles array? ' . (in_array($sourceFile, $includedFiles) ? 'YES' : 'not found :-(') . PHP_EOL;"


        the following output will be displayed:
        ...
        f:\workspace\nl.markei.posto-2.3\lib\relaties\Contact.php is loaded
        ...
        nl\markei\posto\relaties\Contact is loaded from: F:\workspace\nl.markei.posto-2.3\lib\relaties\Contact.php in the includedFiles array? not found :-(

        It seems that Doctrine includes the file from f: but ReflectionClass say it is loaded from F:. The in_array() will fail and Doctrine will not recognized the entity.

        But this is not the full problem. I created a new debug point:

        file AnnotationDriver.php method getAllClassNames()
        after the line: "foreach ($this->_paths as $path) {"
        add: "echo 'path: ' . $path . ' after realpath: ' . realpath($path) . PHP_EOL;"

        This will result in the following output:
        "path: F:\domains\markei.nl\lib\nl.markei.posto\ after realpath: f:\workspace\nl.markei.posto-2.3\lib"

        So the conversion of the F: to f: is done by realpath; its look like :-)

        A simple fix should be in AnnotationDriver.php / getAllClassNames()
        replace: "$sourceFile = $rc->getFileName();"
        by: "$sourceFile = realpath($rc->getFileName());"

        After I did that, the problem still exists. So I add to echo's (one with realpath and one without at the part of the code). And both echo's result in a path starting with "F:".

        So my first reaction was freaky!

        After some frustrating hours I found the problem in the symlink I used.
        "F:\domains\markei.nl\lib\nl.markei.posto" was a symlink to "f:\workspace\nl.markei.posto-2.3\lib" and realpath will not convert the driver char in the target of the symlink for some freaky reason. After changing the symlink target to "F:\workspace...." everything works fine.


        Summary:
        --------
        realpath results are not consistent on Windows. This will resulting in problems under Windows.


        Possible solutions:
        -------------------
        Saying "this is a PHP bug".
        It is possible that there are more case sensitive problems hidding here on Windows. Maybe it is better to use (for Windows only!) a case insensitive in_array-alternative in AnnotationDriver.php getAllClassNames() (or convert all paths for to lowercase for Windows)
        Maarten de Keizer made changes -
        Environment Windows 7 Profesional, Enterprise and Windows Server 2003 and 2008 Windows 7 Profesional, Enterprise and Windows Server 2003 and 2008; Common: 2.2.3 DBAL: 2.2.2 ORM: 2.2.3; PHP 5.4.5 and 5.3.5
        Maarten de Keizer made changes -
        Priority Major [ 3 ] Trivial [ 5 ]
        Marco Pivetta made changes -
        Project Doctrine 2 - ORM [ 10032 ] Doctrine Common [ 10043 ]
        Key DDC-2009 DCOM-165
        Affects Version/s 2.3 [ 10183 ]
        Affects Version/s 2.2 [ 10152 ]
        Affects Version/s 2.2.3 [ 10196 ]
        Component/s Annotations [ 10050 ]
        Component/s ORM [ 10012 ]
        Component/s Mapping Drivers [ 10044 ]
        Marco Pivetta made changes -
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Marco Pivetta made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Maarten de Keizer
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: