Version Description
(14th Dec 2019) = * Fix: Sub Menus -> Text Alignment Option does not work * Fix: Trigger Icon Position * Fix: Trigger Icon Border CSS code * Fix: Menu Text goes under Trigger Icon
Download this release
Release Info
Developer | expresstech |
Plugin | ![]() |
Version | 3.1.25 |
Comparing to | |
See all releases |
Code changes from version 3.1.24 to 3.1.25
- public/css/app.css.twig +48 -4
- public/img/banner.jpg +0 -0
- public/img/banner.png +0 -0
- readme.txt +11 -5
- responsive-menu.php +33 -4
- vendor/composer/autoload_files.php +10 -0
- vendor/symfony/polyfill-ctype/Ctype.php +227 -0
- vendor/symfony/polyfill-ctype/LICENSE +19 -0
- vendor/symfony/polyfill-ctype/README.md +12 -0
- vendor/symfony/polyfill-ctype/bootstrap.php +26 -0
- vendor/symfony/polyfill-ctype/composer.json +34 -0
- vendor/twig/twig/.gitignore +5 -0
- vendor/twig/twig/doc/filters/filter.rst +58 -0
- vendor/twig/twig/doc/filters/map.rst +38 -0
- vendor/twig/twig/doc/filters/reduce.rst +33 -0
- vendor/twig/twig/doc/filters/spaceless.rst +65 -0
- vendor/twig/twig/doc/tags/apply.rst +23 -0
- vendor/twig/twig/doc/tags/deprecated.rst +30 -0
- vendor/twig/twig/drupal_test.sh +51 -0
- vendor/twig/twig/ext/twig/.gitignore +30 -0
- vendor/twig/twig/lib/Twig/Node/Deprecated.php +11 -0
- vendor/twig/twig/lib/Twig/Profiler/Dumper/Base.php +11 -0
- vendor/twig/twig/lib/Twig/TokenParser/Deprecated.php +11 -0
- vendor/twig/twig/src/Cache/CacheInterface.php +60 -0
- vendor/twig/twig/src/Cache/FilesystemCache.php +93 -0
- vendor/twig/twig/src/Cache/NullCache.php +42 -0
- vendor/twig/twig/src/Compiler.php +288 -0
- vendor/twig/twig/src/Environment.php +1638 -0
- vendor/twig/twig/src/Error/Error.php +325 -0
- vendor/twig/twig/src/Error/LoaderError.php +23 -0
- vendor/twig/twig/src/Error/RuntimeError.php +24 -0
- vendor/twig/twig/src/Error/SyntaxError.php +57 -0
- vendor/twig/twig/src/ExpressionParser.php +834 -0
- vendor/twig/twig/src/Extension/AbstractExtension.php +72 -0
- vendor/twig/twig/src/Extension/CoreExtension.php +1724 -0
- vendor/twig/twig/src/Extension/DebugExtension.php +76 -0
- vendor/twig/twig/src/Extension/EscaperExtension.php +120 -0
- vendor/twig/twig/src/Extension/ExtensionInterface.php +101 -0
- vendor/twig/twig/src/Extension/GlobalsInterface.php +26 -0
- vendor/twig/twig/src/Extension/InitRuntimeInterface.php +26 -0
- vendor/twig/twig/src/Extension/OptimizerExtension.php +39 -0
- vendor/twig/twig/src/Extension/ProfilerExtension.php +53 -0
- vendor/twig/twig/src/Extension/RuntimeExtensionInterface.php +19 -0
- vendor/twig/twig/src/Extension/SandboxExtension.php +109 -0
- vendor/twig/twig/src/Extension/StagingExtension.php +117 -0
- vendor/twig/twig/src/Extension/StringLoaderExtension.php +54 -0
- vendor/twig/twig/src/FileExtensionEscapingStrategy.php +62 -0
- vendor/twig/twig/src/Lexer.php +534 -0
- vendor/twig/twig/src/Loader/ArrayLoader.php +102 -0
- vendor/twig/twig/src/Loader/ChainLoader.php +164 -0
- vendor/twig/twig/src/Loader/ExistsLoaderInterface.php +33 -0
- vendor/twig/twig/src/Loader/FilesystemLoader.php +323 -0
- vendor/twig/twig/src/Loader/LoaderInterface.php +61 -0
- vendor/twig/twig/src/Loader/SourceContextLoaderInterface.php +38 -0
- vendor/twig/twig/src/Markup.php +41 -0
- vendor/twig/twig/src/Node/AutoEscapeNode.php +40 -0
- vendor/twig/twig/src/Node/BlockNode.php +45 -0
- vendor/twig/twig/src/Node/BlockReferenceNode.php +38 -0
- vendor/twig/twig/src/Node/BodyNode.php +23 -0
- vendor/twig/twig/src/Node/CheckSecurityNode.php +85 -0
- vendor/twig/twig/src/Node/CheckToStringNode.php +42 -0
- vendor/twig/twig/src/Node/DeprecatedNode.php +55 -0
- vendor/twig/twig/src/Node/DoNode.php +40 -0
- vendor/twig/twig/src/Node/EmbedNode.php +52 -0
- vendor/twig/twig/src/Node/Expression/AbstractExpression.php +26 -0
- vendor/twig/twig/src/Node/Expression/ArrayExpression.php +88 -0
- vendor/twig/twig/src/Node/Expression/ArrowFunctionExpression.php +64 -0
- vendor/twig/twig/src/Node/Expression/AssignNameExpression.php +29 -0
- vendor/twig/twig/src/Node/Expression/Binary/AbstractBinary.php +43 -0
- vendor/twig/twig/src/Node/Expression/Binary/AddBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/AndBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/ConcatBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/DivBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php +37 -0
- vendor/twig/twig/src/Node/Expression/Binary/EqualBinary.php +24 -0
- vendor/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php +31 -0
- vendor/twig/twig/src/Node/Expression/Binary/GreaterBinary.php +24 -0
- vendor/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php +24 -0
- vendor/twig/twig/src/Node/Expression/Binary/InBinary.php +35 -0
- vendor/twig/twig/src/Node/Expression/Binary/LessBinary.php +24 -0
- vendor/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php +24 -0
- vendor/twig/twig/src/Node/Expression/Binary/MatchesBinary.php +35 -0
- vendor/twig/twig/src/Node/Expression/Binary/ModBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/MulBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php +24 -0
- vendor/twig/twig/src/Node/Expression/Binary/NotInBinary.php +35 -0
- vendor/twig/twig/src/Node/Expression/Binary/OrBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Binary/PowerBinary.php +39 -0
- vendor/twig/twig/src/Node/Expression/Binary/RangeBinary.php +35 -0
- vendor/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php +37 -0
- vendor/twig/twig/src/Node/Expression/Binary/SubBinary.php +25 -0
- vendor/twig/twig/src/Node/Expression/BlockReferenceExpression.php +98 -0
- vendor/twig/twig/src/Node/Expression/CallExpression.php +305 -0
- vendor/twig/twig/src/Node/Expression/ConditionalExpression.php +38 -0
- vendor/twig/twig/src/Node/Expression/ConstantExpression.php +30 -0
- vendor/twig/twig/src/Node/Expression/Filter/DefaultFilter.php +54 -0
- vendor/twig/twig/src/Node/Expression/FilterExpression.php +47 -0
- vendor/twig/twig/src/Node/Expression/FunctionExpression.php +51 -0
- vendor/twig/twig/src/Node/Expression/GetAttrExpression.php +80 -0
- vendor/twig/twig/src/Node/Expression/InlinePrint.php +35 -0
- vendor/twig/twig/src/Node/Expression/MethodCallExpression.php +48 -0
- vendor/twig/twig/src/Node/Expression/NameExpression.php +119 -0
- vendor/twig/twig/src/Node/Expression/NullCoalesceExpression.php +58 -0
- vendor/twig/twig/src/Node/Expression/ParentExpression.php +48 -0
- vendor/twig/twig/src/Node/Expression/TempNameExpression.php +33 -0
- vendor/twig/twig/src/Node/Expression/Test/ConstantTest.php +51 -0
- vendor/twig/twig/src/Node/Expression/Test/DefinedTest.php +71 -0
- vendor/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php +38 -0
- vendor/twig/twig/src/Node/Expression/Test/EvenTest.php +37 -0
- vendor/twig/twig/src/Node/Expression/Test/NullTest.php +36 -0
- vendor/twig/twig/src/Node/Expression/Test/OddTest.php +37 -0
- vendor/twig/twig/src/Node/Expression/Test/SameasTest.php +36 -0
- vendor/twig/twig/src/Node/Expression/TestExpression.php +51 -0
- vendor/twig/twig/src/Node/Expression/Unary/AbstractUnary.php +35 -0
- vendor/twig/twig/src/Node/Expression/Unary/NegUnary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Unary/NotUnary.php +25 -0
- vendor/twig/twig/src/Node/Expression/Unary/PosUnary.php +25 -0
- vendor/twig/twig/src/Node/FlushNode.php +37 -0
- vendor/twig/twig/src/Node/ForLoopNode.php +56 -0
- vendor/twig/twig/src/Node/ForNode.php +119 -0
- vendor/twig/twig/src/Node/IfNode.php +72 -0
- vendor/twig/twig/src/Node/ImportNode.php +57 -0
- vendor/twig/twig/src/Node/IncludeNode.php +108 -0
- vendor/twig/twig/src/Node/MacroNode.php +136 -0
- vendor/twig/twig/src/Node/ModuleNode.php +492 -0
- vendor/twig/twig/src/Node/Node.php +274 -0
- vendor/twig/twig/src/Node/NodeCaptureInterface.php +23 -0
- vendor/twig/twig/src/Node/NodeOutputInterface.php +23 -0
- vendor/twig/twig/src/Node/PrintNode.php +41 -0
- vendor/twig/twig/src/Node/SandboxNode.php +47 -0
- vendor/twig/twig/src/Node/SandboxedPrintNode.php +69 -0
- vendor/twig/twig/src/Node/SetNode.php +107 -0
- vendor/twig/twig/src/Node/SetTempNode.php +44 -0
- vendor/twig/twig/src/Node/SpacelessNode.php +47 -0
- vendor/twig/twig/src/Node/TextNode.php +40 -0
- vendor/twig/twig/src/Node/WithNode.php +72 -0
- vendor/twig/twig/src/NodeTraverser.php +89 -0
- vendor/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php +59 -0
- vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php +209 -0
- vendor/twig/twig/src/NodeVisitor/NodeVisitorInterface.php +50 -0
- vendor/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php +273 -0
- vendor/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php +164 -0
- vendor/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php +137 -0
- vendor/twig/twig/src/Parser.php +439 -0
- vendor/twig/twig/src/Profiler/Dumper/BaseDumper.php +65 -0
- vendor/twig/twig/src/Profiler/Dumper/BlackfireDumper.php +76 -0
- vendor/twig/twig/src/Profiler/Dumper/HtmlDumper.php +51 -0
- vendor/twig/twig/src/Profiler/Dumper/TextDumper.php +39 -0
- vendor/twig/twig/src/Profiler/Node/EnterProfileNode.php +44 -0
- vendor/twig/twig/src/Profiler/Node/LeaveProfileNode.php +38 -0
- vendor/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php +80 -0
- vendor/twig/twig/src/Profiler/Profile.php +188 -0
- vendor/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php +41 -0
- vendor/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php +41 -0
- vendor/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php +31 -0
- vendor/twig/twig/src/Sandbox/SecurityError.php +25 -0
- vendor/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php +35 -0
- vendor/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php +35 -0
- vendor/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php +42 -0
- vendor/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php +42 -0
- vendor/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php +35 -0
- vendor/twig/twig/src/Sandbox/SecurityPolicy.php +129 -0
- vendor/twig/twig/src/Sandbox/SecurityPolicyInterface.php +28 -0
- vendor/twig/twig/src/Source.php +55 -0
- vendor/twig/twig/src/Template.php +733 -0
- vendor/twig/twig/src/TemplateWrapper.php +161 -0
- vendor/twig/twig/src/Test/IntegrationTestCase.php +257 -0
- vendor/twig/twig/src/Test/NodeTestCase.php +79 -0
- vendor/twig/twig/src/Token.php +215 -0
- vendor/twig/twig/src/TokenParser/AbstractTokenParser.php +34 -0
- vendor/twig/twig/src/TokenParser/ApplyTokenParser.php +58 -0
- vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php +88 -0
- vendor/twig/twig/src/TokenParser/BlockTokenParser.php +80 -0
- vendor/twig/twig/src/TokenParser/DeprecatedTokenParser.php +44 -0
- vendor/twig/twig/src/TokenParser/DoTokenParser.php +39 -0
- vendor/twig/twig/src/TokenParser/EmbedTokenParser.php +74 -0
- vendor/twig/twig/src/TokenParser/ExtendsTokenParser.php +54 -0
- vendor/twig/twig/src/TokenParser/FilterTokenParser.php +59 -0
- vendor/twig/twig/src/TokenParser/FlushTokenParser.php +39 -0
- vendor/twig/twig/src/TokenParser/ForTokenParser.php +136 -0
- vendor/twig/twig/src/TokenParser/FromTokenParser.php +72 -0
- vendor/twig/twig/src/TokenParser/IfTokenParser.php +91 -0
- vendor/twig/twig/src/TokenParser/ImportTokenParser.php +45 -0
- vendor/twig/twig/src/TokenParser/IncludeTokenParser.php +68 -0
- vendor/twig/twig/src/TokenParser/MacroTokenParser.php +68 -0
- vendor/twig/twig/src/TokenParser/SandboxTokenParser.php +67 -0
- vendor/twig/twig/src/TokenParser/SetTokenParser.php +74 -0
- vendor/twig/twig/src/TokenParser/SpacelessTokenParser.php +53 -0
- vendor/twig/twig/src/TokenParser/TokenParserInterface.php +51 -0
- vendor/twig/twig/src/TokenParser/UseTokenParser.php +75 -0
- vendor/twig/twig/src/TokenParser/WithTokenParser.php +57 -0
- vendor/twig/twig/src/TokenStream.php +201 -0
- vendor/twig/twig/src/TwigFilter.php +128 -0
- vendor/twig/twig/src/TwigFunction.php +118 -0
- vendor/twig/twig/src/TwigTest.php +87 -0
- vendor/twig/twig/src/Util/DeprecationCollector.php +92 -0
- vendor/twig/twig/src/Util/TemplateDirIterator.php +30 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/errors/leak-output.php +31 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/exception_in_extension_extends.test +12 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/exception_in_extension_include.test +12 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/strict_comparison_operator.test +6 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/call_argument_defined_twice.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/call_positional_arg_after_named_arg.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/floats.test +16 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/not_arrow_fn.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/string_operator_as_var_assignment.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_more_elements.test +23 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter.test +46 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter_php_55.test +23 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/filter_php_56.test +27 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/map.test +41 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reduce.test +14 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/filters/spaceless.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing_exists.test +11 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/include_missing_extends.test +13 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include_template_from_string.test +11 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string_error.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/regression/block_names_unicity.test +19 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/basic.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/json_encode.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/multiple.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/nested.test +16 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/scope.test +15 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/with_for_tag.test +13 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/apply/with_if_tag.test +29 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/block.legacy.test +20 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/macro.legacy.test +21 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/deprecated/template.legacy.test +12 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/scope.test +11 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing_exists.test +11 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/include_missing_extends.test +13 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_in_block.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_in_macro.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_as_template_wrapper.test +12 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_in_block_is_local.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_local_override.test +28 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_macro_in_a_macro.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_nested_blocks.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_nested_blocks_with_global_macro.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from_syntax_error.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_and_blocks.test +36 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_from_string_template.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_in_block_is_local.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_local_override.test +28 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_macro_in_a_macro.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_nested_blocks.legacy.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_nested_blocks_with_global_macro.legacy.test +18 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_self_parent.test +23 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_syntax_error.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_name.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/array.test +16 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture_scope.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/inheritance.test +24 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/inheritance_overriding.test +24 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/mutating.test +17 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/use_with_parent.test +24 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/with/globals.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tags/with/iterable.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined_on_complex_expr.test +8 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/tests/dynamic_test.test +14 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_block.test +68 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_delimiter_as_strings.test +10 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_left.test +32 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_line_left.test +33 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_line_right.test +32 -0
- vendor/twig/twig/test/Twig/Tests/Fixtures/whitespace/trim_right.test +28 -0
- vendor/twig/twig/test/Twig/Tests/Node/DeprecatedTest.php +80 -0
- vendor/twig/twig/test/Twig/Tests/NodeTraverserTest.php +47 -0
public/css/app.css.twig
CHANGED
@@ -149,10 +149,33 @@ button#responsive-menu-button,
|
|
149 |
width: 100%;
|
150 |
display: block;
|
151 |
text-decoration: none;
|
152 |
-
|
153 |
position: relative;
|
154 |
}
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
#responsive-menu-container li.responsive-menu-item a .fa {
|
157 |
margin-right: 15px;
|
158 |
}
|
@@ -512,7 +535,13 @@ button#responsive-menu-button,
|
|
512 |
line-height: {{ options.submenu_arrow_height }}px;
|
513 |
width: {{ options.submenu_arrow_width }}px;
|
514 |
color: {{ options.menu_sub_arrow_shape_colour }};
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
background-color: {{ options.menu_sub_arrow_background_colour }};
|
517 |
}
|
518 |
|
@@ -552,6 +581,7 @@ button#responsive-menu-button,
|
|
552 |
font-family: {{ "'" ~ options.submenu_font ~ "'" }};
|
553 |
{% endif %}
|
554 |
font-size: {{ options.submenu_font_size }}px;
|
|
|
555 |
}
|
556 |
|
557 |
#responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a {
|
@@ -587,12 +617,26 @@ button#responsive-menu-button,
|
|
587 |
}
|
588 |
|
589 |
#responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a .responsive-menu-subarrow {
|
590 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
height: {{ options.submenu_submenu_arrow_height }}px;
|
592 |
line-height: {{ options.submenu_submenu_arrow_height }}px;
|
593 |
width: {{ options.submenu_submenu_arrow_width }}px;
|
594 |
color: {{ options.submenu_sub_arrow_shape_colour }};
|
595 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
background-color: {{ options.submenu_sub_arrow_background_colour }};
|
597 |
}
|
598 |
|
149 |
width: 100%;
|
150 |
display: block;
|
151 |
text-decoration: none;
|
152 |
+
|
153 |
position: relative;
|
154 |
}
|
155 |
|
156 |
+
|
157 |
+
#responsive-menu-container #responsive-menu li.responsive-menu-item a {
|
158 |
+
{% if options.menu_text_alignment == 'left' and options.arrow_position == 'left' %}
|
159 |
+
padding-left: {{options.submenu_arrow_width + 5}}px;
|
160 |
+
{% elseif options.menu_text_alignment == 'right' and options.arrow_position == 'right' %}
|
161 |
+
padding-right: {{options.submenu_arrow_width + 5}}px;
|
162 |
+
{% else %}
|
163 |
+
padding: 0 {{ options.menu_depth_0 }}%;
|
164 |
+
{% endif %}
|
165 |
+
}
|
166 |
+
|
167 |
+
#responsive-menu-container .responsive-menu-submenu li.responsive-menu-item a {
|
168 |
+
{% if options.submenu_text_alignment == 'left' and options.submenu_arrow_position == 'left' %}
|
169 |
+
padding-left: {{options.submenu_submenu_arrow_width + 5}}px !important;
|
170 |
+
padding-right:unset !important;
|
171 |
+
{% elseif options.submenu_text_alignment == 'right' and options.submenu_arrow_position == 'right' %}
|
172 |
+
padding-right: {{options.submenu_submenu_arrow_width + 5}}px !important;
|
173 |
+
padding-left:unset !important;
|
174 |
+
{% else %}
|
175 |
+
padding: 0 {{ options.menu_depth_0 }}%;
|
176 |
+
{% endif %}
|
177 |
+
}
|
178 |
+
|
179 |
#responsive-menu-container li.responsive-menu-item a .fa {
|
180 |
margin-right: 15px;
|
181 |
}
|
535 |
line-height: {{ options.submenu_arrow_height }}px;
|
536 |
width: {{ options.submenu_arrow_width }}px;
|
537 |
color: {{ options.menu_sub_arrow_shape_colour }};
|
538 |
+
{% if options.arrow_position == 'left' %}
|
539 |
+
border-right: {{ options.menu_border_width }}px
|
540 |
+
{% endif %}
|
541 |
+
{% if options.arrow_position == 'right' %}
|
542 |
+
border-left: {{ options.menu_border_width }}px
|
543 |
+
{% endif %}
|
544 |
+
solid {{ options.menu_sub_arrow_border_colour }};
|
545 |
background-color: {{ options.menu_sub_arrow_background_colour }};
|
546 |
}
|
547 |
|
581 |
font-family: {{ "'" ~ options.submenu_font ~ "'" }};
|
582 |
{% endif %}
|
583 |
font-size: {{ options.submenu_font_size }}px;
|
584 |
+
text-align: {{ options.submenu_text_alignment }};
|
585 |
}
|
586 |
|
587 |
#responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a {
|
617 |
}
|
618 |
|
619 |
#responsive-menu-container #responsive-menu ul.responsive-menu-submenu li.responsive-menu-item a .responsive-menu-subarrow {
|
620 |
+
{% if options.submenu_arrow_position == 'left' %}
|
621 |
+
left:0;
|
622 |
+
right:unset;
|
623 |
+
{% endif %}
|
624 |
+
{% if options.submenu_arrow_position == 'right' %}
|
625 |
+
left:unset;
|
626 |
+
right:0;
|
627 |
+
{% endif %}
|
628 |
height: {{ options.submenu_submenu_arrow_height }}px;
|
629 |
line-height: {{ options.submenu_submenu_arrow_height }}px;
|
630 |
width: {{ options.submenu_submenu_arrow_width }}px;
|
631 |
color: {{ options.submenu_sub_arrow_shape_colour }};
|
632 |
+
{% if options.submenu_arrow_position == 'left' %}
|
633 |
+
border-right: {{ options.submenu_border_width }}px solid {{ options.submenu_sub_arrow_border_colour }} !important;
|
634 |
+
border-left:unset !important;
|
635 |
+
{% endif %}
|
636 |
+
{% if options.submenu_arrow_position == 'right' %}
|
637 |
+
border-left: {{ options.submenu_border_width }}px solid {{ options.submenu_sub_arrow_border_colour }} !important;
|
638 |
+
border-right:unset !important;
|
639 |
+
{% endif %}
|
640 |
background-color: {{ options.submenu_sub_arrow_background_colour }};
|
641 |
}
|
642 |
|
public/img/banner.jpg
ADDED
Binary file
|
public/img/banner.png
ADDED
Binary file
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
=== Responsive Menu ===
|
2 |
-
Contributors:
|
3 |
-
Tags: responsive, menu, navigation, mobile, hamburger
|
4 |
Requires at least: 3.6
|
5 |
-
Tested up to: 5.
|
6 |
-
Stable tag: 3.1.
|
7 |
Requires PHP: 5.5
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -111,6 +111,12 @@ To view our FAQ, please go to [https://responsive.menu/faq/](https://responsive.
|
|
111 |
|
112 |
== Changelog ==
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
= 3.1.24 (14th Aug 2019) =
|
115 |
* Allow support for PHP 5.5 again.
|
116 |
* Downgrade Twig back to 1.33.0 as it doesn't play nicely with other plugins.
|
1 |
+
=== Responsive Menu - Create Mobile-Friendly Menu ===
|
2 |
+
Contributors: expresstech,responsivemenu
|
3 |
+
Tags: responsive, menu, navigation, mobile, hamburger, mobile menu, responsive menu
|
4 |
Requires at least: 3.6
|
5 |
+
Tested up to: 5.3.2
|
6 |
+
Stable tag: 3.1.25
|
7 |
Requires PHP: 5.5
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
111 |
|
112 |
== Changelog ==
|
113 |
|
114 |
+
= 3.1.25 (14th Dec 2019) =
|
115 |
+
* Fix: Sub Menus -> Text Alignment Option does not work
|
116 |
+
* Fix: Trigger Icon Position
|
117 |
+
* Fix: Trigger Icon Border CSS code
|
118 |
+
* Fix: Menu Text goes under Trigger Icon
|
119 |
+
|
120 |
= 3.1.24 (14th Aug 2019) =
|
121 |
* Allow support for PHP 5.5 again.
|
122 |
* Downgrade Twig back to 1.33.0 as it doesn't play nicely with other plugins.
|
responsive-menu.php
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
|
3 |
/*
|
4 |
Plugin Name: Responsive Menu
|
5 |
-
Plugin URI: https://
|
6 |
Description: Highly Customisable Responsive Menu Plugin for WordPress
|
7 |
-
Version: 3.1.
|
8 |
-
Author:
|
9 |
Text Domain: responsive-menu
|
10 |
Author URI: https://responsive.menu
|
11 |
License: GPL2
|
12 |
-
Tags: responsive, menu, responsive menu
|
13 |
*/
|
14 |
|
15 |
add_action('admin_init', 'check_responsive_menu_php_version');
|
@@ -32,6 +32,35 @@ function responsive_menu_deactivation_text() {
|
|
32 |
if(version_compare(PHP_VERSION, '5.4', '<'))
|
33 |
return;
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
include dirname(__FILE__) . '/vendor/autoload.php';
|
36 |
include dirname(__FILE__) . '/config/default_options.php';
|
37 |
include dirname(__FILE__) . '/config/services.php';
|
2 |
|
3 |
/*
|
4 |
Plugin Name: Responsive Menu
|
5 |
+
Plugin URI: https://expresstech.io
|
6 |
Description: Highly Customisable Responsive Menu Plugin for WordPress
|
7 |
+
Version: 3.1.25
|
8 |
+
Author: ExpressTech
|
9 |
Text Domain: responsive-menu
|
10 |
Author URI: https://responsive.menu
|
11 |
License: GPL2
|
12 |
+
Tags: responsive, menu, responsive menu, mega menu, max mega menu, max menu
|
13 |
*/
|
14 |
|
15 |
add_action('admin_init', 'check_responsive_menu_php_version');
|
32 |
if(version_compare(PHP_VERSION, '5.4', '<'))
|
33 |
return;
|
34 |
|
35 |
+
add_action( 'admin_notices', 'og_pro_deactivate_pro_version_notice');
|
36 |
+
|
37 |
+
function og_pro_deactivate_pro_version_notice() {
|
38 |
+
if(get_transient('og-admin-notice-activation-pro')) {
|
39 |
+
?>
|
40 |
+
<div class="notice notice-error is-dismissible">
|
41 |
+
<p>Responsive Menu Pro has been deactivated<p/>
|
42 |
+
|
43 |
+
</div>
|
44 |
+
<?php
|
45 |
+
delete_transient('og-admin-notice-activation-pro');
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
function og_deactivate_responsive_menu_pro() {
|
50 |
+
|
51 |
+
$plugin = 'responsive-menu-pro/responsive-menu-pro.php';
|
52 |
+
|
53 |
+
if( is_plugin_active($plugin) ){
|
54 |
+
deactivate_plugins( 'responsive-menu-pro/responsive-menu-pro.php');
|
55 |
+
set_transient( 'og-admin-notice-activation-pro', true, 5 );
|
56 |
+
|
57 |
+
return;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
//to check weather another plugin is acivated or not.
|
61 |
+
register_activation_hook( __FILE__, 'og_deactivate_responsive_menu_pro');
|
62 |
+
|
63 |
+
|
64 |
include dirname(__FILE__) . '/vendor/autoload.php';
|
65 |
include dirname(__FILE__) . '/config/default_options.php';
|
66 |
include dirname(__FILE__) . '/config/services.php';
|
vendor/composer/autoload_files.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// autoload_files.php @generated by Composer
|
4 |
+
|
5 |
+
$vendorDir = dirname(dirname(__FILE__));
|
6 |
+
$baseDir = dirname($vendorDir);
|
7 |
+
|
8 |
+
return array(
|
9 |
+
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
|
10 |
+
);
|
vendor/symfony/polyfill-ctype/Ctype.php
ADDED
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of the Symfony package.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier <fabien@symfony.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Symfony\Polyfill\Ctype;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Ctype implementation through regex.
|
16 |
+
*
|
17 |
+
* @internal
|
18 |
+
*
|
19 |
+
* @author Gert de Pagter <BackEndTea@gmail.com>
|
20 |
+
*/
|
21 |
+
final class Ctype
|
22 |
+
{
|
23 |
+
/**
|
24 |
+
* Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
|
25 |
+
*
|
26 |
+
* @see https://php.net/ctype-alnum
|
27 |
+
*
|
28 |
+
* @param string|int $text
|
29 |
+
*
|
30 |
+
* @return bool
|
31 |
+
*/
|
32 |
+
public static function ctype_alnum($text)
|
33 |
+
{
|
34 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
35 |
+
|
36 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Returns TRUE if every character in text is a letter, FALSE otherwise.
|
41 |
+
*
|
42 |
+
* @see https://php.net/ctype-alpha
|
43 |
+
*
|
44 |
+
* @param string|int $text
|
45 |
+
*
|
46 |
+
* @return bool
|
47 |
+
*/
|
48 |
+
public static function ctype_alpha($text)
|
49 |
+
{
|
50 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
51 |
+
|
52 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
|
57 |
+
*
|
58 |
+
* @see https://php.net/ctype-cntrl
|
59 |
+
*
|
60 |
+
* @param string|int $text
|
61 |
+
*
|
62 |
+
* @return bool
|
63 |
+
*/
|
64 |
+
public static function ctype_cntrl($text)
|
65 |
+
{
|
66 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
67 |
+
|
68 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
|
73 |
+
*
|
74 |
+
* @see https://php.net/ctype-digit
|
75 |
+
*
|
76 |
+
* @param string|int $text
|
77 |
+
*
|
78 |
+
* @return bool
|
79 |
+
*/
|
80 |
+
public static function ctype_digit($text)
|
81 |
+
{
|
82 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
83 |
+
|
84 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
|
89 |
+
*
|
90 |
+
* @see https://php.net/ctype-graph
|
91 |
+
*
|
92 |
+
* @param string|int $text
|
93 |
+
*
|
94 |
+
* @return bool
|
95 |
+
*/
|
96 |
+
public static function ctype_graph($text)
|
97 |
+
{
|
98 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
99 |
+
|
100 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Returns TRUE if every character in text is a lowercase letter.
|
105 |
+
*
|
106 |
+
* @see https://php.net/ctype-lower
|
107 |
+
*
|
108 |
+
* @param string|int $text
|
109 |
+
*
|
110 |
+
* @return bool
|
111 |
+
*/
|
112 |
+
public static function ctype_lower($text)
|
113 |
+
{
|
114 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
115 |
+
|
116 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
|
121 |
+
*
|
122 |
+
* @see https://php.net/ctype-print
|
123 |
+
*
|
124 |
+
* @param string|int $text
|
125 |
+
*
|
126 |
+
* @return bool
|
127 |
+
*/
|
128 |
+
public static function ctype_print($text)
|
129 |
+
{
|
130 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
131 |
+
|
132 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
|
137 |
+
*
|
138 |
+
* @see https://php.net/ctype-punct
|
139 |
+
*
|
140 |
+
* @param string|int $text
|
141 |
+
*
|
142 |
+
* @return bool
|
143 |
+
*/
|
144 |
+
public static function ctype_punct($text)
|
145 |
+
{
|
146 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
147 |
+
|
148 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
|
153 |
+
*
|
154 |
+
* @see https://php.net/ctype-space
|
155 |
+
*
|
156 |
+
* @param string|int $text
|
157 |
+
*
|
158 |
+
* @return bool
|
159 |
+
*/
|
160 |
+
public static function ctype_space($text)
|
161 |
+
{
|
162 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
163 |
+
|
164 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Returns TRUE if every character in text is an uppercase letter.
|
169 |
+
*
|
170 |
+
* @see https://php.net/ctype-upper
|
171 |
+
*
|
172 |
+
* @param string|int $text
|
173 |
+
*
|
174 |
+
* @return bool
|
175 |
+
*/
|
176 |
+
public static function ctype_upper($text)
|
177 |
+
{
|
178 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
179 |
+
|
180 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
|
185 |
+
*
|
186 |
+
* @see https://php.net/ctype-xdigit
|
187 |
+
*
|
188 |
+
* @param string|int $text
|
189 |
+
*
|
190 |
+
* @return bool
|
191 |
+
*/
|
192 |
+
public static function ctype_xdigit($text)
|
193 |
+
{
|
194 |
+
$text = self::convert_int_to_char_for_ctype($text);
|
195 |
+
|
196 |
+
return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Converts integers to their char versions according to normal ctype behaviour, if needed.
|
201 |
+
*
|
202 |
+
* If an integer between -128 and 255 inclusive is provided,
|
203 |
+
* it is interpreted as the ASCII value of a single character
|
204 |
+
* (negative values have 256 added in order to allow characters in the Extended ASCII range).
|
205 |
+
* Any other integer is interpreted as a string containing the decimal digits of the integer.
|
206 |
+
*
|
207 |
+
* @param string|int $int
|
208 |
+
*
|
209 |
+
* @return mixed
|
210 |
+
*/
|
211 |
+
private static function convert_int_to_char_for_ctype($int)
|
212 |
+
{
|
213 |
+
if (!\is_int($int)) {
|
214 |
+
return $int;
|
215 |
+
}
|
216 |
+
|
217 |
+
if ($int < -128 || $int > 255) {
|
218 |
+
return (string) $int;
|
219 |
+
}
|
220 |
+
|
221 |
+
if ($int < 0) {
|
222 |
+
$int += 256;
|
223 |
+
}
|
224 |
+
|
225 |
+
return \chr($int);
|
226 |
+
}
|
227 |
+
}
|
vendor/symfony/polyfill-ctype/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright (c) 2018-2019 Fabien Potencier
|
2 |
+
|
3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4 |
+
of this software and associated documentation files (the "Software"), to deal
|
5 |
+
in the Software without restriction, including without limitation the rights
|
6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7 |
+
copies of the Software, and to permit persons to whom the Software is furnished
|
8 |
+
to do so, subject to the following conditions:
|
9 |
+
|
10 |
+
The above copyright notice and this permission notice shall be included in all
|
11 |
+
copies or substantial portions of the Software.
|
12 |
+
|
13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19 |
+
THE SOFTWARE.
|
vendor/symfony/polyfill-ctype/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Symfony Polyfill / Ctype
|
2 |
+
========================
|
3 |
+
|
4 |
+
This component provides `ctype_*` functions to users who run php versions without the ctype extension.
|
5 |
+
|
6 |
+
More information can be found in the
|
7 |
+
[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md).
|
8 |
+
|
9 |
+
License
|
10 |
+
=======
|
11 |
+
|
12 |
+
This library is released under the [MIT license](LICENSE).
|
vendor/symfony/polyfill-ctype/bootstrap.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of the Symfony package.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier <fabien@symfony.com>
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
use Symfony\Polyfill\Ctype as p;
|
13 |
+
|
14 |
+
if (!function_exists('ctype_alnum')) {
|
15 |
+
function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); }
|
16 |
+
function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); }
|
17 |
+
function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); }
|
18 |
+
function ctype_digit($text) { return p\Ctype::ctype_digit($text); }
|
19 |
+
function ctype_graph($text) { return p\Ctype::ctype_graph($text); }
|
20 |
+
function ctype_lower($text) { return p\Ctype::ctype_lower($text); }
|
21 |
+
function ctype_print($text) { return p\Ctype::ctype_print($text); }
|
22 |
+
function ctype_punct($text) { return p\Ctype::ctype_punct($text); }
|
23 |
+
function ctype_space($text) { return p\Ctype::ctype_space($text); }
|
24 |
+
function ctype_upper($text) { return p\Ctype::ctype_upper($text); }
|
25 |
+
function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); }
|
26 |
+
}
|
vendor/symfony/polyfill-ctype/composer.json
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "symfony/polyfill-ctype",
|
3 |
+
"type": "library",
|
4 |
+
"description": "Symfony polyfill for ctype functions",
|
5 |
+
"keywords": ["polyfill", "compatibility", "portable", "ctype"],
|
6 |
+
"homepage": "https://symfony.com",
|
7 |
+
"license": "MIT",
|
8 |
+
"authors": [
|
9 |
+
{
|
10 |
+
"name": "Gert de Pagter",
|
11 |
+
"email": "BackEndTea@gmail.com"
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"name": "Symfony Community",
|
15 |
+
"homepage": "https://symfony.com/contributors"
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"require": {
|
19 |
+
"php": ">=5.3.3"
|
20 |
+
},
|
21 |
+
"autoload": {
|
22 |
+
"psr-4": { "Symfony\\Polyfill\\Ctype\\": "" },
|
23 |
+
"files": [ "bootstrap.php" ]
|
24 |
+
},
|
25 |
+
"suggest": {
|
26 |
+
"ext-ctype": "For best performance"
|
27 |
+
},
|
28 |
+
"minimum-stability": "dev",
|
29 |
+
"extra": {
|
30 |
+
"branch-alias": {
|
31 |
+
"dev-master": "1.12-dev"
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
vendor/twig/twig/.gitignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/build
|
2 |
+
/composer.lock
|
3 |
+
/ext/twig/autom4te.cache/
|
4 |
+
/phpunit.xml
|
5 |
+
/vendor
|
vendor/twig/twig/doc/filters/filter.rst
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
``filter``
|
2 |
+
=========
|
3 |
+
|
4 |
+
.. versionadded:: 1.41
|
5 |
+
The ``filter`` filter was added in Twig 1.41 and 2.10.
|
6 |
+
|
7 |
+
The ``filter`` filter filters elements of a sequence or a mapping using an arrow
|
8 |
+
function. The arrow function receives the value of the sequence or mapping:
|
9 |
+
|
10 |
+
.. code-block:: twig
|
11 |
+
|
12 |
+
{% set sizes = [34, 36, 38, 40, 42] %}
|
13 |
+
|
14 |
+
{{ sizes|filter(v => v > 38)|join(', ') }}
|
15 |
+
{# output 40, 42 #}
|
16 |
+
|
17 |
+
Combined with the ``for`` tag, it allows to filter the items to iterate over:
|
18 |
+
|
19 |
+
.. code-block:: twig
|
20 |
+
|
21 |
+
{% for v in sizes|filter(v => v > 38) -%}
|
22 |
+
{{ v }}
|
23 |
+
{% endfor %}
|
24 |
+
{# output 40 42 #}
|
25 |
+
|
26 |
+
It also works with mappings:
|
27 |
+
|
28 |
+
.. code-block:: twig
|
29 |
+
|
30 |
+
{% set sizes = {
|
31 |
+
xs: 34,
|
32 |
+
s: 36,
|
33 |
+
m: 38,
|
34 |
+
l: 40,
|
35 |
+
xl: 42,
|
36 |
+
} %}
|
37 |
+
|
38 |
+
{% for k, v in sizes|filter(v => v > 38) -%}
|
39 |
+
{{ k }} = {{ v }}
|
40 |
+
{% endfor %}
|
41 |
+
{# output l = 40 xl = 42 #}
|
42 |
+
|
43 |
+
The arrow function also receives the key as a second argument:
|
44 |
+
|
45 |
+
.. code-block:: twig
|
46 |
+
|
47 |
+
{% for k, v in sizes|filter((v, k) => v > 38 and k != "xl") -%}
|
48 |
+
{{ k }} = {{ v }}
|
49 |
+
{% endfor %}
|
50 |
+
{# output l = 40 #}
|
51 |
+
|
52 |
+
Note that the arrow function has access to the current context.
|
53 |
+
|
54 |
+
Arguments
|
55 |
+
---------
|
56 |
+
|
57 |
+
* ``array``: The sequence or mapping
|
58 |
+
* ``arrow``: The arrow function
|
vendor/twig/twig/doc/filters/map.rst
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
``map``
|
2 |
+
=======
|
3 |
+
|
4 |
+
.. versionadded:: 1.41
|
5 |
+
The ``map`` filter was added in Twig 1.41 and 2.10.
|
6 |
+
|
7 |
+
The ``map`` filter applies an arrow function to the elements of a sequence or a
|
8 |
+
mapping. The arrow function receives the value of the sequence or mapping:
|
9 |
+
|
10 |
+
.. code-block:: twig
|
11 |
+
|
12 |
+
{% set people = [
|
13 |
+
{first: "Bob", last: "Smith"},
|
14 |
+
{first: "Alice", last: "Dupond"},
|
15 |
+
] %}
|
16 |
+
|
17 |
+
{{ people|map(p => "#{p.first} #{p.last}")|join(', ') }}
|
18 |
+
{# outputs Bob Smith, Alice Dupond #}
|
19 |
+
|
20 |
+
The arrow function also receives the key as a second argument:
|
21 |
+
|
22 |
+
.. code-block:: twig
|
23 |
+
|
24 |
+
{% set people = {
|
25 |
+
"Bob": "Smith",
|
26 |
+
"Alice": "Dupond",
|
27 |
+
} %}
|
28 |
+
|
29 |
+
{{ people|map((first, last) => "#{first} #{last}")|join(', ') }}
|
30 |
+
{# outputs Bob Smith, Alice Dupond #}
|
31 |
+
|
32 |
+
Note that the arrow function has access to the current context.
|
33 |
+
|
34 |
+
Arguments
|
35 |
+
---------
|
36 |
+
|
37 |
+
* ``array``: The sequence or mapping
|
38 |
+
* ``arrow``: The arrow function
|
vendor/twig/twig/doc/filters/reduce.rst
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
``reduce``
|
2 |
+
=========
|
3 |
+
|
4 |
+
.. versionadded:: 1.41
|
5 |
+
The ``reduce`` filter was added in Twig 1.41 and 2.10.
|
6 |
+
|
7 |
+
The ``reduce`` filter iteratively reduces a sequence or a mapping to a single
|
8 |
+
value using an arrow function, so as to reduce it to a single value. The arrow
|
9 |
+
function receives the return value of the previous iteration and the current
|
10 |
+
value of the sequence or mapping:
|
11 |
+
|
12 |
+
.. code-block:: twig
|
13 |
+
|
14 |
+
{% set numbers = [1, 2, 3] %}
|
15 |
+
|
16 |
+
{{ numbers|reduce((carry, v) => carry + v) }}
|
17 |
+
{# output 6 #}
|
18 |
+
|
19 |
+
The ``reduce`` filter takes an ``initial`` value as a second argument:
|
20 |
+
|
21 |
+
.. code-block:: twig
|
22 |
+
|
23 |
+
{{ numbers|reduce((carry, v) => carry + v, 10) }}
|
24 |
+
{# output 16 #}
|
25 |
+
|
26 |
+
Note that the arrow function has access to the current context.
|
27 |
+
|
28 |
+
Arguments
|
29 |
+
---------
|
30 |
+
|
31 |
+
* ``array``: The sequence or mapping
|
32 |
+
* ``arrow``: The arrow function
|
33 |
+
* ``initial``: The initial value
|
vendor/twig/twig/doc/filters/spaceless.rst
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
``spaceless``
|
2 |
+
=============
|
3 |
+
|
4 |
+
.. versionadded:: 1.38
|
5 |
+
|
6 |
+
The ``spaceless`` filter was added in Twig 1.38.
|
7 |
+
|
8 |
+
Use the ``spaceless`` filter to remove whitespace *between HTML tags*, not
|
9 |
+
whitespace within HTML tags or whitespace in plain text:
|
10 |
+
|
11 |
+
.. code-block:: twig
|
12 |
+
|
13 |
+
{{
|
14 |
+
"<div>
|
15 |
+
<strong>foo</strong>
|
16 |
+
</div>
|
17 |
+
"|spaceless }}
|
18 |
+
|
19 |
+
{# output will be <div><strong>foo</strong></div> #}
|
20 |
+
|
21 |
+
You can combine ``spaceless`` with the ``apply`` tag to apply the transformation
|
22 |
+
on large amounts of HTML:
|
23 |
+
|
24 |
+
.. code-block:: twig
|
25 |
+
|
26 |
+
{% apply spaceless %}
|
27 |
+
<div>
|
28 |
+
<strong>foo</strong>
|
29 |
+
</div>
|
30 |
+
{% endapply %}
|
31 |
+
|
32 |
+
{# output will be <div><strong>foo</strong></div> #}
|
33 |
+
|
34 |
+
.. note::
|
35 |
+
|
36 |
+
The ``apply`` tag was introduced in Twig 1.40; use the ``filter`` tag with
|
37 |
+
previous versions.
|
38 |
+
|
39 |
+
This tag is not meant to "optimize" the size of the generated HTML content but
|
40 |
+
merely to avoid extra whitespace between HTML tags to avoid browser rendering
|
41 |
+
quirks under some circumstances.
|
42 |
+
|
43 |
+
.. caution::
|
44 |
+
|
45 |
+
As the filter uses a regular expression behind the scenes, its performance
|
46 |
+
is directly related to the text size you are working on (remember that
|
47 |
+
filters are executed at runtime).
|
48 |
+
|
49 |
+
.. tip::
|
50 |
+
|
51 |
+
If you want to optimize the size of the generated HTML content, gzip
|
52 |
+
compress the output instead.
|
53 |
+
|
54 |
+
.. tip::
|
55 |
+
|
56 |
+
If you want to create a tag that actually removes all extra whitespace in
|
57 |
+
an HTML string, be warned that this is not as easy as it seems to be
|
58 |
+
(think of ``textarea`` or ``pre`` tags for instance). Using a third-party
|
59 |
+
library like Tidy is probably a better idea.
|
60 |
+
|
61 |
+
.. tip::
|
62 |
+
|
63 |
+
For more information on whitespace control, read the
|
64 |
+
:ref:`dedicated section <templates-whitespace-control>` of the documentation and learn how
|
65 |
+
you can also use the whitespace control modifier on your tags.
|
vendor/twig/twig/doc/tags/apply.rst
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
``apply``
|
2 |
+
=========
|
3 |
+
|
4 |
+
.. versionadded:: 1.40
|
5 |
+
The ``apply`` tag was added in Twig 1.40.
|
6 |
+
|
7 |
+
The ``apply`` tag allows you to apply Twig filters on a block of template data:
|
8 |
+
|
9 |
+
.. code-block:: twig
|
10 |
+
|
11 |
+
{% apply upper %}
|
12 |
+
This text becomes uppercase
|
13 |
+
{% endapply %}
|
14 |
+
|
15 |
+
You can also chain filters and pass arguments to them:
|
16 |
+
|
17 |
+
.. code-block:: twig
|
18 |
+
|
19 |
+
{% apply lower|escape('html') %}
|
20 |
+
<strong>SOME TEXT</strong>
|
21 |
+
{% endapply %}
|
22 |
+
|
23 |
+
{# outputs "<strong>some text</strong>" #}
|
vendor/twig/twig/doc/tags/deprecated.rst
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
``deprecated``
|
2 |
+
==============
|
3 |
+
|
4 |
+
.. versionadded:: 1.36 and 2.6
|
5 |
+
The ``deprecated`` tag was added in Twig 1.36 and 2.6.
|
6 |
+
|
7 |
+
Twig generates a deprecation notice (via a call to the ``trigger_error()``
|
8 |
+
PHP function) where the ``deprecated`` tag is used in a template:
|
9 |
+
|
10 |
+
.. code-block:: twig
|
11 |
+
|
12 |
+
{# base.twig #}
|
13 |
+
{% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %}
|
14 |
+
{% extends 'layout.twig' %}
|
15 |
+
|
16 |
+
Also you can deprecate a block in the following way:
|
17 |
+
|
18 |
+
.. code-block:: twig
|
19 |
+
|
20 |
+
{% block hey %}
|
21 |
+
{% deprecated 'The "hey" block is deprecated, use "greet" instead.' %}
|
22 |
+
{{ block('greet') }}
|
23 |
+
{% endblock %}
|
24 |
+
|
25 |
+
{% block greet %}
|
26 |
+
Hey you!
|
27 |
+
{% endblock %}
|
28 |
+
|
29 |
+
Note that by default, the deprecation notices are silenced and never displayed nor logged.
|
30 |
+
See :ref:`deprecation-notices` to learn how to handle them.
|
vendor/twig/twig/drupal_test.sh
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
set -x
|
4 |
+
set -e
|
5 |
+
|
6 |
+
REPO=`pwd`
|
7 |
+
cd /tmp
|
8 |
+
rm -rf drupal-twig-test
|
9 |
+
composer create-project --no-interaction drupal-composer/drupal-project:8.x-dev drupal-twig-test
|
10 |
+
cd drupal-twig-test
|
11 |
+
(cd vendor/twig && rm -rf twig && ln -sf $REPO twig)
|
12 |
+
echo '$config["system.logging"]["error_level"] = "verbose";' >> web/sites/default/settings.php
|
13 |
+
php ./web/core/scripts/drupal install --no-interaction demo_umami > output
|
14 |
+
perl -p -i -e 's/^([A-Za-z]+)\: (.+)$/export DRUPAL_\1=\2/' output
|
15 |
+
source output
|
16 |
+
|
17 |
+
wget https://get.symfony.com/cli/installer -O - | bash
|
18 |
+
export PATH="$HOME/.symfony/bin:$PATH"
|
19 |
+
symfony server:start -d --no-tls
|
20 |
+
ENDPOINT=`symfony server:status -no-ansi | sed -E 's/^.+ http/http/'`
|
21 |
+
|
22 |
+
curl -OLsS https://get.blackfire.io/blackfire-player.phar
|
23 |
+
chmod +x blackfire-player.phar
|
24 |
+
cat > drupal-tests.bkf <<EOF
|
25 |
+
name "Drupal tests"
|
26 |
+
|
27 |
+
scenario
|
28 |
+
name "homepage"
|
29 |
+
set name "admin"
|
30 |
+
set pass "pass"
|
31 |
+
|
32 |
+
visit url('/')
|
33 |
+
expect status_code() == 200
|
34 |
+
click link('Articles')
|
35 |
+
expect status_code() == 200
|
36 |
+
click link('Dairy-free and delicious milk chocolate')
|
37 |
+
expect body() matches "/Dairy\-free milk chocolate is made in largely the same way as regular chocolate/"
|
38 |
+
expect status_code() == 200
|
39 |
+
click link('Log in')
|
40 |
+
expect status_code() == 200
|
41 |
+
submit button("Log in")
|
42 |
+
param name name
|
43 |
+
param pass pass
|
44 |
+
expect status_code() == 303
|
45 |
+
follow
|
46 |
+
expect status_code() == 200
|
47 |
+
click link('Structure')
|
48 |
+
expect status_code() == 200
|
49 |
+
EOF
|
50 |
+
./blackfire-player.phar run drupal-tests.bkf --endpoint=$ENDPOINT --variable name=$DRUPAL_Username --variable pass=$DRUPAL_Password
|
51 |
+
symfony server:stop
|
vendor/twig/twig/ext/twig/.gitignore
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.sw*
|
2 |
+
.deps
|
3 |
+
Makefile
|
4 |
+
Makefile.fragments
|
5 |
+
Makefile.global
|
6 |
+
Makefile.objects
|
7 |
+
acinclude.m4
|
8 |
+
aclocal.m4
|
9 |
+
build/
|
10 |
+
config.cache
|
11 |
+
config.guess
|
12 |
+
config.h
|
13 |
+
config.h.in
|
14 |
+
config.log
|
15 |
+
config.nice
|
16 |
+
config.status
|
17 |
+
config.sub
|
18 |
+
configure
|
19 |
+
configure.in
|
20 |
+
install-sh
|
21 |
+
libtool
|
22 |
+
ltmain.sh
|
23 |
+
missing
|
24 |
+
mkinstalldirs
|
25 |
+
run-tests.php
|
26 |
+
twig.loT
|
27 |
+
.libs/
|
28 |
+
modules/
|
29 |
+
twig.la
|
30 |
+
twig.lo
|
vendor/twig/twig/lib/Twig/Node/Deprecated.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
use Twig\Node\DeprecatedNode;
|
4 |
+
|
5 |
+
class_exists('Twig\Node\DeprecatedNode');
|
6 |
+
|
7 |
+
if (\false) {
|
8 |
+
class Twig_Node_Deprecated extends DeprecatedNode
|
9 |
+
{
|
10 |
+
}
|
11 |
+
}
|
vendor/twig/twig/lib/Twig/Profiler/Dumper/Base.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
use Twig\Profiler\Dumper\BaseDumper;
|
4 |
+
|
5 |
+
class_exists('Twig\Profiler\Dumper\BaseDumper');
|
6 |
+
|
7 |
+
if (\false) {
|
8 |
+
class Twig_Profiler_Dumper_Base extends BaseDumper
|
9 |
+
{
|
10 |
+
}
|
11 |
+
}
|
vendor/twig/twig/lib/Twig/TokenParser/Deprecated.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
use Twig\TokenParser\DeprecatedTokenParser;
|
4 |
+
|
5 |
+
class_exists('Twig\TokenParser\DeprecatedTokenParser');
|
6 |
+
|
7 |
+
if (\false) {
|
8 |
+
class Twig_TokenParser_Deprecated extends DeprecatedTokenParser
|
9 |
+
{
|
10 |
+
}
|
11 |
+
}
|
vendor/twig/twig/src/Cache/CacheInterface.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Cache;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Interface implemented by cache classes.
|
16 |
+
*
|
17 |
+
* It is highly recommended to always store templates on the filesystem to
|
18 |
+
* benefit from the PHP opcode cache. This interface is mostly useful if you
|
19 |
+
* need to implement a custom strategy for storing templates on the filesystem.
|
20 |
+
*
|
21 |
+
* @author Andrew Tch <andrew@noop.lv>
|
22 |
+
*/
|
23 |
+
interface CacheInterface
|
24 |
+
{
|
25 |
+
/**
|
26 |
+
* Generates a cache key for the given template class name.
|
27 |
+
*
|
28 |
+
* @param string $name The template name
|
29 |
+
* @param string $className The template class name
|
30 |
+
*
|
31 |
+
* @return string
|
32 |
+
*/
|
33 |
+
public function generateKey($name, $className);
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Writes the compiled template to cache.
|
37 |
+
*
|
38 |
+
* @param string $key The cache key
|
39 |
+
* @param string $content The template representation as a PHP class
|
40 |
+
*/
|
41 |
+
public function write($key, $content);
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Loads a template from the cache.
|
45 |
+
*
|
46 |
+
* @param string $key The cache key
|
47 |
+
*/
|
48 |
+
public function load($key);
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Returns the modification timestamp of a key.
|
52 |
+
*
|
53 |
+
* @param string $key The cache key
|
54 |
+
*
|
55 |
+
* @return int
|
56 |
+
*/
|
57 |
+
public function getTimestamp($key);
|
58 |
+
}
|
59 |
+
|
60 |
+
class_alias('Twig\Cache\CacheInterface', 'Twig_CacheInterface');
|
vendor/twig/twig/src/Cache/FilesystemCache.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Cache;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Implements a cache on the filesystem.
|
16 |
+
*
|
17 |
+
* @author Andrew Tch <andrew@noop.lv>
|
18 |
+
*/
|
19 |
+
class FilesystemCache implements CacheInterface
|
20 |
+
{
|
21 |
+
const FORCE_BYTECODE_INVALIDATION = 1;
|
22 |
+
|
23 |
+
private $directory;
|
24 |
+
private $options;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @param string $directory The root cache directory
|
28 |
+
* @param int $options A set of options
|
29 |
+
*/
|
30 |
+
public function __construct($directory, $options = 0)
|
31 |
+
{
|
32 |
+
$this->directory = rtrim($directory, '\/').'/';
|
33 |
+
$this->options = $options;
|
34 |
+
}
|
35 |
+
|
36 |
+
public function generateKey($name, $className)
|
37 |
+
{
|
38 |
+
$hash = hash('sha256', $className);
|
39 |
+
|
40 |
+
return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
|
41 |
+
}
|
42 |
+
|
43 |
+
public function load($key)
|
44 |
+
{
|
45 |
+
if (file_exists($key)) {
|
46 |
+
@include_once $key;
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
public function write($key, $content)
|
51 |
+
{
|
52 |
+
$dir = \dirname($key);
|
53 |
+
if (!is_dir($dir)) {
|
54 |
+
if (false === @mkdir($dir, 0777, true)) {
|
55 |
+
clearstatcache(true, $dir);
|
56 |
+
if (!is_dir($dir)) {
|
57 |
+
throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
|
58 |
+
}
|
59 |
+
}
|
60 |
+
} elseif (!is_writable($dir)) {
|
61 |
+
throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
|
62 |
+
}
|
63 |
+
|
64 |
+
$tmpFile = tempnam($dir, basename($key));
|
65 |
+
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
|
66 |
+
@chmod($key, 0666 & ~umask());
|
67 |
+
|
68 |
+
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
|
69 |
+
// Compile cached file into bytecode cache
|
70 |
+
if (\function_exists('opcache_invalidate')) {
|
71 |
+
opcache_invalidate($key, true);
|
72 |
+
} elseif (\function_exists('apc_compile_file')) {
|
73 |
+
apc_compile_file($key);
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
return;
|
78 |
+
}
|
79 |
+
|
80 |
+
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $key));
|
81 |
+
}
|
82 |
+
|
83 |
+
public function getTimestamp($key)
|
84 |
+
{
|
85 |
+
if (!file_exists($key)) {
|
86 |
+
return 0;
|
87 |
+
}
|
88 |
+
|
89 |
+
return (int) @filemtime($key);
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
class_alias('Twig\Cache\FilesystemCache', 'Twig_Cache_Filesystem');
|
vendor/twig/twig/src/Cache/NullCache.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Cache;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Implements a no-cache strategy.
|
16 |
+
*
|
17 |
+
* @final
|
18 |
+
*
|
19 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
20 |
+
*/
|
21 |
+
class NullCache implements CacheInterface
|
22 |
+
{
|
23 |
+
public function generateKey($name, $className)
|
24 |
+
{
|
25 |
+
return '';
|
26 |
+
}
|
27 |
+
|
28 |
+
public function write($key, $content)
|
29 |
+
{
|
30 |
+
}
|
31 |
+
|
32 |
+
public function load($key)
|
33 |
+
{
|
34 |
+
}
|
35 |
+
|
36 |
+
public function getTimestamp($key)
|
37 |
+
{
|
38 |
+
return 0;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
class_alias('Twig\Cache\NullCache', 'Twig_Cache_Null');
|
vendor/twig/twig/src/Compiler.php
ADDED
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
* (c) Armin Ronacher
|
8 |
+
*
|
9 |
+
* For the full copyright and license information, please view the LICENSE
|
10 |
+
* file that was distributed with this source code.
|
11 |
+
*/
|
12 |
+
|
13 |
+
namespace Twig;
|
14 |
+
|
15 |
+
use Twig\Node\ModuleNode;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Compiles a node to PHP code.
|
19 |
+
*
|
20 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
21 |
+
*/
|
22 |
+
class Compiler implements \Twig_CompilerInterface
|
23 |
+
{
|
24 |
+
protected $lastLine;
|
25 |
+
protected $source;
|
26 |
+
protected $indentation;
|
27 |
+
protected $env;
|
28 |
+
protected $debugInfo = [];
|
29 |
+
protected $sourceOffset;
|
30 |
+
protected $sourceLine;
|
31 |
+
protected $filename;
|
32 |
+
private $varNameSalt = 0;
|
33 |
+
|
34 |
+
public function __construct(Environment $env)
|
35 |
+
{
|
36 |
+
$this->env = $env;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @deprecated since 1.25 (to be removed in 2.0)
|
41 |
+
*/
|
42 |
+
public function getFilename()
|
43 |
+
{
|
44 |
+
@trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
|
45 |
+
|
46 |
+
return $this->filename;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Returns the environment instance related to this compiler.
|
51 |
+
*
|
52 |
+
* @return Environment
|
53 |
+
*/
|
54 |
+
public function getEnvironment()
|
55 |
+
{
|
56 |
+
return $this->env;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Gets the current PHP code after compilation.
|
61 |
+
*
|
62 |
+
* @return string The PHP code
|
63 |
+
*/
|
64 |
+
public function getSource()
|
65 |
+
{
|
66 |
+
return $this->source;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Compiles a node.
|
71 |
+
*
|
72 |
+
* @param int $indentation The current indentation
|
73 |
+
*
|
74 |
+
* @return $this
|
75 |
+
*/
|
76 |
+
public function compile(\Twig_NodeInterface $node, $indentation = 0)
|
77 |
+
{
|
78 |
+
$this->lastLine = null;
|
79 |
+
$this->source = '';
|
80 |
+
$this->debugInfo = [];
|
81 |
+
$this->sourceOffset = 0;
|
82 |
+
// source code starts at 1 (as we then increment it when we encounter new lines)
|
83 |
+
$this->sourceLine = 1;
|
84 |
+
$this->indentation = $indentation;
|
85 |
+
$this->varNameSalt = 0;
|
86 |
+
|
87 |
+
if ($node instanceof ModuleNode) {
|
88 |
+
// to be removed in 2.0
|
89 |
+
$this->filename = $node->getTemplateName();
|
90 |
+
}
|
91 |
+
|
92 |
+
$node->compile($this);
|
93 |
+
|
94 |
+
return $this;
|
95 |
+
}
|
96 |
+
|
97 |
+
public function subcompile(\Twig_NodeInterface $node, $raw = true)
|
98 |
+
{
|
99 |
+
if (false === $raw) {
|
100 |
+
$this->source .= str_repeat(' ', $this->indentation * 4);
|
101 |
+
}
|
102 |
+
|
103 |
+
$node->compile($this);
|
104 |
+
|
105 |
+
return $this;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Adds a raw string to the compiled code.
|
110 |
+
*
|
111 |
+
* @param string $string The string
|
112 |
+
*
|
113 |
+
* @return $this
|
114 |
+
*/
|
115 |
+
public function raw($string)
|
116 |
+
{
|
117 |
+
$this->source .= $string;
|
118 |
+
|
119 |
+
return $this;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Writes a string to the compiled code by adding indentation.
|
124 |
+
*
|
125 |
+
* @return $this
|
126 |
+
*/
|
127 |
+
public function write()
|
128 |
+
{
|
129 |
+
$strings = \func_get_args();
|
130 |
+
foreach ($strings as $string) {
|
131 |
+
$this->source .= str_repeat(' ', $this->indentation * 4).$string;
|
132 |
+
}
|
133 |
+
|
134 |
+
return $this;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Appends an indentation to the current PHP code after compilation.
|
139 |
+
*
|
140 |
+
* @return $this
|
141 |
+
*
|
142 |
+
* @deprecated since 1.27 (to be removed in 2.0).
|
143 |
+
*/
|
144 |
+
public function addIndentation()
|
145 |
+
{
|
146 |
+
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED);
|
147 |
+
|
148 |
+
$this->source .= str_repeat(' ', $this->indentation * 4);
|
149 |
+
|
150 |
+
return $this;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Adds a quoted string to the compiled code.
|
155 |
+
*
|
156 |
+
* @param string $value The string
|
157 |
+
*
|
158 |
+
* @return $this
|
159 |
+
*/
|
160 |
+
public function string($value)
|
161 |
+
{
|
162 |
+
$this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\"));
|
163 |
+
|
164 |
+
return $this;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Returns a PHP representation of a given value.
|
169 |
+
*
|
170 |
+
* @param mixed $value The value to convert
|
171 |
+
*
|
172 |
+
* @return $this
|
173 |
+
*/
|
174 |
+
public function repr($value)
|
175 |
+
{
|
176 |
+
if (\is_int($value) || \is_float($value)) {
|
177 |
+
if (false !== $locale = setlocale(LC_NUMERIC, '0')) {
|
178 |
+
setlocale(LC_NUMERIC, 'C');
|
179 |
+
}
|
180 |
+
|
181 |
+
$this->raw(var_export($value, true));
|
182 |
+
|
183 |
+
if (false !== $locale) {
|
184 |
+
setlocale(LC_NUMERIC, $locale);
|
185 |
+
}
|
186 |
+
} elseif (null === $value) {
|
187 |
+
$this->raw('null');
|
188 |
+
} elseif (\is_bool($value)) {
|
189 |
+
$this->raw($value ? 'true' : 'false');
|
190 |
+
} elseif (\is_array($value)) {
|
191 |
+
$this->raw('[');
|
192 |
+
$first = true;
|
193 |
+
foreach ($value as $key => $v) {
|
194 |
+
if (!$first) {
|
195 |
+
$this->raw(', ');
|
196 |
+
}
|
197 |
+
$first = false;
|
198 |
+
$this->repr($key);
|
199 |
+
$this->raw(' => ');
|
200 |
+
$this->repr($v);
|
201 |
+
}
|
202 |
+
$this->raw(']');
|
203 |
+
} else {
|
204 |
+
$this->string($value);
|
205 |
+
}
|
206 |
+
|
207 |
+
return $this;
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Adds debugging information.
|
212 |
+
*
|
213 |
+
* @return $this
|
214 |
+
*/
|
215 |
+
public function addDebugInfo(\Twig_NodeInterface $node)
|
216 |
+
{
|
217 |
+
if ($node->getTemplateLine() != $this->lastLine) {
|
218 |
+
$this->write(sprintf("// line %d\n", $node->getTemplateLine()));
|
219 |
+
|
220 |
+
// when mbstring.func_overload is set to 2
|
221 |
+
// mb_substr_count() replaces substr_count()
|
222 |
+
// but they have different signatures!
|
223 |
+
if (((int) ini_get('mbstring.func_overload')) & 2) {
|
224 |
+
@trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED);
|
225 |
+
|
226 |
+
// this is much slower than the "right" version
|
227 |
+
$this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n");
|
228 |
+
} else {
|
229 |
+
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
|
230 |
+
}
|
231 |
+
$this->sourceOffset = \strlen($this->source);
|
232 |
+
$this->debugInfo[$this->sourceLine] = $node->getTemplateLine();
|
233 |
+
|
234 |
+
$this->lastLine = $node->getTemplateLine();
|
235 |
+
}
|
236 |
+
|
237 |
+
return $this;
|
238 |
+
}
|
239 |
+
|
240 |
+
public function getDebugInfo()
|
241 |
+
{
|
242 |
+
ksort($this->debugInfo);
|
243 |
+
|
244 |
+
return $this->debugInfo;
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Indents the generated code.
|
249 |
+
*
|
250 |
+
* @param int $step The number of indentation to add
|
251 |
+
*
|
252 |
+
* @return $this
|
253 |
+
*/
|
254 |
+
public function indent($step = 1)
|
255 |
+
{
|
256 |
+
$this->indentation += $step;
|
257 |
+
|
258 |
+
return $this;
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Outdents the generated code.
|
263 |
+
*
|
264 |
+
* @param int $step The number of indentation to remove
|
265 |
+
*
|
266 |
+
* @return $this
|
267 |
+
*
|
268 |
+
* @throws \LogicException When trying to outdent too much so the indentation would become negative
|
269 |
+
*/
|
270 |
+
public function outdent($step = 1)
|
271 |
+
{
|
272 |
+
// can't outdent by more steps than the current indentation level
|
273 |
+
if ($this->indentation < $step) {
|
274 |
+
throw new \LogicException('Unable to call outdent() as the indentation would become negative.');
|
275 |
+
}
|
276 |
+
|
277 |
+
$this->indentation -= $step;
|
278 |
+
|
279 |
+
return $this;
|
280 |
+
}
|
281 |
+
|
282 |
+
public function getVarName()
|
283 |
+
{
|
284 |
+
return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++));
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
288 |
+
class_alias('Twig\Compiler', 'Twig_Compiler');
|
vendor/twig/twig/src/Environment.php
ADDED
@@ -0,0 +1,1638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig;
|
13 |
+
|
14 |
+
use Twig\Cache\CacheInterface;
|
15 |
+
use Twig\Cache\FilesystemCache;
|
16 |
+
use Twig\Cache\NullCache;
|
17 |
+
use Twig\Error\Error;
|
18 |
+
use Twig\Error\LoaderError;
|
19 |
+
use Twig\Error\RuntimeError;
|
20 |
+
use Twig\Error\SyntaxError;
|
21 |
+
use Twig\Extension\CoreExtension;
|
22 |
+
use Twig\Extension\EscaperExtension;
|
23 |
+
use Twig\Extension\ExtensionInterface;
|
24 |
+
use Twig\Extension\GlobalsInterface;
|
25 |
+
use Twig\Extension\InitRuntimeInterface;
|
26 |
+
use Twig\Extension\OptimizerExtension;
|
27 |
+
use Twig\Extension\StagingExtension;
|
28 |
+
use Twig\Loader\ArrayLoader;
|
29 |
+
use Twig\Loader\ChainLoader;
|
30 |
+
use Twig\Loader\LoaderInterface;
|
31 |
+
use Twig\Loader\SourceContextLoaderInterface;
|
32 |
+
use Twig\Node\ModuleNode;
|
33 |
+
use Twig\NodeVisitor\NodeVisitorInterface;
|
34 |
+
use Twig\RuntimeLoader\RuntimeLoaderInterface;
|
35 |
+
use Twig\TokenParser\TokenParserInterface;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Stores the Twig configuration.
|
39 |
+
*
|
40 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
41 |
+
*/
|
42 |
+
class Environment
|
43 |
+
{
|
44 |
+
const VERSION = '1.42.2';
|
45 |
+
const VERSION_ID = 14202;
|
46 |
+
const MAJOR_VERSION = 1;
|
47 |
+
const MINOR_VERSION = 42;
|
48 |
+
const RELEASE_VERSION = 2;
|
49 |
+
const EXTRA_VERSION = '';
|
50 |
+
|
51 |
+
protected $charset;
|
52 |
+
protected $loader;
|
53 |
+
protected $debug;
|
54 |
+
protected $autoReload;
|
55 |
+
protected $cache;
|
56 |
+
protected $lexer;
|
57 |
+
protected $parser;
|
58 |
+
protected $compiler;
|
59 |
+
protected $baseTemplateClass;
|
60 |
+
protected $extensions;
|
61 |
+
protected $parsers;
|
62 |
+
protected $visitors;
|
63 |
+
protected $filters;
|
64 |
+
protected $tests;
|
65 |
+
protected $functions;
|
66 |
+
protected $globals;
|
67 |
+
protected $runtimeInitialized = false;
|
68 |
+
protected $extensionInitialized = false;
|
69 |
+
protected $loadedTemplates;
|
70 |
+
protected $strictVariables;
|
71 |
+
protected $unaryOperators;
|
72 |
+
protected $binaryOperators;
|
73 |
+
protected $templateClassPrefix = '__TwigTemplate_';
|
74 |
+
protected $functionCallbacks = [];
|
75 |
+
protected $filterCallbacks = [];
|
76 |
+
protected $staging;
|
77 |
+
|
78 |
+
private $originalCache;
|
79 |
+
private $bcWriteCacheFile = false;
|
80 |
+
private $bcGetCacheFilename = false;
|
81 |
+
private $lastModifiedExtension = 0;
|
82 |
+
private $extensionsByClass = [];
|
83 |
+
private $runtimeLoaders = [];
|
84 |
+
private $runtimes = [];
|
85 |
+
private $optionsHash;
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Constructor.
|
89 |
+
*
|
90 |
+
* Available options:
|
91 |
+
*
|
92 |
+
* * debug: When set to true, it automatically set "auto_reload" to true as
|
93 |
+
* well (default to false).
|
94 |
+
*
|
95 |
+
* * charset: The charset used by the templates (default to UTF-8).
|
96 |
+
*
|
97 |
+
* * base_template_class: The base template class to use for generated
|
98 |
+
* templates (default to \Twig\Template).
|
99 |
+
*
|
100 |
+
* * cache: An absolute path where to store the compiled templates,
|
101 |
+
* a \Twig\Cache\CacheInterface implementation,
|
102 |
+
* or false to disable compilation cache (default).
|
103 |
+
*
|
104 |
+
* * auto_reload: Whether to reload the template if the original source changed.
|
105 |
+
* If you don't provide the auto_reload option, it will be
|
106 |
+
* determined automatically based on the debug value.
|
107 |
+
*
|
108 |
+
* * strict_variables: Whether to ignore invalid variables in templates
|
109 |
+
* (default to false).
|
110 |
+
*
|
111 |
+
* * autoescape: Whether to enable auto-escaping (default to html):
|
112 |
+
* * false: disable auto-escaping
|
113 |
+
* * true: equivalent to html
|
114 |
+
* * html, js: set the autoescaping to one of the supported strategies
|
115 |
+
* * name: set the autoescaping strategy based on the template name extension
|
116 |
+
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "name"
|
117 |
+
*
|
118 |
+
* * optimizations: A flag that indicates which optimizations to apply
|
119 |
+
* (default to -1 which means that all optimizations are enabled;
|
120 |
+
* set it to 0 to disable).
|
121 |
+
*/
|
122 |
+
public function __construct(LoaderInterface $loader = null, $options = [])
|
123 |
+
{
|
124 |
+
if (null !== $loader) {
|
125 |
+
$this->setLoader($loader);
|
126 |
+
} else {
|
127 |
+
@trigger_error('Not passing a "Twig\Lodaer\LoaderInterface" as the first constructor argument of "Twig\Environment" is deprecated since version 1.21.', E_USER_DEPRECATED);
|
128 |
+
}
|
129 |
+
|
130 |
+
$options = array_merge([
|
131 |
+
'debug' => false,
|
132 |
+
'charset' => 'UTF-8',
|
133 |
+
'base_template_class' => '\Twig\Template',
|
134 |
+
'strict_variables' => false,
|
135 |
+
'autoescape' => 'html',
|
136 |
+
'cache' => false,
|
137 |
+
'auto_reload' => null,
|
138 |
+
'optimizations' => -1,
|
139 |
+
], $options);
|
140 |
+
|
141 |
+
$this->debug = (bool) $options['debug'];
|
142 |
+
$this->charset = strtoupper($options['charset']);
|
143 |
+
$this->baseTemplateClass = $options['base_template_class'];
|
144 |
+
$this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload'];
|
145 |
+
$this->strictVariables = (bool) $options['strict_variables'];
|
146 |
+
$this->setCache($options['cache']);
|
147 |
+
|
148 |
+
$this->addExtension(new CoreExtension());
|
149 |
+
$this->addExtension(new EscaperExtension($options['autoescape']));
|
150 |
+
$this->addExtension(new OptimizerExtension($options['optimizations']));
|
151 |
+
$this->staging = new StagingExtension();
|
152 |
+
|
153 |
+
// For BC
|
154 |
+
if (\is_string($this->originalCache)) {
|
155 |
+
$r = new \ReflectionMethod($this, 'writeCacheFile');
|
156 |
+
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
|
157 |
+
@trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
|
158 |
+
|
159 |
+
$this->bcWriteCacheFile = true;
|
160 |
+
}
|
161 |
+
|
162 |
+
$r = new \ReflectionMethod($this, 'getCacheFilename');
|
163 |
+
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
|
164 |
+
@trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
|
165 |
+
|
166 |
+
$this->bcGetCacheFilename = true;
|
167 |
+
}
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Gets the base template class for compiled templates.
|
173 |
+
*
|
174 |
+
* @return string The base template class name
|
175 |
+
*/
|
176 |
+
public function getBaseTemplateClass()
|
177 |
+
{
|
178 |
+
return $this->baseTemplateClass;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Sets the base template class for compiled templates.
|
183 |
+
*
|
184 |
+
* @param string $class The base template class name
|
185 |
+
*/
|
186 |
+
public function setBaseTemplateClass($class)
|
187 |
+
{
|
188 |
+
$this->baseTemplateClass = $class;
|
189 |
+
$this->updateOptionsHash();
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Enables debugging mode.
|
194 |
+
*/
|
195 |
+
public function enableDebug()
|
196 |
+
{
|
197 |
+
$this->debug = true;
|
198 |
+
$this->updateOptionsHash();
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Disables debugging mode.
|
203 |
+
*/
|
204 |
+
public function disableDebug()
|
205 |
+
{
|
206 |
+
$this->debug = false;
|
207 |
+
$this->updateOptionsHash();
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Checks if debug mode is enabled.
|
212 |
+
*
|
213 |
+
* @return bool true if debug mode is enabled, false otherwise
|
214 |
+
*/
|
215 |
+
public function isDebug()
|
216 |
+
{
|
217 |
+
return $this->debug;
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Enables the auto_reload option.
|
222 |
+
*/
|
223 |
+
public function enableAutoReload()
|
224 |
+
{
|
225 |
+
$this->autoReload = true;
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Disables the auto_reload option.
|
230 |
+
*/
|
231 |
+
public function disableAutoReload()
|
232 |
+
{
|
233 |
+
$this->autoReload = false;
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Checks if the auto_reload option is enabled.
|
238 |
+
*
|
239 |
+
* @return bool true if auto_reload is enabled, false otherwise
|
240 |
+
*/
|
241 |
+
public function isAutoReload()
|
242 |
+
{
|
243 |
+
return $this->autoReload;
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Enables the strict_variables option.
|
248 |
+
*/
|
249 |
+
public function enableStrictVariables()
|
250 |
+
{
|
251 |
+
$this->strictVariables = true;
|
252 |
+
$this->updateOptionsHash();
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Disables the strict_variables option.
|
257 |
+
*/
|
258 |
+
public function disableStrictVariables()
|
259 |
+
{
|
260 |
+
$this->strictVariables = false;
|
261 |
+
$this->updateOptionsHash();
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* Checks if the strict_variables option is enabled.
|
266 |
+
*
|
267 |
+
* @return bool true if strict_variables is enabled, false otherwise
|
268 |
+
*/
|
269 |
+
public function isStrictVariables()
|
270 |
+
{
|
271 |
+
return $this->strictVariables;
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Gets the current cache implementation.
|
276 |
+
*
|
277 |
+
* @param bool $original Whether to return the original cache option or the real cache instance
|
278 |
+
*
|
279 |
+
* @return CacheInterface|string|false A Twig\Cache\CacheInterface implementation,
|
280 |
+
* an absolute path to the compiled templates,
|
281 |
+
* or false to disable cache
|
282 |
+
*/
|
283 |
+
public function getCache($original = true)
|
284 |
+
{
|
285 |
+
return $original ? $this->originalCache : $this->cache;
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Sets the current cache implementation.
|
290 |
+
*
|
291 |
+
* @param CacheInterface|string|false $cache A Twig\Cache\CacheInterface implementation,
|
292 |
+
* an absolute path to the compiled templates,
|
293 |
+
* or false to disable cache
|
294 |
+
*/
|
295 |
+
public function setCache($cache)
|
296 |
+
{
|
297 |
+
if (\is_string($cache)) {
|
298 |
+
$this->originalCache = $cache;
|
299 |
+
$this->cache = new FilesystemCache($cache);
|
300 |
+
} elseif (false === $cache) {
|
301 |
+
$this->originalCache = $cache;
|
302 |
+
$this->cache = new NullCache();
|
303 |
+
} elseif (null === $cache) {
|
304 |
+
@trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', E_USER_DEPRECATED);
|
305 |
+
$this->originalCache = false;
|
306 |
+
$this->cache = new NullCache();
|
307 |
+
} elseif ($cache instanceof CacheInterface) {
|
308 |
+
$this->originalCache = $this->cache = $cache;
|
309 |
+
} else {
|
310 |
+
throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.'));
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Gets the cache filename for a given template.
|
316 |
+
*
|
317 |
+
* @param string $name The template name
|
318 |
+
*
|
319 |
+
* @return string|false The cache file name or false when caching is disabled
|
320 |
+
*
|
321 |
+
* @deprecated since 1.22 (to be removed in 2.0)
|
322 |
+
*/
|
323 |
+
public function getCacheFilename($name)
|
324 |
+
{
|
325 |
+
@trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
326 |
+
|
327 |
+
$key = $this->cache->generateKey($name, $this->getTemplateClass($name));
|
328 |
+
|
329 |
+
return !$key ? false : $key;
|
330 |
+
}
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Gets the template class associated with the given string.
|
334 |
+
*
|
335 |
+
* The generated template class is based on the following parameters:
|
336 |
+
*
|
337 |
+
* * The cache key for the given template;
|
338 |
+
* * The currently enabled extensions;
|
339 |
+
* * Whether the Twig C extension is available or not;
|
340 |
+
* * PHP version;
|
341 |
+
* * Twig version;
|
342 |
+
* * Options with what environment was created.
|
343 |
+
*
|
344 |
+
* @param string $name The name for which to calculate the template class name
|
345 |
+
* @param int|null $index The index if it is an embedded template
|
346 |
+
*
|
347 |
+
* @return string The template class name
|
348 |
+
*/
|
349 |
+
public function getTemplateClass($name, $index = null)
|
350 |
+
{
|
351 |
+
$key = $this->getLoader()->getCacheKey($name).$this->optionsHash;
|
352 |
+
|
353 |
+
return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '___'.$index);
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Gets the template class prefix.
|
358 |
+
*
|
359 |
+
* @return string The template class prefix
|
360 |
+
*
|
361 |
+
* @deprecated since 1.22 (to be removed in 2.0)
|
362 |
+
*/
|
363 |
+
public function getTemplateClassPrefix()
|
364 |
+
{
|
365 |
+
@trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
366 |
+
|
367 |
+
return $this->templateClassPrefix;
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Renders a template.
|
372 |
+
*
|
373 |
+
* @param string|TemplateWrapper $name The template name
|
374 |
+
* @param array $context An array of parameters to pass to the template
|
375 |
+
*
|
376 |
+
* @return string The rendered template
|
377 |
+
*
|
378 |
+
* @throws LoaderError When the template cannot be found
|
379 |
+
* @throws SyntaxError When an error occurred during compilation
|
380 |
+
* @throws RuntimeError When an error occurred during rendering
|
381 |
+
*/
|
382 |
+
public function render($name, array $context = [])
|
383 |
+
{
|
384 |
+
return $this->load($name)->render($context);
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Displays a template.
|
389 |
+
*
|
390 |
+
* @param string|TemplateWrapper $name The template name
|
391 |
+
* @param array $context An array of parameters to pass to the template
|
392 |
+
*
|
393 |
+
* @throws LoaderError When the template cannot be found
|
394 |
+
* @throws SyntaxError When an error occurred during compilation
|
395 |
+
* @throws RuntimeError When an error occurred during rendering
|
396 |
+
*/
|
397 |
+
public function display($name, array $context = [])
|
398 |
+
{
|
399 |
+
$this->load($name)->display($context);
|
400 |
+
}
|
401 |
+
|
402 |
+
/**
|
403 |
+
* Loads a template.
|
404 |
+
*
|
405 |
+
* @param string|TemplateWrapper|\Twig\Template $name The template name
|
406 |
+
*
|
407 |
+
* @throws LoaderError When the template cannot be found
|
408 |
+
* @throws RuntimeError When a previously generated cache is corrupted
|
409 |
+
* @throws SyntaxError When an error occurred during compilation
|
410 |
+
*
|
411 |
+
* @return TemplateWrapper
|
412 |
+
*/
|
413 |
+
public function load($name)
|
414 |
+
{
|
415 |
+
if ($name instanceof TemplateWrapper) {
|
416 |
+
return $name;
|
417 |
+
}
|
418 |
+
|
419 |
+
if ($name instanceof Template) {
|
420 |
+
return new TemplateWrapper($this, $name);
|
421 |
+
}
|
422 |
+
|
423 |
+
return new TemplateWrapper($this, $this->loadTemplate($name));
|
424 |
+
}
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Loads a template internal representation.
|
428 |
+
*
|
429 |
+
* This method is for internal use only and should never be called
|
430 |
+
* directly.
|
431 |
+
*
|
432 |
+
* @param string $name The template name
|
433 |
+
* @param int $index The index if it is an embedded template
|
434 |
+
*
|
435 |
+
* @return \Twig_TemplateInterface A template instance representing the given template name
|
436 |
+
*
|
437 |
+
* @throws LoaderError When the template cannot be found
|
438 |
+
* @throws RuntimeError When a previously generated cache is corrupted
|
439 |
+
* @throws SyntaxError When an error occurred during compilation
|
440 |
+
*
|
441 |
+
* @internal
|
442 |
+
*/
|
443 |
+
public function loadTemplate($name, $index = null)
|
444 |
+
{
|
445 |
+
return $this->loadClass($this->getTemplateClass($name), $name, $index);
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* @internal
|
450 |
+
*/
|
451 |
+
public function loadClass($cls, $name, $index = null)
|
452 |
+
{
|
453 |
+
$mainCls = $cls;
|
454 |
+
if (null !== $index) {
|
455 |
+
$cls .= '___'.$index;
|
456 |
+
}
|
457 |
+
|
458 |
+
if (isset($this->loadedTemplates[$cls])) {
|
459 |
+
return $this->loadedTemplates[$cls];
|
460 |
+
}
|
461 |
+
|
462 |
+
if (!class_exists($cls, false)) {
|
463 |
+
if ($this->bcGetCacheFilename) {
|
464 |
+
$key = $this->getCacheFilename($name);
|
465 |
+
} else {
|
466 |
+
$key = $this->cache->generateKey($name, $mainCls);
|
467 |
+
}
|
468 |
+
|
469 |
+
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
|
470 |
+
$this->cache->load($key);
|
471 |
+
}
|
472 |
+
|
473 |
+
$source = null;
|
474 |
+
if (!class_exists($cls, false)) {
|
475 |
+
$loader = $this->getLoader();
|
476 |
+
if (!$loader instanceof SourceContextLoaderInterface) {
|
477 |
+
$source = new Source($loader->getSource($name), $name);
|
478 |
+
} else {
|
479 |
+
$source = $loader->getSourceContext($name);
|
480 |
+
}
|
481 |
+
|
482 |
+
$content = $this->compileSource($source);
|
483 |
+
|
484 |
+
if ($this->bcWriteCacheFile) {
|
485 |
+
$this->writeCacheFile($key, $content);
|
486 |
+
} else {
|
487 |
+
$this->cache->write($key, $content);
|
488 |
+
$this->cache->load($key);
|
489 |
+
}
|
490 |
+
|
491 |
+
if (!class_exists($mainCls, false)) {
|
492 |
+
/* Last line of defense if either $this->bcWriteCacheFile was used,
|
493 |
+
* $this->cache is implemented as a no-op or we have a race condition
|
494 |
+
* where the cache was cleared between the above calls to write to and load from
|
495 |
+
* the cache.
|
496 |
+
*/
|
497 |
+
eval('?>'.$content);
|
498 |
+
}
|
499 |
+
}
|
500 |
+
|
501 |
+
if (!class_exists($cls, false)) {
|
502 |
+
throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source);
|
503 |
+
}
|
504 |
+
}
|
505 |
+
|
506 |
+
if (!$this->runtimeInitialized) {
|
507 |
+
$this->initRuntime();
|
508 |
+
}
|
509 |
+
|
510 |
+
return $this->loadedTemplates[$cls] = new $cls($this);
|
511 |
+
}
|
512 |
+
|
513 |
+
/**
|
514 |
+
* Creates a template from source.
|
515 |
+
*
|
516 |
+
* This method should not be used as a generic way to load templates.
|
517 |
+
*
|
518 |
+
* @param string $template The template name
|
519 |
+
* @param string $name An optional name of the template to be used in error messages
|
520 |
+
*
|
521 |
+
* @return TemplateWrapper A template instance representing the given template name
|
522 |
+
*
|
523 |
+
* @throws LoaderError When the template cannot be found
|
524 |
+
* @throws SyntaxError When an error occurred during compilation
|
525 |
+
*/
|
526 |
+
public function createTemplate($template, $name = null)
|
527 |
+
{
|
528 |
+
$hash = hash('sha256', $template, false);
|
529 |
+
if (null !== $name) {
|
530 |
+
$name = sprintf('%s (string template %s)', $name, $hash);
|
531 |
+
} else {
|
532 |
+
$name = sprintf('__string_template__%s', $hash);
|
533 |
+
}
|
534 |
+
|
535 |
+
$loader = new ChainLoader([
|
536 |
+
new ArrayLoader([$name => $template]),
|
537 |
+
$current = $this->getLoader(),
|
538 |
+
]);
|
539 |
+
|
540 |
+
$this->setLoader($loader);
|
541 |
+
try {
|
542 |
+
$template = new TemplateWrapper($this, $this->loadTemplate($name));
|
543 |
+
} catch (\Exception $e) {
|
544 |
+
$this->setLoader($current);
|
545 |
+
|
546 |
+
throw $e;
|
547 |
+
} catch (\Throwable $e) {
|
548 |
+
$this->setLoader($current);
|
549 |
+
|
550 |
+
throw $e;
|
551 |
+
}
|
552 |
+
$this->setLoader($current);
|
553 |
+
|
554 |
+
return $template;
|
555 |
+
}
|
556 |
+
|
557 |
+
/**
|
558 |
+
* Returns true if the template is still fresh.
|
559 |
+
*
|
560 |
+
* Besides checking the loader for freshness information,
|
561 |
+
* this method also checks if the enabled extensions have
|
562 |
+
* not changed.
|
563 |
+
*
|
564 |
+
* @param string $name The template name
|
565 |
+
* @param int $time The last modification time of the cached template
|
566 |
+
*
|
567 |
+
* @return bool true if the template is fresh, false otherwise
|
568 |
+
*/
|
569 |
+
public function isTemplateFresh($name, $time)
|
570 |
+
{
|
571 |
+
if (0 === $this->lastModifiedExtension) {
|
572 |
+
foreach ($this->extensions as $extension) {
|
573 |
+
$r = new \ReflectionObject($extension);
|
574 |
+
if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) {
|
575 |
+
$this->lastModifiedExtension = $extensionTime;
|
576 |
+
}
|
577 |
+
}
|
578 |
+
}
|
579 |
+
|
580 |
+
return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time);
|
581 |
+
}
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Tries to load a template consecutively from an array.
|
585 |
+
*
|
586 |
+
* Similar to load() but it also accepts instances of \Twig\Template and
|
587 |
+
* \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded.
|
588 |
+
*
|
589 |
+
* @param string|Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively
|
590 |
+
*
|
591 |
+
* @return TemplateWrapper|Template
|
592 |
+
*
|
593 |
+
* @throws LoaderError When none of the templates can be found
|
594 |
+
* @throws SyntaxError When an error occurred during compilation
|
595 |
+
*/
|
596 |
+
public function resolveTemplate($names)
|
597 |
+
{
|
598 |
+
if (!\is_array($names)) {
|
599 |
+
$names = [$names];
|
600 |
+
}
|
601 |
+
|
602 |
+
foreach ($names as $name) {
|
603 |
+
if ($name instanceof Template) {
|
604 |
+
return $name;
|
605 |
+
}
|
606 |
+
if ($name instanceof TemplateWrapper) {
|
607 |
+
return $name;
|
608 |
+
}
|
609 |
+
|
610 |
+
try {
|
611 |
+
return $this->loadTemplate($name);
|
612 |
+
} catch (LoaderError $e) {
|
613 |
+
if (1 === \count($names)) {
|
614 |
+
throw $e;
|
615 |
+
}
|
616 |
+
}
|
617 |
+
}
|
618 |
+
|
619 |
+
throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
|
620 |
+
}
|
621 |
+
|
622 |
+
/**
|
623 |
+
* Clears the internal template cache.
|
624 |
+
*
|
625 |
+
* @deprecated since 1.18.3 (to be removed in 2.0)
|
626 |
+
*/
|
627 |
+
public function clearTemplateCache()
|
628 |
+
{
|
629 |
+
@trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
630 |
+
|
631 |
+
$this->loadedTemplates = [];
|
632 |
+
}
|
633 |
+
|
634 |
+
/**
|
635 |
+
* Clears the template cache files on the filesystem.
|
636 |
+
*
|
637 |
+
* @deprecated since 1.22 (to be removed in 2.0)
|
638 |
+
*/
|
639 |
+
public function clearCacheFiles()
|
640 |
+
{
|
641 |
+
@trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
642 |
+
|
643 |
+
if (\is_string($this->originalCache)) {
|
644 |
+
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
|
645 |
+
if ($file->isFile()) {
|
646 |
+
@unlink($file->getPathname());
|
647 |
+
}
|
648 |
+
}
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
/**
|
653 |
+
* Gets the Lexer instance.
|
654 |
+
*
|
655 |
+
* @return \Twig_LexerInterface
|
656 |
+
*
|
657 |
+
* @deprecated since 1.25 (to be removed in 2.0)
|
658 |
+
*/
|
659 |
+
public function getLexer()
|
660 |
+
{
|
661 |
+
@trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
|
662 |
+
|
663 |
+
if (null === $this->lexer) {
|
664 |
+
$this->lexer = new Lexer($this);
|
665 |
+
}
|
666 |
+
|
667 |
+
return $this->lexer;
|
668 |
+
}
|
669 |
+
|
670 |
+
public function setLexer(\Twig_LexerInterface $lexer)
|
671 |
+
{
|
672 |
+
$this->lexer = $lexer;
|
673 |
+
}
|
674 |
+
|
675 |
+
/**
|
676 |
+
* Tokenizes a source code.
|
677 |
+
*
|
678 |
+
* @param string|Source $source The template source code
|
679 |
+
* @param string $name The template name (deprecated)
|
680 |
+
*
|
681 |
+
* @return TokenStream
|
682 |
+
*
|
683 |
+
* @throws SyntaxError When the code is syntactically wrong
|
684 |
+
*/
|
685 |
+
public function tokenize($source, $name = null)
|
686 |
+
{
|
687 |
+
if (!$source instanceof Source) {
|
688 |
+
@trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
|
689 |
+
$source = new Source($source, $name);
|
690 |
+
}
|
691 |
+
|
692 |
+
if (null === $this->lexer) {
|
693 |
+
$this->lexer = new Lexer($this);
|
694 |
+
}
|
695 |
+
|
696 |
+
return $this->lexer->tokenize($source);
|
697 |
+
}
|
698 |
+
|
699 |
+
/**
|
700 |
+
* Gets the Parser instance.
|
701 |
+
*
|
702 |
+
* @return \Twig_ParserInterface
|
703 |
+
*
|
704 |
+
* @deprecated since 1.25 (to be removed in 2.0)
|
705 |
+
*/
|
706 |
+
public function getParser()
|
707 |
+
{
|
708 |
+
@trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
|
709 |
+
|
710 |
+
if (null === $this->parser) {
|
711 |
+
$this->parser = new Parser($this);
|
712 |
+
}
|
713 |
+
|
714 |
+
return $this->parser;
|
715 |
+
}
|
716 |
+
|
717 |
+
public function setParser(\Twig_ParserInterface $parser)
|
718 |
+
{
|
719 |
+
$this->parser = $parser;
|
720 |
+
}
|
721 |
+
|
722 |
+
/**
|
723 |
+
* Converts a token stream to a node tree.
|
724 |
+
*
|
725 |
+
* @return ModuleNode
|
726 |
+
*
|
727 |
+
* @throws SyntaxError When the token stream is syntactically or semantically wrong
|
728 |
+
*/
|
729 |
+
public function parse(TokenStream $stream)
|
730 |
+
{
|
731 |
+
if (null === $this->parser) {
|
732 |
+
$this->parser = new Parser($this);
|
733 |
+
}
|
734 |
+
|
735 |
+
return $this->parser->parse($stream);
|
736 |
+
}
|
737 |
+
|
738 |
+
/**
|
739 |
+
* Gets the Compiler instance.
|
740 |
+
*
|
741 |
+
* @return \Twig_CompilerInterface
|
742 |
+
*
|
743 |
+
* @deprecated since 1.25 (to be removed in 2.0)
|
744 |
+
*/
|
745 |
+
public function getCompiler()
|
746 |
+
{
|
747 |
+
@trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
|
748 |
+
|
749 |
+
if (null === $this->compiler) {
|
750 |
+
$this->compiler = new Compiler($this);
|
751 |
+
}
|
752 |
+
|
753 |
+
return $this->compiler;
|
754 |
+
}
|
755 |
+
|
756 |
+
public function setCompiler(\Twig_CompilerInterface $compiler)
|
757 |
+
{
|
758 |
+
$this->compiler = $compiler;
|
759 |
+
}
|
760 |
+
|
761 |
+
/**
|
762 |
+
* Compiles a node and returns the PHP code.
|
763 |
+
*
|
764 |
+
* @return string The compiled PHP source code
|
765 |
+
*/
|
766 |
+
public function compile(\Twig_NodeInterface $node)
|
767 |
+
{
|
768 |
+
if (null === $this->compiler) {
|
769 |
+
$this->compiler = new Compiler($this);
|
770 |
+
}
|
771 |
+
|
772 |
+
return $this->compiler->compile($node)->getSource();
|
773 |
+
}
|
774 |
+
|
775 |
+
/**
|
776 |
+
* Compiles a template source code.
|
777 |
+
*
|
778 |
+
* @param string|Source $source The template source code
|
779 |
+
* @param string $name The template name (deprecated)
|
780 |
+
*
|
781 |
+
* @return string The compiled PHP source code
|
782 |
+
*
|
783 |
+
* @throws SyntaxError When there was an error during tokenizing, parsing or compiling
|
784 |
+
*/
|
785 |
+
public function compileSource($source, $name = null)
|
786 |
+
{
|
787 |
+
if (!$source instanceof Source) {
|
788 |
+
@trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
|
789 |
+
$source = new Source($source, $name);
|
790 |
+
}
|
791 |
+
|
792 |
+
try {
|
793 |
+
return $this->compile($this->parse($this->tokenize($source)));
|
794 |
+
} catch (Error $e) {
|
795 |
+
$e->setSourceContext($source);
|
796 |
+
throw $e;
|
797 |
+
} catch (\Exception $e) {
|
798 |
+
throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e);
|
799 |
+
}
|
800 |
+
}
|
801 |
+
|
802 |
+
public function setLoader(LoaderInterface $loader)
|
803 |
+
{
|
804 |
+
if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) {
|
805 |
+
@trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED);
|
806 |
+
}
|
807 |
+
|
808 |
+
$this->loader = $loader;
|
809 |
+
}
|
810 |
+
|
811 |
+
/**
|
812 |
+
* Gets the Loader instance.
|
813 |
+
*
|
814 |
+
* @return LoaderInterface
|
815 |
+
*/
|
816 |
+
public function getLoader()
|
817 |
+
{
|
818 |
+
if (null === $this->loader) {
|
819 |
+
throw new \LogicException('You must set a loader first.');
|
820 |
+
}
|
821 |
+
|
822 |
+
return $this->loader;
|
823 |
+
}
|
824 |
+
|
825 |
+
/**
|
826 |
+
* Sets the default template charset.
|
827 |
+
*
|
828 |
+
* @param string $charset The default charset
|
829 |
+
*/
|
830 |
+
public function setCharset($charset)
|
831 |
+
{
|
832 |
+
$this->charset = strtoupper($charset);
|
833 |
+
}
|
834 |
+
|
835 |
+
/**
|
836 |
+
* Gets the default template charset.
|
837 |
+
*
|
838 |
+
* @return string The default charset
|
839 |
+
*/
|
840 |
+
public function getCharset()
|
841 |
+
{
|
842 |
+
return $this->charset;
|
843 |
+
}
|
844 |
+
|
845 |
+
/**
|
846 |
+
* Initializes the runtime environment.
|
847 |
+
*
|
848 |
+
* @deprecated since 1.23 (to be removed in 2.0)
|
849 |
+
*/
|
850 |
+
public function initRuntime()
|
851 |
+
{
|
852 |
+
$this->runtimeInitialized = true;
|
853 |
+
|
854 |
+
foreach ($this->getExtensions() as $name => $extension) {
|
855 |
+
if (!$extension instanceof InitRuntimeInterface) {
|
856 |
+
$m = new \ReflectionMethod($extension, 'initRuntime');
|
857 |
+
|
858 |
+
$parentClass = $m->getDeclaringClass()->getName();
|
859 |
+
if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) {
|
860 |
+
@trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the \Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig\Extension\InitRuntimeInterface if needed (not recommended).', $name), E_USER_DEPRECATED);
|
861 |
+
}
|
862 |
+
}
|
863 |
+
|
864 |
+
$extension->initRuntime($this);
|
865 |
+
}
|
866 |
+
}
|
867 |
+
|
868 |
+
/**
|
869 |
+
* Returns true if the given extension is registered.
|
870 |
+
*
|
871 |
+
* @param string $class The extension class name
|
872 |
+
*
|
873 |
+
* @return bool Whether the extension is registered or not
|
874 |
+
*/
|
875 |
+
public function hasExtension($class)
|
876 |
+
{
|
877 |
+
$class = ltrim($class, '\\');
|
878 |
+
if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
|
879 |
+
// For BC/FC with namespaced aliases
|
880 |
+
$class = new \ReflectionClass($class);
|
881 |
+
$class = $class->name;
|
882 |
+
}
|
883 |
+
|
884 |
+
if (isset($this->extensions[$class])) {
|
885 |
+
if ($class !== \get_class($this->extensions[$class])) {
|
886 |
+
@trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
|
887 |
+
}
|
888 |
+
|
889 |
+
return true;
|
890 |
+
}
|
891 |
+
|
892 |
+
return isset($this->extensionsByClass[$class]);
|
893 |
+
}
|
894 |
+
|
895 |
+
/**
|
896 |
+
* Adds a runtime loader.
|
897 |
+
*/
|
898 |
+
public function addRuntimeLoader(RuntimeLoaderInterface $loader)
|
899 |
+
{
|
900 |
+
$this->runtimeLoaders[] = $loader;
|
901 |
+
}
|
902 |
+
|
903 |
+
/**
|
904 |
+
* Gets an extension by class name.
|
905 |
+
*
|
906 |
+
* @param string $class The extension class name
|
907 |
+
*
|
908 |
+
* @return ExtensionInterface
|
909 |
+
*/
|
910 |
+
public function getExtension($class)
|
911 |
+
{
|
912 |
+
$class = ltrim($class, '\\');
|
913 |
+
if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
|
914 |
+
// For BC/FC with namespaced aliases
|
915 |
+
$class = new \ReflectionClass($class);
|
916 |
+
$class = $class->name;
|
917 |
+
}
|
918 |
+
|
919 |
+
if (isset($this->extensions[$class])) {
|
920 |
+
if ($class !== \get_class($this->extensions[$class])) {
|
921 |
+
@trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
|
922 |
+
}
|
923 |
+
|
924 |
+
return $this->extensions[$class];
|
925 |
+
}
|
926 |
+
|
927 |
+
if (!isset($this->extensionsByClass[$class])) {
|
928 |
+
throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class));
|
929 |
+
}
|
930 |
+
|
931 |
+
return $this->extensionsByClass[$class];
|
932 |
+
}
|
933 |
+
|
934 |
+
/**
|
935 |
+
* Returns the runtime implementation of a Twig element (filter/function/test).
|
936 |
+
*
|
937 |
+
* @param string $class A runtime class name
|
938 |
+
*
|
939 |
+
* @return object The runtime implementation
|
940 |
+
*
|
941 |
+
* @throws RuntimeError When the template cannot be found
|
942 |
+
*/
|
943 |
+
public function getRuntime($class)
|
944 |
+
{
|
945 |
+
if (isset($this->runtimes[$class])) {
|
946 |
+
return $this->runtimes[$class];
|
947 |
+
}
|
948 |
+
|
949 |
+
foreach ($this->runtimeLoaders as $loader) {
|
950 |
+
if (null !== $runtime = $loader->load($class)) {
|
951 |
+
return $this->runtimes[$class] = $runtime;
|
952 |
+
}
|
953 |
+
}
|
954 |
+
|
955 |
+
throw new RuntimeError(sprintf('Unable to load the "%s" runtime.', $class));
|
956 |
+
}
|
957 |
+
|
958 |
+
public function addExtension(ExtensionInterface $extension)
|
959 |
+
{
|
960 |
+
if ($this->extensionInitialized) {
|
961 |
+
throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName()));
|
962 |
+
}
|
963 |
+
|
964 |
+
$class = \get_class($extension);
|
965 |
+
if ($class !== $extension->getName()) {
|
966 |
+
if (isset($this->extensions[$extension->getName()])) {
|
967 |
+
unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]);
|
968 |
+
@trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), E_USER_DEPRECATED);
|
969 |
+
}
|
970 |
+
}
|
971 |
+
|
972 |
+
$this->lastModifiedExtension = 0;
|
973 |
+
$this->extensionsByClass[$class] = $extension;
|
974 |
+
$this->extensions[$extension->getName()] = $extension;
|
975 |
+
$this->updateOptionsHash();
|
976 |
+
}
|
977 |
+
|
978 |
+
/**
|
979 |
+
* Removes an extension by name.
|
980 |
+
*
|
981 |
+
* This method is deprecated and you should not use it.
|
982 |
+
*
|
983 |
+
* @param string $name The extension name
|
984 |
+
*
|
985 |
+
* @deprecated since 1.12 (to be removed in 2.0)
|
986 |
+
*/
|
987 |
+
public function removeExtension($name)
|
988 |
+
{
|
989 |
+
@trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
990 |
+
|
991 |
+
if ($this->extensionInitialized) {
|
992 |
+
throw new \LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name));
|
993 |
+
}
|
994 |
+
|
995 |
+
$class = ltrim($name, '\\');
|
996 |
+
if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
|
997 |
+
// For BC/FC with namespaced aliases
|
998 |
+
$class = new \ReflectionClass($class);
|
999 |
+
$class = $class->name;
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
if (isset($this->extensions[$class])) {
|
1003 |
+
if ($class !== \get_class($this->extensions[$class])) {
|
1004 |
+
@trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
|
1005 |
+
}
|
1006 |
+
|
1007 |
+
unset($this->extensions[$class]);
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
unset($this->extensions[$class]);
|
1011 |
+
$this->updateOptionsHash();
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
/**
|
1015 |
+
* Registers an array of extensions.
|
1016 |
+
*
|
1017 |
+
* @param array $extensions An array of extensions
|
1018 |
+
*/
|
1019 |
+
public function setExtensions(array $extensions)
|
1020 |
+
{
|
1021 |
+
foreach ($extensions as $extension) {
|
1022 |
+
$this->addExtension($extension);
|
1023 |
+
}
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
/**
|
1027 |
+
* Returns all registered extensions.
|
1028 |
+
*
|
1029 |
+
* @return ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on)
|
1030 |
+
*/
|
1031 |
+
public function getExtensions()
|
1032 |
+
{
|
1033 |
+
return $this->extensions;
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
public function addTokenParser(TokenParserInterface $parser)
|
1037 |
+
{
|
1038 |
+
if ($this->extensionInitialized) {
|
1039 |
+
throw new \LogicException('Unable to add a token parser as extensions have already been initialized.');
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
$this->staging->addTokenParser($parser);
|
1043 |
+
}
|
1044 |
+
|
1045 |
+
/**
|
1046 |
+
* Gets the registered Token Parsers.
|
1047 |
+
*
|
1048 |
+
* @return \Twig_TokenParserBrokerInterface
|
1049 |
+
*
|
1050 |
+
* @internal
|
1051 |
+
*/
|
1052 |
+
public function getTokenParsers()
|
1053 |
+
{
|
1054 |
+
if (!$this->extensionInitialized) {
|
1055 |
+
$this->initExtensions();
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
return $this->parsers;
|
1059 |
+
}
|
1060 |
+
|
1061 |
+
/**
|
1062 |
+
* Gets registered tags.
|
1063 |
+
*
|
1064 |
+
* Be warned that this method cannot return tags defined by \Twig_TokenParserBrokerInterface classes.
|
1065 |
+
*
|
1066 |
+
* @return TokenParserInterface[]
|
1067 |
+
*
|
1068 |
+
* @internal
|
1069 |
+
*/
|
1070 |
+
public function getTags()
|
1071 |
+
{
|
1072 |
+
$tags = [];
|
1073 |
+
foreach ($this->getTokenParsers()->getParsers() as $parser) {
|
1074 |
+
if ($parser instanceof TokenParserInterface) {
|
1075 |
+
$tags[$parser->getTag()] = $parser;
|
1076 |
+
}
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
return $tags;
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
public function addNodeVisitor(NodeVisitorInterface $visitor)
|
1083 |
+
{
|
1084 |
+
if ($this->extensionInitialized) {
|
1085 |
+
throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.');
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
$this->staging->addNodeVisitor($visitor);
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
/**
|
1092 |
+
* Gets the registered Node Visitors.
|
1093 |
+
*
|
1094 |
+
* @return NodeVisitorInterface[]
|
1095 |
+
*
|
1096 |
+
* @internal
|
1097 |
+
*/
|
1098 |
+
public function getNodeVisitors()
|
1099 |
+
{
|
1100 |
+
if (!$this->extensionInitialized) {
|
1101 |
+
$this->initExtensions();
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
return $this->visitors;
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
/**
|
1108 |
+
* Registers a Filter.
|
1109 |
+
*
|
1110 |
+
* @param string|TwigFilter $name The filter name or a \Twig_SimpleFilter instance
|
1111 |
+
* @param \Twig_FilterInterface|TwigFilter $filter
|
1112 |
+
*/
|
1113 |
+
public function addFilter($name, $filter = null)
|
1114 |
+
{
|
1115 |
+
if (!$name instanceof TwigFilter && !($filter instanceof TwigFilter || $filter instanceof \Twig_FilterInterface)) {
|
1116 |
+
throw new \LogicException('A filter must be an instance of \Twig_FilterInterface or \Twig_SimpleFilter.');
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
if ($name instanceof TwigFilter) {
|
1120 |
+
$filter = $name;
|
1121 |
+
$name = $filter->getName();
|
1122 |
+
} else {
|
1123 |
+
@trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), E_USER_DEPRECATED);
|
1124 |
+
}
|
1125 |
+
|
1126 |
+
if ($this->extensionInitialized) {
|
1127 |
+
throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name));
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
$this->staging->addFilter($name, $filter);
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
/**
|
1134 |
+
* Get a filter by name.
|
1135 |
+
*
|
1136 |
+
* Subclasses may override this method and load filters differently;
|
1137 |
+
* so no list of filters is available.
|
1138 |
+
*
|
1139 |
+
* @param string $name The filter name
|
1140 |
+
*
|
1141 |
+
* @return \Twig_Filter|false
|
1142 |
+
*
|
1143 |
+
* @internal
|
1144 |
+
*/
|
1145 |
+
public function getFilter($name)
|
1146 |
+
{
|
1147 |
+
if (!$this->extensionInitialized) {
|
1148 |
+
$this->initExtensions();
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
if (isset($this->filters[$name])) {
|
1152 |
+
return $this->filters[$name];
|
1153 |
+
}
|
1154 |
+
|
1155 |
+
foreach ($this->filters as $pattern => $filter) {
|
1156 |
+
$pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
|
1157 |
+
|
1158 |
+
if ($count) {
|
1159 |
+
if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
|
1160 |
+
array_shift($matches);
|
1161 |
+
$filter->setArguments($matches);
|
1162 |
+
|
1163 |
+
return $filter;
|
1164 |
+
}
|
1165 |
+
}
|
1166 |
+
}
|
1167 |
+
|
1168 |
+
foreach ($this->filterCallbacks as $callback) {
|
1169 |
+
if (false !== $filter = \call_user_func($callback, $name)) {
|
1170 |
+
return $filter;
|
1171 |
+
}
|
1172 |
+
}
|
1173 |
+
|
1174 |
+
return false;
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
public function registerUndefinedFilterCallback($callable)
|
1178 |
+
{
|
1179 |
+
$this->filterCallbacks[] = $callable;
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
/**
|
1183 |
+
* Gets the registered Filters.
|
1184 |
+
*
|
1185 |
+
* Be warned that this method cannot return filters defined with registerUndefinedFilterCallback.
|
1186 |
+
*
|
1187 |
+
* @return \Twig_FilterInterface[]
|
1188 |
+
*
|
1189 |
+
* @see registerUndefinedFilterCallback
|
1190 |
+
*
|
1191 |
+
* @internal
|
1192 |
+
*/
|
1193 |
+
public function getFilters()
|
1194 |
+
{
|
1195 |
+
if (!$this->extensionInitialized) {
|
1196 |
+
$this->initExtensions();
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
return $this->filters;
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
/**
|
1203 |
+
* Registers a Test.
|
1204 |
+
*
|
1205 |
+
* @param string|TwigTest $name The test name or a \Twig_SimpleTest instance
|
1206 |
+
* @param \Twig_TestInterface|TwigTest $test A \Twig_TestInterface instance or a \Twig_SimpleTest instance
|
1207 |
+
*/
|
1208 |
+
public function addTest($name, $test = null)
|
1209 |
+
{
|
1210 |
+
if (!$name instanceof TwigTest && !($test instanceof TwigTest || $test instanceof \Twig_TestInterface)) {
|
1211 |
+
throw new \LogicException('A test must be an instance of \Twig_TestInterface or \Twig_SimpleTest.');
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
if ($name instanceof TwigTest) {
|
1215 |
+
$test = $name;
|
1216 |
+
$name = $test->getName();
|
1217 |
+
} else {
|
1218 |
+
@trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED);
|
1219 |
+
}
|
1220 |
+
|
1221 |
+
if ($this->extensionInitialized) {
|
1222 |
+
throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name));
|
1223 |
+
}
|
1224 |
+
|
1225 |
+
$this->staging->addTest($name, $test);
|
1226 |
+
}
|
1227 |
+
|
1228 |
+
/**
|
1229 |
+
* Gets the registered Tests.
|
1230 |
+
*
|
1231 |
+
* @return \Twig_TestInterface[]
|
1232 |
+
*
|
1233 |
+
* @internal
|
1234 |
+
*/
|
1235 |
+
public function getTests()
|
1236 |
+
{
|
1237 |
+
if (!$this->extensionInitialized) {
|
1238 |
+
$this->initExtensions();
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
return $this->tests;
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
/**
|
1245 |
+
* Gets a test by name.
|
1246 |
+
*
|
1247 |
+
* @param string $name The test name
|
1248 |
+
*
|
1249 |
+
* @return \Twig_Test|false
|
1250 |
+
*
|
1251 |
+
* @internal
|
1252 |
+
*/
|
1253 |
+
public function getTest($name)
|
1254 |
+
{
|
1255 |
+
if (!$this->extensionInitialized) {
|
1256 |
+
$this->initExtensions();
|
1257 |
+
}
|
1258 |
+
|
1259 |
+
if (isset($this->tests[$name])) {
|
1260 |
+
return $this->tests[$name];
|
1261 |
+
}
|
1262 |
+
|
1263 |
+
foreach ($this->tests as $pattern => $test) {
|
1264 |
+
$pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
|
1265 |
+
|
1266 |
+
if ($count) {
|
1267 |
+
if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
|
1268 |
+
array_shift($matches);
|
1269 |
+
$test->setArguments($matches);
|
1270 |
+
|
1271 |
+
return $test;
|
1272 |
+
}
|
1273 |
+
}
|
1274 |
+
}
|
1275 |
+
|
1276 |
+
return false;
|
1277 |
+
}
|
1278 |
+
|
1279 |
+
/**
|
1280 |
+
* Registers a Function.
|
1281 |
+
*
|
1282 |
+
* @param string|TwigFunction $name The function name or a \Twig_SimpleFunction instance
|
1283 |
+
* @param \Twig_FunctionInterface|TwigFunction $function
|
1284 |
+
*/
|
1285 |
+
public function addFunction($name, $function = null)
|
1286 |
+
{
|
1287 |
+
if (!$name instanceof TwigFunction && !($function instanceof TwigFunction || $function instanceof \Twig_FunctionInterface)) {
|
1288 |
+
throw new \LogicException('A function must be an instance of \Twig_FunctionInterface or \Twig_SimpleFunction.');
|
1289 |
+
}
|
1290 |
+
|
1291 |
+
if ($name instanceof TwigFunction) {
|
1292 |
+
$function = $name;
|
1293 |
+
$name = $function->getName();
|
1294 |
+
} else {
|
1295 |
+
@trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED);
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
if ($this->extensionInitialized) {
|
1299 |
+
throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
$this->staging->addFunction($name, $function);
|
1303 |
+
}
|
1304 |
+
|
1305 |
+
/**
|
1306 |
+
* Get a function by name.
|
1307 |
+
*
|
1308 |
+
* Subclasses may override this method and load functions differently;
|
1309 |
+
* so no list of functions is available.
|
1310 |
+
*
|
1311 |
+
* @param string $name function name
|
1312 |
+
*
|
1313 |
+
* @return \Twig_Function|false
|
1314 |
+
*
|
1315 |
+
* @internal
|
1316 |
+
*/
|
1317 |
+
public function getFunction($name)
|
1318 |
+
{
|
1319 |
+
if (!$this->extensionInitialized) {
|
1320 |
+
$this->initExtensions();
|
1321 |
+
}
|
1322 |
+
|
1323 |
+
if (isset($this->functions[$name])) {
|
1324 |
+
return $this->functions[$name];
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
foreach ($this->functions as $pattern => $function) {
|
1328 |
+
$pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
|
1329 |
+
|
1330 |
+
if ($count) {
|
1331 |
+
if (preg_match('#^'.$pattern.'$#', $name, $matches)) {
|
1332 |
+
array_shift($matches);
|
1333 |
+
$function->setArguments($matches);
|
1334 |
+
|
1335 |
+
return $function;
|
1336 |
+
}
|
1337 |
+
}
|
1338 |
+
}
|
1339 |
+
|
1340 |
+
foreach ($this->functionCallbacks as $callback) {
|
1341 |
+
if (false !== $function = \call_user_func($callback, $name)) {
|
1342 |
+
return $function;
|
1343 |
+
}
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
return false;
|
1347 |
+
}
|
1348 |
+
|
1349 |
+
public function registerUndefinedFunctionCallback($callable)
|
1350 |
+
{
|
1351 |
+
$this->functionCallbacks[] = $callable;
|
1352 |
+
}
|
1353 |
+
|
1354 |
+
/**
|
1355 |
+
* Gets registered functions.
|
1356 |
+
*
|
1357 |
+
* Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback.
|
1358 |
+
*
|
1359 |
+
* @return \Twig_FunctionInterface[]
|
1360 |
+
*
|
1361 |
+
* @see registerUndefinedFunctionCallback
|
1362 |
+
*
|
1363 |
+
* @internal
|
1364 |
+
*/
|
1365 |
+
public function getFunctions()
|
1366 |
+
{
|
1367 |
+
if (!$this->extensionInitialized) {
|
1368 |
+
$this->initExtensions();
|
1369 |
+
}
|
1370 |
+
|
1371 |
+
return $this->functions;
|
1372 |
+
}
|
1373 |
+
|
1374 |
+
/**
|
1375 |
+
* Registers a Global.
|
1376 |
+
*
|
1377 |
+
* New globals can be added before compiling or rendering a template;
|
1378 |
+
* but after, you can only update existing globals.
|
1379 |
+
*
|
1380 |
+
* @param string $name The global name
|
1381 |
+
* @param mixed $value The global value
|
1382 |
+
*/
|
1383 |
+
public function addGlobal($name, $value)
|
1384 |
+
{
|
1385 |
+
if ($this->extensionInitialized || $this->runtimeInitialized) {
|
1386 |
+
if (null === $this->globals) {
|
1387 |
+
$this->globals = $this->initGlobals();
|
1388 |
+
}
|
1389 |
+
|
1390 |
+
if (!\array_key_exists($name, $this->globals)) {
|
1391 |
+
// The deprecation notice must be turned into the following exception in Twig 2.0
|
1392 |
+
@trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.', $name), E_USER_DEPRECATED);
|
1393 |
+
//throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name));
|
1394 |
+
}
|
1395 |
+
}
|
1396 |
+
|
1397 |
+
if ($this->extensionInitialized || $this->runtimeInitialized) {
|
1398 |
+
// update the value
|
1399 |
+
$this->globals[$name] = $value;
|
1400 |
+
} else {
|
1401 |
+
$this->staging->addGlobal($name, $value);
|
1402 |
+
}
|
1403 |
+
}
|
1404 |
+
|
1405 |
+
/**
|
1406 |
+
* Gets the registered Globals.
|
1407 |
+
*
|
1408 |
+
* @return array An array of globals
|
1409 |
+
*
|
1410 |
+
* @internal
|
1411 |
+
*/
|
1412 |
+
public function getGlobals()
|
1413 |
+
{
|
1414 |
+
if (!$this->runtimeInitialized && !$this->extensionInitialized) {
|
1415 |
+
return $this->initGlobals();
|
1416 |
+
}
|
1417 |
+
|
1418 |
+
if (null === $this->globals) {
|
1419 |
+
$this->globals = $this->initGlobals();
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
return $this->globals;
|
1423 |
+
}
|
1424 |
+
|
1425 |
+
/**
|
1426 |
+
* Merges a context with the defined globals.
|
1427 |
+
*
|
1428 |
+
* @param array $context An array representing the context
|
1429 |
+
*
|
1430 |
+
* @return array The context merged with the globals
|
1431 |
+
*/
|
1432 |
+
public function mergeGlobals(array $context)
|
1433 |
+
{
|
1434 |
+
// we don't use array_merge as the context being generally
|
1435 |
+
// bigger than globals, this code is faster.
|
1436 |
+
foreach ($this->getGlobals() as $key => $value) {
|
1437 |
+
if (!\array_key_exists($key, $context)) {
|
1438 |
+
$context[$key] = $value;
|
1439 |
+
}
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
return $context;
|
1443 |
+
}
|
1444 |
+
|
1445 |
+
/**
|
1446 |
+
* Gets the registered unary Operators.
|
1447 |
+
*
|
1448 |
+
* @return array An array of unary operators
|
1449 |
+
*
|
1450 |
+
* @internal
|
1451 |
+
*/
|
1452 |
+
public function getUnaryOperators()
|
1453 |
+
{
|
1454 |
+
if (!$this->extensionInitialized) {
|
1455 |
+
$this->initExtensions();
|
1456 |
+
}
|
1457 |
+
|
1458 |
+
return $this->unaryOperators;
|
1459 |
+
}
|
1460 |
+
|
1461 |
+
/**
|
1462 |
+
* Gets the registered binary Operators.
|
1463 |
+
*
|
1464 |
+
* @return array An array of binary operators
|
1465 |
+
*
|
1466 |
+
* @internal
|
1467 |
+
*/
|
1468 |
+
public function getBinaryOperators()
|
1469 |
+
{
|
1470 |
+
if (!$this->extensionInitialized) {
|
1471 |
+
$this->initExtensions();
|
1472 |
+
}
|
1473 |
+
|
1474 |
+
return $this->binaryOperators;
|
1475 |
+
}
|
1476 |
+
|
1477 |
+
/**
|
1478 |
+
* @deprecated since 1.23 (to be removed in 2.0)
|
1479 |
+
*/
|
1480 |
+
public function computeAlternatives($name, $items)
|
1481 |
+
{
|
1482 |
+
@trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
1483 |
+
|
1484 |
+
return SyntaxError::computeAlternatives($name, $items);
|
1485 |
+
}
|
1486 |
+
|
1487 |
+
/**
|
1488 |
+
* @internal
|
1489 |
+
*/
|
1490 |
+
protected function initGlobals()
|
1491 |
+
{
|
1492 |
+
$globals = [];
|
1493 |
+
foreach ($this->extensions as $name => $extension) {
|
1494 |
+
if (!$extension instanceof GlobalsInterface) {
|
1495 |
+
$m = new \ReflectionMethod($extension, 'getGlobals');
|
1496 |
+
|
1497 |
+
$parentClass = $m->getDeclaringClass()->getName();
|
1498 |
+
if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) {
|
1499 |
+
@trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig\Extension\GlobalsInterface is deprecated since version 1.23.', $name), E_USER_DEPRECATED);
|
1500 |
+
}
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
$extGlob = $extension->getGlobals();
|
1504 |
+
if (!\is_array($extGlob)) {
|
1505 |
+
throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension)));
|
1506 |
+
}
|
1507 |
+
|
1508 |
+
$globals[] = $extGlob;
|
1509 |
+
}
|
1510 |
+
|
1511 |
+
$globals[] = $this->staging->getGlobals();
|
1512 |
+
|
1513 |
+
return \call_user_func_array('array_merge', $globals);
|
1514 |
+
}
|
1515 |
+
|
1516 |
+
/**
|
1517 |
+
* @internal
|
1518 |
+
*/
|
1519 |
+
protected function initExtensions()
|
1520 |
+
{
|
1521 |
+
if ($this->extensionInitialized) {
|
1522 |
+
return;
|
1523 |
+
}
|
1524 |
+
|
1525 |
+
$this->parsers = new \Twig_TokenParserBroker([], [], false);
|
1526 |
+
$this->filters = [];
|
1527 |
+
$this->functions = [];
|
1528 |
+
$this->tests = [];
|
1529 |
+
$this->visitors = [];
|
1530 |
+
$this->unaryOperators = [];
|
1531 |
+
$this->binaryOperators = [];
|
1532 |
+
|
1533 |
+
foreach ($this->extensions as $extension) {
|
1534 |
+
$this->initExtension($extension);
|
1535 |
+
}
|
1536 |
+
$this->initExtension($this->staging);
|
1537 |
+
// Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception
|
1538 |
+
$this->extensionInitialized = true;
|
1539 |
+
}
|
1540 |
+
|
1541 |
+
/**
|
1542 |
+
* @internal
|
1543 |
+
*/
|
1544 |
+
protected function initExtension(ExtensionInterface $extension)
|
1545 |
+
{
|
1546 |
+
// filters
|
1547 |
+
foreach ($extension->getFilters() as $name => $filter) {
|
1548 |
+
if ($filter instanceof TwigFilter) {
|
1549 |
+
$name = $filter->getName();
|
1550 |
+
} else {
|
1551 |
+
@trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use \Twig_SimpleFilter instead.', \get_class($filter), $name), E_USER_DEPRECATED);
|
1552 |
+
}
|
1553 |
+
|
1554 |
+
$this->filters[$name] = $filter;
|
1555 |
+
}
|
1556 |
+
|
1557 |
+
// functions
|
1558 |
+
foreach ($extension->getFunctions() as $name => $function) {
|
1559 |
+
if ($function instanceof TwigFunction) {
|
1560 |
+
$name = $function->getName();
|
1561 |
+
} else {
|
1562 |
+
@trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use \Twig_SimpleFunction instead.', \get_class($function), $name), E_USER_DEPRECATED);
|
1563 |
+
}
|
1564 |
+
|
1565 |
+
$this->functions[$name] = $function;
|
1566 |
+
}
|
1567 |
+
|
1568 |
+
// tests
|
1569 |
+
foreach ($extension->getTests() as $name => $test) {
|
1570 |
+
if ($test instanceof TwigTest) {
|
1571 |
+
$name = $test->getName();
|
1572 |
+
} else {
|
1573 |
+
@trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use \Twig_SimpleTest instead.', \get_class($test), $name), E_USER_DEPRECATED);
|
1574 |
+
}
|
1575 |
+
|
1576 |
+
$this->tests[$name] = $test;
|
1577 |
+
}
|
1578 |
+
|
1579 |
+
// token parsers
|
1580 |
+
foreach ($extension->getTokenParsers() as $parser) {
|
1581 |
+
if ($parser instanceof TokenParserInterface) {
|
1582 |
+
$this->parsers->addTokenParser($parser);
|
1583 |
+
} elseif ($parser instanceof \Twig_TokenParserBrokerInterface) {
|
1584 |
+
@trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED);
|
1585 |
+
|
1586 |
+
$this->parsers->addTokenParserBroker($parser);
|
1587 |
+
} else {
|
1588 |
+
throw new \LogicException('getTokenParsers() must return an array of \Twig_TokenParserInterface or \Twig_TokenParserBrokerInterface instances.');
|
1589 |
+
}
|
1590 |
+
}
|
1591 |
+
|
1592 |
+
// node visitors
|
1593 |
+
foreach ($extension->getNodeVisitors() as $visitor) {
|
1594 |
+
$this->visitors[] = $visitor;
|
1595 |
+
}
|
1596 |
+
|
1597 |
+
// operators
|
1598 |
+
if ($operators = $extension->getOperators()) {
|
1599 |
+
if (!\is_array($operators)) {
|
1600 |
+
throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), \is_object($operators) ? \get_class($operators) : \gettype($operators).(\is_resource($operators) ? '' : '#'.$operators)));
|
1601 |
+
}
|
1602 |
+
|
1603 |
+
if (2 !== \count($operators)) {
|
1604 |
+
throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators)));
|
1605 |
+
}
|
1606 |
+
|
1607 |
+
$this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
|
1608 |
+
$this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
|
1609 |
+
}
|
1610 |
+
}
|
1611 |
+
|
1612 |
+
/**
|
1613 |
+
* @deprecated since 1.22 (to be removed in 2.0)
|
1614 |
+
*/
|
1615 |
+
protected function writeCacheFile($file, $content)
|
1616 |
+
{
|
1617 |
+
$this->cache->write($file, $content);
|
1618 |
+
}
|
1619 |
+
|
1620 |
+
private function updateOptionsHash()
|
1621 |
+
{
|
1622 |
+
$hashParts = array_merge(
|
1623 |
+
array_keys($this->extensions),
|
1624 |
+
[
|
1625 |
+
(int) \function_exists('twig_template_get_attributes'),
|
1626 |
+
PHP_MAJOR_VERSION,
|
1627 |
+
PHP_MINOR_VERSION,
|
1628 |
+
self::VERSION,
|
1629 |
+
(int) $this->debug,
|
1630 |
+
$this->baseTemplateClass,
|
1631 |
+
(int) $this->strictVariables,
|
1632 |
+
]
|
1633 |
+
);
|
1634 |
+
$this->optionsHash = implode(':', $hashParts);
|
1635 |
+
}
|
1636 |
+
}
|
1637 |
+
|
1638 |
+
class_alias('Twig\Environment', 'Twig_Environment');
|
vendor/twig/twig/src/Error/Error.php
ADDED
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Error;
|
13 |
+
|
14 |
+
use Twig\Source;
|
15 |
+
use Twig\Template;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Twig base exception.
|
19 |
+
*
|
20 |
+
* This exception class and its children must only be used when
|
21 |
+
* an error occurs during the loading of a template, when a syntax error
|
22 |
+
* is detected in a template, or when rendering a template. Other
|
23 |
+
* errors must use regular PHP exception classes (like when the template
|
24 |
+
* cache directory is not writable for instance).
|
25 |
+
*
|
26 |
+
* To help debugging template issues, this class tracks the original template
|
27 |
+
* name and line where the error occurred.
|
28 |
+
*
|
29 |
+
* Whenever possible, you must set these information (original template name
|
30 |
+
* and line number) yourself by passing them to the constructor. If some or all
|
31 |
+
* these information are not available from where you throw the exception, then
|
32 |
+
* this class will guess them automatically (when the line number is set to -1
|
33 |
+
* and/or the name is set to null). As this is a costly operation, this
|
34 |
+
* can be disabled by passing false for both the name and the line number
|
35 |
+
* when creating a new instance of this class.
|
36 |
+
*
|
37 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
38 |
+
*/
|
39 |
+
class Error extends \Exception
|
40 |
+
{
|
41 |
+
protected $lineno;
|
42 |
+
// to be renamed to name in 2.0
|
43 |
+
protected $filename;
|
44 |
+
protected $rawMessage;
|
45 |
+
|
46 |
+
private $sourcePath;
|
47 |
+
private $sourceCode;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Constructor.
|
51 |
+
*
|
52 |
+
* Set the line number to -1 to enable its automatic guessing.
|
53 |
+
* Set the name to null to enable its automatic guessing.
|
54 |
+
*
|
55 |
+
* @param string $message The error message
|
56 |
+
* @param int $lineno The template line where the error occurred
|
57 |
+
* @param Source|string|null $source The source context where the error occurred
|
58 |
+
* @param \Exception $previous The previous exception
|
59 |
+
*/
|
60 |
+
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null)
|
61 |
+
{
|
62 |
+
if (null === $source) {
|
63 |
+
$name = null;
|
64 |
+
} elseif (!$source instanceof Source) {
|
65 |
+
// for compat with the Twig C ext., passing the template name as string is accepted
|
66 |
+
$name = $source;
|
67 |
+
} else {
|
68 |
+
$name = $source->getName();
|
69 |
+
$this->sourceCode = $source->getCode();
|
70 |
+
$this->sourcePath = $source->getPath();
|
71 |
+
}
|
72 |
+
parent::__construct('', 0, $previous);
|
73 |
+
|
74 |
+
$this->lineno = $lineno;
|
75 |
+
$this->filename = $name;
|
76 |
+
$this->rawMessage = $message;
|
77 |
+
$this->updateRepr();
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Gets the raw message.
|
82 |
+
*
|
83 |
+
* @return string The raw message
|
84 |
+
*/
|
85 |
+
public function getRawMessage()
|
86 |
+
{
|
87 |
+
return $this->rawMessage;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Gets the logical name where the error occurred.
|
92 |
+
*
|
93 |
+
* @return string The name
|
94 |
+
*
|
95 |
+
* @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead.
|
96 |
+
*/
|
97 |
+
public function getTemplateFile()
|
98 |
+
{
|
99 |
+
@trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
|
100 |
+
|
101 |
+
return $this->filename;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Sets the logical name where the error occurred.
|
106 |
+
*
|
107 |
+
* @param string $name The name
|
108 |
+
*
|
109 |
+
* @deprecated since 1.27 (to be removed in 2.0). Use setSourceContext() instead.
|
110 |
+
*/
|
111 |
+
public function setTemplateFile($name)
|
112 |
+
{
|
113 |
+
@trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
|
114 |
+
|
115 |
+
$this->filename = $name;
|
116 |
+
|
117 |
+
$this->updateRepr();
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Gets the logical name where the error occurred.
|
122 |
+
*
|
123 |
+
* @return string The name
|
124 |
+
*
|
125 |
+
* @deprecated since 1.29 (to be removed in 2.0). Use getSourceContext() instead.
|
126 |
+
*/
|
127 |
+
public function getTemplateName()
|
128 |
+
{
|
129 |
+
@trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
|
130 |
+
|
131 |
+
return $this->filename;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Sets the logical name where the error occurred.
|
136 |
+
*
|
137 |
+
* @param string $name The name
|
138 |
+
*
|
139 |
+
* @deprecated since 1.29 (to be removed in 2.0). Use setSourceContext() instead.
|
140 |
+
*/
|
141 |
+
public function setTemplateName($name)
|
142 |
+
{
|
143 |
+
@trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
|
144 |
+
|
145 |
+
$this->filename = $name;
|
146 |
+
$this->sourceCode = $this->sourcePath = null;
|
147 |
+
|
148 |
+
$this->updateRepr();
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Gets the template line where the error occurred.
|
153 |
+
*
|
154 |
+
* @return int The template line
|
155 |
+
*/
|
156 |
+
public function getTemplateLine()
|
157 |
+
{
|
158 |
+
return $this->lineno;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Sets the template line where the error occurred.
|
163 |
+
*
|
164 |
+
* @param int $lineno The template line
|
165 |
+
*/
|
166 |
+
public function setTemplateLine($lineno)
|
167 |
+
{
|
168 |
+
$this->lineno = $lineno;
|
169 |
+
|
170 |
+
$this->updateRepr();
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Gets the source context of the Twig template where the error occurred.
|
175 |
+
*
|
176 |
+
* @return Source|null
|
177 |
+
*/
|
178 |
+
public function getSourceContext()
|
179 |
+
{
|
180 |
+
return $this->filename ? new Source($this->sourceCode, $this->filename, $this->sourcePath) : null;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Sets the source context of the Twig template where the error occurred.
|
185 |
+
*/
|
186 |
+
public function setSourceContext(Source $source = null)
|
187 |
+
{
|
188 |
+
if (null === $source) {
|
189 |
+
$this->sourceCode = $this->filename = $this->sourcePath = null;
|
190 |
+
} else {
|
191 |
+
$this->sourceCode = $source->getCode();
|
192 |
+
$this->filename = $source->getName();
|
193 |
+
$this->sourcePath = $source->getPath();
|
194 |
+
}
|
195 |
+
|
196 |
+
$this->updateRepr();
|
197 |
+
}
|
198 |
+
|
199 |
+
public function guess()
|
200 |
+
{
|
201 |
+
$this->guessTemplateInfo();
|
202 |
+
$this->updateRepr();
|
203 |
+
}
|
204 |
+
|
205 |
+
public function appendMessage($rawMessage)
|
206 |
+
{
|
207 |
+
$this->rawMessage .= $rawMessage;
|
208 |
+
$this->updateRepr();
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* @internal
|
213 |
+
*/
|
214 |
+
protected function updateRepr()
|
215 |
+
{
|
216 |
+
$this->message = $this->rawMessage;
|
217 |
+
|
218 |
+
if ($this->sourcePath && $this->lineno > 0) {
|
219 |
+
$this->file = $this->sourcePath;
|
220 |
+
$this->line = $this->lineno;
|
221 |
+
|
222 |
+
return;
|
223 |
+
}
|
224 |
+
|
225 |
+
$dot = false;
|
226 |
+
if ('.' === substr($this->message, -1)) {
|
227 |
+
$this->message = substr($this->message, 0, -1);
|
228 |
+
$dot = true;
|
229 |
+
}
|
230 |
+
|
231 |
+
$questionMark = false;
|
232 |
+
if ('?' === substr($this->message, -1)) {
|
233 |
+
$this->message = substr($this->message, 0, -1);
|
234 |
+
$questionMark = true;
|
235 |
+
}
|
236 |
+
|
237 |
+
if ($this->filename) {
|
238 |
+
if (\is_string($this->filename) || (\is_object($this->filename) && method_exists($this->filename, '__toString'))) {
|
239 |
+
$name = sprintf('"%s"', $this->filename);
|
240 |
+
} else {
|
241 |
+
$name = json_encode($this->filename);
|
242 |
+
}
|
243 |
+
$this->message .= sprintf(' in %s', $name);
|
244 |
+
}
|
245 |
+
|
246 |
+
if ($this->lineno && $this->lineno >= 0) {
|
247 |
+
$this->message .= sprintf(' at line %d', $this->lineno);
|
248 |
+
}
|
249 |
+
|
250 |
+
if ($dot) {
|
251 |
+
$this->message .= '.';
|
252 |
+
}
|
253 |
+
|
254 |
+
if ($questionMark) {
|
255 |
+
$this->message .= '?';
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* @internal
|
261 |
+
*/
|
262 |
+
protected function guessTemplateInfo()
|
263 |
+
{
|
264 |
+
$template = null;
|
265 |
+
$templateClass = null;
|
266 |
+
|
267 |
+
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
|
268 |
+
foreach ($backtrace as $trace) {
|
269 |
+
if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) {
|
270 |
+
$currentClass = \get_class($trace['object']);
|
271 |
+
$isEmbedContainer = 0 === strpos($templateClass, $currentClass);
|
272 |
+
if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
|
273 |
+
$template = $trace['object'];
|
274 |
+
$templateClass = \get_class($trace['object']);
|
275 |
+
}
|
276 |
+
}
|
277 |
+
}
|
278 |
+
|
279 |
+
// update template name
|
280 |
+
if (null !== $template && null === $this->filename) {
|
281 |
+
$this->filename = $template->getTemplateName();
|
282 |
+
}
|
283 |
+
|
284 |
+
// update template path if any
|
285 |
+
if (null !== $template && null === $this->sourcePath) {
|
286 |
+
$src = $template->getSourceContext();
|
287 |
+
$this->sourceCode = $src->getCode();
|
288 |
+
$this->sourcePath = $src->getPath();
|
289 |
+
}
|
290 |
+
|
291 |
+
if (null === $template || $this->lineno > -1) {
|
292 |
+
return;
|
293 |
+
}
|
294 |
+
|
295 |
+
$r = new \ReflectionObject($template);
|
296 |
+
$file = $r->getFileName();
|
297 |
+
|
298 |
+
$exceptions = [$e = $this];
|
299 |
+
while ($e instanceof self && $e = $e->getPrevious()) {
|
300 |
+
$exceptions[] = $e;
|
301 |
+
}
|
302 |
+
|
303 |
+
while ($e = array_pop($exceptions)) {
|
304 |
+
$traces = $e->getTrace();
|
305 |
+
array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]);
|
306 |
+
|
307 |
+
while ($trace = array_shift($traces)) {
|
308 |
+
if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
|
309 |
+
continue;
|
310 |
+
}
|
311 |
+
|
312 |
+
foreach ($template->getDebugInfo() as $codeLine => $templateLine) {
|
313 |
+
if ($codeLine <= $trace['line']) {
|
314 |
+
// update template line
|
315 |
+
$this->lineno = $templateLine;
|
316 |
+
|
317 |
+
return;
|
318 |
+
}
|
319 |
+
}
|
320 |
+
}
|
321 |
+
}
|
322 |
+
}
|
323 |
+
}
|
324 |
+
|
325 |
+
class_alias('Twig\Error\Error', 'Twig_Error');
|
vendor/twig/twig/src/Error/LoaderError.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Error;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Exception thrown when an error occurs during template loading.
|
16 |
+
*
|
17 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
18 |
+
*/
|
19 |
+
class LoaderError extends Error
|
20 |
+
{
|
21 |
+
}
|
22 |
+
|
23 |
+
class_alias('Twig\Error\LoaderError', 'Twig_Error_Loader');
|
vendor/twig/twig/src/Error/RuntimeError.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
* (c) Armin Ronacher
|
8 |
+
*
|
9 |
+
* For the full copyright and license information, please view the LICENSE
|
10 |
+
* file that was distributed with this source code.
|
11 |
+
*/
|
12 |
+
|
13 |
+
namespace Twig\Error;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Exception thrown when an error occurs at runtime.
|
17 |
+
*
|
18 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
19 |
+
*/
|
20 |
+
class RuntimeError extends Error
|
21 |
+
{
|
22 |
+
}
|
23 |
+
|
24 |
+
class_alias('Twig\Error\RuntimeError', 'Twig_Error_Runtime');
|
vendor/twig/twig/src/Error/SyntaxError.php
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
* (c) Armin Ronacher
|
8 |
+
*
|
9 |
+
* For the full copyright and license information, please view the LICENSE
|
10 |
+
* file that was distributed with this source code.
|
11 |
+
*/
|
12 |
+
|
13 |
+
namespace Twig\Error;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* \Exception thrown when a syntax error occurs during lexing or parsing of a template.
|
17 |
+
*
|
18 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
19 |
+
*/
|
20 |
+
class SyntaxError extends Error
|
21 |
+
{
|
22 |
+
/**
|
23 |
+
* Tweaks the error message to include suggestions.
|
24 |
+
*
|
25 |
+
* @param string $name The original name of the item that does not exist
|
26 |
+
* @param array $items An array of possible items
|
27 |
+
*/
|
28 |
+
public function addSuggestions($name, array $items)
|
29 |
+
{
|
30 |
+
if (!$alternatives = self::computeAlternatives($name, $items)) {
|
31 |
+
return;
|
32 |
+
}
|
33 |
+
|
34 |
+
$this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives)));
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @internal
|
39 |
+
*
|
40 |
+
* To be merged with the addSuggestions() method in 2.0.
|
41 |
+
*/
|
42 |
+
public static function computeAlternatives($name, $items)
|
43 |
+
{
|
44 |
+
$alternatives = [];
|
45 |
+
foreach ($items as $item) {
|
46 |
+
$lev = levenshtein($name, $item);
|
47 |
+
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
|
48 |
+
$alternatives[$item] = $lev;
|
49 |
+
}
|
50 |
+
}
|
51 |
+
asort($alternatives);
|
52 |
+
|
53 |
+
return array_keys($alternatives);
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
class_alias('Twig\Error\SyntaxError', 'Twig_Error_Syntax');
|
vendor/twig/twig/src/ExpressionParser.php
ADDED
@@ -0,0 +1,834 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
* (c) Armin Ronacher
|
8 |
+
*
|
9 |
+
* For the full copyright and license information, please view the LICENSE
|
10 |
+
* file that was distributed with this source code.
|
11 |
+
*/
|
12 |
+
|
13 |
+
namespace Twig;
|
14 |
+
|
15 |
+
use Twig\Error\SyntaxError;
|
16 |
+
use Twig\Node\Expression\ArrayExpression;
|
17 |
+
use Twig\Node\Expression\ArrowFunctionExpression;
|
18 |
+
use Twig\Node\Expression\AssignNameExpression;
|
19 |
+
use Twig\Node\Expression\Binary\ConcatBinary;
|
20 |
+
use Twig\Node\Expression\BlockReferenceExpression;
|
21 |
+
use Twig\Node\Expression\ConditionalExpression;
|
22 |
+
use Twig\Node\Expression\ConstantExpression;
|
23 |
+
use Twig\Node\Expression\GetAttrExpression;
|
24 |
+
use Twig\Node\Expression\MethodCallExpression;
|
25 |
+
use Twig\Node\Expression\NameExpression;
|
26 |
+
use Twig\Node\Expression\ParentExpression;
|
27 |
+
use Twig\Node\Expression\Unary\NegUnary;
|
28 |
+
use Twig\Node\Expression\Unary\NotUnary;
|
29 |
+
use Twig\Node\Expression\Unary\PosUnary;
|
30 |
+
use Twig\Node\Node;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Parses expressions.
|
34 |
+
*
|
35 |
+
* This parser implements a "Precedence climbing" algorithm.
|
36 |
+
*
|
37 |
+
* @see https://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
|
38 |
+
* @see https://en.wikipedia.org/wiki/Operator-precedence_parser
|
39 |
+
*
|
40 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
41 |
+
*
|
42 |
+
* @internal
|
43 |
+
*/
|
44 |
+
class ExpressionParser
|
45 |
+
{
|
46 |
+
const OPERATOR_LEFT = 1;
|
47 |
+
const OPERATOR_RIGHT = 2;
|
48 |
+
|
49 |
+
protected $parser;
|
50 |
+
protected $unaryOperators;
|
51 |
+
protected $binaryOperators;
|
52 |
+
|
53 |
+
private $env;
|
54 |
+
|
55 |
+
public function __construct(Parser $parser, $env = null)
|
56 |
+
{
|
57 |
+
$this->parser = $parser;
|
58 |
+
|
59 |
+
if ($env instanceof Environment) {
|
60 |
+
$this->env = $env;
|
61 |
+
$this->unaryOperators = $env->getUnaryOperators();
|
62 |
+
$this->binaryOperators = $env->getBinaryOperators();
|
63 |
+
} else {
|
64 |
+
@trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED);
|
65 |
+
|
66 |
+
$this->env = $parser->getEnvironment();
|
67 |
+
$this->unaryOperators = func_get_arg(1);
|
68 |
+
$this->binaryOperators = func_get_arg(2);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
public function parseExpression($precedence = 0, $allowArrow = false)
|
73 |
+
{
|
74 |
+
if ($allowArrow && $arrow = $this->parseArrow()) {
|
75 |
+
return $arrow;
|
76 |
+
}
|
77 |
+
|
78 |
+
$expr = $this->getPrimary();
|
79 |
+
$token = $this->parser->getCurrentToken();
|
80 |
+
while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) {
|
81 |
+
$op = $this->binaryOperators[$token->getValue()];
|
82 |
+
$this->parser->getStream()->next();
|
83 |
+
|
84 |
+
if ('is not' === $token->getValue()) {
|
85 |
+
$expr = $this->parseNotTestExpression($expr);
|
86 |
+
} elseif ('is' === $token->getValue()) {
|
87 |
+
$expr = $this->parseTestExpression($expr);
|
88 |
+
} elseif (isset($op['callable'])) {
|
89 |
+
$expr = \call_user_func($op['callable'], $this->parser, $expr);
|
90 |
+
} else {
|
91 |
+
$expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']);
|
92 |
+
$class = $op['class'];
|
93 |
+
$expr = new $class($expr, $expr1, $token->getLine());
|
94 |
+
}
|
95 |
+
|
96 |
+
$token = $this->parser->getCurrentToken();
|
97 |
+
}
|
98 |
+
|
99 |
+
if (0 === $precedence) {
|
100 |
+
return $this->parseConditionalExpression($expr);
|
101 |
+
}
|
102 |
+
|
103 |
+
return $expr;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* @return ArrowFunctionExpression|null
|
108 |
+
*/
|
109 |
+
private function parseArrow()
|
110 |
+
{
|
111 |
+
$stream = $this->parser->getStream();
|
112 |
+
|
113 |
+
// short array syntax (one argument, no parentheses)?
|
114 |
+
if ($stream->look(1)->test(Token::ARROW_TYPE)) {
|
115 |
+
$line = $stream->getCurrent()->getLine();
|
116 |
+
$token = $stream->expect(Token::NAME_TYPE);
|
117 |
+
$names = [new AssignNameExpression($token->getValue(), $token->getLine())];
|
118 |
+
$stream->expect(Token::ARROW_TYPE);
|
119 |
+
|
120 |
+
return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line);
|
121 |
+
}
|
122 |
+
|
123 |
+
// first, determine if we are parsing an arrow function by finding => (long form)
|
124 |
+
$i = 0;
|
125 |
+
if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, '(')) {
|
126 |
+
return null;
|
127 |
+
}
|
128 |
+
++$i;
|
129 |
+
while (true) {
|
130 |
+
// variable name
|
131 |
+
++$i;
|
132 |
+
if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ',')) {
|
133 |
+
break;
|
134 |
+
}
|
135 |
+
++$i;
|
136 |
+
}
|
137 |
+
if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ')')) {
|
138 |
+
return null;
|
139 |
+
}
|
140 |
+
++$i;
|
141 |
+
if (!$stream->look($i)->test(Token::ARROW_TYPE)) {
|
142 |
+
return null;
|
143 |
+
}
|
144 |
+
|
145 |
+
// yes, let's parse it properly
|
146 |
+
$token = $stream->expect(Token::PUNCTUATION_TYPE, '(');
|
147 |
+
$line = $token->getLine();
|
148 |
+
|
149 |
+
$names = [];
|
150 |
+
while (true) {
|
151 |
+
$token = $stream->expect(Token::NAME_TYPE);
|
152 |
+
$names[] = new AssignNameExpression($token->getValue(), $token->getLine());
|
153 |
+
|
154 |
+
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
155 |
+
break;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ')');
|
159 |
+
$stream->expect(Token::ARROW_TYPE);
|
160 |
+
|
161 |
+
return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line);
|
162 |
+
}
|
163 |
+
|
164 |
+
protected function getPrimary()
|
165 |
+
{
|
166 |
+
$token = $this->parser->getCurrentToken();
|
167 |
+
|
168 |
+
if ($this->isUnary($token)) {
|
169 |
+
$operator = $this->unaryOperators[$token->getValue()];
|
170 |
+
$this->parser->getStream()->next();
|
171 |
+
$expr = $this->parseExpression($operator['precedence']);
|
172 |
+
$class = $operator['class'];
|
173 |
+
|
174 |
+
return $this->parsePostfixExpression(new $class($expr, $token->getLine()));
|
175 |
+
} elseif ($token->test(Token::PUNCTUATION_TYPE, '(')) {
|
176 |
+
$this->parser->getStream()->next();
|
177 |
+
$expr = $this->parseExpression();
|
178 |
+
$this->parser->getStream()->expect(Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed');
|
179 |
+
|
180 |
+
return $this->parsePostfixExpression($expr);
|
181 |
+
}
|
182 |
+
|
183 |
+
return $this->parsePrimaryExpression();
|
184 |
+
}
|
185 |
+
|
186 |
+
protected function parseConditionalExpression($expr)
|
187 |
+
{
|
188 |
+
while ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, '?')) {
|
189 |
+
if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) {
|
190 |
+
$expr2 = $this->parseExpression();
|
191 |
+
if ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) {
|
192 |
+
$expr3 = $this->parseExpression();
|
193 |
+
} else {
|
194 |
+
$expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine());
|
195 |
+
}
|
196 |
+
} else {
|
197 |
+
$expr2 = $expr;
|
198 |
+
$expr3 = $this->parseExpression();
|
199 |
+
}
|
200 |
+
|
201 |
+
$expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine());
|
202 |
+
}
|
203 |
+
|
204 |
+
return $expr;
|
205 |
+
}
|
206 |
+
|
207 |
+
protected function isUnary(Token $token)
|
208 |
+
{
|
209 |
+
return $token->test(Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]);
|
210 |
+
}
|
211 |
+
|
212 |
+
protected function isBinary(Token $token)
|
213 |
+
{
|
214 |
+
return $token->test(Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]);
|
215 |
+
}
|
216 |
+
|
217 |
+
public function parsePrimaryExpression()
|
218 |
+
{
|
219 |
+
$token = $this->parser->getCurrentToken();
|
220 |
+
switch ($token->getType()) {
|
221 |
+
case Token::NAME_TYPE:
|
222 |
+
$this->parser->getStream()->next();
|
223 |
+
switch ($token->getValue()) {
|
224 |
+
case 'true':
|
225 |
+
case 'TRUE':
|
226 |
+
$node = new ConstantExpression(true, $token->getLine());
|
227 |
+
break;
|
228 |
+
|
229 |
+
case 'false':
|
230 |
+
case 'FALSE':
|
231 |
+
$node = new ConstantExpression(false, $token->getLine());
|
232 |
+
break;
|
233 |
+
|
234 |
+
case 'none':
|
235 |
+
case 'NONE':
|
236 |
+
case 'null':
|
237 |
+
case 'NULL':
|
238 |
+
$node = new ConstantExpression(null, $token->getLine());
|
239 |
+
break;
|
240 |
+
|
241 |
+
default:
|
242 |
+
if ('(' === $this->parser->getCurrentToken()->getValue()) {
|
243 |
+
$node = $this->getFunctionNode($token->getValue(), $token->getLine());
|
244 |
+
} else {
|
245 |
+
$node = new NameExpression($token->getValue(), $token->getLine());
|
246 |
+
}
|
247 |
+
}
|
248 |
+
break;
|
249 |
+
|
250 |
+
case Token::NUMBER_TYPE:
|
251 |
+
$this->parser->getStream()->next();
|
252 |
+
$node = new ConstantExpression($token->getValue(), $token->getLine());
|
253 |
+
break;
|
254 |
+
|
255 |
+
case Token::STRING_TYPE:
|
256 |
+
case Token::INTERPOLATION_START_TYPE:
|
257 |
+
$node = $this->parseStringExpression();
|
258 |
+
break;
|
259 |
+
|
260 |
+
case Token::OPERATOR_TYPE:
|
261 |
+
if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) {
|
262 |
+
// in this context, string operators are variable names
|
263 |
+
$this->parser->getStream()->next();
|
264 |
+
$node = new NameExpression($token->getValue(), $token->getLine());
|
265 |
+
break;
|
266 |
+
} elseif (isset($this->unaryOperators[$token->getValue()])) {
|
267 |
+
$class = $this->unaryOperators[$token->getValue()]['class'];
|
268 |
+
|
269 |
+
$ref = new \ReflectionClass($class);
|
270 |
+
$negClass = 'Twig\Node\Expression\Unary\NegUnary';
|
271 |
+
$posClass = 'Twig\Node\Expression\Unary\PosUnary';
|
272 |
+
if (!(\in_array($ref->getName(), [$negClass, $posClass, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos'])
|
273 |
+
|| $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass)
|
274 |
+
|| $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos'))
|
275 |
+
) {
|
276 |
+
throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
277 |
+
}
|
278 |
+
|
279 |
+
$this->parser->getStream()->next();
|
280 |
+
$expr = $this->parsePrimaryExpression();
|
281 |
+
|
282 |
+
$node = new $class($expr, $token->getLine());
|
283 |
+
break;
|
284 |
+
}
|
285 |
+
|
286 |
+
// no break
|
287 |
+
default:
|
288 |
+
if ($token->test(Token::PUNCTUATION_TYPE, '[')) {
|
289 |
+
$node = $this->parseArrayExpression();
|
290 |
+
} elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) {
|
291 |
+
$node = $this->parseHashExpression();
|
292 |
+
} elseif ($token->test(Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) {
|
293 |
+
throw new SyntaxError(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
294 |
+
} else {
|
295 |
+
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
return $this->parsePostfixExpression($node);
|
300 |
+
}
|
301 |
+
|
302 |
+
public function parseStringExpression()
|
303 |
+
{
|
304 |
+
$stream = $this->parser->getStream();
|
305 |
+
|
306 |
+
$nodes = [];
|
307 |
+
// a string cannot be followed by another string in a single expression
|
308 |
+
$nextCanBeString = true;
|
309 |
+
while (true) {
|
310 |
+
if ($nextCanBeString && $token = $stream->nextIf(Token::STRING_TYPE)) {
|
311 |
+
$nodes[] = new ConstantExpression($token->getValue(), $token->getLine());
|
312 |
+
$nextCanBeString = false;
|
313 |
+
} elseif ($stream->nextIf(Token::INTERPOLATION_START_TYPE)) {
|
314 |
+
$nodes[] = $this->parseExpression();
|
315 |
+
$stream->expect(Token::INTERPOLATION_END_TYPE);
|
316 |
+
$nextCanBeString = true;
|
317 |
+
} else {
|
318 |
+
break;
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
$expr = array_shift($nodes);
|
323 |
+
foreach ($nodes as $node) {
|
324 |
+
$expr = new ConcatBinary($expr, $node, $node->getTemplateLine());
|
325 |
+
}
|
326 |
+
|
327 |
+
return $expr;
|
328 |
+
}
|
329 |
+
|
330 |
+
public function parseArrayExpression()
|
331 |
+
{
|
332 |
+
$stream = $this->parser->getStream();
|
333 |
+
$stream->expect(Token::PUNCTUATION_TYPE, '[', 'An array element was expected');
|
334 |
+
|
335 |
+
$node = new ArrayExpression([], $stream->getCurrent()->getLine());
|
336 |
+
$first = true;
|
337 |
+
while (!$stream->test(Token::PUNCTUATION_TYPE, ']')) {
|
338 |
+
if (!$first) {
|
339 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma');
|
340 |
+
|
341 |
+
// trailing ,?
|
342 |
+
if ($stream->test(Token::PUNCTUATION_TYPE, ']')) {
|
343 |
+
break;
|
344 |
+
}
|
345 |
+
}
|
346 |
+
$first = false;
|
347 |
+
|
348 |
+
$node->addElement($this->parseExpression());
|
349 |
+
}
|
350 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed');
|
351 |
+
|
352 |
+
return $node;
|
353 |
+
}
|
354 |
+
|
355 |
+
public function parseHashExpression()
|
356 |
+
{
|
357 |
+
$stream = $this->parser->getStream();
|
358 |
+
$stream->expect(Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
|
359 |
+
|
360 |
+
$node = new ArrayExpression([], $stream->getCurrent()->getLine());
|
361 |
+
$first = true;
|
362 |
+
while (!$stream->test(Token::PUNCTUATION_TYPE, '}')) {
|
363 |
+
if (!$first) {
|
364 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma');
|
365 |
+
|
366 |
+
// trailing ,?
|
367 |
+
if ($stream->test(Token::PUNCTUATION_TYPE, '}')) {
|
368 |
+
break;
|
369 |
+
}
|
370 |
+
}
|
371 |
+
$first = false;
|
372 |
+
|
373 |
+
// a hash key can be:
|
374 |
+
//
|
375 |
+
// * a number -- 12
|
376 |
+
// * a string -- 'a'
|
377 |
+
// * a name, which is equivalent to a string -- a
|
378 |
+
// * an expression, which must be enclosed in parentheses -- (1 + 2)
|
379 |
+
if (($token = $stream->nextIf(Token::STRING_TYPE)) || ($token = $stream->nextIf(Token::NAME_TYPE)) || $token = $stream->nextIf(Token::NUMBER_TYPE)) {
|
380 |
+
$key = new ConstantExpression($token->getValue(), $token->getLine());
|
381 |
+
} elseif ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
|
382 |
+
$key = $this->parseExpression();
|
383 |
+
} else {
|
384 |
+
$current = $stream->getCurrent();
|
385 |
+
|
386 |
+
throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext());
|
387 |
+
}
|
388 |
+
|
389 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
|
390 |
+
$value = $this->parseExpression();
|
391 |
+
|
392 |
+
$node->addElement($value, $key);
|
393 |
+
}
|
394 |
+
$stream->expect(Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed');
|
395 |
+
|
396 |
+
return $node;
|
397 |
+
}
|
398 |
+
|
399 |
+
public function parsePostfixExpression($node)
|
400 |
+
{
|
401 |
+
while (true) {
|
402 |
+
$token = $this->parser->getCurrentToken();
|
403 |
+
if (Token::PUNCTUATION_TYPE == $token->getType()) {
|
404 |
+
if ('.' == $token->getValue() || '[' == $token->getValue()) {
|
405 |
+
$node = $this->parseSubscriptExpression($node);
|
406 |
+
} elseif ('|' == $token->getValue()) {
|
407 |
+
$node = $this->parseFilterExpression($node);
|
408 |
+
} else {
|
409 |
+
break;
|
410 |
+
}
|
411 |
+
} else {
|
412 |
+
break;
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
return $node;
|
417 |
+
}
|
418 |
+
|
419 |
+
public function getFunctionNode($name, $line)
|
420 |
+
{
|
421 |
+
switch ($name) {
|
422 |
+
case 'parent':
|
423 |
+
$this->parseArguments();
|
424 |
+
if (!\count($this->parser->getBlockStack())) {
|
425 |
+
throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext());
|
426 |
+
}
|
427 |
+
|
428 |
+
if (!$this->parser->getParent() && !$this->parser->hasTraits()) {
|
429 |
+
throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext());
|
430 |
+
}
|
431 |
+
|
432 |
+
return new ParentExpression($this->parser->peekBlockStack(), $line);
|
433 |
+
case 'block':
|
434 |
+
$args = $this->parseArguments();
|
435 |
+
if (\count($args) < 1) {
|
436 |
+
throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext());
|
437 |
+
}
|
438 |
+
|
439 |
+
return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line);
|
440 |
+
case 'attribute':
|
441 |
+
$args = $this->parseArguments();
|
442 |
+
if (\count($args) < 2) {
|
443 |
+
throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext());
|
444 |
+
}
|
445 |
+
|
446 |
+
return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line);
|
447 |
+
default:
|
448 |
+
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
449 |
+
$arguments = new ArrayExpression([], $line);
|
450 |
+
foreach ($this->parseArguments() as $n) {
|
451 |
+
$arguments->addElement($n);
|
452 |
+
}
|
453 |
+
|
454 |
+
$node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line);
|
455 |
+
$node->setAttribute('safe', true);
|
456 |
+
|
457 |
+
return $node;
|
458 |
+
}
|
459 |
+
|
460 |
+
$args = $this->parseArguments(true);
|
461 |
+
$class = $this->getFunctionNodeClass($name, $line);
|
462 |
+
|
463 |
+
return new $class($name, $args, $line);
|
464 |
+
}
|
465 |
+
}
|
466 |
+
|
467 |
+
public function parseSubscriptExpression($node)
|
468 |
+
{
|
469 |
+
$stream = $this->parser->getStream();
|
470 |
+
$token = $stream->next();
|
471 |
+
$lineno = $token->getLine();
|
472 |
+
$arguments = new ArrayExpression([], $lineno);
|
473 |
+
$type = Template::ANY_CALL;
|
474 |
+
if ('.' == $token->getValue()) {
|
475 |
+
$token = $stream->next();
|
476 |
+
if (
|
477 |
+
Token::NAME_TYPE == $token->getType()
|
478 |
+
||
|
479 |
+
Token::NUMBER_TYPE == $token->getType()
|
480 |
+
||
|
481 |
+
(Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue()))
|
482 |
+
) {
|
483 |
+
$arg = new ConstantExpression($token->getValue(), $lineno);
|
484 |
+
|
485 |
+
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
|
486 |
+
$type = Template::METHOD_CALL;
|
487 |
+
foreach ($this->parseArguments() as $n) {
|
488 |
+
$arguments->addElement($n);
|
489 |
+
}
|
490 |
+
}
|
491 |
+
} else {
|
492 |
+
throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext());
|
493 |
+
}
|
494 |
+
|
495 |
+
if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
|
496 |
+
if (!$arg instanceof ConstantExpression) {
|
497 |
+
throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext());
|
498 |
+
}
|
499 |
+
|
500 |
+
$name = $arg->getAttribute('value');
|
501 |
+
|
502 |
+
if ($this->parser->isReservedMacroName($name)) {
|
503 |
+
throw new SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
|
504 |
+
}
|
505 |
+
|
506 |
+
$node = new MethodCallExpression($node, 'get'.$name, $arguments, $lineno);
|
507 |
+
$node->setAttribute('safe', true);
|
508 |
+
|
509 |
+
return $node;
|
510 |
+
}
|
511 |
+
} else {
|
512 |
+
$type = Template::ARRAY_CALL;
|
513 |
+
|
514 |
+
// slice?
|
515 |
+
$slice = false;
|
516 |
+
if ($stream->test(Token::PUNCTUATION_TYPE, ':')) {
|
517 |
+
$slice = true;
|
518 |
+
$arg = new ConstantExpression(0, $token->getLine());
|
519 |
+
} else {
|
520 |
+
$arg = $this->parseExpression();
|
521 |
+
}
|
522 |
+
|
523 |
+
if ($stream->nextIf(Token::PUNCTUATION_TYPE, ':')) {
|
524 |
+
$slice = true;
|
525 |
+
}
|
526 |
+
|
527 |
+
if ($slice) {
|
528 |
+
if ($stream->test(Token::PUNCTUATION_TYPE, ']')) {
|
529 |
+
$length = new ConstantExpression(null, $token->getLine());
|
530 |
+
} else {
|
531 |
+
$length = $this->parseExpression();
|
532 |
+
}
|
533 |
+
|
534 |
+
$class = $this->getFilterNodeClass('slice', $token->getLine());
|
535 |
+
$arguments = new Node([$arg, $length]);
|
536 |
+
$filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine());
|
537 |
+
|
538 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ']');
|
539 |
+
|
540 |
+
return $filter;
|
541 |
+
}
|
542 |
+
|
543 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ']');
|
544 |
+
}
|
545 |
+
|
546 |
+
return new GetAttrExpression($node, $arg, $arguments, $type, $lineno);
|
547 |
+
}
|
548 |
+
|
549 |
+
public function parseFilterExpression($node)
|
550 |
+
{
|
551 |
+
$this->parser->getStream()->next();
|
552 |
+
|
553 |
+
return $this->parseFilterExpressionRaw($node);
|
554 |
+
}
|
555 |
+
|
556 |
+
public function parseFilterExpressionRaw($node, $tag = null)
|
557 |
+
{
|
558 |
+
while (true) {
|
559 |
+
$token = $this->parser->getStream()->expect(Token::NAME_TYPE);
|
560 |
+
|
561 |
+
$name = new ConstantExpression($token->getValue(), $token->getLine());
|
562 |
+
if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) {
|
563 |
+
$arguments = new Node();
|
564 |
+
} else {
|
565 |
+
$arguments = $this->parseArguments(true, false, true);
|
566 |
+
}
|
567 |
+
|
568 |
+
$class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine());
|
569 |
+
|
570 |
+
$node = new $class($node, $name, $arguments, $token->getLine(), $tag);
|
571 |
+
|
572 |
+
if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '|')) {
|
573 |
+
break;
|
574 |
+
}
|
575 |
+
|
576 |
+
$this->parser->getStream()->next();
|
577 |
+
}
|
578 |
+
|
579 |
+
return $node;
|
580 |
+
}
|
581 |
+
|
582 |
+
/**
|
583 |
+
* Parses arguments.
|
584 |
+
*
|
585 |
+
* @param bool $namedArguments Whether to allow named arguments or not
|
586 |
+
* @param bool $definition Whether we are parsing arguments for a function definition
|
587 |
+
*
|
588 |
+
* @return Node
|
589 |
+
*
|
590 |
+
* @throws SyntaxError
|
591 |
+
*/
|
592 |
+
public function parseArguments($namedArguments = false, $definition = false, $allowArrow = false)
|
593 |
+
{
|
594 |
+
$args = [];
|
595 |
+
$stream = $this->parser->getStream();
|
596 |
+
|
597 |
+
$stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
|
598 |
+
while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) {
|
599 |
+
if (!empty($args)) {
|
600 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
|
601 |
+
}
|
602 |
+
|
603 |
+
if ($definition) {
|
604 |
+
$token = $stream->expect(Token::NAME_TYPE, null, 'An argument must be a name');
|
605 |
+
$value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine());
|
606 |
+
} else {
|
607 |
+
$value = $this->parseExpression(0, $allowArrow);
|
608 |
+
}
|
609 |
+
|
610 |
+
$name = null;
|
611 |
+
if ($namedArguments && $token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) {
|
612 |
+
if (!$value instanceof NameExpression) {
|
613 |
+
throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
|
614 |
+
}
|
615 |
+
$name = $value->getAttribute('name');
|
616 |
+
|
617 |
+
if ($definition) {
|
618 |
+
$value = $this->parsePrimaryExpression();
|
619 |
+
|
620 |
+
if (!$this->checkConstantExpression($value)) {
|
621 |
+
throw new SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext());
|
622 |
+
}
|
623 |
+
} else {
|
624 |
+
$value = $this->parseExpression(0, $allowArrow);
|
625 |
+
}
|
626 |
+
}
|
627 |
+
|
628 |
+
if ($definition) {
|
629 |
+
if (null === $name) {
|
630 |
+
$name = $value->getAttribute('name');
|
631 |
+
$value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine());
|
632 |
+
}
|
633 |
+
$args[$name] = $value;
|
634 |
+
} else {
|
635 |
+
if (null === $name) {
|
636 |
+
$args[] = $value;
|
637 |
+
} else {
|
638 |
+
$args[$name] = $value;
|
639 |
+
}
|
640 |
+
}
|
641 |
+
}
|
642 |
+
$stream->expect(Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');
|
643 |
+
|
644 |
+
return new Node($args);
|
645 |
+
}
|
646 |
+
|
647 |
+
public function parseAssignmentExpression()
|
648 |
+
{
|
649 |
+
$stream = $this->parser->getStream();
|
650 |
+
$targets = [];
|
651 |
+
while (true) {
|
652 |
+
$token = $this->parser->getCurrentToken();
|
653 |
+
if ($stream->test(Token::OPERATOR_TYPE) && preg_match(Lexer::REGEX_NAME, $token->getValue())) {
|
654 |
+
// in this context, string operators are variable names
|
655 |
+
$this->parser->getStream()->next();
|
656 |
+
} else {
|
657 |
+
$stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
658 |
+
}
|
659 |
+
$value = $token->getValue();
|
660 |
+
if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) {
|
661 |
+
throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext());
|
662 |
+
}
|
663 |
+
$targets[] = new AssignNameExpression($value, $token->getLine());
|
664 |
+
|
665 |
+
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
666 |
+
break;
|
667 |
+
}
|
668 |
+
}
|
669 |
+
|
670 |
+
return new Node($targets);
|
671 |
+
}
|
672 |
+
|
673 |
+
public function parseMultitargetExpression()
|
674 |
+
{
|
675 |
+
$targets = [];
|
676 |
+
while (true) {
|
677 |
+
$targets[] = $this->parseExpression();
|
678 |
+
if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
679 |
+
break;
|
680 |
+
}
|
681 |
+
}
|
682 |
+
|
683 |
+
return new Node($targets);
|
684 |
+
}
|
685 |
+
|
686 |
+
private function parseNotTestExpression(\Twig_NodeInterface $node)
|
687 |
+
{
|
688 |
+
return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine());
|
689 |
+
}
|
690 |
+
|
691 |
+
private function parseTestExpression(\Twig_NodeInterface $node)
|
692 |
+
{
|
693 |
+
$stream = $this->parser->getStream();
|
694 |
+
list($name, $test) = $this->getTest($node->getTemplateLine());
|
695 |
+
|
696 |
+
$class = $this->getTestNodeClass($test);
|
697 |
+
$arguments = null;
|
698 |
+
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
|
699 |
+
$arguments = $this->parseArguments(true);
|
700 |
+
}
|
701 |
+
|
702 |
+
return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine());
|
703 |
+
}
|
704 |
+
|
705 |
+
private function getTest($line)
|
706 |
+
{
|
707 |
+
$stream = $this->parser->getStream();
|
708 |
+
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
709 |
+
|
710 |
+
if ($test = $this->env->getTest($name)) {
|
711 |
+
return [$name, $test];
|
712 |
+
}
|
713 |
+
|
714 |
+
if ($stream->test(Token::NAME_TYPE)) {
|
715 |
+
// try 2-words tests
|
716 |
+
$name = $name.' '.$this->parser->getCurrentToken()->getValue();
|
717 |
+
|
718 |
+
if ($test = $this->env->getTest($name)) {
|
719 |
+
$stream->next();
|
720 |
+
|
721 |
+
return [$name, $test];
|
722 |
+
}
|
723 |
+
}
|
724 |
+
|
725 |
+
$e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext());
|
726 |
+
$e->addSuggestions($name, array_keys($this->env->getTests()));
|
727 |
+
|
728 |
+
throw $e;
|
729 |
+
}
|
730 |
+
|
731 |
+
private function getTestNodeClass($test)
|
732 |
+
{
|
733 |
+
if ($test instanceof TwigTest && $test->isDeprecated()) {
|
734 |
+
$stream = $this->parser->getStream();
|
735 |
+
$message = sprintf('Twig Test "%s" is deprecated', $test->getName());
|
736 |
+
if (!\is_bool($test->getDeprecatedVersion())) {
|
737 |
+
$message .= sprintf(' since version %s', $test->getDeprecatedVersion());
|
738 |
+
}
|
739 |
+
if ($test->getAlternative()) {
|
740 |
+
$message .= sprintf('. Use "%s" instead', $test->getAlternative());
|
741 |
+
}
|
742 |
+
$src = $stream->getSourceContext();
|
743 |
+
$message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $stream->getCurrent()->getLine());
|
744 |
+
|
745 |
+
@trigger_error($message, E_USER_DEPRECATED);
|
746 |
+
}
|
747 |
+
|
748 |
+
if ($test instanceof TwigTest) {
|
749 |
+
return $test->getNodeClass();
|
750 |
+
}
|
751 |
+
|
752 |
+
return $test instanceof \Twig_Test_Node ? $test->getClass() : 'Twig\Node\Expression\TestExpression';
|
753 |
+
}
|
754 |
+
|
755 |
+
protected function getFunctionNodeClass($name, $line)
|
756 |
+
{
|
757 |
+
if (false === $function = $this->env->getFunction($name)) {
|
758 |
+
$e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext());
|
759 |
+
$e->addSuggestions($name, array_keys($this->env->getFunctions()));
|
760 |
+
|
761 |
+
throw $e;
|
762 |
+
}
|
763 |
+
|
764 |
+
if ($function instanceof TwigFunction && $function->isDeprecated()) {
|
765 |
+
$message = sprintf('Twig Function "%s" is deprecated', $function->getName());
|
766 |
+
if (!\is_bool($function->getDeprecatedVersion())) {
|
767 |
+
$message .= sprintf(' since version %s', $function->getDeprecatedVersion());
|
768 |
+
}
|
769 |
+
if ($function->getAlternative()) {
|
770 |
+
$message .= sprintf('. Use "%s" instead', $function->getAlternative());
|
771 |
+
}
|
772 |
+
$src = $this->parser->getStream()->getSourceContext();
|
773 |
+
$message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line);
|
774 |
+
|
775 |
+
@trigger_error($message, E_USER_DEPRECATED);
|
776 |
+
}
|
777 |
+
|
778 |
+
if ($function instanceof TwigFunction) {
|
779 |
+
return $function->getNodeClass();
|
780 |
+
}
|
781 |
+
|
782 |
+
return $function instanceof \Twig_Function_Node ? $function->getClass() : 'Twig\Node\Expression\FunctionExpression';
|
783 |
+
}
|
784 |
+
|
785 |
+
protected function getFilterNodeClass($name, $line)
|
786 |
+
{
|
787 |
+
if (false === $filter = $this->env->getFilter($name)) {
|
788 |
+
$e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext());
|
789 |
+
$e->addSuggestions($name, array_keys($this->env->getFilters()));
|
790 |
+
|
791 |
+
throw $e;
|
792 |
+
}
|
793 |
+
|
794 |
+
if ($filter instanceof TwigFilter && $filter->isDeprecated()) {
|
795 |
+
$message = sprintf('Twig Filter "%s" is deprecated', $filter->getName());
|
796 |
+
if (!\is_bool($filter->getDeprecatedVersion())) {
|
797 |
+
$message .= sprintf(' since version %s', $filter->getDeprecatedVersion());
|
798 |
+
}
|
799 |
+
if ($filter->getAlternative()) {
|
800 |
+
$message .= sprintf('. Use "%s" instead', $filter->getAlternative());
|
801 |
+
}
|
802 |
+
$src = $this->parser->getStream()->getSourceContext();
|
803 |
+
$message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line);
|
804 |
+
|
805 |
+
@trigger_error($message, E_USER_DEPRECATED);
|
806 |
+
}
|
807 |
+
|
808 |
+
if ($filter instanceof TwigFilter) {
|
809 |
+
return $filter->getNodeClass();
|
810 |
+
}
|
811 |
+
|
812 |
+
return $filter instanceof \Twig_Filter_Node ? $filter->getClass() : 'Twig\Node\Expression\FilterExpression';
|
813 |
+
}
|
814 |
+
|
815 |
+
// checks that the node only contains "constant" elements
|
816 |
+
protected function checkConstantExpression(\Twig_NodeInterface $node)
|
817 |
+
{
|
818 |
+
if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression
|
819 |
+
|| $node instanceof NegUnary || $node instanceof PosUnary
|
820 |
+
)) {
|
821 |
+
return false;
|
822 |
+
}
|
823 |
+
|
824 |
+
foreach ($node as $n) {
|
825 |
+
if (!$this->checkConstantExpression($n)) {
|
826 |
+
return false;
|
827 |
+
}
|
828 |
+
}
|
829 |
+
|
830 |
+
return true;
|
831 |
+
}
|
832 |
+
}
|
833 |
+
|
834 |
+
class_alias('Twig\ExpressionParser', 'Twig_ExpressionParser');
|
vendor/twig/twig/src/Extension/AbstractExtension.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
use Twig\Environment;
|
15 |
+
|
16 |
+
abstract class AbstractExtension implements ExtensionInterface
|
17 |
+
{
|
18 |
+
/**
|
19 |
+
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead
|
20 |
+
*/
|
21 |
+
public function initRuntime(Environment $environment)
|
22 |
+
{
|
23 |
+
}
|
24 |
+
|
25 |
+
public function getTokenParsers()
|
26 |
+
{
|
27 |
+
return [];
|
28 |
+
}
|
29 |
+
|
30 |
+
public function getNodeVisitors()
|
31 |
+
{
|
32 |
+
return [];
|
33 |
+
}
|
34 |
+
|
35 |
+
public function getFilters()
|
36 |
+
{
|
37 |
+
return [];
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getTests()
|
41 |
+
{
|
42 |
+
return [];
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getFunctions()
|
46 |
+
{
|
47 |
+
return [];
|
48 |
+
}
|
49 |
+
|
50 |
+
public function getOperators()
|
51 |
+
{
|
52 |
+
return [];
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead
|
57 |
+
*/
|
58 |
+
public function getGlobals()
|
59 |
+
{
|
60 |
+
return [];
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @deprecated since 1.26 (to be removed in 2.0), not used anymore internally
|
65 |
+
*/
|
66 |
+
public function getName()
|
67 |
+
{
|
68 |
+
return \get_class($this);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
class_alias('Twig\Extension\AbstractExtension', 'Twig_Extension');
|
vendor/twig/twig/src/Extension/CoreExtension.php
ADDED
@@ -0,0 +1,1724 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension {
|
13 |
+
use Twig\ExpressionParser;
|
14 |
+
use Twig\TokenParser\ApplyTokenParser;
|
15 |
+
use Twig\TokenParser\BlockTokenParser;
|
16 |
+
use Twig\TokenParser\DeprecatedTokenParser;
|
17 |
+
use Twig\TokenParser\DoTokenParser;
|
18 |
+
use Twig\TokenParser\EmbedTokenParser;
|
19 |
+
use Twig\TokenParser\ExtendsTokenParser;
|
20 |
+
use Twig\TokenParser\FilterTokenParser;
|
21 |
+
use Twig\TokenParser\FlushTokenParser;
|
22 |
+
use Twig\TokenParser\ForTokenParser;
|
23 |
+
use Twig\TokenParser\FromTokenParser;
|
24 |
+
use Twig\TokenParser\IfTokenParser;
|
25 |
+
use Twig\TokenParser\ImportTokenParser;
|
26 |
+
use Twig\TokenParser\IncludeTokenParser;
|
27 |
+
use Twig\TokenParser\MacroTokenParser;
|
28 |
+
use Twig\TokenParser\SetTokenParser;
|
29 |
+
use Twig\TokenParser\SpacelessTokenParser;
|
30 |
+
use Twig\TokenParser\UseTokenParser;
|
31 |
+
use Twig\TokenParser\WithTokenParser;
|
32 |
+
use Twig\TwigFilter;
|
33 |
+
use Twig\TwigFunction;
|
34 |
+
use Twig\TwigTest;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @final
|
38 |
+
*/
|
39 |
+
class CoreExtension extends AbstractExtension
|
40 |
+
{
|
41 |
+
protected $dateFormats = ['F j, Y H:i', '%d days'];
|
42 |
+
protected $numberFormat = [0, '.', ','];
|
43 |
+
protected $timezone = null;
|
44 |
+
protected $escapers = [];
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Defines a new escaper to be used via the escape filter.
|
48 |
+
*
|
49 |
+
* @param string $strategy The strategy name that should be used as a strategy in the escape call
|
50 |
+
* @param callable $callable A valid PHP callable
|
51 |
+
*/
|
52 |
+
public function setEscaper($strategy, $callable)
|
53 |
+
{
|
54 |
+
$this->escapers[$strategy] = $callable;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Gets all defined escapers.
|
59 |
+
*
|
60 |
+
* @return array An array of escapers
|
61 |
+
*/
|
62 |
+
public function getEscapers()
|
63 |
+
{
|
64 |
+
return $this->escapers;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Sets the default format to be used by the date filter.
|
69 |
+
*
|
70 |
+
* @param string $format The default date format string
|
71 |
+
* @param string $dateIntervalFormat The default date interval format string
|
72 |
+
*/
|
73 |
+
public function setDateFormat($format = null, $dateIntervalFormat = null)
|
74 |
+
{
|
75 |
+
if (null !== $format) {
|
76 |
+
$this->dateFormats[0] = $format;
|
77 |
+
}
|
78 |
+
|
79 |
+
if (null !== $dateIntervalFormat) {
|
80 |
+
$this->dateFormats[1] = $dateIntervalFormat;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Gets the default format to be used by the date filter.
|
86 |
+
*
|
87 |
+
* @return array The default date format string and the default date interval format string
|
88 |
+
*/
|
89 |
+
public function getDateFormat()
|
90 |
+
{
|
91 |
+
return $this->dateFormats;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Sets the default timezone to be used by the date filter.
|
96 |
+
*
|
97 |
+
* @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object
|
98 |
+
*/
|
99 |
+
public function setTimezone($timezone)
|
100 |
+
{
|
101 |
+
$this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone);
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Gets the default timezone to be used by the date filter.
|
106 |
+
*
|
107 |
+
* @return \DateTimeZone The default timezone currently in use
|
108 |
+
*/
|
109 |
+
public function getTimezone()
|
110 |
+
{
|
111 |
+
if (null === $this->timezone) {
|
112 |
+
$this->timezone = new \DateTimeZone(date_default_timezone_get());
|
113 |
+
}
|
114 |
+
|
115 |
+
return $this->timezone;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Sets the default format to be used by the number_format filter.
|
120 |
+
*
|
121 |
+
* @param int $decimal the number of decimal places to use
|
122 |
+
* @param string $decimalPoint the character(s) to use for the decimal point
|
123 |
+
* @param string $thousandSep the character(s) to use for the thousands separator
|
124 |
+
*/
|
125 |
+
public function setNumberFormat($decimal, $decimalPoint, $thousandSep)
|
126 |
+
{
|
127 |
+
$this->numberFormat = [$decimal, $decimalPoint, $thousandSep];
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Get the default format used by the number_format filter.
|
132 |
+
*
|
133 |
+
* @return array The arguments for number_format()
|
134 |
+
*/
|
135 |
+
public function getNumberFormat()
|
136 |
+
{
|
137 |
+
return $this->numberFormat;
|
138 |
+
}
|
139 |
+
|
140 |
+
public function getTokenParsers()
|
141 |
+
{
|
142 |
+
return [
|
143 |
+
new ApplyTokenParser(),
|
144 |
+
new ForTokenParser(),
|
145 |
+
new IfTokenParser(),
|
146 |
+
new ExtendsTokenParser(),
|
147 |
+
new IncludeTokenParser(),
|
148 |
+
new BlockTokenParser(),
|
149 |
+
new UseTokenParser(),
|
150 |
+
new FilterTokenParser(),
|
151 |
+
new MacroTokenParser(),
|
152 |
+
new ImportTokenParser(),
|
153 |
+
new FromTokenParser(),
|
154 |
+
new SetTokenParser(),
|
155 |
+
new SpacelessTokenParser(),
|
156 |
+
new FlushTokenParser(),
|
157 |
+
new DoTokenParser(),
|
158 |
+
new EmbedTokenParser(),
|
159 |
+
new WithTokenParser(),
|
160 |
+
new DeprecatedTokenParser(),
|
161 |
+
];
|
162 |
+
}
|
163 |
+
|
164 |
+
public function getFilters()
|
165 |
+
{
|
166 |
+
$filters = [
|
167 |
+
// formatting filters
|
168 |
+
new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]),
|
169 |
+
new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
|
170 |
+
new TwigFilter('format', 'sprintf'),
|
171 |
+
new TwigFilter('replace', 'twig_replace_filter'),
|
172 |
+
new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
|
173 |
+
new TwigFilter('abs', 'abs'),
|
174 |
+
new TwigFilter('round', 'twig_round'),
|
175 |
+
|
176 |
+
// encoding
|
177 |
+
new TwigFilter('url_encode', 'twig_urlencode_filter'),
|
178 |
+
new TwigFilter('json_encode', 'twig_jsonencode_filter'),
|
179 |
+
new TwigFilter('convert_encoding', 'twig_convert_encoding'),
|
180 |
+
|
181 |
+
// string filters
|
182 |
+
new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]),
|
183 |
+
new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]),
|
184 |
+
new TwigFilter('upper', 'strtoupper'),
|
185 |
+
new TwigFilter('lower', 'strtolower'),
|
186 |
+
new TwigFilter('striptags', 'strip_tags'),
|
187 |
+
new TwigFilter('trim', 'twig_trim_filter'),
|
188 |
+
new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
189 |
+
new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]),
|
190 |
+
|
191 |
+
// array helpers
|
192 |
+
new TwigFilter('join', 'twig_join_filter'),
|
193 |
+
new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]),
|
194 |
+
new TwigFilter('sort', 'twig_sort_filter'),
|
195 |
+
new TwigFilter('merge', 'twig_array_merge'),
|
196 |
+
new TwigFilter('batch', 'twig_array_batch'),
|
197 |
+
new TwigFilter('filter', 'twig_array_filter'),
|
198 |
+
new TwigFilter('map', 'twig_array_map'),
|
199 |
+
new TwigFilter('reduce', 'twig_array_reduce'),
|
200 |
+
|
201 |
+
// string/array filters
|
202 |
+
new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]),
|
203 |
+
new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]),
|
204 |
+
new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]),
|
205 |
+
new TwigFilter('first', 'twig_first', ['needs_environment' => true]),
|
206 |
+
new TwigFilter('last', 'twig_last', ['needs_environment' => true]),
|
207 |
+
|
208 |
+
// iteration and runtime
|
209 |
+
new TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']),
|
210 |
+
new TwigFilter('keys', 'twig_get_array_keys_filter'),
|
211 |
+
|
212 |
+
// escaping
|
213 |
+
new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
|
214 |
+
new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
|
215 |
+
];
|
216 |
+
|
217 |
+
if (\function_exists('mb_get_info')) {
|
218 |
+
$filters[] = new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]);
|
219 |
+
$filters[] = new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]);
|
220 |
+
}
|
221 |
+
|
222 |
+
return $filters;
|
223 |
+
}
|
224 |
+
|
225 |
+
public function getFunctions()
|
226 |
+
{
|
227 |
+
return [
|
228 |
+
new TwigFunction('max', 'max'),
|
229 |
+
new TwigFunction('min', 'min'),
|
230 |
+
new TwigFunction('range', 'range'),
|
231 |
+
new TwigFunction('constant', 'twig_constant'),
|
232 |
+
new TwigFunction('cycle', 'twig_cycle'),
|
233 |
+
new TwigFunction('random', 'twig_random', ['needs_environment' => true]),
|
234 |
+
new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]),
|
235 |
+
new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
|
236 |
+
new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]),
|
237 |
+
];
|
238 |
+
}
|
239 |
+
|
240 |
+
public function getTests()
|
241 |
+
{
|
242 |
+
return [
|
243 |
+
new TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']),
|
244 |
+
new TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']),
|
245 |
+
new TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']),
|
246 |
+
new TwigTest('sameas', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest', 'deprecated' => '1.21', 'alternative' => 'same as']),
|
247 |
+
new TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']),
|
248 |
+
new TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
|
249 |
+
new TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
|
250 |
+
new TwigTest('divisibleby', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest', 'deprecated' => '1.21', 'alternative' => 'divisible by']),
|
251 |
+
new TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']),
|
252 |
+
new TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']),
|
253 |
+
new TwigTest('empty', 'twig_test_empty'),
|
254 |
+
new TwigTest('iterable', 'twig_test_iterable'),
|
255 |
+
];
|
256 |
+
}
|
257 |
+
|
258 |
+
public function getOperators()
|
259 |
+
{
|
260 |
+
return [
|
261 |
+
[
|
262 |
+
'not' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'],
|
263 |
+
'-' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\NegUnary'],
|
264 |
+
'+' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\PosUnary'],
|
265 |
+
],
|
266 |
+
[
|
267 |
+
'or' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
268 |
+
'and' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
269 |
+
'b-or' => ['precedence' => 16, 'class' => '\Twig\Node\Expression\Binary\BitwiseOrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
270 |
+
'b-xor' => ['precedence' => 17, 'class' => '\Twig\Node\Expression\Binary\BitwiseXorBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
271 |
+
'b-and' => ['precedence' => 18, 'class' => '\Twig\Node\Expression\Binary\BitwiseAndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
272 |
+
'==' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
273 |
+
'!=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
274 |
+
'<' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
275 |
+
'>' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
276 |
+
'>=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
277 |
+
'<=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
278 |
+
'not in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotInBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
279 |
+
'in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\InBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
280 |
+
'matches' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\MatchesBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
281 |
+
'starts with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\StartsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
282 |
+
'ends with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EndsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
283 |
+
'..' => ['precedence' => 25, 'class' => '\Twig\Node\Expression\Binary\RangeBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
284 |
+
'+' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\AddBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
285 |
+
'-' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\SubBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
286 |
+
'~' => ['precedence' => 40, 'class' => '\Twig\Node\Expression\Binary\ConcatBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
287 |
+
'*' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\MulBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
288 |
+
'/' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\DivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
289 |
+
'//' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\FloorDivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
290 |
+
'%' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
291 |
+
'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
292 |
+
'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT],
|
293 |
+
'**' => ['precedence' => 200, 'class' => '\Twig\Node\Expression\Binary\PowerBinary', 'associativity' => ExpressionParser::OPERATOR_RIGHT],
|
294 |
+
'??' => ['precedence' => 300, 'class' => '\Twig\Node\Expression\NullCoalesceExpression', 'associativity' => ExpressionParser::OPERATOR_RIGHT],
|
295 |
+
],
|
296 |
+
];
|
297 |
+
}
|
298 |
+
|
299 |
+
public function getName()
|
300 |
+
{
|
301 |
+
return 'core';
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
class_alias('Twig\Extension\CoreExtension', 'Twig_Extension_Core');
|
306 |
+
}
|
307 |
+
|
308 |
+
namespace {
|
309 |
+
use Twig\Environment;
|
310 |
+
use Twig\Error\LoaderError;
|
311 |
+
use Twig\Error\RuntimeError;
|
312 |
+
use Twig\Loader\SourceContextLoaderInterface;
|
313 |
+
use Twig\Markup;
|
314 |
+
use Twig\Node\Expression\ConstantExpression;
|
315 |
+
use Twig\Node\Node;
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Cycles over a value.
|
319 |
+
*
|
320 |
+
* @param \ArrayAccess|array $values
|
321 |
+
* @param int $position The cycle position
|
322 |
+
*
|
323 |
+
* @return string The next value in the cycle
|
324 |
+
*/
|
325 |
+
function twig_cycle($values, $position)
|
326 |
+
{
|
327 |
+
if (!\is_array($values) && !$values instanceof \ArrayAccess) {
|
328 |
+
return $values;
|
329 |
+
}
|
330 |
+
|
331 |
+
return $values[$position % \count($values)];
|
332 |
+
}
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Returns a random value depending on the supplied parameter type:
|
336 |
+
* - a random item from a \Traversable or array
|
337 |
+
* - a random character from a string
|
338 |
+
* - a random integer between 0 and the integer parameter.
|
339 |
+
*
|
340 |
+
* @param \Traversable|array|int|float|string $values The values to pick a random item from
|
341 |
+
* @param int|null $max Maximum value used when $values is an int
|
342 |
+
*
|
343 |
+
* @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is)
|
344 |
+
*
|
345 |
+
* @return mixed A random value from the given sequence
|
346 |
+
*/
|
347 |
+
function twig_random(Environment $env, $values = null, $max = null)
|
348 |
+
{
|
349 |
+
if (null === $values) {
|
350 |
+
return null === $max ? mt_rand() : mt_rand(0, $max);
|
351 |
+
}
|
352 |
+
|
353 |
+
if (\is_int($values) || \is_float($values)) {
|
354 |
+
if (null === $max) {
|
355 |
+
if ($values < 0) {
|
356 |
+
$max = 0;
|
357 |
+
$min = $values;
|
358 |
+
} else {
|
359 |
+
$max = $values;
|
360 |
+
$min = 0;
|
361 |
+
}
|
362 |
+
} else {
|
363 |
+
$min = $values;
|
364 |
+
$max = $max;
|
365 |
+
}
|
366 |
+
|
367 |
+
return mt_rand($min, $max);
|
368 |
+
}
|
369 |
+
|
370 |
+
if (\is_string($values)) {
|
371 |
+
if ('' === $values) {
|
372 |
+
return '';
|
373 |
+
}
|
374 |
+
if (null !== $charset = $env->getCharset()) {
|
375 |
+
if ('UTF-8' !== $charset) {
|
376 |
+
$values = twig_convert_encoding($values, 'UTF-8', $charset);
|
377 |
+
}
|
378 |
+
|
379 |
+
// unicode version of str_split()
|
380 |
+
// split at all positions, but not after the start and not before the end
|
381 |
+
$values = preg_split('/(?<!^)(?!$)/u', $values);
|
382 |
+
|
383 |
+
if ('UTF-8' !== $charset) {
|
384 |
+
foreach ($values as $i => $value) {
|
385 |
+
$values[$i] = twig_convert_encoding($value, $charset, 'UTF-8');
|
386 |
+
}
|
387 |
+
}
|
388 |
+
} else {
|
389 |
+
return $values[mt_rand(0, \strlen($values) - 1)];
|
390 |
+
}
|
391 |
+
}
|
392 |
+
|
393 |
+
if (!twig_test_iterable($values)) {
|
394 |
+
return $values;
|
395 |
+
}
|
396 |
+
|
397 |
+
$values = twig_to_array($values);
|
398 |
+
|
399 |
+
if (0 === \count($values)) {
|
400 |
+
throw new RuntimeError('The random function cannot pick from an empty array.');
|
401 |
+
}
|
402 |
+
|
403 |
+
return $values[array_rand($values, 1)];
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Converts a date to the given format.
|
408 |
+
*
|
409 |
+
* {{ post.published_at|date("m/d/Y") }}
|
410 |
+
*
|
411 |
+
* @param \DateTime|\DateTimeInterface|\DateInterval|string $date A date
|
412 |
+
* @param string|null $format The target format, null to use the default
|
413 |
+
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
|
414 |
+
*
|
415 |
+
* @return string The formatted date
|
416 |
+
*/
|
417 |
+
function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null)
|
418 |
+
{
|
419 |
+
if (null === $format) {
|
420 |
+
$formats = $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat();
|
421 |
+
$format = $date instanceof \DateInterval ? $formats[1] : $formats[0];
|
422 |
+
}
|
423 |
+
|
424 |
+
if ($date instanceof \DateInterval) {
|
425 |
+
return $date->format($format);
|
426 |
+
}
|
427 |
+
|
428 |
+
return twig_date_converter($env, $date, $timezone)->format($format);
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* Returns a new date object modified.
|
433 |
+
*
|
434 |
+
* {{ post.published_at|date_modify("-1day")|date("m/d/Y") }}
|
435 |
+
*
|
436 |
+
* @param \DateTime|string $date A date
|
437 |
+
* @param string $modifier A modifier string
|
438 |
+
*
|
439 |
+
* @return \DateTime
|
440 |
+
*/
|
441 |
+
function twig_date_modify_filter(Environment $env, $date, $modifier)
|
442 |
+
{
|
443 |
+
$date = twig_date_converter($env, $date, false);
|
444 |
+
$resultDate = $date->modify($modifier);
|
445 |
+
|
446 |
+
// This is a hack to ensure PHP 5.2 support and support for \DateTimeImmutable
|
447 |
+
// \DateTime::modify does not return the modified \DateTime object < 5.3.0
|
448 |
+
// and \DateTimeImmutable does not modify $date.
|
449 |
+
return null === $resultDate ? $date : $resultDate;
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Converts an input to a \DateTime instance.
|
454 |
+
*
|
455 |
+
* {% if date(user.created_at) < date('+2days') %}
|
456 |
+
* {# do something #}
|
457 |
+
* {% endif %}
|
458 |
+
*
|
459 |
+
* @param \DateTime|\DateTimeInterface|string|null $date A date
|
460 |
+
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
|
461 |
+
*
|
462 |
+
* @return \DateTime
|
463 |
+
*/
|
464 |
+
function twig_date_converter(Environment $env, $date = null, $timezone = null)
|
465 |
+
{
|
466 |
+
// determine the timezone
|
467 |
+
if (false !== $timezone) {
|
468 |
+
if (null === $timezone) {
|
469 |
+
$timezone = $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone();
|
470 |
+
} elseif (!$timezone instanceof \DateTimeZone) {
|
471 |
+
$timezone = new \DateTimeZone($timezone);
|
472 |
+
}
|
473 |
+
}
|
474 |
+
|
475 |
+
// immutable dates
|
476 |
+
if ($date instanceof \DateTimeImmutable) {
|
477 |
+
return false !== $timezone ? $date->setTimezone($timezone) : $date;
|
478 |
+
}
|
479 |
+
|
480 |
+
if ($date instanceof \DateTime || $date instanceof \DateTimeInterface) {
|
481 |
+
$date = clone $date;
|
482 |
+
if (false !== $timezone) {
|
483 |
+
$date->setTimezone($timezone);
|
484 |
+
}
|
485 |
+
|
486 |
+
return $date;
|
487 |
+
}
|
488 |
+
|
489 |
+
if (null === $date || 'now' === $date) {
|
490 |
+
return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone());
|
491 |
+
}
|
492 |
+
|
493 |
+
$asString = (string) $date;
|
494 |
+
if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
|
495 |
+
$date = new \DateTime('@'.$date);
|
496 |
+
} else {
|
497 |
+
$date = new \DateTime($date, $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone());
|
498 |
+
}
|
499 |
+
|
500 |
+
if (false !== $timezone) {
|
501 |
+
$date->setTimezone($timezone);
|
502 |
+
}
|
503 |
+
|
504 |
+
return $date;
|
505 |
+
}
|
506 |
+
|
507 |
+
/**
|
508 |
+
* Replaces strings within a string.
|
509 |
+
*
|
510 |
+
* @param string $str String to replace in
|
511 |
+
* @param array|\Traversable $from Replace values
|
512 |
+
* @param string|null $to Replace to, deprecated (@see https://secure.php.net/manual/en/function.strtr.php)
|
513 |
+
*
|
514 |
+
* @return string
|
515 |
+
*/
|
516 |
+
function twig_replace_filter($str, $from, $to = null)
|
517 |
+
{
|
518 |
+
if (\is_string($from) && \is_string($to)) {
|
519 |
+
@trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', E_USER_DEPRECATED);
|
520 |
+
|
521 |
+
return strtr($str, $from, $to);
|
522 |
+
}
|
523 |
+
|
524 |
+
if (!twig_test_iterable($from)) {
|
525 |
+
throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
|
526 |
+
}
|
527 |
+
|
528 |
+
return strtr($str, twig_to_array($from));
|
529 |
+
}
|
530 |
+
|
531 |
+
/**
|
532 |
+
* Rounds a number.
|
533 |
+
*
|
534 |
+
* @param int|float $value The value to round
|
535 |
+
* @param int|float $precision The rounding precision
|
536 |
+
* @param string $method The method to use for rounding
|
537 |
+
*
|
538 |
+
* @return int|float The rounded number
|
539 |
+
*/
|
540 |
+
function twig_round($value, $precision = 0, $method = 'common')
|
541 |
+
{
|
542 |
+
if ('common' == $method) {
|
543 |
+
return round($value, $precision);
|
544 |
+
}
|
545 |
+
|
546 |
+
if ('ceil' != $method && 'floor' != $method) {
|
547 |
+
throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.');
|
548 |
+
}
|
549 |
+
|
550 |
+
return $method($value * pow(10, $precision)) / pow(10, $precision);
|
551 |
+
}
|
552 |
+
|
553 |
+
/**
|
554 |
+
* Number format filter.
|
555 |
+
*
|
556 |
+
* All of the formatting options can be left null, in that case the defaults will
|
557 |
+
* be used. Supplying any of the parameters will override the defaults set in the
|
558 |
+
* environment object.
|
559 |
+
*
|
560 |
+
* @param mixed $number A float/int/string of the number to format
|
561 |
+
* @param int $decimal the number of decimal points to display
|
562 |
+
* @param string $decimalPoint the character(s) to use for the decimal point
|
563 |
+
* @param string $thousandSep the character(s) to use for the thousands separator
|
564 |
+
*
|
565 |
+
* @return string The formatted number
|
566 |
+
*/
|
567 |
+
function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
|
568 |
+
{
|
569 |
+
$defaults = $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat();
|
570 |
+
if (null === $decimal) {
|
571 |
+
$decimal = $defaults[0];
|
572 |
+
}
|
573 |
+
|
574 |
+
if (null === $decimalPoint) {
|
575 |
+
$decimalPoint = $defaults[1];
|
576 |
+
}
|
577 |
+
|
578 |
+
if (null === $thousandSep) {
|
579 |
+
$thousandSep = $defaults[2];
|
580 |
+
}
|
581 |
+
|
582 |
+
return number_format((float) $number, $decimal, $decimalPoint, $thousandSep);
|
583 |
+
}
|
584 |
+
|
585 |
+
/**
|
586 |
+
* URL encodes (RFC 3986) a string as a path segment or an array as a query string.
|
587 |
+
*
|
588 |
+
* @param string|array $url A URL or an array of query parameters
|
589 |
+
*
|
590 |
+
* @return string The URL encoded value
|
591 |
+
*/
|
592 |
+
function twig_urlencode_filter($url)
|
593 |
+
{
|
594 |
+
if (\is_array($url)) {
|
595 |
+
if (\defined('PHP_QUERY_RFC3986')) {
|
596 |
+
return http_build_query($url, '', '&', PHP_QUERY_RFC3986);
|
597 |
+
}
|
598 |
+
|
599 |
+
return http_build_query($url, '', '&');
|
600 |
+
}
|
601 |
+
|
602 |
+
return rawurlencode($url);
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* JSON encodes a variable.
|
607 |
+
*
|
608 |
+
* @param mixed $value the value to encode
|
609 |
+
* @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT
|
610 |
+
*
|
611 |
+
* @return mixed The JSON encoded value
|
612 |
+
*/
|
613 |
+
function twig_jsonencode_filter($value, $options = 0)
|
614 |
+
{
|
615 |
+
if ($value instanceof Markup) {
|
616 |
+
$value = (string) $value;
|
617 |
+
} elseif (\is_array($value)) {
|
618 |
+
array_walk_recursive($value, '_twig_markup2string');
|
619 |
+
}
|
620 |
+
|
621 |
+
return json_encode($value, $options);
|
622 |
+
}
|
623 |
+
|
624 |
+
function _twig_markup2string(&$value)
|
625 |
+
{
|
626 |
+
if ($value instanceof Markup) {
|
627 |
+
$value = (string) $value;
|
628 |
+
}
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Merges an array with another one.
|
633 |
+
*
|
634 |
+
* {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}
|
635 |
+
*
|
636 |
+
* {% set items = items|merge({ 'peugeot': 'car' }) %}
|
637 |
+
*
|
638 |
+
* {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #}
|
639 |
+
*
|
640 |
+
* @param array|\Traversable $arr1 An array
|
641 |
+
* @param array|\Traversable $arr2 An array
|
642 |
+
*
|
643 |
+
* @return array The merged array
|
644 |
+
*/
|
645 |
+
function twig_array_merge($arr1, $arr2)
|
646 |
+
{
|
647 |
+
if (!twig_test_iterable($arr1)) {
|
648 |
+
throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1)));
|
649 |
+
}
|
650 |
+
|
651 |
+
if (!twig_test_iterable($arr2)) {
|
652 |
+
throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2)));
|
653 |
+
}
|
654 |
+
|
655 |
+
return array_merge(twig_to_array($arr1), twig_to_array($arr2));
|
656 |
+
}
|
657 |
+
|
658 |
+
/**
|
659 |
+
* Slices a variable.
|
660 |
+
*
|
661 |
+
* @param mixed $item A variable
|
662 |
+
* @param int $start Start of the slice
|
663 |
+
* @param int $length Size of the slice
|
664 |
+
* @param bool $preserveKeys Whether to preserve key or not (when the input is an array)
|
665 |
+
*
|
666 |
+
* @return mixed The sliced variable
|
667 |
+
*/
|
668 |
+
function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false)
|
669 |
+
{
|
670 |
+
if ($item instanceof \Traversable) {
|
671 |
+
while ($item instanceof \IteratorAggregate) {
|
672 |
+
$item = $item->getIterator();
|
673 |
+
}
|
674 |
+
|
675 |
+
if ($start >= 0 && $length >= 0 && $item instanceof \Iterator) {
|
676 |
+
try {
|
677 |
+
return iterator_to_array(new \LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys);
|
678 |
+
} catch (\OutOfBoundsException $e) {
|
679 |
+
return [];
|
680 |
+
}
|
681 |
+
}
|
682 |
+
|
683 |
+
$item = iterator_to_array($item, $preserveKeys);
|
684 |
+
}
|
685 |
+
|
686 |
+
if (\is_array($item)) {
|
687 |
+
return \array_slice($item, $start, $length, $preserveKeys);
|
688 |
+
}
|
689 |
+
|
690 |
+
$item = (string) $item;
|
691 |
+
|
692 |
+
if (\function_exists('mb_get_info') && null !== $charset = $env->getCharset()) {
|
693 |
+
return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset);
|
694 |
+
}
|
695 |
+
|
696 |
+
return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length));
|
697 |
+
}
|
698 |
+
|
699 |
+
/**
|
700 |
+
* Returns the first element of the item.
|
701 |
+
*
|
702 |
+
* @param mixed $item A variable
|
703 |
+
*
|
704 |
+
* @return mixed The first element of the item
|
705 |
+
*/
|
706 |
+
function twig_first(Environment $env, $item)
|
707 |
+
{
|
708 |
+
$elements = twig_slice($env, $item, 0, 1, false);
|
709 |
+
|
710 |
+
return \is_string($elements) ? $elements : current($elements);
|
711 |
+
}
|
712 |
+
|
713 |
+
/**
|
714 |
+
* Returns the last element of the item.
|
715 |
+
*
|
716 |
+
* @param mixed $item A variable
|
717 |
+
*
|
718 |
+
* @return mixed The last element of the item
|
719 |
+
*/
|
720 |
+
function twig_last(Environment $env, $item)
|
721 |
+
{
|
722 |
+
$elements = twig_slice($env, $item, -1, 1, false);
|
723 |
+
|
724 |
+
return \is_string($elements) ? $elements : current($elements);
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Joins the values to a string.
|
729 |
+
*
|
730 |
+
* The separators between elements are empty strings per default, you can define them with the optional parameters.
|
731 |
+
*
|
732 |
+
* {{ [1, 2, 3]|join(', ', ' and ') }}
|
733 |
+
* {# returns 1, 2 and 3 #}
|
734 |
+
*
|
735 |
+
* {{ [1, 2, 3]|join('|') }}
|
736 |
+
* {# returns 1|2|3 #}
|
737 |
+
*
|
738 |
+
* {{ [1, 2, 3]|join }}
|
739 |
+
* {# returns 123 #}
|
740 |
+
*
|
741 |
+
* @param array $value An array
|
742 |
+
* @param string $glue The separator
|
743 |
+
* @param string|null $and The separator for the last pair
|
744 |
+
*
|
745 |
+
* @return string The concatenated string
|
746 |
+
*/
|
747 |
+
function twig_join_filter($value, $glue = '', $and = null)
|
748 |
+
{
|
749 |
+
if (!twig_test_iterable($value)) {
|
750 |
+
$value = (array) $value;
|
751 |
+
}
|
752 |
+
|
753 |
+
$value = twig_to_array($value, false);
|
754 |
+
|
755 |
+
if (0 === \count($value)) {
|
756 |
+
return '';
|
757 |
+
}
|
758 |
+
|
759 |
+
if (null === $and || $and === $glue) {
|
760 |
+
return implode($glue, $value);
|
761 |
+
}
|
762 |
+
|
763 |
+
if (1 === \count($value)) {
|
764 |
+
return $value[0];
|
765 |
+
}
|
766 |
+
|
767 |
+
return implode($glue, \array_slice($value, 0, -1)).$and.$value[\count($value) - 1];
|
768 |
+
}
|
769 |
+
|
770 |
+
/**
|
771 |
+
* Splits the string into an array.
|
772 |
+
*
|
773 |
+
* {{ "one,two,three"|split(',') }}
|
774 |
+
* {# returns [one, two, three] #}
|
775 |
+
*
|
776 |
+
* {{ "one,two,three,four,five"|split(',', 3) }}
|
777 |
+
* {# returns [one, two, "three,four,five"] #}
|
778 |
+
*
|
779 |
+
* {{ "123"|split('') }}
|
780 |
+
* {# returns [1, 2, 3] #}
|
781 |
+
*
|
782 |
+
* {{ "aabbcc"|split('', 2) }}
|
783 |
+
* {# returns [aa, bb, cc] #}
|
784 |
+
*
|
785 |
+
* @param string $value A string
|
786 |
+
* @param string $delimiter The delimiter
|
787 |
+
* @param int $limit The limit
|
788 |
+
*
|
789 |
+
* @return array The split string as an array
|
790 |
+
*/
|
791 |
+
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
|
792 |
+
{
|
793 |
+
if (!empty($delimiter)) {
|
794 |
+
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
|
795 |
+
}
|
796 |
+
|
797 |
+
if (!\function_exists('mb_get_info') || null === $charset = $env->getCharset()) {
|
798 |
+
return str_split($value, null === $limit ? 1 : $limit);
|
799 |
+
}
|
800 |
+
|
801 |
+
if ($limit <= 1) {
|
802 |
+
return preg_split('/(?<!^)(?!$)/u', $value);
|
803 |
+
}
|
804 |
+
|
805 |
+
$length = mb_strlen($value, $charset);
|
806 |
+
if ($length < $limit) {
|
807 |
+
return [$value];
|
808 |
+
}
|
809 |
+
|
810 |
+
$r = [];
|
811 |
+
for ($i = 0; $i < $length; $i += $limit) {
|
812 |
+
$r[] = mb_substr($value, $i, $limit, $charset);
|
813 |
+
}
|
814 |
+
|
815 |
+
return $r;
|
816 |
+
}
|
817 |
+
|
818 |
+
// The '_default' filter is used internally to avoid using the ternary operator
|
819 |
+
// which costs a lot for big contexts (before PHP 5.4). So, on average,
|
820 |
+
// a function call is cheaper.
|
821 |
+
/**
|
822 |
+
* @internal
|
823 |
+
*/
|
824 |
+
function _twig_default_filter($value, $default = '')
|
825 |
+
{
|
826 |
+
if (twig_test_empty($value)) {
|
827 |
+
return $default;
|
828 |
+
}
|
829 |
+
|
830 |
+
return $value;
|
831 |
+
}
|
832 |
+
|
833 |
+
/**
|
834 |
+
* Returns the keys for the given array.
|
835 |
+
*
|
836 |
+
* It is useful when you want to iterate over the keys of an array:
|
837 |
+
*
|
838 |
+
* {% for key in array|keys %}
|
839 |
+
* {# ... #}
|
840 |
+
* {% endfor %}
|
841 |
+
*
|
842 |
+
* @param array $array An array
|
843 |
+
*
|
844 |
+
* @return array The keys
|
845 |
+
*/
|
846 |
+
function twig_get_array_keys_filter($array)
|
847 |
+
{
|
848 |
+
if ($array instanceof \Traversable) {
|
849 |
+
while ($array instanceof \IteratorAggregate) {
|
850 |
+
$array = $array->getIterator();
|
851 |
+
}
|
852 |
+
|
853 |
+
if ($array instanceof \Iterator) {
|
854 |
+
$keys = [];
|
855 |
+
$array->rewind();
|
856 |
+
while ($array->valid()) {
|
857 |
+
$keys[] = $array->key();
|
858 |
+
$array->next();
|
859 |
+
}
|
860 |
+
|
861 |
+
return $keys;
|
862 |
+
}
|
863 |
+
|
864 |
+
$keys = [];
|
865 |
+
foreach ($array as $key => $item) {
|
866 |
+
$keys[] = $key;
|
867 |
+
}
|
868 |
+
|
869 |
+
return $keys;
|
870 |
+
}
|
871 |
+
|
872 |
+
if (!\is_array($array)) {
|
873 |
+
return [];
|
874 |
+
}
|
875 |
+
|
876 |
+
return array_keys($array);
|
877 |
+
}
|
878 |
+
|
879 |
+
/**
|
880 |
+
* Reverses a variable.
|
881 |
+
*
|
882 |
+
* @param array|\Traversable|string $item An array, a \Traversable instance, or a string
|
883 |
+
* @param bool $preserveKeys Whether to preserve key or not
|
884 |
+
*
|
885 |
+
* @return mixed The reversed input
|
886 |
+
*/
|
887 |
+
function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
|
888 |
+
{
|
889 |
+
if ($item instanceof \Traversable) {
|
890 |
+
return array_reverse(iterator_to_array($item), $preserveKeys);
|
891 |
+
}
|
892 |
+
|
893 |
+
if (\is_array($item)) {
|
894 |
+
return array_reverse($item, $preserveKeys);
|
895 |
+
}
|
896 |
+
|
897 |
+
if (null !== $charset = $env->getCharset()) {
|
898 |
+
$string = (string) $item;
|
899 |
+
|
900 |
+
if ('UTF-8' !== $charset) {
|
901 |
+
$item = twig_convert_encoding($string, 'UTF-8', $charset);
|
902 |
+
}
|
903 |
+
|
904 |
+
preg_match_all('/./us', $item, $matches);
|
905 |
+
|
906 |
+
$string = implode('', array_reverse($matches[0]));
|
907 |
+
|
908 |
+
if ('UTF-8' !== $charset) {
|
909 |
+
$string = twig_convert_encoding($string, $charset, 'UTF-8');
|
910 |
+
}
|
911 |
+
|
912 |
+
return $string;
|
913 |
+
}
|
914 |
+
|
915 |
+
return strrev((string) $item);
|
916 |
+
}
|
917 |
+
|
918 |
+
/**
|
919 |
+
* Sorts an array.
|
920 |
+
*
|
921 |
+
* @param array|\Traversable $array
|
922 |
+
*
|
923 |
+
* @return array
|
924 |
+
*/
|
925 |
+
function twig_sort_filter($array)
|
926 |
+
{
|
927 |
+
if ($array instanceof \Traversable) {
|
928 |
+
$array = iterator_to_array($array);
|
929 |
+
} elseif (!\is_array($array)) {
|
930 |
+
throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array)));
|
931 |
+
}
|
932 |
+
|
933 |
+
asort($array);
|
934 |
+
|
935 |
+
return $array;
|
936 |
+
}
|
937 |
+
|
938 |
+
/**
|
939 |
+
* @internal
|
940 |
+
*/
|
941 |
+
function twig_in_filter($value, $compare)
|
942 |
+
{
|
943 |
+
if ($value instanceof Markup) {
|
944 |
+
$value = (string) $value;
|
945 |
+
}
|
946 |
+
if ($compare instanceof Markup) {
|
947 |
+
$compare = (string) $compare;
|
948 |
+
}
|
949 |
+
|
950 |
+
if (\is_array($compare)) {
|
951 |
+
return \in_array($value, $compare, \is_object($value) || \is_resource($value));
|
952 |
+
} elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) {
|
953 |
+
return '' === $value || false !== strpos($compare, (string) $value);
|
954 |
+
} elseif ($compare instanceof \Traversable) {
|
955 |
+
if (\is_object($value) || \is_resource($value)) {
|
956 |
+
foreach ($compare as $item) {
|
957 |
+
if ($item === $value) {
|
958 |
+
return true;
|
959 |
+
}
|
960 |
+
}
|
961 |
+
} else {
|
962 |
+
foreach ($compare as $item) {
|
963 |
+
if ($item == $value) {
|
964 |
+
return true;
|
965 |
+
}
|
966 |
+
}
|
967 |
+
}
|
968 |
+
|
969 |
+
return false;
|
970 |
+
}
|
971 |
+
|
972 |
+
return false;
|
973 |
+
}
|
974 |
+
|
975 |
+
/**
|
976 |
+
* Returns a trimmed string.
|
977 |
+
*
|
978 |
+
* @return string
|
979 |
+
*
|
980 |
+
* @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both')
|
981 |
+
*/
|
982 |
+
function twig_trim_filter($string, $characterMask = null, $side = 'both')
|
983 |
+
{
|
984 |
+
if (null === $characterMask) {
|
985 |
+
$characterMask = " \t\n\r\0\x0B";
|
986 |
+
}
|
987 |
+
|
988 |
+
switch ($side) {
|
989 |
+
case 'both':
|
990 |
+
return trim($string, $characterMask);
|
991 |
+
case 'left':
|
992 |
+
return ltrim($string, $characterMask);
|
993 |
+
case 'right':
|
994 |
+
return rtrim($string, $characterMask);
|
995 |
+
default:
|
996 |
+
throw new RuntimeError('Trimming side must be "left", "right" or "both".');
|
997 |
+
}
|
998 |
+
}
|
999 |
+
|
1000 |
+
/**
|
1001 |
+
* Removes whitespaces between HTML tags.
|
1002 |
+
*
|
1003 |
+
* @return string
|
1004 |
+
*/
|
1005 |
+
function twig_spaceless($content)
|
1006 |
+
{
|
1007 |
+
return trim(preg_replace('/>\s+</', '><', $content));
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
/**
|
1011 |
+
* Escapes a string.
|
1012 |
+
*
|
1013 |
+
* @param mixed $string The value to be escaped
|
1014 |
+
* @param string $strategy The escaping strategy
|
1015 |
+
* @param string $charset The charset
|
1016 |
+
* @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false)
|
1017 |
+
*
|
1018 |
+
* @return string
|
1019 |
+
*/
|
1020 |
+
function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false)
|
1021 |
+
{
|
1022 |
+
if ($autoescape && $string instanceof Markup) {
|
1023 |
+
return $string;
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
if (!\is_string($string)) {
|
1027 |
+
if (\is_object($string) && method_exists($string, '__toString')) {
|
1028 |
+
$string = (string) $string;
|
1029 |
+
} elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) {
|
1030 |
+
return $string;
|
1031 |
+
}
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
if ('' === $string) {
|
1035 |
+
return '';
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
if (null === $charset) {
|
1039 |
+
$charset = $env->getCharset();
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
switch ($strategy) {
|
1043 |
+
case 'html':
|
1044 |
+
// see https://secure.php.net/htmlspecialchars
|
1045 |
+
|
1046 |
+
// Using a static variable to avoid initializing the array
|
1047 |
+
// each time the function is called. Moving the declaration on the
|
1048 |
+
// top of the function slow downs other escaping strategies.
|
1049 |
+
static $htmlspecialcharsCharsets = [
|
1050 |
+
'ISO-8859-1' => true, 'ISO8859-1' => true,
|
1051 |
+
'ISO-8859-15' => true, 'ISO8859-15' => true,
|
1052 |
+
'utf-8' => true, 'UTF-8' => true,
|
1053 |
+
'CP866' => true, 'IBM866' => true, '866' => true,
|
1054 |
+
'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true,
|
1055 |
+
'1251' => true,
|
1056 |
+
'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true,
|
1057 |
+
'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true,
|
1058 |
+
'BIG5' => true, '950' => true,
|
1059 |
+
'GB2312' => true, '936' => true,
|
1060 |
+
'BIG5-HKSCS' => true,
|
1061 |
+
'SHIFT_JIS' => true, 'SJIS' => true, '932' => true,
|
1062 |
+
'EUC-JP' => true, 'EUCJP' => true,
|
1063 |
+
'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true,
|
1064 |
+
];
|
1065 |
+
|
1066 |
+
if (isset($htmlspecialcharsCharsets[$charset])) {
|
1067 |
+
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) {
|
1071 |
+
// cache the lowercase variant for future iterations
|
1072 |
+
$htmlspecialcharsCharsets[$charset] = true;
|
1073 |
+
|
1074 |
+
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
|
1075 |
+
}
|
1076 |
+
|
1077 |
+
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
1078 |
+
$string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
1079 |
+
|
1080 |
+
return twig_convert_encoding($string, $charset, 'UTF-8');
|
1081 |
+
|
1082 |
+
case 'js':
|
1083 |
+
// escape all non-alphanumeric characters
|
1084 |
+
// into their \x or \uHHHH representations
|
1085 |
+
if ('UTF-8' !== $charset) {
|
1086 |
+
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
1087 |
+
}
|
1088 |
+
|
1089 |
+
if (!preg_match('//u', $string)) {
|
1090 |
+
throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
|
1091 |
+
}
|
1092 |
+
|
1093 |
+
$string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string);
|
1094 |
+
|
1095 |
+
if ('UTF-8' !== $charset) {
|
1096 |
+
$string = twig_convert_encoding($string, $charset, 'UTF-8');
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
return $string;
|
1100 |
+
|
1101 |
+
case 'css':
|
1102 |
+
if ('UTF-8' !== $charset) {
|
1103 |
+
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
1104 |
+
}
|
1105 |
+
|
1106 |
+
if (!preg_match('//u', $string)) {
|
1107 |
+
throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
|
1108 |
+
}
|
1109 |
+
|
1110 |
+
$string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string);
|
1111 |
+
|
1112 |
+
if ('UTF-8' !== $charset) {
|
1113 |
+
$string = twig_convert_encoding($string, $charset, 'UTF-8');
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
return $string;
|
1117 |
+
|
1118 |
+
case 'html_attr':
|
1119 |
+
if ('UTF-8' !== $charset) {
|
1120 |
+
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
1121 |
+
}
|
1122 |
+
|
1123 |
+
if (!preg_match('//u', $string)) {
|
1124 |
+
throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
|
1125 |
+
}
|
1126 |
+
|
1127 |
+
$string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string);
|
1128 |
+
|
1129 |
+
if ('UTF-8' !== $charset) {
|
1130 |
+
$string = twig_convert_encoding($string, $charset, 'UTF-8');
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
return $string;
|
1134 |
+
|
1135 |
+
case 'url':
|
1136 |
+
return rawurlencode($string);
|
1137 |
+
|
1138 |
+
default:
|
1139 |
+
static $escapers;
|
1140 |
+
|
1141 |
+
if (null === $escapers) {
|
1142 |
+
$escapers = $env->getExtension('\Twig\Extension\CoreExtension')->getEscapers();
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
if (isset($escapers[$strategy])) {
|
1146 |
+
return \call_user_func($escapers[$strategy], $env, $string, $charset);
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
$validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers)));
|
1150 |
+
|
1151 |
+
throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies));
|
1152 |
+
}
|
1153 |
+
}
|
1154 |
+
|
1155 |
+
/**
|
1156 |
+
* @internal
|
1157 |
+
*/
|
1158 |
+
function twig_escape_filter_is_safe(Node $filterArgs)
|
1159 |
+
{
|
1160 |
+
foreach ($filterArgs as $arg) {
|
1161 |
+
if ($arg instanceof ConstantExpression) {
|
1162 |
+
return [$arg->getAttribute('value')];
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
return [];
|
1166 |
+
}
|
1167 |
+
|
1168 |
+
return ['html'];
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
if (\function_exists('mb_convert_encoding')) {
|
1172 |
+
function twig_convert_encoding($string, $to, $from)
|
1173 |
+
{
|
1174 |
+
return mb_convert_encoding($string, $to, $from);
|
1175 |
+
}
|
1176 |
+
} elseif (\function_exists('iconv')) {
|
1177 |
+
function twig_convert_encoding($string, $to, $from)
|
1178 |
+
{
|
1179 |
+
return iconv($from, $to, $string);
|
1180 |
+
}
|
1181 |
+
} else {
|
1182 |
+
function twig_convert_encoding($string, $to, $from)
|
1183 |
+
{
|
1184 |
+
throw new RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
|
1185 |
+
}
|
1186 |
+
}
|
1187 |
+
|
1188 |
+
if (\function_exists('mb_ord')) {
|
1189 |
+
function twig_ord($string)
|
1190 |
+
{
|
1191 |
+
return mb_ord($string, 'UTF-8');
|
1192 |
+
}
|
1193 |
+
} else {
|
1194 |
+
function twig_ord($string)
|
1195 |
+
{
|
1196 |
+
$code = ($string = unpack('C*', substr($string, 0, 4))) ? $string[1] : 0;
|
1197 |
+
if (0xF0 <= $code) {
|
1198 |
+
return (($code - 0xF0) << 18) + (($string[2] - 0x80) << 12) + (($string[3] - 0x80) << 6) + $string[4] - 0x80;
|
1199 |
+
}
|
1200 |
+
if (0xE0 <= $code) {
|
1201 |
+
return (($code - 0xE0) << 12) + (($string[2] - 0x80) << 6) + $string[3] - 0x80;
|
1202 |
+
}
|
1203 |
+
if (0xC0 <= $code) {
|
1204 |
+
return (($code - 0xC0) << 6) + $string[2] - 0x80;
|
1205 |
+
}
|
1206 |
+
|
1207 |
+
return $code;
|
1208 |
+
}
|
1209 |
+
}
|
1210 |
+
|
1211 |
+
function _twig_escape_js_callback($matches)
|
1212 |
+
{
|
1213 |
+
$char = $matches[0];
|
1214 |
+
|
1215 |
+
/*
|
1216 |
+
* A few characters have short escape sequences in JSON and JavaScript.
|
1217 |
+
* Escape sequences supported only by JavaScript, not JSON, are ommitted.
|
1218 |
+
* \" is also supported but omitted, because the resulting string is not HTML safe.
|
1219 |
+
*/
|
1220 |
+
static $shortMap = [
|
1221 |
+
'\\' => '\\\\',
|
1222 |
+
'/' => '\\/',
|
1223 |
+
"\x08" => '\b',
|
1224 |
+
"\x0C" => '\f',
|
1225 |
+
"\x0A" => '\n',
|
1226 |
+
"\x0D" => '\r',
|
1227 |
+
"\x09" => '\t',
|
1228 |
+
];
|
1229 |
+
|
1230 |
+
if (isset($shortMap[$char])) {
|
1231 |
+
return $shortMap[$char];
|
1232 |
+
}
|
1233 |
+
|
1234 |
+
// \uHHHH
|
1235 |
+
$char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
|
1236 |
+
$char = strtoupper(bin2hex($char));
|
1237 |
+
|
1238 |
+
if (4 >= \strlen($char)) {
|
1239 |
+
return sprintf('\u%04s', $char);
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4));
|
1243 |
+
}
|
1244 |
+
|
1245 |
+
function _twig_escape_css_callback($matches)
|
1246 |
+
{
|
1247 |
+
$char = $matches[0];
|
1248 |
+
|
1249 |
+
return sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : twig_ord($char));
|
1250 |
+
}
|
1251 |
+
|
1252 |
+
/**
|
1253 |
+
* This function is adapted from code coming from Zend Framework.
|
1254 |
+
*
|
1255 |
+
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com)
|
1256 |
+
* @license https://framework.zend.com/license/new-bsd New BSD License
|
1257 |
+
*/
|
1258 |
+
function _twig_escape_html_attr_callback($matches)
|
1259 |
+
{
|
1260 |
+
$chr = $matches[0];
|
1261 |
+
$ord = \ord($chr);
|
1262 |
+
|
1263 |
+
/*
|
1264 |
+
* The following replaces characters undefined in HTML with the
|
1265 |
+
* hex entity for the Unicode replacement character.
|
1266 |
+
*/
|
1267 |
+
if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) {
|
1268 |
+
return '�';
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
/*
|
1272 |
+
* Check if the current character to escape has a name entity we should
|
1273 |
+
* replace it with while grabbing the hex value of the character.
|
1274 |
+
*/
|
1275 |
+
if (1 == \strlen($chr)) {
|
1276 |
+
/*
|
1277 |
+
* While HTML supports far more named entities, the lowest common denominator
|
1278 |
+
* has become HTML5's XML Serialisation which is restricted to the those named
|
1279 |
+
* entities that XML supports. Using HTML entities would result in this error:
|
1280 |
+
* XML Parsing Error: undefined entity
|
1281 |
+
*/
|
1282 |
+
static $entityMap = [
|
1283 |
+
34 => '"', /* quotation mark */
|
1284 |
+
38 => '&', /* ampersand */
|
1285 |
+
60 => '<', /* less-than sign */
|
1286 |
+
62 => '>', /* greater-than sign */
|
1287 |
+
];
|
1288 |
+
|
1289 |
+
if (isset($entityMap[$ord])) {
|
1290 |
+
return $entityMap[$ord];
|
1291 |
+
}
|
1292 |
+
|
1293 |
+
return sprintf('&#x%02X;', $ord);
|
1294 |
+
}
|
1295 |
+
|
1296 |
+
/*
|
1297 |
+
* Per OWASP recommendations, we'll use hex entities for any other
|
1298 |
+
* characters where a named entity does not exist.
|
1299 |
+
*/
|
1300 |
+
return sprintf('&#x%04X;', twig_ord($chr));
|
1301 |
+
}
|
1302 |
+
|
1303 |
+
// add multibyte extensions if possible
|
1304 |
+
if (\function_exists('mb_get_info')) {
|
1305 |
+
/**
|
1306 |
+
* Returns the length of a variable.
|
1307 |
+
*
|
1308 |
+
* @param mixed $thing A variable
|
1309 |
+
*
|
1310 |
+
* @return int The length of the value
|
1311 |
+
*/
|
1312 |
+
function twig_length_filter(Environment $env, $thing)
|
1313 |
+
{
|
1314 |
+
if (null === $thing) {
|
1315 |
+
return 0;
|
1316 |
+
}
|
1317 |
+
|
1318 |
+
if (is_scalar($thing)) {
|
1319 |
+
return mb_strlen($thing, $env->getCharset());
|
1320 |
+
}
|
1321 |
+
|
1322 |
+
if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) {
|
1323 |
+
return \count($thing);
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
if ($thing instanceof \Traversable) {
|
1327 |
+
return iterator_count($thing);
|
1328 |
+
}
|
1329 |
+
|
1330 |
+
if (\is_object($thing) && method_exists($thing, '__toString')) {
|
1331 |
+
return mb_strlen((string) $thing, $env->getCharset());
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
return 1;
|
1335 |
+
}
|
1336 |
+
|
1337 |
+
/**
|
1338 |
+
* Converts a string to uppercase.
|
1339 |
+
*
|
1340 |
+
* @param string $string A string
|
1341 |
+
*
|
1342 |
+
* @return string The uppercased string
|
1343 |
+
*/
|
1344 |
+
function twig_upper_filter(Environment $env, $string)
|
1345 |
+
{
|
1346 |
+
if (null !== $charset = $env->getCharset()) {
|
1347 |
+
return mb_strtoupper($string, $charset);
|
1348 |
+
}
|
1349 |
+
|
1350 |
+
return strtoupper($string);
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
/**
|
1354 |
+
* Converts a string to lowercase.
|
1355 |
+
*
|
1356 |
+
* @param string $string A string
|
1357 |
+
*
|
1358 |
+
* @return string The lowercased string
|
1359 |
+
*/
|
1360 |
+
function twig_lower_filter(Environment $env, $string)
|
1361 |
+
{
|
1362 |
+
if (null !== $charset = $env->getCharset()) {
|
1363 |
+
return mb_strtolower($string, $charset);
|
1364 |
+
}
|
1365 |
+
|
1366 |
+
return strtolower($string);
|
1367 |
+
}
|
1368 |
+
|
1369 |
+
/**
|
1370 |
+
* Returns a titlecased string.
|
1371 |
+
*
|
1372 |
+
* @param string $string A string
|
1373 |
+
*
|
1374 |
+
* @return string The titlecased string
|
1375 |
+
*/
|
1376 |
+
function twig_title_string_filter(Environment $env, $string)
|
1377 |
+
{
|
1378 |
+
if (null !== $charset = $env->getCharset()) {
|
1379 |
+
return mb_convert_case($string, MB_CASE_TITLE, $charset);
|
1380 |
+
}
|
1381 |
+
|
1382 |
+
return ucwords(strtolower($string));
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
/**
|
1386 |
+
* Returns a capitalized string.
|
1387 |
+
*
|
1388 |
+
* @param string $string A string
|
1389 |
+
*
|
1390 |
+
* @return string The capitalized string
|
1391 |
+
*/
|
1392 |
+
function twig_capitalize_string_filter(Environment $env, $string)
|
1393 |
+
{
|
1394 |
+
if (null !== $charset = $env->getCharset()) {
|
1395 |
+
return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset);
|
1396 |
+
}
|
1397 |
+
|
1398 |
+
return ucfirst(strtolower($string));
|
1399 |
+
}
|
1400 |
+
}
|
1401 |
+
// and byte fallback
|
1402 |
+
else {
|
1403 |
+
/**
|
1404 |
+
* Returns the length of a variable.
|
1405 |
+
*
|
1406 |
+
* @param mixed $thing A variable
|
1407 |
+
*
|
1408 |
+
* @return int The length of the value
|
1409 |
+
*/
|
1410 |
+
function twig_length_filter(Environment $env, $thing)
|
1411 |
+
{
|
1412 |
+
if (null === $thing) {
|
1413 |
+
return 0;
|
1414 |
+
}
|
1415 |
+
|
1416 |
+
if (is_scalar($thing)) {
|
1417 |
+
return \strlen($thing);
|
1418 |
+
}
|
1419 |
+
|
1420 |
+
if ($thing instanceof \SimpleXMLElement) {
|
1421 |
+
return \count($thing);
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
if (\is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
|
1425 |
+
return \strlen((string) $thing);
|
1426 |
+
}
|
1427 |
+
|
1428 |
+
if ($thing instanceof \Countable || \is_array($thing)) {
|
1429 |
+
return \count($thing);
|
1430 |
+
}
|
1431 |
+
|
1432 |
+
if ($thing instanceof \IteratorAggregate) {
|
1433 |
+
return iterator_count($thing);
|
1434 |
+
}
|
1435 |
+
|
1436 |
+
return 1;
|
1437 |
+
}
|
1438 |
+
|
1439 |
+
/**
|
1440 |
+
* Returns a titlecased string.
|
1441 |
+
*
|
1442 |
+
* @param string $string A string
|
1443 |
+
*
|
1444 |
+
* @return string The titlecased string
|
1445 |
+
*/
|
1446 |
+
function twig_title_string_filter(Environment $env, $string)
|
1447 |
+
{
|
1448 |
+
return ucwords(strtolower($string));
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
/**
|
1452 |
+
* Returns a capitalized string.
|
1453 |
+
*
|
1454 |
+
* @param string $string A string
|
1455 |
+
*
|
1456 |
+
* @return string The capitalized string
|
1457 |
+
*/
|
1458 |
+
function twig_capitalize_string_filter(Environment $env, $string)
|
1459 |
+
{
|
1460 |
+
return ucfirst(strtolower($string));
|
1461 |
+
}
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
/**
|
1465 |
+
* @internal
|
1466 |
+
*/
|
1467 |
+
function twig_ensure_traversable($seq)
|
1468 |
+
{
|
1469 |
+
if ($seq instanceof \Traversable || \is_array($seq)) {
|
1470 |
+
return $seq;
|
1471 |
+
}
|
1472 |
+
|
1473 |
+
return [];
|
1474 |
+
}
|
1475 |
+
|
1476 |
+
/**
|
1477 |
+
* @internal
|
1478 |
+
*/
|
1479 |
+
function twig_to_array($seq, $preserveKeys = true)
|
1480 |
+
{
|
1481 |
+
if ($seq instanceof \Traversable) {
|
1482 |
+
return iterator_to_array($seq, $preserveKeys);
|
1483 |
+
}
|
1484 |
+
|
1485 |
+
if (!\is_array($seq)) {
|
1486 |
+
return $seq;
|
1487 |
+
}
|
1488 |
+
|
1489 |
+
return $preserveKeys ? $seq : array_values($seq);
|
1490 |
+
}
|
1491 |
+
|
1492 |
+
/**
|
1493 |
+
* Checks if a variable is empty.
|
1494 |
+
*
|
1495 |
+
* {# evaluates to true if the foo variable is null, false, or the empty string #}
|
1496 |
+
* {% if foo is empty %}
|
1497 |
+
* {# ... #}
|
1498 |
+
* {% endif %}
|
1499 |
+
*
|
1500 |
+
* @param mixed $value A variable
|
1501 |
+
*
|
1502 |
+
* @return bool true if the value is empty, false otherwise
|
1503 |
+
*/
|
1504 |
+
function twig_test_empty($value)
|
1505 |
+
{
|
1506 |
+
if ($value instanceof \Countable) {
|
1507 |
+
return 0 == \count($value);
|
1508 |
+
}
|
1509 |
+
|
1510 |
+
if (\is_object($value) && method_exists($value, '__toString')) {
|
1511 |
+
return '' === (string) $value;
|
1512 |
+
}
|
1513 |
+
|
1514 |
+
return '' === $value || false === $value || null === $value || [] === $value;
|
1515 |
+
}
|
1516 |
+
|
1517 |
+
/**
|
1518 |
+
* Checks if a variable is traversable.
|
1519 |
+
*
|
1520 |
+
* {# evaluates to true if the foo variable is an array or a traversable object #}
|
1521 |
+
* {% if foo is iterable %}
|
1522 |
+
* {# ... #}
|
1523 |
+
* {% endif %}
|
1524 |
+
*
|
1525 |
+
* @param mixed $value A variable
|
1526 |
+
*
|
1527 |
+
* @return bool true if the value is traversable
|
1528 |
+
*/
|
1529 |
+
function twig_test_iterable($value)
|
1530 |
+
{
|
1531 |
+
return $value instanceof \Traversable || \is_array($value);
|
1532 |
+
}
|
1533 |
+
|
1534 |
+
/**
|
1535 |
+
* Renders a template.
|
1536 |
+
*
|
1537 |
+
* @param array $context
|
1538 |
+
* @param string|array $template The template to render or an array of templates to try consecutively
|
1539 |
+
* @param array $variables The variables to pass to the template
|
1540 |
+
* @param bool $withContext
|
1541 |
+
* @param bool $ignoreMissing Whether to ignore missing templates or not
|
1542 |
+
* @param bool $sandboxed Whether to sandbox the template or not
|
1543 |
+
*
|
1544 |
+
* @return string The rendered template
|
1545 |
+
*/
|
1546 |
+
function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
|
1547 |
+
{
|
1548 |
+
$alreadySandboxed = false;
|
1549 |
+
$sandbox = null;
|
1550 |
+
if ($withContext) {
|
1551 |
+
$variables = array_merge($context, $variables);
|
1552 |
+
}
|
1553 |
+
|
1554 |
+
if ($isSandboxed = $sandboxed && $env->hasExtension('\Twig\Extension\SandboxExtension')) {
|
1555 |
+
$sandbox = $env->getExtension('\Twig\Extension\SandboxExtension');
|
1556 |
+
if (!$alreadySandboxed = $sandbox->isSandboxed()) {
|
1557 |
+
$sandbox->enableSandbox();
|
1558 |
+
}
|
1559 |
+
}
|
1560 |
+
|
1561 |
+
$loaded = null;
|
1562 |
+
try {
|
1563 |
+
$loaded = $env->resolveTemplate($template);
|
1564 |
+
} catch (LoaderError $e) {
|
1565 |
+
if (!$ignoreMissing) {
|
1566 |
+
if ($isSandboxed && !$alreadySandboxed) {
|
1567 |
+
$sandbox->disableSandbox();
|
1568 |
+
}
|
1569 |
+
|
1570 |
+
throw $e;
|
1571 |
+
}
|
1572 |
+
} catch (\Throwable $e) {
|
1573 |
+
if ($isSandboxed && !$alreadySandboxed) {
|
1574 |
+
$sandbox->disableSandbox();
|
1575 |
+
}
|
1576 |
+
|
1577 |
+
throw $e;
|
1578 |
+
} catch (\Exception $e) {
|
1579 |
+
if ($isSandboxed && !$alreadySandboxed) {
|
1580 |
+
$sandbox->disableSandbox();
|
1581 |
+
}
|
1582 |
+
|
1583 |
+
throw $e;
|
1584 |
+
}
|
1585 |
+
|
1586 |
+
try {
|
1587 |
+
$ret = $loaded ? $loaded->render($variables) : '';
|
1588 |
+
} catch (\Exception $e) {
|
1589 |
+
if ($isSandboxed && !$alreadySandboxed) {
|
1590 |
+
$sandbox->disableSandbox();
|
1591 |
+
}
|
1592 |
+
|
1593 |
+
throw $e;
|
1594 |
+
}
|
1595 |
+
|
1596 |
+
if ($isSandboxed && !$alreadySandboxed) {
|
1597 |
+
$sandbox->disableSandbox();
|
1598 |
+
}
|
1599 |
+
|
1600 |
+
return $ret;
|
1601 |
+
}
|
1602 |
+
|
1603 |
+
/**
|
1604 |
+
* Returns a template content without rendering it.
|
1605 |
+
*
|
1606 |
+
* @param string $name The template name
|
1607 |
+
* @param bool $ignoreMissing Whether to ignore missing templates or not
|
1608 |
+
*
|
1609 |
+
* @return string The template source
|
1610 |
+
*/
|
1611 |
+
function twig_source(Environment $env, $name, $ignoreMissing = false)
|
1612 |
+
{
|
1613 |
+
$loader = $env->getLoader();
|
1614 |
+
try {
|
1615 |
+
if (!$loader instanceof SourceContextLoaderInterface) {
|
1616 |
+
return $loader->getSource($name);
|
1617 |
+
} else {
|
1618 |
+
return $loader->getSourceContext($name)->getCode();
|
1619 |
+
}
|
1620 |
+
} catch (LoaderError $e) {
|
1621 |
+
if (!$ignoreMissing) {
|
1622 |
+
throw $e;
|
1623 |
+
}
|
1624 |
+
}
|
1625 |
+
}
|
1626 |
+
|
1627 |
+
/**
|
1628 |
+
* Provides the ability to get constants from instances as well as class/global constants.
|
1629 |
+
*
|
1630 |
+
* @param string $constant The name of the constant
|
1631 |
+
* @param object|null $object The object to get the constant from
|
1632 |
+
*
|
1633 |
+
* @return string
|
1634 |
+
*/
|
1635 |
+
function twig_constant($constant, $object = null)
|
1636 |
+
{
|
1637 |
+
if (null !== $object) {
|
1638 |
+
$constant = \get_class($object).'::'.$constant;
|
1639 |
+
}
|
1640 |
+
|
1641 |
+
return \constant($constant);
|
1642 |
+
}
|
1643 |
+
|
1644 |
+
/**
|
1645 |
+
* Checks if a constant exists.
|
1646 |
+
*
|
1647 |
+
* @param string $constant The name of the constant
|
1648 |
+
* @param object|null $object The object to get the constant from
|
1649 |
+
*
|
1650 |
+
* @return bool
|
1651 |
+
*/
|
1652 |
+
function twig_constant_is_defined($constant, $object = null)
|
1653 |
+
{
|
1654 |
+
if (null !== $object) {
|
1655 |
+
$constant = \get_class($object).'::'.$constant;
|
1656 |
+
}
|
1657 |
+
|
1658 |
+
return \defined($constant);
|
1659 |
+
}
|
1660 |
+
|
1661 |
+
/**
|
1662 |
+
* Batches item.
|
1663 |
+
*
|
1664 |
+
* @param array $items An array of items
|
1665 |
+
* @param int $size The size of the batch
|
1666 |
+
* @param mixed $fill A value used to fill missing items
|
1667 |
+
*
|
1668 |
+
* @return array
|
1669 |
+
*/
|
1670 |
+
function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
|
1671 |
+
{
|
1672 |
+
if (!twig_test_iterable($items)) {
|
1673 |
+
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
|
1674 |
+
}
|
1675 |
+
|
1676 |
+
$size = ceil($size);
|
1677 |
+
|
1678 |
+
$result = array_chunk(twig_to_array($items, $preserveKeys), $size, $preserveKeys);
|
1679 |
+
|
1680 |
+
if (null !== $fill && $result) {
|
1681 |
+
$last = \count($result) - 1;
|
1682 |
+
if ($fillCount = $size - \count($result[$last])) {
|
1683 |
+
for ($i = 0; $i < $fillCount; ++$i) {
|
1684 |
+
$result[$last][] = $fill;
|
1685 |
+
}
|
1686 |
+
}
|
1687 |
+
}
|
1688 |
+
|
1689 |
+
return $result;
|
1690 |
+
}
|
1691 |
+
|
1692 |
+
function twig_array_filter($array, $arrow)
|
1693 |
+
{
|
1694 |
+
if (\is_array($array)) {
|
1695 |
+
if (\PHP_VERSION_ID >= 50600) {
|
1696 |
+
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
|
1697 |
+
}
|
1698 |
+
|
1699 |
+
return array_filter($array, $arrow);
|
1700 |
+
}
|
1701 |
+
|
1702 |
+
// the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator
|
1703 |
+
return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow);
|
1704 |
+
}
|
1705 |
+
|
1706 |
+
function twig_array_map($array, $arrow)
|
1707 |
+
{
|
1708 |
+
$r = [];
|
1709 |
+
foreach ($array as $k => $v) {
|
1710 |
+
$r[$k] = $arrow($v, $k);
|
1711 |
+
}
|
1712 |
+
|
1713 |
+
return $r;
|
1714 |
+
}
|
1715 |
+
|
1716 |
+
function twig_array_reduce($array, $arrow, $initial = null)
|
1717 |
+
{
|
1718 |
+
if (!\is_array($array)) {
|
1719 |
+
$array = iterator_to_array($array);
|
1720 |
+
}
|
1721 |
+
|
1722 |
+
return array_reduce($array, $arrow, $initial);
|
1723 |
+
}
|
1724 |
+
}
|
vendor/twig/twig/src/Extension/DebugExtension.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension {
|
13 |
+
use Twig\TwigFunction;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @final
|
17 |
+
*/
|
18 |
+
class DebugExtension extends AbstractExtension
|
19 |
+
{
|
20 |
+
public function getFunctions()
|
21 |
+
{
|
22 |
+
// dump is safe if var_dump is overridden by xdebug
|
23 |
+
$isDumpOutputHtmlSafe = \extension_loaded('xdebug')
|
24 |
+
// false means that it was not set (and the default is on) or it explicitly enabled
|
25 |
+
&& (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
|
26 |
+
// false means that it was not set (and the default is on) or it explicitly enabled
|
27 |
+
// xdebug.overload_var_dump produces HTML only when html_errors is also enabled
|
28 |
+
&& (false === ini_get('html_errors') || ini_get('html_errors'))
|
29 |
+
|| 'cli' === \PHP_SAPI
|
30 |
+
;
|
31 |
+
|
32 |
+
return [
|
33 |
+
new TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
|
34 |
+
];
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getName()
|
38 |
+
{
|
39 |
+
return 'debug';
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
class_alias('Twig\Extension\DebugExtension', 'Twig_Extension_Debug');
|
44 |
+
}
|
45 |
+
|
46 |
+
namespace {
|
47 |
+
use Twig\Environment;
|
48 |
+
use Twig\Template;
|
49 |
+
use Twig\TemplateWrapper;
|
50 |
+
|
51 |
+
function twig_var_dump(Environment $env, $context, array $vars = [])
|
52 |
+
{
|
53 |
+
if (!$env->isDebug()) {
|
54 |
+
return;
|
55 |
+
}
|
56 |
+
|
57 |
+
ob_start();
|
58 |
+
|
59 |
+
if (!$vars) {
|
60 |
+
$vars = [];
|
61 |
+
foreach ($context as $key => $value) {
|
62 |
+
if (!$value instanceof Template && !$value instanceof TemplateWrapper) {
|
63 |
+
$vars[$key] = $value;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
var_dump($vars);
|
68 |
+
} else {
|
69 |
+
foreach ($vars as $var) {
|
70 |
+
var_dump($var);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
return ob_get_clean();
|
75 |
+
}
|
76 |
+
}
|
vendor/twig/twig/src/Extension/EscaperExtension.php
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension {
|
13 |
+
use Twig\NodeVisitor\EscaperNodeVisitor;
|
14 |
+
use Twig\TokenParser\AutoEscapeTokenParser;
|
15 |
+
use Twig\TwigFilter;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @final
|
19 |
+
*/
|
20 |
+
class EscaperExtension extends AbstractExtension
|
21 |
+
{
|
22 |
+
protected $defaultStrategy;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @param string|false|callable $defaultStrategy An escaping strategy
|
26 |
+
*
|
27 |
+
* @see setDefaultStrategy()
|
28 |
+
*/
|
29 |
+
public function __construct($defaultStrategy = 'html')
|
30 |
+
{
|
31 |
+
$this->setDefaultStrategy($defaultStrategy);
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getTokenParsers()
|
35 |
+
{
|
36 |
+
return [new AutoEscapeTokenParser()];
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getNodeVisitors()
|
40 |
+
{
|
41 |
+
return [new EscaperNodeVisitor()];
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getFilters()
|
45 |
+
{
|
46 |
+
return [
|
47 |
+
new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
|
48 |
+
];
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Sets the default strategy to use when not defined by the user.
|
53 |
+
*
|
54 |
+
* The strategy can be a valid PHP callback that takes the template
|
55 |
+
* name as an argument and returns the strategy to use.
|
56 |
+
*
|
57 |
+
* @param string|false|callable $defaultStrategy An escaping strategy
|
58 |
+
*/
|
59 |
+
public function setDefaultStrategy($defaultStrategy)
|
60 |
+
{
|
61 |
+
// for BC
|
62 |
+
if (true === $defaultStrategy) {
|
63 |
+
@trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED);
|
64 |
+
|
65 |
+
$defaultStrategy = 'html';
|
66 |
+
}
|
67 |
+
|
68 |
+
if ('filename' === $defaultStrategy) {
|
69 |
+
@trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED);
|
70 |
+
|
71 |
+
$defaultStrategy = 'name';
|
72 |
+
}
|
73 |
+
|
74 |
+
if ('name' === $defaultStrategy) {
|
75 |
+
$defaultStrategy = ['\Twig\FileExtensionEscapingStrategy', 'guess'];
|
76 |
+
}
|
77 |
+
|
78 |
+
$this->defaultStrategy = $defaultStrategy;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Gets the default strategy to use when not defined by the user.
|
83 |
+
*
|
84 |
+
* @param string $name The template name
|
85 |
+
*
|
86 |
+
* @return string|false The default strategy to use for the template
|
87 |
+
*/
|
88 |
+
public function getDefaultStrategy($name)
|
89 |
+
{
|
90 |
+
// disable string callables to avoid calling a function named html or js,
|
91 |
+
// or any other upcoming escaping strategy
|
92 |
+
if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
|
93 |
+
return \call_user_func($this->defaultStrategy, $name);
|
94 |
+
}
|
95 |
+
|
96 |
+
return $this->defaultStrategy;
|
97 |
+
}
|
98 |
+
|
99 |
+
public function getName()
|
100 |
+
{
|
101 |
+
return 'escaper';
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
class_alias('Twig\Extension\EscaperExtension', 'Twig_Extension_Escaper');
|
106 |
+
}
|
107 |
+
|
108 |
+
namespace {
|
109 |
+
/**
|
110 |
+
* Marks a variable as being safe.
|
111 |
+
*
|
112 |
+
* @param string $string A PHP variable
|
113 |
+
*
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
function twig_raw_filter($string)
|
117 |
+
{
|
118 |
+
return $string;
|
119 |
+
}
|
120 |
+
}
|
vendor/twig/twig/src/Extension/ExtensionInterface.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
use Twig\Environment;
|
15 |
+
use Twig\NodeVisitor\NodeVisitorInterface;
|
16 |
+
use Twig\TokenParser\TokenParserInterface;
|
17 |
+
use Twig\TwigFilter;
|
18 |
+
use Twig\TwigFunction;
|
19 |
+
use Twig\TwigTest;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Interface implemented by extension classes.
|
23 |
+
*
|
24 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
25 |
+
*/
|
26 |
+
interface ExtensionInterface
|
27 |
+
{
|
28 |
+
/**
|
29 |
+
* Initializes the runtime environment.
|
30 |
+
*
|
31 |
+
* This is where you can load some file that contains filter functions for instance.
|
32 |
+
*
|
33 |
+
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead
|
34 |
+
*/
|
35 |
+
public function initRuntime(Environment $environment);
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Returns the token parser instances to add to the existing list.
|
39 |
+
*
|
40 |
+
* @return TokenParserInterface[]
|
41 |
+
*/
|
42 |
+
public function getTokenParsers();
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Returns the node visitor instances to add to the existing list.
|
46 |
+
*
|
47 |
+
* @return NodeVisitorInterface[]
|
48 |
+
*/
|
49 |
+
public function getNodeVisitors();
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Returns a list of filters to add to the existing list.
|
53 |
+
*
|
54 |
+
* @return TwigFilter[]
|
55 |
+
*/
|
56 |
+
public function getFilters();
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Returns a list of tests to add to the existing list.
|
60 |
+
*
|
61 |
+
* @return TwigTest[]
|
62 |
+
*/
|
63 |
+
public function getTests();
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Returns a list of functions to add to the existing list.
|
67 |
+
*
|
68 |
+
* @return TwigFunction[]
|
69 |
+
*/
|
70 |
+
public function getFunctions();
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Returns a list of operators to add to the existing list.
|
74 |
+
*
|
75 |
+
* @return array<array> First array of unary operators, second array of binary operators
|
76 |
+
*/
|
77 |
+
public function getOperators();
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Returns a list of global variables to add to the existing list.
|
81 |
+
*
|
82 |
+
* @return array An array of global variables
|
83 |
+
*
|
84 |
+
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead
|
85 |
+
*/
|
86 |
+
public function getGlobals();
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Returns the name of the extension.
|
90 |
+
*
|
91 |
+
* @return string The extension name
|
92 |
+
*
|
93 |
+
* @deprecated since 1.26 (to be removed in 2.0), not used anymore internally
|
94 |
+
*/
|
95 |
+
public function getName();
|
96 |
+
}
|
97 |
+
|
98 |
+
class_alias('Twig\Extension\ExtensionInterface', 'Twig_ExtensionInterface');
|
99 |
+
|
100 |
+
// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
|
101 |
+
class_exists('Twig\Environment');
|
vendor/twig/twig/src/Extension/GlobalsInterface.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Enables usage of the deprecated Twig\Extension\AbstractExtension::getGlobals() method.
|
16 |
+
*
|
17 |
+
* Explicitly implement this interface if you really need to implement the
|
18 |
+
* deprecated getGlobals() method in your extensions.
|
19 |
+
*
|
20 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
21 |
+
*/
|
22 |
+
interface GlobalsInterface
|
23 |
+
{
|
24 |
+
}
|
25 |
+
|
26 |
+
class_alias('Twig\Extension\GlobalsInterface', 'Twig_Extension_GlobalsInterface');
|
vendor/twig/twig/src/Extension/InitRuntimeInterface.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Enables usage of the deprecated Twig\Extension\AbstractExtension::initRuntime() method.
|
16 |
+
*
|
17 |
+
* Explicitly implement this interface if you really need to implement the
|
18 |
+
* deprecated initRuntime() method in your extensions.
|
19 |
+
*
|
20 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
21 |
+
*/
|
22 |
+
interface InitRuntimeInterface
|
23 |
+
{
|
24 |
+
}
|
25 |
+
|
26 |
+
class_alias('Twig\Extension\InitRuntimeInterface', 'Twig_Extension_InitRuntimeInterface');
|
vendor/twig/twig/src/Extension/OptimizerExtension.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
use Twig\NodeVisitor\OptimizerNodeVisitor;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @final
|
18 |
+
*/
|
19 |
+
class OptimizerExtension extends AbstractExtension
|
20 |
+
{
|
21 |
+
protected $optimizers;
|
22 |
+
|
23 |
+
public function __construct($optimizers = -1)
|
24 |
+
{
|
25 |
+
$this->optimizers = $optimizers;
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getNodeVisitors()
|
29 |
+
{
|
30 |
+
return [new OptimizerNodeVisitor($this->optimizers)];
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getName()
|
34 |
+
{
|
35 |
+
return 'optimizer';
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
class_alias('Twig\Extension\OptimizerExtension', 'Twig_Extension_Optimizer');
|
vendor/twig/twig/src/Extension/ProfilerExtension.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
use Twig\Profiler\NodeVisitor\ProfilerNodeVisitor;
|
15 |
+
use Twig\Profiler\Profile;
|
16 |
+
|
17 |
+
class ProfilerExtension extends AbstractExtension
|
18 |
+
{
|
19 |
+
private $actives = [];
|
20 |
+
|
21 |
+
public function __construct(Profile $profile)
|
22 |
+
{
|
23 |
+
$this->actives[] = $profile;
|
24 |
+
}
|
25 |
+
|
26 |
+
public function enter(Profile $profile)
|
27 |
+
{
|
28 |
+
$this->actives[0]->addProfile($profile);
|
29 |
+
array_unshift($this->actives, $profile);
|
30 |
+
}
|
31 |
+
|
32 |
+
public function leave(Profile $profile)
|
33 |
+
{
|
34 |
+
$profile->leave();
|
35 |
+
array_shift($this->actives);
|
36 |
+
|
37 |
+
if (1 === \count($this->actives)) {
|
38 |
+
$this->actives[0]->leave();
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
public function getNodeVisitors()
|
43 |
+
{
|
44 |
+
return [new ProfilerNodeVisitor(\get_class($this))];
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getName()
|
48 |
+
{
|
49 |
+
return 'profiler';
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
class_alias('Twig\Extension\ProfilerExtension', 'Twig_Extension_Profiler');
|
vendor/twig/twig/src/Extension/RuntimeExtensionInterface.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
16 |
+
*/
|
17 |
+
interface RuntimeExtensionInterface
|
18 |
+
{
|
19 |
+
}
|
vendor/twig/twig/src/Extension/SandboxExtension.php
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
use Twig\NodeVisitor\SandboxNodeVisitor;
|
15 |
+
use Twig\Sandbox\SecurityPolicyInterface;
|
16 |
+
use Twig\TokenParser\SandboxTokenParser;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @final
|
20 |
+
*/
|
21 |
+
class SandboxExtension extends AbstractExtension
|
22 |
+
{
|
23 |
+
protected $sandboxedGlobally;
|
24 |
+
protected $sandboxed;
|
25 |
+
protected $policy;
|
26 |
+
|
27 |
+
public function __construct(SecurityPolicyInterface $policy, $sandboxed = false)
|
28 |
+
{
|
29 |
+
$this->policy = $policy;
|
30 |
+
$this->sandboxedGlobally = $sandboxed;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getTokenParsers()
|
34 |
+
{
|
35 |
+
return [new SandboxTokenParser()];
|
36 |
+
}
|
37 |
+
|
38 |
+
public function getNodeVisitors()
|
39 |
+
{
|
40 |
+
return [new SandboxNodeVisitor()];
|
41 |
+
}
|
42 |
+
|
43 |
+
public function enableSandbox()
|
44 |
+
{
|
45 |
+
$this->sandboxed = true;
|
46 |
+
}
|
47 |
+
|
48 |
+
public function disableSandbox()
|
49 |
+
{
|
50 |
+
$this->sandboxed = false;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function isSandboxed()
|
54 |
+
{
|
55 |
+
return $this->sandboxedGlobally || $this->sandboxed;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function isSandboxedGlobally()
|
59 |
+
{
|
60 |
+
return $this->sandboxedGlobally;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function setSecurityPolicy(SecurityPolicyInterface $policy)
|
64 |
+
{
|
65 |
+
$this->policy = $policy;
|
66 |
+
}
|
67 |
+
|
68 |
+
public function getSecurityPolicy()
|
69 |
+
{
|
70 |
+
return $this->policy;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function checkSecurity($tags, $filters, $functions)
|
74 |
+
{
|
75 |
+
if ($this->isSandboxed()) {
|
76 |
+
$this->policy->checkSecurity($tags, $filters, $functions);
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
public function checkMethodAllowed($obj, $method)
|
81 |
+
{
|
82 |
+
if ($this->isSandboxed()) {
|
83 |
+
$this->policy->checkMethodAllowed($obj, $method);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
public function checkPropertyAllowed($obj, $method)
|
88 |
+
{
|
89 |
+
if ($this->isSandboxed()) {
|
90 |
+
$this->policy->checkPropertyAllowed($obj, $method);
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
public function ensureToStringAllowed($obj)
|
95 |
+
{
|
96 |
+
if ($this->isSandboxed() && \is_object($obj) && method_exists($obj, '__toString')) {
|
97 |
+
$this->policy->checkMethodAllowed($obj, '__toString');
|
98 |
+
}
|
99 |
+
|
100 |
+
return $obj;
|
101 |
+
}
|
102 |
+
|
103 |
+
public function getName()
|
104 |
+
{
|
105 |
+
return 'sandbox';
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
class_alias('Twig\Extension\SandboxExtension', 'Twig_Extension_Sandbox');
|
vendor/twig/twig/src/Extension/StagingExtension.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension;
|
13 |
+
|
14 |
+
use Twig\NodeVisitor\NodeVisitorInterface;
|
15 |
+
use Twig\TokenParser\TokenParserInterface;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Internal class.
|
19 |
+
*
|
20 |
+
* This class is used by \Twig\Environment as a staging area and must not be used directly.
|
21 |
+
*
|
22 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
23 |
+
*
|
24 |
+
* @internal
|
25 |
+
*/
|
26 |
+
class StagingExtension extends AbstractExtension
|
27 |
+
{
|
28 |
+
protected $functions = [];
|
29 |
+
protected $filters = [];
|
30 |
+
protected $visitors = [];
|
31 |
+
protected $tokenParsers = [];
|
32 |
+
protected $globals = [];
|
33 |
+
protected $tests = [];
|
34 |
+
|
35 |
+
public function addFunction($name, $function)
|
36 |
+
{
|
37 |
+
if (isset($this->functions[$name])) {
|
38 |
+
@trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
|
39 |
+
}
|
40 |
+
|
41 |
+
$this->functions[$name] = $function;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getFunctions()
|
45 |
+
{
|
46 |
+
return $this->functions;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function addFilter($name, $filter)
|
50 |
+
{
|
51 |
+
if (isset($this->filters[$name])) {
|
52 |
+
@trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
|
53 |
+
}
|
54 |
+
|
55 |
+
$this->filters[$name] = $filter;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function getFilters()
|
59 |
+
{
|
60 |
+
return $this->filters;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function addNodeVisitor(NodeVisitorInterface $visitor)
|
64 |
+
{
|
65 |
+
$this->visitors[] = $visitor;
|
66 |
+
}
|
67 |
+
|
68 |
+
public function getNodeVisitors()
|
69 |
+
{
|
70 |
+
return $this->visitors;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function addTokenParser(TokenParserInterface $parser)
|
74 |
+
{
|
75 |
+
if (isset($this->tokenParsers[$parser->getTag()])) {
|
76 |
+
@trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED);
|
77 |
+
}
|
78 |
+
|
79 |
+
$this->tokenParsers[$parser->getTag()] = $parser;
|
80 |
+
}
|
81 |
+
|
82 |
+
public function getTokenParsers()
|
83 |
+
{
|
84 |
+
return $this->tokenParsers;
|
85 |
+
}
|
86 |
+
|
87 |
+
public function addGlobal($name, $value)
|
88 |
+
{
|
89 |
+
$this->globals[$name] = $value;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function getGlobals()
|
93 |
+
{
|
94 |
+
return $this->globals;
|
95 |
+
}
|
96 |
+
|
97 |
+
public function addTest($name, $test)
|
98 |
+
{
|
99 |
+
if (isset($this->tests[$name])) {
|
100 |
+
@trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
|
101 |
+
}
|
102 |
+
|
103 |
+
$this->tests[$name] = $test;
|
104 |
+
}
|
105 |
+
|
106 |
+
public function getTests()
|
107 |
+
{
|
108 |
+
return $this->tests;
|
109 |
+
}
|
110 |
+
|
111 |
+
public function getName()
|
112 |
+
{
|
113 |
+
return 'staging';
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging');
|
vendor/twig/twig/src/Extension/StringLoaderExtension.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig\Extension {
|
13 |
+
use Twig\TwigFunction;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @final
|
17 |
+
*/
|
18 |
+
class StringLoaderExtension extends AbstractExtension
|
19 |
+
{
|
20 |
+
public function getFunctions()
|
21 |
+
{
|
22 |
+
return [
|
23 |
+
new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
|
24 |
+
];
|
25 |
+
}
|
26 |
+
|
27 |
+
public function getName()
|
28 |
+
{
|
29 |
+
return 'string_loader';
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader');
|
34 |
+
}
|
35 |
+
|
36 |
+
namespace {
|
37 |
+
use Twig\Environment;
|
38 |
+
use Twig\TemplateWrapper;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Loads a template from a string.
|
42 |
+
*
|
43 |
+
* {{ include(template_from_string("Hello {{ name }}")) }}
|
44 |
+
*
|
45 |
+
* @param string $template A template as a string or object implementing __toString()
|
46 |
+
* @param string $name An optional name of the template to be used in error messages
|
47 |
+
*
|
48 |
+
* @return TemplateWrapper
|
49 |
+
*/
|
50 |
+
function twig_template_from_string(Environment $env, $template, $name = null)
|
51 |
+
{
|
52 |
+
return $env->createTemplate((string) $template, $name);
|
53 |
+
}
|
54 |
+
}
|
vendor/twig/twig/src/FileExtensionEscapingStrategy.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* This file is part of Twig.
|
5 |
+
*
|
6 |
+
* (c) Fabien Potencier
|
7 |
+
*
|
8 |
+
* For the full copyright and license information, please view the LICENSE
|
9 |
+
* file that was distributed with this source code.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Twig;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Default autoescaping strategy based on file names.
|
16 |
+
*
|
17 |
+
* This strategy sets the HTML as the default autoescaping strategy,
|
18 |
+
* but changes it based on the template name.
|
19 |
+
*
|
20 |
+
* Note that there is no runtime performance impact as the
|
21 |
+
* default autoescaping strategy is set at compilation time.
|
22 |
+
*
|
23 |
+
* @author Fabien Potencier <fabien@symfony.com>
|
24 |
+
*/
|
25 |
+
class FileExtensionEscapingStrategy
|
26 |
+
{
|
27 |
+
/**
|
28 |
+
* Guesses the best autoescaping strategy based on the file name.
|
29 |
+
*
|
30 |
+
* @param string $name The template name
|
31 |
+
*
|
32 |
+
* @return string|false The escaping strategy name to use or false to disable
|
33 |
+
*/
|
34 |
+
public static function guess($name)
|
35 |
+
{
|
36 |
+
if (\in_array(substr($name, -1), ['/', '\\'])) {
|
37 |
+
return 'html'; // return html for directories
|
38 |
+
}
|
39 |
+
|
40 |
+
if ('.twig' === substr($name, -5)) {
|
41 |
+
$name = substr($name, 0, -5);
|
42 |
+
}
|
43 |
+
|
44 |
+
$extension = pathinfo($name, PATHINFO_EXTENSION);
|
45 |
+
|
46 |
+
switch ($extension) {
|
47 |
+
case 'js':
|
48 |
+
return 'js';
|
49 |
+
|
50 |
+
case 'css':
|
51 |
+
return 'css';
|
52 |
+
|
53 |
+
case 'txt':
|
54 |
+
return false;
|
55 |
+
|
56 |
+
default:
|
57 |
+
return 'html';
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
class_alias('Twig\FileExtensionEscapingStrategy', 'Twig_FileExtensionEscapingStrategy');
|
vendor/twig/twig/src/Lexer.php
ADDED
@@ -0,0 +1,534 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|