Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Doctrine 2: How to create custom Types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Nico Kaiser  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 14:22
From: Nico Kaiser <n...@kaiser.me>
Date: Fri, 06 Nov 2009 15:22:02 +0100
Local: Fri 6 Nov 2009 14:22
Subject: Doctrine 2: How to create custom Types
Hi!

What is the best way to add custom Types to DDC? There is for example
DC's ENUM type (which is currently missing in DDC, see DDC-65 [1]) - as
ENUM may be DBMS specific, what is the best way to implement it?

Can I do it as plugin/extension, or do I have to patch DDC?

Nico

[1] http://www.doctrine-project.org/jira/browse/DDC-65


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Eberlei  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 14:32
From: Benjamin Eberlei <kont...@beberlei.de>
Date: Fri, 6 Nov 2009 15:32:31 +0100
Local: Fri 6 Nov 2009 14:32
Subject: Re: [doctrine-user] Doctrine 2: How to create custom Types
what exactly do you need from an enum support? cant you model it as Char and
validate the input against an array of allowed values using in_array() ?

To add types you can use \Doctrine\DBAL\Types\Type which has static methods
for adding types, your type needs to implement \Doctrine\DBAL\Types\Type.
However this is a singleton for each type, so with enums there might be
problems, because an enum effectivly has state (the allowed values).

greetings,
Benjamin

On Friday 06 November 2009 03:22:02 pm Nico Kaiser wrote:

> Hi!

> What is the best way to add custom Types to DDC? There is for example
> DC's ENUM type (which is currently missing in DDC, see DDC-65 [1]) - as
> ENUM may be DBMS specific, what is the best way to implement it?

> Can I do it as plugin/extension, or do I have to patch DDC?

> Nico

> [1] http://www.doctrine-project.org/jira/browse/DDC-65

--
Benjamin Eberlei
http://www.beberlei.de

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Wage  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 17:33
From: Jonathan Wage <jonw...@gmail.com>
Date: Fri, 6 Nov 2009 12:33:27 -0500
Local: Fri 6 Nov 2009 17:33
Subject: Re: [doctrine-user] Doctrine 2: How to create custom Types

Here are some examples:

namespace \Doctrine\DBAL\Types;

class MyCustomObjectType extends Type
{
    public function getName()
    {
        return 'MyCustomObjectType';
    }

    public function getSqlDeclaration(array $fieldDeclaration,
\Doctrine\DBAL\Platforms\AbstractPlatform $platform)
    {
        return $platform->getClobDeclarationSql($fieldDeclaration);
    }

    public function convertToDatabaseValue($value,
\Doctrine\DBAL\Platforms\AbstractPlatform $platform)
    {
        return serialize($value);
    }

    public function convertToPHPValue($value)
    {
        return unserialize($value);
    }

}

Type::addCustomType(
  'MyCustomObjectType',
  'Doctrine\DBAL\Types\MyCustomObjectType'
);

class MyString extends StringType
{

}

Type::overrideType('string', 'Doctrine\DBAL\Types\MyString');

--
Jonathan H. Wage (+1 415 992 5468)
Open Source Software Developer & Evangelist
sensiolabs.com | jwage.com | doctrine-project.org | symfony-project.org

You should follow me on Twitter: http://www.twitter.com/jwage

You can contact Jonathan about Doctrine, Symfony and Open-Source or for
training, consulting, application development, or business related questions
at jonathan.w...@sensio.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guilherme Blanco  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 17:42
From: Guilherme Blanco <guilhermebla...@gmail.com>
Date: Fri, 6 Nov 2009 15:42:54 -0200
Local: Fri 6 Nov 2009 17:42
Subject: Re: [doctrine-user] Re: Doctrine 2: How to create custom Types
Just a small correction:

Type::addType and not Type::addCustomType

Cheers,

--
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9215-8480
MSN: guilhermebla...@hotmail.com
URL: http://blog.bisna.com
São Paulo - SP/Brazil

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nico Kaiser  
View profile   Translate to Translated (View Original)
 More options 9 Nov, 08:59
From: Nico Kaiser <n...@kaiser.me>
Date: Mon, 9 Nov 2009 00:59:54 -0800 (PST)
Local: Mon 9 Nov 2009 08:59
Subject: Re: Doctrine 2: How to create custom Types
I think it's the other direction - I need to create a DDC model around
a given database model, which I don't want to change for some reasons
(and which was once created by Doctrine 1.x).

So an EnumType that maps Enum objects to string (or clob) does not
help here, a custom string object that maps to the DB enum type would
be better (not the best way, as validation would happen at two places
then, but this would be ok for now)...

Nico

On Nov 6, 3:32 pm, Benjamin Eberlei <kont...@beberlei.de> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google