Skip to content

Loading…

DDC-557: Custom Mapping Types docs code example is incomplete #5064

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user mjh_ca:

\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
    }
}
@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-BETA2 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.