This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from archdevil666pl/master
Added database mappers
- Loading branch information
Showing
9 changed files
with
392 additions
and
110 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* This file is part of Vegas package | ||
* | ||
* @author Radosław Fąfara <radek@amsterdam-standard.pl> | ||
* @copyright Amsterdam Standard Sp. Z o.o. | ||
* @homepage http://vegas-cmf.github.io | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vegas\Db\Mapping; | ||
|
||
use Vegas\Db\MappingInterface; | ||
|
||
/** | ||
* Class Blob | ||
* | ||
* Simple mapper for binary fields | ||
* | ||
* @package Vegas\Db\Mapping | ||
*/ | ||
class Blob implements MappingInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'blob'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve(& $value) | ||
{ | ||
if (is_string($value) && strlen($value) > 0) { | ||
$decoded = base64_decode($value, true); | ||
$decoded !== false && $value = $decoded; | ||
} | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* This file is part of Vegas package | ||
* | ||
* @author Radosław Fąfara <radek@amsterdam-standard.pl> | ||
* @copyright Amsterdam Standard Sp. Z o.o. | ||
* @homepage http://vegas-cmf.github.io | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vegas\Db\Mapping; | ||
|
||
use Vegas\Db\MappingInterface; | ||
|
||
/** | ||
* Class Camelize | ||
* | ||
* Simple mapper for converting text to camelize style | ||
* | ||
* @package Vegas\Db\Mapping | ||
*/ | ||
class Camelize implements MappingInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'camelize'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve(& $value) | ||
{ | ||
if (is_string($value) && strlen($value) > 0) { | ||
$value = \Phalcon\Text::camelize($value); | ||
} | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* This file is part of Vegas package | ||
* | ||
* @author Radosław Fąfara <radek@amsterdam-standard.pl> | ||
* @copyright Amsterdam Standard Sp. Z o.o. | ||
* @homepage http://vegas-cmf.github.io | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vegas\Db\Mapping; | ||
|
||
use Vegas\Db\MappingInterface; | ||
|
||
/** | ||
* Class Decimal | ||
* | ||
* Simple mapper for number fields | ||
* | ||
* @package Vegas\Db\Mapping | ||
*/ | ||
class Decimal implements MappingInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'decimal'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve(& $value) | ||
{ | ||
if (is_numeric($value) && strlen($value) > 0) { | ||
$value = number_format($value, 2, '.', ''); | ||
} | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* This file is part of Vegas package | ||
* | ||
* @author Radosław Fąfara <radek@amsterdam-standard.pl> | ||
* @copyright Amsterdam Standard Sp. Z o.o. | ||
* @homepage http://vegas-cmf.github.io | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vegas\Db\Mapping; | ||
|
||
use Vegas\Db\MappingInterface; | ||
|
||
/** | ||
* Class Lowercase | ||
* | ||
* Simple mapper for converting text to lowercase style | ||
* | ||
* @package Vegas\Db\Mapping | ||
*/ | ||
class Lowercase implements MappingInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'lowercase'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve(& $value) | ||
{ | ||
if (is_string($value) && strlen($value) > 0) { | ||
$value = \Phalcon\Text::lower($value); | ||
} | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* This file is part of Vegas package | ||
* | ||
* @author Radosław Fąfara <radek@amsterdam-standard.pl> | ||
* @copyright Amsterdam Standard Sp. Z o.o. | ||
* @homepage http://vegas-cmf.github.io | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vegas\Db\Mapping; | ||
|
||
use Vegas\Db\MappingInterface; | ||
|
||
/** | ||
* Class Serialize | ||
* | ||
* Simple mapper for PHP serialized fields | ||
* | ||
* @package Vegas\Db\Mapping | ||
*/ | ||
class Serialize implements MappingInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'serialize'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve(& $value) | ||
{ | ||
if (is_string($value) && strlen($value) > 0) { | ||
$unserialized = unserialize($value); | ||
if ($value !== serialize(false) && $unserialized !== false) { | ||
$value = $unserialized; | ||
} | ||
} | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* This file is part of Vegas package | ||
* | ||
* @author Radosław Fąfara <radek@amsterdam-standard.pl> | ||
* @copyright Amsterdam Standard Sp. Z o.o. | ||
* @homepage http://vegas-cmf.github.io | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vegas\Db\Mapping; | ||
|
||
use Vegas\Db\MappingInterface; | ||
|
||
/** | ||
* Class Uppercase | ||
* | ||
* Simple mapper for converting text to uppercase style | ||
* | ||
* @package Vegas\Db\Mapping | ||
*/ | ||
class Uppercase implements MappingInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'uppercase'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve(& $value) | ||
{ | ||
if (is_string($value) && strlen($value) > 0) { | ||
$value = \Phalcon\Text::upper($value); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
Oops, something went wrong.