Skip to content

Commit

Permalink
Made Json type more portable between DBs, started working on StringAr…
Browse files Browse the repository at this point in the history
…ray for more focused portable string array searching
  • Loading branch information
barnabywalters committed Feb 6, 2013
1 parent 1e14b8c commit e7a53b8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BarnabyWalters/Doctrine/Types/Json.php
Expand Up @@ -15,7 +15,7 @@ class Json extends Type
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';
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}

public function convertToPHPValue($value, AbstractPlatform $platform)
Expand Down
50 changes: 50 additions & 0 deletions BarnabyWalters/Doctrine/Types/StringArray.php
@@ -0,0 +1,50 @@
<?php

namespace BarnabyWalters\Doctrine\Types;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
* StringArray
*
* @author barnabywalters
*/
class StringArray extends Type{
public function getName() {
return 'stringArray';
}

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) {
if ($platform->getName() == 'postgresql')
return 'string[]';
else
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}

public function convertToDatabaseValue($value, AbstractPlatform $platform) {
if ($platform->getName() == 'postgresql') {
$array = array_map(function ($val) {
return '"' . addslashes((string) $val) . '"';
}, $value);

return '{' . join($array, ', ') . '}';
} else {
$array = array_map(function ($val) {
return (string) $val;
}, $value);

return json_encode($array);
}
}

public function convertToPHPValue($value, AbstractPlatform $platform) {
if ($platform->getName() == 'postgresql') {

} else {
return json_decode($value);
}
}
}

// EOF
15 changes: 14 additions & 1 deletion BarnabyWalters/Helpers/Helpers.php
Expand Up @@ -351,7 +351,20 @@ public static function tagstringClean($tagstring) {
$tags = Helpers::tagstringToArray($tagstring);
return implode(',', $tags);
}


/**
* Auto Link Hashtags
*
* Given a string and a baseurl, finds all hashtags matching
* `#[\-_a-zA-Z0-9]+` and wraps them in an `a` element with `rel=tag` set
* and a `href` of baseurl + '/' + tagname without the #.
*
* @todo Improve the regex to limit false matches
*
* @param string $text
* @param string $baseUrl
* @return string The original text with all hashtags auto-linked
*/
public static function autolinkHashTags($text, $baseUrl) {
$baseUrl = rtrim($baseUrl, '/');

Expand Down

0 comments on commit e7a53b8

Please sign in to comment.