-
-
Notifications
You must be signed in to change notification settings - Fork 711
Add support for shorttags in functions #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wisskid
merged 10 commits into
smarty-php:master
from
pharixces:bugfix/fix_function_compiler_shorthand_attributes
Oct 3, 2025
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bfbbe54
Add support for shorttags in functions
36e6fc5
Change implementation
bef42de
Revert removal of nocache default optionflag as it breaks unittests
4cfee0d
Add small tweaks
be4a4d0
refactored getAttributes into a special Compiler class
wisskid 362c870
Add unittests for attributecompiler class.
833b8e3
Make test compatible with php 7.2
3f5dc0d
Remove splat operator
3a12cd4
Remove last splat operator
7823133
Add unittests for attrivbute function handlers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,77 @@ | ||
| <?php | ||
|
|
||
| namespace Smarty\FunctionHandler; | ||
|
|
||
| use Smarty\Template; | ||
|
|
||
| /** | ||
| * Abstract implementation for function handlers which support custom attributes | ||
| */ | ||
| abstract class AttributeBase implements AttributeFunctionHandlerInterface | ||
| { | ||
| /** | ||
| * Array of names of required attribute required by tag | ||
| * | ||
| * @var array | ||
| */ | ||
| protected array $required_attributes = []; | ||
|
|
||
| /** | ||
| * Array of names of optional attribute required by tag | ||
| * use array('_any') if there is no restriction of attributes names | ||
| * | ||
| * @var array | ||
| */ | ||
| protected array $optional_attributes = []; | ||
|
|
||
| /** | ||
| * Shorttag attribute order defined by its names | ||
| * | ||
| * @var array | ||
| */ | ||
| protected array $shorttag_order = []; | ||
|
|
||
| /** | ||
| * Array of names of valid option flags | ||
| * | ||
| * @var array | ||
| */ | ||
| protected array $option_flags = []; | ||
|
|
||
| /** | ||
| * Return whether the output is cacheable. | ||
| * @var bool | ||
| */ | ||
| protected bool $cacheable = true; | ||
|
|
||
| /** | ||
| * Return whether the output is cacheable. | ||
| * @return bool | ||
| */ | ||
| public function isCacheable(): bool | ||
| { | ||
| return $this->cacheable; | ||
| } | ||
|
|
||
| /** | ||
| * Function body | ||
| * @param mixed $params The supplied parameters. | ||
| * @param Smarty\Template $template | ||
| * @return mixed | ||
| */ | ||
| abstract public function handle($params, Template $template): ?string; | ||
|
|
||
| /** | ||
| * Return the support attributes for this function. | ||
| * @return array<string, array> | ||
| */ | ||
| public function getSupportedAttributes(): array | ||
| { | ||
| return [ | ||
| 'required_attributes' => $this->required_attributes, | ||
| 'optional_attributes' => $this->optional_attributes, | ||
| 'shorttag_order' => $this->shorttag_order, | ||
| 'option_flags' => $this->option_flags, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or 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,15 @@ | ||
| <?php | ||
|
|
||
| namespace Smarty\FunctionHandler; | ||
|
|
||
| /** | ||
| * Function handler interface with support for specifying supported properties | ||
| */ | ||
| interface AttributeFunctionHandlerInterface extends FunctionHandlerInterface | ||
| { | ||
| /** | ||
| * Returns an array with the supported attributes, flags, and shorttags | ||
| * @return array<string, array> | ||
| */ | ||
| public function getSupportedAttributes(): array; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not change
$required_attributesinBase.