Created
April 2, 2014 14:01
-
-
Save vespakoen/9934735 to your computer and use it in GitHub Desktop.
Bolt fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ {% if field.type in app.extensions.getFields|keys %} | |
+ {% include 'custom/fields/' ~ field.type ~ '.twig' %} | |
+ {% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ public function addField($type, $boltType, $doctrineType = null) | |
+ { | |
+ $this->app['extensions']->addField($type, $boltType, $doctrineType); | |
+ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ foreach($this->app['extensions']->getFields() as $type => $field) { | |
+ if($this->fieldtype($key) == $type) { | |
+ $this->values[$key] = $field->unserialize($this->values[$key]); | |
+ } | |
+ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+use Doctrine\DBAL\Types\Type; | |
+use Doctrine\DBAL\Platforms\AbstractPlatform; | |
+ /** | |
+ * List of registered fields. | |
+ * | |
+ * @var array | |
+ */ | |
+ private $fields = array(); | |
+ public function addField($type, $boltType, $doctrineType = null) | |
+ { | |
+ if(class_exists($boltType)) | |
+ { | |
+ $field = new $boltType($this->app); | |
+ $this->fields[$type] = $field; | |
+ } | |
+ | |
+ if(is_null($doctrineType)) | |
+ { | |
+ $doctrineType = $field->getDoctrineType(); | |
+ } | |
+ else | |
+ { | |
+ $field->setDoctrineType($doctrineType); | |
+ } | |
+ | |
+ $platform = $this->app['db']->getDatabasePlatform(); | |
+ Type::addType($type, $doctrineType); | |
+ | |
+ // Since doctrineTypeComments may already be initialized check if added type requires comment | |
+ if (Type::getType($type)->requiresSQLCommentHint($platform)) { | |
+ $platform->markDoctrineTypeCommented($type); | |
+ } | |
+ | |
+ return $this; | |
+ } | |
+ | |
+ public function getFields() | |
+ { | |
+ return $this->fields; | |
+ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Bolt; | |
use Bolt\Fields\FieldInteface; | |
abstract class Field { | |
protected $app; | |
protected $doctrineType = 'Doctrine\DBAL\Types\StringType'; | |
public function __construct($app) | |
{ | |
$this->app = $app; | |
} | |
public function getDoctrineType() | |
{ | |
return $this->doctrineType; | |
} | |
public function setDoctrineType($type) | |
{ | |
$this->doctrineType = $type; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Bolt\Fields; | |
interface FieldInterface { | |
public function serialize($value); | |
public function unserialize($value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ foreach($this->app['extensions']->getFields() as $type => $field) { | |
+ if($values['type'] == $type) { | |
+ $fieldvalues[$key] = $field->serialize($fieldvalues[$key]); | |
+ } | |
+ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment