-
-
Notifications
You must be signed in to change notification settings - Fork 586
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 #1341 from schmittjoh/twig
Allow to add prefix to twig helpers
- Loading branch information
Showing
4 changed files
with
62 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
|
||
abstract class SerializerBaseExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $serializationFunctionsPrefix; | ||
|
||
/** | ||
* @return string | ||
* | ||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
*/ | ||
public function getName() | ||
{ | ||
return 'jms_serializer'; | ||
} | ||
|
||
public function __construct(string $serializationFunctionsPrefix = '') | ||
{ | ||
$this->serializationFunctionsPrefix = $serializationFunctionsPrefix; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,25 +4,14 @@ | |
|
||
namespace JMS\Serializer\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFilter; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* @author Asmir Mustafic <[email protected]> | ||
*/ | ||
final class SerializerRuntimeExtension extends AbstractExtension | ||
final class SerializerRuntimeExtension extends SerializerBaseExtension | ||
{ | ||
/** | ||
* @return string | ||
* | ||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
*/ | ||
public function getName() | ||
{ | ||
return 'jms_serializer'; | ||
} | ||
|
||
/** | ||
* @return TwigFilter[] | ||
* | ||
|
@@ -31,7 +20,7 @@ public function getName() | |
public function getFilters() | ||
{ | ||
return [ | ||
new TwigFilter('serialize', [SerializerRuntimeHelper::class, 'serialize']), | ||
new TwigFilter($this->serializationFunctionsPrefix . 'serialize', [SerializerRuntimeHelper::class, 'serialize']), | ||
]; | ||
} | ||
|
||
|
@@ -43,7 +32,7 @@ public function getFilters() | |
public function getFunctions() | ||
{ | ||
return [ | ||
new TwigFunction('serialization_context', '\JMS\Serializer\SerializationContext::create'), | ||
new TwigFunction($this->serializationFunctionsPrefix . 'serialization_context', '\JMS\Serializer\SerializationContext::create'), | ||
]; | ||
} | ||
} |
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