-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
9 changed files
with
254 additions
and
78 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
21 changes: 21 additions & 0 deletions
21
lib/common/Form/DataTransformer/AbstractDataTransformer.php
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,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jquery-datatables-bundle package. | ||
* | ||
* (c) 2024 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Bundle\CommonBundle\Form\DataTransformer; | ||
|
||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
// TODO: Remove when dropping support for Symfony 6.4 | ||
if (Kernel::VERSION_ID < 70000) { | ||
class_alias("WBW\Bundle\CommonBundle\Form\DataTransformer\Symfony6DataTransformer", "WBW\Bundle\CommonBundle\Form\DataTransformer\AbstractDataTransformer"); | ||
} else { | ||
class_alias("WBW\Bundle\CommonBundle\Form\DataTransformer\Symfony7DataTransformer", "WBW\Bundle\CommonBundle\Form\DataTransformer\AbstractDataTransformer"); | ||
} |
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
64 changes: 64 additions & 0 deletions
64
lib/common/Form/DataTransformer/Symfony6DataTransformer.php
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,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jquery-datatables-bundle package. | ||
* | ||
* (c) 2024 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Bundle\CommonBundle\Form\DataTransformer; | ||
|
||
use Throwable; | ||
|
||
/** | ||
* Symfony 6.x data transformer. | ||
* | ||
* @author webeweb <https://github.com/webeweb> | ||
* @package WBW\Bundle\CommonBundle\Form\DataTransformer | ||
* @abstract | ||
*/ | ||
abstract class Symfony6DataTransformer { | ||
|
||
/** | ||
* Decode a value. | ||
* | ||
* @param mixed|null $value The value. | ||
* @return mixed|null Returns the decoded value. | ||
* @throws Throwable Throws an exception if an error occurs. | ||
*/ | ||
abstract protected function decode($value); | ||
|
||
/** | ||
* Encode a value. | ||
* | ||
* @param mixed|null $value The value. | ||
* @return mixed|null Returns the encoded value. | ||
* @throws Throwable Throws an exception if an error occurs. | ||
*/ | ||
abstract protected function encode($value); | ||
|
||
/** | ||
* Reverse a transformed value. | ||
* | ||
* @param mixed|null $value The value. | ||
* @return mixed|null Returns the original value. | ||
* @throws Throwable Throws an exception if an error occurs. | ||
*/ | ||
public function reverseTransform($value) { | ||
return $this->decode($value); | ||
} | ||
|
||
/** | ||
* Transform a value. | ||
* | ||
* @param mixed|null $value The value. | ||
* @return mixed|null Returns the transformed value. | ||
* @throws Throwable Throws an exception if an error occurs. | ||
*/ | ||
public function transform($value) { | ||
return $this->encode($value); | ||
} | ||
} |
Oops, something went wrong.