-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
121d216
commit 5c33609
Showing
2 changed files
with
27 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use Ronanchilvers\Orm\Features\Type\ArrayHandler; | ||
use Ronanchilvers\Orm\Features\Type\DateTimeHandler; | ||
use Ronanchilvers\Orm\Features\Type\HandlerInterface; | ||
use Ronanchilvers\Orm\Features\Type\ModelHandler; | ||
use Ronanchilvers\Utility\Str; | ||
|
||
/** | ||
|
@@ -240,9 +241,12 @@ protected function getTypeHandler($type) | |
* @param string $attribute | ||
* @author Ronan Chilvers <[email protected]> | ||
*/ | ||
public function addType($type, $attribute) | ||
public function addType($type, $attribute, array $options = []) | ||
{ | ||
$this->types[$attribute] = $type; | ||
$this->types[$attribute] = [ | ||
'type' => $type, | ||
'options' => $options, | ||
]; | ||
} | ||
|
||
/** | ||
|
@@ -257,7 +261,7 @@ protected function hasType($attribute) | |
if (!isset($this->types[$attribute])) { | ||
return false; | ||
} | ||
$type = $this->types[$attribute]; | ||
$type = $this->types[$attribute]['type']; | ||
if (!isset(self::$typeHandlers[$type])) { | ||
return false; | ||
} | ||
|
@@ -279,10 +283,11 @@ protected function getAttributeToType( | |
if (is_null($value)) { | ||
return $value; | ||
} | ||
$handler = self::getTypeHandler($this->types[$attribute]); | ||
$handler = self::getTypeHandler($this->types[$attribute]['type']); | ||
|
||
return $handler->toType( | ||
$value | ||
$value, | ||
$this->types[$attribute]['options'] | ||
); | ||
} | ||
|
||
|
@@ -301,10 +306,11 @@ protected function getAttributeToRaw( | |
if (is_null($value)) { | ||
return $value; | ||
} | ||
$handler = self::getTypeHandler($this->types[$attribute]); | ||
$handler = self::getTypeHandler($this->types[$attribute]['type']); | ||
|
||
return $handler->toRaw( | ||
$value | ||
$value, | ||
$this->types[$attribute]['options'] | ||
); | ||
} | ||
|
||
|
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