Skip to content
Browse files

Added Doctrine JSON type

  • Loading branch information...
1 parent 946e54e commit 507180b8a75b9974ed27677af698aa35eeb9c46e @barnabywalters committed Nov 12, 2012
Showing with 66 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +37 −0 BarnabyWalters/Doctrine/Types/Json.php
  3. +3 −0 composer.json
  4. +15 −0 nbproject/project.properties
  5. +9 −0 nbproject/project.xml
View
3 .gitignore
@@ -1,4 +1,5 @@
.DS_Store
composer.phar
vendor/
-tmp/
+tmp/
+/nbproject/private/
View
37 BarnabyWalters/Doctrine/Types/Json.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace BarnabyWalters\Doctrine\Types;
+
+use Doctrine\DBAL\Types\Type;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
+
+/**
+ * My custom datatype.
+ */
+class Json extends Type
+{
+ const JSON = 'json'; // 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.
+ return 'LONGTEXT';
+ }
+
+ 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.
+ return json_decode($value);
+ }
+
+ 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.
+ return json_encode($value);
+ }
+
+ public function getName()
+ {
+ return self::JSON; // modify to match your constant name
+ }
+}
View
3 composer.json
@@ -10,5 +10,8 @@
"require": {
"tantek/cassis": "*"
},
+ "suggests": {
+ "doctrine/orm": "*"
+ },
"minimum-stability": "dev"
}
View
15 nbproject/project.properties
@@ -0,0 +1,15 @@
+include.path=${php.global.include.path}
+php.version=PHP_54
+phpunit.bootstrap=
+phpunit.bootstrap.create.tests=false
+phpunit.configuration=
+phpunit.run.test.files=true
+phpunit.script=
+phpunit.suite=
+phpunit.test.groups.ask=false
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+test.src.dir=tests
+web.root=.
View
9 nbproject/project.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.php.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/php-project/1">
+ <name>php-helpers</name>
+ </data>
+ </configuration>
+</project>

0 comments on commit 507180b

Please sign in to comment.
Something went wrong with that request. Please try again.