Doctrine 1
  1. Doctrine 1
  2. DC-858

Custom Behaviors/Templates cause autoloader errors

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1, 1.2.2, 1.2.3
    • Fix Version/s: None
    • Component/s: Behaviors, Schema Files
    • Labels:
      None
    • Environment:
      Windows Vista/7
      PHP 5.3.1 - 5.3.3
      Zend autoloader
      not occuring under Ubuntu 10.05 / MacOSX

      Description

      When emitting Behaviors from schema files (YAML in our case),
      Doctrine expects a shortened class name of the behavior (e.g. 'Timestampable') instead of the full class name:
      The string 'Doctrine_Template_' is automatically prepended and a check (class_exists()) is made.

      This is leading to possible autoloader errors (in our case: Zend autoloader does not find our custom behavior):

      YAML:

      {{
      Person:
      actAs: [SoftDelete, My_Doctrine_Template_CustomBehavior]
      ...
      }}

      'SoftDelete' is the short class name of 'Doctrine_Template_SoftDelete'.
      'My_Doctrine_Template_CustomBehavior' is the full class name and shall not be prefixed with 'Doctrine_Template_'.

      The corresponding section responsible for this bug:

      File: Doctrine/Import/Builder.php
      Lines: 702-704, function emitAssign()

      {{
      if (class_exists("Doctrine_Template_$name", true))

      { $classname = "Doctrine_Template_$name"; } }}

      There is no test whether a full class name is given as $name, so there is no way to add custom behaviors to records without the autoloader checking for a non-existing class and spilling errors/notices.
      With the above YAML schema file it would test for class_exists('Doctrine_Template_My_Doctrine_Template_CustomBehavior'), which is obviously not existing.

      a quick fix could look like this:

      {{
      if (strpos($name, '_') === false // is this a shortened name of an original Doctrine behaviour class?
      && class_exists("Doctrine_Template_$name", true)) { $classname = "Doctrine_Template_$name";}}}

      Another alternative (but breaking compatability with existing schema files) would be to always use full class names instead of fancy short names.

      Interestingly enough, this error is only occuring with Zend autoloader on Windows systems, but can be easily avoided with the fix like suggested above.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        I believe this is because the Zend autoloader does not fail silently by default. I think it can be configured to check if the file exists and not throw any errors.

        Show
        Jonathan H. Wage added a comment - I believe this is because the Zend autoloader does not fail silently by default. I think it can be configured to check if the file exists and not throw any errors.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            apric
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: