Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-557

Custom Mapping Types docs code example is incomplete

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA2
    • Component/s: Documentation
    • Security Level: All
    • Labels:
      None

      Description

      \Doctrine\DBAL\Types\Type defines an abstract method getName() however the code example at http://www.doctrine-project.org/documentation/manual/2_0/en/basic-mapping#custom-mapping-types does not include a getName() function:

      Fatal error: Class My\Doctrine\DBAL\Types\MyType contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Doctrine\DBAL\Types\Type::getName) in /www/app/lib/My/Doctrine/DBAL/Types/MyType.php
      

      Suggest amending example to:

      <?php
      
      namespace My\Project\Types;
      
      use Doctrine\DBAL\Types\Type;
      use Doctrine\DBAL\Platforms\AbstractPlatform;
      
      /**
       * My custom datatype.
       */
      class MyType extends Type
      {
          const MYTYPE = 'mytype'; // modify to match your type name
      
          public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
          {
              // return the SQL used to create your column type. To create a portable column type, use the $platform.
          }
      
          public function convertToPHPValue($value, AbstractPlatform $platform)
          {
              // This is executed when the value is read from the database. Make your conversions here, optionally using the $platform.
          }
      
          public function convertToDatabaseValue($value, AbstractPlatform $platform)
          {
              // This is executed when the value is written to the database. Make your conversions here, optionally using the $platform.
          }
      
          public function getName()
          {
              return self::MYTYPE; // modify to match your constant name
          }
      }
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Marc Hodgins
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: