-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Form\Value
: Move data methods to Data
classes
- Loading branch information
1 parent
bf4c4e7
commit 5cb9522
Showing
7 changed files
with
30 additions
and
217 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
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
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 |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
|
||
namespace Kirby\Form\Mixin; | ||
|
||
use Kirby\Data\Data; | ||
use Throwable; | ||
|
||
/** | ||
* @package Kirby Form | ||
* @author Bastian Allgeier <[email protected]> | ||
|
@@ -119,48 +116,4 @@ public function value(bool $default = false): mixed | |
|
||
return $this->value; | ||
} | ||
|
||
/** | ||
* Decodes a JSON string into an array | ||
*/ | ||
protected function valueFromJson(mixed $value): array | ||
{ | ||
try { | ||
return Data::decode($value, 'json'); | ||
} catch (Throwable) { | ||
return []; | ||
} | ||
} | ||
|
||
/** | ||
* Decodes a YAML string into an array | ||
*/ | ||
protected function valueFromYaml(mixed $value): array | ||
{ | ||
return Data::decode($value, 'yaml'); | ||
} | ||
|
||
/** | ||
* Encodes an array into a JSON string | ||
*/ | ||
protected function valueToJson( | ||
array|null $value = null, | ||
bool $pretty = false | ||
): string { | ||
$constants = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; | ||
|
||
if ($pretty === true) { | ||
$constants |= JSON_PRETTY_PRINT; | ||
} | ||
|
||
return json_encode($value, $constants); | ||
} | ||
|
||
/** | ||
* Encodes an array into a YAML string | ||
*/ | ||
protected function valueToYaml(array|null $value = null): string | ||
{ | ||
return Data::encode($value, 'yaml'); | ||
} | ||
} |
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