From f16eefd91096bc715c2b8004926b24cbfd77e451 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Sat, 4 Apr 2020 00:12:41 -0300 Subject: [PATCH] PHP SESSION Prefix and IP check, engine constants and user_constants as a function for better memory usage, add SQLite 3 driver, new loader for aditional database method, new REST HTPP method check, updated template engines: Mustache 2.13, Smarty 3.1.34, Twig 1.42.5, Twig 2.12.5, add Twig 3 support to PHP 7.2+, define Dwoo template as deprecated, Caches and captcha bugfix in PHP 5.4.x --- README.md | 13 +- system/caches/caches.php | 4 +- system/captcha/autoload.php | 4 +- system/database/database/dbmysqli.php | 1 - system/database/database/sqlite3_db.php | 61 + system/database/library/db.php | 6 +- system/engine/VERSION | 2 +- system/engine/controller.php | 22 +- system/engine/loader.php | 16 +- system/engine/log.php | 3 +- system/engine/registry.php | 1 - system/request/autoload.php | 102 +- system/session/autoload.php | 60 +- system/system.php | 65 +- system/templateEngines/Mustache/Engine.php | 2 +- system/templateEngines/Mustache/Parser.php | 4 +- system/templateEngines/Mustache/Tokenizer.php | 91 +- .../Twig/Extension/ExacTITranslate.php | 28 +- .../Twig/Extension/ExacTITranslate1x.php | 186 ++ .../Twig/Twig1x/Autoloader.php | 50 - .../Twig/Twig1x/BaseNodeVisitor.php | 54 - .../Twig/Twig1x/Cache/Filesystem.php | 91 - .../Twig/Twig1x/Cache/Null.php | 40 - .../Twig/Twig1x/CacheInterface.php | 58 - .../templateEngines/Twig/Twig1x/Compiler.php | 286 -- .../Twig/Twig1x/ContainerRuntimeLoader.php | 39 - .../Twig/Twig1x/Environment.php | 1617 ----------- system/templateEngines/Twig/Twig1x/Error.php | 333 --- .../Twig/Twig1x/Error/Loader.php | 36 - .../Twig/Twig1x/Error/Runtime.php | 22 - .../Twig/Twig1x/Error/Syntax.php | 55 - .../Twig/Twig1x/ExistsLoaderInterface.php | 31 - .../Twig/Twig1x/ExpressionParser.php | 744 ----- .../templateEngines/Twig/Twig1x/Extension.php | 69 - .../Twig/Twig1x/Extension/Core.php | 1647 ----------- .../Twig/Twig1x/Extension/Debug.php | 67 - .../Twig/Twig1x/Extension/Escaper.php | 112 - .../Twig1x/Extension/GlobalsInterface.php | 24 - .../Twig1x/Extension/InitRuntimeInterface.php | 24 - .../Twig/Twig1x/Extension/Optimizer.php | 35 - .../Twig/Twig1x/Extension/Profiler.php | 49 - .../Twig/Twig1x/Extension/Sandbox.php | 103 - .../Twig/Twig1x/Extension/Staging.php | 112 - .../Twig/Twig1x/Extension/StringLoader.php | 47 - .../Twig/Twig1x/ExtensionInterface.php | 90 - .../Twig/Twig1x/FactoryRuntimeLoader.php | 39 - .../Twig1x/FileExtensionEscapingStrategy.php | 60 - system/templateEngines/Twig/Twig1x/Filter.php | 84 - .../Twig/Twig1x/Filter/Function.php | 40 - .../Twig/Twig1x/Filter/Method.php | 42 - .../Twig/Twig1x/Filter/Node.php | 42 - .../Twig/Twig1x/FilterCallableInterface.php | 24 - .../Twig/Twig1x/FilterInterface.php | 43 - .../templateEngines/Twig/Twig1x/Function.php | 74 - .../Twig/Twig1x/Function/Function.php | 41 - .../Twig/Twig1x/Function/Method.php | 43 - .../Twig/Twig1x/Function/Node.php | 42 - .../Twig/Twig1x/FunctionCallableInterface.php | 24 - .../Twig/Twig1x/FunctionInterface.php | 40 - system/templateEngines/Twig/Twig1x/Lexer.php | 427 --- .../Twig/Twig1x/LexerInterface.php | 32 - .../Twig/Twig1x/Loader/Array.php | 97 - .../Twig/Twig1x/Loader/Chain.php | 151 -- .../Twig/Twig1x/Loader/Filesystem.php | 298 -- .../Twig/Twig1x/Loader/String.php | 58 - .../Twig/Twig1x/LoaderInterface.php | 57 - system/templateEngines/Twig/Twig1x/Markup.php | 39 - system/templateEngines/Twig/Twig1x/Node.php | 256 -- .../Twig/Twig1x/Node/AutoEscape.php | 36 - .../Twig/Twig1x/Node/Block.php | 41 - .../Twig/Twig1x/Node/BlockReference.php | 34 - .../templateEngines/Twig/Twig1x/Node/Body.php | 21 - .../Twig/Twig1x/Node/CheckSecurity.php | 80 - .../Twig/Twig1x/Node/Deprecated.php | 49 - .../templateEngines/Twig/Twig1x/Node/Do.php | 35 - .../Twig/Twig1x/Node/Embed.php | 46 - .../Twig/Twig1x/Node/Expression.php | 22 - .../Twig/Twig1x/Node/Expression/Array.php | 83 - .../Twig1x/Node/Expression/AssignName.php | 25 - .../Twig/Twig1x/Node/Expression/Binary.php | 37 - .../Twig1x/Node/Expression/Binary/Add.php | 20 - .../Twig1x/Node/Expression/Binary/And.php | 20 - .../Node/Expression/Binary/BitwiseAnd.php | 20 - .../Node/Expression/Binary/BitwiseOr.php | 20 - .../Node/Expression/Binary/BitwiseXor.php | 20 - .../Twig1x/Node/Expression/Binary/Concat.php | 20 - .../Twig1x/Node/Expression/Binary/Div.php | 20 - .../Node/Expression/Binary/EndsWith.php | 32 - .../Twig1x/Node/Expression/Binary/Equal.php | 19 - .../Node/Expression/Binary/FloorDiv.php | 26 - .../Twig1x/Node/Expression/Binary/Greater.php | 19 - .../Node/Expression/Binary/GreaterEqual.php | 19 - .../Twig/Twig1x/Node/Expression/Binary/In.php | 30 - .../Twig1x/Node/Expression/Binary/Less.php | 19 - .../Node/Expression/Binary/LessEqual.php | 19 - .../Twig1x/Node/Expression/Binary/Matches.php | 30 - .../Twig1x/Node/Expression/Binary/Mod.php | 20 - .../Twig1x/Node/Expression/Binary/Mul.php | 20 - .../Node/Expression/Binary/NotEqual.php | 19 - .../Twig1x/Node/Expression/Binary/NotIn.php | 30 - .../Twig/Twig1x/Node/Expression/Binary/Or.php | 20 - .../Twig1x/Node/Expression/Binary/Power.php | 34 - .../Twig1x/Node/Expression/Binary/Range.php | 30 - .../Node/Expression/Binary/StartsWith.php | 32 - .../Twig1x/Node/Expression/Binary/Sub.php | 20 - .../Twig1x/Node/Expression/BlockReference.php | 93 - .../Twig/Twig1x/Node/Expression/Call.php | 293 -- .../Twig1x/Node/Expression/Conditional.php | 33 - .../Twig/Twig1x/Node/Expression/Constant.php | 25 - .../Node/Expression/ExtensionReference.php | 32 - .../Twig/Twig1x/Node/Expression/Filter.php | 41 - .../Twig1x/Node/Expression/Filter/Default.php | 45 - .../Twig/Twig1x/Node/Expression/Function.php | 45 - .../Twig/Twig1x/Node/Expression/GetAttr.php | 74 - .../Twig1x/Node/Expression/MethodCall.php | 43 - .../Twig/Twig1x/Node/Expression/Name.php | 107 - .../Twig1x/Node/Expression/NullCoalesce.php | 48 - .../Twig/Twig1x/Node/Expression/Parent.php | 44 - .../Twig/Twig1x/Node/Expression/TempName.php | 28 - .../Twig/Twig1x/Node/Expression/Test.php | 45 - .../Twig1x/Node/Expression/Test/Constant.php | 48 - .../Twig1x/Node/Expression/Test/Defined.php | 61 - .../Node/Expression/Test/Divisibleby.php | 35 - .../Twig/Twig1x/Node/Expression/Test/Even.php | 34 - .../Twig/Twig1x/Node/Expression/Test/Null.php | 33 - .../Twig/Twig1x/Node/Expression/Test/Odd.php | 34 - .../Twig1x/Node/Expression/Test/Sameas.php | 31 - .../Twig/Twig1x/Node/Expression/Unary.php | 29 - .../Twig/Twig1x/Node/Expression/Unary/Neg.php | 20 - .../Twig/Twig1x/Node/Expression/Unary/Not.php | 20 - .../Twig/Twig1x/Node/Expression/Unary/Pos.php | 20 - .../Twig/Twig1x/Node/Flush.php | 33 - .../templateEngines/Twig/Twig1x/Node/For.php | 113 - .../Twig/Twig1x/Node/ForLoop.php | 52 - .../templateEngines/Twig/Twig1x/Node/If.php | 68 - .../Twig/Twig1x/Node/Import.php | 51 - .../Twig/Twig1x/Node/Include.php | 90 - .../Twig/Twig1x/Node/Macro.php | 125 - .../Twig/Twig1x/Node/Module.php | 466 ---- .../Twig/Twig1x/Node/Print.php | 36 - .../Twig/Twig1x/Node/Sandbox.php | 44 - .../Twig/Twig1x/Node/SandboxedPrint.php | 51 - .../templateEngines/Twig/Twig1x/Node/Set.php | 98 - .../Twig/Twig1x/Node/SetTemp.php | 40 - .../Twig/Twig1x/Node/Spaceless.php | 37 - .../templateEngines/Twig/Twig1x/Node/Text.php | 36 - .../templateEngines/Twig/Twig1x/Node/With.php | 64 - .../Twig/Twig1x/NodeCaptureInterface.php | 21 - .../Twig/Twig1x/NodeInterface.php | 32 - .../Twig/Twig1x/NodeOutputInterface.php | 21 - .../Twig/Twig1x/NodeTraverser.php | 86 - .../Twig/Twig1x/NodeVisitor/Escaper.php | 154 -- .../Twig/Twig1x/NodeVisitor/Optimizer.php | 253 -- .../Twig/Twig1x/NodeVisitor/SafeAnalysis.php | 150 - .../Twig/Twig1x/NodeVisitor/Sandbox.php | 82 - .../Twig/Twig1x/NodeVisitorInterface.php | 45 - system/templateEngines/Twig/Twig1x/Parser.php | 416 --- .../Twig/Twig1x/ParserInterface.php | 29 - .../Twig/Twig1x/Profiler/Dumper/Base.php | 62 - .../Twig/Twig1x/Profiler/Dumper/Blackfire.php | 72 - .../Twig/Twig1x/Profiler/Dumper/Html.php | 47 - .../Twig/Twig1x/Profiler/Dumper/Text.php | 35 - .../Twig1x/Profiler/Node/EnterProfile.php | 39 - .../Twig1x/Profiler/Node/LeaveProfile.php | 33 - .../Twig1x/Profiler/NodeVisitor/Profiler.php | 67 - .../Twig/Twig1x/Profiler/Profile.php | 170 -- .../Twig/Twig1x/RuntimeLoaderInterface.php | 29 - .../Twig/Twig1x/Sandbox/SecurityError.php | 21 - .../Sandbox/SecurityNotAllowedFilterError.php | 33 - .../SecurityNotAllowedFunctionError.php | 33 - .../Sandbox/SecurityNotAllowedMethodError.php | 40 - .../SecurityNotAllowedPropertyError.php | 40 - .../Sandbox/SecurityNotAllowedTagError.php | 33 - .../Twig/Twig1x/Sandbox/SecurityPolicy.php | 125 - .../Sandbox/SecurityPolicyInterface.php | 26 - .../Twig/Twig1x/SimpleFilter.php | 121 - .../Twig/Twig1x/SimpleFunction.php | 111 - .../Twig/Twig1x/SimpleTest.php | 85 - system/templateEngines/Twig/Twig1x/Source.php | 53 - .../Twig1x/SourceContextLoaderInterface.php | 33 - .../templateEngines/Twig/Twig1x/Template.php | 704 ----- .../Twig/Twig1x/TemplateInterface.php | 48 - .../Twig/Twig1x/TemplateWrapper.php | 137 - system/templateEngines/Twig/Twig1x/Test.php | 37 - .../Twig/Twig1x/Test/Function.php | 38 - .../Twig/Twig1x/Test/IntegrationTestCase.php | 245 -- .../Twig/Twig1x/Test/Method.php | 40 - .../Twig/Twig1x/Test/NodeTestCase.php | 75 - system/templateEngines/Twig/Twig1x/Token.php | 207 -- .../Twig/Twig1x/TokenParser.php | 33 - .../Twig/Twig1x/TokenParser/AutoEscape.php | 83 - .../Twig/Twig1x/TokenParser/Block.php | 73 - .../Twig/Twig1x/TokenParser/Deprecated.php | 42 - .../Twig/Twig1x/TokenParser/Do.php | 34 - .../Twig/Twig1x/TokenParser/Embed.php | 67 - .../Twig/Twig1x/TokenParser/Extends.php | 46 - .../Twig/Twig1x/TokenParser/Filter.php | 53 - .../Twig/Twig1x/TokenParser/Flush.php | 34 - .../Twig/Twig1x/TokenParser/For.php | 127 - .../Twig/Twig1x/TokenParser/From.php | 66 - .../Twig/Twig1x/TokenParser/If.php | 86 - .../Twig/Twig1x/TokenParser/Import.php | 41 - .../Twig/Twig1x/TokenParser/Include.php | 65 - .../Twig/Twig1x/TokenParser/Macro.php | 60 - .../Twig/Twig1x/TokenParser/Sandbox.php | 61 - .../Twig/Twig1x/TokenParser/Set.php | 75 - .../Twig/Twig1x/TokenParser/Spaceless.php | 51 - .../Twig/Twig1x/TokenParser/Use.php | 70 - .../Twig/Twig1x/TokenParser/With.php | 52 - .../Twig/Twig1x/TokenParserBroker.php | 120 - .../Twig1x/TokenParserBrokerInterface.php | 44 - .../Twig/Twig1x/TokenParserInterface.php | 43 - .../Twig/Twig1x/TokenStream.php | 196 -- .../Twig/Twig1x/Util/DeprecationCollector.php | 86 - .../Twig/Twig1x/Util/TemplateDirIterator.php | 28 - .../templateEngines/Twig/Twig1x/autoload.php | 7 + .../Twig/Twig1x/composer/ClassLoader.php | 445 +++ .../Twig/Twig1x/composer/LICENSE | 21 + .../Twig1x/composer/autoload_classmap.php | 9 + .../Twig/Twig1x/composer/autoload_files.php | 10 + .../Twig1x/composer/autoload_namespaces.php | 10 + .../Twig/Twig1x/composer/autoload_psr4.php | 11 + .../Twig/Twig1x/composer/autoload_real.php | 70 + .../Twig/Twig1x/composer/autoload_static.php | 54 + .../Twig/Twig1x/composer/installed.json | 128 + .../Twig1x/symfony/polyfill-ctype/Ctype.php | 227 ++ .../Twig1x/symfony/polyfill-ctype/LICENSE | 19 + .../Twig1x/symfony/polyfill-ctype/README.md | 12 + .../symfony/polyfill-ctype/bootstrap.php | 26 + .../symfony/polyfill-ctype/composer.json | 34 + .../Twig/Twig1x/twig/twig/.editorconfig | 18 + .../Twig/Twig1x/twig/twig/.gitattributes | 2 + .../Twig/Twig1x/twig/twig/.gitignore | 6 + .../Twig/Twig1x/twig/twig/.php_cs.dist | 20 + .../Twig/Twig1x/twig/twig/.travis.yml | 46 + .../Twig/Twig1x/twig/twig/LICENSE | 29 + .../Twig/Twig1x/twig/twig/README.rst | 24 + .../Twig1x/twig/twig/lib/Twig/Autoloader.php | 52 + .../twig/twig/lib/Twig/BaseNodeVisitor.php | 11 + .../twig/twig/lib/Twig/Cache/Filesystem.php | 11 + .../Twig1x/twig/twig/lib/Twig/Cache/Null.php | 11 + .../twig/twig/lib/Twig/CacheInterface.php | 11 + .../Twig1x/twig/twig/lib/Twig/Compiler.php | 11 + .../twig/lib/Twig}/CompilerInterface.php | 0 .../twig/lib/Twig/ContainerRuntimeLoader.php | 11 + .../Twig1x/twig/twig/lib/Twig/Environment.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Error.php | 11 + .../twig/twig/lib/Twig/Error/Loader.php | 11 + .../twig/twig/lib/Twig/Error/Runtime.php | 11 + .../twig/twig/lib/Twig/Error/Syntax.php | 11 + .../twig/lib/Twig/ExistsLoaderInterface.php | 11 + .../twig/twig/lib/Twig/ExpressionParser.php | 11 + .../Twig1x/twig/twig/lib/Twig/Extension.php | 11 + .../twig/twig/lib/Twig/Extension/Core.php | 11 + .../twig/twig/lib/Twig/Extension/Debug.php | 11 + .../twig/twig/lib/Twig/Extension/Escaper.php | 11 + .../lib/Twig/Extension/GlobalsInterface.php | 11 + .../Twig/Extension/InitRuntimeInterface.php | 11 + .../twig/lib/Twig/Extension/Optimizer.php | 11 + .../twig/twig/lib/Twig/Extension/Profiler.php | 11 + .../twig/twig/lib/Twig/Extension/Sandbox.php | 11 + .../twig/twig/lib/Twig/Extension/Staging.php | 11 + .../twig/lib/Twig/Extension/StringLoader.php | 11 + .../twig/twig/lib/Twig/ExtensionInterface.php | 11 + .../twig/lib/Twig/FactoryRuntimeLoader.php | 11 + .../Twig/FileExtensionEscapingStrategy.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Filter.php | 86 + .../twig/twig/lib/Twig/Filter/Function.php | 40 + .../twig/twig/lib/Twig/Filter/Method.php | 44 + .../Twig1x/twig/twig/lib/Twig/Filter/Node.php | 42 + .../twig/lib/Twig/FilterCallableInterface.php | 24 + .../twig/twig/lib/Twig/FilterInterface.php | 45 + .../Twig1x/twig/twig/lib/Twig/Function.php | 76 + .../twig/twig/lib/Twig/Function/Function.php | 41 + .../twig/twig/lib/Twig/Function/Method.php | 45 + .../twig/twig/lib/Twig/Function/Node.php | 42 + .../lib/Twig/FunctionCallableInterface.php | 24 + .../twig/twig/lib/Twig/FunctionInterface.php | 42 + .../Twig/Twig1x/twig/twig/lib/Twig/Lexer.php | 11 + .../twig/twig/lib/Twig/LexerInterface.php | 36 + .../twig/twig/lib/Twig/Loader/Array.php | 11 + .../twig/twig/lib/Twig/Loader/Chain.php | 11 + .../twig/twig/lib/Twig/Loader/Filesystem.php | 11 + .../twig/twig/lib/Twig/Loader/String.php | 63 + .../twig/twig/lib/Twig/LoaderInterface.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Markup.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Node.php | 11 + .../twig/twig/lib/Twig/Node/AutoEscape.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Block.php | 11 + .../twig/lib/Twig/Node/BlockReference.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Body.php | 11 + .../twig/twig/lib/Twig/Node/CheckSecurity.php | 11 + .../twig/twig/lib/Twig/Node/Deprecated.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Do.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Embed.php | 11 + .../twig/twig/lib/Twig/Node/Expression.php | 11 + .../twig/lib/Twig/Node/Expression/Array.php | 11 + .../lib/Twig/Node/Expression/AssignName.php | 11 + .../twig/lib/Twig/Node/Expression/Binary.php | 11 + .../lib/Twig/Node/Expression/Binary/Add.php | 11 + .../lib/Twig/Node/Expression/Binary/And.php | 11 + .../Node/Expression/Binary/BitwiseAnd.php | 11 + .../Twig/Node/Expression/Binary/BitwiseOr.php | 11 + .../Node/Expression/Binary/BitwiseXor.php | 11 + .../Twig/Node/Expression/Binary/Concat.php | 11 + .../lib/Twig/Node/Expression/Binary/Div.php | 11 + .../Twig/Node/Expression/Binary/EndsWith.php | 11 + .../lib/Twig/Node/Expression/Binary/Equal.php | 11 + .../Twig/Node/Expression/Binary/FloorDiv.php | 11 + .../Twig/Node/Expression/Binary/Greater.php | 11 + .../Node/Expression/Binary/GreaterEqual.php | 11 + .../lib/Twig/Node/Expression/Binary/In.php | 11 + .../lib/Twig/Node/Expression/Binary/Less.php | 11 + .../Twig/Node/Expression/Binary/LessEqual.php | 11 + .../Twig/Node/Expression/Binary/Matches.php | 11 + .../lib/Twig/Node/Expression/Binary/Mod.php | 11 + .../lib/Twig/Node/Expression/Binary/Mul.php | 11 + .../Twig/Node/Expression/Binary/NotEqual.php | 11 + .../lib/Twig/Node/Expression/Binary/NotIn.php | 11 + .../lib/Twig/Node/Expression/Binary/Or.php | 11 + .../lib/Twig/Node/Expression/Binary/Power.php | 11 + .../lib/Twig/Node/Expression/Binary/Range.php | 11 + .../Node/Expression/Binary/StartsWith.php | 11 + .../lib/Twig/Node/Expression/Binary/Sub.php | 11 + .../Twig/Node/Expression/BlockReference.php | 11 + .../twig/lib/Twig/Node/Expression/Call.php | 11 + .../lib/Twig/Node/Expression/Conditional.php | 11 + .../lib/Twig/Node/Expression/Constant.php | 11 + .../Node/Expression/ExtensionReference.php | 35 + .../twig/lib/Twig/Node/Expression/Filter.php | 11 + .../Twig/Node/Expression/Filter/Default.php | 11 + .../lib/Twig/Node/Expression/Function.php | 11 + .../twig/lib/Twig/Node/Expression/GetAttr.php | 11 + .../lib/Twig/Node/Expression/MethodCall.php | 11 + .../twig/lib/Twig/Node/Expression/Name.php | 11 + .../lib/Twig/Node/Expression/NullCoalesce.php | 11 + .../twig/lib/Twig/Node/Expression/Parent.php | 11 + .../lib/Twig/Node/Expression/TempName.php | 11 + .../twig/lib/Twig/Node/Expression/Test.php | 11 + .../Twig/Node/Expression/Test/Constant.php | 11 + .../lib/Twig/Node/Expression/Test/Defined.php | 11 + .../Twig/Node/Expression/Test/Divisibleby.php | 11 + .../lib/Twig/Node/Expression/Test/Even.php | 11 + .../lib/Twig/Node/Expression/Test/Null.php | 11 + .../lib/Twig/Node/Expression/Test/Odd.php | 11 + .../lib/Twig/Node/Expression/Test/Sameas.php | 11 + .../twig/lib/Twig/Node/Expression/Unary.php | 11 + .../lib/Twig/Node/Expression/Unary/Neg.php | 11 + .../lib/Twig/Node/Expression/Unary/Not.php | 11 + .../lib/Twig/Node/Expression/Unary/Pos.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Flush.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/For.php | 11 + .../twig/twig/lib/Twig/Node/ForLoop.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/If.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Import.php | 11 + .../twig/twig/lib/Twig/Node/Include.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Macro.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Module.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Print.php | 11 + .../twig/twig/lib/Twig/Node/Sandbox.php | 11 + .../twig/lib/Twig/Node/SandboxedPrint.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Set.php | 11 + .../twig/twig/lib/Twig/Node/SetTemp.php | 11 + .../twig/twig/lib/Twig/Node/Spaceless.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/Text.php | 11 + .../Twig1x/twig/twig/lib/Twig/Node/With.php | 11 + .../twig/lib/Twig/NodeCaptureInterface.php | 11 + .../twig/twig/lib/Twig/NodeInterface.php | 34 + .../twig/lib/Twig/NodeOutputInterface.php | 11 + .../twig/twig/lib/Twig/NodeTraverser.php | 11 + .../twig/lib/Twig/NodeVisitor/Escaper.php | 11 + .../twig/lib/Twig/NodeVisitor/Optimizer.php | 11 + .../lib/Twig/NodeVisitor/SafeAnalysis.php | 11 + .../twig/lib/Twig/NodeVisitor/Sandbox.php | 11 + .../twig/lib/Twig/NodeVisitorInterface.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Parser.php | 11 + .../twig/twig/lib/Twig/ParserInterface.php | 33 + .../twig/lib/Twig/Profiler/Dumper/Base.php | 11 + .../lib/Twig/Profiler/Dumper/Blackfire.php | 11 + .../twig/lib/Twig/Profiler/Dumper/Html.php | 11 + .../twig/lib/Twig/Profiler/Dumper/Text.php | 11 + .../lib/Twig/Profiler/Node/EnterProfile.php | 11 + .../lib/Twig/Profiler/Node/LeaveProfile.php | 11 + .../Twig/Profiler/NodeVisitor/Profiler.php | 11 + .../twig/twig/lib/Twig/Profiler/Profile.php | 11 + .../twig/lib/Twig/RuntimeLoaderInterface.php | 11 + .../twig/lib/Twig/Sandbox/SecurityError.php | 11 + .../Sandbox/SecurityNotAllowedFilterError.php | 11 + .../SecurityNotAllowedFunctionError.php | 11 + .../Sandbox/SecurityNotAllowedMethodError.php | 11 + .../SecurityNotAllowedPropertyError.php | 11 + .../Sandbox/SecurityNotAllowedTagError.php | 11 + .../twig/lib/Twig/Sandbox/SecurityPolicy.php | 11 + .../Twig/Sandbox/SecurityPolicyInterface.php | 11 + .../twig/twig/lib/Twig/SimpleFilter.php | 11 + .../twig/twig/lib/Twig/SimpleFunction.php | 11 + .../Twig1x/twig/twig/lib/Twig/SimpleTest.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Source.php | 11 + .../lib/Twig/SourceContextLoaderInterface.php | 11 + .../Twig1x/twig/twig/lib/Twig/Template.php | 11 + .../twig/twig/lib/Twig/TemplateInterface.php | 50 + .../twig/twig/lib/Twig/TemplateWrapper.php | 11 + .../Twig/Twig1x/twig/twig/lib/Twig/Test.php | 37 + .../twig/twig/lib/Twig/Test/Function.php | 38 + .../lib/Twig/Test/IntegrationTestCase.php | 11 + .../Twig1x/twig/twig/lib/Twig/Test/Method.php | 42 + .../{ => twig/twig/lib/Twig}/Test/Node.php | 0 .../twig/twig/lib/Twig/Test/NodeTestCase.php | 11 + .../twig/lib/Twig}/TestCallableInterface.php | 0 .../twig/lib/Twig}/TestInterface.php | 0 .../Twig/Twig1x/twig/twig/lib/Twig/Token.php | 11 + .../Twig1x/twig/twig/lib/Twig/TokenParser.php | 11 + .../twig/lib/Twig/TokenParser/AutoEscape.php | 11 + .../twig/twig/lib/Twig/TokenParser/Block.php | 11 + .../twig/lib/Twig/TokenParser/Deprecated.php | 11 + .../twig/twig/lib/Twig/TokenParser/Do.php | 11 + .../twig/twig/lib/Twig/TokenParser/Embed.php | 11 + .../twig/lib/Twig/TokenParser/Extends.php | 11 + .../twig/twig/lib/Twig/TokenParser/Filter.php | 11 + .../twig/twig/lib/Twig/TokenParser/Flush.php | 11 + .../twig/twig/lib/Twig/TokenParser/For.php | 11 + .../twig/twig/lib/Twig/TokenParser/From.php | 11 + .../twig/twig/lib/Twig/TokenParser/If.php | 11 + .../twig/twig/lib/Twig/TokenParser/Import.php | 11 + .../twig/lib/Twig/TokenParser/Include.php | 11 + .../twig/twig/lib/Twig/TokenParser/Macro.php | 11 + .../twig/lib/Twig/TokenParser/Sandbox.php | 11 + .../twig/twig/lib/Twig/TokenParser/Set.php | 11 + .../twig/lib/Twig/TokenParser/Spaceless.php | 11 + .../twig/twig/lib/Twig/TokenParser/Use.php | 11 + .../twig/twig/lib/Twig/TokenParser/With.php | 11 + .../twig/twig/lib/Twig/TokenParserBroker.php | 122 + .../lib/Twig/TokenParserBrokerInterface.php | 46 + .../twig/lib/Twig/TokenParserInterface.php | 11 + .../Twig1x/twig/twig/lib/Twig/TokenStream.php | 11 + .../lib/Twig/Util/DeprecationCollector.php | 11 + .../lib/Twig/Util/TemplateDirIterator.php | 11 + .../twig/twig/src/Cache/CacheInterface.php | 60 + .../twig/twig/src/Cache/FilesystemCache.php | 93 + .../Twig1x/twig/twig/src/Cache/NullCache.php | 42 + .../Twig/Twig1x/twig/twig/src/Compiler.php | 288 ++ .../Twig/Twig1x/twig/twig/src/Environment.php | 1638 +++++++++++ .../Twig/Twig1x/twig/twig/src/Error/Error.php | 325 +++ .../twig/twig/src/Error/LoaderError.php | 23 + .../twig/twig/src/Error/RuntimeError.php | 24 + .../twig/twig/src/Error/SyntaxError.php | 57 + .../Twig1x/twig/twig/src/ExpressionParser.php | 834 ++++++ .../twig/src/Extension/AbstractExtension.php | 72 + .../twig/twig/src/Extension/CoreExtension.php | 1728 ++++++++++++ .../twig/src/Extension/DebugExtension.php | 76 + .../twig/src/Extension/EscaperExtension.php | 120 + .../twig/src/Extension/ExtensionInterface.php | 101 + .../twig/src/Extension/GlobalsInterface.php | 26 + .../src/Extension/InitRuntimeInterface.php | 26 + .../twig/src/Extension/OptimizerExtension.php | 39 + .../twig/src/Extension/ProfilerExtension.php | 53 + .../Extension/RuntimeExtensionInterface.php | 19 + .../twig/src/Extension/SandboxExtension.php | 109 + .../twig/src/Extension/StagingExtension.php | 117 + .../src/Extension/StringLoaderExtension.php | 54 + .../src/FileExtensionEscapingStrategy.php | 62 + .../Twig/Twig1x/twig/twig/src/Lexer.php | 534 ++++ .../twig/twig/src/Loader/ArrayLoader.php | 102 + .../twig/twig/src/Loader/ChainLoader.php | 164 ++ .../twig/src/Loader/ExistsLoaderInterface.php | 33 + .../twig/twig/src/Loader/FilesystemLoader.php | 323 +++ .../twig/twig/src/Loader/LoaderInterface.php | 61 + .../Loader/SourceContextLoaderInterface.php | 38 + .../Twig/Twig1x/twig/twig/src/Markup.php | 41 + .../twig/twig/src/Node/AutoEscapeNode.php | 40 + .../Twig1x/twig/twig/src/Node/BlockNode.php | 45 + .../twig/twig/src/Node/BlockReferenceNode.php | 38 + .../Twig1x/twig/twig/src/Node/BodyNode.php | 23 + .../twig/twig/src/Node/CheckSecurityNode.php | 85 + .../twig/twig/src/Node/CheckToStringNode.php | 42 + .../twig/twig/src/Node/DeprecatedNode.php | 55 + .../Twig/Twig1x/twig/twig/src/Node/DoNode.php | 40 + .../Twig1x/twig/twig/src/Node/EmbedNode.php | 52 + .../Node/Expression/AbstractExpression.php | 26 + .../src/Node/Expression/ArrayExpression.php | 88 + .../Expression/ArrowFunctionExpression.php | 64 + .../Node/Expression/AssignNameExpression.php | 29 + .../Node/Expression/Binary/AbstractBinary.php | 43 + .../src/Node/Expression/Binary/AddBinary.php | 25 + .../src/Node/Expression/Binary/AndBinary.php | 25 + .../Expression/Binary/BitwiseAndBinary.php | 25 + .../Expression/Binary/BitwiseOrBinary.php | 25 + .../Expression/Binary/BitwiseXorBinary.php | 25 + .../Node/Expression/Binary/ConcatBinary.php | 25 + .../src/Node/Expression/Binary/DivBinary.php | 25 + .../Node/Expression/Binary/EndsWithBinary.php | 37 + .../Node/Expression/Binary/EqualBinary.php | 24 + .../Node/Expression/Binary/FloorDivBinary.php | 31 + .../Node/Expression/Binary/GreaterBinary.php | 24 + .../Expression/Binary/GreaterEqualBinary.php | 24 + .../src/Node/Expression/Binary/InBinary.php | 35 + .../src/Node/Expression/Binary/LessBinary.php | 24 + .../Expression/Binary/LessEqualBinary.php | 24 + .../Node/Expression/Binary/MatchesBinary.php | 35 + .../src/Node/Expression/Binary/ModBinary.php | 25 + .../src/Node/Expression/Binary/MulBinary.php | 25 + .../Node/Expression/Binary/NotEqualBinary.php | 24 + .../Node/Expression/Binary/NotInBinary.php | 35 + .../src/Node/Expression/Binary/OrBinary.php | 25 + .../Node/Expression/Binary/PowerBinary.php | 39 + .../Node/Expression/Binary/RangeBinary.php | 35 + .../Expression/Binary/StartsWithBinary.php | 37 + .../src/Node/Expression/Binary/SubBinary.php | 25 + .../Expression/BlockReferenceExpression.php | 98 + .../src/Node/Expression/CallExpression.php | 305 +++ .../Node/Expression/ConditionalExpression.php | 38 + .../Node/Expression/ConstantExpression.php | 30 + .../Node/Expression/Filter/DefaultFilter.php | 54 + .../src/Node/Expression/FilterExpression.php | 47 + .../Node/Expression/FunctionExpression.php | 51 + .../src/Node/Expression/GetAttrExpression.php | 80 + .../twig/src/Node/Expression/InlinePrint.php | 35 + .../Node/Expression/MethodCallExpression.php | 48 + .../src/Node/Expression/NameExpression.php | 119 + .../Expression/NullCoalesceExpression.php | 62 + .../src/Node/Expression/ParentExpression.php | 48 + .../Node/Expression/TempNameExpression.php | 33 + .../src/Node/Expression/Test/ConstantTest.php | 51 + .../src/Node/Expression/Test/DefinedTest.php | 71 + .../Node/Expression/Test/DivisiblebyTest.php | 38 + .../src/Node/Expression/Test/EvenTest.php | 37 + .../src/Node/Expression/Test/NullTest.php | 36 + .../twig/src/Node/Expression/Test/OddTest.php | 37 + .../src/Node/Expression/Test/SameasTest.php | 36 + .../src/Node/Expression/TestExpression.php | 51 + .../Node/Expression/Unary/AbstractUnary.php | 35 + .../src/Node/Expression/Unary/NegUnary.php | 25 + .../src/Node/Expression/Unary/NotUnary.php | 25 + .../src/Node/Expression/Unary/PosUnary.php | 25 + .../Twig1x/twig/twig/src/Node/FlushNode.php | 37 + .../Twig1x/twig/twig/src/Node/ForLoopNode.php | 56 + .../Twig1x/twig/twig/src/Node/ForNode.php | 119 + .../Twig/Twig1x/twig/twig/src/Node/IfNode.php | 72 + .../Twig1x/twig/twig/src/Node/ImportNode.php | 57 + .../Twig1x/twig/twig/src/Node/IncludeNode.php | 108 + .../Twig1x/twig/twig/src/Node/MacroNode.php | 136 + .../Twig1x/twig/twig/src/Node/ModuleNode.php | 492 ++++ .../Twig/Twig1x/twig/twig/src/Node/Node.php | 274 ++ .../twig/src/Node/NodeCaptureInterface.php | 23 + .../twig/src/Node/NodeOutputInterface.php | 23 + .../Twig1x/twig/twig/src/Node/PrintNode.php | 41 + .../Twig1x/twig/twig/src/Node/SandboxNode.php | 47 + .../twig/twig/src/Node/SandboxedPrintNode.php | 69 + .../Twig1x/twig/twig/src/Node/SetNode.php | 107 + .../Twig1x/twig/twig/src/Node/SetTempNode.php | 44 + .../twig/twig/src/Node/SpacelessNode.php | 47 + .../Twig1x/twig/twig/src/Node/TextNode.php | 40 + .../Twig1x/twig/twig/src/Node/WithNode.php | 72 + .../Twig1x/twig/twig/src/NodeTraverser.php | 89 + .../src/NodeVisitor/AbstractNodeVisitor.php | 59 + .../src/NodeVisitor/EscaperNodeVisitor.php | 209 ++ .../src/NodeVisitor/NodeVisitorInterface.php | 50 + .../src/NodeVisitor/OptimizerNodeVisitor.php | 273 ++ .../NodeVisitor/SafeAnalysisNodeVisitor.php | 164 ++ .../src/NodeVisitor/SandboxNodeVisitor.php | 137 + .../Twig/Twig1x/twig/twig/src/Parser.php | 439 +++ .../twig/src/Profiler/Dumper/BaseDumper.php | 65 + .../src/Profiler/Dumper/BlackfireDumper.php | 76 + .../twig/src/Profiler/Dumper/HtmlDumper.php | 51 + .../twig/src/Profiler/Dumper/TextDumper.php | 39 + .../src/Profiler/Node/EnterProfileNode.php | 44 + .../src/Profiler/Node/LeaveProfileNode.php | 38 + .../NodeVisitor/ProfilerNodeVisitor.php | 80 + .../Twig1x/twig/twig/src/Profiler/Profile.php | 188 ++ .../RuntimeLoader/ContainerRuntimeLoader.php | 41 + .../RuntimeLoader/FactoryRuntimeLoader.php | 41 + .../RuntimeLoader/RuntimeLoaderInterface.php | 31 + .../twig/twig/src/Sandbox/SecurityError.php | 25 + .../Sandbox/SecurityNotAllowedFilterError.php | 35 + .../SecurityNotAllowedFunctionError.php | 35 + .../Sandbox/SecurityNotAllowedMethodError.php | 42 + .../SecurityNotAllowedPropertyError.php | 42 + .../Sandbox/SecurityNotAllowedTagError.php | 35 + .../twig/twig/src/Sandbox/SecurityPolicy.php | 129 + .../src/Sandbox/SecurityPolicyInterface.php | 28 + .../Twig/Twig1x/twig/twig/src/Source.php | 55 + .../Twig/Twig1x/twig/twig/src/Template.php | 733 +++++ .../Twig1x/twig/twig/src/TemplateWrapper.php | 161 ++ .../twig/src/Test/IntegrationTestCase.php | 257 ++ .../twig/twig/src/Test/NodeTestCase.php | 79 + .../Twig/Twig1x/twig/twig/src/Token.php | 215 ++ .../src/TokenParser/AbstractTokenParser.php | 34 + .../twig/src/TokenParser/ApplyTokenParser.php | 58 + .../src/TokenParser/AutoEscapeTokenParser.php | 88 + .../twig/src/TokenParser/BlockTokenParser.php | 80 + .../src/TokenParser/DeprecatedTokenParser.php | 44 + .../twig/src/TokenParser/DoTokenParser.php | 39 + .../twig/src/TokenParser/EmbedTokenParser.php | 74 + .../src/TokenParser/ExtendsTokenParser.php | 54 + .../src/TokenParser/FilterTokenParser.php | 59 + .../twig/src/TokenParser/FlushTokenParser.php | 39 + .../twig/src/TokenParser/ForTokenParser.php | 136 + .../twig/src/TokenParser/FromTokenParser.php | 72 + .../twig/src/TokenParser/IfTokenParser.php | 91 + .../src/TokenParser/ImportTokenParser.php | 45 + .../src/TokenParser/IncludeTokenParser.php | 68 + .../twig/src/TokenParser/MacroTokenParser.php | 68 + .../src/TokenParser/SandboxTokenParser.php | 67 + .../twig/src/TokenParser/SetTokenParser.php | 74 + .../src/TokenParser/SpacelessTokenParser.php | 53 + .../src/TokenParser/TokenParserInterface.php | 51 + .../twig/src/TokenParser/UseTokenParser.php | 75 + .../twig/src/TokenParser/WithTokenParser.php | 57 + .../Twig/Twig1x/twig/twig/src/TokenStream.php | 201 ++ .../Twig/Twig1x/twig/twig/src/TwigFilter.php | 128 + .../Twig1x/twig/twig/src/TwigFunction.php | 118 + .../Twig/Twig1x/twig/twig/src/TwigTest.php | 87 + .../twig/src/Util/DeprecationCollector.php | 92 + .../twig/src/Util/TemplateDirIterator.php | 30 + .../Twig/Twig2x/BaseNodeVisitor.php | 46 - .../Twig/Twig2x/Cache/Filesystem.php | 91 - .../Twig/Twig2x/Cache/Null.php | 38 - .../Twig/Twig2x/CacheInterface.php | 58 - .../templateEngines/Twig/Twig2x/Compiler.php | 243 -- .../Twig/Twig2x/ContainerRuntimeLoader.php | 39 - .../Twig/Twig2x/Environment.php | 970 ------- system/templateEngines/Twig/Twig2x/Error.php | 265 -- .../Twig/Twig2x/Error/Loader.php | 35 - .../Twig/Twig2x/Error/Runtime.php | 22 - .../Twig/Twig2x/Error/Syntax.php | 46 - .../Twig/Twig2x/ExistsLoaderInterface.php | 19 - .../Twig/Twig2x/ExpressionParser.php | 719 ----- .../templateEngines/Twig/Twig2x/Extension.php | 46 - .../Twig/Twig2x/Extension/Core.php | 1637 ----------- .../Twig/Twig2x/Extension/Debug.php | 56 - .../Twig/Twig2x/Extension/Escaper.php | 91 - .../Twig2x/Extension/GlobalsInterface.php | 30 - .../Twig2x/Extension/InitRuntimeInterface.php | 32 - .../Twig/Twig2x/Extension/Optimizer.php | 27 - .../Twig/Twig2x/Extension/Profiler.php | 44 - .../Twig/Twig2x/Extension/Sandbox.php | 95 - .../Twig/Twig2x/Extension/Staging.php | 94 - .../Twig/Twig2x/Extension/StringLoader.php | 39 - .../Twig/Twig2x/ExtensionInterface.php | 63 - .../Twig/Twig2x/ExtensionSet.php | 498 ---- .../Twig/Twig2x/FactoryRuntimeLoader.php | 39 - .../Twig2x/FileExtensionEscapingStrategy.php | 60 - system/templateEngines/Twig/Twig2x/Filter.php | 142 - .../templateEngines/Twig/Twig2x/Function.php | 132 - system/templateEngines/Twig/Twig2x/Lexer.php | 398 --- .../Twig/Twig2x/Loader/Array.php | 81 - .../Twig/Twig2x/Loader/Chain.php | 108 - .../Twig/Twig2x/Loader/Filesystem.php | 292 -- .../Twig/Twig2x/LoaderInterface.php | 64 - system/templateEngines/Twig/Twig2x/Markup.php | 44 - system/templateEngines/Twig/Twig2x/Node.php | 185 -- .../Twig/Twig2x/Node/AutoEscape.php | 36 - .../Twig/Twig2x/Node/Block.php | 41 - .../Twig/Twig2x/Node/BlockReference.php | 34 - .../templateEngines/Twig/Twig2x/Node/Body.php | 21 - .../Twig/Twig2x/Node/CheckSecurity.php | 80 - .../Twig/Twig2x/Node/Deprecated.php | 49 - .../templateEngines/Twig/Twig2x/Node/Do.php | 35 - .../Twig/Twig2x/Node/Embed.php | 44 - .../Twig/Twig2x/Node/Expression.php | 22 - .../Twig/Twig2x/Node/Expression/Array.php | 83 - .../Twig2x/Node/Expression/AssignName.php | 25 - .../Twig/Twig2x/Node/Expression/Binary.php | 37 - .../Twig2x/Node/Expression/Binary/Add.php | 20 - .../Twig2x/Node/Expression/Binary/And.php | 20 - .../Node/Expression/Binary/BitwiseAnd.php | 20 - .../Node/Expression/Binary/BitwiseOr.php | 20 - .../Node/Expression/Binary/BitwiseXor.php | 20 - .../Twig2x/Node/Expression/Binary/Concat.php | 20 - .../Twig2x/Node/Expression/Binary/Div.php | 20 - .../Node/Expression/Binary/EndsWith.php | 32 - .../Twig2x/Node/Expression/Binary/Equal.php | 19 - .../Node/Expression/Binary/FloorDiv.php | 26 - .../Twig2x/Node/Expression/Binary/Greater.php | 19 - .../Node/Expression/Binary/GreaterEqual.php | 19 - .../Twig/Twig2x/Node/Expression/Binary/In.php | 30 - .../Twig2x/Node/Expression/Binary/Less.php | 19 - .../Node/Expression/Binary/LessEqual.php | 19 - .../Twig2x/Node/Expression/Binary/Matches.php | 30 - .../Twig2x/Node/Expression/Binary/Mod.php | 20 - .../Twig2x/Node/Expression/Binary/Mul.php | 20 - .../Node/Expression/Binary/NotEqual.php | 19 - .../Twig2x/Node/Expression/Binary/NotIn.php | 30 - .../Twig/Twig2x/Node/Expression/Binary/Or.php | 20 - .../Twig2x/Node/Expression/Binary/Power.php | 19 - .../Twig2x/Node/Expression/Binary/Range.php | 30 - .../Node/Expression/Binary/StartsWith.php | 32 - .../Twig2x/Node/Expression/Binary/Sub.php | 20 - .../Twig2x/Node/Expression/BlockReference.php | 84 - .../Twig/Twig2x/Node/Expression/Call.php | 297 -- .../Twig2x/Node/Expression/Conditional.php | 33 - .../Twig/Twig2x/Node/Expression/Constant.php | 25 - .../Twig/Twig2x/Node/Expression/Filter.php | 36 - .../Twig2x/Node/Expression/Filter/Default.php | 45 - .../Twig/Twig2x/Node/Expression/Function.php | 39 - .../Twig/Twig2x/Node/Expression/GetAttr.php | 98 - .../Twig2x/Node/Expression/MethodCall.php | 43 - .../Twig/Twig2x/Node/Expression/Name.php | 87 - .../Twig2x/Node/Expression/NullCoalesce.php | 48 - .../Twig/Twig2x/Node/Expression/Parent.php | 44 - .../Twig/Twig2x/Node/Expression/TempName.php | 28 - .../Twig/Twig2x/Node/Expression/Test.php | 38 - .../Twig2x/Node/Expression/Test/Constant.php | 48 - .../Twig2x/Node/Expression/Test/Defined.php | 62 - .../Node/Expression/Test/Divisibleby.php | 35 - .../Twig/Twig2x/Node/Expression/Test/Even.php | 34 - .../Twig/Twig2x/Node/Expression/Test/Null.php | 33 - .../Twig/Twig2x/Node/Expression/Test/Odd.php | 34 - .../Twig2x/Node/Expression/Test/Sameas.php | 31 - .../Twig/Twig2x/Node/Expression/Unary.php | 29 - .../Twig/Twig2x/Node/Expression/Unary/Neg.php | 20 - .../Twig/Twig2x/Node/Expression/Unary/Not.php | 20 - .../Twig/Twig2x/Node/Expression/Unary/Pos.php | 20 - .../Twig/Twig2x/Node/Flush.php | 33 - .../templateEngines/Twig/Twig2x/Node/For.php | 113 - .../Twig/Twig2x/Node/ForLoop.php | 52 - .../templateEngines/Twig/Twig2x/Node/If.php | 68 - .../Twig/Twig2x/Node/Import.php | 51 - .../Twig/Twig2x/Node/Include.php | 90 - .../Twig/Twig2x/Node/Macro.php | 106 - .../Twig/Twig2x/Node/Module.php | 454 ---- .../Twig/Twig2x/Node/Print.php | 36 - .../Twig/Twig2x/Node/Sandbox.php | 44 - .../Twig/Twig2x/Node/SandboxedPrint.php | 51 - .../templateEngines/Twig/Twig2x/Node/Set.php | 98 - .../Twig/Twig2x/Node/Spaceless.php | 37 - .../templateEngines/Twig/Twig2x/Node/Text.php | 36 - .../templateEngines/Twig/Twig2x/Node/With.php | 66 - .../Twig/Twig2x/NodeCaptureInterface.php | 21 - .../Twig/Twig2x/NodeOutputInterface.php | 21 - .../Twig/Twig2x/NodeTraverser.php | 80 - .../Twig/Twig2x/NodeVisitor/Escaper.php | 152 -- .../Twig/Twig2x/NodeVisitor/Optimizer.php | 207 -- .../Twig/Twig2x/NodeVisitor/SafeAnalysis.php | 146 - .../Twig/Twig2x/NodeVisitor/Sandbox.php | 80 - .../Twig/Twig2x/NodeVisitorInterface.php | 45 - system/templateEngines/Twig/Twig2x/Parser.php | 377 --- .../Twig/Twig2x/Profiler/Dumper/Base.php | 62 - .../Twig/Twig2x/Profiler/Dumper/Blackfire.php | 70 - .../Twig/Twig2x/Profiler/Dumper/Html.php | 45 - .../Twig/Twig2x/Profiler/Dumper/Text.php | 33 - .../Twig2x/Profiler/Node/EnterProfile.php | 39 - .../Twig2x/Profiler/Node/LeaveProfile.php | 33 - .../Twig2x/Profiler/NodeVisitor/Profiler.php | 65 - .../Twig/Twig2x/Profiler/Profile.php | 174 -- .../Twig/Twig2x/RuntimeLoaderInterface.php | 29 - .../Twig/Twig2x/Sandbox/SecurityError.php | 21 - .../Sandbox/SecurityNotAllowedFilterError.php | 33 - .../SecurityNotAllowedFunctionError.php | 33 - .../Sandbox/SecurityNotAllowedMethodError.php | 40 - .../SecurityNotAllowedPropertyError.php | 40 - .../Sandbox/SecurityNotAllowedTagError.php | 33 - .../Twig/Twig2x/Sandbox/SecurityPolicy.php | 123 - .../Sandbox/SecurityPolicyInterface.php | 26 - .../Twig/Twig2x/SimpleFilter.php | 21 - .../Twig/Twig2x/SimpleFunction.php | 21 - .../Twig/Twig2x/SimpleTest.php | 21 - system/templateEngines/Twig/Twig2x/Source.php | 51 - .../Twig2x/SourceContextLoaderInterface.php | 19 - .../templateEngines/Twig/Twig2x/Template.php | 414 --- .../Twig/Twig2x/TemplateWrapper.php | 131 - system/templateEngines/Twig/Twig2x/Test.php | 105 - .../Twig/Twig2x/Test/IntegrationTestCase.php | 257 -- .../Twig/Twig2x/Test/NodeTestCase.php | 63 - system/templateEngines/Twig/Twig2x/Token.php | 205 -- .../Twig/Twig2x/TokenParser.php | 33 - .../Twig/Twig2x/TokenParser/AutoEscape.php | 50 - .../Twig/Twig2x/TokenParser/Block.php | 71 - .../Twig/Twig2x/TokenParser/Deprecated.php | 42 - .../Twig/Twig2x/TokenParser/Do.php | 32 - .../Twig/Twig2x/TokenParser/Embed.php | 65 - .../Twig/Twig2x/TokenParser/Extends.php | 44 - .../Twig/Twig2x/TokenParser/Filter.php | 51 - .../Twig/Twig2x/TokenParser/Flush.php | 32 - .../Twig/Twig2x/TokenParser/For.php | 125 - .../Twig/Twig2x/TokenParser/From.php | 60 - .../Twig/Twig2x/TokenParser/If.php | 84 - .../Twig/Twig2x/TokenParser/Import.php | 39 - .../Twig/Twig2x/TokenParser/Include.php | 65 - .../Twig/Twig2x/TokenParser/Macro.php | 58 - .../Twig/Twig2x/TokenParser/Sandbox.php | 59 - .../Twig/Twig2x/TokenParser/Set.php | 73 - .../Twig/Twig2x/TokenParser/Spaceless.php | 49 - .../Twig/Twig2x/TokenParser/Use.php | 68 - .../Twig/Twig2x/TokenParser/With.php | 50 - .../Twig/Twig2x/TokenParserInterface.php | 43 - .../Twig/Twig2x/TokenStream.php | 150 - .../Twig/Twig2x/Util/DeprecationCollector.php | 73 - .../Twig/Twig2x/Util/TemplateDirIterator.php | 28 - .../templateEngines/Twig/Twig2x/autoload.php | 7 + .../Twig/Twig2x/composer/ClassLoader.php | 445 +++ .../Twig/Twig2x/composer/LICENSE | 21 + .../Twig2x/composer/autoload_classmap.php | 9 + .../Twig/Twig2x/composer/autoload_files.php | 11 + .../Twig2x/composer/autoload_namespaces.php | 10 + .../Twig/Twig2x/composer/autoload_psr4.php | 12 + .../Twig/Twig2x/composer/autoload_real.php | 70 + .../Twig/Twig2x/composer/autoload_static.php | 60 + .../Twig/Twig2x/composer/installed.json | 190 ++ .../Twig2x/symfony/polyfill-ctype/Ctype.php | 227 ++ .../Twig2x/symfony/polyfill-ctype/LICENSE | 19 + .../Twig2x/symfony/polyfill-ctype/README.md | 12 + .../symfony/polyfill-ctype/bootstrap.php | 26 + .../symfony/polyfill-ctype/composer.json | 34 + .../Twig2x/symfony/polyfill-mbstring/LICENSE | 19 + .../symfony/polyfill-mbstring/Mbstring.php | 847 ++++++ .../symfony/polyfill-mbstring/README.md | 13 + .../Resources/unidata/lowerCase.php | 1096 ++++++++ .../Resources/unidata/titleCaseRegexp.php | 5 + .../Resources/unidata/upperCase.php | 1104 ++++++++ .../symfony/polyfill-mbstring/bootstrap.php | 62 + .../symfony/polyfill-mbstring/composer.json | 34 + .../Twig/Twig2x/twig/twig/LICENSE | 29 + .../Twig/Twig2x/twig/twig/README.rst | 24 + .../twig/twig/lib/Twig/BaseNodeVisitor.php | 14 + .../twig/twig/lib/Twig/Cache/Filesystem.php | 14 + .../Twig2x/twig/twig/lib/Twig/Cache/Null.php | 14 + .../twig/twig/lib/Twig/CacheInterface.php | 14 + .../Twig2x/twig/twig/lib/Twig/Compiler.php | 14 + .../twig/lib/Twig/ContainerRuntimeLoader.php | 14 + .../Twig2x/twig/twig/lib/Twig/Environment.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Error.php | 14 + .../twig/twig/lib/Twig/Error/Loader.php | 14 + .../twig/twig/lib/Twig/Error/Runtime.php | 14 + .../twig/twig/lib/Twig/Error/Syntax.php | 14 + .../twig/lib/Twig/ExistsLoaderInterface.php | 14 + .../twig/twig/lib/Twig/ExpressionParser.php | 14 + .../Twig2x/twig/twig/lib/Twig/Extension.php | 14 + .../twig/twig/lib/Twig/Extension/Core.php | 14 + .../twig/twig/lib/Twig/Extension/Debug.php | 14 + .../twig/twig/lib/Twig/Extension/Escaper.php | 14 + .../lib/Twig/Extension/GlobalsInterface.php | 14 + .../Twig/Extension/InitRuntimeInterface.php | 14 + .../twig/lib/Twig/Extension/Optimizer.php | 14 + .../twig/twig/lib/Twig/Extension/Profiler.php | 14 + .../twig/twig/lib/Twig/Extension/Sandbox.php | 14 + .../twig/twig/lib/Twig/Extension/Staging.php | 14 + .../twig/lib/Twig/Extension/StringLoader.php | 14 + .../twig/twig/lib/Twig/ExtensionInterface.php | 14 + .../twig/twig/lib/Twig/ExtensionSet.php | 14 + .../twig/lib/Twig/FactoryRuntimeLoader.php | 14 + .../Twig/FileExtensionEscapingStrategy.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Filter.php | 14 + .../Twig2x/twig/twig/lib/Twig/Function.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Lexer.php | 14 + .../twig/twig/lib/Twig/Loader/Array.php | 14 + .../twig/twig/lib/Twig/Loader/Chain.php | 14 + .../twig/twig/lib/Twig/Loader/Filesystem.php | 14 + .../twig/twig/lib/Twig/LoaderInterface.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Markup.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Node.php | 14 + .../twig/twig/lib/Twig/Node/AutoEscape.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Block.php | 14 + .../twig/lib/Twig/Node/BlockReference.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Body.php | 14 + .../twig/twig/lib/Twig/Node/CheckSecurity.php | 14 + .../twig/twig/lib/Twig/Node/Deprecated.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Do.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Embed.php | 14 + .../twig/twig/lib/Twig/Node/Expression.php | 14 + .../twig/lib/Twig/Node/Expression/Array.php | 14 + .../lib/Twig/Node/Expression/AssignName.php | 14 + .../twig/lib/Twig/Node/Expression/Binary.php | 14 + .../lib/Twig/Node/Expression/Binary/Add.php | 14 + .../lib/Twig/Node/Expression/Binary/And.php | 14 + .../Node/Expression/Binary/BitwiseAnd.php | 14 + .../Twig/Node/Expression/Binary/BitwiseOr.php | 14 + .../Node/Expression/Binary/BitwiseXor.php | 14 + .../Twig/Node/Expression/Binary/Concat.php | 14 + .../lib/Twig/Node/Expression/Binary/Div.php | 14 + .../Twig/Node/Expression/Binary/EndsWith.php | 14 + .../lib/Twig/Node/Expression/Binary/Equal.php | 14 + .../Twig/Node/Expression/Binary/FloorDiv.php | 14 + .../Twig/Node/Expression/Binary/Greater.php | 14 + .../Node/Expression/Binary/GreaterEqual.php | 14 + .../lib/Twig/Node/Expression/Binary/In.php | 14 + .../lib/Twig/Node/Expression/Binary/Less.php | 14 + .../Twig/Node/Expression/Binary/LessEqual.php | 14 + .../Twig/Node/Expression/Binary/Matches.php | 14 + .../lib/Twig/Node/Expression/Binary/Mod.php | 14 + .../lib/Twig/Node/Expression/Binary/Mul.php | 14 + .../Twig/Node/Expression/Binary/NotEqual.php | 14 + .../lib/Twig/Node/Expression/Binary/NotIn.php | 14 + .../lib/Twig/Node/Expression/Binary/Or.php | 14 + .../lib/Twig/Node/Expression/Binary/Power.php | 14 + .../lib/Twig/Node/Expression/Binary/Range.php | 14 + .../Node/Expression/Binary/StartsWith.php | 14 + .../lib/Twig/Node/Expression/Binary/Sub.php | 14 + .../Twig/Node/Expression/BlockReference.php | 14 + .../twig/lib/Twig/Node/Expression/Call.php | 14 + .../lib/Twig/Node/Expression/Conditional.php | 14 + .../lib/Twig/Node/Expression/Constant.php | 14 + .../twig/lib/Twig/Node/Expression/Filter.php | 14 + .../Twig/Node/Expression/Filter/Default.php | 14 + .../lib/Twig/Node/Expression/Function.php | 14 + .../twig/lib/Twig/Node/Expression/GetAttr.php | 14 + .../lib/Twig/Node/Expression/MethodCall.php | 14 + .../twig/lib/Twig/Node/Expression/Name.php | 14 + .../lib/Twig/Node/Expression/NullCoalesce.php | 14 + .../twig/lib/Twig/Node/Expression/Parent.php | 14 + .../lib/Twig/Node/Expression/TempName.php | 14 + .../twig/lib/Twig/Node/Expression/Test.php | 14 + .../Twig/Node/Expression/Test/Constant.php | 14 + .../lib/Twig/Node/Expression/Test/Defined.php | 14 + .../Twig/Node/Expression/Test/Divisibleby.php | 14 + .../lib/Twig/Node/Expression/Test/Even.php | 14 + .../lib/Twig/Node/Expression/Test/Null.php | 14 + .../lib/Twig/Node/Expression/Test/Odd.php | 14 + .../lib/Twig/Node/Expression/Test/Sameas.php | 14 + .../twig/lib/Twig/Node/Expression/Unary.php | 14 + .../lib/Twig/Node/Expression/Unary/Neg.php | 14 + .../lib/Twig/Node/Expression/Unary/Not.php | 14 + .../lib/Twig/Node/Expression/Unary/Pos.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Flush.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/For.php | 14 + .../twig/twig/lib/Twig/Node/ForLoop.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/If.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Import.php | 14 + .../twig/twig/lib/Twig/Node/Include.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Macro.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Module.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Print.php | 14 + .../twig/twig/lib/Twig/Node/Sandbox.php | 14 + .../twig/lib/Twig/Node/SandboxedPrint.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Set.php | 14 + .../twig/twig/lib/Twig/Node/Spaceless.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/Text.php | 14 + .../Twig2x/twig/twig/lib/Twig/Node/With.php | 14 + .../twig/lib/Twig/NodeCaptureInterface.php | 14 + .../twig/lib/Twig/NodeOutputInterface.php | 14 + .../twig/twig/lib/Twig/NodeTraverser.php | 14 + .../twig/lib/Twig/NodeVisitor/Escaper.php | 14 + .../twig/lib/Twig/NodeVisitor/Optimizer.php | 14 + .../lib/Twig/NodeVisitor/SafeAnalysis.php | 14 + .../twig/lib/Twig/NodeVisitor/Sandbox.php | 14 + .../twig/lib/Twig/NodeVisitorInterface.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Parser.php | 14 + .../twig/lib/Twig/Profiler/Dumper/Base.php | 14 + .../lib/Twig/Profiler/Dumper/Blackfire.php | 14 + .../twig/lib/Twig/Profiler/Dumper/Html.php | 14 + .../twig/lib/Twig/Profiler/Dumper/Text.php | 14 + .../lib/Twig/Profiler/Node/EnterProfile.php | 14 + .../lib/Twig/Profiler/Node/LeaveProfile.php | 14 + .../Twig/Profiler/NodeVisitor/Profiler.php | 14 + .../twig/twig/lib/Twig/Profiler/Profile.php | 14 + .../twig/lib/Twig/RuntimeLoaderInterface.php | 14 + .../twig/lib/Twig/Sandbox/SecurityError.php | 14 + .../Sandbox/SecurityNotAllowedFilterError.php | 14 + .../SecurityNotAllowedFunctionError.php | 14 + .../Sandbox/SecurityNotAllowedMethodError.php | 14 + .../SecurityNotAllowedPropertyError.php | 14 + .../Sandbox/SecurityNotAllowedTagError.php | 14 + .../twig/lib/Twig/Sandbox/SecurityPolicy.php | 14 + .../Twig/Sandbox/SecurityPolicyInterface.php | 14 + .../twig/twig/lib/Twig/SimpleFilter.php | 26 + .../twig/twig/lib/Twig/SimpleFunction.php | 26 + .../Twig2x/twig/twig/lib/Twig/SimpleTest.php | 26 + .../Twig/Twig2x/twig/twig/lib/Twig/Source.php | 14 + .../lib/Twig/SourceContextLoaderInterface.php | 14 + .../Twig2x/twig/twig/lib/Twig/Template.php | 14 + .../twig/twig/lib/Twig/TemplateWrapper.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Test.php | 14 + .../lib/Twig/Test/IntegrationTestCase.php | 14 + .../twig/twig/lib/Twig/Test/NodeTestCase.php | 14 + .../Twig/Twig2x/twig/twig/lib/Twig/Token.php | 14 + .../Twig2x/twig/twig/lib/Twig/TokenParser.php | 14 + .../twig/lib/Twig/TokenParser/AutoEscape.php | 14 + .../twig/twig/lib/Twig/TokenParser/Block.php | 14 + .../twig/lib/Twig/TokenParser/Deprecated.php | 14 + .../twig/twig/lib/Twig/TokenParser/Do.php | 14 + .../twig/twig/lib/Twig/TokenParser/Embed.php | 14 + .../twig/lib/Twig/TokenParser/Extends.php | 14 + .../twig/twig/lib/Twig/TokenParser/Filter.php | 14 + .../twig/twig/lib/Twig/TokenParser/Flush.php | 14 + .../twig/twig/lib/Twig/TokenParser/For.php | 14 + .../twig/twig/lib/Twig/TokenParser/From.php | 14 + .../twig/twig/lib/Twig/TokenParser/If.php | 14 + .../twig/twig/lib/Twig/TokenParser/Import.php | 14 + .../twig/lib/Twig/TokenParser/Include.php | 14 + .../twig/twig/lib/Twig/TokenParser/Macro.php | 14 + .../twig/lib/Twig/TokenParser/Sandbox.php | 14 + .../twig/twig/lib/Twig/TokenParser/Set.php | 14 + .../twig/lib/Twig/TokenParser/Spaceless.php | 14 + .../twig/twig/lib/Twig/TokenParser/Use.php | 14 + .../twig/twig/lib/Twig/TokenParser/With.php | 14 + .../twig/lib/Twig/TokenParserInterface.php | 14 + .../Twig2x/twig/twig/lib/Twig/TokenStream.php | 14 + .../lib/Twig/Util/DeprecationCollector.php | 14 + .../lib/Twig/Util/TemplateDirIterator.php | 14 + .../twig/twig/src/Cache/CacheInterface.php | 60 + .../twig/twig/src/Cache/FilesystemCache.php | 93 + .../Twig2x/twig/twig/src/Cache/NullCache.php | 40 + .../Twig/Twig2x/twig/twig/src/Compiler.php | 245 ++ .../Twig/Twig2x/twig/twig/src/Environment.php | 995 +++++++ .../Twig/Twig2x/twig/twig/src/Error/Error.php | 257 ++ .../twig/twig/src/Error/LoaderError.php | 23 + .../twig/twig/src/Error/RuntimeError.php | 24 + .../twig/twig/src/Error/SyntaxError.php | 48 + .../Twig2x/twig/twig/src/ExpressionParser.php | 814 ++++++ .../twig/src/Extension/AbstractExtension.php | 47 + .../twig/twig/src/Extension/CoreExtension.php | 1566 +++++++++++ .../twig/src/Extension/DebugExtension.php | 66 + .../twig/src/Extension/EscaperExtension.php | 427 +++ .../twig/src/Extension/ExtensionInterface.php | 73 + .../twig/src/Extension/GlobalsInterface.php | 32 + .../src/Extension/InitRuntimeInterface.php | 36 + .../twig/src/Extension/OptimizerExtension.php | 31 + .../twig/src/Extension/ProfilerExtension.php | 48 + .../Extension/RuntimeExtensionInterface.php | 19 + .../twig/src/Extension/SandboxExtension.php | 125 + .../twig/src/Extension/StagingExtension.php | 102 + .../src/Extension/StringLoaderExtension.php | 46 + .../Twig2x/twig/twig/src/ExtensionSet.php | 477 ++++ .../src/FileExtensionEscapingStrategy.php | 62 + .../Twig/Twig2x/twig/twig/src/Lexer.php | 501 ++++ .../twig/twig/src/Loader/ArrayLoader.php | 86 + .../twig/twig/src/Loader/ChainLoader.php | 120 + .../twig/src/Loader/ExistsLoaderInterface.php | 23 + .../twig/twig/src/Loader/FilesystemLoader.php | 308 +++ .../twig/twig/src/Loader/LoaderInterface.php | 69 + .../Loader/SourceContextLoaderInterface.php | 21 + .../Twig/Twig2x/twig/twig/src/Markup.php | 46 + .../twig/twig/src/Node/AutoEscapeNode.php | 40 + .../Twig2x/twig/twig/src/Node/BlockNode.php | 46 + .../twig/twig/src/Node/BlockReferenceNode.php | 38 + .../Twig2x/twig/twig/src/Node/BodyNode.php | 23 + .../twig/twig/src/Node/CheckSecurityNode.php | 85 + .../twig/twig/src/Node/CheckToStringNode.php | 45 + .../twig/twig/src/Node/DeprecatedNode.php | 55 + .../Twig/Twig2x/twig/twig/src/Node/DoNode.php | 40 + .../Twig2x/twig/twig/src/Node/EmbedNode.php | 50 + .../Node/Expression/AbstractExpression.php | 26 + .../src/Node/Expression/ArrayExpression.php | 88 + .../Expression/ArrowFunctionExpression.php | 64 + .../Node/Expression/AssignNameExpression.php | 29 + .../Node/Expression/Binary/AbstractBinary.php | 44 + .../src/Node/Expression/Binary/AddBinary.php | 25 + .../src/Node/Expression/Binary/AndBinary.php | 25 + .../Expression/Binary/BitwiseAndBinary.php | 25 + .../Expression/Binary/BitwiseOrBinary.php | 25 + .../Expression/Binary/BitwiseXorBinary.php | 25 + .../Node/Expression/Binary/ConcatBinary.php | 25 + .../src/Node/Expression/Binary/DivBinary.php | 25 + .../Node/Expression/Binary/EndsWithBinary.php | 37 + .../Node/Expression/Binary/EqualBinary.php | 24 + .../Node/Expression/Binary/FloorDivBinary.php | 31 + .../Node/Expression/Binary/GreaterBinary.php | 24 + .../Expression/Binary/GreaterEqualBinary.php | 24 + .../src/Node/Expression/Binary/InBinary.php | 35 + .../src/Node/Expression/Binary/LessBinary.php | 24 + .../Expression/Binary/LessEqualBinary.php | 24 + .../Node/Expression/Binary/MatchesBinary.php | 35 + .../src/Node/Expression/Binary/ModBinary.php | 25 + .../src/Node/Expression/Binary/MulBinary.php | 25 + .../Node/Expression/Binary/NotEqualBinary.php | 24 + .../Node/Expression/Binary/NotInBinary.php | 35 + .../src/Node/Expression/Binary/OrBinary.php | 25 + .../Node/Expression/Binary/PowerBinary.php | 24 + .../Node/Expression/Binary/RangeBinary.php | 35 + .../Expression/Binary/SpaceshipBinary.php | 22 + .../Expression/Binary/StartsWithBinary.php | 37 + .../src/Node/Expression/Binary/SubBinary.php | 25 + .../Expression/BlockReferenceExpression.php | 88 + .../src/Node/Expression/CallExpression.php | 313 +++ .../Node/Expression/ConditionalExpression.php | 38 + .../Node/Expression/ConstantExpression.php | 30 + .../Node/Expression/Filter/DefaultFilter.php | 54 + .../src/Node/Expression/FilterExpression.php | 42 + .../Node/Expression/FunctionExpression.php | 45 + .../src/Node/Expression/GetAttrExpression.php | 89 + .../twig/src/Node/Expression/InlinePrint.php | 35 + .../Node/Expression/MethodCallExpression.php | 64 + .../src/Node/Expression/NameExpression.php | 99 + .../Expression/NullCoalesceExpression.php | 62 + .../src/Node/Expression/ParentExpression.php | 48 + .../Node/Expression/TempNameExpression.php | 33 + .../src/Node/Expression/Test/ConstantTest.php | 51 + .../src/Node/Expression/Test/DefinedTest.php | 76 + .../Node/Expression/Test/DivisiblebyTest.php | 38 + .../src/Node/Expression/Test/EvenTest.php | 37 + .../src/Node/Expression/Test/NullTest.php | 36 + .../twig/src/Node/Expression/Test/OddTest.php | 37 + .../src/Node/Expression/Test/SameasTest.php | 36 + .../src/Node/Expression/TestExpression.php | 44 + .../Node/Expression/Unary/AbstractUnary.php | 36 + .../src/Node/Expression/Unary/NegUnary.php | 25 + .../src/Node/Expression/Unary/NotUnary.php | 25 + .../src/Node/Expression/Unary/PosUnary.php | 25 + .../Node/Expression/VariadicExpression.php | 24 + .../Twig2x/twig/twig/src/Node/FlushNode.php | 37 + .../Twig2x/twig/twig/src/Node/ForLoopNode.php | 56 + .../Twig2x/twig/twig/src/Node/ForNode.php | 119 + .../Twig/Twig2x/twig/twig/src/Node/IfNode.php | 72 + .../Twig2x/twig/twig/src/Node/ImportNode.php | 65 + .../Twig2x/twig/twig/src/Node/IncludeNode.php | 108 + .../Twig2x/twig/twig/src/Node/MacroNode.php | 115 + .../Twig2x/twig/twig/src/Node/ModuleNode.php | 472 ++++ .../Twig/Twig2x/twig/twig/src/Node/Node.php | 211 ++ .../twig/src/Node/NodeCaptureInterface.php | 23 + .../twig/src/Node/NodeOutputInterface.php | 23 + .../Twig2x/twig/twig/src/Node/PrintNode.php | 41 + .../Twig2x/twig/twig/src/Node/SandboxNode.php | 47 + .../twig/twig/src/Node/SandboxedPrintNode.php | 54 + .../Twig2x/twig/twig/src/Node/SetNode.php | 107 + .../twig/twig/src/Node/SpacelessNode.php | 49 + .../Twig2x/twig/twig/src/Node/TextNode.php | 40 + .../Twig2x/twig/twig/src/Node/WithNode.php | 72 + .../Twig2x/twig/twig/src/NodeTraverser.php | 85 + .../src/NodeVisitor/AbstractNodeVisitor.php | 51 + .../src/NodeVisitor/EscaperNodeVisitor.php | 208 ++ .../MacroAutoImportNodeVisitor.php | 72 + .../src/NodeVisitor/NodeVisitorInterface.php | 51 + .../src/NodeVisitor/OptimizerNodeVisitor.php | 219 ++ .../NodeVisitor/SafeAnalysisNodeVisitor.php | 160 ++ .../src/NodeVisitor/SandboxNodeVisitor.php | 135 + .../Twig/Twig2x/twig/twig/src/Parser.php | 394 +++ .../twig/src/Profiler/Dumper/BaseDumper.php | 65 + .../src/Profiler/Dumper/BlackfireDumper.php | 74 + .../twig/src/Profiler/Dumper/HtmlDumper.php | 49 + .../twig/src/Profiler/Dumper/TextDumper.php | 37 + .../src/Profiler/Node/EnterProfileNode.php | 44 + .../src/Profiler/Node/LeaveProfileNode.php | 38 + .../NodeVisitor/ProfilerNodeVisitor.php | 78 + .../Twig2x/twig/twig/src/Profiler/Profile.php | 192 ++ .../RuntimeLoader/ContainerRuntimeLoader.php | 41 + .../RuntimeLoader/FactoryRuntimeLoader.php | 41 + .../RuntimeLoader/RuntimeLoaderInterface.php | 31 + .../twig/twig/src/Sandbox/SecurityError.php | 25 + .../Sandbox/SecurityNotAllowedFilterError.php | 46 + .../SecurityNotAllowedFunctionError.php | 46 + .../Sandbox/SecurityNotAllowedMethodError.php | 53 + .../SecurityNotAllowedPropertyError.php | 53 + .../Sandbox/SecurityNotAllowedTagError.php | 46 + .../twig/twig/src/Sandbox/SecurityPolicy.php | 128 + .../src/Sandbox/SecurityPolicyInterface.php | 37 + .../Twig/Twig2x/twig/twig/src/Source.php | 53 + .../Twig/Twig2x/twig/twig/src/Template.php | 437 +++ .../Twig2x/twig/twig/src/TemplateWrapper.php | 145 + .../twig/src/Test/IntegrationTestCase.php | 267 ++ .../twig/twig/src/Test/NodeTestCase.php | 67 + .../Twig/Twig2x/twig/twig/src/Token.php | 213 ++ .../src/TokenParser/AbstractTokenParser.php | 34 + .../twig/src/TokenParser/ApplyTokenParser.php | 58 + .../src/TokenParser/AutoEscapeTokenParser.php | 57 + .../twig/src/TokenParser/BlockTokenParser.php | 78 + .../src/TokenParser/DeprecatedTokenParser.php | 44 + .../twig/src/TokenParser/DoTokenParser.php | 37 + .../twig/src/TokenParser/EmbedTokenParser.php | 72 + .../src/TokenParser/ExtendsTokenParser.php | 52 + .../src/TokenParser/FilterTokenParser.php | 64 + .../twig/src/TokenParser/FlushTokenParser.php | 37 + .../twig/src/TokenParser/ForTokenParser.php | 137 + .../twig/src/TokenParser/FromTokenParser.php | 65 + .../twig/src/TokenParser/IfTokenParser.php | 89 + .../src/TokenParser/ImportTokenParser.php | 43 + .../src/TokenParser/IncludeTokenParser.php | 68 + .../twig/src/TokenParser/MacroTokenParser.php | 66 + .../src/TokenParser/SandboxTokenParser.php | 65 + .../twig/src/TokenParser/SetTokenParser.php | 72 + .../src/TokenParser/SpacelessTokenParser.php | 56 + .../src/TokenParser/TokenParserInterface.php | 52 + .../twig/src/TokenParser/UseTokenParser.php | 73 + .../twig/src/TokenParser/WithTokenParser.php | 55 + .../Twig/Twig2x/twig/twig/src/TokenStream.php | 134 + .../Twig/Twig2x/twig/twig/src/TwigFilter.php | 150 + .../Twig2x/twig/twig/src/TwigFunction.php | 140 + .../Twig/Twig2x/twig/twig/src/TwigTest.php | 109 + .../twig/src/Util/DeprecationCollector.php | 79 + .../twig/src/Util/TemplateDirIterator.php | 30 + .../templateEngines/Twig/Twig3x/autoload.php | 7 + .../Twig/Twig3x/composer/ClassLoader.php | 445 +++ .../Twig/Twig3x/composer/LICENSE | 21 + .../Twig3x/composer/autoload_classmap.php | 9 + .../Twig/Twig3x/composer/autoload_files.php | 11 + .../Twig3x/composer/autoload_namespaces.php | 9 + .../Twig/Twig3x/composer/autoload_psr4.php | 12 + .../Twig/Twig3x/composer/autoload_real.php | 70 + .../Twig/Twig3x/composer/autoload_static.php | 49 + .../Twig/Twig3x/composer/installed.json | 187 ++ .../Twig3x/symfony/polyfill-ctype/Ctype.php | 227 ++ .../Twig3x/symfony/polyfill-ctype/LICENSE | 19 + .../Twig3x/symfony/polyfill-ctype/README.md | 12 + .../symfony/polyfill-ctype/bootstrap.php | 26 + .../symfony/polyfill-ctype/composer.json | 34 + .../Twig3x/symfony/polyfill-mbstring/LICENSE | 19 + .../symfony/polyfill-mbstring/Mbstring.php | 847 ++++++ .../symfony/polyfill-mbstring/README.md | 13 + .../Resources/unidata/lowerCase.php | 1096 ++++++++ .../Resources/unidata/titleCaseRegexp.php | 5 + .../Resources/unidata/upperCase.php | 1104 ++++++++ .../symfony/polyfill-mbstring/bootstrap.php | 62 + .../symfony/polyfill-mbstring/composer.json | 34 + .../Twig/Twig3x/twig/twig/.editorconfig | 18 + .../Twig/Twig3x/twig/twig/.gitattributes | 3 + .../Twig/Twig3x/twig/twig/.gitignore | 4 + .../Twig/Twig3x/twig/twig/.php_cs.dist | 20 + .../Twig/Twig3x/twig/twig/.travis.yml | 43 + .../Twig/Twig3x/twig/twig/LICENSE | 29 + .../Twig/Twig3x/twig/twig/README.rst | 24 + .../twig/twig/src/Cache/CacheInterface.php | 46 + .../twig/twig/src/Cache/FilesystemCache.php | 87 + .../Twig3x/twig/twig/src/Cache/NullCache.php | 38 + .../Twig/Twig3x/twig/twig/src/Compiler.php | 214 ++ .../Twig/Twig3x/twig/twig/src/Environment.php | 816 ++++++ .../Twig/Twig3x/twig/twig/src/Error/Error.php | 227 ++ .../twig/twig/src/Error/LoaderError.php | 21 + .../twig/twig/src/Error/RuntimeError.php | 22 + .../twig/twig/src/Error/SyntaxError.php | 46 + .../Twig3x/twig/twig/src/ExpressionParser.php | 807 ++++++ .../twig/src/Extension/AbstractExtension.php | 45 + .../twig/twig/src/Extension/CoreExtension.php | 1598 +++++++++++ .../twig/src/Extension/DebugExtension.php | 64 + .../twig/src/Extension/EscaperExtension.php | 418 +++ .../twig/src/Extension/ExtensionInterface.php | 68 + .../twig/src/Extension/GlobalsInterface.php | 25 + .../twig/src/Extension/OptimizerExtension.php | 29 + .../twig/src/Extension/ProfilerExtension.php | 52 + .../Extension/RuntimeExtensionInterface.php | 19 + .../twig/src/Extension/SandboxExtension.php | 123 + .../twig/src/Extension/StagingExtension.php | 100 + .../src/Extension/StringLoaderExtension.php | 42 + .../Twig3x/twig/twig/src/ExtensionSet.php | 438 +++ .../src/FileExtensionEscapingStrategy.php | 60 + .../Twig/Twig3x/twig/twig/src/Lexer.php | 497 ++++ .../twig/twig/src/Loader/ArrayLoader.php | 78 + .../twig/twig/src/Loader/ChainLoader.php | 119 + .../twig/twig/src/Loader/FilesystemLoader.php | 283 ++ .../twig/twig/src/Loader/LoaderInterface.php | 49 + .../Twig/Twig3x/twig/twig/src/Markup.php | 44 + .../twig/twig/src/Node/AutoEscapeNode.php | 38 + .../Twig3x/twig/twig/src/Node/BlockNode.php | 44 + .../twig/twig/src/Node/BlockReferenceNode.php | 36 + .../Twig3x/twig/twig/src/Node/BodyNode.php | 21 + .../twig/twig/src/Node/CheckSecurityNode.php | 83 + .../twig/twig/src/Node/CheckToStringNode.php | 45 + .../twig/twig/src/Node/DeprecatedNode.php | 53 + .../Twig/Twig3x/twig/twig/src/Node/DoNode.php | 38 + .../Twig3x/twig/twig/src/Node/EmbedNode.php | 48 + .../Node/Expression/AbstractExpression.php | 24 + .../src/Node/Expression/ArrayExpression.php | 85 + .../Expression/ArrowFunctionExpression.php | 64 + .../Node/Expression/AssignNameExpression.php | 27 + .../Node/Expression/Binary/AbstractBinary.php | 42 + .../src/Node/Expression/Binary/AddBinary.php | 23 + .../src/Node/Expression/Binary/AndBinary.php | 23 + .../Expression/Binary/BitwiseAndBinary.php | 23 + .../Expression/Binary/BitwiseOrBinary.php | 23 + .../Expression/Binary/BitwiseXorBinary.php | 23 + .../Node/Expression/Binary/ConcatBinary.php | 23 + .../src/Node/Expression/Binary/DivBinary.php | 23 + .../Node/Expression/Binary/EndsWithBinary.php | 35 + .../Node/Expression/Binary/EqualBinary.php | 39 + .../Node/Expression/Binary/FloorDivBinary.php | 29 + .../Node/Expression/Binary/GreaterBinary.php | 39 + .../Expression/Binary/GreaterEqualBinary.php | 39 + .../src/Node/Expression/Binary/InBinary.php | 33 + .../src/Node/Expression/Binary/LessBinary.php | 39 + .../Expression/Binary/LessEqualBinary.php | 39 + .../Node/Expression/Binary/MatchesBinary.php | 33 + .../src/Node/Expression/Binary/ModBinary.php | 23 + .../src/Node/Expression/Binary/MulBinary.php | 23 + .../Node/Expression/Binary/NotEqualBinary.php | 39 + .../Node/Expression/Binary/NotInBinary.php | 33 + .../src/Node/Expression/Binary/OrBinary.php | 23 + .../Node/Expression/Binary/PowerBinary.php | 22 + .../Node/Expression/Binary/RangeBinary.php | 33 + .../Expression/Binary/SpaceshipBinary.php | 22 + .../Expression/Binary/StartsWithBinary.php | 35 + .../src/Node/Expression/Binary/SubBinary.php | 23 + .../Expression/BlockReferenceExpression.php | 86 + .../src/Node/Expression/CallExpression.php | 310 +++ .../Node/Expression/ConditionalExpression.php | 36 + .../Node/Expression/ConstantExpression.php | 28 + .../Node/Expression/Filter/DefaultFilter.php | 52 + .../src/Node/Expression/FilterExpression.php | 40 + .../Node/Expression/FunctionExpression.php | 43 + .../src/Node/Expression/GetAttrExpression.php | 87 + .../twig/src/Node/Expression/InlinePrint.php | 35 + .../Node/Expression/MethodCallExpression.php | 62 + .../src/Node/Expression/NameExpression.php | 97 + .../Expression/NullCoalesceExpression.php | 60 + .../src/Node/Expression/ParentExpression.php | 46 + .../Node/Expression/TempNameExpression.php | 31 + .../src/Node/Expression/Test/ConstantTest.php | 49 + .../src/Node/Expression/Test/DefinedTest.php | 74 + .../Node/Expression/Test/DivisiblebyTest.php | 36 + .../src/Node/Expression/Test/EvenTest.php | 35 + .../src/Node/Expression/Test/NullTest.php | 34 + .../twig/src/Node/Expression/Test/OddTest.php | 35 + .../src/Node/Expression/Test/SameasTest.php | 34 + .../src/Node/Expression/TestExpression.php | 42 + .../Node/Expression/Unary/AbstractUnary.php | 34 + .../src/Node/Expression/Unary/NegUnary.php | 23 + .../src/Node/Expression/Unary/NotUnary.php | 23 + .../src/Node/Expression/Unary/PosUnary.php | 23 + .../Node/Expression/VariadicExpression.php | 24 + .../Twig3x/twig/twig/src/Node/FlushNode.php | 35 + .../Twig3x/twig/twig/src/Node/ForLoopNode.php | 49 + .../Twig3x/twig/twig/src/Node/ForNode.php | 107 + .../Twig/Twig3x/twig/twig/src/Node/IfNode.php | 70 + .../Twig3x/twig/twig/src/Node/ImportNode.php | 63 + .../Twig3x/twig/twig/src/Node/IncludeNode.php | 106 + .../Twig3x/twig/twig/src/Node/MacroNode.php | 113 + .../Twig3x/twig/twig/src/Node/ModuleNode.php | 464 ++++ .../Twig/Twig3x/twig/twig/src/Node/Node.php | 175 ++ .../twig/src/Node/NodeCaptureInterface.php | 21 + .../twig/src/Node/NodeOutputInterface.php | 21 + .../Twig3x/twig/twig/src/Node/PrintNode.php | 39 + .../Twig3x/twig/twig/src/Node/SandboxNode.php | 45 + .../Twig3x/twig/twig/src/Node/SetNode.php | 105 + .../Twig3x/twig/twig/src/Node/TextNode.php | 38 + .../Twig3x/twig/twig/src/Node/WithNode.php | 70 + .../Twig3x/twig/twig/src/NodeTraverser.php | 76 + .../src/NodeVisitor/AbstractNodeVisitor.php | 49 + .../src/NodeVisitor/EscaperNodeVisitor.php | 206 ++ .../MacroAutoImportNodeVisitor.php | 72 + .../src/NodeVisitor/NodeVisitorInterface.php | 46 + .../src/NodeVisitor/OptimizerNodeVisitor.php | 215 ++ .../NodeVisitor/SafeAnalysisNodeVisitor.php | 157 ++ .../src/NodeVisitor/SandboxNodeVisitor.php | 132 + .../Twig/Twig3x/twig/twig/src/Parser.php | 360 +++ .../twig/src/Profiler/Dumper/BaseDumper.php | 63 + .../src/Profiler/Dumper/BlackfireDumper.php | 72 + .../twig/src/Profiler/Dumper/HtmlDumper.php | 47 + .../twig/src/Profiler/Dumper/TextDumper.php | 35 + .../src/Profiler/Node/EnterProfileNode.php | 42 + .../src/Profiler/Node/LeaveProfileNode.php | 36 + .../NodeVisitor/ProfilerNodeVisitor.php | 76 + .../Twig3x/twig/twig/src/Profiler/Profile.php | 181 ++ .../RuntimeLoader/ContainerRuntimeLoader.php | 37 + .../RuntimeLoader/FactoryRuntimeLoader.php | 41 + .../RuntimeLoader/RuntimeLoaderInterface.php | 27 + .../twig/twig/src/Sandbox/SecurityError.php | 23 + .../Sandbox/SecurityNotAllowedFilterError.php | 33 + .../SecurityNotAllowedFunctionError.php | 33 + .../Sandbox/SecurityNotAllowedMethodError.php | 40 + .../SecurityNotAllowedPropertyError.php | 40 + .../Sandbox/SecurityNotAllowedTagError.php | 33 + .../twig/twig/src/Sandbox/SecurityPolicy.php | 126 + .../src/Sandbox/SecurityPolicyInterface.php | 35 + .../Twig/Twig3x/twig/twig/src/Source.php | 51 + .../Twig/Twig3x/twig/twig/src/Template.php | 424 +++ .../Twig3x/twig/twig/src/TemplateWrapper.php | 109 + .../twig/src/Test/IntegrationTestCase.php | 265 ++ .../twig/twig/src/Test/NodeTestCase.php | 65 + .../Twig/Twig3x/twig/twig/src/Token.php | 178 ++ .../src/TokenParser/AbstractTokenParser.php | 32 + .../twig/src/TokenParser/ApplyTokenParser.php | 58 + .../src/TokenParser/AutoEscapeTokenParser.php | 56 + .../twig/src/TokenParser/BlockTokenParser.php | 76 + .../src/TokenParser/DeprecatedTokenParser.php | 41 + .../twig/src/TokenParser/DoTokenParser.php | 36 + .../twig/src/TokenParser/EmbedTokenParser.php | 71 + .../src/TokenParser/ExtendsTokenParser.php | 50 + .../twig/src/TokenParser/FlushTokenParser.php | 36 + .../twig/src/TokenParser/ForTokenParser.php | 77 + .../twig/src/TokenParser/FromTokenParser.php | 64 + .../twig/src/TokenParser/IfTokenParser.php | 87 + .../src/TokenParser/ImportTokenParser.php | 42 + .../src/TokenParser/IncludeTokenParser.php | 67 + .../twig/src/TokenParser/MacroTokenParser.php | 64 + .../src/TokenParser/SandboxTokenParser.php | 64 + .../twig/src/TokenParser/SetTokenParser.php | 71 + .../src/TokenParser/TokenParserInterface.php | 46 + .../twig/src/TokenParser/UseTokenParser.php | 71 + .../twig/src/TokenParser/WithTokenParser.php | 54 + .../Twig/Twig3x/twig/twig/src/TokenStream.php | 132 + .../Twig/Twig3x/twig/twig/src/TwigFilter.php | 134 + .../Twig3x/twig/twig/src/TwigFunction.php | 122 + .../Twig/Twig3x/twig/twig/src/TwigTest.php | 94 + .../twig/src/Util/DeprecationCollector.php | 77 + .../twig/src/Util/TemplateDirIterator.php | 28 + system/templateEngines/Twig/autoload.php | 54 +- system/templateEngines/smarty/Autoloader.php | 2 +- .../templateEngines/smarty/Smarty.class.php | 4 +- .../smarty/plugins/modifier.date_format.php | 4 +- .../smarty_internal_compile_insert.php | 1 + .../smarty_internal_compile_private_php.php | 4 +- .../smarty_internal_runtime_inheritance.php | 2 +- .../smarty_internal_templatelexer.php | 127 +- .../smarty_internal_templateparser.php | 2415 +++++++++-------- system/token/autoload.php | 47 +- 1382 files changed, 68930 insertions(+), 34391 deletions(-) create mode 100644 system/database/database/sqlite3_db.php create mode 100644 system/templateEngines/Twig/Extension/ExacTITranslate1x.php delete mode 100644 system/templateEngines/Twig/Twig1x/Autoloader.php delete mode 100644 system/templateEngines/Twig/Twig1x/BaseNodeVisitor.php delete mode 100644 system/templateEngines/Twig/Twig1x/Cache/Filesystem.php delete mode 100644 system/templateEngines/Twig/Twig1x/Cache/Null.php delete mode 100644 system/templateEngines/Twig/Twig1x/CacheInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Compiler.php delete mode 100644 system/templateEngines/Twig/Twig1x/ContainerRuntimeLoader.php delete mode 100644 system/templateEngines/Twig/Twig1x/Environment.php delete mode 100644 system/templateEngines/Twig/Twig1x/Error.php delete mode 100644 system/templateEngines/Twig/Twig1x/Error/Loader.php delete mode 100644 system/templateEngines/Twig/Twig1x/Error/Runtime.php delete mode 100644 system/templateEngines/Twig/Twig1x/Error/Syntax.php delete mode 100644 system/templateEngines/Twig/Twig1x/ExistsLoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/ExpressionParser.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Core.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Debug.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Escaper.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/GlobalsInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/InitRuntimeInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Optimizer.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Profiler.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/Staging.php delete mode 100644 system/templateEngines/Twig/Twig1x/Extension/StringLoader.php delete mode 100644 system/templateEngines/Twig/Twig1x/ExtensionInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/FactoryRuntimeLoader.php delete mode 100644 system/templateEngines/Twig/Twig1x/FileExtensionEscapingStrategy.php delete mode 100644 system/templateEngines/Twig/Twig1x/Filter.php delete mode 100644 system/templateEngines/Twig/Twig1x/Filter/Function.php delete mode 100644 system/templateEngines/Twig/Twig1x/Filter/Method.php delete mode 100644 system/templateEngines/Twig/Twig1x/Filter/Node.php delete mode 100644 system/templateEngines/Twig/Twig1x/FilterCallableInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/FilterInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Function.php delete mode 100644 system/templateEngines/Twig/Twig1x/Function/Function.php delete mode 100644 system/templateEngines/Twig/Twig1x/Function/Method.php delete mode 100644 system/templateEngines/Twig/Twig1x/Function/Node.php delete mode 100644 system/templateEngines/Twig/Twig1x/FunctionCallableInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/FunctionInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Lexer.php delete mode 100644 system/templateEngines/Twig/Twig1x/LexerInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Loader/Array.php delete mode 100644 system/templateEngines/Twig/Twig1x/Loader/Chain.php delete mode 100644 system/templateEngines/Twig/Twig1x/Loader/Filesystem.php delete mode 100644 system/templateEngines/Twig/Twig1x/Loader/String.php delete mode 100644 system/templateEngines/Twig/Twig1x/LoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Markup.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/AutoEscape.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Block.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/BlockReference.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Body.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/CheckSecurity.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Deprecated.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Do.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Embed.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Array.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/AssignName.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Add.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/And.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseAnd.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseOr.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseXor.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Concat.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Div.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/EndsWith.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Equal.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/FloorDiv.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Greater.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/GreaterEqual.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/In.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Less.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/LessEqual.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Matches.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mod.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mul.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotEqual.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotIn.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Or.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Power.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Range.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/StartsWith.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Sub.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/BlockReference.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Call.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Conditional.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Constant.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/ExtensionReference.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Filter.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Filter/Default.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Function.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/GetAttr.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/MethodCall.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Name.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/NullCoalesce.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Parent.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/TempName.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Constant.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Defined.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Divisibleby.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Even.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Null.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Odd.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Test/Sameas.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Unary.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Neg.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Not.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Pos.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Flush.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/For.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/ForLoop.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/If.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Import.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Include.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Macro.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Module.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Print.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/SandboxedPrint.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Set.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/SetTemp.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Spaceless.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/Text.php delete mode 100644 system/templateEngines/Twig/Twig1x/Node/With.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeCaptureInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeOutputInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeTraverser.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeVisitor/Escaper.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeVisitor/Optimizer.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeVisitor/SafeAnalysis.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeVisitor/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig1x/NodeVisitorInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Parser.php delete mode 100644 system/templateEngines/Twig/Twig1x/ParserInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Dumper/Base.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Dumper/Blackfire.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Dumper/Html.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Dumper/Text.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Node/EnterProfile.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Node/LeaveProfile.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/NodeVisitor/Profiler.php delete mode 100644 system/templateEngines/Twig/Twig1x/Profiler/Profile.php delete mode 100644 system/templateEngines/Twig/Twig1x/RuntimeLoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityError.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFilterError.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFunctionError.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedMethodError.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedPropertyError.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedTagError.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicy.php delete mode 100644 system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicyInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/SimpleFilter.php delete mode 100644 system/templateEngines/Twig/Twig1x/SimpleFunction.php delete mode 100644 system/templateEngines/Twig/Twig1x/SimpleTest.php delete mode 100644 system/templateEngines/Twig/Twig1x/Source.php delete mode 100644 system/templateEngines/Twig/Twig1x/SourceContextLoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/Template.php delete mode 100644 system/templateEngines/Twig/Twig1x/TemplateInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/TemplateWrapper.php delete mode 100644 system/templateEngines/Twig/Twig1x/Test.php delete mode 100644 system/templateEngines/Twig/Twig1x/Test/Function.php delete mode 100644 system/templateEngines/Twig/Twig1x/Test/IntegrationTestCase.php delete mode 100644 system/templateEngines/Twig/Twig1x/Test/Method.php delete mode 100644 system/templateEngines/Twig/Twig1x/Test/NodeTestCase.php delete mode 100644 system/templateEngines/Twig/Twig1x/Token.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/AutoEscape.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Block.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Deprecated.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Do.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Embed.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Extends.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Filter.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Flush.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/For.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/From.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/If.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Import.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Include.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Macro.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Set.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Spaceless.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/Use.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParser/With.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParserBroker.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParserBrokerInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenParserInterface.php delete mode 100644 system/templateEngines/Twig/Twig1x/TokenStream.php delete mode 100644 system/templateEngines/Twig/Twig1x/Util/DeprecationCollector.php delete mode 100644 system/templateEngines/Twig/Twig1x/Util/TemplateDirIterator.php create mode 100644 system/templateEngines/Twig/Twig1x/autoload.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/ClassLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/LICENSE create mode 100644 system/templateEngines/Twig/Twig1x/composer/autoload_classmap.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/autoload_files.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/autoload_namespaces.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/autoload_psr4.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/autoload_real.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/autoload_static.php create mode 100644 system/templateEngines/Twig/Twig1x/composer/installed.json create mode 100644 system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/Ctype.php create mode 100644 system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/LICENSE create mode 100644 system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/README.md create mode 100644 system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/bootstrap.php create mode 100644 system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/composer.json create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/.editorconfig create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/.gitattributes create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/.gitignore create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/.php_cs.dist create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/.travis.yml create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/LICENSE create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/README.rst create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Autoloader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/BaseNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Cache/Filesystem.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Cache/Null.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/CacheInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Compiler.php rename system/templateEngines/Twig/Twig1x/{ => twig/twig/lib/Twig}/CompilerInterface.php (100%) create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/ContainerRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Environment.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Error.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Error/Loader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Error/Runtime.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Error/Syntax.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/ExistsLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/ExpressionParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Core.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Debug.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Escaper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/GlobalsInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/InitRuntimeInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Optimizer.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Profiler.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/Staging.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Extension/StringLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/ExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FactoryRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Function.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Method.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Node.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterCallableInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Function.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Method.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Node.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionCallableInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Lexer.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/LexerInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/Array.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/Chain.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/Filesystem.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/String.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/LoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Markup.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/AutoEscape.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Block.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/BlockReference.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Body.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/CheckSecurity.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Deprecated.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Do.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Embed.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Array.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/AssignName.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Add.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/And.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Concat.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Div.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Equal.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Greater.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/In.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Less.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/LessEqual.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Matches.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Mod.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Mul.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/NotEqual.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Or.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Power.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Range.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Binary/Sub.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/BlockReference.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Call.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Conditional.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Constant.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Filter.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Filter/Default.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Function.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/GetAttr.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/MethodCall.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Name.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/NullCoalesce.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Parent.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/TempName.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Constant.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Defined.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Even.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Null.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Odd.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Test/Sameas.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Unary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Unary/Neg.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Unary/Not.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Unary/Pos.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Flush.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/For.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/ForLoop.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/If.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Import.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Include.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Macro.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Module.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Print.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/SandboxedPrint.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Set.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/SetTemp.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Spaceless.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Text.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/With.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeCaptureInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeOutputInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeTraverser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeVisitor/Escaper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeVisitor/Optimizer.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeVisitor/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeVisitorInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Parser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/ParserInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Base.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Blackfire.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Html.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Text.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Node/EnterProfile.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Node/LeaveProfile.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Profile.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/RuntimeLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Sandbox/SecurityPolicyInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/SimpleFilter.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/SimpleFunction.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/SimpleTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Source.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/SourceContextLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Template.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TemplateInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TemplateWrapper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Function.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/IntegrationTestCase.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Method.php rename system/templateEngines/Twig/Twig1x/{ => twig/twig/lib/Twig}/Test/Node.php (100%) create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/NodeTestCase.php rename system/templateEngines/Twig/Twig1x/{ => twig/twig/lib/Twig}/TestCallableInterface.php (100%) rename system/templateEngines/Twig/Twig1x/{ => twig/twig/lib/Twig}/TestInterface.php (100%) create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Token.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/AutoEscape.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Block.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Deprecated.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Do.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Embed.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Extends.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Filter.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Flush.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/For.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/From.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/If.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Import.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Include.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Macro.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Set.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Spaceless.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/Use.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParser/With.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserBroker.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserBrokerInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenStream.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Util/DeprecationCollector.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Util/TemplateDirIterator.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/CacheInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/FilesystemCache.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/NullCache.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Compiler.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Environment.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Error/Error.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Error/LoaderError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Error/RuntimeError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Error/SyntaxError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/ExpressionParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/AbstractExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/CoreExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/DebugExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/EscaperExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/GlobalsInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/InitRuntimeInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/OptimizerExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ProfilerExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/RuntimeExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/SandboxExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StagingExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StringLoaderExtension.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/FileExtensionEscapingStrategy.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Lexer.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ArrayLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ChainLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ExistsLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/FilesystemLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/LoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/SourceContextLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Markup.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/AutoEscapeNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockReferenceNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BodyNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckSecurityNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckToStringNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DeprecatedNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DoNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/EmbedNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AbstractExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrayExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AssignNameExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AddBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AndBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/DivBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EqualBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/InBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ModBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MulBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotInBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/OrBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/PowerBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/RangeBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/SubBinary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/BlockReferenceExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/CallExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConditionalExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConstantExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FilterExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FunctionExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/GetAttrExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/InlinePrint.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/MethodCallExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NameExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NullCoalesceExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ParentExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TempNameExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/ConstantTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DefinedTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/EvenTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/NullTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/OddTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/SameasTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TestExpression.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NegUnary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NotUnary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/PosUnary.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/FlushNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForLoopNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IfNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ImportNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IncludeNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/MacroNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ModuleNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Node.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeCaptureInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeOutputInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/PrintNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxedPrintNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetTempNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SpacelessNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/TextNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Node/WithNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeTraverser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Parser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BaseDumper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/HtmlDumper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/TextDumper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/EnterProfileNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/LeaveProfileNode.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Profile.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicy.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicyInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Source.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Template.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TemplateWrapper.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Test/IntegrationTestCase.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Test/NodeTestCase.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Token.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AbstractTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ApplyTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/BlockTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DeprecatedTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DoTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/EmbedTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ExtendsTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FilterTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FlushTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ForTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FromTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IfTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ImportTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IncludeTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/MacroTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SandboxTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SetTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SpacelessTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/TokenParserInterface.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/UseTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/WithTokenParser.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TokenStream.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFilter.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFunction.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/TwigTest.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Util/DeprecationCollector.php create mode 100644 system/templateEngines/Twig/Twig1x/twig/twig/src/Util/TemplateDirIterator.php delete mode 100644 system/templateEngines/Twig/Twig2x/BaseNodeVisitor.php delete mode 100644 system/templateEngines/Twig/Twig2x/Cache/Filesystem.php delete mode 100644 system/templateEngines/Twig/Twig2x/Cache/Null.php delete mode 100644 system/templateEngines/Twig/Twig2x/CacheInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Compiler.php delete mode 100644 system/templateEngines/Twig/Twig2x/ContainerRuntimeLoader.php delete mode 100644 system/templateEngines/Twig/Twig2x/Environment.php delete mode 100644 system/templateEngines/Twig/Twig2x/Error.php delete mode 100644 system/templateEngines/Twig/Twig2x/Error/Loader.php delete mode 100644 system/templateEngines/Twig/Twig2x/Error/Runtime.php delete mode 100644 system/templateEngines/Twig/Twig2x/Error/Syntax.php delete mode 100644 system/templateEngines/Twig/Twig2x/ExistsLoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/ExpressionParser.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Core.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Debug.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Escaper.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/GlobalsInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/InitRuntimeInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Optimizer.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Profiler.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/Staging.php delete mode 100644 system/templateEngines/Twig/Twig2x/Extension/StringLoader.php delete mode 100644 system/templateEngines/Twig/Twig2x/ExtensionInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/ExtensionSet.php delete mode 100644 system/templateEngines/Twig/Twig2x/FactoryRuntimeLoader.php delete mode 100644 system/templateEngines/Twig/Twig2x/FileExtensionEscapingStrategy.php delete mode 100644 system/templateEngines/Twig/Twig2x/Filter.php delete mode 100644 system/templateEngines/Twig/Twig2x/Function.php delete mode 100644 system/templateEngines/Twig/Twig2x/Lexer.php delete mode 100644 system/templateEngines/Twig/Twig2x/Loader/Array.php delete mode 100644 system/templateEngines/Twig/Twig2x/Loader/Chain.php delete mode 100644 system/templateEngines/Twig/Twig2x/Loader/Filesystem.php delete mode 100644 system/templateEngines/Twig/Twig2x/LoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Markup.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/AutoEscape.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Block.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/BlockReference.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Body.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/CheckSecurity.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Deprecated.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Do.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Embed.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Array.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/AssignName.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Add.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/And.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseAnd.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseOr.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseXor.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Concat.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Div.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/EndsWith.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Equal.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/FloorDiv.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Greater.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/GreaterEqual.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/In.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Less.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/LessEqual.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Matches.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mod.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mul.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotEqual.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotIn.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Or.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Power.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Range.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/StartsWith.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Sub.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/BlockReference.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Call.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Conditional.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Constant.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Filter.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Filter/Default.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Function.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/GetAttr.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/MethodCall.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Name.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/NullCoalesce.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Parent.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/TempName.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Constant.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Defined.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Divisibleby.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Even.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Null.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Odd.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Test/Sameas.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Unary.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Neg.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Not.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Pos.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Flush.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/For.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/ForLoop.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/If.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Import.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Include.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Macro.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Module.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Print.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/SandboxedPrint.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Set.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Spaceless.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/Text.php delete mode 100644 system/templateEngines/Twig/Twig2x/Node/With.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeCaptureInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeOutputInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeTraverser.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeVisitor/Escaper.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeVisitor/Optimizer.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeVisitor/SafeAnalysis.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeVisitor/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig2x/NodeVisitorInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Parser.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Dumper/Base.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Dumper/Blackfire.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Dumper/Html.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Dumper/Text.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Node/EnterProfile.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Node/LeaveProfile.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/NodeVisitor/Profiler.php delete mode 100644 system/templateEngines/Twig/Twig2x/Profiler/Profile.php delete mode 100644 system/templateEngines/Twig/Twig2x/RuntimeLoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityError.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFilterError.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFunctionError.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedMethodError.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedPropertyError.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedTagError.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicy.php delete mode 100644 system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicyInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/SimpleFilter.php delete mode 100644 system/templateEngines/Twig/Twig2x/SimpleFunction.php delete mode 100644 system/templateEngines/Twig/Twig2x/SimpleTest.php delete mode 100644 system/templateEngines/Twig/Twig2x/Source.php delete mode 100644 system/templateEngines/Twig/Twig2x/SourceContextLoaderInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/Template.php delete mode 100644 system/templateEngines/Twig/Twig2x/TemplateWrapper.php delete mode 100644 system/templateEngines/Twig/Twig2x/Test.php delete mode 100644 system/templateEngines/Twig/Twig2x/Test/IntegrationTestCase.php delete mode 100644 system/templateEngines/Twig/Twig2x/Test/NodeTestCase.php delete mode 100644 system/templateEngines/Twig/Twig2x/Token.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/AutoEscape.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Block.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Deprecated.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Do.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Embed.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Extends.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Filter.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Flush.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/For.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/From.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/If.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Import.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Include.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Macro.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Sandbox.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Set.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Spaceless.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/Use.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParser/With.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenParserInterface.php delete mode 100644 system/templateEngines/Twig/Twig2x/TokenStream.php delete mode 100644 system/templateEngines/Twig/Twig2x/Util/DeprecationCollector.php delete mode 100644 system/templateEngines/Twig/Twig2x/Util/TemplateDirIterator.php create mode 100644 system/templateEngines/Twig/Twig2x/autoload.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/ClassLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/LICENSE create mode 100644 system/templateEngines/Twig/Twig2x/composer/autoload_classmap.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/autoload_files.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/autoload_namespaces.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/autoload_psr4.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/autoload_real.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/autoload_static.php create mode 100644 system/templateEngines/Twig/Twig2x/composer/installed.json create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/Ctype.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/LICENSE create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/README.md create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/bootstrap.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/composer.json create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/LICENSE create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Mbstring.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/README.md create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/upperCase.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/bootstrap.php create mode 100644 system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/composer.json create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/LICENSE create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/README.rst create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/BaseNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Cache/Filesystem.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Cache/Null.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/CacheInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Compiler.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/ContainerRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Environment.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Error.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Error/Loader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Error/Runtime.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Error/Syntax.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/ExistsLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/ExpressionParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Core.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Debug.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Escaper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/GlobalsInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/InitRuntimeInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Optimizer.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Profiler.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/Staging.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Extension/StringLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/ExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/ExtensionSet.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/FactoryRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Filter.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Function.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Lexer.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Loader/Array.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Loader/Chain.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Loader/Filesystem.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/LoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Markup.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/AutoEscape.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Block.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/BlockReference.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Body.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/CheckSecurity.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Deprecated.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Do.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Embed.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Array.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/AssignName.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Add.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/And.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Concat.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Div.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Equal.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Greater.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/In.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Less.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/LessEqual.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Matches.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Mod.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Mul.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/NotEqual.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Or.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Power.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Range.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Binary/Sub.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/BlockReference.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Call.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Conditional.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Constant.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Filter.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Filter/Default.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Function.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/GetAttr.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/MethodCall.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Name.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/NullCoalesce.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Parent.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/TempName.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Constant.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Defined.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Even.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Null.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Odd.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Test/Sameas.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Unary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Unary/Neg.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Unary/Not.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Expression/Unary/Pos.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Flush.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/For.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/ForLoop.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/If.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Import.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Include.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Macro.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Module.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Print.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/SandboxedPrint.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Set.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Spaceless.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/Text.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Node/With.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeCaptureInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeOutputInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeTraverser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeVisitor/Escaper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeVisitor/Optimizer.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeVisitor/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/NodeVisitorInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Parser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Dumper/Base.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Dumper/Blackfire.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Dumper/Html.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Dumper/Text.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Node/EnterProfile.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Node/LeaveProfile.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Profiler/Profile.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/RuntimeLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Sandbox/SecurityPolicyInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/SimpleFilter.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/SimpleFunction.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/SimpleTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Source.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/SourceContextLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Template.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TemplateWrapper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Test.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Test/IntegrationTestCase.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Test/NodeTestCase.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Token.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/AutoEscape.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Block.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Deprecated.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Do.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Embed.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Extends.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Filter.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Flush.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/For.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/From.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/If.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Import.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Include.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Macro.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Sandbox.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Set.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Spaceless.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/Use.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParser/With.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenParserInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/TokenStream.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Util/DeprecationCollector.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/Util/TemplateDirIterator.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/CacheInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/FilesystemCache.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/NullCache.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Compiler.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Environment.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Error/Error.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Error/LoaderError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Error/RuntimeError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Error/SyntaxError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/ExpressionParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/AbstractExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/CoreExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/DebugExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/EscaperExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/GlobalsInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/InitRuntimeInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/OptimizerExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ProfilerExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/RuntimeExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/SandboxExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StagingExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StringLoaderExtension.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/ExtensionSet.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/FileExtensionEscapingStrategy.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Lexer.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ArrayLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ChainLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ExistsLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/FilesystemLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/LoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/SourceContextLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Markup.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/AutoEscapeNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockReferenceNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BodyNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckSecurityNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckToStringNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DeprecatedNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DoNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/EmbedNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AbstractExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrayExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AssignNameExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AddBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AndBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/DivBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EqualBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/InBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ModBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MulBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotInBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/OrBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/PowerBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/RangeBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SubBinary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/BlockReferenceExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/CallExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConditionalExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConstantExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FilterExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FunctionExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/GetAttrExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/InlinePrint.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/MethodCallExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NameExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NullCoalesceExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ParentExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TempNameExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/ConstantTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DefinedTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/EvenTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/NullTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/OddTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/SameasTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TestExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NegUnary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NotUnary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/PosUnary.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/VariadicExpression.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/FlushNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForLoopNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IfNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ImportNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IncludeNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/MacroNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ModuleNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Node.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeCaptureInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeOutputInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/PrintNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxedPrintNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SetNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SpacelessNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/TextNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Node/WithNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeTraverser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Parser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BaseDumper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/HtmlDumper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/TextDumper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/EnterProfileNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/LeaveProfileNode.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Profile.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicy.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicyInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Source.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Template.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TemplateWrapper.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Test/IntegrationTestCase.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Test/NodeTestCase.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Token.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AbstractTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ApplyTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/BlockTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DeprecatedTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DoTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/EmbedTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ExtendsTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FilterTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FlushTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ForTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FromTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IfTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ImportTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IncludeTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/MacroTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SandboxTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SetTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SpacelessTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/TokenParserInterface.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/UseTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/WithTokenParser.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TokenStream.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFilter.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFunction.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/TwigTest.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Util/DeprecationCollector.php create mode 100644 system/templateEngines/Twig/Twig2x/twig/twig/src/Util/TemplateDirIterator.php create mode 100644 system/templateEngines/Twig/Twig3x/autoload.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/ClassLoader.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/LICENSE create mode 100644 system/templateEngines/Twig/Twig3x/composer/autoload_classmap.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/autoload_files.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/autoload_namespaces.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/autoload_psr4.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/autoload_real.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/autoload_static.php create mode 100644 system/templateEngines/Twig/Twig3x/composer/installed.json create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/Ctype.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/LICENSE create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/README.md create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/bootstrap.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/composer.json create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/LICENSE create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Mbstring.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/README.md create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/upperCase.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/bootstrap.php create mode 100644 system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/composer.json create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/.editorconfig create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/.gitattributes create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/.gitignore create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/.php_cs.dist create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/.travis.yml create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/LICENSE create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/README.rst create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/CacheInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/FilesystemCache.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/NullCache.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Compiler.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Environment.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Error/Error.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Error/LoaderError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Error/RuntimeError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Error/SyntaxError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/ExpressionParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/AbstractExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/CoreExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/DebugExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/EscaperExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/GlobalsInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/OptimizerExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ProfilerExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/RuntimeExtensionInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/SandboxExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StagingExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StringLoaderExtension.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/ExtensionSet.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/FileExtensionEscapingStrategy.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Lexer.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ArrayLoader.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ChainLoader.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/FilesystemLoader.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/LoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Markup.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/AutoEscapeNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockReferenceNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BodyNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckSecurityNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckToStringNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DeprecatedNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DoNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/EmbedNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AbstractExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrayExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AssignNameExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AddBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AndBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/DivBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EqualBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/InBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ModBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MulBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotInBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/OrBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/PowerBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/RangeBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SubBinary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/BlockReferenceExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/CallExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConditionalExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConstantExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FilterExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FunctionExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/GetAttrExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/InlinePrint.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/MethodCallExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NameExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NullCoalesceExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ParentExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TempNameExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/ConstantTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DefinedTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/EvenTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/NullTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/OddTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/SameasTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TestExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NegUnary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NotUnary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/PosUnary.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/VariadicExpression.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/FlushNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForLoopNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IfNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ImportNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IncludeNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/MacroNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ModuleNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Node.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeCaptureInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeOutputInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/PrintNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SandboxNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SetNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/TextNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Node/WithNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeTraverser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Parser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BaseDumper.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/HtmlDumper.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/TextDumper.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/EnterProfileNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/LeaveProfileNode.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Profile.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicy.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicyInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Source.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Template.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TemplateWrapper.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Test/IntegrationTestCase.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Test/NodeTestCase.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Token.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AbstractTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ApplyTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/BlockTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DeprecatedTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DoTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/EmbedTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ExtendsTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FlushTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ForTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FromTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IfTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ImportTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IncludeTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/MacroTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SandboxTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SetTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/TokenParserInterface.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/UseTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/WithTokenParser.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TokenStream.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFilter.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFunction.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/TwigTest.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Util/DeprecationCollector.php create mode 100644 system/templateEngines/Twig/Twig3x/twig/twig/src/Util/TemplateDirIterator.php diff --git a/README.md b/README.md index 3513a44..ea511c7 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ All routes are a mapping class with extends the primary Controller class. In a s | DEFAULT_ROUTE | string | Define the default route to assume with initial page. Default is *common/home*. | | CUSTOM_DB_CONFIG | string | Custom SQL to load application configs in database. | | NOT_FOUND | string | Custom route to not found page. Default is error/not_found. | +| SESSION_PREFIX | string | Custom session cookie name prefix. Default is SESS. | ## Outputs and renders @@ -209,15 +210,15 @@ For functions inside the controller that are different from index, for automatic - TPL (basic template with PHP and HTML); - [Twig](https://twig.symfony.com); - [Mustache](https://mustache.github.io); - - [Dwoo](http://dwoo.org); - - [Smarty](https://www.smarty.net). + - [Smarty](https://www.smarty.net); + - [Dwoo](http://dwoo.org) (Deprecated, will be removed soon in further versions). To use a determined template engine, just create a file with name of engine in extension, for sample, if you like to use a Twig, the template file is **demo.twig**, if desire the Mustache template, use **demo.mustache** extension file. The ExacTI Phacil Framework allows to use various template engines in the same project. ## Easy made functions - This framework is very focused in agile, security and reusable code in PHP. Contains a very utile functions we see in the next section. + This framework is very focused in agile, security and reusable code in PHP. Contains a very utils functions we see in the next section. ### Database @@ -271,6 +272,7 @@ To get these rows: | postgre | PostgreSQL | Driver for connect to PostgreSQL databases. | | sqlsrv | MS SQL Server | Connect a Microsoft SQL Server database with sqlsrv PHP extension. | | sqlsrvpdo | MS SQL Server | Connect to Microsoft SQL Server using PDO driver. | +| sqlite3_db | SQLite 3 | Use the SQLite 3 database | ### Cache @@ -388,7 +390,7 @@ This load is simple and registry to object of origin. public function otherData() { $this->load->database('mpdo', 'localhost', 'root', 'imtheking', 'nameDatabase'); - $sql = $this->nameDatabase->query("SELECT * FROM mundo"); + $sql = $this->db->nameDatabase->query("SELECT * FROM mundo"); return $sql->rows; } @@ -441,11 +443,14 @@ To create a model, put in the models folder a directory and file with the code. To use a magic request system, you just need to call a `$this->request` method. For sample, to obtain a POST value, use `$this->request->post['field']` to get the post value with security. For a $_SERVER predefined variables, use `$this->request->server['VALUE']` and `$this->request->get[key]` for $_GET values. + For REST services you can use `$this->request->method` to check if is a POST, GET, PUT, DELETE or other HTTP method. You can use the auxiliary functions to determinate the HTTP method, like `$this->request->isPUT()` to return *true* or *false* for PUT method. Also others methods have your functions, like `$this->request->isPOST()`, `$this->request->isGET()`, `$this->request->isHEAD()`, `$this->request->isCONNECT()`, `$this->request->isOPTIONS()`, `$this->request->isTRACE()`, `$this->request->isPATCH()` or `$this->request->isDELETE()`. All are equivalent to "is" function in request, like this sample: `$this->request->is('PUT')` return true or false for PUT HTTP method. The advantages to use this requests instead the predefined variables of PHP are more the more security, upgradable and unicode values. ### Sessions Sessions is a little different method, you can define and use with `$this->session->data['name']`. + All sessions called with Phacil are secure for HTTPS and IP verify, in other words, we made the session cookie stolen more difficulty, to have less chance of session hijacking. + You can define the session prefix name with constant `SESSION_PREFIX` in your config file. For default, the prefix is "SESS". ## Special controller parameters diff --git a/system/caches/caches.php b/system/caches/caches.php index f20bdfc..10df317 100644 --- a/system/caches/caches.php +++ b/system/caches/caches.php @@ -2,9 +2,11 @@ final class Caches { private $expire = 3600; - public $dirCache = DIR_CACHE."caches/"; + public $dirCache = "caches/"; public function __construct() { + $this->dirCache = DIR_CACHE."caches/"; + if (!file_exists($this->dirCache)) { mkdir($this->dirCache, 0760, true); } diff --git a/system/captcha/autoload.php b/system/captcha/autoload.php index 8ab0a38..de216bf 100644 --- a/system/captcha/autoload.php +++ b/system/captcha/autoload.php @@ -9,11 +9,13 @@ class Captcha { protected $perturbation = 0.90; protected $noise_level = 1; protected $background = 'black'; - public $fonts = __DIR__."/fonts/*/*.ttf"; + public $fonts = "/fonts/*/*.ttf"; public $pos = 'ABCDEFGHJKLMNOPQRSTUWVXZ0123456789abcdefhijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXZ0123456789'; function __construct($width = NULL, $height = NULL, $numChar = 6, $background = 'black') { + $this->fonts = __DIR__."/fonts/*/*.ttf"; + if(!extension_loaded('gd')){ throw new \Exception("The captcha function requires GD extension on PHP!"); } diff --git a/system/database/database/dbmysqli.php b/system/database/database/dbmysqli.php index 0754769..30cc6e2 100644 --- a/system/database/database/dbmysqli.php +++ b/system/database/database/dbmysqli.php @@ -49,4 +49,3 @@ final class DBMySQLi { $this->connection->close(); } } -?> \ No newline at end of file diff --git a/system/database/database/sqlite3_db.php b/system/database/database/sqlite3_db.php new file mode 100644 index 0000000..a0f3f97 --- /dev/null +++ b/system/database/database/sqlite3_db.php @@ -0,0 +1,61 @@ +connection = new SQLite3($hostname.$database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $password); + + if (!$this->connection) { + throw new \Exception('Error: ' . $this->connection->lastErrorMsg() . '
Error No: ' . $this->connection->lastErrorCode()); + } + } + + public function query($sql){ + //$query = $this->connection->query($sql); + + if ($stm = $this->connection->prepare($sql)) { + + $query = $stm->execute(); + + if (!$query instanceof \SQLite3Result || $query->numColumns() == 0) + return true; + + + $data = []; + while ($row = $query->fetchArray(SQLITE3_ASSOC)) { + $data[] = $row; + } + $result = new \stdClass(); + $result->num_rows = (!empty($data)) ? count($data) : 0; + $result->row = isset($data[0]) ? $data[0] : array(); + $result->rows = $data; + $query->finalize(); + return $result; + + } else { + throw new \Exception('Error: ' . $this->connection->lastErrorMsg() . '
Error No: ' . $this->connection->lastErrorCode() . '
' . $sql); + } + + } + + public function escape($value) { + return $this->connection->escapeString($value); + } + + public function countAffected() { + return $this->connection->changes(); + } + public function getLastId() { + return $this->connection->lastInsertRowID(); + } + + public function isConnected() { + return ($this->connection) ? true : false; + } + + public function __destruct() { + $this->connection->close(); + } +} \ No newline at end of file diff --git a/system/database/library/db.php b/system/database/library/db.php index 680ab19..ed3ada9 100644 --- a/system/database/library/db.php +++ b/system/database/library/db.php @@ -96,5 +96,9 @@ final class DB { return $this->driver->query($sql); } } + + public function createSubBase($nome, $object) { + + $this->$nome = $object; + } } -?> \ No newline at end of file diff --git a/system/engine/VERSION b/system/engine/VERSION index 3c80e4f..3e1ad72 100644 --- a/system/engine/VERSION +++ b/system/engine/VERSION @@ -1 +1 @@ -1.4.3 \ No newline at end of file +1.5.0 \ No newline at end of file diff --git a/system/engine/controller.php b/system/engine/controller.php index a5f8de2..f2469d5 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -10,6 +10,7 @@ abstract class Controller { protected $twig = array(); protected $error = array(); protected $output; + public $templateTypes = ["tpl", "twig", "mustache", "smarty", "dwoo"]; public function __construct($registry) { $this->registry = $registry; @@ -62,8 +63,6 @@ abstract class Controller { if($this->template === NULL) { $pegRout = explode("/", $this->request->get['route']); - $this->templateTypes = array("tpl", "twig", "dwoo", "mustache", "smarty"); - $thema = ($this->config->get("config_template") != NULL) ? $this->config->get("config_template") : "default"; foreach($this->templateTypes as $extensionTemplate) { @@ -110,27 +109,32 @@ abstract class Controller { 'cache' => DIR_CACHE."twig/", 'debug' => (defined('DEBUG')) ? DEBUG : false ); - $loader = new Twig_Loader_Filesystem(DIR_TEMPLATE); - $twig = new Twig_Environment($loader, $config); + $TwigLoaderFilesystem = constant('TwigLoaderFilesystem'); + $Twig_Environment = constant('TwigEnvironment'); + $Twig_SimpleFilter = constant('TwigSimpleFilter'); + $Twig_Extension_Debug = constant('TwigExtensionDebug'); + + $loader = new $TwigLoaderFilesystem (DIR_TEMPLATE); + $twig = new $Twig_Environment($loader, $config); if($config['debug']) { - $twig->addExtension(new Twig_Extension_Debug()); + $twig->addExtension(new $Twig_Extension_Debug()); } $twig->addExtension(new transExtension()); - $twig->addFilter(new Twig_SimpleFilter('translate', function ($str) { + $twig->addFilter(new $Twig_SimpleFilter('translate', function ($str) { // do something different from the built-in date filter return traduzir($str); })); - $twig->addFilter(new Twig_SimpleFilter('config', function ($str) { + $twig->addFilter(new $Twig_SimpleFilter('config', function ($str) { // do something different from the built-in date filter return $this->config->get($str); })); foreach ($this->twig as $key => $item) { - $twig->addFilter(new Twig_SimpleFilter($key, $item)); + $twig->addFilter(new $Twig_SimpleFilter($key, $item)); } $template = $twig->load($this->template); @@ -141,6 +145,8 @@ abstract class Controller { case 'dwoo': require_once(DIR_SYSTEM."templateEngines/Dwoo/autoload.php"); + @trigger_error(sprintf("Dwoo template engine is deprecated since Phacil 1.5.0 and will be removed in further versions. Migration to Smarty (most similarity) or other template engine is recommended."), E_USER_DEPRECATED); + $dwoo = new Dwoo\Core(); // Configure directories diff --git a/system/engine/loader.php b/system/engine/loader.php index e961798..82f1bf1 100644 --- a/system/engine/loader.php +++ b/system/engine/loader.php @@ -60,11 +60,21 @@ final class Loader { public function database($driver, $hostname, $username, $password, $database, $port = NULL, $charset = NULL) { $file = DIR_SYSTEM . 'database/database/' . $driver . '.php'; $class = ($driver); + + $replace = [ + '/' => '_', + '.' => '_' + ]; + + $database_name = str_replace(array_keys($replace), array_values($replace), preg_replace('/[^a-zA-Z0-9]/', '', $database)); + if (file_exists($file)) { - include_once($file); - - $this->registry->set(str_replace('/', '_', $database), new $class($hostname, $username, $password, $database)); + //include_once($file); + + $this->db->createSubBase($database_name, new DB($driver, $hostname, $username, $password, $database)); + + return $database_name; } else { trigger_error('Error: Could not load database ' . $driver . '!'); exit(); diff --git a/system/engine/log.php b/system/engine/log.php index a93e23c..d0a91dc 100644 --- a/system/engine/log.php +++ b/system/engine/log.php @@ -2,7 +2,7 @@ final class Log { private $filename; - public function __construct($filename) { + public function __construct($filename = "error.log") { $this->filename = fopen(DIR_LOGS . $filename, 'a'); } @@ -14,4 +14,3 @@ final class Log { fclose($this->filename); } } -?> \ No newline at end of file diff --git a/system/engine/registry.php b/system/engine/registry.php index 8c3a816..101c77a 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -14,4 +14,3 @@ final class Registry { return isset($this->data[$key]); } } -?> \ No newline at end of file diff --git a/system/request/autoload.php b/system/request/autoload.php index bf2e22a..e5f43df 100644 --- a/system/request/autoload.php +++ b/system/request/autoload.php @@ -1,39 +1,71 @@ clean($_GET); - $_POST = $this->clean($_POST); - $_REQUEST = $this->clean($_REQUEST); - $_COOKIE = $this->clean($_COOKIE); - $_FILES = $this->clean($_FILES); - $_SERVER = $this->clean($_SERVER); - - $this->get = $_GET; - $this->post = $_POST; - $this->request = $_REQUEST; - $this->cookie = $_COOKIE; - $this->files = $_FILES; - $this->server = $_SERVER; - } - - public function clean($data) { - if (is_array($data)) { - foreach ($data as $key => $value) { - unset($data[$key]); - - $data[$this->clean($key)] = $this->clean($value); - } - } else { - $data = htmlspecialchars($data, ENT_COMPAT); - } + public $get = array(); + public $post = array(); + public $cookie = array(); + public $files = array(); + public $server = array(); + public $method; - return $data; - } + public function __construct() { + $_GET = $this->clean($_GET); + $_POST = $this->clean($_POST); + $_REQUEST = $this->clean($_REQUEST); + $_COOKIE = $this->clean($_COOKIE); + $_FILES = $this->clean($_FILES); + $_SERVER = $this->clean($_SERVER); + + $this->get = $_GET; + $this->post = $_POST; + $this->request = $_REQUEST; + $this->cookie = $_COOKIE; + $this->files = $_FILES; + $this->server = $_SERVER; + $this->method = (isset($this->server['REQUEST_METHOD'])) ? $this->clean($this->server['REQUEST_METHOD']) : false; + } + + public function clean($data) { + if (is_array($data)) { + foreach ($data as $key => $value) { + unset($data[$key]); + + $data[$this->clean($key)] = $this->clean($value); + } + } else { + $data = htmlspecialchars($data, ENT_COMPAT); + } + + return $data; + } + + public function isPOST() { + return $this->is('POST'); + } + public function isGET() { + return $this->is('GET'); + } + public function isHEAD() { + return $this->is('HEAD'); + } + public function isPUT() { + return $this->is('PUT'); + } + public function isDELETE() { + return $this->is('DELETE'); + } + public function isCONNECT() { + return $this->is('CONNECT') ; + } + public function isOPTIONS() { + return $this->is('OPTIONS') ; + } + public function isTRACE() { + return $this->is('TRACE'); + } + public function isPATCH() { + return $this->is('PATCH'); + } + public function is($method){ + return ($this->method == $method) ? true : false; + } } -?> \ No newline at end of file diff --git a/system/session/autoload.php b/system/session/autoload.php index 2e3a105..7cde310 100644 --- a/system/session/autoload.php +++ b/system/session/autoload.php @@ -1,17 +1,49 @@ data =& $_SESSION; - } + public $data = array(); + private $name; + + public function __construct() { + $this->name = ((defined('SESSION_PREFIX')) ? SESSION_PREFIX : 'SESS').(isset($_SERVER['REMOTE_ADDR']) ? md5($_SERVER['REMOTE_ADDR']) : md5(date("dmY"))); + + if (!session_id()) { + $this->openSession(); + } + + if(session_name() === $this->name) { + $this->data =& $_SESSION; + }else { + $this->openSession(); + $this->data =& $_SESSION; + } + + } + + private function openSession() { + + $this->closeSession(); + + ini_set('session.use_cookies', 'On'); + ini_set('session.use_trans_sid', 'Off'); + ini_set('session.cookie_httponly', 1); + if($this->isSecure()) + ini_set('session.cookie_secure', 1); + + session_set_cookie_params(0, '/'); + //session_id(md5()); + session_name($this->name); + session_start(); + + } + + private function closeSession() { + if (session_status() == PHP_SESSION_ACTIVE) { + session_unset(); + session_destroy(); + } + } + + private function isSecure() { + return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443; + } } -?> \ No newline at end of file diff --git a/system/system.php b/system/system.php index a8f1b25..c7c5df0 100644 --- a/system/system.php +++ b/system/system.php @@ -7,17 +7,17 @@ */ class startEngineExacTI { - public $constants; - public $userConstants; + /*public $constants; + public $userConstants;*/ public $phpversion; - protected $includes; + //protected $includes; protected $dirs; public $registry; public function __construct () { - $this->constants = get_defined_constants(true); - $this->userConstants = $this->constants['user']; - $this->includes = get_included_files(); + //$this->constants = get_defined_constants(true); + //$this->userConstants = $this->constants['user']; + //$this->includes = get_included_files(); // Check Version $this->phpversion = $this->checkPHPversion(); @@ -78,6 +78,14 @@ class startEngineExacTI { } private function checkConstantsRequired () { + $dbConsts = ['DB_DRIVER' => 'nullStatement', 'DB_HOSTNAME' => NULL, 'DB_USERNAME' => NULL, 'DB_PASSWORD' => NULL, 'DB_DATABASE' => NULL]; + + foreach ($dbConsts as $constDB => $value) { + if (!defined($constDB)) { + define($constDB, $value); + } + } + if (!defined('DIR_APPLICATION') || !defined('DIR_SYSTEM') || !defined('DIR_PUBLIC') || !defined('DIR_TEMPLATE') || !defined('USE_DB_CONFIG')) { return(false); } else { @@ -141,6 +149,24 @@ class startEngineExacTI { include(DIR_SYSTEM."registrations.php"); } + public function constants(){ + return get_defined_constants(true); + } + + public function userConstants() { + return $this->constants()['user']; + } + + public function constantName($constant, $group = 'user') { + + foreach ($this->constants()[$group] as $name => $value){ + if($constant === $value) + return $name; + } + + return $constant; + } + } $engine = new startEngineExacTI(); @@ -157,7 +183,7 @@ $engine->registry->set('load', $loader); $config = new Config(); $engine->registry->set('config', $config); -$engine->registry->set('db', $db); +$engine->registry->set('db', new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE)); // Settings if(!empty($configs)){ @@ -207,8 +233,8 @@ if(!$config->get('config_error_filename')){ $log = new Log($config->get('config_error_filename')); $engine->registry->set('log', $log); -function error_handler($errno, $errstr, $errfile, $errline) { - global $log, $config; +// Error Handler +set_error_handler(function ($errno, $errstr, $errfile, $errline) use ($log, $config, $engine){ switch ($errno) { case E_NOTICE: @@ -223,8 +249,12 @@ function error_handler($errno, $errstr, $errfile, $errline) { case E_USER_ERROR: $error = 'Fatal Error'; break; + case E_DEPRECATED: + case E_USER_DEPRECATED: + $error = 'Deprecated'; + break; default: - $error = 'Unknown'; + $error = $engine->constantName($errno, 'Core'); break; } @@ -233,14 +263,21 @@ function error_handler($errno, $errstr, $errfile, $errline) { } if ($config->get('config_error_log')) { - $log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline); + $log->write( $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline.' | Phacil '.$engine->version(). ' on PHP '.$engine->phpversion); } return true; -} +}); -// Error Handler -set_error_handler('error_handler'); +set_exception_handler(function($e) use ($log, $config) { + if ($config->get('config_error_display')) { + echo '' . get_class($e) . ': ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . ''; + } + + if ($config->get('config_error_log')) { + $log->write(get_class($e) . ': ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()); + } +}); //Caches $caches = new Caches(); diff --git a/system/templateEngines/Mustache/Engine.php b/system/templateEngines/Mustache/Engine.php index 9110977..fe99799 100644 --- a/system/templateEngines/Mustache/Engine.php +++ b/system/templateEngines/Mustache/Engine.php @@ -23,7 +23,7 @@ */ class Mustache_Engine { - const VERSION = '2.12.0'; + const VERSION = '2.13.0'; const SPEC_VERSION = '1.1.2'; const PRAGMA_FILTERS = 'FILTERS'; diff --git a/system/templateEngines/Mustache/Parser.php b/system/templateEngines/Mustache/Parser.php index c36a84a..0ec4192 100644 --- a/system/templateEngines/Mustache/Parser.php +++ b/system/templateEngines/Mustache/Parser.php @@ -149,7 +149,7 @@ class Mustache_Parser case Mustache_Tokenizer::T_BLOCK_VAR: if ($this->pragmaBlocks) { // BLOCKS pragma is enabled, let's do this! - if ($parent[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_PARENT) { + if (isset($parent) && $parent[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_PARENT) { $token[Mustache_Tokenizer::TYPE] = Mustache_Tokenizer::T_BLOCK_ARG; } $this->clearStandaloneLines($nodes, $tokens); @@ -275,7 +275,7 @@ class Mustache_Parser */ private function checkIfTokenIsAllowedInParent($parent, array $token) { - if ($parent[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_PARENT) { + if (isset($parent) && $parent[Mustache_Tokenizer::TYPE] === Mustache_Tokenizer::T_PARENT) { throw new Mustache_Exception_SyntaxException('Illegal content in < parent tag', $token); } } diff --git a/system/templateEngines/Mustache/Tokenizer.php b/system/templateEngines/Mustache/Tokenizer.php index b1f3d73..6dbe0cd 100644 --- a/system/templateEngines/Mustache/Tokenizer.php +++ b/system/templateEngines/Mustache/Tokenizer.php @@ -72,15 +72,20 @@ class Mustache_Tokenizer private $tokens; private $seenTag; private $line; + private $otag; - private $ctag; + private $otagChar; private $otagLen; + + private $ctag; + private $ctagChar; private $ctagLen; /** * Scan and tokenize template source. * * @throws Mustache_Exception_SyntaxException when mismatched section tags are encountered + * @throws Mustache_Exception_InvalidArgumentException when $delimiters string is invalid * * @param string $text Mustache template source to tokenize * @param string $delimiters Optionally, pass initial opening and closing delimiters (default: null) @@ -110,12 +115,13 @@ class Mustache_Tokenizer for ($i = 0; $i < $len; $i++) { switch ($this->state) { case self::IN_TEXT: - if ($this->tagChange($this->otag, $this->otagLen, $text, $i)) { + $char = $text[$i]; + // Test whether it's time to change tags. + if ($char === $this->otagChar && substr($text, $i, $this->otagLen) === $this->otag) { $i--; $this->flushBuffer(); $this->state = self::IN_TAG_TYPE; } else { - $char = $text[$i]; $this->buffer .= $char; if ($char === "\n") { $this->flushBuffer(); @@ -151,7 +157,9 @@ class Mustache_Tokenizer break; default: - if ($this->tagChange($this->ctag, $this->ctagLen, $text, $i)) { + $char = $text[$i]; + // Test whether it's time to change tags. + if ($char === $this->ctagChar && substr($text, $i, $this->ctagLen) === $this->ctag) { $token = array( self::TYPE => $this->tagType, self::NAME => trim($this->buffer), @@ -196,7 +204,7 @@ class Mustache_Tokenizer $this->state = self::IN_TEXT; $this->tokens[] = $token; } else { - $this->buffer .= $text[$i]; + $this->buffer .= $char; } break; } @@ -219,16 +227,20 @@ class Mustache_Tokenizer */ private function reset() { - $this->state = self::IN_TEXT; - $this->tagType = null; - $this->buffer = ''; - $this->tokens = array(); - $this->seenTag = false; - $this->line = 0; - $this->otag = '{{'; - $this->ctag = '}}'; - $this->otagLen = 2; - $this->ctagLen = 2; + $this->state = self::IN_TEXT; + $this->tagType = null; + $this->buffer = ''; + $this->tokens = array(); + $this->seenTag = false; + $this->line = 0; + + $this->otag = '{{'; + $this->otagChar = '{'; + $this->otagLen = 2; + + $this->ctag = '}}'; + $this->ctagChar = '}'; + $this->ctagLen = 2; } /** @@ -249,6 +261,8 @@ class Mustache_Tokenizer /** * Change the current Mustache delimiters. Set new `otag` and `ctag` values. * + * @throws Mustache_Exception_SyntaxException when delimiter string is invalid + * * @param string $text Mustache template source * @param int $index Current tokenizer index * @@ -260,28 +274,44 @@ class Mustache_Tokenizer $close = '=' . $this->ctag; $closeIndex = strpos($text, $close, $index); - $this->setDelimiters(trim(substr($text, $startIndex, $closeIndex - $startIndex))); - - $this->tokens[] = array( + $token = array( self::TYPE => self::T_DELIM_CHANGE, self::LINE => $this->line, ); + try { + $this->setDelimiters(trim(substr($text, $startIndex, $closeIndex - $startIndex))); + } catch (Mustache_Exception_InvalidArgumentException $e) { + throw new Mustache_Exception_SyntaxException($e->getMessage(), $token); + } + + $this->tokens[] = $token; + return $closeIndex + strlen($close) - 1; } /** * Set the current Mustache `otag` and `ctag` delimiters. * + * @throws Mustache_Exception_InvalidArgumentException when delimiter string is invalid + * * @param string $delimiters */ private function setDelimiters($delimiters) { - list($otag, $ctag) = explode(' ', $delimiters); - $this->otag = $otag; - $this->ctag = $ctag; - $this->otagLen = strlen($otag); - $this->ctagLen = strlen($ctag); + if (!preg_match('/^\s*(\S+)\s+(\S+)\s*$/', $delimiters, $matches)) { + throw new Mustache_Exception_InvalidArgumentException(sprintf('Invalid delimiters: %s', $delimiters)); + } + + list($_, $otag, $ctag) = $matches; + + $this->otag = $otag; + $this->otagChar = $otag[0]; + $this->otagLen = strlen($otag); + + $this->ctag = $ctag; + $this->ctagChar = $ctag[0]; + $this->ctagLen = strlen($ctag); } /** @@ -309,19 +339,4 @@ class Mustache_Tokenizer return $end + $this->ctagLen - 1; } - - /** - * Test whether it's time to change tags. - * - * @param string $tag Current tag name - * @param int $tagLen Current tag name length - * @param string $text Mustache template source - * @param int $index Current tokenizer index - * - * @return bool True if this is a closing section tag - */ - private function tagChange($tag, $tagLen, $text, $index) - { - return substr($text, $index, $tagLen) === $tag; - } } diff --git a/system/templateEngines/Twig/Extension/ExacTITranslate.php b/system/templateEngines/Twig/Extension/ExacTITranslate.php index 1c9fdcd..fee2700 100644 --- a/system/templateEngines/Twig/Extension/ExacTITranslate.php +++ b/system/templateEngines/Twig/Extension/ExacTITranslate.php @@ -3,10 +3,12 @@ define('TWIGtagIni', 't'); define('TWIGtagClose', 'endt'); -class transTokenParser extends \Twig_TokenParser + + +class transTokenParser extends \Twig\TokenParser\AbstractTokenParser { - public function parse(\Twig_Token $token) + public function parse(\Twig\Token $token) { $lineno = $token->getLine(); @@ -40,10 +42,10 @@ class transTokenParser extends \Twig_TokenParser // if your endtrans can also contains params, you can uncomment this line: // $params = array_merge($params, $this->getInlineParams($token)); // and comment this one: - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); } - return new transNode(new \Twig_Node($params), $lineno, $this->getTag()); + return new transNode(new \Twig\Node($params), $lineno, $this->getTag()); } /** @@ -52,15 +54,15 @@ class transTokenParser extends \Twig_TokenParser * @param \Twig_Token $token * @return array */ - protected function getInlineParams(\Twig_Token $token) + protected function getInlineParams(\Twig\Token $token) { $stream = $this->parser->getStream(); $params = array (); - while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) + while (!$stream->test(\Twig\Token::BLOCK_END_TYPE)) { $params[] = $this->parser->getExpressionParser()->parseExpression(); } - $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $stream->expect(\Twig\Token::BLOCK_END_TYPE); return $params; } @@ -68,10 +70,10 @@ class transTokenParser extends \Twig_TokenParser * Callback called at each tag name when subparsing, must return * true when the expected end tag is reached. * - * @param \Twig_Token $token + * @param \Twig\Token $token * @return bool */ - public function decidetransFork(\Twig_Token $token) + public function decidetransFork(\Twig\Token $token) { return $token->test(array (TWIGtagClose)); } @@ -90,7 +92,7 @@ class transTokenParser extends \Twig_TokenParser } -class transNode extends \Twig_Node +class transNode extends \Twig\Node\Node { public function __construct($params, $lineno = 0, $tag = null) @@ -98,7 +100,7 @@ class transNode extends \Twig_Node parent::__construct(array ('params' => $params), array (), $lineno, $tag); } - public function compile(\Twig_Compiler $compiler) + public function compile(\Twig\Compiler $compiler) { $count = count($this->getNode('params')); @@ -110,7 +112,7 @@ class transNode extends \Twig_Node // argument is not an expression (such as, a \Twig_Node_Textbody) // we should trick with output buffering to get a valid argument to pass // to the functionToCall() function. - if (!($this->getNode('params')->getNode($i) instanceof \Twig_Node_Expression)) + if (!($this->getNode('params')->getNode($i) instanceof \Twig\Node\Expression\AbstractExpression)) { $compiler ->write('ob_start();') @@ -148,7 +150,7 @@ class transNode extends \Twig_Node -class transExtension extends \Twig_Extension +class transExtension extends \Twig\Extension\AbstractExtension { public function getTokenParsers() diff --git a/system/templateEngines/Twig/Extension/ExacTITranslate1x.php b/system/templateEngines/Twig/Extension/ExacTITranslate1x.php new file mode 100644 index 0000000..54867a3 --- /dev/null +++ b/system/templateEngines/Twig/Extension/ExacTITranslate1x.php @@ -0,0 +1,186 @@ +getLine(); + + $stream = $this->parser->getStream(); + + // recovers all inline parameters close to your tag name + $params = array_merge(array (), $this->getInlineParams($token)); + + $continue = true; + while ($continue) + { + // create subtree until the decidetransFork() callback returns true + $body = $this->parser->subparse(array ($this, 'decidetransFork')); + + // I like to put a switch here, in case you need to add middle tags, such + // as: {% trans %}, {% nexttrans %}, {% endtrans %}. + $tag = $stream->next()->getValue(); + + switch ($tag) + { + case TWIGtagClose: + $continue = false; + break; + default: + throw new \Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags '.TWIGtagClose.' to close the '.TWIGtagIni.' block started at line %d)', $lineno), -1); + } + + // you want $body at the beginning of your arguments + array_unshift($params, $body); + + // if your endtrans can also contains params, you can uncomment this line: + // $params = array_merge($params, $this->getInlineParams($token)); + // and comment this one: + $stream->expect(\Twig_Token::BLOCK_END_TYPE); + } + + return new transNode(new \Twig_Node($params), $lineno, $this->getTag()); + } + + /** + * Recovers all tag parameters until we find a BLOCK_END_TYPE ( %} ) + * + * @param \Twig_Token $token + * @return array + */ + protected function getInlineParams(\Twig_Token $token) + { + $stream = $this->parser->getStream(); + $params = array (); + while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) + { + $params[] = $this->parser->getExpressionParser()->parseExpression(); + } + $stream->expect(\Twig_Token::BLOCK_END_TYPE); + return $params; + } + + /** + * Callback called at each tag name when subparsing, must return + * true when the expected end tag is reached. + * + * @param \Twig_Token $token + * @return bool + */ + public function decidetransFork(\Twig_Token $token) + { + return $token->test(array (TWIGtagClose)); + } + + /** + * Your tag name: if the parsed tag match the one you put here, your parse() + * method will be called. + * + * @return string + */ + public function getTag() + { + return TWIGtagIni; + } + +} + + +class transNode extends \Twig_Node +{ + + public function __construct($params, $lineno = 0, $tag = null) + { + parent::__construct(array ('params' => $params), array (), $lineno, $tag); + } + + public function compile(\Twig_Compiler $compiler) + { + $count = count($this->getNode('params')); + + $compiler + ->addDebugInfo($this); + + for ($i = 0; ($i < $count); $i++) + { + // argument is not an expression (such as, a \Twig_Node_Textbody) + // we should trick with output buffering to get a valid argument to pass + // to the functionToCall() function. + if (!($this->getNode('params')->getNode($i) instanceof \Twig_Node_Expression)) + { + $compiler + ->write('ob_start();') + ->raw(PHP_EOL); + + $compiler + ->subcompile($this->getNode('params')->getNode($i)); + + $compiler + ->write('$_trans[] = ob_get_clean();') + ->raw(PHP_EOL); + } + else + { + $compiler + ->write('$_trans[] = ') + ->subcompile($this->getNode('params')->getNode($i)) + ->raw(';') + ->raw(PHP_EOL); + } + } + + $compiler + ->write('call_user_func_array(') + ->string('traduzir') + ->raw(', $_trans);') + ->raw(PHP_EOL); + + $compiler + ->write('unset($_trans);') + ->raw(PHP_EOL); + } + +} + + + +class transExtension extends \Twig_Extension +{ + + public function getTokenParsers() + { + return array ( + new transTokenParser(), + ); + } + + public function getName() + { + return TWIGtagIni; + } + +} + + +function traduzir() { + $params = func_get_args(); + $body = array_shift($params); + + if (class_exists('Translate')) { + $trans = new Translate(); + echo ($trans->translation($body)); + } else { + echo $body; + } + +} \ No newline at end of file diff --git a/system/templateEngines/Twig/Twig1x/Autoloader.php b/system/templateEngines/Twig/Twig1x/Autoloader.php deleted file mode 100644 index 6a2bf4a..0000000 --- a/system/templateEngines/Twig/Twig1x/Autoloader.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * @deprecated since 1.21 and will be removed in 2.0. Use Composer instead. 2.0. - */ -class Twig_Autoloader -{ - /** - * Registers Twig_Autoloader as an SPL autoloader. - * - * @param bool $prepend whether to prepend the autoloader or not - */ - public static function register($prepend = false) - { - @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED); - - spl_autoload_register([__CLASS__, 'autoload'], true, $prepend); - } - - /** - * Handles autoloading of classes. - * - * @param string $class a class name - */ - public static function autoload($class) - { - if (0 !== strpos($class, 'Twig')) { - return; - } - - if (is_file($file = dirname(__FILE__).'/../'.str_replace(['_', "\0"], ['/', ''], $class).'.php')) { - require $file; - } - } -} diff --git a/system/templateEngines/Twig/Twig1x/BaseNodeVisitor.php b/system/templateEngines/Twig/Twig1x/BaseNodeVisitor.php deleted file mode 100644 index d8ef02f..0000000 --- a/system/templateEngines/Twig/Twig1x/BaseNodeVisitor.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ -abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface -{ - final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) - { - if (!$node instanceof Twig_Node) { - throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.'); - } - - return $this->doEnterNode($node, $env); - } - - final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) - { - if (!$node instanceof Twig_Node) { - throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.'); - } - - return $this->doLeaveNode($node, $env); - } - - /** - * Called before child nodes are visited. - * - * @return Twig_Node The modified node - */ - abstract protected function doEnterNode(Twig_Node $node, Twig_Environment $env); - - /** - * Called after child nodes are visited. - * - * @return Twig_Node|false The modified node or false if the node must be removed - */ - abstract protected function doLeaveNode(Twig_Node $node, Twig_Environment $env); -} - -class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false); -class_exists('Twig_Environment'); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig1x/Cache/Filesystem.php b/system/templateEngines/Twig/Twig1x/Cache/Filesystem.php deleted file mode 100644 index 5b0acc0..0000000 --- a/system/templateEngines/Twig/Twig1x/Cache/Filesystem.php +++ /dev/null @@ -1,91 +0,0 @@ - - */ -class Twig_Cache_Filesystem implements Twig_CacheInterface -{ - const FORCE_BYTECODE_INVALIDATION = 1; - - private $directory; - private $options; - - /** - * @param $directory string The root cache directory - * @param $options int A set of options - */ - public function __construct($directory, $options = 0) - { - $this->directory = rtrim($directory, '\/').'/'; - $this->options = $options; - } - - public function generateKey($name, $className) - { - $hash = hash('sha256', $className); - - return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; - } - - public function load($key) - { - if (file_exists($key)) { - @include_once $key; - } - } - - public function write($key, $content) - { - $dir = dirname($key); - if (!is_dir($dir)) { - if (false === @mkdir($dir, 0777, true)) { - clearstatcache(true, $dir); - if (!is_dir($dir)) { - throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); - } - } - } elseif (!is_writable($dir)) { - throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); - } - - $tmpFile = tempnam($dir, basename($key)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { - @chmod($key, 0666 & ~umask()); - - if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { - // Compile cached file into bytecode cache - if (function_exists('opcache_invalidate')) { - opcache_invalidate($key, true); - } elseif (function_exists('apc_compile_file')) { - apc_compile_file($key); - } - } - - return; - } - - throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key)); - } - - public function getTimestamp($key) - { - if (!file_exists($key)) { - return 0; - } - - return (int) @filemtime($key); - } -} - -class_alias('Twig_Cache_Filesystem', 'Twig\Cache\FilesystemCache', false); diff --git a/system/templateEngines/Twig/Twig1x/Cache/Null.php b/system/templateEngines/Twig/Twig1x/Cache/Null.php deleted file mode 100644 index 69d1d2f..0000000 --- a/system/templateEngines/Twig/Twig1x/Cache/Null.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -class Twig_Cache_Null implements Twig_CacheInterface -{ - public function generateKey($name, $className) - { - return ''; - } - - public function write($key, $content) - { - } - - public function load($key) - { - } - - public function getTimestamp($key) - { - return 0; - } -} - -class_alias('Twig_Cache_Null', 'Twig\Cache\NullCache', false); diff --git a/system/templateEngines/Twig/Twig1x/CacheInterface.php b/system/templateEngines/Twig/Twig1x/CacheInterface.php deleted file mode 100644 index 776808b..0000000 --- a/system/templateEngines/Twig/Twig1x/CacheInterface.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -interface Twig_CacheInterface -{ - /** - * Generates a cache key for the given template class name. - * - * @param string $name The template name - * @param string $className The template class name - * - * @return string - */ - public function generateKey($name, $className); - - /** - * Writes the compiled template to cache. - * - * @param string $key The cache key - * @param string $content The template representation as a PHP class - */ - public function write($key, $content); - - /** - * Loads a template from the cache. - * - * @param string $key The cache key - */ - public function load($key); - - /** - * Returns the modification timestamp of a key. - * - * @param string $key The cache key - * - * @return int - */ - public function getTimestamp($key); -} - -class_alias('Twig_CacheInterface', 'Twig\Cache\CacheInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/Compiler.php b/system/templateEngines/Twig/Twig1x/Compiler.php deleted file mode 100644 index a5a6030..0000000 --- a/system/templateEngines/Twig/Twig1x/Compiler.php +++ /dev/null @@ -1,286 +0,0 @@ - - */ -class Twig_Compiler implements Twig_CompilerInterface -{ - protected $lastLine; - protected $source; - protected $indentation; - protected $env; - protected $debugInfo = []; - protected $sourceOffset; - protected $sourceLine; - protected $filename; - private $varNameSalt = 0; - - public function __construct(Twig_Environment $env) - { - $this->env = $env; - } - - /** - * @deprecated since 1.25 (to be removed in 2.0) - */ - public function getFilename() - { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); - - return $this->filename; - } - - /** - * Returns the environment instance related to this compiler. - * - * @return Twig_Environment - */ - public function getEnvironment() - { - return $this->env; - } - - /** - * Gets the current PHP code after compilation. - * - * @return string The PHP code - */ - public function getSource() - { - return $this->source; - } - - /** - * Compiles a node. - * - * @param Twig_NodeInterface $node The node to compile - * @param int $indentation The current indentation - * - * @return $this - */ - public function compile(Twig_NodeInterface $node, $indentation = 0) - { - $this->lastLine = null; - $this->source = ''; - $this->debugInfo = []; - $this->sourceOffset = 0; - // source code starts at 1 (as we then increment it when we encounter new lines) - $this->sourceLine = 1; - $this->indentation = $indentation; - $this->varNameSalt = 0; - - if ($node instanceof Twig_Node_Module) { - // to be removed in 2.0 - $this->filename = $node->getTemplateName(); - } - - $node->compile($this); - - return $this; - } - - public function subcompile(Twig_NodeInterface $node, $raw = true) - { - if (false === $raw) { - $this->source .= str_repeat(' ', $this->indentation * 4); - } - - $node->compile($this); - - return $this; - } - - /** - * Adds a raw string to the compiled code. - * - * @param string $string The string - * - * @return $this - */ - public function raw($string) - { - $this->source .= $string; - - return $this; - } - - /** - * Writes a string to the compiled code by adding indentation. - * - * @return $this - */ - public function write() - { - $strings = func_get_args(); - foreach ($strings as $string) { - $this->source .= str_repeat(' ', $this->indentation * 4).$string; - } - - return $this; - } - - /** - * Appends an indentation to the current PHP code after compilation. - * - * @return $this - * - * @deprecated since 1.27 (to be removed in 2.0). - */ - public function addIndentation() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED); - - $this->source .= str_repeat(' ', $this->indentation * 4); - - return $this; - } - - /** - * Adds a quoted string to the compiled code. - * - * @param string $value The string - * - * @return $this - */ - public function string($value) - { - $this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\")); - - return $this; - } - - /** - * Returns a PHP representation of a given value. - * - * @param mixed $value The value to convert - * - * @return $this - */ - public function repr($value) - { - if (is_int($value) || is_float($value)) { - if (false !== $locale = setlocale(LC_NUMERIC, '0')) { - setlocale(LC_NUMERIC, 'C'); - } - - $this->raw(var_export($value, true)); - - if (false !== $locale) { - setlocale(LC_NUMERIC, $locale); - } - } elseif (null === $value) { - $this->raw('null'); - } elseif (is_bool($value)) { - $this->raw($value ? 'true' : 'false'); - } elseif (is_array($value)) { - $this->raw('['); - $first = true; - foreach ($value as $key => $v) { - if (!$first) { - $this->raw(', '); - } - $first = false; - $this->repr($key); - $this->raw(' => '); - $this->repr($v); - } - $this->raw(']'); - } else { - $this->string($value); - } - - return $this; - } - - /** - * Adds debugging information. - * - * @return $this - */ - public function addDebugInfo(Twig_NodeInterface $node) - { - if ($node->getTemplateLine() != $this->lastLine) { - $this->write(sprintf("// line %d\n", $node->getTemplateLine())); - - // when mbstring.func_overload is set to 2 - // mb_substr_count() replaces substr_count() - // but they have different signatures! - if (((int) ini_get('mbstring.func_overload')) & 2) { - @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); - - // this is much slower than the "right" version - $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); - } else { - $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); - } - $this->sourceOffset = strlen($this->source); - $this->debugInfo[$this->sourceLine] = $node->getTemplateLine(); - - $this->lastLine = $node->getTemplateLine(); - } - - return $this; - } - - public function getDebugInfo() - { - ksort($this->debugInfo); - - return $this->debugInfo; - } - - /** - * Indents the generated code. - * - * @param int $step The number of indentation to add - * - * @return $this - */ - public function indent($step = 1) - { - $this->indentation += $step; - - return $this; - } - - /** - * Outdents the generated code. - * - * @param int $step The number of indentation to remove - * - * @return $this - * - * @throws LogicException When trying to outdent too much so the indentation would become negative - */ - public function outdent($step = 1) - { - // can't outdent by more steps than the current indentation level - if ($this->indentation < $step) { - throw new LogicException('Unable to call outdent() as the indentation would become negative.'); - } - - $this->indentation -= $step; - - return $this; - } - - public function getVarName() - { - return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++)); - } -} - -class_alias('Twig_Compiler', 'Twig\Compiler', false); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig1x/ContainerRuntimeLoader.php b/system/templateEngines/Twig/Twig1x/ContainerRuntimeLoader.php deleted file mode 100644 index 814ab58..0000000 --- a/system/templateEngines/Twig/Twig1x/ContainerRuntimeLoader.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @author Robin Chalas - */ -class Twig_ContainerRuntimeLoader implements Twig_RuntimeLoaderInterface -{ - private $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - public function load($class) - { - if ($this->container->has($class)) { - return $this->container->get($class); - } - } -} - -class_alias('Twig_ContainerRuntimeLoader', 'Twig\RuntimeLoader\ContainerRuntimeLoader', false); diff --git a/system/templateEngines/Twig/Twig1x/Environment.php b/system/templateEngines/Twig/Twig1x/Environment.php deleted file mode 100644 index 2a051b9..0000000 --- a/system/templateEngines/Twig/Twig1x/Environment.php +++ /dev/null @@ -1,1617 +0,0 @@ - - */ -class Twig_Environment -{ - const VERSION = '1.37.1'; - const VERSION_ID = 13701; - const MAJOR_VERSION = 1; - const MINOR_VERSION = 37; - const RELEASE_VERSION = 1; - const EXTRA_VERSION = ''; - - protected $charset; - protected $loader; - protected $debug; - protected $autoReload; - protected $cache; - protected $lexer; - protected $parser; - protected $compiler; - protected $baseTemplateClass; - protected $extensions; - protected $parsers; - protected $visitors; - protected $filters; - protected $tests; - protected $functions; - protected $globals; - protected $runtimeInitialized = false; - protected $extensionInitialized = false; - protected $loadedTemplates; - protected $strictVariables; - protected $unaryOperators; - protected $binaryOperators; - protected $templateClassPrefix = '__TwigTemplate_'; - protected $functionCallbacks = []; - protected $filterCallbacks = []; - protected $staging; - - private $originalCache; - private $bcWriteCacheFile = false; - private $bcGetCacheFilename = false; - private $lastModifiedExtension = 0; - private $extensionsByClass = []; - private $runtimeLoaders = []; - private $runtimes = []; - private $optionsHash; - private $loading = []; - - /** - * Constructor. - * - * Available options: - * - * * debug: When set to true, it automatically set "auto_reload" to true as - * well (default to false). - * - * * charset: The charset used by the templates (default to UTF-8). - * - * * base_template_class: The base template class to use for generated - * templates (default to Twig_Template). - * - * * cache: An absolute path where to store the compiled templates, - * a Twig_Cache_Interface implementation, - * or false to disable compilation cache (default). - * - * * auto_reload: Whether to reload the template if the original source changed. - * If you don't provide the auto_reload option, it will be - * determined automatically based on the debug value. - * - * * strict_variables: Whether to ignore invalid variables in templates - * (default to false). - * - * * autoescape: Whether to enable auto-escaping (default to html): - * * false: disable auto-escaping - * * true: equivalent to html - * * html, js: set the autoescaping to one of the supported strategies - * * name: set the autoescaping strategy based on the template name extension - * * PHP callback: a PHP callback that returns an escaping strategy based on the template "name" - * - * * optimizations: A flag that indicates which optimizations to apply - * (default to -1 which means that all optimizations are enabled; - * set it to 0 to disable). - * - * @param Twig_LoaderInterface $loader - * @param array $options An array of options - */ - public function __construct(Twig_LoaderInterface $loader = null, $options = []) - { - if (null !== $loader) { - $this->setLoader($loader); - } else { - @trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated since version 1.21.', E_USER_DEPRECATED); - } - - $options = array_merge([ - 'debug' => false, - 'charset' => 'UTF-8', - 'base_template_class' => 'Twig_Template', - 'strict_variables' => false, - 'autoescape' => 'html', - 'cache' => false, - 'auto_reload' => null, - 'optimizations' => -1, - ], $options); - - $this->debug = (bool) $options['debug']; - $this->charset = strtoupper($options['charset']); - $this->baseTemplateClass = $options['base_template_class']; - $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; - $this->strictVariables = (bool) $options['strict_variables']; - $this->setCache($options['cache']); - - $this->addExtension(new Twig_Extension_Core()); - $this->addExtension(new Twig_Extension_Escaper($options['autoescape'])); - $this->addExtension(new Twig_Extension_Optimizer($options['optimizations'])); - $this->staging = new Twig_Extension_Staging(); - - // For BC - if (is_string($this->originalCache)) { - $r = new ReflectionMethod($this, 'writeCacheFile'); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The Twig_Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); - - $this->bcWriteCacheFile = true; - } - - $r = new ReflectionMethod($this, 'getCacheFilename'); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The Twig_Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); - - $this->bcGetCacheFilename = true; - } - } - } - - /** - * Gets the base template class for compiled templates. - * - * @return string The base template class name - */ - public function getBaseTemplateClass() - { - return $this->baseTemplateClass; - } - - /** - * Sets the base template class for compiled templates. - * - * @param string $class The base template class name - */ - public function setBaseTemplateClass($class) - { - $this->baseTemplateClass = $class; - $this->updateOptionsHash(); - } - - /** - * Enables debugging mode. - */ - public function enableDebug() - { - $this->debug = true; - $this->updateOptionsHash(); - } - - /** - * Disables debugging mode. - */ - public function disableDebug() - { - $this->debug = false; - $this->updateOptionsHash(); - } - - /** - * Checks if debug mode is enabled. - * - * @return bool true if debug mode is enabled, false otherwise - */ - public function isDebug() - { - return $this->debug; - } - - /** - * Enables the auto_reload option. - */ - public function enableAutoReload() - { - $this->autoReload = true; - } - - /** - * Disables the auto_reload option. - */ - public function disableAutoReload() - { - $this->autoReload = false; - } - - /** - * Checks if the auto_reload option is enabled. - * - * @return bool true if auto_reload is enabled, false otherwise - */ - public function isAutoReload() - { - return $this->autoReload; - } - - /** - * Enables the strict_variables option. - */ - public function enableStrictVariables() - { - $this->strictVariables = true; - $this->updateOptionsHash(); - } - - /** - * Disables the strict_variables option. - */ - public function disableStrictVariables() - { - $this->strictVariables = false; - $this->updateOptionsHash(); - } - - /** - * Checks if the strict_variables option is enabled. - * - * @return bool true if strict_variables is enabled, false otherwise - */ - public function isStrictVariables() - { - return $this->strictVariables; - } - - /** - * Gets the current cache implementation. - * - * @param bool $original Whether to return the original cache option or the real cache instance - * - * @return Twig_CacheInterface|string|false A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache - */ - public function getCache($original = true) - { - return $original ? $this->originalCache : $this->cache; - } - - /** - * Sets the current cache implementation. - * - * @param Twig_CacheInterface|string|false $cache A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache - */ - public function setCache($cache) - { - if (is_string($cache)) { - $this->originalCache = $cache; - $this->cache = new Twig_Cache_Filesystem($cache); - } elseif (false === $cache) { - $this->originalCache = $cache; - $this->cache = new Twig_Cache_Null(); - } elseif (null === $cache) { - @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); - $this->originalCache = false; - $this->cache = new Twig_Cache_Null(); - } elseif ($cache instanceof Twig_CacheInterface) { - $this->originalCache = $this->cache = $cache; - } else { - throw new LogicException(sprintf('Cache can only be a string, false, or a Twig_CacheInterface implementation.')); - } - } - - /** - * Gets the cache filename for a given template. - * - * @param string $name The template name - * - * @return string|false The cache file name or false when caching is disabled - * - * @deprecated since 1.22 (to be removed in 2.0) - */ - public function getCacheFilename($name) - { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - $key = $this->cache->generateKey($name, $this->getTemplateClass($name)); - - return !$key ? false : $key; - } - - /** - * Gets the template class associated with the given string. - * - * The generated template class is based on the following parameters: - * - * * The cache key for the given template; - * * The currently enabled extensions; - * * Whether the Twig C extension is available or not; - * * PHP version; - * * Twig version; - * * Options with what environment was created. - * - * @param string $name The name for which to calculate the template class name - * @param int|null $index The index if it is an embedded template - * - * @return string The template class name - */ - public function getTemplateClass($name, $index = null) - { - $key = $this->getLoader()->getCacheKey($name).$this->optionsHash; - - return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '_'.$index); - } - - /** - * Gets the template class prefix. - * - * @return string The template class prefix - * - * @deprecated since 1.22 (to be removed in 2.0) - */ - public function getTemplateClassPrefix() - { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - return $this->templateClassPrefix; - } - - /** - * Renders a template. - * - * @param string $name The template name - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered template - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - * @throws Twig_Error_Runtime When an error occurred during rendering - */ - public function render($name, array $context = []) - { - return $this->loadTemplate($name)->render($context); - } - - /** - * Displays a template. - * - * @param string $name The template name - * @param array $context An array of parameters to pass to the template - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - * @throws Twig_Error_Runtime When an error occurred during rendering - */ - public function display($name, array $context = []) - { - $this->loadTemplate($name)->display($context); - } - - /** - * Loads a template. - * - * @param string|Twig_TemplateWrapper|Twig_Template $name The template name - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Runtime When a previously generated cache is corrupted - * @throws Twig_Error_Syntax When an error occurred during compilation - * - * @return Twig_TemplateWrapper - */ - public function load($name) - { - if ($name instanceof Twig_TemplateWrapper) { - return $name; - } - - if ($name instanceof Twig_Template) { - return new Twig_TemplateWrapper($this, $name); - } - - return new Twig_TemplateWrapper($this, $this->loadTemplate($name)); - } - - /** - * Loads a template internal representation. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The template name - * @param int $index The index if it is an embedded template - * - * @return Twig_TemplateInterface A template instance representing the given template name - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Runtime When a previously generated cache is corrupted - * @throws Twig_Error_Syntax When an error occurred during compilation - * - * @internal - */ - public function loadTemplate($name, $index = null) - { - $cls = $mainCls = $this->getTemplateClass($name); - if (null !== $index) { - $cls .= '_'.$index; - } - - if (isset($this->loadedTemplates[$cls])) { - return $this->loadedTemplates[$cls]; - } - - if (!class_exists($cls, false)) { - if ($this->bcGetCacheFilename) { - $key = $this->getCacheFilename($name); - } else { - $key = $this->cache->generateKey($name, $mainCls); - } - - if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) { - $this->cache->load($key); - } - - if (!class_exists($cls, false)) { - $loader = $this->getLoader(); - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - $source = new Twig_Source($loader->getSource($name), $name); - } else { - $source = $loader->getSourceContext($name); - } - - $content = $this->compileSource($source); - - if ($this->bcWriteCacheFile) { - $this->writeCacheFile($key, $content); - } else { - $this->cache->write($key, $content); - $this->cache->load($key); - } - - if (!class_exists($mainCls, false)) { - /* Last line of defense if either $this->bcWriteCacheFile was used, - * $this->cache is implemented as a no-op or we have a race condition - * where the cache was cleared between the above calls to write to and load from - * the cache. - */ - eval('?>'.$content); - } - } - - if (!class_exists($cls, false)) { - throw new Twig_Error_Runtime(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source); - } - } - - if (!$this->runtimeInitialized) { - $this->initRuntime(); - } - - if (isset($this->loading[$cls])) { - throw new Twig_Error_Runtime(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, [$name])))); - } - - $this->loading[$cls] = $name; - - try { - $this->loadedTemplates[$cls] = new $cls($this); - unset($this->loading[$cls]); - } catch (\Exception $e) { - unset($this->loading[$cls]); - - throw $e; - } - - return $this->loadedTemplates[$cls]; - } - - /** - * Creates a template from source. - * - * This method should not be used as a generic way to load templates. - * - * @param string $template The template name - * - * @return Twig_Template A template instance representing the given template name - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - */ - public function createTemplate($template) - { - $name = sprintf('__string_template__%s', hash('sha256', $template, false)); - - $loader = new Twig_Loader_Chain([ - new Twig_Loader_Array([$name => $template]), - $current = $this->getLoader(), - ]); - - $this->setLoader($loader); - try { - $template = $this->loadTemplate($name); - } catch (Exception $e) { - $this->setLoader($current); - - throw $e; - } catch (Throwable $e) { - $this->setLoader($current); - - throw $e; - } - $this->setLoader($current); - - return $template; - } - - /** - * Returns true if the template is still fresh. - * - * Besides checking the loader for freshness information, - * this method also checks if the enabled extensions have - * not changed. - * - * @param string $name The template name - * @param int $time The last modification time of the cached template - * - * @return bool true if the template is fresh, false otherwise - */ - public function isTemplateFresh($name, $time) - { - if (0 === $this->lastModifiedExtension) { - foreach ($this->extensions as $extension) { - $r = new ReflectionObject($extension); - if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) { - $this->lastModifiedExtension = $extensionTime; - } - } - } - - return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time); - } - - /** - * Tries to load a template consecutively from an array. - * - * Similar to loadTemplate() but it also accepts instances of Twig_Template and - * Twig_TemplateWrapper, and an array of templates where each is tried to be loaded. - * - * @param string|Twig_Template|Twig_TemplateWrapper|array $names A template or an array of templates to try consecutively - * - * @return Twig_Template|Twig_TemplateWrapper - * - * @throws Twig_Error_Loader When none of the templates can be found - * @throws Twig_Error_Syntax When an error occurred during compilation - */ - public function resolveTemplate($names) - { - if (!is_array($names)) { - $names = [$names]; - } - - foreach ($names as $name) { - if ($name instanceof Twig_Template) { - return $name; - } - - if ($name instanceof Twig_TemplateWrapper) { - return $name; - } - - try { - return $this->loadTemplate($name); - } catch (Twig_Error_Loader $e) { - } - } - - if (1 === count($names)) { - throw $e; - } - - throw new Twig_Error_Loader(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); - } - - /** - * Clears the internal template cache. - * - * @deprecated since 1.18.3 (to be removed in 2.0) - */ - public function clearTemplateCache() - { - @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); - - $this->loadedTemplates = []; - } - - /** - * Clears the template cache files on the filesystem. - * - * @deprecated since 1.22 (to be removed in 2.0) - */ - public function clearCacheFiles() - { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - if (is_string($this->originalCache)) { - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->originalCache), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { - if ($file->isFile()) { - @unlink($file->getPathname()); - } - } - } - } - - /** - * Gets the Lexer instance. - * - * @return Twig_LexerInterface - * - * @deprecated since 1.25 (to be removed in 2.0) - */ - public function getLexer() - { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); - - if (null === $this->lexer) { - $this->lexer = new Twig_Lexer($this); - } - - return $this->lexer; - } - - public function setLexer(Twig_LexerInterface $lexer) - { - $this->lexer = $lexer; - } - - /** - * Tokenizes a source code. - * - * @param string|Twig_Source $source The template source code - * @param string $name The template name (deprecated) - * - * @return Twig_TokenStream - * - * @throws Twig_Error_Syntax When the code is syntactically wrong - */ - public function tokenize($source, $name = null) - { - if (!$source instanceof Twig_Source) { - @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); - $source = new Twig_Source($source, $name); - } - - if (null === $this->lexer) { - $this->lexer = new Twig_Lexer($this); - } - - return $this->lexer->tokenize($source); - } - - /** - * Gets the Parser instance. - * - * @return Twig_ParserInterface - * - * @deprecated since 1.25 (to be removed in 2.0) - */ - public function getParser() - { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); - - if (null === $this->parser) { - $this->parser = new Twig_Parser($this); - } - - return $this->parser; - } - - public function setParser(Twig_ParserInterface $parser) - { - $this->parser = $parser; - } - - /** - * Converts a token stream to a node tree. - * - * @return Twig_Node_Module - * - * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong - */ - public function parse(Twig_TokenStream $stream) - { - if (null === $this->parser) { - $this->parser = new Twig_Parser($this); - } - - return $this->parser->parse($stream); - } - - /** - * Gets the Compiler instance. - * - * @return Twig_CompilerInterface - * - * @deprecated since 1.25 (to be removed in 2.0) - */ - public function getCompiler() - { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); - - if (null === $this->compiler) { - $this->compiler = new Twig_Compiler($this); - } - - return $this->compiler; - } - - public function setCompiler(Twig_CompilerInterface $compiler) - { - $this->compiler = $compiler; - } - - /** - * Compiles a node and returns the PHP code. - * - * @return string The compiled PHP source code - */ - public function compile(Twig_NodeInterface $node) - { - if (null === $this->compiler) { - $this->compiler = new Twig_Compiler($this); - } - - return $this->compiler->compile($node)->getSource(); - } - - /** - * Compiles a template source code. - * - * @param string|Twig_Source $source The template source code - * @param string $name The template name (deprecated) - * - * @return string The compiled PHP source code - * - * @throws Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling - */ - public function compileSource($source, $name = null) - { - if (!$source instanceof Twig_Source) { - @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); - $source = new Twig_Source($source, $name); - } - - try { - return $this->compile($this->parse($this->tokenize($source))); - } catch (Twig_Error $e) { - $e->setSourceContext($source); - throw $e; - } catch (Exception $e) { - throw new Twig_Error_Syntax(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); - } - } - - public function setLoader(Twig_LoaderInterface $loader) - { - if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(get_class($loader), 'Mock_')) { - @trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', get_class($loader)), E_USER_DEPRECATED); - } - - $this->loader = $loader; - } - - /** - * Gets the Loader instance. - * - * @return Twig_LoaderInterface - */ - public function getLoader() - { - if (null === $this->loader) { - throw new LogicException('You must set a loader first.'); - } - - return $this->loader; - } - - /** - * Sets the default template charset. - * - * @param string $charset The default charset - */ - public function setCharset($charset) - { - $this->charset = strtoupper($charset); - } - - /** - * Gets the default template charset. - * - * @return string The default charset - */ - public function getCharset() - { - return $this->charset; - } - - /** - * Initializes the runtime environment. - * - * @deprecated since 1.23 (to be removed in 2.0) - */ - public function initRuntime() - { - $this->runtimeInitialized = true; - - foreach ($this->getExtensions() as $name => $extension) { - if (!$extension instanceof Twig_Extension_InitRuntimeInterface) { - $m = new ReflectionMethod($extension, 'initRuntime'); - - if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { - @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); - } - } - - $extension->initRuntime($this); - } - } - - /** - * Returns true if the given extension is registered. - * - * @param string $class The extension class name - * - * @return bool Whether the extension is registered or not - */ - public function hasExtension($class) - { - $class = ltrim($class, '\\'); - if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) { - // For BC/FC with namespaced aliases - $class = new ReflectionClass($class); - $class = $class->name; - } - - if (isset($this->extensions[$class])) { - if ($class !== get_class($this->extensions[$class])) { - @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); - } - - return true; - } - - return isset($this->extensionsByClass[$class]); - } - - /** - * Adds a runtime loader. - */ - public function addRuntimeLoader(Twig_RuntimeLoaderInterface $loader) - { - $this->runtimeLoaders[] = $loader; - } - - /** - * Gets an extension by class name. - * - * @param string $class The extension class name - * - * @return Twig_ExtensionInterface - */ - public function getExtension($class) - { - $class = ltrim($class, '\\'); - if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) { - // For BC/FC with namespaced aliases - $class = new ReflectionClass($class); - $class = $class->name; - } - - if (isset($this->extensions[$class])) { - if ($class !== get_class($this->extensions[$class])) { - @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); - } - - return $this->extensions[$class]; - } - - if (!isset($this->extensionsByClass[$class])) { - throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $class)); - } - - return $this->extensionsByClass[$class]; - } - - /** - * Returns the runtime implementation of a Twig element (filter/function/test). - * - * @param string $class A runtime class name - * - * @return object The runtime implementation - * - * @throws Twig_Error_Runtime When the template cannot be found - */ - public function getRuntime($class) - { - if (isset($this->runtimes[$class])) { - return $this->runtimes[$class]; - } - - foreach ($this->runtimeLoaders as $loader) { - if (null !== $runtime = $loader->load($class)) { - return $this->runtimes[$class] = $runtime; - } - } - - throw new Twig_Error_Runtime(sprintf('Unable to load the "%s" runtime.', $class)); - } - - public function addExtension(Twig_ExtensionInterface $extension) - { - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); - } - - $class = get_class($extension); - if ($class !== $extension->getName()) { - if (isset($this->extensions[$extension->getName()])) { - unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]); - @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); - } - } - - $this->lastModifiedExtension = 0; - $this->extensionsByClass[$class] = $extension; - $this->extensions[$extension->getName()] = $extension; - $this->updateOptionsHash(); - } - - /** - * Removes an extension by name. - * - * This method is deprecated and you should not use it. - * - * @param string $name The extension name - * - * @deprecated since 1.12 (to be removed in 2.0) - */ - public function removeExtension($name) - { - @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); - } - - $class = ltrim($name, '\\'); - if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) { - // For BC/FC with namespaced aliases - $class = new ReflectionClass($class); - $class = $class->name; - } - - if (isset($this->extensions[$class])) { - if ($class !== get_class($this->extensions[$class])) { - @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); - } - - unset($this->extensions[$class]); - } - - unset($this->extensions[$class]); - $this->updateOptionsHash(); - } - - /** - * Registers an array of extensions. - * - * @param array $extensions An array of extensions - */ - public function setExtensions(array $extensions) - { - foreach ($extensions as $extension) { - $this->addExtension($extension); - } - } - - /** - * Returns all registered extensions. - * - * @return Twig_ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) - */ - public function getExtensions() - { - return $this->extensions; - } - - public function addTokenParser(Twig_TokenParserInterface $parser) - { - if ($this->extensionInitialized) { - throw new LogicException('Unable to add a token parser as extensions have already been initialized.'); - } - - $this->staging->addTokenParser($parser); - } - - /** - * Gets the registered Token Parsers. - * - * @return Twig_TokenParserBrokerInterface - * - * @internal - */ - public function getTokenParsers() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->parsers; - } - - /** - * Gets registered tags. - * - * Be warned that this method cannot return tags defined by Twig_TokenParserBrokerInterface classes. - * - * @return Twig_TokenParserInterface[] - * - * @internal - */ - public function getTags() - { - $tags = []; - foreach ($this->getTokenParsers()->getParsers() as $parser) { - if ($parser instanceof Twig_TokenParserInterface) { - $tags[$parser->getTag()] = $parser; - } - } - - return $tags; - } - - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) - { - if ($this->extensionInitialized) { - throw new LogicException('Unable to add a node visitor as extensions have already been initialized.'); - } - - $this->staging->addNodeVisitor($visitor); - } - - /** - * Gets the registered Node Visitors. - * - * @return Twig_NodeVisitorInterface[] - * - * @internal - */ - public function getNodeVisitors() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->visitors; - } - - /** - * Registers a Filter. - * - * @param string|Twig_SimpleFilter $name The filter name or a Twig_SimpleFilter instance - * @param Twig_FilterInterface|Twig_SimpleFilter $filter - */ - public function addFilter($name, $filter = null) - { - if (!$name instanceof Twig_SimpleFilter && !($filter instanceof Twig_SimpleFilter || $filter instanceof Twig_FilterInterface)) { - throw new LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter.'); - } - - if ($name instanceof Twig_SimpleFilter) { - $filter = $name; - $name = $filter->getName(); - } else { - @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); - } - - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name)); - } - - $this->staging->addFilter($name, $filter); - } - - /** - * Get a filter by name. - * - * Subclasses may override this method and load filters differently; - * so no list of filters is available. - * - * @param string $name The filter name - * - * @return Twig_Filter|false A Twig_Filter instance or false if the filter does not exist - * - * @internal - */ - public function getFilter($name) - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - if (isset($this->filters[$name])) { - return $this->filters[$name]; - } - - foreach ($this->filters as $pattern => $filter) { - $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); - - if ($count) { - if (preg_match('#^'.$pattern.'$#', $name, $matches)) { - array_shift($matches); - $filter->setArguments($matches); - - return $filter; - } - } - } - - foreach ($this->filterCallbacks as $callback) { - if (false !== $filter = call_user_func($callback, $name)) { - return $filter; - } - } - - return false; - } - - public function registerUndefinedFilterCallback($callable) - { - $this->filterCallbacks[] = $callable; - } - - /** - * Gets the registered Filters. - * - * Be warned that this method cannot return filters defined with registerUndefinedFilterCallback. - * - * @return Twig_FilterInterface[] - * - * @see registerUndefinedFilterCallback - * - * @internal - */ - public function getFilters() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->filters; - } - - /** - * Registers a Test. - * - * @param string|Twig_SimpleTest $name The test name or a Twig_SimpleTest instance - * @param Twig_TestInterface|Twig_SimpleTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance - */ - public function addTest($name, $test = null) - { - if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) { - throw new LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest.'); - } - - if ($name instanceof Twig_SimpleTest) { - $test = $name; - $name = $test->getName(); - } else { - @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); - } - - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name)); - } - - $this->staging->addTest($name, $test); - } - - /** - * Gets the registered Tests. - * - * @return Twig_TestInterface[] - * - * @internal - */ - public function getTests() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->tests; - } - - /** - * Gets a test by name. - * - * @param string $name The test name - * - * @return Twig_Test|false A Twig_Test instance or false if the test does not exist - * - * @internal - */ - public function getTest($name) - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - if (isset($this->tests[$name])) { - return $this->tests[$name]; - } - - foreach ($this->tests as $pattern => $test) { - $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); - - if ($count) { - if (preg_match('#^'.$pattern.'$#', $name, $matches)) { - array_shift($matches); - $test->setArguments($matches); - - return $test; - } - } - } - - return false; - } - - /** - * Registers a Function. - * - * @param string|Twig_SimpleFunction $name The function name or a Twig_SimpleFunction instance - * @param Twig_FunctionInterface|Twig_SimpleFunction $function - */ - public function addFunction($name, $function = null) - { - if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) { - throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction.'); - } - - if ($name instanceof Twig_SimpleFunction) { - $function = $name; - $name = $function->getName(); - } else { - @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); - } - - if ($this->extensionInitialized) { - throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name)); - } - - $this->staging->addFunction($name, $function); - } - - /** - * Get a function by name. - * - * Subclasses may override this method and load functions differently; - * so no list of functions is available. - * - * @param string $name function name - * - * @return Twig_Function|false A Twig_Function instance or false if the function does not exist - * - * @internal - */ - public function getFunction($name) - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - if (isset($this->functions[$name])) { - return $this->functions[$name]; - } - - foreach ($this->functions as $pattern => $function) { - $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); - - if ($count) { - if (preg_match('#^'.$pattern.'$#', $name, $matches)) { - array_shift($matches); - $function->setArguments($matches); - - return $function; - } - } - } - - foreach ($this->functionCallbacks as $callback) { - if (false !== $function = call_user_func($callback, $name)) { - return $function; - } - } - - return false; - } - - public function registerUndefinedFunctionCallback($callable) - { - $this->functionCallbacks[] = $callable; - } - - /** - * Gets registered functions. - * - * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback. - * - * @return Twig_FunctionInterface[] - * - * @see registerUndefinedFunctionCallback - * - * @internal - */ - public function getFunctions() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->functions; - } - - /** - * Registers a Global. - * - * New globals can be added before compiling or rendering a template; - * but after, you can only update existing globals. - * - * @param string $name The global name - * @param mixed $value The global value - */ - public function addGlobal($name, $value) - { - if ($this->extensionInitialized || $this->runtimeInitialized) { - if (null === $this->globals) { - $this->globals = $this->initGlobals(); - } - - if (!array_key_exists($name, $this->globals)) { - // The deprecation notice must be turned into the following exception in Twig 2.0 - @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); - //throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); - } - } - - if ($this->extensionInitialized || $this->runtimeInitialized) { - // update the value - $this->globals[$name] = $value; - } else { - $this->staging->addGlobal($name, $value); - } - } - - /** - * Gets the registered Globals. - * - * @return array An array of globals - * - * @internal - */ - public function getGlobals() - { - if (!$this->runtimeInitialized && !$this->extensionInitialized) { - return $this->initGlobals(); - } - - if (null === $this->globals) { - $this->globals = $this->initGlobals(); - } - - return $this->globals; - } - - /** - * Merges a context with the defined globals. - * - * @param array $context An array representing the context - * - * @return array The context merged with the globals - */ - public function mergeGlobals(array $context) - { - // we don't use array_merge as the context being generally - // bigger than globals, this code is faster. - foreach ($this->getGlobals() as $key => $value) { - if (!array_key_exists($key, $context)) { - $context[$key] = $value; - } - } - - return $context; - } - - /** - * Gets the registered unary Operators. - * - * @return array An array of unary operators - * - * @internal - */ - public function getUnaryOperators() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->unaryOperators; - } - - /** - * Gets the registered binary Operators. - * - * @return array An array of binary operators - * - * @internal - */ - public function getBinaryOperators() - { - if (!$this->extensionInitialized) { - $this->initExtensions(); - } - - return $this->binaryOperators; - } - - /** - * @deprecated since 1.23 (to be removed in 2.0) - */ - public function computeAlternatives($name, $items) - { - @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - - return Twig_Error_Syntax::computeAlternatives($name, $items); - } - - /** - * @internal - */ - protected function initGlobals() - { - $globals = []; - foreach ($this->extensions as $name => $extension) { - if (!$extension instanceof Twig_Extension_GlobalsInterface) { - $m = new ReflectionMethod($extension, 'getGlobals'); - - if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { - @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); - } - } - - $extGlob = $extension->getGlobals(); - if (!is_array($extGlob)) { - throw new UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', get_class($extension))); - } - - $globals[] = $extGlob; - } - - $globals[] = $this->staging->getGlobals(); - - return call_user_func_array('array_merge', $globals); - } - - /** - * @internal - */ - protected function initExtensions() - { - if ($this->extensionInitialized) { - return; - } - - $this->parsers = new Twig_TokenParserBroker([], [], false); - $this->filters = []; - $this->functions = []; - $this->tests = []; - $this->visitors = []; - $this->unaryOperators = []; - $this->binaryOperators = []; - - foreach ($this->extensions as $extension) { - $this->initExtension($extension); - } - $this->initExtension($this->staging); - // Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception - $this->extensionInitialized = true; - } - - /** - * @internal - */ - protected function initExtension(Twig_ExtensionInterface $extension) - { - // filters - foreach ($extension->getFilters() as $name => $filter) { - if ($filter instanceof Twig_SimpleFilter) { - $name = $filter->getName(); - } else { - @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); - } - - $this->filters[$name] = $filter; - } - - // functions - foreach ($extension->getFunctions() as $name => $function) { - if ($function instanceof Twig_SimpleFunction) { - $name = $function->getName(); - } else { - @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); - } - - $this->functions[$name] = $function; - } - - // tests - foreach ($extension->getTests() as $name => $test) { - if ($test instanceof Twig_SimpleTest) { - $name = $test->getName(); - } else { - @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); - } - - $this->tests[$name] = $test; - } - - // token parsers - foreach ($extension->getTokenParsers() as $parser) { - if ($parser instanceof Twig_TokenParserInterface) { - $this->parsers->addTokenParser($parser); - } elseif ($parser instanceof Twig_TokenParserBrokerInterface) { - @trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED); - - $this->parsers->addTokenParserBroker($parser); - } else { - throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances.'); - } - } - - // node visitors - foreach ($extension->getNodeVisitors() as $visitor) { - $this->visitors[] = $visitor; - } - - // operators - if ($operators = $extension->getOperators()) { - if (!is_array($operators)) { - 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))); - } - - if (2 !== count($operators)) { - throw new InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', get_class($extension), count($operators))); - } - - $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); - $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]); - } - } - - /** - * @deprecated since 1.22 (to be removed in 2.0) - */ - protected function writeCacheFile($file, $content) - { - $this->cache->write($file, $content); - } - - private function updateOptionsHash() - { - $hashParts = array_merge( - array_keys($this->extensions), - [ - (int) function_exists('twig_template_get_attributes'), - PHP_MAJOR_VERSION, - PHP_MINOR_VERSION, - self::VERSION, - (int) $this->debug, - $this->baseTemplateClass, - (int) $this->strictVariables, - ] - ); - $this->optionsHash = implode(':', $hashParts); - } -} - -class_alias('Twig_Environment', 'Twig\Environment', false); diff --git a/system/templateEngines/Twig/Twig1x/Error.php b/system/templateEngines/Twig/Twig1x/Error.php deleted file mode 100644 index 569c2fe..0000000 --- a/system/templateEngines/Twig/Twig1x/Error.php +++ /dev/null @@ -1,333 +0,0 @@ - - */ -class Twig_Error extends Exception -{ - protected $lineno; - // to be renamed to name in 2.0 - protected $filename; - protected $rawMessage; - - private $sourcePath; - private $sourceCode; - - /** - * Constructor. - * - * Set both the line number and the name to false to - * disable automatic guessing of the original template name - * and line number. - * - * Set the line number to -1 to enable its automatic guessing. - * Set the name to null to enable its automatic guessing. - * - * By default, automatic guessing is enabled. - * - * @param string $message The error message - * @param int $lineno The template line where the error occurred - * @param Twig_Source|string|null $source The source context where the error occurred - * @param Exception $previous The previous exception - */ - public function __construct($message, $lineno = -1, $source = null, Exception $previous = null) - { - if (null === $source) { - $name = null; - } elseif (!$source instanceof Twig_Source) { - // for compat with the Twig C ext., passing the template name as string is accepted - $name = $source; - } else { - $name = $source->getName(); - $this->sourceCode = $source->getCode(); - $this->sourcePath = $source->getPath(); - } - parent::__construct('', 0, $previous); - - $this->lineno = $lineno; - $this->filename = $name; - - if (-1 === $lineno || null === $name || null === $this->sourcePath) { - $this->guessTemplateInfo(); - } - - $this->rawMessage = $message; - - $this->updateRepr(); - } - - /** - * Gets the raw message. - * - * @return string The raw message - */ - public function getRawMessage() - { - return $this->rawMessage; - } - - /** - * Gets the logical name where the error occurred. - * - * @return string The name - * - * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead. - */ - public function getTemplateFile() - { - @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); - - return $this->filename; - } - - /** - * Sets the logical name where the error occurred. - * - * @param string $name The name - * - * @deprecated since 1.27 (to be removed in 2.0). Use setSourceContext() instead. - */ - public function setTemplateFile($name) - { - @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); - - $this->filename = $name; - - $this->updateRepr(); - } - - /** - * Gets the logical name where the error occurred. - * - * @return string The name - * - * @deprecated since 1.29 (to be removed in 2.0). Use getSourceContext() instead. - */ - public function getTemplateName() - { - @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); - - return $this->filename; - } - - /** - * Sets the logical name where the error occurred. - * - * @param string $name The name - * - * @deprecated since 1.29 (to be removed in 2.0). Use setSourceContext() instead. - */ - public function setTemplateName($name) - { - @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); - - $this->filename = $name; - $this->sourceCode = $this->sourcePath = null; - - $this->updateRepr(); - } - - /** - * Gets the template line where the error occurred. - * - * @return int The template line - */ - public function getTemplateLine() - { - return $this->lineno; - } - - /** - * Sets the template line where the error occurred. - * - * @param int $lineno The template line - */ - public function setTemplateLine($lineno) - { - $this->lineno = $lineno; - - $this->updateRepr(); - } - - /** - * Gets the source context of the Twig template where the error occurred. - * - * @return Twig_Source|null - */ - public function getSourceContext() - { - return $this->filename ? new Twig_Source($this->sourceCode, $this->filename, $this->sourcePath) : null; - } - - /** - * Sets the source context of the Twig template where the error occurred. - */ - public function setSourceContext(Twig_Source $source = null) - { - if (null === $source) { - $this->sourceCode = $this->filename = $this->sourcePath = null; - } else { - $this->sourceCode = $source->getCode(); - $this->filename = $source->getName(); - $this->sourcePath = $source->getPath(); - } - - $this->updateRepr(); - } - - public function guess() - { - $this->guessTemplateInfo(); - $this->updateRepr(); - } - - public function appendMessage($rawMessage) - { - $this->rawMessage .= $rawMessage; - $this->updateRepr(); - } - - /** - * @internal - */ - protected function updateRepr() - { - $this->message = $this->rawMessage; - - if ($this->sourcePath && $this->lineno > 0) { - $this->file = $this->sourcePath; - $this->line = $this->lineno; - - return; - } - - $dot = false; - if ('.' === substr($this->message, -1)) { - $this->message = substr($this->message, 0, -1); - $dot = true; - } - - $questionMark = false; - if ('?' === substr($this->message, -1)) { - $this->message = substr($this->message, 0, -1); - $questionMark = true; - } - - if ($this->filename) { - if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) { - $name = sprintf('"%s"', $this->filename); - } else { - $name = json_encode($this->filename); - } - $this->message .= sprintf(' in %s', $name); - } - - if ($this->lineno && $this->lineno >= 0) { - $this->message .= sprintf(' at line %d', $this->lineno); - } - - if ($dot) { - $this->message .= '.'; - } - - if ($questionMark) { - $this->message .= '?'; - } - } - - /** - * @internal - */ - protected function guessTemplateInfo() - { - $template = null; - $templateClass = null; - - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); - foreach ($backtrace as $trace) { - if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) { - $currentClass = get_class($trace['object']); - $isEmbedContainer = 0 === strpos($templateClass, $currentClass); - if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) { - $template = $trace['object']; - $templateClass = get_class($trace['object']); - } - } - } - - // update template name - if (null !== $template && null === $this->filename) { - $this->filename = $template->getTemplateName(); - } - - // update template path if any - if (null !== $template && null === $this->sourcePath) { - $src = $template->getSourceContext(); - $this->sourceCode = $src->getCode(); - $this->sourcePath = $src->getPath(); - } - - if (null === $template || $this->lineno > -1) { - return; - } - - $r = new ReflectionObject($template); - $file = $r->getFileName(); - - $exceptions = [$e = $this]; - while ($e instanceof self && $e = $e->getPrevious()) { - $exceptions[] = $e; - } - - while ($e = array_pop($exceptions)) { - $traces = $e->getTrace(); - array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]); - - while ($trace = array_shift($traces)) { - if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) { - continue; - } - - foreach ($template->getDebugInfo() as $codeLine => $templateLine) { - if ($codeLine <= $trace['line']) { - // update template line - $this->lineno = $templateLine; - - return; - } - } - } - } - } -} - -class_alias('Twig_Error', 'Twig\Error\Error', false); -class_exists('Twig_Source'); diff --git a/system/templateEngines/Twig/Twig1x/Error/Loader.php b/system/templateEngines/Twig/Twig1x/Error/Loader.php deleted file mode 100644 index 2ef0480..0000000 --- a/system/templateEngines/Twig/Twig1x/Error/Loader.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Error_Loader extends Twig_Error -{ - public function __construct($message, $lineno = -1, $source = null, Exception $previous = null) - { - Exception::__construct('', 0, $previous); - - $this->appendMessage($message); - $this->setTemplateLine(false); - } -} - -class_alias('Twig_Error_Loader', 'Twig\Error\LoaderError', false); diff --git a/system/templateEngines/Twig/Twig1x/Error/Runtime.php b/system/templateEngines/Twig/Twig1x/Error/Runtime.php deleted file mode 100644 index 3b24ad3..0000000 --- a/system/templateEngines/Twig/Twig1x/Error/Runtime.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -class Twig_Error_Runtime extends Twig_Error -{ -} - -class_alias('Twig_Error_Runtime', 'Twig\Error\RuntimeError', false); diff --git a/system/templateEngines/Twig/Twig1x/Error/Syntax.php b/system/templateEngines/Twig/Twig1x/Error/Syntax.php deleted file mode 100644 index c889dc6..0000000 --- a/system/templateEngines/Twig/Twig1x/Error/Syntax.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ -class Twig_Error_Syntax extends Twig_Error -{ - /** - * Tweaks the error message to include suggestions. - * - * @param string $name The original name of the item that does not exist - * @param array $items An array of possible items - */ - public function addSuggestions($name, array $items) - { - if (!$alternatives = self::computeAlternatives($name, $items)) { - return; - } - - $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives))); - } - - /** - * @internal - * - * To be merged with the addSuggestions() method in 2.0. - */ - public static function computeAlternatives($name, $items) - { - $alternatives = []; - foreach ($items as $item) { - $lev = levenshtein($name, $item); - if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) { - $alternatives[$item] = $lev; - } - } - asort($alternatives); - - return array_keys($alternatives); - } -} - -class_alias('Twig_Error_Syntax', 'Twig\Error\SyntaxError', false); diff --git a/system/templateEngines/Twig/Twig1x/ExistsLoaderInterface.php b/system/templateEngines/Twig/Twig1x/ExistsLoaderInterface.php deleted file mode 100644 index 968cb21..0000000 --- a/system/templateEngines/Twig/Twig1x/ExistsLoaderInterface.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_ExistsLoaderInterface -{ - /** - * Check if we have the source code of a template, given its name. - * - * @param string $name The name of the template to check if we can load - * - * @return bool If the template source code is handled by this loader or not - */ - public function exists($name); -} - -class_alias('Twig_ExistsLoaderInterface', 'Twig\Loader\ExistsLoaderInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/ExpressionParser.php b/system/templateEngines/Twig/Twig1x/ExpressionParser.php deleted file mode 100644 index eaaafb1..0000000 --- a/system/templateEngines/Twig/Twig1x/ExpressionParser.php +++ /dev/null @@ -1,744 +0,0 @@ - - * - * @internal - */ -class Twig_ExpressionParser -{ - const OPERATOR_LEFT = 1; - const OPERATOR_RIGHT = 2; - - protected $parser; - protected $unaryOperators; - protected $binaryOperators; - - private $env; - - public function __construct(Twig_Parser $parser, $env = null) - { - $this->parser = $parser; - - if ($env instanceof Twig_Environment) { - $this->env = $env; - $this->unaryOperators = $env->getUnaryOperators(); - $this->binaryOperators = $env->getBinaryOperators(); - } else { - @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED); - - $this->env = $parser->getEnvironment(); - $this->unaryOperators = func_get_arg(1); - $this->binaryOperators = func_get_arg(2); - } - } - - public function parseExpression($precedence = 0) - { - $expr = $this->getPrimary(); - $token = $this->parser->getCurrentToken(); - while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) { - $op = $this->binaryOperators[$token->getValue()]; - $this->parser->getStream()->next(); - - if ('is not' === $token->getValue()) { - $expr = $this->parseNotTestExpression($expr); - } elseif ('is' === $token->getValue()) { - $expr = $this->parseTestExpression($expr); - } elseif (isset($op['callable'])) { - $expr = call_user_func($op['callable'], $this->parser, $expr); - } else { - $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); - $class = $op['class']; - $expr = new $class($expr, $expr1, $token->getLine()); - } - - $token = $this->parser->getCurrentToken(); - } - - if (0 === $precedence) { - return $this->parseConditionalExpression($expr); - } - - return $expr; - } - - protected function getPrimary() - { - $token = $this->parser->getCurrentToken(); - - if ($this->isUnary($token)) { - $operator = $this->unaryOperators[$token->getValue()]; - $this->parser->getStream()->next(); - $expr = $this->parseExpression($operator['precedence']); - $class = $operator['class']; - - return $this->parsePostfixExpression(new $class($expr, $token->getLine())); - } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $this->parser->getStream()->next(); - $expr = $this->parseExpression(); - $this->parser->getStream()->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed'); - - return $this->parsePostfixExpression($expr); - } - - return $this->parsePrimaryExpression(); - } - - protected function parseConditionalExpression($expr) - { - while ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, '?')) { - if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { - $expr2 = $this->parseExpression(); - if ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { - $expr3 = $this->parseExpression(); - } else { - $expr3 = new Twig_Node_Expression_Constant('', $this->parser->getCurrentToken()->getLine()); - } - } else { - $expr2 = $expr; - $expr3 = $this->parseExpression(); - } - - $expr = new Twig_Node_Expression_Conditional($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); - } - - return $expr; - } - - protected function isUnary(Twig_Token $token) - { - return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); - } - - protected function isBinary(Twig_Token $token) - { - return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); - } - - public function parsePrimaryExpression() - { - $token = $this->parser->getCurrentToken(); - switch ($token->getType()) { - case Twig_Token::NAME_TYPE: - $this->parser->getStream()->next(); - switch ($token->getValue()) { - case 'true': - case 'TRUE': - $node = new Twig_Node_Expression_Constant(true, $token->getLine()); - break; - - case 'false': - case 'FALSE': - $node = new Twig_Node_Expression_Constant(false, $token->getLine()); - break; - - case 'none': - case 'NONE': - case 'null': - case 'NULL': - $node = new Twig_Node_Expression_Constant(null, $token->getLine()); - break; - - default: - if ('(' === $this->parser->getCurrentToken()->getValue()) { - $node = $this->getFunctionNode($token->getValue(), $token->getLine()); - } else { - $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine()); - } - } - break; - - case Twig_Token::NUMBER_TYPE: - $this->parser->getStream()->next(); - $node = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - break; - - case Twig_Token::STRING_TYPE: - case Twig_Token::INTERPOLATION_START_TYPE: - $node = $this->parseStringExpression(); - break; - - case Twig_Token::OPERATOR_TYPE: - if (preg_match(Twig_Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { - // in this context, string operators are variable names - $this->parser->getStream()->next(); - $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine()); - break; - } elseif (isset($this->unaryOperators[$token->getValue()])) { - $class = $this->unaryOperators[$token->getValue()]['class']; - - $ref = new ReflectionClass($class); - $negClass = 'Twig_Node_Expression_Unary_Neg'; - $posClass = 'Twig_Node_Expression_Unary_Pos'; - if (!(in_array($ref->getName(), [$negClass, $posClass]) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { - throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); - } - - $this->parser->getStream()->next(); - $expr = $this->parsePrimaryExpression(); - - $node = new $class($expr, $token->getLine()); - break; - } - - // no break - default: - if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) { - $node = $this->parseArrayExpression(); - } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) { - $node = $this->parseHashExpression(); - } elseif ($token->test(Twig_Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { - throw new Twig_Error_Syntax(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()); - } else { - throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); - } - } - - return $this->parsePostfixExpression($node); - } - - public function parseStringExpression() - { - $stream = $this->parser->getStream(); - - $nodes = []; - // a string cannot be followed by another string in a single expression - $nextCanBeString = true; - while (true) { - if ($nextCanBeString && $token = $stream->nextIf(Twig_Token::STRING_TYPE)) { - $nodes[] = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - $nextCanBeString = false; - } elseif ($stream->nextIf(Twig_Token::INTERPOLATION_START_TYPE)) { - $nodes[] = $this->parseExpression(); - $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); - $nextCanBeString = true; - } else { - break; - } - } - - $expr = array_shift($nodes); - foreach ($nodes as $node) { - $expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getTemplateLine()); - } - - return $expr; - } - - public function parseArrayExpression() - { - $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '[', 'An array element was expected'); - - $node = new Twig_Node_Expression_Array([], $stream->getCurrent()->getLine()); - $first = true; - while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) { - if (!$first) { - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma'); - - // trailing ,? - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) { - break; - } - } - $first = false; - - $node->addElement($this->parseExpression()); - } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed'); - - return $node; - } - - public function parseHashExpression() - { - $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '{', 'A hash element was expected'); - - $node = new Twig_Node_Expression_Array([], $stream->getCurrent()->getLine()); - $first = true; - while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) { - if (!$first) { - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma'); - - // trailing ,? - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) { - break; - } - } - $first = false; - - // a hash key can be: - // - // * a number -- 12 - // * a string -- 'a' - // * a name, which is equivalent to a string -- a - // * an expression, which must be enclosed in parentheses -- (1 + 2) - if (($token = $stream->nextIf(Twig_Token::STRING_TYPE)) || ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) || $token = $stream->nextIf(Twig_Token::NUMBER_TYPE)) { - $key = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - } elseif ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $key = $this->parseExpression(); - } else { - $current = $stream->getCurrent(); - - throw new Twig_Error_Syntax(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".', Twig_Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext()); - } - - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); - $value = $this->parseExpression(); - - $node->addElement($value, $key); - } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed'); - - return $node; - } - - public function parsePostfixExpression($node) - { - while (true) { - $token = $this->parser->getCurrentToken(); - if (Twig_Token::PUNCTUATION_TYPE == $token->getType()) { - if ('.' == $token->getValue() || '[' == $token->getValue()) { - $node = $this->parseSubscriptExpression($node); - } elseif ('|' == $token->getValue()) { - $node = $this->parseFilterExpression($node); - } else { - break; - } - } else { - break; - } - } - - return $node; - } - - public function getFunctionNode($name, $line) - { - switch ($name) { - case 'parent': - $this->parseArguments(); - if (!count($this->parser->getBlockStack())) { - throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); - } - - if (!$this->parser->getParent() && !$this->parser->hasTraits()) { - throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); - } - - return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); - case 'block': - $args = $this->parseArguments(); - if (count($args) < 1) { - throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); - } - - return new Twig_Node_Expression_BlockReference($args->getNode(0), count($args) > 1 ? $args->getNode(1) : null, $line); - case 'attribute': - $args = $this->parseArguments(); - if (count($args) < 2) { - throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); - } - - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line); - default: - if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { - $arguments = new Twig_Node_Expression_Array([], $line); - foreach ($this->parseArguments() as $n) { - $arguments->addElement($n); - } - - $node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line); - $node->setAttribute('safe', true); - - return $node; - } - - $args = $this->parseArguments(true); - $class = $this->getFunctionNodeClass($name, $line); - - return new $class($name, $args, $line); - } - } - - public function parseSubscriptExpression($node) - { - $stream = $this->parser->getStream(); - $token = $stream->next(); - $lineno = $token->getLine(); - $arguments = new Twig_Node_Expression_Array([], $lineno); - $type = Twig_Template::ANY_CALL; - if ('.' == $token->getValue()) { - $token = $stream->next(); - if ( - Twig_Token::NAME_TYPE == $token->getType() - || - Twig_Token::NUMBER_TYPE == $token->getType() - || - (Twig_Token::OPERATOR_TYPE == $token->getType() && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) - ) { - $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno); - - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $type = Twig_Template::METHOD_CALL; - foreach ($this->parseArguments() as $n) { - $arguments->addElement($n); - } - } - } else { - throw new Twig_Error_Syntax('Expected name or number.', $lineno, $stream->getSourceContext()); - } - - if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { - if (!$arg instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); - } - - $name = $arg->getAttribute('value'); - - if ($this->parser->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); - } - - $node = new Twig_Node_Expression_MethodCall($node, 'get'.$name, $arguments, $lineno); - $node->setAttribute('safe', true); - - return $node; - } - } else { - $type = Twig_Template::ARRAY_CALL; - - // slice? - $slice = false; - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) { - $slice = true; - $arg = new Twig_Node_Expression_Constant(0, $token->getLine()); - } else { - $arg = $this->parseExpression(); - } - - if ($stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { - $slice = true; - } - - if ($slice) { - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) { - $length = new Twig_Node_Expression_Constant(null, $token->getLine()); - } else { - $length = $this->parseExpression(); - } - - $class = $this->getFilterNodeClass('slice', $token->getLine()); - $arguments = new Twig_Node([$arg, $length]); - $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine()); - - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']'); - - return $filter; - } - - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']'); - } - - return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno); - } - - public function parseFilterExpression($node) - { - $this->parser->getStream()->next(); - - return $this->parseFilterExpressionRaw($node); - } - - public function parseFilterExpressionRaw($node, $tag = null) - { - while (true) { - $token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE); - - $name = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $arguments = new Twig_Node(); - } else { - $arguments = $this->parseArguments(true); - } - - $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine()); - - $node = new $class($node, $name, $arguments, $token->getLine(), $tag); - - if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '|')) { - break; - } - - $this->parser->getStream()->next(); - } - - return $node; - } - - /** - * Parses arguments. - * - * @param bool $namedArguments Whether to allow named arguments or not - * @param bool $definition Whether we are parsing arguments for a function definition - * - * @return Twig_Node - * - * @throws Twig_Error_Syntax - */ - public function parseArguments($namedArguments = false, $definition = false) - { - $args = []; - $stream = $this->parser->getStream(); - - $stream->expect(Twig_Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis'); - while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ')')) { - if (!empty($args)) { - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma'); - } - - if ($definition) { - $token = $stream->expect(Twig_Token::NAME_TYPE, null, 'An argument must be a name'); - $value = new Twig_Node_Expression_Name($token->getValue(), $this->parser->getCurrentToken()->getLine()); - } else { - $value = $this->parseExpression(); - } - - $name = null; - if ($namedArguments && $token = $stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) { - if (!$value instanceof Twig_Node_Expression_Name) { - throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', get_class($value)), $token->getLine(), $stream->getSourceContext()); - } - $name = $value->getAttribute('name'); - - if ($definition) { - $value = $this->parsePrimaryExpression(); - - if (!$this->checkConstantExpression($value)) { - throw new Twig_Error_Syntax(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); - } - } else { - $value = $this->parseExpression(); - } - } - - if ($definition) { - if (null === $name) { - $name = $value->getAttribute('name'); - $value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine()); - } - $args[$name] = $value; - } else { - if (null === $name) { - $args[] = $value; - } else { - $args[$name] = $value; - } - } - } - $stream->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis'); - - return new Twig_Node($args); - } - - public function parseAssignmentExpression() - { - $stream = $this->parser->getStream(); - $targets = []; - while (true) { - $token = $stream->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to'); - $value = $token->getValue(); - if (in_array(strtolower($value), ['true', 'false', 'none', 'null'])) { - throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); - } - $targets[] = new Twig_Node_Expression_AssignName($value, $token->getLine()); - - if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { - break; - } - } - - return new Twig_Node($targets); - } - - public function parseMultitargetExpression() - { - $targets = []; - while (true) { - $targets[] = $this->parseExpression(); - if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { - break; - } - } - - return new Twig_Node($targets); - } - - private function parseNotTestExpression(Twig_NodeInterface $node) - { - return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); - } - - private function parseTestExpression(Twig_NodeInterface $node) - { - $stream = $this->parser->getStream(); - list($name, $test) = $this->getTest($node->getTemplateLine()); - - $class = $this->getTestNodeClass($test); - $arguments = null; - if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $arguments = $this->parser->getExpressionParser()->parseArguments(true); - } - - return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine()); - } - - private function getTest($line) - { - $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - if ($test = $this->env->getTest($name)) { - return [$name, $test]; - } - - if ($stream->test(Twig_Token::NAME_TYPE)) { - // try 2-words tests - $name = $name.' '.$this->parser->getCurrentToken()->getValue(); - - if ($test = $this->env->getTest($name)) { - $stream->next(); - - return [$name, $test]; - } - } - - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); - $e->addSuggestions($name, array_keys($this->env->getTests())); - - throw $e; - } - - private function getTestNodeClass($test) - { - if ($test instanceof Twig_SimpleTest && $test->isDeprecated()) { - $stream = $this->parser->getStream(); - $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); - if (!is_bool($test->getDeprecatedVersion())) { - $message .= sprintf(' since version %s', $test->getDeprecatedVersion()); - } - if ($test->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $test->getAlternative()); - } - $src = $stream->getSourceContext(); - $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $stream->getCurrent()->getLine()); - - @trigger_error($message, E_USER_DEPRECATED); - } - - if ($test instanceof Twig_SimpleTest) { - return $test->getNodeClass(); - } - - return $test instanceof Twig_Test_Node ? $test->getClass() : 'Twig_Node_Expression_Test'; - } - - protected function getFunctionNodeClass($name, $line) - { - if (false === $function = $this->env->getFunction($name)) { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); - $e->addSuggestions($name, array_keys($this->env->getFunctions())); - - throw $e; - } - - if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) { - $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); - if (!is_bool($function->getDeprecatedVersion())) { - $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); - } - if ($function->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $function->getAlternative()); - } - $src = $this->parser->getStream()->getSourceContext(); - $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line); - - @trigger_error($message, E_USER_DEPRECATED); - } - - if ($function instanceof Twig_SimpleFunction) { - return $function->getNodeClass(); - } - - return $function instanceof Twig_Function_Node ? $function->getClass() : 'Twig_Node_Expression_Function'; - } - - protected function getFilterNodeClass($name, $line) - { - if (false === $filter = $this->env->getFilter($name)) { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); - $e->addSuggestions($name, array_keys($this->env->getFilters())); - - throw $e; - } - - if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) { - $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); - if (!is_bool($filter->getDeprecatedVersion())) { - $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); - } - if ($filter->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); - } - $src = $this->parser->getStream()->getSourceContext(); - $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line); - - @trigger_error($message, E_USER_DEPRECATED); - } - - if ($filter instanceof Twig_SimpleFilter) { - return $filter->getNodeClass(); - } - - return $filter instanceof Twig_Filter_Node ? $filter->getClass() : 'Twig_Node_Expression_Filter'; - } - - // checks that the node only contains "constant" elements - protected function checkConstantExpression(Twig_NodeInterface $node) - { - if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array - || $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos - )) { - return false; - } - - foreach ($node as $n) { - if (!$this->checkConstantExpression($n)) { - return false; - } - } - - return true; - } -} - -class_alias('Twig_ExpressionParser', 'Twig\ExpressionParser', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension.php b/system/templateEngines/Twig/Twig1x/Extension.php deleted file mode 100644 index de93ca6..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension.php +++ /dev/null @@ -1,69 +0,0 @@ -escapers[$strategy] = $callable; - } - - /** - * Gets all defined escapers. - * - * @return array An array of escapers - */ - public function getEscapers() - { - return $this->escapers; - } - - /** - * Sets the default format to be used by the date filter. - * - * @param string $format The default date format string - * @param string $dateIntervalFormat The default date interval format string - */ - public function setDateFormat($format = null, $dateIntervalFormat = null) - { - if (null !== $format) { - $this->dateFormats[0] = $format; - } - - if (null !== $dateIntervalFormat) { - $this->dateFormats[1] = $dateIntervalFormat; - } - } - - /** - * Gets the default format to be used by the date filter. - * - * @return array The default date format string and the default date interval format string - */ - public function getDateFormat() - { - return $this->dateFormats; - } - - /** - * Sets the default timezone to be used by the date filter. - * - * @param DateTimeZone|string $timezone The default timezone string or a DateTimeZone object - */ - public function setTimezone($timezone) - { - $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); - } - - /** - * Gets the default timezone to be used by the date filter. - * - * @return DateTimeZone The default timezone currently in use - */ - public function getTimezone() - { - if (null === $this->timezone) { - $this->timezone = new DateTimeZone(date_default_timezone_get()); - } - - return $this->timezone; - } - - /** - * Sets the default format to be used by the number_format filter. - * - * @param int $decimal the number of decimal places to use - * @param string $decimalPoint the character(s) to use for the decimal point - * @param string $thousandSep the character(s) to use for the thousands separator - */ - public function setNumberFormat($decimal, $decimalPoint, $thousandSep) - { - $this->numberFormat = [$decimal, $decimalPoint, $thousandSep]; - } - - /** - * Get the default format used by the number_format filter. - * - * @return array The arguments for number_format() - */ - public function getNumberFormat() - { - return $this->numberFormat; - } - - public function getTokenParsers() - { - return [ - new Twig_TokenParser_For(), - new Twig_TokenParser_If(), - new Twig_TokenParser_Extends(), - new Twig_TokenParser_Include(), - new Twig_TokenParser_Block(), - new Twig_TokenParser_Use(), - new Twig_TokenParser_Filter(), - new Twig_TokenParser_Macro(), - new Twig_TokenParser_Import(), - new Twig_TokenParser_From(), - new Twig_TokenParser_Set(), - new Twig_TokenParser_Spaceless(), - new Twig_TokenParser_Flush(), - new Twig_TokenParser_Do(), - new Twig_TokenParser_Embed(), - new Twig_TokenParser_With(), - new Twig_TokenParser_Deprecated(), - ]; - } - - public function getFilters() - { - $filters = [ - // formatting filters - new Twig_SimpleFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('format', 'sprintf'), - new Twig_SimpleFilter('replace', 'twig_replace_filter'), - new Twig_SimpleFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('abs', 'abs'), - new Twig_SimpleFilter('round', 'twig_round'), - - // encoding - new Twig_SimpleFilter('url_encode', 'twig_urlencode_filter'), - new Twig_SimpleFilter('json_encode', 'twig_jsonencode_filter'), - new Twig_SimpleFilter('convert_encoding', 'twig_convert_encoding'), - - // string filters - new Twig_SimpleFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('upper', 'strtoupper'), - new Twig_SimpleFilter('lower', 'strtolower'), - new Twig_SimpleFilter('striptags', 'strip_tags'), - new Twig_SimpleFilter('trim', 'twig_trim_filter'), - new Twig_SimpleFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), - - // array helpers - new Twig_SimpleFilter('join', 'twig_join_filter'), - new Twig_SimpleFilter('split', 'twig_split_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('sort', 'twig_sort_filter'), - new Twig_SimpleFilter('merge', 'twig_array_merge'), - new Twig_SimpleFilter('batch', 'twig_array_batch'), - - // string/array filters - new Twig_SimpleFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('length', 'twig_length_filter', ['needs_environment' => true]), - new Twig_SimpleFilter('slice', 'twig_slice', ['needs_environment' => true]), - new Twig_SimpleFilter('first', 'twig_first', ['needs_environment' => true]), - new Twig_SimpleFilter('last', 'twig_last', ['needs_environment' => true]), - - // iteration and runtime - new Twig_SimpleFilter('default', '_twig_default_filter', ['node_class' => 'Twig_Node_Expression_Filter_Default']), - new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'), - - // escaping - new Twig_SimpleFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), - new Twig_SimpleFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), - ]; - - if (function_exists('mb_get_info')) { - $filters[] = new Twig_SimpleFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); - $filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); - } - - return $filters; - } - - public function getFunctions() - { - return [ - new Twig_SimpleFunction('max', 'max'), - new Twig_SimpleFunction('min', 'min'), - new Twig_SimpleFunction('range', 'range'), - new Twig_SimpleFunction('constant', 'twig_constant'), - new Twig_SimpleFunction('cycle', 'twig_cycle'), - new Twig_SimpleFunction('random', 'twig_random', ['needs_environment' => true]), - new Twig_SimpleFunction('date', 'twig_date_converter', ['needs_environment' => true]), - new Twig_SimpleFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), - new Twig_SimpleFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), - ]; - } - - public function getTests() - { - return [ - new Twig_SimpleTest('even', null, ['node_class' => 'Twig_Node_Expression_Test_Even']), - new Twig_SimpleTest('odd', null, ['node_class' => 'Twig_Node_Expression_Test_Odd']), - new Twig_SimpleTest('defined', null, ['node_class' => 'Twig_Node_Expression_Test_Defined']), - new Twig_SimpleTest('sameas', null, ['node_class' => 'Twig_Node_Expression_Test_Sameas', 'deprecated' => '1.21', 'alternative' => 'same as']), - new Twig_SimpleTest('same as', null, ['node_class' => 'Twig_Node_Expression_Test_Sameas']), - new Twig_SimpleTest('none', null, ['node_class' => 'Twig_Node_Expression_Test_Null']), - new Twig_SimpleTest('null', null, ['node_class' => 'Twig_Node_Expression_Test_Null']), - new Twig_SimpleTest('divisibleby', null, ['node_class' => 'Twig_Node_Expression_Test_Divisibleby', 'deprecated' => '1.21', 'alternative' => 'divisible by']), - new Twig_SimpleTest('divisible by', null, ['node_class' => 'Twig_Node_Expression_Test_Divisibleby']), - new Twig_SimpleTest('constant', null, ['node_class' => 'Twig_Node_Expression_Test_Constant']), - new Twig_SimpleTest('empty', 'twig_test_empty'), - new Twig_SimpleTest('iterable', 'twig_test_iterable'), - ]; - } - - public function getOperators() - { - return [ - [ - 'not' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'], - '-' => ['precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'], - '+' => ['precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'], - ], - [ - 'or' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'and' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-or' => ['precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-xor' => ['precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-and' => ['precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '==' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '!=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '<' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '>' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '>=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '<=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'not in' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'in' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'matches' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Matches', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'starts with' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_StartsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'ends with' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_EndsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '..' => ['precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '+' => ['precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '-' => ['precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '~' => ['precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '*' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mul', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '/' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Div', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '//' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_FloorDiv', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '%' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'is' => ['precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'is not' => ['precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '**' => ['precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT], - '??' => ['precedence' => 300, 'class' => 'Twig_Node_Expression_NullCoalesce', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT], - ], - ]; - } - - public function getName() - { - return 'core'; - } -} - -/** - * Cycles over a value. - * - * @param ArrayAccess|array $values - * @param int $position The cycle position - * - * @return string The next value in the cycle - */ -function twig_cycle($values, $position) -{ - if (!is_array($values) && !$values instanceof ArrayAccess) { - return $values; - } - - return $values[$position % count($values)]; -} - -/** - * Returns a random value depending on the supplied parameter type: - * - a random item from a Traversable or array - * - a random character from a string - * - a random integer between 0 and the integer parameter. - * - * @param Twig_Environment $env - * @param Traversable|array|int|float|string $values The values to pick a random item from - * - * @throws Twig_Error_Runtime when $values is an empty array (does not apply to an empty string which is returned as is) - * - * @return mixed A random value from the given sequence - */ -function twig_random(Twig_Environment $env, $values = null) -{ - if (null === $values) { - return mt_rand(); - } - - if (is_int($values) || is_float($values)) { - return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values); - } - - if ($values instanceof Traversable) { - $values = iterator_to_array($values); - } elseif (is_string($values)) { - if ('' === $values) { - return ''; - } - if (null !== $charset = $env->getCharset()) { - if ('UTF-8' !== $charset) { - $values = twig_convert_encoding($values, 'UTF-8', $charset); - } - - // unicode version of str_split() - // split at all positions, but not after the start and not before the end - $values = preg_split('/(? $value) { - $values[$i] = twig_convert_encoding($value, $charset, 'UTF-8'); - } - } - } else { - return $values[mt_rand(0, strlen($values) - 1)]; - } - } - - if (!is_array($values)) { - return $values; - } - - if (0 === count($values)) { - throw new Twig_Error_Runtime('The random function cannot pick from an empty array.'); - } - - return $values[array_rand($values, 1)]; -} - -/** - * Converts a date to the given format. - * - *
- *   {{ post.published_at|date("m/d/Y") }}
- * 
- * - * @param Twig_Environment $env - * @param DateTime|DateTimeInterface|DateInterval|string $date A date - * @param string|null $format The target format, null to use the default - * @param DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged - * - * @return string The formatted date - */ -function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) -{ - if (null === $format) { - $formats = $env->getExtension('Twig_Extension_Core')->getDateFormat(); - $format = $date instanceof DateInterval ? $formats[1] : $formats[0]; - } - - if ($date instanceof DateInterval) { - return $date->format($format); - } - - return twig_date_converter($env, $date, $timezone)->format($format); -} - -/** - * Returns a new date object modified. - * - *
- *   {{ post.published_at|date_modify("-1day")|date("m/d/Y") }}
- * 
- * - * @param Twig_Environment $env - * @param DateTime|string $date A date - * @param string $modifier A modifier string - * - * @return DateTime A new date object - */ -function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) -{ - $date = twig_date_converter($env, $date, false); - $resultDate = $date->modify($modifier); - - // This is a hack to ensure PHP 5.2 support and support for DateTimeImmutable - // DateTime::modify does not return the modified DateTime object < 5.3.0 - // and DateTimeImmutable does not modify $date. - return null === $resultDate ? $date : $resultDate; -} - -/** - * Converts an input to a DateTime instance. - * - *
- *    {% if date(user.created_at) < date('+2days') %}
- *      {# do something #}
- *    {% endif %}
- * 
- * - * @param Twig_Environment $env - * @param DateTime|DateTimeInterface|string|null $date A date - * @param DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged - * - * @return DateTime A DateTime instance - */ -function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) -{ - // determine the timezone - if (false !== $timezone) { - if (null === $timezone) { - $timezone = $env->getExtension('Twig_Extension_Core')->getTimezone(); - } elseif (!$timezone instanceof DateTimeZone) { - $timezone = new DateTimeZone($timezone); - } - } - - // immutable dates - if ($date instanceof DateTimeImmutable) { - return false !== $timezone ? $date->setTimezone($timezone) : $date; - } - - if ($date instanceof DateTime || $date instanceof DateTimeInterface) { - $date = clone $date; - if (false !== $timezone) { - $date->setTimezone($timezone); - } - - return $date; - } - - if (null === $date || 'now' === $date) { - return new DateTime($date, false !== $timezone ? $timezone : $env->getExtension('Twig_Extension_Core')->getTimezone()); - } - - $asString = (string) $date; - if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { - $date = new DateTime('@'.$date); - } else { - $date = new DateTime($date, $env->getExtension('Twig_Extension_Core')->getTimezone()); - } - - if (false !== $timezone) { - $date->setTimezone($timezone); - } - - return $date; -} - -/** - * Replaces strings within a string. - * - * @param string $str String to replace in - * @param array|Traversable $from Replace values - * @param string|null $to Replace to, deprecated (@see https://secure.php.net/manual/en/function.strtr.php) - * - * @return string - */ -function twig_replace_filter($str, $from, $to = null) -{ - if ($from instanceof Traversable) { - $from = iterator_to_array($from); - } elseif (is_string($from) && is_string($to)) { - @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); - - return strtr($str, $from, $to); - } elseif (!is_array($from)) { - throw new Twig_Error_Runtime(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', is_object($from) ? get_class($from) : gettype($from))); - } - - return strtr($str, $from); -} - -/** - * Rounds a number. - * - * @param int|float $value The value to round - * @param int|float $precision The rounding precision - * @param string $method The method to use for rounding - * - * @return int|float The rounded number - */ -function twig_round($value, $precision = 0, $method = 'common') -{ - if ('common' == $method) { - return round($value, $precision); - } - - if ('ceil' != $method && 'floor' != $method) { - throw new Twig_Error_Runtime('The round filter only supports the "common", "ceil", and "floor" methods.'); - } - - return $method($value * pow(10, $precision)) / pow(10, $precision); -} - -/** - * Number format filter. - * - * All of the formatting options can be left null, in that case the defaults will - * be used. Supplying any of the parameters will override the defaults set in the - * environment object. - * - * @param Twig_Environment $env - * @param mixed $number A float/int/string of the number to format - * @param int $decimal the number of decimal points to display - * @param string $decimalPoint the character(s) to use for the decimal point - * @param string $thousandSep the character(s) to use for the thousands separator - * - * @return string The formatted number - */ -function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) -{ - $defaults = $env->getExtension('Twig_Extension_Core')->getNumberFormat(); - if (null === $decimal) { - $decimal = $defaults[0]; - } - - if (null === $decimalPoint) { - $decimalPoint = $defaults[1]; - } - - if (null === $thousandSep) { - $thousandSep = $defaults[2]; - } - - return number_format((float) $number, $decimal, $decimalPoint, $thousandSep); -} - -/** - * URL encodes (RFC 3986) a string as a path segment or an array as a query string. - * - * @param string|array $url A URL or an array of query parameters - * - * @return string The URL encoded value - */ -function twig_urlencode_filter($url) -{ - if (is_array($url)) { - if (defined('PHP_QUERY_RFC3986')) { - return http_build_query($url, '', '&', PHP_QUERY_RFC3986); - } - - return http_build_query($url, '', '&'); - } - - return rawurlencode($url); -} - -/** - * JSON encodes a variable. - * - * @param mixed $value the value to encode - * @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 - * - * @return mixed The JSON encoded value - */ -function twig_jsonencode_filter($value, $options = 0) -{ - if ($value instanceof Twig_Markup) { - $value = (string) $value; - } elseif (is_array($value)) { - array_walk_recursive($value, '_twig_markup2string'); - } - - return json_encode($value, $options); -} - -function _twig_markup2string(&$value) -{ - if ($value instanceof Twig_Markup) { - $value = (string) $value; - } -} - -/** - * Merges an array with another one. - * - *
- *  {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}
- *
- *  {% set items = items|merge({ 'peugeot': 'car' }) %}
- *
- *  {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #}
- * 
- * - * @param array|Traversable $arr1 An array - * @param array|Traversable $arr2 An array - * - * @return array The merged array - */ -function twig_array_merge($arr1, $arr2) -{ - if ($arr1 instanceof Traversable) { - $arr1 = iterator_to_array($arr1); - } elseif (!is_array($arr1)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', gettype($arr1))); - } - - if ($arr2 instanceof Traversable) { - $arr2 = iterator_to_array($arr2); - } elseif (!is_array($arr2)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', gettype($arr2))); - } - - return array_merge($arr1, $arr2); -} - -/** - * Slices a variable. - * - * @param Twig_Environment $env - * @param mixed $item A variable - * @param int $start Start of the slice - * @param int $length Size of the slice - * @param bool $preserveKeys Whether to preserve key or not (when the input is an array) - * - * @return mixed The sliced variable - */ -function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) -{ - if ($item instanceof Traversable) { - while ($item instanceof IteratorAggregate) { - $item = $item->getIterator(); - } - - if ($start >= 0 && $length >= 0 && $item instanceof Iterator) { - try { - return iterator_to_array(new LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys); - } catch (OutOfBoundsException $exception) { - return []; - } - } - - $item = iterator_to_array($item, $preserveKeys); - } - - if (is_array($item)) { - return array_slice($item, $start, $length, $preserveKeys); - } - - $item = (string) $item; - - if (function_exists('mb_get_info') && null !== $charset = $env->getCharset()) { - return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); - } - - return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length)); -} - -/** - * Returns the first element of the item. - * - * @param Twig_Environment $env - * @param mixed $item A variable - * - * @return mixed The first element of the item - */ -function twig_first(Twig_Environment $env, $item) -{ - $elements = twig_slice($env, $item, 0, 1, false); - - return is_string($elements) ? $elements : current($elements); -} - -/** - * Returns the last element of the item. - * - * @param Twig_Environment $env - * @param mixed $item A variable - * - * @return mixed The last element of the item - */ -function twig_last(Twig_Environment $env, $item) -{ - $elements = twig_slice($env, $item, -1, 1, false); - - return is_string($elements) ? $elements : current($elements); -} - -/** - * Joins the values to a string. - * - * The separators between elements are empty strings per default, you can define them with the optional parameters. - * - *
- *  {{ [1, 2, 3]|join(', ', ' and ') }}
- *  {# returns 1, 2 and 3 #}
- *
- *  {{ [1, 2, 3]|join('|') }}
- *  {# returns 1|2|3 #}
- *
- *  {{ [1, 2, 3]|join }}
- *  {# returns 123 #}
- * 
- * - * @param array $value An array - * @param string $glue The separator - * @param string|null $and The separator for the last pair - * - * @return string The concatenated string - */ -function twig_join_filter($value, $glue = '', $and = null) -{ - if ($value instanceof Traversable) { - $value = iterator_to_array($value, false); - } else { - $value = (array) $value; - } - - if (0 === count($value)) { - return ''; - } - - if (null === $and || $and === $glue) { - return implode($glue, $value); - } - - $v = array_values($value); - if (1 === count($v)) { - return $v[0]; - } - - return implode($glue, array_slice($value, 0, -1)).$and.$v[count($v) - 1]; -} - -/** - * Splits the string into an array. - * - *
- *  {{ "one,two,three"|split(',') }}
- *  {# returns [one, two, three] #}
- *
- *  {{ "one,two,three,four,five"|split(',', 3) }}
- *  {# returns [one, two, "three,four,five"] #}
- *
- *  {{ "123"|split('') }}
- *  {# returns [1, 2, 3] #}
- *
- *  {{ "aabbcc"|split('', 2) }}
- *  {# returns [aa, bb, cc] #}
- * 
- * - * @param Twig_Environment $env - * @param string $value A string - * @param string $delimiter The delimiter - * @param int $limit The limit - * - * @return array The split string as an array - */ -function twig_split_filter(Twig_Environment $env, $value, $delimiter, $limit = null) -{ - if (!empty($delimiter)) { - return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); - } - - if (!function_exists('mb_get_info') || null === $charset = $env->getCharset()) { - return str_split($value, null === $limit ? 1 : $limit); - } - - if ($limit <= 1) { - return preg_split('/(? - * {% for key in array|keys %} - * {# ... #} - * {% endfor %} - * - * - * @param array $array An array - * - * @return array The keys - */ -function twig_get_array_keys_filter($array) -{ - if ($array instanceof Traversable) { - while ($array instanceof IteratorAggregate) { - $array = $array->getIterator(); - } - - if ($array instanceof Iterator) { - $keys = []; - $array->rewind(); - while ($array->valid()) { - $keys[] = $array->key(); - $array->next(); - } - - return $keys; - } - - $keys = []; - foreach ($array as $key => $item) { - $keys[] = $key; - } - - return $keys; - } - - if (!is_array($array)) { - return []; - } - - return array_keys($array); -} - -/** - * Reverses a variable. - * - * @param Twig_Environment $env - * @param array|Traversable|string $item An array, a Traversable instance, or a string - * @param bool $preserveKeys Whether to preserve key or not - * - * @return mixed The reversed input - */ -function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false) -{ - if ($item instanceof Traversable) { - return array_reverse(iterator_to_array($item), $preserveKeys); - } - - if (is_array($item)) { - return array_reverse($item, $preserveKeys); - } - - if (null !== $charset = $env->getCharset()) { - $string = (string) $item; - - if ('UTF-8' !== $charset) { - $item = twig_convert_encoding($string, 'UTF-8', $charset); - } - - preg_match_all('/./us', $item, $matches); - - $string = implode('', array_reverse($matches[0])); - - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, $charset, 'UTF-8'); - } - - return $string; - } - - return strrev((string) $item); -} - -/** - * Sorts an array. - * - * @param array|Traversable $array - * - * @return array - */ -function twig_sort_filter($array) -{ - if ($array instanceof Traversable) { - $array = iterator_to_array($array); - } elseif (!is_array($array)) { - throw new Twig_Error_Runtime(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', gettype($array))); - } - - asort($array); - - return $array; -} - -/** - * @internal - */ -function twig_in_filter($value, $compare) -{ - if (is_array($compare)) { - return in_array($value, $compare, is_object($value) || is_resource($value)); - } elseif (is_string($compare) && (is_string($value) || is_int($value) || is_float($value))) { - return '' === $value || false !== strpos($compare, (string) $value); - } elseif ($compare instanceof Traversable) { - if (is_object($value) || is_resource($value)) { - foreach ($compare as $item) { - if ($item === $value) { - return true; - } - } - } else { - foreach ($compare as $item) { - if ($item == $value) { - return true; - } - } - } - - return false; - } - - return false; -} - -/** - * Returns a trimmed string. - * - * @return string - * - * @throws Twig_Error_Runtime When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') - */ -function twig_trim_filter($string, $characterMask = null, $side = 'both') -{ - if (null === $characterMask) { - $characterMask = " \t\n\r\0\x0B"; - } - - switch ($side) { - case 'both': - return trim($string, $characterMask); - case 'left': - return ltrim($string, $characterMask); - case 'right': - return rtrim($string, $characterMask); - default: - throw new Twig_Error_Runtime('Trimming side must be "left", "right" or "both".'); - } -} - -/** - * Escapes a string. - * - * @param Twig_Environment $env - * @param mixed $string The value to be escaped - * @param string $strategy The escaping strategy - * @param string $charset The charset - * @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false) - * - * @return string - */ -function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) -{ - if ($autoescape && $string instanceof Twig_Markup) { - return $string; - } - - if (!is_string($string)) { - if (is_object($string) && method_exists($string, '__toString')) { - $string = (string) $string; - } elseif (in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { - return $string; - } - } - - if ('' === $string) { - return ''; - } - - if (null === $charset) { - $charset = $env->getCharset(); - } - - switch ($strategy) { - case 'html': - // see https://secure.php.net/htmlspecialchars - - // Using a static variable to avoid initializing the array - // each time the function is called. Moving the declaration on the - // top of the function slow downs other escaping strategies. - static $htmlspecialcharsCharsets = [ - 'ISO-8859-1' => true, 'ISO8859-1' => true, - 'ISO-8859-15' => true, 'ISO8859-15' => true, - 'utf-8' => true, 'UTF-8' => true, - 'CP866' => true, 'IBM866' => true, '866' => true, - 'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true, - '1251' => true, - 'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true, - 'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true, - 'BIG5' => true, '950' => true, - 'GB2312' => true, '936' => true, - 'BIG5-HKSCS' => true, - 'SHIFT_JIS' => true, 'SJIS' => true, '932' => true, - 'EUC-JP' => true, 'EUCJP' => true, - 'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true, - ]; - - if (isset($htmlspecialcharsCharsets[$charset])) { - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); - } - - if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { - // cache the lowercase variant for future iterations - $htmlspecialcharsCharsets[$charset] = true; - - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); - } - - $string = twig_convert_encoding($string, 'UTF-8', $charset); - $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); - - return twig_convert_encoding($string, $charset, 'UTF-8'); - - case 'js': - // escape all non-alphanumeric characters - // into their \x or \uHHHH representations - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, 'UTF-8', $charset); - } - - if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); - } - - $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string); - - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, $charset, 'UTF-8'); - } - - return $string; - - case 'css': - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, 'UTF-8', $charset); - } - - if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); - } - - $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string); - - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, $charset, 'UTF-8'); - } - - return $string; - - case 'html_attr': - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, 'UTF-8', $charset); - } - - if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); - } - - $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string); - - if ('UTF-8' !== $charset) { - $string = twig_convert_encoding($string, $charset, 'UTF-8'); - } - - return $string; - - case 'url': - return rawurlencode($string); - - default: - static $escapers; - - if (null === $escapers) { - $escapers = $env->getExtension('Twig_Extension_Core')->getEscapers(); - } - - if (isset($escapers[$strategy])) { - return call_user_func($escapers[$strategy], $env, $string, $charset); - } - - $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); - - throw new Twig_Error_Runtime(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); - } -} - -/** - * @internal - */ -function twig_escape_filter_is_safe(Twig_Node $filterArgs) -{ - foreach ($filterArgs as $arg) { - if ($arg instanceof Twig_Node_Expression_Constant) { - return [$arg->getAttribute('value')]; - } - - return []; - } - - return ['html']; -} - -if (function_exists('mb_convert_encoding')) { - function twig_convert_encoding($string, $to, $from) - { - return mb_convert_encoding($string, $to, $from); - } -} elseif (function_exists('iconv')) { - function twig_convert_encoding($string, $to, $from) - { - return iconv($from, $to, $string); - } -} else { - function twig_convert_encoding($string, $to, $from) - { - throw new Twig_Error_Runtime('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); - } -} - -if (function_exists('mb_ord')) { - function twig_ord($string) - { - return mb_ord($string, 'UTF-8'); - } -} else { - function twig_ord($string) - { - $code = ($string = unpack('C*', substr($string, 0, 4))) ? $string[1] : 0; - if (0xF0 <= $code) { - return (($code - 0xF0) << 18) + (($string[2] - 0x80) << 12) + (($string[3] - 0x80) << 6) + $string[4] - 0x80; - } - if (0xE0 <= $code) { - return (($code - 0xE0) << 12) + (($string[2] - 0x80) << 6) + $string[3] - 0x80; - } - if (0xC0 <= $code) { - return (($code - 0xC0) << 6) + $string[2] - 0x80; - } - - return $code; - } -} - -function _twig_escape_js_callback($matches) -{ - $char = $matches[0]; - - /* - * A few characters have short escape sequences in JSON and JavaScript. - * Escape sequences supported only by JavaScript, not JSON, are ommitted. - * \" is also supported but omitted, because the resulting string is not HTML safe. - */ - static $shortMap = [ - '\\' => '\\\\', - '/' => '\\/', - "\x08" => '\b', - "\x0C" => '\f', - "\x0A" => '\n', - "\x0D" => '\r', - "\x09" => '\t', - ]; - - if (isset($shortMap[$char])) { - return $shortMap[$char]; - } - - // \uHHHH - $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); - $char = strtoupper(bin2hex($char)); - - if (4 >= strlen($char)) { - return sprintf('\u%04s', $char); - } - - return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4)); -} - -function _twig_escape_css_callback($matches) -{ - $char = $matches[0]; - - return sprintf('\\%X ', 1 === strlen($char) ? ord($char) : twig_ord($char)); -} - -/** - * This function is adapted from code coming from Zend Framework. - * - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com) - * @license https://framework.zend.com/license/new-bsd New BSD License - */ -function _twig_escape_html_attr_callback($matches) -{ - $chr = $matches[0]; - $ord = ord($chr); - - /* - * The following replaces characters undefined in HTML with the - * hex entity for the Unicode replacement character. - */ - if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) { - return '�'; - } - - /* - * Check if the current character to escape has a name entity we should - * replace it with while grabbing the hex value of the character. - */ - if (1 == strlen($chr)) { - /* - * While HTML supports far more named entities, the lowest common denominator - * has become HTML5's XML Serialisation which is restricted to the those named - * entities that XML supports. Using HTML entities would result in this error: - * XML Parsing Error: undefined entity - */ - static $entityMap = [ - 34 => '"', /* quotation mark */ - 38 => '&', /* ampersand */ - 60 => '<', /* less-than sign */ - 62 => '>', /* greater-than sign */ - ]; - - if (isset($entityMap[$ord])) { - return $entityMap[$ord]; - } - - return sprintf('&#x%02X;', $ord); - } - - /* - * Per OWASP recommendations, we'll use hex entities for any other - * characters where a named entity does not exist. - */ - return sprintf('&#x%04X;', twig_ord($chr)); -} - -// add multibyte extensions if possible -if (function_exists('mb_get_info')) { - /** - * Returns the length of a variable. - * - * @param Twig_Environment $env - * @param mixed $thing A variable - * - * @return int The length of the value - */ - function twig_length_filter(Twig_Environment $env, $thing) - { - if (null === $thing) { - return 0; - } - - if (is_scalar($thing)) { - return mb_strlen($thing, $env->getCharset()); - } - - if ($thing instanceof \SimpleXMLElement) { - return count($thing); - } - - if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { - return mb_strlen((string) $thing, $env->getCharset()); - } - - if ($thing instanceof \Countable || is_array($thing)) { - return count($thing); - } - - if ($thing instanceof \IteratorAggregate) { - return iterator_count($thing); - } - - return 1; - } - - /** - * Converts a string to uppercase. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The uppercased string - */ - function twig_upper_filter(Twig_Environment $env, $string) - { - if (null !== $charset = $env->getCharset()) { - return mb_strtoupper($string, $charset); - } - - return strtoupper($string); - } - - /** - * Converts a string to lowercase. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The lowercased string - */ - function twig_lower_filter(Twig_Environment $env, $string) - { - if (null !== $charset = $env->getCharset()) { - return mb_strtolower($string, $charset); - } - - return strtolower($string); - } - - /** - * Returns a titlecased string. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The titlecased string - */ - function twig_title_string_filter(Twig_Environment $env, $string) - { - if (null !== $charset = $env->getCharset()) { - return mb_convert_case($string, MB_CASE_TITLE, $charset); - } - - return ucwords(strtolower($string)); - } - - /** - * Returns a capitalized string. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The capitalized string - */ - function twig_capitalize_string_filter(Twig_Environment $env, $string) - { - if (null !== $charset = $env->getCharset()) { - return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset); - } - - return ucfirst(strtolower($string)); - } -} -// and byte fallback -else { - /** - * Returns the length of a variable. - * - * @param Twig_Environment $env - * @param mixed $thing A variable - * - * @return int The length of the value - */ - function twig_length_filter(Twig_Environment $env, $thing) - { - if (null === $thing) { - return 0; - } - - if (is_scalar($thing)) { - return strlen($thing); - } - - if ($thing instanceof \SimpleXMLElement) { - return count($thing); - } - - if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { - return strlen((string) $thing); - } - - if ($thing instanceof \Countable || is_array($thing)) { - return count($thing); - } - - if ($thing instanceof \IteratorAggregate) { - return iterator_count($thing); - } - - return 1; - } - - /** - * Returns a titlecased string. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The titlecased string - */ - function twig_title_string_filter(Twig_Environment $env, $string) - { - return ucwords(strtolower($string)); - } - - /** - * Returns a capitalized string. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The capitalized string - */ - function twig_capitalize_string_filter(Twig_Environment $env, $string) - { - return ucfirst(strtolower($string)); - } -} - -/** - * @internal - */ -function twig_ensure_traversable($seq) -{ - if ($seq instanceof Traversable || is_array($seq)) { - return $seq; - } - - return []; -} - -/** - * Checks if a variable is empty. - * - *
- * {# evaluates to true if the foo variable is null, false, or the empty string #}
- * {% if foo is empty %}
- *     {# ... #}
- * {% endif %}
- * 
- * - * @param mixed $value A variable - * - * @return bool true if the value is empty, false otherwise - */ -function twig_test_empty($value) -{ - if ($value instanceof Countable) { - return 0 == count($value); - } - - if (is_object($value) && method_exists($value, '__toString')) { - return '' === (string) $value; - } - - return '' === $value || false === $value || null === $value || [] === $value; -} - -/** - * Checks if a variable is traversable. - * - *
- * {# evaluates to true if the foo variable is an array or a traversable object #}
- * {% if foo is iterable %}
- *     {# ... #}
- * {% endif %}
- * 
- * - * @param mixed $value A variable - * - * @return bool true if the value is traversable - */ -function twig_test_iterable($value) -{ - return $value instanceof Traversable || is_array($value); -} - -/** - * Renders a template. - * - * @param Twig_Environment $env - * @param array $context - * @param string|array $template The template to render or an array of templates to try consecutively - * @param array $variables The variables to pass to the template - * @param bool $withContext - * @param bool $ignoreMissing Whether to ignore missing templates or not - * @param bool $sandboxed Whether to sandbox the template or not - * - * @return string The rendered template - */ -function twig_include(Twig_Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) -{ - $alreadySandboxed = false; - $sandbox = null; - if ($withContext) { - $variables = array_merge($context, $variables); - } - - if ($isSandboxed = $sandboxed && $env->hasExtension('Twig_Extension_Sandbox')) { - $sandbox = $env->getExtension('Twig_Extension_Sandbox'); - if (!$alreadySandboxed = $sandbox->isSandboxed()) { - $sandbox->enableSandbox(); - } - } - - $result = ''; - try { - $result = $env->resolveTemplate($template)->render($variables); - } catch (Twig_Error_Loader $e) { - if (!$ignoreMissing) { - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - throw $e; - } - } catch (Throwable $e) { - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - throw $e; - } catch (Exception $e) { - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - throw $e; - } - - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - return $result; -} - -/** - * Returns a template content without rendering it. - * - * @param Twig_Environment $env - * @param string $name The template name - * @param bool $ignoreMissing Whether to ignore missing templates or not - * - * @return string The template source - */ -function twig_source(Twig_Environment $env, $name, $ignoreMissing = false) -{ - $loader = $env->getLoader(); - try { - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - return $loader->getSource($name); - } else { - return $loader->getSourceContext($name)->getCode(); - } - } catch (Twig_Error_Loader $e) { - if (!$ignoreMissing) { - throw $e; - } - } -} - -/** - * Provides the ability to get constants from instances as well as class/global constants. - * - * @param string $constant The name of the constant - * @param object|null $object The object to get the constant from - * - * @return string - */ -function twig_constant($constant, $object = null) -{ - if (null !== $object) { - $constant = get_class($object).'::'.$constant; - } - - return constant($constant); -} - -/** - * Checks if a constant exists. - * - * @param string $constant The name of the constant - * @param object|null $object The object to get the constant from - * - * @return bool - */ -function twig_constant_is_defined($constant, $object = null) -{ - if (null !== $object) { - $constant = get_class($object).'::'.$constant; - } - - return defined($constant); -} - -/** - * Batches item. - * - * @param array $items An array of items - * @param int $size The size of the batch - * @param mixed $fill A value used to fill missing items - * - * @return array - */ -function twig_array_batch($items, $size, $fill = null) -{ - if ($items instanceof Traversable) { - $items = iterator_to_array($items, false); - } - - $size = ceil($size); - - $result = array_chunk($items, $size, true); - - if (null !== $fill && !empty($result)) { - $last = count($result) - 1; - if ($fillCount = $size - count($result[$last])) { - $result[$last] = array_merge( - $result[$last], - array_fill(0, $fillCount, $fill) - ); - } - } - - return $result; -} - -class_alias('Twig_Extension_Core', 'Twig\Extension\CoreExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/Debug.php b/system/templateEngines/Twig/Twig1x/Extension/Debug.php deleted file mode 100644 index 87f47d6..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/Debug.php +++ /dev/null @@ -1,67 +0,0 @@ - $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]), - ]; - } - - public function getName() - { - return 'debug'; - } -} - -function twig_var_dump(Twig_Environment $env, $context) -{ - if (!$env->isDebug()) { - return; - } - - ob_start(); - - $count = func_num_args(); - if (2 === $count) { - $vars = []; - foreach ($context as $key => $value) { - if (!$value instanceof Twig_Template) { - $vars[$key] = $value; - } - } - - var_dump($vars); - } else { - for ($i = 2; $i < $count; ++$i) { - var_dump(func_get_arg($i)); - } - } - - return ob_get_clean(); -} - -class_alias('Twig_Extension_Debug', 'Twig\Extension\DebugExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/Escaper.php b/system/templateEngines/Twig/Twig1x/Extension/Escaper.php deleted file mode 100644 index 74f0e99..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/Escaper.php +++ /dev/null @@ -1,112 +0,0 @@ -setDefaultStrategy($defaultStrategy); - } - - public function getTokenParsers() - { - return [new Twig_TokenParser_AutoEscape()]; - } - - public function getNodeVisitors() - { - return [new Twig_NodeVisitor_Escaper()]; - } - - public function getFilters() - { - return [ - new Twig_SimpleFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), - ]; - } - - /** - * Sets the default strategy to use when not defined by the user. - * - * The strategy can be a valid PHP callback that takes the template - * name as an argument and returns the strategy to use. - * - * @param string|false|callable $defaultStrategy An escaping strategy - */ - public function setDefaultStrategy($defaultStrategy) - { - // for BC - if (true === $defaultStrategy) { - @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED); - - $defaultStrategy = 'html'; - } - - if ('filename' === $defaultStrategy) { - @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED); - - $defaultStrategy = 'name'; - } - - if ('name' === $defaultStrategy) { - $defaultStrategy = ['Twig_FileExtensionEscapingStrategy', 'guess']; - } - - $this->defaultStrategy = $defaultStrategy; - } - - /** - * Gets the default strategy to use when not defined by the user. - * - * @param string $name The template name - * - * @return string|false The default strategy to use for the template - */ - public function getDefaultStrategy($name) - { - // disable string callables to avoid calling a function named html or js, - // or any other upcoming escaping strategy - if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { - return call_user_func($this->defaultStrategy, $name); - } - - return $this->defaultStrategy; - } - - public function getName() - { - return 'escaper'; - } -} - -/** - * Marks a variable as being safe. - * - * @param string $string A PHP variable - * - * @return string - */ -function twig_raw_filter($string) -{ - return $string; -} - -class_alias('Twig_Extension_Escaper', 'Twig\Extension\EscaperExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/GlobalsInterface.php b/system/templateEngines/Twig/Twig1x/Extension/GlobalsInterface.php deleted file mode 100644 index 922cd2c..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/GlobalsInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ -interface Twig_Extension_GlobalsInterface -{ -} - -class_alias('Twig_Extension_GlobalsInterface', 'Twig\Extension\GlobalsInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/InitRuntimeInterface.php b/system/templateEngines/Twig/Twig1x/Extension/InitRuntimeInterface.php deleted file mode 100644 index 1549862..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/InitRuntimeInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ -interface Twig_Extension_InitRuntimeInterface -{ -} - -class_alias('Twig_Extension_InitRuntimeInterface', 'Twig\Extension\InitRuntimeInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/Optimizer.php b/system/templateEngines/Twig/Twig1x/Extension/Optimizer.php deleted file mode 100644 index 70a64be..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/Optimizer.php +++ /dev/null @@ -1,35 +0,0 @@ -optimizers = $optimizers; - } - - public function getNodeVisitors() - { - return [new Twig_NodeVisitor_Optimizer($this->optimizers)]; - } - - public function getName() - { - return 'optimizer'; - } -} - -class_alias('Twig_Extension_Optimizer', 'Twig\Extension\OptimizerExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/Profiler.php b/system/templateEngines/Twig/Twig1x/Extension/Profiler.php deleted file mode 100644 index d7faef8..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/Profiler.php +++ /dev/null @@ -1,49 +0,0 @@ -actives[] = $profile; - } - - public function enter(Twig_Profiler_Profile $profile) - { - $this->actives[0]->addProfile($profile); - array_unshift($this->actives, $profile); - } - - public function leave(Twig_Profiler_Profile $profile) - { - $profile->leave(); - array_shift($this->actives); - - if (1 === count($this->actives)) { - $this->actives[0]->leave(); - } - } - - public function getNodeVisitors() - { - return [new Twig_Profiler_NodeVisitor_Profiler(get_class($this))]; - } - - public function getName() - { - return 'profiler'; - } -} - -class_alias('Twig_Extension_Profiler', 'Twig\Extension\ProfilerExtension', false); -class_exists('Twig_Profiler_Profile'); diff --git a/system/templateEngines/Twig/Twig1x/Extension/Sandbox.php b/system/templateEngines/Twig/Twig1x/Extension/Sandbox.php deleted file mode 100644 index cacde63..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/Sandbox.php +++ /dev/null @@ -1,103 +0,0 @@ -policy = $policy; - $this->sandboxedGlobally = $sandboxed; - } - - public function getTokenParsers() - { - return [new Twig_TokenParser_Sandbox()]; - } - - public function getNodeVisitors() - { - return [new Twig_NodeVisitor_Sandbox()]; - } - - public function enableSandbox() - { - $this->sandboxed = true; - } - - public function disableSandbox() - { - $this->sandboxed = false; - } - - public function isSandboxed() - { - return $this->sandboxedGlobally || $this->sandboxed; - } - - public function isSandboxedGlobally() - { - return $this->sandboxedGlobally; - } - - public function setSecurityPolicy(Twig_Sandbox_SecurityPolicyInterface $policy) - { - $this->policy = $policy; - } - - public function getSecurityPolicy() - { - return $this->policy; - } - - public function checkSecurity($tags, $filters, $functions) - { - if ($this->isSandboxed()) { - $this->policy->checkSecurity($tags, $filters, $functions); - } - } - - public function checkMethodAllowed($obj, $method) - { - if ($this->isSandboxed()) { - $this->policy->checkMethodAllowed($obj, $method); - } - } - - public function checkPropertyAllowed($obj, $method) - { - if ($this->isSandboxed()) { - $this->policy->checkPropertyAllowed($obj, $method); - } - } - - public function ensureToStringAllowed($obj) - { - if ($this->isSandboxed() && is_object($obj)) { - $this->policy->checkMethodAllowed($obj, '__toString'); - } - - return $obj; - } - - public function getName() - { - return 'sandbox'; - } -} - -class_alias('Twig_Extension_Sandbox', 'Twig\Extension\SandboxExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/Staging.php b/system/templateEngines/Twig/Twig1x/Extension/Staging.php deleted file mode 100644 index 897b379..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/Staging.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * @internal - */ -class Twig_Extension_Staging extends Twig_Extension -{ - protected $functions = []; - protected $filters = []; - protected $visitors = []; - protected $tokenParsers = []; - protected $globals = []; - protected $tests = []; - - public function addFunction($name, $function) - { - if (isset($this->functions[$name])) { - @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); - } - - $this->functions[$name] = $function; - } - - public function getFunctions() - { - return $this->functions; - } - - public function addFilter($name, $filter) - { - if (isset($this->filters[$name])) { - @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); - } - - $this->filters[$name] = $filter; - } - - public function getFilters() - { - return $this->filters; - } - - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) - { - $this->visitors[] = $visitor; - } - - public function getNodeVisitors() - { - return $this->visitors; - } - - public function addTokenParser(Twig_TokenParserInterface $parser) - { - if (isset($this->tokenParsers[$parser->getTag()])) { - @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); - } - - $this->tokenParsers[$parser->getTag()] = $parser; - } - - public function getTokenParsers() - { - return $this->tokenParsers; - } - - public function addGlobal($name, $value) - { - $this->globals[$name] = $value; - } - - public function getGlobals() - { - return $this->globals; - } - - public function addTest($name, $test) - { - if (isset($this->tests[$name])) { - @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); - } - - $this->tests[$name] = $test; - } - - public function getTests() - { - return $this->tests; - } - - public function getName() - { - return 'staging'; - } -} - -class_alias('Twig_Extension_Staging', 'Twig\Extension\StagingExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/Extension/StringLoader.php b/system/templateEngines/Twig/Twig1x/Extension/StringLoader.php deleted file mode 100644 index 58b731c..0000000 --- a/system/templateEngines/Twig/Twig1x/Extension/StringLoader.php +++ /dev/null @@ -1,47 +0,0 @@ - true]), - ]; - } - - public function getName() - { - return 'string_loader'; - } -} - -/** - * Loads a template from a string. - * - *
- * {{ include(template_from_string("Hello {{ name }}")) }}
- * 
- * - * @param Twig_Environment $env A Twig_Environment instance - * @param string $template A template as a string or object implementing __toString() - * - * @return Twig_Template - */ -function twig_template_from_string(Twig_Environment $env, $template) -{ - return $env->createTemplate((string) $template); -} - -class_alias('Twig_Extension_StringLoader', 'Twig\Extension\StringLoaderExtension', false); diff --git a/system/templateEngines/Twig/Twig1x/ExtensionInterface.php b/system/templateEngines/Twig/Twig1x/ExtensionInterface.php deleted file mode 100644 index 946df50..0000000 --- a/system/templateEngines/Twig/Twig1x/ExtensionInterface.php +++ /dev/null @@ -1,90 +0,0 @@ - - */ -interface Twig_ExtensionInterface -{ - /** - * Initializes the runtime environment. - * - * This is where you can load some file that contains filter functions for instance. - * - * @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead - */ - public function initRuntime(Twig_Environment $environment); - - /** - * Returns the token parser instances to add to the existing list. - * - * @return Twig_TokenParserInterface[] - */ - public function getTokenParsers(); - - /** - * Returns the node visitor instances to add to the existing list. - * - * @return Twig_NodeVisitorInterface[] - */ - public function getNodeVisitors(); - - /** - * Returns a list of filters to add to the existing list. - * - * @return Twig_SimpleFilter[] - */ - public function getFilters(); - - /** - * Returns a list of tests to add to the existing list. - * - * @return Twig_SimpleTest[] - */ - public function getTests(); - - /** - * Returns a list of functions to add to the existing list. - * - * @return Twig_SimpleFunction[] - */ - public function getFunctions(); - - /** - * Returns a list of operators to add to the existing list. - * - * @return array First array of unary operators, second array of binary operators - */ - public function getOperators(); - - /** - * Returns a list of global variables to add to the existing list. - * - * @return array An array of global variables - * - * @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead - */ - public function getGlobals(); - - /** - * Returns the name of the extension. - * - * @return string The extension name - * - * @deprecated since 1.26 (to be removed in 2.0), not used anymore internally - */ - public function getName(); -} - -class_alias('Twig_ExtensionInterface', 'Twig\Extension\ExtensionInterface', false); -class_exists('Twig_Environment'); diff --git a/system/templateEngines/Twig/Twig1x/FactoryRuntimeLoader.php b/system/templateEngines/Twig/Twig1x/FactoryRuntimeLoader.php deleted file mode 100644 index 2a86712..0000000 --- a/system/templateEngines/Twig/Twig1x/FactoryRuntimeLoader.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Twig_FactoryRuntimeLoader implements Twig_RuntimeLoaderInterface -{ - private $map; - - /** - * @param array $map An array where keys are class names and values factory callables - */ - public function __construct($map = []) - { - $this->map = $map; - } - - public function load($class) - { - if (isset($this->map[$class])) { - $runtimeFactory = $this->map[$class]; - - return $runtimeFactory(); - } - } -} - -class_alias('Twig_FactoryRuntimeLoader', 'Twig\RuntimeLoader\FactoryRuntimeLoader', false); diff --git a/system/templateEngines/Twig/Twig1x/FileExtensionEscapingStrategy.php b/system/templateEngines/Twig/Twig1x/FileExtensionEscapingStrategy.php deleted file mode 100644 index 6b13c72..0000000 --- a/system/templateEngines/Twig/Twig1x/FileExtensionEscapingStrategy.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class Twig_FileExtensionEscapingStrategy -{ - /** - * Guesses the best autoescaping strategy based on the file name. - * - * @param string $name The template name - * - * @return string|false The escaping strategy name to use or false to disable - */ - public static function guess($name) - { - if (in_array(substr($name, -1), ['/', '\\'])) { - return 'html'; // return html for directories - } - - if ('.twig' === substr($name, -5)) { - $name = substr($name, 0, -5); - } - - $extension = pathinfo($name, PATHINFO_EXTENSION); - - switch ($extension) { - case 'js': - return 'js'; - - case 'css': - return 'css'; - - case 'txt': - return false; - - default: - return 'html'; - } - } -} - -class_alias('Twig_FileExtensionEscapingStrategy', 'Twig\FileExtensionEscapingStrategy', false); diff --git a/system/templateEngines/Twig/Twig1x/Filter.php b/system/templateEngines/Twig/Twig1x/Filter.php deleted file mode 100644 index 9191c54..0000000 --- a/system/templateEngines/Twig/Twig1x/Filter.php +++ /dev/null @@ -1,84 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface -{ - protected $options; - protected $arguments = []; - - public function __construct(array $options = []) - { - $this->options = array_merge([ - 'needs_environment' => false, - 'needs_context' => false, - 'pre_escape' => null, - 'preserves_safety' => null, - 'callable' => null, - ], $options); - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $filterArgs) - { - if (isset($this->options['is_safe'])) { - return $this->options['is_safe']; - } - - if (isset($this->options['is_safe_callback'])) { - return call_user_func($this->options['is_safe_callback'], $filterArgs); - } - } - - public function getPreservesSafety() - { - return $this->options['preserves_safety']; - } - - public function getPreEscape() - { - return $this->options['pre_escape']; - } - - public function getCallable() - { - return $this->options['callable']; - } -} diff --git a/system/templateEngines/Twig/Twig1x/Filter/Function.php b/system/templateEngines/Twig/Twig1x/Filter/Function.php deleted file mode 100644 index 0423102..0000000 --- a/system/templateEngines/Twig/Twig1x/Filter/Function.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Filter_Function extends Twig_Filter -{ - protected $function; - - public function __construct($function, array $options = []) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/system/templateEngines/Twig/Twig1x/Filter/Method.php b/system/templateEngines/Twig/Twig1x/Filter/Method.php deleted file mode 100644 index 2dc39b6..0000000 --- a/system/templateEngines/Twig/Twig1x/Filter/Method.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Filter_Method extends Twig_Filter -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = []) - { - $options['callable'] = [$extension, $method]; - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', get_class($this->extension), $this->method); - } -} diff --git a/system/templateEngines/Twig/Twig1x/Filter/Node.php b/system/templateEngines/Twig/Twig1x/Filter/Node.php deleted file mode 100644 index 0d96081..0000000 --- a/system/templateEngines/Twig/Twig1x/Filter/Node.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Filter_Node extends Twig_Filter -{ - protected $class; - - public function __construct($class, array $options = []) - { - parent::__construct($options); - - $this->class = $class; - } - - public function getClass() - { - return $this->class; - } - - public function compile() - { - } -} diff --git a/system/templateEngines/Twig/Twig1x/FilterCallableInterface.php b/system/templateEngines/Twig/Twig1x/FilterCallableInterface.php deleted file mode 100644 index 21b028c..0000000 --- a/system/templateEngines/Twig/Twig1x/FilterCallableInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FilterCallableInterface -{ - public function getCallable(); -} diff --git a/system/templateEngines/Twig/Twig1x/FilterInterface.php b/system/templateEngines/Twig/Twig1x/FilterInterface.php deleted file mode 100644 index 9d7e9ab..0000000 --- a/system/templateEngines/Twig/Twig1x/FilterInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FilterInterface -{ - /** - * Compiles a filter. - * - * @return string The PHP code for the filter - */ - public function compile(); - - public function needsEnvironment(); - - public function needsContext(); - - public function getSafe(Twig_Node $filterArgs); - - public function getPreservesSafety(); - - public function getPreEscape(); - - public function setArguments($arguments); - - public function getArguments(); -} diff --git a/system/templateEngines/Twig/Twig1x/Function.php b/system/templateEngines/Twig/Twig1x/Function.php deleted file mode 100644 index a829eee..0000000 --- a/system/templateEngines/Twig/Twig1x/Function.php +++ /dev/null @@ -1,74 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface -{ - protected $options; - protected $arguments = []; - - public function __construct(array $options = []) - { - $this->options = array_merge([ - 'needs_environment' => false, - 'needs_context' => false, - 'callable' => null, - ], $options); - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $functionArgs) - { - if (isset($this->options['is_safe'])) { - return $this->options['is_safe']; - } - - if (isset($this->options['is_safe_callback'])) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); - } - - return []; - } - - public function getCallable() - { - return $this->options['callable']; - } -} diff --git a/system/templateEngines/Twig/Twig1x/Function/Function.php b/system/templateEngines/Twig/Twig1x/Function/Function.php deleted file mode 100644 index 86f853b..0000000 --- a/system/templateEngines/Twig/Twig1x/Function/Function.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Function extends Twig_Function -{ - protected $function; - - public function __construct($function, array $options = []) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/system/templateEngines/Twig/Twig1x/Function/Method.php b/system/templateEngines/Twig/Twig1x/Function/Method.php deleted file mode 100644 index 4806a43..0000000 --- a/system/templateEngines/Twig/Twig1x/Function/Method.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Method extends Twig_Function -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = []) - { - $options['callable'] = [$extension, $method]; - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', get_class($this->extension), $this->method); - } -} diff --git a/system/templateEngines/Twig/Twig1x/Function/Node.php b/system/templateEngines/Twig/Twig1x/Function/Node.php deleted file mode 100644 index 68688c7..0000000 --- a/system/templateEngines/Twig/Twig1x/Function/Node.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Node extends Twig_Function -{ - protected $class; - - public function __construct($class, array $options = []) - { - parent::__construct($options); - - $this->class = $class; - } - - public function getClass() - { - return $this->class; - } - - public function compile() - { - } -} diff --git a/system/templateEngines/Twig/Twig1x/FunctionCallableInterface.php b/system/templateEngines/Twig/Twig1x/FunctionCallableInterface.php deleted file mode 100644 index d23d691..0000000 --- a/system/templateEngines/Twig/Twig1x/FunctionCallableInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FunctionCallableInterface -{ - public function getCallable(); -} diff --git a/system/templateEngines/Twig/Twig1x/FunctionInterface.php b/system/templateEngines/Twig/Twig1x/FunctionInterface.php deleted file mode 100644 index 00d4f95..0000000 --- a/system/templateEngines/Twig/Twig1x/FunctionInterface.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FunctionInterface -{ - /** - * Compiles a function. - * - * @return string The PHP code for the function - */ - public function compile(); - - public function needsEnvironment(); - - public function needsContext(); - - public function getSafe(Twig_Node $filterArgs); - - public function setArguments($arguments); - - public function getArguments(); -} diff --git a/system/templateEngines/Twig/Twig1x/Lexer.php b/system/templateEngines/Twig/Twig1x/Lexer.php deleted file mode 100644 index eea2d0f..0000000 --- a/system/templateEngines/Twig/Twig1x/Lexer.php +++ /dev/null @@ -1,427 +0,0 @@ - - */ -class Twig_Lexer implements Twig_LexerInterface -{ - protected $tokens; - protected $code; - protected $cursor; - protected $lineno; - protected $end; - protected $state; - protected $states; - protected $brackets; - protected $env; - // to be renamed to $name in 2.0 (where it is private) - protected $filename; - protected $options; - protected $regexes; - protected $position; - protected $positions; - protected $currentVarBlockLine; - - private $source; - - const STATE_DATA = 0; - const STATE_BLOCK = 1; - const STATE_VAR = 2; - const STATE_STRING = 3; - const STATE_INTERPOLATION = 4; - - const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; - const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A'; - const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; - const REGEX_DQ_STRING_DELIM = '/"/A'; - const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; - const PUNCTUATION = '()[]{}?:.,|'; - - public function __construct(Twig_Environment $env, array $options = []) - { - $this->env = $env; - - $this->options = array_merge([ - 'tag_comment' => ['{#', '#}'], - 'tag_block' => ['{%', '%}'], - 'tag_variable' => ['{{', '}}'], - 'whitespace_trim' => '-', - 'interpolation' => ['#{', '}'], - ], $options); - - $this->regexes = [ - 'lex_var' => '/\s*'.preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_variable'][1], '/').'/A', - 'lex_block' => '/\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')\n?/A', - 'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*(?:end%s)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s', - 'operator' => $this->getOperatorRegex(), - 'lex_comment' => '/(?:'.preg_quote($this->options['whitespace_trim'], '/').preg_quote($this->options['tag_comment'][1], '/').'\s*|'.preg_quote($this->options['tag_comment'][1], '/').')\n?/s', - 'lex_block_raw' => '/\s*(raw|verbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As', - 'lex_block_line' => '/\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '/').'/As', - 'lex_tokens_start' => '/('.preg_quote($this->options['tag_variable'][0], '/').'|'.preg_quote($this->options['tag_block'][0], '/').'|'.preg_quote($this->options['tag_comment'][0], '/').')('.preg_quote($this->options['whitespace_trim'], '/').')?/s', - 'interpolation_start' => '/'.preg_quote($this->options['interpolation'][0], '/').'\s*/A', - 'interpolation_end' => '/\s*'.preg_quote($this->options['interpolation'][1], '/').'/A', - ]; - } - - public function tokenize($code, $name = null) - { - if (!$code instanceof Twig_Source) { - @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $this->source = new Twig_Source($code, $name); - } else { - $this->source = $code; - } - - if (((int) ini_get('mbstring.func_overload')) & 2) { - @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); - } - - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { - $mbEncoding = mb_internal_encoding(); - mb_internal_encoding('ASCII'); - } else { - $mbEncoding = null; - } - - $this->code = str_replace(["\r\n", "\r"], "\n", $this->source->getCode()); - $this->filename = $this->source->getName(); - $this->cursor = 0; - $this->lineno = 1; - $this->end = strlen($this->code); - $this->tokens = []; - $this->state = self::STATE_DATA; - $this->states = []; - $this->brackets = []; - $this->position = -1; - - // find all token starts in one go - preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); - $this->positions = $matches; - - while ($this->cursor < $this->end) { - // dispatch to the lexing functions depending - // on the current state - switch ($this->state) { - case self::STATE_DATA: - $this->lexData(); - break; - - case self::STATE_BLOCK: - $this->lexBlock(); - break; - - case self::STATE_VAR: - $this->lexVar(); - break; - - case self::STATE_STRING: - $this->lexString(); - break; - - case self::STATE_INTERPOLATION: - $this->lexInterpolation(); - break; - } - } - - $this->pushToken(Twig_Token::EOF_TYPE); - - if (!empty($this->brackets)) { - list($expect, $lineno) = array_pop($this->brackets); - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); - } - - if ($mbEncoding) { - mb_internal_encoding($mbEncoding); - } - - return new Twig_TokenStream($this->tokens, $this->source); - } - - protected function lexData() - { - // if no matches are left we return the rest of the template as simple text token - if ($this->position == count($this->positions[0]) - 1) { - $this->pushToken(Twig_Token::TEXT_TYPE, substr($this->code, $this->cursor)); - $this->cursor = $this->end; - - return; - } - - // Find the first token after the current cursor - $position = $this->positions[0][++$this->position]; - while ($position[1] < $this->cursor) { - if ($this->position == count($this->positions[0]) - 1) { - return; - } - $position = $this->positions[0][++$this->position]; - } - - // push the template text first - $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor); - if (isset($this->positions[2][$this->position][0])) { - $text = rtrim($text); - } - $this->pushToken(Twig_Token::TEXT_TYPE, $text); - $this->moveCursor($textContent.$position[0]); - - switch ($this->positions[1][$this->position][0]) { - case $this->options['tag_comment'][0]: - $this->lexComment(); - break; - - case $this->options['tag_block'][0]: - // raw data? - if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) { - $this->moveCursor($match[0]); - $this->lexRawData($match[1]); - // {% line \d+ %} - } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) { - $this->moveCursor($match[0]); - $this->lineno = (int) $match[1]; - } else { - $this->pushToken(Twig_Token::BLOCK_START_TYPE); - $this->pushState(self::STATE_BLOCK); - $this->currentVarBlockLine = $this->lineno; - } - break; - - case $this->options['tag_variable'][0]: - $this->pushToken(Twig_Token::VAR_START_TYPE); - $this->pushState(self::STATE_VAR); - $this->currentVarBlockLine = $this->lineno; - break; - } - } - - protected function lexBlock() - { - if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::BLOCK_END_TYPE); - $this->moveCursor($match[0]); - $this->popState(); - } else { - $this->lexExpression(); - } - } - - protected function lexVar() - { - if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::VAR_END_TYPE); - $this->moveCursor($match[0]); - $this->popState(); - } else { - $this->lexExpression(); - } - } - - protected function lexExpression() - { - // whitespace - if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) { - $this->moveCursor($match[0]); - - if ($this->cursor >= $this->end) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); - } - } - - // operators - if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0])); - $this->moveCursor($match[0]); - } - // names - elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::NAME_TYPE, $match[0]); - $this->moveCursor($match[0]); - } - // numbers - elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) { - $number = (float) $match[0]; // floats - if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { - $number = (int) $match[0]; // integers lower than the maximum - } - $this->pushToken(Twig_Token::NUMBER_TYPE, $number); - $this->moveCursor($match[0]); - } - // punctuation - elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) { - // opening bracket - if (false !== strpos('([{', $this->code[$this->cursor])) { - $this->brackets[] = [$this->code[$this->cursor], $this->lineno]; - } - // closing bracket - elseif (false !== strpos(')]}', $this->code[$this->cursor])) { - if (empty($this->brackets)) { - throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); - } - - list($expect, $lineno) = array_pop($this->brackets); - if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); - } - } - - $this->pushToken(Twig_Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); - ++$this->cursor; - } - // strings - elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); - $this->moveCursor($match[0]); - } - // opening double quoted string - elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { - $this->brackets[] = ['"', $this->lineno]; - $this->pushState(self::STATE_STRING); - $this->moveCursor($match[0]); - } - // unlexable - else { - throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); - } - } - - protected function lexRawData($tag) - { - if ('raw' === $tag) { - @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED); - } - - if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); - } - - $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); - $this->moveCursor($text.$match[0][0]); - - if (false !== strpos($match[1][0], $this->options['whitespace_trim'])) { - $text = rtrim($text); - } - - $this->pushToken(Twig_Token::TEXT_TYPE, $text); - } - - protected function lexComment() - { - if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->source); - } - - $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); - } - - protected function lexString() - { - if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) { - $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; - $this->pushToken(Twig_Token::INTERPOLATION_START_TYPE); - $this->moveCursor($match[0]); - $this->pushState(self::STATE_INTERPOLATION); - } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && strlen($match[0]) > 0) { - $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[0])); - $this->moveCursor($match[0]); - } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { - list($expect, $lineno) = array_pop($this->brackets); - if ('"' != $this->code[$this->cursor]) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); - } - - $this->popState(); - ++$this->cursor; - } else { - // unlexable - throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); - } - } - - protected function lexInterpolation() - { - $bracket = end($this->brackets); - if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) { - array_pop($this->brackets); - $this->pushToken(Twig_Token::INTERPOLATION_END_TYPE); - $this->moveCursor($match[0]); - $this->popState(); - } else { - $this->lexExpression(); - } - } - - protected function pushToken($type, $value = '') - { - // do not push empty text tokens - if (Twig_Token::TEXT_TYPE === $type && '' === $value) { - return; - } - - $this->tokens[] = new Twig_Token($type, $value, $this->lineno); - } - - protected function moveCursor($text) - { - $this->cursor += strlen($text); - $this->lineno += substr_count($text, "\n"); - } - - protected function getOperatorRegex() - { - $operators = array_merge( - ['='], - array_keys($this->env->getUnaryOperators()), - array_keys($this->env->getBinaryOperators()) - ); - - $operators = array_combine($operators, array_map('strlen', $operators)); - arsort($operators); - - $regex = []; - foreach ($operators as $operator => $length) { - // an operator that ends with a character must be followed by - // a whitespace or a parenthesis - if (ctype_alpha($operator[$length - 1])) { - $r = preg_quote($operator, '/').'(?=[\s()])'; - } else { - $r = preg_quote($operator, '/'); - } - - // an operator with a space can be any amount of whitespaces - $r = preg_replace('/\s+/', '\s+', $r); - - $regex[] = $r; - } - - return '/'.implode('|', $regex).'/A'; - } - - protected function pushState($state) - { - $this->states[] = $this->state; - $this->state = $state; - } - - protected function popState() - { - if (0 === count($this->states)) { - throw new Exception('Cannot pop state without a previous state.'); - } - - $this->state = array_pop($this->states); - } -} - -class_alias('Twig_Lexer', 'Twig\Lexer', false); diff --git a/system/templateEngines/Twig/Twig1x/LexerInterface.php b/system/templateEngines/Twig/Twig1x/LexerInterface.php deleted file mode 100644 index c10bbfe..0000000 --- a/system/templateEngines/Twig/Twig1x/LexerInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_LexerInterface -{ - /** - * Tokenizes a source code. - * - * @param string|Twig_Source $code The source code - * @param string $name A unique identifier for the source code - * - * @return Twig_TokenStream - * - * @throws Twig_Error_Syntax When the code is syntactically wrong - */ - public function tokenize($code, $name = null); -} diff --git a/system/templateEngines/Twig/Twig1x/Loader/Array.php b/system/templateEngines/Twig/Twig1x/Loader/Array.php deleted file mode 100644 index 7c51317..0000000 --- a/system/templateEngines/Twig/Twig1x/Loader/Array.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ -class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - protected $templates = []; - - /** - * @param array $templates An array of templates (keys are the names, and values are the source code) - */ - public function __construct(array $templates = []) - { - $this->templates = $templates; - } - - /** - * Adds or overrides a template. - * - * @param string $name The template name - * @param string $template The template source - */ - public function setTemplate($name, $template) - { - $this->templates[(string) $name] = $template; - } - - public function getSource($name) - { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); - - $name = (string) $name; - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return $this->templates[$name]; - } - - public function getSourceContext($name) - { - $name = (string) $name; - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return new Twig_Source($this->templates[$name], $name); - } - - public function exists($name) - { - return isset($this->templates[(string) $name]); - } - - public function getCacheKey($name) - { - $name = (string) $name; - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return $name.':'.$this->templates[$name]; - } - - public function isFresh($name, $time) - { - $name = (string) $name; - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return true; - } -} - -class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false); diff --git a/system/templateEngines/Twig/Twig1x/Loader/Chain.php b/system/templateEngines/Twig/Twig1x/Loader/Chain.php deleted file mode 100644 index 8ccf8c9..0000000 --- a/system/templateEngines/Twig/Twig1x/Loader/Chain.php +++ /dev/null @@ -1,151 +0,0 @@ - - */ -class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - private $hasSourceCache = []; - protected $loaders = []; - - /** - * @param Twig_LoaderInterface[] $loaders - */ - public function __construct(array $loaders = []) - { - foreach ($loaders as $loader) { - $this->addLoader($loader); - } - } - - public function addLoader(Twig_LoaderInterface $loader) - { - $this->loaders[] = $loader; - $this->hasSourceCache = []; - } - - public function getSource($name) - { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); - - $exceptions = []; - foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { - continue; - } - - try { - return $loader->getSource($name); - } catch (Twig_Error_Loader $e) { - $exceptions[] = $e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - - public function getSourceContext($name) - { - $exceptions = []; - foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { - continue; - } - - try { - if ($loader instanceof Twig_SourceContextLoaderInterface) { - return $loader->getSourceContext($name); - } - - return new Twig_Source($loader->getSource($name), $name); - } catch (Twig_Error_Loader $e) { - $exceptions[] = $e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - - public function exists($name) - { - $name = (string) $name; - - if (isset($this->hasSourceCache[$name])) { - return $this->hasSourceCache[$name]; - } - - foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface) { - if ($loader->exists($name)) { - return $this->hasSourceCache[$name] = true; - } - - continue; - } - - try { - if ($loader instanceof Twig_SourceContextLoaderInterface) { - $loader->getSourceContext($name); - } else { - $loader->getSource($name); - } - - return $this->hasSourceCache[$name] = true; - } catch (Twig_Error_Loader $e) { - } - } - - return $this->hasSourceCache[$name] = false; - } - - public function getCacheKey($name) - { - $exceptions = []; - foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { - continue; - } - - try { - return $loader->getCacheKey($name); - } catch (Twig_Error_Loader $e) { - $exceptions[] = get_class($loader).': '.$e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - - public function isFresh($name, $time) - { - $exceptions = []; - foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { - continue; - } - - try { - return $loader->isFresh($name, $time); - } catch (Twig_Error_Loader $e) { - $exceptions[] = get_class($loader).': '.$e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } -} - -class_alias('Twig_Loader_Chain', 'Twig\Loader\ChainLoader', false); diff --git a/system/templateEngines/Twig/Twig1x/Loader/Filesystem.php b/system/templateEngines/Twig/Twig1x/Loader/Filesystem.php deleted file mode 100644 index 1263dc4..0000000 --- a/system/templateEngines/Twig/Twig1x/Loader/Filesystem.php +++ /dev/null @@ -1,298 +0,0 @@ - - */ -class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - /** Identifier of the main namespace. */ - const MAIN_NAMESPACE = '__main__'; - - protected $paths = []; - protected $cache = []; - protected $errorCache = []; - - private $rootPath; - - /** - * @param string|array $paths A path or an array of paths where to look for templates - * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) - */ - public function __construct($paths = [], $rootPath = null) - { - $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).DIRECTORY_SEPARATOR; - if (false !== $realPath = realpath($rootPath)) { - $this->rootPath = $realPath.DIRECTORY_SEPARATOR; - } - - if ($paths) { - $this->setPaths($paths); - } - } - - /** - * Returns the paths to the templates. - * - * @param string $namespace A path namespace - * - * @return array The array of paths where to look for templates - */ - public function getPaths($namespace = self::MAIN_NAMESPACE) - { - return isset($this->paths[$namespace]) ? $this->paths[$namespace] : []; - } - - /** - * Returns the path namespaces. - * - * The main namespace is always defined. - * - * @return array The array of defined namespaces - */ - public function getNamespaces() - { - return array_keys($this->paths); - } - - /** - * Sets the paths where templates are stored. - * - * @param string|array $paths A path or an array of paths where to look for templates - * @param string $namespace A path namespace - */ - public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) - { - if (!is_array($paths)) { - $paths = [$paths]; - } - - $this->paths[$namespace] = []; - foreach ($paths as $path) { - $this->addPath($path, $namespace); - } - } - - /** - * Adds a path where templates are stored. - * - * @param string $path A path where to look for templates - * @param string $namespace A path namespace - * - * @throws Twig_Error_Loader - */ - public function addPath($path, $namespace = self::MAIN_NAMESPACE) - { - // invalidate the cache - $this->cache = $this->errorCache = []; - - $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; - if (!is_dir($checkPath)) { - throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); - } - - $this->paths[$namespace][] = rtrim($path, '/\\'); - } - - /** - * Prepends a path where templates are stored. - * - * @param string $path A path where to look for templates - * @param string $namespace A path namespace - * - * @throws Twig_Error_Loader - */ - public function prependPath($path, $namespace = self::MAIN_NAMESPACE) - { - // invalidate the cache - $this->cache = $this->errorCache = []; - - $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; - if (!is_dir($checkPath)) { - throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); - } - - $path = rtrim($path, '/\\'); - - if (!isset($this->paths[$namespace])) { - $this->paths[$namespace][] = $path; - } else { - array_unshift($this->paths[$namespace], $path); - } - } - - public function getSource($name) - { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); - - return file_get_contents($this->findTemplate($name)); - } - - public function getSourceContext($name) - { - $path = $this->findTemplate($name); - - return new Twig_Source(file_get_contents($path), $name, $path); - } - - public function getCacheKey($name) - { - $path = $this->findTemplate($name); - $len = strlen($this->rootPath); - if (0 === strncmp($this->rootPath, $path, $len)) { - return substr($path, $len); - } - - return $path; - } - - public function exists($name) - { - $name = $this->normalizeName($name); - - if (isset($this->cache[$name])) { - return true; - } - - try { - return false !== $this->findTemplate($name, false); - } catch (Twig_Error_Loader $exception) { - @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', get_class($this)), E_USER_DEPRECATED); - - return false; - } - } - - public function isFresh($name, $time) - { - return filemtime($this->findTemplate($name)) < $time; - } - - protected function findTemplate($name) - { - $throw = func_num_args() > 1 ? func_get_arg(1) : true; - $name = $this->normalizeName($name); - - if (isset($this->cache[$name])) { - return $this->cache[$name]; - } - - if (isset($this->errorCache[$name])) { - if (!$throw) { - return false; - } - - throw new Twig_Error_Loader($this->errorCache[$name]); - } - - try { - $this->validateName($name); - - list($namespace, $shortname) = $this->parseName($name); - } catch (Twig_Error_Loader $e) { - if (!$throw) { - return false; - } - - throw $e; - } - - if (!isset($this->paths[$namespace])) { - $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace); - - if (!$throw) { - return false; - } - - throw new Twig_Error_Loader($this->errorCache[$name]); - } - - foreach ($this->paths[$namespace] as $path) { - if (!$this->isAbsolutePath($path)) { - $path = $this->rootPath.'/'.$path; - } - - if (is_file($path.'/'.$shortname)) { - if (false !== $realpath = realpath($path.'/'.$shortname)) { - return $this->cache[$name] = $realpath; - } - - return $this->cache[$name] = $path.'/'.$shortname; - } - } - - $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])); - - if (!$throw) { - return false; - } - - throw new Twig_Error_Loader($this->errorCache[$name]); - } - - protected function parseName($name, $default = self::MAIN_NAMESPACE) - { - if (isset($name[0]) && '@' == $name[0]) { - if (false === $pos = strpos($name, '/')) { - throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); - } - - $namespace = substr($name, 1, $pos - 1); - $shortname = substr($name, $pos + 1); - - return [$namespace, $shortname]; - } - - return [$default, $name]; - } - - protected function normalizeName($name) - { - return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name)); - } - - protected function validateName($name) - { - if (false !== strpos($name, "\0")) { - throw new Twig_Error_Loader('A template name cannot contain NUL bytes.'); - } - - $name = ltrim($name, '/'); - $parts = explode('/', $name); - $level = 0; - foreach ($parts as $part) { - if ('..' === $part) { - --$level; - } elseif ('.' !== $part) { - ++$level; - } - - if ($level < 0) { - throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); - } - } - } - - private function isAbsolutePath($file) - { - return strspn($file, '/\\', 0, 1) - || (strlen($file) > 3 && ctype_alpha($file[0]) - && ':' === substr($file, 1, 1) - && strspn($file, '/\\', 2, 1) - ) - || null !== parse_url($file, PHP_URL_SCHEME) - ; - } -} - -class_alias('Twig_Loader_Filesystem', 'Twig\Loader\FilesystemLoader', false); diff --git a/system/templateEngines/Twig/Twig1x/Loader/String.php b/system/templateEngines/Twig/Twig1x/Loader/String.php deleted file mode 100644 index 950bd35..0000000 --- a/system/templateEngines/Twig/Twig1x/Loader/String.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - public function getSource($name) - { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); - - return $name; - } - - public function getSourceContext($name) - { - return new Twig_Source($name, $name); - } - - public function exists($name) - { - return true; - } - - public function getCacheKey($name) - { - return $name; - } - - public function isFresh($name, $time) - { - return true; - } -} diff --git a/system/templateEngines/Twig/Twig1x/LoaderInterface.php b/system/templateEngines/Twig/Twig1x/LoaderInterface.php deleted file mode 100644 index 459a70a..0000000 --- a/system/templateEngines/Twig/Twig1x/LoaderInterface.php +++ /dev/null @@ -1,57 +0,0 @@ - - */ -interface Twig_LoaderInterface -{ - /** - * Gets the source code of a template, given its name. - * - * @param string $name The name of the template to load - * - * @return string The template source code - * - * @throws Twig_Error_Loader When $name is not found - * - * @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface - */ - public function getSource($name); - - /** - * Gets the cache key to use for the cache for a given template name. - * - * @param string $name The name of the template to load - * - * @return string The cache key - * - * @throws Twig_Error_Loader When $name is not found - */ - public function getCacheKey($name); - - /** - * Returns true if the template is still fresh. - * - * @param string $name The template name - * @param int $time Timestamp of the last modification time of the - * cached template - * - * @return bool true if the template is fresh, false otherwise - * - * @throws Twig_Error_Loader When $name is not found - */ - public function isFresh($name, $time); -} - -class_alias('Twig_LoaderInterface', 'Twig\Loader\LoaderInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/Markup.php b/system/templateEngines/Twig/Twig1x/Markup.php deleted file mode 100644 index 8591d1f..0000000 --- a/system/templateEngines/Twig/Twig1x/Markup.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Twig_Markup implements Countable -{ - protected $content; - protected $charset; - - public function __construct($content, $charset) - { - $this->content = (string) $content; - $this->charset = $charset; - } - - public function __toString() - { - return $this->content; - } - - public function count() - { - return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content); - } -} - -class_alias('Twig_Markup', 'Twig\Markup', false); diff --git a/system/templateEngines/Twig/Twig1x/Node.php b/system/templateEngines/Twig/Twig1x/Node.php deleted file mode 100644 index bdc9ec2..0000000 --- a/system/templateEngines/Twig/Twig1x/Node.php +++ /dev/null @@ -1,256 +0,0 @@ - - */ -class Twig_Node implements Twig_NodeInterface -{ - protected $nodes; - protected $attributes; - protected $lineno; - protected $tag; - - private $name; - - /** - * Constructor. - * - * The nodes are automatically made available as properties ($this->node). - * The attributes are automatically made available as array items ($this['name']). - * - * @param array $nodes An array of named nodes - * @param array $attributes An array of attributes (should not be nodes) - * @param int $lineno The line number - * @param string $tag The tag name associated with the Node - */ - public function __construct(array $nodes = [], array $attributes = [], $lineno = 0, $tag = null) - { - foreach ($nodes as $name => $node) { - if (!$node instanceof Twig_NodeInterface) { - @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', is_object($node) ? get_class($node) : null === $node ? 'null' : gettype($node), $name, get_class($this)), E_USER_DEPRECATED); - } - } - $this->nodes = $nodes; - $this->attributes = $attributes; - $this->lineno = $lineno; - $this->tag = $tag; - } - - public function __toString() - { - $attributes = []; - foreach ($this->attributes as $name => $value) { - $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); - } - - $repr = [get_class($this).'('.implode(', ', $attributes)]; - - if (count($this->nodes)) { - foreach ($this->nodes as $name => $node) { - $len = strlen($name) + 4; - $noderepr = []; - foreach (explode("\n", (string) $node) as $line) { - $noderepr[] = str_repeat(' ', $len).$line; - } - - $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr))); - } - - $repr[] = ')'; - } else { - $repr[0] .= ')'; - } - - return implode("\n", $repr); - } - - /** - * @deprecated since 1.16.1 (to be removed in 2.0) - */ - public function toXml($asDom = false) - { - @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); - - $dom = new DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - $dom->appendChild($xml = $dom->createElement('twig')); - - $xml->appendChild($node = $dom->createElement('node')); - $node->setAttribute('class', get_class($this)); - - foreach ($this->attributes as $name => $value) { - $node->appendChild($attribute = $dom->createElement('attribute')); - $attribute->setAttribute('name', $name); - $attribute->appendChild($dom->createTextNode($value)); - } - - foreach ($this->nodes as $name => $n) { - if (null === $n) { - continue; - } - - $child = $n->toXml(true)->getElementsByTagName('node')->item(0); - $child = $dom->importNode($child, true); - $child->setAttribute('name', $name); - - $node->appendChild($child); - } - - return $asDom ? $dom : $dom->saveXML(); - } - - public function compile(Twig_Compiler $compiler) - { - foreach ($this->nodes as $node) { - $node->compile($compiler); - } - } - - public function getTemplateLine() - { - return $this->lineno; - } - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function getLine() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED); - - return $this->lineno; - } - - public function getNodeTag() - { - return $this->tag; - } - - /** - * @return bool - */ - public function hasAttribute($name) - { - return array_key_exists($name, $this->attributes); - } - - /** - * @return mixed - */ - public function getAttribute($name) - { - if (!array_key_exists($name, $this->attributes)) { - throw new LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this))); - } - - return $this->attributes[$name]; - } - - /** - * @param string $name - * @param mixed $value - */ - public function setAttribute($name, $value) - { - $this->attributes[$name] = $value; - } - - public function removeAttribute($name) - { - unset($this->attributes[$name]); - } - - /** - * @return bool - */ - public function hasNode($name) - { - return array_key_exists($name, $this->nodes); - } - - /** - * @return Twig_Node - */ - public function getNode($name) - { - if (!array_key_exists($name, $this->nodes)) { - throw new LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this))); - } - - return $this->nodes[$name]; - } - - public function setNode($name, $node = null) - { - if (!$node instanceof Twig_NodeInterface) { - @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', is_object($node) ? get_class($node) : null === $node ? 'null' : gettype($node), $name, get_class($this)), E_USER_DEPRECATED); - } - - $this->nodes[$name] = $node; - } - - public function removeNode($name) - { - unset($this->nodes[$name]); - } - - public function count() - { - return count($this->nodes); - } - - public function getIterator() - { - return new ArrayIterator($this->nodes); - } - - public function setTemplateName($name) - { - $this->name = $name; - foreach ($this->nodes as $node) { - if (null !== $node) { - $node->setTemplateName($name); - } - } - } - - public function getTemplateName() - { - return $this->name; - } - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function setFilename($name) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED); - - $this->setTemplateName($name); - } - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function getFilename() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED); - - return $this->name; - } -} - -class_alias('Twig_Node', 'Twig\Node\Node', false); -class_exists('Twig_Compiler'); diff --git a/system/templateEngines/Twig/Twig1x/Node/AutoEscape.php b/system/templateEngines/Twig/Twig1x/Node/AutoEscape.php deleted file mode 100644 index 62e0961..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/AutoEscape.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Node_AutoEscape extends Twig_Node -{ - public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape') - { - parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('body')); - } -} - -class_alias('Twig_Node_AutoEscape', 'Twig\Node\AutoEscapeNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Block.php b/system/templateEngines/Twig/Twig1x/Node/Block.php deleted file mode 100644 index 2d0300b..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Block.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ -class Twig_Node_Block extends Twig_Node -{ - public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null) - { - parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n") - ->indent() - ; - - $compiler - ->subcompile($this->getNode('body')) - ->outdent() - ->write("}\n\n") - ; - } -} - -class_alias('Twig_Node_Block', 'Twig\Node\BlockNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/BlockReference.php b/system/templateEngines/Twig/Twig1x/Node/BlockReference.php deleted file mode 100644 index 0b0f7b3..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/BlockReference.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ -class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct($name, $lineno, $tag = null) - { - parent::__construct([], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) - ; - } -} - -class_alias('Twig_Node_BlockReference', 'Twig\Node\BlockReferenceNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Body.php b/system/templateEngines/Twig/Twig1x/Node/Body.php deleted file mode 100644 index 07dfef8..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Body.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -class Twig_Node_Body extends Twig_Node -{ -} - -class_alias('Twig_Node_Body', 'Twig\Node\BodyNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/CheckSecurity.php b/system/templateEngines/Twig/Twig1x/Node/CheckSecurity.php deleted file mode 100644 index aecdb83..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/CheckSecurity.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ -class Twig_Node_CheckSecurity extends Twig_Node -{ - protected $usedFilters; - protected $usedTags; - protected $usedFunctions; - - public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) - { - $this->usedFilters = $usedFilters; - $this->usedTags = $usedTags; - $this->usedFunctions = $usedFunctions; - - parent::__construct(); - } - - public function compile(Twig_Compiler $compiler) - { - $tags = $filters = $functions = []; - foreach (['tags', 'filters', 'functions'] as $type) { - foreach ($this->{'used'.ucfirst($type)} as $name => $node) { - if ($node instanceof Twig_Node) { - ${$type}[$name] = $node->getTemplateLine(); - } else { - ${$type}[$node] = null; - } - } - } - - $compiler - ->write('$tags = ')->repr(array_filter($tags))->raw(";\n") - ->write('$filters = ')->repr(array_filter($filters))->raw(";\n") - ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n") - ->write("try {\n") - ->indent() - ->write("\$this->env->getExtension('Twig_Extension_Sandbox')->checkSecurity(\n") - ->indent() - ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n") - ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n") - ->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n") - ->outdent() - ->write(");\n") - ->outdent() - ->write("} catch (Twig_Sandbox_SecurityError \$e) {\n") - ->indent() - ->write("\$e->setSourceContext(\$this->getSourceContext());\n\n") - ->write("if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") - ->indent() - ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") - ->outdent() - ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") - ->indent() - ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") - ->outdent() - ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") - ->indent() - ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") - ->outdent() - ->write("}\n\n") - ->write("throw \$e;\n") - ->outdent() - ->write("}\n\n") - ; - } -} - -class_alias('Twig_Node_CheckSecurity', 'Twig\Node\CheckSecurityNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Deprecated.php b/system/templateEngines/Twig/Twig1x/Node/Deprecated.php deleted file mode 100644 index fc4c392..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Deprecated.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -class Twig_Node_Deprecated extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - $expr = $this->getNode('expr'); - - if ($expr instanceof Twig_Node_Expression_Constant) { - $compiler->write('@trigger_error(') - ->subcompile($expr); - } else { - $varName = $compiler->getVarName(); - $compiler->write(sprintf('$%s = ', $varName)) - ->subcompile($expr) - ->raw(";\n") - ->write(sprintf('@trigger_error($%s', $varName)); - } - - $compiler - ->raw('.') - ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine())) - ->raw(", E_USER_DEPRECATED);\n") - ; - } -} - -class_alias('Twig_Node_Deprecated', 'Twig\Node\DeprecatedNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Do.php b/system/templateEngines/Twig/Twig1x/Node/Do.php deleted file mode 100644 index 1335045..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Do.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -class Twig_Node_Do extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('') - ->subcompile($this->getNode('expr')) - ->raw(";\n") - ; - } -} - -class_alias('Twig_Node_Do', 'Twig\Node\DoNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Embed.php b/system/templateEngines/Twig/Twig1x/Node/Embed.php deleted file mode 100644 index 3785d3a..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Embed.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ -class Twig_Node_Embed extends Twig_Node_Include -{ - // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) - public function __construct($name, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) - { - parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); - - $this->setAttribute('name', $name); - // to be removed in 2.0, used name instead - $this->setAttribute('filename', $name); - $this->setAttribute('index', $index); - } - - protected function addGetTemplate(Twig_Compiler $compiler) - { - $compiler - ->write('$this->loadTemplate(') - ->string($this->getAttribute('name')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(', ') - ->string($this->getAttribute('index')) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Embed', 'Twig\Node\EmbedNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression.php b/system/templateEngines/Twig/Twig1x/Node/Expression.php deleted file mode 100644 index a99c4e6..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -abstract class Twig_Node_Expression extends Twig_Node -{ -} - -class_alias('Twig_Node_Expression', 'Twig\Node\Expression\AbstractExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Array.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Array.php deleted file mode 100644 index 61e0d96..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Array.php +++ /dev/null @@ -1,83 +0,0 @@ -index = -1; - foreach ($this->getKeyValuePairs() as $pair) { - if ($pair['key'] instanceof Twig_Node_Expression_Constant && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { - $this->index = $pair['key']->getAttribute('value'); - } - } - } - - public function getKeyValuePairs() - { - $pairs = []; - - foreach (array_chunk($this->nodes, 2) as $pair) { - $pairs[] = [ - 'key' => $pair[0], - 'value' => $pair[1], - ]; - } - - return $pairs; - } - - public function hasElement(Twig_Node_Expression $key) - { - foreach ($this->getKeyValuePairs() as $pair) { - // we compare the string representation of the keys - // to avoid comparing the line numbers which are not relevant here. - if ((string) $key === (string) $pair['key']) { - return true; - } - } - - return false; - } - - public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null) - { - if (null === $key) { - $key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine()); - } - - array_push($this->nodes, $key, $value); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->raw('['); - $first = true; - foreach ($this->getKeyValuePairs() as $pair) { - if (!$first) { - $compiler->raw(', '); - } - $first = false; - - $compiler - ->subcompile($pair['key']) - ->raw(' => ') - ->subcompile($pair['value']) - ; - } - $compiler->raw(']'); - } -} - -class_alias('Twig_Node_Expression_Array', 'Twig\Node\Expression\ArrayExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/AssignName.php b/system/templateEngines/Twig/Twig1x/Node/Expression/AssignName.php deleted file mode 100644 index 2e6b4c7..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/AssignName.php +++ /dev/null @@ -1,25 +0,0 @@ -raw('$context[') - ->string($this->getAttribute('name')) - ->raw(']') - ; - } -} - -class_alias('Twig_Node_Expression_AssignName', 'Twig\Node\Expression\AssignNameExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary.php deleted file mode 100644 index e9155dd..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary.php +++ /dev/null @@ -1,37 +0,0 @@ - $left, 'right' => $right], [], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('left')) - ->raw(' ') - ; - $this->operator($compiler); - $compiler - ->raw(' ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - abstract public function operator(Twig_Compiler $compiler); -} - -class_alias('Twig_Node_Expression_Binary', 'Twig\Node\Expression\Binary\AbstractBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Add.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Add.php deleted file mode 100644 index 5a09d83..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Add.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('+'); - } -} - -class_alias('Twig_Node_Expression_Binary_Add', 'Twig\Node\Expression\Binary\AddBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/And.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/And.php deleted file mode 100644 index 9ffddce..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/And.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('&&'); - } -} - -class_alias('Twig_Node_Expression_Binary_And', 'Twig\Node\Expression\Binary\AndBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseAnd.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseAnd.php deleted file mode 100644 index e46e9eb..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseAnd.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('&'); - } -} - -class_alias('Twig_Node_Expression_Binary_BitwiseAnd', 'Twig\Node\Expression\Binary\BitwiseAndBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseOr.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseOr.php deleted file mode 100644 index 5d7f1b7..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseOr.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('|'); - } -} - -class_alias('Twig_Node_Expression_Binary_BitwiseOr', 'Twig\Node\Expression\Binary\BitwiseOrBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseXor.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseXor.php deleted file mode 100644 index 82edf51..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/BitwiseXor.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('^'); - } -} - -class_alias('Twig_Node_Expression_Binary_BitwiseXor', 'Twig\Node\Expression\Binary\BitwiseXorBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Concat.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Concat.php deleted file mode 100644 index 91abca6..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Concat.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('.'); - } -} - -class_alias('Twig_Node_Expression_Binary_Concat', 'Twig\Node\Expression\Binary\ConcatBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Div.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Div.php deleted file mode 100644 index 38ffa30..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Div.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('/'); - } -} - -class_alias('Twig_Node_Expression_Binary_Div', 'Twig\Node\Expression\Binary\DivBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/EndsWith.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/EndsWith.php deleted file mode 100644 index 85c5293..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/EndsWith.php +++ /dev/null @@ -1,32 +0,0 @@ -getVarName(); - $right = $compiler->getVarName(); - $compiler - ->raw(sprintf('(is_string($%s = ', $left)) - ->subcompile($this->getNode('left')) - ->raw(sprintf(') && is_string($%s = ', $right)) - ->subcompile($this->getNode('right')) - ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right)) - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw(''); - } -} - -class_alias('Twig_Node_Expression_Binary_EndsWith', 'Twig\Node\Expression\Binary\EndsWithBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Equal.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Equal.php deleted file mode 100644 index a6a6946..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Equal.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('=='); - } -} - -class_alias('Twig_Node_Expression_Binary_Equal', 'Twig\Node\Expression\Binary\EqualBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/FloorDiv.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/FloorDiv.php deleted file mode 100644 index 7393bcb..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/FloorDiv.php +++ /dev/null @@ -1,26 +0,0 @@ -raw('(int) floor('); - parent::compile($compiler); - $compiler->raw(')'); - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('/'); - } -} - -class_alias('Twig_Node_Expression_Binary_FloorDiv', 'Twig\Node\Expression\Binary\FloorDivBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Greater.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Greater.php deleted file mode 100644 index 832f979..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Greater.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('>'); - } -} - -class_alias('Twig_Node_Expression_Binary_Greater', 'Twig\Node\Expression\Binary\GreaterBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/GreaterEqual.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/GreaterEqual.php deleted file mode 100644 index c5f7624..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/GreaterEqual.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('>='); - } -} - -class_alias('Twig_Node_Expression_Binary_GreaterEqual', 'Twig\Node\Expression\Binary\GreaterEqualBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/In.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/In.php deleted file mode 100644 index af11244..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/In.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('twig_in_filter(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('in'); - } -} - -class_alias('Twig_Node_Expression_Binary_In', 'Twig\Node\Expression\Binary\InBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Less.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Less.php deleted file mode 100644 index ab8fc1f..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Less.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('<'); - } -} - -class_alias('Twig_Node_Expression_Binary_Less', 'Twig\Node\Expression\Binary\LessBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/LessEqual.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/LessEqual.php deleted file mode 100644 index 71a279e..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/LessEqual.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('<='); - } -} - -class_alias('Twig_Node_Expression_Binary_LessEqual', 'Twig\Node\Expression\Binary\LessEqualBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Matches.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Matches.php deleted file mode 100644 index 5cb8558..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Matches.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('preg_match(') - ->subcompile($this->getNode('right')) - ->raw(', ') - ->subcompile($this->getNode('left')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw(''); - } -} - -class_alias('Twig_Node_Expression_Binary_Matches', 'Twig\Node\Expression\Binary\MatchesBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mod.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mod.php deleted file mode 100644 index 2810963..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mod.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('%'); - } -} - -class_alias('Twig_Node_Expression_Binary_Mod', 'Twig\Node\Expression\Binary\ModBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mul.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mul.php deleted file mode 100644 index 790c6a2..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Mul.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('*'); - } -} - -class_alias('Twig_Node_Expression_Binary_Mul', 'Twig\Node\Expression\Binary\MulBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotEqual.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotEqual.php deleted file mode 100644 index bb45c9e..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotEqual.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('!='); - } -} - -class_alias('Twig_Node_Expression_Binary_NotEqual', 'Twig\Node\Expression\Binary\NotEqualBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotIn.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotIn.php deleted file mode 100644 index 9dedf92..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/NotIn.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('!twig_in_filter(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('not in'); - } -} - -class_alias('Twig_Node_Expression_Binary_NotIn', 'Twig\Node\Expression\Binary\NotInBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Or.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Or.php deleted file mode 100644 index dc9eece..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Or.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('||'); - } -} - -class_alias('Twig_Node_Expression_Binary_Or', 'Twig\Node\Expression\Binary\OrBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Power.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Power.php deleted file mode 100644 index d24777b..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Power.php +++ /dev/null @@ -1,34 +0,0 @@ -= 50600) { - return parent::compile($compiler); - } - - $compiler - ->raw('pow(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('**'); - } -} - -class_alias('Twig_Node_Expression_Binary_Power', 'Twig\Node\Expression\Binary\PowerBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Range.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Range.php deleted file mode 100644 index 187f676..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Range.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('range(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('..'); - } -} - -class_alias('Twig_Node_Expression_Binary_Range', 'Twig\Node\Expression\Binary\RangeBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/StartsWith.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/StartsWith.php deleted file mode 100644 index 7e43b8d..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/StartsWith.php +++ /dev/null @@ -1,32 +0,0 @@ -getVarName(); - $right = $compiler->getVarName(); - $compiler - ->raw(sprintf('(is_string($%s = ', $left)) - ->subcompile($this->getNode('left')) - ->raw(sprintf(') && is_string($%s = ', $right)) - ->subcompile($this->getNode('right')) - ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw(''); - } -} - -class_alias('Twig_Node_Expression_Binary_StartsWith', 'Twig\Node\Expression\Binary\StartsWithBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Sub.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Sub.php deleted file mode 100644 index cff8ed0..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Binary/Sub.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('-'); - } -} - -class_alias('Twig_Node_Expression_Binary_Sub', 'Twig\Node\Expression\Binary\SubBinary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/BlockReference.php b/system/templateEngines/Twig/Twig1x/Node/Expression/BlockReference.php deleted file mode 100644 index 4beb13a..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/BlockReference.php +++ /dev/null @@ -1,93 +0,0 @@ - - */ -class Twig_Node_Expression_BlockReference extends Twig_Node_Expression -{ - /** - * @param Twig_Node|null $template - */ - public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null) - { - if (is_bool($template)) { - @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); - - $template = null; - } - - $nodes = ['name' => $name]; - if (null !== $template) { - $nodes['template'] = $template; - } - - parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('is_defined_test')) { - $this->compileTemplateCall($compiler, 'hasBlock'); - } else { - if ($this->getAttribute('output')) { - $compiler->addDebugInfo($this); - - $this - ->compileTemplateCall($compiler, 'displayBlock') - ->raw(";\n"); - } else { - $this->compileTemplateCall($compiler, 'renderBlock'); - } - } - } - - private function compileTemplateCall(Twig_Compiler $compiler, $method) - { - if (!$this->hasNode('template')) { - $compiler->write('$this'); - } else { - $compiler - ->write('$this->loadTemplate(') - ->subcompile($this->getNode('template')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(')') - ; - } - - $compiler->raw(sprintf('->%s', $method)); - $this->compileBlockArguments($compiler); - - return $compiler; - } - - private function compileBlockArguments(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('name')) - ->raw(', $context'); - - if (!$this->hasNode('template')) { - $compiler->raw(', $blocks'); - } - - return $compiler->raw(')'); - } -} - -class_alias('Twig_Node_Expression_BlockReference', 'Twig\Node\Expression\BlockReferenceExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Call.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Call.php deleted file mode 100644 index d1d3025..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Call.php +++ /dev/null @@ -1,293 +0,0 @@ -hasAttribute('callable') && $callable = $this->getAttribute('callable')) { - if (is_string($callable) && false === strpos($callable, '::')) { - $compiler->raw($callable); - } else { - list($r, $callable) = $this->reflectCallable($callable); - if ($r instanceof ReflectionMethod && is_string($callable[0])) { - if ($r->isStatic()) { - $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1])); - } else { - $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); - } - } elseif ($r instanceof ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) { - $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', get_class($callable[0]), $callable[1])); - } else { - $type = ucfirst($this->getAttribute('type')); - $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', $type, $this->getAttribute('name'))); - $closingParenthesis = true; - $isArray = true; - } - } - } else { - $compiler->raw($this->getAttribute('thing')->compile()); - } - - $this->compileArguments($compiler, $isArray); - - if ($closingParenthesis) { - $compiler->raw(')'); - } - } - - protected function compileArguments(Twig_Compiler $compiler, $isArray = false) - { - $compiler->raw($isArray ? '[' : '('); - - $first = true; - - if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { - $compiler->raw('$this->env'); - $first = false; - } - - if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->raw('$context'); - $first = false; - } - - if ($this->hasAttribute('arguments')) { - foreach ($this->getAttribute('arguments') as $argument) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->string($argument); - $first = false; - } - } - - if ($this->hasNode('node')) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->subcompile($this->getNode('node')); - $first = false; - } - - if ($this->hasNode('arguments')) { - $callable = $this->hasAttribute('callable') ? $this->getAttribute('callable') : null; - - $arguments = $this->getArguments($callable, $this->getNode('arguments')); - - foreach ($arguments as $node) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->subcompile($node); - $first = false; - } - } - - $compiler->raw($isArray ? ']' : ')'); - } - - protected function getArguments($callable, $arguments) - { - $callType = $this->getAttribute('type'); - $callName = $this->getAttribute('name'); - - $parameters = []; - $named = false; - foreach ($arguments as $name => $node) { - if (!is_int($name)) { - $named = true; - $name = $this->normalizeName($name); - } elseif ($named) { - throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine()); - } - - $parameters[$name] = $node; - } - - $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic'); - if (!$named && !$isVariadic) { - return $parameters; - } - - if (!$callable) { - if ($named) { - $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName); - } else { - $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName); - } - - throw new LogicException($message); - } - - $callableParameters = $this->getCallableParameters($callable, $isVariadic); - $arguments = []; - $names = []; - $missingArguments = []; - $optionalArguments = []; - $pos = 0; - foreach ($callableParameters as $callableParameter) { - $names[] = $name = $this->normalizeName($callableParameter->name); - - if (array_key_exists($name, $parameters)) { - if (array_key_exists($pos, $parameters)) { - throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); - } - - if (count($missingArguments)) { - throw new Twig_Error_Syntax(sprintf( - 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', - $name, $callType, $callName, implode(', ', $names), count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) - ), $this->getTemplateLine()); - } - - $arguments = array_merge($arguments, $optionalArguments); - $arguments[] = $parameters[$name]; - unset($parameters[$name]); - $optionalArguments = []; - } elseif (array_key_exists($pos, $parameters)) { - $arguments = array_merge($arguments, $optionalArguments); - $arguments[] = $parameters[$pos]; - unset($parameters[$pos]); - $optionalArguments = []; - ++$pos; - } elseif ($callableParameter->isDefaultValueAvailable()) { - $optionalArguments[] = new Twig_Node_Expression_Constant($callableParameter->getDefaultValue(), -1); - } elseif ($callableParameter->isOptional()) { - if (empty($parameters)) { - break; - } else { - $missingArguments[] = $name; - } - } else { - throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); - } - } - - if ($isVariadic) { - $arbitraryArguments = new Twig_Node_Expression_Array([], -1); - foreach ($parameters as $key => $value) { - if (is_int($key)) { - $arbitraryArguments->addElement($value); - } else { - $arbitraryArguments->addElement($value, new Twig_Node_Expression_Constant($key, -1)); - } - unset($parameters[$key]); - } - - if ($arbitraryArguments->count()) { - $arguments = array_merge($arguments, $optionalArguments); - $arguments[] = $arbitraryArguments; - } - } - - if (!empty($parameters)) { - $unknownParameter = null; - foreach ($parameters as $parameter) { - if ($parameter instanceof Twig_Node) { - $unknownParameter = $parameter; - break; - } - } - - throw new Twig_Error_Syntax(sprintf( - 'Unknown argument%s "%s" for %s "%s(%s)".', - count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) - ), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine()); - } - - return $arguments; - } - - protected function normalizeName($name) - { - return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); - } - - private function getCallableParameters($callable, $isVariadic) - { - list($r) = $this->reflectCallable($callable); - if (null === $r) { - return []; - } - - $parameters = $r->getParameters(); - if ($this->hasNode('node')) { - array_shift($parameters); - } - if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { - array_shift($parameters); - } - if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { - array_shift($parameters); - } - if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { - foreach ($this->getAttribute('arguments') as $argument) { - array_shift($parameters); - } - } - if ($isVariadic) { - $argument = end($parameters); - if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { - array_pop($parameters); - } else { - $callableName = $r->name; - if ($r instanceof ReflectionMethod) { - $callableName = $r->getDeclaringClass()->name.'::'.$callableName; - } - - throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); - } - } - - return $parameters; - } - - private function reflectCallable($callable) - { - if (null !== $this->reflector) { - return $this->reflector; - } - - if (is_array($callable)) { - if (!method_exists($callable[0], $callable[1])) { - // __call() - return [null, []]; - } - $r = new ReflectionMethod($callable[0], $callable[1]); - } elseif (is_object($callable) && !$callable instanceof Closure) { - $r = new ReflectionObject($callable); - $r = $r->getMethod('__invoke'); - $callable = [$callable, '__invoke']; - } elseif (is_string($callable) && false !== $pos = strpos($callable, '::')) { - $class = substr($callable, 0, $pos); - $method = substr($callable, $pos + 2); - if (!method_exists($class, $method)) { - // __staticCall() - return [null, []]; - } - $r = new ReflectionMethod($callable); - $callable = [$class, $method]; - } else { - $r = new ReflectionFunction($callable); - } - - return $this->reflector = [$r, $callable]; - } -} - -class_alias('Twig_Node_Expression_Call', 'Twig\Node\Expression\CallExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Conditional.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Conditional.php deleted file mode 100644 index 996772a..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Conditional.php +++ /dev/null @@ -1,33 +0,0 @@ - $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('((') - ->subcompile($this->getNode('expr1')) - ->raw(') ? (') - ->subcompile($this->getNode('expr2')) - ->raw(') : (') - ->subcompile($this->getNode('expr3')) - ->raw('))') - ; - } -} - -class_alias('Twig_Node_Expression_Conditional', 'Twig\Node\Expression\ConditionalExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Constant.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Constant.php deleted file mode 100644 index 7304e8c..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Constant.php +++ /dev/null @@ -1,25 +0,0 @@ - $value], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->repr($this->getAttribute('value')); - } -} - -class_alias('Twig_Node_Expression_Constant', 'Twig\Node\Expression\ConstantExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/ExtensionReference.php b/system/templateEngines/Twig/Twig1x/Node/Expression/ExtensionReference.php deleted file mode 100644 index 7bcc078..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/ExtensionReference.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * @deprecated since 1.23 and will be removed in 2.0. - */ -class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression -{ - public function __construct($name, $lineno, $tag = null) - { - parent::__construct([], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); - } -} diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Filter.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Filter.php deleted file mode 100644 index 7b5952f..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Filter.php +++ /dev/null @@ -1,41 +0,0 @@ - $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getNode('filter')->getAttribute('value'); - $filter = $compiler->getEnvironment()->getFilter($name); - - $this->setAttribute('name', $name); - $this->setAttribute('type', 'filter'); - $this->setAttribute('thing', $filter); - $this->setAttribute('needs_environment', $filter->needsEnvironment()); - $this->setAttribute('needs_context', $filter->needsContext()); - $this->setAttribute('arguments', $filter->getArguments()); - if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof Twig_SimpleFilter) { - $this->setAttribute('callable', $filter->getCallable()); - } - if ($filter instanceof Twig_SimpleFilter) { - $this->setAttribute('is_variadic', $filter->isVariadic()); - } - - $this->compileCallable($compiler); - } -} - -class_alias('Twig_Node_Expression_Filter', 'Twig\Node\Expression\FilterExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Filter/Default.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Filter/Default.php deleted file mode 100644 index d2e19d5..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Filter/Default.php +++ /dev/null @@ -1,45 +0,0 @@ - - * {{ var.foo|default('foo item on var is not defined') }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter -{ - public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) - { - $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); - - if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) { - $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine()); - $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine()); - - $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine()); - } else { - $node = $default; - } - - parent::__construct($node, $filterName, $arguments, $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('node')); - } -} - -class_alias('Twig_Node_Expression_Filter_Default', 'Twig\Node\Expression\Filter\DefaultFilter', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Function.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Function.php deleted file mode 100644 index c19633f..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Function.php +++ /dev/null @@ -1,45 +0,0 @@ - $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $function = $compiler->getEnvironment()->getFunction($name); - - $this->setAttribute('name', $name); - $this->setAttribute('type', 'function'); - $this->setAttribute('thing', $function); - $this->setAttribute('needs_environment', $function->needsEnvironment()); - $this->setAttribute('needs_context', $function->needsContext()); - $this->setAttribute('arguments', $function->getArguments()); - if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) { - $callable = $function->getCallable(); - if ('constant' === $name && $this->getAttribute('is_defined_test')) { - $callable = 'twig_constant_is_defined'; - } - - $this->setAttribute('callable', $callable); - } - if ($function instanceof Twig_SimpleFunction) { - $this->setAttribute('is_variadic', $function->isVariadic()); - } - - $this->compileCallable($compiler); - } -} - -class_alias('Twig_Node_Expression_Function', 'Twig\Node\Expression\FunctionExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/GetAttr.php b/system/templateEngines/Twig/Twig1x/Node/Expression/GetAttr.php deleted file mode 100644 index 8976915..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/GetAttr.php +++ /dev/null @@ -1,74 +0,0 @@ - $node, 'attribute' => $attribute]; - if (null !== $arguments) { - $nodes['arguments'] = $arguments; - } - - parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('disable_c_ext')) { - @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED); - } - - if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { - $compiler->raw('twig_template_get_attributes($this, '); - } else { - $compiler->raw('$this->getAttribute('); - } - - if ($this->getAttribute('ignore_strict_check')) { - $this->getNode('node')->setAttribute('ignore_strict_check', true); - } - - $compiler->subcompile($this->getNode('node')); - - $compiler->raw(', ')->subcompile($this->getNode('attribute')); - - // only generate optional arguments when needed (to make generated code more readable) - $needFourth = $this->getAttribute('ignore_strict_check'); - $needThird = $needFourth || $this->getAttribute('is_defined_test'); - $needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type'); - $needFirst = $needSecond || $this->hasNode('arguments'); - - if ($needFirst) { - if ($this->hasNode('arguments')) { - $compiler->raw(', ')->subcompile($this->getNode('arguments')); - } else { - $compiler->raw(', []'); - } - } - - if ($needSecond) { - $compiler->raw(', ')->repr($this->getAttribute('type')); - } - - if ($needThird) { - $compiler->raw(', ')->repr($this->getAttribute('is_defined_test')); - } - - if ($needFourth) { - $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check')); - } - - $compiler->raw(')'); - } -} - -class_alias('Twig_Node_Expression_GetAttr', 'Twig\Node\Expression\GetAttrExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/MethodCall.php b/system/templateEngines/Twig/Twig1x/Node/Expression/MethodCall.php deleted file mode 100644 index b8a8345..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/MethodCall.php +++ /dev/null @@ -1,43 +0,0 @@ - $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno); - - if ($node instanceof Twig_Node_Expression_Name) { - $node->setAttribute('always_defined', true); - } - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->subcompile($this->getNode('node')) - ->raw('->') - ->raw($this->getAttribute('method')) - ->raw('(') - ; - $first = true; - foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { - if (!$first) { - $compiler->raw(', '); - } - $first = false; - - $compiler->subcompile($pair['value']); - } - $compiler->raw(')'); - } -} - -class_alias('Twig_Node_Expression_MethodCall', 'Twig\Node\Expression\MethodCallExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Name.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Name.php deleted file mode 100644 index 2d1d3d1..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Name.php +++ /dev/null @@ -1,107 +0,0 @@ - '$this', - '_context' => '$context', - '_charset' => '$this->env->getCharset()', - ]; - - public function __construct($name, $lineno) - { - parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - - $compiler->addDebugInfo($this); - - if ($this->getAttribute('is_defined_test')) { - if ($this->isSpecial()) { - $compiler->repr(true); - } else { - $compiler - ->raw('(isset($context[') - ->string($name) - ->raw(']) || array_key_exists(') - ->string($name) - ->raw(', $context))'); - } - } elseif ($this->isSpecial()) { - $compiler->raw($this->specialVars[$name]); - } elseif ($this->getAttribute('always_defined')) { - $compiler - ->raw('$context[') - ->string($name) - ->raw(']') - ; - } else { - if (PHP_VERSION_ID >= 70000) { - // use PHP 7 null coalescing operator - $compiler - ->raw('($context[') - ->string($name) - ->raw('] ?? ') - ; - - if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { - $compiler->raw('null)'); - } else { - $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); - } - } elseif (PHP_VERSION_ID >= 50400) { - // PHP 5.4 ternary operator performance was optimized - $compiler - ->raw('(isset($context[') - ->string($name) - ->raw(']) ? $context[') - ->string($name) - ->raw('] : ') - ; - - if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { - $compiler->raw('null)'); - } else { - $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); - } - } else { - $compiler - ->raw('$this->getContext($context, ') - ->string($name) - ; - - if ($this->getAttribute('ignore_strict_check')) { - $compiler->raw(', true'); - } - - $compiler - ->raw(')') - ; - } - } - } - - public function isSpecial() - { - return isset($this->specialVars[$this->getAttribute('name')]); - } - - public function isSimple() - { - return !$this->isSpecial() && !$this->getAttribute('is_defined_test'); - } -} - -class_alias('Twig_Node_Expression_Name', 'Twig\Node\Expression\NameExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/NullCoalesce.php b/system/templateEngines/Twig/Twig1x/Node/Expression/NullCoalesce.php deleted file mode 100644 index eaafa4c..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/NullCoalesce.php +++ /dev/null @@ -1,48 +0,0 @@ -getTemplateLine()), - new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getTemplateLine()), $left->getTemplateLine()), - $left->getTemplateLine() - ); - - parent::__construct($test, $left, $right, $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - /* - * This optimizes only one case. PHP 7 also supports more complex expressions - * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works, - * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced - * cases might be implemented as an optimizer node visitor, but has not been done - * as benefits are probably not worth the added complexity. - */ - if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof Twig_Node_Expression_Name) { - $this->getNode('expr2')->setAttribute('always_defined', true); - $compiler - ->raw('((') - ->subcompile($this->getNode('expr2')) - ->raw(') ?? (') - ->subcompile($this->getNode('expr3')) - ->raw('))') - ; - } else { - parent::compile($compiler); - } - } -} - -class_alias('Twig_Node_Expression_NullCoalesce', 'Twig\Node\Expression\NullCoalesceExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Parent.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Parent.php deleted file mode 100644 index 8623685..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Parent.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Twig_Node_Expression_Parent extends Twig_Node_Expression -{ - public function __construct($name, $lineno, $tag = null) - { - parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('output')) { - $compiler - ->addDebugInfo($this) - ->write('$this->displayParentBlock(') - ->string($this->getAttribute('name')) - ->raw(", \$context, \$blocks);\n") - ; - } else { - $compiler - ->raw('$this->renderParentBlock(') - ->string($this->getAttribute('name')) - ->raw(', $context, $blocks)') - ; - } - } -} - -class_alias('Twig_Node_Expression_Parent', 'Twig\Node\Expression\ParentExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/TempName.php b/system/templateEngines/Twig/Twig1x/Node/Expression/TempName.php deleted file mode 100644 index 4be1cc2..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/TempName.php +++ /dev/null @@ -1,28 +0,0 @@ - $name], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('$_') - ->raw($this->getAttribute('name')) - ->raw('_') - ; - } -} - -class_alias('Twig_Node_Expression_TempName', 'Twig\Node\Expression\TempNameExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test.php deleted file mode 100644 index a543ec5..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test.php +++ /dev/null @@ -1,45 +0,0 @@ - $node]; - if (null !== $arguments) { - $nodes['arguments'] = $arguments; - } - - parent::__construct($nodes, ['name' => $name], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $test = $compiler->getEnvironment()->getTest($name); - - $this->setAttribute('name', $name); - $this->setAttribute('type', 'test'); - $this->setAttribute('thing', $test); - if ($test instanceof Twig_SimpleTest) { - $this->setAttribute('arguments', $test->getArguments()); - } - if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) { - $this->setAttribute('callable', $test->getCallable()); - } - if ($test instanceof Twig_SimpleTest) { - $this->setAttribute('is_variadic', $test->isVariadic()); - } - - $this->compileCallable($compiler); - } -} - -class_alias('Twig_Node_Expression_Test', 'Twig\Node\Expression\TestExpression', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Constant.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Constant.php deleted file mode 100644 index a51a4ba..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Constant.php +++ /dev/null @@ -1,48 +0,0 @@ - - * {% if post.status is constant('Post::PUBLISHED') %} - * the status attribute is exactly the same as Post::PUBLISHED - * {% endif %} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' === constant(') - ; - - if ($this->getNode('arguments')->hasNode(1)) { - $compiler - ->raw('get_class(') - ->subcompile($this->getNode('arguments')->getNode(1)) - ->raw(')."::".') - ; - } - - $compiler - ->subcompile($this->getNode('arguments')->getNode(0)) - ->raw('))') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Constant', 'Twig\Node\Expression\Test\ConstantTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Defined.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Defined.php deleted file mode 100644 index 2136c39..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Defined.php +++ /dev/null @@ -1,61 +0,0 @@ - - * {# defined works with variable names and variable attributes #} - * {% if foo is defined %} - * {# ... #} - * {% endif %} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test -{ - public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) - { - if ($node instanceof Twig_Node_Expression_Name) { - $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_GetAttr) { - $node->setAttribute('is_defined_test', true); - $this->changeIgnoreStrictCheck($node); - } elseif ($node instanceof Twig_Node_Expression_BlockReference) { - $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name')) { - $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) { - $node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine()); - } else { - throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine()); - } - - parent::__construct($node, $name, $arguments, $lineno); - } - - protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) - { - $node->setAttribute('ignore_strict_check', true); - - if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) { - $this->changeIgnoreStrictCheck($node->getNode('node')); - } - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('node')); - } -} - -class_alias('Twig_Node_Expression_Test_Defined', 'Twig\Node\Expression\Test\DefinedTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Divisibleby.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Divisibleby.php deleted file mode 100644 index a5d7196..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Divisibleby.php +++ /dev/null @@ -1,35 +0,0 @@ - - * {% if loop.index is divisible by(3) %} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(0 == ') - ->subcompile($this->getNode('node')) - ->raw(' % ') - ->subcompile($this->getNode('arguments')->getNode(0)) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Divisibleby', 'Twig\Node\Expression\Test\DivisiblebyTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Even.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Even.php deleted file mode 100644 index 7e198be..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Even.php +++ /dev/null @@ -1,34 +0,0 @@ - - * {{ var is even }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Even extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' % 2 == 0') - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Even', 'Twig\Node\Expression\Test\EvenTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Null.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Null.php deleted file mode 100644 index 3746e4c..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Null.php +++ /dev/null @@ -1,33 +0,0 @@ - - * {{ var is none }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Null extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(null === ') - ->subcompile($this->getNode('node')) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Null', 'Twig\Node\Expression\Test\NullTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Odd.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Odd.php deleted file mode 100644 index 0c6c099..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Odd.php +++ /dev/null @@ -1,34 +0,0 @@ - - * {{ var is odd }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' % 2 == 1') - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Odd', 'Twig\Node\Expression\Test\OddTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Sameas.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Sameas.php deleted file mode 100644 index e95ff1f..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Test/Sameas.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -class Twig_Node_Expression_Test_Sameas extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' === ') - ->subcompile($this->getNode('arguments')->getNode(0)) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Sameas', 'Twig\Node\Expression\Test\SameasTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Unary.php deleted file mode 100644 index abf191a..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary.php +++ /dev/null @@ -1,29 +0,0 @@ - $node], [], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->raw(' '); - $this->operator($compiler); - $compiler->subcompile($this->getNode('node')); - } - - abstract public function operator(Twig_Compiler $compiler); -} - -class_alias('Twig_Node_Expression_Unary', 'Twig\Node\Expression\Unary\AbstractUnary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Neg.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Neg.php deleted file mode 100644 index 039d933..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Neg.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('-'); - } -} - -class_alias('Twig_Node_Expression_Unary_Neg', 'Twig\Node\Expression\Unary\NegUnary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Not.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Not.php deleted file mode 100644 index a0860b1..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Not.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('!'); - } -} - -class_alias('Twig_Node_Expression_Unary_Not', 'Twig\Node\Expression\Unary\NotUnary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Pos.php b/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Pos.php deleted file mode 100644 index eeff545..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Expression/Unary/Pos.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('+'); - } -} - -class_alias('Twig_Node_Expression_Unary_Pos', 'Twig\Node\Expression\Unary\PosUnary', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Flush.php b/system/templateEngines/Twig/Twig1x/Node/Flush.php deleted file mode 100644 index 5d3ffd5..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Flush.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Node_Flush extends Twig_Node -{ - public function __construct($lineno, $tag) - { - parent::__construct([], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("flush();\n") - ; - } -} - -class_alias('Twig_Node_Flush', 'Twig\Node\FlushNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/For.php b/system/templateEngines/Twig/Twig1x/Node/For.php deleted file mode 100644 index 7651945..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/For.php +++ /dev/null @@ -1,113 +0,0 @@ - - */ -class Twig_Node_For extends Twig_Node -{ - protected $loop; - - public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null) - { - $body = new Twig_Node([$body, $this->loop = new Twig_Node_ForLoop($lineno, $tag)]); - - if (null !== $ifexpr) { - $body = new Twig_Node_If(new Twig_Node([$ifexpr, $body]), null, $lineno, $tag); - } - - $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; - if (null !== $else) { - $nodes['else'] = $else; - } - - parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("\$context['_parent'] = \$context;\n") - ->write("\$context['_seq'] = twig_ensure_traversable(") - ->subcompile($this->getNode('seq')) - ->raw(");\n") - ; - - if ($this->hasNode('else')) { - $compiler->write("\$context['_iterated'] = false;\n"); - } - - if ($this->getAttribute('with_loop')) { - $compiler - ->write("\$context['loop'] = [\n") - ->write(" 'parent' => \$context['_parent'],\n") - ->write(" 'index0' => 0,\n") - ->write(" 'index' => 1,\n") - ->write(" 'first' => true,\n") - ->write("];\n") - ; - - if (!$this->getAttribute('ifexpr')) { - $compiler - ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n") - ->indent() - ->write("\$length = count(\$context['_seq']);\n") - ->write("\$context['loop']['revindex0'] = \$length - 1;\n") - ->write("\$context['loop']['revindex'] = \$length;\n") - ->write("\$context['loop']['length'] = \$length;\n") - ->write("\$context['loop']['last'] = 1 === \$length;\n") - ->outdent() - ->write("}\n") - ; - } - } - - $this->loop->setAttribute('else', $this->hasNode('else')); - $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop')); - $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr')); - - $compiler - ->write("foreach (\$context['_seq'] as ") - ->subcompile($this->getNode('key_target')) - ->raw(' => ') - ->subcompile($this->getNode('value_target')) - ->raw(") {\n") - ->indent() - ->subcompile($this->getNode('body')) - ->outdent() - ->write("}\n") - ; - - if ($this->hasNode('else')) { - $compiler - ->write("if (!\$context['_iterated']) {\n") - ->indent() - ->subcompile($this->getNode('else')) - ->outdent() - ->write("}\n") - ; - } - - $compiler->write("\$_parent = \$context['_parent'];\n"); - - // remove some "private" loop variables (needed for nested loops) - $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); - - // keep the values set in the inner context for variables defined in the outer context - $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n"); - } -} - -class_alias('Twig_Node_For', 'Twig\Node\ForNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/ForLoop.php b/system/templateEngines/Twig/Twig1x/Node/ForLoop.php deleted file mode 100644 index 31f282d..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/ForLoop.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -class Twig_Node_ForLoop extends Twig_Node -{ - public function __construct($lineno, $tag = null) - { - parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('else')) { - $compiler->write("\$context['_iterated'] = true;\n"); - } - - if ($this->getAttribute('with_loop')) { - $compiler - ->write("++\$context['loop']['index0'];\n") - ->write("++\$context['loop']['index'];\n") - ->write("\$context['loop']['first'] = false;\n") - ; - - if (!$this->getAttribute('ifexpr')) { - $compiler - ->write("if (isset(\$context['loop']['length'])) {\n") - ->indent() - ->write("--\$context['loop']['revindex0'];\n") - ->write("--\$context['loop']['revindex'];\n") - ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") - ->outdent() - ->write("}\n") - ; - } - } - } -} - -class_alias('Twig_Node_ForLoop', 'Twig\Node\ForLoopNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/If.php b/system/templateEngines/Twig/Twig1x/Node/If.php deleted file mode 100644 index b096cd4..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/If.php +++ /dev/null @@ -1,68 +0,0 @@ - - */ -class Twig_Node_If extends Twig_Node -{ - public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null) - { - $nodes = ['tests' => $tests]; - if (null !== $else) { - $nodes['else'] = $else; - } - - parent::__construct($nodes, [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) { - if ($i > 0) { - $compiler - ->outdent() - ->write('} elseif (') - ; - } else { - $compiler - ->write('if (') - ; - } - - $compiler - ->subcompile($this->getNode('tests')->getNode($i)) - ->raw(") {\n") - ->indent() - ->subcompile($this->getNode('tests')->getNode($i + 1)) - ; - } - - if ($this->hasNode('else')) { - $compiler - ->outdent() - ->write("} else {\n") - ->indent() - ->subcompile($this->getNode('else')) - ; - } - - $compiler - ->outdent() - ->write("}\n"); - } -} - -class_alias('Twig_Node_If', 'Twig\Node\IfNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Import.php b/system/templateEngines/Twig/Twig1x/Node/Import.php deleted file mode 100644 index 44b2131..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Import.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -class Twig_Node_Import extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $var, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('') - ->subcompile($this->getNode('var')) - ->raw(' = ') - ; - - if ($this->getNode('expr') instanceof Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) { - $compiler->raw('$this'); - } else { - $compiler - ->raw('$this->loadTemplate(') - ->subcompile($this->getNode('expr')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(')') - ; - } - - $compiler->raw(";\n"); - } -} - -class_alias('Twig_Node_Import', 'Twig\Node\ImportNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Include.php b/system/templateEngines/Twig/Twig1x/Node/Include.php deleted file mode 100644 index 4b26381..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Include.php +++ /dev/null @@ -1,90 +0,0 @@ - - */ -class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) - { - $nodes = ['expr' => $expr]; - if (null !== $variables) { - $nodes['variables'] = $variables; - } - - parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - if ($this->getAttribute('ignore_missing')) { - $compiler - ->write("try {\n") - ->indent() - ; - } - - $this->addGetTemplate($compiler); - - $compiler->raw('->display('); - - $this->addTemplateArguments($compiler); - - $compiler->raw(");\n"); - - if ($this->getAttribute('ignore_missing')) { - $compiler - ->outdent() - ->write("} catch (Twig_Error_Loader \$e) {\n") - ->indent() - ->write("// ignore missing template\n") - ->outdent() - ->write("}\n\n") - ; - } - } - - protected function addGetTemplate(Twig_Compiler $compiler) - { - $compiler - ->write('$this->loadTemplate(') - ->subcompile($this->getNode('expr')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(')') - ; - } - - protected function addTemplateArguments(Twig_Compiler $compiler) - { - if (!$this->hasNode('variables')) { - $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); - } elseif (false === $this->getAttribute('only')) { - $compiler - ->raw('array_merge($context, ') - ->subcompile($this->getNode('variables')) - ->raw(')') - ; - } else { - $compiler->subcompile($this->getNode('variables')); - } - } -} - -class_alias('Twig_Node_Include', 'Twig\Node\IncludeNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Macro.php b/system/templateEngines/Twig/Twig1x/Node/Macro.php deleted file mode 100644 index 0c4f928..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Macro.php +++ /dev/null @@ -1,125 +0,0 @@ - - */ -class Twig_Node_Macro extends Twig_Node -{ - const VARARGS_NAME = 'varargs'; - - public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null) - { - foreach ($arguments as $argumentName => $argument) { - if (self::VARARGS_NAME === $argumentName) { - throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine()); - } - } - - parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write(sprintf('public function get%s(', $this->getAttribute('name'))) - ; - - $count = count($this->getNode('arguments')); - $pos = 0; - foreach ($this->getNode('arguments') as $name => $default) { - $compiler - ->raw('$__'.$name.'__ = ') - ->subcompile($default) - ; - - if (++$pos < $count) { - $compiler->raw(', '); - } - } - - if (PHP_VERSION_ID >= 50600) { - if ($count) { - $compiler->raw(', '); - } - - $compiler->raw('...$__varargs__'); - } - - $compiler - ->raw(")\n") - ->write("{\n") - ->indent() - ; - - $compiler - ->write("\$context = \$this->env->mergeGlobals([\n") - ->indent() - ; - - foreach ($this->getNode('arguments') as $name => $default) { - $compiler - ->write('') - ->string($name) - ->raw(' => $__'.$name.'__') - ->raw(",\n") - ; - } - - $compiler - ->write('') - ->string(self::VARARGS_NAME) - ->raw(' => ') - ; - - if (PHP_VERSION_ID >= 50600) { - $compiler->raw("\$__varargs__,\n"); - } else { - $compiler - ->raw('func_num_args() > ') - ->repr($count) - ->raw(' ? array_slice(func_get_args(), ') - ->repr($count) - ->raw(") : [],\n") - ; - } - - $compiler - ->outdent() - ->write("]);\n\n") - ->write("\$blocks = [];\n\n") - ->write("ob_start();\n") - ->write("try {\n") - ->indent() - ->subcompile($this->getNode('body')) - ->outdent() - ->write("} catch (Exception \$e) {\n") - ->indent() - ->write("ob_end_clean();\n\n") - ->write("throw \$e;\n") - ->outdent() - ->write("} catch (Throwable \$e) {\n") - ->indent() - ->write("ob_end_clean();\n\n") - ->write("throw \$e;\n") - ->outdent() - ->write("}\n\n") - ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") - ->outdent() - ->write("}\n\n") - ; - } -} - -class_alias('Twig_Node_Macro', 'Twig\Node\MacroNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Module.php b/system/templateEngines/Twig/Twig1x/Node/Module.php deleted file mode 100644 index c33bbe1..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Module.php +++ /dev/null @@ -1,466 +0,0 @@ - - */ -class Twig_Node_Module extends Twig_Node -{ - private $source; - - public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') - { - if (!$name instanceof Twig_Source) { - @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $this->source = new Twig_Source($source, $name); - } else { - $this->source = $name; - } - - $nodes = [ - 'body' => $body, - 'blocks' => $blocks, - 'macros' => $macros, - 'traits' => $traits, - 'display_start' => new Twig_Node(), - 'display_end' => new Twig_Node(), - 'constructor_start' => new Twig_Node(), - 'constructor_end' => new Twig_Node(), - 'class_end' => new Twig_Node(), - ]; - if (null !== $parent) { - $nodes['parent'] = $parent; - } - - // embedded templates are set as attributes so that they are only visited once by the visitors - parent::__construct($nodes, [ - // source to be remove in 2.0 - 'source' => $this->source->getCode(), - // filename to be remove in 2.0 (use getTemplateName() instead) - 'filename' => $this->source->getName(), - 'index' => null, - 'embedded_templates' => $embeddedTemplates, - ], 1); - - // populate the template name of all node children - $this->setTemplateName($this->source->getName()); - } - - public function setIndex($index) - { - $this->setAttribute('index', $index); - } - - public function compile(Twig_Compiler $compiler) - { - $this->compileTemplate($compiler); - - foreach ($this->getAttribute('embedded_templates') as $template) { - $compiler->subcompile($template); - } - } - - protected function compileTemplate(Twig_Compiler $compiler) - { - if (!$this->getAttribute('index')) { - $compiler->write('compileClassHeader($compiler); - - if ( - count($this->getNode('blocks')) - || count($this->getNode('traits')) - || !$this->hasNode('parent') - || $this->getNode('parent') instanceof Twig_Node_Expression_Constant - || count($this->getNode('constructor_start')) - || count($this->getNode('constructor_end')) - ) { - $this->compileConstructor($compiler); - } - - $this->compileGetParent($compiler); - - $this->compileDisplay($compiler); - - $compiler->subcompile($this->getNode('blocks')); - - $this->compileMacros($compiler); - - $this->compileGetTemplateName($compiler); - - $this->compileIsTraitable($compiler); - - $this->compileDebugInfo($compiler); - - $this->compileGetSource($compiler); - - $this->compileGetSourceContext($compiler); - - $this->compileClassFooter($compiler); - } - - protected function compileGetParent(Twig_Compiler $compiler) - { - if (!$this->hasNode('parent')) { - return; - } - $parent = $this->getNode('parent'); - - $compiler - ->write("protected function doGetParent(array \$context)\n", "{\n") - ->indent() - ->addDebugInfo($parent) - ->write('return ') - ; - - if ($parent instanceof Twig_Node_Expression_Constant) { - $compiler->subcompile($parent); - } else { - $compiler - ->raw('$this->loadTemplate(') - ->subcompile($parent) - ->raw(', ') - ->repr($this->source->getName()) - ->raw(', ') - ->repr($parent->getTemplateLine()) - ->raw(')') - ; - } - - $compiler - ->raw(";\n") - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileClassHeader(Twig_Compiler $compiler) - { - $compiler - ->write("\n\n") - // if the template name contains */, add a blank to avoid a PHP parse error - ->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n") - ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index'))) - ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) - ->write("{\n") - ->indent() - ; - } - - protected function compileConstructor(Twig_Compiler $compiler) - { - $compiler - ->write("public function __construct(Twig_Environment \$env)\n", "{\n") - ->indent() - ->subcompile($this->getNode('constructor_start')) - ->write("parent::__construct(\$env);\n\n") - ; - - // parent - if (!$this->hasNode('parent')) { - $compiler->write("\$this->parent = false;\n\n"); - } elseif (($parent = $this->getNode('parent')) && $parent instanceof Twig_Node_Expression_Constant) { - $compiler - ->addDebugInfo($parent) - ->write('$this->parent = $this->loadTemplate(') - ->subcompile($parent) - ->raw(', ') - ->repr($this->source->getName()) - ->raw(', ') - ->repr($parent->getTemplateLine()) - ->raw(");\n") - ; - } - - $countTraits = count($this->getNode('traits')); - if ($countTraits) { - // traits - foreach ($this->getNode('traits') as $i => $trait) { - $this->compileLoadTemplate($compiler, $trait->getNode('template'), sprintf('$_trait_%s', $i)); - - $compiler - ->addDebugInfo($trait->getNode('template')) - ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) - ->indent() - ->write("throw new Twig_Error_Runtime('Template \"'.") - ->subcompile($trait->getNode('template')) - ->raw(".'\" cannot be used as a trait.');\n") - ->outdent() - ->write("}\n") - ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i)) - ; - - foreach ($trait->getNode('targets') as $key => $value) { - $compiler - ->write(sprintf('if (!isset($_trait_%s_blocks[', $i)) - ->string($key) - ->raw("])) {\n") - ->indent() - ->write("throw new Twig_Error_Runtime(sprintf('Block ") - ->string($key) - ->raw(' is not defined in trait ') - ->subcompile($trait->getNode('template')) - ->raw(".'));\n") - ->outdent() - ->write("}\n\n") - - ->write(sprintf('$_trait_%s_blocks[', $i)) - ->subcompile($value) - ->raw(sprintf('] = $_trait_%s_blocks[', $i)) - ->string($key) - ->raw(sprintf(']; unset($_trait_%s_blocks[', $i)) - ->string($key) - ->raw("]);\n\n") - ; - } - } - - if ($countTraits > 1) { - $compiler - ->write("\$this->traits = array_merge(\n") - ->indent() - ; - - for ($i = 0; $i < $countTraits; ++$i) { - $compiler - ->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i)) - ; - } - - $compiler - ->outdent() - ->write(");\n\n") - ; - } else { - $compiler - ->write("\$this->traits = \$_trait_0_blocks;\n\n") - ; - } - - $compiler - ->write("\$this->blocks = array_merge(\n") - ->indent() - ->write("\$this->traits,\n") - ->write("[\n") - ; - } else { - $compiler - ->write("\$this->blocks = [\n") - ; - } - - // blocks - $compiler - ->indent() - ; - - foreach ($this->getNode('blocks') as $name => $node) { - $compiler - ->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name)) - ; - } - - if ($countTraits) { - $compiler - ->outdent() - ->write("]\n") - ->outdent() - ->write(");\n") - ; - } else { - $compiler - ->outdent() - ->write("];\n") - ; - } - - $compiler - ->outdent() - ->subcompile($this->getNode('constructor_end')) - ->write("}\n\n") - ; - } - - protected function compileDisplay(Twig_Compiler $compiler) - { - $compiler - ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") - ->indent() - ->subcompile($this->getNode('display_start')) - ->subcompile($this->getNode('body')) - ; - - if ($this->hasNode('parent')) { - $parent = $this->getNode('parent'); - $compiler->addDebugInfo($parent); - if ($parent instanceof Twig_Node_Expression_Constant) { - $compiler->write('$this->parent'); - } else { - $compiler->write('$this->getParent($context)'); - } - $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n"); - } - - $compiler - ->subcompile($this->getNode('display_end')) - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileClassFooter(Twig_Compiler $compiler) - { - $compiler - ->subcompile($this->getNode('class_end')) - ->outdent() - ->write("}\n") - ; - } - - protected function compileMacros(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('macros')); - } - - protected function compileGetTemplateName(Twig_Compiler $compiler) - { - $compiler - ->write("public function getTemplateName()\n", "{\n") - ->indent() - ->write('return ') - ->repr($this->source->getName()) - ->raw(";\n") - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileIsTraitable(Twig_Compiler $compiler) - { - // A template can be used as a trait if: - // * it has no parent - // * it has no macros - // * it has no body - // - // Put another way, a template can be used as a trait if it - // only contains blocks and use statements. - $traitable = !$this->hasNode('parent') && 0 === count($this->getNode('macros')); - if ($traitable) { - if ($this->getNode('body') instanceof Twig_Node_Body) { - $nodes = $this->getNode('body')->getNode(0); - } else { - $nodes = $this->getNode('body'); - } - - if (!count($nodes)) { - $nodes = new Twig_Node([$nodes]); - } - - foreach ($nodes as $node) { - if (!count($node)) { - continue; - } - - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { - continue; - } - - if ($node instanceof Twig_Node_BlockReference) { - continue; - } - - $traitable = false; - break; - } - } - - if ($traitable) { - return; - } - - $compiler - ->write("public function isTraitable()\n", "{\n") - ->indent() - ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false')) - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileDebugInfo(Twig_Compiler $compiler) - { - $compiler - ->write("public function getDebugInfo()\n", "{\n") - ->indent() - ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true)))) - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileGetSource(Twig_Compiler $compiler) - { - $compiler - ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n") - ->write("public function getSource()\n", "{\n") - ->indent() - ->write("@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);\n\n") - ->write('return $this->getSourceContext()->getCode();') - ->raw("\n") - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileGetSourceContext(Twig_Compiler $compiler) - { - $compiler - ->write("public function getSourceContext()\n", "{\n") - ->indent() - ->write('return new Twig_Source(') - ->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '') - ->raw(', ') - ->string($this->source->getName()) - ->raw(', ') - ->string($this->source->getPath()) - ->raw(");\n") - ->outdent() - ->write("}\n") - ; - } - - protected function compileLoadTemplate(Twig_Compiler $compiler, $node, $var) - { - if ($node instanceof Twig_Node_Expression_Constant) { - $compiler - ->write(sprintf('%s = $this->loadTemplate(', $var)) - ->subcompile($node) - ->raw(', ') - ->repr($node->getTemplateName()) - ->raw(', ') - ->repr($node->getTemplateLine()) - ->raw(");\n") - ; - } else { - throw new LogicException('Trait templates can only be constant nodes.'); - } - } -} - -class_alias('Twig_Node_Module', 'Twig\Node\ModuleNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Print.php b/system/templateEngines/Twig/Twig1x/Node/Print.php deleted file mode 100644 index 215d712..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Print.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo ') - ->subcompile($this->getNode('expr')) - ->raw(";\n") - ; - } -} - -class_alias('Twig_Node_Print', 'Twig\Node\PrintNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Sandbox.php b/system/templateEngines/Twig/Twig1x/Node/Sandbox.php deleted file mode 100644 index e06f332..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Sandbox.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Twig_Node_Sandbox extends Twig_Node -{ - public function __construct(Twig_NodeInterface $body, $lineno, $tag = null) - { - parent::__construct(['body' => $body], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("\$sandbox = \$this->env->getExtension('Twig_Extension_Sandbox');\n") - ->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n") - ->indent() - ->write("\$sandbox->enableSandbox();\n") - ->outdent() - ->write("}\n") - ->subcompile($this->getNode('body')) - ->write("if (!\$alreadySandboxed) {\n") - ->indent() - ->write("\$sandbox->disableSandbox();\n") - ->outdent() - ->write("}\n") - ; - } -} - -class_alias('Twig_Node_Sandbox', 'Twig\Node\SandboxNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/SandboxedPrint.php b/system/templateEngines/Twig/Twig1x/Node/SandboxedPrint.php deleted file mode 100644 index a08f21f..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/SandboxedPrint.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -class Twig_Node_SandboxedPrint extends Twig_Node_Print -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo $this->env->getExtension(\'Twig_Extension_Sandbox\')->ensureToStringAllowed(') - ->subcompile($this->getNode('expr')) - ->raw(");\n") - ; - } - - /** - * Removes node filters. - * - * This is mostly needed when another visitor adds filters (like the escaper one). - * - * @return Twig_Node - */ - protected function removeNodeFilter(Twig_Node $node) - { - if ($node instanceof Twig_Node_Expression_Filter) { - return $this->removeNodeFilter($node->getNode('node')); - } - - return $node; - } -} - -class_alias('Twig_Node_SandboxedPrint', 'Twig\Node\SandboxedPrintNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Set.php b/system/templateEngines/Twig/Twig1x/Node/Set.php deleted file mode 100644 index 155cc48..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Set.php +++ /dev/null @@ -1,98 +0,0 @@ - - */ -class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface -{ - public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) - { - parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag); - - /* - * Optimizes the node when capture is used for a large block of text. - * - * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo"); - */ - if ($this->getAttribute('capture')) { - $this->setAttribute('safe', true); - - $values = $this->getNode('values'); - if ($values instanceof Twig_Node_Text) { - $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getTemplateLine())); - $this->setAttribute('capture', false); - } - } - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - if (count($this->getNode('names')) > 1) { - $compiler->write('list('); - foreach ($this->getNode('names') as $idx => $node) { - if ($idx) { - $compiler->raw(', '); - } - - $compiler->subcompile($node); - } - $compiler->raw(')'); - } else { - if ($this->getAttribute('capture')) { - $compiler - ->write("ob_start();\n") - ->subcompile($this->getNode('values')) - ; - } - - $compiler->subcompile($this->getNode('names'), false); - - if ($this->getAttribute('capture')) { - $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())"); - } - } - - if (!$this->getAttribute('capture')) { - $compiler->raw(' = '); - - if (count($this->getNode('names')) > 1) { - $compiler->write('['); - foreach ($this->getNode('values') as $idx => $value) { - if ($idx) { - $compiler->raw(', '); - } - - $compiler->subcompile($value); - } - $compiler->raw(']'); - } else { - if ($this->getAttribute('safe')) { - $compiler - ->raw("('' === \$tmp = ") - ->subcompile($this->getNode('values')) - ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())") - ; - } else { - $compiler->subcompile($this->getNode('values')); - } - } - } - - $compiler->raw(";\n"); - } -} - -class_alias('Twig_Node_Set', 'Twig\Node\SetNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/SetTemp.php b/system/templateEngines/Twig/Twig1x/Node/SetTemp.php deleted file mode 100644 index c04ff45..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/SetTemp.php +++ /dev/null @@ -1,40 +0,0 @@ - $name], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $compiler - ->addDebugInfo($this) - ->write('if (isset($context[') - ->string($name) - ->raw('])) { $_') - ->raw($name) - ->raw('_ = $context[') - ->repr($name) - ->raw(']; } else { $_') - ->raw($name) - ->raw("_ = null; }\n") - ; - } -} - -class_alias('Twig_Node_SetTemp', 'Twig\Node\SetTempNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Spaceless.php b/system/templateEngines/Twig/Twig1x/Node/Spaceless.php deleted file mode 100644 index 43e907a..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Spaceless.php +++ /dev/null @@ -1,37 +0,0 @@ - - */ -class Twig_Node_Spaceless extends Twig_Node -{ - public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless') - { - parent::__construct(['body' => $body], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("ob_start();\n") - ->subcompile($this->getNode('body')) - ->write("echo trim(preg_replace('/>\s+<', ob_get_clean()));\n") - ; - } -} - -class_alias('Twig_Node_Spaceless', 'Twig\Node\SpacelessNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/Text.php b/system/templateEngines/Twig/Twig1x/Node/Text.php deleted file mode 100644 index ab24d71..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/Text.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct($data, $lineno) - { - parent::__construct([], ['data' => $data], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo ') - ->string($this->getAttribute('data')) - ->raw(";\n") - ; - } -} - -class_alias('Twig_Node_Text', 'Twig\Node\TextNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Node/With.php b/system/templateEngines/Twig/Twig1x/Node/With.php deleted file mode 100644 index 422cc81..0000000 --- a/system/templateEngines/Twig/Twig1x/Node/With.php +++ /dev/null @@ -1,64 +0,0 @@ - - */ -class Twig_Node_With extends Twig_Node -{ - public function __construct(Twig_Node $body, Twig_Node $variables = null, $only = false, $lineno, $tag = null) - { - $nodes = ['body' => $body]; - if (null !== $variables) { - $nodes['variables'] = $variables; - } - - parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - if ($this->hasNode('variables')) { - $varsName = $compiler->getVarName(); - $compiler - ->write(sprintf('$%s = ', $varsName)) - ->subcompile($this->getNode('variables')) - ->raw(";\n") - ->write(sprintf("if (!is_array(\$%s)) {\n", $varsName)) - ->indent() - ->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.');\n") - ->outdent() - ->write("}\n") - ; - - if ($this->getAttribute('only')) { - $compiler->write("\$context = ['_parent' => \$context];\n"); - } else { - $compiler->write("\$context['_parent'] = \$context;\n"); - } - - $compiler->write(sprintf("\$context = array_merge(\$context, \$%s);\n", $varsName)); - } else { - $compiler->write("\$context['_parent'] = \$context;\n"); - } - - $compiler - ->subcompile($this->getNode('body')) - ->write("\$context = \$context['_parent'];\n") - ; - } -} - -class_alias('Twig_Node_With', 'Twig\Node\WithNode', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeCaptureInterface.php b/system/templateEngines/Twig/Twig1x/NodeCaptureInterface.php deleted file mode 100644 index 6638834..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeCaptureInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -interface Twig_NodeCaptureInterface -{ -} - -class_alias('Twig_NodeCaptureInterface', 'Twig\Node\NodeCaptureInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeInterface.php b/system/templateEngines/Twig/Twig1x/NodeInterface.php deleted file mode 100644 index 78e758b..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_NodeInterface extends Countable, IteratorAggregate -{ - /** - * Compiles the node to PHP. - */ - public function compile(Twig_Compiler $compiler); - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function getLine(); - - public function getNodeTag(); -} diff --git a/system/templateEngines/Twig/Twig1x/NodeOutputInterface.php b/system/templateEngines/Twig/Twig1x/NodeOutputInterface.php deleted file mode 100644 index 5a8eaa9..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeOutputInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -interface Twig_NodeOutputInterface -{ -} - -class_alias('Twig_NodeOutputInterface', 'Twig\Node\NodeOutputInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeTraverser.php b/system/templateEngines/Twig/Twig1x/NodeTraverser.php deleted file mode 100644 index 7f80e76..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeTraverser.php +++ /dev/null @@ -1,86 +0,0 @@ - - */ -class Twig_NodeTraverser -{ - protected $env; - protected $visitors = []; - - /** - * @param Twig_Environment $env - * @param Twig_NodeVisitorInterface[] $visitors - */ - public function __construct(Twig_Environment $env, array $visitors = []) - { - $this->env = $env; - foreach ($visitors as $visitor) { - $this->addVisitor($visitor); - } - } - - public function addVisitor(Twig_NodeVisitorInterface $visitor) - { - if (!isset($this->visitors[$visitor->getPriority()])) { - $this->visitors[$visitor->getPriority()] = []; - } - - $this->visitors[$visitor->getPriority()][] = $visitor; - } - - /** - * Traverses a node and calls the registered visitors. - * - * @return Twig_NodeInterface - */ - public function traverse(Twig_NodeInterface $node) - { - ksort($this->visitors); - foreach ($this->visitors as $visitors) { - foreach ($visitors as $visitor) { - $node = $this->traverseForVisitor($visitor, $node); - } - } - - return $node; - } - - protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) - { - if (null === $node) { - return; - } - - $node = $visitor->enterNode($node, $this->env); - - foreach ($node as $k => $n) { - if (false !== $m = $this->traverseForVisitor($visitor, $n)) { - if ($m !== $n) { - $node->setNode($k, $m); - } - } else { - $node->removeNode($k); - } - } - - return $visitor->leaveNode($node, $this->env); - } -} - -class_alias('Twig_NodeTraverser', 'Twig\NodeTraverser', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeVisitor/Escaper.php b/system/templateEngines/Twig/Twig1x/NodeVisitor/Escaper.php deleted file mode 100644 index 5eb32ea..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeVisitor/Escaper.php +++ /dev/null @@ -1,154 +0,0 @@ - - */ -class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor -{ - protected $statusStack = []; - protected $blocks = []; - protected $safeAnalysis; - protected $traverser; - protected $defaultStrategy = false; - protected $safeVars = []; - - public function __construct() - { - $this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis(); - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getTemplateName())) { - $this->defaultStrategy = $defaultStrategy; - } - $this->safeVars = []; - $this->blocks = []; - } elseif ($node instanceof Twig_Node_AutoEscape) { - $this->statusStack[] = $node->getAttribute('value'); - } elseif ($node instanceof Twig_Node_Block) { - $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); - } elseif ($node instanceof Twig_Node_Import) { - $this->safeVars[] = $node->getNode('var')->getAttribute('name'); - } - - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $this->defaultStrategy = false; - $this->safeVars = []; - $this->blocks = []; - } elseif ($node instanceof Twig_Node_Expression_Filter) { - return $this->preEscapeFilterNode($node, $env); - } elseif ($node instanceof Twig_Node_Print) { - return $this->escapePrintNode($node, $env, $this->needEscaping($env)); - } - - if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) { - array_pop($this->statusStack); - } elseif ($node instanceof Twig_Node_BlockReference) { - $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); - } - - return $node; - } - - protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type) - { - if (false === $type) { - return $node; - } - - $expression = $node->getNode('expr'); - - if ($this->isSafeFor($type, $expression, $env)) { - return $node; - } - - $class = get_class($node); - - return new $class( - $this->getEscaperFilter($type, $expression), - $node->getTemplateLine() - ); - } - - protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env) - { - $name = $filter->getNode('filter')->getAttribute('value'); - - $type = $env->getFilter($name)->getPreEscape(); - if (null === $type) { - return $filter; - } - - $node = $filter->getNode('node'); - if ($this->isSafeFor($type, $node, $env)) { - return $filter; - } - - $filter->setNode('node', $this->getEscaperFilter($type, $node)); - - return $filter; - } - - protected function isSafeFor($type, Twig_NodeInterface $expression, $env) - { - $safe = $this->safeAnalysis->getSafe($expression); - - if (null === $safe) { - if (null === $this->traverser) { - $this->traverser = new Twig_NodeTraverser($env, [$this->safeAnalysis]); - } - - $this->safeAnalysis->setSafeVars($this->safeVars); - - $this->traverser->traverse($expression); - $safe = $this->safeAnalysis->getSafe($expression); - } - - return in_array($type, $safe) || in_array('all', $safe); - } - - protected function needEscaping(Twig_Environment $env) - { - if (count($this->statusStack)) { - return $this->statusStack[count($this->statusStack) - 1]; - } - - return $this->defaultStrategy ? $this->defaultStrategy : false; - } - - protected function getEscaperFilter($type, Twig_NodeInterface $node) - { - $line = $node->getTemplateLine(); - $name = new Twig_Node_Expression_Constant('escape', $line); - $args = new Twig_Node([new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)]); - - return new Twig_Node_Expression_Filter($node, $name, $args, $line); - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_NodeVisitor_Escaper', 'Twig\NodeVisitor\EscaperNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeVisitor/Optimizer.php b/system/templateEngines/Twig/Twig1x/NodeVisitor/Optimizer.php deleted file mode 100644 index f97ea56..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeVisitor/Optimizer.php +++ /dev/null @@ -1,253 +0,0 @@ - - */ -class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor -{ - const OPTIMIZE_ALL = -1; - const OPTIMIZE_NONE = 0; - const OPTIMIZE_FOR = 2; - const OPTIMIZE_RAW_FILTER = 4; - const OPTIMIZE_VAR_ACCESS = 8; - - protected $loops = []; - protected $loopsTargets = []; - protected $optimizers; - protected $prependedNodes = []; - protected $inABody = false; - - /** - * @param int $optimizers The optimizer mode - */ - public function __construct($optimizers = -1) - { - if (!is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) { - throw new InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers)); - } - - $this->optimizers = $optimizers; - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { - $this->enterOptimizeFor($node, $env); - } - - if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) { - if ($this->inABody) { - if (!$node instanceof Twig_Node_Expression) { - if ('Twig_Node' !== get_class($node)) { - array_unshift($this->prependedNodes, []); - } - } else { - $node = $this->optimizeVariables($node, $env); - } - } elseif ($node instanceof Twig_Node_Body) { - $this->inABody = true; - } - } - - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - $expression = $node instanceof Twig_Node_Expression; - - if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { - $this->leaveOptimizeFor($node, $env); - } - - if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) { - $node = $this->optimizeRawFilter($node, $env); - } - - $node = $this->optimizePrintNode($node, $env); - - if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) { - if ($node instanceof Twig_Node_Body) { - $this->inABody = false; - } elseif ($this->inABody) { - if (!$expression && 'Twig_Node' !== get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) { - $nodes = []; - foreach (array_unique($prependedNodes) as $name) { - $nodes[] = new Twig_Node_SetTemp($name, $node->getTemplateLine()); - } - - $nodes[] = $node; - $node = new Twig_Node($nodes); - } - } - } - - return $node; - } - - protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment $env) - { - if ('Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) { - $this->prependedNodes[0][] = $node->getAttribute('name'); - - return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getTemplateLine()); - } - - return $node; - } - - /** - * Optimizes print nodes. - * - * It replaces: - * - * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" - * - * @return Twig_NodeInterface - */ - protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env) - { - if (!$node instanceof Twig_Node_Print) { - return $node; - } - - $exprNode = $node->getNode('expr'); - if ( - $exprNode instanceof Twig_Node_Expression_BlockReference || - $exprNode instanceof Twig_Node_Expression_Parent - ) { - $exprNode->setAttribute('output', true); - - return $exprNode; - } - - return $node; - } - - /** - * Removes "raw" filters. - * - * @return Twig_NodeInterface - */ - protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Expression_Filter && 'raw' == $node->getNode('filter')->getAttribute('value')) { - return $node->getNode('node'); - } - - return $node; - } - - /** - * Optimizes "for" tag by removing the "loop" variable creation whenever possible. - */ - protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_For) { - // disable the loop variable by default - $node->setAttribute('with_loop', false); - array_unshift($this->loops, $node); - array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); - array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); - } elseif (!$this->loops) { - // we are outside a loop - return; - } - - // when do we need to add the loop variable back? - - // the loop variable is referenced for the current loop - elseif ($node instanceof Twig_Node_Expression_Name && 'loop' === $node->getAttribute('name')) { - $node->setAttribute('always_defined', true); - $this->addLoopToCurrent(); - } - - // optimize access to loop targets - elseif ($node instanceof Twig_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) { - $node->setAttribute('always_defined', true); - } - - // block reference - elseif ($node instanceof Twig_Node_BlockReference || $node instanceof Twig_Node_Expression_BlockReference) { - $this->addLoopToCurrent(); - } - - // include without the only attribute - elseif ($node instanceof Twig_Node_Include && !$node->getAttribute('only')) { - $this->addLoopToAll(); - } - - // include function without the with_context=false parameter - elseif ($node instanceof Twig_Node_Expression_Function - && 'include' === $node->getAttribute('name') - && (!$node->getNode('arguments')->hasNode('with_context') - || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') - ) - ) { - $this->addLoopToAll(); - } - - // the loop variable is referenced via an attribute - elseif ($node instanceof Twig_Node_Expression_GetAttr - && (!$node->getNode('attribute') instanceof Twig_Node_Expression_Constant - || 'parent' === $node->getNode('attribute')->getAttribute('value') - ) - && (true === $this->loops[0]->getAttribute('with_loop') - || ($node->getNode('node') instanceof Twig_Node_Expression_Name - && 'loop' === $node->getNode('node')->getAttribute('name') - ) - ) - ) { - $this->addLoopToAll(); - } - } - - /** - * Optimizes "for" tag by removing the "loop" variable creation whenever possible. - */ - protected function leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_For) { - array_shift($this->loops); - array_shift($this->loopsTargets); - array_shift($this->loopsTargets); - } - } - - protected function addLoopToCurrent() - { - $this->loops[0]->setAttribute('with_loop', true); - } - - protected function addLoopToAll() - { - foreach ($this->loops as $loop) { - $loop->setAttribute('with_loop', true); - } - } - - public function getPriority() - { - return 255; - } -} - -class_alias('Twig_NodeVisitor_Optimizer', 'Twig\NodeVisitor\OptimizerNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeVisitor/SafeAnalysis.php b/system/templateEngines/Twig/Twig1x/NodeVisitor/SafeAnalysis.php deleted file mode 100644 index eff855b..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeVisitor/SafeAnalysis.php +++ /dev/null @@ -1,150 +0,0 @@ -safeVars = $safeVars; - } - - public function getSafe(Twig_NodeInterface $node) - { - $hash = spl_object_hash($node); - if (!isset($this->data[$hash])) { - return; - } - - foreach ($this->data[$hash] as $bucket) { - if ($bucket['key'] !== $node) { - continue; - } - - if (in_array('html_attr', $bucket['value'])) { - $bucket['value'][] = 'html'; - } - - return $bucket['value']; - } - } - - protected function setSafe(Twig_NodeInterface $node, array $safe) - { - $hash = spl_object_hash($node); - if (isset($this->data[$hash])) { - foreach ($this->data[$hash] as &$bucket) { - if ($bucket['key'] === $node) { - $bucket['value'] = $safe; - - return; - } - } - } - $this->data[$hash][] = [ - 'key' => $node, - 'value' => $safe, - ]; - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Expression_Constant) { - // constants are marked safe for all - $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_BlockReference) { - // blocks are safe by definition - $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_Parent) { - // parent block is safe by definition - $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_Conditional) { - // intersect safeness of both operands - $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); - $this->setSafe($node, $safe); - } elseif ($node instanceof Twig_Node_Expression_Filter) { - // filter expression is safe when the filter is safe - $name = $node->getNode('filter')->getAttribute('value'); - $args = $node->getNode('arguments'); - if (false !== $filter = $env->getFilter($name)) { - $safe = $filter->getSafe($args); - if (null === $safe) { - $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety()); - } - $this->setSafe($node, $safe); - } else { - $this->setSafe($node, []); - } - } elseif ($node instanceof Twig_Node_Expression_Function) { - // function expression is safe when the function is safe - $name = $node->getAttribute('name'); - $args = $node->getNode('arguments'); - $function = $env->getFunction($name); - if (false !== $function) { - $this->setSafe($node, $function->getSafe($args)); - } else { - $this->setSafe($node, []); - } - } elseif ($node instanceof Twig_Node_Expression_MethodCall) { - if ($node->getAttribute('safe')) { - $this->setSafe($node, ['all']); - } else { - $this->setSafe($node, []); - } - } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) { - $name = $node->getNode('node')->getAttribute('name'); - // attributes on template instances are safe - if ('_self' == $name || in_array($name, $this->safeVars)) { - $this->setSafe($node, ['all']); - } else { - $this->setSafe($node, []); - } - } else { - $this->setSafe($node, []); - } - - return $node; - } - - protected function intersectSafe(array $a = null, array $b = null) - { - if (null === $a || null === $b) { - return []; - } - - if (in_array('all', $a)) { - return $b; - } - - if (in_array('all', $b)) { - return $a; - } - - return array_intersect($a, $b); - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_NodeVisitor_SafeAnalysis', 'Twig\NodeVisitor\SafeAnalysisNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeVisitor/Sandbox.php b/system/templateEngines/Twig/Twig1x/NodeVisitor/Sandbox.php deleted file mode 100644 index 894cc1a..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeVisitor/Sandbox.php +++ /dev/null @@ -1,82 +0,0 @@ - - */ -class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor -{ - protected $inAModule = false; - protected $tags; - protected $filters; - protected $functions; - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $this->inAModule = true; - $this->tags = []; - $this->filters = []; - $this->functions = []; - - return $node; - } elseif ($this->inAModule) { - // look for tags - if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { - $this->tags[$node->getNodeTag()] = $node; - } - - // look for filters - if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { - $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; - } - - // look for functions - if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) { - $this->functions[$node->getAttribute('name')] = $node; - } - - // the .. operator is equivalent to the range() function - if ($node instanceof Twig_Node_Expression_Binary_Range && !isset($this->functions['range'])) { - $this->functions['range'] = $node; - } - - // wrap print to check __toString() calls - if ($node instanceof Twig_Node_Print) { - return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag()); - } - } - - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $this->inAModule = false; - - $node->setNode('display_start', new Twig_Node([new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); - } - - return $node; - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_NodeVisitor_Sandbox', 'Twig\NodeVisitor\SandboxNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig1x/NodeVisitorInterface.php b/system/templateEngines/Twig/Twig1x/NodeVisitorInterface.php deleted file mode 100644 index 1270a37..0000000 --- a/system/templateEngines/Twig/Twig1x/NodeVisitorInterface.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -interface Twig_NodeVisitorInterface -{ - /** - * Called before child nodes are visited. - * - * @return Twig_NodeInterface The modified node - */ - public function enterNode(Twig_NodeInterface $node, Twig_Environment $env); - - /** - * Called after child nodes are visited. - * - * @return Twig_NodeInterface|false The modified node or false if the node must be removed - */ - public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env); - - /** - * Returns the priority for this visitor. - * - * Priority should be between -10 and 10 (0 is the default). - * - * @return int The priority level - */ - public function getPriority(); -} - -class_alias('Twig_NodeVisitorInterface', 'Twig\NodeVisitor\NodeVisitorInterface', false); -class_exists('Twig_Environment'); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig1x/Parser.php b/system/templateEngines/Twig/Twig1x/Parser.php deleted file mode 100644 index ff44401..0000000 --- a/system/templateEngines/Twig/Twig1x/Parser.php +++ /dev/null @@ -1,416 +0,0 @@ - - */ -class Twig_Parser implements Twig_ParserInterface -{ - protected $stack = []; - protected $stream; - protected $parent; - protected $handlers; - protected $visitors; - protected $expressionParser; - protected $blocks; - protected $blockStack; - protected $macros; - protected $env; - protected $reservedMacroNames; - protected $importedSymbols; - protected $traits; - protected $embeddedTemplates = []; - private $varNameSalt = 0; - - public function __construct(Twig_Environment $env) - { - $this->env = $env; - } - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function getEnvironment() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); - - return $this->env; - } - - public function getVarName() - { - return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++)); - } - - /** - * @deprecated since 1.27 (to be removed in 2.0). Use $parser->getStream()->getSourceContext()->getPath() instead. - */ - public function getFilename() - { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->stream->getSourceContext()->getName(); - } - - public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) - { - // push all variables into the stack to keep the current state of the parser - // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336 - // This hack can be removed when min version if PHP 7.0 - $vars = []; - foreach ($this as $k => $v) { - $vars[$k] = $v; - } - - unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']); - $this->stack[] = $vars; - - // tag handlers - if (null === $this->handlers) { - $this->handlers = $this->env->getTokenParsers(); - $this->handlers->setParser($this); - } - - // node visitors - if (null === $this->visitors) { - $this->visitors = $this->env->getNodeVisitors(); - } - - if (null === $this->expressionParser) { - $this->expressionParser = new Twig_ExpressionParser($this, $this->env); - } - - $this->stream = $stream; - $this->parent = null; - $this->blocks = []; - $this->macros = []; - $this->traits = []; - $this->blockStack = []; - $this->importedSymbols = [[]]; - $this->embeddedTemplates = []; - $this->varNameSalt = 0; - - try { - $body = $this->subparse($test, $dropNeedle); - - if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { - $body = new Twig_Node(); - } - } catch (Twig_Error_Syntax $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($this->stream->getSourceContext()); - } - - if (!$e->getTemplateLine()) { - $e->setTemplateLine($this->stream->getCurrent()->getLine()); - } - - throw $e; - } - - $node = new Twig_Node_Module(new Twig_Node_Body([$body]), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); - - $traverser = new Twig_NodeTraverser($this->env, $this->visitors); - - $node = $traverser->traverse($node); - - // restore previous stack so previous parse() call can resume working - foreach (array_pop($this->stack) as $key => $val) { - $this->$key = $val; - } - - return $node; - } - - public function subparse($test, $dropNeedle = false) - { - $lineno = $this->getCurrentToken()->getLine(); - $rv = []; - while (!$this->stream->isEOF()) { - switch ($this->getCurrentToken()->getType()) { - case Twig_Token::TEXT_TYPE: - $token = $this->stream->next(); - $rv[] = new Twig_Node_Text($token->getValue(), $token->getLine()); - break; - - case Twig_Token::VAR_START_TYPE: - $token = $this->stream->next(); - $expr = $this->expressionParser->parseExpression(); - $this->stream->expect(Twig_Token::VAR_END_TYPE); - $rv[] = new Twig_Node_Print($expr, $token->getLine()); - break; - - case Twig_Token::BLOCK_START_TYPE: - $this->stream->next(); - $token = $this->getCurrentToken(); - - if (Twig_Token::NAME_TYPE !== $token->getType()) { - throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); - } - - if (null !== $test && call_user_func($test, $token)) { - if ($dropNeedle) { - $this->stream->next(); - } - - if (1 === count($rv)) { - return $rv[0]; - } - - return new Twig_Node($rv, [], $lineno); - } - - $subparser = $this->handlers->getTokenParser($token->getValue()); - if (null === $subparser) { - if (null !== $test) { - $e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - - if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { - $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); - } - } else { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); - } - - throw $e; - } - - $this->stream->next(); - - $node = $subparser->parse($token); - if (null !== $node) { - $rv[] = $node; - } - break; - - default: - throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); - } - } - - if (1 === count($rv)) { - return $rv[0]; - } - - return new Twig_Node($rv, [], $lineno); - } - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function addHandler($name, $class) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); - - $this->handlers[$name] = $class; - } - - /** - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); - - $this->visitors[] = $visitor; - } - - public function getBlockStack() - { - return $this->blockStack; - } - - public function peekBlockStack() - { - return $this->blockStack[count($this->blockStack) - 1]; - } - - public function popBlockStack() - { - array_pop($this->blockStack); - } - - public function pushBlockStack($name) - { - $this->blockStack[] = $name; - } - - public function hasBlock($name) - { - return isset($this->blocks[$name]); - } - - public function getBlock($name) - { - return $this->blocks[$name]; - } - - public function setBlock($name, Twig_Node_Block $value) - { - $this->blocks[$name] = new Twig_Node_Body([$value], [], $value->getTemplateLine()); - } - - public function hasMacro($name) - { - return isset($this->macros[$name]); - } - - public function setMacro($name, Twig_Node_Macro $node) - { - if ($this->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()); - } - - $this->macros[$name] = $node; - } - - public function isReservedMacroName($name) - { - if (null === $this->reservedMacroNames) { - $this->reservedMacroNames = []; - $r = new ReflectionClass($this->env->getBaseTemplateClass()); - foreach ($r->getMethods() as $method) { - $methodName = strtolower($method->getName()); - - if ('get' === substr($methodName, 0, 3) && isset($methodName[3])) { - $this->reservedMacroNames[] = substr($methodName, 3); - } - } - } - - return in_array(strtolower($name), $this->reservedMacroNames); - } - - public function addTrait($trait) - { - $this->traits[] = $trait; - } - - public function hasTraits() - { - return count($this->traits) > 0; - } - - public function embedTemplate(Twig_Node_Module $template) - { - $template->setIndex(mt_rand()); - - $this->embeddedTemplates[] = $template; - } - - public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null) - { - $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; - } - - public function getImportedSymbol($type, $alias) - { - foreach ($this->importedSymbols as $functions) { - if (isset($functions[$type][$alias])) { - return $functions[$type][$alias]; - } - } - } - - public function isMainScope() - { - return 1 === count($this->importedSymbols); - } - - public function pushLocalScope() - { - array_unshift($this->importedSymbols, []); - } - - public function popLocalScope() - { - array_shift($this->importedSymbols); - } - - /** - * @return Twig_ExpressionParser - */ - public function getExpressionParser() - { - return $this->expressionParser; - } - - public function getParent() - { - return $this->parent; - } - - public function setParent($parent) - { - $this->parent = $parent; - } - - /** - * @return Twig_TokenStream - */ - public function getStream() - { - return $this->stream; - } - - /** - * @return Twig_Token - */ - public function getCurrentToken() - { - return $this->stream->getCurrent(); - } - - protected function filterBodyNodes(Twig_NodeInterface $node) - { - // check that the body does not contain non-empty output nodes - if ( - ($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data'))) - || - (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) - ) { - if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) { - $t = substr($node->getAttribute('data'), 3); - if ('' === $t || ctype_space($t)) { - // bypass empty nodes starting with a BOM - return; - } - } - - throw new Twig_Error_Syntax('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); - } - - // bypass nodes that will "capture" the output - if ($node instanceof Twig_NodeCaptureInterface) { - return $node; - } - - if ($node instanceof Twig_NodeOutputInterface) { - return; - } - - foreach ($node as $k => $n) { - if (null !== $n && null === $this->filterBodyNodes($n)) { - $node->removeNode($k); - } - } - - return $node; - } -} - -class_alias('Twig_Parser', 'Twig\Parser', false); -class_exists('Twig_Node'); -class_exists('Twig_TokenStream'); diff --git a/system/templateEngines/Twig/Twig1x/ParserInterface.php b/system/templateEngines/Twig/Twig1x/ParserInterface.php deleted file mode 100644 index 85c6e67..0000000 --- a/system/templateEngines/Twig/Twig1x/ParserInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_ParserInterface -{ - /** - * Converts a token stream to a node tree. - * - * @return Twig_Node_Module - * - * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong - */ - public function parse(Twig_TokenStream $stream); -} diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Base.php b/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Base.php deleted file mode 100644 index 913afd4..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Base.php +++ /dev/null @@ -1,62 +0,0 @@ - - */ -abstract class Twig_Profiler_Dumper_Base -{ - private $root; - - public function dump(Twig_Profiler_Profile $profile) - { - return $this->dumpProfile($profile); - } - - abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix); - - abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix); - - abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent); - - private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false) - { - if ($profile->isRoot()) { - $this->root = $profile->getDuration(); - $start = $profile->getName(); - } else { - if ($profile->isTemplate()) { - $start = $this->formatTemplate($profile, $prefix); - } else { - $start = $this->formatNonTemplate($profile, $prefix); - } - $prefix .= $sibling ? '│ ' : ' '; - } - - $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0; - - if ($profile->getDuration() * 1000 < 1) { - $str = $start."\n"; - } else { - $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent)); - } - - $nCount = count($profile->getProfiles()); - foreach ($profile as $i => $p) { - $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount); - } - - return $str; - } -} - -class_alias('Twig_Profiler_Dumper_Base', 'Twig\Profiler\Dumper\BaseDumper', false); -class_exists('Twig_Profiler_Profile'); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Blackfire.php b/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Blackfire.php deleted file mode 100644 index 4ebb0d0..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Blackfire.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * @final - */ -class Twig_Profiler_Dumper_Blackfire -{ - public function dump(Twig_Profiler_Profile $profile) - { - $data = []; - $this->dumpProfile('main()', $profile, $data); - $this->dumpChildren('main()', $profile, $data); - - $start = sprintf('%f', microtime(true)); - $str = << $values) { - $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; - } - - return $str; - } - - private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data) - { - foreach ($profile as $p) { - if ($p->isTemplate()) { - $name = $p->getTemplate(); - } else { - $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName()); - } - $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data); - $this->dumpChildren($name, $p, $data); - } - } - - private function dumpProfile($edge, Twig_Profiler_Profile $profile, &$data) - { - if (isset($data[$edge])) { - ++$data[$edge]['ct']; - $data[$edge]['wt'] += floor($profile->getDuration() * 1000000); - $data[$edge]['mu'] += $profile->getMemoryUsage(); - $data[$edge]['pmu'] += $profile->getPeakMemoryUsage(); - } else { - $data[$edge] = [ - 'ct' => 1, - 'wt' => floor($profile->getDuration() * 1000000), - 'mu' => $profile->getMemoryUsage(), - 'pmu' => $profile->getPeakMemoryUsage(), - ]; - } - } -} - -class_alias('Twig_Profiler_Dumper_Blackfire', 'Twig\Profiler\Dumper\BlackfireDumper', false); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Html.php b/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Html.php deleted file mode 100644 index 974b521..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Html.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * @final - */ -class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base -{ - private static $colors = [ - 'block' => '#dfd', - 'macro' => '#ddf', - 'template' => '#ffd', - 'big' => '#d44', - ]; - - public function dump(Twig_Profiler_Profile $profile) - { - return '
'.parent::dump($profile).'
'; - } - - protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); - } - - protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); - } - - protected function formatTime(Twig_Profiler_Profile $profile, $percent) - { - return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); - } -} - -class_alias('Twig_Profiler_Dumper_Html', 'Twig\Profiler\Dumper\HtmlDumper', false); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Text.php b/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Text.php deleted file mode 100644 index 69d2c4b..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Dumper/Text.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * @final - */ -class Twig_Profiler_Dumper_Text extends Twig_Profiler_Dumper_Base -{ - protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s', $prefix, $profile->getTemplate()); - } - - protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); - } - - protected function formatTime(Twig_Profiler_Profile $profile, $percent) - { - return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); - } -} - -class_alias('Twig_Profiler_Dumper_Text', 'Twig\Profiler\Dumper\TextDumper', false); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Node/EnterProfile.php b/system/templateEngines/Twig/Twig1x/Profiler/Node/EnterProfile.php deleted file mode 100644 index b29ec9b..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Node/EnterProfile.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Twig_Profiler_Node_EnterProfile extends Twig_Node -{ - public function __construct($extensionName, $type, $name, $varName) - { - parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name'))) - ->repr($this->getAttribute('extension_name')) - ->raw(");\n") - ->write(sprintf('$%s->enter($%s = new Twig_Profiler_Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) - ->repr($this->getAttribute('type')) - ->raw(', ') - ->repr($this->getAttribute('name')) - ->raw("));\n\n") - ; - } -} - -class_alias('Twig_Profiler_Node_EnterProfile', 'Twig\Profiler\Node\EnterProfileNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Node/LeaveProfile.php b/system/templateEngines/Twig/Twig1x/Profiler/Node/LeaveProfile.php deleted file mode 100644 index bcb912d..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Node/LeaveProfile.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Profiler_Node_LeaveProfile extends Twig_Node -{ - public function __construct($varName) - { - parent::__construct([], ['var_name' => $varName]); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->write("\n") - ->write(sprintf("\$%s->leave(\$%s);\n\n", $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) - ; - } -} - -class_alias('Twig_Profiler_Node_LeaveProfile', 'Twig\Profiler\Node\LeaveProfileNode', false); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/NodeVisitor/Profiler.php b/system/templateEngines/Twig/Twig1x/Profiler/NodeVisitor/Profiler.php deleted file mode 100644 index 6cf5bb0..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/NodeVisitor/Profiler.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * @final - */ -class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor -{ - private $extensionName; - - public function __construct($extensionName) - { - $this->extensionName = $extensionName; - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $varName = $this->getVarName(); - $node->setNode('display_start', new Twig_Node([new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); - $node->setNode('display_end', new Twig_Node([new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end')])); - } elseif ($node instanceof Twig_Node_Block) { - $varName = $this->getVarName(); - $node->setNode('body', new Twig_Node_Body([ - new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), - $node->getNode('body'), - new Twig_Profiler_Node_LeaveProfile($varName), - ])); - } elseif ($node instanceof Twig_Node_Macro) { - $varName = $this->getVarName(); - $node->setNode('body', new Twig_Node_Body([ - new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName), - $node->getNode('body'), - new Twig_Profiler_Node_LeaveProfile($varName), - ])); - } - - return $node; - } - - private function getVarName() - { - return sprintf('__internal_%s', hash('sha256', $this->extensionName)); - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_Profiler_NodeVisitor_Profiler', 'Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig1x/Profiler/Profile.php b/system/templateEngines/Twig/Twig1x/Profiler/Profile.php deleted file mode 100644 index 8ba1c4c..0000000 --- a/system/templateEngines/Twig/Twig1x/Profiler/Profile.php +++ /dev/null @@ -1,170 +0,0 @@ - - * - * @final - */ -class Twig_Profiler_Profile implements IteratorAggregate, Serializable -{ - const ROOT = 'ROOT'; - const BLOCK = 'block'; - const TEMPLATE = 'template'; - const MACRO = 'macro'; - - private $template; - private $name; - private $type; - private $starts = []; - private $ends = []; - private $profiles = []; - - public function __construct($template = 'main', $type = self::ROOT, $name = 'main') - { - $this->template = $template; - $this->type = $type; - $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name; - $this->enter(); - } - - public function getTemplate() - { - return $this->template; - } - - public function getType() - { - return $this->type; - } - - public function getName() - { - return $this->name; - } - - public function isRoot() - { - return self::ROOT === $this->type; - } - - public function isTemplate() - { - return self::TEMPLATE === $this->type; - } - - public function isBlock() - { - return self::BLOCK === $this->type; - } - - public function isMacro() - { - return self::MACRO === $this->type; - } - - public function getProfiles() - { - return $this->profiles; - } - - public function addProfile(self $profile) - { - $this->profiles[] = $profile; - } - - /** - * Returns the duration in microseconds. - * - * @return int - */ - public function getDuration() - { - if ($this->isRoot() && $this->profiles) { - // for the root node with children, duration is the sum of all child durations - $duration = 0; - foreach ($this->profiles as $profile) { - $duration += $profile->getDuration(); - } - - return $duration; - } - - return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0; - } - - /** - * Returns the memory usage in bytes. - * - * @return int - */ - public function getMemoryUsage() - { - return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0; - } - - /** - * Returns the peak memory usage in bytes. - * - * @return int - */ - public function getPeakMemoryUsage() - { - return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0; - } - - /** - * Starts the profiling. - */ - public function enter() - { - $this->starts = [ - 'wt' => microtime(true), - 'mu' => memory_get_usage(), - 'pmu' => memory_get_peak_usage(), - ]; - } - - /** - * Stops the profiling. - */ - public function leave() - { - $this->ends = [ - 'wt' => microtime(true), - 'mu' => memory_get_usage(), - 'pmu' => memory_get_peak_usage(), - ]; - } - - public function reset() - { - $this->starts = $this->ends = $this->profiles = []; - $this->enter(); - } - - public function getIterator() - { - return new ArrayIterator($this->profiles); - } - - public function serialize() - { - return serialize([$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles]); - } - - public function unserialize($data) - { - list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = unserialize($data); - } -} - -class_alias('Twig_Profiler_Profile', 'Twig\Profiler\Profile', false); diff --git a/system/templateEngines/Twig/Twig1x/RuntimeLoaderInterface.php b/system/templateEngines/Twig/Twig1x/RuntimeLoaderInterface.php deleted file mode 100644 index f5eb14e..0000000 --- a/system/templateEngines/Twig/Twig1x/RuntimeLoaderInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - */ -interface Twig_RuntimeLoaderInterface -{ - /** - * Creates the runtime implementation of a Twig element (filter/function/test). - * - * @param string $class A runtime class - * - * @return object|null The runtime instance or null if the loader does not know how to create the runtime for this class - */ - public function load($class); -} - -class_alias('Twig_RuntimeLoaderInterface', 'Twig\RuntimeLoader\RuntimeLoaderInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityError.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityError.php deleted file mode 100644 index b6707e3..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityError.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -class Twig_Sandbox_SecurityError extends Twig_Error -{ -} - -class_alias('Twig_Sandbox_SecurityError', 'Twig\Sandbox\SecurityError', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFilterError.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFilterError.php deleted file mode 100644 index 0ba3327..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFilterError.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedFilterError extends Twig_Sandbox_SecurityError -{ - private $filterName; - - public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->filterName = $functionName; - } - - public function getFilterName() - { - return $this->filterName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedFilterError', 'Twig\Sandbox\SecurityNotAllowedFilterError', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFunctionError.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFunctionError.php deleted file mode 100644 index aa39142..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedFunctionError.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedFunctionError extends Twig_Sandbox_SecurityError -{ - private $functionName; - - public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->functionName = $functionName; - } - - public function getFunctionName() - { - return $this->functionName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedFunctionError', 'Twig\Sandbox\SecurityNotAllowedFunctionError', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedMethodError.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedMethodError.php deleted file mode 100644 index 93012fe..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedMethodError.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedMethodError extends Twig_Sandbox_SecurityError -{ - private $className; - private $methodName; - - public function __construct($message, $className, $methodName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->className = $className; - $this->methodName = $methodName; - } - - public function getClassName() - { - return $this->className; - } - - public function getMethodName() - { - return $this->methodName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedMethodError', 'Twig\Sandbox\SecurityNotAllowedMethodError', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedPropertyError.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedPropertyError.php deleted file mode 100644 index f27969c..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedPropertyError.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedPropertyError extends Twig_Sandbox_SecurityError -{ - private $className; - private $propertyName; - - public function __construct($message, $className, $propertyName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->className = $className; - $this->propertyName = $propertyName; - } - - public function getClassName() - { - return $this->className; - } - - public function getPropertyName() - { - return $this->propertyName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedPropertyError', 'Twig\Sandbox\SecurityNotAllowedPropertyError', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedTagError.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedTagError.php deleted file mode 100644 index 4bbd223..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityNotAllowedTagError.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedTagError extends Twig_Sandbox_SecurityError -{ - private $tagName; - - public function __construct($message, $tagName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->tagName = $tagName; - } - - public function getTagName() - { - return $this->tagName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedTagError', 'Twig\Sandbox\SecurityNotAllowedTagError', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicy.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicy.php deleted file mode 100644 index cf59117..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicy.php +++ /dev/null @@ -1,125 +0,0 @@ - - */ -class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface -{ - protected $allowedTags; - protected $allowedFilters; - protected $allowedMethods; - protected $allowedProperties; - protected $allowedFunctions; - - public function __construct(array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = []) - { - $this->allowedTags = $allowedTags; - $this->allowedFilters = $allowedFilters; - $this->setAllowedMethods($allowedMethods); - $this->allowedProperties = $allowedProperties; - $this->allowedFunctions = $allowedFunctions; - } - - public function setAllowedTags(array $tags) - { - $this->allowedTags = $tags; - } - - public function setAllowedFilters(array $filters) - { - $this->allowedFilters = $filters; - } - - public function setAllowedMethods(array $methods) - { - $this->allowedMethods = []; - foreach ($methods as $class => $m) { - $this->allowedMethods[$class] = array_map('strtolower', is_array($m) ? $m : [$m]); - } - } - - public function setAllowedProperties(array $properties) - { - $this->allowedProperties = $properties; - } - - public function setAllowedFunctions(array $functions) - { - $this->allowedFunctions = $functions; - } - - public function checkSecurity($tags, $filters, $functions) - { - foreach ($tags as $tag) { - if (!in_array($tag, $this->allowedTags)) { - throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); - } - } - - foreach ($filters as $filter) { - if (!in_array($filter, $this->allowedFilters)) { - throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); - } - } - - foreach ($functions as $function) { - if (!in_array($function, $this->allowedFunctions)) { - throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); - } - } - } - - public function checkMethodAllowed($obj, $method) - { - if ($obj instanceof Twig_TemplateInterface || $obj instanceof Twig_Markup) { - return true; - } - - $allowed = false; - $method = strtolower($method); - foreach ($this->allowedMethods as $class => $methods) { - if ($obj instanceof $class) { - $allowed = in_array($method, $methods); - - break; - } - } - - if (!$allowed) { - $class = get_class($obj); - throw new Twig_Sandbox_SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); - } - } - - public function checkPropertyAllowed($obj, $property) - { - $allowed = false; - foreach ($this->allowedProperties as $class => $properties) { - if ($obj instanceof $class) { - $allowed = in_array($property, is_array($properties) ? $properties : [$properties]); - - break; - } - } - - if (!$allowed) { - $class = get_class($obj); - throw new Twig_Sandbox_SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); - } - } -} - -class_alias('Twig_Sandbox_SecurityPolicy', 'Twig\Sandbox\SecurityPolicy', false); diff --git a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicyInterface.php b/system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicyInterface.php deleted file mode 100644 index 88f6444..0000000 --- a/system/templateEngines/Twig/Twig1x/Sandbox/SecurityPolicyInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -interface Twig_Sandbox_SecurityPolicyInterface -{ - public function checkSecurity($tags, $filters, $functions); - - public function checkMethodAllowed($obj, $method); - - public function checkPropertyAllowed($obj, $method); -} - -class_alias('Twig_Sandbox_SecurityPolicyInterface', 'Twig\Sandbox\SecurityPolicyInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/SimpleFilter.php b/system/templateEngines/Twig/Twig1x/SimpleFilter.php deleted file mode 100644 index 5c4cfc5..0000000 --- a/system/templateEngines/Twig/Twig1x/SimpleFilter.php +++ /dev/null @@ -1,121 +0,0 @@ - - */ -class Twig_SimpleFilter -{ - protected $name; - protected $callable; - protected $options; - protected $arguments = []; - - public function __construct($name, $callable, array $options = []) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge([ - 'needs_environment' => false, - 'needs_context' => false, - 'is_variadic' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'pre_escape' => null, - 'preserves_safety' => null, - 'node_class' => 'Twig_Node_Expression_Filter', - 'deprecated' => false, - 'alternative' => null, - ], $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $filterArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $filterArgs); - } - } - - public function getPreservesSafety() - { - return $this->options['preserves_safety']; - } - - public function getPreEscape() - { - return $this->options['pre_escape']; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return (bool) $this->options['deprecated']; - } - - public function getDeprecatedVersion() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } -} - -class_alias('Twig_SimpleFilter', 'Twig\TwigFilter', false); diff --git a/system/templateEngines/Twig/Twig1x/SimpleFunction.php b/system/templateEngines/Twig/Twig1x/SimpleFunction.php deleted file mode 100644 index fbe06b9..0000000 --- a/system/templateEngines/Twig/Twig1x/SimpleFunction.php +++ /dev/null @@ -1,111 +0,0 @@ - - */ -class Twig_SimpleFunction -{ - protected $name; - protected $callable; - protected $options; - protected $arguments = []; - - public function __construct($name, $callable, array $options = []) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge([ - 'needs_environment' => false, - 'needs_context' => false, - 'is_variadic' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'node_class' => 'Twig_Node_Expression_Function', - 'deprecated' => false, - 'alternative' => null, - ], $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $functionArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); - } - - return []; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return (bool) $this->options['deprecated']; - } - - public function getDeprecatedVersion() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } -} - -class_alias('Twig_SimpleFunction', 'Twig\TwigFunction', false); diff --git a/system/templateEngines/Twig/Twig1x/SimpleTest.php b/system/templateEngines/Twig/Twig1x/SimpleTest.php deleted file mode 100644 index 393fad1..0000000 --- a/system/templateEngines/Twig/Twig1x/SimpleTest.php +++ /dev/null @@ -1,85 +0,0 @@ - - */ -class Twig_SimpleTest -{ - protected $name; - protected $callable; - protected $options; - - private $arguments = []; - - public function __construct($name, $callable, array $options = []) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge([ - 'is_variadic' => false, - 'node_class' => 'Twig_Node_Expression_Test', - 'deprecated' => false, - 'alternative' => null, - ], $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return (bool) $this->options['deprecated']; - } - - public function getDeprecatedVersion() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } -} - -class_alias('Twig_SimpleTest', 'Twig\TwigTest', false); diff --git a/system/templateEngines/Twig/Twig1x/Source.php b/system/templateEngines/Twig/Twig1x/Source.php deleted file mode 100644 index bd8d869..0000000 --- a/system/templateEngines/Twig/Twig1x/Source.php +++ /dev/null @@ -1,53 +0,0 @@ - - */ -class Twig_Source -{ - private $code; - private $name; - private $path; - - /** - * @param string $code The template source code - * @param string $name The template logical name - * @param string $path The filesystem path of the template if any - */ - public function __construct($code, $name, $path = '') - { - $this->code = $code; - $this->name = $name; - $this->path = $path; - } - - public function getCode() - { - return $this->code; - } - - public function getName() - { - return $this->name; - } - - public function getPath() - { - return $this->path; - } -} - -class_alias('Twig_Source', 'Twig\Source', false); diff --git a/system/templateEngines/Twig/Twig1x/SourceContextLoaderInterface.php b/system/templateEngines/Twig/Twig1x/SourceContextLoaderInterface.php deleted file mode 100644 index a6e8c42..0000000 --- a/system/templateEngines/Twig/Twig1x/SourceContextLoaderInterface.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * @deprecated since 1.27 (to be removed in 3.0) - */ -interface Twig_SourceContextLoaderInterface -{ - /** - * Returns the source context for a given template logical name. - * - * @param string $name The template logical name - * - * @return Twig_Source - * - * @throws Twig_Error_Loader When $name is not found - */ - public function getSourceContext($name); -} - -class_alias('Twig_SourceContextLoaderInterface', 'Twig\Loader\SourceContextLoaderInterface', false); diff --git a/system/templateEngines/Twig/Twig1x/Template.php b/system/templateEngines/Twig/Twig1x/Template.php deleted file mode 100644 index 78a5738..0000000 --- a/system/templateEngines/Twig/Twig1x/Template.php +++ /dev/null @@ -1,704 +0,0 @@ -load() - * instead, which returns an instance of Twig_TemplateWrapper. - * - * @author Fabien Potencier - * - * @internal - */ -abstract class Twig_Template implements Twig_TemplateInterface -{ - /** - * @internal - */ - protected static $cache = []; - - protected $parent; - protected $parents = []; - protected $env; - protected $blocks = []; - protected $traits = []; - - public function __construct(Twig_Environment $env) - { - $this->env = $env; - } - - /** - * @internal this method will be removed in 2.0 and is only used internally to provide an upgrade path from 1.x to 2.0 - */ - public function __toString() - { - return $this->getTemplateName(); - } - - /** - * Returns the template name. - * - * @return string The template name - */ - abstract public function getTemplateName(); - - /** - * Returns debug information about the template. - * - * @return array Debug information - * - * @internal - */ - public function getDebugInfo() - { - return []; - } - - /** - * Returns the template source code. - * - * @return string The template source code - * - * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead - */ - public function getSource() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); - - return ''; - } - - /** - * Returns information about the original template source code. - * - * @return Twig_Source - */ - public function getSourceContext() - { - return new Twig_Source('', $this->getTemplateName()); - } - - /** - * @deprecated since 1.20 (to be removed in 2.0) - */ - public function getEnvironment() - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED); - - return $this->env; - } - - /** - * Returns the parent template. - * - * This method is for internal use only and should never be called - * directly. - * - * @param array $context - * - * @return Twig_TemplateInterface|Twig_TemplateWrapper|false The parent template or false if there is no parent - * - * @internal - */ - public function getParent(array $context) - { - if (null !== $this->parent) { - return $this->parent; - } - - try { - $parent = $this->doGetParent($context); - - if (false === $parent) { - return false; - } - - if ($parent instanceof self || $parent instanceof Twig_TemplateWrapper) { - return $this->parents[$parent->getSourceContext()->getName()] = $parent; - } - - if (!isset($this->parents[$parent])) { - $this->parents[$parent] = $this->loadTemplate($parent); - } - } catch (Twig_Error_Loader $e) { - $e->setSourceContext(null); - $e->guess(); - - throw $e; - } - - return $this->parents[$parent]; - } - - protected function doGetParent(array $context) - { - return false; - } - - public function isTraitable() - { - return true; - } - - /** - * Displays a parent block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to display from the parent - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @internal - */ - public function displayParentBlock($name, array $context, array $blocks = []) - { - $name = (string) $name; - - if (isset($this->traits[$name])) { - $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); - } elseif (false !== $parent = $this->getParent($context)) { - $parent->displayBlock($name, $context, $blocks, false); - } else { - throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); - } - } - - /** - * Displays a block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to display - * @param array $context The context - * @param array $blocks The current set of blocks - * @param bool $useBlocks Whether to use the current set of blocks - * - * @internal - */ - public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true) - { - $name = (string) $name; - - if ($useBlocks && isset($blocks[$name])) { - $template = $blocks[$name][0]; - $block = $blocks[$name][1]; - } elseif (isset($this->blocks[$name])) { - $template = $this->blocks[$name][0]; - $block = $this->blocks[$name][1]; - } else { - $template = null; - $block = null; - } - - // avoid RCEs when sandbox is enabled - if (null !== $template && !$template instanceof self) { - throw new LogicException('A block must be a method on a Twig_Template instance.'); - } - - if (null !== $template) { - try { - $template->$block($context, $blocks); - } catch (Twig_Error $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($template->getSourceContext()); - } - - // this is mostly useful for Twig_Error_Loader exceptions - // see Twig_Error_Loader - if (false === $e->getTemplateLine()) { - $e->setTemplateLine(-1); - $e->guess(); - } - - throw $e; - } catch (Exception $e) { - throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); - } - } elseif (false !== $parent = $this->getParent($context)) { - $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); - } else { - @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED); - } - } - - /** - * Renders a parent block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to render from the parent - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @return string The rendered block - * - * @internal - */ - public function renderParentBlock($name, array $context, array $blocks = []) - { - ob_start(); - $this->displayParentBlock($name, $context, $blocks); - - return ob_get_clean(); - } - - /** - * Renders a block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to render - * @param array $context The context - * @param array $blocks The current set of blocks - * @param bool $useBlocks Whether to use the current set of blocks - * - * @return string The rendered block - * - * @internal - */ - public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true) - { - ob_start(); - $this->displayBlock($name, $context, $blocks, $useBlocks); - - return ob_get_clean(); - } - - /** - * Returns whether a block exists or not in the current context of the template. - * - * This method checks blocks defined in the current template - * or defined in "used" traits or defined in parent templates. - * - * @param string $name The block name - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @return bool true if the block exists, false otherwise - * - * @internal - */ - public function hasBlock($name, array $context = null, array $blocks = []) - { - if (null === $context) { - @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); - - return isset($this->blocks[(string) $name]); - } - - if (isset($blocks[$name])) { - return $blocks[$name][0] instanceof self; - } - - if (isset($this->blocks[$name])) { - return true; - } - - if (false !== $parent = $this->getParent($context)) { - return $parent->hasBlock($name, $context); - } - - return false; - } - - /** - * Returns all block names in the current context of the template. - * - * This method checks blocks defined in the current template - * or defined in "used" traits or defined in parent templates. - * - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @return array An array of block names - * - * @internal - */ - public function getBlockNames(array $context = null, array $blocks = []) - { - if (null === $context) { - @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); - - return array_keys($this->blocks); - } - - $names = array_merge(array_keys($blocks), array_keys($this->blocks)); - - if (false !== $parent = $this->getParent($context)) { - $names = array_merge($names, $parent->getBlockNames($context)); - } - - return array_unique($names); - } - - protected function loadTemplate($template, $templateName = null, $line = null, $index = null) - { - try { - if (is_array($template)) { - return $this->env->resolveTemplate($template); - } - - if ($template instanceof self || $template instanceof Twig_TemplateWrapper) { - return $template; - } - - return $this->env->loadTemplate($template, $index); - } catch (Twig_Error $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($templateName ? new Twig_Source('', $templateName) : $this->getSourceContext()); - } - - if ($e->getTemplateLine()) { - throw $e; - } - - if (!$line) { - $e->guess(); - } else { - $e->setTemplateLine($line); - } - - throw $e; - } - } - - /** - * Returns all blocks. - * - * This method is for internal use only and should never be called - * directly. - * - * @return array An array of blocks - * - * @internal - */ - public function getBlocks() - { - return $this->blocks; - } - - public function display(array $context, array $blocks = []) - { - $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); - } - - public function render(array $context) - { - $level = ob_get_level(); - ob_start(); - try { - $this->display($context); - } catch (Exception $e) { - while (ob_get_level() > $level) { - ob_end_clean(); - } - - throw $e; - } catch (Throwable $e) { - while (ob_get_level() > $level) { - ob_end_clean(); - } - - throw $e; - } - - return ob_get_clean(); - } - - protected function displayWithErrorHandling(array $context, array $blocks = []) - { - try { - $this->doDisplay($context, $blocks); - } catch (Twig_Error $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($this->getSourceContext()); - } - - // this is mostly useful for Twig_Error_Loader exceptions - // see Twig_Error_Loader - if (false === $e->getTemplateLine()) { - $e->setTemplateLine(-1); - $e->guess(); - } - - throw $e; - } catch (Exception $e) { - throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); - } - } - - /** - * Auto-generated method to display the template with the given context. - * - * @param array $context An array of parameters to pass to the template - * @param array $blocks An array of blocks to pass to the template - */ - abstract protected function doDisplay(array $context, array $blocks = []); - - /** - * Returns a variable from the context. - * - * This method is for internal use only and should never be called - * directly. - * - * This method should not be overridden in a sub-class as this is an - * implementation detail that has been introduced to optimize variable - * access for versions of PHP before 5.4. This is not a way to override - * the way to get a variable value. - * - * @param array $context The context - * @param string $item The variable to return from the context - * @param bool $ignoreStrictCheck Whether to ignore the strict variable check or not - * - * @return mixed The content of the context variable - * - * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode - * - * @internal - */ - final protected function getContext($context, $item, $ignoreStrictCheck = false) - { - if (!array_key_exists($item, $context)) { - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return; - } - - throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext()); - } - - return $context[$item]; - } - - /** - * Returns the attribute value for a given array/object. - * - * @param mixed $object The object or array from where to get the item - * @param mixed $item The item to get from the array or object - * @param array $arguments An array of arguments to pass if the item is an object method - * @param string $type The type of attribute (@see Twig_Template constants) - * @param bool $isDefinedTest Whether this is only a defined check - * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not - * - * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true - * - * @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false - * - * @internal - */ - protected function getAttribute($object, $item, array $arguments = [], $type = self::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) - { - // array - if (self::METHOD_CALL !== $type) { - $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; - - if (((is_array($object) || $object instanceof ArrayObject) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object))) - || ($object instanceof ArrayAccess && isset($object[$arrayItem])) - ) { - if ($isDefinedTest) { - return true; - } - - return $object[$arrayItem]; - } - - if (self::ARRAY_CALL === $type || !is_object($object)) { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return; - } - - if ($object instanceof ArrayAccess) { - $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, get_class($object)); - } elseif (is_object($object)) { - $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, get_class($object)); - } elseif (is_array($object)) { - if (empty($object)) { - $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); - } else { - $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object))); - } - } elseif (self::ARRAY_CALL === $type) { - if (null === $object) { - $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); - } else { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, gettype($object), $object); - } - } elseif (null === $object) { - $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); - } else { - $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, gettype($object), $object); - } - - throw new Twig_Error_Runtime($message, -1, $this->getSourceContext()); - } - } - - if (!is_object($object)) { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return; - } - - if (null === $object) { - $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); - } elseif (is_array($object)) { - $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); - } else { - $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, gettype($object), $object); - } - - throw new Twig_Error_Runtime($message, -1, $this->getSourceContext()); - } - - // object property - if (self::METHOD_CALL !== $type && !$object instanceof self) { // Twig_Template does not have public properties, and we don't want to allow access to internal ones - if (isset($object->$item) || array_key_exists((string) $item, $object)) { - if ($isDefinedTest) { - return true; - } - - if ($this->env->hasExtension('Twig_Extension_Sandbox')) { - $this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item); - } - - return $object->$item; - } - } - - $class = get_class($object); - - // object method - if (!isset(self::$cache[$class])) { - // get_class_methods returns all methods accessible in the scope, but we only want public ones to be accessible in templates - if ($object instanceof self) { - $ref = new ReflectionClass($class); - $methods = []; - - foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) { - // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment - if ('getenvironment' !== strtolower($refMethod->name)) { - $methods[] = $refMethod->name; - } - } - } else { - $methods = get_class_methods($object); - } - // sort values to have consistent behavior, so that "get" methods win precedence over "is" methods - sort($methods); - - $cache = []; - - foreach ($methods as $method) { - $cache[$method] = $method; - $cache[$lcName = strtolower($method)] = $method; - - if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) { - $name = substr($method, 3); - $lcName = substr($lcName, 3); - } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) { - $name = substr($method, 2); - $lcName = substr($lcName, 2); - } else { - continue; - } - - // skip get() and is() methods (in which case, $name is empty) - if ($name) { - if (!isset($cache[$name])) { - $cache[$name] = $method; - } - if (!isset($cache[$lcName])) { - $cache[$lcName] = $method; - } - } - } - self::$cache[$class] = $cache; - } - - $call = false; - if (isset(self::$cache[$class][$item])) { - $method = self::$cache[$class][$item]; - } elseif (isset(self::$cache[$class][$lcItem = strtolower($item)])) { - $method = self::$cache[$class][$lcItem]; - } elseif (isset(self::$cache[$class]['__call'])) { - $method = $item; - $call = true; - } else { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return; - } - - throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext()); - } - - if ($isDefinedTest) { - return true; - } - - if ($this->env->hasExtension('Twig_Extension_Sandbox')) { - $this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method); - } - - // Some objects throw exceptions when they have __call, and the method we try - // to call is not supported. If ignoreStrictCheck is true, we should return null. - try { - if (!$arguments) { - $ret = $object->$method(); - } else { - $ret = call_user_func_array([$object, $method], $arguments); - } - } catch (BadMethodCallException $e) { - if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { - return; - } - throw $e; - } - - // @deprecated in 1.28 - if ($object instanceof Twig_TemplateInterface) { - $self = $object->getTemplateName() === $this->getTemplateName(); - $message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName()); - if ('renderBlock' === $method || 'displayBlock' === $method) { - $message .= sprintf(' Use block("%s"%s) instead).', $arguments[0], $self ? '' : ', template'); - } elseif ('hasBlock' === $method) { - $message .= sprintf(' Use "block("%s"%s) is defined" instead).', $arguments[0], $self ? '' : ', template'); - } elseif ('render' === $method || 'display' === $method) { - $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName()); - } - @trigger_error($message, E_USER_DEPRECATED); - - return '' === $ret ? '' : new Twig_Markup($ret, $this->env->getCharset()); - } - - return $ret; - } -} - -class_alias('Twig_Template', 'Twig\Template', false); diff --git a/system/templateEngines/Twig/Twig1x/TemplateInterface.php b/system/templateEngines/Twig/Twig1x/TemplateInterface.php deleted file mode 100644 index 4ab9c57..0000000 --- a/system/templateEngines/Twig/Twig1x/TemplateInterface.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 3.0) - */ -interface Twig_TemplateInterface -{ - const ANY_CALL = 'any'; - const ARRAY_CALL = 'array'; - const METHOD_CALL = 'method'; - - /** - * Renders the template with the given context and returns it as string. - * - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered template - */ - public function render(array $context); - - /** - * Displays the template with the given context. - * - * @param array $context An array of parameters to pass to the template - * @param array $blocks An array of blocks to pass to the template - */ - public function display(array $context, array $blocks = []); - - /** - * Returns the bound environment for this template. - * - * @return Twig_Environment - */ - public function getEnvironment(); -} diff --git a/system/templateEngines/Twig/Twig1x/TemplateWrapper.php b/system/templateEngines/Twig/Twig1x/TemplateWrapper.php deleted file mode 100644 index 430e91c..0000000 --- a/system/templateEngines/Twig/Twig1x/TemplateWrapper.php +++ /dev/null @@ -1,137 +0,0 @@ - - */ -final class Twig_TemplateWrapper -{ - private $env; - private $template; - - /** - * This method is for internal use only and should never be called - * directly (use Twig_Environment::load() instead). - * - * @internal - */ - public function __construct(Twig_Environment $env, Twig_Template $template) - { - $this->env = $env; - $this->template = $template; - } - - /** - * Renders the template. - * - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered template - */ - public function render($context = []) - { - // using func_get_args() allows to not expose the blocks argument - // as it should only be used by internal code - return $this->template->render($context, func_num_args() > 1 ? func_get_arg(1) : []); - } - - /** - * Displays the template. - * - * @param array $context An array of parameters to pass to the template - */ - public function display($context = []) - { - // using func_get_args() allows to not expose the blocks argument - // as it should only be used by internal code - $this->template->display($context, func_num_args() >= 1 ? func_get_arg(1) : []); - } - - /** - * Checks if a block is defined. - * - * @param string $name The block name - * @param array $context An array of parameters to pass to the template - * - * @return bool - */ - public function hasBlock($name, $context = []) - { - return $this->template->hasBlock($name, $context); - } - - /** - * Returns defined block names in the template. - * - * @param array $context An array of parameters to pass to the template - * - * @return string[] An array of defined template block names - */ - public function getBlockNames($context = []) - { - return $this->template->getBlockNames($context); - } - - /** - * Renders a template block. - * - * @param string $name The block name to render - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered block - */ - public function renderBlock($name, $context = []) - { - $context = $this->env->mergeGlobals($context); - $level = ob_get_level(); - ob_start(); - try { - $this->template->displayBlock($name, $context); - } catch (Exception $e) { - while (ob_get_level() > $level) { - ob_end_clean(); - } - - throw $e; - } catch (Throwable $e) { - while (ob_get_level() > $level) { - ob_end_clean(); - } - - throw $e; - } - - return ob_get_clean(); - } - - /** - * Displays a template block. - * - * @param string $name The block name to render - * @param array $context An array of parameters to pass to the template - */ - public function displayBlock($name, $context = []) - { - $this->template->displayBlock($name, $this->env->mergeGlobals($context)); - } - - /** - * @return Twig_Source - */ - public function getSourceContext() - { - return $this->template->getSourceContext(); - } -} - -class_alias('Twig_TemplateWrapper', 'Twig\TemplateWrapper', false); diff --git a/system/templateEngines/Twig/Twig1x/Test.php b/system/templateEngines/Twig/Twig1x/Test.php deleted file mode 100644 index 5396644..0000000 --- a/system/templateEngines/Twig/Twig1x/Test.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -abstract class Twig_Test implements Twig_TestInterface, Twig_TestCallableInterface -{ - protected $options; - protected $arguments = []; - - public function __construct(array $options = []) - { - $this->options = array_merge([ - 'callable' => null, - ], $options); - } - - public function getCallable() - { - return $this->options['callable']; - } -} diff --git a/system/templateEngines/Twig/Twig1x/Test/Function.php b/system/templateEngines/Twig/Twig1x/Test/Function.php deleted file mode 100644 index f34fb05..0000000 --- a/system/templateEngines/Twig/Twig1x/Test/Function.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Test_Function extends Twig_Test -{ - protected $function; - - public function __construct($function, array $options = []) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/system/templateEngines/Twig/Twig1x/Test/IntegrationTestCase.php b/system/templateEngines/Twig/Twig1x/Test/IntegrationTestCase.php deleted file mode 100644 index 31db139..0000000 --- a/system/templateEngines/Twig/Twig1x/Test/IntegrationTestCase.php +++ /dev/null @@ -1,245 +0,0 @@ - - * @author Karma Dordrak - */ -abstract class Twig_Test_IntegrationTestCase extends TestCase -{ - /** - * @return string - */ - abstract protected function getFixturesDir(); - - /** - * @return Twig_RuntimeLoaderInterface[] - */ - protected function getRuntimeLoaders() - { - return []; - } - - /** - * @return Twig_ExtensionInterface[] - */ - protected function getExtensions() - { - return []; - } - - /** - * @return Twig_SimpleFilter[] - */ - protected function getTwigFilters() - { - return []; - } - - /** - * @return Twig_SimpleFunction[] - */ - protected function getTwigFunctions() - { - return []; - } - - /** - * @return Twig_SimpleTest[] - */ - protected function getTwigTests() - { - return []; - } - - /** - * @dataProvider getTests - */ - public function testIntegration($file, $message, $condition, $templates, $exception, $outputs) - { - $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); - } - - /** - * @dataProvider getLegacyTests - * @group legacy - */ - public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs) - { - $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); - } - - public function getTests($name, $legacyTests = false) - { - $fixturesDir = realpath($this->getFixturesDir()); - $tests = []; - - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { - if (!preg_match('/\.test$/', $file)) { - continue; - } - - if ($legacyTests xor false !== strpos($file->getRealpath(), '.legacy.test')) { - continue; - } - - $test = file_get_contents($file->getRealpath()); - - if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { - $message = $match[1]; - $condition = $match[2]; - $templates = self::parseTemplates($match[3]); - $exception = $match[5]; - $outputs = [[null, $match[4], null, '']]; - } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { - $message = $match[1]; - $condition = $match[2]; - $templates = self::parseTemplates($match[3]); - $exception = false; - preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); - } else { - throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); - } - - $tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs]; - } - - if ($legacyTests && empty($tests)) { - // add a dummy test to avoid a PHPUnit message - return [['not', '-', '', [], '', []]]; - } - - return $tests; - } - - public function getLegacyTests() - { - return $this->getTests('testLegacyIntegration', true); - } - - protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) - { - if (!$outputs) { - $this->markTestSkipped('no tests to run'); - } - - if ($condition) { - eval('$ret = '.$condition.';'); - if (!$ret) { - $this->markTestSkipped($condition); - } - } - - $loader = new Twig_Loader_Array($templates); - - foreach ($outputs as $i => $match) { - $config = array_merge([ - 'cache' => false, - 'strict_variables' => true, - ], $match[2] ? eval($match[2].';') : []); - $twig = new Twig_Environment($loader, $config); - $twig->addGlobal('global', 'global'); - foreach ($this->getRuntimeLoaders() as $runtimeLoader) { - $twig->addRuntimeLoader($runtimeLoader); - } - - foreach ($this->getExtensions() as $extension) { - $twig->addExtension($extension); - } - - foreach ($this->getTwigFilters() as $filter) { - $twig->addFilter($filter); - } - - foreach ($this->getTwigTests() as $test) { - $twig->addTest($test); - } - - foreach ($this->getTwigFunctions() as $function) { - $twig->addFunction($function); - } - - $p = new ReflectionProperty($twig, 'templateClassPrefix'); - $p->setAccessible(true); - $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); - - try { - $template = $twig->loadTemplate('index.twig'); - } catch (Exception $e) { - if (false !== $exception) { - $message = $e->getMessage(); - $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $message))); - $last = substr($message, strlen($message) - 1); - $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.'); - - return; - } - - throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); - } - - try { - $output = trim($template->render(eval($match[1].';')), "\n "); - } catch (Exception $e) { - if (false !== $exception) { - $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); - - return; - } - - $e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); - - $output = trim(sprintf('%s: %s', get_class($e), $e->getMessage())); - } - - if (false !== $exception) { - list($class) = explode(':', $exception); - $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception'; - $this->assertThat(null, new $constraintClass($class)); - } - - $expected = trim($match[3], "\n "); - - if ($expected !== $output) { - printf("Compiled templates that failed on case %d:\n", $i + 1); - - foreach (array_keys($templates) as $name) { - echo "Template: $name\n"; - $loader = $twig->getLoader(); - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - $source = new Twig_Source($loader->getSource($name), $name); - } else { - $source = $loader->getSourceContext($name); - } - echo $twig->compile($twig->parse($twig->tokenize($source))); - } - } - $this->assertEquals($expected, $output, $message.' (in '.$file.')'); - } - } - - protected static function parseTemplates($test) - { - $templates = []; - preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); - foreach ($matches as $match) { - $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; - } - - return $templates; - } -} - -class_alias('Twig_Test_IntegrationTestCase', 'Twig\Test\IntegrationTestCase', false); diff --git a/system/templateEngines/Twig/Twig1x/Test/Method.php b/system/templateEngines/Twig/Twig1x/Test/Method.php deleted file mode 100644 index 6949bb2..0000000 --- a/system/templateEngines/Twig/Twig1x/Test/Method.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Test_Method extends Twig_Test -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = []) - { - $options['callable'] = [$extension, $method]; - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', get_class($this->extension), $this->method); - } -} diff --git a/system/templateEngines/Twig/Twig1x/Test/NodeTestCase.php b/system/templateEngines/Twig/Twig1x/Test/NodeTestCase.php deleted file mode 100644 index a20fbba..0000000 --- a/system/templateEngines/Twig/Twig1x/Test/NodeTestCase.php +++ /dev/null @@ -1,75 +0,0 @@ -assertNodeCompilation($source, $node, $environment, $isPattern); - } - - public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null, $isPattern = false) - { - $compiler = $this->getCompiler($environment); - $compiler->compile($node); - - if ($isPattern) { - $this->assertStringMatchesFormat($source, trim($compiler->getSource())); - } else { - $this->assertEquals($source, trim($compiler->getSource())); - } - } - - protected function getCompiler(Twig_Environment $environment = null) - { - return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment); - } - - protected function getEnvironment() - { - return new Twig_Environment(new Twig_Loader_Array([])); - } - - protected function getVariableGetter($name, $line = false) - { - $line = $line > 0 ? "// line {$line}\n" : ''; - - if (PHP_VERSION_ID >= 70000) { - return sprintf('%s($context["%s"] ?? null)', $line, $name, $name); - } - - if (PHP_VERSION_ID >= 50400) { - return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); - } - - return sprintf('%s$this->getContext($context, "%s")', $line, $name); - } - - protected function getAttributeGetter() - { - if (function_exists('twig_template_get_attributes')) { - return 'twig_template_get_attributes($this, '; - } - - return '$this->getAttribute('; - } -} - -class_alias('Twig_Test_NodeTestCase', 'Twig\Test\NodeTestCase', false); -class_exists('Twig_Environment'); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig1x/Token.php b/system/templateEngines/Twig/Twig1x/Token.php deleted file mode 100644 index 8906686..0000000 --- a/system/templateEngines/Twig/Twig1x/Token.php +++ /dev/null @@ -1,207 +0,0 @@ - - * - * @final - */ -class Twig_Token -{ - protected $value; - protected $type; - protected $lineno; - - const EOF_TYPE = -1; - const TEXT_TYPE = 0; - const BLOCK_START_TYPE = 1; - const VAR_START_TYPE = 2; - const BLOCK_END_TYPE = 3; - const VAR_END_TYPE = 4; - const NAME_TYPE = 5; - const NUMBER_TYPE = 6; - const STRING_TYPE = 7; - const OPERATOR_TYPE = 8; - const PUNCTUATION_TYPE = 9; - const INTERPOLATION_START_TYPE = 10; - const INTERPOLATION_END_TYPE = 11; - - /** - * @param int $type The type of the token - * @param string $value The token value - * @param int $lineno The line position in the source - */ - public function __construct($type, $value, $lineno) - { - $this->type = $type; - $this->value = $value; - $this->lineno = $lineno; - } - - public function __toString() - { - return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value); - } - - /** - * Tests the current token for a type and/or a value. - * - * Parameters may be: - * * just type - * * type and value (or array of possible values) - * * just value (or array of possible values) (NAME_TYPE is used as type) - * - * @param array|string|int $type The type to test - * @param array|string|null $values The token value - * - * @return bool - */ - public function test($type, $values = null) - { - if (null === $values && !is_int($type)) { - $values = $type; - $type = self::NAME_TYPE; - } - - return ($this->type === $type) && ( - null === $values || - (is_array($values) && in_array($this->value, $values)) || - $this->value == $values - ); - } - - /** - * @return int - */ - public function getLine() - { - return $this->lineno; - } - - /** - * @return int - */ - public function getType() - { - return $this->type; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * Returns the constant representation (internal) of a given type. - * - * @param int $type The type as an integer - * @param bool $short Whether to return a short representation or not - * - * @return string The string representation - */ - public static function typeToString($type, $short = false) - { - switch ($type) { - case self::EOF_TYPE: - $name = 'EOF_TYPE'; - break; - case self::TEXT_TYPE: - $name = 'TEXT_TYPE'; - break; - case self::BLOCK_START_TYPE: - $name = 'BLOCK_START_TYPE'; - break; - case self::VAR_START_TYPE: - $name = 'VAR_START_TYPE'; - break; - case self::BLOCK_END_TYPE: - $name = 'BLOCK_END_TYPE'; - break; - case self::VAR_END_TYPE: - $name = 'VAR_END_TYPE'; - break; - case self::NAME_TYPE: - $name = 'NAME_TYPE'; - break; - case self::NUMBER_TYPE: - $name = 'NUMBER_TYPE'; - break; - case self::STRING_TYPE: - $name = 'STRING_TYPE'; - break; - case self::OPERATOR_TYPE: - $name = 'OPERATOR_TYPE'; - break; - case self::PUNCTUATION_TYPE: - $name = 'PUNCTUATION_TYPE'; - break; - case self::INTERPOLATION_START_TYPE: - $name = 'INTERPOLATION_START_TYPE'; - break; - case self::INTERPOLATION_END_TYPE: - $name = 'INTERPOLATION_END_TYPE'; - break; - default: - throw new LogicException(sprintf('Token of type "%s" does not exist.', $type)); - } - - return $short ? $name : 'Twig_Token::'.$name; - } - - /** - * Returns the English representation of a given type. - * - * @param int $type The type as an integer - * - * @return string The string representation - */ - public static function typeToEnglish($type) - { - switch ($type) { - case self::EOF_TYPE: - return 'end of template'; - case self::TEXT_TYPE: - return 'text'; - case self::BLOCK_START_TYPE: - return 'begin of statement block'; - case self::VAR_START_TYPE: - return 'begin of print statement'; - case self::BLOCK_END_TYPE: - return 'end of statement block'; - case self::VAR_END_TYPE: - return 'end of print statement'; - case self::NAME_TYPE: - return 'name'; - case self::NUMBER_TYPE: - return 'number'; - case self::STRING_TYPE: - return 'string'; - case self::OPERATOR_TYPE: - return 'operator'; - case self::PUNCTUATION_TYPE: - return 'punctuation'; - case self::INTERPOLATION_START_TYPE: - return 'begin of string interpolation'; - case self::INTERPOLATION_END_TYPE: - return 'end of string interpolation'; - default: - throw new LogicException(sprintf('Token of type "%s" does not exist.', $type)); - } - } -} - -class_alias('Twig_Token', 'Twig\Token', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser.php b/system/templateEngines/Twig/Twig1x/TokenParser.php deleted file mode 100644 index 1b4de14..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -abstract class Twig_TokenParser implements Twig_TokenParserInterface -{ - /** - * @var Twig_Parser - */ - protected $parser; - - /** - * Sets the parser associated with this token parser. - */ - public function setParser(Twig_Parser $parser) - { - $this->parser = $parser; - } -} - -class_alias('Twig_TokenParser', 'Twig\TokenParser\AbstractTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/AutoEscape.php b/system/templateEngines/Twig/Twig1x/TokenParser/AutoEscape.php deleted file mode 100644 index 0a3ba09..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/AutoEscape.php +++ /dev/null @@ -1,83 +0,0 @@ - - * {% autoescape true %} - * Everything will be automatically escaped in this block - * {% endautoescape %} - * - * {% autoescape false %} - * Everything will be outputed as is in this block - * {% endautoescape %} - * - * {% autoescape true js %} - * Everything will be automatically escaped in this block - * using the js escaping strategy - * {% endautoescape %} - * - * - * @final - */ -class Twig_TokenParser_AutoEscape extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - - if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { - $value = 'html'; - } else { - $expr = $this->parser->getExpressionParser()->parseExpression(); - if (!$expr instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - $value = $expr->getAttribute('value'); - - $compat = true === $value || false === $value; - - if (true === $value) { - $value = 'html'; - } - - if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { - @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED); - - if (false === $value) { - throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - - $value = $stream->next()->getValue(); - } - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endautoescape'); - } - - public function getTag() - { - return 'autoescape'; - } -} - -class_alias('Twig_TokenParser_AutoEscape', 'Twig\TokenParser\AutoEscapeTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Block.php b/system/templateEngines/Twig/Twig1x/TokenParser/Block.php deleted file mode 100644 index 2f83315..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Block.php +++ /dev/null @@ -1,73 +0,0 @@ - - * {% block head %} - * - * {% block title %}{% endblock %} - My Webpage - * {% endblock %} - * - * - * @final - */ -class Twig_TokenParser_Block extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - if ($this->parser->hasBlock($name)) { - throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node([]), $lineno)); - $this->parser->pushLocalScope(); - $this->parser->pushBlockStack($name); - - if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) { - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) { - $value = $token->getValue(); - - if ($value != $name) { - throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } - } else { - $body = new Twig_Node([ - new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno), - ]); - } - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $block->setNode('body', $body); - $this->parser->popBlockStack(); - $this->parser->popLocalScope(); - - return new Twig_Node_BlockReference($name, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endblock'); - } - - public function getTag() - { - return 'block'; - } -} - -class_alias('Twig_TokenParser_Block', 'Twig\TokenParser\BlockTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Deprecated.php b/system/templateEngines/Twig/Twig1x/TokenParser/Deprecated.php deleted file mode 100644 index be5d549..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Deprecated.php +++ /dev/null @@ -1,42 +0,0 @@ - - * {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %} - * - * {% extends 'layout.html.twig' %} - * - * - * @author Yonel Ceruto - * - * @final - */ -class Twig_TokenParser_Deprecated extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $expr = $this->parser->getExpressionParser()->parseExpression(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Deprecated($expr, $token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'deprecated'; - } -} - -class_alias('Twig_TokenParser_Deprecated', 'Twig\TokenParser\DeprecatedTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Do.php b/system/templateEngines/Twig/Twig1x/TokenParser/Do.php deleted file mode 100644 index 8ce0880..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Do.php +++ /dev/null @@ -1,34 +0,0 @@ -parser->getExpressionParser()->parseExpression(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Do($expr, $token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'do'; - } -} - -class_alias('Twig_TokenParser_Do', 'Twig\TokenParser\DoTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Embed.php b/system/templateEngines/Twig/Twig1x/TokenParser/Embed.php deleted file mode 100644 index 62ad917..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Embed.php +++ /dev/null @@ -1,67 +0,0 @@ -parser->getStream(); - - $parent = $this->parser->getExpressionParser()->parseExpression(); - - list($variables, $only, $ignoreMissing) = $this->parseArguments(); - - $parentToken = $fakeParentToken = new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine()); - if ($parent instanceof Twig_Node_Expression_Constant) { - $parentToken = new Twig_Token(Twig_Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine()); - } elseif ($parent instanceof Twig_Node_Expression_Name) { - $parentToken = new Twig_Token(Twig_Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine()); - } - - // inject a fake parent to make the parent() function work - $stream->injectTokens([ - new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()), - new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()), - $parentToken, - new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()), - ]); - - $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); - - // override the parent with the correct one - if ($fakeParentToken === $parentToken) { - $module->setNode('parent', $parent); - } - - $this->parser->embedTemplate($module); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endembed'); - } - - public function getTag() - { - return 'embed'; - } -} - -class_alias('Twig_TokenParser_Embed', 'Twig\TokenParser\EmbedTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Extends.php b/system/templateEngines/Twig/Twig1x/TokenParser/Extends.php deleted file mode 100644 index 31168cc..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Extends.php +++ /dev/null @@ -1,46 +0,0 @@ - - * {% extends "base.html" %} - * - * - * @final - */ -class Twig_TokenParser_Extends extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - - if (!$this->parser->isMainScope()) { - throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext()); - } - - if (null !== $this->parser->getParent()) { - throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); - } - $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - } - - public function getTag() - { - return 'extends'; - } -} - -class_alias('Twig_TokenParser_Extends', 'Twig\TokenParser\ExtendsTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Filter.php b/system/templateEngines/Twig/Twig1x/TokenParser/Filter.php deleted file mode 100644 index e956d04..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Filter.php +++ /dev/null @@ -1,53 +0,0 @@ - - * {% filter upper %} - * This text becomes uppercase - * {% endfilter %} - * - * - * @final - */ -class Twig_TokenParser_Filter extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $name = $this->parser->getVarName(); - $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), null, $token->getLine(), $this->getTag()); - - $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - $block = new Twig_Node_Block($name, $body, $token->getLine()); - $this->parser->setBlock($name, $block); - - return new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endfilter'); - } - - public function getTag() - { - return 'filter'; - } -} - -class_alias('Twig_TokenParser_Filter', 'Twig\TokenParser\FilterTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Flush.php b/system/templateEngines/Twig/Twig1x/TokenParser/Flush.php deleted file mode 100644 index 51832c7..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Flush.php +++ /dev/null @@ -1,34 +0,0 @@ -parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Flush($token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'flush'; - } -} - -class_alias('Twig_TokenParser_Flush', 'Twig\TokenParser\FlushTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/For.php b/system/templateEngines/Twig/Twig1x/TokenParser/For.php deleted file mode 100644 index fecf58b..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/For.php +++ /dev/null @@ -1,127 +0,0 @@ - - *
    - * {% for user in users %} - *
  • {{ user.username|e }}
  • - * {% endfor %} - *
- * - * - * @final - */ -class Twig_TokenParser_For extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); - $stream->expect(Twig_Token::OPERATOR_TYPE, 'in'); - $seq = $this->parser->getExpressionParser()->parseExpression(); - - $ifexpr = null; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'if')) { - $ifexpr = $this->parser->getExpressionParser()->parseExpression(); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse([$this, 'decideForFork']); - if ('else' == $stream->next()->getValue()) { - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $else = $this->parser->subparse([$this, 'decideForEnd'], true); - } else { - $else = null; - } - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - if (count($targets) > 1) { - $keyTarget = $targets->getNode(0); - $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); - $valueTarget = $targets->getNode(1); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); - } else { - $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno); - $valueTarget = $targets->getNode(0); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); - } - - if ($ifexpr) { - $this->checkLoopUsageCondition($stream, $ifexpr); - $this->checkLoopUsageBody($stream, $body); - } - - return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); - } - - public function decideForFork(Twig_Token $token) - { - return $token->test(['else', 'endfor']); - } - - public function decideForEnd(Twig_Token $token) - { - return $token->test('endfor'); - } - - // the loop variable cannot be used in the condition - protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node) - { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); - } - - foreach ($node as $n) { - if (!$n) { - continue; - } - - $this->checkLoopUsageCondition($stream, $n); - } - } - - // check usage of non-defined loop-items - // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) - protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node) - { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - $attribute = $node->getNode('attribute'); - if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { - throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); - } - } - - // should check for parent.loop.XXX usage - if ($node instanceof Twig_Node_For) { - return; - } - - foreach ($node as $n) { - if (!$n) { - continue; - } - - $this->checkLoopUsageBody($stream, $n); - } - } - - public function getTag() - { - return 'for'; - } -} - -class_alias('Twig_TokenParser_For', 'Twig\TokenParser\ForTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/From.php b/system/templateEngines/Twig/Twig1x/TokenParser/From.php deleted file mode 100644 index 234301b..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/From.php +++ /dev/null @@ -1,66 +0,0 @@ - - * {% from 'forms.html' import forms %} - * - * - * @final - */ -class Twig_TokenParser_From extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $macro = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - $stream->expect('import'); - - $targets = []; - do { - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - $alias = $name; - if ($stream->nextIf('as')) { - $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - } - - $targets[$name] = $alias; - - if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { - break; - } - } while (true); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); - - foreach ($targets as $name => $alias) { - if ($this->parser->isReservedMacroName($name)) { - throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); - } - - $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var')); - } - - return $node; - } - - public function getTag() - { - return 'from'; - } -} - -class_alias('Twig_TokenParser_From', 'Twig\TokenParser\FromTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/If.php b/system/templateEngines/Twig/Twig1x/TokenParser/If.php deleted file mode 100644 index ba48e27..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/If.php +++ /dev/null @@ -1,86 +0,0 @@ - - * {% if users %} - *
    - * {% for user in users %} - *
  • {{ user.username|e }}
  • - * {% endfor %} - *
- * {% endif %} - * - * - * @final - */ -class Twig_TokenParser_If extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse([$this, 'decideIfFork']); - $tests = [$expr, $body]; - $else = null; - - $end = false; - while (!$end) { - switch ($stream->next()->getValue()) { - case 'else': - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $else = $this->parser->subparse([$this, 'decideIfEnd']); - break; - - case 'elseif': - $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse([$this, 'decideIfFork']); - $tests[] = $expr; - $tests[] = $body; - break; - - case 'endif': - $end = true; - break; - - default: - throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); - } - - public function decideIfFork(Twig_Token $token) - { - return $token->test(['elseif', 'else', 'endif']); - } - - public function decideIfEnd(Twig_Token $token) - { - return $token->test(['endif']); - } - - public function getTag() - { - return 'if'; - } -} - -class_alias('Twig_TokenParser_If', 'Twig\TokenParser\IfTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Import.php b/system/templateEngines/Twig/Twig1x/TokenParser/Import.php deleted file mode 100644 index 47802f5..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Import.php +++ /dev/null @@ -1,41 +0,0 @@ - - * {% import 'forms.html' as forms %} - * - * - * @final - */ -class Twig_TokenParser_Import extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $macro = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect('as'); - $var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine()); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - $this->parser->addImportedSymbol('template', $var->getAttribute('name')); - - return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'import'; - } -} - -class_alias('Twig_TokenParser_Import', 'Twig\TokenParser\ImportTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Include.php b/system/templateEngines/Twig/Twig1x/TokenParser/Include.php deleted file mode 100644 index 483f107..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Include.php +++ /dev/null @@ -1,65 +0,0 @@ - - * {% include 'header.html' %} - * Body - * {% include 'footer.html' %} - * - */ -class Twig_TokenParser_Include extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $expr = $this->parser->getExpressionParser()->parseExpression(); - - list($variables, $only, $ignoreMissing) = $this->parseArguments(); - - return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); - } - - protected function parseArguments() - { - $stream = $this->parser->getStream(); - - $ignoreMissing = false; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'ignore')) { - $stream->expect(Twig_Token::NAME_TYPE, 'missing'); - - $ignoreMissing = true; - } - - $variables = null; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'with')) { - $variables = $this->parser->getExpressionParser()->parseExpression(); - } - - $only = false; - if ($stream->nextIf(Twig_Token::NAME_TYPE, 'only')) { - $only = true; - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return [$variables, $only, $ignoreMissing]; - } - - public function getTag() - { - return 'include'; - } -} - -class_alias('Twig_TokenParser_Include', 'Twig\TokenParser\IncludeTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Macro.php b/system/templateEngines/Twig/Twig1x/TokenParser/Macro.php deleted file mode 100644 index fa55a7c..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Macro.php +++ /dev/null @@ -1,60 +0,0 @@ - - * {% macro input(name, value, type, size) %} - * - * {% endmacro %} - * - * - * @final - */ -class Twig_TokenParser_Macro extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $this->parser->pushLocalScope(); - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) { - $value = $token->getValue(); - - if ($value != $name) { - throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } - $this->parser->popLocalScope(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body([$body]), $arguments, $lineno, $this->getTag())); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endmacro'); - } - - public function getTag() - { - return 'macro'; - } -} - -class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Sandbox.php b/system/templateEngines/Twig/Twig1x/TokenParser/Sandbox.php deleted file mode 100644 index 5161458..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Sandbox.php +++ /dev/null @@ -1,61 +0,0 @@ - - * {% sandbox %} - * {% include 'user.html' %} - * {% endsandbox %} - * - * - * @see https://twig.symfony.com/doc/api.html#sandbox-extension for details - * - * @final - */ -class Twig_TokenParser_Sandbox extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - // in a sandbox tag, only include tags are allowed - if (!$body instanceof Twig_Node_Include) { - foreach ($body as $node) { - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { - continue; - } - - if (!$node instanceof Twig_Node_Include) { - throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); - } - } - } - - return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endsandbox'); - } - - public function getTag() - { - return 'sandbox'; - } -} - -class_alias('Twig_TokenParser_Sandbox', 'Twig\TokenParser\SandboxTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Set.php b/system/templateEngines/Twig/Twig1x/TokenParser/Set.php deleted file mode 100644 index a692947..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Set.php +++ /dev/null @@ -1,75 +0,0 @@ - - * {% set foo = 'foo' %} - * - * {% set foo = [1, 2] %} - * - * {% set foo = {'foo': 'bar'} %} - * - * {% set foo = 'foo' ~ 'bar' %} - * - * {% set foo, bar = 'foo', 'bar' %} - * - * {% set foo %}Some content{% endset %} - * - * - * @final - */ -class Twig_TokenParser_Set extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); - - $capture = false; - if ($stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) { - $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - if (count($names) !== count($values)) { - throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } else { - $capture = true; - - if (count($names) > 1) { - throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); - } - - return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endset'); - } - - public function getTag() - { - return 'set'; - } -} - -class_alias('Twig_TokenParser_Set', 'Twig\TokenParser\SetTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Spaceless.php b/system/templateEngines/Twig/Twig1x/TokenParser/Spaceless.php deleted file mode 100644 index 934717c..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Spaceless.php +++ /dev/null @@ -1,51 +0,0 @@ - - * {% spaceless %} - *
- * foo - *
- * {% endspaceless %} - * - * {# output will be
foo
#} - * - * - * @final - */ -class Twig_TokenParser_Spaceless extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Spaceless($body, $lineno, $this->getTag()); - } - - public function decideSpacelessEnd(Twig_Token $token) - { - return $token->test('endspaceless'); - } - - public function getTag() - { - return 'spaceless'; - } -} - -class_alias('Twig_TokenParser_Spaceless', 'Twig\TokenParser\SpacelessTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/Use.php b/system/templateEngines/Twig/Twig1x/TokenParser/Use.php deleted file mode 100644 index fc4471f..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/Use.php +++ /dev/null @@ -1,70 +0,0 @@ - - * {% extends "base.html" %} - * - * {% use "blocks.html" %} - * - * {% block title %}{% endblock %} - * {% block content %}{% endblock %} - * - * - * @see https://twig.symfony.com/doc/templates.html#horizontal-reuse for details. - * - * @final - */ -class Twig_TokenParser_Use extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $template = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - - if (!$template instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - - $targets = []; - if ($stream->nextIf('with')) { - do { - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - - $alias = $name; - if ($stream->nextIf('as')) { - $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - } - - $targets[$name] = new Twig_Node_Expression_Constant($alias, -1); - - if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { - break; - } - } while (true); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $this->parser->addTrait(new Twig_Node(['template' => $template, 'targets' => new Twig_Node($targets)])); - - return new Twig_Node(); - } - - public function getTag() - { - return 'use'; - } -} - -class_alias('Twig_TokenParser_Use', 'Twig\TokenParser\UseTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParser/With.php b/system/templateEngines/Twig/Twig1x/TokenParser/With.php deleted file mode 100644 index 34a0812..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParser/With.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * @final - */ -class Twig_TokenParser_With extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - - $variables = null; - $only = false; - if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) { - $variables = $this->parser->getExpressionParser()->parseExpression(); - $only = $stream->nextIf(Twig_Token::NAME_TYPE, 'only'); - } - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - $body = $this->parser->subparse([$this, 'decideWithEnd'], true); - - $stream->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_With($body, $variables, $only, $token->getLine(), $this->getTag()); - } - - public function decideWithEnd(Twig_Token $token) - { - return $token->test('endwith'); - } - - public function getTag() - { - return 'with'; - } -} - -class_alias('Twig_TokenParser_With', 'Twig\TokenParser\WithTokenParser', false); diff --git a/system/templateEngines/Twig/Twig1x/TokenParserBroker.php b/system/templateEngines/Twig/Twig1x/TokenParserBroker.php deleted file mode 100644 index c90a3c6..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParserBroker.php +++ /dev/null @@ -1,120 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface -{ - protected $parser; - protected $parsers = []; - protected $brokers = []; - - /** - * @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances - * @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances - * @param bool $triggerDeprecationError - */ - public function __construct($parsers = [], $brokers = [], $triggerDeprecationError = true) - { - if ($triggerDeprecationError) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); - } - - foreach ($parsers as $parser) { - if (!$parser instanceof Twig_TokenParserInterface) { - throw new LogicException('$parsers must a an array of Twig_TokenParserInterface.'); - } - $this->parsers[$parser->getTag()] = $parser; - } - foreach ($brokers as $broker) { - if (!$broker instanceof Twig_TokenParserBrokerInterface) { - throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface.'); - } - $this->brokers[] = $broker; - } - } - - public function addTokenParser(Twig_TokenParserInterface $parser) - { - $this->parsers[$parser->getTag()] = $parser; - } - - public function removeTokenParser(Twig_TokenParserInterface $parser) - { - $name = $parser->getTag(); - if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { - unset($this->parsers[$name]); - } - } - - public function addTokenParserBroker(self $broker) - { - $this->brokers[] = $broker; - } - - public function removeTokenParserBroker(self $broker) - { - if (false !== $pos = array_search($broker, $this->brokers)) { - unset($this->brokers[$pos]); - } - } - - /** - * Gets a suitable TokenParser for a tag. - * - * First looks in parsers, then in brokers. - * - * @param string $tag A tag name - * - * @return Twig_TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found - */ - public function getTokenParser($tag) - { - if (isset($this->parsers[$tag])) { - return $this->parsers[$tag]; - } - $broker = end($this->brokers); - while (false !== $broker) { - $parser = $broker->getTokenParser($tag); - if (null !== $parser) { - return $parser; - } - $broker = prev($this->brokers); - } - } - - public function getParsers() - { - return $this->parsers; - } - - public function getParser() - { - return $this->parser; - } - - public function setParser(Twig_ParserInterface $parser) - { - $this->parser = $parser; - foreach ($this->parsers as $tokenParser) { - $tokenParser->setParser($parser); - } - foreach ($this->brokers as $broker) { - $broker->setParser($parser); - } - } -} diff --git a/system/templateEngines/Twig/Twig1x/TokenParserBrokerInterface.php b/system/templateEngines/Twig/Twig1x/TokenParserBrokerInterface.php deleted file mode 100644 index c239c2e..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParserBrokerInterface.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_TokenParserBrokerInterface -{ - /** - * Gets a TokenParser suitable for a tag. - * - * @param string $tag A tag name - * - * @return Twig_TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found - */ - public function getTokenParser($tag); - - /** - * Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of. - */ - public function setParser(Twig_ParserInterface $parser); - - /** - * Gets the Twig_ParserInterface. - * - * @return Twig_ParserInterface|null A Twig_ParserInterface instance or null - */ - public function getParser(); -} diff --git a/system/templateEngines/Twig/Twig1x/TokenParserInterface.php b/system/templateEngines/Twig/Twig1x/TokenParserInterface.php deleted file mode 100644 index 14acc80..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenParserInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -interface Twig_TokenParserInterface -{ - /** - * Sets the parser associated with this token parser. - */ - public function setParser(Twig_Parser $parser); - - /** - * Parses a token and returns a node. - * - * @return Twig_NodeInterface - * - * @throws Twig_Error_Syntax - */ - public function parse(Twig_Token $token); - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag(); -} - -class_alias('Twig_TokenParserInterface', 'Twig\TokenParser\TokenParserInterface', false); -class_exists('Twig_Parser'); -class_exists('Twig_Token'); diff --git a/system/templateEngines/Twig/Twig1x/TokenStream.php b/system/templateEngines/Twig/Twig1x/TokenStream.php deleted file mode 100644 index 81c043c..0000000 --- a/system/templateEngines/Twig/Twig1x/TokenStream.php +++ /dev/null @@ -1,196 +0,0 @@ - - */ -class Twig_TokenStream -{ - protected $tokens; - protected $current = 0; - protected $filename; - - private $source; - - /** - * @param array $tokens An array of tokens - * @param string|null $name The name of the template which tokens are associated with - * @param string|null $source The source code associated with the tokens - */ - public function __construct(array $tokens, $name = null, $source = null) - { - if (!$name instanceof Twig_Source) { - if (null !== $name || null !== $source) { - @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - } - $this->source = new Twig_Source($source, $name); - } else { - $this->source = $name; - } - - $this->tokens = $tokens; - - // deprecated, not used anymore, to be removed in 2.0 - $this->filename = $this->source->getName(); - } - - public function __toString() - { - return implode("\n", $this->tokens); - } - - public function injectTokens(array $tokens) - { - $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current)); - } - - /** - * Sets the pointer to the next token and returns the old one. - * - * @return Twig_Token - */ - public function next() - { - if (!isset($this->tokens[++$this->current])) { - throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); - } - - return $this->tokens[$this->current - 1]; - } - - /** - * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. - * - * @return Twig_Token|null The next token if the condition is true, null otherwise - */ - public function nextIf($primary, $secondary = null) - { - if ($this->tokens[$this->current]->test($primary, $secondary)) { - return $this->next(); - } - } - - /** - * Tests a token and returns it or throws a syntax error. - * - * @return Twig_Token - */ - public function expect($type, $value = null, $message = null) - { - $token = $this->tokens[$this->current]; - if (!$token->test($type, $value)) { - $line = $token->getLine(); - throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', - $message ? $message.'. ' : '', - Twig_Token::typeToEnglish($token->getType()), $token->getValue(), - Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), - $line, - $this->source - ); - } - $this->next(); - - return $token; - } - - /** - * Looks at the next token. - * - * @param int $number - * - * @return Twig_Token - */ - public function look($number = 1) - { - if (!isset($this->tokens[$this->current + $number])) { - throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); - } - - return $this->tokens[$this->current + $number]; - } - - /** - * Tests the current token. - * - * @return bool - */ - public function test($primary, $secondary = null) - { - return $this->tokens[$this->current]->test($primary, $secondary); - } - - /** - * Checks if end of stream was reached. - * - * @return bool - */ - public function isEOF() - { - return Twig_Token::EOF_TYPE === $this->tokens[$this->current]->getType(); - } - - /** - * @return Twig_Token - */ - public function getCurrent() - { - return $this->tokens[$this->current]; - } - - /** - * Gets the name associated with this stream (null if not defined). - * - * @return string|null - * - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function getFilename() - { - @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); - - return $this->source->getName(); - } - - /** - * Gets the source code associated with this stream. - * - * @return string - * - * @internal Don't use this as it might be empty depending on the environment configuration - * - * @deprecated since 1.27 (to be removed in 2.0) - */ - public function getSource() - { - @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); - - return $this->source->getCode(); - } - - /** - * Gets the source associated with this stream. - * - * @return Twig_Source - * - * @internal - */ - public function getSourceContext() - { - return $this->source; - } -} - -class_alias('Twig_TokenStream', 'Twig\TokenStream', false); diff --git a/system/templateEngines/Twig/Twig1x/Util/DeprecationCollector.php b/system/templateEngines/Twig/Twig1x/Util/DeprecationCollector.php deleted file mode 100644 index b6cccf2..0000000 --- a/system/templateEngines/Twig/Twig1x/Util/DeprecationCollector.php +++ /dev/null @@ -1,86 +0,0 @@ - - * - * @final - */ -class Twig_Util_DeprecationCollector -{ - private $twig; - private $deprecations; - - public function __construct(Twig_Environment $twig) - { - $this->twig = $twig; - } - - /** - * Returns deprecations for templates contained in a directory. - * - * @param string $dir A directory where templates are stored - * @param string $ext Limit the loaded templates by extension - * - * @return array An array of deprecations - */ - public function collectDir($dir, $ext = '.twig') - { - $iterator = new RegexIterator( - new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY - ), '{'.preg_quote($ext).'$}' - ); - - return $this->collect(new Twig_Util_TemplateDirIterator($iterator)); - } - - /** - * Returns deprecations for passed templates. - * - * @param Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) - * - * @return array An array of deprecations - */ - public function collect(Traversable $iterator) - { - $this->deprecations = []; - - set_error_handler([$this, 'errorHandler']); - - foreach ($iterator as $name => $contents) { - try { - $this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name))); - } catch (Twig_Error_Syntax $e) { - // ignore templates containing syntax errors - } - } - - restore_error_handler(); - - $deprecations = $this->deprecations; - $this->deprecations = []; - - return $deprecations; - } - - /** - * @internal - */ - public function errorHandler($type, $msg) - { - if (E_USER_DEPRECATED === $type) { - $this->deprecations[] = $msg; - } - } -} - -class_alias('Twig_Util_DeprecationCollector', 'Twig\Util\DeprecationCollector', false); diff --git a/system/templateEngines/Twig/Twig1x/Util/TemplateDirIterator.php b/system/templateEngines/Twig/Twig1x/Util/TemplateDirIterator.php deleted file mode 100644 index c868233..0000000 --- a/system/templateEngines/Twig/Twig1x/Util/TemplateDirIterator.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ -class Twig_Util_TemplateDirIterator extends IteratorIterator -{ - public function current() - { - return file_get_contents(parent::current()); - } - - public function key() - { - return (string) parent::key(); - } -} - -class_alias('Twig_Util_TemplateDirIterator', 'Twig\Util\TemplateDirIterator', false); diff --git a/system/templateEngines/Twig/Twig1x/autoload.php b/system/templateEngines/Twig/Twig1x/autoload.php new file mode 100644 index 0000000..3f98022 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/system/templateEngines/Twig/Twig1x/composer/LICENSE b/system/templateEngines/Twig/Twig1x/composer/LICENSE new file mode 100644 index 0000000..f27399a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/system/templateEngines/Twig/Twig1x/composer/autoload_classmap.php b/system/templateEngines/Twig/Twig1x/composer/autoload_classmap.php new file mode 100644 index 0000000..7a91153 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', +); diff --git a/system/templateEngines/Twig/Twig1x/composer/autoload_namespaces.php b/system/templateEngines/Twig/Twig1x/composer/autoload_namespaces.php new file mode 100644 index 0000000..a7edd32 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/autoload_namespaces.php @@ -0,0 +1,10 @@ + array($vendorDir . '/twig/twig/lib'), +); diff --git a/system/templateEngines/Twig/Twig1x/composer/autoload_psr4.php b/system/templateEngines/Twig/Twig1x/composer/autoload_psr4.php new file mode 100644 index 0000000..adead07 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/autoload_psr4.php @@ -0,0 +1,11 @@ + array($vendorDir . '/twig/twig/src'), + 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), +); diff --git a/system/templateEngines/Twig/Twig1x/composer/autoload_real.php b/system/templateEngines/Twig/Twig1x/composer/autoload_real.php new file mode 100644 index 0000000..0b0ecc3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/autoload_real.php @@ -0,0 +1,70 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit09a276ab747dde32eaeb090fed801b7d::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + if ($useStaticLoader) { + $includeFiles = Composer\Autoload\ComposerStaticInit09a276ab747dde32eaeb090fed801b7d::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } + foreach ($includeFiles as $fileIdentifier => $file) { + composerRequire09a276ab747dde32eaeb090fed801b7d($fileIdentifier, $file); + } + + return $loader; + } +} + +function composerRequire09a276ab747dde32eaeb090fed801b7d($fileIdentifier, $file) +{ + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { + require $file; + + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + } +} diff --git a/system/templateEngines/Twig/Twig1x/composer/autoload_static.php b/system/templateEngines/Twig/Twig1x/composer/autoload_static.php new file mode 100644 index 0000000..e84611e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/autoload_static.php @@ -0,0 +1,54 @@ + __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', + ); + + public static $prefixLengthsPsr4 = array ( + 'T' => + array ( + 'Twig\\' => 5, + ), + 'S' => + array ( + 'Symfony\\Polyfill\\Ctype\\' => 23, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Twig\\' => + array ( + 0 => __DIR__ . '/..' . '/twig/twig/src', + ), + 'Symfony\\Polyfill\\Ctype\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', + ), + ); + + public static $prefixesPsr0 = array ( + 'T' => + array ( + 'Twig_' => + array ( + 0 => __DIR__ . '/..' . '/twig/twig/lib', + ), + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit09a276ab747dde32eaeb090fed801b7d::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit09a276ab747dde32eaeb090fed801b7d::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInit09a276ab747dde32eaeb090fed801b7d::$prefixesPsr0; + + }, null, ClassLoader::class); + } +} diff --git a/system/templateEngines/Twig/Twig1x/composer/installed.json b/system/templateEngines/Twig/Twig1x/composer/installed.json new file mode 100644 index 0000000..cadff09 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/composer/installed.json @@ -0,0 +1,128 @@ +[ + { + "name": "symfony/polyfill-ctype", + "version": "v1.14.0", + "version_normalized": "1.14.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "time": "2020-01-13T11:15:53+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ] + }, + { + "name": "twig/twig", + "version": "v1.42.5", + "version_normalized": "1.42.5.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "87b2ea9d8f6fd014d0621ca089bb1b3769ea3f8e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/87b2ea9d8f6fd014d0621ca089bb1b3769ea3f8e", + "reference": "87b2ea9d8f6fd014d0621ca089bb1b3769ea3f8e", + "shasum": "" + }, + "require": { + "php": ">=5.5.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/phpunit-bridge": "^4.4|^5.0" + }, + "time": "2020-02-11T05:59:23+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.42-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Twig_": "lib/" + }, + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ] + } +] diff --git a/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/Ctype.php b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/Ctype.php new file mode 100644 index 0000000..58414dc --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/Ctype.php @@ -0,0 +1,227 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Ctype; + +/** + * Ctype implementation through regex. + * + * @internal + * + * @author Gert de Pagter + */ +final class Ctype +{ + /** + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. + * + * @see https://php.net/ctype-alnum + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alnum($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is a letter, FALSE otherwise. + * + * @see https://php.net/ctype-alpha + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alpha($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); + } + + /** + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. + * + * @see https://php.net/ctype-cntrl + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_cntrl($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); + } + + /** + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. + * + * @see https://php.net/ctype-digit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_digit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. + * + * @see https://php.net/ctype-graph + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_graph($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); + } + + /** + * Returns TRUE if every character in text is a lowercase letter. + * + * @see https://php.net/ctype-lower + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_lower($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-print + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_print($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); + } + + /** + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. + * + * @see https://php.net/ctype-punct + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_punct($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-space + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_space($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); + } + + /** + * Returns TRUE if every character in text is an uppercase letter. + * + * @see https://php.net/ctype-upper + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_upper($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-xdigit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_xdigit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); + } + + /** + * Converts integers to their char versions according to normal ctype behaviour, if needed. + * + * If an integer between -128 and 255 inclusive is provided, + * it is interpreted as the ASCII value of a single character + * (negative values have 256 added in order to allow characters in the Extended ASCII range). + * Any other integer is interpreted as a string containing the decimal digits of the integer. + * + * @param string|int $int + * + * @return mixed + */ + private static function convert_int_to_char_for_ctype($int) + { + if (!\is_int($int)) { + return $int; + } + + if ($int < -128 || $int > 255) { + return (string) $int; + } + + if ($int < 0) { + $int += 256; + } + + return \chr($int); + } +} diff --git a/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/LICENSE b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/LICENSE new file mode 100644 index 0000000..3f853aa --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/README.md b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/README.md new file mode 100644 index 0000000..8add1ab --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/README.md @@ -0,0 +1,12 @@ +Symfony Polyfill / Ctype +======================== + +This component provides `ctype_*` functions to users who run php versions without the ctype extension. + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/bootstrap.php b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/bootstrap.php new file mode 100644 index 0000000..14d1d0f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/bootstrap.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (!function_exists('ctype_alnum')) { + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } + function ctype_print($text) { return p\Ctype::ctype_print($text); } + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } + function ctype_space($text) { return p\Ctype::ctype_space($text); } + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } +} diff --git a/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/composer.json b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/composer.json new file mode 100644 index 0000000..2596c74 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/symfony/polyfill-ctype/composer.json @@ -0,0 +1,34 @@ +{ + "name": "symfony/polyfill-ctype", + "type": "library", + "description": "Symfony polyfill for ctype functions", + "keywords": ["polyfill", "compatibility", "portable", "ctype"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.3" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Ctype\\": "" }, + "files": [ "bootstrap.php" ] + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/.editorconfig b/system/templateEngines/Twig/Twig1x/twig/twig/.editorconfig new file mode 100644 index 0000000..270f1d1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/.editorconfig @@ -0,0 +1,18 @@ +; top-most EditorConfig file +root = true + +; Unix-style newlines +[*] +end_of_line = LF + +[*.php] +indent_style = space +indent_size = 4 + +[*.test] +indent_style = space +indent_size = 4 + +[*.rst] +indent_style = space +indent_size = 4 diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/.gitattributes b/system/templateEngines/Twig/Twig1x/twig/twig/.gitattributes new file mode 100644 index 0000000..3a3ce6e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/.gitattributes @@ -0,0 +1,2 @@ +/tests export-ignore +/phpunit.xml.dist export-ignore diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/.gitignore b/system/templateEngines/Twig/Twig1x/twig/twig/.gitignore new file mode 100644 index 0000000..8a29959 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/.gitignore @@ -0,0 +1,6 @@ +/build +/composer.lock +/ext/twig/autom4te.cache/ +/phpunit.xml +/vendor +.phpunit.result.cache diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/.php_cs.dist b/system/templateEngines/Twig/Twig1x/twig/twig/.php_cs.dist new file mode 100644 index 0000000..b81882f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/.php_cs.dist @@ -0,0 +1,20 @@ +setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + '@PHPUnit75Migration:risky' => true, + 'php_unit_dedicate_assert' => ['target' => '5.6'], + 'array_syntax' => ['syntax' => 'short'], + 'php_unit_fqcn_annotation' => true, + 'no_unreachable_default_argument_value' => false, + 'braces' => ['allow_single_line_closure' => true], + 'heredoc_to_nowdoc' => false, + 'ordered_imports' => true, + 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'], + ]) + ->setRiskyAllowed(true) + ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)) +; diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/.travis.yml b/system/templateEngines/Twig/Twig1x/twig/twig/.travis.yml new file mode 100644 index 0000000..ff6132b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/.travis.yml @@ -0,0 +1,46 @@ +language: php + +dist: trusty + +sudo: false + +cache: + directories: + - vendor + - $HOME/.composer/cache/files + + +env: + global: + - TWIG_EXT=no + - SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 + +before_install: + - phpenv config-rm xdebug.ini || return 0 + +install: + - travis_retry composer install + +before_script: + - if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi + - if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi + +script: ./vendor/bin/simple-phpunit + +jobs: + fast_finish: true + include: + - php: 5.5 + - php: 5.5 + env: TWIG_EXT=yes + - php: 5.6 + - php: 5.6 + env: TWIG_EXT=yes + - php: 7.0 + - php: 7.1 + - php: 7.2 + - php: 7.3 + - php: 7.4snapshot + - stage: integration tests + php: 7.3 + script: ./drupal_test.sh diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/LICENSE b/system/templateEngines/Twig/Twig1x/twig/twig/LICENSE new file mode 100644 index 0000000..5e8a0b8 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/LICENSE @@ -0,0 +1,29 @@ +Copyright (c) 2009-2020 by the Twig Team. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/README.rst b/system/templateEngines/Twig/Twig1x/twig/twig/README.rst new file mode 100644 index 0000000..d896ff5 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/README.rst @@ -0,0 +1,24 @@ +Twig, the flexible, fast, and secure template language for PHP +============================================================== + +Twig is a template language for PHP, released under the new BSD license (code +and documentation). + +Twig uses a syntax similar to the Django and Jinja template languages which +inspired the Twig runtime environment. + +Sponsors +-------- + +.. raw:: html + + + Blackfire.io + + +More Information +---------------- + +Read the `documentation`_ for more information. + +.. _documentation: https://twig.symfony.com/documentation diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Autoloader.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Autoloader.php new file mode 100644 index 0000000..e34e214 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Autoloader.php @@ -0,0 +1,52 @@ + + * + * @deprecated since 1.21 and will be removed in 2.0. Use Composer instead. 2.0. + */ +class Twig_Autoloader +{ + /** + * Registers Twig_Autoloader as an SPL autoloader. + * + * @param bool $prepend whether to prepend the autoloader or not + */ + public static function register($prepend = false) + { + @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED); + + spl_autoload_register([__CLASS__, 'autoload'], true, $prepend); + } + + /** + * Handles autoloading of classes. + * + * @param string $class a class name + */ + public static function autoload($class) + { + if (0 !== strpos($class, 'Twig')) { + return; + } + + if (is_file($file = __DIR__.'/../'.str_replace(['_', "\0"], ['/', ''], $class).'.php')) { + require $file; + } elseif (is_file($file = __DIR__.'/../../src/'.str_replace(['Twig\\', '\\', "\0"], ['', '/', ''], $class).'.php')) { + require $file; + } + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/BaseNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/BaseNodeVisitor.php new file mode 100644 index 0000000..fe99b25 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/BaseNodeVisitor.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface +{ + protected $options; + protected $arguments = []; + + public function __construct(array $options = []) + { + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'pre_escape' => null, + 'preserves_safety' => null, + 'callable' => null, + ], $options); + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Node $filterArgs) + { + if (isset($this->options['is_safe'])) { + return $this->options['is_safe']; + } + + if (isset($this->options['is_safe_callback'])) { + return \call_user_func($this->options['is_safe_callback'], $filterArgs); + } + } + + public function getPreservesSafety() + { + return $this->options['preserves_safety']; + } + + public function getPreEscape() + { + return $this->options['pre_escape']; + } + + public function getCallable() + { + return $this->options['callable']; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Function.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Function.php new file mode 100644 index 0000000..011d4cc --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Function.php @@ -0,0 +1,40 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Filter_Function extends Twig_Filter +{ + protected $function; + + public function __construct($function, array $options = []) + { + $options['callable'] = $function; + + parent::__construct($options); + + $this->function = $function; + } + + public function compile() + { + return $this->function; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Method.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Method.php new file mode 100644 index 0000000..5cd0628 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Method.php @@ -0,0 +1,44 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Filter_Method extends Twig_Filter +{ + protected $extension; + protected $method; + + public function __construct(ExtensionInterface $extension, $method, array $options = []) + { + $options['callable'] = [$extension, $method]; + + parent::__construct($options); + + $this->extension = $extension; + $this->method = $method; + } + + public function compile() + { + return sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($this->extension), $this->method); + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Node.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Node.php new file mode 100644 index 0000000..8bb2899 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Filter/Node.php @@ -0,0 +1,42 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Filter_Node extends Twig_Filter +{ + protected $class; + + public function __construct($class, array $options = []) + { + parent::__construct($options); + + $this->class = $class; + } + + public function getClass() + { + return $this->class; + } + + public function compile() + { + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterCallableInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterCallableInterface.php new file mode 100644 index 0000000..091ca97 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterCallableInterface.php @@ -0,0 +1,24 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_FilterCallableInterface +{ + public function getCallable(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterInterface.php new file mode 100644 index 0000000..9b85f97 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FilterInterface.php @@ -0,0 +1,45 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_FilterInterface +{ + /** + * Compiles a filter. + * + * @return string The PHP code for the filter + */ + public function compile(); + + public function needsEnvironment(); + + public function needsContext(); + + public function getSafe(Node $filterArgs); + + public function getPreservesSafety(); + + public function getPreEscape(); + + public function setArguments($arguments); + + public function getArguments(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function.php new file mode 100644 index 0000000..6646e74 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function.php @@ -0,0 +1,76 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface +{ + protected $options; + protected $arguments = []; + + public function __construct(array $options = []) + { + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'callable' => null, + ], $options); + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Node $functionArgs) + { + if (isset($this->options['is_safe'])) { + return $this->options['is_safe']; + } + + if (isset($this->options['is_safe_callback'])) { + return \call_user_func($this->options['is_safe_callback'], $functionArgs); + } + + return []; + } + + public function getCallable() + { + return $this->options['callable']; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Function.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Function.php new file mode 100644 index 0000000..605d8d3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Function.php @@ -0,0 +1,41 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Function_Function extends Twig_Function +{ + protected $function; + + public function __construct($function, array $options = []) + { + $options['callable'] = $function; + + parent::__construct($options); + + $this->function = $function; + } + + public function compile() + { + return $this->function; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Method.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Method.php new file mode 100644 index 0000000..9e472c5 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Method.php @@ -0,0 +1,45 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Function_Method extends Twig_Function +{ + protected $extension; + protected $method; + + public function __construct(ExtensionInterface $extension, $method, array $options = []) + { + $options['callable'] = [$extension, $method]; + + parent::__construct($options); + + $this->extension = $extension; + $this->method = $method; + } + + public function compile() + { + return sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($this->extension), $this->method); + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Node.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Node.php new file mode 100644 index 0000000..8148ec3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Function/Node.php @@ -0,0 +1,42 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Function_Node extends Twig_Function +{ + protected $class; + + public function __construct($class, array $options = []) + { + parent::__construct($options); + + $this->class = $class; + } + + public function getClass() + { + return $this->class; + } + + public function compile() + { + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionCallableInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionCallableInterface.php new file mode 100644 index 0000000..abc83ea --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionCallableInterface.php @@ -0,0 +1,24 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_FunctionCallableInterface +{ + public function getCallable(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionInterface.php new file mode 100644 index 0000000..915d6cc --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/FunctionInterface.php @@ -0,0 +1,42 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_FunctionInterface +{ + /** + * Compiles a function. + * + * @return string The PHP code for the function + */ + public function compile(); + + public function needsEnvironment(); + + public function needsContext(); + + public function getSafe(Node $filterArgs); + + public function setArguments($arguments); + + public function getArguments(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Lexer.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Lexer.php new file mode 100644 index 0000000..00d74cc --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Lexer.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_LexerInterface +{ + /** + * Tokenizes a source code. + * + * @param string|Source $code The source code + * @param string $name A unique identifier for the source code + * + * @return TokenStream + * + * @throws SyntaxError When the code is syntactically wrong + */ + public function tokenize($code, $name = null); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/Array.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/Array.php new file mode 100644 index 0000000..13f915c --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Loader/Array.php @@ -0,0 +1,11 @@ + + */ +class Twig_Loader_String implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + public function getSource($name) + { + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); + + return $name; + } + + public function getSourceContext($name) + { + return new Source($name, $name); + } + + public function exists($name) + { + return true; + } + + public function getCacheKey($name) + { + return $name; + } + + public function isFresh($name, $time) + { + return true; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/LoaderInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/LoaderInterface.php new file mode 100644 index 0000000..db515bb --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/LoaderInterface.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.23 and will be removed in 2.0. + */ +class Twig_Node_Expression_ExtensionReference extends AbstractExpression +{ + public function __construct($name, $lineno, $tag = null) + { + parent::__construct([], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Filter.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Filter.php new file mode 100644 index 0000000..8570571 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Node/Expression/Filter.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_NodeInterface extends \Countable, \IteratorAggregate +{ + /** + * Compiles the node to PHP. + */ + public function compile(Compiler $compiler); + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getLine(); + + public function getNodeTag(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeOutputInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeOutputInterface.php new file mode 100644 index 0000000..54009c0 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/NodeOutputInterface.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_ParserInterface +{ + /** + * Converts a token stream to a node tree. + * + * @return ModuleNode + * + * @throws SyntaxError When the token stream is syntactically or semantically wrong + */ + public function parse(TokenStream $stream); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Base.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Base.php new file mode 100644 index 0000000..5bcb1ba --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Profiler/Dumper/Base.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_TemplateInterface +{ + const ANY_CALL = 'any'; + const ARRAY_CALL = 'array'; + const METHOD_CALL = 'method'; + + /** + * Renders the template with the given context and returns it as string. + * + * @param array $context An array of parameters to pass to the template + * + * @return string The rendered template + */ + public function render(array $context); + + /** + * Displays the template with the given context. + * + * @param array $context An array of parameters to pass to the template + * @param array $blocks An array of blocks to pass to the template + */ + public function display(array $context, array $blocks = []); + + /** + * Returns the bound environment for this template. + * + * @return Environment + */ + public function getEnvironment(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TemplateWrapper.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TemplateWrapper.php new file mode 100644 index 0000000..6cb4ce4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TemplateWrapper.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +abstract class Twig_Test implements Twig_TestInterface, Twig_TestCallableInterface +{ + protected $options; + protected $arguments = []; + + public function __construct(array $options = []) + { + $this->options = array_merge([ + 'callable' => null, + ], $options); + } + + public function getCallable() + { + return $this->options['callable']; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Function.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Function.php new file mode 100644 index 0000000..a789c40 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Function.php @@ -0,0 +1,38 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Test_Function extends Twig_Test +{ + protected $function; + + public function __construct($function, array $options = []) + { + $options['callable'] = $function; + + parent::__construct($options); + + $this->function = $function; + } + + public function compile() + { + return $this->function; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/IntegrationTestCase.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/IntegrationTestCase.php new file mode 100644 index 0000000..e302bdb --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/IntegrationTestCase.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Test_Method extends Twig_Test +{ + protected $extension; + protected $method; + + public function __construct(ExtensionInterface $extension, $method, array $options = []) + { + $options['callable'] = [$extension, $method]; + + parent::__construct($options); + + $this->extension = $extension; + $this->method = $method; + } + + public function compile() + { + return sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($this->extension), $this->method); + } +} diff --git a/system/templateEngines/Twig/Twig1x/Test/Node.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Node.php similarity index 100% rename from system/templateEngines/Twig/Twig1x/Test/Node.php rename to system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/Node.php diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/NodeTestCase.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/NodeTestCase.php new file mode 100644 index 0000000..62aaaaf --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/Test/NodeTestCase.php @@ -0,0 +1,11 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface +{ + protected $parser; + protected $parsers = []; + protected $brokers = []; + + /** + * @param array|\Traversable $parsers A \Traversable of Twig_TokenParserInterface instances + * @param array|\Traversable $brokers A \Traversable of Twig_TokenParserBrokerInterface instances + * @param bool $triggerDeprecationError + */ + public function __construct($parsers = [], $brokers = [], $triggerDeprecationError = true) + { + if ($triggerDeprecationError) { + @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); + } + + foreach ($parsers as $parser) { + if (!$parser instanceof TokenParserInterface) { + throw new \LogicException('$parsers must a an array of Twig_TokenParserInterface.'); + } + $this->parsers[$parser->getTag()] = $parser; + } + foreach ($brokers as $broker) { + if (!$broker instanceof Twig_TokenParserBrokerInterface) { + throw new \LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface.'); + } + $this->brokers[] = $broker; + } + } + + public function addTokenParser(TokenParserInterface $parser) + { + $this->parsers[$parser->getTag()] = $parser; + } + + public function removeTokenParser(TokenParserInterface $parser) + { + $name = $parser->getTag(); + if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { + unset($this->parsers[$name]); + } + } + + public function addTokenParserBroker(self $broker) + { + $this->brokers[] = $broker; + } + + public function removeTokenParserBroker(self $broker) + { + if (false !== $pos = array_search($broker, $this->brokers)) { + unset($this->brokers[$pos]); + } + } + + /** + * Gets a suitable TokenParser for a tag. + * + * First looks in parsers, then in brokers. + * + * @param string $tag A tag name + * + * @return TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found + */ + public function getTokenParser($tag) + { + if (isset($this->parsers[$tag])) { + return $this->parsers[$tag]; + } + $broker = end($this->brokers); + while (false !== $broker) { + $parser = $broker->getTokenParser($tag); + if (null !== $parser) { + return $parser; + } + $broker = prev($this->brokers); + } + } + + public function getParsers() + { + return $this->parsers; + } + + public function getParser() + { + return $this->parser; + } + + public function setParser(Twig_ParserInterface $parser) + { + $this->parser = $parser; + foreach ($this->parsers as $tokenParser) { + $tokenParser->setParser($parser); + } + foreach ($this->brokers as $broker) { + $broker->setParser($parser); + } + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserBrokerInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserBrokerInterface.php new file mode 100644 index 0000000..f369264 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserBrokerInterface.php @@ -0,0 +1,46 @@ + + * + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_TokenParserBrokerInterface +{ + /** + * Gets a TokenParser suitable for a tag. + * + * @param string $tag A tag name + * + * @return TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found + */ + public function getTokenParser($tag); + + /** + * Calls Twig\TokenParser\TokenParserInterface::setParser on all parsers the implementation knows of. + */ + public function setParser(Twig_ParserInterface $parser); + + /** + * Gets the Twig_ParserInterface. + * + * @return Twig_ParserInterface|null A Twig_ParserInterface instance or null + */ + public function getParser(); +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserInterface.php new file mode 100644 index 0000000..800c971 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/lib/Twig/TokenParserInterface.php @@ -0,0 +1,11 @@ + + */ +interface CacheInterface +{ + /** + * Generates a cache key for the given template class name. + * + * @param string $name The template name + * @param string $className The template class name + * + * @return string + */ + public function generateKey($name, $className); + + /** + * Writes the compiled template to cache. + * + * @param string $key The cache key + * @param string $content The template representation as a PHP class + */ + public function write($key, $content); + + /** + * Loads a template from the cache. + * + * @param string $key The cache key + */ + public function load($key); + + /** + * Returns the modification timestamp of a key. + * + * @param string $key The cache key + * + * @return int + */ + public function getTimestamp($key); +} + +class_alias('Twig\Cache\CacheInterface', 'Twig_CacheInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/FilesystemCache.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/FilesystemCache.php new file mode 100644 index 0000000..b7c1e43 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/FilesystemCache.php @@ -0,0 +1,93 @@ + + */ +class FilesystemCache implements CacheInterface +{ + const FORCE_BYTECODE_INVALIDATION = 1; + + private $directory; + private $options; + + /** + * @param string $directory The root cache directory + * @param int $options A set of options + */ + public function __construct($directory, $options = 0) + { + $this->directory = rtrim($directory, '\/').'/'; + $this->options = $options; + } + + public function generateKey($name, $className) + { + $hash = hash('sha256', $className); + + return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; + } + + public function load($key) + { + if (file_exists($key)) { + @include_once $key; + } + } + + public function write($key, $content) + { + $dir = \dirname($key); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true)) { + clearstatcache(true, $dir); + if (!is_dir($dir)) { + throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); + } + } + } elseif (!is_writable($dir)) { + throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); + } + + $tmpFile = tempnam($dir, basename($key)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { + @chmod($key, 0666 & ~umask()); + + if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { + // Compile cached file into bytecode cache + if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { + @opcache_invalidate($key, true); + } elseif (\function_exists('apc_compile_file')) { + apc_compile_file($key); + } + } + + return; + } + + throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $key)); + } + + public function getTimestamp($key) + { + if (!file_exists($key)) { + return 0; + } + + return (int) @filemtime($key); + } +} + +class_alias('Twig\Cache\FilesystemCache', 'Twig_Cache_Filesystem'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/NullCache.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/NullCache.php new file mode 100644 index 0000000..c1b37c1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Cache/NullCache.php @@ -0,0 +1,42 @@ + + */ +class NullCache implements CacheInterface +{ + public function generateKey($name, $className) + { + return ''; + } + + public function write($key, $content) + { + } + + public function load($key) + { + } + + public function getTimestamp($key) + { + return 0; + } +} + +class_alias('Twig\Cache\NullCache', 'Twig_Cache_Null'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Compiler.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Compiler.php new file mode 100644 index 0000000..e47003a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Compiler.php @@ -0,0 +1,288 @@ + + */ +class Compiler implements \Twig_CompilerInterface +{ + protected $lastLine; + protected $source; + protected $indentation; + protected $env; + protected $debugInfo = []; + protected $sourceOffset; + protected $sourceLine; + protected $filename; + private $varNameSalt = 0; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + /** + * @deprecated since 1.25 (to be removed in 2.0) + */ + public function getFilename() + { + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + + return $this->filename; + } + + /** + * Returns the environment instance related to this compiler. + * + * @return Environment + */ + public function getEnvironment() + { + return $this->env; + } + + /** + * Gets the current PHP code after compilation. + * + * @return string The PHP code + */ + public function getSource() + { + return $this->source; + } + + /** + * Compiles a node. + * + * @param int $indentation The current indentation + * + * @return $this + */ + public function compile(\Twig_NodeInterface $node, $indentation = 0) + { + $this->lastLine = null; + $this->source = ''; + $this->debugInfo = []; + $this->sourceOffset = 0; + // source code starts at 1 (as we then increment it when we encounter new lines) + $this->sourceLine = 1; + $this->indentation = $indentation; + $this->varNameSalt = 0; + + if ($node instanceof ModuleNode) { + // to be removed in 2.0 + $this->filename = $node->getTemplateName(); + } + + $node->compile($this); + + return $this; + } + + public function subcompile(\Twig_NodeInterface $node, $raw = true) + { + if (false === $raw) { + $this->source .= str_repeat(' ', $this->indentation * 4); + } + + $node->compile($this); + + return $this; + } + + /** + * Adds a raw string to the compiled code. + * + * @param string $string The string + * + * @return $this + */ + public function raw($string) + { + $this->source .= $string; + + return $this; + } + + /** + * Writes a string to the compiled code by adding indentation. + * + * @return $this + */ + public function write() + { + $strings = \func_get_args(); + foreach ($strings as $string) { + $this->source .= str_repeat(' ', $this->indentation * 4).$string; + } + + return $this; + } + + /** + * Appends an indentation to the current PHP code after compilation. + * + * @return $this + * + * @deprecated since 1.27 (to be removed in 2.0). + */ + public function addIndentation() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED); + + $this->source .= str_repeat(' ', $this->indentation * 4); + + return $this; + } + + /** + * Adds a quoted string to the compiled code. + * + * @param string $value The string + * + * @return $this + */ + public function string($value) + { + $this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\")); + + return $this; + } + + /** + * Returns a PHP representation of a given value. + * + * @param mixed $value The value to convert + * + * @return $this + */ + public function repr($value) + { + if (\is_int($value) || \is_float($value)) { + if (false !== $locale = setlocale(LC_NUMERIC, '0')) { + setlocale(LC_NUMERIC, 'C'); + } + + $this->raw(var_export($value, true)); + + if (false !== $locale) { + setlocale(LC_NUMERIC, $locale); + } + } elseif (null === $value) { + $this->raw('null'); + } elseif (\is_bool($value)) { + $this->raw($value ? 'true' : 'false'); + } elseif (\is_array($value)) { + $this->raw('['); + $first = true; + foreach ($value as $key => $v) { + if (!$first) { + $this->raw(', '); + } + $first = false; + $this->repr($key); + $this->raw(' => '); + $this->repr($v); + } + $this->raw(']'); + } else { + $this->string($value); + } + + return $this; + } + + /** + * Adds debugging information. + * + * @return $this + */ + public function addDebugInfo(\Twig_NodeInterface $node) + { + if ($node->getTemplateLine() != $this->lastLine) { + $this->write(sprintf("// line %d\n", $node->getTemplateLine())); + + // when mbstring.func_overload is set to 2 + // mb_substr_count() replaces substr_count() + // but they have different signatures! + if (((int) ini_get('mbstring.func_overload')) & 2) { + @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); + + // this is much slower than the "right" version + $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); + } else { + $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); + } + $this->sourceOffset = \strlen($this->source); + $this->debugInfo[$this->sourceLine] = $node->getTemplateLine(); + + $this->lastLine = $node->getTemplateLine(); + } + + return $this; + } + + public function getDebugInfo() + { + ksort($this->debugInfo); + + return $this->debugInfo; + } + + /** + * Indents the generated code. + * + * @param int $step The number of indentation to add + * + * @return $this + */ + public function indent($step = 1) + { + $this->indentation += $step; + + return $this; + } + + /** + * Outdents the generated code. + * + * @param int $step The number of indentation to remove + * + * @return $this + * + * @throws \LogicException When trying to outdent too much so the indentation would become negative + */ + public function outdent($step = 1) + { + // can't outdent by more steps than the current indentation level + if ($this->indentation < $step) { + throw new \LogicException('Unable to call outdent() as the indentation would become negative.'); + } + + $this->indentation -= $step; + + return $this; + } + + public function getVarName() + { + return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++)); + } +} + +class_alias('Twig\Compiler', 'Twig_Compiler'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Environment.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Environment.php new file mode 100644 index 0000000..97fa4c4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Environment.php @@ -0,0 +1,1638 @@ + + */ +class Environment +{ + const VERSION = '1.42.5'; + const VERSION_ID = 14205; + const MAJOR_VERSION = 1; + const MINOR_VERSION = 42; + const RELEASE_VERSION = 5; + const EXTRA_VERSION = ''; + + protected $charset; + protected $loader; + protected $debug; + protected $autoReload; + protected $cache; + protected $lexer; + protected $parser; + protected $compiler; + protected $baseTemplateClass; + protected $extensions; + protected $parsers; + protected $visitors; + protected $filters; + protected $tests; + protected $functions; + protected $globals; + protected $runtimeInitialized = false; + protected $extensionInitialized = false; + protected $loadedTemplates; + protected $strictVariables; + protected $unaryOperators; + protected $binaryOperators; + protected $templateClassPrefix = '__TwigTemplate_'; + protected $functionCallbacks = []; + protected $filterCallbacks = []; + protected $staging; + + private $originalCache; + private $bcWriteCacheFile = false; + private $bcGetCacheFilename = false; + private $lastModifiedExtension = 0; + private $extensionsByClass = []; + private $runtimeLoaders = []; + private $runtimes = []; + private $optionsHash; + + /** + * Constructor. + * + * Available options: + * + * * debug: When set to true, it automatically set "auto_reload" to true as + * well (default to false). + * + * * charset: The charset used by the templates (default to UTF-8). + * + * * base_template_class: The base template class to use for generated + * templates (default to \Twig\Template). + * + * * cache: An absolute path where to store the compiled templates, + * a \Twig\Cache\CacheInterface implementation, + * or false to disable compilation cache (default). + * + * * auto_reload: Whether to reload the template if the original source changed. + * If you don't provide the auto_reload option, it will be + * determined automatically based on the debug value. + * + * * strict_variables: Whether to ignore invalid variables in templates + * (default to false). + * + * * autoescape: Whether to enable auto-escaping (default to html): + * * false: disable auto-escaping + * * true: equivalent to html + * * html, js: set the autoescaping to one of the supported strategies + * * name: set the autoescaping strategy based on the template name extension + * * PHP callback: a PHP callback that returns an escaping strategy based on the template "name" + * + * * optimizations: A flag that indicates which optimizations to apply + * (default to -1 which means that all optimizations are enabled; + * set it to 0 to disable). + */ + public function __construct(LoaderInterface $loader = null, $options = []) + { + if (null !== $loader) { + $this->setLoader($loader); + } else { + @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); + } + + $options = array_merge([ + 'debug' => false, + 'charset' => 'UTF-8', + 'base_template_class' => '\Twig\Template', + 'strict_variables' => false, + 'autoescape' => 'html', + 'cache' => false, + 'auto_reload' => null, + 'optimizations' => -1, + ], $options); + + $this->debug = (bool) $options['debug']; + $this->charset = strtoupper($options['charset']); + $this->baseTemplateClass = $options['base_template_class']; + $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; + $this->strictVariables = (bool) $options['strict_variables']; + $this->setCache($options['cache']); + + $this->addExtension(new CoreExtension()); + $this->addExtension(new EscaperExtension($options['autoescape'])); + $this->addExtension(new OptimizerExtension($options['optimizations'])); + $this->staging = new StagingExtension(); + + // For BC + if (\is_string($this->originalCache)) { + $r = new \ReflectionMethod($this, 'writeCacheFile'); + if (__CLASS__ !== $r->getDeclaringClass()->getName()) { + @trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + + $this->bcWriteCacheFile = true; + } + + $r = new \ReflectionMethod($this, 'getCacheFilename'); + if (__CLASS__ !== $r->getDeclaringClass()->getName()) { + @trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + + $this->bcGetCacheFilename = true; + } + } + } + + /** + * Gets the base template class for compiled templates. + * + * @return string The base template class name + */ + public function getBaseTemplateClass() + { + return $this->baseTemplateClass; + } + + /** + * Sets the base template class for compiled templates. + * + * @param string $class The base template class name + */ + public function setBaseTemplateClass($class) + { + $this->baseTemplateClass = $class; + $this->updateOptionsHash(); + } + + /** + * Enables debugging mode. + */ + public function enableDebug() + { + $this->debug = true; + $this->updateOptionsHash(); + } + + /** + * Disables debugging mode. + */ + public function disableDebug() + { + $this->debug = false; + $this->updateOptionsHash(); + } + + /** + * Checks if debug mode is enabled. + * + * @return bool true if debug mode is enabled, false otherwise + */ + public function isDebug() + { + return $this->debug; + } + + /** + * Enables the auto_reload option. + */ + public function enableAutoReload() + { + $this->autoReload = true; + } + + /** + * Disables the auto_reload option. + */ + public function disableAutoReload() + { + $this->autoReload = false; + } + + /** + * Checks if the auto_reload option is enabled. + * + * @return bool true if auto_reload is enabled, false otherwise + */ + public function isAutoReload() + { + return $this->autoReload; + } + + /** + * Enables the strict_variables option. + */ + public function enableStrictVariables() + { + $this->strictVariables = true; + $this->updateOptionsHash(); + } + + /** + * Disables the strict_variables option. + */ + public function disableStrictVariables() + { + $this->strictVariables = false; + $this->updateOptionsHash(); + } + + /** + * Checks if the strict_variables option is enabled. + * + * @return bool true if strict_variables is enabled, false otherwise + */ + public function isStrictVariables() + { + return $this->strictVariables; + } + + /** + * Gets the current cache implementation. + * + * @param bool $original Whether to return the original cache option or the real cache instance + * + * @return CacheInterface|string|false A Twig\Cache\CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache + */ + public function getCache($original = true) + { + return $original ? $this->originalCache : $this->cache; + } + + /** + * Sets the current cache implementation. + * + * @param CacheInterface|string|false $cache A Twig\Cache\CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache + */ + public function setCache($cache) + { + if (\is_string($cache)) { + $this->originalCache = $cache; + $this->cache = new FilesystemCache($cache); + } elseif (false === $cache) { + $this->originalCache = $cache; + $this->cache = new NullCache(); + } elseif (null === $cache) { + @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); + $this->originalCache = false; + $this->cache = new NullCache(); + } elseif ($cache instanceof CacheInterface) { + $this->originalCache = $this->cache = $cache; + } else { + throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.')); + } + } + + /** + * Gets the cache filename for a given template. + * + * @param string $name The template name + * + * @return string|false The cache file name or false when caching is disabled + * + * @deprecated since 1.22 (to be removed in 2.0) + */ + public function getCacheFilename($name) + { + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + + $key = $this->cache->generateKey($name, $this->getTemplateClass($name)); + + return !$key ? false : $key; + } + + /** + * Gets the template class associated with the given string. + * + * The generated template class is based on the following parameters: + * + * * The cache key for the given template; + * * The currently enabled extensions; + * * Whether the Twig C extension is available or not; + * * PHP version; + * * Twig version; + * * Options with what environment was created. + * + * @param string $name The name for which to calculate the template class name + * @param int|null $index The index if it is an embedded template + * + * @return string The template class name + */ + public function getTemplateClass($name, $index = null) + { + $key = $this->getLoader()->getCacheKey($name).$this->optionsHash; + + return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '___'.$index); + } + + /** + * Gets the template class prefix. + * + * @return string The template class prefix + * + * @deprecated since 1.22 (to be removed in 2.0) + */ + public function getTemplateClassPrefix() + { + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + + return $this->templateClassPrefix; + } + + /** + * Renders a template. + * + * @param string|TemplateWrapper $name The template name + * @param array $context An array of parameters to pass to the template + * + * @return string The rendered template + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering + */ + public function render($name, array $context = []) + { + return $this->load($name)->render($context); + } + + /** + * Displays a template. + * + * @param string|TemplateWrapper $name The template name + * @param array $context An array of parameters to pass to the template + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering + */ + public function display($name, array $context = []) + { + $this->load($name)->display($context); + } + + /** + * Loads a template. + * + * @param string|TemplateWrapper|\Twig\Template $name The template name + * + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation + * + * @return TemplateWrapper + */ + public function load($name) + { + if ($name instanceof TemplateWrapper) { + return $name; + } + + if ($name instanceof Template) { + return new TemplateWrapper($this, $name); + } + + return new TemplateWrapper($this, $this->loadTemplate($name)); + } + + /** + * Loads a template internal representation. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The template name + * @param int $index The index if it is an embedded template + * + * @return \Twig_TemplateInterface A template instance representing the given template name + * + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation + * + * @internal + */ + public function loadTemplate($name, $index = null) + { + return $this->loadClass($this->getTemplateClass($name), $name, $index); + } + + /** + * @internal + */ + public function loadClass($cls, $name, $index = null) + { + $mainCls = $cls; + if (null !== $index) { + $cls .= '___'.$index; + } + + if (isset($this->loadedTemplates[$cls])) { + return $this->loadedTemplates[$cls]; + } + + if (!class_exists($cls, false)) { + if ($this->bcGetCacheFilename) { + $key = $this->getCacheFilename($name); + } else { + $key = $this->cache->generateKey($name, $mainCls); + } + + if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) { + $this->cache->load($key); + } + + $source = null; + if (!class_exists($cls, false)) { + $loader = $this->getLoader(); + if (!$loader instanceof SourceContextLoaderInterface) { + $source = new Source($loader->getSource($name), $name); + } else { + $source = $loader->getSourceContext($name); + } + + $content = $this->compileSource($source); + + if ($this->bcWriteCacheFile) { + $this->writeCacheFile($key, $content); + } else { + $this->cache->write($key, $content); + $this->cache->load($key); + } + + if (!class_exists($mainCls, false)) { + /* Last line of defense if either $this->bcWriteCacheFile was used, + * $this->cache is implemented as a no-op or we have a race condition + * where the cache was cleared between the above calls to write to and load from + * the cache. + */ + eval('?>'.$content); + } + } + + if (!class_exists($cls, false)) { + throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source); + } + } + + if (!$this->runtimeInitialized) { + $this->initRuntime(); + } + + return $this->loadedTemplates[$cls] = new $cls($this); + } + + /** + * Creates a template from source. + * + * This method should not be used as a generic way to load templates. + * + * @param string $template The template source + * @param string $name An optional name of the template to be used in error messages + * + * @return TemplateWrapper A template instance representing the given template name + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + */ + public function createTemplate($template, $name = null) + { + $hash = hash('sha256', $template, false); + if (null !== $name) { + $name = sprintf('%s (string template %s)', $name, $hash); + } else { + $name = sprintf('__string_template__%s', $hash); + } + + $loader = new ChainLoader([ + new ArrayLoader([$name => $template]), + $current = $this->getLoader(), + ]); + + $this->setLoader($loader); + try { + $template = new TemplateWrapper($this, $this->loadTemplate($name)); + } catch (\Exception $e) { + $this->setLoader($current); + + throw $e; + } catch (\Throwable $e) { + $this->setLoader($current); + + throw $e; + } + $this->setLoader($current); + + return $template; + } + + /** + * Returns true if the template is still fresh. + * + * Besides checking the loader for freshness information, + * this method also checks if the enabled extensions have + * not changed. + * + * @param string $name The template name + * @param int $time The last modification time of the cached template + * + * @return bool true if the template is fresh, false otherwise + */ + public function isTemplateFresh($name, $time) + { + if (0 === $this->lastModifiedExtension) { + foreach ($this->extensions as $extension) { + $r = new \ReflectionObject($extension); + if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) { + $this->lastModifiedExtension = $extensionTime; + } + } + } + + return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time); + } + + /** + * Tries to load a template consecutively from an array. + * + * Similar to load() but it also accepts instances of \Twig\Template and + * \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded. + * + * @param string|Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively + * + * @return TemplateWrapper|Template + * + * @throws LoaderError When none of the templates can be found + * @throws SyntaxError When an error occurred during compilation + */ + public function resolveTemplate($names) + { + if (!\is_array($names)) { + $names = [$names]; + } + + foreach ($names as $name) { + if ($name instanceof Template) { + return $name; + } + if ($name instanceof TemplateWrapper) { + return $name; + } + + try { + return $this->loadTemplate($name); + } catch (LoaderError $e) { + if (1 === \count($names)) { + throw $e; + } + } + } + + throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); + } + + /** + * Clears the internal template cache. + * + * @deprecated since 1.18.3 (to be removed in 2.0) + */ + public function clearTemplateCache() + { + @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); + + $this->loadedTemplates = []; + } + + /** + * Clears the template cache files on the filesystem. + * + * @deprecated since 1.22 (to be removed in 2.0) + */ + public function clearCacheFiles() + { + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + + if (\is_string($this->originalCache)) { + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if ($file->isFile()) { + @unlink($file->getPathname()); + } + } + } + } + + /** + * Gets the Lexer instance. + * + * @return \Twig_LexerInterface + * + * @deprecated since 1.25 (to be removed in 2.0) + */ + public function getLexer() + { + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + + if (null === $this->lexer) { + $this->lexer = new Lexer($this); + } + + return $this->lexer; + } + + public function setLexer(\Twig_LexerInterface $lexer) + { + $this->lexer = $lexer; + } + + /** + * Tokenizes a source code. + * + * @param string|Source $source The template source code + * @param string $name The template name (deprecated) + * + * @return TokenStream + * + * @throws SyntaxError When the code is syntactically wrong + */ + public function tokenize($source, $name = null) + { + if (!$source instanceof Source) { + @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); + $source = new Source($source, $name); + } + + if (null === $this->lexer) { + $this->lexer = new Lexer($this); + } + + return $this->lexer->tokenize($source); + } + + /** + * Gets the Parser instance. + * + * @return \Twig_ParserInterface + * + * @deprecated since 1.25 (to be removed in 2.0) + */ + public function getParser() + { + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + + if (null === $this->parser) { + $this->parser = new Parser($this); + } + + return $this->parser; + } + + public function setParser(\Twig_ParserInterface $parser) + { + $this->parser = $parser; + } + + /** + * Converts a token stream to a node tree. + * + * @return ModuleNode + * + * @throws SyntaxError When the token stream is syntactically or semantically wrong + */ + public function parse(TokenStream $stream) + { + if (null === $this->parser) { + $this->parser = new Parser($this); + } + + return $this->parser->parse($stream); + } + + /** + * Gets the Compiler instance. + * + * @return \Twig_CompilerInterface + * + * @deprecated since 1.25 (to be removed in 2.0) + */ + public function getCompiler() + { + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + + if (null === $this->compiler) { + $this->compiler = new Compiler($this); + } + + return $this->compiler; + } + + public function setCompiler(\Twig_CompilerInterface $compiler) + { + $this->compiler = $compiler; + } + + /** + * Compiles a node and returns the PHP code. + * + * @return string The compiled PHP source code + */ + public function compile(\Twig_NodeInterface $node) + { + if (null === $this->compiler) { + $this->compiler = new Compiler($this); + } + + return $this->compiler->compile($node)->getSource(); + } + + /** + * Compiles a template source code. + * + * @param string|Source $source The template source code + * @param string $name The template name (deprecated) + * + * @return string The compiled PHP source code + * + * @throws SyntaxError When there was an error during tokenizing, parsing or compiling + */ + public function compileSource($source, $name = null) + { + if (!$source instanceof Source) { + @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); + $source = new Source($source, $name); + } + + try { + return $this->compile($this->parse($this->tokenize($source))); + } catch (Error $e) { + $e->setSourceContext($source); + throw $e; + } catch (\Exception $e) { + throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); + } + } + + public function setLoader(LoaderInterface $loader) + { + if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { + @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED); + } + + $this->loader = $loader; + } + + /** + * Gets the Loader instance. + * + * @return LoaderInterface + */ + public function getLoader() + { + if (null === $this->loader) { + throw new \LogicException('You must set a loader first.'); + } + + return $this->loader; + } + + /** + * Sets the default template charset. + * + * @param string $charset The default charset + */ + public function setCharset($charset) + { + $this->charset = strtoupper($charset); + } + + /** + * Gets the default template charset. + * + * @return string The default charset + */ + public function getCharset() + { + return $this->charset; + } + + /** + * Initializes the runtime environment. + * + * @deprecated since 1.23 (to be removed in 2.0) + */ + public function initRuntime() + { + $this->runtimeInitialized = true; + + foreach ($this->getExtensions() as $name => $extension) { + if (!$extension instanceof InitRuntimeInterface) { + $m = new \ReflectionMethod($extension, 'initRuntime'); + + $parentClass = $m->getDeclaringClass()->getName(); + if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) { + @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); + } + } + + $extension->initRuntime($this); + } + } + + /** + * Returns true if the given extension is registered. + * + * @param string $class The extension class name + * + * @return bool Whether the extension is registered or not + */ + public function hasExtension($class) + { + $class = ltrim($class, '\\'); + if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) { + // For BC/FC with namespaced aliases + $class = new \ReflectionClass($class); + $class = $class->name; + } + + if (isset($this->extensions[$class])) { + if ($class !== \get_class($this->extensions[$class])) { + @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); + } + + return true; + } + + return isset($this->extensionsByClass[$class]); + } + + /** + * Adds a runtime loader. + */ + public function addRuntimeLoader(RuntimeLoaderInterface $loader) + { + $this->runtimeLoaders[] = $loader; + } + + /** + * Gets an extension by class name. + * + * @param string $class The extension class name + * + * @return ExtensionInterface + */ + public function getExtension($class) + { + $class = ltrim($class, '\\'); + if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) { + // For BC/FC with namespaced aliases + $class = new \ReflectionClass($class); + $class = $class->name; + } + + if (isset($this->extensions[$class])) { + if ($class !== \get_class($this->extensions[$class])) { + @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); + } + + return $this->extensions[$class]; + } + + if (!isset($this->extensionsByClass[$class])) { + throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class)); + } + + return $this->extensionsByClass[$class]; + } + + /** + * Returns the runtime implementation of a Twig element (filter/function/test). + * + * @param string $class A runtime class name + * + * @return object The runtime implementation + * + * @throws RuntimeError When the template cannot be found + */ + public function getRuntime($class) + { + if (isset($this->runtimes[$class])) { + return $this->runtimes[$class]; + } + + foreach ($this->runtimeLoaders as $loader) { + if (null !== $runtime = $loader->load($class)) { + return $this->runtimes[$class] = $runtime; + } + } + + throw new RuntimeError(sprintf('Unable to load the "%s" runtime.', $class)); + } + + public function addExtension(ExtensionInterface $extension) + { + if ($this->extensionInitialized) { + throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); + } + + $class = \get_class($extension); + if ($class !== $extension->getName()) { + if (isset($this->extensions[$extension->getName()])) { + unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]); + @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); + } + } + + $this->lastModifiedExtension = 0; + $this->extensionsByClass[$class] = $extension; + $this->extensions[$extension->getName()] = $extension; + $this->updateOptionsHash(); + } + + /** + * Removes an extension by name. + * + * This method is deprecated and you should not use it. + * + * @param string $name The extension name + * + * @deprecated since 1.12 (to be removed in 2.0) + */ + public function removeExtension($name) + { + @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + + if ($this->extensionInitialized) { + throw new \LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); + } + + $class = ltrim($name, '\\'); + if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) { + // For BC/FC with namespaced aliases + $class = new \ReflectionClass($class); + $class = $class->name; + } + + if (isset($this->extensions[$class])) { + if ($class !== \get_class($this->extensions[$class])) { + @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); + } + + unset($this->extensions[$class]); + } + + unset($this->extensions[$class]); + $this->updateOptionsHash(); + } + + /** + * Registers an array of extensions. + * + * @param array $extensions An array of extensions + */ + public function setExtensions(array $extensions) + { + foreach ($extensions as $extension) { + $this->addExtension($extension); + } + } + + /** + * Returns all registered extensions. + * + * @return ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) + */ + public function getExtensions() + { + return $this->extensions; + } + + public function addTokenParser(TokenParserInterface $parser) + { + if ($this->extensionInitialized) { + throw new \LogicException('Unable to add a token parser as extensions have already been initialized.'); + } + + $this->staging->addTokenParser($parser); + } + + /** + * Gets the registered Token Parsers. + * + * @return \Twig_TokenParserBrokerInterface + * + * @internal + */ + public function getTokenParsers() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->parsers; + } + + /** + * Gets registered tags. + * + * Be warned that this method cannot return tags defined by \Twig_TokenParserBrokerInterface classes. + * + * @return TokenParserInterface[] + * + * @internal + */ + public function getTags() + { + $tags = []; + foreach ($this->getTokenParsers()->getParsers() as $parser) { + if ($parser instanceof TokenParserInterface) { + $tags[$parser->getTag()] = $parser; + } + } + + return $tags; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + if ($this->extensionInitialized) { + throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.'); + } + + $this->staging->addNodeVisitor($visitor); + } + + /** + * Gets the registered Node Visitors. + * + * @return NodeVisitorInterface[] + * + * @internal + */ + public function getNodeVisitors() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->visitors; + } + + /** + * Registers a Filter. + * + * @param string|TwigFilter $name The filter name or a \Twig_SimpleFilter instance + * @param \Twig_FilterInterface|TwigFilter $filter + */ + public function addFilter($name, $filter = null) + { + if (!$name instanceof TwigFilter && !($filter instanceof TwigFilter || $filter instanceof \Twig_FilterInterface)) { + throw new \LogicException('A filter must be an instance of \Twig_FilterInterface or \Twig_SimpleFilter.'); + } + + if ($name instanceof TwigFilter) { + $filter = $name; + $name = $filter->getName(); + } else { + @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); + } + + if ($this->extensionInitialized) { + throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name)); + } + + $this->staging->addFilter($name, $filter); + } + + /** + * Get a filter by name. + * + * Subclasses may override this method and load filters differently; + * so no list of filters is available. + * + * @param string $name The filter name + * + * @return \Twig_Filter|false + * + * @internal + */ + public function getFilter($name) + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + if (isset($this->filters[$name])) { + return $this->filters[$name]; + } + + foreach ($this->filters as $pattern => $filter) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count) { + if (preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $filter->setArguments($matches); + + return $filter; + } + } + } + + foreach ($this->filterCallbacks as $callback) { + if (false !== $filter = \call_user_func($callback, $name)) { + return $filter; + } + } + + return false; + } + + public function registerUndefinedFilterCallback($callable) + { + $this->filterCallbacks[] = $callable; + } + + /** + * Gets the registered Filters. + * + * Be warned that this method cannot return filters defined with registerUndefinedFilterCallback. + * + * @return \Twig_FilterInterface[] + * + * @see registerUndefinedFilterCallback + * + * @internal + */ + public function getFilters() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->filters; + } + + /** + * Registers a Test. + * + * @param string|TwigTest $name The test name or a \Twig_SimpleTest instance + * @param \Twig_TestInterface|TwigTest $test A \Twig_TestInterface instance or a \Twig_SimpleTest instance + */ + public function addTest($name, $test = null) + { + if (!$name instanceof TwigTest && !($test instanceof TwigTest || $test instanceof \Twig_TestInterface)) { + throw new \LogicException('A test must be an instance of \Twig_TestInterface or \Twig_SimpleTest.'); + } + + if ($name instanceof TwigTest) { + $test = $name; + $name = $test->getName(); + } else { + @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); + } + + if ($this->extensionInitialized) { + throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name)); + } + + $this->staging->addTest($name, $test); + } + + /** + * Gets the registered Tests. + * + * @return \Twig_TestInterface[] + * + * @internal + */ + public function getTests() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->tests; + } + + /** + * Gets a test by name. + * + * @param string $name The test name + * + * @return \Twig_Test|false + * + * @internal + */ + public function getTest($name) + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + if (isset($this->tests[$name])) { + return $this->tests[$name]; + } + + foreach ($this->tests as $pattern => $test) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count) { + if (preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $test->setArguments($matches); + + return $test; + } + } + } + + return false; + } + + /** + * Registers a Function. + * + * @param string|TwigFunction $name The function name or a \Twig_SimpleFunction instance + * @param \Twig_FunctionInterface|TwigFunction $function + */ + public function addFunction($name, $function = null) + { + if (!$name instanceof TwigFunction && !($function instanceof TwigFunction || $function instanceof \Twig_FunctionInterface)) { + throw new \LogicException('A function must be an instance of \Twig_FunctionInterface or \Twig_SimpleFunction.'); + } + + if ($name instanceof TwigFunction) { + $function = $name; + $name = $function->getName(); + } else { + @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); + } + + if ($this->extensionInitialized) { + throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name)); + } + + $this->staging->addFunction($name, $function); + } + + /** + * Get a function by name. + * + * Subclasses may override this method and load functions differently; + * so no list of functions is available. + * + * @param string $name function name + * + * @return \Twig_Function|false + * + * @internal + */ + public function getFunction($name) + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + if (isset($this->functions[$name])) { + return $this->functions[$name]; + } + + foreach ($this->functions as $pattern => $function) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count) { + if (preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $function->setArguments($matches); + + return $function; + } + } + } + + foreach ($this->functionCallbacks as $callback) { + if (false !== $function = \call_user_func($callback, $name)) { + return $function; + } + } + + return false; + } + + public function registerUndefinedFunctionCallback($callable) + { + $this->functionCallbacks[] = $callable; + } + + /** + * Gets registered functions. + * + * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback. + * + * @return \Twig_FunctionInterface[] + * + * @see registerUndefinedFunctionCallback + * + * @internal + */ + public function getFunctions() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->functions; + } + + /** + * Registers a Global. + * + * New globals can be added before compiling or rendering a template; + * but after, you can only update existing globals. + * + * @param string $name The global name + * @param mixed $value The global value + */ + public function addGlobal($name, $value) + { + if ($this->extensionInitialized || $this->runtimeInitialized) { + if (null === $this->globals) { + $this->globals = $this->initGlobals(); + } + + if (!\array_key_exists($name, $this->globals)) { + // The deprecation notice must be turned into the following exception in Twig 2.0 + @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); + //throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); + } + } + + if ($this->extensionInitialized || $this->runtimeInitialized) { + // update the value + $this->globals[$name] = $value; + } else { + $this->staging->addGlobal($name, $value); + } + } + + /** + * Gets the registered Globals. + * + * @return array An array of globals + * + * @internal + */ + public function getGlobals() + { + if (!$this->runtimeInitialized && !$this->extensionInitialized) { + return $this->initGlobals(); + } + + if (null === $this->globals) { + $this->globals = $this->initGlobals(); + } + + return $this->globals; + } + + /** + * Merges a context with the defined globals. + * + * @param array $context An array representing the context + * + * @return array The context merged with the globals + */ + public function mergeGlobals(array $context) + { + // we don't use array_merge as the context being generally + // bigger than globals, this code is faster. + foreach ($this->getGlobals() as $key => $value) { + if (!\array_key_exists($key, $context)) { + $context[$key] = $value; + } + } + + return $context; + } + + /** + * Gets the registered unary Operators. + * + * @return array An array of unary operators + * + * @internal + */ + public function getUnaryOperators() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->unaryOperators; + } + + /** + * Gets the registered binary Operators. + * + * @return array An array of binary operators + * + * @internal + */ + public function getBinaryOperators() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->binaryOperators; + } + + /** + * @deprecated since 1.23 (to be removed in 2.0) + */ + public function computeAlternatives($name, $items) + { + @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + + return SyntaxError::computeAlternatives($name, $items); + } + + /** + * @internal + */ + protected function initGlobals() + { + $globals = []; + foreach ($this->extensions as $name => $extension) { + if (!$extension instanceof GlobalsInterface) { + $m = new \ReflectionMethod($extension, 'getGlobals'); + + $parentClass = $m->getDeclaringClass()->getName(); + if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) { + @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); + } + } + + $extGlob = $extension->getGlobals(); + if (!\is_array($extGlob)) { + throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension))); + } + + $globals[] = $extGlob; + } + + $globals[] = $this->staging->getGlobals(); + + return \call_user_func_array('array_merge', $globals); + } + + /** + * @internal + */ + protected function initExtensions() + { + if ($this->extensionInitialized) { + return; + } + + $this->parsers = new \Twig_TokenParserBroker([], [], false); + $this->filters = []; + $this->functions = []; + $this->tests = []; + $this->visitors = []; + $this->unaryOperators = []; + $this->binaryOperators = []; + + foreach ($this->extensions as $extension) { + $this->initExtension($extension); + } + $this->initExtension($this->staging); + // Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception + $this->extensionInitialized = true; + } + + /** + * @internal + */ + protected function initExtension(ExtensionInterface $extension) + { + // filters + foreach ($extension->getFilters() as $name => $filter) { + if ($filter instanceof TwigFilter) { + $name = $filter->getName(); + } else { + @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); + } + + $this->filters[$name] = $filter; + } + + // functions + foreach ($extension->getFunctions() as $name => $function) { + if ($function instanceof TwigFunction) { + $name = $function->getName(); + } else { + @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); + } + + $this->functions[$name] = $function; + } + + // tests + foreach ($extension->getTests() as $name => $test) { + if ($test instanceof TwigTest) { + $name = $test->getName(); + } else { + @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); + } + + $this->tests[$name] = $test; + } + + // token parsers + foreach ($extension->getTokenParsers() as $parser) { + if ($parser instanceof TokenParserInterface) { + $this->parsers->addTokenParser($parser); + } elseif ($parser instanceof \Twig_TokenParserBrokerInterface) { + @trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED); + + $this->parsers->addTokenParserBroker($parser); + } else { + throw new \LogicException('getTokenParsers() must return an array of \Twig_TokenParserInterface or \Twig_TokenParserBrokerInterface instances.'); + } + } + + // node visitors + foreach ($extension->getNodeVisitors() as $visitor) { + $this->visitors[] = $visitor; + } + + // operators + if ($operators = $extension->getOperators()) { + if (!\is_array($operators)) { + 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))); + } + + if (2 !== \count($operators)) { + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators))); + } + + $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); + $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]); + } + } + + /** + * @deprecated since 1.22 (to be removed in 2.0) + */ + protected function writeCacheFile($file, $content) + { + $this->cache->write($file, $content); + } + + private function updateOptionsHash() + { + $hashParts = array_merge( + array_keys($this->extensions), + [ + (int) \function_exists('twig_template_get_attributes'), + PHP_MAJOR_VERSION, + PHP_MINOR_VERSION, + self::VERSION, + (int) $this->debug, + $this->baseTemplateClass, + (int) $this->strictVariables, + ] + ); + $this->optionsHash = implode(':', $hashParts); + } +} + +class_alias('Twig\Environment', 'Twig_Environment'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/Error.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/Error.php new file mode 100644 index 0000000..2aa70f1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/Error.php @@ -0,0 +1,325 @@ + + */ +class Error extends \Exception +{ + protected $lineno; + // to be renamed to name in 2.0 + protected $filename; + protected $rawMessage; + + private $sourcePath; + private $sourceCode; + + /** + * Constructor. + * + * Set the line number to -1 to enable its automatic guessing. + * Set the name to null to enable its automatic guessing. + * + * @param string $message The error message + * @param int $lineno The template line where the error occurred + * @param Source|string|null $source The source context where the error occurred + * @param \Exception $previous The previous exception + */ + public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null) + { + if (null === $source) { + $name = null; + } elseif (!$source instanceof Source) { + // for compat with the Twig C ext., passing the template name as string is accepted + $name = $source; + } else { + $name = $source->getName(); + $this->sourceCode = $source->getCode(); + $this->sourcePath = $source->getPath(); + } + parent::__construct('', 0, $previous); + + $this->lineno = $lineno; + $this->filename = $name; + $this->rawMessage = $message; + $this->updateRepr(); + } + + /** + * Gets the raw message. + * + * @return string The raw message + */ + public function getRawMessage() + { + return $this->rawMessage; + } + + /** + * Gets the logical name where the error occurred. + * + * @return string The name + * + * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead. + */ + public function getTemplateFile() + { + @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); + + return $this->filename; + } + + /** + * Sets the logical name where the error occurred. + * + * @param string $name The name + * + * @deprecated since 1.27 (to be removed in 2.0). Use setSourceContext() instead. + */ + public function setTemplateFile($name) + { + @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); + + $this->filename = $name; + + $this->updateRepr(); + } + + /** + * Gets the logical name where the error occurred. + * + * @return string The name + * + * @deprecated since 1.29 (to be removed in 2.0). Use getSourceContext() instead. + */ + public function getTemplateName() + { + @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); + + return $this->filename; + } + + /** + * Sets the logical name where the error occurred. + * + * @param string $name The name + * + * @deprecated since 1.29 (to be removed in 2.0). Use setSourceContext() instead. + */ + public function setTemplateName($name) + { + @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); + + $this->filename = $name; + $this->sourceCode = $this->sourcePath = null; + + $this->updateRepr(); + } + + /** + * Gets the template line where the error occurred. + * + * @return int The template line + */ + public function getTemplateLine() + { + return $this->lineno; + } + + /** + * Sets the template line where the error occurred. + * + * @param int $lineno The template line + */ + public function setTemplateLine($lineno) + { + $this->lineno = $lineno; + + $this->updateRepr(); + } + + /** + * Gets the source context of the Twig template where the error occurred. + * + * @return Source|null + */ + public function getSourceContext() + { + return $this->filename ? new Source($this->sourceCode, $this->filename, $this->sourcePath) : null; + } + + /** + * Sets the source context of the Twig template where the error occurred. + */ + public function setSourceContext(Source $source = null) + { + if (null === $source) { + $this->sourceCode = $this->filename = $this->sourcePath = null; + } else { + $this->sourceCode = $source->getCode(); + $this->filename = $source->getName(); + $this->sourcePath = $source->getPath(); + } + + $this->updateRepr(); + } + + public function guess() + { + $this->guessTemplateInfo(); + $this->updateRepr(); + } + + public function appendMessage($rawMessage) + { + $this->rawMessage .= $rawMessage; + $this->updateRepr(); + } + + /** + * @internal + */ + protected function updateRepr() + { + $this->message = $this->rawMessage; + + if ($this->sourcePath && $this->lineno > 0) { + $this->file = $this->sourcePath; + $this->line = $this->lineno; + + return; + } + + $dot = false; + if ('.' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $dot = true; + } + + $questionMark = false; + if ('?' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $questionMark = true; + } + + if ($this->filename) { + if (\is_string($this->filename) || (\is_object($this->filename) && method_exists($this->filename, '__toString'))) { + $name = sprintf('"%s"', $this->filename); + } else { + $name = json_encode($this->filename); + } + $this->message .= sprintf(' in %s', $name); + } + + if ($this->lineno && $this->lineno >= 0) { + $this->message .= sprintf(' at line %d', $this->lineno); + } + + if ($dot) { + $this->message .= '.'; + } + + if ($questionMark) { + $this->message .= '?'; + } + } + + /** + * @internal + */ + protected function guessTemplateInfo() + { + $template = null; + $templateClass = null; + + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + foreach ($backtrace as $trace) { + if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) { + $currentClass = \get_class($trace['object']); + $isEmbedContainer = 0 === strpos($templateClass, $currentClass); + if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) { + $template = $trace['object']; + $templateClass = \get_class($trace['object']); + } + } + } + + // update template name + if (null !== $template && null === $this->filename) { + $this->filename = $template->getTemplateName(); + } + + // update template path if any + if (null !== $template && null === $this->sourcePath) { + $src = $template->getSourceContext(); + $this->sourceCode = $src->getCode(); + $this->sourcePath = $src->getPath(); + } + + if (null === $template || $this->lineno > -1) { + return; + } + + $r = new \ReflectionObject($template); + $file = $r->getFileName(); + + $exceptions = [$e = $this]; + while ($e instanceof self && $e = $e->getPrevious()) { + $exceptions[] = $e; + } + + while ($e = array_pop($exceptions)) { + $traces = $e->getTrace(); + array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]); + + while ($trace = array_shift($traces)) { + if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) { + continue; + } + + foreach ($template->getDebugInfo() as $codeLine => $templateLine) { + if ($codeLine <= $trace['line']) { + // update template line + $this->lineno = $templateLine; + + return; + } + } + } + } + } +} + +class_alias('Twig\Error\Error', 'Twig_Error'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/LoaderError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/LoaderError.php new file mode 100644 index 0000000..dc5a9f1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/LoaderError.php @@ -0,0 +1,23 @@ + + */ +class LoaderError extends Error +{ +} + +class_alias('Twig\Error\LoaderError', 'Twig_Error_Loader'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/RuntimeError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/RuntimeError.php new file mode 100644 index 0000000..9b3f36e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/RuntimeError.php @@ -0,0 +1,24 @@ + + */ +class RuntimeError extends Error +{ +} + +class_alias('Twig\Error\RuntimeError', 'Twig_Error_Runtime'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/SyntaxError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/SyntaxError.php new file mode 100644 index 0000000..480e660 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Error/SyntaxError.php @@ -0,0 +1,57 @@ + + */ +class SyntaxError extends Error +{ + /** + * Tweaks the error message to include suggestions. + * + * @param string $name The original name of the item that does not exist + * @param array $items An array of possible items + */ + public function addSuggestions($name, array $items) + { + if (!$alternatives = self::computeAlternatives($name, $items)) { + return; + } + + $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives))); + } + + /** + * @internal + * + * To be merged with the addSuggestions() method in 2.0. + */ + public static function computeAlternatives($name, $items) + { + $alternatives = []; + foreach ($items as $item) { + $lev = levenshtein($name, $item); + if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) { + $alternatives[$item] = $lev; + } + } + asort($alternatives); + + return array_keys($alternatives); + } +} + +class_alias('Twig\Error\SyntaxError', 'Twig_Error_Syntax'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/ExpressionParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/ExpressionParser.php new file mode 100644 index 0000000..a3ff725 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/ExpressionParser.php @@ -0,0 +1,834 @@ + + * + * @internal + */ +class ExpressionParser +{ + const OPERATOR_LEFT = 1; + const OPERATOR_RIGHT = 2; + + protected $parser; + protected $unaryOperators; + protected $binaryOperators; + + private $env; + + public function __construct(Parser $parser, $env = null) + { + $this->parser = $parser; + + if ($env instanceof Environment) { + $this->env = $env; + $this->unaryOperators = $env->getUnaryOperators(); + $this->binaryOperators = $env->getBinaryOperators(); + } else { + @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED); + + $this->env = $parser->getEnvironment(); + $this->unaryOperators = func_get_arg(1); + $this->binaryOperators = func_get_arg(2); + } + } + + public function parseExpression($precedence = 0, $allowArrow = false) + { + if ($allowArrow && $arrow = $this->parseArrow()) { + return $arrow; + } + + $expr = $this->getPrimary(); + $token = $this->parser->getCurrentToken(); + while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) { + $op = $this->binaryOperators[$token->getValue()]; + $this->parser->getStream()->next(); + + if ('is not' === $token->getValue()) { + $expr = $this->parseNotTestExpression($expr); + } elseif ('is' === $token->getValue()) { + $expr = $this->parseTestExpression($expr); + } elseif (isset($op['callable'])) { + $expr = \call_user_func($op['callable'], $this->parser, $expr); + } else { + $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); + $class = $op['class']; + $expr = new $class($expr, $expr1, $token->getLine()); + } + + $token = $this->parser->getCurrentToken(); + } + + if (0 === $precedence) { + return $this->parseConditionalExpression($expr); + } + + return $expr; + } + + /** + * @return ArrowFunctionExpression|null + */ + private function parseArrow() + { + $stream = $this->parser->getStream(); + + // short array syntax (one argument, no parentheses)? + if ($stream->look(1)->test(Token::ARROW_TYPE)) { + $line = $stream->getCurrent()->getLine(); + $token = $stream->expect(Token::NAME_TYPE); + $names = [new AssignNameExpression($token->getValue(), $token->getLine())]; + $stream->expect(Token::ARROW_TYPE); + + return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line); + } + + // first, determine if we are parsing an arrow function by finding => (long form) + $i = 0; + if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, '(')) { + return null; + } + ++$i; + while (true) { + // variable name + ++$i; + if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ',')) { + break; + } + ++$i; + } + if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ')')) { + return null; + } + ++$i; + if (!$stream->look($i)->test(Token::ARROW_TYPE)) { + return null; + } + + // yes, let's parse it properly + $token = $stream->expect(Token::PUNCTUATION_TYPE, '('); + $line = $token->getLine(); + + $names = []; + while (true) { + $token = $stream->expect(Token::NAME_TYPE); + $names[] = new AssignNameExpression($token->getValue(), $token->getLine()); + + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { + break; + } + } + $stream->expect(Token::PUNCTUATION_TYPE, ')'); + $stream->expect(Token::ARROW_TYPE); + + return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line); + } + + protected function getPrimary() + { + $token = $this->parser->getCurrentToken(); + + if ($this->isUnary($token)) { + $operator = $this->unaryOperators[$token->getValue()]; + $this->parser->getStream()->next(); + $expr = $this->parseExpression($operator['precedence']); + $class = $operator['class']; + + return $this->parsePostfixExpression(new $class($expr, $token->getLine())); + } elseif ($token->test(Token::PUNCTUATION_TYPE, '(')) { + $this->parser->getStream()->next(); + $expr = $this->parseExpression(); + $this->parser->getStream()->expect(Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed'); + + return $this->parsePostfixExpression($expr); + } + + return $this->parsePrimaryExpression(); + } + + protected function parseConditionalExpression($expr) + { + while ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, '?')) { + if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) { + $expr2 = $this->parseExpression(); + if ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) { + $expr3 = $this->parseExpression(); + } else { + $expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine()); + } + } else { + $expr2 = $expr; + $expr3 = $this->parseExpression(); + } + + $expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); + } + + return $expr; + } + + protected function isUnary(Token $token) + { + return $token->test(Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); + } + + protected function isBinary(Token $token) + { + return $token->test(Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); + } + + public function parsePrimaryExpression() + { + $token = $this->parser->getCurrentToken(); + switch ($token->getType()) { + case Token::NAME_TYPE: + $this->parser->getStream()->next(); + switch ($token->getValue()) { + case 'true': + case 'TRUE': + $node = new ConstantExpression(true, $token->getLine()); + break; + + case 'false': + case 'FALSE': + $node = new ConstantExpression(false, $token->getLine()); + break; + + case 'none': + case 'NONE': + case 'null': + case 'NULL': + $node = new ConstantExpression(null, $token->getLine()); + break; + + default: + if ('(' === $this->parser->getCurrentToken()->getValue()) { + $node = $this->getFunctionNode($token->getValue(), $token->getLine()); + } else { + $node = new NameExpression($token->getValue(), $token->getLine()); + } + } + break; + + case Token::NUMBER_TYPE: + $this->parser->getStream()->next(); + $node = new ConstantExpression($token->getValue(), $token->getLine()); + break; + + case Token::STRING_TYPE: + case Token::INTERPOLATION_START_TYPE: + $node = $this->parseStringExpression(); + break; + + case Token::OPERATOR_TYPE: + if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { + // in this context, string operators are variable names + $this->parser->getStream()->next(); + $node = new NameExpression($token->getValue(), $token->getLine()); + break; + } elseif (isset($this->unaryOperators[$token->getValue()])) { + $class = $this->unaryOperators[$token->getValue()]['class']; + + $ref = new \ReflectionClass($class); + $negClass = 'Twig\Node\Expression\Unary\NegUnary'; + $posClass = 'Twig\Node\Expression\Unary\PosUnary'; + if (!(\in_array($ref->getName(), [$negClass, $posClass, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos']) + || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass) + || $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos')) + ) { + throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } + + $this->parser->getStream()->next(); + $expr = $this->parsePrimaryExpression(); + + $node = new $class($expr, $token->getLine()); + break; + } + + // no break + default: + if ($token->test(Token::PUNCTUATION_TYPE, '[')) { + $node = $this->parseArrayExpression(); + } elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) { + $node = $this->parseHashExpression(); + } elseif ($token->test(Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { + 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()); + } else { + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } + } + + return $this->parsePostfixExpression($node); + } + + public function parseStringExpression() + { + $stream = $this->parser->getStream(); + + $nodes = []; + // a string cannot be followed by another string in a single expression + $nextCanBeString = true; + while (true) { + if ($nextCanBeString && $token = $stream->nextIf(Token::STRING_TYPE)) { + $nodes[] = new ConstantExpression($token->getValue(), $token->getLine()); + $nextCanBeString = false; + } elseif ($stream->nextIf(Token::INTERPOLATION_START_TYPE)) { + $nodes[] = $this->parseExpression(); + $stream->expect(Token::INTERPOLATION_END_TYPE); + $nextCanBeString = true; + } else { + break; + } + } + + $expr = array_shift($nodes); + foreach ($nodes as $node) { + $expr = new ConcatBinary($expr, $node, $node->getTemplateLine()); + } + + return $expr; + } + + public function parseArrayExpression() + { + $stream = $this->parser->getStream(); + $stream->expect(Token::PUNCTUATION_TYPE, '[', 'An array element was expected'); + + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); + $first = true; + while (!$stream->test(Token::PUNCTUATION_TYPE, ']')) { + if (!$first) { + $stream->expect(Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma'); + + // trailing ,? + if ($stream->test(Token::PUNCTUATION_TYPE, ']')) { + break; + } + } + $first = false; + + $node->addElement($this->parseExpression()); + } + $stream->expect(Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed'); + + return $node; + } + + public function parseHashExpression() + { + $stream = $this->parser->getStream(); + $stream->expect(Token::PUNCTUATION_TYPE, '{', 'A hash element was expected'); + + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); + $first = true; + while (!$stream->test(Token::PUNCTUATION_TYPE, '}')) { + if (!$first) { + $stream->expect(Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma'); + + // trailing ,? + if ($stream->test(Token::PUNCTUATION_TYPE, '}')) { + break; + } + } + $first = false; + + // a hash key can be: + // + // * a number -- 12 + // * a string -- 'a' + // * a name, which is equivalent to a string -- a + // * an expression, which must be enclosed in parentheses -- (1 + 2) + if (($token = $stream->nextIf(Token::STRING_TYPE)) || ($token = $stream->nextIf(Token::NAME_TYPE)) || $token = $stream->nextIf(Token::NUMBER_TYPE)) { + $key = new ConstantExpression($token->getValue(), $token->getLine()); + } elseif ($stream->test(Token::PUNCTUATION_TYPE, '(')) { + $key = $this->parseExpression(); + } else { + $current = $stream->getCurrent(); + + 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()); + } + + $stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); + $value = $this->parseExpression(); + + $node->addElement($value, $key); + } + $stream->expect(Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed'); + + return $node; + } + + public function parsePostfixExpression($node) + { + while (true) { + $token = $this->parser->getCurrentToken(); + if (Token::PUNCTUATION_TYPE == $token->getType()) { + if ('.' == $token->getValue() || '[' == $token->getValue()) { + $node = $this->parseSubscriptExpression($node); + } elseif ('|' == $token->getValue()) { + $node = $this->parseFilterExpression($node); + } else { + break; + } + } else { + break; + } + } + + return $node; + } + + public function getFunctionNode($name, $line) + { + switch ($name) { + case 'parent': + $this->parseArguments(); + if (!\count($this->parser->getBlockStack())) { + throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + } + + if (!$this->parser->getParent() && !$this->parser->hasTraits()) { + throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + } + + return new ParentExpression($this->parser->peekBlockStack(), $line); + case 'block': + $args = $this->parseArguments(); + if (\count($args) < 1) { + throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); + } + + return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); + case 'attribute': + $args = $this->parseArguments(); + if (\count($args) < 2) { + throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); + } + + return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line); + default: + if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { + $arguments = new ArrayExpression([], $line); + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + + $node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line); + $node->setAttribute('safe', true); + + return $node; + } + + $args = $this->parseArguments(true); + $class = $this->getFunctionNodeClass($name, $line); + + return new $class($name, $args, $line); + } + } + + public function parseSubscriptExpression($node) + { + $stream = $this->parser->getStream(); + $token = $stream->next(); + $lineno = $token->getLine(); + $arguments = new ArrayExpression([], $lineno); + $type = Template::ANY_CALL; + if ('.' == $token->getValue()) { + $token = $stream->next(); + if ( + Token::NAME_TYPE == $token->getType() + || + Token::NUMBER_TYPE == $token->getType() + || + (Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue())) + ) { + $arg = new ConstantExpression($token->getValue(), $lineno); + + if ($stream->test(Token::PUNCTUATION_TYPE, '(')) { + $type = Template::METHOD_CALL; + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + } + } else { + throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext()); + } + + if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { + if (!$arg instanceof ConstantExpression) { + throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); + } + + $name = $arg->getAttribute('value'); + + if ($this->parser->isReservedMacroName($name)) { + throw new SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); + } + + $node = new MethodCallExpression($node, 'get'.$name, $arguments, $lineno); + $node->setAttribute('safe', true); + + return $node; + } + } else { + $type = Template::ARRAY_CALL; + + // slice? + $slice = false; + if ($stream->test(Token::PUNCTUATION_TYPE, ':')) { + $slice = true; + $arg = new ConstantExpression(0, $token->getLine()); + } else { + $arg = $this->parseExpression(); + } + + if ($stream->nextIf(Token::PUNCTUATION_TYPE, ':')) { + $slice = true; + } + + if ($slice) { + if ($stream->test(Token::PUNCTUATION_TYPE, ']')) { + $length = new ConstantExpression(null, $token->getLine()); + } else { + $length = $this->parseExpression(); + } + + $class = $this->getFilterNodeClass('slice', $token->getLine()); + $arguments = new Node([$arg, $length]); + $filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine()); + + $stream->expect(Token::PUNCTUATION_TYPE, ']'); + + return $filter; + } + + $stream->expect(Token::PUNCTUATION_TYPE, ']'); + } + + return new GetAttrExpression($node, $arg, $arguments, $type, $lineno); + } + + public function parseFilterExpression($node) + { + $this->parser->getStream()->next(); + + return $this->parseFilterExpressionRaw($node); + } + + public function parseFilterExpressionRaw($node, $tag = null) + { + while (true) { + $token = $this->parser->getStream()->expect(Token::NAME_TYPE); + + $name = new ConstantExpression($token->getValue(), $token->getLine()); + if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) { + $arguments = new Node(); + } else { + $arguments = $this->parseArguments(true, false, true); + } + + $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine()); + + $node = new $class($node, $name, $arguments, $token->getLine(), $tag); + + if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '|')) { + break; + } + + $this->parser->getStream()->next(); + } + + return $node; + } + + /** + * Parses arguments. + * + * @param bool $namedArguments Whether to allow named arguments or not + * @param bool $definition Whether we are parsing arguments for a function definition + * + * @return Node + * + * @throws SyntaxError + */ + public function parseArguments($namedArguments = false, $definition = false, $allowArrow = false) + { + $args = []; + $stream = $this->parser->getStream(); + + $stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis'); + while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) { + if (!empty($args)) { + $stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma'); + } + + if ($definition) { + $token = $stream->expect(Token::NAME_TYPE, null, 'An argument must be a name'); + $value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine()); + } else { + $value = $this->parseExpression(0, $allowArrow); + } + + $name = null; + if ($namedArguments && $token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) { + if (!$value instanceof NameExpression) { + throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); + } + $name = $value->getAttribute('name'); + + if ($definition) { + $value = $this->parsePrimaryExpression(); + + if (!$this->checkConstantExpression($value)) { + 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()); + } + } else { + $value = $this->parseExpression(0, $allowArrow); + } + } + + if ($definition) { + if (null === $name) { + $name = $value->getAttribute('name'); + $value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine()); + } + $args[$name] = $value; + } else { + if (null === $name) { + $args[] = $value; + } else { + $args[$name] = $value; + } + } + } + $stream->expect(Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis'); + + return new Node($args); + } + + public function parseAssignmentExpression() + { + $stream = $this->parser->getStream(); + $targets = []; + while (true) { + $token = $this->parser->getCurrentToken(); + if ($stream->test(Token::OPERATOR_TYPE) && preg_match(Lexer::REGEX_NAME, $token->getValue())) { + // in this context, string operators are variable names + $this->parser->getStream()->next(); + } else { + $stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to'); + } + $value = $token->getValue(); + if (\in_array(strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), ['true', 'false', 'none', 'null'])) { + throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); + } + $targets[] = new AssignNameExpression($value, $token->getLine()); + + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { + break; + } + } + + return new Node($targets); + } + + public function parseMultitargetExpression() + { + $targets = []; + while (true) { + $targets[] = $this->parseExpression(); + if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) { + break; + } + } + + return new Node($targets); + } + + private function parseNotTestExpression(\Twig_NodeInterface $node) + { + return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); + } + + private function parseTestExpression(\Twig_NodeInterface $node) + { + $stream = $this->parser->getStream(); + list($name, $test) = $this->getTest($node->getTemplateLine()); + + $class = $this->getTestNodeClass($test); + $arguments = null; + if ($stream->test(Token::PUNCTUATION_TYPE, '(')) { + $arguments = $this->parseArguments(true); + } + + return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine()); + } + + private function getTest($line) + { + $stream = $this->parser->getStream(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); + + if ($test = $this->env->getTest($name)) { + return [$name, $test]; + } + + if ($stream->test(Token::NAME_TYPE)) { + // try 2-words tests + $name = $name.' '.$this->parser->getCurrentToken()->getValue(); + + if ($test = $this->env->getTest($name)) { + $stream->next(); + + return [$name, $test]; + } + } + + $e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getTests())); + + throw $e; + } + + private function getTestNodeClass($test) + { + if ($test instanceof TwigTest && $test->isDeprecated()) { + $stream = $this->parser->getStream(); + $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); + if (!\is_bool($test->getDeprecatedVersion())) { + $message .= sprintf(' since version %s', $test->getDeprecatedVersion()); + } + if ($test->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $test->getAlternative()); + } + $src = $stream->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $stream->getCurrent()->getLine()); + + @trigger_error($message, E_USER_DEPRECATED); + } + + if ($test instanceof TwigTest) { + return $test->getNodeClass(); + } + + return $test instanceof \Twig_Test_Node ? $test->getClass() : 'Twig\Node\Expression\TestExpression'; + } + + protected function getFunctionNodeClass($name, $line) + { + if (false === $function = $this->env->getFunction($name)) { + $e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getFunctions())); + + throw $e; + } + + if ($function instanceof TwigFunction && $function->isDeprecated()) { + $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); + if (!\is_bool($function->getDeprecatedVersion())) { + $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); + } + if ($function->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $function->getAlternative()); + } + $src = $this->parser->getStream()->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + + if ($function instanceof TwigFunction) { + return $function->getNodeClass(); + } + + return $function instanceof \Twig_Function_Node ? $function->getClass() : 'Twig\Node\Expression\FunctionExpression'; + } + + protected function getFilterNodeClass($name, $line) + { + if (false === $filter = $this->env->getFilter($name)) { + $e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getFilters())); + + throw $e; + } + + if ($filter instanceof TwigFilter && $filter->isDeprecated()) { + $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); + if (!\is_bool($filter->getDeprecatedVersion())) { + $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); + } + if ($filter->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); + } + $src = $this->parser->getStream()->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ? $src->getPath() : $src->getName(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + + if ($filter instanceof TwigFilter) { + return $filter->getNodeClass(); + } + + return $filter instanceof \Twig_Filter_Node ? $filter->getClass() : 'Twig\Node\Expression\FilterExpression'; + } + + // checks that the node only contains "constant" elements + protected function checkConstantExpression(\Twig_NodeInterface $node) + { + if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression + || $node instanceof NegUnary || $node instanceof PosUnary + )) { + return false; + } + + foreach ($node as $n) { + if (!$this->checkConstantExpression($n)) { + return false; + } + } + + return true; + } +} + +class_alias('Twig\ExpressionParser', 'Twig_ExpressionParser'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/AbstractExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/AbstractExtension.php new file mode 100644 index 0000000..fa3245b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/AbstractExtension.php @@ -0,0 +1,72 @@ +escapers[$strategy] = $callable; + } + + /** + * Gets all defined escapers. + * + * @return array An array of escapers + */ + public function getEscapers() + { + return $this->escapers; + } + + /** + * Sets the default format to be used by the date filter. + * + * @param string $format The default date format string + * @param string $dateIntervalFormat The default date interval format string + */ + public function setDateFormat($format = null, $dateIntervalFormat = null) + { + if (null !== $format) { + $this->dateFormats[0] = $format; + } + + if (null !== $dateIntervalFormat) { + $this->dateFormats[1] = $dateIntervalFormat; + } + } + + /** + * Gets the default format to be used by the date filter. + * + * @return array The default date format string and the default date interval format string + */ + public function getDateFormat() + { + return $this->dateFormats; + } + + /** + * Sets the default timezone to be used by the date filter. + * + * @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object + */ + public function setTimezone($timezone) + { + $this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone); + } + + /** + * Gets the default timezone to be used by the date filter. + * + * @return \DateTimeZone The default timezone currently in use + */ + public function getTimezone() + { + if (null === $this->timezone) { + $this->timezone = new \DateTimeZone(date_default_timezone_get()); + } + + return $this->timezone; + } + + /** + * Sets the default format to be used by the number_format filter. + * + * @param int $decimal the number of decimal places to use + * @param string $decimalPoint the character(s) to use for the decimal point + * @param string $thousandSep the character(s) to use for the thousands separator + */ + public function setNumberFormat($decimal, $decimalPoint, $thousandSep) + { + $this->numberFormat = [$decimal, $decimalPoint, $thousandSep]; + } + + /** + * Get the default format used by the number_format filter. + * + * @return array The arguments for number_format() + */ + public function getNumberFormat() + { + return $this->numberFormat; + } + + public function getTokenParsers() + { + return [ + new ApplyTokenParser(), + new ForTokenParser(), + new IfTokenParser(), + new ExtendsTokenParser(), + new IncludeTokenParser(), + new BlockTokenParser(), + new UseTokenParser(), + new FilterTokenParser(), + new MacroTokenParser(), + new ImportTokenParser(), + new FromTokenParser(), + new SetTokenParser(), + new SpacelessTokenParser(), + new FlushTokenParser(), + new DoTokenParser(), + new EmbedTokenParser(), + new WithTokenParser(), + new DeprecatedTokenParser(), + ]; + } + + public function getFilters() + { + $filters = [ + // formatting filters + new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), + new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), + new TwigFilter('format', 'sprintf'), + new TwigFilter('replace', 'twig_replace_filter'), + new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), + new TwigFilter('abs', 'abs'), + new TwigFilter('round', 'twig_round'), + + // encoding + new TwigFilter('url_encode', 'twig_urlencode_filter'), + new TwigFilter('json_encode', 'twig_jsonencode_filter'), + new TwigFilter('convert_encoding', 'twig_convert_encoding'), + + // string filters + new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), + new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), + new TwigFilter('upper', 'strtoupper'), + new TwigFilter('lower', 'strtolower'), + new TwigFilter('striptags', 'strip_tags'), + new TwigFilter('trim', 'twig_trim_filter'), + new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), + new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]), + + // array helpers + new TwigFilter('join', 'twig_join_filter'), + new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]), + new TwigFilter('sort', 'twig_sort_filter'), + new TwigFilter('merge', 'twig_array_merge'), + new TwigFilter('batch', 'twig_array_batch'), + new TwigFilter('filter', 'twig_array_filter'), + new TwigFilter('map', 'twig_array_map'), + new TwigFilter('reduce', 'twig_array_reduce'), + + // string/array filters + new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), + new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]), + new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]), + new TwigFilter('first', 'twig_first', ['needs_environment' => true]), + new TwigFilter('last', 'twig_last', ['needs_environment' => true]), + + // iteration and runtime + new TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']), + new TwigFilter('keys', 'twig_get_array_keys_filter'), + + // escaping + new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + ]; + + if (\function_exists('mb_get_info')) { + $filters[] = new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); + $filters[] = new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); + } + + return $filters; + } + + public function getFunctions() + { + return [ + new TwigFunction('max', 'max'), + new TwigFunction('min', 'min'), + new TwigFunction('range', 'range'), + new TwigFunction('constant', 'twig_constant'), + new TwigFunction('cycle', 'twig_cycle'), + new TwigFunction('random', 'twig_random', ['needs_environment' => true]), + new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]), + new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), + new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), + ]; + } + + public function getTests() + { + return [ + new TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']), + new TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']), + new TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']), + new TwigTest('sameas', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest', 'deprecated' => '1.21', 'alternative' => 'same as']), + new TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']), + new TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), + new TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), + new TwigTest('divisibleby', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest', 'deprecated' => '1.21', 'alternative' => 'divisible by']), + new TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']), + new TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']), + new TwigTest('empty', 'twig_test_empty'), + new TwigTest('iterable', 'twig_test_iterable'), + ]; + } + + public function getOperators() + { + return [ + [ + 'not' => ['precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'], + '-' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\NegUnary'], + '+' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\PosUnary'], + ], + [ + 'or' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'and' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-or' => ['precedence' => 16, 'class' => '\Twig\Node\Expression\Binary\BitwiseOrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-xor' => ['precedence' => 17, 'class' => '\Twig\Node\Expression\Binary\BitwiseXorBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-and' => ['precedence' => 18, 'class' => '\Twig\Node\Expression\Binary\BitwiseAndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '==' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '!=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'not in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotInBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\InBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'matches' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\MatchesBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'starts with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\StartsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'ends with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EndsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '..' => ['precedence' => 25, 'class' => '\Twig\Node\Expression\Binary\RangeBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '+' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\AddBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '-' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\SubBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '~' => ['precedence' => 40, 'class' => '\Twig\Node\Expression\Binary\ConcatBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '*' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\MulBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '/' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\DivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '//' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\FloorDivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '%' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '**' => ['precedence' => 200, 'class' => '\Twig\Node\Expression\Binary\PowerBinary', 'associativity' => ExpressionParser::OPERATOR_RIGHT], + '??' => ['precedence' => 300, 'class' => '\Twig\Node\Expression\NullCoalesceExpression', 'associativity' => ExpressionParser::OPERATOR_RIGHT], + ], + ]; + } + + public function getName() + { + return 'core'; + } +} + +class_alias('Twig\Extension\CoreExtension', 'Twig_Extension_Core'); +} + +namespace { +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Markup; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; + +/** + * Cycles over a value. + * + * @param \ArrayAccess|array $values + * @param int $position The cycle position + * + * @return string The next value in the cycle + */ +function twig_cycle($values, $position) +{ + if (!\is_array($values) && !$values instanceof \ArrayAccess) { + return $values; + } + + return $values[$position % \count($values)]; +} + +/** + * Returns a random value depending on the supplied parameter type: + * - a random item from a \Traversable or array + * - a random character from a string + * - a random integer between 0 and the integer parameter. + * + * @param \Traversable|array|int|float|string $values The values to pick a random item from + * @param int|null $max Maximum value used when $values is an int + * + * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) + * + * @return mixed A random value from the given sequence + */ +function twig_random(Environment $env, $values = null, $max = null) +{ + if (null === $values) { + return null === $max ? mt_rand() : mt_rand(0, $max); + } + + if (\is_int($values) || \is_float($values)) { + if (null === $max) { + if ($values < 0) { + $max = 0; + $min = $values; + } else { + $max = $values; + $min = 0; + } + } else { + $min = $values; + $max = $max; + } + + return mt_rand($min, $max); + } + + if (\is_string($values)) { + if ('' === $values) { + return ''; + } + if (null !== $charset = $env->getCharset()) { + if ('UTF-8' !== $charset) { + $values = twig_convert_encoding($values, 'UTF-8', $charset); + } + + // unicode version of str_split() + // split at all positions, but not after the start and not before the end + $values = preg_split('/(? $value) { + $values[$i] = twig_convert_encoding($value, $charset, 'UTF-8'); + } + } + } else { + return $values[mt_rand(0, \strlen($values) - 1)]; + } + } + + if (!twig_test_iterable($values)) { + return $values; + } + + $values = twig_to_array($values); + + if (0 === \count($values)) { + throw new RuntimeError('The random function cannot pick from an empty array.'); + } + + return $values[array_rand($values, 1)]; +} + +/** + * Converts a date to the given format. + * + * {{ post.published_at|date("m/d/Y") }} + * + * @param \DateTime|\DateTimeInterface|\DateInterval|string $date A date + * @param string|null $format The target format, null to use the default + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * + * @return string The formatted date + */ +function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null) +{ + if (null === $format) { + $formats = $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat(); + $format = $date instanceof \DateInterval ? $formats[1] : $formats[0]; + } + + if ($date instanceof \DateInterval) { + return $date->format($format); + } + + return twig_date_converter($env, $date, $timezone)->format($format); +} + +/** + * Returns a new date object modified. + * + * {{ post.published_at|date_modify("-1day")|date("m/d/Y") }} + * + * @param \DateTime|string $date A date + * @param string $modifier A modifier string + * + * @return \DateTime + */ +function twig_date_modify_filter(Environment $env, $date, $modifier) +{ + $date = twig_date_converter($env, $date, false); + $resultDate = $date->modify($modifier); + + // This is a hack to ensure PHP 5.2 support and support for \DateTimeImmutable + // \DateTime::modify does not return the modified \DateTime object < 5.3.0 + // and \DateTimeImmutable does not modify $date. + return null === $resultDate ? $date : $resultDate; +} + +/** + * Converts an input to a \DateTime instance. + * + * {% if date(user.created_at) < date('+2days') %} + * {# do something #} + * {% endif %} + * + * @param \DateTime|\DateTimeInterface|string|null $date A date + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * + * @return \DateTimeInterface + */ +function twig_date_converter(Environment $env, $date = null, $timezone = null) +{ + // determine the timezone + if (false !== $timezone) { + if (null === $timezone) { + $timezone = $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone(); + } elseif (!$timezone instanceof \DateTimeZone) { + $timezone = new \DateTimeZone($timezone); + } + } + + // immutable dates + if ($date instanceof \DateTimeImmutable) { + return false !== $timezone ? $date->setTimezone($timezone) : $date; + } + + if ($date instanceof \DateTime || $date instanceof \DateTimeInterface) { + $date = clone $date; + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; + } + + if (null === $date || 'now' === $date) { + return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone()); + } + + $asString = (string) $date; + if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { + $date = new \DateTime('@'.$date); + } else { + $date = new \DateTime($date, $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone()); + } + + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; +} + +/** + * Replaces strings within a string. + * + * @param string $str String to replace in + * @param array|\Traversable $from Replace values + * @param string|null $to Replace to, deprecated (@see https://secure.php.net/manual/en/function.strtr.php) + * + * @return string + */ +function twig_replace_filter($str, $from, $to = null) +{ + if (\is_string($from) && \is_string($to)) { + @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); + + return strtr($str, $from, $to); + } + + if (!twig_test_iterable($from)) { + 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))); + } + + return strtr($str, twig_to_array($from)); +} + +/** + * Rounds a number. + * + * @param int|float $value The value to round + * @param int|float $precision The rounding precision + * @param string $method The method to use for rounding + * + * @return int|float The rounded number + */ +function twig_round($value, $precision = 0, $method = 'common') +{ + if ('common' == $method) { + return round($value, $precision); + } + + if ('ceil' != $method && 'floor' != $method) { + throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); + } + + return $method($value * pow(10, $precision)) / pow(10, $precision); +} + +/** + * Number format filter. + * + * All of the formatting options can be left null, in that case the defaults will + * be used. Supplying any of the parameters will override the defaults set in the + * environment object. + * + * @param mixed $number A float/int/string of the number to format + * @param int $decimal the number of decimal points to display + * @param string $decimalPoint the character(s) to use for the decimal point + * @param string $thousandSep the character(s) to use for the thousands separator + * + * @return string The formatted number + */ +function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) +{ + $defaults = $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat(); + if (null === $decimal) { + $decimal = $defaults[0]; + } + + if (null === $decimalPoint) { + $decimalPoint = $defaults[1]; + } + + if (null === $thousandSep) { + $thousandSep = $defaults[2]; + } + + return number_format((float) $number, $decimal, $decimalPoint, $thousandSep); +} + +/** + * URL encodes (RFC 3986) a string as a path segment or an array as a query string. + * + * @param string|array $url A URL or an array of query parameters + * + * @return string The URL encoded value + */ +function twig_urlencode_filter($url) +{ + if (\is_array($url)) { + if (\defined('PHP_QUERY_RFC3986')) { + return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + } + + return http_build_query($url, '', '&'); + } + + return rawurlencode($url); +} + +/** + * JSON encodes a variable. + * + * @param mixed $value the value to encode + * @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 + * + * @return mixed The JSON encoded value + */ +function twig_jsonencode_filter($value, $options = 0) +{ + if ($value instanceof Markup) { + $value = (string) $value; + } elseif (\is_array($value)) { + array_walk_recursive($value, '_twig_markup2string'); + } + + return json_encode($value, $options); +} + +function _twig_markup2string(&$value) +{ + if ($value instanceof Markup) { + $value = (string) $value; + } +} + +/** + * Merges an array with another one. + * + * {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %} + * + * {% set items = items|merge({ 'peugeot': 'car' }) %} + * + * {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #} + * + * @param array|\Traversable $arr1 An array + * @param array|\Traversable $arr2 An array + * + * @return array The merged array + */ +function twig_array_merge($arr1, $arr2) +{ + if (!twig_test_iterable($arr1)) { + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); + } + + if (!twig_test_iterable($arr2)) { + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); + } + + return array_merge(twig_to_array($arr1), twig_to_array($arr2)); +} + +/** + * Slices a variable. + * + * @param mixed $item A variable + * @param int $start Start of the slice + * @param int $length Size of the slice + * @param bool $preserveKeys Whether to preserve key or not (when the input is an array) + * + * @return mixed The sliced variable + */ +function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false) +{ + if ($item instanceof \Traversable) { + while ($item instanceof \IteratorAggregate) { + $item = $item->getIterator(); + } + + if ($start >= 0 && $length >= 0 && $item instanceof \Iterator) { + try { + return iterator_to_array(new \LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys); + } catch (\OutOfBoundsException $e) { + return []; + } + } + + $item = iterator_to_array($item, $preserveKeys); + } + + if (\is_array($item)) { + return \array_slice($item, $start, $length, $preserveKeys); + } + + $item = (string) $item; + + if (\function_exists('mb_get_info') && null !== $charset = $env->getCharset()) { + return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); + } + + return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length)); +} + +/** + * Returns the first element of the item. + * + * @param mixed $item A variable + * + * @return mixed The first element of the item + */ +function twig_first(Environment $env, $item) +{ + $elements = twig_slice($env, $item, 0, 1, false); + + return \is_string($elements) ? $elements : current($elements); +} + +/** + * Returns the last element of the item. + * + * @param mixed $item A variable + * + * @return mixed The last element of the item + */ +function twig_last(Environment $env, $item) +{ + $elements = twig_slice($env, $item, -1, 1, false); + + return \is_string($elements) ? $elements : current($elements); +} + +/** + * Joins the values to a string. + * + * The separators between elements are empty strings per default, you can define them with the optional parameters. + * + * {{ [1, 2, 3]|join(', ', ' and ') }} + * {# returns 1, 2 and 3 #} + * + * {{ [1, 2, 3]|join('|') }} + * {# returns 1|2|3 #} + * + * {{ [1, 2, 3]|join }} + * {# returns 123 #} + * + * @param array $value An array + * @param string $glue The separator + * @param string|null $and The separator for the last pair + * + * @return string The concatenated string + */ +function twig_join_filter($value, $glue = '', $and = null) +{ + if (!twig_test_iterable($value)) { + $value = (array) $value; + } + + $value = twig_to_array($value, false); + + if (0 === \count($value)) { + return ''; + } + + if (null === $and || $and === $glue) { + return implode($glue, $value); + } + + if (1 === \count($value)) { + return $value[0]; + } + + return implode($glue, \array_slice($value, 0, -1)).$and.$value[\count($value) - 1]; +} + +/** + * Splits the string into an array. + * + * {{ "one,two,three"|split(',') }} + * {# returns [one, two, three] #} + * + * {{ "one,two,three,four,five"|split(',', 3) }} + * {# returns [one, two, "three,four,five"] #} + * + * {{ "123"|split('') }} + * {# returns [1, 2, 3] #} + * + * {{ "aabbcc"|split('', 2) }} + * {# returns [aa, bb, cc] #} + * + * @param string $value A string + * @param string $delimiter The delimiter + * @param int $limit The limit + * + * @return array The split string as an array + */ +function twig_split_filter(Environment $env, $value, $delimiter, $limit = null) +{ + if (\strlen($delimiter) > 0) { + return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); + } + + if (!\function_exists('mb_get_info') || null === $charset = $env->getCharset()) { + return str_split($value, null === $limit ? 1 : $limit); + } + + if ($limit <= 1) { + return preg_split('/(?getIterator(); + } + + if ($array instanceof \Iterator) { + $keys = []; + $array->rewind(); + while ($array->valid()) { + $keys[] = $array->key(); + $array->next(); + } + + return $keys; + } + + $keys = []; + foreach ($array as $key => $item) { + $keys[] = $key; + } + + return $keys; + } + + if (!\is_array($array)) { + return []; + } + + return array_keys($array); +} + +/** + * Reverses a variable. + * + * @param array|\Traversable|string $item An array, a \Traversable instance, or a string + * @param bool $preserveKeys Whether to preserve key or not + * + * @return mixed The reversed input + */ +function twig_reverse_filter(Environment $env, $item, $preserveKeys = false) +{ + if ($item instanceof \Traversable) { + return array_reverse(iterator_to_array($item), $preserveKeys); + } + + if (\is_array($item)) { + return array_reverse($item, $preserveKeys); + } + + if (null !== $charset = $env->getCharset()) { + $string = (string) $item; + + if ('UTF-8' !== $charset) { + $item = twig_convert_encoding($string, 'UTF-8', $charset); + } + + preg_match_all('/./us', $item, $matches); + + $string = implode('', array_reverse($matches[0])); + + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, $charset, 'UTF-8'); + } + + return $string; + } + + return strrev((string) $item); +} + +/** + * Sorts an array. + * + * @param array|\Traversable $array + * + * @return array + */ +function twig_sort_filter($array) +{ + if ($array instanceof \Traversable) { + $array = iterator_to_array($array); + } elseif (!\is_array($array)) { + throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); + } + + asort($array); + + return $array; +} + +/** + * @internal + */ +function twig_in_filter($value, $compare) +{ + if ($value instanceof Markup) { + $value = (string) $value; + } + if ($compare instanceof Markup) { + $compare = (string) $compare; + } + + if (\is_array($compare)) { + return \in_array($value, $compare, \is_object($value) || \is_resource($value)); + } elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) { + return '' === $value || false !== strpos($compare, (string) $value); + } elseif ($compare instanceof \Traversable) { + if (\is_object($value) || \is_resource($value)) { + foreach ($compare as $item) { + if ($item === $value) { + return true; + } + } + } else { + foreach ($compare as $item) { + if ($item == $value) { + return true; + } + } + } + + return false; + } + + return false; +} + +/** + * Returns a trimmed string. + * + * @return string + * + * @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') + */ +function twig_trim_filter($string, $characterMask = null, $side = 'both') +{ + if (null === $characterMask) { + $characterMask = " \t\n\r\0\x0B"; + } + + switch ($side) { + case 'both': + return trim($string, $characterMask); + case 'left': + return ltrim($string, $characterMask); + case 'right': + return rtrim($string, $characterMask); + default: + throw new RuntimeError('Trimming side must be "left", "right" or "both".'); + } +} + +/** + * Removes whitespaces between HTML tags. + * + * @return string + */ +function twig_spaceless($content) +{ + return trim(preg_replace('/>\s+<', $content)); +} + +/** + * Escapes a string. + * + * @param mixed $string The value to be escaped + * @param string $strategy The escaping strategy + * @param string $charset The charset + * @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false) + * + * @return string + */ +function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) +{ + if ($autoescape && $string instanceof Markup) { + return $string; + } + + if (!\is_string($string)) { + if (\is_object($string) && method_exists($string, '__toString')) { + $string = (string) $string; + } elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { + return $string; + } + } + + if ('' === $string) { + return ''; + } + + if (null === $charset) { + $charset = $env->getCharset(); + } + + switch ($strategy) { + case 'html': + // see https://secure.php.net/htmlspecialchars + + // Using a static variable to avoid initializing the array + // each time the function is called. Moving the declaration on the + // top of the function slow downs other escaping strategies. + static $htmlspecialcharsCharsets = [ + 'ISO-8859-1' => true, 'ISO8859-1' => true, + 'ISO-8859-15' => true, 'ISO8859-15' => true, + 'utf-8' => true, 'UTF-8' => true, + 'CP866' => true, 'IBM866' => true, '866' => true, + 'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true, + '1251' => true, + 'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true, + 'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true, + 'BIG5' => true, '950' => true, + 'GB2312' => true, '936' => true, + 'BIG5-HKSCS' => true, + 'SHIFT_JIS' => true, 'SJIS' => true, '932' => true, + 'EUC-JP' => true, 'EUCJP' => true, + 'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true, + ]; + + if (isset($htmlspecialcharsCharsets[$charset])) { + return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + } + + if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { + // cache the lowercase variant for future iterations + $htmlspecialcharsCharsets[$charset] = true; + + return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + } + + $string = twig_convert_encoding($string, 'UTF-8', $charset); + $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); + + return twig_convert_encoding($string, $charset, 'UTF-8'); + + case 'js': + // escape all non-alphanumeric characters + // into their \x or \uHHHH representations + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string); + + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, $charset, 'UTF-8'); + } + + return $string; + + case 'css': + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string); + + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, $charset, 'UTF-8'); + } + + return $string; + + case 'html_attr': + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string); + + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, $charset, 'UTF-8'); + } + + return $string; + + case 'url': + return rawurlencode($string); + + default: + static $escapers; + + if (null === $escapers) { + $escapers = $env->getExtension('\Twig\Extension\CoreExtension')->getEscapers(); + } + + if (isset($escapers[$strategy])) { + return \call_user_func($escapers[$strategy], $env, $string, $charset); + } + + $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); + + throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); + } +} + +/** + * @internal + */ +function twig_escape_filter_is_safe(Node $filterArgs) +{ + foreach ($filterArgs as $arg) { + if ($arg instanceof ConstantExpression) { + return [$arg->getAttribute('value')]; + } + + return []; + } + + return ['html']; +} + +if (\function_exists('mb_convert_encoding')) { + function twig_convert_encoding($string, $to, $from) + { + return mb_convert_encoding($string, $to, $from); + } +} elseif (\function_exists('iconv')) { + function twig_convert_encoding($string, $to, $from) + { + return iconv($from, $to, $string); + } +} else { + function twig_convert_encoding($string, $to, $from) + { + throw new RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + } +} + +if (\function_exists('mb_ord')) { + function twig_ord($string) + { + return mb_ord($string, 'UTF-8'); + } +} else { + function twig_ord($string) + { + $code = ($string = unpack('C*', substr($string, 0, 4))) ? $string[1] : 0; + if (0xF0 <= $code) { + return (($code - 0xF0) << 18) + (($string[2] - 0x80) << 12) + (($string[3] - 0x80) << 6) + $string[4] - 0x80; + } + if (0xE0 <= $code) { + return (($code - 0xE0) << 12) + (($string[2] - 0x80) << 6) + $string[3] - 0x80; + } + if (0xC0 <= $code) { + return (($code - 0xC0) << 6) + $string[2] - 0x80; + } + + return $code; + } +} + +function _twig_escape_js_callback($matches) +{ + $char = $matches[0]; + + /* + * A few characters have short escape sequences in JSON and JavaScript. + * Escape sequences supported only by JavaScript, not JSON, are ommitted. + * \" is also supported but omitted, because the resulting string is not HTML safe. + */ + static $shortMap = [ + '\\' => '\\\\', + '/' => '\\/', + "\x08" => '\b', + "\x0C" => '\f', + "\x0A" => '\n', + "\x0D" => '\r', + "\x09" => '\t', + ]; + + if (isset($shortMap[$char])) { + return $shortMap[$char]; + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + $char = strtoupper(bin2hex($char)); + + if (4 >= \strlen($char)) { + return sprintf('\u%04s', $char); + } + + return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4)); +} + +function _twig_escape_css_callback($matches) +{ + $char = $matches[0]; + + return sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : twig_ord($char)); +} + +/** + * This function is adapted from code coming from Zend Framework. + * + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com) + * @license https://framework.zend.com/license/new-bsd New BSD License + */ +function _twig_escape_html_attr_callback($matches) +{ + $chr = $matches[0]; + $ord = \ord($chr); + + /* + * The following replaces characters undefined in HTML with the + * hex entity for the Unicode replacement character. + */ + if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) { + return '�'; + } + + /* + * Check if the current character to escape has a name entity we should + * replace it with while grabbing the hex value of the character. + */ + if (1 == \strlen($chr)) { + /* + * While HTML supports far more named entities, the lowest common denominator + * has become HTML5's XML Serialisation which is restricted to the those named + * entities that XML supports. Using HTML entities would result in this error: + * XML Parsing Error: undefined entity + */ + static $entityMap = [ + 34 => '"', /* quotation mark */ + 38 => '&', /* ampersand */ + 60 => '<', /* less-than sign */ + 62 => '>', /* greater-than sign */ + ]; + + if (isset($entityMap[$ord])) { + return $entityMap[$ord]; + } + + return sprintf('&#x%02X;', $ord); + } + + /* + * Per OWASP recommendations, we'll use hex entities for any other + * characters where a named entity does not exist. + */ + return sprintf('&#x%04X;', twig_ord($chr)); +} + +// add multibyte extensions if possible +if (\function_exists('mb_get_info')) { + /** + * Returns the length of a variable. + * + * @param mixed $thing A variable + * + * @return int The length of the value + */ + function twig_length_filter(Environment $env, $thing) + { + if (null === $thing) { + return 0; + } + + if (is_scalar($thing)) { + return mb_strlen($thing, $env->getCharset()); + } + + if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) { + return \count($thing); + } + + if ($thing instanceof \Traversable) { + return iterator_count($thing); + } + + if (\is_object($thing) && method_exists($thing, '__toString')) { + return mb_strlen((string) $thing, $env->getCharset()); + } + + return 1; + } + + /** + * Converts a string to uppercase. + * + * @param string $string A string + * + * @return string The uppercased string + */ + function twig_upper_filter(Environment $env, $string) + { + if (null !== $charset = $env->getCharset()) { + return mb_strtoupper($string, $charset); + } + + return strtoupper($string); + } + + /** + * Converts a string to lowercase. + * + * @param string $string A string + * + * @return string The lowercased string + */ + function twig_lower_filter(Environment $env, $string) + { + if (null !== $charset = $env->getCharset()) { + return mb_strtolower($string, $charset); + } + + return strtolower($string); + } + + /** + * Returns a titlecased string. + * + * @param string $string A string + * + * @return string The titlecased string + */ + function twig_title_string_filter(Environment $env, $string) + { + if (null !== $charset = $env->getCharset()) { + return mb_convert_case($string, MB_CASE_TITLE, $charset); + } + + return ucwords(strtolower($string)); + } + + /** + * Returns a capitalized string. + * + * @param string $string A string + * + * @return string The capitalized string + */ + function twig_capitalize_string_filter(Environment $env, $string) + { + if (null !== $charset = $env->getCharset()) { + return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset); + } + + return ucfirst(strtolower($string)); + } +} +// and byte fallback +else { + /** + * Returns the length of a variable. + * + * @param mixed $thing A variable + * + * @return int The length of the value + */ + function twig_length_filter(Environment $env, $thing) + { + if (null === $thing) { + return 0; + } + + if (is_scalar($thing)) { + return \strlen($thing); + } + + if ($thing instanceof \SimpleXMLElement) { + return \count($thing); + } + + if (\is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { + return \strlen((string) $thing); + } + + if ($thing instanceof \Countable || \is_array($thing)) { + return \count($thing); + } + + if ($thing instanceof \IteratorAggregate) { + return iterator_count($thing); + } + + return 1; + } + + /** + * Returns a titlecased string. + * + * @param string $string A string + * + * @return string The titlecased string + */ + function twig_title_string_filter(Environment $env, $string) + { + return ucwords(strtolower($string)); + } + + /** + * Returns a capitalized string. + * + * @param string $string A string + * + * @return string The capitalized string + */ + function twig_capitalize_string_filter(Environment $env, $string) + { + return ucfirst(strtolower($string)); + } +} + +/** + * @internal + */ +function twig_ensure_traversable($seq) +{ + if ($seq instanceof \Traversable || \is_array($seq)) { + return $seq; + } + + return []; +} + +/** + * @internal + */ +function twig_to_array($seq, $preserveKeys = true) +{ + if ($seq instanceof \Traversable) { + return iterator_to_array($seq, $preserveKeys); + } + + if (!\is_array($seq)) { + return $seq; + } + + return $preserveKeys ? $seq : array_values($seq); +} + +/** + * Checks if a variable is empty. + * + * {# evaluates to true if the foo variable is null, false, or the empty string #} + * {% if foo is empty %} + * {# ... #} + * {% endif %} + * + * @param mixed $value A variable + * + * @return bool true if the value is empty, false otherwise + */ +function twig_test_empty($value) +{ + if ($value instanceof \Countable) { + return 0 == \count($value); + } + + if ($value instanceof \Traversable) { + return !iterator_count($value); + } + + if (\is_object($value) && method_exists($value, '__toString')) { + return '' === (string) $value; + } + + return '' === $value || false === $value || null === $value || [] === $value; +} + +/** + * Checks if a variable is traversable. + * + * {# evaluates to true if the foo variable is an array or a traversable object #} + * {% if foo is iterable %} + * {# ... #} + * {% endif %} + * + * @param mixed $value A variable + * + * @return bool true if the value is traversable + */ +function twig_test_iterable($value) +{ + return $value instanceof \Traversable || \is_array($value); +} + +/** + * Renders a template. + * + * @param array $context + * @param string|array $template The template to render or an array of templates to try consecutively + * @param array $variables The variables to pass to the template + * @param bool $withContext + * @param bool $ignoreMissing Whether to ignore missing templates or not + * @param bool $sandboxed Whether to sandbox the template or not + * + * @return string The rendered template + */ +function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) +{ + $alreadySandboxed = false; + $sandbox = null; + if ($withContext) { + $variables = array_merge($context, $variables); + } + + if ($isSandboxed = $sandboxed && $env->hasExtension('\Twig\Extension\SandboxExtension')) { + $sandbox = $env->getExtension('\Twig\Extension\SandboxExtension'); + if (!$alreadySandboxed = $sandbox->isSandboxed()) { + $sandbox->enableSandbox(); + } + } + + $loaded = null; + try { + $loaded = $env->resolveTemplate($template); + } catch (LoaderError $e) { + if (!$ignoreMissing) { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + + throw $e; + } + } catch (\Throwable $e) { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + + throw $e; + } catch (\Exception $e) { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + + throw $e; + } + + try { + $ret = $loaded ? $loaded->render($variables) : ''; + } catch (\Exception $e) { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + + throw $e; + } + + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + + return $ret; +} + +/** + * Returns a template content without rendering it. + * + * @param string $name The template name + * @param bool $ignoreMissing Whether to ignore missing templates or not + * + * @return string The template source + */ +function twig_source(Environment $env, $name, $ignoreMissing = false) +{ + $loader = $env->getLoader(); + try { + if (!$loader instanceof SourceContextLoaderInterface) { + return $loader->getSource($name); + } else { + return $loader->getSourceContext($name)->getCode(); + } + } catch (LoaderError $e) { + if (!$ignoreMissing) { + throw $e; + } + } +} + +/** + * Provides the ability to get constants from instances as well as class/global constants. + * + * @param string $constant The name of the constant + * @param object|null $object The object to get the constant from + * + * @return string + */ +function twig_constant($constant, $object = null) +{ + if (null !== $object) { + $constant = \get_class($object).'::'.$constant; + } + + return \constant($constant); +} + +/** + * Checks if a constant exists. + * + * @param string $constant The name of the constant + * @param object|null $object The object to get the constant from + * + * @return bool + */ +function twig_constant_is_defined($constant, $object = null) +{ + if (null !== $object) { + $constant = \get_class($object).'::'.$constant; + } + + return \defined($constant); +} + +/** + * Batches item. + * + * @param array $items An array of items + * @param int $size The size of the batch + * @param mixed $fill A value used to fill missing items + * + * @return array + */ +function twig_array_batch($items, $size, $fill = null, $preserveKeys = true) +{ + if (!twig_test_iterable($items)) { + throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); + } + + $size = ceil($size); + + $result = array_chunk(twig_to_array($items, $preserveKeys), $size, $preserveKeys); + + if (null !== $fill && $result) { + $last = \count($result) - 1; + if ($fillCount = $size - \count($result[$last])) { + for ($i = 0; $i < $fillCount; ++$i) { + $result[$last][] = $fill; + } + } + } + + return $result; +} + +function twig_array_filter($array, $arrow) +{ + if (\is_array($array)) { + if (\PHP_VERSION_ID >= 50600) { + return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH); + } + + return array_filter($array, $arrow); + } + + // the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator + return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow); +} + +function twig_array_map($array, $arrow) +{ + $r = []; + foreach ($array as $k => $v) { + $r[$k] = $arrow($v, $k); + } + + return $r; +} + +function twig_array_reduce($array, $arrow, $initial = null) +{ + if (!\is_array($array)) { + $array = iterator_to_array($array); + } + + return array_reduce($array, $arrow, $initial); +} +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/DebugExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/DebugExtension.php new file mode 100644 index 0000000..09b0223 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/DebugExtension.php @@ -0,0 +1,76 @@ + $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]), + ]; + } + + public function getName() + { + return 'debug'; + } +} + +class_alias('Twig\Extension\DebugExtension', 'Twig_Extension_Debug'); +} + +namespace { +use Twig\Environment; +use Twig\Template; +use Twig\TemplateWrapper; + +function twig_var_dump(Environment $env, $context, array $vars = []) +{ + if (!$env->isDebug()) { + return; + } + + ob_start(); + + if (!$vars) { + $vars = []; + foreach ($context as $key => $value) { + if (!$value instanceof Template && !$value instanceof TemplateWrapper) { + $vars[$key] = $value; + } + } + + var_dump($vars); + } else { + foreach ($vars as $var) { + var_dump($var); + } + } + + return ob_get_clean(); +} +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/EscaperExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/EscaperExtension.php new file mode 100644 index 0000000..fc7f6df --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/EscaperExtension.php @@ -0,0 +1,120 @@ +setDefaultStrategy($defaultStrategy); + } + + public function getTokenParsers() + { + return [new AutoEscapeTokenParser()]; + } + + public function getNodeVisitors() + { + return [new EscaperNodeVisitor()]; + } + + public function getFilters() + { + return [ + new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), + ]; + } + + /** + * Sets the default strategy to use when not defined by the user. + * + * The strategy can be a valid PHP callback that takes the template + * name as an argument and returns the strategy to use. + * + * @param string|false|callable $defaultStrategy An escaping strategy + */ + public function setDefaultStrategy($defaultStrategy) + { + // for BC + if (true === $defaultStrategy) { + @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED); + + $defaultStrategy = 'html'; + } + + if ('filename' === $defaultStrategy) { + @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED); + + $defaultStrategy = 'name'; + } + + if ('name' === $defaultStrategy) { + $defaultStrategy = ['\Twig\FileExtensionEscapingStrategy', 'guess']; + } + + $this->defaultStrategy = $defaultStrategy; + } + + /** + * Gets the default strategy to use when not defined by the user. + * + * @param string $name The template name + * + * @return string|false The default strategy to use for the template + */ + public function getDefaultStrategy($name) + { + // disable string callables to avoid calling a function named html or js, + // or any other upcoming escaping strategy + if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { + return \call_user_func($this->defaultStrategy, $name); + } + + return $this->defaultStrategy; + } + + public function getName() + { + return 'escaper'; + } +} + +class_alias('Twig\Extension\EscaperExtension', 'Twig_Extension_Escaper'); +} + +namespace { +/** + * Marks a variable as being safe. + * + * @param string $string A PHP variable + * + * @return string + */ +function twig_raw_filter($string) +{ + return $string; +} +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ExtensionInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ExtensionInterface.php new file mode 100644 index 0000000..72b31e9 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ExtensionInterface.php @@ -0,0 +1,101 @@ + + */ +interface ExtensionInterface +{ + /** + * Initializes the runtime environment. + * + * This is where you can load some file that contains filter functions for instance. + * + * @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead + */ + public function initRuntime(Environment $environment); + + /** + * Returns the token parser instances to add to the existing list. + * + * @return TokenParserInterface[] + */ + public function getTokenParsers(); + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return NodeVisitorInterface[] + */ + public function getNodeVisitors(); + + /** + * Returns a list of filters to add to the existing list. + * + * @return TwigFilter[] + */ + public function getFilters(); + + /** + * Returns a list of tests to add to the existing list. + * + * @return TwigTest[] + */ + public function getTests(); + + /** + * Returns a list of functions to add to the existing list. + * + * @return TwigFunction[] + */ + public function getFunctions(); + + /** + * Returns a list of operators to add to the existing list. + * + * @return array First array of unary operators, second array of binary operators + */ + public function getOperators(); + + /** + * Returns a list of global variables to add to the existing list. + * + * @return array An array of global variables + * + * @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead + */ + public function getGlobals(); + + /** + * Returns the name of the extension. + * + * @return string The extension name + * + * @deprecated since 1.26 (to be removed in 2.0), not used anymore internally + */ + public function getName(); +} + +class_alias('Twig\Extension\ExtensionInterface', 'Twig_ExtensionInterface'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Environment'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/GlobalsInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/GlobalsInterface.php new file mode 100644 index 0000000..1f54e25 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/GlobalsInterface.php @@ -0,0 +1,26 @@ + + */ +interface GlobalsInterface +{ +} + +class_alias('Twig\Extension\GlobalsInterface', 'Twig_Extension_GlobalsInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/InitRuntimeInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/InitRuntimeInterface.php new file mode 100644 index 0000000..f71d9cb --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/InitRuntimeInterface.php @@ -0,0 +1,26 @@ + + */ +interface InitRuntimeInterface +{ +} + +class_alias('Twig\Extension\InitRuntimeInterface', 'Twig_Extension_InitRuntimeInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/OptimizerExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/OptimizerExtension.php new file mode 100644 index 0000000..3e13740 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/OptimizerExtension.php @@ -0,0 +1,39 @@ +optimizers = $optimizers; + } + + public function getNodeVisitors() + { + return [new OptimizerNodeVisitor($this->optimizers)]; + } + + public function getName() + { + return 'optimizer'; + } +} + +class_alias('Twig\Extension\OptimizerExtension', 'Twig_Extension_Optimizer'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ProfilerExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ProfilerExtension.php new file mode 100644 index 0000000..7b21b9f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/ProfilerExtension.php @@ -0,0 +1,53 @@ +actives[] = $profile; + } + + public function enter(Profile $profile) + { + $this->actives[0]->addProfile($profile); + array_unshift($this->actives, $profile); + } + + public function leave(Profile $profile) + { + $profile->leave(); + array_shift($this->actives); + + if (1 === \count($this->actives)) { + $this->actives[0]->leave(); + } + } + + public function getNodeVisitors() + { + return [new ProfilerNodeVisitor(\get_class($this))]; + } + + public function getName() + { + return 'profiler'; + } +} + +class_alias('Twig\Extension\ProfilerExtension', 'Twig_Extension_Profiler'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/RuntimeExtensionInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/RuntimeExtensionInterface.php new file mode 100644 index 0000000..63bc3b1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/RuntimeExtensionInterface.php @@ -0,0 +1,19 @@ + + */ +interface RuntimeExtensionInterface +{ +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/SandboxExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/SandboxExtension.php new file mode 100644 index 0000000..818c8c9 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/SandboxExtension.php @@ -0,0 +1,109 @@ +policy = $policy; + $this->sandboxedGlobally = $sandboxed; + } + + public function getTokenParsers() + { + return [new SandboxTokenParser()]; + } + + public function getNodeVisitors() + { + return [new SandboxNodeVisitor()]; + } + + public function enableSandbox() + { + $this->sandboxed = true; + } + + public function disableSandbox() + { + $this->sandboxed = false; + } + + public function isSandboxed() + { + return $this->sandboxedGlobally || $this->sandboxed; + } + + public function isSandboxedGlobally() + { + return $this->sandboxedGlobally; + } + + public function setSecurityPolicy(SecurityPolicyInterface $policy) + { + $this->policy = $policy; + } + + public function getSecurityPolicy() + { + return $this->policy; + } + + public function checkSecurity($tags, $filters, $functions) + { + if ($this->isSandboxed()) { + $this->policy->checkSecurity($tags, $filters, $functions); + } + } + + public function checkMethodAllowed($obj, $method) + { + if ($this->isSandboxed()) { + $this->policy->checkMethodAllowed($obj, $method); + } + } + + public function checkPropertyAllowed($obj, $method) + { + if ($this->isSandboxed()) { + $this->policy->checkPropertyAllowed($obj, $method); + } + } + + public function ensureToStringAllowed($obj) + { + if ($this->isSandboxed() && \is_object($obj) && method_exists($obj, '__toString')) { + $this->policy->checkMethodAllowed($obj, '__toString'); + } + + return $obj; + } + + public function getName() + { + return 'sandbox'; + } +} + +class_alias('Twig\Extension\SandboxExtension', 'Twig_Extension_Sandbox'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StagingExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StagingExtension.php new file mode 100644 index 0000000..049c5c7 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StagingExtension.php @@ -0,0 +1,117 @@ + + * + * @internal + */ +class StagingExtension extends AbstractExtension +{ + protected $functions = []; + protected $filters = []; + protected $visitors = []; + protected $tokenParsers = []; + protected $globals = []; + protected $tests = []; + + public function addFunction($name, $function) + { + if (isset($this->functions[$name])) { + @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); + } + + $this->functions[$name] = $function; + } + + public function getFunctions() + { + return $this->functions; + } + + public function addFilter($name, $filter) + { + if (isset($this->filters[$name])) { + @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); + } + + $this->filters[$name] = $filter; + } + + public function getFilters() + { + return $this->filters; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + $this->visitors[] = $visitor; + } + + public function getNodeVisitors() + { + return $this->visitors; + } + + public function addTokenParser(TokenParserInterface $parser) + { + if (isset($this->tokenParsers[$parser->getTag()])) { + @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); + } + + $this->tokenParsers[$parser->getTag()] = $parser; + } + + public function getTokenParsers() + { + return $this->tokenParsers; + } + + public function addGlobal($name, $value) + { + $this->globals[$name] = $value; + } + + public function getGlobals() + { + return $this->globals; + } + + public function addTest($name, $test) + { + if (isset($this->tests[$name])) { + @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); + } + + $this->tests[$name] = $test; + } + + public function getTests() + { + return $this->tests; + } + + public function getName() + { + return 'staging'; + } +} + +class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StringLoaderExtension.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StringLoaderExtension.php new file mode 100644 index 0000000..93ac834 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Extension/StringLoaderExtension.php @@ -0,0 +1,54 @@ + true]), + ]; + } + + public function getName() + { + return 'string_loader'; + } +} + +class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader'); +} + +namespace { +use Twig\Environment; +use Twig\TemplateWrapper; + +/** + * Loads a template from a string. + * + * {{ include(template_from_string("Hello {{ name }}")) }} + * + * @param string $template A template as a string or object implementing __toString() + * @param string $name An optional name of the template to be used in error messages + * + * @return TemplateWrapper + */ +function twig_template_from_string(Environment $env, $template, $name = null) +{ + return $env->createTemplate((string) $template, $name); +} +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/FileExtensionEscapingStrategy.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/FileExtensionEscapingStrategy.php new file mode 100644 index 0000000..bc95f33 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/FileExtensionEscapingStrategy.php @@ -0,0 +1,62 @@ + + */ +class FileExtensionEscapingStrategy +{ + /** + * Guesses the best autoescaping strategy based on the file name. + * + * @param string $name The template name + * + * @return string|false The escaping strategy name to use or false to disable + */ + public static function guess($name) + { + if (\in_array(substr($name, -1), ['/', '\\'])) { + return 'html'; // return html for directories + } + + if ('.twig' === substr($name, -5)) { + $name = substr($name, 0, -5); + } + + $extension = pathinfo($name, PATHINFO_EXTENSION); + + switch ($extension) { + case 'js': + return 'js'; + + case 'css': + return 'css'; + + case 'txt': + return false; + + default: + return 'html'; + } + } +} + +class_alias('Twig\FileExtensionEscapingStrategy', 'Twig_FileExtensionEscapingStrategy'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Lexer.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Lexer.php new file mode 100644 index 0000000..697a6cf --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Lexer.php @@ -0,0 +1,534 @@ + + */ +class Lexer implements \Twig_LexerInterface +{ + protected $tokens; + protected $code; + protected $cursor; + protected $lineno; + protected $end; + protected $state; + protected $states; + protected $brackets; + protected $env; + // to be renamed to $name in 2.0 (where it is private) + protected $filename; + protected $options; + protected $regexes; + protected $position; + protected $positions; + protected $currentVarBlockLine; + + private $source; + + const STATE_DATA = 0; + const STATE_BLOCK = 1; + const STATE_VAR = 2; + const STATE_STRING = 3; + const STATE_INTERPOLATION = 4; + + const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; + const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; + const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; + const REGEX_DQ_STRING_DELIM = '/"/A'; + const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; + const PUNCTUATION = '()[]{}?:.,|'; + + public function __construct(Environment $env, array $options = []) + { + $this->env = $env; + + $this->options = array_merge([ + 'tag_comment' => ['{#', '#}'], + 'tag_block' => ['{%', '%}'], + 'tag_variable' => ['{{', '}}'], + 'whitespace_trim' => '-', + 'whitespace_line_trim' => '~', + 'whitespace_line_chars' => ' \t\0\x0B', + 'interpolation' => ['#{', '}'], + ], $options); + + // when PHP 7.3 is the min version, we will be able to remove the '#' part in preg_quote as it's part of the default + $this->regexes = [ + // }} + 'lex_var' => '{ + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '#').'\s*'. // -}}\s* + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_variable'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~}}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_variable'][1], '#'). // }} + ') + }Ax', + + // %} + 'lex_block' => '{ + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*\n?'. // -%}\s*\n? + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#').'\n?'. // %}\n? + ') + }Ax', + + // {% endverbatim %} + 'lex_raw_data' => '{'. + preg_quote($this->options['tag_block'][0], '#'). // {% + '('. + $this->options['whitespace_trim']. // - + '|'. + $this->options['whitespace_line_trim']. // ~ + ')?\s*'. + '(?:end%s)'. // endraw or endverbatim + '\s*'. + '(?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%} + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#'). // %} + ') + }sx', + + 'operator' => $this->getOperatorRegex(), + + // #} + 'lex_comment' => '{ + (?:'. + preg_quote($this->options['whitespace_trim']).preg_quote($this->options['tag_comment'][1], '#').'\s*\n?'. // -#}\s*\n? + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_comment'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~#}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_comment'][1], '#').'\n?'. // #}\n? + ') + }sx', + + // verbatim %} + 'lex_block_raw' => '{ + \s* + (raw|verbatim) + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}\s* + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#'). // %} + ') + }Asx', + + 'lex_block_line' => '{\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '#').'}As', + + // {{ or {% or {# + 'lex_tokens_start' => '{ + ('. + preg_quote($this->options['tag_variable'][0], '#'). // {{ + '|'. + preg_quote($this->options['tag_block'][0], '#'). // {% + '|'. + preg_quote($this->options['tag_comment'][0], '#'). // {# + ')('. + preg_quote($this->options['whitespace_trim'], '#'). // - + '|'. + preg_quote($this->options['whitespace_line_trim'], '#'). // ~ + ')? + }sx', + 'interpolation_start' => '{'.preg_quote($this->options['interpolation'][0], '#').'\s*}A', + 'interpolation_end' => '{\s*'.preg_quote($this->options['interpolation'][1], '#').'}A', + ]; + } + + public function tokenize($code, $name = null) + { + if (!$code instanceof Source) { + @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + $this->source = new Source($code, $name); + } else { + $this->source = $code; + } + + if (((int) ini_get('mbstring.func_overload')) & 2) { + @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); + } + + if (\function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + $mbEncoding = mb_internal_encoding(); + mb_internal_encoding('ASCII'); + } else { + $mbEncoding = null; + } + + $this->code = str_replace(["\r\n", "\r"], "\n", $this->source->getCode()); + $this->filename = $this->source->getName(); + $this->cursor = 0; + $this->lineno = 1; + $this->end = \strlen($this->code); + $this->tokens = []; + $this->state = self::STATE_DATA; + $this->states = []; + $this->brackets = []; + $this->position = -1; + + // find all token starts in one go + preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); + $this->positions = $matches; + + while ($this->cursor < $this->end) { + // dispatch to the lexing functions depending + // on the current state + switch ($this->state) { + case self::STATE_DATA: + $this->lexData(); + break; + + case self::STATE_BLOCK: + $this->lexBlock(); + break; + + case self::STATE_VAR: + $this->lexVar(); + break; + + case self::STATE_STRING: + $this->lexString(); + break; + + case self::STATE_INTERPOLATION: + $this->lexInterpolation(); + break; + } + } + + $this->pushToken(Token::EOF_TYPE); + + if (!empty($this->brackets)) { + list($expect, $lineno) = array_pop($this->brackets); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + + if ($mbEncoding) { + mb_internal_encoding($mbEncoding); + } + + return new TokenStream($this->tokens, $this->source); + } + + protected function lexData() + { + // if no matches are left we return the rest of the template as simple text token + if ($this->position == \count($this->positions[0]) - 1) { + $this->pushToken(Token::TEXT_TYPE, substr($this->code, $this->cursor)); + $this->cursor = $this->end; + + return; + } + + // Find the first token after the current cursor + $position = $this->positions[0][++$this->position]; + while ($position[1] < $this->cursor) { + if ($this->position == \count($this->positions[0]) - 1) { + return; + } + $position = $this->positions[0][++$this->position]; + } + + // push the template text first + $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor); + + // trim? + if (isset($this->positions[2][$this->position][0])) { + if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) { + // whitespace_trim detected ({%-, {{- or {#-) + $text = rtrim($text); + } elseif ($this->options['whitespace_line_trim'] === $this->positions[2][$this->position][0]) { + // whitespace_line_trim detected ({%~, {{~ or {#~) + // don't trim \r and \n + $text = rtrim($text, " \t\0\x0B"); + } + } + $this->pushToken(Token::TEXT_TYPE, $text); + $this->moveCursor($textContent.$position[0]); + + switch ($this->positions[1][$this->position][0]) { + case $this->options['tag_comment'][0]: + $this->lexComment(); + break; + + case $this->options['tag_block'][0]: + // raw data? + if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + $this->lexRawData($match[1]); + // {% line \d+ %} + } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + $this->lineno = (int) $match[1]; + } else { + $this->pushToken(Token::BLOCK_START_TYPE); + $this->pushState(self::STATE_BLOCK); + $this->currentVarBlockLine = $this->lineno; + } + break; + + case $this->options['tag_variable'][0]: + $this->pushToken(Token::VAR_START_TYPE); + $this->pushState(self::STATE_VAR); + $this->currentVarBlockLine = $this->lineno; + break; + } + } + + protected function lexBlock() + { + if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(Token::BLOCK_END_TYPE); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + protected function lexVar() + { + if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(Token::VAR_END_TYPE); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + protected function lexExpression() + { + // whitespace + if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + + if ($this->cursor >= $this->end) { + throw new SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); + } + } + + // arrow function + if ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) { + $this->pushToken(Token::ARROW_TYPE, '=>'); + $this->moveCursor('=>'); + } + // operators + elseif (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0])); + $this->moveCursor($match[0]); + } + // names + elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) { + $this->pushToken(Token::NAME_TYPE, $match[0]); + $this->moveCursor($match[0]); + } + // numbers + elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) { + $number = (float) $match[0]; // floats + if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { + $number = (int) $match[0]; // integers lower than the maximum + } + $this->pushToken(Token::NUMBER_TYPE, $number); + $this->moveCursor($match[0]); + } + // punctuation + elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) { + // opening bracket + if (false !== strpos('([{', $this->code[$this->cursor])) { + $this->brackets[] = [$this->code[$this->cursor], $this->lineno]; + } + // closing bracket + elseif (false !== strpos(')]}', $this->code[$this->cursor])) { + if (empty($this->brackets)) { + throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + + list($expect, $lineno) = array_pop($this->brackets); + if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + } + + $this->pushToken(Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); + ++$this->cursor; + } + // strings + elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) { + $this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); + $this->moveCursor($match[0]); + } + // opening double quoted string + elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { + $this->brackets[] = ['"', $this->lineno]; + $this->pushState(self::STATE_STRING); + $this->moveCursor($match[0]); + } + // unlexable + else { + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + } + + protected function lexRawData($tag) + { + if ('raw' === $tag) { + @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED); + } + + if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); + } + + $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); + $this->moveCursor($text.$match[0][0]); + + // trim? + if (isset($match[1][0])) { + if ($this->options['whitespace_trim'] === $match[1][0]) { + // whitespace_trim detected ({%-, {{- or {#-) + $text = rtrim($text); + } else { + // whitespace_line_trim detected ({%~, {{~ or {#~) + // don't trim \r and \n + $text = rtrim($text, " \t\0\x0B"); + } + } + + $this->pushToken(Token::TEXT_TYPE, $text); + } + + protected function lexComment() + { + if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source); + } + + $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); + } + + protected function lexString() + { + if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) { + $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; + $this->pushToken(Token::INTERPOLATION_START_TYPE); + $this->moveCursor($match[0]); + $this->pushState(self::STATE_INTERPOLATION); + } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) { + $this->pushToken(Token::STRING_TYPE, stripcslashes($match[0])); + $this->moveCursor($match[0]); + } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { + list($expect, $lineno) = array_pop($this->brackets); + if ('"' != $this->code[$this->cursor]) { + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + + $this->popState(); + ++$this->cursor; + } else { + // unlexable + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + } + + protected function lexInterpolation() + { + $bracket = end($this->brackets); + if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) { + array_pop($this->brackets); + $this->pushToken(Token::INTERPOLATION_END_TYPE); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + protected function pushToken($type, $value = '') + { + // do not push empty text tokens + if (Token::TEXT_TYPE === $type && '' === $value) { + return; + } + + $this->tokens[] = new Token($type, $value, $this->lineno); + } + + protected function moveCursor($text) + { + $this->cursor += \strlen($text); + $this->lineno += substr_count($text, "\n"); + } + + protected function getOperatorRegex() + { + $operators = array_merge( + ['='], + array_keys($this->env->getUnaryOperators()), + array_keys($this->env->getBinaryOperators()) + ); + + $operators = array_combine($operators, array_map('strlen', $operators)); + arsort($operators); + + $regex = []; + foreach ($operators as $operator => $length) { + // an operator that ends with a character must be followed by + // a whitespace or a parenthesis + if (ctype_alpha($operator[$length - 1])) { + $r = preg_quote($operator, '/').'(?=[\s()])'; + } else { + $r = preg_quote($operator, '/'); + } + + // an operator with a space can be any amount of whitespaces + $r = preg_replace('/\s+/', '\s+', $r); + + $regex[] = $r; + } + + return '/'.implode('|', $regex).'/A'; + } + + protected function pushState($state) + { + $this->states[] = $this->state; + $this->state = $state; + } + + protected function popState() + { + if (0 === \count($this->states)) { + throw new \LogicException('Cannot pop state without a previous state.'); + } + + $this->state = array_pop($this->states); + } +} + +class_alias('Twig\Lexer', 'Twig_Lexer'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ArrayLoader.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ArrayLoader.php new file mode 100644 index 0000000..6bc430f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ArrayLoader.php @@ -0,0 +1,102 @@ + + */ +class ArrayLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + protected $templates = []; + + /** + * @param array $templates An array of templates (keys are the names, and values are the source code) + */ + public function __construct(array $templates = []) + { + $this->templates = $templates; + } + + /** + * Adds or overrides a template. + * + * @param string $name The template name + * @param string $template The template source + */ + public function setTemplate($name, $template) + { + $this->templates[(string) $name] = $template; + } + + public function getSource($name) + { + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); + + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return $this->templates[$name]; + } + + public function getSourceContext($name) + { + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return new Source($this->templates[$name], $name); + } + + public function exists($name) + { + return isset($this->templates[(string) $name]); + } + + public function getCacheKey($name) + { + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return $name.':'.$this->templates[$name]; + } + + public function isFresh($name, $time) + { + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return true; + } +} + +class_alias('Twig\Loader\ArrayLoader', 'Twig_Loader_Array'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ChainLoader.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ChainLoader.php new file mode 100644 index 0000000..25ac55a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ChainLoader.php @@ -0,0 +1,164 @@ + + */ +class ChainLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + private $hasSourceCache = []; + protected $loaders = []; + + /** + * @param LoaderInterface[] $loaders + */ + public function __construct(array $loaders = []) + { + foreach ($loaders as $loader) { + $this->addLoader($loader); + } + } + + public function addLoader(LoaderInterface $loader) + { + $this->loaders[] = $loader; + $this->hasSourceCache = []; + } + + /** + * @return LoaderInterface[] + */ + public function getLoaders() + { + return $this->loaders; + } + + public function getSource($name) + { + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); + + $exceptions = []; + foreach ($this->loaders as $loader) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { + continue; + } + + try { + return $loader->getSource($name); + } catch (LoaderError $e) { + $exceptions[] = $e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function getSourceContext($name) + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { + continue; + } + + try { + if ($loader instanceof SourceContextLoaderInterface) { + return $loader->getSourceContext($name); + } + + return new Source($loader->getSource($name), $name); + } catch (LoaderError $e) { + $exceptions[] = $e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function exists($name) + { + $name = (string) $name; + + if (isset($this->hasSourceCache[$name])) { + return $this->hasSourceCache[$name]; + } + + foreach ($this->loaders as $loader) { + if ($loader instanceof ExistsLoaderInterface) { + if ($loader->exists($name)) { + return $this->hasSourceCache[$name] = true; + } + + continue; + } + + try { + if ($loader instanceof SourceContextLoaderInterface) { + $loader->getSourceContext($name); + } else { + $loader->getSource($name); + } + + return $this->hasSourceCache[$name] = true; + } catch (LoaderError $e) { + } + } + + return $this->hasSourceCache[$name] = false; + } + + public function getCacheKey($name) + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { + continue; + } + + try { + return $loader->getCacheKey($name); + } catch (LoaderError $e) { + $exceptions[] = \get_class($loader).': '.$e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function isFresh($name, $time) + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { + continue; + } + + try { + return $loader->isFresh($name, $time); + } catch (LoaderError $e) { + $exceptions[] = \get_class($loader).': '.$e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } +} + +class_alias('Twig\Loader\ChainLoader', 'Twig_Loader_Chain'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ExistsLoaderInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ExistsLoaderInterface.php new file mode 100644 index 0000000..940d876 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/ExistsLoaderInterface.php @@ -0,0 +1,33 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface ExistsLoaderInterface +{ + /** + * Check if we have the source code of a template, given its name. + * + * @param string $name The name of the template to check if we can load + * + * @return bool If the template source code is handled by this loader or not + */ + public function exists($name); +} + +class_alias('Twig\Loader\ExistsLoaderInterface', 'Twig_ExistsLoaderInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/FilesystemLoader.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/FilesystemLoader.php new file mode 100644 index 0000000..19b43a2 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/FilesystemLoader.php @@ -0,0 +1,323 @@ + + */ +class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + /** Identifier of the main namespace. */ + const MAIN_NAMESPACE = '__main__'; + + protected $paths = []; + protected $cache = []; + protected $errorCache = []; + + private $rootPath; + + /** + * @param string|array $paths A path or an array of paths where to look for templates + * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) + */ + public function __construct($paths = [], $rootPath = null) + { + $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR; + if (false !== $realPath = realpath($rootPath)) { + $this->rootPath = $realPath.\DIRECTORY_SEPARATOR; + } + + if ($paths) { + $this->setPaths($paths); + } + } + + /** + * Returns the paths to the templates. + * + * @param string $namespace A path namespace + * + * @return array The array of paths where to look for templates + */ + public function getPaths($namespace = self::MAIN_NAMESPACE) + { + return isset($this->paths[$namespace]) ? $this->paths[$namespace] : []; + } + + /** + * Returns the path namespaces. + * + * The main namespace is always defined. + * + * @return array The array of defined namespaces + */ + public function getNamespaces() + { + return array_keys($this->paths); + } + + /** + * Sets the paths where templates are stored. + * + * @param string|array $paths A path or an array of paths where to look for templates + * @param string $namespace A path namespace + */ + public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) + { + if (!\is_array($paths)) { + $paths = [$paths]; + } + + $this->paths[$namespace] = []; + foreach ($paths as $path) { + $this->addPath($path, $namespace); + } + } + + /** + * Adds a path where templates are stored. + * + * @param string $path A path where to look for templates + * @param string $namespace A path namespace + * + * @throws LoaderError + */ + public function addPath($path, $namespace = self::MAIN_NAMESPACE) + { + // invalidate the cache + $this->cache = $this->errorCache = []; + + $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; + if (!is_dir($checkPath)) { + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + } + + $this->paths[$namespace][] = rtrim($path, '/\\'); + } + + /** + * Prepends a path where templates are stored. + * + * @param string $path A path where to look for templates + * @param string $namespace A path namespace + * + * @throws LoaderError + */ + public function prependPath($path, $namespace = self::MAIN_NAMESPACE) + { + // invalidate the cache + $this->cache = $this->errorCache = []; + + $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; + if (!is_dir($checkPath)) { + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + } + + $path = rtrim($path, '/\\'); + + if (!isset($this->paths[$namespace])) { + $this->paths[$namespace][] = $path; + } else { + array_unshift($this->paths[$namespace], $path); + } + } + + public function getSource($name) + { + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); + + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return ''; + } + + return file_get_contents($path); + } + + public function getSourceContext($name) + { + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return new Source('', $name, ''); + } + + return new Source(file_get_contents($path), $name, $path); + } + + public function getCacheKey($name) + { + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return ''; + } + $len = \strlen($this->rootPath); + if (0 === strncmp($this->rootPath, $path, $len)) { + return substr($path, $len); + } + + return $path; + } + + public function exists($name) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return true; + } + + try { + return null !== ($path = $this->findTemplate($name, false)) && false !== $path; + } catch (LoaderError $e) { + @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), E_USER_DEPRECATED); + + return false; + } + } + + public function isFresh($name, $time) + { + // false support to be removed in 3.0 + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return false; + } + + return filemtime($path) < $time; + } + + /** + * Checks if the template can be found. + * + * @param string $name The template name + * + * @return string|false|null The template name or false/null + */ + protected function findTemplate($name) + { + $throw = \func_num_args() > 1 ? func_get_arg(1) : true; + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } + + if (isset($this->errorCache[$name])) { + if (!$throw) { + return false; + } + + throw new LoaderError($this->errorCache[$name]); + } + + try { + $this->validateName($name); + + list($namespace, $shortname) = $this->parseName($name); + } catch (LoaderError $e) { + if (!$throw) { + return false; + } + + throw $e; + } + + if (!isset($this->paths[$namespace])) { + $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace); + + if (!$throw) { + return false; + } + + throw new LoaderError($this->errorCache[$name]); + } + + foreach ($this->paths[$namespace] as $path) { + if (!$this->isAbsolutePath($path)) { + $path = $this->rootPath.$path; + } + + if (is_file($path.'/'.$shortname)) { + if (false !== $realpath = realpath($path.'/'.$shortname)) { + return $this->cache[$name] = $realpath; + } + + return $this->cache[$name] = $path.'/'.$shortname; + } + } + + $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])); + + if (!$throw) { + return false; + } + + throw new LoaderError($this->errorCache[$name]); + } + + protected function parseName($name, $default = self::MAIN_NAMESPACE) + { + if (isset($name[0]) && '@' == $name[0]) { + if (false === $pos = strpos($name, '/')) { + throw new LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + } + + $namespace = substr($name, 1, $pos - 1); + $shortname = substr($name, $pos + 1); + + return [$namespace, $shortname]; + } + + return [$default, $name]; + } + + protected function normalizeName($name) + { + return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name)); + } + + protected function validateName($name) + { + if (false !== strpos($name, "\0")) { + throw new LoaderError('A template name cannot contain NUL bytes.'); + } + + $name = ltrim($name, '/'); + $parts = explode('/', $name); + $level = 0; + foreach ($parts as $part) { + if ('..' === $part) { + --$level; + } elseif ('.' !== $part) { + ++$level; + } + + if ($level < 0) { + throw new LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); + } + } + } + + private function isAbsolutePath($file) + { + return strspn($file, '/\\', 0, 1) + || (\strlen($file) > 3 && ctype_alpha($file[0]) + && ':' === substr($file, 1, 1) + && strspn($file, '/\\', 2, 1) + ) + || null !== parse_url($file, PHP_URL_SCHEME) + ; + } +} + +class_alias('Twig\Loader\FilesystemLoader', 'Twig_Loader_Filesystem'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/LoaderInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/LoaderInterface.php new file mode 100644 index 0000000..15be7a8 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/LoaderInterface.php @@ -0,0 +1,61 @@ + + */ +interface LoaderInterface +{ + /** + * Gets the source code of a template, given its name. + * + * @param string $name The name of the template to load + * + * @return string The template source code + * + * @throws LoaderError When $name is not found + * + * @deprecated since 1.27 (to be removed in 2.0), implement Twig\Loader\SourceContextLoaderInterface + */ + public function getSource($name); + + /** + * Gets the cache key to use for the cache for a given template name. + * + * @param string $name The name of the template to load + * + * @return string The cache key + * + * @throws LoaderError When $name is not found + */ + public function getCacheKey($name); + + /** + * Returns true if the template is still fresh. + * + * @param string $name The template name + * @param int $time Timestamp of the last modification time of the + * cached template + * + * @return bool true if the template is fresh, false otherwise + * + * @throws LoaderError When $name is not found + */ + public function isFresh($name, $time); +} + +class_alias('Twig\Loader\LoaderInterface', 'Twig_LoaderInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/SourceContextLoaderInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/SourceContextLoaderInterface.php new file mode 100644 index 0000000..78b1fcd --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Loader/SourceContextLoaderInterface.php @@ -0,0 +1,38 @@ + + * + * @deprecated since 1.27 (to be removed in 3.0) + */ +interface SourceContextLoaderInterface +{ + /** + * Returns the source context for a given template logical name. + * + * @param string $name The template logical name + * + * @return Source + * + * @throws LoaderError When $name is not found + */ + public function getSourceContext($name); +} + +class_alias('Twig\Loader\SourceContextLoaderInterface', 'Twig_SourceContextLoaderInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Markup.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Markup.php new file mode 100644 index 0000000..107941c --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Markup.php @@ -0,0 +1,41 @@ + + */ +class Markup implements \Countable +{ + protected $content; + protected $charset; + + public function __construct($content, $charset) + { + $this->content = (string) $content; + $this->charset = $charset; + } + + public function __toString() + { + return $this->content; + } + + public function count() + { + return \function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : \strlen($this->content); + } +} + +class_alias('Twig\Markup', 'Twig_Markup'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/AutoEscapeNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/AutoEscapeNode.php new file mode 100644 index 0000000..a940306 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/AutoEscapeNode.php @@ -0,0 +1,40 @@ + + */ +class AutoEscapeNode extends Node +{ + public function __construct($value, \Twig_NodeInterface $body, $lineno, $tag = 'autoescape') + { + parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->subcompile($this->getNode('body')); + } +} + +class_alias('Twig\Node\AutoEscapeNode', 'Twig_Node_AutoEscape'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockNode.php new file mode 100644 index 0000000..1ffc8ca --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockNode.php @@ -0,0 +1,45 @@ + + */ +class BlockNode extends Node +{ + public function __construct($name, \Twig_NodeInterface $body, $lineno, $tag = null) + { + parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n") + ->indent() + ; + + $compiler + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n\n") + ; + } +} + +class_alias('Twig\Node\BlockNode', 'Twig_Node_Block'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockReferenceNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockReferenceNode.php new file mode 100644 index 0000000..de06909 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BlockReferenceNode.php @@ -0,0 +1,38 @@ + + */ +class BlockReferenceNode extends Node implements NodeOutputInterface +{ + public function __construct($name, $lineno, $tag = null) + { + parent::__construct([], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) + ; + } +} + +class_alias('Twig\Node\BlockReferenceNode', 'Twig_Node_BlockReference'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BodyNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BodyNode.php new file mode 100644 index 0000000..5290be5 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/BodyNode.php @@ -0,0 +1,23 @@ + + */ +class BodyNode extends Node +{ +} + +class_alias('Twig\Node\BodyNode', 'Twig_Node_Body'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckSecurityNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckSecurityNode.php new file mode 100644 index 0000000..cf0a7a1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckSecurityNode.php @@ -0,0 +1,85 @@ + + */ +class CheckSecurityNode extends Node +{ + protected $usedFilters; + protected $usedTags; + protected $usedFunctions; + + public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) + { + $this->usedFilters = $usedFilters; + $this->usedTags = $usedTags; + $this->usedFunctions = $usedFunctions; + + parent::__construct(); + } + + public function compile(Compiler $compiler) + { + $tags = $filters = $functions = []; + foreach (['tags', 'filters', 'functions'] as $type) { + foreach ($this->{'used'.ucfirst($type)} as $name => $node) { + if ($node instanceof Node) { + ${$type}[$name] = $node->getTemplateLine(); + } else { + ${$type}[$node] = null; + } + } + } + + $compiler + ->write("\$this->sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n") + ->write('$tags = ')->repr(array_filter($tags))->raw(";\n") + ->write('$filters = ')->repr(array_filter($filters))->raw(";\n") + ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n") + ->write("try {\n") + ->indent() + ->write("\$this->sandbox->checkSecurity(\n") + ->indent() + ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n") + ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n") + ->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n") + ->outdent() + ->write(");\n") + ->outdent() + ->write("} catch (SecurityError \$e) {\n") + ->indent() + ->write("\$e->setSourceContext(\$this->getSourceContext());\n\n") + ->write("if (\$e instanceof SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") + ->outdent() + ->write("}\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("}\n\n") + ; + } +} + +class_alias('Twig\Node\CheckSecurityNode', 'Twig_Node_CheckSecurity'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckToStringNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckToStringNode.php new file mode 100644 index 0000000..5d67467 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/CheckToStringNode.php @@ -0,0 +1,42 @@ + + */ +class CheckToStringNode extends AbstractExpression +{ + public function __construct(AbstractExpression $expr) + { + parent::__construct(['expr' => $expr], [], $expr->getTemplateLine(), $expr->getNodeTag()); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('$this->sandbox->ensureToStringAllowed(') + ->subcompile($this->getNode('expr')) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DeprecatedNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DeprecatedNode.php new file mode 100644 index 0000000..62c0dd4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DeprecatedNode.php @@ -0,0 +1,55 @@ + + */ +class DeprecatedNode extends Node +{ + public function __construct(AbstractExpression $expr, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $expr = $this->getNode('expr'); + + if ($expr instanceof ConstantExpression) { + $compiler->write('@trigger_error(') + ->subcompile($expr); + } else { + $varName = $compiler->getVarName(); + $compiler->write(sprintf('$%s = ', $varName)) + ->subcompile($expr) + ->raw(";\n") + ->write(sprintf('@trigger_error($%s', $varName)); + } + + $compiler + ->raw('.') + ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine())) + ->raw(", E_USER_DEPRECATED);\n") + ; + } +} + +class_alias('Twig\Node\DeprecatedNode', 'Twig_Node_Deprecated'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DoNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DoNode.php new file mode 100644 index 0000000..80c4cea --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/DoNode.php @@ -0,0 +1,40 @@ + + */ +class DoNode extends Node +{ + public function __construct(AbstractExpression $expr, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} + +class_alias('Twig\Node\DoNode', 'Twig_Node_Do'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/EmbedNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/EmbedNode.php new file mode 100644 index 0000000..05051ec --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/EmbedNode.php @@ -0,0 +1,52 @@ + + */ +class EmbedNode extends IncludeNode +{ + // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) + public function __construct($name, $index, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) + { + parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); + + $this->setAttribute('name', $name); + // to be removed in 2.0, used name instead + $this->setAttribute('filename', $name); + $this->setAttribute('index', $index); + } + + protected function addGetTemplate(Compiler $compiler) + { + $compiler + ->write('$this->loadTemplate(') + ->string($this->getAttribute('name')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(', ') + ->string($this->getAttribute('index')) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\EmbedNode', 'Twig_Node_Embed'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AbstractExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AbstractExpression.php new file mode 100644 index 0000000..a352892 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AbstractExpression.php @@ -0,0 +1,26 @@ + + */ +abstract class AbstractExpression extends Node +{ +} + +class_alias('Twig\Node\Expression\AbstractExpression', 'Twig_Node_Expression'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrayExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrayExpression.php new file mode 100644 index 0000000..cd63f93 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrayExpression.php @@ -0,0 +1,88 @@ +index = -1; + foreach ($this->getKeyValuePairs() as $pair) { + if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { + $this->index = $pair['key']->getAttribute('value'); + } + } + } + + public function getKeyValuePairs() + { + $pairs = []; + + foreach (array_chunk($this->nodes, 2) as $pair) { + $pairs[] = [ + 'key' => $pair[0], + 'value' => $pair[1], + ]; + } + + return $pairs; + } + + public function hasElement(AbstractExpression $key) + { + foreach ($this->getKeyValuePairs() as $pair) { + // we compare the string representation of the keys + // to avoid comparing the line numbers which are not relevant here. + if ((string) $key === (string) $pair['key']) { + return true; + } + } + + return false; + } + + public function addElement(AbstractExpression $value, AbstractExpression $key = null) + { + if (null === $key) { + $key = new ConstantExpression(++$this->index, $value->getTemplateLine()); + } + + array_push($this->nodes, $key, $value); + } + + public function compile(Compiler $compiler) + { + $compiler->raw('['); + $first = true; + foreach ($this->getKeyValuePairs() as $pair) { + if (!$first) { + $compiler->raw(', '); + } + $first = false; + + $compiler + ->subcompile($pair['key']) + ->raw(' => ') + ->subcompile($pair['value']) + ; + } + $compiler->raw(']'); + } +} + +class_alias('Twig\Node\Expression\ArrayExpression', 'Twig_Node_Expression_Array'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php new file mode 100644 index 0000000..36b77da --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php @@ -0,0 +1,64 @@ + + */ +class ArrowFunctionExpression extends AbstractExpression +{ + public function __construct(AbstractExpression $expr, Node $names, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr, 'names' => $names], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->raw('function (') + ; + foreach ($this->getNode('names') as $i => $name) { + if ($i) { + $compiler->raw(', '); + } + + $compiler + ->raw('$__') + ->raw($name->getAttribute('name')) + ->raw('__') + ; + } + $compiler + ->raw(') use ($context) { ') + ; + foreach ($this->getNode('names') as $name) { + $compiler + ->raw('$context["') + ->raw($name->getAttribute('name')) + ->raw('"] = $__') + ->raw($name->getAttribute('name')) + ->raw('__; ') + ; + } + $compiler + ->raw('return ') + ->subcompile($this->getNode('expr')) + ->raw('; }') + ; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AssignNameExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AssignNameExpression.php new file mode 100644 index 0000000..62c4ac0 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/AssignNameExpression.php @@ -0,0 +1,29 @@ +raw('$context[') + ->string($this->getAttribute('name')) + ->raw(']') + ; + } +} + +class_alias('Twig\Node\Expression\AssignNameExpression', 'Twig_Node_Expression_AssignName'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php new file mode 100644 index 0000000..0600aee --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php @@ -0,0 +1,43 @@ + $left, 'right' => $right], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('left')) + ->raw(' ') + ; + $this->operator($compiler); + $compiler + ->raw(' ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + abstract public function operator(Compiler $compiler); +} + +class_alias('Twig\Node\Expression\Binary\AbstractBinary', 'Twig_Node_Expression_Binary'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AddBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AddBinary.php new file mode 100644 index 0000000..f7719a1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AddBinary.php @@ -0,0 +1,25 @@ +raw('+'); + } +} + +class_alias('Twig\Node\Expression\Binary\AddBinary', 'Twig_Node_Expression_Binary_Add'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AndBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AndBinary.php new file mode 100644 index 0000000..484597d --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/AndBinary.php @@ -0,0 +1,25 @@ +raw('&&'); + } +} + +class_alias('Twig\Node\Expression\Binary\AndBinary', 'Twig_Node_Expression_Binary_And'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php new file mode 100644 index 0000000..cf28691 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php @@ -0,0 +1,25 @@ +raw('&'); + } +} + +class_alias('Twig\Node\Expression\Binary\BitwiseAndBinary', 'Twig_Node_Expression_Binary_BitwiseAnd'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php new file mode 100644 index 0000000..7d5d260 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php @@ -0,0 +1,25 @@ +raw('|'); + } +} + +class_alias('Twig\Node\Expression\Binary\BitwiseOrBinary', 'Twig_Node_Expression_Binary_BitwiseOr'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php new file mode 100644 index 0000000..7291987 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php @@ -0,0 +1,25 @@ +raw('^'); + } +} + +class_alias('Twig\Node\Expression\Binary\BitwiseXorBinary', 'Twig_Node_Expression_Binary_BitwiseXor'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php new file mode 100644 index 0000000..f6e5938 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php @@ -0,0 +1,25 @@ +raw('.'); + } +} + +class_alias('Twig\Node\Expression\Binary\ConcatBinary', 'Twig_Node_Expression_Binary_Concat'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/DivBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/DivBinary.php new file mode 100644 index 0000000..ebfcc75 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/DivBinary.php @@ -0,0 +1,25 @@ +raw('/'); + } +} + +class_alias('Twig\Node\Expression\Binary\DivBinary', 'Twig_Node_Expression_Binary_Div'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php new file mode 100644 index 0000000..41a0065 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php @@ -0,0 +1,37 @@ +getVarName(); + $right = $compiler->getVarName(); + $compiler + ->raw(sprintf('(is_string($%s = ', $left)) + ->subcompile($this->getNode('left')) + ->raw(sprintf(') && is_string($%s = ', $right)) + ->subcompile($this->getNode('right')) + ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right)) + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw(''); + } +} + +class_alias('Twig\Node\Expression\Binary\EndsWithBinary', 'Twig_Node_Expression_Binary_EndsWith'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EqualBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EqualBinary.php new file mode 100644 index 0000000..84904c3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/EqualBinary.php @@ -0,0 +1,24 @@ +raw('=='); + } +} + +class_alias('Twig\Node\Expression\Binary\EqualBinary', 'Twig_Node_Expression_Binary_Equal'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php new file mode 100644 index 0000000..4dd5e3d --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php @@ -0,0 +1,31 @@ +raw('(int) floor('); + parent::compile($compiler); + $compiler->raw(')'); + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('/'); + } +} + +class_alias('Twig\Node\Expression\Binary\FloorDivBinary', 'Twig_Node_Expression_Binary_FloorDiv'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php new file mode 100644 index 0000000..be73001 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php @@ -0,0 +1,24 @@ +raw('>'); + } +} + +class_alias('Twig\Node\Expression\Binary\GreaterBinary', 'Twig_Node_Expression_Binary_Greater'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php new file mode 100644 index 0000000..5c2ae72 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php @@ -0,0 +1,24 @@ +raw('>='); + } +} + +class_alias('Twig\Node\Expression\Binary\GreaterEqualBinary', 'Twig_Node_Expression_Binary_GreaterEqual'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/InBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/InBinary.php new file mode 100644 index 0000000..f00b230 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/InBinary.php @@ -0,0 +1,35 @@ +raw('twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('in'); + } +} + +class_alias('Twig\Node\Expression\Binary\InBinary', 'Twig_Node_Expression_Binary_In'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessBinary.php new file mode 100644 index 0000000..2b202da --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessBinary.php @@ -0,0 +1,24 @@ +raw('<'); + } +} + +class_alias('Twig\Node\Expression\Binary\LessBinary', 'Twig_Node_Expression_Binary_Less'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php new file mode 100644 index 0000000..4fffafe --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php @@ -0,0 +1,24 @@ +raw('<='); + } +} + +class_alias('Twig\Node\Expression\Binary\LessEqualBinary', 'Twig_Node_Expression_Binary_LessEqual'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php new file mode 100644 index 0000000..ae810b2 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php @@ -0,0 +1,35 @@ +raw('preg_match(') + ->subcompile($this->getNode('right')) + ->raw(', ') + ->subcompile($this->getNode('left')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw(''); + } +} + +class_alias('Twig\Node\Expression\Binary\MatchesBinary', 'Twig_Node_Expression_Binary_Matches'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ModBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ModBinary.php new file mode 100644 index 0000000..e6a2b36 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/ModBinary.php @@ -0,0 +1,25 @@ +raw('%'); + } +} + +class_alias('Twig\Node\Expression\Binary\ModBinary', 'Twig_Node_Expression_Binary_Mod'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MulBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MulBinary.php new file mode 100644 index 0000000..cd65f5d --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/MulBinary.php @@ -0,0 +1,25 @@ +raw('*'); + } +} + +class_alias('Twig\Node\Expression\Binary\MulBinary', 'Twig_Node_Expression_Binary_Mul'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php new file mode 100644 index 0000000..df5c6a2 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php @@ -0,0 +1,24 @@ +raw('!='); + } +} + +class_alias('Twig\Node\Expression\Binary\NotEqualBinary', 'Twig_Node_Expression_Binary_NotEqual'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotInBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotInBinary.php new file mode 100644 index 0000000..ed2034e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/NotInBinary.php @@ -0,0 +1,35 @@ +raw('!twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('not in'); + } +} + +class_alias('Twig\Node\Expression\Binary\NotInBinary', 'Twig_Node_Expression_Binary_NotIn'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/OrBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/OrBinary.php new file mode 100644 index 0000000..8f9da43 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/OrBinary.php @@ -0,0 +1,25 @@ +raw('||'); + } +} + +class_alias('Twig\Node\Expression\Binary\OrBinary', 'Twig_Node_Expression_Binary_Or'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/PowerBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/PowerBinary.php new file mode 100644 index 0000000..10a8d94 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/PowerBinary.php @@ -0,0 +1,39 @@ += 50600) { + return parent::compile($compiler); + } + + $compiler + ->raw('pow(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('**'); + } +} + +class_alias('Twig\Node\Expression\Binary\PowerBinary', 'Twig_Node_Expression_Binary_Power'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/RangeBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/RangeBinary.php new file mode 100644 index 0000000..e9c0cdf --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/RangeBinary.php @@ -0,0 +1,35 @@ +raw('range(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('..'); + } +} + +class_alias('Twig\Node\Expression\Binary\RangeBinary', 'Twig_Node_Expression_Binary_Range'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php new file mode 100644 index 0000000..1fe59fb --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php @@ -0,0 +1,37 @@ +getVarName(); + $right = $compiler->getVarName(); + $compiler + ->raw(sprintf('(is_string($%s = ', $left)) + ->subcompile($this->getNode('left')) + ->raw(sprintf(') && is_string($%s = ', $right)) + ->subcompile($this->getNode('right')) + ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw(''); + } +} + +class_alias('Twig\Node\Expression\Binary\StartsWithBinary', 'Twig_Node_Expression_Binary_StartsWith'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/SubBinary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/SubBinary.php new file mode 100644 index 0000000..2546975 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Binary/SubBinary.php @@ -0,0 +1,25 @@ +raw('-'); + } +} + +class_alias('Twig\Node\Expression\Binary\SubBinary', 'Twig_Node_Expression_Binary_Sub'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/BlockReferenceExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/BlockReferenceExpression.php new file mode 100644 index 0000000..0a56849 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/BlockReferenceExpression.php @@ -0,0 +1,98 @@ + + */ +class BlockReferenceExpression extends AbstractExpression +{ + /** + * @param Node|null $template + */ + public function __construct(\Twig_NodeInterface $name, $template = null, $lineno, $tag = null) + { + if (\is_bool($template)) { + @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + + $template = null; + } + + $nodes = ['name' => $name]; + if (null !== $template) { + $nodes['template'] = $template; + } + + parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('is_defined_test')) { + $this->compileTemplateCall($compiler, 'hasBlock'); + } else { + if ($this->getAttribute('output')) { + $compiler->addDebugInfo($this); + + $this + ->compileTemplateCall($compiler, 'displayBlock') + ->raw(";\n"); + } else { + $this->compileTemplateCall($compiler, 'renderBlock'); + } + } + } + + private function compileTemplateCall(Compiler $compiler, $method) + { + if (!$this->hasNode('template')) { + $compiler->write('$this'); + } else { + $compiler + ->write('$this->loadTemplate(') + ->subcompile($this->getNode('template')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')') + ; + } + + $compiler->raw(sprintf('->%s', $method)); + $this->compileBlockArguments($compiler); + + return $compiler; + } + + private function compileBlockArguments(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('name')) + ->raw(', $context'); + + if (!$this->hasNode('template')) { + $compiler->raw(', $blocks'); + } + + return $compiler->raw(')'); + } +} + +class_alias('Twig\Node\Expression\BlockReferenceExpression', 'Twig_Node_Expression_BlockReference'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/CallExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/CallExpression.php new file mode 100644 index 0000000..d202a73 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/CallExpression.php @@ -0,0 +1,305 @@ +hasAttribute('callable') && $callable = $this->getAttribute('callable')) { + if (\is_string($callable) && false === strpos($callable, '::')) { + $compiler->raw($callable); + } else { + list($r, $callable) = $this->reflectCallable($callable); + if ($r instanceof \ReflectionMethod && \is_string($callable[0])) { + if ($r->isStatic()) { + $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1])); + } else { + $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); + } + } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) { + $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($callable[0]), $callable[1])); + } else { + $type = ucfirst($this->getAttribute('type')); + $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', $type, $this->getAttribute('name'))); + $closingParenthesis = true; + $isArray = true; + } + } + } else { + $compiler->raw($this->getAttribute('thing')->compile()); + } + + $this->compileArguments($compiler, $isArray); + + if ($closingParenthesis) { + $compiler->raw(')'); + } + } + + protected function compileArguments(Compiler $compiler, $isArray = false) + { + $compiler->raw($isArray ? '[' : '('); + + $first = true; + + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + $compiler->raw('$this->env'); + $first = false; + } + + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->raw('$context'); + $first = false; + } + + if ($this->hasAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->string($argument); + $first = false; + } + } + + if ($this->hasNode('node')) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->subcompile($this->getNode('node')); + $first = false; + } + + if ($this->hasNode('arguments')) { + $callable = $this->hasAttribute('callable') ? $this->getAttribute('callable') : null; + + $arguments = $this->getArguments($callable, $this->getNode('arguments')); + + foreach ($arguments as $node) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->subcompile($node); + $first = false; + } + } + + $compiler->raw($isArray ? ']' : ')'); + } + + protected function getArguments($callable, $arguments) + { + $callType = $this->getAttribute('type'); + $callName = $this->getAttribute('name'); + + $parameters = []; + $named = false; + foreach ($arguments as $name => $node) { + if (!\is_int($name)) { + $named = true; + $name = $this->normalizeName($name); + } elseif ($named) { + throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + + $parameters[$name] = $node; + } + + $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic'); + if (!$named && !$isVariadic) { + return $parameters; + } + + if (!$callable) { + if ($named) { + $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName); + } else { + $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName); + } + + throw new \LogicException($message); + } + + $callableParameters = $this->getCallableParameters($callable, $isVariadic); + $arguments = []; + $names = []; + $missingArguments = []; + $optionalArguments = []; + $pos = 0; + foreach ($callableParameters as $callableParameter) { + $names[] = $name = $this->normalizeName($callableParameter->name); + + if (\array_key_exists($name, $parameters)) { + if (\array_key_exists($pos, $parameters)) { + throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + + if (\count($missingArguments)) { + throw new SyntaxError(sprintf( + 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', + $name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) + ), $this->getTemplateLine(), $this->getSourceContext()); + } + + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$name]; + unset($parameters[$name]); + $optionalArguments = []; + } elseif (\array_key_exists($pos, $parameters)) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$pos]; + unset($parameters[$pos]); + $optionalArguments = []; + ++$pos; + } elseif ($callableParameter->isDefaultValueAvailable()) { + $optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1); + } elseif ($callableParameter->isOptional()) { + if (empty($parameters)) { + break; + } else { + $missingArguments[] = $name; + } + } else { + throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + } + + if ($isVariadic) { + $arbitraryArguments = new ArrayExpression([], -1); + foreach ($parameters as $key => $value) { + if (\is_int($key)) { + $arbitraryArguments->addElement($value); + } else { + $arbitraryArguments->addElement($value, new ConstantExpression($key, -1)); + } + unset($parameters[$key]); + } + + if ($arbitraryArguments->count()) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $arbitraryArguments; + } + } + + if (!empty($parameters)) { + $unknownParameter = null; + foreach ($parameters as $parameter) { + if ($parameter instanceof Node) { + $unknownParameter = $parameter; + break; + } + } + + throw new SyntaxError( + sprintf( + 'Unknown argument%s "%s" for %s "%s(%s)".', + \count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) + ), + $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(), + $unknownParameter ? $unknownParameter->getSourceContext() : $this->getSourceContext() + ); + } + + return $arguments; + } + + protected function normalizeName($name) + { + return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); + } + + private function getCallableParameters($callable, $isVariadic) + { + list($r) = $this->reflectCallable($callable); + if (null === $r) { + return []; + } + + $parameters = $r->getParameters(); + if ($this->hasNode('node')) { + array_shift($parameters); + } + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + array_shift($parameters); + } + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + array_shift($parameters); + } + if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + array_shift($parameters); + } + } + if ($isVariadic) { + $argument = end($parameters); + if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { + array_pop($parameters); + } else { + $callableName = $r->name; + if ($r instanceof \ReflectionMethod) { + $callableName = $r->getDeclaringClass()->name.'::'.$callableName; + } + + throw new \LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); + } + } + + return $parameters; + } + + private function reflectCallable($callable) + { + if (null !== $this->reflector) { + return $this->reflector; + } + + if (\is_array($callable)) { + if (!method_exists($callable[0], $callable[1])) { + // __call() + return [null, []]; + } + $r = new \ReflectionMethod($callable[0], $callable[1]); + } elseif (\is_object($callable) && !$callable instanceof \Closure) { + $r = new \ReflectionObject($callable); + $r = $r->getMethod('__invoke'); + $callable = [$callable, '__invoke']; + } elseif (\is_string($callable) && false !== $pos = strpos($callable, '::')) { + $class = substr($callable, 0, $pos); + $method = substr($callable, $pos + 2); + if (!method_exists($class, $method)) { + // __staticCall() + return [null, []]; + } + $r = new \ReflectionMethod($callable); + $callable = [$class, $method]; + } else { + $r = new \ReflectionFunction($callable); + } + + return $this->reflector = [$r, $callable]; + } +} + +class_alias('Twig\Node\Expression\CallExpression', 'Twig_Node_Expression_Call'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConditionalExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConditionalExpression.php new file mode 100644 index 0000000..b611218 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConditionalExpression.php @@ -0,0 +1,38 @@ + $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('((') + ->subcompile($this->getNode('expr1')) + ->raw(') ? (') + ->subcompile($this->getNode('expr2')) + ->raw(') : (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } +} + +class_alias('Twig\Node\Expression\ConditionalExpression', 'Twig_Node_Expression_Conditional'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConstantExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConstantExpression.php new file mode 100644 index 0000000..fd58264 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ConstantExpression.php @@ -0,0 +1,30 @@ + $value], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler->repr($this->getAttribute('value')); + } +} + +class_alias('Twig\Node\Expression\ConstantExpression', 'Twig_Node_Expression_Constant'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php new file mode 100644 index 0000000..7c5e2d2 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php @@ -0,0 +1,54 @@ + + */ +class DefaultFilter extends FilterExpression +{ + public function __construct(\Twig_NodeInterface $node, ConstantExpression $filterName, \Twig_NodeInterface $arguments, $lineno, $tag = null) + { + $default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); + + if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) { + $test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine()); + $false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine()); + + $node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine()); + } else { + $node = $default; + } + + parent::__construct($node, $filterName, $arguments, $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->subcompile($this->getNode('node')); + } +} + +class_alias('Twig\Node\Expression\Filter\DefaultFilter', 'Twig_Node_Expression_Filter_Default'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FilterExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FilterExpression.php new file mode 100644 index 0000000..6131c2f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FilterExpression.php @@ -0,0 +1,47 @@ + $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $name = $this->getNode('filter')->getAttribute('value'); + $filter = $compiler->getEnvironment()->getFilter($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'filter'); + $this->setAttribute('thing', $filter); + $this->setAttribute('needs_environment', $filter->needsEnvironment()); + $this->setAttribute('needs_context', $filter->needsContext()); + $this->setAttribute('arguments', $filter->getArguments()); + if ($filter instanceof \Twig_FilterCallableInterface || $filter instanceof TwigFilter) { + $this->setAttribute('callable', $filter->getCallable()); + } + if ($filter instanceof TwigFilter) { + $this->setAttribute('is_variadic', $filter->isVariadic()); + } + + $this->compileCallable($compiler); + } +} + +class_alias('Twig\Node\Expression\FilterExpression', 'Twig_Node_Expression_Filter'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FunctionExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FunctionExpression.php new file mode 100644 index 0000000..cf2c72b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/FunctionExpression.php @@ -0,0 +1,51 @@ + $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + $function = $compiler->getEnvironment()->getFunction($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'function'); + $this->setAttribute('thing', $function); + $this->setAttribute('needs_environment', $function->needsEnvironment()); + $this->setAttribute('needs_context', $function->needsContext()); + $this->setAttribute('arguments', $function->getArguments()); + if ($function instanceof \Twig_FunctionCallableInterface || $function instanceof TwigFunction) { + $callable = $function->getCallable(); + if ('constant' === $name && $this->getAttribute('is_defined_test')) { + $callable = 'twig_constant_is_defined'; + } + + $this->setAttribute('callable', $callable); + } + if ($function instanceof TwigFunction) { + $this->setAttribute('is_variadic', $function->isVariadic()); + } + + $this->compileCallable($compiler); + } +} + +class_alias('Twig\Node\Expression\FunctionExpression', 'Twig_Node_Expression_Function'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/GetAttrExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/GetAttrExpression.php new file mode 100644 index 0000000..b790bf7 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/GetAttrExpression.php @@ -0,0 +1,80 @@ + $node, 'attribute' => $attribute]; + if (null !== $arguments) { + $nodes['arguments'] = $arguments; + } + + parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false], $lineno); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('disable_c_ext')) { + @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED); + } + + if (\function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { + $compiler->raw('twig_template_get_attributes($this, '); + } else { + $compiler->raw('$this->getAttribute('); + } + + if ($this->getAttribute('ignore_strict_check')) { + $this->getNode('node')->setAttribute('ignore_strict_check', true); + } + + $compiler->subcompile($this->getNode('node')); + + $compiler->raw(', ')->subcompile($this->getNode('attribute')); + + // only generate optional arguments when needed (to make generated code more readable) + $needFourth = $this->getAttribute('ignore_strict_check'); + $needThird = $needFourth || $this->getAttribute('is_defined_test'); + $needSecond = $needThird || Template::ANY_CALL !== $this->getAttribute('type'); + $needFirst = $needSecond || $this->hasNode('arguments'); + + if ($needFirst) { + if ($this->hasNode('arguments')) { + $compiler->raw(', ')->subcompile($this->getNode('arguments')); + } else { + $compiler->raw(', []'); + } + } + + if ($needSecond) { + $compiler->raw(', ')->repr($this->getAttribute('type')); + } + + if ($needThird) { + $compiler->raw(', ')->repr($this->getAttribute('is_defined_test')); + } + + if ($needFourth) { + $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check')); + } + + $compiler->raw(')'); + } +} + +class_alias('Twig\Node\Expression\GetAttrExpression', 'Twig_Node_Expression_GetAttr'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/InlinePrint.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/InlinePrint.php new file mode 100644 index 0000000..469e736 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/InlinePrint.php @@ -0,0 +1,35 @@ + $node], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('print (') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/MethodCallExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/MethodCallExpression.php new file mode 100644 index 0000000..f631124 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/MethodCallExpression.php @@ -0,0 +1,48 @@ + $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno); + + if ($node instanceof NameExpression) { + $node->setAttribute('always_defined', true); + } + } + + public function compile(Compiler $compiler) + { + $compiler + ->subcompile($this->getNode('node')) + ->raw('->') + ->raw($this->getAttribute('method')) + ->raw('(') + ; + $first = true; + foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { + if (!$first) { + $compiler->raw(', '); + } + $first = false; + + $compiler->subcompile($pair['value']); + } + $compiler->raw(')'); + } +} + +class_alias('Twig\Node\Expression\MethodCallExpression', 'Twig_Node_Expression_MethodCall'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NameExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NameExpression.php new file mode 100644 index 0000000..d3f7d10 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NameExpression.php @@ -0,0 +1,119 @@ + '$this', + '_context' => '$context', + '_charset' => '$this->env->getCharset()', + ]; + + public function __construct($name, $lineno) + { + parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + + $compiler->addDebugInfo($this); + + if ($this->getAttribute('is_defined_test')) { + if ($this->isSpecial()) { + $compiler->repr(true); + } elseif (\PHP_VERSION_ID >= 700400) { + $compiler + ->raw('array_key_exists(') + ->string($name) + ->raw(', $context)') + ; + } else { + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) || array_key_exists(') + ->string($name) + ->raw(', $context))') + ; + } + } elseif ($this->isSpecial()) { + $compiler->raw($this->specialVars[$name]); + } elseif ($this->getAttribute('always_defined')) { + $compiler + ->raw('$context[') + ->string($name) + ->raw(']') + ; + } else { + if (\PHP_VERSION_ID >= 70000) { + // use PHP 7 null coalescing operator + $compiler + ->raw('($context[') + ->string($name) + ->raw('] ?? ') + ; + + if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { + $compiler->raw('null)'); + } else { + $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); + } + } elseif (\PHP_VERSION_ID >= 50400) { + // PHP 5.4 ternary operator performance was optimized + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) ? $context[') + ->string($name) + ->raw('] : ') + ; + + if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { + $compiler->raw('null)'); + } else { + $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); + } + } else { + $compiler + ->raw('$this->getContext($context, ') + ->string($name) + ; + + if ($this->getAttribute('ignore_strict_check')) { + $compiler->raw(', true'); + } + + $compiler + ->raw(')') + ; + } + } + } + + public function isSpecial() + { + return isset($this->specialVars[$this->getAttribute('name')]); + } + + public function isSimple() + { + return !$this->isSpecial() && !$this->getAttribute('is_defined_test'); + } +} + +class_alias('Twig\Node\Expression\NameExpression', 'Twig_Node_Expression_Name'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NullCoalesceExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NullCoalesceExpression.php new file mode 100644 index 0000000..917d31a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/NullCoalesceExpression.php @@ -0,0 +1,62 @@ +getTemplateLine()); + // for "block()", we don't need the null test as the return value is always a string + if (!$left instanceof BlockReferenceExpression) { + $test = new AndBinary( + $test, + new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()), + $left->getTemplateLine() + ); + } + + parent::__construct($test, $left, $right, $lineno); + } + + public function compile(Compiler $compiler) + { + /* + * This optimizes only one case. PHP 7 also supports more complex expressions + * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works, + * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced + * cases might be implemented as an optimizer node visitor, but has not been done + * as benefits are probably not worth the added complexity. + */ + if (\PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof NameExpression) { + $this->getNode('expr2')->setAttribute('always_defined', true); + $compiler + ->raw('((') + ->subcompile($this->getNode('expr2')) + ->raw(') ?? (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } else { + parent::compile($compiler); + } + } +} + +class_alias('Twig\Node\Expression\NullCoalesceExpression', 'Twig_Node_Expression_NullCoalesce'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ParentExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ParentExpression.php new file mode 100644 index 0000000..1247283 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/ParentExpression.php @@ -0,0 +1,48 @@ + + */ +class ParentExpression extends AbstractExpression +{ + public function __construct($name, $lineno, $tag = null) + { + parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('output')) { + $compiler + ->addDebugInfo($this) + ->write('$this->displayParentBlock(') + ->string($this->getAttribute('name')) + ->raw(", \$context, \$blocks);\n") + ; + } else { + $compiler + ->raw('$this->renderParentBlock(') + ->string($this->getAttribute('name')) + ->raw(', $context, $blocks)') + ; + } + } +} + +class_alias('Twig\Node\Expression\ParentExpression', 'Twig_Node_Expression_Parent'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TempNameExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TempNameExpression.php new file mode 100644 index 0000000..ce0a158 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TempNameExpression.php @@ -0,0 +1,33 @@ + $name], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('$_') + ->raw($this->getAttribute('name')) + ->raw('_') + ; + } +} + +class_alias('Twig\Node\Expression\TempNameExpression', 'Twig_Node_Expression_TempName'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/ConstantTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/ConstantTest.php new file mode 100644 index 0000000..78353a8 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/ConstantTest.php @@ -0,0 +1,51 @@ + + */ +class ConstantTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === constant(') + ; + + if ($this->getNode('arguments')->hasNode(1)) { + $compiler + ->raw('get_class(') + ->subcompile($this->getNode('arguments')->getNode(1)) + ->raw(')."::".') + ; + } + + $compiler + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw('))') + ; + } +} + +class_alias('Twig\Node\Expression\Test\ConstantTest', 'Twig_Node_Expression_Test_Constant'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DefinedTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DefinedTest.php new file mode 100644 index 0000000..2222e11 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DefinedTest.php @@ -0,0 +1,71 @@ + + */ +class DefinedTest extends TestExpression +{ + public function __construct(\Twig_NodeInterface $node, $name, \Twig_NodeInterface $arguments = null, $lineno) + { + if ($node instanceof NameExpression) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof GetAttrExpression) { + $node->setAttribute('is_defined_test', true); + $this->changeIgnoreStrictCheck($node); + } elseif ($node instanceof BlockReferenceExpression) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) { + $node = new ConstantExpression(true, $node->getTemplateLine()); + } else { + throw new SyntaxError('The "defined" test only works with simple variables.', $lineno); + } + + parent::__construct($node, $name, $arguments, $lineno); + } + + protected function changeIgnoreStrictCheck(GetAttrExpression $node) + { + $node->setAttribute('ignore_strict_check', true); + + if ($node->getNode('node') instanceof GetAttrExpression) { + $this->changeIgnoreStrictCheck($node->getNode('node')); + } + } + + public function compile(Compiler $compiler) + { + $compiler->subcompile($this->getNode('node')); + } +} + +class_alias('Twig\Node\Expression\Test\DefinedTest', 'Twig_Node_Expression_Test_Defined'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php new file mode 100644 index 0000000..05c8ad8 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php @@ -0,0 +1,38 @@ + + */ +class DivisiblebyTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(0 == ') + ->subcompile($this->getNode('node')) + ->raw(' % ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\DivisiblebyTest', 'Twig_Node_Expression_Test_Divisibleby'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/EvenTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/EvenTest.php new file mode 100644 index 0000000..3b955d2 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/EvenTest.php @@ -0,0 +1,37 @@ + + */ +class EvenTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 0') + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\EvenTest', 'Twig_Node_Expression_Test_Even'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/NullTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/NullTest.php new file mode 100644 index 0000000..24d3997 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/NullTest.php @@ -0,0 +1,36 @@ + + */ +class NullTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(null === ') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\NullTest', 'Twig_Node_Expression_Test_Null'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/OddTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/OddTest.php new file mode 100644 index 0000000..2dc693a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/OddTest.php @@ -0,0 +1,37 @@ + + */ +class OddTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 1') + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\OddTest', 'Twig_Node_Expression_Test_Odd'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/SameasTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/SameasTest.php new file mode 100644 index 0000000..75f2b82 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Test/SameasTest.php @@ -0,0 +1,36 @@ + + */ +class SameasTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\SameasTest', 'Twig_Node_Expression_Test_Sameas'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TestExpression.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TestExpression.php new file mode 100644 index 0000000..8fc31d3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/TestExpression.php @@ -0,0 +1,51 @@ + $node]; + if (null !== $arguments) { + $nodes['arguments'] = $arguments; + } + + parent::__construct($nodes, ['name' => $name], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + $test = $compiler->getEnvironment()->getTest($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'test'); + $this->setAttribute('thing', $test); + if ($test instanceof TwigTest) { + $this->setAttribute('arguments', $test->getArguments()); + } + if ($test instanceof \Twig_TestCallableInterface || $test instanceof TwigTest) { + $this->setAttribute('callable', $test->getCallable()); + } + if ($test instanceof TwigTest) { + $this->setAttribute('is_variadic', $test->isVariadic()); + } + + $this->compileCallable($compiler); + } +} + +class_alias('Twig\Node\Expression\TestExpression', 'Twig_Node_Expression_Test'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php new file mode 100644 index 0000000..415c3d4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php @@ -0,0 +1,35 @@ + $node], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler->raw(' '); + $this->operator($compiler); + $compiler->subcompile($this->getNode('node')); + } + + abstract public function operator(Compiler $compiler); +} + +class_alias('Twig\Node\Expression\Unary\AbstractUnary', 'Twig_Node_Expression_Unary'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NegUnary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NegUnary.php new file mode 100644 index 0000000..dfb6f54 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NegUnary.php @@ -0,0 +1,25 @@ +raw('-'); + } +} + +class_alias('Twig\Node\Expression\Unary\NegUnary', 'Twig_Node_Expression_Unary_Neg'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NotUnary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NotUnary.php new file mode 100644 index 0000000..7bdde96 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/NotUnary.php @@ -0,0 +1,25 @@ +raw('!'); + } +} + +class_alias('Twig\Node\Expression\Unary\NotUnary', 'Twig_Node_Expression_Unary_Not'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/PosUnary.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/PosUnary.php new file mode 100644 index 0000000..52d5d0c --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Expression/Unary/PosUnary.php @@ -0,0 +1,25 @@ +raw('+'); + } +} + +class_alias('Twig\Node\Expression\Unary\PosUnary', 'Twig_Node_Expression_Unary_Pos'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/FlushNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/FlushNode.php new file mode 100644 index 0000000..6cbc489 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/FlushNode.php @@ -0,0 +1,37 @@ + + */ +class FlushNode extends Node +{ + public function __construct($lineno, $tag) + { + parent::__construct([], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("flush();\n") + ; + } +} + +class_alias('Twig\Node\FlushNode', 'Twig_Node_Flush'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForLoopNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForLoopNode.php new file mode 100644 index 0000000..3902093 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForLoopNode.php @@ -0,0 +1,56 @@ + + */ +class ForLoopNode extends Node +{ + public function __construct($lineno, $tag = null) + { + parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('else')) { + $compiler->write("\$context['_iterated'] = true;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("++\$context['loop']['index0'];\n") + ->write("++\$context['loop']['index'];\n") + ->write("\$context['loop']['first'] = false;\n") + ; + + if (!$this->getAttribute('ifexpr')) { + $compiler + ->write("if (isset(\$context['loop']['length'])) {\n") + ->indent() + ->write("--\$context['loop']['revindex0'];\n") + ->write("--\$context['loop']['revindex'];\n") + ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") + ->outdent() + ->write("}\n") + ; + } + } + } +} + +class_alias('Twig\Node\ForLoopNode', 'Twig_Node_ForLoop'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForNode.php new file mode 100644 index 0000000..49409a3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ForNode.php @@ -0,0 +1,119 @@ + + */ +class ForNode extends Node +{ + protected $loop; + + public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, \Twig_NodeInterface $body, \Twig_NodeInterface $else = null, $lineno, $tag = null) + { + $body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]); + + if (null !== $ifexpr) { + $body = new IfNode(new Node([$ifexpr, $body]), null, $lineno, $tag); + } + + $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; + if (null !== $else) { + $nodes['else'] = $else; + } + + parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("\$context['_parent'] = \$context;\n") + ->write("\$context['_seq'] = twig_ensure_traversable(") + ->subcompile($this->getNode('seq')) + ->raw(");\n") + ; + + if ($this->hasNode('else')) { + $compiler->write("\$context['_iterated'] = false;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("\$context['loop'] = [\n") + ->write(" 'parent' => \$context['_parent'],\n") + ->write(" 'index0' => 0,\n") + ->write(" 'index' => 1,\n") + ->write(" 'first' => true,\n") + ->write("];\n") + ; + + if (!$this->getAttribute('ifexpr')) { + $compiler + ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \Countable)) {\n") + ->indent() + ->write("\$length = count(\$context['_seq']);\n") + ->write("\$context['loop']['revindex0'] = \$length - 1;\n") + ->write("\$context['loop']['revindex'] = \$length;\n") + ->write("\$context['loop']['length'] = \$length;\n") + ->write("\$context['loop']['last'] = 1 === \$length;\n") + ->outdent() + ->write("}\n") + ; + } + } + + $this->loop->setAttribute('else', $this->hasNode('else')); + $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop')); + $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr')); + + $compiler + ->write("foreach (\$context['_seq'] as ") + ->subcompile($this->getNode('key_target')) + ->raw(' => ') + ->subcompile($this->getNode('value_target')) + ->raw(") {\n") + ->indent() + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n") + ; + + if ($this->hasNode('else')) { + $compiler + ->write("if (!\$context['_iterated']) {\n") + ->indent() + ->subcompile($this->getNode('else')) + ->outdent() + ->write("}\n") + ; + } + + $compiler->write("\$_parent = \$context['_parent'];\n"); + + // remove some "private" loop variables (needed for nested loops) + $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); + + // keep the values set in the inner context for variables defined in the outer context + $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n"); + } +} + +class_alias('Twig\Node\ForNode', 'Twig_Node_For'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IfNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IfNode.php new file mode 100644 index 0000000..4836d91 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IfNode.php @@ -0,0 +1,72 @@ + + */ +class IfNode extends Node +{ + public function __construct(\Twig_NodeInterface $tests, \Twig_NodeInterface $else = null, $lineno, $tag = null) + { + $nodes = ['tests' => $tests]; + if (null !== $else) { + $nodes['else'] = $else; + } + + parent::__construct($nodes, [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) { + if ($i > 0) { + $compiler + ->outdent() + ->write('} elseif (') + ; + } else { + $compiler + ->write('if (') + ; + } + + $compiler + ->subcompile($this->getNode('tests')->getNode($i)) + ->raw(") {\n") + ->indent() + ->subcompile($this->getNode('tests')->getNode($i + 1)) + ; + } + + if ($this->hasNode('else')) { + $compiler + ->outdent() + ->write("} else {\n") + ->indent() + ->subcompile($this->getNode('else')) + ; + } + + $compiler + ->outdent() + ->write("}\n"); + } +} + +class_alias('Twig\Node\IfNode', 'Twig_Node_If'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ImportNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ImportNode.php new file mode 100644 index 0000000..236db89 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ImportNode.php @@ -0,0 +1,57 @@ + + */ +class ImportNode extends Node +{ + public function __construct(AbstractExpression $expr, AbstractExpression $var, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('') + ->subcompile($this->getNode('var')) + ->raw(' = ') + ; + + if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) { + $compiler->raw('$this'); + } else { + $compiler + ->raw('$this->loadTemplate(') + ->subcompile($this->getNode('expr')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')->unwrap()') + ; + } + + $compiler->raw(";\n"); + } +} + +class_alias('Twig\Node\ImportNode', 'Twig_Node_Import'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IncludeNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IncludeNode.php new file mode 100644 index 0000000..544db81 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/IncludeNode.php @@ -0,0 +1,108 @@ + + */ +class IncludeNode extends Node implements NodeOutputInterface +{ + public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) + { + $nodes = ['expr' => $expr]; + if (null !== $variables) { + $nodes['variables'] = $variables; + } + + parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if ($this->getAttribute('ignore_missing')) { + $template = $compiler->getVarName(); + + $compiler + ->write(sprintf("$%s = null;\n", $template)) + ->write("try {\n") + ->indent() + ->write(sprintf('$%s = ', $template)) + ; + + $this->addGetTemplate($compiler); + + $compiler + ->raw(";\n") + ->outdent() + ->write("} catch (LoaderError \$e) {\n") + ->indent() + ->write("// ignore missing template\n") + ->outdent() + ->write("}\n") + ->write(sprintf("if ($%s) {\n", $template)) + ->indent() + ->write(sprintf('$%s->display(', $template)) + ; + $this->addTemplateArguments($compiler); + $compiler + ->raw(");\n") + ->outdent() + ->write("}\n") + ; + } else { + $this->addGetTemplate($compiler); + $compiler->raw('->display('); + $this->addTemplateArguments($compiler); + $compiler->raw(");\n"); + } + } + + protected function addGetTemplate(Compiler $compiler) + { + $compiler + ->write('$this->loadTemplate(') + ->subcompile($this->getNode('expr')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')') + ; + } + + protected function addTemplateArguments(Compiler $compiler) + { + if (!$this->hasNode('variables')) { + $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('twig_array_merge($context, ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; + } else { + $compiler->raw('twig_to_array('); + $compiler->subcompile($this->getNode('variables')); + $compiler->raw(')'); + } + } +} + +class_alias('Twig\Node\IncludeNode', 'Twig_Node_Include'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/MacroNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/MacroNode.php new file mode 100644 index 0000000..6eb6795 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/MacroNode.php @@ -0,0 +1,136 @@ + + */ +class MacroNode extends Node +{ + const VARARGS_NAME = 'varargs'; + + public function __construct($name, \Twig_NodeInterface $body, \Twig_NodeInterface $arguments, $lineno, $tag = null) + { + foreach ($arguments as $argumentName => $argument) { + if (self::VARARGS_NAME === $argumentName) { + throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine(), $argument->getSourceContext()); + } + } + + parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf('public function get%s(', $this->getAttribute('name'))) + ; + + $count = \count($this->getNode('arguments')); + $pos = 0; + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->raw('$__'.$name.'__ = ') + ->subcompile($default) + ; + + if (++$pos < $count) { + $compiler->raw(', '); + } + } + + if (\PHP_VERSION_ID >= 50600) { + if ($count) { + $compiler->raw(', '); + } + + $compiler->raw('...$__varargs__'); + } + + $compiler + ->raw(")\n") + ->write("{\n") + ->indent() + ; + + $compiler + ->write("\$context = \$this->env->mergeGlobals([\n") + ->indent() + ; + + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->write('') + ->string($name) + ->raw(' => $__'.$name.'__') + ->raw(",\n") + ; + } + + $compiler + ->write('') + ->string(self::VARARGS_NAME) + ->raw(' => ') + ; + + if (\PHP_VERSION_ID >= 50600) { + $compiler->raw("\$__varargs__,\n"); + } else { + $compiler + ->raw('func_num_args() > ') + ->repr($count) + ->raw(' ? array_slice(func_get_args(), ') + ->repr($count) + ->raw(") : [],\n") + ; + } + + $compiler + ->outdent() + ->write("]);\n\n") + ->write("\$blocks = [];\n\n") + ; + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->write("try {\n") + ->indent() + ->subcompile($this->getNode('body')) + ->outdent() + ->write("} catch (\Exception \$e) {\n") + ->indent() + ->write("ob_end_clean();\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("} catch (\Throwable \$e) {\n") + ->indent() + ->write("ob_end_clean();\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("}\n\n") + ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n") + ->outdent() + ->write("}\n\n") + ; + } +} + +class_alias('Twig\Node\MacroNode', 'Twig_Node_Macro'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ModuleNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ModuleNode.php new file mode 100644 index 0000000..aab2aa3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/ModuleNode.php @@ -0,0 +1,492 @@ + + */ +class ModuleNode extends Node +{ + public function __construct(\Twig_NodeInterface $body, AbstractExpression $parent = null, \Twig_NodeInterface $blocks, \Twig_NodeInterface $macros, \Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') + { + if (!$name instanceof Source) { + @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + $source = new Source($source, $name); + } else { + $source = $name; + } + + $nodes = [ + 'body' => $body, + 'blocks' => $blocks, + 'macros' => $macros, + 'traits' => $traits, + 'display_start' => new Node(), + 'display_end' => new Node(), + 'constructor_start' => new Node(), + 'constructor_end' => new Node(), + 'class_end' => new Node(), + ]; + if (null !== $parent) { + $nodes['parent'] = $parent; + } + + // embedded templates are set as attributes so that they are only visited once by the visitors + parent::__construct($nodes, [ + // source to be remove in 2.0 + 'source' => $source->getCode(), + // filename to be remove in 2.0 (use getTemplateName() instead) + 'filename' => $source->getName(), + 'index' => null, + 'embedded_templates' => $embeddedTemplates, + ], 1); + + // populate the template name of all node children + $this->setTemplateName($source->getName()); + $this->setSourceContext($source); + } + + public function setIndex($index) + { + $this->setAttribute('index', $index); + } + + public function compile(Compiler $compiler) + { + $this->compileTemplate($compiler); + + foreach ($this->getAttribute('embedded_templates') as $template) { + $compiler->subcompile($template); + } + } + + protected function compileTemplate(Compiler $compiler) + { + if (!$this->getAttribute('index')) { + $compiler->write('compileClassHeader($compiler); + + if ( + \count($this->getNode('blocks')) + || \count($this->getNode('traits')) + || !$this->hasNode('parent') + || $this->getNode('parent') instanceof ConstantExpression + || \count($this->getNode('constructor_start')) + || \count($this->getNode('constructor_end')) + ) { + $this->compileConstructor($compiler); + } + + $this->compileGetParent($compiler); + + $this->compileDisplay($compiler); + + $compiler->subcompile($this->getNode('blocks')); + + $this->compileMacros($compiler); + + $this->compileGetTemplateName($compiler); + + $this->compileIsTraitable($compiler); + + $this->compileDebugInfo($compiler); + + $this->compileGetSource($compiler); + + $this->compileGetSourceContext($compiler); + + $this->compileClassFooter($compiler); + } + + protected function compileGetParent(Compiler $compiler) + { + if (!$this->hasNode('parent')) { + return; + } + $parent = $this->getNode('parent'); + + $compiler + ->write("protected function doGetParent(array \$context)\n", "{\n") + ->indent() + ->addDebugInfo($parent) + ->write('return ') + ; + + if ($parent instanceof ConstantExpression) { + $compiler->subcompile($parent); + } else { + $compiler + ->raw('$this->loadTemplate(') + ->subcompile($parent) + ->raw(', ') + ->repr($this->getSourceContext()->getName()) + ->raw(', ') + ->repr($parent->getTemplateLine()) + ->raw(')') + ; + } + + $compiler + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassHeader(Compiler $compiler) + { + $compiler + ->write("\n\n") + ; + if (!$this->getAttribute('index')) { + $compiler + ->write("use Twig\Environment;\n") + ->write("use Twig\Error\LoaderError;\n") + ->write("use Twig\Error\RuntimeError;\n") + ->write("use Twig\Markup;\n") + ->write("use Twig\Sandbox\SecurityError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedTagError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n") + ->write("use Twig\Source;\n") + ->write("use Twig\Template;\n\n") + ; + } + $compiler + // if the template name contains */, add a blank to avoid a PHP parse error + ->write('/* '.str_replace('*/', '* /', $this->getSourceContext()->getName())." */\n") + ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index'))) + ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) + ->write("{\n") + ->indent() + ; + } + + protected function compileConstructor(Compiler $compiler) + { + $compiler + ->write("public function __construct(Environment \$env)\n", "{\n") + ->indent() + ->subcompile($this->getNode('constructor_start')) + ->write("parent::__construct(\$env);\n\n") + ; + + // parent + if (!$this->hasNode('parent')) { + $compiler->write("\$this->parent = false;\n\n"); + } + + $countTraits = \count($this->getNode('traits')); + if ($countTraits) { + // traits + foreach ($this->getNode('traits') as $i => $trait) { + $this->compileLoadTemplate($compiler, $trait->getNode('template'), sprintf('$_trait_%s', $i)); + + $node = $trait->getNode('template'); + $compiler + ->addDebugInfo($node) + ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) + ->indent() + ->write("throw new RuntimeError('Template \"'.") + ->subcompile($trait->getNode('template')) + ->raw(".'\" cannot be used as a trait.', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->getSourceContext());\n") + ->outdent() + ->write("}\n") + ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i)) + ; + + foreach ($trait->getNode('targets') as $key => $value) { + $compiler + ->write(sprintf('if (!isset($_trait_%s_blocks[', $i)) + ->string($key) + ->raw("])) {\n") + ->indent() + ->write("throw new RuntimeError(sprintf('Block ") + ->string($key) + ->raw(' is not defined in trait ') + ->subcompile($trait->getNode('template')) + ->raw(".'), ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->getSourceContext());\n") + ->outdent() + ->write("}\n\n") + + ->write(sprintf('$_trait_%s_blocks[', $i)) + ->subcompile($value) + ->raw(sprintf('] = $_trait_%s_blocks[', $i)) + ->string($key) + ->raw(sprintf(']; unset($_trait_%s_blocks[', $i)) + ->string($key) + ->raw("]);\n\n") + ; + } + } + + if ($countTraits > 1) { + $compiler + ->write("\$this->traits = array_merge(\n") + ->indent() + ; + + for ($i = 0; $i < $countTraits; ++$i) { + $compiler + ->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i)) + ; + } + + $compiler + ->outdent() + ->write(");\n\n") + ; + } else { + $compiler + ->write("\$this->traits = \$_trait_0_blocks;\n\n") + ; + } + + $compiler + ->write("\$this->blocks = array_merge(\n") + ->indent() + ->write("\$this->traits,\n") + ->write("[\n") + ; + } else { + $compiler + ->write("\$this->blocks = [\n") + ; + } + + // blocks + $compiler + ->indent() + ; + + foreach ($this->getNode('blocks') as $name => $node) { + $compiler + ->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name)) + ; + } + + if ($countTraits) { + $compiler + ->outdent() + ->write("]\n") + ->outdent() + ->write(");\n") + ; + } else { + $compiler + ->outdent() + ->write("];\n") + ; + } + + $compiler + ->subcompile($this->getNode('constructor_end')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileDisplay(Compiler $compiler) + { + $compiler + ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") + ->indent() + ->subcompile($this->getNode('display_start')) + ->subcompile($this->getNode('body')) + ; + + if ($this->hasNode('parent')) { + $parent = $this->getNode('parent'); + + $compiler->addDebugInfo($parent); + if ($parent instanceof ConstantExpression) { + $compiler + ->write('$this->parent = $this->loadTemplate(') + ->subcompile($parent) + ->raw(', ') + ->repr($this->getSourceContext()->getName()) + ->raw(', ') + ->repr($parent->getTemplateLine()) + ->raw(");\n") + ; + $compiler->write('$this->parent'); + } else { + $compiler->write('$this->getParent($context)'); + } + $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n"); + } + + $compiler + ->subcompile($this->getNode('display_end')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassFooter(Compiler $compiler) + { + $compiler + ->subcompile($this->getNode('class_end')) + ->outdent() + ->write("}\n") + ; + } + + protected function compileMacros(Compiler $compiler) + { + $compiler->subcompile($this->getNode('macros')); + } + + protected function compileGetTemplateName(Compiler $compiler) + { + $compiler + ->write("public function getTemplateName()\n", "{\n") + ->indent() + ->write('return ') + ->repr($this->getSourceContext()->getName()) + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileIsTraitable(Compiler $compiler) + { + // A template can be used as a trait if: + // * it has no parent + // * it has no macros + // * it has no body + // + // Put another way, a template can be used as a trait if it + // only contains blocks and use statements. + $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros')); + if ($traitable) { + if ($this->getNode('body') instanceof BodyNode) { + $nodes = $this->getNode('body')->getNode(0); + } else { + $nodes = $this->getNode('body'); + } + + if (!\count($nodes)) { + $nodes = new Node([$nodes]); + } + + foreach ($nodes as $node) { + if (!\count($node)) { + continue; + } + + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { + continue; + } + + if ($node instanceof BlockReferenceNode) { + continue; + } + + $traitable = false; + break; + } + } + + if ($traitable) { + return; + } + + $compiler + ->write("public function isTraitable()\n", "{\n") + ->indent() + ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileDebugInfo(Compiler $compiler) + { + $compiler + ->write("public function getDebugInfo()\n", "{\n") + ->indent() + ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true)))) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileGetSource(Compiler $compiler) + { + $compiler + ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n") + ->write("public function getSource()\n", "{\n") + ->indent() + ->write("@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);\n\n") + ->write('return $this->getSourceContext()->getCode();') + ->raw("\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileGetSourceContext(Compiler $compiler) + { + $compiler + ->write("public function getSourceContext()\n", "{\n") + ->indent() + ->write('return new Source(') + ->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '') + ->raw(', ') + ->string($this->getSourceContext()->getName()) + ->raw(', ') + ->string($this->getSourceContext()->getPath()) + ->raw(");\n") + ->outdent() + ->write("}\n") + ; + } + + protected function compileLoadTemplate(Compiler $compiler, $node, $var) + { + if ($node instanceof ConstantExpression) { + $compiler + ->write(sprintf('%s = $this->loadTemplate(', $var)) + ->subcompile($node) + ->raw(', ') + ->repr($node->getTemplateName()) + ->raw(', ') + ->repr($node->getTemplateLine()) + ->raw(");\n") + ; + } else { + throw new \LogicException('Trait templates can only be constant nodes.'); + } + } +} + +class_alias('Twig\Node\ModuleNode', 'Twig_Node_Module'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Node.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Node.php new file mode 100644 index 0000000..c890feb --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/Node.php @@ -0,0 +1,274 @@ + + */ +class Node implements \Twig_NodeInterface +{ + protected $nodes; + protected $attributes; + protected $lineno; + protected $tag; + + private $name; + private $sourceContext; + + /** + * @param array $nodes An array of named nodes + * @param array $attributes An array of attributes (should not be nodes) + * @param int $lineno The line number + * @param string $tag The tag name associated with the Node + */ + public function __construct(array $nodes = [], array $attributes = [], $lineno = 0, $tag = null) + { + foreach ($nodes as $name => $node) { + if (!$node instanceof \Twig_NodeInterface) { + @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, \get_class($this)), E_USER_DEPRECATED); + } + } + $this->nodes = $nodes; + $this->attributes = $attributes; + $this->lineno = $lineno; + $this->tag = $tag; + } + + public function __toString() + { + $attributes = []; + foreach ($this->attributes as $name => $value) { + $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); + } + + $repr = [\get_class($this).'('.implode(', ', $attributes)]; + + if (\count($this->nodes)) { + foreach ($this->nodes as $name => $node) { + $len = \strlen($name) + 4; + $noderepr = []; + foreach (explode("\n", (string) $node) as $line) { + $noderepr[] = str_repeat(' ', $len).$line; + } + + $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr))); + } + + $repr[] = ')'; + } else { + $repr[0] .= ')'; + } + + return implode("\n", $repr); + } + + /** + * @deprecated since 1.16.1 (to be removed in 2.0) + */ + public function toXml($asDom = false) + { + @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + + $dom = new \DOMDocument('1.0', 'UTF-8'); + $dom->formatOutput = true; + $dom->appendChild($xml = $dom->createElement('twig')); + + $xml->appendChild($node = $dom->createElement('node')); + $node->setAttribute('class', \get_class($this)); + + foreach ($this->attributes as $name => $value) { + $node->appendChild($attribute = $dom->createElement('attribute')); + $attribute->setAttribute('name', $name); + $attribute->appendChild($dom->createTextNode($value)); + } + + foreach ($this->nodes as $name => $n) { + if (null === $n) { + continue; + } + + $child = $n->toXml(true)->getElementsByTagName('node')->item(0); + $child = $dom->importNode($child, true); + $child->setAttribute('name', $name); + + $node->appendChild($child); + } + + return $asDom ? $dom : $dom->saveXML(); + } + + public function compile(Compiler $compiler) + { + foreach ($this->nodes as $node) { + $node->compile($compiler); + } + } + + public function getTemplateLine() + { + return $this->lineno; + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getLine() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED); + + return $this->lineno; + } + + public function getNodeTag() + { + return $this->tag; + } + + /** + * @return bool + */ + public function hasAttribute($name) + { + return \array_key_exists($name, $this->attributes); + } + + /** + * @return mixed + */ + public function getAttribute($name) + { + if (!\array_key_exists($name, $this->attributes)) { + throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, \get_class($this))); + } + + return $this->attributes[$name]; + } + + /** + * @param string $name + * @param mixed $value + */ + public function setAttribute($name, $value) + { + $this->attributes[$name] = $value; + } + + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + + /** + * @return bool + */ + public function hasNode($name) + { + return \array_key_exists($name, $this->nodes); + } + + /** + * @return Node + */ + public function getNode($name) + { + if (!\array_key_exists($name, $this->nodes)) { + throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, \get_class($this))); + } + + return $this->nodes[$name]; + } + + public function setNode($name, $node = null) + { + if (!$node instanceof \Twig_NodeInterface) { + @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, \get_class($this)), E_USER_DEPRECATED); + } + + $this->nodes[$name] = $node; + } + + public function removeNode($name) + { + unset($this->nodes[$name]); + } + + public function count() + { + return \count($this->nodes); + } + + public function getIterator() + { + return new \ArrayIterator($this->nodes); + } + + public function setTemplateName($name) + { + $this->name = $name; + foreach ($this->nodes as $node) { + if (null !== $node) { + $node->setTemplateName($name); + } + } + } + + public function getTemplateName() + { + return $this->name; + } + + public function setSourceContext(Source $source) + { + $this->sourceContext = $source; + foreach ($this->nodes as $node) { + if ($node instanceof Node) { + $node->setSourceContext($source); + } + } + } + + public function getSourceContext() + { + return $this->sourceContext; + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function setFilename($name) + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED); + + $this->setTemplateName($name); + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getFilename() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED); + + return $this->name; + } +} + +class_alias('Twig\Node\Node', 'Twig_Node'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Compiler'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeCaptureInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeCaptureInterface.php new file mode 100644 index 0000000..474003f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeCaptureInterface.php @@ -0,0 +1,23 @@ + + */ +interface NodeCaptureInterface +{ +} + +class_alias('Twig\Node\NodeCaptureInterface', 'Twig_NodeCaptureInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeOutputInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeOutputInterface.php new file mode 100644 index 0000000..8b046ee --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/NodeOutputInterface.php @@ -0,0 +1,23 @@ + + */ +interface NodeOutputInterface +{ +} + +class_alias('Twig\Node\NodeOutputInterface', 'Twig_NodeOutputInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/PrintNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/PrintNode.php new file mode 100644 index 0000000..27f1ca4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/PrintNode.php @@ -0,0 +1,41 @@ + + */ +class PrintNode extends Node implements NodeOutputInterface +{ + public function __construct(AbstractExpression $expr, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} + +class_alias('Twig\Node\PrintNode', 'Twig_Node_Print'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxNode.php new file mode 100644 index 0000000..2d644c3 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxNode.php @@ -0,0 +1,47 @@ + + */ +class SandboxNode extends Node +{ + public function __construct(\Twig_NodeInterface $body, $lineno, $tag = null) + { + parent::__construct(['body' => $body], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {\n") + ->indent() + ->write("\$this->sandbox->enableSandbox();\n") + ->outdent() + ->write("}\n") + ->subcompile($this->getNode('body')) + ->write("if (!\$alreadySandboxed) {\n") + ->indent() + ->write("\$this->sandbox->disableSandbox();\n") + ->outdent() + ->write("}\n") + ; + } +} + +class_alias('Twig\Node\SandboxNode', 'Twig_Node_Sandbox'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxedPrintNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxedPrintNode.php new file mode 100644 index 0000000..2359af9 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SandboxedPrintNode.php @@ -0,0 +1,69 @@ + + */ +class SandboxedPrintNode extends PrintNode +{ + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ; + $expr = $this->getNode('expr'); + if ($expr instanceof ConstantExpression) { + $compiler + ->subcompile($expr) + ->raw(";\n") + ; + } else { + $compiler + ->write('$this->env->getExtension(\'\Twig\Extension\SandboxExtension\')->ensureToStringAllowed(') + ->subcompile($expr) + ->raw(");\n") + ; + } + } + + /** + * Removes node filters. + * + * This is mostly needed when another visitor adds filters (like the escaper one). + * + * @return Node + */ + protected function removeNodeFilter(Node $node) + { + if ($node instanceof FilterExpression) { + return $this->removeNodeFilter($node->getNode('node')); + } + + return $node; + } +} + +class_alias('Twig\Node\SandboxedPrintNode', 'Twig_Node_SandboxedPrint'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetNode.php new file mode 100644 index 0000000..656103b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetNode.php @@ -0,0 +1,107 @@ + + */ +class SetNode extends Node implements NodeCaptureInterface +{ + public function __construct($capture, \Twig_NodeInterface $names, \Twig_NodeInterface $values, $lineno, $tag = null) + { + parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag); + + /* + * Optimizes the node when capture is used for a large block of text. + * + * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig\Markup("foo"); + */ + if ($this->getAttribute('capture')) { + $this->setAttribute('safe', true); + + $values = $this->getNode('values'); + if ($values instanceof TextNode) { + $this->setNode('values', new ConstantExpression($values->getAttribute('data'), $values->getTemplateLine())); + $this->setAttribute('capture', false); + } + } + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if (\count($this->getNode('names')) > 1) { + $compiler->write('list('); + foreach ($this->getNode('names') as $idx => $node) { + if ($idx) { + $compiler->raw(', '); + } + + $compiler->subcompile($node); + } + $compiler->raw(')'); + } else { + if ($this->getAttribute('capture')) { + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->subcompile($this->getNode('values')) + ; + } + + $compiler->subcompile($this->getNode('names'), false); + + if ($this->getAttribute('capture')) { + $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset())"); + } + } + + if (!$this->getAttribute('capture')) { + $compiler->raw(' = '); + + if (\count($this->getNode('names')) > 1) { + $compiler->write('['); + foreach ($this->getNode('values') as $idx => $value) { + if ($idx) { + $compiler->raw(', '); + } + + $compiler->subcompile($value); + } + $compiler->raw(']'); + } else { + if ($this->getAttribute('safe')) { + $compiler + ->raw("('' === \$tmp = ") + ->subcompile($this->getNode('values')) + ->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())") + ; + } else { + $compiler->subcompile($this->getNode('values')); + } + } + } + + $compiler->raw(";\n"); + } +} + +class_alias('Twig\Node\SetNode', 'Twig_Node_Set'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetTempNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetTempNode.php new file mode 100644 index 0000000..918fb99 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SetTempNode.php @@ -0,0 +1,44 @@ + $name], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + $compiler + ->addDebugInfo($this) + ->write('if (isset($context[') + ->string($name) + ->raw('])) { $_') + ->raw($name) + ->raw('_ = $context[') + ->repr($name) + ->raw(']; } else { $_') + ->raw($name) + ->raw("_ = null; }\n") + ; + } +} + +class_alias('Twig\Node\SetTempNode', 'Twig_Node_SetTemp'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SpacelessNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SpacelessNode.php new file mode 100644 index 0000000..c8d32da --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/SpacelessNode.php @@ -0,0 +1,47 @@ + + */ +class SpacelessNode extends Node +{ + public function __construct(\Twig_NodeInterface $body, $lineno, $tag = 'spaceless') + { + parent::__construct(['body' => $body], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ; + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->subcompile($this->getNode('body')) + ->write("echo trim(preg_replace('/>\s+<', ob_get_clean()));\n") + ; + } +} + +class_alias('Twig\Node\SpacelessNode', 'Twig_Node_Spaceless'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/TextNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/TextNode.php new file mode 100644 index 0000000..9ac435e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/TextNode.php @@ -0,0 +1,40 @@ + + */ +class TextNode extends Node implements NodeOutputInterface +{ + public function __construct($data, $lineno) + { + parent::__construct([], ['data' => $data], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->string($this->getAttribute('data')) + ->raw(";\n") + ; + } +} + +class_alias('Twig\Node\TextNode', 'Twig_Node_Text'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/WithNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/WithNode.php new file mode 100644 index 0000000..f5ae924 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Node/WithNode.php @@ -0,0 +1,72 @@ + + */ +class WithNode extends Node +{ + public function __construct(Node $body, Node $variables = null, $only = false, $lineno, $tag = null) + { + $nodes = ['body' => $body]; + if (null !== $variables) { + $nodes['variables'] = $variables; + } + + parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if ($this->hasNode('variables')) { + $node = $this->getNode('variables'); + $varsName = $compiler->getVarName(); + $compiler + ->write(sprintf('$%s = ', $varsName)) + ->subcompile($node) + ->raw(";\n") + ->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName)) + ->indent() + ->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->getSourceContext());\n") + ->outdent() + ->write("}\n") + ->write(sprintf("\$%s = twig_to_array(\$%s);\n", $varsName, $varsName)) + ; + + if ($this->getAttribute('only')) { + $compiler->write("\$context = ['_parent' => \$context];\n"); + } else { + $compiler->write("\$context['_parent'] = \$context;\n"); + } + + $compiler->write(sprintf("\$context = \$this->env->mergeGlobals(array_merge(\$context, \$%s));\n", $varsName)); + } else { + $compiler->write("\$context['_parent'] = \$context;\n"); + } + + $compiler + ->subcompile($this->getNode('body')) + ->write("\$context = \$context['_parent'];\n") + ; + } +} + +class_alias('Twig\Node\WithNode', 'Twig_Node_With'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeTraverser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeTraverser.php new file mode 100644 index 0000000..bd25d3c --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeTraverser.php @@ -0,0 +1,89 @@ + + */ +class NodeTraverser +{ + protected $env; + protected $visitors = []; + + /** + * @param NodeVisitorInterface[] $visitors + */ + public function __construct(Environment $env, array $visitors = []) + { + $this->env = $env; + foreach ($visitors as $visitor) { + $this->addVisitor($visitor); + } + } + + public function addVisitor(NodeVisitorInterface $visitor) + { + $this->visitors[$visitor->getPriority()][] = $visitor; + } + + /** + * Traverses a node and calls the registered visitors. + * + * @return \Twig_NodeInterface + */ + public function traverse(\Twig_NodeInterface $node) + { + ksort($this->visitors); + foreach ($this->visitors as $visitors) { + foreach ($visitors as $visitor) { + $node = $this->traverseForVisitor($visitor, $node); + } + } + + return $node; + } + + protected function traverseForVisitor(NodeVisitorInterface $visitor, \Twig_NodeInterface $node = null) + { + if (null === $node) { + return; + } + + $node = $visitor->enterNode($node, $this->env); + + foreach ($node as $k => $n) { + if (null === $n) { + continue; + } + + if (false !== ($m = $this->traverseForVisitor($visitor, $n)) && null !== $m) { + if ($m !== $n) { + $node->setNode($k, $m); + } + } else { + $node->removeNode($k); + } + } + + return $visitor->leaveNode($node, $this->env); + } +} + +class_alias('Twig\NodeTraverser', 'Twig_NodeTraverser'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php new file mode 100644 index 0000000..b66c3c6 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php @@ -0,0 +1,59 @@ + + */ +abstract class AbstractNodeVisitor implements NodeVisitorInterface +{ + final public function enterNode(\Twig_NodeInterface $node, Environment $env) + { + if (!$node instanceof Node) { + throw new \LogicException(sprintf('%s only supports \Twig\Node\Node instances.', __CLASS__)); + } + + return $this->doEnterNode($node, $env); + } + + final public function leaveNode(\Twig_NodeInterface $node, Environment $env) + { + if (!$node instanceof Node) { + throw new \LogicException(sprintf('%s only supports \Twig\Node\Node instances.', __CLASS__)); + } + + return $this->doLeaveNode($node, $env); + } + + /** + * Called before child nodes are visited. + * + * @return Node The modified node + */ + abstract protected function doEnterNode(Node $node, Environment $env); + + /** + * Called after child nodes are visited. + * + * @return Node|false|null The modified node or null if the node must be removed + */ + abstract protected function doLeaveNode(Node $node, Environment $env); +} + +class_alias('Twig\NodeVisitor\AbstractNodeVisitor', 'Twig_BaseNodeVisitor'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php new file mode 100644 index 0000000..f6e16fa --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php @@ -0,0 +1,209 @@ + + */ +class EscaperNodeVisitor extends AbstractNodeVisitor +{ + protected $statusStack = []; + protected $blocks = []; + protected $safeAnalysis; + protected $traverser; + protected $defaultStrategy = false; + protected $safeVars = []; + + public function __construct() + { + $this->safeAnalysis = new SafeAnalysisNodeVisitor(); + } + + protected function doEnterNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + if ($env->hasExtension('\Twig\Extension\EscaperExtension') && $defaultStrategy = $env->getExtension('\Twig\Extension\EscaperExtension')->getDefaultStrategy($node->getTemplateName())) { + $this->defaultStrategy = $defaultStrategy; + } + $this->safeVars = []; + $this->blocks = []; + } elseif ($node instanceof AutoEscapeNode) { + $this->statusStack[] = $node->getAttribute('value'); + } elseif ($node instanceof BlockNode) { + $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); + } elseif ($node instanceof ImportNode) { + $this->safeVars[] = $node->getNode('var')->getAttribute('name'); + } + + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->defaultStrategy = false; + $this->safeVars = []; + $this->blocks = []; + } elseif ($node instanceof FilterExpression) { + return $this->preEscapeFilterNode($node, $env); + } elseif ($node instanceof PrintNode && false !== $type = $this->needEscaping($env)) { + $expression = $node->getNode('expr'); + if ($expression instanceof ConditionalExpression && $this->shouldUnwrapConditional($expression, $env, $type)) { + return new DoNode($this->unwrapConditional($expression, $env, $type), $expression->getTemplateLine()); + } + + return $this->escapePrintNode($node, $env, $type); + } + + if ($node instanceof AutoEscapeNode || $node instanceof BlockNode) { + array_pop($this->statusStack); + } elseif ($node instanceof BlockReferenceNode) { + $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); + } + + return $node; + } + + private function shouldUnwrapConditional(ConditionalExpression $expression, Environment $env, $type) + { + $expr2Safe = $this->isSafeFor($type, $expression->getNode('expr2'), $env); + $expr3Safe = $this->isSafeFor($type, $expression->getNode('expr3'), $env); + + return $expr2Safe !== $expr3Safe; + } + + private function unwrapConditional(ConditionalExpression $expression, Environment $env, $type) + { + // convert "echo a ? b : c" to "a ? echo b : echo c" recursively + $expr2 = $expression->getNode('expr2'); + if ($expr2 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr2, $env, $type)) { + $expr2 = $this->unwrapConditional($expr2, $env, $type); + } else { + $expr2 = $this->escapeInlinePrintNode(new InlinePrint($expr2, $expr2->getTemplateLine()), $env, $type); + } + $expr3 = $expression->getNode('expr3'); + if ($expr3 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr3, $env, $type)) { + $expr3 = $this->unwrapConditional($expr3, $env, $type); + } else { + $expr3 = $this->escapeInlinePrintNode(new InlinePrint($expr3, $expr3->getTemplateLine()), $env, $type); + } + + return new ConditionalExpression($expression->getNode('expr1'), $expr2, $expr3, $expression->getTemplateLine()); + } + + private function escapeInlinePrintNode(InlinePrint $node, Environment $env, $type) + { + $expression = $node->getNode('node'); + + if ($this->isSafeFor($type, $expression, $env)) { + return $node; + } + + return new InlinePrint($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); + } + + protected function escapePrintNode(PrintNode $node, Environment $env, $type) + { + if (false === $type) { + return $node; + } + + $expression = $node->getNode('expr'); + + if ($this->isSafeFor($type, $expression, $env)) { + return $node; + } + + $class = \get_class($node); + + return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); + } + + protected function preEscapeFilterNode(FilterExpression $filter, Environment $env) + { + $name = $filter->getNode('filter')->getAttribute('value'); + + $type = $env->getFilter($name)->getPreEscape(); + if (null === $type) { + return $filter; + } + + $node = $filter->getNode('node'); + if ($this->isSafeFor($type, $node, $env)) { + return $filter; + } + + $filter->setNode('node', $this->getEscaperFilter($type, $node)); + + return $filter; + } + + protected function isSafeFor($type, \Twig_NodeInterface $expression, $env) + { + $safe = $this->safeAnalysis->getSafe($expression); + + if (null === $safe) { + if (null === $this->traverser) { + $this->traverser = new NodeTraverser($env, [$this->safeAnalysis]); + } + + $this->safeAnalysis->setSafeVars($this->safeVars); + + $this->traverser->traverse($expression); + $safe = $this->safeAnalysis->getSafe($expression); + } + + return \in_array($type, $safe) || \in_array('all', $safe); + } + + protected function needEscaping(Environment $env) + { + if (\count($this->statusStack)) { + return $this->statusStack[\count($this->statusStack) - 1]; + } + + return $this->defaultStrategy ? $this->defaultStrategy : false; + } + + protected function getEscaperFilter($type, \Twig_NodeInterface $node) + { + $line = $node->getTemplateLine(); + $name = new ConstantExpression('escape', $line); + $args = new Node([new ConstantExpression((string) $type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]); + + return new FilterExpression($node, $name, $args, $line); + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\NodeVisitor\EscaperNodeVisitor', 'Twig_NodeVisitor_Escaper'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php new file mode 100644 index 0000000..9b8730b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php @@ -0,0 +1,50 @@ + + */ +interface NodeVisitorInterface +{ + /** + * Called before child nodes are visited. + * + * @return \Twig_NodeInterface The modified node + */ + public function enterNode(\Twig_NodeInterface $node, Environment $env); + + /** + * Called after child nodes are visited. + * + * @return \Twig_NodeInterface|false|null The modified node or null if the node must be removed + */ + public function leaveNode(\Twig_NodeInterface $node, Environment $env); + + /** + * Returns the priority for this visitor. + * + * Priority should be between -10 and 10 (0 is the default). + * + * @return int The priority level + */ + public function getPriority(); +} + +class_alias('Twig\NodeVisitor\NodeVisitorInterface', 'Twig_NodeVisitorInterface'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Environment'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php new file mode 100644 index 0000000..e5ea9b7 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php @@ -0,0 +1,273 @@ + + */ +class OptimizerNodeVisitor extends AbstractNodeVisitor +{ + const OPTIMIZE_ALL = -1; + const OPTIMIZE_NONE = 0; + const OPTIMIZE_FOR = 2; + const OPTIMIZE_RAW_FILTER = 4; + const OPTIMIZE_VAR_ACCESS = 8; + + protected $loops = []; + protected $loopsTargets = []; + protected $optimizers; + protected $prependedNodes = []; + protected $inABody = false; + + /** + * @param int $optimizers The optimizer mode + */ + public function __construct($optimizers = -1) + { + if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) { + throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers)); + } + + $this->optimizers = $optimizers; + } + + protected function doEnterNode(Node $node, Environment $env) + { + if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { + $this->enterOptimizeFor($node, $env); + } + + if (\PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) { + if ($this->inABody) { + if (!$node instanceof AbstractExpression) { + if ('Twig_Node' !== \get_class($node)) { + array_unshift($this->prependedNodes, []); + } + } else { + $node = $this->optimizeVariables($node, $env); + } + } elseif ($node instanceof BodyNode) { + $this->inABody = true; + } + } + + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + $expression = $node instanceof AbstractExpression; + + if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { + $this->leaveOptimizeFor($node, $env); + } + + if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) { + $node = $this->optimizeRawFilter($node, $env); + } + + $node = $this->optimizePrintNode($node, $env); + + if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) { + if ($node instanceof BodyNode) { + $this->inABody = false; + } elseif ($this->inABody) { + if (!$expression && 'Twig_Node' !== \get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) { + $nodes = []; + foreach (array_unique($prependedNodes) as $name) { + $nodes[] = new SetTempNode($name, $node->getTemplateLine()); + } + + $nodes[] = $node; + $node = new Node($nodes); + } + } + } + + return $node; + } + + protected function optimizeVariables(\Twig_NodeInterface $node, Environment $env) + { + if ('Twig_Node_Expression_Name' === \get_class($node) && $node->isSimple()) { + $this->prependedNodes[0][] = $node->getAttribute('name'); + + return new TempNameExpression($node->getAttribute('name'), $node->getTemplateLine()); + } + + return $node; + } + + /** + * Optimizes print nodes. + * + * It replaces: + * + * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" + * + * @return \Twig_NodeInterface + */ + protected function optimizePrintNode(\Twig_NodeInterface $node, Environment $env) + { + if (!$node instanceof PrintNode) { + return $node; + } + + $exprNode = $node->getNode('expr'); + if ( + $exprNode instanceof BlockReferenceExpression || + $exprNode instanceof ParentExpression + ) { + $exprNode->setAttribute('output', true); + + return $exprNode; + } + + return $node; + } + + /** + * Removes "raw" filters. + * + * @return \Twig_NodeInterface + */ + protected function optimizeRawFilter(\Twig_NodeInterface $node, Environment $env) + { + if ($node instanceof FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { + return $node->getNode('node'); + } + + return $node; + } + + /** + * Optimizes "for" tag by removing the "loop" variable creation whenever possible. + */ + protected function enterOptimizeFor(\Twig_NodeInterface $node, Environment $env) + { + if ($node instanceof ForNode) { + // disable the loop variable by default + $node->setAttribute('with_loop', false); + array_unshift($this->loops, $node); + array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); + array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); + } elseif (!$this->loops) { + // we are outside a loop + return; + } + + // when do we need to add the loop variable back? + + // the loop variable is referenced for the current loop + elseif ($node instanceof NameExpression && 'loop' === $node->getAttribute('name')) { + $node->setAttribute('always_defined', true); + $this->addLoopToCurrent(); + } + + // optimize access to loop targets + elseif ($node instanceof NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) { + $node->setAttribute('always_defined', true); + } + + // block reference + elseif ($node instanceof BlockReferenceNode || $node instanceof BlockReferenceExpression) { + $this->addLoopToCurrent(); + } + + // include without the only attribute + elseif ($node instanceof IncludeNode && !$node->getAttribute('only')) { + $this->addLoopToAll(); + } + + // include function without the with_context=false parameter + elseif ($node instanceof FunctionExpression + && 'include' === $node->getAttribute('name') + && (!$node->getNode('arguments')->hasNode('with_context') + || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') + ) + ) { + $this->addLoopToAll(); + } + + // the loop variable is referenced via an attribute + elseif ($node instanceof GetAttrExpression + && (!$node->getNode('attribute') instanceof ConstantExpression + || 'parent' === $node->getNode('attribute')->getAttribute('value') + ) + && (true === $this->loops[0]->getAttribute('with_loop') + || ($node->getNode('node') instanceof NameExpression + && 'loop' === $node->getNode('node')->getAttribute('name') + ) + ) + ) { + $this->addLoopToAll(); + } + } + + /** + * Optimizes "for" tag by removing the "loop" variable creation whenever possible. + */ + protected function leaveOptimizeFor(\Twig_NodeInterface $node, Environment $env) + { + if ($node instanceof ForNode) { + array_shift($this->loops); + array_shift($this->loopsTargets); + array_shift($this->loopsTargets); + } + } + + protected function addLoopToCurrent() + { + $this->loops[0]->setAttribute('with_loop', true); + } + + protected function addLoopToAll() + { + foreach ($this->loops as $loop) { + $loop->setAttribute('with_loop', true); + } + } + + public function getPriority() + { + return 255; + } +} + +class_alias('Twig\NodeVisitor\OptimizerNodeVisitor', 'Twig_NodeVisitor_Optimizer'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php new file mode 100644 index 0000000..97a7a3e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php @@ -0,0 +1,164 @@ +safeVars = $safeVars; + } + + public function getSafe(\Twig_NodeInterface $node) + { + $hash = spl_object_hash($node); + if (!isset($this->data[$hash])) { + return; + } + + foreach ($this->data[$hash] as $bucket) { + if ($bucket['key'] !== $node) { + continue; + } + + if (\in_array('html_attr', $bucket['value'])) { + $bucket['value'][] = 'html'; + } + + return $bucket['value']; + } + } + + protected function setSafe(\Twig_NodeInterface $node, array $safe) + { + $hash = spl_object_hash($node); + if (isset($this->data[$hash])) { + foreach ($this->data[$hash] as &$bucket) { + if ($bucket['key'] === $node) { + $bucket['value'] = $safe; + + return; + } + } + } + $this->data[$hash][] = [ + 'key' => $node, + 'value' => $safe, + ]; + } + + protected function doEnterNode(Node $node, Environment $env) + { + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ConstantExpression) { + // constants are marked safe for all + $this->setSafe($node, ['all']); + } elseif ($node instanceof BlockReferenceExpression) { + // blocks are safe by definition + $this->setSafe($node, ['all']); + } elseif ($node instanceof ParentExpression) { + // parent block is safe by definition + $this->setSafe($node, ['all']); + } elseif ($node instanceof ConditionalExpression) { + // intersect safeness of both operands + $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); + $this->setSafe($node, $safe); + } elseif ($node instanceof FilterExpression) { + // filter expression is safe when the filter is safe + $name = $node->getNode('filter')->getAttribute('value'); + $args = $node->getNode('arguments'); + if (false !== $filter = $env->getFilter($name)) { + $safe = $filter->getSafe($args); + if (null === $safe) { + $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety()); + } + $this->setSafe($node, $safe); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof FunctionExpression) { + // function expression is safe when the function is safe + $name = $node->getAttribute('name'); + $args = $node->getNode('arguments'); + $function = $env->getFunction($name); + if (false !== $function) { + $this->setSafe($node, $function->getSafe($args)); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof MethodCallExpression) { + if ($node->getAttribute('safe')) { + $this->setSafe($node, ['all']); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) { + $name = $node->getNode('node')->getAttribute('name'); + // attributes on template instances are safe + if ('_self' == $name || \in_array($name, $this->safeVars)) { + $this->setSafe($node, ['all']); + } else { + $this->setSafe($node, []); + } + } else { + $this->setSafe($node, []); + } + + return $node; + } + + protected function intersectSafe(array $a = null, array $b = null) + { + if (null === $a || null === $b) { + return []; + } + + if (\in_array('all', $a)) { + return $b; + } + + if (\in_array('all', $b)) { + return $a; + } + + return array_intersect($a, $b); + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\NodeVisitor\SafeAnalysisNodeVisitor', 'Twig_NodeVisitor_SafeAnalysis'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php new file mode 100644 index 0000000..c940339 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php @@ -0,0 +1,137 @@ + + */ +class SandboxNodeVisitor extends AbstractNodeVisitor +{ + protected $inAModule = false; + protected $tags; + protected $filters; + protected $functions; + + private $needsToStringWrap = false; + + protected function doEnterNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->inAModule = true; + $this->tags = []; + $this->filters = []; + $this->functions = []; + + return $node; + } elseif ($this->inAModule) { + // look for tags + if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { + $this->tags[$node->getNodeTag()] = $node; + } + + // look for filters + if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { + $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; + } + + // look for functions + if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { + $this->functions[$node->getAttribute('name')] = $node; + } + + // the .. operator is equivalent to the range() function + if ($node instanceof RangeBinary && !isset($this->functions['range'])) { + $this->functions['range'] = $node; + } + + if ($node instanceof PrintNode) { + $this->needsToStringWrap = true; + $this->wrapNode($node, 'expr'); + } + + if ($node instanceof SetNode && !$node->getAttribute('capture')) { + $this->needsToStringWrap = true; + } + + // wrap outer nodes that can implicitly call __toString() + if ($this->needsToStringWrap) { + if ($node instanceof ConcatBinary) { + $this->wrapNode($node, 'left'); + $this->wrapNode($node, 'right'); + } + if ($node instanceof FilterExpression) { + $this->wrapNode($node, 'node'); + $this->wrapArrayNode($node, 'arguments'); + } + if ($node instanceof FunctionExpression) { + $this->wrapArrayNode($node, 'arguments'); + } + } + } + + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->inAModule = false; + + $node->getNode('constructor_end')->setNode('_security_check', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); + } elseif ($this->inAModule) { + if ($node instanceof PrintNode || $node instanceof SetNode) { + $this->needsToStringWrap = false; + } + } + + return $node; + } + + private function wrapNode(Node $node, $name) + { + $expr = $node->getNode($name); + if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) { + $node->setNode($name, new CheckToStringNode($expr)); + } + } + + private function wrapArrayNode(Node $node, $name) + { + $args = $node->getNode($name); + foreach ($args as $name => $_) { + $this->wrapNode($args, $name); + } + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\NodeVisitor\SandboxNodeVisitor', 'Twig_NodeVisitor_Sandbox'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Parser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Parser.php new file mode 100644 index 0000000..9fb6a83 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Parser.php @@ -0,0 +1,439 @@ + + */ +class Parser implements \Twig_ParserInterface +{ + protected $stack = []; + protected $stream; + protected $parent; + protected $handlers; + protected $visitors; + protected $expressionParser; + protected $blocks; + protected $blockStack; + protected $macros; + protected $env; + protected $reservedMacroNames; + protected $importedSymbols; + protected $traits; + protected $embeddedTemplates = []; + private $varNameSalt = 0; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getEnvironment() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + + return $this->env; + } + + public function getVarName() + { + return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++)); + } + + /** + * @deprecated since 1.27 (to be removed in 2.0). Use $parser->getStream()->getSourceContext()->getPath() instead. + */ + public function getFilename() + { + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), E_USER_DEPRECATED); + + return $this->stream->getSourceContext()->getName(); + } + + public function parse(TokenStream $stream, $test = null, $dropNeedle = false) + { + // push all variables into the stack to keep the current state of the parser + // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336 + // This hack can be removed when min version if PHP 7.0 + $vars = []; + foreach ($this as $k => $v) { + $vars[$k] = $v; + } + + unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']); + $this->stack[] = $vars; + + // tag handlers + if (null === $this->handlers) { + $this->handlers = $this->env->getTokenParsers(); + $this->handlers->setParser($this); + } + + // node visitors + if (null === $this->visitors) { + $this->visitors = $this->env->getNodeVisitors(); + } + + if (null === $this->expressionParser) { + $this->expressionParser = new ExpressionParser($this, $this->env); + } + + $this->stream = $stream; + $this->parent = null; + $this->blocks = []; + $this->macros = []; + $this->traits = []; + $this->blockStack = []; + $this->importedSymbols = [[]]; + $this->embeddedTemplates = []; + $this->varNameSalt = 0; + + try { + $body = $this->subparse($test, $dropNeedle); + + if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { + $body = new Node(); + } + } catch (SyntaxError $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($this->stream->getSourceContext()); + } + + if (!$e->getTemplateLine()) { + $e->setTemplateLine($this->stream->getCurrent()->getLine()); + } + + throw $e; + } + + $node = new ModuleNode(new BodyNode([$body]), $this->parent, new Node($this->blocks), new Node($this->macros), new Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); + + $traverser = new NodeTraverser($this->env, $this->visitors); + + $node = $traverser->traverse($node); + + // restore previous stack so previous parse() call can resume working + foreach (array_pop($this->stack) as $key => $val) { + $this->$key = $val; + } + + return $node; + } + + public function subparse($test, $dropNeedle = false) + { + $lineno = $this->getCurrentToken()->getLine(); + $rv = []; + while (!$this->stream->isEOF()) { + switch ($this->getCurrentToken()->getType()) { + case Token::TEXT_TYPE: + $token = $this->stream->next(); + $rv[] = new TextNode($token->getValue(), $token->getLine()); + break; + + case Token::VAR_START_TYPE: + $token = $this->stream->next(); + $expr = $this->expressionParser->parseExpression(); + $this->stream->expect(Token::VAR_END_TYPE); + $rv[] = new PrintNode($expr, $token->getLine()); + break; + + case Token::BLOCK_START_TYPE: + $this->stream->next(); + $token = $this->getCurrentToken(); + + if (Token::NAME_TYPE !== $token->getType()) { + throw new SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); + } + + if (null !== $test && \call_user_func($test, $token)) { + if ($dropNeedle) { + $this->stream->next(); + } + + if (1 === \count($rv)) { + return $rv[0]; + } + + return new Node($rv, [], $lineno); + } + + $subparser = $this->handlers->getTokenParser($token->getValue()); + if (null === $subparser) { + if (null !== $test) { + $e = new SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + + if (\is_array($test) && isset($test[0]) && $test[0] instanceof TokenParserInterface) { + $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); + } + } else { + $e = new SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); + } + + throw $e; + } + + $this->stream->next(); + + $node = $subparser->parse($token); + if (null !== $node) { + $rv[] = $node; + } + break; + + default: + throw new SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); + } + } + + if (1 === \count($rv)) { + return $rv[0]; + } + + return new Node($rv, [], $lineno); + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function addHandler($name, $class) + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + + $this->handlers[$name] = $class; + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + + $this->visitors[] = $visitor; + } + + public function getBlockStack() + { + return $this->blockStack; + } + + public function peekBlockStack() + { + return isset($this->blockStack[\count($this->blockStack) - 1]) ? $this->blockStack[\count($this->blockStack) - 1] : null; + } + + public function popBlockStack() + { + array_pop($this->blockStack); + } + + public function pushBlockStack($name) + { + $this->blockStack[] = $name; + } + + public function hasBlock($name) + { + return isset($this->blocks[$name]); + } + + public function getBlock($name) + { + return $this->blocks[$name]; + } + + public function setBlock($name, BlockNode $value) + { + $this->blocks[$name] = new BodyNode([$value], [], $value->getTemplateLine()); + } + + public function hasMacro($name) + { + return isset($this->macros[$name]); + } + + public function setMacro($name, MacroNode $node) + { + if ($this->isReservedMacroName($name)) { + throw new SyntaxError(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()); + } + + $this->macros[$name] = $node; + } + + public function isReservedMacroName($name) + { + if (null === $this->reservedMacroNames) { + $this->reservedMacroNames = []; + $r = new \ReflectionClass($this->env->getBaseTemplateClass()); + foreach ($r->getMethods() as $method) { + $methodName = strtr($method->getName(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); + + if ('get' === substr($methodName, 0, 3) && isset($methodName[3])) { + $this->reservedMacroNames[] = substr($methodName, 3); + } + } + } + + return \in_array(strtr($name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), $this->reservedMacroNames); + } + + public function addTrait($trait) + { + $this->traits[] = $trait; + } + + public function hasTraits() + { + return \count($this->traits) > 0; + } + + public function embedTemplate(ModuleNode $template) + { + $template->setIndex(mt_rand()); + + $this->embeddedTemplates[] = $template; + } + + public function addImportedSymbol($type, $alias, $name = null, AbstractExpression $node = null) + { + $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; + } + + public function getImportedSymbol($type, $alias) + { + if (null !== $this->peekBlockStack()) { + foreach ($this->importedSymbols as $functions) { + if (isset($functions[$type][$alias])) { + if (\count($this->blockStack) > 1) { + return null; + } + + return $functions[$type][$alias]; + } + } + } else { + return isset($this->importedSymbols[0][$type][$alias]) ? $this->importedSymbols[0][$type][$alias] : null; + } + } + + public function isMainScope() + { + return 1 === \count($this->importedSymbols); + } + + public function pushLocalScope() + { + array_unshift($this->importedSymbols, []); + } + + public function popLocalScope() + { + array_shift($this->importedSymbols); + } + + /** + * @return ExpressionParser + */ + public function getExpressionParser() + { + return $this->expressionParser; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + } + + /** + * @return TokenStream + */ + public function getStream() + { + return $this->stream; + } + + /** + * @return Token + */ + public function getCurrentToken() + { + return $this->stream->getCurrent(); + } + + protected function filterBodyNodes(\Twig_NodeInterface $node) + { + // check that the body does not contain non-empty output nodes + if ( + ($node instanceof TextNode && !ctype_space($node->getAttribute('data'))) + || + (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface) + ) { + if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { + $t = substr($node->getAttribute('data'), 3); + if ('' === $t || ctype_space($t)) { + // bypass empty nodes starting with a BOM + return; + } + } + + throw new SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); + } + + // bypass nodes that will "capture" the output + if ($node instanceof NodeCaptureInterface) { + return $node; + } + + if ($node instanceof NodeOutputInterface) { + return; + } + + foreach ($node as $k => $n) { + if (null !== $n && null === $this->filterBodyNodes($n)) { + $node->removeNode($k); + } + } + + return $node; + } +} + +class_alias('Twig\Parser', 'Twig_Parser'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BaseDumper.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BaseDumper.php new file mode 100644 index 0000000..d965dc7 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BaseDumper.php @@ -0,0 +1,65 @@ + + */ +abstract class BaseDumper +{ + private $root; + + public function dump(Profile $profile) + { + return $this->dumpProfile($profile); + } + + abstract protected function formatTemplate(Profile $profile, $prefix); + + abstract protected function formatNonTemplate(Profile $profile, $prefix); + + abstract protected function formatTime(Profile $profile, $percent); + + private function dumpProfile(Profile $profile, $prefix = '', $sibling = false) + { + if ($profile->isRoot()) { + $this->root = $profile->getDuration(); + $start = $profile->getName(); + } else { + if ($profile->isTemplate()) { + $start = $this->formatTemplate($profile, $prefix); + } else { + $start = $this->formatNonTemplate($profile, $prefix); + } + $prefix .= $sibling ? '│ ' : ' '; + } + + $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0; + + if ($profile->getDuration() * 1000 < 1) { + $str = $start."\n"; + } else { + $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent)); + } + + $nCount = \count($profile->getProfiles()); + foreach ($profile as $i => $p) { + $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount); + } + + return $str; + } +} + +class_alias('Twig\Profiler\Dumper\BaseDumper', 'Twig_Profiler_Dumper_Base'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php new file mode 100644 index 0000000..a1c3c7b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php @@ -0,0 +1,76 @@ + + * + * @final + */ +class BlackfireDumper +{ + public function dump(Profile $profile) + { + $data = []; + $this->dumpProfile('main()', $profile, $data); + $this->dumpChildren('main()', $profile, $data); + + $start = sprintf('%f', microtime(true)); + $str = << $values) { + $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; + } + + return $str; + } + + private function dumpChildren($parent, Profile $profile, &$data) + { + foreach ($profile as $p) { + if ($p->isTemplate()) { + $name = $p->getTemplate(); + } else { + $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName()); + } + $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data); + $this->dumpChildren($name, $p, $data); + } + } + + private function dumpProfile($edge, Profile $profile, &$data) + { + if (isset($data[$edge])) { + ++$data[$edge]['ct']; + $data[$edge]['wt'] += floor($profile->getDuration() * 1000000); + $data[$edge]['mu'] += $profile->getMemoryUsage(); + $data[$edge]['pmu'] += $profile->getPeakMemoryUsage(); + } else { + $data[$edge] = [ + 'ct' => 1, + 'wt' => floor($profile->getDuration() * 1000000), + 'mu' => $profile->getMemoryUsage(), + 'pmu' => $profile->getPeakMemoryUsage(), + ]; + } + } +} + +class_alias('Twig\Profiler\Dumper\BlackfireDumper', 'Twig_Profiler_Dumper_Blackfire'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/HtmlDumper.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/HtmlDumper.php new file mode 100644 index 0000000..c70b405 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/HtmlDumper.php @@ -0,0 +1,51 @@ + + * + * @final + */ +class HtmlDumper extends BaseDumper +{ + private static $colors = [ + 'block' => '#dfd', + 'macro' => '#ddf', + 'template' => '#ffd', + 'big' => '#d44', + ]; + + public function dump(Profile $profile) + { + return '
'.parent::dump($profile).'
'; + } + + protected function formatTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); + } + + protected function formatNonTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); + } + + protected function formatTime(Profile $profile, $percent) + { + return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); + } +} + +class_alias('Twig\Profiler\Dumper\HtmlDumper', 'Twig_Profiler_Dumper_Html'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/TextDumper.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/TextDumper.php new file mode 100644 index 0000000..c6b5158 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Dumper/TextDumper.php @@ -0,0 +1,39 @@ + + * + * @final + */ +class TextDumper extends BaseDumper +{ + protected function formatTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s', $prefix, $profile->getTemplate()); + } + + protected function formatNonTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); + } + + protected function formatTime(Profile $profile, $percent) + { + return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); + } +} + +class_alias('Twig\Profiler\Dumper\TextDumper', 'Twig_Profiler_Dumper_Text'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/EnterProfileNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/EnterProfileNode.php new file mode 100644 index 0000000..8ffd3dc --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/EnterProfileNode.php @@ -0,0 +1,44 @@ + + */ +class EnterProfileNode extends Node +{ + public function __construct($extensionName, $type, $name, $varName) + { + parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); + } + + public function compile(Compiler $compiler) + { + $compiler + ->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name'))) + ->repr($this->getAttribute('extension_name')) + ->raw(");\n") + ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ->repr($this->getAttribute('type')) + ->raw(', ') + ->repr($this->getAttribute('name')) + ->raw("));\n\n") + ; + } +} + +class_alias('Twig\Profiler\Node\EnterProfileNode', 'Twig_Profiler_Node_EnterProfile'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/LeaveProfileNode.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/LeaveProfileNode.php new file mode 100644 index 0000000..3b7a74d --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Node/LeaveProfileNode.php @@ -0,0 +1,38 @@ + + */ +class LeaveProfileNode extends Node +{ + public function __construct($varName) + { + parent::__construct([], ['var_name' => $varName]); + } + + public function compile(Compiler $compiler) + { + $compiler + ->write("\n") + ->write(sprintf("\$%s->leave(\$%s);\n\n", $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ; + } +} + +class_alias('Twig\Profiler\Node\LeaveProfileNode', 'Twig_Profiler_Node_LeaveProfile'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php new file mode 100644 index 0000000..41ca9e1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php @@ -0,0 +1,80 @@ + + * + * @final + */ +class ProfilerNodeVisitor extends AbstractNodeVisitor +{ + private $extensionName; + + public function __construct($extensionName) + { + $this->extensionName = $extensionName; + } + + protected function doEnterNode(Node $node, Environment $env) + { + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $varName = $this->getVarName(); + $node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); + $node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')])); + } elseif ($node instanceof BlockNode) { + $varName = $this->getVarName(); + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName), + $node->getNode('body'), + new LeaveProfileNode($varName), + ])); + } elseif ($node instanceof MacroNode) { + $varName = $this->getVarName(); + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName), + $node->getNode('body'), + new LeaveProfileNode($varName), + ])); + } + + return $node; + } + + private function getVarName() + { + return sprintf('__internal_%s', hash('sha256', $this->extensionName)); + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', 'Twig_Profiler_NodeVisitor_Profiler'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Profile.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Profile.php new file mode 100644 index 0000000..d83da40 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Profiler/Profile.php @@ -0,0 +1,188 @@ + + * + * @final + */ +class Profile implements \IteratorAggregate, \Serializable +{ + const ROOT = 'ROOT'; + const BLOCK = 'block'; + const TEMPLATE = 'template'; + const MACRO = 'macro'; + + private $template; + private $name; + private $type; + private $starts = []; + private $ends = []; + private $profiles = []; + + public function __construct($template = 'main', $type = self::ROOT, $name = 'main') + { + $this->template = $template; + $this->type = $type; + $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name; + $this->enter(); + } + + public function getTemplate() + { + return $this->template; + } + + public function getType() + { + return $this->type; + } + + public function getName() + { + return $this->name; + } + + public function isRoot() + { + return self::ROOT === $this->type; + } + + public function isTemplate() + { + return self::TEMPLATE === $this->type; + } + + public function isBlock() + { + return self::BLOCK === $this->type; + } + + public function isMacro() + { + return self::MACRO === $this->type; + } + + public function getProfiles() + { + return $this->profiles; + } + + public function addProfile(self $profile) + { + $this->profiles[] = $profile; + } + + /** + * Returns the duration in microseconds. + * + * @return float + */ + public function getDuration() + { + if ($this->isRoot() && $this->profiles) { + // for the root node with children, duration is the sum of all child durations + $duration = 0; + foreach ($this->profiles as $profile) { + $duration += $profile->getDuration(); + } + + return $duration; + } + + return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0; + } + + /** + * Returns the memory usage in bytes. + * + * @return int + */ + public function getMemoryUsage() + { + return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0; + } + + /** + * Returns the peak memory usage in bytes. + * + * @return int + */ + public function getPeakMemoryUsage() + { + return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0; + } + + /** + * Starts the profiling. + */ + public function enter() + { + $this->starts = [ + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ]; + } + + /** + * Stops the profiling. + */ + public function leave() + { + $this->ends = [ + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ]; + } + + public function reset() + { + $this->starts = $this->ends = $this->profiles = []; + $this->enter(); + } + + public function getIterator() + { + return new \ArrayIterator($this->profiles); + } + + public function serialize() + { + return serialize($this->__serialize()); + } + + public function unserialize($data) + { + $this->__unserialize(unserialize($data)); + } + + /** + * @internal + */ + public function __serialize() + { + return [$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles]; + } + + /** + * @internal + */ + public function __unserialize(array $data) + { + list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = $data; + } +} + +class_alias('Twig\Profiler\Profile', 'Twig_Profiler_Profile'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php new file mode 100644 index 0000000..04a6602 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php @@ -0,0 +1,41 @@ + + * @author Robin Chalas + */ +class ContainerRuntimeLoader implements RuntimeLoaderInterface +{ + private $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + public function load($class) + { + if ($this->container->has($class)) { + return $this->container->get($class); + } + } +} + +class_alias('Twig\RuntimeLoader\ContainerRuntimeLoader', 'Twig_ContainerRuntimeLoader'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php new file mode 100644 index 0000000..43b5f24 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php @@ -0,0 +1,41 @@ + + */ +class FactoryRuntimeLoader implements RuntimeLoaderInterface +{ + private $map; + + /** + * @param array $map An array where keys are class names and values factory callables + */ + public function __construct($map = []) + { + $this->map = $map; + } + + public function load($class) + { + if (isset($this->map[$class])) { + $runtimeFactory = $this->map[$class]; + + return $runtimeFactory(); + } + } +} + +class_alias('Twig\RuntimeLoader\FactoryRuntimeLoader', 'Twig_FactoryRuntimeLoader'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php new file mode 100644 index 0000000..4eb5ad8 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php @@ -0,0 +1,31 @@ + + */ +interface RuntimeLoaderInterface +{ + /** + * Creates the runtime implementation of a Twig element (filter/function/test). + * + * @param string $class A runtime class + * + * @return object|null The runtime instance or null if the loader does not know how to create the runtime for this class + */ + public function load($class); +} + +class_alias('Twig\RuntimeLoader\RuntimeLoaderInterface', 'Twig_RuntimeLoaderInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityError.php new file mode 100644 index 0000000..5f96d46 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityError.php @@ -0,0 +1,25 @@ + + */ +class SecurityError extends Error +{ +} + +class_alias('Twig\Sandbox\SecurityError', 'Twig_Sandbox_SecurityError'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php new file mode 100644 index 0000000..fa0fdee --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php @@ -0,0 +1,35 @@ + + */ +class SecurityNotAllowedFilterError extends SecurityError +{ + private $filterName; + + public function __construct($message, $functionName, $lineno = -1, $filename = null, \Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->filterName = $functionName; + } + + public function getFilterName() + { + return $this->filterName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedFilterError', 'Twig_Sandbox_SecurityNotAllowedFilterError'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php new file mode 100644 index 0000000..8f23f93 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php @@ -0,0 +1,35 @@ + + */ +class SecurityNotAllowedFunctionError extends SecurityError +{ + private $functionName; + + public function __construct($message, $functionName, $lineno = -1, $filename = null, \Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->functionName = $functionName; + } + + public function getFunctionName() + { + return $this->functionName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedFunctionError', 'Twig_Sandbox_SecurityNotAllowedFunctionError'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php new file mode 100644 index 0000000..62e13f4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php @@ -0,0 +1,42 @@ + + */ +class SecurityNotAllowedMethodError extends SecurityError +{ + private $className; + private $methodName; + + public function __construct($message, $className, $methodName, $lineno = -1, $filename = null, \Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->className = $className; + $this->methodName = $methodName; + } + + public function getClassName() + { + return $this->className; + } + + public function getMethodName() + { + return $this->methodName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedMethodError', 'Twig_Sandbox_SecurityNotAllowedMethodError'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php new file mode 100644 index 0000000..3bf5305 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php @@ -0,0 +1,42 @@ + + */ +class SecurityNotAllowedPropertyError extends SecurityError +{ + private $className; + private $propertyName; + + public function __construct($message, $className, $propertyName, $lineno = -1, $filename = null, \Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->className = $className; + $this->propertyName = $propertyName; + } + + public function getClassName() + { + return $this->className; + } + + public function getPropertyName() + { + return $this->propertyName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedPropertyError', 'Twig_Sandbox_SecurityNotAllowedPropertyError'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php new file mode 100644 index 0000000..de283b4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php @@ -0,0 +1,35 @@ + + */ +class SecurityNotAllowedTagError extends SecurityError +{ + private $tagName; + + public function __construct($message, $tagName, $lineno = -1, $filename = null, \Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->tagName = $tagName; + } + + public function getTagName() + { + return $this->tagName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedTagError', 'Twig_Sandbox_SecurityNotAllowedTagError'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicy.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicy.php new file mode 100644 index 0000000..6038435 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicy.php @@ -0,0 +1,129 @@ + + */ +class SecurityPolicy implements SecurityPolicyInterface +{ + protected $allowedTags; + protected $allowedFilters; + protected $allowedMethods; + protected $allowedProperties; + protected $allowedFunctions; + + public function __construct(array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = []) + { + $this->allowedTags = $allowedTags; + $this->allowedFilters = $allowedFilters; + $this->setAllowedMethods($allowedMethods); + $this->allowedProperties = $allowedProperties; + $this->allowedFunctions = $allowedFunctions; + } + + public function setAllowedTags(array $tags) + { + $this->allowedTags = $tags; + } + + public function setAllowedFilters(array $filters) + { + $this->allowedFilters = $filters; + } + + public function setAllowedMethods(array $methods) + { + $this->allowedMethods = []; + foreach ($methods as $class => $m) { + $this->allowedMethods[$class] = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]); + } + } + + public function setAllowedProperties(array $properties) + { + $this->allowedProperties = $properties; + } + + public function setAllowedFunctions(array $functions) + { + $this->allowedFunctions = $functions; + } + + public function checkSecurity($tags, $filters, $functions) + { + foreach ($tags as $tag) { + if (!\in_array($tag, $this->allowedTags)) { + throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); + } + } + + foreach ($filters as $filter) { + if (!\in_array($filter, $this->allowedFilters)) { + throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); + } + } + + foreach ($functions as $function) { + if (!\in_array($function, $this->allowedFunctions)) { + throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); + } + } + } + + public function checkMethodAllowed($obj, $method) + { + if ($obj instanceof \Twig_TemplateInterface || $obj instanceof Markup) { + return; + } + + $allowed = false; + $method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); + foreach ($this->allowedMethods as $class => $methods) { + if ($obj instanceof $class) { + $allowed = \in_array($method, $methods); + + break; + } + } + + if (!$allowed) { + $class = \get_class($obj); + throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); + } + } + + public function checkPropertyAllowed($obj, $property) + { + $allowed = false; + foreach ($this->allowedProperties as $class => $properties) { + if ($obj instanceof $class) { + $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]); + + break; + } + } + + if (!$allowed) { + $class = \get_class($obj); + throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); + } + } +} + +class_alias('Twig\Sandbox\SecurityPolicy', 'Twig_Sandbox_SecurityPolicy'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicyInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicyInterface.php new file mode 100644 index 0000000..a31863f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Sandbox/SecurityPolicyInterface.php @@ -0,0 +1,28 @@ + + */ +interface SecurityPolicyInterface +{ + public function checkSecurity($tags, $filters, $functions); + + public function checkMethodAllowed($obj, $method); + + public function checkPropertyAllowed($obj, $method); +} + +class_alias('Twig\Sandbox\SecurityPolicyInterface', 'Twig_Sandbox_SecurityPolicyInterface'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Source.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Source.php new file mode 100644 index 0000000..32a8216 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Source.php @@ -0,0 +1,55 @@ + + */ +class Source +{ + private $code; + private $name; + private $path; + + /** + * @param string $code The template source code + * @param string $name The template logical name + * @param string $path The filesystem path of the template if any + */ + public function __construct($code, $name, $path = '') + { + $this->code = $code; + $this->name = $name; + $this->path = $path; + } + + public function getCode() + { + return $this->code; + } + + public function getName() + { + return $this->name; + } + + public function getPath() + { + return $this->path; + } +} + +class_alias('Twig\Source', 'Twig_Source'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Template.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Template.php new file mode 100644 index 0000000..704125e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Template.php @@ -0,0 +1,733 @@ +load() + * instead, which returns an instance of \Twig\TemplateWrapper. + * + * @author Fabien Potencier + * + * @internal + */ +abstract class Template implements \Twig_TemplateInterface +{ + /** + * @internal + */ + protected static $cache = []; + + protected $parent; + protected $parents = []; + protected $env; + protected $blocks = []; + protected $traits = []; + protected $sandbox; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + /** + * @internal this method will be removed in 2.0 and is only used internally to provide an upgrade path from 1.x to 2.0 + */ + public function __toString() + { + return $this->getTemplateName(); + } + + /** + * Returns the template name. + * + * @return string The template name + */ + abstract public function getTemplateName(); + + /** + * Returns debug information about the template. + * + * @return array Debug information + */ + public function getDebugInfo() + { + return []; + } + + /** + * Returns the template source code. + * + * @return string The template source code + * + * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead + */ + public function getSource() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + + return ''; + } + + /** + * Returns information about the original template source code. + * + * @return Source + */ + public function getSourceContext() + { + return new Source('', $this->getTemplateName()); + } + + /** + * @deprecated since 1.20 (to be removed in 2.0) + */ + public function getEnvironment() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED); + + return $this->env; + } + + /** + * Returns the parent template. + * + * This method is for internal use only and should never be called + * directly. + * + * @param array $context + * + * @return \Twig_TemplateInterface|TemplateWrapper|false The parent template or false if there is no parent + * + * @internal + */ + public function getParent(array $context) + { + if (null !== $this->parent) { + return $this->parent; + } + + try { + $parent = $this->doGetParent($context); + + if (false === $parent) { + return false; + } + + if ($parent instanceof self || $parent instanceof TemplateWrapper) { + return $this->parents[$parent->getSourceContext()->getName()] = $parent; + } + + if (!isset($this->parents[$parent])) { + $this->parents[$parent] = $this->loadTemplate($parent); + } + } catch (LoaderError $e) { + $e->setSourceContext(null); + $e->guess(); + + throw $e; + } + + return $this->parents[$parent]; + } + + protected function doGetParent(array $context) + { + return false; + } + + public function isTraitable() + { + return true; + } + + /** + * Displays a parent block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to display from the parent + * @param array $context The context + * @param array $blocks The current set of blocks + */ + public function displayParentBlock($name, array $context, array $blocks = []) + { + $name = (string) $name; + + if (isset($this->traits[$name])) { + $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, $blocks, false); + } else { + throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); + } + } + + /** + * Displays a block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to display + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks + */ + public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true) + { + $name = (string) $name; + + if ($useBlocks && isset($blocks[$name])) { + $template = $blocks[$name][0]; + $block = $blocks[$name][1]; + } elseif (isset($this->blocks[$name])) { + $template = $this->blocks[$name][0]; + $block = $this->blocks[$name][1]; + } else { + $template = null; + $block = null; + } + + // avoid RCEs when sandbox is enabled + if (null !== $template && !$template instanceof self) { + throw new \LogicException('A block must be a method on a \Twig\Template instance.'); + } + + if (null !== $template) { + try { + $template->$block($context, $blocks); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($template->getSourceContext()); + } + + // this is mostly useful for \Twig\Error\LoaderError exceptions + // see \Twig\Error\LoaderError + if (-1 === $e->getTemplateLine()) { + $e->guess(); + } + + throw $e; + } catch (\Exception $e) { + $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); + $e->guess(); + + throw $e; + } + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); + } else { + @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED); + } + } + + /** + * Renders a parent block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to render from the parent + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return string The rendered block + */ + public function renderParentBlock($name, array $context, array $blocks = []) + { + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + $this->displayParentBlock($name, $context, $blocks); + + return ob_get_clean(); + } + + /** + * Renders a block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to render + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks + * + * @return string The rendered block + */ + public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true) + { + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + $this->displayBlock($name, $context, $blocks, $useBlocks); + + return ob_get_clean(); + } + + /** + * Returns whether a block exists or not in the current context of the template. + * + * This method checks blocks defined in the current template + * or defined in "used" traits or defined in parent templates. + * + * @param string $name The block name + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return bool true if the block exists, false otherwise + */ + public function hasBlock($name, array $context = null, array $blocks = []) + { + if (null === $context) { + @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); + + return isset($this->blocks[(string) $name]); + } + + if (isset($blocks[$name])) { + return $blocks[$name][0] instanceof self; + } + + if (isset($this->blocks[$name])) { + return true; + } + + if (false !== $parent = $this->getParent($context)) { + return $parent->hasBlock($name, $context); + } + + return false; + } + + /** + * Returns all block names in the current context of the template. + * + * This method checks blocks defined in the current template + * or defined in "used" traits or defined in parent templates. + * + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return array An array of block names + */ + public function getBlockNames(array $context = null, array $blocks = []) + { + if (null === $context) { + @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); + + return array_keys($this->blocks); + } + + $names = array_merge(array_keys($blocks), array_keys($this->blocks)); + + if (false !== $parent = $this->getParent($context)) { + $names = array_merge($names, $parent->getBlockNames($context)); + } + + return array_unique($names); + } + + /** + * @return Template|TemplateWrapper + */ + protected function loadTemplate($template, $templateName = null, $line = null, $index = null) + { + try { + if (\is_array($template)) { + return $this->env->resolveTemplate($template); + } + + if ($template instanceof self || $template instanceof TemplateWrapper) { + return $template; + } + + if ($template === $this->getTemplateName()) { + $class = \get_class($this); + if (false !== $pos = strrpos($class, '___', -1)) { + $class = substr($class, 0, $pos); + } + + return $this->env->loadClass($class, $template, $index); + } + + return $this->env->loadTemplate($template, $index); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext()); + } + + if ($e->getTemplateLine() > 0) { + throw $e; + } + + if (!$line) { + $e->guess(); + } else { + $e->setTemplateLine($line); + } + + throw $e; + } + } + + /** + * @internal + * + * @return Template + */ + protected function unwrap() + { + return $this; + } + + /** + * Returns all blocks. + * + * This method is for internal use only and should never be called + * directly. + * + * @return array An array of blocks + */ + public function getBlocks() + { + return $this->blocks; + } + + public function display(array $context, array $blocks = []) + { + $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); + } + + public function render(array $context) + { + $level = ob_get_level(); + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + try { + $this->display($context); + } catch (\Exception $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } catch (\Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + + return ob_get_clean(); + } + + protected function displayWithErrorHandling(array $context, array $blocks = []) + { + try { + $this->doDisplay($context, $blocks); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($this->getSourceContext()); + } + + // this is mostly useful for \Twig\Error\LoaderError exceptions + // see \Twig\Error\LoaderError + if (-1 === $e->getTemplateLine()) { + $e->guess(); + } + + throw $e; + } catch (\Exception $e) { + $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); + $e->guess(); + + throw $e; + } + } + + /** + * Auto-generated method to display the template with the given context. + * + * @param array $context An array of parameters to pass to the template + * @param array $blocks An array of blocks to pass to the template + */ + abstract protected function doDisplay(array $context, array $blocks = []); + + /** + * Returns a variable from the context. + * + * This method is for internal use only and should never be called + * directly. + * + * This method should not be overridden in a sub-class as this is an + * implementation detail that has been introduced to optimize variable + * access for versions of PHP before 5.4. This is not a way to override + * the way to get a variable value. + * + * @param array $context The context + * @param string $item The variable to return from the context + * @param bool $ignoreStrictCheck Whether to ignore the strict variable check or not + * + * @return mixed The content of the context variable + * + * @throws RuntimeError if the variable does not exist and Twig is running in strict mode + * + * @internal + */ + final protected function getContext($context, $item, $ignoreStrictCheck = false) + { + if (!\array_key_exists($item, $context)) { + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return; + } + + throw new RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext()); + } + + return $context[$item]; + } + + /** + * Returns the attribute value for a given array/object. + * + * @param mixed $object The object or array from where to get the item + * @param mixed $item The item to get from the array or object + * @param array $arguments An array of arguments to pass if the item is an object method + * @param string $type The type of attribute (@see \Twig\Template constants) + * @param bool $isDefinedTest Whether this is only a defined check + * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not + * + * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true + * + * @throws RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false + * + * @internal + */ + protected function getAttribute($object, $item, array $arguments = [], $type = self::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + { + // array + if (self::METHOD_CALL !== $type) { + $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; + + if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object))) + || ($object instanceof \ArrayAccess && isset($object[$arrayItem])) + ) { + if ($isDefinedTest) { + return true; + } + + return $object[$arrayItem]; + } + + if (self::ARRAY_CALL === $type || !\is_object($object)) { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return; + } + + if ($object instanceof \ArrayAccess) { + $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object)); + } elseif (\is_object($object)) { + $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object)); + } elseif (\is_array($object)) { + if (empty($object)) { + $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); + } else { + $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object))); + } + } elseif (self::ARRAY_CALL === $type) { + if (null === $object) { + $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); + } else { + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + } elseif (null === $object) { + $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); + } else { + $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + + throw new RuntimeError($message, -1, $this->getSourceContext()); + } + } + + if (!\is_object($object)) { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return; + } + + if (null === $object) { + $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); + } elseif (\is_array($object)) { + $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); + } else { + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + + throw new RuntimeError($message, -1, $this->getSourceContext()); + } + + // object property + if (self::METHOD_CALL !== $type && !$object instanceof self) { // \Twig\Template does not have public properties, and we don't want to allow access to internal ones + if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) { + if ($isDefinedTest) { + return true; + } + + if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { + $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item); + } + + return $object->$item; + } + } + + $class = \get_class($object); + + // object method + if (!isset(self::$cache[$class])) { + // get_class_methods returns all methods accessible in the scope, but we only want public ones to be accessible in templates + if ($object instanceof self) { + $ref = new \ReflectionClass($class); + $methods = []; + + foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $refMethod) { + // Accessing the environment from templates is forbidden to prevent untrusted changes to the environment + if ('getenvironment' !== strtr($refMethod->name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) { + $methods[] = $refMethod->name; + } + } + } else { + $methods = get_class_methods($object); + } + // sort values to have consistent behavior, so that "get" methods win precedence over "is" methods + sort($methods); + + $cache = []; + + foreach ($methods as $method) { + $cache[$method] = $method; + $cache[$lcName = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')] = $method; + + if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) { + $name = substr($method, 3); + $lcName = substr($lcName, 3); + } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) { + $name = substr($method, 2); + $lcName = substr($lcName, 2); + } else { + continue; + } + + // skip get() and is() methods (in which case, $name is empty) + if ($name) { + if (!isset($cache[$name])) { + $cache[$name] = $method; + } + if (!isset($cache[$lcName])) { + $cache[$lcName] = $method; + } + } + } + self::$cache[$class] = $cache; + } + + $call = false; + if (isset(self::$cache[$class][$item])) { + $method = self::$cache[$class][$item]; + } elseif (isset(self::$cache[$class][$lcItem = strtr($item, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')])) { + $method = self::$cache[$class][$lcItem]; + } elseif (isset(self::$cache[$class]['__call'])) { + $method = $item; + $call = true; + } else { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return; + } + + throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext()); + } + + if ($isDefinedTest) { + return true; + } + + if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) { + $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method); + } + + // Some objects throw exceptions when they have __call, and the method we try + // to call is not supported. If ignoreStrictCheck is true, we should return null. + try { + if (!$arguments) { + $ret = $object->$method(); + } else { + $ret = \call_user_func_array([$object, $method], $arguments); + } + } catch (\BadMethodCallException $e) { + if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { + return; + } + throw $e; + } + + // @deprecated in 1.28 + if ($object instanceof \Twig_TemplateInterface) { + $self = $object->getTemplateName() === $this->getTemplateName(); + $message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName()); + if ('renderBlock' === $method || 'displayBlock' === $method) { + $message .= sprintf(' Use block("%s"%s) instead).', $arguments[0], $self ? '' : ', template'); + } elseif ('hasBlock' === $method) { + $message .= sprintf(' Use "block("%s"%s) is defined" instead).', $arguments[0], $self ? '' : ', template'); + } elseif ('render' === $method || 'display' === $method) { + $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName()); + } + @trigger_error($message, E_USER_DEPRECATED); + + return '' === $ret ? '' : new Markup($ret, $this->env->getCharset()); + } + + return $ret; + } +} + +class_alias('Twig\Template', 'Twig_Template'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TemplateWrapper.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TemplateWrapper.php new file mode 100644 index 0000000..e265409 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TemplateWrapper.php @@ -0,0 +1,161 @@ + + */ +final class TemplateWrapper +{ + private $env; + private $template; + + /** + * This method is for internal use only and should never be called + * directly (use Twig\Environment::load() instead). + * + * @internal + */ + public function __construct(Environment $env, Template $template) + { + $this->env = $env; + $this->template = $template; + } + + /** + * Renders the template. + * + * @param array $context An array of parameters to pass to the template + * + * @return string The rendered template + */ + public function render($context = []) + { + // using func_get_args() allows to not expose the blocks argument + // as it should only be used by internal code + return $this->template->render($context, \func_num_args() > 1 ? func_get_arg(1) : []); + } + + /** + * Displays the template. + * + * @param array $context An array of parameters to pass to the template + */ + public function display($context = []) + { + // using func_get_args() allows to not expose the blocks argument + // as it should only be used by internal code + $this->template->display($context, \func_num_args() > 1 ? func_get_arg(1) : []); + } + + /** + * Checks if a block is defined. + * + * @param string $name The block name + * @param array $context An array of parameters to pass to the template + * + * @return bool + */ + public function hasBlock($name, $context = []) + { + return $this->template->hasBlock($name, $context); + } + + /** + * Returns defined block names in the template. + * + * @param array $context An array of parameters to pass to the template + * + * @return string[] An array of defined template block names + */ + public function getBlockNames($context = []) + { + return $this->template->getBlockNames($context); + } + + /** + * Renders a template block. + * + * @param string $name The block name to render + * @param array $context An array of parameters to pass to the template + * + * @return string The rendered block + */ + public function renderBlock($name, $context = []) + { + $context = $this->env->mergeGlobals($context); + $level = ob_get_level(); + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + try { + $this->template->displayBlock($name, $context); + } catch (\Exception $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } catch (\Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + + return ob_get_clean(); + } + + /** + * Displays a template block. + * + * @param string $name The block name to render + * @param array $context An array of parameters to pass to the template + */ + public function displayBlock($name, $context = []) + { + $this->template->displayBlock($name, $this->env->mergeGlobals($context)); + } + + /** + * @return Source + */ + public function getSourceContext() + { + return $this->template->getSourceContext(); + } + + /** + * @return string + */ + public function getTemplateName() + { + return $this->template->getTemplateName(); + } + + /** + * @internal + * + * @return Template + */ + public function unwrap() + { + return $this->template; + } +} + +class_alias('Twig\TemplateWrapper', 'Twig_TemplateWrapper'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Test/IntegrationTestCase.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Test/IntegrationTestCase.php new file mode 100644 index 0000000..36b3607 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Test/IntegrationTestCase.php @@ -0,0 +1,257 @@ + + * @author Karma Dordrak + */ +abstract class IntegrationTestCase extends TestCase +{ + /** + * @return string + */ + abstract protected function getFixturesDir(); + + /** + * @return RuntimeLoaderInterface[] + */ + protected function getRuntimeLoaders() + { + return []; + } + + /** + * @return ExtensionInterface[] + */ + protected function getExtensions() + { + return []; + } + + /** + * @return TwigFilter[] + */ + protected function getTwigFilters() + { + return []; + } + + /** + * @return TwigFunction[] + */ + protected function getTwigFunctions() + { + return []; + } + + /** + * @return TwigTest[] + */ + protected function getTwigTests() + { + return []; + } + + /** + * @dataProvider getTests + */ + public function testIntegration($file, $message, $condition, $templates, $exception, $outputs) + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); + } + + /** + * @dataProvider getLegacyTests + * @group legacy + */ + public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs) + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); + } + + public function getTests($name, $legacyTests = false) + { + $fixturesDir = realpath($this->getFixturesDir()); + $tests = []; + + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if (!preg_match('/\.test$/', $file)) { + continue; + } + + if ($legacyTests xor false !== strpos($file->getRealpath(), '.legacy.test')) { + continue; + } + + $test = file_get_contents($file->getRealpath()); + + if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { + $message = $match[1]; + $condition = $match[2]; + $templates = self::parseTemplates($match[3]); + $exception = $match[5]; + $outputs = [[null, $match[4], null, '']]; + } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { + $message = $match[1]; + $condition = $match[2]; + $templates = self::parseTemplates($match[3]); + $exception = false; + preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); + } else { + throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); + } + + $tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs]; + } + + if ($legacyTests && empty($tests)) { + // add a dummy test to avoid a PHPUnit message + return [['not', '-', '', [], '', []]]; + } + + return $tests; + } + + public function getLegacyTests() + { + return $this->getTests('testLegacyIntegration', true); + } + + protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) + { + if (!$outputs) { + $this->markTestSkipped('no tests to run'); + } + + if ($condition) { + eval('$ret = '.$condition.';'); + if (!$ret) { + $this->markTestSkipped($condition); + } + } + + $loader = new ArrayLoader($templates); + + foreach ($outputs as $i => $match) { + $config = array_merge([ + 'cache' => false, + 'strict_variables' => true, + ], $match[2] ? eval($match[2].';') : []); + $twig = new Environment($loader, $config); + $twig->addGlobal('global', 'global'); + foreach ($this->getRuntimeLoaders() as $runtimeLoader) { + $twig->addRuntimeLoader($runtimeLoader); + } + + foreach ($this->getExtensions() as $extension) { + $twig->addExtension($extension); + } + + foreach ($this->getTwigFilters() as $filter) { + $twig->addFilter($filter); + } + + foreach ($this->getTwigTests() as $test) { + $twig->addTest($test); + } + + foreach ($this->getTwigFunctions() as $function) { + $twig->addFunction($function); + } + + $p = new \ReflectionProperty($twig, 'templateClassPrefix'); + $p->setAccessible(true); + $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); + + try { + $template = $twig->load('index.twig'); + } catch (\Exception $e) { + if (false !== $exception) { + $message = $e->getMessage(); + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message))); + $last = substr($message, \strlen($message) - 1); + $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.'); + + return; + } + + throw new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + } + + try { + $output = trim($template->render(eval($match[1].';')), "\n "); + } catch (\Exception $e) { + if (false !== $exception) { + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $e->getMessage()))); + + return; + } + + $e = new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + + $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); + } + + if (false !== $exception) { + list($class) = explode(':', $exception); + $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception'; + $this->assertThat(null, new $constraintClass($class)); + } + + $expected = trim($match[3], "\n "); + + if ($expected !== $output) { + printf("Compiled templates that failed on case %d:\n", $i + 1); + + foreach (array_keys($templates) as $name) { + echo "Template: $name\n"; + $loader = $twig->getLoader(); + if (!$loader instanceof SourceContextLoaderInterface) { + $source = new Source($loader->getSource($name), $name); + } else { + $source = $loader->getSourceContext($name); + } + echo $twig->compile($twig->parse($twig->tokenize($source))); + } + } + $this->assertEquals($expected, $output, $message.' (in '.$file.')'); + } + } + + protected static function parseTemplates($test) + { + $templates = []; + preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; + } + + return $templates; + } +} + +class_alias('Twig\Test\IntegrationTestCase', 'Twig_Test_IntegrationTestCase'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Test/NodeTestCase.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Test/NodeTestCase.php new file mode 100644 index 0000000..f3358cb --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Test/NodeTestCase.php @@ -0,0 +1,79 @@ +assertNodeCompilation($source, $node, $environment, $isPattern); + } + + public function assertNodeCompilation($source, Node $node, Environment $environment = null, $isPattern = false) + { + $compiler = $this->getCompiler($environment); + $compiler->compile($node); + + if ($isPattern) { + $this->assertStringMatchesFormat($source, trim($compiler->getSource())); + } else { + $this->assertEquals($source, trim($compiler->getSource())); + } + } + + protected function getCompiler(Environment $environment = null) + { + return new Compiler(null === $environment ? $this->getEnvironment() : $environment); + } + + protected function getEnvironment() + { + return new Environment(new ArrayLoader([])); + } + + protected function getVariableGetter($name, $line = false) + { + $line = $line > 0 ? "// line {$line}\n" : ''; + + if (\PHP_VERSION_ID >= 70000) { + return sprintf('%s($context["%s"] ?? null)', $line, $name); + } + + if (\PHP_VERSION_ID >= 50400) { + return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); + } + + return sprintf('%s$this->getContext($context, "%s")', $line, $name); + } + + protected function getAttributeGetter() + { + if (\function_exists('twig_template_get_attributes')) { + return 'twig_template_get_attributes($this, '; + } + + return '$this->getAttribute('; + } +} + +class_alias('Twig\Test\NodeTestCase', 'Twig_Test_NodeTestCase'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Token.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Token.php new file mode 100644 index 0000000..a0bb11a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Token.php @@ -0,0 +1,215 @@ + + * + * @final + */ +class Token +{ + protected $value; + protected $type; + protected $lineno; + + const EOF_TYPE = -1; + const TEXT_TYPE = 0; + const BLOCK_START_TYPE = 1; + const VAR_START_TYPE = 2; + const BLOCK_END_TYPE = 3; + const VAR_END_TYPE = 4; + const NAME_TYPE = 5; + const NUMBER_TYPE = 6; + const STRING_TYPE = 7; + const OPERATOR_TYPE = 8; + const PUNCTUATION_TYPE = 9; + const INTERPOLATION_START_TYPE = 10; + const INTERPOLATION_END_TYPE = 11; + const ARROW_TYPE = 12; + + /** + * @param int $type The type of the token + * @param string $value The token value + * @param int $lineno The line position in the source + */ + public function __construct($type, $value, $lineno) + { + $this->type = $type; + $this->value = $value; + $this->lineno = $lineno; + } + + public function __toString() + { + return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value); + } + + /** + * Tests the current token for a type and/or a value. + * + * Parameters may be: + * * just type + * * type and value (or array of possible values) + * * just value (or array of possible values) (NAME_TYPE is used as type) + * + * @param array|string|int $type The type to test + * @param array|string|null $values The token value + * + * @return bool + */ + public function test($type, $values = null) + { + if (null === $values && !\is_int($type)) { + $values = $type; + $type = self::NAME_TYPE; + } + + return ($this->type === $type) && ( + null === $values || + (\is_array($values) && \in_array($this->value, $values)) || + $this->value == $values + ); + } + + /** + * @return int + */ + public function getLine() + { + return $this->lineno; + } + + /** + * @return int + */ + public function getType() + { + return $this->type; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Returns the constant representation (internal) of a given type. + * + * @param int $type The type as an integer + * @param bool $short Whether to return a short representation or not + * + * @return string The string representation + */ + public static function typeToString($type, $short = false) + { + switch ($type) { + case self::EOF_TYPE: + $name = 'EOF_TYPE'; + break; + case self::TEXT_TYPE: + $name = 'TEXT_TYPE'; + break; + case self::BLOCK_START_TYPE: + $name = 'BLOCK_START_TYPE'; + break; + case self::VAR_START_TYPE: + $name = 'VAR_START_TYPE'; + break; + case self::BLOCK_END_TYPE: + $name = 'BLOCK_END_TYPE'; + break; + case self::VAR_END_TYPE: + $name = 'VAR_END_TYPE'; + break; + case self::NAME_TYPE: + $name = 'NAME_TYPE'; + break; + case self::NUMBER_TYPE: + $name = 'NUMBER_TYPE'; + break; + case self::STRING_TYPE: + $name = 'STRING_TYPE'; + break; + case self::OPERATOR_TYPE: + $name = 'OPERATOR_TYPE'; + break; + case self::PUNCTUATION_TYPE: + $name = 'PUNCTUATION_TYPE'; + break; + case self::INTERPOLATION_START_TYPE: + $name = 'INTERPOLATION_START_TYPE'; + break; + case self::INTERPOLATION_END_TYPE: + $name = 'INTERPOLATION_END_TYPE'; + break; + case self::ARROW_TYPE: + $name = 'ARROW_TYPE'; + break; + default: + throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); + } + + return $short ? $name : 'Twig\Token::'.$name; + } + + /** + * Returns the English representation of a given type. + * + * @param int $type The type as an integer + * + * @return string The string representation + */ + public static function typeToEnglish($type) + { + switch ($type) { + case self::EOF_TYPE: + return 'end of template'; + case self::TEXT_TYPE: + return 'text'; + case self::BLOCK_START_TYPE: + return 'begin of statement block'; + case self::VAR_START_TYPE: + return 'begin of print statement'; + case self::BLOCK_END_TYPE: + return 'end of statement block'; + case self::VAR_END_TYPE: + return 'end of print statement'; + case self::NAME_TYPE: + return 'name'; + case self::NUMBER_TYPE: + return 'number'; + case self::STRING_TYPE: + return 'string'; + case self::OPERATOR_TYPE: + return 'operator'; + case self::PUNCTUATION_TYPE: + return 'punctuation'; + case self::INTERPOLATION_START_TYPE: + return 'begin of string interpolation'; + case self::INTERPOLATION_END_TYPE: + return 'end of string interpolation'; + case self::ARROW_TYPE: + return 'arrow function'; + default: + throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); + } + } +} + +class_alias('Twig\Token', 'Twig_Token'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AbstractTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AbstractTokenParser.php new file mode 100644 index 0000000..2c2f90b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AbstractTokenParser.php @@ -0,0 +1,34 @@ + + */ +abstract class AbstractTokenParser implements TokenParserInterface +{ + /** + * @var Parser + */ + protected $parser; + + public function setParser(Parser $parser) + { + $this->parser = $parser; + } +} + +class_alias('Twig\TokenParser\AbstractTokenParser', 'Twig_TokenParser'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ApplyTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ApplyTokenParser.php new file mode 100644 index 0000000..879879a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ApplyTokenParser.php @@ -0,0 +1,58 @@ +getLine(); + $name = $this->parser->getVarName(); + + $ref = new TempNameExpression($name, $lineno); + $ref->setAttribute('always_defined', true); + + $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideApplyEnd'], true); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new Node([ + new SetNode(true, $ref, $body, $lineno, $this->getTag()), + new PrintNode($filter, $lineno, $this->getTag()), + ]); + } + + public function decideApplyEnd(Token $token) + { + return $token->test('endapply'); + } + + public function getTag() + { + return 'apply'; + } +} diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php new file mode 100644 index 0000000..2cd0cc6 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php @@ -0,0 +1,88 @@ +getLine(); + $stream = $this->parser->getStream(); + + if ($stream->test(Token::BLOCK_END_TYPE)) { + $value = 'html'; + } else { + $expr = $this->parser->getExpressionParser()->parseExpression(); + if (!$expr instanceof ConstantExpression) { + throw new SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + $value = $expr->getAttribute('value'); + + $compat = true === $value || false === $value; + + if (true === $value) { + $value = 'html'; + } + + if ($compat && $stream->test(Token::NAME_TYPE)) { + @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED); + + if (false === $value) { + throw new SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $value = $stream->next()->getValue(); + } + } + + $stream->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(Token::BLOCK_END_TYPE); + + return new AutoEscapeNode($value, $body, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endautoescape'); + } + + public function getTag() + { + return 'autoescape'; + } +} + +class_alias('Twig\TokenParser\AutoEscapeTokenParser', 'Twig_TokenParser_AutoEscape'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/BlockTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/BlockTokenParser.php new file mode 100644 index 0000000..caf11f0 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/BlockTokenParser.php @@ -0,0 +1,80 @@ + + * {% block title %}{% endblock %} - My Webpage + * {% endblock %} + * + * @final + */ +class BlockTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); + if ($this->parser->hasBlock($name)) { + throw new SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + $this->parser->setBlock($name, $block = new BlockNode($name, new Node([]), $lineno)); + $this->parser->pushLocalScope(); + $this->parser->pushBlockStack($name); + + if ($stream->nextIf(Token::BLOCK_END_TYPE)) { + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + if ($token = $stream->nextIf(Token::NAME_TYPE)) { + $value = $token->getValue(); + + if ($value != $name) { + throw new SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + } else { + $body = new Node([ + new PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno), + ]); + } + $stream->expect(Token::BLOCK_END_TYPE); + + $block->setNode('body', $body); + $this->parser->popBlockStack(); + $this->parser->popLocalScope(); + + return new BlockReferenceNode($name, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endblock'); + } + + public function getTag() + { + return 'block'; + } +} + +class_alias('Twig\TokenParser\BlockTokenParser', 'Twig_TokenParser_Block'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DeprecatedTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DeprecatedTokenParser.php new file mode 100644 index 0000000..6575cff --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DeprecatedTokenParser.php @@ -0,0 +1,44 @@ + + * + * @final + */ +class DeprecatedTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $expr = $this->parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new DeprecatedNode($expr, $token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'deprecated'; + } +} + +class_alias('Twig\TokenParser\DeprecatedTokenParser', 'Twig_TokenParser_Deprecated'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DoTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DoTokenParser.php new file mode 100644 index 0000000..e1eae10 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/DoTokenParser.php @@ -0,0 +1,39 @@ +parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new DoNode($expr, $token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'do'; + } +} + +class_alias('Twig\TokenParser\DoTokenParser', 'Twig_TokenParser_Do'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/EmbedTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/EmbedTokenParser.php new file mode 100644 index 0000000..973ff2e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/EmbedTokenParser.php @@ -0,0 +1,74 @@ +parser->getStream(); + + $parent = $this->parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + $parentToken = $fakeParentToken = new Token(Token::STRING_TYPE, '__parent__', $token->getLine()); + if ($parent instanceof ConstantExpression) { + $parentToken = new Token(Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine()); + } elseif ($parent instanceof NameExpression) { + $parentToken = new Token(Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine()); + } + + // inject a fake parent to make the parent() function work + $stream->injectTokens([ + new Token(Token::BLOCK_START_TYPE, '', $token->getLine()), + new Token(Token::NAME_TYPE, 'extends', $token->getLine()), + $parentToken, + new Token(Token::BLOCK_END_TYPE, '', $token->getLine()), + ]); + + $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); + + // override the parent with the correct one + if ($fakeParentToken === $parentToken) { + $module->setNode('parent', $parent); + } + + $this->parser->embedTemplate($module); + + $stream->expect(Token::BLOCK_END_TYPE); + + return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endembed'); + } + + public function getTag() + { + return 'embed'; + } +} + +class_alias('Twig\TokenParser\EmbedTokenParser', 'Twig_TokenParser_Embed'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ExtendsTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ExtendsTokenParser.php new file mode 100644 index 0000000..e66789a --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ExtendsTokenParser.php @@ -0,0 +1,54 @@ +parser->getStream(); + + if ($this->parser->peekBlockStack()) { + throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext()); + } elseif (!$this->parser->isMainScope()) { + throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext()); + } + + if (null !== $this->parser->getParent()) { + throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); + } + $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); + + $stream->expect(Token::BLOCK_END_TYPE); + + return new Node(); + } + + public function getTag() + { + return 'extends'; + } +} + +class_alias('Twig\TokenParser\ExtendsTokenParser', 'Twig_TokenParser_Extends'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FilterTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FilterTokenParser.php new file mode 100644 index 0000000..dc07dcf --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FilterTokenParser.php @@ -0,0 +1,59 @@ +parser->getVarName(); + $ref = new BlockReferenceExpression(new ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag()); + + $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + $block = new BlockNode($name, $body, $token->getLine()); + $this->parser->setBlock($name, $block); + + return new PrintNode($filter, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endfilter'); + } + + public function getTag() + { + return 'filter'; + } +} + +class_alias('Twig\TokenParser\FilterTokenParser', 'Twig_TokenParser_Filter'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FlushTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FlushTokenParser.php new file mode 100644 index 0000000..b25524f --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FlushTokenParser.php @@ -0,0 +1,39 @@ +parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new FlushNode($token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'flush'; + } +} + +class_alias('Twig\TokenParser\FlushTokenParser', 'Twig_TokenParser_Flush'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ForTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ForTokenParser.php new file mode 100644 index 0000000..69278d9 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ForTokenParser.php @@ -0,0 +1,136 @@ + + * {% for user in users %} + *
  • {{ user.username|e }}
  • + * {% endfor %} + * + * + * @final + */ +class ForTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); + $stream->expect(Token::OPERATOR_TYPE, 'in'); + $seq = $this->parser->getExpressionParser()->parseExpression(); + + $ifexpr = null; + if ($stream->nextIf(Token::NAME_TYPE, 'if')) { + $ifexpr = $this->parser->getExpressionParser()->parseExpression(); + } + + $stream->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideForFork']); + if ('else' == $stream->next()->getValue()) { + $stream->expect(Token::BLOCK_END_TYPE); + $else = $this->parser->subparse([$this, 'decideForEnd'], true); + } else { + $else = null; + } + $stream->expect(Token::BLOCK_END_TYPE); + + if (\count($targets) > 1) { + $keyTarget = $targets->getNode(0); + $keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); + $valueTarget = $targets->getNode(1); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + } else { + $keyTarget = new AssignNameExpression('_key', $lineno); + $valueTarget = $targets->getNode(0); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + } + + if ($ifexpr) { + $this->checkLoopUsageCondition($stream, $ifexpr); + $this->checkLoopUsageBody($stream, $body); + } + + return new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); + } + + public function decideForFork(Token $token) + { + return $token->test(['else', 'endfor']); + } + + public function decideForEnd(Token $token) + { + return $token->test('endfor'); + } + + // the loop variable cannot be used in the condition + protected function checkLoopUsageCondition(TokenStream $stream, \Twig_NodeInterface $node) + { + if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + throw new SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); + } + + foreach ($node as $n) { + if (!$n) { + continue; + } + + $this->checkLoopUsageCondition($stream, $n); + } + } + + // check usage of non-defined loop-items + // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) + protected function checkLoopUsageBody(TokenStream $stream, \Twig_NodeInterface $node) + { + if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + $attribute = $node->getNode('attribute'); + if ($attribute instanceof ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { + throw new SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); + } + } + + // should check for parent.loop.XXX usage + if ($node instanceof ForNode) { + return; + } + + foreach ($node as $n) { + if (!$n) { + continue; + } + + $this->checkLoopUsageBody($stream, $n); + } + } + + public function getTag() + { + return 'for'; + } +} + +class_alias('Twig\TokenParser\ForTokenParser', 'Twig_TokenParser_For'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FromTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FromTokenParser.php new file mode 100644 index 0000000..4cce650 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/FromTokenParser.php @@ -0,0 +1,72 @@ +parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect(Token::NAME_TYPE, 'import'); + + $targets = []; + do { + $name = $stream->expect(Token::NAME_TYPE)->getValue(); + + $alias = $name; + if ($stream->nextIf('as')) { + $alias = $stream->expect(Token::NAME_TYPE)->getValue(); + } + + $targets[$name] = $alias; + + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { + break; + } + } while (true); + + $stream->expect(Token::BLOCK_END_TYPE); + + $var = new AssignNameExpression($this->parser->getVarName(), $token->getLine()); + $node = new ImportNode($macro, $var, $token->getLine(), $this->getTag()); + + foreach ($targets as $name => $alias) { + if ($this->parser->isReservedMacroName($name)) { + throw new SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); + } + + $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $var); + } + + return $node; + } + + public function getTag() + { + return 'from'; + } +} + +class_alias('Twig\TokenParser\FromTokenParser', 'Twig_TokenParser_From'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IfTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IfTokenParser.php new file mode 100644 index 0000000..2631a20 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IfTokenParser.php @@ -0,0 +1,91 @@ + + * {% for user in users %} + *
  • {{ user.username|e }}
  • + * {% endfor %} + * + * {% endif %} + * + * @final + */ +class IfTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideIfFork']); + $tests = [$expr, $body]; + $else = null; + + $end = false; + while (!$end) { + switch ($stream->next()->getValue()) { + case 'else': + $stream->expect(Token::BLOCK_END_TYPE); + $else = $this->parser->subparse([$this, 'decideIfEnd']); + break; + + case 'elseif': + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideIfFork']); + $tests[] = $expr; + $tests[] = $body; + break; + + case 'endif': + $end = true; + break; + + default: + throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + + $stream->expect(Token::BLOCK_END_TYPE); + + return new IfNode(new Node($tests), $else, $lineno, $this->getTag()); + } + + public function decideIfFork(Token $token) + { + return $token->test(['elseif', 'else', 'endif']); + } + + public function decideIfEnd(Token $token) + { + return $token->test(['endif']); + } + + public function getTag() + { + return 'if'; + } +} + +class_alias('Twig\TokenParser\IfTokenParser', 'Twig_TokenParser_If'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ImportTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ImportTokenParser.php new file mode 100644 index 0000000..88395b9 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/ImportTokenParser.php @@ -0,0 +1,45 @@ +parser->getExpressionParser()->parseExpression(); + $this->parser->getStream()->expect(Token::NAME_TYPE, 'as'); + $var = new AssignNameExpression($this->parser->getStream()->expect(Token::NAME_TYPE)->getValue(), $token->getLine()); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + $this->parser->addImportedSymbol('template', $var->getAttribute('name')); + + return new ImportNode($macro, $var, $token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'import'; + } +} + +class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IncludeTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IncludeTokenParser.php new file mode 100644 index 0000000..57aa4cf --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/IncludeTokenParser.php @@ -0,0 +1,68 @@ +parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + protected function parseArguments() + { + $stream = $this->parser->getStream(); + + $ignoreMissing = false; + if ($stream->nextIf(Token::NAME_TYPE, 'ignore')) { + $stream->expect(Token::NAME_TYPE, 'missing'); + + $ignoreMissing = true; + } + + $variables = null; + if ($stream->nextIf(Token::NAME_TYPE, 'with')) { + $variables = $this->parser->getExpressionParser()->parseExpression(); + } + + $only = false; + if ($stream->nextIf(Token::NAME_TYPE, 'only')) { + $only = true; + } + + $stream->expect(Token::BLOCK_END_TYPE); + + return [$variables, $only, $ignoreMissing]; + } + + public function getTag() + { + return 'include'; + } +} + +class_alias('Twig\TokenParser\IncludeTokenParser', 'Twig_TokenParser_Include'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/MacroTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/MacroTokenParser.php new file mode 100644 index 0000000..a0d66e7 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/MacroTokenParser.php @@ -0,0 +1,68 @@ + + * {% endmacro %} + * + * @final + */ +class MacroTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); + + $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); + + $stream->expect(Token::BLOCK_END_TYPE); + $this->parser->pushLocalScope(); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + if ($token = $stream->nextIf(Token::NAME_TYPE)) { + $value = $token->getValue(); + + if ($value != $name) { + throw new SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + $this->parser->popLocalScope(); + $stream->expect(Token::BLOCK_END_TYPE); + + $this->parser->setMacro($name, new MacroNode($name, new BodyNode([$body]), $arguments, $lineno, $this->getTag())); + + return new Node(); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endmacro'); + } + + public function getTag() + { + return 'macro'; + } +} + +class_alias('Twig\TokenParser\MacroTokenParser', 'Twig_TokenParser_Macro'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SandboxTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SandboxTokenParser.php new file mode 100644 index 0000000..0f3ad9e --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SandboxTokenParser.php @@ -0,0 +1,67 @@ +parser->getStream(); + $stream->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(Token::BLOCK_END_TYPE); + + // in a sandbox tag, only include tags are allowed + if (!$body instanceof IncludeNode) { + foreach ($body as $node) { + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { + continue; + } + + if (!$node instanceof IncludeNode) { + throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); + } + } + } + + return new SandboxNode($body, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endsandbox'); + } + + public function getTag() + { + return 'sandbox'; + } +} + +class_alias('Twig\TokenParser\SandboxTokenParser', 'Twig_TokenParser_Sandbox'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SetTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SetTokenParser.php new file mode 100644 index 0000000..eebebc6 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SetTokenParser.php @@ -0,0 +1,74 @@ +getLine(); + $stream = $this->parser->getStream(); + $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); + + $capture = false; + if ($stream->nextIf(Token::OPERATOR_TYPE, '=')) { + $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); + + $stream->expect(Token::BLOCK_END_TYPE); + + if (\count($names) !== \count($values)) { + throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } else { + $capture = true; + + if (\count($names) > 1) { + throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $stream->expect(Token::BLOCK_END_TYPE); + + $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(Token::BLOCK_END_TYPE); + } + + return new SetNode($capture, $names, $values, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endset'); + } + + public function getTag() + { + return 'set'; + } +} + +class_alias('Twig\TokenParser\SetTokenParser', 'Twig_TokenParser_Set'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SpacelessTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SpacelessTokenParser.php new file mode 100644 index 0000000..5b5656b --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/SpacelessTokenParser.php @@ -0,0 +1,53 @@ + + * foo + * + * {% endspaceless %} + * {# output will be
    foo
    #} + * + * @final + */ +class SpacelessTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new SpacelessNode($body, $lineno, $this->getTag()); + } + + public function decideSpacelessEnd(Token $token) + { + return $token->test('endspaceless'); + } + + public function getTag() + { + return 'spaceless'; + } +} + +class_alias('Twig\TokenParser\SpacelessTokenParser', 'Twig_TokenParser_Spaceless'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/TokenParserInterface.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/TokenParserInterface.php new file mode 100644 index 0000000..4b603b2 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/TokenParserInterface.php @@ -0,0 +1,51 @@ + + */ +interface TokenParserInterface +{ + /** + * Sets the parser associated with this token parser. + */ + public function setParser(Parser $parser); + + /** + * Parses a token and returns a node. + * + * @return \Twig_NodeInterface + * + * @throws SyntaxError + */ + public function parse(Token $token); + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag(); +} + +class_alias('Twig\TokenParser\TokenParserInterface', 'Twig_TokenParserInterface'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Token'); +class_exists('Twig\Parser'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/UseTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/UseTokenParser.php new file mode 100644 index 0000000..d2e39aa --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/UseTokenParser.php @@ -0,0 +1,75 @@ +parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + + if (!$template instanceof ConstantExpression) { + throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $targets = []; + if ($stream->nextIf('with')) { + do { + $name = $stream->expect(Token::NAME_TYPE)->getValue(); + + $alias = $name; + if ($stream->nextIf('as')) { + $alias = $stream->expect(Token::NAME_TYPE)->getValue(); + } + + $targets[$name] = new ConstantExpression($alias, -1); + + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { + break; + } + } while (true); + } + + $stream->expect(Token::BLOCK_END_TYPE); + + $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)])); + + return new Node(); + } + + public function getTag() + { + return 'use'; + } +} + +class_alias('Twig\TokenParser\UseTokenParser', 'Twig_TokenParser_Use'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/WithTokenParser.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/WithTokenParser.php new file mode 100644 index 0000000..411e2b4 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenParser/WithTokenParser.php @@ -0,0 +1,57 @@ + + * + * @final + */ +class WithTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $stream = $this->parser->getStream(); + + $variables = null; + $only = false; + if (!$stream->test(Token::BLOCK_END_TYPE)) { + $variables = $this->parser->getExpressionParser()->parseExpression(); + $only = $stream->nextIf(Token::NAME_TYPE, 'only'); + } + + $stream->expect(Token::BLOCK_END_TYPE); + + $body = $this->parser->subparse([$this, 'decideWithEnd'], true); + + $stream->expect(Token::BLOCK_END_TYPE); + + return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag()); + } + + public function decideWithEnd(Token $token) + { + return $token->test('endwith'); + } + + public function getTag() + { + return 'with'; + } +} + +class_alias('Twig\TokenParser\WithTokenParser', 'Twig_TokenParser_With'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenStream.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenStream.php new file mode 100644 index 0000000..4597816 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TokenStream.php @@ -0,0 +1,201 @@ + + */ +class TokenStream +{ + protected $tokens; + protected $current = 0; + protected $filename; + + private $source; + + /** + * @param array $tokens An array of tokens + * @param string|null $name The name of the template which tokens are associated with + * @param string|null $source The source code associated with the tokens + */ + public function __construct(array $tokens, $name = null, $source = null) + { + if (!$name instanceof Source) { + if (null !== $name || null !== $source) { + @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); + } + $this->source = new Source($source, $name); + } else { + $this->source = $name; + } + + $this->tokens = $tokens; + + // deprecated, not used anymore, to be removed in 2.0 + $this->filename = $this->source->getName(); + } + + public function __toString() + { + return implode("\n", $this->tokens); + } + + public function injectTokens(array $tokens) + { + $this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current)); + } + + /** + * Sets the pointer to the next token and returns the old one. + * + * @return Token + */ + public function next() + { + if (!isset($this->tokens[++$this->current])) { + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); + } + + return $this->tokens[$this->current - 1]; + } + + /** + * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. + * + * @return Token|null The next token if the condition is true, null otherwise + */ + public function nextIf($primary, $secondary = null) + { + if ($this->tokens[$this->current]->test($primary, $secondary)) { + return $this->next(); + } + } + + /** + * Tests a token and returns it or throws a syntax error. + * + * @return Token + */ + public function expect($type, $value = null, $message = null) + { + $token = $this->tokens[$this->current]; + if (!$token->test($type, $value)) { + $line = $token->getLine(); + throw new SyntaxError(sprintf('%sUnexpected token "%s"%s ("%s" expected%s).', + $message ? $message.'. ' : '', + Token::typeToEnglish($token->getType()), + $token->getValue() ? sprintf(' of value "%s"', $token->getValue()) : '', + Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), + $line, + $this->source + ); + } + $this->next(); + + return $token; + } + + /** + * Looks at the next token. + * + * @param int $number + * + * @return Token + */ + public function look($number = 1) + { + if (!isset($this->tokens[$this->current + $number])) { + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); + } + + return $this->tokens[$this->current + $number]; + } + + /** + * Tests the current token. + * + * @return bool + */ + public function test($primary, $secondary = null) + { + return $this->tokens[$this->current]->test($primary, $secondary); + } + + /** + * Checks if end of stream was reached. + * + * @return bool + */ + public function isEOF() + { + return Token::EOF_TYPE === $this->tokens[$this->current]->getType(); + } + + /** + * @return Token + */ + public function getCurrent() + { + return $this->tokens[$this->current]; + } + + /** + * Gets the name associated with this stream (null if not defined). + * + * @return string|null + * + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getFilename() + { + @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); + + return $this->source->getName(); + } + + /** + * Gets the source code associated with this stream. + * + * @return string + * + * @internal Don't use this as it might be empty depending on the environment configuration + * + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getSource() + { + @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); + + return $this->source->getCode(); + } + + /** + * Gets the source associated with this stream. + * + * @return Source + * + * @internal + */ + public function getSourceContext() + { + return $this->source; + } +} + +class_alias('Twig\TokenStream', 'Twig_TokenStream'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFilter.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFilter.php new file mode 100644 index 0000000..089a6d1 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFilter.php @@ -0,0 +1,128 @@ + + */ +class TwigFilter +{ + protected $name; + protected $callable; + protected $options; + protected $arguments = []; + + public function __construct($name, $callable, array $options = []) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'pre_escape' => null, + 'preserves_safety' => null, + 'node_class' => '\Twig\Node\Expression\FilterExpression', + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName() + { + return $this->name; + } + + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Node $filterArgs) + { + if (null !== $this->options['is_safe']) { + return $this->options['is_safe']; + } + + if (null !== $this->options['is_safe_callback']) { + return \call_user_func($this->options['is_safe_callback'], $filterArgs); + } + } + + public function getPreservesSafety() + { + return $this->options['preserves_safety']; + } + + public function getPreEscape() + { + return $this->options['pre_escape']; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } +} + +class_alias('Twig\TwigFilter', 'Twig_SimpleFilter'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Node\Node'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFunction.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFunction.php new file mode 100644 index 0000000..374f070 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigFunction.php @@ -0,0 +1,118 @@ + + */ +class TwigFunction +{ + protected $name; + protected $callable; + protected $options; + protected $arguments = []; + + public function __construct($name, $callable, array $options = []) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'node_class' => '\Twig\Node\Expression\FunctionExpression', + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName() + { + return $this->name; + } + + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Node $functionArgs) + { + if (null !== $this->options['is_safe']) { + return $this->options['is_safe']; + } + + if (null !== $this->options['is_safe_callback']) { + return \call_user_func($this->options['is_safe_callback'], $functionArgs); + } + + return []; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } +} + +class_alias('Twig\TwigFunction', 'Twig_SimpleFunction'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Node\Node'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigTest.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigTest.php new file mode 100644 index 0000000..5054965 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/TwigTest.php @@ -0,0 +1,87 @@ + + */ +class TwigTest +{ + protected $name; + protected $callable; + protected $options; + + private $arguments = []; + + public function __construct($name, $callable, array $options = []) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'is_variadic' => false, + 'node_class' => '\Twig\Node\Expression\TestExpression', + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName() + { + return $this->name; + } + + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } +} + +class_alias('Twig\TwigTest', 'Twig_SimpleTest'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Util/DeprecationCollector.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Util/DeprecationCollector.php new file mode 100644 index 0000000..09917e9 --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Util/DeprecationCollector.php @@ -0,0 +1,92 @@ + + * + * @final + */ +class DeprecationCollector +{ + private $twig; + private $deprecations; + + public function __construct(Environment $twig) + { + $this->twig = $twig; + } + + /** + * Returns deprecations for templates contained in a directory. + * + * @param string $dir A directory where templates are stored + * @param string $ext Limit the loaded templates by extension + * + * @return array An array of deprecations + */ + public function collectDir($dir, $ext = '.twig') + { + $iterator = new \RegexIterator( + new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY + ), '{'.preg_quote($ext).'$}' + ); + + return $this->collect(new TemplateDirIterator($iterator)); + } + + /** + * Returns deprecations for passed templates. + * + * @param \Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) + * + * @return array An array of deprecations + */ + public function collect(\Traversable $iterator) + { + $this->deprecations = []; + + set_error_handler([$this, 'errorHandler']); + + foreach ($iterator as $name => $contents) { + try { + $this->twig->parse($this->twig->tokenize(new Source($contents, $name))); + } catch (SyntaxError $e) { + // ignore templates containing syntax errors + } + } + + restore_error_handler(); + + $deprecations = $this->deprecations; + $this->deprecations = []; + + return $deprecations; + } + + /** + * @internal + */ + public function errorHandler($type, $msg) + { + if (E_USER_DEPRECATED === $type) { + $this->deprecations[] = $msg; + } + } +} + +class_alias('Twig\Util\DeprecationCollector', 'Twig_Util_DeprecationCollector'); diff --git a/system/templateEngines/Twig/Twig1x/twig/twig/src/Util/TemplateDirIterator.php b/system/templateEngines/Twig/Twig1x/twig/twig/src/Util/TemplateDirIterator.php new file mode 100644 index 0000000..1ab0dac --- /dev/null +++ b/system/templateEngines/Twig/Twig1x/twig/twig/src/Util/TemplateDirIterator.php @@ -0,0 +1,30 @@ + + */ +class TemplateDirIterator extends \IteratorIterator +{ + public function current() + { + return file_get_contents(parent::current()); + } + + public function key() + { + return (string) parent::key(); + } +} + +class_alias('Twig\Util\TemplateDirIterator', 'Twig_Util_TemplateDirIterator'); diff --git a/system/templateEngines/Twig/Twig2x/BaseNodeVisitor.php b/system/templateEngines/Twig/Twig2x/BaseNodeVisitor.php deleted file mode 100644 index 1e1e13e..0000000 --- a/system/templateEngines/Twig/Twig2x/BaseNodeVisitor.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ -abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface -{ - final public function enterNode(Twig_Node $node, Twig_Environment $env) - { - return $this->doEnterNode($node, $env); - } - - final public function leaveNode(Twig_Node $node, Twig_Environment $env) - { - return $this->doLeaveNode($node, $env); - } - - /** - * Called before child nodes are visited. - * - * @return Twig_Node The modified node - */ - abstract protected function doEnterNode(Twig_Node $node, Twig_Environment $env); - - /** - * Called after child nodes are visited. - * - * @return Twig_Node|false The modified node or false if the node must be removed - */ - abstract protected function doLeaveNode(Twig_Node $node, Twig_Environment $env); -} - -class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false); -class_exists('Twig_Environment'); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig2x/Cache/Filesystem.php b/system/templateEngines/Twig/Twig2x/Cache/Filesystem.php deleted file mode 100644 index 5b0acc0..0000000 --- a/system/templateEngines/Twig/Twig2x/Cache/Filesystem.php +++ /dev/null @@ -1,91 +0,0 @@ - - */ -class Twig_Cache_Filesystem implements Twig_CacheInterface -{ - const FORCE_BYTECODE_INVALIDATION = 1; - - private $directory; - private $options; - - /** - * @param $directory string The root cache directory - * @param $options int A set of options - */ - public function __construct($directory, $options = 0) - { - $this->directory = rtrim($directory, '\/').'/'; - $this->options = $options; - } - - public function generateKey($name, $className) - { - $hash = hash('sha256', $className); - - return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; - } - - public function load($key) - { - if (file_exists($key)) { - @include_once $key; - } - } - - public function write($key, $content) - { - $dir = dirname($key); - if (!is_dir($dir)) { - if (false === @mkdir($dir, 0777, true)) { - clearstatcache(true, $dir); - if (!is_dir($dir)) { - throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); - } - } - } elseif (!is_writable($dir)) { - throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); - } - - $tmpFile = tempnam($dir, basename($key)); - if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { - @chmod($key, 0666 & ~umask()); - - if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { - // Compile cached file into bytecode cache - if (function_exists('opcache_invalidate')) { - opcache_invalidate($key, true); - } elseif (function_exists('apc_compile_file')) { - apc_compile_file($key); - } - } - - return; - } - - throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key)); - } - - public function getTimestamp($key) - { - if (!file_exists($key)) { - return 0; - } - - return (int) @filemtime($key); - } -} - -class_alias('Twig_Cache_Filesystem', 'Twig\Cache\FilesystemCache', false); diff --git a/system/templateEngines/Twig/Twig2x/Cache/Null.php b/system/templateEngines/Twig/Twig2x/Cache/Null.php deleted file mode 100644 index 224048d..0000000 --- a/system/templateEngines/Twig/Twig2x/Cache/Null.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -final class Twig_Cache_Null implements Twig_CacheInterface -{ - public function generateKey($name, $className) - { - return ''; - } - - public function write($key, $content) - { - } - - public function load($key) - { - } - - public function getTimestamp($key) - { - return 0; - } -} - -class_alias('Twig_Cache_Null', 'Twig\Cache\NullCache', false); diff --git a/system/templateEngines/Twig/Twig2x/CacheInterface.php b/system/templateEngines/Twig/Twig2x/CacheInterface.php deleted file mode 100644 index 776808b..0000000 --- a/system/templateEngines/Twig/Twig2x/CacheInterface.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -interface Twig_CacheInterface -{ - /** - * Generates a cache key for the given template class name. - * - * @param string $name The template name - * @param string $className The template class name - * - * @return string - */ - public function generateKey($name, $className); - - /** - * Writes the compiled template to cache. - * - * @param string $key The cache key - * @param string $content The template representation as a PHP class - */ - public function write($key, $content); - - /** - * Loads a template from the cache. - * - * @param string $key The cache key - */ - public function load($key); - - /** - * Returns the modification timestamp of a key. - * - * @param string $key The cache key - * - * @return int - */ - public function getTimestamp($key); -} - -class_alias('Twig_CacheInterface', 'Twig\Cache\CacheInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/Compiler.php b/system/templateEngines/Twig/Twig2x/Compiler.php deleted file mode 100644 index 62aa314..0000000 --- a/system/templateEngines/Twig/Twig2x/Compiler.php +++ /dev/null @@ -1,243 +0,0 @@ - - */ -class Twig_Compiler -{ - private $lastLine; - private $source; - private $indentation; - private $env; - private $debugInfo = []; - private $sourceOffset; - private $sourceLine; - private $varNameSalt = 0; - - public function __construct(Twig_Environment $env) - { - $this->env = $env; - } - - /** - * Returns the environment instance related to this compiler. - * - * @return Twig_Environment - */ - public function getEnvironment() - { - return $this->env; - } - - /** - * Gets the current PHP code after compilation. - * - * @return string The PHP code - */ - public function getSource() - { - return $this->source; - } - - /** - * Compiles a node. - * - * @param Twig_Node $node The node to compile - * @param int $indentation The current indentation - * - * @return $this - */ - public function compile(Twig_Node $node, $indentation = 0) - { - $this->lastLine = null; - $this->source = ''; - $this->debugInfo = []; - $this->sourceOffset = 0; - // source code starts at 1 (as we then increment it when we encounter new lines) - $this->sourceLine = 1; - $this->indentation = $indentation; - $this->varNameSalt = 0; - - $node->compile($this); - - return $this; - } - - public function subcompile(Twig_Node $node, $raw = true) - { - if (false === $raw) { - $this->source .= str_repeat(' ', $this->indentation * 4); - } - - $node->compile($this); - - return $this; - } - - /** - * Adds a raw string to the compiled code. - * - * @param string $string The string - * - * @return $this - */ - public function raw($string) - { - $this->source .= $string; - - return $this; - } - - /** - * Writes a string to the compiled code by adding indentation. - * - * @return $this - */ - public function write(...$strings) - { - foreach ($strings as $string) { - $this->source .= str_repeat(' ', $this->indentation * 4).$string; - } - - return $this; - } - - /** - * Adds a quoted string to the compiled code. - * - * @param string $value The string - * - * @return $this - */ - public function string($value) - { - $this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\")); - - return $this; - } - - /** - * Returns a PHP representation of a given value. - * - * @param mixed $value The value to convert - * - * @return $this - */ - public function repr($value) - { - if (is_int($value) || is_float($value)) { - if (false !== $locale = setlocale(LC_NUMERIC, '0')) { - setlocale(LC_NUMERIC, 'C'); - } - - $this->raw(var_export($value, true)); - - if (false !== $locale) { - setlocale(LC_NUMERIC, $locale); - } - } elseif (null === $value) { - $this->raw('null'); - } elseif (is_bool($value)) { - $this->raw($value ? 'true' : 'false'); - } elseif (is_array($value)) { - $this->raw('array('); - $first = true; - foreach ($value as $key => $v) { - if (!$first) { - $this->raw(', '); - } - $first = false; - $this->repr($key); - $this->raw(' => '); - $this->repr($v); - } - $this->raw(')'); - } else { - $this->string($value); - } - - return $this; - } - - /** - * Adds debugging information. - * - * @return $this - */ - public function addDebugInfo(Twig_Node $node) - { - if ($node->getTemplateLine() != $this->lastLine) { - $this->write(sprintf("// line %d\n", $node->getTemplateLine())); - - $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); - $this->sourceOffset = strlen($this->source); - $this->debugInfo[$this->sourceLine] = $node->getTemplateLine(); - - $this->lastLine = $node->getTemplateLine(); - } - - return $this; - } - - public function getDebugInfo() - { - ksort($this->debugInfo); - - return $this->debugInfo; - } - - /** - * Indents the generated code. - * - * @param int $step The number of indentation to add - * - * @return $this - */ - public function indent($step = 1) - { - $this->indentation += $step; - - return $this; - } - - /** - * Outdents the generated code. - * - * @param int $step The number of indentation to remove - * - * @return $this - * - * @throws LogicException When trying to outdent too much so the indentation would become negative - */ - public function outdent($step = 1) - { - // can't outdent by more steps than the current indentation level - if ($this->indentation < $step) { - throw new LogicException('Unable to call outdent() as the indentation would become negative.'); - } - - $this->indentation -= $step; - - return $this; - } - - public function getVarName() - { - return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++)); - } -} - -class_alias('Twig_Compiler', 'Twig\Compiler', false); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig2x/ContainerRuntimeLoader.php b/system/templateEngines/Twig/Twig2x/ContainerRuntimeLoader.php deleted file mode 100644 index 814ab58..0000000 --- a/system/templateEngines/Twig/Twig2x/ContainerRuntimeLoader.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @author Robin Chalas - */ -class Twig_ContainerRuntimeLoader implements Twig_RuntimeLoaderInterface -{ - private $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - public function load($class) - { - if ($this->container->has($class)) { - return $this->container->get($class); - } - } -} - -class_alias('Twig_ContainerRuntimeLoader', 'Twig\RuntimeLoader\ContainerRuntimeLoader', false); diff --git a/system/templateEngines/Twig/Twig2x/Environment.php b/system/templateEngines/Twig/Twig2x/Environment.php deleted file mode 100644 index f63153c..0000000 --- a/system/templateEngines/Twig/Twig2x/Environment.php +++ /dev/null @@ -1,970 +0,0 @@ - - */ -class Twig_Environment -{ - const VERSION = '2.6.2'; - const VERSION_ID = 20602; - const MAJOR_VERSION = 2; - const MINOR_VERSION = 6; - const RELEASE_VERSION = 2; - const EXTRA_VERSION = ''; - - private $charset; - private $loader; - private $debug; - private $autoReload; - private $cache; - private $lexer; - private $parser; - private $compiler; - private $baseTemplateClass; - private $globals = []; - private $resolvedGlobals; - private $loadedTemplates; - private $strictVariables; - private $templateClassPrefix = '__TwigTemplate_'; - private $originalCache; - private $extensionSet; - private $runtimeLoaders = []; - private $runtimes = []; - private $optionsHash; - private $loading = []; - - /** - * Constructor. - * - * Available options: - * - * * debug: When set to true, it automatically set "auto_reload" to true as - * well (default to false). - * - * * charset: The charset used by the templates (default to UTF-8). - * - * * base_template_class: The base template class to use for generated - * templates (default to Twig_Template). - * - * * cache: An absolute path where to store the compiled templates, - * a Twig_Cache_Interface implementation, - * or false to disable compilation cache (default). - * - * * auto_reload: Whether to reload the template if the original source changed. - * If you don't provide the auto_reload option, it will be - * determined automatically based on the debug value. - * - * * strict_variables: Whether to ignore invalid variables in templates - * (default to false). - * - * * autoescape: Whether to enable auto-escaping (default to html): - * * false: disable auto-escaping - * * html, js: set the autoescaping to one of the supported strategies - * * name: set the autoescaping strategy based on the template name extension - * * PHP callback: a PHP callback that returns an escaping strategy based on the template "name" - * - * * optimizations: A flag that indicates which optimizations to apply - * (default to -1 which means that all optimizations are enabled; - * set it to 0 to disable). - * - * @param Twig_LoaderInterface $loader - * @param array $options An array of options - */ - public function __construct(Twig_LoaderInterface $loader, $options = []) - { - $this->setLoader($loader); - - $options = array_merge([ - 'debug' => false, - 'charset' => 'UTF-8', - 'base_template_class' => 'Twig_Template', - 'strict_variables' => false, - 'autoescape' => 'html', - 'cache' => false, - 'auto_reload' => null, - 'optimizations' => -1, - ], $options); - - $this->debug = (bool) $options['debug']; - $this->setCharset($options['charset']); - $this->baseTemplateClass = $options['base_template_class']; - $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; - $this->strictVariables = (bool) $options['strict_variables']; - $this->setCache($options['cache']); - $this->extensionSet = new Twig_ExtensionSet(); - - $this->addExtension(new Twig_Extension_Core()); - $this->addExtension(new Twig_Extension_Escaper($options['autoescape'])); - $this->addExtension(new Twig_Extension_Optimizer($options['optimizations'])); - } - - /** - * Gets the base template class for compiled templates. - * - * @return string The base template class name - */ - public function getBaseTemplateClass() - { - return $this->baseTemplateClass; - } - - /** - * Sets the base template class for compiled templates. - * - * @param string $class The base template class name - */ - public function setBaseTemplateClass($class) - { - $this->baseTemplateClass = $class; - $this->updateOptionsHash(); - } - - /** - * Enables debugging mode. - */ - public function enableDebug() - { - $this->debug = true; - $this->updateOptionsHash(); - } - - /** - * Disables debugging mode. - */ - public function disableDebug() - { - $this->debug = false; - $this->updateOptionsHash(); - } - - /** - * Checks if debug mode is enabled. - * - * @return bool true if debug mode is enabled, false otherwise - */ - public function isDebug() - { - return $this->debug; - } - - /** - * Enables the auto_reload option. - */ - public function enableAutoReload() - { - $this->autoReload = true; - } - - /** - * Disables the auto_reload option. - */ - public function disableAutoReload() - { - $this->autoReload = false; - } - - /** - * Checks if the auto_reload option is enabled. - * - * @return bool true if auto_reload is enabled, false otherwise - */ - public function isAutoReload() - { - return $this->autoReload; - } - - /** - * Enables the strict_variables option. - */ - public function enableStrictVariables() - { - $this->strictVariables = true; - $this->updateOptionsHash(); - } - - /** - * Disables the strict_variables option. - */ - public function disableStrictVariables() - { - $this->strictVariables = false; - $this->updateOptionsHash(); - } - - /** - * Checks if the strict_variables option is enabled. - * - * @return bool true if strict_variables is enabled, false otherwise - */ - public function isStrictVariables() - { - return $this->strictVariables; - } - - /** - * Gets the current cache implementation. - * - * @param bool $original Whether to return the original cache option or the real cache instance - * - * @return Twig_CacheInterface|string|false A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache - */ - public function getCache($original = true) - { - return $original ? $this->originalCache : $this->cache; - } - - /** - * Sets the current cache implementation. - * - * @param Twig_CacheInterface|string|false $cache A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache - */ - public function setCache($cache) - { - if (is_string($cache)) { - $this->originalCache = $cache; - $this->cache = new Twig_Cache_Filesystem($cache); - } elseif (false === $cache) { - $this->originalCache = $cache; - $this->cache = new Twig_Cache_Null(); - } elseif ($cache instanceof Twig_CacheInterface) { - $this->originalCache = $this->cache = $cache; - } else { - throw new LogicException(sprintf('Cache can only be a string, false, or a Twig_CacheInterface implementation.')); - } - } - - /** - * Gets the template class associated with the given string. - * - * The generated template class is based on the following parameters: - * - * * The cache key for the given template; - * * The currently enabled extensions; - * * Whether the Twig C extension is available or not; - * * PHP version; - * * Twig version; - * * Options with what environment was created. - * - * @param string $name The name for which to calculate the template class name - * @param int|null $index The index if it is an embedded template - * - * @return string The template class name - */ - public function getTemplateClass($name, $index = null) - { - $key = $this->getLoader()->getCacheKey($name).$this->optionsHash; - - return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '_'.$index); - } - - /** - * Renders a template. - * - * @param string $name The template name - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered template - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - * @throws Twig_Error_Runtime When an error occurred during rendering - */ - public function render($name, array $context = []) - { - return $this->loadTemplate($name)->render($context); - } - - /** - * Displays a template. - * - * @param string $name The template name - * @param array $context An array of parameters to pass to the template - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - * @throws Twig_Error_Runtime When an error occurred during rendering - */ - public function display($name, array $context = []) - { - $this->loadTemplate($name)->display($context); - } - - /** - * Loads a template. - * - * @param string|Twig_TemplateWrapper|Twig_Template $name The template name - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Runtime When a previously generated cache is corrupted - * @throws Twig_Error_Syntax When an error occurred during compilation - * - * @return Twig_TemplateWrapper - */ - public function load($name) - { - if ($name instanceof Twig_TemplateWrapper) { - return $name; - } - - if ($name instanceof Twig_Template) { - return new Twig_TemplateWrapper($this, $name); - } - - return new Twig_TemplateWrapper($this, $this->loadTemplate($name)); - } - - /** - * Loads a template internal representation. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The template name - * @param int $index The index if it is an embedded template - * - * @return Twig_Template A template instance representing the given template name - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Runtime When a previously generated cache is corrupted - * @throws Twig_Error_Syntax When an error occurred during compilation - * - * @internal - */ - public function loadTemplate($name, $index = null) - { - $cls = $mainCls = $this->getTemplateClass($name); - if (null !== $index) { - $cls .= '_'.$index; - } - - if (isset($this->loadedTemplates[$cls])) { - return $this->loadedTemplates[$cls]; - } - - if (!class_exists($cls, false)) { - $key = $this->cache->generateKey($name, $mainCls); - - if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) { - $this->cache->load($key); - } - - if (!class_exists($cls, false)) { - $source = $this->getLoader()->getSourceContext($name); - $content = $this->compileSource($source); - $this->cache->write($key, $content); - $this->cache->load($key); - - if (!class_exists($mainCls, false)) { - /* Last line of defense if either $this->bcWriteCacheFile was used, - * $this->cache is implemented as a no-op or we have a race condition - * where the cache was cleared between the above calls to write to and load from - * the cache. - */ - eval('?>'.$content); - } - - if (!class_exists($cls, false)) { - throw new Twig_Error_Runtime(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source); - } - } - } - - // to be removed in 3.0 - $this->extensionSet->initRuntime($this); - - if (isset($this->loading[$cls])) { - throw new Twig_Error_Runtime(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, [$name])))); - } - - $this->loading[$cls] = $name; - - try { - $this->loadedTemplates[$cls] = new $cls($this); - } finally { - unset($this->loading[$cls]); - } - - return $this->loadedTemplates[$cls]; - } - - /** - * Creates a template from source. - * - * This method should not be used as a generic way to load templates. - * - * @param string $template The template name - * - * @return Twig_Template A template instance representing the given template name - * - * @throws Twig_Error_Loader When the template cannot be found - * @throws Twig_Error_Syntax When an error occurred during compilation - */ - public function createTemplate($template) - { - $name = sprintf('__string_template__%s', hash('sha256', $template, false)); - - $loader = new Twig_Loader_Chain([ - new Twig_Loader_Array([$name => $template]), - $current = $this->getLoader(), - ]); - - $this->setLoader($loader); - try { - $template = $this->loadTemplate($name); - } finally { - $this->setLoader($current); - } - - return $template; - } - - /** - * Returns true if the template is still fresh. - * - * Besides checking the loader for freshness information, - * this method also checks if the enabled extensions have - * not changed. - * - * @param string $name The template name - * @param int $time The last modification time of the cached template - * - * @return bool true if the template is fresh, false otherwise - */ - public function isTemplateFresh($name, $time) - { - return $this->extensionSet->getLastModified() <= $time && $this->getLoader()->isFresh($name, $time); - } - - /** - * Tries to load a template consecutively from an array. - * - * Similar to loadTemplate() but it also accepts instances of Twig_Template and - * Twig_TemplateWrapper, and an array of templates where each is tried to be loaded. - * - * @param string|Twig_Template|Twig_TemplateWrapper|array $names A template or an array of templates to try consecutively - * - * @return Twig_Template|Twig_TemplateWrapper - * - * @throws Twig_Error_Loader When none of the templates can be found - * @throws Twig_Error_Syntax When an error occurred during compilation - */ - public function resolveTemplate($names) - { - if (!is_array($names)) { - $names = [$names]; - } - - foreach ($names as $name) { - if ($name instanceof Twig_Template) { - return $name; - } - - if ($name instanceof Twig_TemplateWrapper) { - return $name; - } - - try { - return $this->loadTemplate($name); - } catch (Twig_Error_Loader $e) { - } - } - - if (1 === count($names)) { - throw $e; - } - - throw new Twig_Error_Loader(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); - } - - public function setLexer(Twig_Lexer $lexer) - { - $this->lexer = $lexer; - } - - /** - * Tokenizes a source code. - * - * @return Twig_TokenStream - * - * @throws Twig_Error_Syntax When the code is syntactically wrong - */ - public function tokenize(Twig_Source $source) - { - if (null === $this->lexer) { - $this->lexer = new Twig_Lexer($this); - } - - return $this->lexer->tokenize($source); - } - - public function setParser(Twig_Parser $parser) - { - $this->parser = $parser; - } - - /** - * Converts a token stream to a node tree. - * - * @return Twig_Node_Module - * - * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong - */ - public function parse(Twig_TokenStream $stream) - { - if (null === $this->parser) { - $this->parser = new Twig_Parser($this); - } - - return $this->parser->parse($stream); - } - - public function setCompiler(Twig_Compiler $compiler) - { - $this->compiler = $compiler; - } - - /** - * Compiles a node and returns the PHP code. - * - * @return string The compiled PHP source code - */ - public function compile(Twig_Node $node) - { - if (null === $this->compiler) { - $this->compiler = new Twig_Compiler($this); - } - - return $this->compiler->compile($node)->getSource(); - } - - /** - * Compiles a template source code. - * - * @return string The compiled PHP source code - * - * @throws Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling - */ - public function compileSource(Twig_Source $source) - { - try { - return $this->compile($this->parse($this->tokenize($source))); - } catch (Twig_Error $e) { - $e->setSourceContext($source); - throw $e; - } catch (Exception $e) { - throw new Twig_Error_Syntax(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); - } - } - - public function setLoader(Twig_LoaderInterface $loader) - { - $this->loader = $loader; - } - - /** - * Gets the Loader instance. - * - * @return Twig_LoaderInterface - */ - public function getLoader() - { - return $this->loader; - } - - /** - * Sets the default template charset. - * - * @param string $charset The default charset - */ - public function setCharset($charset) - { - if ('UTF8' === $charset = strtoupper($charset)) { - // iconv on Windows requires "UTF-8" instead of "UTF8" - $charset = 'UTF-8'; - } - - $this->charset = $charset; - } - - /** - * Gets the default template charset. - * - * @return string The default charset - */ - public function getCharset() - { - return $this->charset; - } - - /** - * Returns true if the given extension is registered. - * - * @param string $class The extension class name - * - * @return bool Whether the extension is registered or not - */ - public function hasExtension($class) - { - return $this->extensionSet->hasExtension($class); - } - - /** - * Adds a runtime loader. - */ - public function addRuntimeLoader(Twig_RuntimeLoaderInterface $loader) - { - $this->runtimeLoaders[] = $loader; - } - - /** - * Gets an extension by class name. - * - * @param string $class The extension class name - * - * @return Twig_ExtensionInterface - */ - public function getExtension($class) - { - return $this->extensionSet->getExtension($class); - } - - /** - * Returns the runtime implementation of a Twig element (filter/function/test). - * - * @param string $class A runtime class name - * - * @return object The runtime implementation - * - * @throws Twig_Error_Runtime When the template cannot be found - */ - public function getRuntime($class) - { - if (isset($this->runtimes[$class])) { - return $this->runtimes[$class]; - } - - foreach ($this->runtimeLoaders as $loader) { - if (null !== $runtime = $loader->load($class)) { - return $this->runtimes[$class] = $runtime; - } - } - - throw new Twig_Error_Runtime(sprintf('Unable to load the "%s" runtime.', $class)); - } - - public function addExtension(Twig_ExtensionInterface $extension) - { - $this->extensionSet->addExtension($extension); - $this->updateOptionsHash(); - } - - /** - * Registers an array of extensions. - * - * @param array $extensions An array of extensions - */ - public function setExtensions(array $extensions) - { - $this->extensionSet->setExtensions($extensions); - $this->updateOptionsHash(); - } - - /** - * Returns all registered extensions. - * - * @return Twig_ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) - */ - public function getExtensions() - { - return $this->extensionSet->getExtensions(); - } - - public function addTokenParser(Twig_TokenParserInterface $parser) - { - $this->extensionSet->addTokenParser($parser); - } - - /** - * Gets the registered Token Parsers. - * - * @return Twig_TokenParserInterface[] - * - * @internal - */ - public function getTokenParsers() - { - return $this->extensionSet->getTokenParsers(); - } - - /** - * Gets registered tags. - * - * @return Twig_TokenParserInterface[] - * - * @internal - */ - public function getTags() - { - $tags = []; - foreach ($this->getTokenParsers() as $parser) { - $tags[$parser->getTag()] = $parser; - } - - return $tags; - } - - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) - { - $this->extensionSet->addNodeVisitor($visitor); - } - - /** - * Gets the registered Node Visitors. - * - * @return Twig_NodeVisitorInterface[] - * - * @internal - */ - public function getNodeVisitors() - { - return $this->extensionSet->getNodeVisitors(); - } - - public function addFilter(Twig_Filter $filter) - { - $this->extensionSet->addFilter($filter); - } - - /** - * Get a filter by name. - * - * Subclasses may override this method and load filters differently; - * so no list of filters is available. - * - * @param string $name The filter name - * - * @return Twig_Filter|false A Twig_Filter instance or false if the filter does not exist - * - * @internal - */ - public function getFilter($name) - { - return $this->extensionSet->getFilter($name); - } - - public function registerUndefinedFilterCallback(callable $callable) - { - $this->extensionSet->registerUndefinedFilterCallback($callable); - } - - /** - * Gets the registered Filters. - * - * Be warned that this method cannot return filters defined with registerUndefinedFilterCallback. - * - * @return Twig_Filter[] - * - * @see registerUndefinedFilterCallback - * - * @internal - */ - public function getFilters() - { - return $this->extensionSet->getFilters(); - } - - /** - * Registers a Test. - * - * @param Twig_Test $test A Twig_Test instance - */ - public function addTest(Twig_Test $test) - { - $this->extensionSet->addTest($test); - } - - /** - * Gets the registered Tests. - * - * @return Twig_Test[] - * - * @internal - */ - public function getTests() - { - return $this->extensionSet->getTests(); - } - - /** - * Gets a test by name. - * - * @param string $name The test name - * - * @return Twig_Test|false A Twig_Test instance or false if the test does not exist - * - * @internal - */ - public function getTest($name) - { - return $this->extensionSet->getTest($name); - } - - public function addFunction(Twig_Function $function) - { - $this->extensionSet->addFunction($function); - } - - /** - * Get a function by name. - * - * Subclasses may override this method and load functions differently; - * so no list of functions is available. - * - * @param string $name function name - * - * @return Twig_Function|false A Twig_Function instance or false if the function does not exist - * - * @internal - */ - public function getFunction($name) - { - return $this->extensionSet->getFunction($name); - } - - public function registerUndefinedFunctionCallback(callable $callable) - { - $this->extensionSet->registerUndefinedFunctionCallback($callable); - } - - /** - * Gets registered functions. - * - * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback. - * - * @return Twig_Function[] - * - * @see registerUndefinedFunctionCallback - * - * @internal - */ - public function getFunctions() - { - return $this->extensionSet->getFunctions(); - } - - /** - * Registers a Global. - * - * New globals can be added before compiling or rendering a template; - * but after, you can only update existing globals. - * - * @param string $name The global name - * @param mixed $value The global value - */ - public function addGlobal($name, $value) - { - if ($this->extensionSet->isInitialized() && !array_key_exists($name, $this->getGlobals())) { - throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); - } - - if (null !== $this->resolvedGlobals) { - $this->resolvedGlobals[$name] = $value; - } else { - $this->globals[$name] = $value; - } - } - - /** - * Gets the registered Globals. - * - * @return array An array of globals - * - * @internal - */ - public function getGlobals() - { - if ($this->extensionSet->isInitialized()) { - if (null === $this->resolvedGlobals) { - $this->resolvedGlobals = array_merge($this->extensionSet->getGlobals(), $this->globals); - } - - return $this->resolvedGlobals; - } - - return array_merge($this->extensionSet->getGlobals(), $this->globals); - } - - /** - * Merges a context with the defined globals. - * - * @param array $context An array representing the context - * - * @return array The context merged with the globals - */ - public function mergeGlobals(array $context) - { - // we don't use array_merge as the context being generally - // bigger than globals, this code is faster. - foreach ($this->getGlobals() as $key => $value) { - if (!array_key_exists($key, $context)) { - $context[$key] = $value; - } - } - - return $context; - } - - /** - * Gets the registered unary Operators. - * - * @return array An array of unary operators - * - * @internal - */ - public function getUnaryOperators() - { - return $this->extensionSet->getUnaryOperators(); - } - - /** - * Gets the registered binary Operators. - * - * @return array An array of binary operators - * - * @internal - */ - public function getBinaryOperators() - { - return $this->extensionSet->getBinaryOperators(); - } - - private function updateOptionsHash() - { - $this->optionsHash = implode(':', [ - $this->extensionSet->getSignature(), - PHP_MAJOR_VERSION, - PHP_MINOR_VERSION, - self::VERSION, - (int) $this->debug, - $this->baseTemplateClass, - (int) $this->strictVariables, - ]); - } -} - -class_alias('Twig_Environment', 'Twig\Environment', false); diff --git a/system/templateEngines/Twig/Twig2x/Error.php b/system/templateEngines/Twig/Twig2x/Error.php deleted file mode 100644 index 1f36852..0000000 --- a/system/templateEngines/Twig/Twig2x/Error.php +++ /dev/null @@ -1,265 +0,0 @@ - - */ -class Twig_Error extends Exception -{ - private $lineno; - private $name; - private $rawMessage; - private $sourcePath; - private $sourceCode; - - /** - * Constructor. - * - * Set both the line number and the name to false to - * disable automatic guessing of the original template name - * and line number. - * - * Set the line number to -1 to enable its automatic guessing. - * Set the name to null to enable its automatic guessing. - * - * By default, automatic guessing is enabled. - * - * @param string $message The error message - * @param int $lineno The template line where the error occurred - * @param Twig_Source|string|null $source The source context where the error occurred - * @param Exception $previous The previous exception - */ - public function __construct($message, $lineno = -1, $source = null, Exception $previous = null) - { - parent::__construct('', 0, $previous); - - if (null === $source) { - $name = null; - } elseif (!$source instanceof Twig_Source) { - @trigger_error(sprintf('Passing a string as a source to %s is deprecated since version 2.6.1; pass a Twig_Source instance instead.', __CLASS__), E_USER_DEPRECATED); - $name = $source; - } else { - $name = $source->getName(); - $this->sourceCode = $source->getCode(); - $this->sourcePath = $source->getPath(); - } - - $this->lineno = $lineno; - $this->name = $name; - - if (-1 === $lineno || null === $name || null === $this->sourcePath) { - $this->guessTemplateInfo(); - } - - $this->rawMessage = $message; - - $this->updateRepr(); - } - - /** - * Gets the raw message. - * - * @return string The raw message - */ - public function getRawMessage() - { - return $this->rawMessage; - } - - /** - * Gets the template line where the error occurred. - * - * @return int The template line - */ - public function getTemplateLine() - { - return $this->lineno; - } - - /** - * Sets the template line where the error occurred. - * - * @param int $lineno The template line - */ - public function setTemplateLine($lineno) - { - $this->lineno = $lineno; - - $this->updateRepr(); - } - - /** - * Gets the source context of the Twig template where the error occurred. - * - * @return Twig_Source|null - */ - public function getSourceContext() - { - return $this->name ? new Twig_Source($this->sourceCode, $this->name, $this->sourcePath) : null; - } - - /** - * Sets the source context of the Twig template where the error occurred. - */ - public function setSourceContext(Twig_Source $source = null) - { - if (null === $source) { - $this->sourceCode = $this->name = $this->sourcePath = null; - } else { - $this->sourceCode = $source->getCode(); - $this->name = $source->getName(); - $this->sourcePath = $source->getPath(); - } - - $this->updateRepr(); - } - - public function guess() - { - $this->guessTemplateInfo(); - $this->updateRepr(); - } - - public function appendMessage($rawMessage) - { - $this->rawMessage .= $rawMessage; - $this->updateRepr(); - } - - private function updateRepr() - { - $this->message = $this->rawMessage; - - if ($this->sourcePath && $this->lineno > 0) { - $this->file = $this->sourcePath; - $this->line = $this->lineno; - - return; - } - - $dot = false; - if ('.' === substr($this->message, -1)) { - $this->message = substr($this->message, 0, -1); - $dot = true; - } - - $questionMark = false; - if ('?' === substr($this->message, -1)) { - $this->message = substr($this->message, 0, -1); - $questionMark = true; - } - - if ($this->name) { - if (is_string($this->name) || (is_object($this->name) && method_exists($this->name, '__toString'))) { - $name = sprintf('"%s"', $this->name); - } else { - $name = json_encode($this->name); - } - $this->message .= sprintf(' in %s', $name); - } - - if ($this->lineno && $this->lineno >= 0) { - $this->message .= sprintf(' at line %d', $this->lineno); - } - - if ($dot) { - $this->message .= '.'; - } - - if ($questionMark) { - $this->message .= '?'; - } - } - - private function guessTemplateInfo() - { - $template = null; - $templateClass = null; - - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); - foreach ($backtrace as $trace) { - if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) { - $currentClass = get_class($trace['object']); - $isEmbedContainer = 0 === strpos($templateClass, $currentClass); - if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) { - $template = $trace['object']; - $templateClass = get_class($trace['object']); - } - } - } - - // update template name - if (null !== $template && null === $this->name) { - $this->name = $template->getTemplateName(); - } - - // update template path if any - if (null !== $template && null === $this->sourcePath) { - $src = $template->getSourceContext(); - $this->sourceCode = $src->getCode(); - $this->sourcePath = $src->getPath(); - } - - if (null === $template || $this->lineno > -1) { - return; - } - - $r = new ReflectionObject($template); - $file = $r->getFileName(); - - $exceptions = [$e = $this]; - while ($e = $e->getPrevious()) { - $exceptions[] = $e; - } - - while ($e = array_pop($exceptions)) { - $traces = $e->getTrace(); - array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]); - - while ($trace = array_shift($traces)) { - if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) { - continue; - } - - foreach ($template->getDebugInfo() as $codeLine => $templateLine) { - if ($codeLine <= $trace['line']) { - // update template line - $this->lineno = $templateLine; - - return; - } - } - } - } - } -} - -class_alias('Twig_Error', 'Twig\Error\Error', false); -class_exists('Twig_Source'); diff --git a/system/templateEngines/Twig/Twig2x/Error/Loader.php b/system/templateEngines/Twig/Twig2x/Error/Loader.php deleted file mode 100644 index aec5b33..0000000 --- a/system/templateEngines/Twig/Twig2x/Error/Loader.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -class Twig_Error_Loader extends Twig_Error -{ - public function __construct($message, $lineno = -1, $source = null, Exception $previous = null) - { - Exception::__construct('', 0, $previous); - $this->appendMessage($message); - $this->setTemplateLine(false); - } -} - -class_alias('Twig_Error_Loader', 'Twig\Error\LoaderError', false); diff --git a/system/templateEngines/Twig/Twig2x/Error/Runtime.php b/system/templateEngines/Twig/Twig2x/Error/Runtime.php deleted file mode 100644 index 3b24ad3..0000000 --- a/system/templateEngines/Twig/Twig2x/Error/Runtime.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -class Twig_Error_Runtime extends Twig_Error -{ -} - -class_alias('Twig_Error_Runtime', 'Twig\Error\RuntimeError', false); diff --git a/system/templateEngines/Twig/Twig2x/Error/Syntax.php b/system/templateEngines/Twig/Twig2x/Error/Syntax.php deleted file mode 100644 index 3f76920..0000000 --- a/system/templateEngines/Twig/Twig2x/Error/Syntax.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ -class Twig_Error_Syntax extends Twig_Error -{ - /** - * Tweaks the error message to include suggestions. - * - * @param string $name The original name of the item that does not exist - * @param array $items An array of possible items - */ - public function addSuggestions($name, array $items) - { - $alternatives = []; - foreach ($items as $item) { - $lev = levenshtein($name, $item); - if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) { - $alternatives[$item] = $lev; - } - } - - if (!$alternatives) { - return; - } - - asort($alternatives); - - $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives)))); - } -} - -class_alias('Twig_Error_Syntax', 'Twig\Error\SyntaxError', false); diff --git a/system/templateEngines/Twig/Twig2x/ExistsLoaderInterface.php b/system/templateEngines/Twig/Twig2x/ExistsLoaderInterface.php deleted file mode 100644 index 544a831..0000000 --- a/system/templateEngines/Twig/Twig2x/ExistsLoaderInterface.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * @internal - */ -class Twig_ExpressionParser -{ - const OPERATOR_LEFT = 1; - const OPERATOR_RIGHT = 2; - - private $parser; - private $env; - private $unaryOperators; - private $binaryOperators; - - public function __construct(Twig_Parser $parser, Twig_Environment $env) - { - $this->parser = $parser; - $this->env = $env; - $this->unaryOperators = $env->getUnaryOperators(); - $this->binaryOperators = $env->getBinaryOperators(); - } - - public function parseExpression($precedence = 0) - { - $expr = $this->getPrimary(); - $token = $this->parser->getCurrentToken(); - while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) { - $op = $this->binaryOperators[$token->getValue()]; - $this->parser->getStream()->next(); - - if ('is not' === $token->getValue()) { - $expr = $this->parseNotTestExpression($expr); - } elseif ('is' === $token->getValue()) { - $expr = $this->parseTestExpression($expr); - } elseif (isset($op['callable'])) { - $expr = $op['callable']($this->parser, $expr); - } else { - $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); - $class = $op['class']; - $expr = new $class($expr, $expr1, $token->getLine()); - } - - $token = $this->parser->getCurrentToken(); - } - - if (0 === $precedence) { - return $this->parseConditionalExpression($expr); - } - - return $expr; - } - - private function getPrimary() - { - $token = $this->parser->getCurrentToken(); - - if ($this->isUnary($token)) { - $operator = $this->unaryOperators[$token->getValue()]; - $this->parser->getStream()->next(); - $expr = $this->parseExpression($operator['precedence']); - $class = $operator['class']; - - return $this->parsePostfixExpression(new $class($expr, $token->getLine())); - } elseif ($token->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '(')) { - $this->parser->getStream()->next(); - $expr = $this->parseExpression(); - $this->parser->getStream()->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ')', 'An opened parenthesis is not properly closed'); - - return $this->parsePostfixExpression($expr); - } - - return $this->parsePrimaryExpression(); - } - - private function parseConditionalExpression($expr) - { - while ($this->parser->getStream()->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, '?')) { - if (!$this->parser->getStream()->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ':')) { - $expr2 = $this->parseExpression(); - if ($this->parser->getStream()->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ':')) { - $expr3 = $this->parseExpression(); - } else { - $expr3 = new Twig_Node_Expression_Constant('', $this->parser->getCurrentToken()->getLine()); - } - } else { - $expr2 = $expr; - $expr3 = $this->parseExpression(); - } - - $expr = new Twig_Node_Expression_Conditional($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); - } - - return $expr; - } - - private function isUnary(Twig_Token $token) - { - return $token->test(/* Twig_Token::OPERATOR_TYPE */ 8) && isset($this->unaryOperators[$token->getValue()]); - } - - private function isBinary(Twig_Token $token) - { - return $token->test(/* Twig_Token::OPERATOR_TYPE */ 8) && isset($this->binaryOperators[$token->getValue()]); - } - - public function parsePrimaryExpression() - { - $token = $this->parser->getCurrentToken(); - switch ($token->getType()) { - case /* Twig_Token::NAME_TYPE */ 5: - $this->parser->getStream()->next(); - switch ($token->getValue()) { - case 'true': - case 'TRUE': - $node = new Twig_Node_Expression_Constant(true, $token->getLine()); - break; - - case 'false': - case 'FALSE': - $node = new Twig_Node_Expression_Constant(false, $token->getLine()); - break; - - case 'none': - case 'NONE': - case 'null': - case 'NULL': - $node = new Twig_Node_Expression_Constant(null, $token->getLine()); - break; - - default: - if ('(' === $this->parser->getCurrentToken()->getValue()) { - $node = $this->getFunctionNode($token->getValue(), $token->getLine()); - } else { - $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine()); - } - } - break; - - case /* Twig_Token::NUMBER_TYPE */ 6: - $this->parser->getStream()->next(); - $node = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - break; - - case /* Twig_Token::STRING_TYPE */ 7: - case /* Twig_Token::INTERPOLATION_START_TYPE */ 10: - $node = $this->parseStringExpression(); - break; - - case /* Twig_Token::OPERATOR_TYPE */ 8: - if (preg_match(Twig_Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { - // in this context, string operators are variable names - $this->parser->getStream()->next(); - $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine()); - break; - } elseif (isset($this->unaryOperators[$token->getValue()])) { - $class = $this->unaryOperators[$token->getValue()]['class']; - - $ref = new ReflectionClass($class); - $negClass = 'Twig_Node_Expression_Unary_Neg'; - $posClass = 'Twig_Node_Expression_Unary_Pos'; - if (!(in_array($ref->getName(), [$negClass, $posClass]) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { - throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); - } - - $this->parser->getStream()->next(); - $expr = $this->parsePrimaryExpression(); - - $node = new $class($expr, $token->getLine()); - break; - } - - // no break - default: - if ($token->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '[')) { - $node = $this->parseArrayExpression(); - } elseif ($token->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '{')) { - $node = $this->parseHashExpression(); - } elseif ($token->test(/* Twig_Token::OPERATOR_TYPE */ 8, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { - throw new Twig_Error_Syntax(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()); - } else { - throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); - } - } - - return $this->parsePostfixExpression($node); - } - - public function parseStringExpression() - { - $stream = $this->parser->getStream(); - - $nodes = []; - // a string cannot be followed by another string in a single expression - $nextCanBeString = true; - while (true) { - if ($nextCanBeString && $token = $stream->nextIf(/* Twig_Token::STRING_TYPE */ 7)) { - $nodes[] = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - $nextCanBeString = false; - } elseif ($stream->nextIf(/* Twig_Token::INTERPOLATION_START_TYPE */ 10)) { - $nodes[] = $this->parseExpression(); - $stream->expect(/* Twig_Token::INTERPOLATION_END_TYPE */ 11); - $nextCanBeString = true; - } else { - break; - } - } - - $expr = array_shift($nodes); - foreach ($nodes as $node) { - $expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getTemplateLine()); - } - - return $expr; - } - - public function parseArrayExpression() - { - $stream = $this->parser->getStream(); - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, '[', 'An array element was expected'); - - $node = new Twig_Node_Expression_Array([], $stream->getCurrent()->getLine()); - $first = true; - while (!$stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, ']')) { - if (!$first) { - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',', 'An array element must be followed by a comma'); - - // trailing ,? - if ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, ']')) { - break; - } - } - $first = false; - - $node->addElement($this->parseExpression()); - } - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ']', 'An opened array is not properly closed'); - - return $node; - } - - public function parseHashExpression() - { - $stream = $this->parser->getStream(); - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, '{', 'A hash element was expected'); - - $node = new Twig_Node_Expression_Array([], $stream->getCurrent()->getLine()); - $first = true; - while (!$stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '}')) { - if (!$first) { - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',', 'A hash value must be followed by a comma'); - - // trailing ,? - if ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '}')) { - break; - } - } - $first = false; - - // a hash key can be: - // - // * a number -- 12 - // * a string -- 'a' - // * a name, which is equivalent to a string -- a - // * an expression, which must be enclosed in parentheses -- (1 + 2) - if (($token = $stream->nextIf(/* Twig_Token::STRING_TYPE */ 7)) || ($token = $stream->nextIf(/* Twig_Token::NAME_TYPE */ 5)) || $token = $stream->nextIf(/* Twig_Token::NUMBER_TYPE */ 6)) { - $key = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - } elseif ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '(')) { - $key = $this->parseExpression(); - } else { - $current = $stream->getCurrent(); - - throw new Twig_Error_Syntax(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".', Twig_Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext()); - } - - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ':', 'A hash key must be followed by a colon (:)'); - $value = $this->parseExpression(); - - $node->addElement($value, $key); - } - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, '}', 'An opened hash is not properly closed'); - - return $node; - } - - public function parsePostfixExpression($node) - { - while (true) { - $token = $this->parser->getCurrentToken(); - if (/* Twig_Token::PUNCTUATION_TYPE */ 9 == $token->getType()) { - if ('.' == $token->getValue() || '[' == $token->getValue()) { - $node = $this->parseSubscriptExpression($node); - } elseif ('|' == $token->getValue()) { - $node = $this->parseFilterExpression($node); - } else { - break; - } - } else { - break; - } - } - - return $node; - } - - public function getFunctionNode($name, $line) - { - switch ($name) { - case 'parent': - $this->parseArguments(); - if (!count($this->parser->getBlockStack())) { - throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); - } - - if (!$this->parser->getParent() && !$this->parser->hasTraits()) { - throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); - } - - return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); - case 'block': - $args = $this->parseArguments(); - if (count($args) < 1) { - throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); - } - - return new Twig_Node_Expression_BlockReference($args->getNode(0), count($args) > 1 ? $args->getNode(1) : null, $line); - case 'attribute': - $args = $this->parseArguments(); - if (count($args) < 2) { - throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); - } - - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line); - default: - if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { - $arguments = new Twig_Node_Expression_Array([], $line); - foreach ($this->parseArguments() as $n) { - $arguments->addElement($n); - } - - $node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line); - $node->setAttribute('safe', true); - - return $node; - } - - $args = $this->parseArguments(true); - $class = $this->getFunctionNodeClass($name, $line); - - return new $class($name, $args, $line); - } - } - - public function parseSubscriptExpression($node) - { - $stream = $this->parser->getStream(); - $token = $stream->next(); - $lineno = $token->getLine(); - $arguments = new Twig_Node_Expression_Array([], $lineno); - $type = Twig_Template::ANY_CALL; - if ('.' == $token->getValue()) { - $token = $stream->next(); - if ( - /* Twig_Token::NAME_TYPE */ 5 == $token->getType() - || - /* Twig_Token::NUMBER_TYPE */ 6 == $token->getType() - || - (/* Twig_Token::OPERATOR_TYPE */ 8 == $token->getType() && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) - ) { - $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno); - - if ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '(')) { - $type = Twig_Template::METHOD_CALL; - foreach ($this->parseArguments() as $n) { - $arguments->addElement($n); - } - } - } else { - throw new Twig_Error_Syntax('Expected name or number.', $lineno, $stream->getSourceContext()); - } - - if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { - if (!$arg instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); - } - - $name = $arg->getAttribute('value'); - - $node = new Twig_Node_Expression_MethodCall($node, 'macro_'.$name, $arguments, $lineno); - $node->setAttribute('safe', true); - - return $node; - } - } else { - $type = Twig_Template::ARRAY_CALL; - - // slice? - $slice = false; - if ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, ':')) { - $slice = true; - $arg = new Twig_Node_Expression_Constant(0, $token->getLine()); - } else { - $arg = $this->parseExpression(); - } - - if ($stream->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ':')) { - $slice = true; - } - - if ($slice) { - if ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, ']')) { - $length = new Twig_Node_Expression_Constant(null, $token->getLine()); - } else { - $length = $this->parseExpression(); - } - - $class = $this->getFilterNodeClass('slice', $token->getLine()); - $arguments = new Twig_Node([$arg, $length]); - $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine()); - - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ']'); - - return $filter; - } - - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ']'); - } - - return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno); - } - - public function parseFilterExpression($node) - { - $this->parser->getStream()->next(); - - return $this->parseFilterExpressionRaw($node); - } - - public function parseFilterExpressionRaw($node, $tag = null) - { - while (true) { - $token = $this->parser->getStream()->expect(/* Twig_Token::NAME_TYPE */ 5); - - $name = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - if (!$this->parser->getStream()->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '(')) { - $arguments = new Twig_Node(); - } else { - $arguments = $this->parseArguments(true); - } - - $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine()); - - $node = new $class($node, $name, $arguments, $token->getLine(), $tag); - - if (!$this->parser->getStream()->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '|')) { - break; - } - - $this->parser->getStream()->next(); - } - - return $node; - } - - /** - * Parses arguments. - * - * @param bool $namedArguments Whether to allow named arguments or not - * @param bool $definition Whether we are parsing arguments for a function definition - * - * @return Twig_Node - * - * @throws Twig_Error_Syntax - */ - public function parseArguments($namedArguments = false, $definition = false) - { - $args = []; - $stream = $this->parser->getStream(); - - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, '(', 'A list of arguments must begin with an opening parenthesis'); - while (!$stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, ')')) { - if (!empty($args)) { - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',', 'Arguments must be separated by a comma'); - } - - if ($definition) { - $token = $stream->expect(/* Twig_Token::NAME_TYPE */ 5, null, 'An argument must be a name'); - $value = new Twig_Node_Expression_Name($token->getValue(), $this->parser->getCurrentToken()->getLine()); - } else { - $value = $this->parseExpression(); - } - - $name = null; - if ($namedArguments && $token = $stream->nextIf(/* Twig_Token::OPERATOR_TYPE */ 8, '=')) { - if (!$value instanceof Twig_Node_Expression_Name) { - throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', get_class($value)), $token->getLine(), $stream->getSourceContext()); - } - $name = $value->getAttribute('name'); - - if ($definition) { - $value = $this->parsePrimaryExpression(); - - if (!$this->checkConstantExpression($value)) { - throw new Twig_Error_Syntax(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); - } - } else { - $value = $this->parseExpression(); - } - } - - if ($definition) { - if (null === $name) { - $name = $value->getAttribute('name'); - $value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine()); - } - $args[$name] = $value; - } else { - if (null === $name) { - $args[] = $value; - } else { - $args[$name] = $value; - } - } - } - $stream->expect(/* Twig_Token::PUNCTUATION_TYPE */ 9, ')', 'A list of arguments must be closed by a parenthesis'); - - return new Twig_Node($args); - } - - public function parseAssignmentExpression() - { - $stream = $this->parser->getStream(); - $targets = []; - while (true) { - $token = $stream->expect(/* Twig_Token::NAME_TYPE */ 5, null, 'Only variables can be assigned to'); - $value = $token->getValue(); - if (in_array(strtolower($value), ['true', 'false', 'none', 'null'])) { - throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); - } - $targets[] = new Twig_Node_Expression_AssignName($value, $token->getLine()); - - if (!$stream->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',')) { - break; - } - } - - return new Twig_Node($targets); - } - - public function parseMultitargetExpression() - { - $targets = []; - while (true) { - $targets[] = $this->parseExpression(); - if (!$this->parser->getStream()->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',')) { - break; - } - } - - return new Twig_Node($targets); - } - - private function parseNotTestExpression(Twig_Node $node) - { - return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); - } - - private function parseTestExpression(Twig_Node $node) - { - $stream = $this->parser->getStream(); - list($name, $test) = $this->getTest($node->getTemplateLine()); - - $class = $this->getTestNodeClass($test); - $arguments = null; - if ($stream->test(/* Twig_Token::PUNCTUATION_TYPE */ 9, '(')) { - $arguments = $this->parser->getExpressionParser()->parseArguments(true); - } - - return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine()); - } - - private function getTest($line) - { - $stream = $this->parser->getStream(); - $name = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - - if ($test = $this->env->getTest($name)) { - return [$name, $test]; - } - - if ($stream->test(/* Twig_Token::NAME_TYPE */ 5)) { - // try 2-words tests - $name = $name.' '.$this->parser->getCurrentToken()->getValue(); - - if ($test = $this->env->getTest($name)) { - $stream->next(); - - return [$name, $test]; - } - } - - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); - $e->addSuggestions($name, array_keys($this->env->getTests())); - - throw $e; - } - - private function getTestNodeClass($test) - { - if ($test->isDeprecated()) { - $stream = $this->parser->getStream(); - $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); - - if (!is_bool($test->getDeprecatedVersion())) { - $message .= sprintf(' since version %s', $test->getDeprecatedVersion()); - } - if ($test->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $test->getAlternative()); - } - $src = $stream->getSourceContext(); - $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $stream->getCurrent()->getLine()); - - @trigger_error($message, E_USER_DEPRECATED); - } - - return $test->getNodeClass(); - } - - private function getFunctionNodeClass($name, $line) - { - if (false === $function = $this->env->getFunction($name)) { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); - $e->addSuggestions($name, array_keys($this->env->getFunctions())); - - throw $e; - } - - if ($function->isDeprecated()) { - $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); - if (!is_bool($function->getDeprecatedVersion())) { - $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); - } - if ($function->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $function->getAlternative()); - } - $src = $this->parser->getStream()->getSourceContext(); - $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); - - @trigger_error($message, E_USER_DEPRECATED); - } - - return $function->getNodeClass(); - } - - private function getFilterNodeClass($name, $line) - { - if (false === $filter = $this->env->getFilter($name)) { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); - $e->addSuggestions($name, array_keys($this->env->getFilters())); - - throw $e; - } - - if ($filter->isDeprecated()) { - $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); - if (!is_bool($filter->getDeprecatedVersion())) { - $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); - } - if ($filter->getAlternative()) { - $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); - } - $src = $this->parser->getStream()->getSourceContext(); - $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); - - @trigger_error($message, E_USER_DEPRECATED); - } - - return $filter->getNodeClass(); - } - - // checks that the node only contains "constant" elements - private function checkConstantExpression(Twig_Node $node) - { - if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array - || $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos - )) { - return false; - } - - foreach ($node as $n) { - if (!$this->checkConstantExpression($n)) { - return false; - } - } - - return true; - } -} - -class_alias('Twig_ExpressionParser', 'Twig\ExpressionParser', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension.php b/system/templateEngines/Twig/Twig2x/Extension.php deleted file mode 100644 index 5d1b505..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension.php +++ /dev/null @@ -1,46 +0,0 @@ -escapers[$strategy] = $callable; - } - - /** - * Gets all defined escapers. - * - * @return callable[] An array of escapers - */ - public function getEscapers() - { - return $this->escapers; - } - - /** - * Sets the default format to be used by the date filter. - * - * @param string $format The default date format string - * @param string $dateIntervalFormat The default date interval format string - */ - public function setDateFormat($format = null, $dateIntervalFormat = null) - { - if (null !== $format) { - $this->dateFormats[0] = $format; - } - - if (null !== $dateIntervalFormat) { - $this->dateFormats[1] = $dateIntervalFormat; - } - } - - /** - * Gets the default format to be used by the date filter. - * - * @return array The default date format string and the default date interval format string - */ - public function getDateFormat() - { - return $this->dateFormats; - } - - /** - * Sets the default timezone to be used by the date filter. - * - * @param DateTimeZone|string $timezone The default timezone string or a DateTimeZone object - */ - public function setTimezone($timezone) - { - $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); - } - - /** - * Gets the default timezone to be used by the date filter. - * - * @return DateTimeZone The default timezone currently in use - */ - public function getTimezone() - { - if (null === $this->timezone) { - $this->timezone = new DateTimeZone(date_default_timezone_get()); - } - - return $this->timezone; - } - - /** - * Sets the default format to be used by the number_format filter. - * - * @param int $decimal the number of decimal places to use - * @param string $decimalPoint the character(s) to use for the decimal point - * @param string $thousandSep the character(s) to use for the thousands separator - */ - public function setNumberFormat($decimal, $decimalPoint, $thousandSep) - { - $this->numberFormat = [$decimal, $decimalPoint, $thousandSep]; - } - - /** - * Get the default format used by the number_format filter. - * - * @return array The arguments for number_format() - */ - public function getNumberFormat() - { - return $this->numberFormat; - } - - public function getTokenParsers() - { - return [ - new Twig_TokenParser_For(), - new Twig_TokenParser_If(), - new Twig_TokenParser_Extends(), - new Twig_TokenParser_Include(), - new Twig_TokenParser_Block(), - new Twig_TokenParser_Use(), - new Twig_TokenParser_Filter(), - new Twig_TokenParser_Macro(), - new Twig_TokenParser_Import(), - new Twig_TokenParser_From(), - new Twig_TokenParser_Set(), - new Twig_TokenParser_Spaceless(), - new Twig_TokenParser_Flush(), - new Twig_TokenParser_Do(), - new Twig_TokenParser_Embed(), - new Twig_TokenParser_With(), - new Twig_TokenParser_Deprecated(), - ]; - } - - public function getFilters() - { - return [ - // formatting filters - new Twig_Filter('date', 'twig_date_format_filter', ['needs_environment' => true]), - new Twig_Filter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), - new Twig_Filter('format', 'sprintf'), - new Twig_Filter('replace', 'twig_replace_filter'), - new Twig_Filter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), - new Twig_Filter('abs', 'abs'), - new Twig_Filter('round', 'twig_round'), - - // encoding - new Twig_Filter('url_encode', 'twig_urlencode_filter'), - new Twig_Filter('json_encode', 'json_encode'), - new Twig_Filter('convert_encoding', 'twig_convert_encoding'), - - // string filters - new Twig_Filter('title', 'twig_title_string_filter', ['needs_environment' => true]), - new Twig_Filter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), - new Twig_Filter('upper', 'twig_upper_filter', ['needs_environment' => true]), - new Twig_Filter('lower', 'twig_lower_filter', ['needs_environment' => true]), - new Twig_Filter('striptags', 'strip_tags'), - new Twig_Filter('trim', 'twig_trim_filter'), - new Twig_Filter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), - - // array helpers - new Twig_Filter('join', 'twig_join_filter'), - new Twig_Filter('split', 'twig_split_filter', ['needs_environment' => true]), - new Twig_Filter('sort', 'twig_sort_filter'), - new Twig_Filter('merge', 'twig_array_merge'), - new Twig_Filter('batch', 'twig_array_batch'), - - // string/array filters - new Twig_Filter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), - new Twig_Filter('length', 'twig_length_filter', ['needs_environment' => true]), - new Twig_Filter('slice', 'twig_slice', ['needs_environment' => true]), - new Twig_Filter('first', 'twig_first', ['needs_environment' => true]), - new Twig_Filter('last', 'twig_last', ['needs_environment' => true]), - - // iteration and runtime - new Twig_Filter('default', '_twig_default_filter', ['node_class' => 'Twig_Node_Expression_Filter_Default']), - new Twig_Filter('keys', 'twig_get_array_keys_filter'), - - // escaping - new Twig_Filter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), - new Twig_Filter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), - ]; - } - - public function getFunctions() - { - return [ - new Twig_Function('max', 'max'), - new Twig_Function('min', 'min'), - new Twig_Function('range', 'range'), - new Twig_Function('constant', 'twig_constant'), - new Twig_Function('cycle', 'twig_cycle'), - new Twig_Function('random', 'twig_random', ['needs_environment' => true]), - new Twig_Function('date', 'twig_date_converter', ['needs_environment' => true]), - new Twig_Function('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), - new Twig_Function('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), - ]; - } - - public function getTests() - { - return [ - new Twig_Test('even', null, ['node_class' => 'Twig_Node_Expression_Test_Even']), - new Twig_Test('odd', null, ['node_class' => 'Twig_Node_Expression_Test_Odd']), - new Twig_Test('defined', null, ['node_class' => 'Twig_Node_Expression_Test_Defined']), - new Twig_Test('same as', null, ['node_class' => 'Twig_Node_Expression_Test_Sameas']), - new Twig_Test('none', null, ['node_class' => 'Twig_Node_Expression_Test_Null']), - new Twig_Test('null', null, ['node_class' => 'Twig_Node_Expression_Test_Null']), - new Twig_Test('divisible by', null, ['node_class' => 'Twig_Node_Expression_Test_Divisibleby']), - new Twig_Test('constant', null, ['node_class' => 'Twig_Node_Expression_Test_Constant']), - new Twig_Test('empty', 'twig_test_empty'), - new Twig_Test('iterable', 'twig_test_iterable'), - ]; - } - - public function getOperators() - { - return [ - [ - 'not' => ['precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'], - '-' => ['precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'], - '+' => ['precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'], - ], - [ - 'or' => ['precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'and' => ['precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-or' => ['precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-xor' => ['precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'b-and' => ['precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '==' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '!=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '<' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '>' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '>=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '<=' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'not in' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'in' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'matches' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Matches', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'starts with' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_StartsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'ends with' => ['precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_EndsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '..' => ['precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '+' => ['precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '-' => ['precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '~' => ['precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '*' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mul', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '/' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Div', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '//' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_FloorDiv', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '%' => ['precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'is' => ['precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - 'is not' => ['precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT], - '**' => ['precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT], - '??' => ['precedence' => 300, 'class' => 'Twig_Node_Expression_NullCoalesce', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT], - ], - ]; - } -} - -/** - * Cycles over a value. - * - * @param ArrayAccess|array $values - * @param int $position The cycle position - * - * @return string The next value in the cycle - */ -function twig_cycle($values, $position) -{ - if (!is_array($values) && !$values instanceof ArrayAccess) { - return $values; - } - - return $values[$position % count($values)]; -} - -/** - * Returns a random value depending on the supplied parameter type: - * - a random item from a Traversable or array - * - a random character from a string - * - a random integer between 0 and the integer parameter. - * - * @param Twig_Environment $env - * @param Traversable|array|int|float|string $values The values to pick a random item from - * - * @throws Twig_Error_Runtime when $values is an empty array (does not apply to an empty string which is returned as is) - * - * @return mixed A random value from the given sequence - */ -function twig_random(Twig_Environment $env, $values = null) -{ - if (null === $values) { - return mt_rand(); - } - - if (is_int($values) || is_float($values)) { - return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values); - } - - if ($values instanceof Traversable) { - $values = iterator_to_array($values); - } elseif (is_string($values)) { - if ('' === $values) { - return ''; - } - - $charset = $env->getCharset(); - - if ('UTF-8' !== $charset) { - $values = iconv($charset, 'UTF-8', $values); - } - - // unicode version of str_split() - // split at all positions, but not after the start and not before the end - $values = preg_split('/(? $value) { - $values[$i] = iconv('UTF-8', $charset, $value); - } - } - } - - if (!is_array($values)) { - return $values; - } - - if (0 === count($values)) { - throw new Twig_Error_Runtime('The random function cannot pick from an empty array.'); - } - - return $values[array_rand($values, 1)]; -} - -/** - * Converts a date to the given format. - * - *
    - *   {{ post.published_at|date("m/d/Y") }}
    - * 
    - * - * @param Twig_Environment $env - * @param DateTimeInterface|DateInterval|string $date A date - * @param string|null $format The target format, null to use the default - * @param DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged - * - * @return string The formatted date - */ -function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) -{ - if (null === $format) { - $formats = $env->getExtension('Twig_Extension_Core')->getDateFormat(); - $format = $date instanceof DateInterval ? $formats[1] : $formats[0]; - } - - if ($date instanceof DateInterval) { - return $date->format($format); - } - - return twig_date_converter($env, $date, $timezone)->format($format); -} - -/** - * Returns a new date object modified. - * - *
    - *   {{ post.published_at|date_modify("-1day")|date("m/d/Y") }}
    - * 
    - * - * @param Twig_Environment $env - * @param DateTimeInterface|string $date A date - * @param string $modifier A modifier string - * - * @return DateTimeInterface A new date object - */ -function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) -{ - $date = twig_date_converter($env, $date, false); - - return $date->modify($modifier); -} - -/** - * Converts an input to a DateTime instance. - * - *
    - *    {% if date(user.created_at) < date('+2days') %}
    - *      {# do something #}
    - *    {% endif %}
    - * 
    - * - * @param Twig_Environment $env - * @param DateTimeInterface|string|null $date A date or null to use the current time - * @param DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged - * - * @return DateTime A DateTime instance - */ -function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) -{ - // determine the timezone - if (false !== $timezone) { - if (null === $timezone) { - $timezone = $env->getExtension('Twig_Extension_Core')->getTimezone(); - } elseif (!$timezone instanceof DateTimeZone) { - $timezone = new DateTimeZone($timezone); - } - } - - // immutable dates - if ($date instanceof DateTimeImmutable) { - return false !== $timezone ? $date->setTimezone($timezone) : $date; - } - - if ($date instanceof DateTimeInterface) { - $date = clone $date; - if (false !== $timezone) { - $date->setTimezone($timezone); - } - - return $date; - } - - if (null === $date || 'now' === $date) { - return new DateTime($date, false !== $timezone ? $timezone : $env->getExtension('Twig_Extension_Core')->getTimezone()); - } - - $asString = (string) $date; - if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { - $date = new DateTime('@'.$date); - } else { - $date = new DateTime($date, $env->getExtension('Twig_Extension_Core')->getTimezone()); - } - - if (false !== $timezone) { - $date->setTimezone($timezone); - } - - return $date; -} - -/** - * Replaces strings within a string. - * - * @param string $str String to replace in - * @param array|Traversable $from Replace values - * - * @return string - */ -function twig_replace_filter($str, $from) -{ - if ($from instanceof Traversable) { - $from = iterator_to_array($from); - } elseif (!is_array($from)) { - throw new Twig_Error_Runtime(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', is_object($from) ? get_class($from) : gettype($from))); - } - - return strtr($str, $from); -} - -/** - * Rounds a number. - * - * @param int|float $value The value to round - * @param int|float $precision The rounding precision - * @param string $method The method to use for rounding - * - * @return int|float The rounded number - */ -function twig_round($value, $precision = 0, $method = 'common') -{ - if ('common' == $method) { - return round($value, $precision); - } - - if ('ceil' != $method && 'floor' != $method) { - throw new Twig_Error_Runtime('The round filter only supports the "common", "ceil", and "floor" methods.'); - } - - return $method($value * pow(10, $precision)) / pow(10, $precision); -} - -/** - * Number format filter. - * - * All of the formatting options can be left null, in that case the defaults will - * be used. Supplying any of the parameters will override the defaults set in the - * environment object. - * - * @param Twig_Environment $env - * @param mixed $number A float/int/string of the number to format - * @param int $decimal the number of decimal points to display - * @param string $decimalPoint the character(s) to use for the decimal point - * @param string $thousandSep the character(s) to use for the thousands separator - * - * @return string The formatted number - */ -function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) -{ - $defaults = $env->getExtension('Twig_Extension_Core')->getNumberFormat(); - if (null === $decimal) { - $decimal = $defaults[0]; - } - - if (null === $decimalPoint) { - $decimalPoint = $defaults[1]; - } - - if (null === $thousandSep) { - $thousandSep = $defaults[2]; - } - - return number_format((float) $number, $decimal, $decimalPoint, $thousandSep); -} - -/** - * URL encodes (RFC 3986) a string as a path segment or an array as a query string. - * - * @param string|array $url A URL or an array of query parameters - * - * @return string The URL encoded value - */ -function twig_urlencode_filter($url) -{ - if (is_array($url)) { - return http_build_query($url, '', '&', PHP_QUERY_RFC3986); - } - - return rawurlencode($url); -} - -/** - * Merges an array with another one. - * - *
    - *  {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}
    - *
    - *  {% set items = items|merge({ 'peugeot': 'car' }) %}
    - *
    - *  {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #}
    - * 
    - * - * @param array|Traversable $arr1 An array - * @param array|Traversable $arr2 An array - * - * @return array The merged array - */ -function twig_array_merge($arr1, $arr2) -{ - if ($arr1 instanceof Traversable) { - $arr1 = iterator_to_array($arr1); - } elseif (!is_array($arr1)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', gettype($arr1))); - } - - if ($arr2 instanceof Traversable) { - $arr2 = iterator_to_array($arr2); - } elseif (!is_array($arr2)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', gettype($arr2))); - } - - return array_merge($arr1, $arr2); -} - -/** - * Slices a variable. - * - * @param Twig_Environment $env - * @param mixed $item A variable - * @param int $start Start of the slice - * @param int $length Size of the slice - * @param bool $preserveKeys Whether to preserve key or not (when the input is an array) - * - * @return mixed The sliced variable - */ -function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) -{ - if ($item instanceof Traversable) { - while ($item instanceof IteratorAggregate) { - $item = $item->getIterator(); - } - - if ($start >= 0 && $length >= 0 && $item instanceof Iterator) { - try { - return iterator_to_array(new LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys); - } catch (OutOfBoundsException $exception) { - return []; - } - } - - $item = iterator_to_array($item, $preserveKeys); - } - - if (is_array($item)) { - return array_slice($item, $start, $length, $preserveKeys); - } - - $item = (string) $item; - - return (string) mb_substr($item, $start, $length, $env->getCharset()); -} - -/** - * Returns the first element of the item. - * - * @param Twig_Environment $env - * @param mixed $item A variable - * - * @return mixed The first element of the item - */ -function twig_first(Twig_Environment $env, $item) -{ - $elements = twig_slice($env, $item, 0, 1, false); - - return is_string($elements) ? $elements : current($elements); -} - -/** - * Returns the last element of the item. - * - * @param Twig_Environment $env - * @param mixed $item A variable - * - * @return mixed The last element of the item - */ -function twig_last(Twig_Environment $env, $item) -{ - $elements = twig_slice($env, $item, -1, 1, false); - - return is_string($elements) ? $elements : current($elements); -} - -/** - * Joins the values to a string. - * - * The separators between elements are empty strings per default, you can define them with the optional parameters. - * - *
    - *  {{ [1, 2, 3]|join(', ', ' and ') }}
    - *  {# returns 1, 2 and 3 #}
    - *
    - *  {{ [1, 2, 3]|join('|') }}
    - *  {# returns 1|2|3 #}
    - *
    - *  {{ [1, 2, 3]|join }}
    - *  {# returns 123 #}
    - * 
    - * - * @param array $value An array - * @param string $glue The separator - * @param string|null $and The separator for the last pair - * - * @return string The concatenated string - */ -function twig_join_filter($value, $glue = '', $and = null) -{ - if ($value instanceof Traversable) { - $value = iterator_to_array($value, false); - } else { - $value = (array) $value; - } - - if (0 === count($value)) { - return ''; - } - - if (null === $and || $and === $glue) { - return implode($glue, $value); - } - - $v = array_values($value); - if (1 === count($v)) { - return $v[0]; - } - - return implode($glue, array_slice($value, 0, -1)).$and.$v[count($v) - 1]; -} - -/** - * Splits the string into an array. - * - *
    - *  {{ "one,two,three"|split(',') }}
    - *  {# returns [one, two, three] #}
    - *
    - *  {{ "one,two,three,four,five"|split(',', 3) }}
    - *  {# returns [one, two, "three,four,five"] #}
    - *
    - *  {{ "123"|split('') }}
    - *  {# returns [1, 2, 3] #}
    - *
    - *  {{ "aabbcc"|split('', 2) }}
    - *  {# returns [aa, bb, cc] #}
    - * 
    - * - * @param Twig_Environment $env - * @param string $value A string - * @param string $delimiter The delimiter - * @param int $limit The limit - * - * @return array The split string as an array - */ -function twig_split_filter(Twig_Environment $env, $value, $delimiter, $limit = null) -{ - if (!empty($delimiter)) { - return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); - } - - if ($limit <= 1) { - return preg_split('/(?getCharset()); - if ($length < $limit) { - return [$value]; - } - - $r = []; - for ($i = 0; $i < $length; $i += $limit) { - $r[] = mb_substr($value, $i, $limit, $env->getCharset()); - } - - return $r; -} - -// The '_default' filter is used internally to avoid using the ternary operator -// which costs a lot for big contexts (before PHP 5.4). So, on average, -// a function call is cheaper. -/** - * @internal - */ -function _twig_default_filter($value, $default = '') -{ - if (twig_test_empty($value)) { - return $default; - } - - return $value; -} - -/** - * Returns the keys for the given array. - * - * It is useful when you want to iterate over the keys of an array: - * - *
    - *  {% for key in array|keys %}
    - *      {# ... #}
    - *  {% endfor %}
    - * 
    - * - * @param array $array An array - * - * @return array The keys - */ -function twig_get_array_keys_filter($array) -{ - if ($array instanceof Traversable) { - while ($array instanceof IteratorAggregate) { - $array = $array->getIterator(); - } - - if ($array instanceof Iterator) { - $keys = []; - $array->rewind(); - while ($array->valid()) { - $keys[] = $array->key(); - $array->next(); - } - - return $keys; - } - - $keys = []; - foreach ($array as $key => $item) { - $keys[] = $key; - } - - return $keys; - } - - if (!is_array($array)) { - return []; - } - - return array_keys($array); -} - -/** - * Reverses a variable. - * - * @param Twig_Environment $env - * @param array|Traversable|string $item An array, a Traversable instance, or a string - * @param bool $preserveKeys Whether to preserve key or not - * - * @return mixed The reversed input - */ -function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false) -{ - if ($item instanceof Traversable) { - return array_reverse(iterator_to_array($item), $preserveKeys); - } - - if (is_array($item)) { - return array_reverse($item, $preserveKeys); - } - - $string = (string) $item; - - $charset = $env->getCharset(); - - if ('UTF-8' !== $charset) { - $item = iconv($charset, 'UTF-8', $string); - } - - preg_match_all('/./us', $item, $matches); - - $string = implode('', array_reverse($matches[0])); - - if ('UTF-8' !== $charset) { - $string = iconv('UTF-8', $charset, $string); - } - - return $string; -} - -/** - * Sorts an array. - * - * @param array|Traversable $array - * - * @return array - */ -function twig_sort_filter($array) -{ - if ($array instanceof Traversable) { - $array = iterator_to_array($array); - } elseif (!is_array($array)) { - throw new Twig_Error_Runtime(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', gettype($array))); - } - - asort($array); - - return $array; -} - -/** - * @internal - */ -function twig_in_filter($value, $compare) -{ - if (is_array($compare)) { - return in_array($value, $compare, is_object($value) || is_resource($value)); - } elseif (is_string($compare) && (is_string($value) || is_int($value) || is_float($value))) { - return '' === $value || false !== strpos($compare, (string) $value); - } elseif ($compare instanceof Traversable) { - if (is_object($value) || is_resource($value)) { - foreach ($compare as $item) { - if ($item === $value) { - return true; - } - } - } else { - foreach ($compare as $item) { - if ($item == $value) { - return true; - } - } - } - - return false; - } - - return false; -} - -/** - * Returns a trimmed string. - * - * @return string - * - * @throws Twig_Error_Runtime When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') - */ -function twig_trim_filter($string, $characterMask = null, $side = 'both') -{ - if (null === $characterMask) { - $characterMask = " \t\n\r\0\x0B"; - } - - switch ($side) { - case 'both': - return trim($string, $characterMask); - case 'left': - return ltrim($string, $characterMask); - case 'right': - return rtrim($string, $characterMask); - default: - throw new Twig_Error_Runtime('Trimming side must be "left", "right" or "both".'); - } -} - -/** - * Escapes a string. - * - * @param Twig_Environment $env - * @param mixed $string The value to be escaped - * @param string $strategy The escaping strategy - * @param string $charset The charset - * @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false) - * - * @return string - */ -function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) -{ - if ($autoescape && $string instanceof Twig_Markup) { - return $string; - } - - if (!is_string($string)) { - if (is_object($string) && method_exists($string, '__toString')) { - $string = (string) $string; - } elseif (in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { - return $string; - } - } - - if ('' === $string) { - return ''; - } - - if (null === $charset) { - $charset = $env->getCharset(); - } - - switch ($strategy) { - case 'html': - // see https://secure.php.net/htmlspecialchars - - // Using a static variable to avoid initializing the array - // each time the function is called. Moving the declaration on the - // top of the function slow downs other escaping strategies. - static $htmlspecialcharsCharsets = [ - 'ISO-8859-1' => true, 'ISO8859-1' => true, - 'ISO-8859-15' => true, 'ISO8859-15' => true, - 'utf-8' => true, 'UTF-8' => true, - 'CP866' => true, 'IBM866' => true, '866' => true, - 'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true, - '1251' => true, - 'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true, - 'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true, - 'BIG5' => true, '950' => true, - 'GB2312' => true, '936' => true, - 'BIG5-HKSCS' => true, - 'SHIFT_JIS' => true, 'SJIS' => true, '932' => true, - 'EUC-JP' => true, 'EUCJP' => true, - 'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true, - ]; - - if (isset($htmlspecialcharsCharsets[$charset])) { - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); - } - - if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { - // cache the lowercase variant for future iterations - $htmlspecialcharsCharsets[$charset] = true; - - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); - } - - $string = iconv($charset, 'UTF-8', $string); - $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); - - return iconv('UTF-8', $charset, $string); - - case 'js': - // escape all non-alphanumeric characters - // into their \x or \uHHHH representations - if ('UTF-8' !== $charset) { - $string = iconv($charset, 'UTF-8', $string); - } - - if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); - } - - $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', function ($matches) { - $char = $matches[0]; - - /* - * A few characters have short escape sequences in JSON and JavaScript. - * Escape sequences supported only by JavaScript, not JSON, are ommitted. - * \" is also supported but omitted, because the resulting string is not HTML safe. - */ - static $shortMap = [ - '\\' => '\\\\', - '/' => '\\/', - "\x08" => '\b', - "\x0C" => '\f', - "\x0A" => '\n', - "\x0D" => '\r', - "\x09" => '\t', - ]; - - if (isset($shortMap[$char])) { - return $shortMap[$char]; - } - - // \uHHHH - $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); - $char = strtoupper(bin2hex($char)); - - if (4 >= strlen($char)) { - return sprintf('\u%04s', $char); - } - - return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4)); - }, $string); - - if ('UTF-8' !== $charset) { - $string = iconv('UTF-8', $charset, $string); - } - - return $string; - - case 'css': - if ('UTF-8' !== $charset) { - $string = iconv($charset, 'UTF-8', $string); - } - - if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); - } - - $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', function ($matches) { - $char = $matches[0]; - - return sprintf('\\%X ', 1 === strlen($char) ? ord($char) : mb_ord($char, 'UTF-8')); - }, $string); - - if ('UTF-8' !== $charset) { - $string = iconv('UTF-8', $charset, $string); - } - - return $string; - - case 'html_attr': - if ('UTF-8' !== $charset) { - $string = iconv($charset, 'UTF-8', $string); - } - - if (!preg_match('//u', $string)) { - throw new Twig_Error_Runtime('The string to escape is not a valid UTF-8 string.'); - } - - $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', function ($matches) { - /** - * This function is adapted from code coming from Zend Framework. - * - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com) - * @license https://framework.zend.com/license/new-bsd New BSD License - */ - $chr = $matches[0]; - $ord = ord($chr); - - /* - * The following replaces characters undefined in HTML with the - * hex entity for the Unicode replacement character. - */ - if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) { - return '�'; - } - - /* - * Check if the current character to escape has a name entity we should - * replace it with while grabbing the hex value of the character. - */ - if (1 === strlen($chr)) { - /* - * While HTML supports far more named entities, the lowest common denominator - * has become HTML5's XML Serialisation which is restricted to the those named - * entities that XML supports. Using HTML entities would result in this error: - * XML Parsing Error: undefined entity - */ - static $entityMap = [ - 34 => '"', /* quotation mark */ - 38 => '&', /* ampersand */ - 60 => '<', /* less-than sign */ - 62 => '>', /* greater-than sign */ - ]; - - if (isset($entityMap[$ord])) { - return $entityMap[$ord]; - } - - return sprintf('&#x%02X;', $ord); - } - - /* - * Per OWASP recommendations, we'll use hex entities for any other - * characters where a named entity does not exist. - */ - return sprintf('&#x%04X;', mb_ord($chr, 'UTF-8')); - }, $string); - - if ('UTF-8' !== $charset) { - $string = iconv('UTF-8', $charset, $string); - } - - return $string; - - case 'url': - return rawurlencode($string); - - default: - static $escapers; - - if (null === $escapers) { - $escapers = $env->getExtension('Twig_Extension_Core')->getEscapers(); - } - - if (isset($escapers[$strategy])) { - return $escapers[$strategy]($env, $string, $charset); - } - - $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); - - throw new Twig_Error_Runtime(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); - } -} - -/** - * @internal - */ -function twig_escape_filter_is_safe(Twig_Node $filterArgs) -{ - foreach ($filterArgs as $arg) { - if ($arg instanceof Twig_Node_Expression_Constant) { - return [$arg->getAttribute('value')]; - } - - return []; - } - - return ['html']; -} - -function twig_convert_encoding($string, $to, $from) -{ - return iconv($from, $to, $string); -} - -/** - * Returns the length of a variable. - * - * @param Twig_Environment $env A Twig_Environment instance - * @param mixed $thing A variable - * - * @return int The length of the value - */ -function twig_length_filter(Twig_Environment $env, $thing) -{ - if (null === $thing) { - return 0; - } - - if (is_scalar($thing)) { - return mb_strlen($thing, $env->getCharset()); - } - - if ($thing instanceof \SimpleXMLElement) { - return count($thing); - } - - if (method_exists($thing, '__toString') && !$thing instanceof \Countable) { - return mb_strlen((string) $thing, $env->getCharset()); - } - - if ($thing instanceof \Countable || is_array($thing)) { - return count($thing); - } - - if ($thing instanceof \IteratorAggregate) { - return iterator_count($thing); - } - - return 1; -} - -/** - * Converts a string to uppercase. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The uppercased string - */ -function twig_upper_filter(Twig_Environment $env, $string) -{ - return mb_strtoupper($string, $env->getCharset()); -} - -/** - * Converts a string to lowercase. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The lowercased string - */ -function twig_lower_filter(Twig_Environment $env, $string) -{ - return mb_strtolower($string, $env->getCharset()); -} - -/** - * Returns a titlecased string. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The titlecased string - */ -function twig_title_string_filter(Twig_Environment $env, $string) -{ - if (null !== $charset = $env->getCharset()) { - return mb_convert_case($string, MB_CASE_TITLE, $charset); - } - - return ucwords(strtolower($string)); -} - -/** - * Returns a capitalized string. - * - * @param Twig_Environment $env - * @param string $string A string - * - * @return string The capitalized string - */ -function twig_capitalize_string_filter(Twig_Environment $env, $string) -{ - $charset = $env->getCharset(); - - return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, null, $charset), $charset); -} - -/** - * @internal - */ -function twig_ensure_traversable($seq) -{ - if ($seq instanceof Traversable || is_array($seq)) { - return $seq; - } - - return []; -} - -/** - * Checks if a variable is empty. - * - *
    - * {# evaluates to true if the foo variable is null, false, or the empty string #}
    - * {% if foo is empty %}
    - *     {# ... #}
    - * {% endif %}
    - * 
    - * - * @param mixed $value A variable - * - * @return bool true if the value is empty, false otherwise - */ -function twig_test_empty($value) -{ - if ($value instanceof Countable) { - return 0 == count($value); - } - - if (is_object($value) && method_exists($value, '__toString')) { - return '' === (string) $value; - } - - return '' === $value || false === $value || null === $value || [] === $value; -} - -/** - * Checks if a variable is traversable. - * - *
    - * {# evaluates to true if the foo variable is an array or a traversable object #}
    - * {% if foo is iterable %}
    - *     {# ... #}
    - * {% endif %}
    - * 
    - * - * @param mixed $value A variable - * - * @return bool true if the value is traversable - */ -function twig_test_iterable($value) -{ - return $value instanceof Traversable || is_array($value); -} - -/** - * Renders a template. - * - * @param Twig_Environment $env - * @param array $context - * @param string|array $template The template to render or an array of templates to try consecutively - * @param array $variables The variables to pass to the template - * @param bool $withContext - * @param bool $ignoreMissing Whether to ignore missing templates or not - * @param bool $sandboxed Whether to sandbox the template or not - * - * @return string The rendered template - */ -function twig_include(Twig_Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) -{ - $alreadySandboxed = false; - $sandbox = null; - if ($withContext) { - $variables = array_merge($context, $variables); - } - - if ($isSandboxed = $sandboxed && $env->hasExtension('Twig_Extension_Sandbox')) { - $sandbox = $env->getExtension('Twig_Extension_Sandbox'); - if (!$alreadySandboxed = $sandbox->isSandboxed()) { - $sandbox->enableSandbox(); - } - } - - $result = ''; - try { - $result = $env->resolveTemplate($template)->render($variables); - } catch (Twig_Error_Loader $e) { - if (!$ignoreMissing) { - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - throw $e; - } - } catch (Throwable $e) { - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - throw $e; - } - - if ($isSandboxed && !$alreadySandboxed) { - $sandbox->disableSandbox(); - } - - return $result; -} - -/** - * Returns a template content without rendering it. - * - * @param Twig_Environment $env - * @param string $name The template name - * @param bool $ignoreMissing Whether to ignore missing templates or not - * - * @return string The template source - */ -function twig_source(Twig_Environment $env, $name, $ignoreMissing = false) -{ - $loader = $env->getLoader(); - try { - return $loader->getSourceContext($name)->getCode(); - } catch (Twig_Error_Loader $e) { - if (!$ignoreMissing) { - throw $e; - } - } -} - -/** - * Provides the ability to get constants from instances as well as class/global constants. - * - * @param string $constant The name of the constant - * @param object|null $object The object to get the constant from - * - * @return string - */ -function twig_constant($constant, $object = null) -{ - if (null !== $object) { - $constant = get_class($object).'::'.$constant; - } - - return constant($constant); -} - -/** - * Checks if a constant exists. - * - * @param string $constant The name of the constant - * @param object|null $object The object to get the constant from - * - * @return bool - */ -function twig_constant_is_defined($constant, $object = null) -{ - if (null !== $object) { - $constant = get_class($object).'::'.$constant; - } - - return defined($constant); -} - -/** - * Batches item. - * - * @param array $items An array of items - * @param int $size The size of the batch - * @param mixed $fill A value used to fill missing items - * - * @return array - */ -function twig_array_batch($items, $size, $fill = null) -{ - if ($items instanceof Traversable) { - $items = iterator_to_array($items, false); - } - - $size = ceil($size); - - $result = array_chunk($items, $size, true); - - if (null !== $fill && !empty($result)) { - $last = count($result) - 1; - if ($fillCount = $size - count($result[$last])) { - $result[$last] = array_merge( - $result[$last], - array_fill(0, $fillCount, $fill) - ); - } - } - - return $result; -} - -/** - * Returns the attribute value for a given array/object. - * - * @param mixed $object The object or array from where to get the item - * @param mixed $item The item to get from the array or object - * @param array $arguments An array of arguments to pass if the item is an object method - * @param string $type The type of attribute (@see Twig_Template constants) - * @param bool $isDefinedTest Whether this is only a defined check - * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not - * - * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true - * - * @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false - * - * @internal - */ -function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, $item, array $arguments = [], $type = /* Twig_Template::ANY_CALL */ 'any', $isDefinedTest = false, $ignoreStrictCheck = false, $sandboxed = false) -{ - // array - if (/* Twig_Template::METHOD_CALL */ 'method' !== $type) { - $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; - - if (((is_array($object) || $object instanceof ArrayObject) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object))) - || ($object instanceof ArrayAccess && isset($object[$arrayItem])) - ) { - if ($isDefinedTest) { - return true; - } - - return $object[$arrayItem]; - } - - if (/* Twig_Template::ARRAY_CALL */ 'array' === $type || !is_object($object)) { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$env->isStrictVariables()) { - return; - } - - if ($object instanceof ArrayAccess) { - $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, get_class($object)); - } elseif (is_object($object)) { - $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, get_class($object)); - } elseif (is_array($object)) { - if (empty($object)) { - $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); - } else { - $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object))); - } - } elseif (/* Twig_Template::ARRAY_CALL */ 'array' === $type) { - if (null === $object) { - $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); - } else { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, gettype($object), $object); - } - } elseif (null === $object) { - $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); - } else { - $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, gettype($object), $object); - } - - throw new Twig_Error_Runtime($message, -1, $source); - } - } - - if (!is_object($object)) { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$env->isStrictVariables()) { - return; - } - - if (null === $object) { - $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); - } elseif (is_array($object)) { - $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); - } else { - $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, gettype($object), $object); - } - - throw new Twig_Error_Runtime($message, -1, $source); - } - - if ($object instanceof Twig_Template) { - throw new Twig_Error_Runtime('Accessing Twig_Template attributes is forbidden.'); - } - - // object property - if (/* Twig_Template::METHOD_CALL */ 'method' !== $type) { - if (isset($object->$item) || array_key_exists((string) $item, $object)) { - if ($isDefinedTest) { - return true; - } - - if ($sandboxed) { - $env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item); - } - - return $object->$item; - } - } - - static $cache = []; - - $class = get_class($object); - - // object method - // precedence: getXxx() > isXxx() > hasXxx() - if (!isset($cache[$class])) { - $methods = get_class_methods($object); - sort($methods); - $lcMethods = array_map('strtolower', $methods); - $classCache = []; - foreach ($methods as $i => $method) { - $classCache[$method] = $method; - $classCache[$lcName = $lcMethods[$i]] = $method; - - if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) { - $name = substr($method, 3); - $lcName = substr($lcName, 3); - } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) { - $name = substr($method, 2); - $lcName = substr($lcName, 2); - } elseif ('h' === $lcName[0] && 0 === strpos($lcName, 'has')) { - $name = substr($method, 3); - $lcName = substr($lcName, 3); - if (in_array('is'.$lcName, $lcMethods)) { - continue; - } - } else { - continue; - } - - // skip get() and is() methods (in which case, $name is empty) - if ($name) { - if (!isset($classCache[$name])) { - $classCache[$name] = $method; - } - - if (!isset($classCache[$lcName])) { - $classCache[$lcName] = $method; - } - } - } - $cache[$class] = $classCache; - } - - $call = false; - if (isset($cache[$class][$item])) { - $method = $cache[$class][$item]; - } elseif (isset($cache[$class][$lcItem = strtolower($item)])) { - $method = $cache[$class][$lcItem]; - } elseif (isset($cache[$class]['__call'])) { - $method = $item; - $call = true; - } else { - if ($isDefinedTest) { - return false; - } - - if ($ignoreStrictCheck || !$env->isStrictVariables()) { - return; - } - - throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()"/"has%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $source); - } - - if ($isDefinedTest) { - return true; - } - - if ($sandboxed) { - $env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method); - } - - // Some objects throw exceptions when they have __call, and the method we try - // to call is not supported. If ignoreStrictCheck is true, we should return null. - try { - $ret = $object->$method(...$arguments); - } catch (BadMethodCallException $e) { - if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) { - return; - } - throw $e; - } - - return $ret; -} - -class_alias('Twig_Extension_Core', 'Twig\Extension\CoreExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/Debug.php b/system/templateEngines/Twig/Twig2x/Extension/Debug.php deleted file mode 100644 index f7d3d7c..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/Debug.php +++ /dev/null @@ -1,56 +0,0 @@ - $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]), - ]; - } -} - -function twig_var_dump(Twig_Environment $env, $context, ...$vars) -{ - if (!$env->isDebug()) { - return; - } - - ob_start(); - - if (!$vars) { - $vars = []; - foreach ($context as $key => $value) { - if (!$value instanceof Twig_Template) { - $vars[$key] = $value; - } - } - - var_dump($vars); - } else { - var_dump(...$vars); - } - - return ob_get_clean(); -} - -class_alias('Twig_Extension_Debug', 'Twig\Extension\DebugExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/Escaper.php b/system/templateEngines/Twig/Twig2x/Extension/Escaper.php deleted file mode 100644 index d4808f6..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/Escaper.php +++ /dev/null @@ -1,91 +0,0 @@ -setDefaultStrategy($defaultStrategy); - } - - public function getTokenParsers() - { - return [new Twig_TokenParser_AutoEscape()]; - } - - public function getNodeVisitors() - { - return [new Twig_NodeVisitor_Escaper()]; - } - - public function getFilters() - { - return [ - new Twig_Filter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), - ]; - } - - /** - * Sets the default strategy to use when not defined by the user. - * - * The strategy can be a valid PHP callback that takes the template - * name as an argument and returns the strategy to use. - * - * @param string|false|callable $defaultStrategy An escaping strategy - */ - public function setDefaultStrategy($defaultStrategy) - { - if ('name' === $defaultStrategy) { - $defaultStrategy = ['Twig_FileExtensionEscapingStrategy', 'guess']; - } - - $this->defaultStrategy = $defaultStrategy; - } - - /** - * Gets the default strategy to use when not defined by the user. - * - * @param string $name The template name - * - * @return string|false The default strategy to use for the template - */ - public function getDefaultStrategy($name) - { - // disable string callables to avoid calling a function named html or js, - // or any other upcoming escaping strategy - if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { - return call_user_func($this->defaultStrategy, $name); - } - - return $this->defaultStrategy; - } -} - -/** - * Marks a variable as being safe. - * - * @param string $string A PHP variable - * - * @return string - */ -function twig_raw_filter($string) -{ - return $string; -} - -class_alias('Twig_Extension_Escaper', 'Twig\Extension\EscaperExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/GlobalsInterface.php b/system/templateEngines/Twig/Twig2x/Extension/GlobalsInterface.php deleted file mode 100644 index 518e3ca..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/GlobalsInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - */ -interface Twig_Extension_GlobalsInterface -{ - /** - * Returns a list of global variables to add to the existing list. - * - * @return array An array of global variables - */ - public function getGlobals(); -} - -class_alias('Twig_Extension_GlobalsInterface', 'Twig\Extension\GlobalsInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/InitRuntimeInterface.php b/system/templateEngines/Twig/Twig2x/Extension/InitRuntimeInterface.php deleted file mode 100644 index eab6191..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/InitRuntimeInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -interface Twig_Extension_InitRuntimeInterface -{ - /** - * Initializes the runtime environment. - * - * This is where you can load some file that contains filter functions for instance. - * - * @param Twig_Environment $environment The current Twig_Environment instance - */ - public function initRuntime(Twig_Environment $environment); -} - -class_alias('Twig_Extension_InitRuntimeInterface', 'Twig\Extension\InitRuntimeInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/Optimizer.php b/system/templateEngines/Twig/Twig2x/Extension/Optimizer.php deleted file mode 100644 index 140020f..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/Optimizer.php +++ /dev/null @@ -1,27 +0,0 @@ -optimizers = $optimizers; - } - - public function getNodeVisitors() - { - return [new Twig_NodeVisitor_Optimizer($this->optimizers)]; - } -} - -class_alias('Twig_Extension_Optimizer', 'Twig\Extension\OptimizerExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/Profiler.php b/system/templateEngines/Twig/Twig2x/Extension/Profiler.php deleted file mode 100644 index 065b221..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/Profiler.php +++ /dev/null @@ -1,44 +0,0 @@ -actives[] = $profile; - } - - public function enter(Twig_Profiler_Profile $profile) - { - $this->actives[0]->addProfile($profile); - array_unshift($this->actives, $profile); - } - - public function leave(Twig_Profiler_Profile $profile) - { - $profile->leave(); - array_shift($this->actives); - - if (1 === count($this->actives)) { - $this->actives[0]->leave(); - } - } - - public function getNodeVisitors() - { - return [new Twig_Profiler_NodeVisitor_Profiler(get_class($this))]; - } -} - -class_alias('Twig_Extension_Profiler', 'Twig\Extension\ProfilerExtension', false); -class_exists('Twig_Profiler_Profile'); diff --git a/system/templateEngines/Twig/Twig2x/Extension/Sandbox.php b/system/templateEngines/Twig/Twig2x/Extension/Sandbox.php deleted file mode 100644 index 77b23c5..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/Sandbox.php +++ /dev/null @@ -1,95 +0,0 @@ -policy = $policy; - $this->sandboxedGlobally = $sandboxed; - } - - public function getTokenParsers() - { - return [new Twig_TokenParser_Sandbox()]; - } - - public function getNodeVisitors() - { - return [new Twig_NodeVisitor_Sandbox()]; - } - - public function enableSandbox() - { - $this->sandboxed = true; - } - - public function disableSandbox() - { - $this->sandboxed = false; - } - - public function isSandboxed() - { - return $this->sandboxedGlobally || $this->sandboxed; - } - - public function isSandboxedGlobally() - { - return $this->sandboxedGlobally; - } - - public function setSecurityPolicy(Twig_Sandbox_SecurityPolicyInterface $policy) - { - $this->policy = $policy; - } - - public function getSecurityPolicy() - { - return $this->policy; - } - - public function checkSecurity($tags, $filters, $functions) - { - if ($this->isSandboxed()) { - $this->policy->checkSecurity($tags, $filters, $functions); - } - } - - public function checkMethodAllowed($obj, $method) - { - if ($this->isSandboxed()) { - $this->policy->checkMethodAllowed($obj, $method); - } - } - - public function checkPropertyAllowed($obj, $method) - { - if ($this->isSandboxed()) { - $this->policy->checkPropertyAllowed($obj, $method); - } - } - - public function ensureToStringAllowed($obj) - { - if ($this->isSandboxed() && is_object($obj)) { - $this->policy->checkMethodAllowed($obj, '__toString'); - } - - return $obj; - } -} - -class_alias('Twig_Extension_Sandbox', 'Twig\Extension\SandboxExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/Staging.php b/system/templateEngines/Twig/Twig2x/Extension/Staging.php deleted file mode 100644 index 36876b7..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/Staging.php +++ /dev/null @@ -1,94 +0,0 @@ - - * - * @internal - */ -final class Twig_Extension_Staging extends Twig_Extension -{ - private $functions = []; - private $filters = []; - private $visitors = []; - private $tokenParsers = []; - private $tests = []; - - public function addFunction(Twig_Function $function) - { - if (isset($this->functions[$function->getName()])) { - throw new LogicException(sprintf('Function "%s" is already registered.', $function->getName())); - } - - $this->functions[$function->getName()] = $function; - } - - public function getFunctions() - { - return $this->functions; - } - - public function addFilter(Twig_Filter $filter) - { - if (isset($this->filters[$filter->getName()])) { - throw new LogicException(sprintf('Filter "%s" is already registered.', $filter->getName())); - } - - $this->filters[$filter->getName()] = $filter; - } - - public function getFilters() - { - return $this->filters; - } - - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) - { - $this->visitors[] = $visitor; - } - - public function getNodeVisitors() - { - return $this->visitors; - } - - public function addTokenParser(Twig_TokenParserInterface $parser) - { - if (isset($this->tokenParsers[$parser->getTag()])) { - throw new LogicException(sprintf('Tag "%s" is already registered.', $parser->getTag())); - } - - $this->tokenParsers[$parser->getTag()] = $parser; - } - - public function getTokenParsers() - { - return $this->tokenParsers; - } - - public function addTest(Twig_Test $test) - { - if (isset($this->tests[$test->getName()])) { - throw new LogicException(sprintf('Test "%s" is already registered.', $test->getTag())); - } - - $this->tests[$test->getName()] = $test; - } - - public function getTests() - { - return $this->tests; - } -} - -class_alias('Twig_Extension_Staging', 'Twig\Extension\StagingExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/Extension/StringLoader.php b/system/templateEngines/Twig/Twig2x/Extension/StringLoader.php deleted file mode 100644 index 606b24d..0000000 --- a/system/templateEngines/Twig/Twig2x/Extension/StringLoader.php +++ /dev/null @@ -1,39 +0,0 @@ - true]), - ]; - } -} - -/** - * Loads a template from a string. - * - *
    - * {{ include(template_from_string("Hello {{ name }}")) }}
    - * 
    - * - * @param Twig_Environment $env A Twig_Environment instance - * @param string $template A template as a string or object implementing __toString() - * - * @return Twig_Template - */ -function twig_template_from_string(Twig_Environment $env, $template) -{ - return $env->createTemplate((string) $template); -} - -class_alias('Twig_Extension_StringLoader', 'Twig\Extension\StringLoaderExtension', false); diff --git a/system/templateEngines/Twig/Twig2x/ExtensionInterface.php b/system/templateEngines/Twig/Twig2x/ExtensionInterface.php deleted file mode 100644 index 66d2b99..0000000 --- a/system/templateEngines/Twig/Twig2x/ExtensionInterface.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -interface Twig_ExtensionInterface -{ - /** - * Returns the token parser instances to add to the existing list. - * - * @return Twig_TokenParserInterface[] - */ - public function getTokenParsers(); - - /** - * Returns the node visitor instances to add to the existing list. - * - * @return Twig_NodeVisitorInterface[] - */ - public function getNodeVisitors(); - - /** - * Returns a list of filters to add to the existing list. - * - * @return Twig_Filter[] - */ - public function getFilters(); - - /** - * Returns a list of tests to add to the existing list. - * - * @return Twig_Test[] - */ - public function getTests(); - - /** - * Returns a list of functions to add to the existing list. - * - * @return Twig_Function[] - */ - public function getFunctions(); - - /** - * Returns a list of operators to add to the existing list. - * - * @return array First array of unary operators, second array of binary operators - */ - public function getOperators(); -} - -class_alias('Twig_ExtensionInterface', 'Twig\Extension\ExtensionInterface', false); -class_exists('Twig_Environment'); diff --git a/system/templateEngines/Twig/Twig2x/ExtensionSet.php b/system/templateEngines/Twig/Twig2x/ExtensionSet.php deleted file mode 100644 index c1bd03c..0000000 --- a/system/templateEngines/Twig/Twig2x/ExtensionSet.php +++ /dev/null @@ -1,498 +0,0 @@ - - * - * @internal - */ -final class Twig_ExtensionSet -{ - private $extensions; - private $initialized = false; - private $runtimeInitialized = false; - private $staging; - private $parsers; - private $visitors; - private $filters; - private $tests; - private $functions; - private $unaryOperators; - private $binaryOperators; - private $globals; - private $functionCallbacks = []; - private $filterCallbacks = []; - private $lastModified = 0; - - public function __construct() - { - $this->staging = new Twig_Extension_Staging(); - } - - /** - * Initializes the runtime environment. - */ - public function initRuntime(Twig_Environment $env) - { - if ($this->runtimeInitialized) { - return; - } - - $this->runtimeInitialized = true; - - foreach ($this->extensions as $extension) { - if ($extension instanceof Twig_Extension_InitRuntimeInterface) { - $extension->initRuntime($env); - } - } - } - - /** - * Returns true if the given extension is registered. - * - * @param string $class The extension class name - * - * @return bool Whether the extension is registered or not - */ - public function hasExtension($class) - { - $class = ltrim($class, '\\'); - if (!isset($this->extensions[$class]) && class_exists($class, false)) { - // For BC/FC with namespaced aliases - $class = (new ReflectionClass($class))->name; - } - - return isset($this->extensions[$class]); - } - - /** - * Gets an extension by class name. - * - * @param string $class The extension class name - * - * @return Twig_ExtensionInterface A Twig_ExtensionInterface instance - */ - public function getExtension($class) - { - $class = ltrim($class, '\\'); - if (!isset($this->extensions[$class]) && class_exists($class, false)) { - // For BC/FC with namespaced aliases - $class = (new ReflectionClass($class))->name; - } - - if (!isset($this->extensions[$class])) { - throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $class)); - } - - return $this->extensions[$class]; - } - - /** - * Registers an array of extensions. - * - * @param array $extensions An array of extensions - */ - public function setExtensions(array $extensions) - { - foreach ($extensions as $extension) { - $this->addExtension($extension); - } - } - - /** - * Returns all registered extensions. - * - * @return array An array of extensions - */ - public function getExtensions() - { - return $this->extensions; - } - - public function getSignature() - { - return json_encode(array_keys($this->extensions)); - } - - public function isInitialized() - { - return $this->initialized || $this->runtimeInitialized; - } - - public function getLastModified() - { - if (0 !== $this->lastModified) { - return $this->lastModified; - } - - foreach ($this->extensions as $extension) { - $r = new ReflectionObject($extension); - if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModified) { - $this->lastModified = $extensionTime; - } - } - - return $this->lastModified; - } - - /** - * Registers an extension. - * - * @param Twig_ExtensionInterface $extension A Twig_ExtensionInterface instance - */ - public function addExtension(Twig_ExtensionInterface $extension) - { - $class = get_class($extension); - - if ($this->initialized) { - throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class)); - } - - if (isset($this->extensions[$class])) { - throw new LogicException(sprintf('Unable to register extension "%s" as it is already registered.', $class)); - } - - // For BC/FC with namespaced aliases - $class = (new ReflectionClass($class))->name; - $this->extensions[$class] = $extension; - } - - public function addFunction(Twig_Function $function) - { - if ($this->initialized) { - throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $function->getName())); - } - - $this->staging->addFunction($function); - } - - public function getFunctions() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->functions; - } - - /** - * Get a function by name. - * - * @param string $name function name - * - * @return Twig_Function|false A Twig_Function instance or false if the function does not exist - */ - public function getFunction($name) - { - if (!$this->initialized) { - $this->initExtensions(); - } - - if (isset($this->functions[$name])) { - return $this->functions[$name]; - } - - foreach ($this->functions as $pattern => $function) { - $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); - - if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) { - array_shift($matches); - $function->setArguments($matches); - - return $function; - } - } - - foreach ($this->functionCallbacks as $callback) { - if (false !== $function = $callback($name)) { - return $function; - } - } - - return false; - } - - public function registerUndefinedFunctionCallback(callable $callable) - { - $this->functionCallbacks[] = $callable; - } - - public function addFilter(Twig_Filter $filter) - { - if ($this->initialized) { - throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $filter->getName())); - } - - $this->staging->addFilter($filter); - } - - public function getFilters() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->filters; - } - - /** - * Get a filter by name. - * - * Subclasses may override this method and load filters differently; - * so no list of filters is available. - * - * @param string $name The filter name - * - * @return Twig_Filter|false A Twig_Filter instance or false if the filter does not exist - */ - public function getFilter($name) - { - if (!$this->initialized) { - $this->initExtensions(); - } - - if (isset($this->filters[$name])) { - return $this->filters[$name]; - } - - foreach ($this->filters as $pattern => $filter) { - $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); - - if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) { - array_shift($matches); - $filter->setArguments($matches); - - return $filter; - } - } - - foreach ($this->filterCallbacks as $callback) { - if (false !== $filter = $callback($name)) { - return $filter; - } - } - - return false; - } - - public function registerUndefinedFilterCallback(callable $callable) - { - $this->filterCallbacks[] = $callable; - } - - public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) - { - if ($this->initialized) { - throw new LogicException('Unable to add a node visitor as extensions have already been initialized.'); - } - - $this->staging->addNodeVisitor($visitor); - } - - public function getNodeVisitors() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->visitors; - } - - public function addTokenParser(Twig_TokenParserInterface $parser) - { - if ($this->initialized) { - throw new LogicException('Unable to add a token parser as extensions have already been initialized.'); - } - - $this->staging->addTokenParser($parser); - } - - public function getTokenParsers() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->parsers; - } - - public function getGlobals() - { - if (null !== $this->globals) { - return $this->globals; - } - - $globals = []; - foreach ($this->extensions as $extension) { - if (!$extension instanceof Twig_Extension_GlobalsInterface) { - continue; - } - - $extGlobals = $extension->getGlobals(); - if (!is_array($extGlobals)) { - throw new UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', get_class($extension))); - } - - $globals = array_merge($globals, $extGlobals); - } - - if ($this->initialized) { - $this->globals = $globals; - } - - return $globals; - } - - public function addTest(Twig_Test $test) - { - if ($this->initialized) { - throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $test->getName())); - } - - $this->staging->addTest($test); - } - - public function getTests() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->tests; - } - - /** - * Gets a test by name. - * - * @param string $name The test name - * - * @return Twig_Test|false A Twig_Test instance or false if the test does not exist - */ - public function getTest($name) - { - if (!$this->initialized) { - $this->initExtensions(); - } - - if (isset($this->tests[$name])) { - return $this->tests[$name]; - } - - foreach ($this->tests as $pattern => $test) { - $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); - - if ($count) { - if (preg_match('#^'.$pattern.'$#', $name, $matches)) { - array_shift($matches); - $test->setArguments($matches); - - return $test; - } - } - } - - return false; - } - - /** - * Gets the registered unary Operators. - * - * @return array An array of unary operators - */ - public function getUnaryOperators() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->unaryOperators; - } - - /** - * Gets the registered binary Operators. - * - * @return array An array of binary operators - */ - public function getBinaryOperators() - { - if (!$this->initialized) { - $this->initExtensions(); - } - - return $this->binaryOperators; - } - - private function initExtensions() - { - $this->parsers = []; - $this->filters = []; - $this->functions = []; - $this->tests = []; - $this->visitors = []; - $this->unaryOperators = []; - $this->binaryOperators = []; - - foreach ($this->extensions as $extension) { - $this->initExtension($extension); - } - $this->initExtension($this->staging); - // Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception - $this->initialized = true; - } - - private function initExtension(Twig_ExtensionInterface $extension) - { - // filters - foreach ($extension->getFilters() as $filter) { - $this->filters[$filter->getName()] = $filter; - } - - // functions - foreach ($extension->getFunctions() as $function) { - $this->functions[$function->getName()] = $function; - } - - // tests - foreach ($extension->getTests() as $test) { - $this->tests[$test->getName()] = $test; - } - - // token parsers - foreach ($extension->getTokenParsers() as $parser) { - if (!$parser instanceof Twig_TokenParserInterface) { - throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface.'); - } - - $this->parsers[] = $parser; - } - - // node visitors - foreach ($extension->getNodeVisitors() as $visitor) { - $this->visitors[] = $visitor; - } - - // operators - if ($operators = $extension->getOperators()) { - if (!is_array($operators)) { - 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))); - } - - if (2 !== count($operators)) { - throw new InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', get_class($extension), count($operators))); - } - - $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); - $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]); - } - } -} - -class_alias('Twig_ExtensionSet', 'Twig\ExtensionSet', false); diff --git a/system/templateEngines/Twig/Twig2x/FactoryRuntimeLoader.php b/system/templateEngines/Twig/Twig2x/FactoryRuntimeLoader.php deleted file mode 100644 index 2a86712..0000000 --- a/system/templateEngines/Twig/Twig2x/FactoryRuntimeLoader.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Twig_FactoryRuntimeLoader implements Twig_RuntimeLoaderInterface -{ - private $map; - - /** - * @param array $map An array where keys are class names and values factory callables - */ - public function __construct($map = []) - { - $this->map = $map; - } - - public function load($class) - { - if (isset($this->map[$class])) { - $runtimeFactory = $this->map[$class]; - - return $runtimeFactory(); - } - } -} - -class_alias('Twig_FactoryRuntimeLoader', 'Twig\RuntimeLoader\FactoryRuntimeLoader', false); diff --git a/system/templateEngines/Twig/Twig2x/FileExtensionEscapingStrategy.php b/system/templateEngines/Twig/Twig2x/FileExtensionEscapingStrategy.php deleted file mode 100644 index 6b13c72..0000000 --- a/system/templateEngines/Twig/Twig2x/FileExtensionEscapingStrategy.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class Twig_FileExtensionEscapingStrategy -{ - /** - * Guesses the best autoescaping strategy based on the file name. - * - * @param string $name The template name - * - * @return string|false The escaping strategy name to use or false to disable - */ - public static function guess($name) - { - if (in_array(substr($name, -1), ['/', '\\'])) { - return 'html'; // return html for directories - } - - if ('.twig' === substr($name, -5)) { - $name = substr($name, 0, -5); - } - - $extension = pathinfo($name, PATHINFO_EXTENSION); - - switch ($extension) { - case 'js': - return 'js'; - - case 'css': - return 'css'; - - case 'txt': - return false; - - default: - return 'html'; - } - } -} - -class_alias('Twig_FileExtensionEscapingStrategy', 'Twig\FileExtensionEscapingStrategy', false); diff --git a/system/templateEngines/Twig/Twig2x/Filter.php b/system/templateEngines/Twig/Twig2x/Filter.php deleted file mode 100644 index 9a86d06..0000000 --- a/system/templateEngines/Twig/Twig2x/Filter.php +++ /dev/null @@ -1,142 +0,0 @@ - - * - * @see https://twig.symfony.com/doc/templates.html#filters - */ -class Twig_Filter -{ - private $name; - private $callable; - private $options; - private $arguments = []; - - /** - * Creates a template filter. - * - * @param string $name Name of this filter - * @param callable|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation. - * @param array $options Options array - */ - public function __construct(string $name, $callable = null, array $options = []) - { - if (__CLASS__ !== get_class($this)) { - @trigger_error('Overriding '.__CLASS__.' is deprecated since version 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); - } - - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge([ - 'needs_environment' => false, - 'needs_context' => false, - 'is_variadic' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'pre_escape' => null, - 'preserves_safety' => null, - 'node_class' => 'Twig_Node_Expression_Filter', - 'deprecated' => false, - 'alternative' => null, - ], $options); - } - - public function getName() - { - return $this->name; - } - - /** - * Returns the callable to execute for this filter. - * - * @return callable|null - */ - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $filterArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return $this->options['is_safe_callback']($filterArgs); - } - } - - public function getPreservesSafety() - { - return $this->options['preserves_safety']; - } - - public function getPreEscape() - { - return $this->options['pre_escape']; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return (bool) $this->options['deprecated']; - } - - public function getDeprecatedVersion() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } -} - -// For Twig 1.x compatibility -class_alias('Twig_Filter', 'Twig_SimpleFilter', false); - -class_alias('Twig_Filter', 'Twig\TwigFilter', false); diff --git a/system/templateEngines/Twig/Twig2x/Function.php b/system/templateEngines/Twig/Twig2x/Function.php deleted file mode 100644 index b0b6cc0..0000000 --- a/system/templateEngines/Twig/Twig2x/Function.php +++ /dev/null @@ -1,132 +0,0 @@ - - * - * @see https://twig.symfony.com/doc/templates.html#functions - */ -class Twig_Function -{ - private $name; - private $callable; - private $options; - private $arguments = []; - - /** - * Creates a template function. - * - * @param string $name Name of this function - * @param callable|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation. - * @param array $options Options array - */ - public function __construct(string $name, $callable = null, array $options = []) - { - if (__CLASS__ !== get_class($this)) { - @trigger_error('Overriding '.__CLASS__.' is deprecated since version 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); - } - - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge([ - 'needs_environment' => false, - 'needs_context' => false, - 'is_variadic' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'node_class' => 'Twig_Node_Expression_Function', - 'deprecated' => false, - 'alternative' => null, - ], $options); - } - - public function getName() - { - return $this->name; - } - - /** - * Returns the callable to execute for this function. - * - * @return callable|null - */ - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $functionArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return $this->options['is_safe_callback']($functionArgs); - } - - return []; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return (bool) $this->options['deprecated']; - } - - public function getDeprecatedVersion() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } -} - -// For Twig 1.x compatibility -class_alias('Twig_Function', 'Twig_SimpleFunction', false); - -class_alias('Twig_Function', 'Twig\TwigFunction', false); diff --git a/system/templateEngines/Twig/Twig2x/Lexer.php b/system/templateEngines/Twig/Twig2x/Lexer.php deleted file mode 100644 index 75f45d1..0000000 --- a/system/templateEngines/Twig/Twig2x/Lexer.php +++ /dev/null @@ -1,398 +0,0 @@ - - */ -class Twig_Lexer -{ - private $tokens; - private $code; - private $cursor; - private $lineno; - private $end; - private $state; - private $states; - private $brackets; - private $env; - private $source; - private $options; - private $regexes; - private $position; - private $positions; - private $currentVarBlockLine; - - const STATE_DATA = 0; - const STATE_BLOCK = 1; - const STATE_VAR = 2; - const STATE_STRING = 3; - const STATE_INTERPOLATION = 4; - - const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; - const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A'; - const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; - const REGEX_DQ_STRING_DELIM = '/"/A'; - const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; - const PUNCTUATION = '()[]{}?:.,|'; - - public function __construct(Twig_Environment $env, array $options = []) - { - $this->env = $env; - - $this->options = array_merge([ - 'tag_comment' => ['{#', '#}'], - 'tag_block' => ['{%', '%}'], - 'tag_variable' => ['{{', '}}'], - 'whitespace_trim' => '-', - 'interpolation' => ['#{', '}'], - ], $options); - - $this->regexes = [ - 'lex_var' => '/\s*'.preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_variable'][1], '/').'/A', - 'lex_block' => '/\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')\n?/A', - 'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*(?:endverbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s', - 'operator' => $this->getOperatorRegex(), - 'lex_comment' => '/(?:'.preg_quote($this->options['whitespace_trim'], '/').preg_quote($this->options['tag_comment'][1], '/').'\s*|'.preg_quote($this->options['tag_comment'][1], '/').')\n?/s', - 'lex_block_raw' => '/\s*verbatim\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As', - 'lex_block_line' => '/\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '/').'/As', - 'lex_tokens_start' => '/('.preg_quote($this->options['tag_variable'][0], '/').'|'.preg_quote($this->options['tag_block'][0], '/').'|'.preg_quote($this->options['tag_comment'][0], '/').')('.preg_quote($this->options['whitespace_trim'], '/').')?/s', - 'interpolation_start' => '/'.preg_quote($this->options['interpolation'][0], '/').'\s*/A', - 'interpolation_end' => '/\s*'.preg_quote($this->options['interpolation'][1], '/').'/A', - ]; - } - - public function tokenize(Twig_Source $source) - { - $this->source = $source; - $this->code = str_replace(["\r\n", "\r"], "\n", $source->getCode()); - $this->cursor = 0; - $this->lineno = 1; - $this->end = strlen($this->code); - $this->tokens = []; - $this->state = self::STATE_DATA; - $this->states = []; - $this->brackets = []; - $this->position = -1; - - // find all token starts in one go - preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); - $this->positions = $matches; - - while ($this->cursor < $this->end) { - // dispatch to the lexing functions depending - // on the current state - switch ($this->state) { - case self::STATE_DATA: - $this->lexData(); - break; - - case self::STATE_BLOCK: - $this->lexBlock(); - break; - - case self::STATE_VAR: - $this->lexVar(); - break; - - case self::STATE_STRING: - $this->lexString(); - break; - - case self::STATE_INTERPOLATION: - $this->lexInterpolation(); - break; - } - } - - $this->pushToken(/* Twig_Token::EOF_TYPE */ -1); - - if (!empty($this->brackets)) { - list($expect, $lineno) = array_pop($this->brackets); - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); - } - - return new Twig_TokenStream($this->tokens, $this->source); - } - - private function lexData() - { - // if no matches are left we return the rest of the template as simple text token - if ($this->position == count($this->positions[0]) - 1) { - $this->pushToken(/* Twig_Token::TEXT_TYPE */ 0, substr($this->code, $this->cursor)); - $this->cursor = $this->end; - - return; - } - - // Find the first token after the current cursor - $position = $this->positions[0][++$this->position]; - while ($position[1] < $this->cursor) { - if ($this->position == count($this->positions[0]) - 1) { - return; - } - $position = $this->positions[0][++$this->position]; - } - - // push the template text first - $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor); - if (isset($this->positions[2][$this->position][0])) { - $text = rtrim($text); - } - $this->pushToken(/* Twig_Token::TEXT_TYPE */ 0, $text); - $this->moveCursor($textContent.$position[0]); - - switch ($this->positions[1][$this->position][0]) { - case $this->options['tag_comment'][0]: - $this->lexComment(); - break; - - case $this->options['tag_block'][0]: - // raw data? - if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) { - $this->moveCursor($match[0]); - $this->lexRawData(); - // {% line \d+ %} - } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) { - $this->moveCursor($match[0]); - $this->lineno = (int) $match[1]; - } else { - $this->pushToken(/* Twig_Token::BLOCK_START_TYPE */ 1); - $this->pushState(self::STATE_BLOCK); - $this->currentVarBlockLine = $this->lineno; - } - break; - - case $this->options['tag_variable'][0]: - $this->pushToken(/* Twig_Token::VAR_START_TYPE */ 2); - $this->pushState(self::STATE_VAR); - $this->currentVarBlockLine = $this->lineno; - break; - } - } - - private function lexBlock() - { - if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(/* Twig_Token::BLOCK_END_TYPE */ 3); - $this->moveCursor($match[0]); - $this->popState(); - } else { - $this->lexExpression(); - } - } - - private function lexVar() - { - if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(/* Twig_Token::VAR_END_TYPE */ 4); - $this->moveCursor($match[0]); - $this->popState(); - } else { - $this->lexExpression(); - } - } - - private function lexExpression() - { - // whitespace - if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) { - $this->moveCursor($match[0]); - - if ($this->cursor >= $this->end) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); - } - } - - // operators - if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(/* Twig_Token::OPERATOR_TYPE */ 8, preg_replace('/\s+/', ' ', $match[0])); - $this->moveCursor($match[0]); - } - // names - elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) { - $this->pushToken(/* Twig_Token::NAME_TYPE */ 5, $match[0]); - $this->moveCursor($match[0]); - } - // numbers - elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) { - $number = (float) $match[0]; // floats - if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { - $number = (int) $match[0]; // integers lower than the maximum - } - $this->pushToken(/* Twig_Token::NUMBER_TYPE */ 6, $number); - $this->moveCursor($match[0]); - } - // punctuation - elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) { - // opening bracket - if (false !== strpos('([{', $this->code[$this->cursor])) { - $this->brackets[] = [$this->code[$this->cursor], $this->lineno]; - } - // closing bracket - elseif (false !== strpos(')]}', $this->code[$this->cursor])) { - if (empty($this->brackets)) { - throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); - } - - list($expect, $lineno) = array_pop($this->brackets); - if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); - } - } - - $this->pushToken(/* Twig_Token::PUNCTUATION_TYPE */ 9, $this->code[$this->cursor]); - ++$this->cursor; - } - // strings - elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) { - $this->pushToken(/* Twig_Token::STRING_TYPE */ 7, stripcslashes(substr($match[0], 1, -1))); - $this->moveCursor($match[0]); - } - // opening double quoted string - elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { - $this->brackets[] = ['"', $this->lineno]; - $this->pushState(self::STATE_STRING); - $this->moveCursor($match[0]); - } - // unlexable - else { - throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); - } - } - - private function lexRawData() - { - if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax('Unexpected end of file: Unclosed "verbatim" block.', $this->lineno, $this->source); - } - - $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); - $this->moveCursor($text.$match[0][0]); - - if (false !== strpos($match[1][0], $this->options['whitespace_trim'])) { - $text = rtrim($text); - } - - $this->pushToken(/* Twig_Token::TEXT_TYPE */ 0, $text); - } - - private function lexComment() - { - if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->source); - } - - $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); - } - - private function lexString() - { - if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) { - $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; - $this->pushToken(/* Twig_Token::INTERPOLATION_START_TYPE */ 10); - $this->moveCursor($match[0]); - $this->pushState(self::STATE_INTERPOLATION); - } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && strlen($match[0]) > 0) { - $this->pushToken(/* Twig_Token::STRING_TYPE */ 7, stripcslashes($match[0])); - $this->moveCursor($match[0]); - } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { - list($expect, $lineno) = array_pop($this->brackets); - if ('"' != $this->code[$this->cursor]) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); - } - - $this->popState(); - ++$this->cursor; - } else { - // unlexable - throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); - } - } - - private function lexInterpolation() - { - $bracket = end($this->brackets); - if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) { - array_pop($this->brackets); - $this->pushToken(/* Twig_Token::INTERPOLATION_END_TYPE */ 11); - $this->moveCursor($match[0]); - $this->popState(); - } else { - $this->lexExpression(); - } - } - - private function pushToken($type, $value = '') - { - // do not push empty text tokens - if (/* Twig_Token::TEXT_TYPE */ 0 === $type && '' === $value) { - return; - } - - $this->tokens[] = new Twig_Token($type, $value, $this->lineno); - } - - private function moveCursor($text) - { - $this->cursor += strlen($text); - $this->lineno += substr_count($text, "\n"); - } - - private function getOperatorRegex() - { - $operators = array_merge( - ['='], - array_keys($this->env->getUnaryOperators()), - array_keys($this->env->getBinaryOperators()) - ); - - $operators = array_combine($operators, array_map('strlen', $operators)); - arsort($operators); - - $regex = []; - foreach ($operators as $operator => $length) { - // an operator that ends with a character must be followed by - // a whitespace or a parenthesis - if (ctype_alpha($operator[$length - 1])) { - $r = preg_quote($operator, '/').'(?=[\s()])'; - } else { - $r = preg_quote($operator, '/'); - } - - // an operator with a space can be any amount of whitespaces - $r = preg_replace('/\s+/', '\s+', $r); - - $regex[] = $r; - } - - return '/'.implode('|', $regex).'/A'; - } - - private function pushState($state) - { - $this->states[] = $this->state; - $this->state = $state; - } - - private function popState() - { - if (0 === count($this->states)) { - throw new LogicException('Cannot pop state without a previous state.'); - } - - $this->state = array_pop($this->states); - } -} - -class_alias('Twig_Lexer', 'Twig\Lexer', false); diff --git a/system/templateEngines/Twig/Twig2x/Loader/Array.php b/system/templateEngines/Twig/Twig2x/Loader/Array.php deleted file mode 100644 index a7e8057..0000000 --- a/system/templateEngines/Twig/Twig2x/Loader/Array.php +++ /dev/null @@ -1,81 +0,0 @@ - - */ -final class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - private $templates = []; - - /** - * @param array $templates An array of templates (keys are the names, and values are the source code) - */ - public function __construct(array $templates = []) - { - $this->templates = $templates; - } - - /** - * Adds or overrides a template. - * - * @param string $name The template name - * @param string $template The template source - */ - public function setTemplate($name, $template) - { - $this->templates[$name] = $template; - } - - public function getSourceContext($name) - { - $name = (string) $name; - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return new Twig_Source($this->templates[$name], $name); - } - - public function exists($name) - { - return isset($this->templates[$name]); - } - - public function getCacheKey($name) - { - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return $name.':'.$this->templates[$name]; - } - - public function isFresh($name, $time) - { - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return true; - } -} - -class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false); diff --git a/system/templateEngines/Twig/Twig2x/Loader/Chain.php b/system/templateEngines/Twig/Twig2x/Loader/Chain.php deleted file mode 100644 index c4ff8b6..0000000 --- a/system/templateEngines/Twig/Twig2x/Loader/Chain.php +++ /dev/null @@ -1,108 +0,0 @@ - - */ -final class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - private $hasSourceCache = []; - private $loaders = []; - - /** - * @param Twig_LoaderInterface[] $loaders - */ - public function __construct(array $loaders = []) - { - foreach ($loaders as $loader) { - $this->addLoader($loader); - } - } - - public function addLoader(Twig_LoaderInterface $loader) - { - $this->loaders[] = $loader; - $this->hasSourceCache = []; - } - - public function getSourceContext($name) - { - $exceptions = []; - foreach ($this->loaders as $loader) { - if (!$loader->exists($name)) { - continue; - } - - try { - return $loader->getSourceContext($name); - } catch (Twig_Error_Loader $e) { - $exceptions[] = $e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - - public function exists($name) - { - if (isset($this->hasSourceCache[$name])) { - return $this->hasSourceCache[$name]; - } - - foreach ($this->loaders as $loader) { - if ($loader->exists($name)) { - return $this->hasSourceCache[$name] = true; - } - } - - return $this->hasSourceCache[$name] = false; - } - - public function getCacheKey($name) - { - $exceptions = []; - foreach ($this->loaders as $loader) { - if (!$loader->exists($name)) { - continue; - } - - try { - return $loader->getCacheKey($name); - } catch (Twig_Error_Loader $e) { - $exceptions[] = get_class($loader).': '.$e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - - public function isFresh($name, $time) - { - $exceptions = []; - foreach ($this->loaders as $loader) { - if (!$loader->exists($name)) { - continue; - } - - try { - return $loader->isFresh($name, $time); - } catch (Twig_Error_Loader $e) { - $exceptions[] = get_class($loader).': '.$e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } -} - -class_alias('Twig_Loader_Chain', 'Twig\Loader\ChainLoader', false); diff --git a/system/templateEngines/Twig/Twig2x/Loader/Filesystem.php b/system/templateEngines/Twig/Twig2x/Loader/Filesystem.php deleted file mode 100644 index 58d082c..0000000 --- a/system/templateEngines/Twig/Twig2x/Loader/Filesystem.php +++ /dev/null @@ -1,292 +0,0 @@ - - */ -class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface -{ - /** Identifier of the main namespace. */ - const MAIN_NAMESPACE = '__main__'; - - protected $paths = []; - protected $cache = []; - protected $errorCache = []; - - private $rootPath; - - /** - * @param string|array $paths A path or an array of paths where to look for templates - * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) - */ - public function __construct($paths = [], $rootPath = null) - { - $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).DIRECTORY_SEPARATOR; - if (false !== $realPath = realpath($rootPath)) { - $this->rootPath = $realPath.DIRECTORY_SEPARATOR; - } - - if ($paths) { - $this->setPaths($paths); - } - } - - /** - * Returns the paths to the templates. - * - * @param string $namespace A path namespace - * - * @return array The array of paths where to look for templates - */ - public function getPaths($namespace = self::MAIN_NAMESPACE) - { - return isset($this->paths[$namespace]) ? $this->paths[$namespace] : []; - } - - /** - * Returns the path namespaces. - * - * The main namespace is always defined. - * - * @return array The array of defined namespaces - */ - public function getNamespaces() - { - return array_keys($this->paths); - } - - /** - * Sets the paths where templates are stored. - * - * @param string|array $paths A path or an array of paths where to look for templates - * @param string $namespace A path namespace - */ - public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) - { - if (!is_array($paths)) { - $paths = [$paths]; - } - - $this->paths[$namespace] = []; - foreach ($paths as $path) { - $this->addPath($path, $namespace); - } - } - - /** - * Adds a path where templates are stored. - * - * @param string $path A path where to look for templates - * @param string $namespace A path namespace - * - * @throws Twig_Error_Loader - */ - public function addPath($path, $namespace = self::MAIN_NAMESPACE) - { - // invalidate the cache - $this->cache = $this->errorCache = []; - - $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; - if (!is_dir($checkPath)) { - throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); - } - - $this->paths[$namespace][] = rtrim($path, '/\\'); - } - - /** - * Prepends a path where templates are stored. - * - * @param string $path A path where to look for templates - * @param string $namespace A path namespace - * - * @throws Twig_Error_Loader - */ - public function prependPath($path, $namespace = self::MAIN_NAMESPACE) - { - // invalidate the cache - $this->cache = $this->errorCache = []; - - $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; - if (!is_dir($checkPath)) { - throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); - } - - $path = rtrim($path, '/\\'); - - if (!isset($this->paths[$namespace])) { - $this->paths[$namespace][] = $path; - } else { - array_unshift($this->paths[$namespace], $path); - } - } - - public function getSourceContext($name) - { - $path = $this->findTemplate($name); - - return new Twig_Source(file_get_contents($path), $name, $path); - } - - public function getCacheKey($name) - { - $path = $this->findTemplate($name); - $len = strlen($this->rootPath); - if (0 === strncmp($this->rootPath, $path, $len)) { - return substr($path, $len); - } - - return $path; - } - - public function exists($name) - { - $name = $this->normalizeName($name); - - if (isset($this->cache[$name])) { - return true; - } - - return false !== $this->findTemplate($name, false); - } - - public function isFresh($name, $time) - { - return filemtime($this->findTemplate($name)) < $time; - } - - /** - * Checks if the template can be found. - * - * @param string $name The template name - * @param bool $throw Whether to throw an exception when an error occurs - * - * @return string|false The template name or false - */ - protected function findTemplate($name, $throw = true) - { - $name = $this->normalizeName($name); - - if (isset($this->cache[$name])) { - return $this->cache[$name]; - } - - if (isset($this->errorCache[$name])) { - if (!$throw) { - return false; - } - - throw new Twig_Error_Loader($this->errorCache[$name]); - } - - try { - $this->validateName($name); - - list($namespace, $shortname) = $this->parseName($name); - } catch (Twig_Error_Loader $e) { - if (!$throw) { - return false; - } - - throw $e; - } - - if (!isset($this->paths[$namespace])) { - $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace); - - if (!$throw) { - return false; - } - - throw new Twig_Error_Loader($this->errorCache[$name]); - } - - foreach ($this->paths[$namespace] as $path) { - if (!$this->isAbsolutePath($path)) { - $path = $this->rootPath.'/'.$path; - } - - if (is_file($path.'/'.$shortname)) { - if (false !== $realpath = realpath($path.'/'.$shortname)) { - return $this->cache[$name] = $realpath; - } - - return $this->cache[$name] = $path.'/'.$shortname; - } - } - - $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])); - - if (!$throw) { - return false; - } - - throw new Twig_Error_Loader($this->errorCache[$name]); - } - - private function normalizeName($name) - { - return preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name)); - } - - private function parseName($name, $default = self::MAIN_NAMESPACE) - { - if (isset($name[0]) && '@' == $name[0]) { - if (false === $pos = strpos($name, '/')) { - throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); - } - - $namespace = substr($name, 1, $pos - 1); - $shortname = substr($name, $pos + 1); - - return [$namespace, $shortname]; - } - - return [$default, $name]; - } - - private function validateName($name) - { - if (false !== strpos($name, "\0")) { - throw new Twig_Error_Loader('A template name cannot contain NUL bytes.'); - } - - $name = ltrim($name, '/'); - $parts = explode('/', $name); - $level = 0; - foreach ($parts as $part) { - if ('..' === $part) { - --$level; - } elseif ('.' !== $part) { - ++$level; - } - - if ($level < 0) { - throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); - } - } - } - - private function isAbsolutePath($file) - { - return strspn($file, '/\\', 0, 1) - || (strlen($file) > 3 && ctype_alpha($file[0]) - && ':' === $file[1] - && strspn($file, '/\\', 2, 1) - ) - || null !== parse_url($file, PHP_URL_SCHEME) - ; - } -} - -class_alias('Twig_Loader_Filesystem', 'Twig\Loader\FilesystemLoader', false); diff --git a/system/templateEngines/Twig/Twig2x/LoaderInterface.php b/system/templateEngines/Twig/Twig2x/LoaderInterface.php deleted file mode 100644 index e2f2ede..0000000 --- a/system/templateEngines/Twig/Twig2x/LoaderInterface.php +++ /dev/null @@ -1,64 +0,0 @@ - - */ -interface Twig_LoaderInterface -{ - /** - * Returns the source context for a given template logical name. - * - * @param string $name The template logical name - * - * @return Twig_Source - * - * @throws Twig_Error_Loader When $name is not found - */ - public function getSourceContext($name); - - /** - * Gets the cache key to use for the cache for a given template name. - * - * @param string $name The name of the template to load - * - * @return string The cache key - * - * @throws Twig_Error_Loader When $name is not found - */ - public function getCacheKey($name); - - /** - * Returns true if the template is still fresh. - * - * @param string $name The template name - * @param int $time Timestamp of the last modification time of the - * cached template - * - * @return bool true if the template is fresh, false otherwise - * - * @throws Twig_Error_Loader When $name is not found - */ - public function isFresh($name, $time); - - /** - * Check if we have the source code of a template, given its name. - * - * @param string $name The name of the template to check if we can load - * - * @return bool If the template source code is handled by this loader or not - */ - public function exists($name); -} - -class_alias('Twig_LoaderInterface', 'Twig\Loader\LoaderInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/Markup.php b/system/templateEngines/Twig/Twig2x/Markup.php deleted file mode 100644 index f542169..0000000 --- a/system/templateEngines/Twig/Twig2x/Markup.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Twig_Markup implements Countable, JsonSerializable -{ - private $content; - private $charset; - - public function __construct($content, $charset) - { - $this->content = (string) $content; - $this->charset = $charset; - } - - public function __toString() - { - return $this->content; - } - - public function count() - { - return mb_strlen($this->content, $this->charset); - } - - public function jsonSerialize() - { - return $this->content; - } -} - -class_alias('Twig_Markup', 'Twig\Markup', false); diff --git a/system/templateEngines/Twig/Twig2x/Node.php b/system/templateEngines/Twig/Twig2x/Node.php deleted file mode 100644 index d0272cc..0000000 --- a/system/templateEngines/Twig/Twig2x/Node.php +++ /dev/null @@ -1,185 +0,0 @@ - - */ -class Twig_Node implements Countable, IteratorAggregate -{ - protected $nodes; - protected $attributes; - protected $lineno; - protected $tag; - - private $name; - - /** - * Constructor. - * - * The nodes are automatically made available as properties ($this->node). - * The attributes are automatically made available as array items ($this['name']). - * - * @param array $nodes An array of named nodes - * @param array $attributes An array of attributes (should not be nodes) - * @param int $lineno The line number - * @param string $tag The tag name associated with the Node - */ - public function __construct(array $nodes = [], array $attributes = [], $lineno = 0, $tag = null) - { - foreach ($nodes as $name => $node) { - if (!$node instanceof self) { - throw new InvalidArgumentException(sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a Twig_Node instance.', is_object($node) ? get_class($node) : null === $node ? 'null' : gettype($node), $name, get_class($this))); - } - } - $this->nodes = $nodes; - $this->attributes = $attributes; - $this->lineno = $lineno; - $this->tag = $tag; - } - - public function __toString() - { - $attributes = []; - foreach ($this->attributes as $name => $value) { - $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); - } - - $repr = [get_class($this).'('.implode(', ', $attributes)]; - - if (count($this->nodes)) { - foreach ($this->nodes as $name => $node) { - $len = strlen($name) + 4; - $noderepr = []; - foreach (explode("\n", (string) $node) as $line) { - $noderepr[] = str_repeat(' ', $len).$line; - } - - $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr))); - } - - $repr[] = ')'; - } else { - $repr[0] .= ')'; - } - - return implode("\n", $repr); - } - - public function compile(Twig_Compiler $compiler) - { - foreach ($this->nodes as $node) { - $node->compile($compiler); - } - } - - public function getTemplateLine() - { - return $this->lineno; - } - - public function getNodeTag() - { - return $this->tag; - } - - /** - * @return bool - */ - public function hasAttribute($name) - { - return array_key_exists($name, $this->attributes); - } - - /** - * @return mixed - */ - public function getAttribute($name) - { - if (!array_key_exists($name, $this->attributes)) { - throw new LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this))); - } - - return $this->attributes[$name]; - } - - /** - * @param string $name - * @param mixed $value - */ - public function setAttribute($name, $value) - { - $this->attributes[$name] = $value; - } - - public function removeAttribute($name) - { - unset($this->attributes[$name]); - } - - /** - * @return bool - */ - public function hasNode($name) - { - return isset($this->nodes[$name]); - } - - /** - * @return Twig_Node - */ - public function getNode($name) - { - if (!isset($this->nodes[$name])) { - throw new LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this))); - } - - return $this->nodes[$name]; - } - - public function setNode($name, self $node) - { - $this->nodes[$name] = $node; - } - - public function removeNode($name) - { - unset($this->nodes[$name]); - } - - public function count() - { - return count($this->nodes); - } - - public function getIterator() - { - return new ArrayIterator($this->nodes); - } - - public function setTemplateName($name) - { - $this->name = $name; - foreach ($this->nodes as $node) { - $node->setTemplateName($name); - } - } - - public function getTemplateName() - { - return $this->name; - } -} - -class_alias('Twig_Node', 'Twig\Node\Node', false); -class_exists('Twig_Compiler'); diff --git a/system/templateEngines/Twig/Twig2x/Node/AutoEscape.php b/system/templateEngines/Twig/Twig2x/Node/AutoEscape.php deleted file mode 100644 index a191cbf..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/AutoEscape.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Node_AutoEscape extends Twig_Node -{ - public function __construct($value, Twig_Node $body, $lineno, $tag = 'autoescape') - { - parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('body')); - } -} - -class_alias('Twig_Node_AutoEscape', 'Twig\Node\AutoEscapeNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Block.php b/system/templateEngines/Twig/Twig2x/Node/Block.php deleted file mode 100644 index 2e8ebdf..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Block.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ -class Twig_Node_Block extends Twig_Node -{ - public function __construct($name, Twig_Node $body, $lineno, $tag = null) - { - parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n") - ->indent() - ; - - $compiler - ->subcompile($this->getNode('body')) - ->outdent() - ->write("}\n\n") - ; - } -} - -class_alias('Twig_Node_Block', 'Twig\Node\BlockNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/BlockReference.php b/system/templateEngines/Twig/Twig2x/Node/BlockReference.php deleted file mode 100644 index 0b0f7b3..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/BlockReference.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ -class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct($name, $lineno, $tag = null) - { - parent::__construct([], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) - ; - } -} - -class_alias('Twig_Node_BlockReference', 'Twig\Node\BlockReferenceNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Body.php b/system/templateEngines/Twig/Twig2x/Node/Body.php deleted file mode 100644 index 07dfef8..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Body.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -class Twig_Node_Body extends Twig_Node -{ -} - -class_alias('Twig_Node_Body', 'Twig\Node\BodyNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/CheckSecurity.php b/system/templateEngines/Twig/Twig2x/Node/CheckSecurity.php deleted file mode 100644 index e3faf86..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/CheckSecurity.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ -class Twig_Node_CheckSecurity extends Twig_Node -{ - private $usedFilters; - private $usedTags; - private $usedFunctions; - - public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) - { - $this->usedFilters = $usedFilters; - $this->usedTags = $usedTags; - $this->usedFunctions = $usedFunctions; - - parent::__construct(); - } - - public function compile(Twig_Compiler $compiler) - { - $tags = $filters = $functions = []; - foreach (['tags', 'filters', 'functions'] as $type) { - foreach ($this->{'used'.ucfirst($type)} as $name => $node) { - if ($node instanceof Twig_Node) { - ${$type}[$name] = $node->getTemplateLine(); - } else { - ${$type}[$node] = null; - } - } - } - - $compiler - ->write('$tags = ')->repr(array_filter($tags))->raw(";\n") - ->write('$filters = ')->repr(array_filter($filters))->raw(";\n") - ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n") - ->write("try {\n") - ->indent() - ->write("\$this->extensions['Twig_Extension_Sandbox']->checkSecurity(\n") - ->indent() - ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n") - ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n") - ->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n") - ->outdent() - ->write(");\n") - ->outdent() - ->write("} catch (Twig_Sandbox_SecurityError \$e) {\n") - ->indent() - ->write("\$e->setSourceContext(\$this->source);\n\n") - ->write("if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") - ->indent() - ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") - ->outdent() - ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") - ->indent() - ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") - ->outdent() - ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") - ->indent() - ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") - ->outdent() - ->write("}\n\n") - ->write("throw \$e;\n") - ->outdent() - ->write("}\n\n") - ; - } -} - -class_alias('Twig_Node_CheckSecurity', 'Twig\Node\CheckSecurityNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Deprecated.php b/system/templateEngines/Twig/Twig2x/Node/Deprecated.php deleted file mode 100644 index fc4c392..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Deprecated.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -class Twig_Node_Deprecated extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - $expr = $this->getNode('expr'); - - if ($expr instanceof Twig_Node_Expression_Constant) { - $compiler->write('@trigger_error(') - ->subcompile($expr); - } else { - $varName = $compiler->getVarName(); - $compiler->write(sprintf('$%s = ', $varName)) - ->subcompile($expr) - ->raw(";\n") - ->write(sprintf('@trigger_error($%s', $varName)); - } - - $compiler - ->raw('.') - ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine())) - ->raw(", E_USER_DEPRECATED);\n") - ; - } -} - -class_alias('Twig_Node_Deprecated', 'Twig\Node\DeprecatedNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Do.php b/system/templateEngines/Twig/Twig2x/Node/Do.php deleted file mode 100644 index 1335045..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Do.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ -class Twig_Node_Do extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('') - ->subcompile($this->getNode('expr')) - ->raw(";\n") - ; - } -} - -class_alias('Twig_Node_Do', 'Twig\Node\DoNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Embed.php b/system/templateEngines/Twig/Twig2x/Node/Embed.php deleted file mode 100644 index 880216f..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Embed.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Twig_Node_Embed extends Twig_Node_Include -{ - // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) - public function __construct($name, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) - { - parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); - - $this->setAttribute('name', $name); - $this->setAttribute('index', $index); - } - - protected function addGetTemplate(Twig_Compiler $compiler) - { - $compiler - ->write('$this->loadTemplate(') - ->string($this->getAttribute('name')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(', ') - ->string($this->getAttribute('index')) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Embed', 'Twig\Node\EmbedNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression.php b/system/templateEngines/Twig/Twig2x/Node/Expression.php deleted file mode 100644 index a99c4e6..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -abstract class Twig_Node_Expression extends Twig_Node -{ -} - -class_alias('Twig_Node_Expression', 'Twig\Node\Expression\AbstractExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Array.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Array.php deleted file mode 100644 index 664a213..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Array.php +++ /dev/null @@ -1,83 +0,0 @@ -index = -1; - foreach ($this->getKeyValuePairs() as $pair) { - if ($pair['key'] instanceof Twig_Node_Expression_Constant && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { - $this->index = $pair['key']->getAttribute('value'); - } - } - } - - public function getKeyValuePairs() - { - $pairs = []; - - foreach (array_chunk($this->nodes, 2) as $pair) { - $pairs[] = [ - 'key' => $pair[0], - 'value' => $pair[1], - ]; - } - - return $pairs; - } - - public function hasElement(Twig_Node_Expression $key) - { - foreach ($this->getKeyValuePairs() as $pair) { - // we compare the string representation of the keys - // to avoid comparing the line numbers which are not relevant here. - if ((string) $key === (string) $pair['key']) { - return true; - } - } - - return false; - } - - public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null) - { - if (null === $key) { - $key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine()); - } - - array_push($this->nodes, $key, $value); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->raw('['); - $first = true; - foreach ($this->getKeyValuePairs() as $pair) { - if (!$first) { - $compiler->raw(', '); - } - $first = false; - - $compiler - ->subcompile($pair['key']) - ->raw(' => ') - ->subcompile($pair['value']) - ; - } - $compiler->raw(']'); - } -} - -class_alias('Twig_Node_Expression_Array', 'Twig\Node\Expression\ArrayExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/AssignName.php b/system/templateEngines/Twig/Twig2x/Node/Expression/AssignName.php deleted file mode 100644 index 2e6b4c7..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/AssignName.php +++ /dev/null @@ -1,25 +0,0 @@ -raw('$context[') - ->string($this->getAttribute('name')) - ->raw(']') - ; - } -} - -class_alias('Twig_Node_Expression_AssignName', 'Twig\Node\Expression\AssignNameExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary.php deleted file mode 100644 index f5296fd..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary.php +++ /dev/null @@ -1,37 +0,0 @@ - $left, 'right' => $right], [], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('left')) - ->raw(' ') - ; - $this->operator($compiler); - $compiler - ->raw(' ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - abstract public function operator(Twig_Compiler $compiler); -} - -class_alias('Twig_Node_Expression_Binary', 'Twig\Node\Expression\Binary\AbstractBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Add.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Add.php deleted file mode 100644 index 5a09d83..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Add.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('+'); - } -} - -class_alias('Twig_Node_Expression_Binary_Add', 'Twig\Node\Expression\Binary\AddBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/And.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/And.php deleted file mode 100644 index 9ffddce..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/And.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('&&'); - } -} - -class_alias('Twig_Node_Expression_Binary_And', 'Twig\Node\Expression\Binary\AndBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseAnd.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseAnd.php deleted file mode 100644 index e46e9eb..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseAnd.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('&'); - } -} - -class_alias('Twig_Node_Expression_Binary_BitwiseAnd', 'Twig\Node\Expression\Binary\BitwiseAndBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseOr.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseOr.php deleted file mode 100644 index 5d7f1b7..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseOr.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('|'); - } -} - -class_alias('Twig_Node_Expression_Binary_BitwiseOr', 'Twig\Node\Expression\Binary\BitwiseOrBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseXor.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseXor.php deleted file mode 100644 index 82edf51..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/BitwiseXor.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('^'); - } -} - -class_alias('Twig_Node_Expression_Binary_BitwiseXor', 'Twig\Node\Expression\Binary\BitwiseXorBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Concat.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Concat.php deleted file mode 100644 index 91abca6..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Concat.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('.'); - } -} - -class_alias('Twig_Node_Expression_Binary_Concat', 'Twig\Node\Expression\Binary\ConcatBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Div.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Div.php deleted file mode 100644 index 38ffa30..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Div.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('/'); - } -} - -class_alias('Twig_Node_Expression_Binary_Div', 'Twig\Node\Expression\Binary\DivBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/EndsWith.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/EndsWith.php deleted file mode 100644 index 85c5293..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/EndsWith.php +++ /dev/null @@ -1,32 +0,0 @@ -getVarName(); - $right = $compiler->getVarName(); - $compiler - ->raw(sprintf('(is_string($%s = ', $left)) - ->subcompile($this->getNode('left')) - ->raw(sprintf(') && is_string($%s = ', $right)) - ->subcompile($this->getNode('right')) - ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right)) - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw(''); - } -} - -class_alias('Twig_Node_Expression_Binary_EndsWith', 'Twig\Node\Expression\Binary\EndsWithBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Equal.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Equal.php deleted file mode 100644 index a6a6946..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Equal.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('=='); - } -} - -class_alias('Twig_Node_Expression_Binary_Equal', 'Twig\Node\Expression\Binary\EqualBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/FloorDiv.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/FloorDiv.php deleted file mode 100644 index 7393bcb..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/FloorDiv.php +++ /dev/null @@ -1,26 +0,0 @@ -raw('(int) floor('); - parent::compile($compiler); - $compiler->raw(')'); - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('/'); - } -} - -class_alias('Twig_Node_Expression_Binary_FloorDiv', 'Twig\Node\Expression\Binary\FloorDivBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Greater.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Greater.php deleted file mode 100644 index 832f979..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Greater.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('>'); - } -} - -class_alias('Twig_Node_Expression_Binary_Greater', 'Twig\Node\Expression\Binary\GreaterBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/GreaterEqual.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/GreaterEqual.php deleted file mode 100644 index c5f7624..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/GreaterEqual.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('>='); - } -} - -class_alias('Twig_Node_Expression_Binary_GreaterEqual', 'Twig\Node\Expression\Binary\GreaterEqualBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/In.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/In.php deleted file mode 100644 index af11244..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/In.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('twig_in_filter(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('in'); - } -} - -class_alias('Twig_Node_Expression_Binary_In', 'Twig\Node\Expression\Binary\InBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Less.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Less.php deleted file mode 100644 index ab8fc1f..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Less.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('<'); - } -} - -class_alias('Twig_Node_Expression_Binary_Less', 'Twig\Node\Expression\Binary\LessBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/LessEqual.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/LessEqual.php deleted file mode 100644 index 71a279e..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/LessEqual.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('<='); - } -} - -class_alias('Twig_Node_Expression_Binary_LessEqual', 'Twig\Node\Expression\Binary\LessEqualBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Matches.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Matches.php deleted file mode 100644 index 5cb8558..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Matches.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('preg_match(') - ->subcompile($this->getNode('right')) - ->raw(', ') - ->subcompile($this->getNode('left')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw(''); - } -} - -class_alias('Twig_Node_Expression_Binary_Matches', 'Twig\Node\Expression\Binary\MatchesBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mod.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mod.php deleted file mode 100644 index 2810963..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mod.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('%'); - } -} - -class_alias('Twig_Node_Expression_Binary_Mod', 'Twig\Node\Expression\Binary\ModBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mul.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mul.php deleted file mode 100644 index 790c6a2..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Mul.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('*'); - } -} - -class_alias('Twig_Node_Expression_Binary_Mul', 'Twig\Node\Expression\Binary\MulBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotEqual.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotEqual.php deleted file mode 100644 index bb45c9e..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotEqual.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('!='); - } -} - -class_alias('Twig_Node_Expression_Binary_NotEqual', 'Twig\Node\Expression\Binary\NotEqualBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotIn.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotIn.php deleted file mode 100644 index 9dedf92..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/NotIn.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('!twig_in_filter(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('not in'); - } -} - -class_alias('Twig_Node_Expression_Binary_NotIn', 'Twig\Node\Expression\Binary\NotInBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Or.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Or.php deleted file mode 100644 index dc9eece..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Or.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('||'); - } -} - -class_alias('Twig_Node_Expression_Binary_Or', 'Twig\Node\Expression\Binary\OrBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Power.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Power.php deleted file mode 100644 index b8cac78..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Power.php +++ /dev/null @@ -1,19 +0,0 @@ -raw('**'); - } -} - -class_alias('Twig_Node_Expression_Binary_Power', 'Twig\Node\Expression\Binary\PowerBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Range.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Range.php deleted file mode 100644 index 187f676..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Range.php +++ /dev/null @@ -1,30 +0,0 @@ -raw('range(') - ->subcompile($this->getNode('left')) - ->raw(', ') - ->subcompile($this->getNode('right')) - ->raw(')') - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw('..'); - } -} - -class_alias('Twig_Node_Expression_Binary_Range', 'Twig\Node\Expression\Binary\RangeBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/StartsWith.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/StartsWith.php deleted file mode 100644 index 7e43b8d..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/StartsWith.php +++ /dev/null @@ -1,32 +0,0 @@ -getVarName(); - $right = $compiler->getVarName(); - $compiler - ->raw(sprintf('(is_string($%s = ', $left)) - ->subcompile($this->getNode('left')) - ->raw(sprintf(') && is_string($%s = ', $right)) - ->subcompile($this->getNode('right')) - ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) - ; - } - - public function operator(Twig_Compiler $compiler) - { - return $compiler->raw(''); - } -} - -class_alias('Twig_Node_Expression_Binary_StartsWith', 'Twig\Node\Expression\Binary\StartsWithBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Sub.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Sub.php deleted file mode 100644 index cff8ed0..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Binary/Sub.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('-'); - } -} - -class_alias('Twig_Node_Expression_Binary_Sub', 'Twig\Node\Expression\Binary\SubBinary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/BlockReference.php b/system/templateEngines/Twig/Twig2x/Node/Expression/BlockReference.php deleted file mode 100644 index daed1c5..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/BlockReference.php +++ /dev/null @@ -1,84 +0,0 @@ - - */ -class Twig_Node_Expression_BlockReference extends Twig_Node_Expression -{ - public function __construct(Twig_Node $name, Twig_Node $template = null, $lineno, $tag = null) - { - $nodes = ['name' => $name]; - if (null !== $template) { - $nodes['template'] = $template; - } - - parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('is_defined_test')) { - $this->compileTemplateCall($compiler, 'hasBlock'); - } else { - if ($this->getAttribute('output')) { - $compiler->addDebugInfo($this); - - $this - ->compileTemplateCall($compiler, 'displayBlock') - ->raw(";\n"); - } else { - $this->compileTemplateCall($compiler, 'renderBlock'); - } - } - } - - private function compileTemplateCall(Twig_Compiler $compiler, $method) - { - if (!$this->hasNode('template')) { - $compiler->write('$this'); - } else { - $compiler - ->write('$this->loadTemplate(') - ->subcompile($this->getNode('template')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(')') - ; - } - - $compiler->raw(sprintf('->%s', $method)); - $this->compileBlockArguments($compiler); - - return $compiler; - } - - private function compileBlockArguments(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('name')) - ->raw(', $context'); - - if (!$this->hasNode('template')) { - $compiler->raw(', $blocks'); - } - - return $compiler->raw(')'); - } -} - -class_alias('Twig_Node_Expression_BlockReference', 'Twig\Node\Expression\BlockReferenceExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Call.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Call.php deleted file mode 100644 index 27b86e2..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Call.php +++ /dev/null @@ -1,297 +0,0 @@ -getAttribute('callable'); - - $closingParenthesis = false; - $isArray = false; - if (is_string($callable) && false === strpos($callable, '::')) { - $compiler->raw($callable); - } else { - list($r, $callable) = $this->reflectCallable($callable); - if ($r instanceof ReflectionMethod && is_string($callable[0])) { - if ($r->isStatic()) { - $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1])); - } else { - $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); - } - } elseif ($r instanceof ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) { - // For BC/FC with namespaced aliases - $class = (new ReflectionClass(get_class($callable[0])))->name; - if (!$compiler->getEnvironment()->hasExtension($class)) { - // Compile a non-optimized call to trigger a Twig_Error_Runtime, which cannot be a compile-time error - $compiler->raw(sprintf('$this->env->getExtension(\'%s\')', $class)); - } else { - $compiler->raw(sprintf('$this->extensions[\'%s\']', ltrim($class, '\\'))); - } - - $compiler->raw(sprintf('->%s', $callable[1])); - } else { - $closingParenthesis = true; - $isArray = true; - $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', ucfirst($this->getAttribute('type')), $this->getAttribute('name'))); - } - } - - $this->compileArguments($compiler, $isArray); - - if ($closingParenthesis) { - $compiler->raw(')'); - } - } - - protected function compileArguments(Twig_Compiler $compiler, $isArray = false) - { - $compiler->raw($isArray ? '[' : '('); - - $first = true; - - if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { - $compiler->raw('$this->env'); - $first = false; - } - - if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->raw('$context'); - $first = false; - } - - if ($this->hasAttribute('arguments')) { - foreach ($this->getAttribute('arguments') as $argument) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->string($argument); - $first = false; - } - } - - if ($this->hasNode('node')) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->subcompile($this->getNode('node')); - $first = false; - } - - if ($this->hasNode('arguments')) { - $callable = $this->getAttribute('callable'); - $arguments = $this->getArguments($callable, $this->getNode('arguments')); - foreach ($arguments as $node) { - if (!$first) { - $compiler->raw(', '); - } - $compiler->subcompile($node); - $first = false; - } - } - - $compiler->raw($isArray ? ']' : ')'); - } - - protected function getArguments($callable = null, $arguments) - { - $callType = $this->getAttribute('type'); - $callName = $this->getAttribute('name'); - - $parameters = []; - $named = false; - foreach ($arguments as $name => $node) { - if (!is_int($name)) { - $named = true; - $name = $this->normalizeName($name); - } elseif ($named) { - throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine()); - } - - $parameters[$name] = $node; - } - - $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic'); - if (!$named && !$isVariadic) { - return $parameters; - } - - if (!$callable) { - if ($named) { - $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName); - } else { - $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName); - } - - throw new LogicException($message); - } - - $callableParameters = $this->getCallableParameters($callable, $isVariadic); - $arguments = []; - $names = []; - $missingArguments = []; - $optionalArguments = []; - $pos = 0; - foreach ($callableParameters as $callableParameter) { - $names[] = $name = $this->normalizeName($callableParameter->name); - - if (array_key_exists($name, $parameters)) { - if (array_key_exists($pos, $parameters)) { - throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); - } - - if (count($missingArguments)) { - throw new Twig_Error_Syntax(sprintf( - 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', - $name, $callType, $callName, implode(', ', $names), count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) - ), $this->getTemplateLine()); - } - - $arguments = array_merge($arguments, $optionalArguments); - $arguments[] = $parameters[$name]; - unset($parameters[$name]); - $optionalArguments = []; - } elseif (array_key_exists($pos, $parameters)) { - $arguments = array_merge($arguments, $optionalArguments); - $arguments[] = $parameters[$pos]; - unset($parameters[$pos]); - $optionalArguments = []; - ++$pos; - } elseif ($callableParameter->isDefaultValueAvailable()) { - $optionalArguments[] = new Twig_Node_Expression_Constant($callableParameter->getDefaultValue(), -1); - } elseif ($callableParameter->isOptional()) { - if (empty($parameters)) { - break; - } else { - $missingArguments[] = $name; - } - } else { - throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); - } - } - - if ($isVariadic) { - $arbitraryArguments = new Twig_Node_Expression_Array([], -1); - foreach ($parameters as $key => $value) { - if (is_int($key)) { - $arbitraryArguments->addElement($value); - } else { - $arbitraryArguments->addElement($value, new Twig_Node_Expression_Constant($key, -1)); - } - unset($parameters[$key]); - } - - if ($arbitraryArguments->count()) { - $arguments = array_merge($arguments, $optionalArguments); - $arguments[] = $arbitraryArguments; - } - } - - if (!empty($parameters)) { - $unknownParameter = null; - foreach ($parameters as $parameter) { - if ($parameter instanceof Twig_Node) { - $unknownParameter = $parameter; - break; - } - } - - throw new Twig_Error_Syntax(sprintf( - 'Unknown argument%s "%s" for %s "%s(%s)".', - count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) - ), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine()); - } - - return $arguments; - } - - protected function normalizeName($name) - { - return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); - } - - private function getCallableParameters($callable, $isVariadic) - { - list($r) = $this->reflectCallable($callable); - if (null === $r) { - return []; - } - - $parameters = $r->getParameters(); - if ($this->hasNode('node')) { - array_shift($parameters); - } - if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { - array_shift($parameters); - } - if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { - array_shift($parameters); - } - if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { - foreach ($this->getAttribute('arguments') as $argument) { - array_shift($parameters); - } - } - if ($isVariadic) { - $argument = end($parameters); - if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { - array_pop($parameters); - } else { - $callableName = $r->name; - if ($r instanceof ReflectionMethod) { - $callableName = $r->getDeclaringClass()->name.'::'.$callableName; - } - - throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); - } - } - - return $parameters; - } - - private function reflectCallable($callable) - { - if (null !== $this->reflector) { - return $this->reflector; - } - - if (is_array($callable)) { - if (!method_exists($callable[0], $callable[1])) { - // __call() - return [null, []]; - } - $r = new ReflectionMethod($callable[0], $callable[1]); - } elseif (is_object($callable) && !$callable instanceof Closure) { - $r = new ReflectionObject($callable); - $r = $r->getMethod('__invoke'); - $callable = [$callable, '__invoke']; - } elseif (is_string($callable) && false !== $pos = strpos($callable, '::')) { - $class = substr($callable, 0, $pos); - $method = substr($callable, $pos + 2); - if (!method_exists($class, $method)) { - // __staticCall() - return [null, []]; - } - $r = new ReflectionMethod($callable); - $callable = [$class, $method]; - } else { - $r = new ReflectionFunction($callable); - } - - return $this->reflector = [$r, $callable]; - } -} - -class_alias('Twig_Node_Expression_Call', 'Twig\Node\Expression\CallExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Conditional.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Conditional.php deleted file mode 100644 index 996772a..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Conditional.php +++ /dev/null @@ -1,33 +0,0 @@ - $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('((') - ->subcompile($this->getNode('expr1')) - ->raw(') ? (') - ->subcompile($this->getNode('expr2')) - ->raw(') : (') - ->subcompile($this->getNode('expr3')) - ->raw('))') - ; - } -} - -class_alias('Twig_Node_Expression_Conditional', 'Twig\Node\Expression\ConditionalExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Constant.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Constant.php deleted file mode 100644 index 7304e8c..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Constant.php +++ /dev/null @@ -1,25 +0,0 @@ - $value], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->repr($this->getAttribute('value')); - } -} - -class_alias('Twig_Node_Expression_Constant', 'Twig\Node\Expression\ConstantExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Filter.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Filter.php deleted file mode 100644 index 61b0470..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Filter.php +++ /dev/null @@ -1,36 +0,0 @@ - $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getNode('filter')->getAttribute('value'); - $filter = $compiler->getEnvironment()->getFilter($name); - - $this->setAttribute('name', $name); - $this->setAttribute('type', 'filter'); - $this->setAttribute('needs_environment', $filter->needsEnvironment()); - $this->setAttribute('needs_context', $filter->needsContext()); - $this->setAttribute('arguments', $filter->getArguments()); - $this->setAttribute('callable', $filter->getCallable()); - $this->setAttribute('is_variadic', $filter->isVariadic()); - - $this->compileCallable($compiler); - } -} - -class_alias('Twig_Node_Expression_Filter', 'Twig\Node\Expression\FilterExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Filter/Default.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Filter/Default.php deleted file mode 100644 index f073dd2..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Filter/Default.php +++ /dev/null @@ -1,45 +0,0 @@ - - * {{ var.foo|default('foo item on var is not defined') }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter -{ - public function __construct(Twig_Node $node, Twig_Node_Expression_Constant $filterName, Twig_Node $arguments, $lineno, $tag = null) - { - $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); - - if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) { - $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine()); - $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine()); - - $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine()); - } else { - $node = $default; - } - - parent::__construct($node, $filterName, $arguments, $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('node')); - } -} - -class_alias('Twig_Node_Expression_Filter_Default', 'Twig\Node\Expression\Filter\DefaultFilter', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Function.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Function.php deleted file mode 100644 index 37281d7..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Function.php +++ /dev/null @@ -1,39 +0,0 @@ - $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $function = $compiler->getEnvironment()->getFunction($name); - - $this->setAttribute('name', $name); - $this->setAttribute('type', 'function'); - $this->setAttribute('needs_environment', $function->needsEnvironment()); - $this->setAttribute('needs_context', $function->needsContext()); - $this->setAttribute('arguments', $function->getArguments()); - $callable = $function->getCallable(); - if ('constant' === $name && $this->getAttribute('is_defined_test')) { - $callable = 'twig_constant_is_defined'; - } - $this->setAttribute('callable', $callable); - $this->setAttribute('is_variadic', $function->isVariadic()); - - $this->compileCallable($compiler); - } -} - -class_alias('Twig_Node_Expression_Function', 'Twig\Node\Expression\FunctionExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/GetAttr.php b/system/templateEngines/Twig/Twig2x/Node/Expression/GetAttr.php deleted file mode 100644 index 3423af0..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/GetAttr.php +++ /dev/null @@ -1,98 +0,0 @@ - $node, 'attribute' => $attribute]; - if (null !== $arguments) { - $nodes['arguments'] = $arguments; - } - - parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'optimizable' => true], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $env = $compiler->getEnvironment(); - - // optimize array calls - if ( - $this->getAttribute('optimizable') - && (!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check')) - && !$this->getAttribute('is_defined_test') - && Twig_Template::ARRAY_CALL === $this->getAttribute('type') - ) { - $var = '$'.$compiler->getVarName(); - $compiler - ->raw('(('.$var.' = ') - ->subcompile($this->getNode('node')) - ->raw(') && is_array(') - ->raw($var) - ->raw(') || ') - ->raw($var) - ->raw(' instanceof ArrayAccess ? (') - ->raw($var) - ->raw('[') - ->subcompile($this->getNode('attribute')) - ->raw('] ?? null) : null)') - ; - - return; - } - - $compiler->raw('twig_get_attribute($this->env, $this->source, '); - - if ($this->getAttribute('ignore_strict_check')) { - $this->getNode('node')->setAttribute('ignore_strict_check', true); - } - - $compiler->subcompile($this->getNode('node')); - - $compiler->raw(', ')->subcompile($this->getNode('attribute')); - - // only generate optional arguments when needed (to make generated code more readable) - $needFifth = $env->hasExtension('Twig_Extension_Sandbox'); - $needFourth = $needFifth || $this->getAttribute('ignore_strict_check'); - $needThird = $needFourth || $this->getAttribute('is_defined_test'); - $needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type'); - $needFirst = $needSecond || $this->hasNode('arguments'); - - if ($needFirst) { - if ($this->hasNode('arguments')) { - $compiler->raw(', ')->subcompile($this->getNode('arguments')); - } else { - $compiler->raw(', []'); - } - } - - if ($needSecond) { - $compiler->raw(', ')->repr($this->getAttribute('type')); - } - - if ($needThird) { - $compiler->raw(', ')->repr($this->getAttribute('is_defined_test')); - } - - if ($needFourth) { - $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check')); - } - - if ($needFifth) { - $compiler->raw(', ')->repr($env->hasExtension('Twig_Extension_Sandbox')); - } - - $compiler->raw(')'); - } -} - -class_alias('Twig_Node_Expression_GetAttr', 'Twig\Node\Expression\GetAttrExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/MethodCall.php b/system/templateEngines/Twig/Twig2x/Node/Expression/MethodCall.php deleted file mode 100644 index b8a8345..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/MethodCall.php +++ /dev/null @@ -1,43 +0,0 @@ - $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno); - - if ($node instanceof Twig_Node_Expression_Name) { - $node->setAttribute('always_defined', true); - } - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->subcompile($this->getNode('node')) - ->raw('->') - ->raw($this->getAttribute('method')) - ->raw('(') - ; - $first = true; - foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { - if (!$first) { - $compiler->raw(', '); - } - $first = false; - - $compiler->subcompile($pair['value']); - } - $compiler->raw(')'); - } -} - -class_alias('Twig_Node_Expression_MethodCall', 'Twig\Node\Expression\MethodCallExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Name.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Name.php deleted file mode 100644 index f265267..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Name.php +++ /dev/null @@ -1,87 +0,0 @@ - '$this->getTemplateName()', - '_context' => '$context', - '_charset' => '$this->env->getCharset()', - ]; - - public function __construct($name, $lineno) - { - parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - - $compiler->addDebugInfo($this); - - if ($this->getAttribute('is_defined_test')) { - if ($this->isSpecial()) { - $compiler->repr(true); - } else { - $compiler - ->raw('(isset($context[') - ->string($name) - ->raw(']) || array_key_exists(') - ->string($name) - ->raw(', $context))'); - } - } elseif ($this->isSpecial()) { - $compiler->raw($this->specialVars[$name]); - } elseif ($this->getAttribute('always_defined')) { - $compiler - ->raw('$context[') - ->string($name) - ->raw(']') - ; - } else { - if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { - $compiler - ->raw('($context[') - ->string($name) - ->raw('] ?? null)') - ; - } else { - $compiler - ->raw('(isset($context[') - ->string($name) - ->raw(']) || array_key_exists(') - ->string($name) - ->raw(', $context) ? $context[') - ->string($name) - ->raw('] : (function () { throw new Twig_Error_Runtime(\'Variable ') - ->string($name) - ->raw(' does not exist.\', ') - ->repr($this->lineno) - ->raw(', $this->source); })()') - ->raw(')') - ; - } - } - } - - public function isSpecial() - { - return isset($this->specialVars[$this->getAttribute('name')]); - } - - public function isSimple() - { - return !$this->isSpecial() && !$this->getAttribute('is_defined_test'); - } -} - -class_alias('Twig_Node_Expression_Name', 'Twig\Node\Expression\NameExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/NullCoalesce.php b/system/templateEngines/Twig/Twig2x/Node/Expression/NullCoalesce.php deleted file mode 100644 index 46ea208..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/NullCoalesce.php +++ /dev/null @@ -1,48 +0,0 @@ -getTemplateLine()), - new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getTemplateLine()), $left->getTemplateLine()), - $left->getTemplateLine() - ); - - parent::__construct($test, $left, $right, $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - /* - * This optimizes only one case. PHP 7 also supports more complex expressions - * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works, - * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced - * cases might be implemented as an optimizer node visitor, but has not been done - * as benefits are probably not worth the added complexity. - */ - if ($this->getNode('expr2') instanceof Twig_Node_Expression_Name) { - $this->getNode('expr2')->setAttribute('always_defined', true); - $compiler - ->raw('((') - ->subcompile($this->getNode('expr2')) - ->raw(') ?? (') - ->subcompile($this->getNode('expr3')) - ->raw('))') - ; - } else { - parent::compile($compiler); - } - } -} - -class_alias('Twig_Node_Expression_NullCoalesce', 'Twig\Node\Expression\NullCoalesceExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Parent.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Parent.php deleted file mode 100644 index 8623685..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Parent.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Twig_Node_Expression_Parent extends Twig_Node_Expression -{ - public function __construct($name, $lineno, $tag = null) - { - parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('output')) { - $compiler - ->addDebugInfo($this) - ->write('$this->displayParentBlock(') - ->string($this->getAttribute('name')) - ->raw(", \$context, \$blocks);\n") - ; - } else { - $compiler - ->raw('$this->renderParentBlock(') - ->string($this->getAttribute('name')) - ->raw(', $context, $blocks)') - ; - } - } -} - -class_alias('Twig_Node_Expression_Parent', 'Twig\Node\Expression\ParentExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/TempName.php b/system/templateEngines/Twig/Twig2x/Node/Expression/TempName.php deleted file mode 100644 index 4be1cc2..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/TempName.php +++ /dev/null @@ -1,28 +0,0 @@ - $name], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('$_') - ->raw($this->getAttribute('name')) - ->raw('_') - ; - } -} - -class_alias('Twig_Node_Expression_TempName', 'Twig\Node\Expression\TempNameExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test.php deleted file mode 100644 index 328823b..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test.php +++ /dev/null @@ -1,38 +0,0 @@ - $node]; - if (null !== $arguments) { - $nodes['arguments'] = $arguments; - } - - parent::__construct($nodes, ['name' => $name], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $test = $compiler->getEnvironment()->getTest($name); - - $this->setAttribute('name', $name); - $this->setAttribute('type', 'test'); - $this->setAttribute('arguments', $test->getArguments()); - $this->setAttribute('callable', $test->getCallable()); - $this->setAttribute('is_variadic', $test->isVariadic()); - - $this->compileCallable($compiler); - } -} - -class_alias('Twig_Node_Expression_Test', 'Twig\Node\Expression\TestExpression', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Constant.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Constant.php deleted file mode 100644 index a51a4ba..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Constant.php +++ /dev/null @@ -1,48 +0,0 @@ - - * {% if post.status is constant('Post::PUBLISHED') %} - * the status attribute is exactly the same as Post::PUBLISHED - * {% endif %} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' === constant(') - ; - - if ($this->getNode('arguments')->hasNode(1)) { - $compiler - ->raw('get_class(') - ->subcompile($this->getNode('arguments')->getNode(1)) - ->raw(')."::".') - ; - } - - $compiler - ->subcompile($this->getNode('arguments')->getNode(0)) - ->raw('))') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Constant', 'Twig\Node\Expression\Test\ConstantTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Defined.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Defined.php deleted file mode 100644 index 493098d..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Defined.php +++ /dev/null @@ -1,62 +0,0 @@ - - * {# defined works with variable names and variable attributes #} - * {% if foo is defined %} - * {# ... #} - * {% endif %} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test -{ - public function __construct(Twig_Node $node, $name, Twig_Node $arguments = null, $lineno) - { - if ($node instanceof Twig_Node_Expression_Name) { - $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_GetAttr) { - $node->setAttribute('is_defined_test', true); - $this->changeIgnoreStrictCheck($node); - } elseif ($node instanceof Twig_Node_Expression_BlockReference) { - $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name')) { - $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) { - $node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine()); - } else { - throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine()); - } - - parent::__construct($node, $name, $arguments, $lineno); - } - - private function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) - { - $node->setAttribute('optimizable', false); - $node->setAttribute('ignore_strict_check', true); - - if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) { - $this->changeIgnoreStrictCheck($node->getNode('node')); - } - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('node')); - } -} - -class_alias('Twig_Node_Expression_Test_Defined', 'Twig\Node\Expression\Test\DefinedTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Divisibleby.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Divisibleby.php deleted file mode 100644 index a5d7196..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Divisibleby.php +++ /dev/null @@ -1,35 +0,0 @@ - - * {% if loop.index is divisible by(3) %} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(0 == ') - ->subcompile($this->getNode('node')) - ->raw(' % ') - ->subcompile($this->getNode('arguments')->getNode(0)) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Divisibleby', 'Twig\Node\Expression\Test\DivisiblebyTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Even.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Even.php deleted file mode 100644 index 7e198be..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Even.php +++ /dev/null @@ -1,34 +0,0 @@ - - * {{ var is even }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Even extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' % 2 == 0') - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Even', 'Twig\Node\Expression\Test\EvenTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Null.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Null.php deleted file mode 100644 index 3746e4c..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Null.php +++ /dev/null @@ -1,33 +0,0 @@ - - * {{ var is none }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Null extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(null === ') - ->subcompile($this->getNode('node')) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Null', 'Twig\Node\Expression\Test\NullTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Odd.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Odd.php deleted file mode 100644 index 0c6c099..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Odd.php +++ /dev/null @@ -1,34 +0,0 @@ - - * {{ var is odd }} - * - * - * @author Fabien Potencier - */ -class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' % 2 == 1') - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Odd', 'Twig\Node\Expression\Test\OddTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Sameas.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Sameas.php deleted file mode 100644 index e95ff1f..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Test/Sameas.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -class Twig_Node_Expression_Test_Sameas extends Twig_Node_Expression_Test -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->raw('(') - ->subcompile($this->getNode('node')) - ->raw(' === ') - ->subcompile($this->getNode('arguments')->getNode(0)) - ->raw(')') - ; - } -} - -class_alias('Twig_Node_Expression_Test_Sameas', 'Twig\Node\Expression\Test\SameasTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Unary.php deleted file mode 100644 index 85ad1f6..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary.php +++ /dev/null @@ -1,29 +0,0 @@ - $node], [], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->raw(' '); - $this->operator($compiler); - $compiler->subcompile($this->getNode('node')); - } - - abstract public function operator(Twig_Compiler $compiler); -} - -class_alias('Twig_Node_Expression_Unary', 'Twig\Node\Expression\Unary\AbstractUnary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Neg.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Neg.php deleted file mode 100644 index 039d933..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Neg.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('-'); - } -} - -class_alias('Twig_Node_Expression_Unary_Neg', 'Twig\Node\Expression\Unary\NegUnary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Not.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Not.php deleted file mode 100644 index a0860b1..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Not.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('!'); - } -} - -class_alias('Twig_Node_Expression_Unary_Not', 'Twig\Node\Expression\Unary\NotUnary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Pos.php b/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Pos.php deleted file mode 100644 index eeff545..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Expression/Unary/Pos.php +++ /dev/null @@ -1,20 +0,0 @@ -raw('+'); - } -} - -class_alias('Twig_Node_Expression_Unary_Pos', 'Twig\Node\Expression\Unary\PosUnary', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Flush.php b/system/templateEngines/Twig/Twig2x/Node/Flush.php deleted file mode 100644 index 5d3ffd5..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Flush.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Node_Flush extends Twig_Node -{ - public function __construct($lineno, $tag) - { - parent::__construct([], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("flush();\n") - ; - } -} - -class_alias('Twig_Node_Flush', 'Twig\Node\FlushNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/For.php b/system/templateEngines/Twig/Twig2x/Node/For.php deleted file mode 100644 index 0ed1bc5..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/For.php +++ /dev/null @@ -1,113 +0,0 @@ - - */ -class Twig_Node_For extends Twig_Node -{ - private $loop; - - public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_Node $body, Twig_Node $else = null, $lineno, $tag = null) - { - $body = new Twig_Node([$body, $this->loop = new Twig_Node_ForLoop($lineno, $tag)]); - - if (null !== $ifexpr) { - $body = new Twig_Node_If(new Twig_Node([$ifexpr, $body]), null, $lineno, $tag); - } - - $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; - if (null !== $else) { - $nodes['else'] = $else; - } - - parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("\$context['_parent'] = \$context;\n") - ->write("\$context['_seq'] = twig_ensure_traversable(") - ->subcompile($this->getNode('seq')) - ->raw(");\n") - ; - - if ($this->hasNode('else')) { - $compiler->write("\$context['_iterated'] = false;\n"); - } - - if ($this->getAttribute('with_loop')) { - $compiler - ->write("\$context['loop'] = [\n") - ->write(" 'parent' => \$context['_parent'],\n") - ->write(" 'index0' => 0,\n") - ->write(" 'index' => 1,\n") - ->write(" 'first' => true,\n") - ->write("];\n") - ; - - if (!$this->getAttribute('ifexpr')) { - $compiler - ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n") - ->indent() - ->write("\$length = count(\$context['_seq']);\n") - ->write("\$context['loop']['revindex0'] = \$length - 1;\n") - ->write("\$context['loop']['revindex'] = \$length;\n") - ->write("\$context['loop']['length'] = \$length;\n") - ->write("\$context['loop']['last'] = 1 === \$length;\n") - ->outdent() - ->write("}\n") - ; - } - } - - $this->loop->setAttribute('else', $this->hasNode('else')); - $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop')); - $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr')); - - $compiler - ->write("foreach (\$context['_seq'] as ") - ->subcompile($this->getNode('key_target')) - ->raw(' => ') - ->subcompile($this->getNode('value_target')) - ->raw(") {\n") - ->indent() - ->subcompile($this->getNode('body')) - ->outdent() - ->write("}\n") - ; - - if ($this->hasNode('else')) { - $compiler - ->write("if (!\$context['_iterated']) {\n") - ->indent() - ->subcompile($this->getNode('else')) - ->outdent() - ->write("}\n") - ; - } - - $compiler->write("\$_parent = \$context['_parent'];\n"); - - // remove some "private" loop variables (needed for nested loops) - $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); - - // keep the values set in the inner context for variables defined in the outer context - $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n"); - } -} - -class_alias('Twig_Node_For', 'Twig\Node\ForNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/ForLoop.php b/system/templateEngines/Twig/Twig2x/Node/ForLoop.php deleted file mode 100644 index 31f282d..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/ForLoop.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -class Twig_Node_ForLoop extends Twig_Node -{ - public function __construct($lineno, $tag = null) - { - parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - if ($this->getAttribute('else')) { - $compiler->write("\$context['_iterated'] = true;\n"); - } - - if ($this->getAttribute('with_loop')) { - $compiler - ->write("++\$context['loop']['index0'];\n") - ->write("++\$context['loop']['index'];\n") - ->write("\$context['loop']['first'] = false;\n") - ; - - if (!$this->getAttribute('ifexpr')) { - $compiler - ->write("if (isset(\$context['loop']['length'])) {\n") - ->indent() - ->write("--\$context['loop']['revindex0'];\n") - ->write("--\$context['loop']['revindex'];\n") - ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") - ->outdent() - ->write("}\n") - ; - } - } - } -} - -class_alias('Twig_Node_ForLoop', 'Twig\Node\ForLoopNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/If.php b/system/templateEngines/Twig/Twig2x/Node/If.php deleted file mode 100644 index 2980a67..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/If.php +++ /dev/null @@ -1,68 +0,0 @@ - - */ -class Twig_Node_If extends Twig_Node -{ - public function __construct(Twig_Node $tests, Twig_Node $else = null, $lineno, $tag = null) - { - $nodes = ['tests' => $tests]; - if (null !== $else) { - $nodes['else'] = $else; - } - - parent::__construct($nodes, [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) { - if ($i > 0) { - $compiler - ->outdent() - ->write('} elseif (') - ; - } else { - $compiler - ->write('if (') - ; - } - - $compiler - ->subcompile($this->getNode('tests')->getNode($i)) - ->raw(") {\n") - ->indent() - ->subcompile($this->getNode('tests')->getNode($i + 1)) - ; - } - - if ($this->hasNode('else')) { - $compiler - ->outdent() - ->write("} else {\n") - ->indent() - ->subcompile($this->getNode('else')) - ; - } - - $compiler - ->outdent() - ->write("}\n"); - } -} - -class_alias('Twig_Node_If', 'Twig\Node\IfNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Import.php b/system/templateEngines/Twig/Twig2x/Node/Import.php deleted file mode 100644 index 44b2131..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Import.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -class Twig_Node_Import extends Twig_Node -{ - public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $var, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('') - ->subcompile($this->getNode('var')) - ->raw(' = ') - ; - - if ($this->getNode('expr') instanceof Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) { - $compiler->raw('$this'); - } else { - $compiler - ->raw('$this->loadTemplate(') - ->subcompile($this->getNode('expr')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(')') - ; - } - - $compiler->raw(";\n"); - } -} - -class_alias('Twig_Node_Import', 'Twig\Node\ImportNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Include.php b/system/templateEngines/Twig/Twig2x/Node/Include.php deleted file mode 100644 index 4b26381..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Include.php +++ /dev/null @@ -1,90 +0,0 @@ - - */ -class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) - { - $nodes = ['expr' => $expr]; - if (null !== $variables) { - $nodes['variables'] = $variables; - } - - parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - if ($this->getAttribute('ignore_missing')) { - $compiler - ->write("try {\n") - ->indent() - ; - } - - $this->addGetTemplate($compiler); - - $compiler->raw('->display('); - - $this->addTemplateArguments($compiler); - - $compiler->raw(");\n"); - - if ($this->getAttribute('ignore_missing')) { - $compiler - ->outdent() - ->write("} catch (Twig_Error_Loader \$e) {\n") - ->indent() - ->write("// ignore missing template\n") - ->outdent() - ->write("}\n\n") - ; - } - } - - protected function addGetTemplate(Twig_Compiler $compiler) - { - $compiler - ->write('$this->loadTemplate(') - ->subcompile($this->getNode('expr')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(')') - ; - } - - protected function addTemplateArguments(Twig_Compiler $compiler) - { - if (!$this->hasNode('variables')) { - $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); - } elseif (false === $this->getAttribute('only')) { - $compiler - ->raw('array_merge($context, ') - ->subcompile($this->getNode('variables')) - ->raw(')') - ; - } else { - $compiler->subcompile($this->getNode('variables')); - } - } -} - -class_alias('Twig_Node_Include', 'Twig\Node\IncludeNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Macro.php b/system/templateEngines/Twig/Twig2x/Node/Macro.php deleted file mode 100644 index 1f0d468..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Macro.php +++ /dev/null @@ -1,106 +0,0 @@ - - */ -class Twig_Node_Macro extends Twig_Node -{ - const VARARGS_NAME = 'varargs'; - - public function __construct($name, Twig_Node $body, Twig_Node $arguments, $lineno, $tag = null) - { - foreach ($arguments as $argumentName => $argument) { - if (self::VARARGS_NAME === $argumentName) { - throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine()); - } - } - - parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write(sprintf('public function macro_%s(', $this->getAttribute('name'))) - ; - - $count = count($this->getNode('arguments')); - $pos = 0; - foreach ($this->getNode('arguments') as $name => $default) { - $compiler - ->raw('$__'.$name.'__ = ') - ->subcompile($default) - ; - - if (++$pos < $count) { - $compiler->raw(', '); - } - } - - if ($count) { - $compiler->raw(', '); - } - - $compiler - ->raw('...$__varargs__') - ->raw(")\n") - ->write("{\n") - ->indent() - ; - - $compiler - ->write("\$context = \$this->env->mergeGlobals([\n") - ->indent() - ; - - foreach ($this->getNode('arguments') as $name => $default) { - $compiler - ->write('') - ->string($name) - ->raw(' => $__'.$name.'__') - ->raw(",\n") - ; - } - - $compiler - ->write('') - ->string(self::VARARGS_NAME) - ->raw(' => ') - ; - - $compiler - ->raw("\$__varargs__,\n") - ->outdent() - ->write("]);\n\n") - ->write("\$blocks = [];\n\n") - ->write("ob_start();\n") - ->write("try {\n") - ->indent() - ->subcompile($this->getNode('body')) - ->raw("\n") - ->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") - ->outdent() - ->write("} finally {\n") - ->indent() - ->write("ob_end_clean();\n") - ->outdent() - ->write("}\n") - ->outdent() - ->write("}\n\n") - ; - } -} - -class_alias('Twig_Node_Macro', 'Twig\Node\MacroNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Module.php b/system/templateEngines/Twig/Twig2x/Node/Module.php deleted file mode 100644 index 7b60746..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Module.php +++ /dev/null @@ -1,454 +0,0 @@ - - * - * @final since version 2.4.0 - */ -class Twig_Node_Module extends Twig_Node -{ - private $source; - - public function __construct(Twig_Node $body, Twig_Node_Expression $parent = null, Twig_Node $blocks, Twig_Node $macros, Twig_Node $traits, $embeddedTemplates, Twig_Source $source) - { - if (__CLASS__ !== get_class($this)) { - @trigger_error('Overriding '.__CLASS__.' is deprecated since version 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); - } - - $this->source = $source; - - $nodes = [ - 'body' => $body, - 'blocks' => $blocks, - 'macros' => $macros, - 'traits' => $traits, - 'display_start' => new Twig_Node(), - 'display_end' => new Twig_Node(), - 'constructor_start' => new Twig_Node(), - 'constructor_end' => new Twig_Node(), - 'class_end' => new Twig_Node(), - ]; - if (null !== $parent) { - $nodes['parent'] = $parent; - } - - // embedded templates are set as attributes so that they are only visited once by the visitors - parent::__construct($nodes, [ - 'index' => null, - 'embedded_templates' => $embeddedTemplates, - ], 1); - - // populate the template name of all node children - $this->setTemplateName($this->source->getName()); - } - - public function setIndex($index) - { - $this->setAttribute('index', $index); - } - - public function compile(Twig_Compiler $compiler) - { - $this->compileTemplate($compiler); - - foreach ($this->getAttribute('embedded_templates') as $template) { - $compiler->subcompile($template); - } - } - - protected function compileTemplate(Twig_Compiler $compiler) - { - if (!$this->getAttribute('index')) { - $compiler->write('compileClassHeader($compiler); - - $this->compileConstructor($compiler); - - $this->compileGetParent($compiler); - - $this->compileDisplay($compiler); - - $compiler->subcompile($this->getNode('blocks')); - - $this->compileMacros($compiler); - - $this->compileGetTemplateName($compiler); - - $this->compileIsTraitable($compiler); - - $this->compileDebugInfo($compiler); - - $this->compileGetSourceContext($compiler); - - $this->compileClassFooter($compiler); - } - - protected function compileGetParent(Twig_Compiler $compiler) - { - if (!$this->hasNode('parent')) { - return; - } - $parent = $this->getNode('parent'); - - $compiler - ->write("protected function doGetParent(array \$context)\n", "{\n") - ->indent() - ->addDebugInfo($parent) - ->write('return ') - ; - - if ($parent instanceof Twig_Node_Expression_Constant) { - $compiler->subcompile($parent); - } else { - $compiler - ->raw('$this->loadTemplate(') - ->subcompile($parent) - ->raw(', ') - ->repr($this->source->getName()) - ->raw(', ') - ->repr($parent->getTemplateLine()) - ->raw(')') - ; - } - - $compiler - ->raw(";\n") - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileClassHeader(Twig_Compiler $compiler) - { - $compiler - ->write("\n\n") - // if the template name contains */, add a blank to avoid a PHP parse error - ->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n") - ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index'))) - ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) - ->write("{\n") - ->indent() - ->write("private \$source;\n\n") - ; - } - - protected function compileConstructor(Twig_Compiler $compiler) - { - $compiler - ->write("public function __construct(Twig_Environment \$env)\n", "{\n") - ->indent() - ->subcompile($this->getNode('constructor_start')) - ->write("parent::__construct(\$env);\n\n") - ->write("\$this->source = \$this->getSourceContext();\n\n") - ; - - // parent - if (!$this->hasNode('parent')) { - $compiler->write("\$this->parent = false;\n\n"); - } elseif (($parent = $this->getNode('parent')) && $parent instanceof Twig_Node_Expression_Constant) { - $compiler - ->addDebugInfo($parent) - ->write('$this->parent = $this->loadTemplate(') - ->subcompile($parent) - ->raw(', ') - ->repr($this->source->getName()) - ->raw(', ') - ->repr($parent->getTemplateLine()) - ->raw(");\n") - ; - } - - $countTraits = count($this->getNode('traits')); - if ($countTraits) { - // traits - foreach ($this->getNode('traits') as $i => $trait) { - $node = $trait->getNode('template'); - - $compiler - ->write(sprintf('$_trait_%s = $this->loadTemplate(', $i)) - ->subcompile($node) - ->raw(', ') - ->repr($node->getTemplateName()) - ->raw(', ') - ->repr($node->getTemplateLine()) - ->raw(");\n") - ; - - $compiler - ->addDebugInfo($trait->getNode('template')) - ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) - ->indent() - ->write("throw new Twig_Error_Runtime('Template \"'.") - ->subcompile($trait->getNode('template')) - ->raw(".'\" cannot be used as a trait.', ") - ->repr($node->getTemplateLine()) - ->raw(", \$this->source);\n") - ->outdent() - ->write("}\n") - ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i)) - ; - - foreach ($trait->getNode('targets') as $key => $value) { - $compiler - ->write(sprintf('if (!isset($_trait_%s_blocks[', $i)) - ->string($key) - ->raw("])) {\n") - ->indent() - ->write("throw new Twig_Error_Runtime('Block ") - ->string($key) - ->raw(' is not defined in trait ') - ->subcompile($trait->getNode('template')) - ->raw(".', ") - ->repr($node->getTemplateLine()) - ->raw(", \$this->source);\n") - ->outdent() - ->write("}\n\n") - - ->write(sprintf('$_trait_%s_blocks[', $i)) - ->subcompile($value) - ->raw(sprintf('] = $_trait_%s_blocks[', $i)) - ->string($key) - ->raw(sprintf(']; unset($_trait_%s_blocks[', $i)) - ->string($key) - ->raw("]);\n\n") - ; - } - } - - if ($countTraits > 1) { - $compiler - ->write("\$this->traits = array_merge(\n") - ->indent() - ; - - for ($i = 0; $i < $countTraits; ++$i) { - $compiler - ->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i)) - ; - } - - $compiler - ->outdent() - ->write(");\n\n") - ; - } else { - $compiler - ->write("\$this->traits = \$_trait_0_blocks;\n\n") - ; - } - - $compiler - ->write("\$this->blocks = array_merge(\n") - ->indent() - ->write("\$this->traits,\n") - ->write("[\n") - ; - } else { - $compiler - ->write("\$this->blocks = [\n") - ; - } - - // blocks - $compiler - ->indent() - ; - - foreach ($this->getNode('blocks') as $name => $node) { - $compiler - ->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name)) - ; - } - - if ($countTraits) { - $compiler - ->outdent() - ->write("]\n") - ->outdent() - ->write(");\n") - ; - } else { - $compiler - ->outdent() - ->write("];\n") - ; - } - - $compiler - ->outdent() - ->subcompile($this->getNode('constructor_end')) - ->write("}\n\n") - ; - } - - protected function compileDisplay(Twig_Compiler $compiler) - { - $compiler - ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") - ->indent() - ->subcompile($this->getNode('display_start')) - ->subcompile($this->getNode('body')) - ; - - if ($this->hasNode('parent')) { - $parent = $this->getNode('parent'); - $compiler->addDebugInfo($parent); - if ($parent instanceof Twig_Node_Expression_Constant) { - $compiler->write('$this->parent'); - } else { - $compiler->write('$this->getParent($context)'); - } - $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n"); - } - - $compiler - ->subcompile($this->getNode('display_end')) - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileClassFooter(Twig_Compiler $compiler) - { - $compiler - ->subcompile($this->getNode('class_end')) - ->outdent() - ->write("}\n") - ; - } - - protected function compileMacros(Twig_Compiler $compiler) - { - $compiler->subcompile($this->getNode('macros')); - } - - protected function compileGetTemplateName(Twig_Compiler $compiler) - { - $compiler - ->write("public function getTemplateName()\n", "{\n") - ->indent() - ->write('return ') - ->repr($this->source->getName()) - ->raw(";\n") - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileIsTraitable(Twig_Compiler $compiler) - { - // A template can be used as a trait if: - // * it has no parent - // * it has no macros - // * it has no body - // - // Put another way, a template can be used as a trait if it - // only contains blocks and use statements. - $traitable = !$this->hasNode('parent') && 0 === count($this->getNode('macros')); - if ($traitable) { - if ($this->getNode('body') instanceof Twig_Node_Body) { - $nodes = $this->getNode('body')->getNode(0); - } else { - $nodes = $this->getNode('body'); - } - - if (!count($nodes)) { - $nodes = new Twig_Node([$nodes]); - } - - foreach ($nodes as $node) { - if (!count($node)) { - continue; - } - - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { - continue; - } - - if ($node instanceof Twig_Node_BlockReference) { - continue; - } - - $traitable = false; - break; - } - } - - if ($traitable) { - return; - } - - $compiler - ->write("public function isTraitable()\n", "{\n") - ->indent() - ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false')) - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileDebugInfo(Twig_Compiler $compiler) - { - $compiler - ->write("public function getDebugInfo()\n", "{\n") - ->indent() - ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true)))) - ->outdent() - ->write("}\n\n") - ; - } - - protected function compileGetSourceContext(Twig_Compiler $compiler) - { - $compiler - ->write("public function getSourceContext()\n", "{\n") - ->indent() - ->write('return new Twig_Source(') - ->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '') - ->raw(', ') - ->string($this->source->getName()) - ->raw(', ') - ->string($this->source->getPath()) - ->raw(");\n") - ->outdent() - ->write("}\n") - ; - } - - protected function compileLoadTemplate(Twig_Compiler $compiler, $node, $var) - { - if ($node instanceof Twig_Node_Expression_Constant) { - $compiler - ->write(sprintf('%s = $this->loadTemplate(', $var)) - ->subcompile($node) - ->raw(', ') - ->repr($node->getTemplateName()) - ->raw(', ') - ->repr($node->getTemplateLine()) - ->raw(");\n") - ; - } else { - throw new LogicException('Trait templates can only be constant nodes.'); - } - } -} - -class_alias('Twig_Node_Module', 'Twig\Node\ModuleNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Print.php b/system/templateEngines/Twig/Twig2x/Node/Print.php deleted file mode 100644 index 215d712..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Print.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) - { - parent::__construct(['expr' => $expr], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo ') - ->subcompile($this->getNode('expr')) - ->raw(";\n") - ; - } -} - -class_alias('Twig_Node_Print', 'Twig\Node\PrintNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Sandbox.php b/system/templateEngines/Twig/Twig2x/Node/Sandbox.php deleted file mode 100644 index 4976f74..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Sandbox.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -class Twig_Node_Sandbox extends Twig_Node -{ - public function __construct(Twig_Node $body, $lineno, $tag = null) - { - parent::__construct(['body' => $body], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("\$sandbox = \$this->extensions['Twig_Extension_Sandbox'];\n") - ->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n") - ->indent() - ->write("\$sandbox->enableSandbox();\n") - ->outdent() - ->write("}\n") - ->subcompile($this->getNode('body')) - ->write("if (!\$alreadySandboxed) {\n") - ->indent() - ->write("\$sandbox->disableSandbox();\n") - ->outdent() - ->write("}\n") - ; - } -} - -class_alias('Twig_Node_Sandbox', 'Twig\Node\SandboxNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/SandboxedPrint.php b/system/templateEngines/Twig/Twig2x/Node/SandboxedPrint.php deleted file mode 100644 index eb45cb8..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/SandboxedPrint.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -class Twig_Node_SandboxedPrint extends Twig_Node_Print -{ - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo $this->extensions[\'Twig_Extension_Sandbox\']->ensureToStringAllowed(') - ->subcompile($this->getNode('expr')) - ->raw(");\n") - ; - } - - /** - * Removes node filters. - * - * This is mostly needed when another visitor adds filters (like the escaper one). - * - * @return Twig_Node - */ - private function removeNodeFilter(Twig_Node $node) - { - if ($node instanceof Twig_Node_Expression_Filter) { - return $this->removeNodeFilter($node->getNode('node')); - } - - return $node; - } -} - -class_alias('Twig_Node_SandboxedPrint', 'Twig\Node\SandboxedPrintNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Set.php b/system/templateEngines/Twig/Twig2x/Node/Set.php deleted file mode 100644 index 0db7309..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Set.php +++ /dev/null @@ -1,98 +0,0 @@ - - */ -class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface -{ - public function __construct($capture, Twig_Node $names, Twig_Node $values, $lineno, $tag = null) - { - parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag); - - /* - * Optimizes the node when capture is used for a large block of text. - * - * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo"); - */ - if ($this->getAttribute('capture')) { - $this->setAttribute('safe', true); - - $values = $this->getNode('values'); - if ($values instanceof Twig_Node_Text) { - $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getTemplateLine())); - $this->setAttribute('capture', false); - } - } - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - if (count($this->getNode('names')) > 1) { - $compiler->write('list('); - foreach ($this->getNode('names') as $idx => $node) { - if ($idx) { - $compiler->raw(', '); - } - - $compiler->subcompile($node); - } - $compiler->raw(')'); - } else { - if ($this->getAttribute('capture')) { - $compiler - ->write("ob_start();\n") - ->subcompile($this->getNode('values')) - ; - } - - $compiler->subcompile($this->getNode('names'), false); - - if ($this->getAttribute('capture')) { - $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())"); - } - } - - if (!$this->getAttribute('capture')) { - $compiler->raw(' = '); - - if (count($this->getNode('names')) > 1) { - $compiler->write('['); - foreach ($this->getNode('values') as $idx => $value) { - if ($idx) { - $compiler->raw(', '); - } - - $compiler->subcompile($value); - } - $compiler->raw(']'); - } else { - if ($this->getAttribute('safe')) { - $compiler - ->raw("('' === \$tmp = ") - ->subcompile($this->getNode('values')) - ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())") - ; - } else { - $compiler->subcompile($this->getNode('values')); - } - } - } - - $compiler->raw(";\n"); - } -} - -class_alias('Twig_Node_Set', 'Twig\Node\SetNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Spaceless.php b/system/templateEngines/Twig/Twig2x/Node/Spaceless.php deleted file mode 100644 index 06604f7..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Spaceless.php +++ /dev/null @@ -1,37 +0,0 @@ - - */ -class Twig_Node_Spaceless extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct(Twig_Node $body, $lineno, $tag = 'spaceless') - { - parent::__construct(['body' => $body], [], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("ob_start();\n") - ->subcompile($this->getNode('body')) - ->write("echo trim(preg_replace('/>\s+<', ob_get_clean()));\n") - ; - } -} - -class_alias('Twig_Node_Spaceless', 'Twig\Node\SpacelessNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/Text.php b/system/templateEngines/Twig/Twig2x/Node/Text.php deleted file mode 100644 index ab24d71..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/Text.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface -{ - public function __construct($data, $lineno) - { - parent::__construct([], ['data' => $data], $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write('echo ') - ->string($this->getAttribute('data')) - ->raw(";\n") - ; - } -} - -class_alias('Twig_Node_Text', 'Twig\Node\TextNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Node/With.php b/system/templateEngines/Twig/Twig2x/Node/With.php deleted file mode 100644 index c573c81..0000000 --- a/system/templateEngines/Twig/Twig2x/Node/With.php +++ /dev/null @@ -1,66 +0,0 @@ - - */ -class Twig_Node_With extends Twig_Node -{ - public function __construct(Twig_Node $body, Twig_Node $variables = null, $only = false, $lineno, $tag = null) - { - $nodes = ['body' => $body]; - if (null !== $variables) { - $nodes['variables'] = $variables; - } - - parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); - - if ($this->hasNode('variables')) { - $varsName = $compiler->getVarName(); - $compiler - ->write(sprintf('$%s = ', $varsName)) - ->subcompile($this->getNode('variables')) - ->raw(";\n") - ->write(sprintf("if (!is_array(\$%s)) {\n", $varsName)) - ->indent() - ->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.', ") - ->repr($this->getTemplateLine()) - ->raw(", \$this->source);\n") - ->outdent() - ->write("}\n") - ; - - if ($this->getAttribute('only')) { - $compiler->write("\$context = ['_parent' => \$context];\n"); - } else { - $compiler->write("\$context['_parent'] = \$context;\n"); - } - - $compiler->write(sprintf("\$context = array_merge(\$context, \$%s);\n", $varsName)); - } else { - $compiler->write("\$context['_parent'] = \$context;\n"); - } - - $compiler - ->subcompile($this->getNode('body')) - ->write("\$context = \$context['_parent'];\n") - ; - } -} - -class_alias('Twig_Node_With', 'Twig\Node\WithNode', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeCaptureInterface.php b/system/templateEngines/Twig/Twig2x/NodeCaptureInterface.php deleted file mode 100644 index 6638834..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeCaptureInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -interface Twig_NodeCaptureInterface -{ -} - -class_alias('Twig_NodeCaptureInterface', 'Twig\Node\NodeCaptureInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeOutputInterface.php b/system/templateEngines/Twig/Twig2x/NodeOutputInterface.php deleted file mode 100644 index 5a8eaa9..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeOutputInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -interface Twig_NodeOutputInterface -{ -} - -class_alias('Twig_NodeOutputInterface', 'Twig\Node\NodeOutputInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeTraverser.php b/system/templateEngines/Twig/Twig2x/NodeTraverser.php deleted file mode 100644 index bca741e..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeTraverser.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ -final class Twig_NodeTraverser -{ - private $env; - private $visitors = []; - - /** - * @param Twig_Environment $env - * @param Twig_NodeVisitorInterface[] $visitors - */ - public function __construct(Twig_Environment $env, array $visitors = []) - { - $this->env = $env; - foreach ($visitors as $visitor) { - $this->addVisitor($visitor); - } - } - - public function addVisitor(Twig_NodeVisitorInterface $visitor) - { - if (!isset($this->visitors[$visitor->getPriority()])) { - $this->visitors[$visitor->getPriority()] = []; - } - - $this->visitors[$visitor->getPriority()][] = $visitor; - } - - /** - * Traverses a node and calls the registered visitors. - * - * @return Twig_Node - */ - public function traverse(Twig_Node $node) - { - ksort($this->visitors); - foreach ($this->visitors as $visitors) { - foreach ($visitors as $visitor) { - $node = $this->traverseForVisitor($visitor, $node); - } - } - - return $node; - } - - private function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_Node $node) - { - $node = $visitor->enterNode($node, $this->env); - - foreach ($node as $k => $n) { - if (false !== $m = $this->traverseForVisitor($visitor, $n)) { - if ($m !== $n) { - $node->setNode($k, $m); - } - } else { - $node->removeNode($k); - } - } - - return $visitor->leaveNode($node, $this->env); - } -} - -class_alias('Twig_NodeTraverser', 'Twig\NodeTraverser', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeVisitor/Escaper.php b/system/templateEngines/Twig/Twig2x/NodeVisitor/Escaper.php deleted file mode 100644 index 628a195..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeVisitor/Escaper.php +++ /dev/null @@ -1,152 +0,0 @@ - - */ -final class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor -{ - private $statusStack = []; - private $blocks = []; - private $safeAnalysis; - private $traverser; - private $defaultStrategy = false; - private $safeVars = []; - - public function __construct() - { - $this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis(); - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getTemplateName())) { - $this->defaultStrategy = $defaultStrategy; - } - $this->safeVars = []; - $this->blocks = []; - } elseif ($node instanceof Twig_Node_AutoEscape) { - $this->statusStack[] = $node->getAttribute('value'); - } elseif ($node instanceof Twig_Node_Block) { - $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); - } elseif ($node instanceof Twig_Node_Import) { - $this->safeVars[] = $node->getNode('var')->getAttribute('name'); - } - - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $this->defaultStrategy = false; - $this->safeVars = []; - $this->blocks = []; - } elseif ($node instanceof Twig_Node_Expression_Filter) { - return $this->preEscapeFilterNode($node, $env); - } elseif ($node instanceof Twig_Node_Print) { - return $this->escapePrintNode($node, $env, $this->needEscaping($env)); - } - - if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) { - array_pop($this->statusStack); - } elseif ($node instanceof Twig_Node_BlockReference) { - $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); - } - - return $node; - } - - private function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type) - { - if (false === $type) { - return $node; - } - - $expression = $node->getNode('expr'); - - if ($this->isSafeFor($type, $expression, $env)) { - return $node; - } - - $class = get_class($node); - - return new $class( - $this->getEscaperFilter($type, $expression), - $node->getTemplateLine() - ); - } - - private function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env) - { - $name = $filter->getNode('filter')->getAttribute('value'); - - $type = $env->getFilter($name)->getPreEscape(); - if (null === $type) { - return $filter; - } - - $node = $filter->getNode('node'); - if ($this->isSafeFor($type, $node, $env)) { - return $filter; - } - - $filter->setNode('node', $this->getEscaperFilter($type, $node)); - - return $filter; - } - - private function isSafeFor($type, Twig_Node $expression, $env) - { - $safe = $this->safeAnalysis->getSafe($expression); - - if (null === $safe) { - if (null === $this->traverser) { - $this->traverser = new Twig_NodeTraverser($env, [$this->safeAnalysis]); - } - - $this->safeAnalysis->setSafeVars($this->safeVars); - - $this->traverser->traverse($expression); - $safe = $this->safeAnalysis->getSafe($expression); - } - - return in_array($type, $safe) || in_array('all', $safe); - } - - private function needEscaping(Twig_Environment $env) - { - if (count($this->statusStack)) { - return $this->statusStack[count($this->statusStack) - 1]; - } - - return $this->defaultStrategy ? $this->defaultStrategy : false; - } - - private function getEscaperFilter($type, Twig_Node $node) - { - $line = $node->getTemplateLine(); - $name = new Twig_Node_Expression_Constant('escape', $line); - $args = new Twig_Node([new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)]); - - return new Twig_Node_Expression_Filter($node, $name, $args, $line); - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_NodeVisitor_Escaper', 'Twig\NodeVisitor\EscaperNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeVisitor/Optimizer.php b/system/templateEngines/Twig/Twig2x/NodeVisitor/Optimizer.php deleted file mode 100644 index 1210571..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeVisitor/Optimizer.php +++ /dev/null @@ -1,207 +0,0 @@ - - */ -final class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor -{ - const OPTIMIZE_ALL = -1; - const OPTIMIZE_NONE = 0; - const OPTIMIZE_FOR = 2; - const OPTIMIZE_RAW_FILTER = 4; - // obsolete, does not do anything - const OPTIMIZE_VAR_ACCESS = 8; - - private $loops = []; - private $loopsTargets = []; - private $optimizers; - - /** - * @param int $optimizers The optimizer mode - */ - public function __construct($optimizers = -1) - { - if (!is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) { - throw new InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers)); - } - - $this->optimizers = $optimizers; - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { - $this->enterOptimizeFor($node, $env); - } - - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { - $this->leaveOptimizeFor($node, $env); - } - - if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) { - $node = $this->optimizeRawFilter($node, $env); - } - - $node = $this->optimizePrintNode($node, $env); - - return $node; - } - - /** - * Optimizes print nodes. - * - * It replaces: - * - * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" - * - * @return Twig_Node - */ - private function optimizePrintNode(Twig_Node $node, Twig_Environment $env) - { - if (!$node instanceof Twig_Node_Print) { - return $node; - } - - $exprNode = $node->getNode('expr'); - if ( - $exprNode instanceof Twig_Node_Expression_BlockReference || - $exprNode instanceof Twig_Node_Expression_Parent - ) { - $exprNode->setAttribute('output', true); - - return $exprNode; - } - - return $node; - } - - /** - * Removes "raw" filters. - * - * @return Twig_Node - */ - private function optimizeRawFilter(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Expression_Filter && 'raw' == $node->getNode('filter')->getAttribute('value')) { - return $node->getNode('node'); - } - - return $node; - } - - /** - * Optimizes "for" tag by removing the "loop" variable creation whenever possible. - */ - private function enterOptimizeFor(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_For) { - // disable the loop variable by default - $node->setAttribute('with_loop', false); - array_unshift($this->loops, $node); - array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); - array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); - } elseif (!$this->loops) { - // we are outside a loop - return; - } - - // when do we need to add the loop variable back? - - // the loop variable is referenced for the current loop - elseif ($node instanceof Twig_Node_Expression_Name && 'loop' === $node->getAttribute('name')) { - $node->setAttribute('always_defined', true); - $this->addLoopToCurrent(); - } - - // optimize access to loop targets - elseif ($node instanceof Twig_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) { - $node->setAttribute('always_defined', true); - } - - // block reference - elseif ($node instanceof Twig_Node_BlockReference || $node instanceof Twig_Node_Expression_BlockReference) { - $this->addLoopToCurrent(); - } - - // include without the only attribute - elseif ($node instanceof Twig_Node_Include && !$node->getAttribute('only')) { - $this->addLoopToAll(); - } - - // include function without the with_context=false parameter - elseif ($node instanceof Twig_Node_Expression_Function - && 'include' === $node->getAttribute('name') - && (!$node->getNode('arguments')->hasNode('with_context') - || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') - ) - ) { - $this->addLoopToAll(); - } - - // the loop variable is referenced via an attribute - elseif ($node instanceof Twig_Node_Expression_GetAttr - && (!$node->getNode('attribute') instanceof Twig_Node_Expression_Constant - || 'parent' === $node->getNode('attribute')->getAttribute('value') - ) - && (true === $this->loops[0]->getAttribute('with_loop') - || ($node->getNode('node') instanceof Twig_Node_Expression_Name - && 'loop' === $node->getNode('node')->getAttribute('name') - ) - ) - ) { - $this->addLoopToAll(); - } - } - - /** - * Optimizes "for" tag by removing the "loop" variable creation whenever possible. - */ - private function leaveOptimizeFor(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_For) { - array_shift($this->loops); - array_shift($this->loopsTargets); - array_shift($this->loopsTargets); - } - } - - private function addLoopToCurrent() - { - $this->loops[0]->setAttribute('with_loop', true); - } - - private function addLoopToAll() - { - foreach ($this->loops as $loop) { - $loop->setAttribute('with_loop', true); - } - } - - public function getPriority() - { - return 255; - } -} - -class_alias('Twig_NodeVisitor_Optimizer', 'Twig\NodeVisitor\OptimizerNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeVisitor/SafeAnalysis.php b/system/templateEngines/Twig/Twig2x/NodeVisitor/SafeAnalysis.php deleted file mode 100644 index 64f93b8..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeVisitor/SafeAnalysis.php +++ /dev/null @@ -1,146 +0,0 @@ -safeVars = $safeVars; - } - - public function getSafe(Twig_Node $node) - { - $hash = spl_object_hash($node); - if (!isset($this->data[$hash])) { - return; - } - - foreach ($this->data[$hash] as $bucket) { - if ($bucket['key'] !== $node) { - continue; - } - - if (in_array('html_attr', $bucket['value'])) { - $bucket['value'][] = 'html'; - } - - return $bucket['value']; - } - } - - private function setSafe(Twig_Node $node, array $safe) - { - $hash = spl_object_hash($node); - if (isset($this->data[$hash])) { - foreach ($this->data[$hash] as &$bucket) { - if ($bucket['key'] === $node) { - $bucket['value'] = $safe; - - return; - } - } - } - $this->data[$hash][] = [ - 'key' => $node, - 'value' => $safe, - ]; - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Expression_Constant) { - // constants are marked safe for all - $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_BlockReference) { - // blocks are safe by definition - $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_Parent) { - // parent block is safe by definition - $this->setSafe($node, ['all']); - } elseif ($node instanceof Twig_Node_Expression_Conditional) { - // intersect safeness of both operands - $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); - $this->setSafe($node, $safe); - } elseif ($node instanceof Twig_Node_Expression_Filter) { - // filter expression is safe when the filter is safe - $name = $node->getNode('filter')->getAttribute('value'); - $args = $node->getNode('arguments'); - if (false !== $filter = $env->getFilter($name)) { - $safe = $filter->getSafe($args); - if (null === $safe) { - $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety()); - } - $this->setSafe($node, $safe); - } else { - $this->setSafe($node, []); - } - } elseif ($node instanceof Twig_Node_Expression_Function) { - // function expression is safe when the function is safe - $name = $node->getAttribute('name'); - $args = $node->getNode('arguments'); - $function = $env->getFunction($name); - if (false !== $function) { - $this->setSafe($node, $function->getSafe($args)); - } else { - $this->setSafe($node, []); - } - } elseif ($node instanceof Twig_Node_Expression_MethodCall) { - if ($node->getAttribute('safe')) { - $this->setSafe($node, ['all']); - } else { - $this->setSafe($node, []); - } - } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) { - $name = $node->getNode('node')->getAttribute('name'); - if (in_array($name, $this->safeVars)) { - $this->setSafe($node, ['all']); - } else { - $this->setSafe($node, []); - } - } else { - $this->setSafe($node, []); - } - - return $node; - } - - private function intersectSafe(array $a = null, array $b = null) - { - if (null === $a || null === $b) { - return []; - } - - if (in_array('all', $a)) { - return $b; - } - - if (in_array('all', $b)) { - return $a; - } - - return array_intersect($a, $b); - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_NodeVisitor_SafeAnalysis', 'Twig\NodeVisitor\SafeAnalysisNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeVisitor/Sandbox.php b/system/templateEngines/Twig/Twig2x/NodeVisitor/Sandbox.php deleted file mode 100644 index 4d41ff6..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeVisitor/Sandbox.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ -final class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor -{ - private $inAModule = false; - private $tags; - private $filters; - private $functions; - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $this->inAModule = true; - $this->tags = []; - $this->filters = []; - $this->functions = []; - - return $node; - } elseif ($this->inAModule) { - // look for tags - if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { - $this->tags[$node->getNodeTag()] = $node; - } - - // look for filters - if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { - $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; - } - - // look for functions - if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) { - $this->functions[$node->getAttribute('name')] = $node; - } - - // the .. operator is equivalent to the range() function - if ($node instanceof Twig_Node_Expression_Binary_Range && !isset($this->functions['range'])) { - $this->functions['range'] = $node; - } - - // wrap print to check __toString() calls - if ($node instanceof Twig_Node_Print) { - return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag()); - } - } - - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $this->inAModule = false; - - $node->setNode('display_start', new Twig_Node([new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); - } - - return $node; - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_NodeVisitor_Sandbox', 'Twig\NodeVisitor\SandboxNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig2x/NodeVisitorInterface.php b/system/templateEngines/Twig/Twig2x/NodeVisitorInterface.php deleted file mode 100644 index 6276a31..0000000 --- a/system/templateEngines/Twig/Twig2x/NodeVisitorInterface.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -interface Twig_NodeVisitorInterface -{ - /** - * Called before child nodes are visited. - * - * @return Twig_Node The modified node - */ - public function enterNode(Twig_Node $node, Twig_Environment $env); - - /** - * Called after child nodes are visited. - * - * @return Twig_Node|false The modified node or false if the node must be removed - */ - public function leaveNode(Twig_Node $node, Twig_Environment $env); - - /** - * Returns the priority for this visitor. - * - * Priority should be between -10 and 10 (0 is the default). - * - * @return int The priority level - */ - public function getPriority(); -} - -class_alias('Twig_NodeVisitorInterface', 'Twig\NodeVisitor\NodeVisitorInterface', false); -class_exists('Twig_Environment'); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig2x/Parser.php b/system/templateEngines/Twig/Twig2x/Parser.php deleted file mode 100644 index 43c5ea0..0000000 --- a/system/templateEngines/Twig/Twig2x/Parser.php +++ /dev/null @@ -1,377 +0,0 @@ - - */ -class Twig_Parser -{ - private $stack = []; - private $stream; - private $parent; - private $handlers; - private $visitors; - private $expressionParser; - private $blocks; - private $blockStack; - private $macros; - private $env; - private $importedSymbols; - private $traits; - private $embeddedTemplates = []; - private $varNameSalt = 0; - - public function __construct(Twig_Environment $env) - { - $this->env = $env; - } - - public function getVarName() - { - return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++)); - } - - public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) - { - $vars = get_object_vars($this); - unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']); - $this->stack[] = $vars; - - // tag handlers - if (null === $this->handlers) { - $this->handlers = []; - foreach ($this->env->getTokenParsers() as $handler) { - $handler->setParser($this); - - $this->handlers[$handler->getTag()] = $handler; - } - } - - // node visitors - if (null === $this->visitors) { - $this->visitors = $this->env->getNodeVisitors(); - } - - if (null === $this->expressionParser) { - $this->expressionParser = new Twig_ExpressionParser($this, $this->env); - } - - $this->stream = $stream; - $this->parent = null; - $this->blocks = []; - $this->macros = []; - $this->traits = []; - $this->blockStack = []; - $this->importedSymbols = [[]]; - $this->embeddedTemplates = []; - $this->varNameSalt = 0; - - try { - $body = $this->subparse($test, $dropNeedle); - - if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { - $body = new Twig_Node(); - } - } catch (Twig_Error_Syntax $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($this->stream->getSourceContext()); - } - - if (!$e->getTemplateLine()) { - $e->setTemplateLine($this->stream->getCurrent()->getLine()); - } - - throw $e; - } - - $node = new Twig_Node_Module(new Twig_Node_Body([$body]), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); - - $traverser = new Twig_NodeTraverser($this->env, $this->visitors); - - $node = $traverser->traverse($node); - - // restore previous stack so previous parse() call can resume working - foreach (array_pop($this->stack) as $key => $val) { - $this->$key = $val; - } - - return $node; - } - - public function subparse($test, $dropNeedle = false) - { - $lineno = $this->getCurrentToken()->getLine(); - $rv = []; - while (!$this->stream->isEOF()) { - switch ($this->getCurrentToken()->getType()) { - case /* Twig_Token::TEXT_TYPE */ 0: - $token = $this->stream->next(); - $rv[] = new Twig_Node_Text($token->getValue(), $token->getLine()); - break; - - case /* Twig_Token::VAR_START_TYPE */ 2: - $token = $this->stream->next(); - $expr = $this->expressionParser->parseExpression(); - $this->stream->expect(/* Twig_Token::VAR_END_TYPE */ 4); - $rv[] = new Twig_Node_Print($expr, $token->getLine()); - break; - - case /* Twig_Token::BLOCK_START_TYPE */ 1: - $this->stream->next(); - $token = $this->getCurrentToken(); - - if (/* Twig_Token::NAME_TYPE */ 5 !== $token->getType()) { - throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); - } - - if (null !== $test && $test($token)) { - if ($dropNeedle) { - $this->stream->next(); - } - - if (1 === count($rv)) { - return $rv[0]; - } - - return new Twig_Node($rv, [], $lineno); - } - - if (!isset($this->handlers[$token->getValue()])) { - if (null !== $test) { - $e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - - if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { - $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); - } - } else { - $e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); - } - - throw $e; - } - - $this->stream->next(); - - $subparser = $this->handlers[$token->getValue()]; - $node = $subparser->parse($token); - if (null !== $node) { - $rv[] = $node; - } - break; - - default: - throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); - } - } - - if (1 === count($rv)) { - return $rv[0]; - } - - return new Twig_Node($rv, [], $lineno); - } - - public function getBlockStack() - { - return $this->blockStack; - } - - public function peekBlockStack() - { - return $this->blockStack[count($this->blockStack) - 1]; - } - - public function popBlockStack() - { - array_pop($this->blockStack); - } - - public function pushBlockStack($name) - { - $this->blockStack[] = $name; - } - - public function hasBlock($name) - { - return isset($this->blocks[$name]); - } - - public function getBlock($name) - { - return $this->blocks[$name]; - } - - public function setBlock($name, Twig_Node_Block $value) - { - $this->blocks[$name] = new Twig_Node_Body([$value], [], $value->getTemplateLine()); - } - - public function hasMacro($name) - { - return isset($this->macros[$name]); - } - - public function setMacro($name, Twig_Node_Macro $node) - { - $this->macros[$name] = $node; - } - - public function isReservedMacroName($name) - { - return false; - } - - public function addTrait($trait) - { - $this->traits[] = $trait; - } - - public function hasTraits() - { - return count($this->traits) > 0; - } - - public function embedTemplate(Twig_Node_Module $template) - { - $template->setIndex(mt_rand()); - - $this->embeddedTemplates[] = $template; - } - - public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null) - { - $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; - } - - public function getImportedSymbol($type, $alias) - { - foreach ($this->importedSymbols as $functions) { - if (isset($functions[$type][$alias])) { - return $functions[$type][$alias]; - } - } - } - - public function isMainScope() - { - return 1 === count($this->importedSymbols); - } - - public function pushLocalScope() - { - array_unshift($this->importedSymbols, []); - } - - public function popLocalScope() - { - array_shift($this->importedSymbols); - } - - /** - * @return Twig_ExpressionParser - */ - public function getExpressionParser() - { - return $this->expressionParser; - } - - public function getParent() - { - return $this->parent; - } - - public function setParent($parent) - { - $this->parent = $parent; - } - - /** - * @return Twig_TokenStream - */ - public function getStream() - { - return $this->stream; - } - - /** - * @return Twig_Token - */ - public function getCurrentToken() - { - return $this->stream->getCurrent(); - } - - private function filterBodyNodes(Twig_Node $node, $nested = false) - { - // check that the body does not contain non-empty output nodes - if ( - ($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data'))) - || - // the "&& !$node instanceof Twig_Node_Spaceless" part of the condition must be removed in 3.0 - (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && ($node instanceof Twig_NodeOutputInterface && !$node instanceof Twig_Node_Spaceless)) - ) { - if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) { - $t = substr($node->getAttribute('data'), 3); - if ('' === $t || ctype_space($t)) { - // bypass empty nodes starting with a BOM - return; - } - } - - throw new Twig_Error_Syntax('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); - } - - // bypass nodes that "capture" the output - if ($node instanceof Twig_NodeCaptureInterface) { - // a "block" tag in such a node will serve as a block definition AND be displayed in place as well - return $node; - } - - // to be removed completely in Twig 3.0 - if (!$nested && $node instanceof Twig_Node_Spaceless) { - @trigger_error(sprintf('Using the spaceless tag at the root level of a child template in "%s" at line %d is deprecated since version 2.5.0 and will become a syntax error in 3.0.', $this->stream->getSourceContext()->getName(), $node->getTemplateLine()), E_USER_DEPRECATED); - } - - // "block" tags that are not captured (see above) are only used for defining - // the content of the block. In such a case, nesting it does not work as - // expected as the definition is not part of the default template code flow. - if ($nested && $node instanceof Twig_Node_BlockReference) { - //throw new Twig_Error_Syntax('A block definition cannot be nested under non-capturing nodes.', $node->getTemplateLine(), $this->stream->getSourceContext()); - @trigger_error(sprintf('Nesting a block definition under a non-capturing node in "%s" at line %d is deprecated since version 2.5.0 and will become a syntax error in 3.0.', $this->stream->getSourceContext()->getName(), $node->getTemplateLine()), E_USER_DEPRECATED); - - return; - } - - // the "&& !$node instanceof Twig_Node_Spaceless" part of the condition must be removed in 3.0 - if ($node instanceof Twig_NodeOutputInterface && !$node instanceof Twig_Node_Spaceless) { - return; - } - - // here, $nested means "being at the root level of a child template" - // we need to discard the wrapping "Twig_Node" for the "body" node - $nested = $nested || 'Twig_Node' !== get_class($node); - foreach ($node as $k => $n) { - if (null !== $n && null === $this->filterBodyNodes($n, $nested)) { - $node->removeNode($k); - } - } - - return $node; - } -} - -class_alias('Twig_Parser', 'Twig\Parser', false); -class_exists('Twig_Node'); -class_exists('Twig_TokenStream'); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Base.php b/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Base.php deleted file mode 100644 index 913afd4..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Base.php +++ /dev/null @@ -1,62 +0,0 @@ - - */ -abstract class Twig_Profiler_Dumper_Base -{ - private $root; - - public function dump(Twig_Profiler_Profile $profile) - { - return $this->dumpProfile($profile); - } - - abstract protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix); - - abstract protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix); - - abstract protected function formatTime(Twig_Profiler_Profile $profile, $percent); - - private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false) - { - if ($profile->isRoot()) { - $this->root = $profile->getDuration(); - $start = $profile->getName(); - } else { - if ($profile->isTemplate()) { - $start = $this->formatTemplate($profile, $prefix); - } else { - $start = $this->formatNonTemplate($profile, $prefix); - } - $prefix .= $sibling ? '│ ' : ' '; - } - - $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0; - - if ($profile->getDuration() * 1000 < 1) { - $str = $start."\n"; - } else { - $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent)); - } - - $nCount = count($profile->getProfiles()); - foreach ($profile as $i => $p) { - $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount); - } - - return $str; - } -} - -class_alias('Twig_Profiler_Dumper_Base', 'Twig\Profiler\Dumper\BaseDumper', false); -class_exists('Twig_Profiler_Profile'); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Blackfire.php b/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Blackfire.php deleted file mode 100644 index f6084b5..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Blackfire.php +++ /dev/null @@ -1,70 +0,0 @@ - - */ -final class Twig_Profiler_Dumper_Blackfire -{ - public function dump(Twig_Profiler_Profile $profile) - { - $data = []; - $this->dumpProfile('main()', $profile, $data); - $this->dumpChildren('main()', $profile, $data); - - $start = sprintf('%f', microtime(true)); - $str = << $values) { - $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; - } - - return $str; - } - - private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data) - { - foreach ($profile as $p) { - if ($p->isTemplate()) { - $name = $p->getTemplate(); - } else { - $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName()); - } - $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data); - $this->dumpChildren($name, $p, $data); - } - } - - private function dumpProfile($edge, Twig_Profiler_Profile $profile, &$data) - { - if (isset($data[$edge])) { - ++$data[$edge]['ct']; - $data[$edge]['wt'] += floor($profile->getDuration() * 1000000); - $data[$edge]['mu'] += $profile->getMemoryUsage(); - $data[$edge]['pmu'] += $profile->getPeakMemoryUsage(); - } else { - $data[$edge] = [ - 'ct' => 1, - 'wt' => floor($profile->getDuration() * 1000000), - 'mu' => $profile->getMemoryUsage(), - 'pmu' => $profile->getPeakMemoryUsage(), - ]; - } - } -} - -class_alias('Twig_Profiler_Dumper_Blackfire', 'Twig\Profiler\Dumper\BlackfireDumper', false); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Html.php b/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Html.php deleted file mode 100644 index 25989e2..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Html.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -final class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Base -{ - private static $colors = [ - 'block' => '#dfd', - 'macro' => '#ddf', - 'template' => '#ffd', - 'big' => '#d44', - ]; - - public function dump(Twig_Profiler_Profile $profile) - { - return '
    '.parent::dump($profile).'
    '; - } - - protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); - } - - protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); - } - - protected function formatTime(Twig_Profiler_Profile $profile, $percent) - { - return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); - } -} - -class_alias('Twig_Profiler_Dumper_Html', 'Twig\Profiler\Dumper\HtmlDumper', false); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Text.php b/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Text.php deleted file mode 100644 index 863112d..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Dumper/Text.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -final class Twig_Profiler_Dumper_Text extends Twig_Profiler_Dumper_Base -{ - protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s', $prefix, $profile->getTemplate()); - } - - protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix) - { - return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); - } - - protected function formatTime(Twig_Profiler_Profile $profile, $percent) - { - return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); - } -} - -class_alias('Twig_Profiler_Dumper_Text', 'Twig\Profiler\Dumper\TextDumper', false); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Node/EnterProfile.php b/system/templateEngines/Twig/Twig2x/Profiler/Node/EnterProfile.php deleted file mode 100644 index 8ce40fa..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Node/EnterProfile.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Twig_Profiler_Node_EnterProfile extends Twig_Node -{ - public function __construct($extensionName, $type, $name, $varName) - { - parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->write(sprintf('$%s = $this->extensions[', $this->getAttribute('var_name'))) - ->repr($this->getAttribute('extension_name')) - ->raw("];\n") - ->write(sprintf('$%s->enter($%s = new Twig_Profiler_Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) - ->repr($this->getAttribute('type')) - ->raw(', ') - ->repr($this->getAttribute('name')) - ->raw("));\n\n") - ; - } -} - -class_alias('Twig_Profiler_Node_EnterProfile', 'Twig\Profiler\Node\EnterProfileNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Node/LeaveProfile.php b/system/templateEngines/Twig/Twig2x/Profiler/Node/LeaveProfile.php deleted file mode 100644 index bcb912d..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Node/LeaveProfile.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Profiler_Node_LeaveProfile extends Twig_Node -{ - public function __construct($varName) - { - parent::__construct([], ['var_name' => $varName]); - } - - public function compile(Twig_Compiler $compiler) - { - $compiler - ->write("\n") - ->write(sprintf("\$%s->leave(\$%s);\n\n", $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) - ; - } -} - -class_alias('Twig_Profiler_Node_LeaveProfile', 'Twig\Profiler\Node\LeaveProfileNode', false); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/NodeVisitor/Profiler.php b/system/templateEngines/Twig/Twig2x/Profiler/NodeVisitor/Profiler.php deleted file mode 100644 index e17b368..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/NodeVisitor/Profiler.php +++ /dev/null @@ -1,65 +0,0 @@ - - */ -final class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor -{ - private $extensionName; - - public function __construct($extensionName) - { - $this->extensionName = $extensionName; - } - - protected function doEnterNode(Twig_Node $node, Twig_Environment $env) - { - return $node; - } - - protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) - { - if ($node instanceof Twig_Node_Module) { - $varName = $this->getVarName(); - $node->setNode('display_start', new Twig_Node([new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); - $node->setNode('display_end', new Twig_Node([new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end')])); - } elseif ($node instanceof Twig_Node_Block) { - $varName = $this->getVarName(); - $node->setNode('body', new Twig_Node_Body([ - new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), - $node->getNode('body'), - new Twig_Profiler_Node_LeaveProfile($varName), - ])); - } elseif ($node instanceof Twig_Node_Macro) { - $varName = $this->getVarName(); - $node->setNode('body', new Twig_Node_Body([ - new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName), - $node->getNode('body'), - new Twig_Profiler_Node_LeaveProfile($varName), - ])); - } - - return $node; - } - - private function getVarName() - { - return sprintf('__internal_%s', hash('sha256', $this->extensionName)); - } - - public function getPriority() - { - return 0; - } -} - -class_alias('Twig_Profiler_NodeVisitor_Profiler', 'Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', false); diff --git a/system/templateEngines/Twig/Twig2x/Profiler/Profile.php b/system/templateEngines/Twig/Twig2x/Profiler/Profile.php deleted file mode 100644 index 1cc982c..0000000 --- a/system/templateEngines/Twig/Twig2x/Profiler/Profile.php +++ /dev/null @@ -1,174 +0,0 @@ - - * - * @final since version 2.4.0 - */ -class Twig_Profiler_Profile implements IteratorAggregate, Serializable -{ - const ROOT = 'ROOT'; - const BLOCK = 'block'; - const TEMPLATE = 'template'; - const MACRO = 'macro'; - - private $template; - private $name; - private $type; - private $starts = []; - private $ends = []; - private $profiles = []; - - public function __construct($template = 'main', $type = self::ROOT, $name = 'main') - { - if (__CLASS__ !== get_class($this)) { - @trigger_error('Overriding '.__CLASS__.' is deprecated since version 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); - } - - $this->template = $template; - $this->type = $type; - $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name; - $this->enter(); - } - - public function getTemplate() - { - return $this->template; - } - - public function getType() - { - return $this->type; - } - - public function getName() - { - return $this->name; - } - - public function isRoot() - { - return self::ROOT === $this->type; - } - - public function isTemplate() - { - return self::TEMPLATE === $this->type; - } - - public function isBlock() - { - return self::BLOCK === $this->type; - } - - public function isMacro() - { - return self::MACRO === $this->type; - } - - public function getProfiles() - { - return $this->profiles; - } - - public function addProfile(self $profile) - { - $this->profiles[] = $profile; - } - - /** - * Returns the duration in microseconds. - * - * @return int - */ - public function getDuration() - { - if ($this->isRoot() && $this->profiles) { - // for the root node with children, duration is the sum of all child durations - $duration = 0; - foreach ($this->profiles as $profile) { - $duration += $profile->getDuration(); - } - - return $duration; - } - - return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0; - } - - /** - * Returns the memory usage in bytes. - * - * @return int - */ - public function getMemoryUsage() - { - return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0; - } - - /** - * Returns the peak memory usage in bytes. - * - * @return int - */ - public function getPeakMemoryUsage() - { - return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0; - } - - /** - * Starts the profiling. - */ - public function enter() - { - $this->starts = [ - 'wt' => microtime(true), - 'mu' => memory_get_usage(), - 'pmu' => memory_get_peak_usage(), - ]; - } - - /** - * Stops the profiling. - */ - public function leave() - { - $this->ends = [ - 'wt' => microtime(true), - 'mu' => memory_get_usage(), - 'pmu' => memory_get_peak_usage(), - ]; - } - - public function reset() - { - $this->starts = $this->ends = $this->profiles = []; - $this->enter(); - } - - public function getIterator() - { - return new ArrayIterator($this->profiles); - } - - public function serialize() - { - return serialize([$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles]); - } - - public function unserialize($data) - { - list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = unserialize($data); - } -} - -class_alias('Twig_Profiler_Profile', 'Twig\Profiler\Profile', false); diff --git a/system/templateEngines/Twig/Twig2x/RuntimeLoaderInterface.php b/system/templateEngines/Twig/Twig2x/RuntimeLoaderInterface.php deleted file mode 100644 index f5eb14e..0000000 --- a/system/templateEngines/Twig/Twig2x/RuntimeLoaderInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - */ -interface Twig_RuntimeLoaderInterface -{ - /** - * Creates the runtime implementation of a Twig element (filter/function/test). - * - * @param string $class A runtime class - * - * @return object|null The runtime instance or null if the loader does not know how to create the runtime for this class - */ - public function load($class); -} - -class_alias('Twig_RuntimeLoaderInterface', 'Twig\RuntimeLoader\RuntimeLoaderInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityError.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityError.php deleted file mode 100644 index b6707e3..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityError.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -class Twig_Sandbox_SecurityError extends Twig_Error -{ -} - -class_alias('Twig_Sandbox_SecurityError', 'Twig\Sandbox\SecurityError', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFilterError.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFilterError.php deleted file mode 100644 index 0ba3327..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFilterError.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedFilterError extends Twig_Sandbox_SecurityError -{ - private $filterName; - - public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->filterName = $functionName; - } - - public function getFilterName() - { - return $this->filterName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedFilterError', 'Twig\Sandbox\SecurityNotAllowedFilterError', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFunctionError.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFunctionError.php deleted file mode 100644 index aa39142..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedFunctionError.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedFunctionError extends Twig_Sandbox_SecurityError -{ - private $functionName; - - public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->functionName = $functionName; - } - - public function getFunctionName() - { - return $this->functionName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedFunctionError', 'Twig\Sandbox\SecurityNotAllowedFunctionError', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedMethodError.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedMethodError.php deleted file mode 100644 index 93012fe..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedMethodError.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedMethodError extends Twig_Sandbox_SecurityError -{ - private $className; - private $methodName; - - public function __construct($message, $className, $methodName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->className = $className; - $this->methodName = $methodName; - } - - public function getClassName() - { - return $this->className; - } - - public function getMethodName() - { - return $this->methodName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedMethodError', 'Twig\Sandbox\SecurityNotAllowedMethodError', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedPropertyError.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedPropertyError.php deleted file mode 100644 index f27969c..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedPropertyError.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedPropertyError extends Twig_Sandbox_SecurityError -{ - private $className; - private $propertyName; - - public function __construct($message, $className, $propertyName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->className = $className; - $this->propertyName = $propertyName; - } - - public function getClassName() - { - return $this->className; - } - - public function getPropertyName() - { - return $this->propertyName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedPropertyError', 'Twig\Sandbox\SecurityNotAllowedPropertyError', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedTagError.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedTagError.php deleted file mode 100644 index 4bbd223..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityNotAllowedTagError.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -class Twig_Sandbox_SecurityNotAllowedTagError extends Twig_Sandbox_SecurityError -{ - private $tagName; - - public function __construct($message, $tagName, $lineno = -1, $filename = null, Exception $previous = null) - { - parent::__construct($message, $lineno, $filename, $previous); - $this->tagName = $tagName; - } - - public function getTagName() - { - return $this->tagName; - } -} - -class_alias('Twig_Sandbox_SecurityNotAllowedTagError', 'Twig\Sandbox\SecurityNotAllowedTagError', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicy.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicy.php deleted file mode 100644 index 9c0d352..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicy.php +++ /dev/null @@ -1,123 +0,0 @@ - - */ -final class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface -{ - private $allowedTags; - private $allowedFilters; - private $allowedMethods; - private $allowedProperties; - private $allowedFunctions; - - public function __construct(array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = []) - { - $this->allowedTags = $allowedTags; - $this->allowedFilters = $allowedFilters; - $this->setAllowedMethods($allowedMethods); - $this->allowedProperties = $allowedProperties; - $this->allowedFunctions = $allowedFunctions; - } - - public function setAllowedTags(array $tags) - { - $this->allowedTags = $tags; - } - - public function setAllowedFilters(array $filters) - { - $this->allowedFilters = $filters; - } - - public function setAllowedMethods(array $methods) - { - $this->allowedMethods = []; - foreach ($methods as $class => $m) { - $this->allowedMethods[$class] = array_map('strtolower', is_array($m) ? $m : [$m]); - } - } - - public function setAllowedProperties(array $properties) - { - $this->allowedProperties = $properties; - } - - public function setAllowedFunctions(array $functions) - { - $this->allowedFunctions = $functions; - } - - public function checkSecurity($tags, $filters, $functions) - { - foreach ($tags as $tag) { - if (!in_array($tag, $this->allowedTags)) { - throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); - } - } - - foreach ($filters as $filter) { - if (!in_array($filter, $this->allowedFilters)) { - throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); - } - } - - foreach ($functions as $function) { - if (!in_array($function, $this->allowedFunctions)) { - throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); - } - } - } - - public function checkMethodAllowed($obj, $method) - { - if ($obj instanceof Twig_Template || $obj instanceof Twig_Markup) { - return true; - } - - $allowed = false; - $method = strtolower($method); - foreach ($this->allowedMethods as $class => $methods) { - if ($obj instanceof $class) { - $allowed = in_array($method, $methods); - - break; - } - } - - if (!$allowed) { - $class = get_class($obj); - throw new Twig_Sandbox_SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); - } - } - - public function checkPropertyAllowed($obj, $property) - { - $allowed = false; - foreach ($this->allowedProperties as $class => $properties) { - if ($obj instanceof $class) { - $allowed = in_array($property, is_array($properties) ? $properties : [$properties]); - - break; - } - } - - if (!$allowed) { - $class = get_class($obj); - throw new Twig_Sandbox_SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); - } - } -} - -class_alias('Twig_Sandbox_SecurityPolicy', 'Twig\Sandbox\SecurityPolicy', false); diff --git a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicyInterface.php b/system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicyInterface.php deleted file mode 100644 index 88f6444..0000000 --- a/system/templateEngines/Twig/Twig2x/Sandbox/SecurityPolicyInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -interface Twig_Sandbox_SecurityPolicyInterface -{ - public function checkSecurity($tags, $filters, $functions); - - public function checkMethodAllowed($obj, $method); - - public function checkPropertyAllowed($obj, $method); -} - -class_alias('Twig_Sandbox_SecurityPolicyInterface', 'Twig\Sandbox\SecurityPolicyInterface', false); diff --git a/system/templateEngines/Twig/Twig2x/SimpleFilter.php b/system/templateEngines/Twig/Twig2x/SimpleFilter.php deleted file mode 100644 index 840453e..0000000 --- a/system/templateEngines/Twig/Twig2x/SimpleFilter.php +++ /dev/null @@ -1,21 +0,0 @@ - - */ -final class Twig_Source -{ - private $code; - private $name; - private $path; - - /** - * @param string $code The template source code - * @param string $name The template logical name - * @param string $path The filesystem path of the template if any - */ - public function __construct($code, $name, $path = '') - { - $this->code = $code; - $this->name = $name; - $this->path = $path; - } - - public function getCode() - { - return $this->code; - } - - public function getName() - { - return $this->name; - } - - public function getPath() - { - return $this->path; - } -} - -class_alias('Twig_Source', 'Twig\Source', false); diff --git a/system/templateEngines/Twig/Twig2x/SourceContextLoaderInterface.php b/system/templateEngines/Twig/Twig2x/SourceContextLoaderInterface.php deleted file mode 100644 index dd5608a..0000000 --- a/system/templateEngines/Twig/Twig2x/SourceContextLoaderInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -load() - * instead, which returns an instance of Twig_TemplateWrapper. - * - * @author Fabien Potencier - * - * @internal - */ -abstract class Twig_Template -{ - const ANY_CALL = 'any'; - const ARRAY_CALL = 'array'; - const METHOD_CALL = 'method'; - - protected $parent; - protected $parents = []; - protected $env; - protected $blocks = []; - protected $traits = []; - - /** - * @internal - */ - protected $extensions = []; - - public function __construct(Twig_Environment $env) - { - $this->env = $env; - $this->extensions = $env->getExtensions(); - } - - /** - * @internal this method will be removed in 2.0 and is only used internally to provide an upgrade path from 1.x to 2.0 - */ - public function __toString() - { - return $this->getTemplateName(); - } - - /** - * Returns the template name. - * - * @return string The template name - */ - abstract public function getTemplateName(); - - /** - * Returns debug information about the template. - * - * @return array Debug information - * - * @internal - */ - abstract public function getDebugInfo(); - - /** - * Returns information about the original template source code. - * - * @return Twig_Source - */ - public function getSourceContext() - { - return new Twig_Source('', $this->getTemplateName()); - } - - /** - * Returns the parent template. - * - * This method is for internal use only and should never be called - * directly. - * - * @param array $context - * - * @return Twig_Template|Twig_TemplateWrapper|false The parent template or false if there is no parent - * - * @internal - */ - public function getParent(array $context) - { - if (null !== $this->parent) { - return $this->parent; - } - - try { - $parent = $this->doGetParent($context); - - if (false === $parent) { - return false; - } - - if ($parent instanceof self || $parent instanceof Twig_TemplateWrapper) { - return $this->parents[$parent->getSourceContext()->getName()] = $parent; - } - - if (!isset($this->parents[$parent])) { - $this->parents[$parent] = $this->loadTemplate($parent); - } - } catch (Twig_Error_Loader $e) { - $e->setSourceContext(null); - $e->guess(); - - throw $e; - } - - return $this->parents[$parent]; - } - - protected function doGetParent(array $context) - { - return false; - } - - public function isTraitable() - { - return true; - } - - /** - * Displays a parent block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to display from the parent - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @internal - */ - public function displayParentBlock($name, array $context, array $blocks = []) - { - if (isset($this->traits[$name])) { - $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); - } elseif (false !== $parent = $this->getParent($context)) { - $parent->displayBlock($name, $context, $blocks, false); - } else { - throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); - } - } - - /** - * Displays a block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to display - * @param array $context The context - * @param array $blocks The current set of blocks - * @param bool $useBlocks Whether to use the current set of blocks - * - * @internal - */ - public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, self $templateContext = null) - { - if ($useBlocks && isset($blocks[$name])) { - $template = $blocks[$name][0]; - $block = $blocks[$name][1]; - } elseif (isset($this->blocks[$name])) { - $template = $this->blocks[$name][0]; - $block = $this->blocks[$name][1]; - } else { - $template = null; - $block = null; - } - - // avoid RCEs when sandbox is enabled - if (null !== $template && !$template instanceof self) { - throw new LogicException('A block must be a method on a Twig_Template instance.'); - } - - if (null !== $template) { - try { - $template->$block($context, $blocks); - } catch (Twig_Error $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($template->getSourceContext()); - } - - // this is mostly useful for Twig_Error_Loader exceptions - // see Twig_Error_Loader - if (false === $e->getTemplateLine()) { - $e->setTemplateLine(-1); - $e->guess(); - } - - throw $e; - } catch (Exception $e) { - throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); - } - } elseif (false !== $parent = $this->getParent($context)) { - $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this); - } elseif (isset($blocks[$name])) { - throw new Twig_Error_Runtime(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getSourceContext()); - } else { - throw new Twig_Error_Runtime(sprintf('Block "%s" on template "%s" does not exist.', $name, $this->getTemplateName()), -1, ($templateContext ?? $this)->getSourceContext()); - } - } - - /** - * Renders a parent block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to render from the parent - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @return string The rendered block - * - * @internal - */ - public function renderParentBlock($name, array $context, array $blocks = []) - { - ob_start(); - $this->displayParentBlock($name, $context, $blocks); - - return ob_get_clean(); - } - - /** - * Renders a block. - * - * This method is for internal use only and should never be called - * directly. - * - * @param string $name The block name to render - * @param array $context The context - * @param array $blocks The current set of blocks - * @param bool $useBlocks Whether to use the current set of blocks - * - * @return string The rendered block - * - * @internal - */ - public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true) - { - ob_start(); - $this->displayBlock($name, $context, $blocks, $useBlocks); - - return ob_get_clean(); - } - - /** - * Returns whether a block exists or not in the current context of the template. - * - * This method checks blocks defined in the current template - * or defined in "used" traits or defined in parent templates. - * - * @param string $name The block name - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @return bool true if the block exists, false otherwise - * - * @internal - */ - public function hasBlock($name, array $context, array $blocks = []) - { - if (isset($blocks[$name])) { - return $blocks[$name][0] instanceof self; - } - - if (isset($this->blocks[$name])) { - return true; - } - - if (false !== $parent = $this->getParent($context)) { - return $parent->hasBlock($name, $context); - } - - return false; - } - - /** - * Returns all block names in the current context of the template. - * - * This method checks blocks defined in the current template - * or defined in "used" traits or defined in parent templates. - * - * @param array $context The context - * @param array $blocks The current set of blocks - * - * @return array An array of block names - * - * @internal - */ - public function getBlockNames(array $context, array $blocks = []) - { - $names = array_merge(array_keys($blocks), array_keys($this->blocks)); - - if (false !== $parent = $this->getParent($context)) { - $names = array_merge($names, $parent->getBlockNames($context)); - } - - return array_unique($names); - } - - protected function loadTemplate($template, $templateName = null, $line = null, $index = null) - { - try { - if (is_array($template)) { - return $this->env->resolveTemplate($template); - } - - if ($template instanceof self || $template instanceof Twig_TemplateWrapper) { - return $template; - } - - return $this->env->loadTemplate($template, $index); - } catch (Twig_Error $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($templateName ? new Twig_Source('', $templateName) : $this->getSourceContext()); - } - - if ($e->getTemplateLine()) { - throw $e; - } - - if (!$line) { - $e->guess(); - } else { - $e->setTemplateLine($line); - } - - throw $e; - } - } - - /** - * Returns all blocks. - * - * This method is for internal use only and should never be called - * directly. - * - * @return array An array of blocks - * - * @internal - */ - public function getBlocks() - { - return $this->blocks; - } - - public function display(array $context, array $blocks = []) - { - $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); - } - - public function render(array $context) - { - $level = ob_get_level(); - ob_start(); - try { - $this->display($context); - } catch (Throwable $e) { - while (ob_get_level() > $level) { - ob_end_clean(); - } - - throw $e; - } - - return ob_get_clean(); - } - - protected function displayWithErrorHandling(array $context, array $blocks = []) - { - try { - $this->doDisplay($context, $blocks); - } catch (Twig_Error $e) { - if (!$e->getSourceContext()) { - $e->setSourceContext($this->getSourceContext()); - } - - // this is mostly useful for Twig_Error_Loader exceptions - // see Twig_Error_Loader - if (false === $e->getTemplateLine()) { - $e->setTemplateLine(-1); - $e->guess(); - } - - throw $e; - } catch (Exception $e) { - throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); - } - } - - /** - * Auto-generated method to display the template with the given context. - * - * @param array $context An array of parameters to pass to the template - * @param array $blocks An array of blocks to pass to the template - */ - abstract protected function doDisplay(array $context, array $blocks = []); -} - -class_alias('Twig_Template', 'Twig\Template', false); diff --git a/system/templateEngines/Twig/Twig2x/TemplateWrapper.php b/system/templateEngines/Twig/Twig2x/TemplateWrapper.php deleted file mode 100644 index b0ff5a7..0000000 --- a/system/templateEngines/Twig/Twig2x/TemplateWrapper.php +++ /dev/null @@ -1,131 +0,0 @@ - - */ -final class Twig_TemplateWrapper -{ - private $env; - private $template; - - /** - * This method is for internal use only and should never be called - * directly (use Twig_Environment::load() instead). - * - * @internal - */ - public function __construct(Twig_Environment $env, Twig_Template $template) - { - $this->env = $env; - $this->template = $template; - } - - /** - * Renders the template. - * - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered template - */ - public function render($context = []) - { - // using func_get_args() allows to not expose the blocks argument - // as it should only be used by internal code - return $this->template->render($context, func_get_args()[1] ?? []); - } - - /** - * Displays the template. - * - * @param array $context An array of parameters to pass to the template - */ - public function display($context = []) - { - // using func_get_args() allows to not expose the blocks argument - // as it should only be used by internal code - $this->template->display($context, func_get_args()[1] ?? []); - } - - /** - * Checks if a block is defined. - * - * @param string $name The block name - * @param array $context An array of parameters to pass to the template - * - * @return bool - */ - public function hasBlock($name, $context = []) - { - return $this->template->hasBlock($name, $context); - } - - /** - * Returns defined block names in the template. - * - * @param array $context An array of parameters to pass to the template - * - * @return string[] An array of defined template block names - */ - public function getBlockNames($context = []) - { - return $this->template->getBlockNames($context); - } - - /** - * Renders a template block. - * - * @param string $name The block name to render - * @param array $context An array of parameters to pass to the template - * - * @return string The rendered block - */ - public function renderBlock($name, $context = []) - { - $context = $this->env->mergeGlobals($context); - $level = ob_get_level(); - ob_start(); - try { - $this->template->displayBlock($name, $context); - } catch (Throwable $e) { - while (ob_get_level() > $level) { - ob_end_clean(); - } - - throw $e; - } - - return ob_get_clean(); - } - - /** - * Displays a template block. - * - * @param string $name The block name to render - * @param array $context An array of parameters to pass to the template - */ - public function displayBlock($name, $context = []) - { - $this->template->displayBlock($name, $this->env->mergeGlobals($context)); - } - - /** - * @return Twig_Source - */ - public function getSourceContext() - { - return $this->template->getSourceContext(); - } -} - -class_alias('Twig_TemplateWrapper', 'Twig\TemplateWrapper', false); diff --git a/system/templateEngines/Twig/Twig2x/Test.php b/system/templateEngines/Twig/Twig2x/Test.php deleted file mode 100644 index b604e78..0000000 --- a/system/templateEngines/Twig/Twig2x/Test.php +++ /dev/null @@ -1,105 +0,0 @@ - - * - * @see https://twig.symfony.com/doc/templates.html#test-operator - */ -class Twig_Test -{ - private $name; - private $callable; - private $options; - private $arguments = []; - - /** - * Creates a template test. - * - * @param string $name Name of this test - * @param callable|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation. - * @param array $options Options array - */ - public function __construct(string $name, $callable = null, array $options = []) - { - if (__CLASS__ !== get_class($this)) { - @trigger_error('Overriding '.__CLASS__.' is deprecated since version 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); - } - - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge([ - 'is_variadic' => false, - 'node_class' => 'Twig_Node_Expression_Test', - 'deprecated' => false, - 'alternative' => null, - ], $options); - } - - public function getName() - { - return $this->name; - } - - /** - * Returns the callable to execute for this test. - * - * @return callable|null - */ - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function isVariadic() - { - return $this->options['is_variadic']; - } - - public function isDeprecated() - { - return (bool) $this->options['deprecated']; - } - - public function getDeprecatedVersion() - { - return $this->options['deprecated']; - } - - public function getAlternative() - { - return $this->options['alternative']; - } -} - -// For Twig 1.x compatibility -class_alias('Twig_Test', 'Twig_SimpleTest', false); - -class_alias('Twig_Test', 'Twig\TwigTest', false); diff --git a/system/templateEngines/Twig/Twig2x/Test/IntegrationTestCase.php b/system/templateEngines/Twig/Twig2x/Test/IntegrationTestCase.php deleted file mode 100644 index 566ef3f..0000000 --- a/system/templateEngines/Twig/Twig2x/Test/IntegrationTestCase.php +++ /dev/null @@ -1,257 +0,0 @@ - - * @author Karma Dordrak - */ -abstract class Twig_Test_IntegrationTestCase extends TestCase -{ - /** - * @return string - */ - abstract protected function getFixturesDir(); - - /** - * @return Twig_RuntimeLoaderInterface[] - */ - protected function getRuntimeLoaders() - { - return []; - } - - /** - * @return Twig_ExtensionInterface[] - */ - protected function getExtensions() - { - return []; - } - - /** - * @return Twig_Filter[] - */ - protected function getTwigFilters() - { - return []; - } - - /** - * @return Twig_Function[] - */ - protected function getTwigFunctions() - { - return []; - } - - /** - * @return Twig_Test[] - */ - protected function getTwigTests() - { - return []; - } - - /** - * @dataProvider getTests - */ - public function testIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') - { - $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); - } - - /** - * @dataProvider getLegacyTests - * @group legacy - */ - public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') - { - $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); - } - - public function getTests($name, $legacyTests = false) - { - $fixturesDir = realpath($this->getFixturesDir()); - $tests = []; - - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { - if (!preg_match('/\.test$/', $file)) { - continue; - } - - if ($legacyTests xor false !== strpos($file->getRealpath(), '.legacy.test')) { - continue; - } - - $test = file_get_contents($file->getRealpath()); - - if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*(?:--DEPRECATION--\s*(.*?))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { - $message = $match[1]; - $condition = $match[2]; - $deprecation = $match[3]; - $templates = self::parseTemplates($match[4]); - $exception = $match[6]; - $outputs = [[null, $match[5], null, '']]; - } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*(?:--DEPRECATION--\s*(.*?))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { - $message = $match[1]; - $condition = $match[2]; - $deprecation = $match[3]; - $templates = self::parseTemplates($match[4]); - $exception = false; - preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); - } else { - throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); - } - - $tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs, $deprecation]; - } - - if ($legacyTests && empty($tests)) { - // add a dummy test to avoid a PHPUnit message - return [['not', '-', '', [], '', []]]; - } - - return $tests; - } - - public function getLegacyTests() - { - return $this->getTests('testLegacyIntegration', true); - } - - protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') - { - if (!$outputs) { - $this->markTestSkipped('no tests to run'); - } - - if ($condition) { - eval('$ret = '.$condition.';'); - if (!$ret) { - $this->markTestSkipped($condition); - } - } - - $loader = new Twig_Loader_Array($templates); - - foreach ($outputs as $i => $match) { - $config = array_merge([ - 'cache' => false, - 'strict_variables' => true, - ], $match[2] ? eval($match[2].';') : []); - $twig = new Twig_Environment($loader, $config); - $twig->addGlobal('global', 'global'); - foreach ($this->getRuntimeLoaders() as $runtimeLoader) { - $twig->addRuntimeLoader($runtimeLoader); - } - - foreach ($this->getExtensions() as $extension) { - $twig->addExtension($extension); - } - - foreach ($this->getTwigFilters() as $filter) { - $twig->addFilter($filter); - } - - foreach ($this->getTwigTests() as $test) { - $twig->addTest($test); - } - - foreach ($this->getTwigFunctions() as $function) { - $twig->addFunction($function); - } - - // avoid using the same PHP class name for different cases - $p = new ReflectionProperty($twig, 'templateClassPrefix'); - $p->setAccessible(true); - $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); - - $deprecations = []; - try { - $prevHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) { - if (E_USER_DEPRECATED === $type) { - $deprecations[] = $msg; - - return true; - } - - return $prevHandler ? $prevHandler($type, $msg, $file, $line, $context) : false; - }); - - $template = $twig->loadTemplate('index.twig'); - } catch (Exception $e) { - if (false !== $exception) { - $message = $e->getMessage(); - $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $message))); - $last = substr($message, strlen($message) - 1); - $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.'); - - return; - } - - throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); - } finally { - restore_error_handler(); - } - - $this->assertSame($deprecation, implode("\n", $deprecations)); - - try { - $output = trim($template->render(eval($match[1].';')), "\n "); - } catch (Exception $e) { - if (false !== $exception) { - $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); - - return; - } - - $e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); - - $output = trim(sprintf('%s: %s', get_class($e), $e->getMessage())); - } - - if (false !== $exception) { - list($class) = explode(':', $exception); - $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception'; - $this->assertThat(null, new $constraintClass($class)); - } - - $expected = trim($match[3], "\n "); - - if ($expected !== $output) { - printf("Compiled templates that failed on case %d:\n", $i + 1); - - foreach (array_keys($templates) as $name) { - echo "Template: $name\n"; - echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext($name)))); - } - } - $this->assertEquals($expected, $output, $message.' (in '.$file.')'); - } - } - - protected static function parseTemplates($test) - { - $templates = []; - preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); - foreach ($matches as $match) { - $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; - } - - return $templates; - } -} - -class_alias('Twig_Test_IntegrationTestCase', 'Twig\Test\IntegrationTestCase', false); diff --git a/system/templateEngines/Twig/Twig2x/Test/NodeTestCase.php b/system/templateEngines/Twig/Twig2x/Test/NodeTestCase.php deleted file mode 100644 index f4ba058..0000000 --- a/system/templateEngines/Twig/Twig2x/Test/NodeTestCase.php +++ /dev/null @@ -1,63 +0,0 @@ -assertNodeCompilation($source, $node, $environment, $isPattern); - } - - public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null, $isPattern = false) - { - $compiler = $this->getCompiler($environment); - $compiler->compile($node); - - if ($isPattern) { - $this->assertStringMatchesFormat($source, trim($compiler->getSource())); - } else { - $this->assertEquals($source, trim($compiler->getSource())); - } - } - - protected function getCompiler(Twig_Environment $environment = null) - { - return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment); - } - - protected function getEnvironment() - { - return new Twig_Environment(new Twig_Loader_Array([])); - } - - protected function getVariableGetter($name, $line = false) - { - $line = $line > 0 ? "// line {$line}\n" : ''; - - return sprintf('%s($context["%s"] ?? null)', $line, $name, $name); - } - - protected function getAttributeGetter() - { - return 'twig_get_attribute($this->env, $this->source, '; - } -} - -class_alias('Twig_Test_NodeTestCase', 'Twig\Test\NodeTestCase', false); -class_exists('Twig_Environment'); -class_exists('Twig_Node'); diff --git a/system/templateEngines/Twig/Twig2x/Token.php b/system/templateEngines/Twig/Twig2x/Token.php deleted file mode 100644 index 1586629..0000000 --- a/system/templateEngines/Twig/Twig2x/Token.php +++ /dev/null @@ -1,205 +0,0 @@ - - */ -final class Twig_Token -{ - private $value; - private $type; - private $lineno; - - const EOF_TYPE = -1; - const TEXT_TYPE = 0; - const BLOCK_START_TYPE = 1; - const VAR_START_TYPE = 2; - const BLOCK_END_TYPE = 3; - const VAR_END_TYPE = 4; - const NAME_TYPE = 5; - const NUMBER_TYPE = 6; - const STRING_TYPE = 7; - const OPERATOR_TYPE = 8; - const PUNCTUATION_TYPE = 9; - const INTERPOLATION_START_TYPE = 10; - const INTERPOLATION_END_TYPE = 11; - - /** - * @param int $type The type of the token - * @param string $value The token value - * @param int $lineno The line position in the source - */ - public function __construct($type, $value, $lineno) - { - $this->type = $type; - $this->value = $value; - $this->lineno = $lineno; - } - - public function __toString() - { - return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value); - } - - /** - * Tests the current token for a type and/or a value. - * - * Parameters may be: - * * just type - * * type and value (or array of possible values) - * * just value (or array of possible values) (NAME_TYPE is used as type) - * - * @param array|string|int $type The type to test - * @param array|string|null $values The token value - * - * @return bool - */ - public function test($type, $values = null) - { - if (null === $values && !is_int($type)) { - $values = $type; - $type = self::NAME_TYPE; - } - - return ($this->type === $type) && ( - null === $values || - (is_array($values) && in_array($this->value, $values)) || - $this->value == $values - ); - } - - /** - * @return int - */ - public function getLine() - { - return $this->lineno; - } - - /** - * @return int - */ - public function getType() - { - return $this->type; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * Returns the constant representation (internal) of a given type. - * - * @param int $type The type as an integer - * @param bool $short Whether to return a short representation or not - * - * @return string The string representation - */ - public static function typeToString($type, $short = false) - { - switch ($type) { - case self::EOF_TYPE: - $name = 'EOF_TYPE'; - break; - case self::TEXT_TYPE: - $name = 'TEXT_TYPE'; - break; - case self::BLOCK_START_TYPE: - $name = 'BLOCK_START_TYPE'; - break; - case self::VAR_START_TYPE: - $name = 'VAR_START_TYPE'; - break; - case self::BLOCK_END_TYPE: - $name = 'BLOCK_END_TYPE'; - break; - case self::VAR_END_TYPE: - $name = 'VAR_END_TYPE'; - break; - case self::NAME_TYPE: - $name = 'NAME_TYPE'; - break; - case self::NUMBER_TYPE: - $name = 'NUMBER_TYPE'; - break; - case self::STRING_TYPE: - $name = 'STRING_TYPE'; - break; - case self::OPERATOR_TYPE: - $name = 'OPERATOR_TYPE'; - break; - case self::PUNCTUATION_TYPE: - $name = 'PUNCTUATION_TYPE'; - break; - case self::INTERPOLATION_START_TYPE: - $name = 'INTERPOLATION_START_TYPE'; - break; - case self::INTERPOLATION_END_TYPE: - $name = 'INTERPOLATION_END_TYPE'; - break; - default: - throw new LogicException(sprintf('Token of type "%s" does not exist.', $type)); - } - - return $short ? $name : 'Twig_Token::'.$name; - } - - /** - * Returns the English representation of a given type. - * - * @param int $type The type as an integer - * - * @return string The string representation - */ - public static function typeToEnglish($type) - { - switch ($type) { - case self::EOF_TYPE: - return 'end of template'; - case self::TEXT_TYPE: - return 'text'; - case self::BLOCK_START_TYPE: - return 'begin of statement block'; - case self::VAR_START_TYPE: - return 'begin of print statement'; - case self::BLOCK_END_TYPE: - return 'end of statement block'; - case self::VAR_END_TYPE: - return 'end of print statement'; - case self::NAME_TYPE: - return 'name'; - case self::NUMBER_TYPE: - return 'number'; - case self::STRING_TYPE: - return 'string'; - case self::OPERATOR_TYPE: - return 'operator'; - case self::PUNCTUATION_TYPE: - return 'punctuation'; - case self::INTERPOLATION_START_TYPE: - return 'begin of string interpolation'; - case self::INTERPOLATION_END_TYPE: - return 'end of string interpolation'; - default: - throw new LogicException(sprintf('Token of type "%s" does not exist.', $type)); - } - } -} - -class_alias('Twig_Token', 'Twig\Token', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser.php b/system/templateEngines/Twig/Twig2x/TokenParser.php deleted file mode 100644 index 1b4de14..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ -abstract class Twig_TokenParser implements Twig_TokenParserInterface -{ - /** - * @var Twig_Parser - */ - protected $parser; - - /** - * Sets the parser associated with this token parser. - */ - public function setParser(Twig_Parser $parser) - { - $this->parser = $parser; - } -} - -class_alias('Twig_TokenParser', 'Twig\TokenParser\AbstractTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/AutoEscape.php b/system/templateEngines/Twig/Twig2x/TokenParser/AutoEscape.php deleted file mode 100644 index 789f9dc..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/AutoEscape.php +++ /dev/null @@ -1,50 +0,0 @@ -getLine(); - $stream = $this->parser->getStream(); - - if ($stream->test(/* Twig_Token::BLOCK_END_TYPE */ 3)) { - $value = 'html'; - } else { - $expr = $this->parser->getExpressionParser()->parseExpression(); - if (!$expr instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('An escaping strategy must be a string or false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - $value = $expr->getAttribute('value'); - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endautoescape'); - } - - public function getTag() - { - return 'autoescape'; - } -} - -class_alias('Twig_TokenParser_AutoEscape', 'Twig\TokenParser\AutoEscapeTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Block.php b/system/templateEngines/Twig/Twig2x/TokenParser/Block.php deleted file mode 100644 index 1659361..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Block.php +++ /dev/null @@ -1,71 +0,0 @@ - - * {% block head %} - * - * {% block title %}{% endblock %} - My Webpage - * {% endblock %} - * - */ -final class Twig_TokenParser_Block extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $name = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - if ($this->parser->hasBlock($name)) { - throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node([]), $lineno)); - $this->parser->pushLocalScope(); - $this->parser->pushBlockStack($name); - - if ($stream->nextIf(/* Twig_Token::BLOCK_END_TYPE */ 3)) { - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(/* Twig_Token::NAME_TYPE */ 5)) { - $value = $token->getValue(); - - if ($value != $name) { - throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } - } else { - $body = new Twig_Node([ - new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno), - ]); - } - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $block->setNode('body', $body); - $this->parser->popBlockStack(); - $this->parser->popLocalScope(); - - return new Twig_Node_BlockReference($name, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endblock'); - } - - public function getTag() - { - return 'block'; - } -} - -class_alias('Twig_TokenParser_Block', 'Twig\TokenParser\BlockTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Deprecated.php b/system/templateEngines/Twig/Twig2x/TokenParser/Deprecated.php deleted file mode 100644 index be5d549..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Deprecated.php +++ /dev/null @@ -1,42 +0,0 @@ - - * {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %} - * - * {% extends 'layout.html.twig' %} - * - * - * @author Yonel Ceruto - * - * @final - */ -class Twig_TokenParser_Deprecated extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $expr = $this->parser->getExpressionParser()->parseExpression(); - - $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - - return new Twig_Node_Deprecated($expr, $token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'deprecated'; - } -} - -class_alias('Twig_TokenParser_Deprecated', 'Twig\TokenParser\DeprecatedTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Do.php b/system/templateEngines/Twig/Twig2x/TokenParser/Do.php deleted file mode 100644 index df796fc..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Do.php +++ /dev/null @@ -1,32 +0,0 @@ -parser->getExpressionParser()->parseExpression(); - - $this->parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_Do($expr, $token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'do'; - } -} - -class_alias('Twig_TokenParser_Do', 'Twig\TokenParser\DoTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Embed.php b/system/templateEngines/Twig/Twig2x/TokenParser/Embed.php deleted file mode 100644 index 273d823..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Embed.php +++ /dev/null @@ -1,65 +0,0 @@ -parser->getStream(); - - $parent = $this->parser->getExpressionParser()->parseExpression(); - - list($variables, $only, $ignoreMissing) = $this->parseArguments(); - - $parentToken = $fakeParentToken = new Twig_Token(/* Twig_Token::STRING_TYPE */ 7, '__parent__', $token->getLine()); - if ($parent instanceof Twig_Node_Expression_Constant) { - $parentToken = new Twig_Token(/* Twig_Token::STRING_TYPE */ 7, $parent->getAttribute('value'), $token->getLine()); - } elseif ($parent instanceof Twig_Node_Expression_Name) { - $parentToken = new Twig_Token(/* Twig_Token::NAME_TYPE */ 5, $parent->getAttribute('name'), $token->getLine()); - } - - // inject a fake parent to make the parent() function work - $stream->injectTokens([ - new Twig_Token(/* Twig_Token::BLOCK_START_TYPE */ 1, '', $token->getLine()), - new Twig_Token(/* Twig_Token::NAME_TYPE */ 5, 'extends', $token->getLine()), - $parentToken, - new Twig_Token(/* Twig_Token::BLOCK_END_TYPE */ 3, '', $token->getLine()), - ]); - - $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); - - // override the parent with the correct one - if ($fakeParentToken === $parentToken) { - $module->setNode('parent', $parent); - } - - $this->parser->embedTemplate($module); - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endembed'); - } - - public function getTag() - { - return 'embed'; - } -} - -class_alias('Twig_TokenParser_Embed', 'Twig\TokenParser\EmbedTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Extends.php b/system/templateEngines/Twig/Twig2x/TokenParser/Extends.php deleted file mode 100644 index e017af3..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Extends.php +++ /dev/null @@ -1,44 +0,0 @@ - - * {% extends "base.html" %} - * - */ -final class Twig_TokenParser_Extends extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - - if (!$this->parser->isMainScope()) { - throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext()); - } - - if (null !== $this->parser->getParent()) { - throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); - } - $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - } - - public function getTag() - { - return 'extends'; - } -} - -class_alias('Twig_TokenParser_Extends', 'Twig\TokenParser\ExtendsTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Filter.php b/system/templateEngines/Twig/Twig2x/TokenParser/Filter.php deleted file mode 100644 index 2dc45e3..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Filter.php +++ /dev/null @@ -1,51 +0,0 @@ - - * {% filter upper %} - * This text becomes uppercase - * {% endfilter %} - * - */ -final class Twig_TokenParser_Filter extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $name = $this->parser->getVarName(); - $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), null, $token->getLine(), $this->getTag()); - - $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); - $this->parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $this->parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $block = new Twig_Node_Block($name, $body, $token->getLine()); - $this->parser->setBlock($name, $block); - - return new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endfilter'); - } - - public function getTag() - { - return 'filter'; - } -} - -class_alias('Twig_TokenParser_Filter', 'Twig\TokenParser\FilterTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Flush.php b/system/templateEngines/Twig/Twig2x/TokenParser/Flush.php deleted file mode 100644 index 281e11c..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Flush.php +++ /dev/null @@ -1,32 +0,0 @@ -parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_Flush($token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'flush'; - } -} - -class_alias('Twig_TokenParser_Flush', 'Twig\TokenParser\FlushTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/For.php b/system/templateEngines/Twig/Twig2x/TokenParser/For.php deleted file mode 100644 index fb86900..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/For.php +++ /dev/null @@ -1,125 +0,0 @@ - - *
      - * {% for user in users %} - *
    • {{ user.username|e }}
    • - * {% endfor %} - *
    - * - */ -final class Twig_TokenParser_For extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); - $stream->expect(/* Twig_Token::OPERATOR_TYPE */ 8, 'in'); - $seq = $this->parser->getExpressionParser()->parseExpression(); - - $ifexpr = null; - if ($stream->nextIf(/* Twig_Token::NAME_TYPE */ 5, 'if')) { - $ifexpr = $this->parser->getExpressionParser()->parseExpression(); - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $body = $this->parser->subparse([$this, 'decideForFork']); - if ('else' == $stream->next()->getValue()) { - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $else = $this->parser->subparse([$this, 'decideForEnd'], true); - } else { - $else = null; - } - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - if (count($targets) > 1) { - $keyTarget = $targets->getNode(0); - $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); - $valueTarget = $targets->getNode(1); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); - } else { - $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno); - $valueTarget = $targets->getNode(0); - $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); - } - - if ($ifexpr) { - $this->checkLoopUsageCondition($stream, $ifexpr); - $this->checkLoopUsageBody($stream, $body); - } - - return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); - } - - public function decideForFork(Twig_Token $token) - { - return $token->test(['else', 'endfor']); - } - - public function decideForEnd(Twig_Token $token) - { - return $token->test('endfor'); - } - - // the loop variable cannot be used in the condition - private function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_Node $node) - { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); - } - - foreach ($node as $n) { - if (!$n) { - continue; - } - - $this->checkLoopUsageCondition($stream, $n); - } - } - - // check usage of non-defined loop-items - // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) - private function checkLoopUsageBody(Twig_TokenStream $stream, Twig_Node $node) - { - if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { - $attribute = $node->getNode('attribute'); - if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { - throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); - } - } - - // should check for parent.loop.XXX usage - if ($node instanceof Twig_Node_For) { - return; - } - - foreach ($node as $n) { - if (!$n) { - continue; - } - - $this->checkLoopUsageBody($stream, $n); - } - } - - public function getTag() - { - return 'for'; - } -} - -class_alias('Twig_TokenParser_For', 'Twig\TokenParser\ForTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/From.php b/system/templateEngines/Twig/Twig2x/TokenParser/From.php deleted file mode 100644 index b57b20a..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/From.php +++ /dev/null @@ -1,60 +0,0 @@ - - * {% from 'forms.html' import forms %} - * - */ -final class Twig_TokenParser_From extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $macro = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - $stream->expect('import'); - - $targets = []; - do { - $name = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - - $alias = $name; - if ($stream->nextIf('as')) { - $alias = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - } - - $targets[$name] = $alias; - - if (!$stream->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',')) { - break; - } - } while (true); - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); - - foreach ($targets as $name => $alias) { - $this->parser->addImportedSymbol('function', $alias, 'macro_'.$name, $node->getNode('var')); - } - - return $node; - } - - public function getTag() - { - return 'from'; - } -} - -class_alias('Twig_TokenParser_From', 'Twig\TokenParser\FromTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/If.php b/system/templateEngines/Twig/Twig2x/TokenParser/If.php deleted file mode 100644 index 8b20690..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/If.php +++ /dev/null @@ -1,84 +0,0 @@ - - * {% if users %} - *
      - * {% for user in users %} - *
    • {{ user.username|e }}
    • - * {% endfor %} - *
    - * {% endif %} - * - */ -final class Twig_TokenParser_If extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $body = $this->parser->subparse([$this, 'decideIfFork']); - $tests = [$expr, $body]; - $else = null; - - $end = false; - while (!$end) { - switch ($stream->next()->getValue()) { - case 'else': - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $else = $this->parser->subparse([$this, 'decideIfEnd']); - break; - - case 'elseif': - $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $body = $this->parser->subparse([$this, 'decideIfFork']); - $tests[] = $expr; - $tests[] = $body; - break; - - case 'endif': - $end = true; - break; - - default: - throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); - } - - public function decideIfFork(Twig_Token $token) - { - return $token->test(['elseif', 'else', 'endif']); - } - - public function decideIfEnd(Twig_Token $token) - { - return $token->test(['endif']); - } - - public function getTag() - { - return 'if'; - } -} - -class_alias('Twig_TokenParser_If', 'Twig\TokenParser\IfTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Import.php b/system/templateEngines/Twig/Twig2x/TokenParser/Import.php deleted file mode 100644 index 39d9f2e..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Import.php +++ /dev/null @@ -1,39 +0,0 @@ - - * {% import 'forms.html' as forms %} - * - */ -final class Twig_TokenParser_Import extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $macro = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect('as'); - $var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(), $token->getLine()); - $this->parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $this->parser->addImportedSymbol('template', $var->getAttribute('name')); - - return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag()); - } - - public function getTag() - { - return 'import'; - } -} - -class_alias('Twig_TokenParser_Import', 'Twig\TokenParser\ImportTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Include.php b/system/templateEngines/Twig/Twig2x/TokenParser/Include.php deleted file mode 100644 index 53d8c12..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Include.php +++ /dev/null @@ -1,65 +0,0 @@ - - * {% include 'header.html' %} - * Body - * {% include 'footer.html' %} - * - */ -class Twig_TokenParser_Include extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $expr = $this->parser->getExpressionParser()->parseExpression(); - - list($variables, $only, $ignoreMissing) = $this->parseArguments(); - - return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); - } - - protected function parseArguments() - { - $stream = $this->parser->getStream(); - - $ignoreMissing = false; - if ($stream->nextIf(/* Twig_Token::NAME_TYPE */ 5, 'ignore')) { - $stream->expect(/* Twig_Token::NAME_TYPE */ 5, 'missing'); - - $ignoreMissing = true; - } - - $variables = null; - if ($stream->nextIf(/* Twig_Token::NAME_TYPE */ 5, 'with')) { - $variables = $this->parser->getExpressionParser()->parseExpression(); - } - - $only = false; - if ($stream->nextIf(/* Twig_Token::NAME_TYPE */ 5, 'only')) { - $only = true; - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return [$variables, $only, $ignoreMissing]; - } - - public function getTag() - { - return 'include'; - } -} - -class_alias('Twig_TokenParser_Include', 'Twig\TokenParser\IncludeTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Macro.php b/system/templateEngines/Twig/Twig2x/TokenParser/Macro.php deleted file mode 100644 index 315ed51..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Macro.php +++ /dev/null @@ -1,58 +0,0 @@ - - * {% macro input(name, value, type, size) %} - * - * {% endmacro %} - * - */ -final class Twig_TokenParser_Macro extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $name = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - - $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $this->parser->pushLocalScope(); - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(/* Twig_Token::NAME_TYPE */ 5)) { - $value = $token->getValue(); - - if ($value != $name) { - throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } - $this->parser->popLocalScope(); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body([$body]), $arguments, $lineno, $this->getTag())); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endmacro'); - } - - public function getTag() - { - return 'macro'; - } -} - -class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Sandbox.php b/system/templateEngines/Twig/Twig2x/TokenParser/Sandbox.php deleted file mode 100644 index 495b72a..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Sandbox.php +++ /dev/null @@ -1,59 +0,0 @@ - - * {% sandbox %} - * {% include 'user.html' %} - * {% endsandbox %} - * - * - * @see https://twig.symfony.com/doc/api.html#sandbox-extension for details - */ -final class Twig_TokenParser_Sandbox extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - // in a sandbox tag, only include tags are allowed - if (!$body instanceof Twig_Node_Include) { - foreach ($body as $node) { - if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { - continue; - } - - if (!$node instanceof Twig_Node_Include) { - throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); - } - } - } - - return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endsandbox'); - } - - public function getTag() - { - return 'sandbox'; - } -} - -class_alias('Twig_TokenParser_Sandbox', 'Twig\TokenParser\SandboxTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Set.php b/system/templateEngines/Twig/Twig2x/TokenParser/Set.php deleted file mode 100644 index cdc61d7..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Set.php +++ /dev/null @@ -1,73 +0,0 @@ - - * {% set foo = 'foo' %} - * - * {% set foo = [1, 2] %} - * - * {% set foo = {'foo': 'bar'} %} - * - * {% set foo = 'foo' ~ 'bar' %} - * - * {% set foo, bar = 'foo', 'bar' %} - * - * {% set foo %}Some content{% endset %} - * - */ -final class Twig_TokenParser_Set extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - $stream = $this->parser->getStream(); - $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); - - $capture = false; - if ($stream->nextIf(/* Twig_Token::OPERATOR_TYPE */ 8, '=')) { - $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - if (count($names) !== count($values)) { - throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - } else { - $capture = true; - - if (count($names) > 1) { - throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - } - - return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag()); - } - - public function decideBlockEnd(Twig_Token $token) - { - return $token->test('endset'); - } - - public function getTag() - { - return 'set'; - } -} - -class_alias('Twig_TokenParser_Set', 'Twig\TokenParser\SetTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Spaceless.php b/system/templateEngines/Twig/Twig2x/TokenParser/Spaceless.php deleted file mode 100644 index fda4c4f..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Spaceless.php +++ /dev/null @@ -1,49 +0,0 @@ - - * {% spaceless %} - *
    - * foo - *
    - * {% endspaceless %} - * - * {# output will be
    foo
    #} - * - */ -final class Twig_TokenParser_Spaceless extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $lineno = $token->getLine(); - - $this->parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); - $this->parser->getStream()->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_Spaceless($body, $lineno, $this->getTag()); - } - - public function decideSpacelessEnd(Twig_Token $token) - { - return $token->test('endspaceless'); - } - - public function getTag() - { - return 'spaceless'; - } -} - -class_alias('Twig_TokenParser_Spaceless', 'Twig\TokenParser\SpacelessTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/Use.php b/system/templateEngines/Twig/Twig2x/TokenParser/Use.php deleted file mode 100644 index 9de07ba..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/Use.php +++ /dev/null @@ -1,68 +0,0 @@ - - * {% extends "base.html" %} - * - * {% use "blocks.html" %} - * - * {% block title %}{% endblock %} - * {% block content %}{% endblock %} - * - * - * @see https://twig.symfony.com/doc/templates.html#horizontal-reuse for details. - */ -final class Twig_TokenParser_Use extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $template = $this->parser->getExpressionParser()->parseExpression(); - $stream = $this->parser->getStream(); - - if (!$template instanceof Twig_Node_Expression_Constant) { - throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); - } - - $targets = []; - if ($stream->nextIf('with')) { - do { - $name = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - - $alias = $name; - if ($stream->nextIf('as')) { - $alias = $stream->expect(/* Twig_Token::NAME_TYPE */ 5)->getValue(); - } - - $targets[$name] = new Twig_Node_Expression_Constant($alias, -1); - - if (!$stream->nextIf(/* Twig_Token::PUNCTUATION_TYPE */ 9, ',')) { - break; - } - } while (true); - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $this->parser->addTrait(new Twig_Node(['template' => $template, 'targets' => new Twig_Node($targets)])); - - return new Twig_Node(); - } - - public function getTag() - { - return 'use'; - } -} - -class_alias('Twig_TokenParser_Use', 'Twig\TokenParser\UseTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParser/With.php b/system/templateEngines/Twig/Twig2x/TokenParser/With.php deleted file mode 100644 index 2b0f95f..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParser/With.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ -final class Twig_TokenParser_With extends Twig_TokenParser -{ - public function parse(Twig_Token $token) - { - $stream = $this->parser->getStream(); - - $variables = null; - $only = false; - if (!$stream->test(/* Twig_Token::BLOCK_END_TYPE */ 3)) { - $variables = $this->parser->getExpressionParser()->parseExpression(); - $only = $stream->nextIf(/* Twig_Token::NAME_TYPE */ 5, 'only'); - } - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - $body = $this->parser->subparse([$this, 'decideWithEnd'], true); - - $stream->expect(/* Twig_Token::BLOCK_END_TYPE */ 3); - - return new Twig_Node_With($body, $variables, $only, $token->getLine(), $this->getTag()); - } - - public function decideWithEnd(Twig_Token $token) - { - return $token->test('endwith'); - } - - public function getTag() - { - return 'with'; - } -} - -class_alias('Twig_TokenParser_With', 'Twig\TokenParser\WithTokenParser', false); diff --git a/system/templateEngines/Twig/Twig2x/TokenParserInterface.php b/system/templateEngines/Twig/Twig2x/TokenParserInterface.php deleted file mode 100644 index ee5e09e..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenParserInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -interface Twig_TokenParserInterface -{ - /** - * Sets the parser associated with this token parser. - */ - public function setParser(Twig_Parser $parser); - - /** - * Parses a token and returns a node. - * - * @return Twig_Node A Twig_Node instance - * - * @throws Twig_Error_Syntax - */ - public function parse(Twig_Token $token); - - /** - * Gets the tag name associated with this token parser. - * - * @return string The tag name - */ - public function getTag(); -} - -class_alias('Twig_TokenParserInterface', 'Twig\TokenParser\TokenParserInterface', false); -class_exists('Twig_Parser'); -class_exists('Twig_Token'); diff --git a/system/templateEngines/Twig/Twig2x/TokenStream.php b/system/templateEngines/Twig/Twig2x/TokenStream.php deleted file mode 100644 index 878cfdd..0000000 --- a/system/templateEngines/Twig/Twig2x/TokenStream.php +++ /dev/null @@ -1,150 +0,0 @@ - - */ -final class Twig_TokenStream -{ - private $tokens; - private $current = 0; - private $source; - - /** - * @param array $tokens An array of tokens - * @param Twig_Source $source - */ - public function __construct(array $tokens, Twig_Source $source = null) - { - $this->tokens = $tokens; - $this->source = $source ?: new Twig_Source('', ''); - } - - public function __toString() - { - return implode("\n", $this->tokens); - } - - public function injectTokens(array $tokens) - { - $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current)); - } - - /** - * Sets the pointer to the next token and returns the old one. - * - * @return Twig_Token - */ - public function next() - { - if (!isset($this->tokens[++$this->current])) { - throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); - } - - return $this->tokens[$this->current - 1]; - } - - /** - * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. - * - * @return Twig_Token|null The next token if the condition is true, null otherwise - */ - public function nextIf($primary, $secondary = null) - { - if ($this->tokens[$this->current]->test($primary, $secondary)) { - return $this->next(); - } - } - - /** - * Tests a token and returns it or throws a syntax error. - * - * @return Twig_Token - */ - public function expect($type, $value = null, $message = null) - { - $token = $this->tokens[$this->current]; - if (!$token->test($type, $value)) { - $line = $token->getLine(); - throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', - $message ? $message.'. ' : '', - Twig_Token::typeToEnglish($token->getType()), $token->getValue(), - Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), - $line, - $this->source - ); - } - $this->next(); - - return $token; - } - - /** - * Looks at the next token. - * - * @param int $number - * - * @return Twig_Token - */ - public function look($number = 1) - { - if (!isset($this->tokens[$this->current + $number])) { - throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); - } - - return $this->tokens[$this->current + $number]; - } - - /** - * Tests the current token. - * - * @return bool - */ - public function test($primary, $secondary = null) - { - return $this->tokens[$this->current]->test($primary, $secondary); - } - - /** - * Checks if end of stream was reached. - * - * @return bool - */ - public function isEOF() - { - return /* Twig_Token::EOF_TYPE */ -1 === $this->tokens[$this->current]->getType(); - } - - /** - * @return Twig_Token - */ - public function getCurrent() - { - return $this->tokens[$this->current]; - } - - /** - * Gets the source associated with this stream. - * - * @return Twig_Source - * - * @internal - */ - public function getSourceContext() - { - return $this->source; - } -} - -class_alias('Twig_TokenStream', 'Twig\TokenStream', false); diff --git a/system/templateEngines/Twig/Twig2x/Util/DeprecationCollector.php b/system/templateEngines/Twig/Twig2x/Util/DeprecationCollector.php deleted file mode 100644 index 6959a41..0000000 --- a/system/templateEngines/Twig/Twig2x/Util/DeprecationCollector.php +++ /dev/null @@ -1,73 +0,0 @@ - - */ -final class Twig_Util_DeprecationCollector -{ - private $twig; - - public function __construct(Twig_Environment $twig) - { - $this->twig = $twig; - } - - /** - * Returns deprecations for templates contained in a directory. - * - * @param string $dir A directory where templates are stored - * @param string $ext Limit the loaded templates by extension - * - * @return array An array of deprecations - */ - public function collectDir($dir, $ext = '.twig') - { - $iterator = new RegexIterator( - new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY - ), '{'.preg_quote($ext).'$}' - ); - - return $this->collect(new Twig_Util_TemplateDirIterator($iterator)); - } - - /** - * Returns deprecations for passed templates. - * - * @param Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) - * - * @return array An array of deprecations - */ - public function collect(Traversable $iterator) - { - $deprecations = []; - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED === $type) { - $deprecations[] = $msg; - } - }); - - foreach ($iterator as $name => $contents) { - try { - $this->twig->parse($this->twig->tokenize(new Twig_Source($contents, $name))); - } catch (Twig_Error_Syntax $e) { - // ignore templates containing syntax errors - } - } - - restore_error_handler(); - - return $deprecations; - } -} - -class_alias('Twig_Util_DeprecationCollector', 'Twig\Util\DeprecationCollector', false); diff --git a/system/templateEngines/Twig/Twig2x/Util/TemplateDirIterator.php b/system/templateEngines/Twig/Twig2x/Util/TemplateDirIterator.php deleted file mode 100644 index c868233..0000000 --- a/system/templateEngines/Twig/Twig2x/Util/TemplateDirIterator.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ -class Twig_Util_TemplateDirIterator extends IteratorIterator -{ - public function current() - { - return file_get_contents(parent::current()); - } - - public function key() - { - return (string) parent::key(); - } -} - -class_alias('Twig_Util_TemplateDirIterator', 'Twig\Util\TemplateDirIterator', false); diff --git a/system/templateEngines/Twig/Twig2x/autoload.php b/system/templateEngines/Twig/Twig2x/autoload.php new file mode 100644 index 0000000..bf8baa6 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/system/templateEngines/Twig/Twig2x/composer/LICENSE b/system/templateEngines/Twig/Twig2x/composer/LICENSE new file mode 100644 index 0000000..f27399a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/system/templateEngines/Twig/Twig2x/composer/autoload_classmap.php b/system/templateEngines/Twig/Twig2x/composer/autoload_classmap.php new file mode 100644 index 0000000..7a91153 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', +); diff --git a/system/templateEngines/Twig/Twig2x/composer/autoload_namespaces.php b/system/templateEngines/Twig/Twig2x/composer/autoload_namespaces.php new file mode 100644 index 0000000..a7edd32 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/autoload_namespaces.php @@ -0,0 +1,10 @@ + array($vendorDir . '/twig/twig/lib'), +); diff --git a/system/templateEngines/Twig/Twig2x/composer/autoload_psr4.php b/system/templateEngines/Twig/Twig2x/composer/autoload_psr4.php new file mode 100644 index 0000000..b591d7b --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/autoload_psr4.php @@ -0,0 +1,12 @@ + array($vendorDir . '/twig/twig/src'), + 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), + 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), +); diff --git a/system/templateEngines/Twig/Twig2x/composer/autoload_real.php b/system/templateEngines/Twig/Twig2x/composer/autoload_real.php new file mode 100644 index 0000000..d327384 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/autoload_real.php @@ -0,0 +1,70 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit1187ddbb948ea98f88282cd2e2605ab8::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + if ($useStaticLoader) { + $includeFiles = Composer\Autoload\ComposerStaticInit1187ddbb948ea98f88282cd2e2605ab8::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } + foreach ($includeFiles as $fileIdentifier => $file) { + composerRequire1187ddbb948ea98f88282cd2e2605ab8($fileIdentifier, $file); + } + + return $loader; + } +} + +function composerRequire1187ddbb948ea98f88282cd2e2605ab8($fileIdentifier, $file) +{ + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { + require $file; + + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + } +} diff --git a/system/templateEngines/Twig/Twig2x/composer/autoload_static.php b/system/templateEngines/Twig/Twig2x/composer/autoload_static.php new file mode 100644 index 0000000..f1ac2f6 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/autoload_static.php @@ -0,0 +1,60 @@ + __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', + ); + + public static $prefixLengthsPsr4 = array ( + 'T' => + array ( + 'Twig\\' => 5, + ), + 'S' => + array ( + 'Symfony\\Polyfill\\Mbstring\\' => 26, + 'Symfony\\Polyfill\\Ctype\\' => 23, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Twig\\' => + array ( + 0 => __DIR__ . '/..' . '/twig/twig/src', + ), + 'Symfony\\Polyfill\\Mbstring\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring', + ), + 'Symfony\\Polyfill\\Ctype\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', + ), + ); + + public static $prefixesPsr0 = array ( + 'T' => + array ( + 'Twig_' => + array ( + 0 => __DIR__ . '/..' . '/twig/twig/lib', + ), + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit1187ddbb948ea98f88282cd2e2605ab8::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit1187ddbb948ea98f88282cd2e2605ab8::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInit1187ddbb948ea98f88282cd2e2605ab8::$prefixesPsr0; + + }, null, ClassLoader::class); + } +} diff --git a/system/templateEngines/Twig/Twig2x/composer/installed.json b/system/templateEngines/Twig/Twig2x/composer/installed.json new file mode 100644 index 0000000..e0982d1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/composer/installed.json @@ -0,0 +1,190 @@ +[ + { + "name": "symfony/polyfill-ctype", + "version": "v1.14.0", + "version_normalized": "1.14.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "time": "2020-01-13T11:15:53+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ] + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.14.0", + "version_normalized": "1.14.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/34094cfa9abe1f0f14f48f490772db7a775559f2", + "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "time": "2020-01-13T11:15:53+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ] + }, + { + "name": "twig/twig", + "version": "v2.12.5", + "version_normalized": "2.12.5.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "18772e0190734944277ee97a02a9a6c6555fcd94" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/18772e0190734944277ee97a02a9a6c6555fcd94", + "reference": "18772e0190734944277ee97a02a9a6c6555fcd94", + "shasum": "" + }, + "require": { + "php": "^7.0", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/phpunit-bridge": "^4.4|^5.0" + }, + "time": "2020-02-11T15:31:23+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.12-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Twig_": "lib/" + }, + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ] + } +] diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/Ctype.php b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/Ctype.php new file mode 100644 index 0000000..58414dc --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/Ctype.php @@ -0,0 +1,227 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Ctype; + +/** + * Ctype implementation through regex. + * + * @internal + * + * @author Gert de Pagter + */ +final class Ctype +{ + /** + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. + * + * @see https://php.net/ctype-alnum + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alnum($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is a letter, FALSE otherwise. + * + * @see https://php.net/ctype-alpha + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alpha($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); + } + + /** + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. + * + * @see https://php.net/ctype-cntrl + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_cntrl($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); + } + + /** + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. + * + * @see https://php.net/ctype-digit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_digit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. + * + * @see https://php.net/ctype-graph + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_graph($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); + } + + /** + * Returns TRUE if every character in text is a lowercase letter. + * + * @see https://php.net/ctype-lower + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_lower($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-print + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_print($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); + } + + /** + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. + * + * @see https://php.net/ctype-punct + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_punct($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-space + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_space($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); + } + + /** + * Returns TRUE if every character in text is an uppercase letter. + * + * @see https://php.net/ctype-upper + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_upper($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-xdigit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_xdigit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); + } + + /** + * Converts integers to their char versions according to normal ctype behaviour, if needed. + * + * If an integer between -128 and 255 inclusive is provided, + * it is interpreted as the ASCII value of a single character + * (negative values have 256 added in order to allow characters in the Extended ASCII range). + * Any other integer is interpreted as a string containing the decimal digits of the integer. + * + * @param string|int $int + * + * @return mixed + */ + private static function convert_int_to_char_for_ctype($int) + { + if (!\is_int($int)) { + return $int; + } + + if ($int < -128 || $int > 255) { + return (string) $int; + } + + if ($int < 0) { + $int += 256; + } + + return \chr($int); + } +} diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/LICENSE b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/LICENSE new file mode 100644 index 0000000..3f853aa --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/README.md b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/README.md new file mode 100644 index 0000000..8add1ab --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/README.md @@ -0,0 +1,12 @@ +Symfony Polyfill / Ctype +======================== + +This component provides `ctype_*` functions to users who run php versions without the ctype extension. + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/bootstrap.php b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/bootstrap.php new file mode 100644 index 0000000..14d1d0f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/bootstrap.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (!function_exists('ctype_alnum')) { + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } + function ctype_print($text) { return p\Ctype::ctype_print($text); } + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } + function ctype_space($text) { return p\Ctype::ctype_space($text); } + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } +} diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/composer.json b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/composer.json new file mode 100644 index 0000000..2596c74 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-ctype/composer.json @@ -0,0 +1,34 @@ +{ + "name": "symfony/polyfill-ctype", + "type": "library", + "description": "Symfony polyfill for ctype functions", + "keywords": ["polyfill", "compatibility", "portable", "ctype"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.3" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Ctype\\": "" }, + "files": [ "bootstrap.php" ] + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + } +} diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/LICENSE b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/LICENSE new file mode 100644 index 0000000..4cd8bdd --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015-2019 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Mbstring.php b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Mbstring.php new file mode 100644 index 0000000..15503bc --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Mbstring.php @@ -0,0 +1,847 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Mbstring; + +/** + * Partial mbstring implementation in PHP, iconv based, UTF-8 centric. + * + * Implemented: + * - mb_chr - Returns a specific character from its Unicode code point + * - mb_convert_encoding - Convert character encoding + * - mb_convert_variables - Convert character code in variable(s) + * - mb_decode_mimeheader - Decode string in MIME header field + * - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED + * - mb_decode_numericentity - Decode HTML numeric string reference to character + * - mb_encode_numericentity - Encode character to HTML numeric string reference + * - mb_convert_case - Perform case folding on a string + * - mb_detect_encoding - Detect character encoding + * - mb_get_info - Get internal settings of mbstring + * - mb_http_input - Detect HTTP input character encoding + * - mb_http_output - Set/Get HTTP output character encoding + * - mb_internal_encoding - Set/Get internal character encoding + * - mb_list_encodings - Returns an array of all supported encodings + * - mb_ord - Returns the Unicode code point of a character + * - mb_output_handler - Callback function converts character encoding in output buffer + * - mb_scrub - Replaces ill-formed byte sequences with substitute characters + * - mb_strlen - Get string length + * - mb_strpos - Find position of first occurrence of string in a string + * - mb_strrpos - Find position of last occurrence of a string in a string + * - mb_str_split - Convert a string to an array + * - mb_strtolower - Make a string lowercase + * - mb_strtoupper - Make a string uppercase + * - mb_substitute_character - Set/Get substitution character + * - mb_substr - Get part of string + * - mb_stripos - Finds position of first occurrence of a string within another, case insensitive + * - mb_stristr - Finds first occurrence of a string within another, case insensitive + * - mb_strrchr - Finds the last occurrence of a character in a string within another + * - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive + * - mb_strripos - Finds position of last occurrence of a string within another, case insensitive + * - mb_strstr - Finds first occurrence of a string within another + * - mb_strwidth - Return width of string + * - mb_substr_count - Count the number of substring occurrences + * + * Not implemented: + * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more) + * - mb_ereg_* - Regular expression with multibyte support + * - mb_parse_str - Parse GET/POST/COOKIE data and set global variable + * - mb_preferred_mime_name - Get MIME charset string + * - mb_regex_encoding - Returns current encoding for multibyte regex as string + * - mb_regex_set_options - Set/Get the default options for mbregex functions + * - mb_send_mail - Send encoded mail + * - mb_split - Split multibyte string using regular expression + * - mb_strcut - Get part of string + * - mb_strimwidth - Get truncated string with specified width + * + * @author Nicolas Grekas + * + * @internal + */ +final class Mbstring +{ + const MB_CASE_FOLD = PHP_INT_MAX; + + private static $encodingList = array('ASCII', 'UTF-8'); + private static $language = 'neutral'; + private static $internalEncoding = 'UTF-8'; + private static $caseFold = array( + array('µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"), + array('μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'), + ); + + public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) + { + if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) { + $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); + } else { + $fromEncoding = self::getEncoding($fromEncoding); + } + + $toEncoding = self::getEncoding($toEncoding); + + if ('BASE64' === $fromEncoding) { + $s = base64_decode($s); + $fromEncoding = $toEncoding; + } + + if ('BASE64' === $toEncoding) { + return base64_encode($s); + } + + if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) { + if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) { + $fromEncoding = 'Windows-1252'; + } + if ('UTF-8' !== $fromEncoding) { + $s = iconv($fromEncoding, 'UTF-8//IGNORE', $s); + } + + return preg_replace_callback('/[\x80-\xFF]+/', array(__CLASS__, 'html_encoding_callback'), $s); + } + + if ('HTML-ENTITIES' === $fromEncoding) { + $s = html_entity_decode($s, ENT_COMPAT, 'UTF-8'); + $fromEncoding = 'UTF-8'; + } + + return iconv($fromEncoding, $toEncoding.'//IGNORE', $s); + } + + public static function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null) + { + $vars = array(&$a, &$b, &$c, &$d, &$e, &$f); + + $ok = true; + array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) { + if (false === $v = Mbstring::mb_convert_encoding($v, $toEncoding, $fromEncoding)) { + $ok = false; + } + }); + + return $ok ? $fromEncoding : false; + } + + public static function mb_decode_mimeheader($s) + { + return iconv_mime_decode($s, 2, self::$internalEncoding); + } + + public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null) + { + trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING); + } + + public static function mb_decode_numericentity($s, $convmap, $encoding = null) + { + if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { + trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return null; + } + + if (!\is_array($convmap) || !$convmap) { + return false; + } + + if (null !== $encoding && !\is_scalar($encoding)) { + trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return ''; // Instead of null (cf. mb_encode_numericentity). + } + + $s = (string) $s; + if ('' === $s) { + return ''; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding) { + $encoding = null; + if (!preg_match('//u', $s)) { + $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s); + } + } else { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + $cnt = floor(\count($convmap) / 4) * 4; + + for ($i = 0; $i < $cnt; $i += 4) { + // collector_decode_htmlnumericentity ignores $convmap[$i + 3] + $convmap[$i] += $convmap[$i + 2]; + $convmap[$i + 1] += $convmap[$i + 2]; + } + + $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) { + $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1]; + for ($i = 0; $i < $cnt; $i += 4) { + if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { + return Mbstring::mb_chr($c - $convmap[$i + 2]); + } + } + + return $m[0]; + }, $s); + + if (null === $encoding) { + return $s; + } + + return iconv('UTF-8', $encoding.'//IGNORE', $s); + } + + public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) + { + if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { + trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return null; + } + + if (!\is_array($convmap) || !$convmap) { + return false; + } + + if (null !== $encoding && !\is_scalar($encoding)) { + trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return null; // Instead of '' (cf. mb_decode_numericentity). + } + + if (null !== $is_hex && !\is_scalar($is_hex)) { + trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', E_USER_WARNING); + + return null; + } + + $s = (string) $s; + if ('' === $s) { + return ''; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding) { + $encoding = null; + if (!preg_match('//u', $s)) { + $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s); + } + } else { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); + + $cnt = floor(\count($convmap) / 4) * 4; + $i = 0; + $len = \strlen($s); + $result = ''; + + while ($i < $len) { + $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; + $uchr = substr($s, $i, $ulen); + $i += $ulen; + $c = self::mb_ord($uchr); + + for ($j = 0; $j < $cnt; $j += 4) { + if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) { + $cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3]; + $result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';'; + continue 2; + } + } + $result .= $uchr; + } + + if (null === $encoding) { + return $result; + } + + return iconv('UTF-8', $encoding.'//IGNORE', $result); + } + + public static function mb_convert_case($s, $mode, $encoding = null) + { + $s = (string) $s; + if ('' === $s) { + return ''; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding) { + $encoding = null; + if (!preg_match('//u', $s)) { + $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s); + } + } else { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + if (MB_CASE_TITLE == $mode) { + static $titleRegexp = null; + if (null === $titleRegexp) { + $titleRegexp = self::getData('titleCaseRegexp'); + } + $s = preg_replace_callback($titleRegexp, array(__CLASS__, 'title_case'), $s); + } else { + if (MB_CASE_UPPER == $mode) { + static $upper = null; + if (null === $upper) { + $upper = self::getData('upperCase'); + } + $map = $upper; + } else { + if (self::MB_CASE_FOLD === $mode) { + $s = str_replace(self::$caseFold[0], self::$caseFold[1], $s); + } + + static $lower = null; + if (null === $lower) { + $lower = self::getData('lowerCase'); + } + $map = $lower; + } + + static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); + + $i = 0; + $len = \strlen($s); + + while ($i < $len) { + $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; + $uchr = substr($s, $i, $ulen); + $i += $ulen; + + if (isset($map[$uchr])) { + $uchr = $map[$uchr]; + $nlen = \strlen($uchr); + + if ($nlen == $ulen) { + $nlen = $i; + do { + $s[--$nlen] = $uchr[--$ulen]; + } while ($ulen); + } else { + $s = substr_replace($s, $uchr, $i - $ulen, $ulen); + $len += $nlen - $ulen; + $i += $nlen - $ulen; + } + } + } + } + + if (null === $encoding) { + return $s; + } + + return iconv('UTF-8', $encoding.'//IGNORE', $s); + } + + public static function mb_internal_encoding($encoding = null) + { + if (null === $encoding) { + return self::$internalEncoding; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding || false !== @iconv($encoding, $encoding, ' ')) { + self::$internalEncoding = $encoding; + + return true; + } + + return false; + } + + public static function mb_language($lang = null) + { + if (null === $lang) { + return self::$language; + } + + switch ($lang = strtolower($lang)) { + case 'uni': + case 'neutral': + self::$language = $lang; + + return true; + } + + return false; + } + + public static function mb_list_encodings() + { + return array('UTF-8'); + } + + public static function mb_encoding_aliases($encoding) + { + switch (strtoupper($encoding)) { + case 'UTF8': + case 'UTF-8': + return array('utf8'); + } + + return false; + } + + public static function mb_check_encoding($var = null, $encoding = null) + { + if (null === $encoding) { + if (null === $var) { + return false; + } + $encoding = self::$internalEncoding; + } + + return self::mb_detect_encoding($var, array($encoding)) || false !== @iconv($encoding, $encoding, $var); + } + + public static function mb_detect_encoding($str, $encodingList = null, $strict = false) + { + if (null === $encodingList) { + $encodingList = self::$encodingList; + } else { + if (!\is_array($encodingList)) { + $encodingList = array_map('trim', explode(',', $encodingList)); + } + $encodingList = array_map('strtoupper', $encodingList); + } + + foreach ($encodingList as $enc) { + switch ($enc) { + case 'ASCII': + if (!preg_match('/[\x80-\xFF]/', $str)) { + return $enc; + } + break; + + case 'UTF8': + case 'UTF-8': + if (preg_match('//u', $str)) { + return 'UTF-8'; + } + break; + + default: + if (0 === strncmp($enc, 'ISO-8859-', 9)) { + return $enc; + } + } + } + + return false; + } + + public static function mb_detect_order($encodingList = null) + { + if (null === $encodingList) { + return self::$encodingList; + } + + if (!\is_array($encodingList)) { + $encodingList = array_map('trim', explode(',', $encodingList)); + } + $encodingList = array_map('strtoupper', $encodingList); + + foreach ($encodingList as $enc) { + switch ($enc) { + default: + if (strncmp($enc, 'ISO-8859-', 9)) { + return false; + } + // no break + case 'ASCII': + case 'UTF8': + case 'UTF-8': + } + } + + self::$encodingList = $encodingList; + + return true; + } + + public static function mb_strlen($s, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return \strlen($s); + } + + return @iconv_strlen($s, $encoding); + } + + public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return strpos($haystack, $needle, $offset); + } + + $needle = (string) $needle; + if ('' === $needle) { + trigger_error(__METHOD__.': Empty delimiter', E_USER_WARNING); + + return false; + } + + return iconv_strpos($haystack, $needle, $offset, $encoding); + } + + public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return strrpos($haystack, $needle, $offset); + } + + if ($offset != (int) $offset) { + $offset = 0; + } elseif ($offset = (int) $offset) { + if ($offset < 0) { + if (0 > $offset += self::mb_strlen($needle)) { + $haystack = self::mb_substr($haystack, 0, $offset, $encoding); + } + $offset = 0; + } else { + $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding); + } + } + + $pos = iconv_strrpos($haystack, $needle, $encoding); + + return false !== $pos ? $offset + $pos : false; + } + + public static function mb_str_split($string, $split_length = 1, $encoding = null) + { + if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) { + trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', E_USER_WARNING); + + return null; + } + + if (1 > $split_length = (int) $split_length) { + trigger_error('The length of each segment must be greater than zero', E_USER_WARNING); + + return false; + } + + if (null === $encoding) { + $encoding = mb_internal_encoding(); + } + + if ('UTF-8' === $encoding = self::getEncoding($encoding)) { + $rx = '/('; + while (65535 < $split_length) { + $rx .= '.{65535}'; + $split_length -= 65535; + } + $rx .= '.{'.$split_length.'})/us'; + + return preg_split($rx, $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + } + + $result = array(); + $length = mb_strlen($string, $encoding); + + for ($i = 0; $i < $length; $i += $split_length) { + $result[] = mb_substr($string, $i, $split_length, $encoding); + } + + return $result; + } + + public static function mb_strtolower($s, $encoding = null) + { + return self::mb_convert_case($s, MB_CASE_LOWER, $encoding); + } + + public static function mb_strtoupper($s, $encoding = null) + { + return self::mb_convert_case($s, MB_CASE_UPPER, $encoding); + } + + public static function mb_substitute_character($c = null) + { + if (0 === strcasecmp($c, 'none')) { + return true; + } + + return null !== $c ? false : 'none'; + } + + public static function mb_substr($s, $start, $length = null, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return (string) substr($s, $start, null === $length ? 2147483647 : $length); + } + + if ($start < 0) { + $start = iconv_strlen($s, $encoding) + $start; + if ($start < 0) { + $start = 0; + } + } + + if (null === $length) { + $length = 2147483647; + } elseif ($length < 0) { + $length = iconv_strlen($s, $encoding) + $length - $start; + if ($length < 0) { + return ''; + } + } + + return (string) iconv_substr($s, $start, $length, $encoding); + } + + public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) + { + $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); + $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); + + return self::mb_strpos($haystack, $needle, $offset, $encoding); + } + + public static function mb_stristr($haystack, $needle, $part = false, $encoding = null) + { + $pos = self::mb_stripos($haystack, $needle, 0, $encoding); + + return self::getSubpart($pos, $part, $haystack, $encoding); + } + + public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return strrchr($haystack, $needle, $part); + } + $needle = self::mb_substr($needle, 0, 1, $encoding); + $pos = iconv_strrpos($haystack, $needle, $encoding); + + return self::getSubpart($pos, $part, $haystack, $encoding); + } + + public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null) + { + $needle = self::mb_substr($needle, 0, 1, $encoding); + $pos = self::mb_strripos($haystack, $needle, $encoding); + + return self::getSubpart($pos, $part, $haystack, $encoding); + } + + public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) + { + $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); + $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); + + return self::mb_strrpos($haystack, $needle, $offset, $encoding); + } + + public static function mb_strstr($haystack, $needle, $part = false, $encoding = null) + { + $pos = strpos($haystack, $needle); + if (false === $pos) { + return false; + } + if ($part) { + return substr($haystack, 0, $pos); + } + + return substr($haystack, $pos); + } + + public static function mb_get_info($type = 'all') + { + $info = array( + 'internal_encoding' => self::$internalEncoding, + 'http_output' => 'pass', + 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)', + 'func_overload' => 0, + 'func_overload_list' => 'no overload', + 'mail_charset' => 'UTF-8', + 'mail_header_encoding' => 'BASE64', + 'mail_body_encoding' => 'BASE64', + 'illegal_chars' => 0, + 'encoding_translation' => 'Off', + 'language' => self::$language, + 'detect_order' => self::$encodingList, + 'substitute_character' => 'none', + 'strict_detection' => 'Off', + ); + + if ('all' === $type) { + return $info; + } + if (isset($info[$type])) { + return $info[$type]; + } + + return false; + } + + public static function mb_http_input($type = '') + { + return false; + } + + public static function mb_http_output($encoding = null) + { + return null !== $encoding ? 'pass' === $encoding : 'pass'; + } + + public static function mb_strwidth($s, $encoding = null) + { + $encoding = self::getEncoding($encoding); + + if ('UTF-8' !== $encoding) { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + $s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide); + + return ($wide << 1) + iconv_strlen($s, 'UTF-8'); + } + + public static function mb_substr_count($haystack, $needle, $encoding = null) + { + return substr_count($haystack, $needle); + } + + public static function mb_output_handler($contents, $status) + { + return $contents; + } + + public static function mb_chr($code, $encoding = null) + { + if (0x80 > $code %= 0x200000) { + $s = \chr($code); + } elseif (0x800 > $code) { + $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); + } elseif (0x10000 > $code) { + $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); + } else { + $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); + } + + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { + $s = mb_convert_encoding($s, $encoding, 'UTF-8'); + } + + return $s; + } + + public static function mb_ord($s, $encoding = null) + { + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { + $s = mb_convert_encoding($s, 'UTF-8', $encoding); + } + + if (1 === \strlen($s)) { + return \ord($s); + } + + $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; + if (0xF0 <= $code) { + return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; + } + if (0xE0 <= $code) { + return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; + } + if (0xC0 <= $code) { + return (($code - 0xC0) << 6) + $s[2] - 0x80; + } + + return $code; + } + + private static function getSubpart($pos, $part, $haystack, $encoding) + { + if (false === $pos) { + return false; + } + if ($part) { + return self::mb_substr($haystack, 0, $pos, $encoding); + } + + return self::mb_substr($haystack, $pos, null, $encoding); + } + + private static function html_encoding_callback(array $m) + { + $i = 1; + $entities = ''; + $m = unpack('C*', htmlentities($m[0], ENT_COMPAT, 'UTF-8')); + + while (isset($m[$i])) { + if (0x80 > $m[$i]) { + $entities .= \chr($m[$i++]); + continue; + } + if (0xF0 <= $m[$i]) { + $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; + } elseif (0xE0 <= $m[$i]) { + $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; + } else { + $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; + } + + $entities .= '&#'.$c.';'; + } + + return $entities; + } + + private static function title_case(array $s) + { + return self::mb_convert_case($s[1], MB_CASE_UPPER, 'UTF-8').self::mb_convert_case($s[2], MB_CASE_LOWER, 'UTF-8'); + } + + private static function getData($file) + { + if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) { + return require $file; + } + + return false; + } + + private static function getEncoding($encoding) + { + if (null === $encoding) { + return self::$internalEncoding; + } + + if ('UTF-8' === $encoding) { + return 'UTF-8'; + } + + $encoding = strtoupper($encoding); + + if ('8BIT' === $encoding || 'BINARY' === $encoding) { + return 'CP850'; + } + + if ('UTF8' === $encoding) { + return 'UTF-8'; + } + + return $encoding; + } +} diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/README.md b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/README.md new file mode 100644 index 0000000..342e828 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/README.md @@ -0,0 +1,13 @@ +Symfony Polyfill / Mbstring +=========================== + +This component provides a partial, native PHP implementation for the +[Mbstring](http://php.net/mbstring) extension. + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php new file mode 100644 index 0000000..e6fbfa6 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php @@ -0,0 +1,1096 @@ + 'a', + 'B' => 'b', + 'C' => 'c', + 'D' => 'd', + 'E' => 'e', + 'F' => 'f', + 'G' => 'g', + 'H' => 'h', + 'I' => 'i', + 'J' => 'j', + 'K' => 'k', + 'L' => 'l', + 'M' => 'm', + 'N' => 'n', + 'O' => 'o', + 'P' => 'p', + 'Q' => 'q', + 'R' => 'r', + 'S' => 's', + 'T' => 't', + 'U' => 'u', + 'V' => 'v', + 'W' => 'w', + 'X' => 'x', + 'Y' => 'y', + 'Z' => 'z', + 'À' => 'à', + 'Á' => 'á', + 'Â' => 'â', + 'Ã' => 'ã', + 'Ä' => 'ä', + 'Å' => 'å', + 'Æ' => 'æ', + 'Ç' => 'ç', + 'È' => 'è', + 'É' => 'é', + 'Ê' => 'ê', + 'Ë' => 'ë', + 'Ì' => 'ì', + 'Í' => 'í', + 'Î' => 'î', + 'Ï' => 'ï', + 'Ð' => 'ð', + 'Ñ' => 'ñ', + 'Ò' => 'ò', + 'Ó' => 'ó', + 'Ô' => 'ô', + 'Õ' => 'õ', + 'Ö' => 'ö', + 'Ø' => 'ø', + 'Ù' => 'ù', + 'Ú' => 'ú', + 'Û' => 'û', + 'Ü' => 'ü', + 'Ý' => 'ý', + 'Þ' => 'þ', + 'Ā' => 'ā', + 'Ă' => 'ă', + 'Ą' => 'ą', + 'Ć' => 'ć', + 'Ĉ' => 'ĉ', + 'Ċ' => 'ċ', + 'Č' => 'č', + 'Ď' => 'ď', + 'Đ' => 'đ', + 'Ē' => 'ē', + 'Ĕ' => 'ĕ', + 'Ė' => 'ė', + 'Ę' => 'ę', + 'Ě' => 'ě', + 'Ĝ' => 'ĝ', + 'Ğ' => 'ğ', + 'Ġ' => 'ġ', + 'Ģ' => 'ģ', + 'Ĥ' => 'ĥ', + 'Ħ' => 'ħ', + 'Ĩ' => 'ĩ', + 'Ī' => 'ī', + 'Ĭ' => 'ĭ', + 'Į' => 'į', + 'İ' => 'i', + 'IJ' => 'ij', + 'Ĵ' => 'ĵ', + 'Ķ' => 'ķ', + 'Ĺ' => 'ĺ', + 'Ļ' => 'ļ', + 'Ľ' => 'ľ', + 'Ŀ' => 'ŀ', + 'Ł' => 'ł', + 'Ń' => 'ń', + 'Ņ' => 'ņ', + 'Ň' => 'ň', + 'Ŋ' => 'ŋ', + 'Ō' => 'ō', + 'Ŏ' => 'ŏ', + 'Ő' => 'ő', + 'Œ' => 'œ', + 'Ŕ' => 'ŕ', + 'Ŗ' => 'ŗ', + 'Ř' => 'ř', + 'Ś' => 'ś', + 'Ŝ' => 'ŝ', + 'Ş' => 'ş', + 'Š' => 'š', + 'Ţ' => 'ţ', + 'Ť' => 'ť', + 'Ŧ' => 'ŧ', + 'Ũ' => 'ũ', + 'Ū' => 'ū', + 'Ŭ' => 'ŭ', + 'Ů' => 'ů', + 'Ű' => 'ű', + 'Ų' => 'ų', + 'Ŵ' => 'ŵ', + 'Ŷ' => 'ŷ', + 'Ÿ' => 'ÿ', + 'Ź' => 'ź', + 'Ż' => 'ż', + 'Ž' => 'ž', + 'Ɓ' => 'ɓ', + 'Ƃ' => 'ƃ', + 'Ƅ' => 'ƅ', + 'Ɔ' => 'ɔ', + 'Ƈ' => 'ƈ', + 'Ɖ' => 'ɖ', + 'Ɗ' => 'ɗ', + 'Ƌ' => 'ƌ', + 'Ǝ' => 'ǝ', + 'Ə' => 'ə', + 'Ɛ' => 'ɛ', + 'Ƒ' => 'ƒ', + 'Ɠ' => 'ɠ', + 'Ɣ' => 'ɣ', + 'Ɩ' => 'ɩ', + 'Ɨ' => 'ɨ', + 'Ƙ' => 'ƙ', + 'Ɯ' => 'ɯ', + 'Ɲ' => 'ɲ', + 'Ɵ' => 'ɵ', + 'Ơ' => 'ơ', + 'Ƣ' => 'ƣ', + 'Ƥ' => 'ƥ', + 'Ʀ' => 'ʀ', + 'Ƨ' => 'ƨ', + 'Ʃ' => 'ʃ', + 'Ƭ' => 'ƭ', + 'Ʈ' => 'ʈ', + 'Ư' => 'ư', + 'Ʊ' => 'ʊ', + 'Ʋ' => 'ʋ', + 'Ƴ' => 'ƴ', + 'Ƶ' => 'ƶ', + 'Ʒ' => 'ʒ', + 'Ƹ' => 'ƹ', + 'Ƽ' => 'ƽ', + 'DŽ' => 'dž', + 'Dž' => 'dž', + 'LJ' => 'lj', + 'Lj' => 'lj', + 'NJ' => 'nj', + 'Nj' => 'nj', + 'Ǎ' => 'ǎ', + 'Ǐ' => 'ǐ', + 'Ǒ' => 'ǒ', + 'Ǔ' => 'ǔ', + 'Ǖ' => 'ǖ', + 'Ǘ' => 'ǘ', + 'Ǚ' => 'ǚ', + 'Ǜ' => 'ǜ', + 'Ǟ' => 'ǟ', + 'Ǡ' => 'ǡ', + 'Ǣ' => 'ǣ', + 'Ǥ' => 'ǥ', + 'Ǧ' => 'ǧ', + 'Ǩ' => 'ǩ', + 'Ǫ' => 'ǫ', + 'Ǭ' => 'ǭ', + 'Ǯ' => 'ǯ', + 'DZ' => 'dz', + 'Dz' => 'dz', + 'Ǵ' => 'ǵ', + 'Ƕ' => 'ƕ', + 'Ƿ' => 'ƿ', + 'Ǹ' => 'ǹ', + 'Ǻ' => 'ǻ', + 'Ǽ' => 'ǽ', + 'Ǿ' => 'ǿ', + 'Ȁ' => 'ȁ', + 'Ȃ' => 'ȃ', + 'Ȅ' => 'ȅ', + 'Ȇ' => 'ȇ', + 'Ȉ' => 'ȉ', + 'Ȋ' => 'ȋ', + 'Ȍ' => 'ȍ', + 'Ȏ' => 'ȏ', + 'Ȑ' => 'ȑ', + 'Ȓ' => 'ȓ', + 'Ȕ' => 'ȕ', + 'Ȗ' => 'ȗ', + 'Ș' => 'ș', + 'Ț' => 'ț', + 'Ȝ' => 'ȝ', + 'Ȟ' => 'ȟ', + 'Ƞ' => 'ƞ', + 'Ȣ' => 'ȣ', + 'Ȥ' => 'ȥ', + 'Ȧ' => 'ȧ', + 'Ȩ' => 'ȩ', + 'Ȫ' => 'ȫ', + 'Ȭ' => 'ȭ', + 'Ȯ' => 'ȯ', + 'Ȱ' => 'ȱ', + 'Ȳ' => 'ȳ', + 'Ⱥ' => 'ⱥ', + 'Ȼ' => 'ȼ', + 'Ƚ' => 'ƚ', + 'Ⱦ' => 'ⱦ', + 'Ɂ' => 'ɂ', + 'Ƀ' => 'ƀ', + 'Ʉ' => 'ʉ', + 'Ʌ' => 'ʌ', + 'Ɇ' => 'ɇ', + 'Ɉ' => 'ɉ', + 'Ɋ' => 'ɋ', + 'Ɍ' => 'ɍ', + 'Ɏ' => 'ɏ', + 'Ͱ' => 'ͱ', + 'Ͳ' => 'ͳ', + 'Ͷ' => 'ͷ', + 'Ϳ' => 'ϳ', + 'Ά' => 'ά', + 'Έ' => 'έ', + 'Ή' => 'ή', + 'Ί' => 'ί', + 'Ό' => 'ό', + 'Ύ' => 'ύ', + 'Ώ' => 'ώ', + 'Α' => 'α', + 'Β' => 'β', + 'Γ' => 'γ', + 'Δ' => 'δ', + 'Ε' => 'ε', + 'Ζ' => 'ζ', + 'Η' => 'η', + 'Θ' => 'θ', + 'Ι' => 'ι', + 'Κ' => 'κ', + 'Λ' => 'λ', + 'Μ' => 'μ', + 'Ν' => 'ν', + 'Ξ' => 'ξ', + 'Ο' => 'ο', + 'Π' => 'π', + 'Ρ' => 'ρ', + 'Σ' => 'σ', + 'Τ' => 'τ', + 'Υ' => 'υ', + 'Φ' => 'φ', + 'Χ' => 'χ', + 'Ψ' => 'ψ', + 'Ω' => 'ω', + 'Ϊ' => 'ϊ', + 'Ϋ' => 'ϋ', + 'Ϗ' => 'ϗ', + 'Ϙ' => 'ϙ', + 'Ϛ' => 'ϛ', + 'Ϝ' => 'ϝ', + 'Ϟ' => 'ϟ', + 'Ϡ' => 'ϡ', + 'Ϣ' => 'ϣ', + 'Ϥ' => 'ϥ', + 'Ϧ' => 'ϧ', + 'Ϩ' => 'ϩ', + 'Ϫ' => 'ϫ', + 'Ϭ' => 'ϭ', + 'Ϯ' => 'ϯ', + 'ϴ' => 'θ', + 'Ϸ' => 'ϸ', + 'Ϲ' => 'ϲ', + 'Ϻ' => 'ϻ', + 'Ͻ' => 'ͻ', + 'Ͼ' => 'ͼ', + 'Ͽ' => 'ͽ', + 'Ѐ' => 'ѐ', + 'Ё' => 'ё', + 'Ђ' => 'ђ', + 'Ѓ' => 'ѓ', + 'Є' => 'є', + 'Ѕ' => 'ѕ', + 'І' => 'і', + 'Ї' => 'ї', + 'Ј' => 'ј', + 'Љ' => 'љ', + 'Њ' => 'њ', + 'Ћ' => 'ћ', + 'Ќ' => 'ќ', + 'Ѝ' => 'ѝ', + 'Ў' => 'ў', + 'Џ' => 'џ', + 'А' => 'а', + 'Б' => 'б', + 'В' => 'в', + 'Г' => 'г', + 'Д' => 'д', + 'Е' => 'е', + 'Ж' => 'ж', + 'З' => 'з', + 'И' => 'и', + 'Й' => 'й', + 'К' => 'к', + 'Л' => 'л', + 'М' => 'м', + 'Н' => 'н', + 'О' => 'о', + 'П' => 'п', + 'Р' => 'р', + 'С' => 'с', + 'Т' => 'т', + 'У' => 'у', + 'Ф' => 'ф', + 'Х' => 'х', + 'Ц' => 'ц', + 'Ч' => 'ч', + 'Ш' => 'ш', + 'Щ' => 'щ', + 'Ъ' => 'ъ', + 'Ы' => 'ы', + 'Ь' => 'ь', + 'Э' => 'э', + 'Ю' => 'ю', + 'Я' => 'я', + 'Ѡ' => 'ѡ', + 'Ѣ' => 'ѣ', + 'Ѥ' => 'ѥ', + 'Ѧ' => 'ѧ', + 'Ѩ' => 'ѩ', + 'Ѫ' => 'ѫ', + 'Ѭ' => 'ѭ', + 'Ѯ' => 'ѯ', + 'Ѱ' => 'ѱ', + 'Ѳ' => 'ѳ', + 'Ѵ' => 'ѵ', + 'Ѷ' => 'ѷ', + 'Ѹ' => 'ѹ', + 'Ѻ' => 'ѻ', + 'Ѽ' => 'ѽ', + 'Ѿ' => 'ѿ', + 'Ҁ' => 'ҁ', + 'Ҋ' => 'ҋ', + 'Ҍ' => 'ҍ', + 'Ҏ' => 'ҏ', + 'Ґ' => 'ґ', + 'Ғ' => 'ғ', + 'Ҕ' => 'ҕ', + 'Җ' => 'җ', + 'Ҙ' => 'ҙ', + 'Қ' => 'қ', + 'Ҝ' => 'ҝ', + 'Ҟ' => 'ҟ', + 'Ҡ' => 'ҡ', + 'Ң' => 'ң', + 'Ҥ' => 'ҥ', + 'Ҧ' => 'ҧ', + 'Ҩ' => 'ҩ', + 'Ҫ' => 'ҫ', + 'Ҭ' => 'ҭ', + 'Ү' => 'ү', + 'Ұ' => 'ұ', + 'Ҳ' => 'ҳ', + 'Ҵ' => 'ҵ', + 'Ҷ' => 'ҷ', + 'Ҹ' => 'ҹ', + 'Һ' => 'һ', + 'Ҽ' => 'ҽ', + 'Ҿ' => 'ҿ', + 'Ӏ' => 'ӏ', + 'Ӂ' => 'ӂ', + 'Ӄ' => 'ӄ', + 'Ӆ' => 'ӆ', + 'Ӈ' => 'ӈ', + 'Ӊ' => 'ӊ', + 'Ӌ' => 'ӌ', + 'Ӎ' => 'ӎ', + 'Ӑ' => 'ӑ', + 'Ӓ' => 'ӓ', + 'Ӕ' => 'ӕ', + 'Ӗ' => 'ӗ', + 'Ә' => 'ә', + 'Ӛ' => 'ӛ', + 'Ӝ' => 'ӝ', + 'Ӟ' => 'ӟ', + 'Ӡ' => 'ӡ', + 'Ӣ' => 'ӣ', + 'Ӥ' => 'ӥ', + 'Ӧ' => 'ӧ', + 'Ө' => 'ө', + 'Ӫ' => 'ӫ', + 'Ӭ' => 'ӭ', + 'Ӯ' => 'ӯ', + 'Ӱ' => 'ӱ', + 'Ӳ' => 'ӳ', + 'Ӵ' => 'ӵ', + 'Ӷ' => 'ӷ', + 'Ӹ' => 'ӹ', + 'Ӻ' => 'ӻ', + 'Ӽ' => 'ӽ', + 'Ӿ' => 'ӿ', + 'Ԁ' => 'ԁ', + 'Ԃ' => 'ԃ', + 'Ԅ' => 'ԅ', + 'Ԇ' => 'ԇ', + 'Ԉ' => 'ԉ', + 'Ԋ' => 'ԋ', + 'Ԍ' => 'ԍ', + 'Ԏ' => 'ԏ', + 'Ԑ' => 'ԑ', + 'Ԓ' => 'ԓ', + 'Ԕ' => 'ԕ', + 'Ԗ' => 'ԗ', + 'Ԙ' => 'ԙ', + 'Ԛ' => 'ԛ', + 'Ԝ' => 'ԝ', + 'Ԟ' => 'ԟ', + 'Ԡ' => 'ԡ', + 'Ԣ' => 'ԣ', + 'Ԥ' => 'ԥ', + 'Ԧ' => 'ԧ', + 'Ԩ' => 'ԩ', + 'Ԫ' => 'ԫ', + 'Ԭ' => 'ԭ', + 'Ԯ' => 'ԯ', + 'Ա' => 'ա', + 'Բ' => 'բ', + 'Գ' => 'գ', + 'Դ' => 'դ', + 'Ե' => 'ե', + 'Զ' => 'զ', + 'Է' => 'է', + 'Ը' => 'ը', + 'Թ' => 'թ', + 'Ժ' => 'ժ', + 'Ի' => 'ի', + 'Լ' => 'լ', + 'Խ' => 'խ', + 'Ծ' => 'ծ', + 'Կ' => 'կ', + 'Հ' => 'հ', + 'Ձ' => 'ձ', + 'Ղ' => 'ղ', + 'Ճ' => 'ճ', + 'Մ' => 'մ', + 'Յ' => 'յ', + 'Ն' => 'ն', + 'Շ' => 'շ', + 'Ո' => 'ո', + 'Չ' => 'չ', + 'Պ' => 'պ', + 'Ջ' => 'ջ', + 'Ռ' => 'ռ', + 'Ս' => 'ս', + 'Վ' => 'վ', + 'Տ' => 'տ', + 'Ր' => 'ր', + 'Ց' => 'ց', + 'Ւ' => 'ւ', + 'Փ' => 'փ', + 'Ք' => 'ք', + 'Օ' => 'օ', + 'Ֆ' => 'ֆ', + 'Ⴀ' => 'ⴀ', + 'Ⴁ' => 'ⴁ', + 'Ⴂ' => 'ⴂ', + 'Ⴃ' => 'ⴃ', + 'Ⴄ' => 'ⴄ', + 'Ⴅ' => 'ⴅ', + 'Ⴆ' => 'ⴆ', + 'Ⴇ' => 'ⴇ', + 'Ⴈ' => 'ⴈ', + 'Ⴉ' => 'ⴉ', + 'Ⴊ' => 'ⴊ', + 'Ⴋ' => 'ⴋ', + 'Ⴌ' => 'ⴌ', + 'Ⴍ' => 'ⴍ', + 'Ⴎ' => 'ⴎ', + 'Ⴏ' => 'ⴏ', + 'Ⴐ' => 'ⴐ', + 'Ⴑ' => 'ⴑ', + 'Ⴒ' => 'ⴒ', + 'Ⴓ' => 'ⴓ', + 'Ⴔ' => 'ⴔ', + 'Ⴕ' => 'ⴕ', + 'Ⴖ' => 'ⴖ', + 'Ⴗ' => 'ⴗ', + 'Ⴘ' => 'ⴘ', + 'Ⴙ' => 'ⴙ', + 'Ⴚ' => 'ⴚ', + 'Ⴛ' => 'ⴛ', + 'Ⴜ' => 'ⴜ', + 'Ⴝ' => 'ⴝ', + 'Ⴞ' => 'ⴞ', + 'Ⴟ' => 'ⴟ', + 'Ⴠ' => 'ⴠ', + 'Ⴡ' => 'ⴡ', + 'Ⴢ' => 'ⴢ', + 'Ⴣ' => 'ⴣ', + 'Ⴤ' => 'ⴤ', + 'Ⴥ' => 'ⴥ', + 'Ⴧ' => 'ⴧ', + 'Ⴭ' => 'ⴭ', + 'Ḁ' => 'ḁ', + 'Ḃ' => 'ḃ', + 'Ḅ' => 'ḅ', + 'Ḇ' => 'ḇ', + 'Ḉ' => 'ḉ', + 'Ḋ' => 'ḋ', + 'Ḍ' => 'ḍ', + 'Ḏ' => 'ḏ', + 'Ḑ' => 'ḑ', + 'Ḓ' => 'ḓ', + 'Ḕ' => 'ḕ', + 'Ḗ' => 'ḗ', + 'Ḙ' => 'ḙ', + 'Ḛ' => 'ḛ', + 'Ḝ' => 'ḝ', + 'Ḟ' => 'ḟ', + 'Ḡ' => 'ḡ', + 'Ḣ' => 'ḣ', + 'Ḥ' => 'ḥ', + 'Ḧ' => 'ḧ', + 'Ḩ' => 'ḩ', + 'Ḫ' => 'ḫ', + 'Ḭ' => 'ḭ', + 'Ḯ' => 'ḯ', + 'Ḱ' => 'ḱ', + 'Ḳ' => 'ḳ', + 'Ḵ' => 'ḵ', + 'Ḷ' => 'ḷ', + 'Ḹ' => 'ḹ', + 'Ḻ' => 'ḻ', + 'Ḽ' => 'ḽ', + 'Ḿ' => 'ḿ', + 'Ṁ' => 'ṁ', + 'Ṃ' => 'ṃ', + 'Ṅ' => 'ṅ', + 'Ṇ' => 'ṇ', + 'Ṉ' => 'ṉ', + 'Ṋ' => 'ṋ', + 'Ṍ' => 'ṍ', + 'Ṏ' => 'ṏ', + 'Ṑ' => 'ṑ', + 'Ṓ' => 'ṓ', + 'Ṕ' => 'ṕ', + 'Ṗ' => 'ṗ', + 'Ṙ' => 'ṙ', + 'Ṛ' => 'ṛ', + 'Ṝ' => 'ṝ', + 'Ṟ' => 'ṟ', + 'Ṡ' => 'ṡ', + 'Ṣ' => 'ṣ', + 'Ṥ' => 'ṥ', + 'Ṧ' => 'ṧ', + 'Ṩ' => 'ṩ', + 'Ṫ' => 'ṫ', + 'Ṭ' => 'ṭ', + 'Ṯ' => 'ṯ', + 'Ṱ' => 'ṱ', + 'Ṳ' => 'ṳ', + 'Ṵ' => 'ṵ', + 'Ṷ' => 'ṷ', + 'Ṹ' => 'ṹ', + 'Ṻ' => 'ṻ', + 'Ṽ' => 'ṽ', + 'Ṿ' => 'ṿ', + 'Ẁ' => 'ẁ', + 'Ẃ' => 'ẃ', + 'Ẅ' => 'ẅ', + 'Ẇ' => 'ẇ', + 'Ẉ' => 'ẉ', + 'Ẋ' => 'ẋ', + 'Ẍ' => 'ẍ', + 'Ẏ' => 'ẏ', + 'Ẑ' => 'ẑ', + 'Ẓ' => 'ẓ', + 'Ẕ' => 'ẕ', + 'ẞ' => 'ß', + 'Ạ' => 'ạ', + 'Ả' => 'ả', + 'Ấ' => 'ấ', + 'Ầ' => 'ầ', + 'Ẩ' => 'ẩ', + 'Ẫ' => 'ẫ', + 'Ậ' => 'ậ', + 'Ắ' => 'ắ', + 'Ằ' => 'ằ', + 'Ẳ' => 'ẳ', + 'Ẵ' => 'ẵ', + 'Ặ' => 'ặ', + 'Ẹ' => 'ẹ', + 'Ẻ' => 'ẻ', + 'Ẽ' => 'ẽ', + 'Ế' => 'ế', + 'Ề' => 'ề', + 'Ể' => 'ể', + 'Ễ' => 'ễ', + 'Ệ' => 'ệ', + 'Ỉ' => 'ỉ', + 'Ị' => 'ị', + 'Ọ' => 'ọ', + 'Ỏ' => 'ỏ', + 'Ố' => 'ố', + 'Ồ' => 'ồ', + 'Ổ' => 'ổ', + 'Ỗ' => 'ỗ', + 'Ộ' => 'ộ', + 'Ớ' => 'ớ', + 'Ờ' => 'ờ', + 'Ở' => 'ở', + 'Ỡ' => 'ỡ', + 'Ợ' => 'ợ', + 'Ụ' => 'ụ', + 'Ủ' => 'ủ', + 'Ứ' => 'ứ', + 'Ừ' => 'ừ', + 'Ử' => 'ử', + 'Ữ' => 'ữ', + 'Ự' => 'ự', + 'Ỳ' => 'ỳ', + 'Ỵ' => 'ỵ', + 'Ỷ' => 'ỷ', + 'Ỹ' => 'ỹ', + 'Ỻ' => 'ỻ', + 'Ỽ' => 'ỽ', + 'Ỿ' => 'ỿ', + 'Ἀ' => 'ἀ', + 'Ἁ' => 'ἁ', + 'Ἂ' => 'ἂ', + 'Ἃ' => 'ἃ', + 'Ἄ' => 'ἄ', + 'Ἅ' => 'ἅ', + 'Ἆ' => 'ἆ', + 'Ἇ' => 'ἇ', + 'Ἐ' => 'ἐ', + 'Ἑ' => 'ἑ', + 'Ἒ' => 'ἒ', + 'Ἓ' => 'ἓ', + 'Ἔ' => 'ἔ', + 'Ἕ' => 'ἕ', + 'Ἠ' => 'ἠ', + 'Ἡ' => 'ἡ', + 'Ἢ' => 'ἢ', + 'Ἣ' => 'ἣ', + 'Ἤ' => 'ἤ', + 'Ἥ' => 'ἥ', + 'Ἦ' => 'ἦ', + 'Ἧ' => 'ἧ', + 'Ἰ' => 'ἰ', + 'Ἱ' => 'ἱ', + 'Ἲ' => 'ἲ', + 'Ἳ' => 'ἳ', + 'Ἴ' => 'ἴ', + 'Ἵ' => 'ἵ', + 'Ἶ' => 'ἶ', + 'Ἷ' => 'ἷ', + 'Ὀ' => 'ὀ', + 'Ὁ' => 'ὁ', + 'Ὂ' => 'ὂ', + 'Ὃ' => 'ὃ', + 'Ὄ' => 'ὄ', + 'Ὅ' => 'ὅ', + 'Ὑ' => 'ὑ', + 'Ὓ' => 'ὓ', + 'Ὕ' => 'ὕ', + 'Ὗ' => 'ὗ', + 'Ὠ' => 'ὠ', + 'Ὡ' => 'ὡ', + 'Ὢ' => 'ὢ', + 'Ὣ' => 'ὣ', + 'Ὤ' => 'ὤ', + 'Ὥ' => 'ὥ', + 'Ὦ' => 'ὦ', + 'Ὧ' => 'ὧ', + 'ᾈ' => 'ᾀ', + 'ᾉ' => 'ᾁ', + 'ᾊ' => 'ᾂ', + 'ᾋ' => 'ᾃ', + 'ᾌ' => 'ᾄ', + 'ᾍ' => 'ᾅ', + 'ᾎ' => 'ᾆ', + 'ᾏ' => 'ᾇ', + 'ᾘ' => 'ᾐ', + 'ᾙ' => 'ᾑ', + 'ᾚ' => 'ᾒ', + 'ᾛ' => 'ᾓ', + 'ᾜ' => 'ᾔ', + 'ᾝ' => 'ᾕ', + 'ᾞ' => 'ᾖ', + 'ᾟ' => 'ᾗ', + 'ᾨ' => 'ᾠ', + 'ᾩ' => 'ᾡ', + 'ᾪ' => 'ᾢ', + 'ᾫ' => 'ᾣ', + 'ᾬ' => 'ᾤ', + 'ᾭ' => 'ᾥ', + 'ᾮ' => 'ᾦ', + 'ᾯ' => 'ᾧ', + 'Ᾰ' => 'ᾰ', + 'Ᾱ' => 'ᾱ', + 'Ὰ' => 'ὰ', + 'Ά' => 'ά', + 'ᾼ' => 'ᾳ', + 'Ὲ' => 'ὲ', + 'Έ' => 'έ', + 'Ὴ' => 'ὴ', + 'Ή' => 'ή', + 'ῌ' => 'ῃ', + 'Ῐ' => 'ῐ', + 'Ῑ' => 'ῑ', + 'Ὶ' => 'ὶ', + 'Ί' => 'ί', + 'Ῠ' => 'ῠ', + 'Ῡ' => 'ῡ', + 'Ὺ' => 'ὺ', + 'Ύ' => 'ύ', + 'Ῥ' => 'ῥ', + 'Ὸ' => 'ὸ', + 'Ό' => 'ό', + 'Ὼ' => 'ὼ', + 'Ώ' => 'ώ', + 'ῼ' => 'ῳ', + 'Ω' => 'ω', + 'K' => 'k', + 'Å' => 'å', + 'Ⅎ' => 'ⅎ', + 'Ⅰ' => 'ⅰ', + 'Ⅱ' => 'ⅱ', + 'Ⅲ' => 'ⅲ', + 'Ⅳ' => 'ⅳ', + 'Ⅴ' => 'ⅴ', + 'Ⅵ' => 'ⅵ', + 'Ⅶ' => 'ⅶ', + 'Ⅷ' => 'ⅷ', + 'Ⅸ' => 'ⅸ', + 'Ⅹ' => 'ⅹ', + 'Ⅺ' => 'ⅺ', + 'Ⅻ' => 'ⅻ', + 'Ⅼ' => 'ⅼ', + 'Ⅽ' => 'ⅽ', + 'Ⅾ' => 'ⅾ', + 'Ⅿ' => 'ⅿ', + 'Ↄ' => 'ↄ', + 'Ⓐ' => 'ⓐ', + 'Ⓑ' => 'ⓑ', + 'Ⓒ' => 'ⓒ', + 'Ⓓ' => 'ⓓ', + 'Ⓔ' => 'ⓔ', + 'Ⓕ' => 'ⓕ', + 'Ⓖ' => 'ⓖ', + 'Ⓗ' => 'ⓗ', + 'Ⓘ' => 'ⓘ', + 'Ⓙ' => 'ⓙ', + 'Ⓚ' => 'ⓚ', + 'Ⓛ' => 'ⓛ', + 'Ⓜ' => 'ⓜ', + 'Ⓝ' => 'ⓝ', + 'Ⓞ' => 'ⓞ', + 'Ⓟ' => 'ⓟ', + 'Ⓠ' => 'ⓠ', + 'Ⓡ' => 'ⓡ', + 'Ⓢ' => 'ⓢ', + 'Ⓣ' => 'ⓣ', + 'Ⓤ' => 'ⓤ', + 'Ⓥ' => 'ⓥ', + 'Ⓦ' => 'ⓦ', + 'Ⓧ' => 'ⓧ', + 'Ⓨ' => 'ⓨ', + 'Ⓩ' => 'ⓩ', + 'Ⰰ' => 'ⰰ', + 'Ⰱ' => 'ⰱ', + 'Ⰲ' => 'ⰲ', + 'Ⰳ' => 'ⰳ', + 'Ⰴ' => 'ⰴ', + 'Ⰵ' => 'ⰵ', + 'Ⰶ' => 'ⰶ', + 'Ⰷ' => 'ⰷ', + 'Ⰸ' => 'ⰸ', + 'Ⰹ' => 'ⰹ', + 'Ⰺ' => 'ⰺ', + 'Ⰻ' => 'ⰻ', + 'Ⰼ' => 'ⰼ', + 'Ⰽ' => 'ⰽ', + 'Ⰾ' => 'ⰾ', + 'Ⰿ' => 'ⰿ', + 'Ⱀ' => 'ⱀ', + 'Ⱁ' => 'ⱁ', + 'Ⱂ' => 'ⱂ', + 'Ⱃ' => 'ⱃ', + 'Ⱄ' => 'ⱄ', + 'Ⱅ' => 'ⱅ', + 'Ⱆ' => 'ⱆ', + 'Ⱇ' => 'ⱇ', + 'Ⱈ' => 'ⱈ', + 'Ⱉ' => 'ⱉ', + 'Ⱊ' => 'ⱊ', + 'Ⱋ' => 'ⱋ', + 'Ⱌ' => 'ⱌ', + 'Ⱍ' => 'ⱍ', + 'Ⱎ' => 'ⱎ', + 'Ⱏ' => 'ⱏ', + 'Ⱐ' => 'ⱐ', + 'Ⱑ' => 'ⱑ', + 'Ⱒ' => 'ⱒ', + 'Ⱓ' => 'ⱓ', + 'Ⱔ' => 'ⱔ', + 'Ⱕ' => 'ⱕ', + 'Ⱖ' => 'ⱖ', + 'Ⱗ' => 'ⱗ', + 'Ⱘ' => 'ⱘ', + 'Ⱙ' => 'ⱙ', + 'Ⱚ' => 'ⱚ', + 'Ⱛ' => 'ⱛ', + 'Ⱜ' => 'ⱜ', + 'Ⱝ' => 'ⱝ', + 'Ⱞ' => 'ⱞ', + 'Ⱡ' => 'ⱡ', + 'Ɫ' => 'ɫ', + 'Ᵽ' => 'ᵽ', + 'Ɽ' => 'ɽ', + 'Ⱨ' => 'ⱨ', + 'Ⱪ' => 'ⱪ', + 'Ⱬ' => 'ⱬ', + 'Ɑ' => 'ɑ', + 'Ɱ' => 'ɱ', + 'Ɐ' => 'ɐ', + 'Ɒ' => 'ɒ', + 'Ⱳ' => 'ⱳ', + 'Ⱶ' => 'ⱶ', + 'Ȿ' => 'ȿ', + 'Ɀ' => 'ɀ', + 'Ⲁ' => 'ⲁ', + 'Ⲃ' => 'ⲃ', + 'Ⲅ' => 'ⲅ', + 'Ⲇ' => 'ⲇ', + 'Ⲉ' => 'ⲉ', + 'Ⲋ' => 'ⲋ', + 'Ⲍ' => 'ⲍ', + 'Ⲏ' => 'ⲏ', + 'Ⲑ' => 'ⲑ', + 'Ⲓ' => 'ⲓ', + 'Ⲕ' => 'ⲕ', + 'Ⲗ' => 'ⲗ', + 'Ⲙ' => 'ⲙ', + 'Ⲛ' => 'ⲛ', + 'Ⲝ' => 'ⲝ', + 'Ⲟ' => 'ⲟ', + 'Ⲡ' => 'ⲡ', + 'Ⲣ' => 'ⲣ', + 'Ⲥ' => 'ⲥ', + 'Ⲧ' => 'ⲧ', + 'Ⲩ' => 'ⲩ', + 'Ⲫ' => 'ⲫ', + 'Ⲭ' => 'ⲭ', + 'Ⲯ' => 'ⲯ', + 'Ⲱ' => 'ⲱ', + 'Ⲳ' => 'ⲳ', + 'Ⲵ' => 'ⲵ', + 'Ⲷ' => 'ⲷ', + 'Ⲹ' => 'ⲹ', + 'Ⲻ' => 'ⲻ', + 'Ⲽ' => 'ⲽ', + 'Ⲿ' => 'ⲿ', + 'Ⳁ' => 'ⳁ', + 'Ⳃ' => 'ⳃ', + 'Ⳅ' => 'ⳅ', + 'Ⳇ' => 'ⳇ', + 'Ⳉ' => 'ⳉ', + 'Ⳋ' => 'ⳋ', + 'Ⳍ' => 'ⳍ', + 'Ⳏ' => 'ⳏ', + 'Ⳑ' => 'ⳑ', + 'Ⳓ' => 'ⳓ', + 'Ⳕ' => 'ⳕ', + 'Ⳗ' => 'ⳗ', + 'Ⳙ' => 'ⳙ', + 'Ⳛ' => 'ⳛ', + 'Ⳝ' => 'ⳝ', + 'Ⳟ' => 'ⳟ', + 'Ⳡ' => 'ⳡ', + 'Ⳣ' => 'ⳣ', + 'Ⳬ' => 'ⳬ', + 'Ⳮ' => 'ⳮ', + 'Ⳳ' => 'ⳳ', + 'Ꙁ' => 'ꙁ', + 'Ꙃ' => 'ꙃ', + 'Ꙅ' => 'ꙅ', + 'Ꙇ' => 'ꙇ', + 'Ꙉ' => 'ꙉ', + 'Ꙋ' => 'ꙋ', + 'Ꙍ' => 'ꙍ', + 'Ꙏ' => 'ꙏ', + 'Ꙑ' => 'ꙑ', + 'Ꙓ' => 'ꙓ', + 'Ꙕ' => 'ꙕ', + 'Ꙗ' => 'ꙗ', + 'Ꙙ' => 'ꙙ', + 'Ꙛ' => 'ꙛ', + 'Ꙝ' => 'ꙝ', + 'Ꙟ' => 'ꙟ', + 'Ꙡ' => 'ꙡ', + 'Ꙣ' => 'ꙣ', + 'Ꙥ' => 'ꙥ', + 'Ꙧ' => 'ꙧ', + 'Ꙩ' => 'ꙩ', + 'Ꙫ' => 'ꙫ', + 'Ꙭ' => 'ꙭ', + 'Ꚁ' => 'ꚁ', + 'Ꚃ' => 'ꚃ', + 'Ꚅ' => 'ꚅ', + 'Ꚇ' => 'ꚇ', + 'Ꚉ' => 'ꚉ', + 'Ꚋ' => 'ꚋ', + 'Ꚍ' => 'ꚍ', + 'Ꚏ' => 'ꚏ', + 'Ꚑ' => 'ꚑ', + 'Ꚓ' => 'ꚓ', + 'Ꚕ' => 'ꚕ', + 'Ꚗ' => 'ꚗ', + 'Ꚙ' => 'ꚙ', + 'Ꚛ' => 'ꚛ', + 'Ꜣ' => 'ꜣ', + 'Ꜥ' => 'ꜥ', + 'Ꜧ' => 'ꜧ', + 'Ꜩ' => 'ꜩ', + 'Ꜫ' => 'ꜫ', + 'Ꜭ' => 'ꜭ', + 'Ꜯ' => 'ꜯ', + 'Ꜳ' => 'ꜳ', + 'Ꜵ' => 'ꜵ', + 'Ꜷ' => 'ꜷ', + 'Ꜹ' => 'ꜹ', + 'Ꜻ' => 'ꜻ', + 'Ꜽ' => 'ꜽ', + 'Ꜿ' => 'ꜿ', + 'Ꝁ' => 'ꝁ', + 'Ꝃ' => 'ꝃ', + 'Ꝅ' => 'ꝅ', + 'Ꝇ' => 'ꝇ', + 'Ꝉ' => 'ꝉ', + 'Ꝋ' => 'ꝋ', + 'Ꝍ' => 'ꝍ', + 'Ꝏ' => 'ꝏ', + 'Ꝑ' => 'ꝑ', + 'Ꝓ' => 'ꝓ', + 'Ꝕ' => 'ꝕ', + 'Ꝗ' => 'ꝗ', + 'Ꝙ' => 'ꝙ', + 'Ꝛ' => 'ꝛ', + 'Ꝝ' => 'ꝝ', + 'Ꝟ' => 'ꝟ', + 'Ꝡ' => 'ꝡ', + 'Ꝣ' => 'ꝣ', + 'Ꝥ' => 'ꝥ', + 'Ꝧ' => 'ꝧ', + 'Ꝩ' => 'ꝩ', + 'Ꝫ' => 'ꝫ', + 'Ꝭ' => 'ꝭ', + 'Ꝯ' => 'ꝯ', + 'Ꝺ' => 'ꝺ', + 'Ꝼ' => 'ꝼ', + 'Ᵹ' => 'ᵹ', + 'Ꝿ' => 'ꝿ', + 'Ꞁ' => 'ꞁ', + 'Ꞃ' => 'ꞃ', + 'Ꞅ' => 'ꞅ', + 'Ꞇ' => 'ꞇ', + 'Ꞌ' => 'ꞌ', + 'Ɥ' => 'ɥ', + 'Ꞑ' => 'ꞑ', + 'Ꞓ' => 'ꞓ', + 'Ꞗ' => 'ꞗ', + 'Ꞙ' => 'ꞙ', + 'Ꞛ' => 'ꞛ', + 'Ꞝ' => 'ꞝ', + 'Ꞟ' => 'ꞟ', + 'Ꞡ' => 'ꞡ', + 'Ꞣ' => 'ꞣ', + 'Ꞥ' => 'ꞥ', + 'Ꞧ' => 'ꞧ', + 'Ꞩ' => 'ꞩ', + 'Ɦ' => 'ɦ', + 'Ɜ' => 'ɜ', + 'Ɡ' => 'ɡ', + 'Ɬ' => 'ɬ', + 'Ʞ' => 'ʞ', + 'Ʇ' => 'ʇ', + 'A' => 'a', + 'B' => 'b', + 'C' => 'c', + 'D' => 'd', + 'E' => 'e', + 'F' => 'f', + 'G' => 'g', + 'H' => 'h', + 'I' => 'i', + 'J' => 'j', + 'K' => 'k', + 'L' => 'l', + 'M' => 'm', + 'N' => 'n', + 'O' => 'o', + 'P' => 'p', + 'Q' => 'q', + 'R' => 'r', + 'S' => 's', + 'T' => 't', + 'U' => 'u', + 'V' => 'v', + 'W' => 'w', + 'X' => 'x', + 'Y' => 'y', + 'Z' => 'z', + '𐐀' => '𐐨', + '𐐁' => '𐐩', + '𐐂' => '𐐪', + '𐐃' => '𐐫', + '𐐄' => '𐐬', + '𐐅' => '𐐭', + '𐐆' => '𐐮', + '𐐇' => '𐐯', + '𐐈' => '𐐰', + '𐐉' => '𐐱', + '𐐊' => '𐐲', + '𐐋' => '𐐳', + '𐐌' => '𐐴', + '𐐍' => '𐐵', + '𐐎' => '𐐶', + '𐐏' => '𐐷', + '𐐐' => '𐐸', + '𐐑' => '𐐹', + '𐐒' => '𐐺', + '𐐓' => '𐐻', + '𐐔' => '𐐼', + '𐐕' => '𐐽', + '𐐖' => '𐐾', + '𐐗' => '𐐿', + '𐐘' => '𐑀', + '𐐙' => '𐑁', + '𐐚' => '𐑂', + '𐐛' => '𐑃', + '𐐜' => '𐑄', + '𐐝' => '𐑅', + '𐐞' => '𐑆', + '𐐟' => '𐑇', + '𐐠' => '𐑈', + '𐐡' => '𐑉', + '𐐢' => '𐑊', + '𐐣' => '𐑋', + '𐐤' => '𐑌', + '𐐥' => '𐑍', + '𐐦' => '𐑎', + '𐐧' => '𐑏', + '𑢠' => '𑣀', + '𑢡' => '𑣁', + '𑢢' => '𑣂', + '𑢣' => '𑣃', + '𑢤' => '𑣄', + '𑢥' => '𑣅', + '𑢦' => '𑣆', + '𑢧' => '𑣇', + '𑢨' => '𑣈', + '𑢩' => '𑣉', + '𑢪' => '𑣊', + '𑢫' => '𑣋', + '𑢬' => '𑣌', + '𑢭' => '𑣍', + '𑢮' => '𑣎', + '𑢯' => '𑣏', + '𑢰' => '𑣐', + '𑢱' => '𑣑', + '𑢲' => '𑣒', + '𑢳' => '𑣓', + '𑢴' => '𑣔', + '𑢵' => '𑣕', + '𑢶' => '𑣖', + '𑢷' => '𑣗', + '𑢸' => '𑣘', + '𑢹' => '𑣙', + '𑢺' => '𑣚', + '𑢻' => '𑣛', + '𑢼' => '𑣜', + '𑢽' => '𑣝', + '𑢾' => '𑣞', + '𑢿' => '𑣟', +); diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php new file mode 100644 index 0000000..2a8f6e7 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php @@ -0,0 +1,5 @@ + 'A', + 'b' => 'B', + 'c' => 'C', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + 'k' => 'K', + 'l' => 'L', + 'm' => 'M', + 'n' => 'N', + 'o' => 'O', + 'p' => 'P', + 'q' => 'Q', + 'r' => 'R', + 's' => 'S', + 't' => 'T', + 'u' => 'U', + 'v' => 'V', + 'w' => 'W', + 'x' => 'X', + 'y' => 'Y', + 'z' => 'Z', + 'µ' => 'Μ', + 'à' => 'À', + 'á' => 'Á', + 'â' => 'Â', + 'ã' => 'Ã', + 'ä' => 'Ä', + 'å' => 'Å', + 'æ' => 'Æ', + 'ç' => 'Ç', + 'è' => 'È', + 'é' => 'É', + 'ê' => 'Ê', + 'ë' => 'Ë', + 'ì' => 'Ì', + 'í' => 'Í', + 'î' => 'Î', + 'ï' => 'Ï', + 'ð' => 'Ð', + 'ñ' => 'Ñ', + 'ò' => 'Ò', + 'ó' => 'Ó', + 'ô' => 'Ô', + 'õ' => 'Õ', + 'ö' => 'Ö', + 'ø' => 'Ø', + 'ù' => 'Ù', + 'ú' => 'Ú', + 'û' => 'Û', + 'ü' => 'Ü', + 'ý' => 'Ý', + 'þ' => 'Þ', + 'ÿ' => 'Ÿ', + 'ā' => 'Ā', + 'ă' => 'Ă', + 'ą' => 'Ą', + 'ć' => 'Ć', + 'ĉ' => 'Ĉ', + 'ċ' => 'Ċ', + 'č' => 'Č', + 'ď' => 'Ď', + 'đ' => 'Đ', + 'ē' => 'Ē', + 'ĕ' => 'Ĕ', + 'ė' => 'Ė', + 'ę' => 'Ę', + 'ě' => 'Ě', + 'ĝ' => 'Ĝ', + 'ğ' => 'Ğ', + 'ġ' => 'Ġ', + 'ģ' => 'Ģ', + 'ĥ' => 'Ĥ', + 'ħ' => 'Ħ', + 'ĩ' => 'Ĩ', + 'ī' => 'Ī', + 'ĭ' => 'Ĭ', + 'į' => 'Į', + 'ı' => 'I', + 'ij' => 'IJ', + 'ĵ' => 'Ĵ', + 'ķ' => 'Ķ', + 'ĺ' => 'Ĺ', + 'ļ' => 'Ļ', + 'ľ' => 'Ľ', + 'ŀ' => 'Ŀ', + 'ł' => 'Ł', + 'ń' => 'Ń', + 'ņ' => 'Ņ', + 'ň' => 'Ň', + 'ŋ' => 'Ŋ', + 'ō' => 'Ō', + 'ŏ' => 'Ŏ', + 'ő' => 'Ő', + 'œ' => 'Œ', + 'ŕ' => 'Ŕ', + 'ŗ' => 'Ŗ', + 'ř' => 'Ř', + 'ś' => 'Ś', + 'ŝ' => 'Ŝ', + 'ş' => 'Ş', + 'š' => 'Š', + 'ţ' => 'Ţ', + 'ť' => 'Ť', + 'ŧ' => 'Ŧ', + 'ũ' => 'Ũ', + 'ū' => 'Ū', + 'ŭ' => 'Ŭ', + 'ů' => 'Ů', + 'ű' => 'Ű', + 'ų' => 'Ų', + 'ŵ' => 'Ŵ', + 'ŷ' => 'Ŷ', + 'ź' => 'Ź', + 'ż' => 'Ż', + 'ž' => 'Ž', + 'ſ' => 'S', + 'ƀ' => 'Ƀ', + 'ƃ' => 'Ƃ', + 'ƅ' => 'Ƅ', + 'ƈ' => 'Ƈ', + 'ƌ' => 'Ƌ', + 'ƒ' => 'Ƒ', + 'ƕ' => 'Ƕ', + 'ƙ' => 'Ƙ', + 'ƚ' => 'Ƚ', + 'ƞ' => 'Ƞ', + 'ơ' => 'Ơ', + 'ƣ' => 'Ƣ', + 'ƥ' => 'Ƥ', + 'ƨ' => 'Ƨ', + 'ƭ' => 'Ƭ', + 'ư' => 'Ư', + 'ƴ' => 'Ƴ', + 'ƶ' => 'Ƶ', + 'ƹ' => 'Ƹ', + 'ƽ' => 'Ƽ', + 'ƿ' => 'Ƿ', + 'Dž' => 'DŽ', + 'dž' => 'DŽ', + 'Lj' => 'LJ', + 'lj' => 'LJ', + 'Nj' => 'NJ', + 'nj' => 'NJ', + 'ǎ' => 'Ǎ', + 'ǐ' => 'Ǐ', + 'ǒ' => 'Ǒ', + 'ǔ' => 'Ǔ', + 'ǖ' => 'Ǖ', + 'ǘ' => 'Ǘ', + 'ǚ' => 'Ǚ', + 'ǜ' => 'Ǜ', + 'ǝ' => 'Ǝ', + 'ǟ' => 'Ǟ', + 'ǡ' => 'Ǡ', + 'ǣ' => 'Ǣ', + 'ǥ' => 'Ǥ', + 'ǧ' => 'Ǧ', + 'ǩ' => 'Ǩ', + 'ǫ' => 'Ǫ', + 'ǭ' => 'Ǭ', + 'ǯ' => 'Ǯ', + 'Dz' => 'DZ', + 'dz' => 'DZ', + 'ǵ' => 'Ǵ', + 'ǹ' => 'Ǹ', + 'ǻ' => 'Ǻ', + 'ǽ' => 'Ǽ', + 'ǿ' => 'Ǿ', + 'ȁ' => 'Ȁ', + 'ȃ' => 'Ȃ', + 'ȅ' => 'Ȅ', + 'ȇ' => 'Ȇ', + 'ȉ' => 'Ȉ', + 'ȋ' => 'Ȋ', + 'ȍ' => 'Ȍ', + 'ȏ' => 'Ȏ', + 'ȑ' => 'Ȑ', + 'ȓ' => 'Ȓ', + 'ȕ' => 'Ȕ', + 'ȗ' => 'Ȗ', + 'ș' => 'Ș', + 'ț' => 'Ț', + 'ȝ' => 'Ȝ', + 'ȟ' => 'Ȟ', + 'ȣ' => 'Ȣ', + 'ȥ' => 'Ȥ', + 'ȧ' => 'Ȧ', + 'ȩ' => 'Ȩ', + 'ȫ' => 'Ȫ', + 'ȭ' => 'Ȭ', + 'ȯ' => 'Ȯ', + 'ȱ' => 'Ȱ', + 'ȳ' => 'Ȳ', + 'ȼ' => 'Ȼ', + 'ȿ' => 'Ȿ', + 'ɀ' => 'Ɀ', + 'ɂ' => 'Ɂ', + 'ɇ' => 'Ɇ', + 'ɉ' => 'Ɉ', + 'ɋ' => 'Ɋ', + 'ɍ' => 'Ɍ', + 'ɏ' => 'Ɏ', + 'ɐ' => 'Ɐ', + 'ɑ' => 'Ɑ', + 'ɒ' => 'Ɒ', + 'ɓ' => 'Ɓ', + 'ɔ' => 'Ɔ', + 'ɖ' => 'Ɖ', + 'ɗ' => 'Ɗ', + 'ə' => 'Ə', + 'ɛ' => 'Ɛ', + 'ɜ' => 'Ɜ', + 'ɠ' => 'Ɠ', + 'ɡ' => 'Ɡ', + 'ɣ' => 'Ɣ', + 'ɥ' => 'Ɥ', + 'ɦ' => 'Ɦ', + 'ɨ' => 'Ɨ', + 'ɩ' => 'Ɩ', + 'ɫ' => 'Ɫ', + 'ɬ' => 'Ɬ', + 'ɯ' => 'Ɯ', + 'ɱ' => 'Ɱ', + 'ɲ' => 'Ɲ', + 'ɵ' => 'Ɵ', + 'ɽ' => 'Ɽ', + 'ʀ' => 'Ʀ', + 'ʃ' => 'Ʃ', + 'ʇ' => 'Ʇ', + 'ʈ' => 'Ʈ', + 'ʉ' => 'Ʉ', + 'ʊ' => 'Ʊ', + 'ʋ' => 'Ʋ', + 'ʌ' => 'Ʌ', + 'ʒ' => 'Ʒ', + 'ʞ' => 'Ʞ', + 'ͅ' => 'Ι', + 'ͱ' => 'Ͱ', + 'ͳ' => 'Ͳ', + 'ͷ' => 'Ͷ', + 'ͻ' => 'Ͻ', + 'ͼ' => 'Ͼ', + 'ͽ' => 'Ͽ', + 'ά' => 'Ά', + 'έ' => 'Έ', + 'ή' => 'Ή', + 'ί' => 'Ί', + 'α' => 'Α', + 'β' => 'Β', + 'γ' => 'Γ', + 'δ' => 'Δ', + 'ε' => 'Ε', + 'ζ' => 'Ζ', + 'η' => 'Η', + 'θ' => 'Θ', + 'ι' => 'Ι', + 'κ' => 'Κ', + 'λ' => 'Λ', + 'μ' => 'Μ', + 'ν' => 'Ν', + 'ξ' => 'Ξ', + 'ο' => 'Ο', + 'π' => 'Π', + 'ρ' => 'Ρ', + 'ς' => 'Σ', + 'σ' => 'Σ', + 'τ' => 'Τ', + 'υ' => 'Υ', + 'φ' => 'Φ', + 'χ' => 'Χ', + 'ψ' => 'Ψ', + 'ω' => 'Ω', + 'ϊ' => 'Ϊ', + 'ϋ' => 'Ϋ', + 'ό' => 'Ό', + 'ύ' => 'Ύ', + 'ώ' => 'Ώ', + 'ϐ' => 'Β', + 'ϑ' => 'Θ', + 'ϕ' => 'Φ', + 'ϖ' => 'Π', + 'ϗ' => 'Ϗ', + 'ϙ' => 'Ϙ', + 'ϛ' => 'Ϛ', + 'ϝ' => 'Ϝ', + 'ϟ' => 'Ϟ', + 'ϡ' => 'Ϡ', + 'ϣ' => 'Ϣ', + 'ϥ' => 'Ϥ', + 'ϧ' => 'Ϧ', + 'ϩ' => 'Ϩ', + 'ϫ' => 'Ϫ', + 'ϭ' => 'Ϭ', + 'ϯ' => 'Ϯ', + 'ϰ' => 'Κ', + 'ϱ' => 'Ρ', + 'ϲ' => 'Ϲ', + 'ϳ' => 'Ϳ', + 'ϵ' => 'Ε', + 'ϸ' => 'Ϸ', + 'ϻ' => 'Ϻ', + 'а' => 'А', + 'б' => 'Б', + 'в' => 'В', + 'г' => 'Г', + 'д' => 'Д', + 'е' => 'Е', + 'ж' => 'Ж', + 'з' => 'З', + 'и' => 'И', + 'й' => 'Й', + 'к' => 'К', + 'л' => 'Л', + 'м' => 'М', + 'н' => 'Н', + 'о' => 'О', + 'п' => 'П', + 'р' => 'Р', + 'с' => 'С', + 'т' => 'Т', + 'у' => 'У', + 'ф' => 'Ф', + 'х' => 'Х', + 'ц' => 'Ц', + 'ч' => 'Ч', + 'ш' => 'Ш', + 'щ' => 'Щ', + 'ъ' => 'Ъ', + 'ы' => 'Ы', + 'ь' => 'Ь', + 'э' => 'Э', + 'ю' => 'Ю', + 'я' => 'Я', + 'ѐ' => 'Ѐ', + 'ё' => 'Ё', + 'ђ' => 'Ђ', + 'ѓ' => 'Ѓ', + 'є' => 'Є', + 'ѕ' => 'Ѕ', + 'і' => 'І', + 'ї' => 'Ї', + 'ј' => 'Ј', + 'љ' => 'Љ', + 'њ' => 'Њ', + 'ћ' => 'Ћ', + 'ќ' => 'Ќ', + 'ѝ' => 'Ѝ', + 'ў' => 'Ў', + 'џ' => 'Џ', + 'ѡ' => 'Ѡ', + 'ѣ' => 'Ѣ', + 'ѥ' => 'Ѥ', + 'ѧ' => 'Ѧ', + 'ѩ' => 'Ѩ', + 'ѫ' => 'Ѫ', + 'ѭ' => 'Ѭ', + 'ѯ' => 'Ѯ', + 'ѱ' => 'Ѱ', + 'ѳ' => 'Ѳ', + 'ѵ' => 'Ѵ', + 'ѷ' => 'Ѷ', + 'ѹ' => 'Ѹ', + 'ѻ' => 'Ѻ', + 'ѽ' => 'Ѽ', + 'ѿ' => 'Ѿ', + 'ҁ' => 'Ҁ', + 'ҋ' => 'Ҋ', + 'ҍ' => 'Ҍ', + 'ҏ' => 'Ҏ', + 'ґ' => 'Ґ', + 'ғ' => 'Ғ', + 'ҕ' => 'Ҕ', + 'җ' => 'Җ', + 'ҙ' => 'Ҙ', + 'қ' => 'Қ', + 'ҝ' => 'Ҝ', + 'ҟ' => 'Ҟ', + 'ҡ' => 'Ҡ', + 'ң' => 'Ң', + 'ҥ' => 'Ҥ', + 'ҧ' => 'Ҧ', + 'ҩ' => 'Ҩ', + 'ҫ' => 'Ҫ', + 'ҭ' => 'Ҭ', + 'ү' => 'Ү', + 'ұ' => 'Ұ', + 'ҳ' => 'Ҳ', + 'ҵ' => 'Ҵ', + 'ҷ' => 'Ҷ', + 'ҹ' => 'Ҹ', + 'һ' => 'Һ', + 'ҽ' => 'Ҽ', + 'ҿ' => 'Ҿ', + 'ӂ' => 'Ӂ', + 'ӄ' => 'Ӄ', + 'ӆ' => 'Ӆ', + 'ӈ' => 'Ӈ', + 'ӊ' => 'Ӊ', + 'ӌ' => 'Ӌ', + 'ӎ' => 'Ӎ', + 'ӏ' => 'Ӏ', + 'ӑ' => 'Ӑ', + 'ӓ' => 'Ӓ', + 'ӕ' => 'Ӕ', + 'ӗ' => 'Ӗ', + 'ә' => 'Ә', + 'ӛ' => 'Ӛ', + 'ӝ' => 'Ӝ', + 'ӟ' => 'Ӟ', + 'ӡ' => 'Ӡ', + 'ӣ' => 'Ӣ', + 'ӥ' => 'Ӥ', + 'ӧ' => 'Ӧ', + 'ө' => 'Ө', + 'ӫ' => 'Ӫ', + 'ӭ' => 'Ӭ', + 'ӯ' => 'Ӯ', + 'ӱ' => 'Ӱ', + 'ӳ' => 'Ӳ', + 'ӵ' => 'Ӵ', + 'ӷ' => 'Ӷ', + 'ӹ' => 'Ӹ', + 'ӻ' => 'Ӻ', + 'ӽ' => 'Ӽ', + 'ӿ' => 'Ӿ', + 'ԁ' => 'Ԁ', + 'ԃ' => 'Ԃ', + 'ԅ' => 'Ԅ', + 'ԇ' => 'Ԇ', + 'ԉ' => 'Ԉ', + 'ԋ' => 'Ԋ', + 'ԍ' => 'Ԍ', + 'ԏ' => 'Ԏ', + 'ԑ' => 'Ԑ', + 'ԓ' => 'Ԓ', + 'ԕ' => 'Ԕ', + 'ԗ' => 'Ԗ', + 'ԙ' => 'Ԙ', + 'ԛ' => 'Ԛ', + 'ԝ' => 'Ԝ', + 'ԟ' => 'Ԟ', + 'ԡ' => 'Ԡ', + 'ԣ' => 'Ԣ', + 'ԥ' => 'Ԥ', + 'ԧ' => 'Ԧ', + 'ԩ' => 'Ԩ', + 'ԫ' => 'Ԫ', + 'ԭ' => 'Ԭ', + 'ԯ' => 'Ԯ', + 'ա' => 'Ա', + 'բ' => 'Բ', + 'գ' => 'Գ', + 'դ' => 'Դ', + 'ե' => 'Ե', + 'զ' => 'Զ', + 'է' => 'Է', + 'ը' => 'Ը', + 'թ' => 'Թ', + 'ժ' => 'Ժ', + 'ի' => 'Ի', + 'լ' => 'Լ', + 'խ' => 'Խ', + 'ծ' => 'Ծ', + 'կ' => 'Կ', + 'հ' => 'Հ', + 'ձ' => 'Ձ', + 'ղ' => 'Ղ', + 'ճ' => 'Ճ', + 'մ' => 'Մ', + 'յ' => 'Յ', + 'ն' => 'Ն', + 'շ' => 'Շ', + 'ո' => 'Ո', + 'չ' => 'Չ', + 'պ' => 'Պ', + 'ջ' => 'Ջ', + 'ռ' => 'Ռ', + 'ս' => 'Ս', + 'վ' => 'Վ', + 'տ' => 'Տ', + 'ր' => 'Ր', + 'ց' => 'Ց', + 'ւ' => 'Ւ', + 'փ' => 'Փ', + 'ք' => 'Ք', + 'օ' => 'Օ', + 'ֆ' => 'Ֆ', + 'ᵹ' => 'Ᵹ', + 'ᵽ' => 'Ᵽ', + 'ḁ' => 'Ḁ', + 'ḃ' => 'Ḃ', + 'ḅ' => 'Ḅ', + 'ḇ' => 'Ḇ', + 'ḉ' => 'Ḉ', + 'ḋ' => 'Ḋ', + 'ḍ' => 'Ḍ', + 'ḏ' => 'Ḏ', + 'ḑ' => 'Ḑ', + 'ḓ' => 'Ḓ', + 'ḕ' => 'Ḕ', + 'ḗ' => 'Ḗ', + 'ḙ' => 'Ḙ', + 'ḛ' => 'Ḛ', + 'ḝ' => 'Ḝ', + 'ḟ' => 'Ḟ', + 'ḡ' => 'Ḡ', + 'ḣ' => 'Ḣ', + 'ḥ' => 'Ḥ', + 'ḧ' => 'Ḧ', + 'ḩ' => 'Ḩ', + 'ḫ' => 'Ḫ', + 'ḭ' => 'Ḭ', + 'ḯ' => 'Ḯ', + 'ḱ' => 'Ḱ', + 'ḳ' => 'Ḳ', + 'ḵ' => 'Ḵ', + 'ḷ' => 'Ḷ', + 'ḹ' => 'Ḹ', + 'ḻ' => 'Ḻ', + 'ḽ' => 'Ḽ', + 'ḿ' => 'Ḿ', + 'ṁ' => 'Ṁ', + 'ṃ' => 'Ṃ', + 'ṅ' => 'Ṅ', + 'ṇ' => 'Ṇ', + 'ṉ' => 'Ṉ', + 'ṋ' => 'Ṋ', + 'ṍ' => 'Ṍ', + 'ṏ' => 'Ṏ', + 'ṑ' => 'Ṑ', + 'ṓ' => 'Ṓ', + 'ṕ' => 'Ṕ', + 'ṗ' => 'Ṗ', + 'ṙ' => 'Ṙ', + 'ṛ' => 'Ṛ', + 'ṝ' => 'Ṝ', + 'ṟ' => 'Ṟ', + 'ṡ' => 'Ṡ', + 'ṣ' => 'Ṣ', + 'ṥ' => 'Ṥ', + 'ṧ' => 'Ṧ', + 'ṩ' => 'Ṩ', + 'ṫ' => 'Ṫ', + 'ṭ' => 'Ṭ', + 'ṯ' => 'Ṯ', + 'ṱ' => 'Ṱ', + 'ṳ' => 'Ṳ', + 'ṵ' => 'Ṵ', + 'ṷ' => 'Ṷ', + 'ṹ' => 'Ṹ', + 'ṻ' => 'Ṻ', + 'ṽ' => 'Ṽ', + 'ṿ' => 'Ṿ', + 'ẁ' => 'Ẁ', + 'ẃ' => 'Ẃ', + 'ẅ' => 'Ẅ', + 'ẇ' => 'Ẇ', + 'ẉ' => 'Ẉ', + 'ẋ' => 'Ẋ', + 'ẍ' => 'Ẍ', + 'ẏ' => 'Ẏ', + 'ẑ' => 'Ẑ', + 'ẓ' => 'Ẓ', + 'ẕ' => 'Ẕ', + 'ẛ' => 'Ṡ', + 'ạ' => 'Ạ', + 'ả' => 'Ả', + 'ấ' => 'Ấ', + 'ầ' => 'Ầ', + 'ẩ' => 'Ẩ', + 'ẫ' => 'Ẫ', + 'ậ' => 'Ậ', + 'ắ' => 'Ắ', + 'ằ' => 'Ằ', + 'ẳ' => 'Ẳ', + 'ẵ' => 'Ẵ', + 'ặ' => 'Ặ', + 'ẹ' => 'Ẹ', + 'ẻ' => 'Ẻ', + 'ẽ' => 'Ẽ', + 'ế' => 'Ế', + 'ề' => 'Ề', + 'ể' => 'Ể', + 'ễ' => 'Ễ', + 'ệ' => 'Ệ', + 'ỉ' => 'Ỉ', + 'ị' => 'Ị', + 'ọ' => 'Ọ', + 'ỏ' => 'Ỏ', + 'ố' => 'Ố', + 'ồ' => 'Ồ', + 'ổ' => 'Ổ', + 'ỗ' => 'Ỗ', + 'ộ' => 'Ộ', + 'ớ' => 'Ớ', + 'ờ' => 'Ờ', + 'ở' => 'Ở', + 'ỡ' => 'Ỡ', + 'ợ' => 'Ợ', + 'ụ' => 'Ụ', + 'ủ' => 'Ủ', + 'ứ' => 'Ứ', + 'ừ' => 'Ừ', + 'ử' => 'Ử', + 'ữ' => 'Ữ', + 'ự' => 'Ự', + 'ỳ' => 'Ỳ', + 'ỵ' => 'Ỵ', + 'ỷ' => 'Ỷ', + 'ỹ' => 'Ỹ', + 'ỻ' => 'Ỻ', + 'ỽ' => 'Ỽ', + 'ỿ' => 'Ỿ', + 'ἀ' => 'Ἀ', + 'ἁ' => 'Ἁ', + 'ἂ' => 'Ἂ', + 'ἃ' => 'Ἃ', + 'ἄ' => 'Ἄ', + 'ἅ' => 'Ἅ', + 'ἆ' => 'Ἆ', + 'ἇ' => 'Ἇ', + 'ἐ' => 'Ἐ', + 'ἑ' => 'Ἑ', + 'ἒ' => 'Ἒ', + 'ἓ' => 'Ἓ', + 'ἔ' => 'Ἔ', + 'ἕ' => 'Ἕ', + 'ἠ' => 'Ἠ', + 'ἡ' => 'Ἡ', + 'ἢ' => 'Ἢ', + 'ἣ' => 'Ἣ', + 'ἤ' => 'Ἤ', + 'ἥ' => 'Ἥ', + 'ἦ' => 'Ἦ', + 'ἧ' => 'Ἧ', + 'ἰ' => 'Ἰ', + 'ἱ' => 'Ἱ', + 'ἲ' => 'Ἲ', + 'ἳ' => 'Ἳ', + 'ἴ' => 'Ἴ', + 'ἵ' => 'Ἵ', + 'ἶ' => 'Ἶ', + 'ἷ' => 'Ἷ', + 'ὀ' => 'Ὀ', + 'ὁ' => 'Ὁ', + 'ὂ' => 'Ὂ', + 'ὃ' => 'Ὃ', + 'ὄ' => 'Ὄ', + 'ὅ' => 'Ὅ', + 'ὑ' => 'Ὑ', + 'ὓ' => 'Ὓ', + 'ὕ' => 'Ὕ', + 'ὗ' => 'Ὗ', + 'ὠ' => 'Ὠ', + 'ὡ' => 'Ὡ', + 'ὢ' => 'Ὢ', + 'ὣ' => 'Ὣ', + 'ὤ' => 'Ὤ', + 'ὥ' => 'Ὥ', + 'ὦ' => 'Ὦ', + 'ὧ' => 'Ὧ', + 'ὰ' => 'Ὰ', + 'ά' => 'Ά', + 'ὲ' => 'Ὲ', + 'έ' => 'Έ', + 'ὴ' => 'Ὴ', + 'ή' => 'Ή', + 'ὶ' => 'Ὶ', + 'ί' => 'Ί', + 'ὸ' => 'Ὸ', + 'ό' => 'Ό', + 'ὺ' => 'Ὺ', + 'ύ' => 'Ύ', + 'ὼ' => 'Ὼ', + 'ώ' => 'Ώ', + 'ᾀ' => 'ᾈ', + 'ᾁ' => 'ᾉ', + 'ᾂ' => 'ᾊ', + 'ᾃ' => 'ᾋ', + 'ᾄ' => 'ᾌ', + 'ᾅ' => 'ᾍ', + 'ᾆ' => 'ᾎ', + 'ᾇ' => 'ᾏ', + 'ᾐ' => 'ᾘ', + 'ᾑ' => 'ᾙ', + 'ᾒ' => 'ᾚ', + 'ᾓ' => 'ᾛ', + 'ᾔ' => 'ᾜ', + 'ᾕ' => 'ᾝ', + 'ᾖ' => 'ᾞ', + 'ᾗ' => 'ᾟ', + 'ᾠ' => 'ᾨ', + 'ᾡ' => 'ᾩ', + 'ᾢ' => 'ᾪ', + 'ᾣ' => 'ᾫ', + 'ᾤ' => 'ᾬ', + 'ᾥ' => 'ᾭ', + 'ᾦ' => 'ᾮ', + 'ᾧ' => 'ᾯ', + 'ᾰ' => 'Ᾰ', + 'ᾱ' => 'Ᾱ', + 'ᾳ' => 'ᾼ', + 'ι' => 'Ι', + 'ῃ' => 'ῌ', + 'ῐ' => 'Ῐ', + 'ῑ' => 'Ῑ', + 'ῠ' => 'Ῠ', + 'ῡ' => 'Ῡ', + 'ῥ' => 'Ῥ', + 'ῳ' => 'ῼ', + 'ⅎ' => 'Ⅎ', + 'ⅰ' => 'Ⅰ', + 'ⅱ' => 'Ⅱ', + 'ⅲ' => 'Ⅲ', + 'ⅳ' => 'Ⅳ', + 'ⅴ' => 'Ⅴ', + 'ⅵ' => 'Ⅵ', + 'ⅶ' => 'Ⅶ', + 'ⅷ' => 'Ⅷ', + 'ⅸ' => 'Ⅸ', + 'ⅹ' => 'Ⅹ', + 'ⅺ' => 'Ⅺ', + 'ⅻ' => 'Ⅻ', + 'ⅼ' => 'Ⅼ', + 'ⅽ' => 'Ⅽ', + 'ⅾ' => 'Ⅾ', + 'ⅿ' => 'Ⅿ', + 'ↄ' => 'Ↄ', + 'ⓐ' => 'Ⓐ', + 'ⓑ' => 'Ⓑ', + 'ⓒ' => 'Ⓒ', + 'ⓓ' => 'Ⓓ', + 'ⓔ' => 'Ⓔ', + 'ⓕ' => 'Ⓕ', + 'ⓖ' => 'Ⓖ', + 'ⓗ' => 'Ⓗ', + 'ⓘ' => 'Ⓘ', + 'ⓙ' => 'Ⓙ', + 'ⓚ' => 'Ⓚ', + 'ⓛ' => 'Ⓛ', + 'ⓜ' => 'Ⓜ', + 'ⓝ' => 'Ⓝ', + 'ⓞ' => 'Ⓞ', + 'ⓟ' => 'Ⓟ', + 'ⓠ' => 'Ⓠ', + 'ⓡ' => 'Ⓡ', + 'ⓢ' => 'Ⓢ', + 'ⓣ' => 'Ⓣ', + 'ⓤ' => 'Ⓤ', + 'ⓥ' => 'Ⓥ', + 'ⓦ' => 'Ⓦ', + 'ⓧ' => 'Ⓧ', + 'ⓨ' => 'Ⓨ', + 'ⓩ' => 'Ⓩ', + 'ⰰ' => 'Ⰰ', + 'ⰱ' => 'Ⰱ', + 'ⰲ' => 'Ⰲ', + 'ⰳ' => 'Ⰳ', + 'ⰴ' => 'Ⰴ', + 'ⰵ' => 'Ⰵ', + 'ⰶ' => 'Ⰶ', + 'ⰷ' => 'Ⰷ', + 'ⰸ' => 'Ⰸ', + 'ⰹ' => 'Ⰹ', + 'ⰺ' => 'Ⰺ', + 'ⰻ' => 'Ⰻ', + 'ⰼ' => 'Ⰼ', + 'ⰽ' => 'Ⰽ', + 'ⰾ' => 'Ⰾ', + 'ⰿ' => 'Ⰿ', + 'ⱀ' => 'Ⱀ', + 'ⱁ' => 'Ⱁ', + 'ⱂ' => 'Ⱂ', + 'ⱃ' => 'Ⱃ', + 'ⱄ' => 'Ⱄ', + 'ⱅ' => 'Ⱅ', + 'ⱆ' => 'Ⱆ', + 'ⱇ' => 'Ⱇ', + 'ⱈ' => 'Ⱈ', + 'ⱉ' => 'Ⱉ', + 'ⱊ' => 'Ⱊ', + 'ⱋ' => 'Ⱋ', + 'ⱌ' => 'Ⱌ', + 'ⱍ' => 'Ⱍ', + 'ⱎ' => 'Ⱎ', + 'ⱏ' => 'Ⱏ', + 'ⱐ' => 'Ⱐ', + 'ⱑ' => 'Ⱑ', + 'ⱒ' => 'Ⱒ', + 'ⱓ' => 'Ⱓ', + 'ⱔ' => 'Ⱔ', + 'ⱕ' => 'Ⱕ', + 'ⱖ' => 'Ⱖ', + 'ⱗ' => 'Ⱗ', + 'ⱘ' => 'Ⱘ', + 'ⱙ' => 'Ⱙ', + 'ⱚ' => 'Ⱚ', + 'ⱛ' => 'Ⱛ', + 'ⱜ' => 'Ⱜ', + 'ⱝ' => 'Ⱝ', + 'ⱞ' => 'Ⱞ', + 'ⱡ' => 'Ⱡ', + 'ⱥ' => 'Ⱥ', + 'ⱦ' => 'Ⱦ', + 'ⱨ' => 'Ⱨ', + 'ⱪ' => 'Ⱪ', + 'ⱬ' => 'Ⱬ', + 'ⱳ' => 'Ⱳ', + 'ⱶ' => 'Ⱶ', + 'ⲁ' => 'Ⲁ', + 'ⲃ' => 'Ⲃ', + 'ⲅ' => 'Ⲅ', + 'ⲇ' => 'Ⲇ', + 'ⲉ' => 'Ⲉ', + 'ⲋ' => 'Ⲋ', + 'ⲍ' => 'Ⲍ', + 'ⲏ' => 'Ⲏ', + 'ⲑ' => 'Ⲑ', + 'ⲓ' => 'Ⲓ', + 'ⲕ' => 'Ⲕ', + 'ⲗ' => 'Ⲗ', + 'ⲙ' => 'Ⲙ', + 'ⲛ' => 'Ⲛ', + 'ⲝ' => 'Ⲝ', + 'ⲟ' => 'Ⲟ', + 'ⲡ' => 'Ⲡ', + 'ⲣ' => 'Ⲣ', + 'ⲥ' => 'Ⲥ', + 'ⲧ' => 'Ⲧ', + 'ⲩ' => 'Ⲩ', + 'ⲫ' => 'Ⲫ', + 'ⲭ' => 'Ⲭ', + 'ⲯ' => 'Ⲯ', + 'ⲱ' => 'Ⲱ', + 'ⲳ' => 'Ⲳ', + 'ⲵ' => 'Ⲵ', + 'ⲷ' => 'Ⲷ', + 'ⲹ' => 'Ⲹ', + 'ⲻ' => 'Ⲻ', + 'ⲽ' => 'Ⲽ', + 'ⲿ' => 'Ⲿ', + 'ⳁ' => 'Ⳁ', + 'ⳃ' => 'Ⳃ', + 'ⳅ' => 'Ⳅ', + 'ⳇ' => 'Ⳇ', + 'ⳉ' => 'Ⳉ', + 'ⳋ' => 'Ⳋ', + 'ⳍ' => 'Ⳍ', + 'ⳏ' => 'Ⳏ', + 'ⳑ' => 'Ⳑ', + 'ⳓ' => 'Ⳓ', + 'ⳕ' => 'Ⳕ', + 'ⳗ' => 'Ⳗ', + 'ⳙ' => 'Ⳙ', + 'ⳛ' => 'Ⳛ', + 'ⳝ' => 'Ⳝ', + 'ⳟ' => 'Ⳟ', + 'ⳡ' => 'Ⳡ', + 'ⳣ' => 'Ⳣ', + 'ⳬ' => 'Ⳬ', + 'ⳮ' => 'Ⳮ', + 'ⳳ' => 'Ⳳ', + 'ⴀ' => 'Ⴀ', + 'ⴁ' => 'Ⴁ', + 'ⴂ' => 'Ⴂ', + 'ⴃ' => 'Ⴃ', + 'ⴄ' => 'Ⴄ', + 'ⴅ' => 'Ⴅ', + 'ⴆ' => 'Ⴆ', + 'ⴇ' => 'Ⴇ', + 'ⴈ' => 'Ⴈ', + 'ⴉ' => 'Ⴉ', + 'ⴊ' => 'Ⴊ', + 'ⴋ' => 'Ⴋ', + 'ⴌ' => 'Ⴌ', + 'ⴍ' => 'Ⴍ', + 'ⴎ' => 'Ⴎ', + 'ⴏ' => 'Ⴏ', + 'ⴐ' => 'Ⴐ', + 'ⴑ' => 'Ⴑ', + 'ⴒ' => 'Ⴒ', + 'ⴓ' => 'Ⴓ', + 'ⴔ' => 'Ⴔ', + 'ⴕ' => 'Ⴕ', + 'ⴖ' => 'Ⴖ', + 'ⴗ' => 'Ⴗ', + 'ⴘ' => 'Ⴘ', + 'ⴙ' => 'Ⴙ', + 'ⴚ' => 'Ⴚ', + 'ⴛ' => 'Ⴛ', + 'ⴜ' => 'Ⴜ', + 'ⴝ' => 'Ⴝ', + 'ⴞ' => 'Ⴞ', + 'ⴟ' => 'Ⴟ', + 'ⴠ' => 'Ⴠ', + 'ⴡ' => 'Ⴡ', + 'ⴢ' => 'Ⴢ', + 'ⴣ' => 'Ⴣ', + 'ⴤ' => 'Ⴤ', + 'ⴥ' => 'Ⴥ', + 'ⴧ' => 'Ⴧ', + 'ⴭ' => 'Ⴭ', + 'ꙁ' => 'Ꙁ', + 'ꙃ' => 'Ꙃ', + 'ꙅ' => 'Ꙅ', + 'ꙇ' => 'Ꙇ', + 'ꙉ' => 'Ꙉ', + 'ꙋ' => 'Ꙋ', + 'ꙍ' => 'Ꙍ', + 'ꙏ' => 'Ꙏ', + 'ꙑ' => 'Ꙑ', + 'ꙓ' => 'Ꙓ', + 'ꙕ' => 'Ꙕ', + 'ꙗ' => 'Ꙗ', + 'ꙙ' => 'Ꙙ', + 'ꙛ' => 'Ꙛ', + 'ꙝ' => 'Ꙝ', + 'ꙟ' => 'Ꙟ', + 'ꙡ' => 'Ꙡ', + 'ꙣ' => 'Ꙣ', + 'ꙥ' => 'Ꙥ', + 'ꙧ' => 'Ꙧ', + 'ꙩ' => 'Ꙩ', + 'ꙫ' => 'Ꙫ', + 'ꙭ' => 'Ꙭ', + 'ꚁ' => 'Ꚁ', + 'ꚃ' => 'Ꚃ', + 'ꚅ' => 'Ꚅ', + 'ꚇ' => 'Ꚇ', + 'ꚉ' => 'Ꚉ', + 'ꚋ' => 'Ꚋ', + 'ꚍ' => 'Ꚍ', + 'ꚏ' => 'Ꚏ', + 'ꚑ' => 'Ꚑ', + 'ꚓ' => 'Ꚓ', + 'ꚕ' => 'Ꚕ', + 'ꚗ' => 'Ꚗ', + 'ꚙ' => 'Ꚙ', + 'ꚛ' => 'Ꚛ', + 'ꜣ' => 'Ꜣ', + 'ꜥ' => 'Ꜥ', + 'ꜧ' => 'Ꜧ', + 'ꜩ' => 'Ꜩ', + 'ꜫ' => 'Ꜫ', + 'ꜭ' => 'Ꜭ', + 'ꜯ' => 'Ꜯ', + 'ꜳ' => 'Ꜳ', + 'ꜵ' => 'Ꜵ', + 'ꜷ' => 'Ꜷ', + 'ꜹ' => 'Ꜹ', + 'ꜻ' => 'Ꜻ', + 'ꜽ' => 'Ꜽ', + 'ꜿ' => 'Ꜿ', + 'ꝁ' => 'Ꝁ', + 'ꝃ' => 'Ꝃ', + 'ꝅ' => 'Ꝅ', + 'ꝇ' => 'Ꝇ', + 'ꝉ' => 'Ꝉ', + 'ꝋ' => 'Ꝋ', + 'ꝍ' => 'Ꝍ', + 'ꝏ' => 'Ꝏ', + 'ꝑ' => 'Ꝑ', + 'ꝓ' => 'Ꝓ', + 'ꝕ' => 'Ꝕ', + 'ꝗ' => 'Ꝗ', + 'ꝙ' => 'Ꝙ', + 'ꝛ' => 'Ꝛ', + 'ꝝ' => 'Ꝝ', + 'ꝟ' => 'Ꝟ', + 'ꝡ' => 'Ꝡ', + 'ꝣ' => 'Ꝣ', + 'ꝥ' => 'Ꝥ', + 'ꝧ' => 'Ꝧ', + 'ꝩ' => 'Ꝩ', + 'ꝫ' => 'Ꝫ', + 'ꝭ' => 'Ꝭ', + 'ꝯ' => 'Ꝯ', + 'ꝺ' => 'Ꝺ', + 'ꝼ' => 'Ꝼ', + 'ꝿ' => 'Ꝿ', + 'ꞁ' => 'Ꞁ', + 'ꞃ' => 'Ꞃ', + 'ꞅ' => 'Ꞅ', + 'ꞇ' => 'Ꞇ', + 'ꞌ' => 'Ꞌ', + 'ꞑ' => 'Ꞑ', + 'ꞓ' => 'Ꞓ', + 'ꞗ' => 'Ꞗ', + 'ꞙ' => 'Ꞙ', + 'ꞛ' => 'Ꞛ', + 'ꞝ' => 'Ꞝ', + 'ꞟ' => 'Ꞟ', + 'ꞡ' => 'Ꞡ', + 'ꞣ' => 'Ꞣ', + 'ꞥ' => 'Ꞥ', + 'ꞧ' => 'Ꞧ', + 'ꞩ' => 'Ꞩ', + 'a' => 'A', + 'b' => 'B', + 'c' => 'C', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + 'k' => 'K', + 'l' => 'L', + 'm' => 'M', + 'n' => 'N', + 'o' => 'O', + 'p' => 'P', + 'q' => 'Q', + 'r' => 'R', + 's' => 'S', + 't' => 'T', + 'u' => 'U', + 'v' => 'V', + 'w' => 'W', + 'x' => 'X', + 'y' => 'Y', + 'z' => 'Z', + '𐐨' => '𐐀', + '𐐩' => '𐐁', + '𐐪' => '𐐂', + '𐐫' => '𐐃', + '𐐬' => '𐐄', + '𐐭' => '𐐅', + '𐐮' => '𐐆', + '𐐯' => '𐐇', + '𐐰' => '𐐈', + '𐐱' => '𐐉', + '𐐲' => '𐐊', + '𐐳' => '𐐋', + '𐐴' => '𐐌', + '𐐵' => '𐐍', + '𐐶' => '𐐎', + '𐐷' => '𐐏', + '𐐸' => '𐐐', + '𐐹' => '𐐑', + '𐐺' => '𐐒', + '𐐻' => '𐐓', + '𐐼' => '𐐔', + '𐐽' => '𐐕', + '𐐾' => '𐐖', + '𐐿' => '𐐗', + '𐑀' => '𐐘', + '𐑁' => '𐐙', + '𐑂' => '𐐚', + '𐑃' => '𐐛', + '𐑄' => '𐐜', + '𐑅' => '𐐝', + '𐑆' => '𐐞', + '𐑇' => '𐐟', + '𐑈' => '𐐠', + '𐑉' => '𐐡', + '𐑊' => '𐐢', + '𐑋' => '𐐣', + '𐑌' => '𐐤', + '𐑍' => '𐐥', + '𐑎' => '𐐦', + '𐑏' => '𐐧', + '𑣀' => '𑢠', + '𑣁' => '𑢡', + '𑣂' => '𑢢', + '𑣃' => '𑢣', + '𑣄' => '𑢤', + '𑣅' => '𑢥', + '𑣆' => '𑢦', + '𑣇' => '𑢧', + '𑣈' => '𑢨', + '𑣉' => '𑢩', + '𑣊' => '𑢪', + '𑣋' => '𑢫', + '𑣌' => '𑢬', + '𑣍' => '𑢭', + '𑣎' => '𑢮', + '𑣏' => '𑢯', + '𑣐' => '𑢰', + '𑣑' => '𑢱', + '𑣒' => '𑢲', + '𑣓' => '𑢳', + '𑣔' => '𑢴', + '𑣕' => '𑢵', + '𑣖' => '𑢶', + '𑣗' => '𑢷', + '𑣘' => '𑢸', + '𑣙' => '𑢹', + '𑣚' => '𑢺', + '𑣛' => '𑢻', + '𑣜' => '𑢼', + '𑣝' => '𑢽', + '𑣞' => '𑢾', + '𑣟' => '𑢿', +); diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/bootstrap.php b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/bootstrap.php new file mode 100644 index 0000000..204a41b --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/bootstrap.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Mbstring as p; + +if (!function_exists('mb_strlen')) { + define('MB_CASE_UPPER', 0); + define('MB_CASE_LOWER', 1); + define('MB_CASE_TITLE', 2); + + function mb_convert_encoding($s, $to, $from = null) { return p\Mbstring::mb_convert_encoding($s, $to, $from); } + function mb_decode_mimeheader($s) { return p\Mbstring::mb_decode_mimeheader($s); } + function mb_encode_mimeheader($s, $charset = null, $transferEnc = null, $lf = null, $indent = null) { return p\Mbstring::mb_encode_mimeheader($s, $charset, $transferEnc, $lf, $indent); } + function mb_decode_numericentity($s, $convmap, $enc = null) { return p\Mbstring::mb_decode_numericentity($s, $convmap, $enc); } + function mb_encode_numericentity($s, $convmap, $enc = null, $is_hex = false) { return p\Mbstring::mb_encode_numericentity($s, $convmap, $enc, $is_hex); } + function mb_convert_case($s, $mode, $enc = null) { return p\Mbstring::mb_convert_case($s, $mode, $enc); } + function mb_internal_encoding($enc = null) { return p\Mbstring::mb_internal_encoding($enc); } + function mb_language($lang = null) { return p\Mbstring::mb_language($lang); } + function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } + function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } + function mb_check_encoding($var = null, $encoding = null) { return p\Mbstring::mb_check_encoding($var, $encoding); } + function mb_detect_encoding($str, $encodingList = null, $strict = false) { return p\Mbstring::mb_detect_encoding($str, $encodingList, $strict); } + function mb_detect_order($encodingList = null) { return p\Mbstring::mb_detect_order($encodingList); } + function mb_parse_str($s, &$result = array()) { parse_str($s, $result); } + function mb_strlen($s, $enc = null) { return p\Mbstring::mb_strlen($s, $enc); } + function mb_strpos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strpos($s, $needle, $offset, $enc); } + function mb_strtolower($s, $enc = null) { return p\Mbstring::mb_strtolower($s, $enc); } + function mb_strtoupper($s, $enc = null) { return p\Mbstring::mb_strtoupper($s, $enc); } + function mb_substitute_character($char = null) { return p\Mbstring::mb_substitute_character($char); } + function mb_substr($s, $start, $length = 2147483647, $enc = null) { return p\Mbstring::mb_substr($s, $start, $length, $enc); } + function mb_stripos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_stripos($s, $needle, $offset, $enc); } + function mb_stristr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_stristr($s, $needle, $part, $enc); } + function mb_strrchr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strrchr($s, $needle, $part, $enc); } + function mb_strrichr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strrichr($s, $needle, $part, $enc); } + function mb_strripos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strripos($s, $needle, $offset, $enc); } + function mb_strrpos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strrpos($s, $needle, $offset, $enc); } + function mb_strstr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strstr($s, $needle, $part, $enc); } + function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } + function mb_http_output($enc = null) { return p\Mbstring::mb_http_output($enc); } + function mb_strwidth($s, $enc = null) { return p\Mbstring::mb_strwidth($s, $enc); } + function mb_substr_count($haystack, $needle, $enc = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $enc); } + function mb_output_handler($contents, $status) { return p\Mbstring::mb_output_handler($contents, $status); } + function mb_http_input($type = '') { return p\Mbstring::mb_http_input($type); } + function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null) { return p\Mbstring::mb_convert_variables($toEncoding, $fromEncoding, $a, $b, $c, $d, $e, $f); } +} +if (!function_exists('mb_chr')) { + function mb_ord($s, $enc = null) { return p\Mbstring::mb_ord($s, $enc); } + function mb_chr($code, $enc = null) { return p\Mbstring::mb_chr($code, $enc); } + function mb_scrub($s, $enc = null) { $enc = null === $enc ? mb_internal_encoding() : $enc; return mb_convert_encoding($s, $enc, $enc); } +} + +if (!function_exists('mb_str_split')) { + function mb_str_split($string, $split_length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $split_length, $encoding); } +} diff --git a/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/composer.json b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/composer.json new file mode 100644 index 0000000..1a8bec5 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/symfony/polyfill-mbstring/composer.json @@ -0,0 +1,34 @@ +{ + "name": "symfony/polyfill-mbstring", + "type": "library", + "description": "Symfony polyfill for the Mbstring extension", + "keywords": ["polyfill", "shim", "compatibility", "portable", "mbstring"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.3" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" }, + "files": [ "bootstrap.php" ] + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/LICENSE b/system/templateEngines/Twig/Twig2x/twig/twig/LICENSE new file mode 100644 index 0000000..5e8a0b8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/LICENSE @@ -0,0 +1,29 @@ +Copyright (c) 2009-2020 by the Twig Team. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/README.rst b/system/templateEngines/Twig/Twig2x/twig/twig/README.rst new file mode 100644 index 0000000..d896ff5 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/README.rst @@ -0,0 +1,24 @@ +Twig, the flexible, fast, and secure template language for PHP +============================================================== + +Twig is a template language for PHP, released under the new BSD license (code +and documentation). + +Twig uses a syntax similar to the Django and Jinja template languages which +inspired the Twig runtime environment. + +Sponsors +-------- + +.. raw:: html + + + Blackfire.io + + +More Information +---------------- + +Read the `documentation`_ for more information. + +.. _documentation: https://twig.symfony.com/documentation diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/BaseNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/BaseNodeVisitor.php new file mode 100644 index 0000000..e1191f9 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/lib/Twig/BaseNodeVisitor.php @@ -0,0 +1,14 @@ + + */ +interface CacheInterface +{ + /** + * Generates a cache key for the given template class name. + * + * @param string $name The template name + * @param string $className The template class name + * + * @return string + */ + public function generateKey($name, $className); + + /** + * Writes the compiled template to cache. + * + * @param string $key The cache key + * @param string $content The template representation as a PHP class + */ + public function write($key, $content); + + /** + * Loads a template from the cache. + * + * @param string $key The cache key + */ + public function load($key); + + /** + * Returns the modification timestamp of a key. + * + * @param string $key The cache key + * + * @return int + */ + public function getTimestamp($key); +} + +class_alias('Twig\Cache\CacheInterface', 'Twig_CacheInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/FilesystemCache.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/FilesystemCache.php new file mode 100644 index 0000000..b7c1e43 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/FilesystemCache.php @@ -0,0 +1,93 @@ + + */ +class FilesystemCache implements CacheInterface +{ + const FORCE_BYTECODE_INVALIDATION = 1; + + private $directory; + private $options; + + /** + * @param string $directory The root cache directory + * @param int $options A set of options + */ + public function __construct($directory, $options = 0) + { + $this->directory = rtrim($directory, '\/').'/'; + $this->options = $options; + } + + public function generateKey($name, $className) + { + $hash = hash('sha256', $className); + + return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; + } + + public function load($key) + { + if (file_exists($key)) { + @include_once $key; + } + } + + public function write($key, $content) + { + $dir = \dirname($key); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true)) { + clearstatcache(true, $dir); + if (!is_dir($dir)) { + throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); + } + } + } elseif (!is_writable($dir)) { + throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); + } + + $tmpFile = tempnam($dir, basename($key)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { + @chmod($key, 0666 & ~umask()); + + if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { + // Compile cached file into bytecode cache + if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { + @opcache_invalidate($key, true); + } elseif (\function_exists('apc_compile_file')) { + apc_compile_file($key); + } + } + + return; + } + + throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $key)); + } + + public function getTimestamp($key) + { + if (!file_exists($key)) { + return 0; + } + + return (int) @filemtime($key); + } +} + +class_alias('Twig\Cache\FilesystemCache', 'Twig_Cache_Filesystem'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/NullCache.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/NullCache.php new file mode 100644 index 0000000..02c868c --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Cache/NullCache.php @@ -0,0 +1,40 @@ + + */ +final class NullCache implements CacheInterface +{ + public function generateKey($name, $className) + { + return ''; + } + + public function write($key, $content) + { + } + + public function load($key) + { + } + + public function getTimestamp($key) + { + return 0; + } +} + +class_alias('Twig\Cache\NullCache', 'Twig_Cache_Null'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Compiler.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Compiler.php new file mode 100644 index 0000000..56933e2 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Compiler.php @@ -0,0 +1,245 @@ + + */ +class Compiler +{ + private $lastLine; + private $source; + private $indentation; + private $env; + private $debugInfo = []; + private $sourceOffset; + private $sourceLine; + private $varNameSalt = 0; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + /** + * Returns the environment instance related to this compiler. + * + * @return Environment + */ + public function getEnvironment() + { + return $this->env; + } + + /** + * Gets the current PHP code after compilation. + * + * @return string The PHP code + */ + public function getSource() + { + return $this->source; + } + + /** + * Compiles a node. + * + * @param int $indentation The current indentation + * + * @return $this + */ + public function compile(Node $node, $indentation = 0) + { + $this->lastLine = null; + $this->source = ''; + $this->debugInfo = []; + $this->sourceOffset = 0; + // source code starts at 1 (as we then increment it when we encounter new lines) + $this->sourceLine = 1; + $this->indentation = $indentation; + $this->varNameSalt = 0; + + $node->compile($this); + + return $this; + } + + public function subcompile(Node $node, $raw = true) + { + if (false === $raw) { + $this->source .= str_repeat(' ', $this->indentation * 4); + } + + $node->compile($this); + + return $this; + } + + /** + * Adds a raw string to the compiled code. + * + * @param string $string The string + * + * @return $this + */ + public function raw($string) + { + $this->source .= $string; + + return $this; + } + + /** + * Writes a string to the compiled code by adding indentation. + * + * @return $this + */ + public function write(...$strings) + { + foreach ($strings as $string) { + $this->source .= str_repeat(' ', $this->indentation * 4).$string; + } + + return $this; + } + + /** + * Adds a quoted string to the compiled code. + * + * @param string $value The string + * + * @return $this + */ + public function string($value) + { + $this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\")); + + return $this; + } + + /** + * Returns a PHP representation of a given value. + * + * @param mixed $value The value to convert + * + * @return $this + */ + public function repr($value) + { + if (\is_int($value) || \is_float($value)) { + if (false !== $locale = setlocale(LC_NUMERIC, '0')) { + setlocale(LC_NUMERIC, 'C'); + } + + $this->raw(var_export($value, true)); + + if (false !== $locale) { + setlocale(LC_NUMERIC, $locale); + } + } elseif (null === $value) { + $this->raw('null'); + } elseif (\is_bool($value)) { + $this->raw($value ? 'true' : 'false'); + } elseif (\is_array($value)) { + $this->raw('array('); + $first = true; + foreach ($value as $key => $v) { + if (!$first) { + $this->raw(', '); + } + $first = false; + $this->repr($key); + $this->raw(' => '); + $this->repr($v); + } + $this->raw(')'); + } else { + $this->string($value); + } + + return $this; + } + + /** + * Adds debugging information. + * + * @return $this + */ + public function addDebugInfo(Node $node) + { + if ($node->getTemplateLine() != $this->lastLine) { + $this->write(sprintf("// line %d\n", $node->getTemplateLine())); + + $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); + $this->sourceOffset = \strlen($this->source); + $this->debugInfo[$this->sourceLine] = $node->getTemplateLine(); + + $this->lastLine = $node->getTemplateLine(); + } + + return $this; + } + + public function getDebugInfo() + { + ksort($this->debugInfo); + + return $this->debugInfo; + } + + /** + * Indents the generated code. + * + * @param int $step The number of indentation to add + * + * @return $this + */ + public function indent($step = 1) + { + $this->indentation += $step; + + return $this; + } + + /** + * Outdents the generated code. + * + * @param int $step The number of indentation to remove + * + * @return $this + * + * @throws \LogicException When trying to outdent too much so the indentation would become negative + */ + public function outdent($step = 1) + { + // can't outdent by more steps than the current indentation level + if ($this->indentation < $step) { + throw new \LogicException('Unable to call outdent() as the indentation would become negative.'); + } + + $this->indentation -= $step; + + return $this; + } + + public function getVarName() + { + return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++)); + } +} + +class_alias('Twig\Compiler', 'Twig_Compiler'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Environment.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Environment.php new file mode 100644 index 0000000..d0419fb --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Environment.php @@ -0,0 +1,995 @@ + + */ +class Environment +{ + const VERSION = '2.12.5'; + const VERSION_ID = 21205; + const MAJOR_VERSION = 2; + const MINOR_VERSION = 12; + const RELEASE_VERSION = 5; + const EXTRA_VERSION = ''; + + private $charset; + private $loader; + private $debug; + private $autoReload; + private $cache; + private $lexer; + private $parser; + private $compiler; + private $baseTemplateClass; + private $globals = []; + private $resolvedGlobals; + private $loadedTemplates; + private $strictVariables; + private $templateClassPrefix = '__TwigTemplate_'; + private $originalCache; + private $extensionSet; + private $runtimeLoaders = []; + private $runtimes = []; + private $optionsHash; + + /** + * Constructor. + * + * Available options: + * + * * debug: When set to true, it automatically set "auto_reload" to true as + * well (default to false). + * + * * charset: The charset used by the templates (default to UTF-8). + * + * * base_template_class: The base template class to use for generated + * templates (default to \Twig\Template). + * + * * cache: An absolute path where to store the compiled templates, + * a \Twig\Cache\CacheInterface implementation, + * or false to disable compilation cache (default). + * + * * auto_reload: Whether to reload the template if the original source changed. + * If you don't provide the auto_reload option, it will be + * determined automatically based on the debug value. + * + * * strict_variables: Whether to ignore invalid variables in templates + * (default to false). + * + * * autoescape: Whether to enable auto-escaping (default to html): + * * false: disable auto-escaping + * * html, js: set the autoescaping to one of the supported strategies + * * name: set the autoescaping strategy based on the template name extension + * * PHP callback: a PHP callback that returns an escaping strategy based on the template "name" + * + * * optimizations: A flag that indicates which optimizations to apply + * (default to -1 which means that all optimizations are enabled; + * set it to 0 to disable). + */ + public function __construct(LoaderInterface $loader, $options = []) + { + $this->setLoader($loader); + + $options = array_merge([ + 'debug' => false, + 'charset' => 'UTF-8', + 'base_template_class' => Template::class, + 'strict_variables' => false, + 'autoescape' => 'html', + 'cache' => false, + 'auto_reload' => null, + 'optimizations' => -1, + ], $options); + + $this->debug = (bool) $options['debug']; + $this->setCharset($options['charset']); + $this->baseTemplateClass = '\\'.ltrim($options['base_template_class'], '\\'); + if ('\\'.Template::class !== $this->baseTemplateClass && '\Twig_Template' !== $this->baseTemplateClass) { + @trigger_error('The "base_template_class" option on '.__CLASS__.' is deprecated since Twig 2.7.0.', E_USER_DEPRECATED); + } + $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; + $this->strictVariables = (bool) $options['strict_variables']; + $this->setCache($options['cache']); + $this->extensionSet = new ExtensionSet(); + + $this->addExtension(new CoreExtension()); + $this->addExtension(new EscaperExtension($options['autoescape'])); + $this->addExtension(new OptimizerExtension($options['optimizations'])); + } + + /** + * Gets the base template class for compiled templates. + * + * @return string The base template class name + */ + public function getBaseTemplateClass() + { + if (1 > \func_num_args() || \func_get_arg(0)) { + @trigger_error('The '.__METHOD__.' is deprecated since Twig 2.7.0.', E_USER_DEPRECATED); + } + + return $this->baseTemplateClass; + } + + /** + * Sets the base template class for compiled templates. + * + * @param string $class The base template class name + */ + public function setBaseTemplateClass($class) + { + @trigger_error('The '.__METHOD__.' is deprecated since Twig 2.7.0.', E_USER_DEPRECATED); + + $this->baseTemplateClass = $class; + $this->updateOptionsHash(); + } + + /** + * Enables debugging mode. + */ + public function enableDebug() + { + $this->debug = true; + $this->updateOptionsHash(); + } + + /** + * Disables debugging mode. + */ + public function disableDebug() + { + $this->debug = false; + $this->updateOptionsHash(); + } + + /** + * Checks if debug mode is enabled. + * + * @return bool true if debug mode is enabled, false otherwise + */ + public function isDebug() + { + return $this->debug; + } + + /** + * Enables the auto_reload option. + */ + public function enableAutoReload() + { + $this->autoReload = true; + } + + /** + * Disables the auto_reload option. + */ + public function disableAutoReload() + { + $this->autoReload = false; + } + + /** + * Checks if the auto_reload option is enabled. + * + * @return bool true if auto_reload is enabled, false otherwise + */ + public function isAutoReload() + { + return $this->autoReload; + } + + /** + * Enables the strict_variables option. + */ + public function enableStrictVariables() + { + $this->strictVariables = true; + $this->updateOptionsHash(); + } + + /** + * Disables the strict_variables option. + */ + public function disableStrictVariables() + { + $this->strictVariables = false; + $this->updateOptionsHash(); + } + + /** + * Checks if the strict_variables option is enabled. + * + * @return bool true if strict_variables is enabled, false otherwise + */ + public function isStrictVariables() + { + return $this->strictVariables; + } + + /** + * Gets the current cache implementation. + * + * @param bool $original Whether to return the original cache option or the real cache instance + * + * @return CacheInterface|string|false A Twig\Cache\CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache + */ + public function getCache($original = true) + { + return $original ? $this->originalCache : $this->cache; + } + + /** + * Sets the current cache implementation. + * + * @param CacheInterface|string|false $cache A Twig\Cache\CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache + */ + public function setCache($cache) + { + if (\is_string($cache)) { + $this->originalCache = $cache; + $this->cache = new FilesystemCache($cache); + } elseif (false === $cache) { + $this->originalCache = $cache; + $this->cache = new NullCache(); + } elseif ($cache instanceof CacheInterface) { + $this->originalCache = $this->cache = $cache; + } else { + throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.')); + } + } + + /** + * Gets the template class associated with the given string. + * + * The generated template class is based on the following parameters: + * + * * The cache key for the given template; + * * The currently enabled extensions; + * * Whether the Twig C extension is available or not; + * * PHP version; + * * Twig version; + * * Options with what environment was created. + * + * @param string $name The name for which to calculate the template class name + * @param int|null $index The index if it is an embedded template + * + * @return string The template class name + * + * @internal + */ + public function getTemplateClass($name, $index = null) + { + $key = $this->getLoader()->getCacheKey($name).$this->optionsHash; + + return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '___'.$index); + } + + /** + * Renders a template. + * + * @param string|TemplateWrapper $name The template name + * @param array $context An array of parameters to pass to the template + * + * @return string The rendered template + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering + */ + public function render($name, array $context = []) + { + return $this->load($name)->render($context); + } + + /** + * Displays a template. + * + * @param string|TemplateWrapper $name The template name + * @param array $context An array of parameters to pass to the template + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering + */ + public function display($name, array $context = []) + { + $this->load($name)->display($context); + } + + /** + * Loads a template. + * + * @param string|TemplateWrapper $name The template name + * + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation + * + * @return TemplateWrapper + */ + public function load($name) + { + if ($name instanceof TemplateWrapper) { + return $name; + } + + if ($name instanceof Template) { + @trigger_error('Passing a \Twig\Template instance to '.__METHOD__.' is deprecated since Twig 2.7.0, use \Twig\TemplateWrapper instead.', E_USER_DEPRECATED); + + return new TemplateWrapper($this, $name); + } + + return new TemplateWrapper($this, $this->loadTemplate($name)); + } + + /** + * Loads a template internal representation. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The template name + * @param int $index The index if it is an embedded template + * + * @return Template A template instance representing the given template name + * + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation + * + * @internal + */ + public function loadTemplate($name, $index = null) + { + return $this->loadClass($this->getTemplateClass($name), $name, $index); + } + + /** + * @internal + */ + public function loadClass($cls, $name, $index = null) + { + $mainCls = $cls; + if (null !== $index) { + $cls .= '___'.$index; + } + + if (isset($this->loadedTemplates[$cls])) { + return $this->loadedTemplates[$cls]; + } + + if (!class_exists($cls, false)) { + $key = $this->cache->generateKey($name, $mainCls); + + if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) { + $this->cache->load($key); + } + + $source = null; + if (!class_exists($cls, false)) { + $source = $this->getLoader()->getSourceContext($name); + $content = $this->compileSource($source); + $this->cache->write($key, $content); + $this->cache->load($key); + + if (!class_exists($mainCls, false)) { + /* Last line of defense if either $this->bcWriteCacheFile was used, + * $this->cache is implemented as a no-op or we have a race condition + * where the cache was cleared between the above calls to write to and load from + * the cache. + */ + eval('?>'.$content); + } + + if (!class_exists($cls, false)) { + throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source); + } + } + } + + // to be removed in 3.0 + $this->extensionSet->initRuntime($this); + + return $this->loadedTemplates[$cls] = new $cls($this); + } + + /** + * Creates a template from source. + * + * This method should not be used as a generic way to load templates. + * + * @param string $template The template source + * @param string $name An optional name of the template to be used in error messages + * + * @return TemplateWrapper A template instance representing the given template name + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + */ + public function createTemplate($template, string $name = null) + { + $hash = hash('sha256', $template, false); + if (null !== $name) { + $name = sprintf('%s (string template %s)', $name, $hash); + } else { + $name = sprintf('__string_template__%s', $hash); + } + + $loader = new ChainLoader([ + new ArrayLoader([$name => $template]), + $current = $this->getLoader(), + ]); + + $this->setLoader($loader); + try { + return new TemplateWrapper($this, $this->loadTemplate($name)); + } finally { + $this->setLoader($current); + } + } + + /** + * Returns true if the template is still fresh. + * + * Besides checking the loader for freshness information, + * this method also checks if the enabled extensions have + * not changed. + * + * @param string $name The template name + * @param int $time The last modification time of the cached template + * + * @return bool true if the template is fresh, false otherwise + */ + public function isTemplateFresh($name, $time) + { + return $this->extensionSet->getLastModified() <= $time && $this->getLoader()->isFresh($name, $time); + } + + /** + * Tries to load a template consecutively from an array. + * + * Similar to load() but it also accepts instances of \Twig\Template and + * \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded. + * + * @param string|TemplateWrapper|array $names A template or an array of templates to try consecutively + * + * @return TemplateWrapper|Template + * + * @throws LoaderError When none of the templates can be found + * @throws SyntaxError When an error occurred during compilation + */ + public function resolveTemplate($names) + { + if (!\is_array($names)) { + $names = [$names]; + } + + foreach ($names as $name) { + if ($name instanceof Template) { + return $name; + } + if ($name instanceof TemplateWrapper) { + return $name; + } + + try { + return $this->loadTemplate($name); + } catch (LoaderError $e) { + if (1 === \count($names)) { + throw $e; + } + } + } + + throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); + } + + public function setLexer(Lexer $lexer) + { + $this->lexer = $lexer; + } + + /** + * Tokenizes a source code. + * + * @return TokenStream + * + * @throws SyntaxError When the code is syntactically wrong + */ + public function tokenize(Source $source) + { + if (null === $this->lexer) { + $this->lexer = new Lexer($this); + } + + return $this->lexer->tokenize($source); + } + + public function setParser(Parser $parser) + { + $this->parser = $parser; + } + + /** + * Converts a token stream to a node tree. + * + * @return ModuleNode + * + * @throws SyntaxError When the token stream is syntactically or semantically wrong + */ + public function parse(TokenStream $stream) + { + if (null === $this->parser) { + $this->parser = new Parser($this); + } + + return $this->parser->parse($stream); + } + + public function setCompiler(Compiler $compiler) + { + $this->compiler = $compiler; + } + + /** + * Compiles a node and returns the PHP code. + * + * @return string The compiled PHP source code + */ + public function compile(Node $node) + { + if (null === $this->compiler) { + $this->compiler = new Compiler($this); + } + + return $this->compiler->compile($node)->getSource(); + } + + /** + * Compiles a template source code. + * + * @return string The compiled PHP source code + * + * @throws SyntaxError When there was an error during tokenizing, parsing or compiling + */ + public function compileSource(Source $source) + { + try { + return $this->compile($this->parse($this->tokenize($source))); + } catch (Error $e) { + $e->setSourceContext($source); + throw $e; + } catch (\Exception $e) { + throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); + } + } + + public function setLoader(LoaderInterface $loader) + { + $this->loader = $loader; + } + + /** + * Gets the Loader instance. + * + * @return LoaderInterface + */ + public function getLoader() + { + return $this->loader; + } + + /** + * Sets the default template charset. + * + * @param string $charset The default charset + */ + public function setCharset($charset) + { + if ('UTF8' === $charset = strtoupper($charset)) { + // iconv on Windows requires "UTF-8" instead of "UTF8" + $charset = 'UTF-8'; + } + + $this->charset = $charset; + } + + /** + * Gets the default template charset. + * + * @return string The default charset + */ + public function getCharset() + { + return $this->charset; + } + + /** + * Returns true if the given extension is registered. + * + * @param string $class The extension class name + * + * @return bool Whether the extension is registered or not + */ + public function hasExtension($class) + { + return $this->extensionSet->hasExtension($class); + } + + /** + * Adds a runtime loader. + */ + public function addRuntimeLoader(RuntimeLoaderInterface $loader) + { + $this->runtimeLoaders[] = $loader; + } + + /** + * Gets an extension by class name. + * + * @param string $class The extension class name + * + * @return ExtensionInterface + */ + public function getExtension($class) + { + return $this->extensionSet->getExtension($class); + } + + /** + * Returns the runtime implementation of a Twig element (filter/function/test). + * + * @param string $class A runtime class name + * + * @return object The runtime implementation + * + * @throws RuntimeError When the template cannot be found + */ + public function getRuntime($class) + { + if (isset($this->runtimes[$class])) { + return $this->runtimes[$class]; + } + + foreach ($this->runtimeLoaders as $loader) { + if (null !== $runtime = $loader->load($class)) { + return $this->runtimes[$class] = $runtime; + } + } + + throw new RuntimeError(sprintf('Unable to load the "%s" runtime.', $class)); + } + + public function addExtension(ExtensionInterface $extension) + { + $this->extensionSet->addExtension($extension); + $this->updateOptionsHash(); + } + + /** + * Registers an array of extensions. + * + * @param array $extensions An array of extensions + */ + public function setExtensions(array $extensions) + { + $this->extensionSet->setExtensions($extensions); + $this->updateOptionsHash(); + } + + /** + * Returns all registered extensions. + * + * @return ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) + */ + public function getExtensions() + { + return $this->extensionSet->getExtensions(); + } + + public function addTokenParser(TokenParserInterface $parser) + { + $this->extensionSet->addTokenParser($parser); + } + + /** + * Gets the registered Token Parsers. + * + * @return TokenParserInterface[] + * + * @internal + */ + public function getTokenParsers() + { + return $this->extensionSet->getTokenParsers(); + } + + /** + * Gets registered tags. + * + * @return TokenParserInterface[] + * + * @internal + */ + public function getTags() + { + $tags = []; + foreach ($this->getTokenParsers() as $parser) { + $tags[$parser->getTag()] = $parser; + } + + return $tags; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + $this->extensionSet->addNodeVisitor($visitor); + } + + /** + * Gets the registered Node Visitors. + * + * @return NodeVisitorInterface[] + * + * @internal + */ + public function getNodeVisitors() + { + return $this->extensionSet->getNodeVisitors(); + } + + public function addFilter(TwigFilter $filter) + { + $this->extensionSet->addFilter($filter); + } + + /** + * Get a filter by name. + * + * Subclasses may override this method and load filters differently; + * so no list of filters is available. + * + * @param string $name The filter name + * + * @return TwigFilter|false + * + * @internal + */ + public function getFilter($name) + { + return $this->extensionSet->getFilter($name); + } + + public function registerUndefinedFilterCallback(callable $callable) + { + $this->extensionSet->registerUndefinedFilterCallback($callable); + } + + /** + * Gets the registered Filters. + * + * Be warned that this method cannot return filters defined with registerUndefinedFilterCallback. + * + * @return TwigFilter[] + * + * @see registerUndefinedFilterCallback + * + * @internal + */ + public function getFilters() + { + return $this->extensionSet->getFilters(); + } + + public function addTest(TwigTest $test) + { + $this->extensionSet->addTest($test); + } + + /** + * Gets the registered Tests. + * + * @return TwigTest[] + * + * @internal + */ + public function getTests() + { + return $this->extensionSet->getTests(); + } + + /** + * Gets a test by name. + * + * @param string $name The test name + * + * @return TwigTest|false + * + * @internal + */ + public function getTest($name) + { + return $this->extensionSet->getTest($name); + } + + public function addFunction(TwigFunction $function) + { + $this->extensionSet->addFunction($function); + } + + /** + * Get a function by name. + * + * Subclasses may override this method and load functions differently; + * so no list of functions is available. + * + * @param string $name function name + * + * @return TwigFunction|false + * + * @internal + */ + public function getFunction($name) + { + return $this->extensionSet->getFunction($name); + } + + public function registerUndefinedFunctionCallback(callable $callable) + { + $this->extensionSet->registerUndefinedFunctionCallback($callable); + } + + /** + * Gets registered functions. + * + * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback. + * + * @return TwigFunction[] + * + * @see registerUndefinedFunctionCallback + * + * @internal + */ + public function getFunctions() + { + return $this->extensionSet->getFunctions(); + } + + /** + * Registers a Global. + * + * New globals can be added before compiling or rendering a template; + * but after, you can only update existing globals. + * + * @param string $name The global name + * @param mixed $value The global value + */ + public function addGlobal($name, $value) + { + if ($this->extensionSet->isInitialized() && !\array_key_exists($name, $this->getGlobals())) { + throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); + } + + if (null !== $this->resolvedGlobals) { + $this->resolvedGlobals[$name] = $value; + } else { + $this->globals[$name] = $value; + } + } + + /** + * Gets the registered Globals. + * + * @return array An array of globals + * + * @internal + */ + public function getGlobals() + { + if ($this->extensionSet->isInitialized()) { + if (null === $this->resolvedGlobals) { + $this->resolvedGlobals = array_merge($this->extensionSet->getGlobals(), $this->globals); + } + + return $this->resolvedGlobals; + } + + return array_merge($this->extensionSet->getGlobals(), $this->globals); + } + + /** + * Merges a context with the defined globals. + * + * @param array $context An array representing the context + * + * @return array The context merged with the globals + */ + public function mergeGlobals(array $context) + { + // we don't use array_merge as the context being generally + // bigger than globals, this code is faster. + foreach ($this->getGlobals() as $key => $value) { + if (!\array_key_exists($key, $context)) { + $context[$key] = $value; + } + } + + return $context; + } + + /** + * Gets the registered unary Operators. + * + * @return array An array of unary operators + * + * @internal + */ + public function getUnaryOperators() + { + return $this->extensionSet->getUnaryOperators(); + } + + /** + * Gets the registered binary Operators. + * + * @return array An array of binary operators + * + * @internal + */ + public function getBinaryOperators() + { + return $this->extensionSet->getBinaryOperators(); + } + + private function updateOptionsHash() + { + $this->optionsHash = implode(':', [ + $this->extensionSet->getSignature(), + PHP_MAJOR_VERSION, + PHP_MINOR_VERSION, + self::VERSION, + (int) $this->debug, + $this->baseTemplateClass, + (int) $this->strictVariables, + ]); + } +} + +class_alias('Twig\Environment', 'Twig_Environment'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/Error.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/Error.php new file mode 100644 index 0000000..a64cbcb --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/Error.php @@ -0,0 +1,257 @@ + + */ +class Error extends \Exception +{ + private $lineno; + private $name; + private $rawMessage; + private $sourcePath; + private $sourceCode; + + /** + * Constructor. + * + * Set the line number to -1 to enable its automatic guessing. + * Set the name to null to enable its automatic guessing. + * + * @param string $message The error message + * @param int $lineno The template line where the error occurred + * @param Source|string|null $source The source context where the error occurred + * @param \Exception $previous The previous exception + */ + public function __construct(string $message, int $lineno = -1, $source = null, \Exception $previous = null) + { + parent::__construct('', 0, $previous); + + if (null === $source) { + $name = null; + } elseif (!$source instanceof Source && !$source instanceof \Twig_Source) { + @trigger_error(sprintf('Passing a string as a source to %s is deprecated since Twig 2.6.1; pass a Twig\Source instance instead.', __CLASS__), E_USER_DEPRECATED); + $name = $source; + } else { + $name = $source->getName(); + $this->sourceCode = $source->getCode(); + $this->sourcePath = $source->getPath(); + } + + $this->lineno = $lineno; + $this->name = $name; + $this->rawMessage = $message; + $this->updateRepr(); + } + + /** + * Gets the raw message. + * + * @return string The raw message + */ + public function getRawMessage() + { + return $this->rawMessage; + } + + /** + * Gets the template line where the error occurred. + * + * @return int The template line + */ + public function getTemplateLine() + { + return $this->lineno; + } + + /** + * Sets the template line where the error occurred. + * + * @param int $lineno The template line + */ + public function setTemplateLine($lineno) + { + $this->lineno = $lineno; + + $this->updateRepr(); + } + + /** + * Gets the source context of the Twig template where the error occurred. + * + * @return Source|null + */ + public function getSourceContext() + { + return $this->name ? new Source($this->sourceCode, $this->name, $this->sourcePath) : null; + } + + /** + * Sets the source context of the Twig template where the error occurred. + */ + public function setSourceContext(Source $source = null) + { + if (null === $source) { + $this->sourceCode = $this->name = $this->sourcePath = null; + } else { + $this->sourceCode = $source->getCode(); + $this->name = $source->getName(); + $this->sourcePath = $source->getPath(); + } + + $this->updateRepr(); + } + + public function guess() + { + $this->guessTemplateInfo(); + $this->updateRepr(); + } + + public function appendMessage($rawMessage) + { + $this->rawMessage .= $rawMessage; + $this->updateRepr(); + } + + private function updateRepr() + { + $this->message = $this->rawMessage; + + if ($this->sourcePath && $this->lineno > 0) { + $this->file = $this->sourcePath; + $this->line = $this->lineno; + + return; + } + + $dot = false; + if ('.' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $dot = true; + } + + $questionMark = false; + if ('?' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $questionMark = true; + } + + if ($this->name) { + if (\is_string($this->name) || (\is_object($this->name) && method_exists($this->name, '__toString'))) { + $name = sprintf('"%s"', $this->name); + } else { + $name = json_encode($this->name); + } + $this->message .= sprintf(' in %s', $name); + } + + if ($this->lineno && $this->lineno >= 0) { + $this->message .= sprintf(' at line %d', $this->lineno); + } + + if ($dot) { + $this->message .= '.'; + } + + if ($questionMark) { + $this->message .= '?'; + } + } + + private function guessTemplateInfo() + { + $template = null; + $templateClass = null; + + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + foreach ($backtrace as $trace) { + if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) { + $currentClass = \get_class($trace['object']); + $isEmbedContainer = 0 === strpos($templateClass, $currentClass); + if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) { + $template = $trace['object']; + $templateClass = \get_class($trace['object']); + } + } + } + + // update template name + if (null !== $template && null === $this->name) { + $this->name = $template->getTemplateName(); + } + + // update template path if any + if (null !== $template && null === $this->sourcePath) { + $src = $template->getSourceContext(); + $this->sourceCode = $src->getCode(); + $this->sourcePath = $src->getPath(); + } + + if (null === $template || $this->lineno > -1) { + return; + } + + $r = new \ReflectionObject($template); + $file = $r->getFileName(); + + $exceptions = [$e = $this]; + while ($e = $e->getPrevious()) { + $exceptions[] = $e; + } + + while ($e = array_pop($exceptions)) { + $traces = $e->getTrace(); + array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]); + + while ($trace = array_shift($traces)) { + if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) { + continue; + } + + foreach ($template->getDebugInfo() as $codeLine => $templateLine) { + if ($codeLine <= $trace['line']) { + // update template line + $this->lineno = $templateLine; + + return; + } + } + } + } + } +} + +class_alias('Twig\Error\Error', 'Twig_Error'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/LoaderError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/LoaderError.php new file mode 100644 index 0000000..dc5a9f1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/LoaderError.php @@ -0,0 +1,23 @@ + + */ +class LoaderError extends Error +{ +} + +class_alias('Twig\Error\LoaderError', 'Twig_Error_Loader'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/RuntimeError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/RuntimeError.php new file mode 100644 index 0000000..9b3f36e --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/RuntimeError.php @@ -0,0 +1,24 @@ + + */ +class RuntimeError extends Error +{ +} + +class_alias('Twig\Error\RuntimeError', 'Twig_Error_Runtime'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/SyntaxError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/SyntaxError.php new file mode 100644 index 0000000..efece92 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Error/SyntaxError.php @@ -0,0 +1,48 @@ + + */ +class SyntaxError extends Error +{ + /** + * Tweaks the error message to include suggestions. + * + * @param string $name The original name of the item that does not exist + * @param array $items An array of possible items + */ + public function addSuggestions($name, array $items) + { + $alternatives = []; + foreach ($items as $item) { + $lev = levenshtein($name, $item); + if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) { + $alternatives[$item] = $lev; + } + } + + if (!$alternatives) { + return; + } + + asort($alternatives); + + $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives)))); + } +} + +class_alias('Twig\Error\SyntaxError', 'Twig_Error_Syntax'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/ExpressionParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/ExpressionParser.php new file mode 100644 index 0000000..e6a2073 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/ExpressionParser.php @@ -0,0 +1,814 @@ + + * + * @internal + */ +class ExpressionParser +{ + const OPERATOR_LEFT = 1; + const OPERATOR_RIGHT = 2; + + private $parser; + private $env; + private $unaryOperators; + private $binaryOperators; + + public function __construct(Parser $parser, Environment $env) + { + $this->parser = $parser; + $this->env = $env; + $this->unaryOperators = $env->getUnaryOperators(); + $this->binaryOperators = $env->getBinaryOperators(); + } + + public function parseExpression($precedence = 0, $allowArrow = false) + { + if ($allowArrow && $arrow = $this->parseArrow()) { + return $arrow; + } + + $expr = $this->getPrimary(); + $token = $this->parser->getCurrentToken(); + while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) { + $op = $this->binaryOperators[$token->getValue()]; + $this->parser->getStream()->next(); + + if ('is not' === $token->getValue()) { + $expr = $this->parseNotTestExpression($expr); + } elseif ('is' === $token->getValue()) { + $expr = $this->parseTestExpression($expr); + } elseif (isset($op['callable'])) { + $expr = $op['callable']($this->parser, $expr); + } else { + $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); + $class = $op['class']; + $expr = new $class($expr, $expr1, $token->getLine()); + } + + $token = $this->parser->getCurrentToken(); + } + + if (0 === $precedence) { + return $this->parseConditionalExpression($expr); + } + + return $expr; + } + + /** + * @return ArrowFunctionExpression|null + */ + private function parseArrow() + { + $stream = $this->parser->getStream(); + + // short array syntax (one argument, no parentheses)? + if ($stream->look(1)->test(/* Token::ARROW_TYPE */ 12)) { + $line = $stream->getCurrent()->getLine(); + $token = $stream->expect(/* Token::NAME_TYPE */ 5); + $names = [new AssignNameExpression($token->getValue(), $token->getLine())]; + $stream->expect(/* Token::ARROW_TYPE */ 12); + + return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line); + } + + // first, determine if we are parsing an arrow function by finding => (long form) + $i = 0; + if (!$stream->look($i)->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + return null; + } + ++$i; + while (true) { + // variable name + ++$i; + if (!$stream->look($i)->test(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + ++$i; + } + if (!$stream->look($i)->test(/* Token::PUNCTUATION_TYPE */ 9, ')')) { + return null; + } + ++$i; + if (!$stream->look($i)->test(/* Token::ARROW_TYPE */ 12)) { + return null; + } + + // yes, let's parse it properly + $token = $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '('); + $line = $token->getLine(); + + $names = []; + while (true) { + $token = $stream->expect(/* Token::NAME_TYPE */ 5); + $names[] = new AssignNameExpression($token->getValue(), $token->getLine()); + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ')'); + $stream->expect(/* Token::ARROW_TYPE */ 12); + + return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line); + } + + private function getPrimary(): AbstractExpression + { + $token = $this->parser->getCurrentToken(); + + if ($this->isUnary($token)) { + $operator = $this->unaryOperators[$token->getValue()]; + $this->parser->getStream()->next(); + $expr = $this->parseExpression($operator['precedence']); + $class = $operator['class']; + + return $this->parsePostfixExpression(new $class($expr, $token->getLine())); + } elseif ($token->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $this->parser->getStream()->next(); + $expr = $this->parseExpression(); + $this->parser->getStream()->expect(/* Token::PUNCTUATION_TYPE */ 9, ')', 'An opened parenthesis is not properly closed'); + + return $this->parsePostfixExpression($expr); + } + + return $this->parsePrimaryExpression(); + } + + private function parseConditionalExpression($expr): AbstractExpression + { + while ($this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, '?')) { + if (!$this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $expr2 = $this->parseExpression(); + if ($this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $expr3 = $this->parseExpression(); + } else { + $expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine()); + } + } else { + $expr2 = $expr; + $expr3 = $this->parseExpression(); + } + + $expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); + } + + return $expr; + } + + private function isUnary(Token $token): bool + { + return $token->test(/* Token::OPERATOR_TYPE */ 8) && isset($this->unaryOperators[$token->getValue()]); + } + + private function isBinary(Token $token): bool + { + return $token->test(/* Token::OPERATOR_TYPE */ 8) && isset($this->binaryOperators[$token->getValue()]); + } + + public function parsePrimaryExpression() + { + $token = $this->parser->getCurrentToken(); + switch ($token->getType()) { + case /* Token::NAME_TYPE */ 5: + $this->parser->getStream()->next(); + switch ($token->getValue()) { + case 'true': + case 'TRUE': + $node = new ConstantExpression(true, $token->getLine()); + break; + + case 'false': + case 'FALSE': + $node = new ConstantExpression(false, $token->getLine()); + break; + + case 'none': + case 'NONE': + case 'null': + case 'NULL': + $node = new ConstantExpression(null, $token->getLine()); + break; + + default: + if ('(' === $this->parser->getCurrentToken()->getValue()) { + $node = $this->getFunctionNode($token->getValue(), $token->getLine()); + } else { + $node = new NameExpression($token->getValue(), $token->getLine()); + } + } + break; + + case /* Token::NUMBER_TYPE */ 6: + $this->parser->getStream()->next(); + $node = new ConstantExpression($token->getValue(), $token->getLine()); + break; + + case /* Token::STRING_TYPE */ 7: + case /* Token::INTERPOLATION_START_TYPE */ 10: + $node = $this->parseStringExpression(); + break; + + case /* Token::OPERATOR_TYPE */ 8: + if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { + // in this context, string operators are variable names + $this->parser->getStream()->next(); + $node = new NameExpression($token->getValue(), $token->getLine()); + break; + } elseif (isset($this->unaryOperators[$token->getValue()])) { + $class = $this->unaryOperators[$token->getValue()]['class']; + + $ref = new \ReflectionClass($class); + if (!(\in_array($ref->getName(), [NegUnary::class, PosUnary::class, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos']) + || $ref->isSubclassOf(NegUnary::class) || $ref->isSubclassOf(PosUnary::class) + || $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos')) + ) { + throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } + + $this->parser->getStream()->next(); + $expr = $this->parsePrimaryExpression(); + + $node = new $class($expr, $token->getLine()); + break; + } + + // no break + default: + if ($token->test(/* Token::PUNCTUATION_TYPE */ 9, '[')) { + $node = $this->parseArrayExpression(); + } elseif ($token->test(/* Token::PUNCTUATION_TYPE */ 9, '{')) { + $node = $this->parseHashExpression(); + } elseif ($token->test(/* Token::OPERATOR_TYPE */ 8, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { + 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()); + } else { + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } + } + + return $this->parsePostfixExpression($node); + } + + public function parseStringExpression() + { + $stream = $this->parser->getStream(); + + $nodes = []; + // a string cannot be followed by another string in a single expression + $nextCanBeString = true; + while (true) { + if ($nextCanBeString && $token = $stream->nextIf(/* Token::STRING_TYPE */ 7)) { + $nodes[] = new ConstantExpression($token->getValue(), $token->getLine()); + $nextCanBeString = false; + } elseif ($stream->nextIf(/* Token::INTERPOLATION_START_TYPE */ 10)) { + $nodes[] = $this->parseExpression(); + $stream->expect(/* Token::INTERPOLATION_END_TYPE */ 11); + $nextCanBeString = true; + } else { + break; + } + } + + $expr = array_shift($nodes); + foreach ($nodes as $node) { + $expr = new ConcatBinary($expr, $node, $node->getTemplateLine()); + } + + return $expr; + } + + public function parseArrayExpression() + { + $stream = $this->parser->getStream(); + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '[', 'An array element was expected'); + + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); + $first = true; + while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) { + if (!$first) { + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'An array element must be followed by a comma'); + + // trailing ,? + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) { + break; + } + } + $first = false; + + $node->addElement($this->parseExpression()); + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']', 'An opened array is not properly closed'); + + return $node; + } + + public function parseHashExpression() + { + $stream = $this->parser->getStream(); + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '{', 'A hash element was expected'); + + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); + $first = true; + while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, '}')) { + if (!$first) { + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'A hash value must be followed by a comma'); + + // trailing ,? + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '}')) { + break; + } + } + $first = false; + + // a hash key can be: + // + // * a number -- 12 + // * a string -- 'a' + // * a name, which is equivalent to a string -- a + // * an expression, which must be enclosed in parentheses -- (1 + 2) + if (($token = $stream->nextIf(/* Token::STRING_TYPE */ 7)) || ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) || $token = $stream->nextIf(/* Token::NUMBER_TYPE */ 6)) { + $key = new ConstantExpression($token->getValue(), $token->getLine()); + } elseif ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $key = $this->parseExpression(); + } else { + $current = $stream->getCurrent(); + + 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()); + } + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ':', 'A hash key must be followed by a colon (:)'); + $value = $this->parseExpression(); + + $node->addElement($value, $key); + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '}', 'An opened hash is not properly closed'); + + return $node; + } + + public function parsePostfixExpression($node) + { + while (true) { + $token = $this->parser->getCurrentToken(); + if (/* Token::PUNCTUATION_TYPE */ 9 == $token->getType()) { + if ('.' == $token->getValue() || '[' == $token->getValue()) { + $node = $this->parseSubscriptExpression($node); + } elseif ('|' == $token->getValue()) { + $node = $this->parseFilterExpression($node); + } else { + break; + } + } else { + break; + } + } + + return $node; + } + + public function getFunctionNode($name, $line) + { + switch ($name) { + case 'parent': + $this->parseArguments(); + if (!\count($this->parser->getBlockStack())) { + throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + } + + if (!$this->parser->getParent() && !$this->parser->hasTraits()) { + throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + } + + return new ParentExpression($this->parser->peekBlockStack(), $line); + case 'block': + $args = $this->parseArguments(); + if (\count($args) < 1) { + throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); + } + + return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); + case 'attribute': + $args = $this->parseArguments(); + if (\count($args) < 2) { + throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); + } + + return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line); + default: + if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { + $arguments = new ArrayExpression([], $line); + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + + $node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line); + $node->setAttribute('safe', true); + + return $node; + } + + $args = $this->parseArguments(true); + $class = $this->getFunctionNodeClass($name, $line); + + return new $class($name, $args, $line); + } + } + + public function parseSubscriptExpression($node) + { + $stream = $this->parser->getStream(); + $token = $stream->next(); + $lineno = $token->getLine(); + $arguments = new ArrayExpression([], $lineno); + $type = Template::ANY_CALL; + if ('.' == $token->getValue()) { + $token = $stream->next(); + if ( + /* Token::NAME_TYPE */ 5 == $token->getType() + || + /* Token::NUMBER_TYPE */ 6 == $token->getType() + || + (/* Token::OPERATOR_TYPE */ 8 == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue())) + ) { + $arg = new ConstantExpression($token->getValue(), $lineno); + + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $type = Template::METHOD_CALL; + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + } + } else { + throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext()); + } + + if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { + if (!$arg instanceof ConstantExpression) { + throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); + } + + $name = $arg->getAttribute('value'); + + $node = new MethodCallExpression($node, 'macro_'.$name, $arguments, $lineno); + $node->setAttribute('safe', true); + + return $node; + } + } else { + $type = Template::ARRAY_CALL; + + // slice? + $slice = false; + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $slice = true; + $arg = new ConstantExpression(0, $token->getLine()); + } else { + $arg = $this->parseExpression(); + } + + if ($stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $slice = true; + } + + if ($slice) { + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) { + $length = new ConstantExpression(null, $token->getLine()); + } else { + $length = $this->parseExpression(); + } + + $class = $this->getFilterNodeClass('slice', $token->getLine()); + $arguments = new Node([$arg, $length]); + $filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine()); + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']'); + + return $filter; + } + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']'); + } + + return new GetAttrExpression($node, $arg, $arguments, $type, $lineno); + } + + public function parseFilterExpression($node) + { + $this->parser->getStream()->next(); + + return $this->parseFilterExpressionRaw($node); + } + + public function parseFilterExpressionRaw($node, $tag = null) + { + while (true) { + $token = $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5); + + $name = new ConstantExpression($token->getValue(), $token->getLine()); + if (!$this->parser->getStream()->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $arguments = new Node(); + } else { + $arguments = $this->parseArguments(true, false, true); + } + + $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine()); + + $node = new $class($node, $name, $arguments, $token->getLine(), $tag); + + if (!$this->parser->getStream()->test(/* Token::PUNCTUATION_TYPE */ 9, '|')) { + break; + } + + $this->parser->getStream()->next(); + } + + return $node; + } + + /** + * Parses arguments. + * + * @param bool $namedArguments Whether to allow named arguments or not + * @param bool $definition Whether we are parsing arguments for a function definition + * + * @return Node + * + * @throws SyntaxError + */ + public function parseArguments($namedArguments = false, $definition = false, $allowArrow = false) + { + $args = []; + $stream = $this->parser->getStream(); + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '(', 'A list of arguments must begin with an opening parenthesis'); + while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, ')')) { + if (!empty($args)) { + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'Arguments must be separated by a comma'); + } + + if ($definition) { + $token = $stream->expect(/* Token::NAME_TYPE */ 5, null, 'An argument must be a name'); + $value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine()); + } else { + $value = $this->parseExpression(0, $allowArrow); + } + + $name = null; + if ($namedArguments && $token = $stream->nextIf(/* Token::OPERATOR_TYPE */ 8, '=')) { + if (!$value instanceof NameExpression) { + throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); + } + $name = $value->getAttribute('name'); + + if ($definition) { + $value = $this->parsePrimaryExpression(); + + if (!$this->checkConstantExpression($value)) { + 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()); + } + } else { + $value = $this->parseExpression(0, $allowArrow); + } + } + + if ($definition) { + if (null === $name) { + $name = $value->getAttribute('name'); + $value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine()); + } + $args[$name] = $value; + } else { + if (null === $name) { + $args[] = $value; + } else { + $args[$name] = $value; + } + } + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ')', 'A list of arguments must be closed by a parenthesis'); + + return new Node($args); + } + + public function parseAssignmentExpression() + { + $stream = $this->parser->getStream(); + $targets = []; + while (true) { + $token = $this->parser->getCurrentToken(); + if ($stream->test(/* Token::OPERATOR_TYPE */ 8) && preg_match(Lexer::REGEX_NAME, $token->getValue())) { + // in this context, string operators are variable names + $this->parser->getStream()->next(); + } else { + $stream->expect(/* Token::NAME_TYPE */ 5, null, 'Only variables can be assigned to'); + } + $value = $token->getValue(); + if (\in_array(strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), ['true', 'false', 'none', 'null'])) { + throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); + } + $targets[] = new AssignNameExpression($value, $token->getLine()); + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } + + return new Node($targets); + } + + public function parseMultitargetExpression() + { + $targets = []; + while (true) { + $targets[] = $this->parseExpression(); + if (!$this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } + + return new Node($targets); + } + + private function parseNotTestExpression(Node $node): NotUnary + { + return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); + } + + private function parseTestExpression(Node $node): TestExpression + { + $stream = $this->parser->getStream(); + list($name, $test) = $this->getTest($node->getTemplateLine()); + + $class = $this->getTestNodeClass($test); + $arguments = null; + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $arguments = $this->parseArguments(true); + } + + if ('defined' === $name && $node instanceof NameExpression && null !== $alias = $this->parser->getImportedSymbol('function', $node->getAttribute('name'))) { + $node = new MethodCallExpression($alias['node'], $alias['name'], new ArrayExpression([], $node->getTemplateLine()), $node->getTemplateLine()); + $node->setAttribute('safe', true); + } + + return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine()); + } + + private function getTest(int $line): array + { + $stream = $this->parser->getStream(); + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + if ($test = $this->env->getTest($name)) { + return [$name, $test]; + } + + if ($stream->test(/* Token::NAME_TYPE */ 5)) { + // try 2-words tests + $name = $name.' '.$this->parser->getCurrentToken()->getValue(); + + if ($test = $this->env->getTest($name)) { + $stream->next(); + + return [$name, $test]; + } + } + + $e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getTests())); + + throw $e; + } + + private function getTestNodeClass(TwigTest $test): string + { + if ($test->isDeprecated()) { + $stream = $this->parser->getStream(); + $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); + + if (!\is_bool($test->getDeprecatedVersion())) { + $message .= sprintf(' since version %s', $test->getDeprecatedVersion()); + } + if ($test->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $test->getAlternative()); + } + $src = $stream->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $stream->getCurrent()->getLine()); + + @trigger_error($message, E_USER_DEPRECATED); + } + + return $test->getNodeClass(); + } + + private function getFunctionNodeClass(string $name, int $line): string + { + if (false === $function = $this->env->getFunction($name)) { + $e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getFunctions())); + + throw $e; + } + + if ($function->isDeprecated()) { + $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); + if (!\is_bool($function->getDeprecatedVersion())) { + $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); + } + if ($function->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $function->getAlternative()); + } + $src = $this->parser->getStream()->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + + return $function->getNodeClass(); + } + + private function getFilterNodeClass(string $name, int $line): string + { + if (false === $filter = $this->env->getFilter($name)) { + $e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getFilters())); + + throw $e; + } + + if ($filter->isDeprecated()) { + $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); + if (!\is_bool($filter->getDeprecatedVersion())) { + $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); + } + if ($filter->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); + } + $src = $this->parser->getStream()->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + + return $filter->getNodeClass(); + } + + // checks that the node only contains "constant" elements + private function checkConstantExpression(Node $node): bool + { + if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression + || $node instanceof NegUnary || $node instanceof PosUnary + )) { + return false; + } + + foreach ($node as $n) { + if (!$this->checkConstantExpression($n)) { + return false; + } + } + + return true; + } +} + +class_alias('Twig\ExpressionParser', 'Twig_ExpressionParser'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/AbstractExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/AbstractExtension.php new file mode 100644 index 0000000..0c012b3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/AbstractExtension.php @@ -0,0 +1,47 @@ +escapers[$strategy] = $callable; + } + + /** + * Gets all defined escapers. + * + * @return callable[] An array of escapers + * + * @deprecated since Twig 2.11, to be removed in 3.0; use the same method on EscaperExtension instead + */ + public function getEscapers(/* $triggerDeprecation = true */) + { + if (0 === \func_num_args() || func_get_arg(0)) { + @trigger_error(sprintf('The "%s" method is deprecated since Twig 2.11; use "%s::getEscapers" instead.', __METHOD__, EscaperExtension::class), E_USER_DEPRECATED); + } + + return $this->escapers; + } + + /** + * Sets the default format to be used by the date filter. + * + * @param string $format The default date format string + * @param string $dateIntervalFormat The default date interval format string + */ + public function setDateFormat($format = null, $dateIntervalFormat = null) + { + if (null !== $format) { + $this->dateFormats[0] = $format; + } + + if (null !== $dateIntervalFormat) { + $this->dateFormats[1] = $dateIntervalFormat; + } + } + + /** + * Gets the default format to be used by the date filter. + * + * @return array The default date format string and the default date interval format string + */ + public function getDateFormat() + { + return $this->dateFormats; + } + + /** + * Sets the default timezone to be used by the date filter. + * + * @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object + */ + public function setTimezone($timezone) + { + $this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone); + } + + /** + * Gets the default timezone to be used by the date filter. + * + * @return \DateTimeZone The default timezone currently in use + */ + public function getTimezone() + { + if (null === $this->timezone) { + $this->timezone = new \DateTimeZone(date_default_timezone_get()); + } + + return $this->timezone; + } + + /** + * Sets the default format to be used by the number_format filter. + * + * @param int $decimal the number of decimal places to use + * @param string $decimalPoint the character(s) to use for the decimal point + * @param string $thousandSep the character(s) to use for the thousands separator + */ + public function setNumberFormat($decimal, $decimalPoint, $thousandSep) + { + $this->numberFormat = [$decimal, $decimalPoint, $thousandSep]; + } + + /** + * Get the default format used by the number_format filter. + * + * @return array The arguments for number_format() + */ + public function getNumberFormat() + { + return $this->numberFormat; + } + + public function getTokenParsers() + { + return [ + new ApplyTokenParser(), + new ForTokenParser(), + new IfTokenParser(), + new ExtendsTokenParser(), + new IncludeTokenParser(), + new BlockTokenParser(), + new UseTokenParser(), + new FilterTokenParser(), + new MacroTokenParser(), + new ImportTokenParser(), + new FromTokenParser(), + new SetTokenParser(), + new SpacelessTokenParser(), + new FlushTokenParser(), + new DoTokenParser(), + new EmbedTokenParser(), + new WithTokenParser(), + new DeprecatedTokenParser(), + ]; + } + + public function getFilters() + { + return [ + // formatting filters + new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), + new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), + new TwigFilter('format', 'sprintf'), + new TwigFilter('replace', 'twig_replace_filter'), + new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), + new TwigFilter('abs', 'abs'), + new TwigFilter('round', 'twig_round'), + + // encoding + new TwigFilter('url_encode', 'twig_urlencode_filter'), + new TwigFilter('json_encode', 'json_encode'), + new TwigFilter('convert_encoding', 'twig_convert_encoding'), + + // string filters + new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), + new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), + new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]), + new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]), + new TwigFilter('striptags', 'strip_tags'), + new TwigFilter('trim', 'twig_trim_filter'), + new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), + new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]), + + // array helpers + new TwigFilter('join', 'twig_join_filter'), + new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]), + new TwigFilter('sort', 'twig_sort_filter'), + new TwigFilter('merge', 'twig_array_merge'), + new TwigFilter('batch', 'twig_array_batch'), + new TwigFilter('column', 'twig_array_column'), + new TwigFilter('filter', 'twig_array_filter'), + new TwigFilter('map', 'twig_array_map'), + new TwigFilter('reduce', 'twig_array_reduce'), + + // string/array filters + new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), + new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]), + new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]), + new TwigFilter('first', 'twig_first', ['needs_environment' => true]), + new TwigFilter('last', 'twig_last', ['needs_environment' => true]), + + // iteration and runtime + new TwigFilter('default', '_twig_default_filter', ['node_class' => DefaultFilter::class]), + new TwigFilter('keys', 'twig_get_array_keys_filter'), + ]; + } + + public function getFunctions() + { + return [ + new TwigFunction('max', 'max'), + new TwigFunction('min', 'min'), + new TwigFunction('range', 'range'), + new TwigFunction('constant', 'twig_constant'), + new TwigFunction('cycle', 'twig_cycle'), + new TwigFunction('random', 'twig_random', ['needs_environment' => true]), + new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]), + new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), + new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), + ]; + } + + public function getTests() + { + return [ + new TwigTest('even', null, ['node_class' => EvenTest::class]), + new TwigTest('odd', null, ['node_class' => OddTest::class]), + new TwigTest('defined', null, ['node_class' => DefinedTest::class]), + new TwigTest('same as', null, ['node_class' => SameasTest::class]), + new TwigTest('none', null, ['node_class' => NullTest::class]), + new TwigTest('null', null, ['node_class' => NullTest::class]), + new TwigTest('divisible by', null, ['node_class' => DivisiblebyTest::class]), + new TwigTest('constant', null, ['node_class' => ConstantTest::class]), + new TwigTest('empty', 'twig_test_empty'), + new TwigTest('iterable', 'twig_test_iterable'), + ]; + } + + public function getNodeVisitors() + { + return [new MacroAutoImportNodeVisitor()]; + } + + public function getOperators() + { + return [ + [ + 'not' => ['precedence' => 50, 'class' => NotUnary::class], + '-' => ['precedence' => 500, 'class' => NegUnary::class], + '+' => ['precedence' => 500, 'class' => PosUnary::class], + ], + [ + 'or' => ['precedence' => 10, 'class' => OrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'and' => ['precedence' => 15, 'class' => AndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-or' => ['precedence' => 16, 'class' => BitwiseOrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-xor' => ['precedence' => 17, 'class' => BitwiseXorBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-and' => ['precedence' => 18, 'class' => BitwiseAndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '==' => ['precedence' => 20, 'class' => EqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '!=' => ['precedence' => 20, 'class' => NotEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<=>' => ['precedence' => 20, 'class' => SpaceshipBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<' => ['precedence' => 20, 'class' => LessBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>' => ['precedence' => 20, 'class' => GreaterBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>=' => ['precedence' => 20, 'class' => GreaterEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<=' => ['precedence' => 20, 'class' => LessEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'not in' => ['precedence' => 20, 'class' => NotInBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'in' => ['precedence' => 20, 'class' => InBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'matches' => ['precedence' => 20, 'class' => MatchesBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'starts with' => ['precedence' => 20, 'class' => StartsWithBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'ends with' => ['precedence' => 20, 'class' => EndsWithBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '..' => ['precedence' => 25, 'class' => RangeBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '+' => ['precedence' => 30, 'class' => AddBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '-' => ['precedence' => 30, 'class' => SubBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '~' => ['precedence' => 40, 'class' => ConcatBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '*' => ['precedence' => 60, 'class' => MulBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '/' => ['precedence' => 60, 'class' => DivBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '//' => ['precedence' => 60, 'class' => FloorDivBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '%' => ['precedence' => 60, 'class' => ModBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '**' => ['precedence' => 200, 'class' => PowerBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], + '??' => ['precedence' => 300, 'class' => NullCoalesceExpression::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], + ], + ]; + } +} + +class_alias('Twig\Extension\CoreExtension', 'Twig_Extension_Core'); +} + +namespace { + use Twig\Environment; + use Twig\Error\LoaderError; + use Twig\Error\RuntimeError; + use Twig\Extension\CoreExtension; + use Twig\Extension\SandboxExtension; + use Twig\Markup; + use Twig\Source; + use Twig\Template; + + /** + * Cycles over a value. + * + * @param \ArrayAccess|array $values + * @param int $position The cycle position + * + * @return string The next value in the cycle + */ +function twig_cycle($values, $position) +{ + if (!\is_array($values) && !$values instanceof \ArrayAccess) { + return $values; + } + + return $values[$position % \count($values)]; +} + +/** + * Returns a random value depending on the supplied parameter type: + * - a random item from a \Traversable or array + * - a random character from a string + * - a random integer between 0 and the integer parameter. + * + * @param \Traversable|array|int|float|string $values The values to pick a random item from + * @param int|null $max Maximum value used when $values is an int + * + * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) + * + * @return mixed A random value from the given sequence + */ +function twig_random(Environment $env, $values = null, $max = null) +{ + if (null === $values) { + return null === $max ? mt_rand() : mt_rand(0, $max); + } + + if (\is_int($values) || \is_float($values)) { + if (null === $max) { + if ($values < 0) { + $max = 0; + $min = $values; + } else { + $max = $values; + $min = 0; + } + } else { + $min = $values; + $max = $max; + } + + return mt_rand($min, $max); + } + + if (\is_string($values)) { + if ('' === $values) { + return ''; + } + + $charset = $env->getCharset(); + + if ('UTF-8' !== $charset) { + $values = twig_convert_encoding($values, 'UTF-8', $charset); + } + + // unicode version of str_split() + // split at all positions, but not after the start and not before the end + $values = preg_split('/(? $value) { + $values[$i] = twig_convert_encoding($value, $charset, 'UTF-8'); + } + } + } + + if (!twig_test_iterable($values)) { + return $values; + } + + $values = twig_to_array($values); + + if (0 === \count($values)) { + throw new RuntimeError('The random function cannot pick from an empty array.'); + } + + return $values[array_rand($values, 1)]; +} + +/** + * Converts a date to the given format. + * + * {{ post.published_at|date("m/d/Y") }} + * + * @param \DateTimeInterface|\DateInterval|string $date A date + * @param string|null $format The target format, null to use the default + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * + * @return string The formatted date + */ +function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null) +{ + if (null === $format) { + $formats = $env->getExtension(CoreExtension::class)->getDateFormat(); + $format = $date instanceof \DateInterval ? $formats[1] : $formats[0]; + } + + if ($date instanceof \DateInterval) { + return $date->format($format); + } + + return twig_date_converter($env, $date, $timezone)->format($format); +} + +/** + * Returns a new date object modified. + * + * {{ post.published_at|date_modify("-1day")|date("m/d/Y") }} + * + * @param \DateTimeInterface|string $date A date + * @param string $modifier A modifier string + * + * @return \DateTimeInterface + */ +function twig_date_modify_filter(Environment $env, $date, $modifier) +{ + $date = twig_date_converter($env, $date, false); + + return $date->modify($modifier); +} + +/** + * Converts an input to a \DateTime instance. + * + * {% if date(user.created_at) < date('+2days') %} + * {# do something #} + * {% endif %} + * + * @param \DateTimeInterface|string|null $date A date or null to use the current time + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * + * @return \DateTimeInterface + */ +function twig_date_converter(Environment $env, $date = null, $timezone = null) +{ + // determine the timezone + if (false !== $timezone) { + if (null === $timezone) { + $timezone = $env->getExtension(CoreExtension::class)->getTimezone(); + } elseif (!$timezone instanceof \DateTimeZone) { + $timezone = new \DateTimeZone($timezone); + } + } + + // immutable dates + if ($date instanceof \DateTimeImmutable) { + return false !== $timezone ? $date->setTimezone($timezone) : $date; + } + + if ($date instanceof \DateTimeInterface) { + $date = clone $date; + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; + } + + if (null === $date || 'now' === $date) { + return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension(CoreExtension::class)->getTimezone()); + } + + $asString = (string) $date; + if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { + $date = new \DateTime('@'.$date); + } else { + $date = new \DateTime($date, $env->getExtension(CoreExtension::class)->getTimezone()); + } + + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; +} + +/** + * Replaces strings within a string. + * + * @param string $str String to replace in + * @param array|\Traversable $from Replace values + * + * @return string + */ +function twig_replace_filter($str, $from) +{ + if (!twig_test_iterable($from)) { + 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))); + } + + return strtr($str, twig_to_array($from)); +} + +/** + * Rounds a number. + * + * @param int|float $value The value to round + * @param int|float $precision The rounding precision + * @param string $method The method to use for rounding + * + * @return int|float The rounded number + */ +function twig_round($value, $precision = 0, $method = 'common') +{ + if ('common' == $method) { + return round($value, $precision); + } + + if ('ceil' != $method && 'floor' != $method) { + throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); + } + + return $method($value * pow(10, $precision)) / pow(10, $precision); +} + +/** + * Number format filter. + * + * All of the formatting options can be left null, in that case the defaults will + * be used. Supplying any of the parameters will override the defaults set in the + * environment object. + * + * @param mixed $number A float/int/string of the number to format + * @param int $decimal the number of decimal points to display + * @param string $decimalPoint the character(s) to use for the decimal point + * @param string $thousandSep the character(s) to use for the thousands separator + * + * @return string The formatted number + */ +function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) +{ + $defaults = $env->getExtension(CoreExtension::class)->getNumberFormat(); + if (null === $decimal) { + $decimal = $defaults[0]; + } + + if (null === $decimalPoint) { + $decimalPoint = $defaults[1]; + } + + if (null === $thousandSep) { + $thousandSep = $defaults[2]; + } + + return number_format((float) $number, $decimal, $decimalPoint, $thousandSep); +} + +/** + * URL encodes (RFC 3986) a string as a path segment or an array as a query string. + * + * @param string|array $url A URL or an array of query parameters + * + * @return string The URL encoded value + */ +function twig_urlencode_filter($url) +{ + if (\is_array($url)) { + return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + } + + return rawurlencode($url); +} + +/** + * Merges an array with another one. + * + * {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %} + * + * {% set items = items|merge({ 'peugeot': 'car' }) %} + * + * {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #} + * + * @param array|\Traversable $arr1 An array + * @param array|\Traversable $arr2 An array + * + * @return array The merged array + */ +function twig_array_merge($arr1, $arr2) +{ + if (!twig_test_iterable($arr1)) { + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); + } + + if (!twig_test_iterable($arr2)) { + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); + } + + return array_merge(twig_to_array($arr1), twig_to_array($arr2)); +} + +/** + * Slices a variable. + * + * @param mixed $item A variable + * @param int $start Start of the slice + * @param int $length Size of the slice + * @param bool $preserveKeys Whether to preserve key or not (when the input is an array) + * + * @return mixed The sliced variable + */ +function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false) +{ + if ($item instanceof \Traversable) { + while ($item instanceof \IteratorAggregate) { + $item = $item->getIterator(); + } + + if ($start >= 0 && $length >= 0 && $item instanceof \Iterator) { + try { + return iterator_to_array(new \LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys); + } catch (\OutOfBoundsException $e) { + return []; + } + } + + $item = iterator_to_array($item, $preserveKeys); + } + + if (\is_array($item)) { + return \array_slice($item, $start, $length, $preserveKeys); + } + + $item = (string) $item; + + return (string) mb_substr($item, $start, $length, $env->getCharset()); +} + +/** + * Returns the first element of the item. + * + * @param mixed $item A variable + * + * @return mixed The first element of the item + */ +function twig_first(Environment $env, $item) +{ + $elements = twig_slice($env, $item, 0, 1, false); + + return \is_string($elements) ? $elements : current($elements); +} + +/** + * Returns the last element of the item. + * + * @param mixed $item A variable + * + * @return mixed The last element of the item + */ +function twig_last(Environment $env, $item) +{ + $elements = twig_slice($env, $item, -1, 1, false); + + return \is_string($elements) ? $elements : current($elements); +} + +/** + * Joins the values to a string. + * + * The separators between elements are empty strings per default, you can define them with the optional parameters. + * + * {{ [1, 2, 3]|join(', ', ' and ') }} + * {# returns 1, 2 and 3 #} + * + * {{ [1, 2, 3]|join('|') }} + * {# returns 1|2|3 #} + * + * {{ [1, 2, 3]|join }} + * {# returns 123 #} + * + * @param array $value An array + * @param string $glue The separator + * @param string|null $and The separator for the last pair + * + * @return string The concatenated string + */ +function twig_join_filter($value, $glue = '', $and = null) +{ + if (!twig_test_iterable($value)) { + $value = (array) $value; + } + + $value = twig_to_array($value, false); + + if (0 === \count($value)) { + return ''; + } + + if (null === $and || $and === $glue) { + return implode($glue, $value); + } + + if (1 === \count($value)) { + return $value[0]; + } + + return implode($glue, \array_slice($value, 0, -1)).$and.$value[\count($value) - 1]; +} + +/** + * Splits the string into an array. + * + * {{ "one,two,three"|split(',') }} + * {# returns [one, two, three] #} + * + * {{ "one,two,three,four,five"|split(',', 3) }} + * {# returns [one, two, "three,four,five"] #} + * + * {{ "123"|split('') }} + * {# returns [1, 2, 3] #} + * + * {{ "aabbcc"|split('', 2) }} + * {# returns [aa, bb, cc] #} + * + * @param string $value A string + * @param string $delimiter The delimiter + * @param int $limit The limit + * + * @return array The split string as an array + */ +function twig_split_filter(Environment $env, $value, $delimiter, $limit = null) +{ + if (\strlen($delimiter) > 0) { + return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); + } + + if ($limit <= 1) { + return preg_split('/(?getCharset()); + if ($length < $limit) { + return [$value]; + } + + $r = []; + for ($i = 0; $i < $length; $i += $limit) { + $r[] = mb_substr($value, $i, $limit, $env->getCharset()); + } + + return $r; +} + +// The '_default' filter is used internally to avoid using the ternary operator +// which costs a lot for big contexts (before PHP 5.4). So, on average, +// a function call is cheaper. +/** + * @internal + */ +function _twig_default_filter($value, $default = '') +{ + if (twig_test_empty($value)) { + return $default; + } + + return $value; +} + +/** + * Returns the keys for the given array. + * + * It is useful when you want to iterate over the keys of an array: + * + * {% for key in array|keys %} + * {# ... #} + * {% endfor %} + * + * @param array $array An array + * + * @return array The keys + */ +function twig_get_array_keys_filter($array) +{ + if ($array instanceof \Traversable) { + while ($array instanceof \IteratorAggregate) { + $array = $array->getIterator(); + } + + if ($array instanceof \Iterator) { + $keys = []; + $array->rewind(); + while ($array->valid()) { + $keys[] = $array->key(); + $array->next(); + } + + return $keys; + } + + $keys = []; + foreach ($array as $key => $item) { + $keys[] = $key; + } + + return $keys; + } + + if (!\is_array($array)) { + return []; + } + + return array_keys($array); +} + +/** + * Reverses a variable. + * + * @param array|\Traversable|string $item An array, a \Traversable instance, or a string + * @param bool $preserveKeys Whether to preserve key or not + * + * @return mixed The reversed input + */ +function twig_reverse_filter(Environment $env, $item, $preserveKeys = false) +{ + if ($item instanceof \Traversable) { + return array_reverse(iterator_to_array($item), $preserveKeys); + } + + if (\is_array($item)) { + return array_reverse($item, $preserveKeys); + } + + $string = (string) $item; + + $charset = $env->getCharset(); + + if ('UTF-8' !== $charset) { + $item = twig_convert_encoding($string, 'UTF-8', $charset); + } + + preg_match_all('/./us', $item, $matches); + + $string = implode('', array_reverse($matches[0])); + + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, $charset, 'UTF-8'); + } + + return $string; +} + +/** + * Sorts an array. + * + * @param array|\Traversable $array + * + * @return array + */ +function twig_sort_filter($array, $arrow = null) +{ + if ($array instanceof \Traversable) { + $array = iterator_to_array($array); + } elseif (!\is_array($array)) { + throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); + } + + if (null !== $arrow) { + uasort($array, $arrow); + } else { + asort($array); + } + + return $array; +} + +/** + * @internal + */ +function twig_in_filter($value, $compare) +{ + if ($value instanceof Markup) { + $value = (string) $value; + } + if ($compare instanceof Markup) { + $compare = (string) $compare; + } + + if (\is_array($compare)) { + return \in_array($value, $compare, \is_object($value) || \is_resource($value)); + } elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) { + return '' === $value || false !== strpos($compare, (string) $value); + } elseif ($compare instanceof \Traversable) { + if (\is_object($value) || \is_resource($value)) { + foreach ($compare as $item) { + if ($item === $value) { + return true; + } + } + } else { + foreach ($compare as $item) { + if ($item == $value) { + return true; + } + } + } + + return false; + } + + return false; +} + +/** + * Returns a trimmed string. + * + * @return string + * + * @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') + */ +function twig_trim_filter($string, $characterMask = null, $side = 'both') +{ + if (null === $characterMask) { + $characterMask = " \t\n\r\0\x0B"; + } + + switch ($side) { + case 'both': + return trim($string, $characterMask); + case 'left': + return ltrim($string, $characterMask); + case 'right': + return rtrim($string, $characterMask); + default: + throw new RuntimeError('Trimming side must be "left", "right" or "both".'); + } +} + +/** + * Removes whitespaces between HTML tags. + * + * @return string + */ +function twig_spaceless($content) +{ + return trim(preg_replace('/>\s+<', $content)); +} + +function twig_convert_encoding($string, $to, $from) +{ + if (!function_exists('iconv')) { + throw new RuntimeError('Unable to convert encoding: required function iconv() does not exist. You should install ext-iconv or symfony/polyfill-iconv.'); + } + + return iconv($from, $to, $string); +} + +/** + * Returns the length of a variable. + * + * @param mixed $thing A variable + * + * @return int The length of the value + */ +function twig_length_filter(Environment $env, $thing) +{ + if (null === $thing) { + return 0; + } + + if (is_scalar($thing)) { + return mb_strlen($thing, $env->getCharset()); + } + + if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) { + return \count($thing); + } + + if ($thing instanceof \Traversable) { + return iterator_count($thing); + } + + if (method_exists($thing, '__toString') && !$thing instanceof \Countable) { + return mb_strlen((string) $thing, $env->getCharset()); + } + + return 1; +} + +/** + * Converts a string to uppercase. + * + * @param string $string A string + * + * @return string The uppercased string + */ +function twig_upper_filter(Environment $env, $string) +{ + return mb_strtoupper($string, $env->getCharset()); +} + +/** + * Converts a string to lowercase. + * + * @param string $string A string + * + * @return string The lowercased string + */ +function twig_lower_filter(Environment $env, $string) +{ + return mb_strtolower($string, $env->getCharset()); +} + +/** + * Returns a titlecased string. + * + * @param string $string A string + * + * @return string The titlecased string + */ +function twig_title_string_filter(Environment $env, $string) +{ + if (null !== $charset = $env->getCharset()) { + return mb_convert_case($string, MB_CASE_TITLE, $charset); + } + + return ucwords(strtolower($string)); +} + +/** + * Returns a capitalized string. + * + * @param string $string A string + * + * @return string The capitalized string + */ +function twig_capitalize_string_filter(Environment $env, $string) +{ + $charset = $env->getCharset(); + + return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, null, $charset), $charset); +} + +/** + * @internal + */ +function twig_call_macro(Template $template, string $method, array $args, int $lineno, array $context, Source $source) +{ + if (!method_exists($template, $method)) { + $parent = $template; + while ($parent = $parent->getParent($context)) { + if (method_exists($parent, $method)) { + return $parent->$method(...$args); + } + } + + throw new RuntimeError(sprintf('Macro "%s" is not defined in template "%s".', substr($method, \strlen('macro_')), $template->getTemplateName()), $lineno, $source); + } + + return $template->$method(...$args); +} + +/** + * @internal + */ +function twig_ensure_traversable($seq) +{ + if ($seq instanceof \Traversable || \is_array($seq)) { + return $seq; + } + + return []; +} + +/** + * @internal + */ +function twig_to_array($seq, $preserveKeys = true) +{ + if ($seq instanceof \Traversable) { + return iterator_to_array($seq, $preserveKeys); + } + + if (!\is_array($seq)) { + return $seq; + } + + return $preserveKeys ? $seq : array_values($seq); +} + +/** + * Checks if a variable is empty. + * + * {# evaluates to true if the foo variable is null, false, or the empty string #} + * {% if foo is empty %} + * {# ... #} + * {% endif %} + * + * @param mixed $value A variable + * + * @return bool true if the value is empty, false otherwise + */ +function twig_test_empty($value) +{ + if ($value instanceof \Countable) { + return 0 == \count($value); + } + + if ($value instanceof \Traversable) { + return !iterator_count($value); + } + + if (\is_object($value) && method_exists($value, '__toString')) { + return '' === (string) $value; + } + + return '' === $value || false === $value || null === $value || [] === $value; +} + +/** + * Checks if a variable is traversable. + * + * {# evaluates to true if the foo variable is an array or a traversable object #} + * {% if foo is iterable %} + * {# ... #} + * {% endif %} + * + * @param mixed $value A variable + * + * @return bool true if the value is traversable + */ +function twig_test_iterable($value) +{ + return $value instanceof \Traversable || \is_array($value); +} + +/** + * Renders a template. + * + * @param array $context + * @param string|array $template The template to render or an array of templates to try consecutively + * @param array $variables The variables to pass to the template + * @param bool $withContext + * @param bool $ignoreMissing Whether to ignore missing templates or not + * @param bool $sandboxed Whether to sandbox the template or not + * + * @return string The rendered template + */ +function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) +{ + $alreadySandboxed = false; + $sandbox = null; + if ($withContext) { + $variables = array_merge($context, $variables); + } + + if ($isSandboxed = $sandboxed && $env->hasExtension(SandboxExtension::class)) { + $sandbox = $env->getExtension(SandboxExtension::class); + if (!$alreadySandboxed = $sandbox->isSandboxed()) { + $sandbox->enableSandbox(); + } + } + + try { + $loaded = null; + try { + $loaded = $env->resolveTemplate($template); + } catch (LoaderError $e) { + if (!$ignoreMissing) { + throw $e; + } + } + + return $loaded ? $loaded->render($variables) : ''; + } finally { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + } +} + +/** + * Returns a template content without rendering it. + * + * @param string $name The template name + * @param bool $ignoreMissing Whether to ignore missing templates or not + * + * @return string The template source + */ +function twig_source(Environment $env, $name, $ignoreMissing = false) +{ + $loader = $env->getLoader(); + try { + return $loader->getSourceContext($name)->getCode(); + } catch (LoaderError $e) { + if (!$ignoreMissing) { + throw $e; + } + } +} + +/** + * Provides the ability to get constants from instances as well as class/global constants. + * + * @param string $constant The name of the constant + * @param object|null $object The object to get the constant from + * + * @return string + */ +function twig_constant($constant, $object = null) +{ + if (null !== $object) { + $constant = \get_class($object).'::'.$constant; + } + + return \constant($constant); +} + +/** + * Checks if a constant exists. + * + * @param string $constant The name of the constant + * @param object|null $object The object to get the constant from + * + * @return bool + */ +function twig_constant_is_defined($constant, $object = null) +{ + if (null !== $object) { + $constant = \get_class($object).'::'.$constant; + } + + return \defined($constant); +} + +/** + * Batches item. + * + * @param array $items An array of items + * @param int $size The size of the batch + * @param mixed $fill A value used to fill missing items + * + * @return array + */ +function twig_array_batch($items, $size, $fill = null, $preserveKeys = true) +{ + if (!twig_test_iterable($items)) { + throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); + } + + $size = ceil($size); + + $result = array_chunk(twig_to_array($items, $preserveKeys), $size, $preserveKeys); + + if (null !== $fill && $result) { + $last = \count($result) - 1; + if ($fillCount = $size - \count($result[$last])) { + for ($i = 0; $i < $fillCount; ++$i) { + $result[$last][] = $fill; + } + } + } + + return $result; +} + +/** + * Returns the attribute value for a given array/object. + * + * @param mixed $object The object or array from where to get the item + * @param mixed $item The item to get from the array or object + * @param array $arguments An array of arguments to pass if the item is an object method + * @param string $type The type of attribute (@see \Twig\Template constants) + * @param bool $isDefinedTest Whether this is only a defined check + * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not + * @param int $lineno The template line where the attribute was called + * + * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true + * + * @throws RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false + * + * @internal + */ +function twig_get_attribute(Environment $env, Source $source, $object, $item, array $arguments = [], $type = /* Template::ANY_CALL */ 'any', $isDefinedTest = false, $ignoreStrictCheck = false, $sandboxed = false, int $lineno = -1) +{ + // array + if (/* Template::METHOD_CALL */ 'method' !== $type) { + $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; + + if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object))) + || ($object instanceof ArrayAccess && isset($object[$arrayItem])) + ) { + if ($isDefinedTest) { + return true; + } + + return $object[$arrayItem]; + } + + if (/* Template::ARRAY_CALL */ 'array' === $type || !\is_object($object)) { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$env->isStrictVariables()) { + return; + } + + if ($object instanceof ArrayAccess) { + $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object)); + } elseif (\is_object($object)) { + $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object)); + } elseif (\is_array($object)) { + if (empty($object)) { + $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); + } else { + $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object))); + } + } elseif (/* Template::ARRAY_CALL */ 'array' === $type) { + if (null === $object) { + $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); + } else { + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + } elseif (null === $object) { + $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); + } else { + $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + + throw new RuntimeError($message, $lineno, $source); + } + } + + if (!\is_object($object)) { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$env->isStrictVariables()) { + return; + } + + if (null === $object) { + $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); + } elseif (\is_array($object)) { + $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); + } else { + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + + throw new RuntimeError($message, $lineno, $source); + } + + if ($object instanceof Template) { + throw new RuntimeError('Accessing \Twig\Template attributes is forbidden.', $lineno, $source); + } + + // object property + if (/* Template::METHOD_CALL */ 'method' !== $type) { + if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) { + if ($isDefinedTest) { + return true; + } + + if ($sandboxed) { + $env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $item, $lineno, $source); + } + + return $object->$item; + } + } + + static $cache = []; + + $class = \get_class($object); + + // object method + // precedence: getXxx() > isXxx() > hasXxx() + if (!isset($cache[$class])) { + $methods = get_class_methods($object); + sort($methods); + $lcMethods = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, $methods); + $classCache = []; + foreach ($methods as $i => $method) { + $classCache[$method] = $method; + $classCache[$lcName = $lcMethods[$i]] = $method; + + if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) { + $name = substr($method, 3); + $lcName = substr($lcName, 3); + } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) { + $name = substr($method, 2); + $lcName = substr($lcName, 2); + } elseif ('h' === $lcName[0] && 0 === strpos($lcName, 'has')) { + $name = substr($method, 3); + $lcName = substr($lcName, 3); + if (\in_array('is'.$lcName, $lcMethods)) { + continue; + } + } else { + continue; + } + + // skip get() and is() methods (in which case, $name is empty) + if ($name) { + if (!isset($classCache[$name])) { + $classCache[$name] = $method; + } + + if (!isset($classCache[$lcName])) { + $classCache[$lcName] = $method; + } + } + } + $cache[$class] = $classCache; + } + + $call = false; + if (isset($cache[$class][$item])) { + $method = $cache[$class][$item]; + } elseif (isset($cache[$class][$lcItem = strtr($item, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')])) { + $method = $cache[$class][$lcItem]; + } elseif (isset($cache[$class]['__call'])) { + $method = $item; + $call = true; + } else { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$env->isStrictVariables()) { + return; + } + + throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()"/"has%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), $lineno, $source); + } + + if ($isDefinedTest) { + return true; + } + + if ($sandboxed) { + $env->getExtension(SandboxExtension::class)->checkMethodAllowed($object, $method, $lineno, $source); + } + + // Some objects throw exceptions when they have __call, and the method we try + // to call is not supported. If ignoreStrictCheck is true, we should return null. + try { + $ret = $object->$method(...$arguments); + } catch (\BadMethodCallException $e) { + if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) { + return; + } + throw $e; + } + + return $ret; +} + +/** + * Returns the values from a single column in the input array. + * + *
    + *  {% set items = [{ 'fruit' : 'apple'}, {'fruit' : 'orange' }] %}
    + *
    + *  {% set fruits = items|column('fruit') %}
    + *
    + *  {# fruits now contains ['apple', 'orange'] #}
    + * 
    + * + * @param array|Traversable $array An array + * @param mixed $name The column name + * @param mixed $index The column to use as the index/keys for the returned array + * + * @return array The array of values + */ +function twig_array_column($array, $name, $index = null): array +{ + if ($array instanceof Traversable) { + $array = iterator_to_array($array); + } elseif (!\is_array($array)) { + throw new RuntimeError(sprintf('The column filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($array))); + } + + return array_column($array, $name, $index); +} + +function twig_array_filter($array, $arrow) +{ + if (\is_array($array)) { + return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH); + } + + // the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator + return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow); +} + +function twig_array_map($array, $arrow) +{ + $r = []; + foreach ($array as $k => $v) { + $r[$k] = $arrow($v, $k); + } + + return $r; +} + +function twig_array_reduce($array, $arrow, $initial = null) +{ + if (!\is_array($array)) { + $array = iterator_to_array($array); + } + + return array_reduce($array, $arrow, $initial); +} +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/DebugExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/DebugExtension.php new file mode 100644 index 0000000..2e8510d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/DebugExtension.php @@ -0,0 +1,66 @@ + $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]), + ]; + } +} + +class_alias('Twig\Extension\DebugExtension', 'Twig_Extension_Debug'); +} + +namespace { +use Twig\Environment; +use Twig\Template; +use Twig\TemplateWrapper; + +function twig_var_dump(Environment $env, $context, ...$vars) +{ + if (!$env->isDebug()) { + return; + } + + ob_start(); + + if (!$vars) { + $vars = []; + foreach ($context as $key => $value) { + if (!$value instanceof Template && !$value instanceof TemplateWrapper) { + $vars[$key] = $value; + } + } + + var_dump($vars); + } else { + var_dump(...$vars); + } + + return ob_get_clean(); +} +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/EscaperExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/EscaperExtension.php new file mode 100644 index 0000000..136f75f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/EscaperExtension.php @@ -0,0 +1,427 @@ +setDefaultStrategy($defaultStrategy); + } + + public function getTokenParsers() + { + return [new AutoEscapeTokenParser()]; + } + + public function getNodeVisitors() + { + return [new EscaperNodeVisitor()]; + } + + public function getFilters() + { + return [ + new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), + ]; + } + + /** + * Sets the default strategy to use when not defined by the user. + * + * The strategy can be a valid PHP callback that takes the template + * name as an argument and returns the strategy to use. + * + * @param string|false|callable $defaultStrategy An escaping strategy + */ + public function setDefaultStrategy($defaultStrategy) + { + if ('name' === $defaultStrategy) { + $defaultStrategy = [FileExtensionEscapingStrategy::class, 'guess']; + } + + $this->defaultStrategy = $defaultStrategy; + } + + /** + * Gets the default strategy to use when not defined by the user. + * + * @param string $name The template name + * + * @return string|false The default strategy to use for the template + */ + public function getDefaultStrategy($name) + { + // disable string callables to avoid calling a function named html or js, + // or any other upcoming escaping strategy + if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { + return \call_user_func($this->defaultStrategy, $name); + } + + return $this->defaultStrategy; + } + + /** + * Defines a new escaper to be used via the escape filter. + * + * @param string $strategy The strategy name that should be used as a strategy in the escape call + * @param callable $callable A valid PHP callable + */ + public function setEscaper($strategy, callable $callable) + { + $this->escapers[$strategy] = $callable; + } + + /** + * Gets all defined escapers. + * + * @return callable[] An array of escapers + */ + public function getEscapers() + { + return $this->escapers; + } + + public function setSafeClasses(array $safeClasses = []) + { + $this->safeClasses = []; + $this->safeLookup = []; + foreach ($safeClasses as $class => $strategies) { + $this->addSafeClass($class, $strategies); + } + } + + public function addSafeClass(string $class, array $strategies) + { + $class = ltrim($class, '\\'); + if (!isset($this->safeClasses[$class])) { + $this->safeClasses[$class] = []; + } + $this->safeClasses[$class] = array_merge($this->safeClasses[$class], $strategies); + + foreach ($strategies as $strategy) { + $this->safeLookup[$strategy][$class] = true; + } + } +} + +class_alias('Twig\Extension\EscaperExtension', 'Twig_Extension_Escaper'); +} + +namespace { +use Twig\Environment; +use Twig\Error\RuntimeError; +use Twig\Extension\CoreExtension; +use Twig\Extension\EscaperExtension; +use Twig\Markup; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; + +/** + * Marks a variable as being safe. + * + * @param string $string A PHP variable + * + * @return string + */ +function twig_raw_filter($string) +{ + return $string; +} + +/** + * Escapes a string. + * + * @param mixed $string The value to be escaped + * @param string $strategy The escaping strategy + * @param string $charset The charset + * @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false) + * + * @return string + */ +function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) +{ + if ($autoescape && $string instanceof Markup) { + return $string; + } + + if (!\is_string($string)) { + if (\is_object($string) && method_exists($string, '__toString')) { + if ($autoescape) { + $c = \get_class($string); + $ext = $env->getExtension(EscaperExtension::class); + if (!isset($ext->safeClasses[$c])) { + $ext->safeClasses[$c] = []; + foreach (class_parents($string) + class_implements($string) as $class) { + if (isset($ext->safeClasses[$class])) { + $ext->safeClasses[$c] = array_unique(array_merge($ext->safeClasses[$c], $ext->safeClasses[$class])); + foreach ($ext->safeClasses[$class] as $s) { + $ext->safeLookup[$s][$c] = true; + } + } + } + } + if (isset($ext->safeLookup[$strategy][$c]) || isset($ext->safeLookup['all'][$c])) { + return (string) $string; + } + } + + $string = (string) $string; + } elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { + return $string; + } + } + + if ('' === $string) { + return ''; + } + + if (null === $charset) { + $charset = $env->getCharset(); + } + + switch ($strategy) { + case 'html': + // see https://secure.php.net/htmlspecialchars + + // Using a static variable to avoid initializing the array + // each time the function is called. Moving the declaration on the + // top of the function slow downs other escaping strategies. + static $htmlspecialcharsCharsets = [ + 'ISO-8859-1' => true, 'ISO8859-1' => true, + 'ISO-8859-15' => true, 'ISO8859-15' => true, + 'utf-8' => true, 'UTF-8' => true, + 'CP866' => true, 'IBM866' => true, '866' => true, + 'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true, + '1251' => true, + 'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true, + 'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true, + 'BIG5' => true, '950' => true, + 'GB2312' => true, '936' => true, + 'BIG5-HKSCS' => true, + 'SHIFT_JIS' => true, 'SJIS' => true, '932' => true, + 'EUC-JP' => true, 'EUCJP' => true, + 'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true, + ]; + + if (isset($htmlspecialcharsCharsets[$charset])) { + return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + } + + if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { + // cache the lowercase variant for future iterations + $htmlspecialcharsCharsets[$charset] = true; + + return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + } + + $string = twig_convert_encoding($string, 'UTF-8', $charset); + $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); + + return iconv('UTF-8', $charset, $string); + + case 'js': + // escape all non-alphanumeric characters + // into their \x or \uHHHH representations + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', function ($matches) { + $char = $matches[0]; + + /* + * A few characters have short escape sequences in JSON and JavaScript. + * Escape sequences supported only by JavaScript, not JSON, are ommitted. + * \" is also supported but omitted, because the resulting string is not HTML safe. + */ + static $shortMap = [ + '\\' => '\\\\', + '/' => '\\/', + "\x08" => '\b', + "\x0C" => '\f', + "\x0A" => '\n', + "\x0D" => '\r', + "\x09" => '\t', + ]; + + if (isset($shortMap[$char])) { + return $shortMap[$char]; + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + $char = strtoupper(bin2hex($char)); + + if (4 >= \strlen($char)) { + return sprintf('\u%04s', $char); + } + + return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4)); + }, $string); + + if ('UTF-8' !== $charset) { + $string = iconv('UTF-8', $charset, $string); + } + + return $string; + + case 'css': + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', function ($matches) { + $char = $matches[0]; + + return sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : mb_ord($char, 'UTF-8')); + }, $string); + + if ('UTF-8' !== $charset) { + $string = iconv('UTF-8', $charset, $string); + } + + return $string; + + case 'html_attr': + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', function ($matches) { + /** + * This function is adapted from code coming from Zend Framework. + * + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com) + * @license https://framework.zend.com/license/new-bsd New BSD License + */ + $chr = $matches[0]; + $ord = \ord($chr); + + /* + * The following replaces characters undefined in HTML with the + * hex entity for the Unicode replacement character. + */ + if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) { + return '�'; + } + + /* + * Check if the current character to escape has a name entity we should + * replace it with while grabbing the hex value of the character. + */ + if (1 === \strlen($chr)) { + /* + * While HTML supports far more named entities, the lowest common denominator + * has become HTML5's XML Serialisation which is restricted to the those named + * entities that XML supports. Using HTML entities would result in this error: + * XML Parsing Error: undefined entity + */ + static $entityMap = [ + 34 => '"', /* quotation mark */ + 38 => '&', /* ampersand */ + 60 => '<', /* less-than sign */ + 62 => '>', /* greater-than sign */ + ]; + + if (isset($entityMap[$ord])) { + return $entityMap[$ord]; + } + + return sprintf('&#x%02X;', $ord); + } + + /* + * Per OWASP recommendations, we'll use hex entities for any other + * characters where a named entity does not exist. + */ + return sprintf('&#x%04X;', mb_ord($chr, 'UTF-8')); + }, $string); + + if ('UTF-8' !== $charset) { + $string = iconv('UTF-8', $charset, $string); + } + + return $string; + + case 'url': + return rawurlencode($string); + + default: + static $escapers; + + if (null === $escapers) { + // merge the ones set on CoreExtension for BC (to be removed in 3.0) + $escapers = array_merge( + $env->getExtension(CoreExtension::class)->getEscapers(false), + $env->getExtension(EscaperExtension::class)->getEscapers() + ); + } + + if (isset($escapers[$strategy])) { + return $escapers[$strategy]($env, $string, $charset); + } + + $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); + + throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); + } +} + +/** + * @internal + */ +function twig_escape_filter_is_safe(Node $filterArgs) +{ + foreach ($filterArgs as $arg) { + if ($arg instanceof ConstantExpression) { + return [$arg->getAttribute('value')]; + } + + return []; + } + + return ['html']; +} +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ExtensionInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ExtensionInterface.php new file mode 100644 index 0000000..a083211 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ExtensionInterface.php @@ -0,0 +1,73 @@ + + */ +interface ExtensionInterface +{ + /** + * Returns the token parser instances to add to the existing list. + * + * @return TokenParserInterface[] + */ + public function getTokenParsers(); + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return NodeVisitorInterface[] + */ + public function getNodeVisitors(); + + /** + * Returns a list of filters to add to the existing list. + * + * @return TwigFilter[] + */ + public function getFilters(); + + /** + * Returns a list of tests to add to the existing list. + * + * @return TwigTest[] + */ + public function getTests(); + + /** + * Returns a list of functions to add to the existing list. + * + * @return TwigFunction[] + */ + public function getFunctions(); + + /** + * Returns a list of operators to add to the existing list. + * + * @return array First array of unary operators, second array of binary operators + */ + public function getOperators(); +} + +class_alias('Twig\Extension\ExtensionInterface', 'Twig_ExtensionInterface'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Environment'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/GlobalsInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/GlobalsInterface.php new file mode 100644 index 0000000..4421271 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/GlobalsInterface.php @@ -0,0 +1,32 @@ + + */ +interface GlobalsInterface +{ + /** + * Returns a list of global variables to add to the existing list. + * + * @return array An array of global variables + */ + public function getGlobals(); +} + +class_alias('Twig\Extension\GlobalsInterface', 'Twig_Extension_GlobalsInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/InitRuntimeInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/InitRuntimeInterface.php new file mode 100644 index 0000000..d64d3cd --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/InitRuntimeInterface.php @@ -0,0 +1,36 @@ + + * + * @deprecated since Twig 2.7, to be removed in 3.0 + */ +interface InitRuntimeInterface +{ + /** + * Initializes the runtime environment. + * + * This is where you can load some file that contains filter functions for instance. + */ + public function initRuntime(Environment $environment); +} + +class_alias('Twig\Extension\InitRuntimeInterface', 'Twig_Extension_InitRuntimeInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/OptimizerExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/OptimizerExtension.php new file mode 100644 index 0000000..9552b35 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/OptimizerExtension.php @@ -0,0 +1,31 @@ +optimizers = $optimizers; + } + + public function getNodeVisitors() + { + return [new OptimizerNodeVisitor($this->optimizers)]; + } +} + +class_alias('Twig\Extension\OptimizerExtension', 'Twig_Extension_Optimizer'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ProfilerExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ProfilerExtension.php new file mode 100644 index 0000000..ca5367c --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/ProfilerExtension.php @@ -0,0 +1,48 @@ +actives[] = $profile; + } + + public function enter(Profile $profile) + { + $this->actives[0]->addProfile($profile); + array_unshift($this->actives, $profile); + } + + public function leave(Profile $profile) + { + $profile->leave(); + array_shift($this->actives); + + if (1 === \count($this->actives)) { + $this->actives[0]->leave(); + } + } + + public function getNodeVisitors() + { + return [new ProfilerNodeVisitor(\get_class($this))]; + } +} + +class_alias('Twig\Extension\ProfilerExtension', 'Twig_Extension_Profiler'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/RuntimeExtensionInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/RuntimeExtensionInterface.php new file mode 100644 index 0000000..63bc3b1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/RuntimeExtensionInterface.php @@ -0,0 +1,19 @@ + + */ +interface RuntimeExtensionInterface +{ +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/SandboxExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/SandboxExtension.php new file mode 100644 index 0000000..d16e4ed --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/SandboxExtension.php @@ -0,0 +1,125 @@ +policy = $policy; + $this->sandboxedGlobally = $sandboxed; + } + + public function getTokenParsers() + { + return [new SandboxTokenParser()]; + } + + public function getNodeVisitors() + { + return [new SandboxNodeVisitor()]; + } + + public function enableSandbox() + { + $this->sandboxed = true; + } + + public function disableSandbox() + { + $this->sandboxed = false; + } + + public function isSandboxed() + { + return $this->sandboxedGlobally || $this->sandboxed; + } + + public function isSandboxedGlobally() + { + return $this->sandboxedGlobally; + } + + public function setSecurityPolicy(SecurityPolicyInterface $policy) + { + $this->policy = $policy; + } + + public function getSecurityPolicy() + { + return $this->policy; + } + + public function checkSecurity($tags, $filters, $functions) + { + if ($this->isSandboxed()) { + $this->policy->checkSecurity($tags, $filters, $functions); + } + } + + public function checkMethodAllowed($obj, $method, int $lineno = -1, Source $source = null) + { + if ($this->isSandboxed()) { + try { + $this->policy->checkMethodAllowed($obj, $method); + } catch (SecurityNotAllowedMethodError $e) { + $e->setSourceContext($source); + $e->setTemplateLine($lineno); + + throw $e; + } + } + } + + public function checkPropertyAllowed($obj, $method, int $lineno = -1, Source $source = null) + { + if ($this->isSandboxed()) { + try { + $this->policy->checkPropertyAllowed($obj, $method); + } catch (SecurityNotAllowedPropertyError $e) { + $e->setSourceContext($source); + $e->setTemplateLine($lineno); + + throw $e; + } + } + } + + public function ensureToStringAllowed($obj, int $lineno = -1, Source $source = null) + { + if ($this->isSandboxed() && \is_object($obj) && method_exists($obj, '__toString')) { + try { + $this->policy->checkMethodAllowed($obj, '__toString'); + } catch (SecurityNotAllowedMethodError $e) { + $e->setSourceContext($source); + $e->setTemplateLine($lineno); + + throw $e; + } + } + + return $obj; + } +} + +class_alias('Twig\Extension\SandboxExtension', 'Twig_Extension_Sandbox'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StagingExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StagingExtension.php new file mode 100644 index 0000000..7c0c26c --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StagingExtension.php @@ -0,0 +1,102 @@ + + * + * @internal + */ +final class StagingExtension extends AbstractExtension +{ + private $functions = []; + private $filters = []; + private $visitors = []; + private $tokenParsers = []; + private $tests = []; + + public function addFunction(TwigFunction $function) + { + if (isset($this->functions[$function->getName()])) { + throw new \LogicException(sprintf('Function "%s" is already registered.', $function->getName())); + } + + $this->functions[$function->getName()] = $function; + } + + public function getFunctions() + { + return $this->functions; + } + + public function addFilter(TwigFilter $filter) + { + if (isset($this->filters[$filter->getName()])) { + throw new \LogicException(sprintf('Filter "%s" is already registered.', $filter->getName())); + } + + $this->filters[$filter->getName()] = $filter; + } + + public function getFilters() + { + return $this->filters; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + $this->visitors[] = $visitor; + } + + public function getNodeVisitors() + { + return $this->visitors; + } + + public function addTokenParser(TokenParserInterface $parser) + { + if (isset($this->tokenParsers[$parser->getTag()])) { + throw new \LogicException(sprintf('Tag "%s" is already registered.', $parser->getTag())); + } + + $this->tokenParsers[$parser->getTag()] = $parser; + } + + public function getTokenParsers() + { + return $this->tokenParsers; + } + + public function addTest(TwigTest $test) + { + if (isset($this->tests[$test->getName()])) { + throw new \LogicException(sprintf('Test "%s" is already registered.', $test->getName())); + } + + $this->tests[$test->getName()] = $test; + } + + public function getTests() + { + return $this->tests; + } +} + +class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StringLoaderExtension.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StringLoaderExtension.php new file mode 100644 index 0000000..d671862 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Extension/StringLoaderExtension.php @@ -0,0 +1,46 @@ + true]), + ]; + } +} + +class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader'); +} + +namespace { +use Twig\Environment; +use Twig\TemplateWrapper; + +/** + * Loads a template from a string. + * + * {{ include(template_from_string("Hello {{ name }}")) }} + * + * @param string $template A template as a string or object implementing __toString() + * @param string $name An optional name of the template to be used in error messages + * + * @return TemplateWrapper + */ +function twig_template_from_string(Environment $env, $template, string $name = null) +{ + return $env->createTemplate((string) $template, $name); +} +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/ExtensionSet.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/ExtensionSet.php new file mode 100644 index 0000000..dc25b13 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/ExtensionSet.php @@ -0,0 +1,477 @@ + + * + * @internal + */ +final class ExtensionSet +{ + private $extensions; + private $initialized = false; + private $runtimeInitialized = false; + private $staging; + private $parsers; + private $visitors; + private $filters; + private $tests; + private $functions; + private $unaryOperators; + private $binaryOperators; + private $globals; + private $functionCallbacks = []; + private $filterCallbacks = []; + private $lastModified = 0; + + public function __construct() + { + $this->staging = new StagingExtension(); + } + + /** + * Initializes the runtime environment. + * + * @deprecated since Twig 2.7 + */ + public function initRuntime(Environment $env) + { + if ($this->runtimeInitialized) { + return; + } + + $this->runtimeInitialized = true; + + foreach ($this->extensions as $extension) { + if ($extension instanceof InitRuntimeInterface) { + $extension->initRuntime($env); + } + } + } + + public function hasExtension(string $class): bool + { + $class = ltrim($class, '\\'); + if (!isset($this->extensions[$class]) && class_exists($class, false)) { + // For BC/FC with namespaced aliases + $class = (new \ReflectionClass($class))->name; + } + + return isset($this->extensions[$class]); + } + + public function getExtension(string $class): ExtensionInterface + { + $class = ltrim($class, '\\'); + if (!isset($this->extensions[$class]) && class_exists($class, false)) { + // For BC/FC with namespaced aliases + $class = (new \ReflectionClass($class))->name; + } + + if (!isset($this->extensions[$class])) { + throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class)); + } + + return $this->extensions[$class]; + } + + /** + * @param ExtensionInterface[] $extensions + */ + public function setExtensions(array $extensions) + { + foreach ($extensions as $extension) { + $this->addExtension($extension); + } + } + + /** + * @return ExtensionInterface[] + */ + public function getExtensions(): array + { + return $this->extensions; + } + + public function getSignature(): string + { + return json_encode(array_keys($this->extensions)); + } + + public function isInitialized(): bool + { + return $this->initialized || $this->runtimeInitialized; + } + + public function getLastModified(): int + { + if (0 !== $this->lastModified) { + return $this->lastModified; + } + + foreach ($this->extensions as $extension) { + $r = new \ReflectionObject($extension); + if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModified) { + $this->lastModified = $extensionTime; + } + } + + return $this->lastModified; + } + + public function addExtension(ExtensionInterface $extension) + { + $class = \get_class($extension); + + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class)); + } + + if (isset($this->extensions[$class])) { + throw new \LogicException(sprintf('Unable to register extension "%s" as it is already registered.', $class)); + } + + // For BC/FC with namespaced aliases + $class = (new \ReflectionClass($class))->name; + $this->extensions[$class] = $extension; + } + + public function addFunction(TwigFunction $function) + { + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $function->getName())); + } + + $this->staging->addFunction($function); + } + + /** + * @return TwigFunction[] + */ + public function getFunctions(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->functions; + } + + /** + * @return TwigFunction|false + */ + public function getFunction(string $name) + { + if (!$this->initialized) { + $this->initExtensions(); + } + + if (isset($this->functions[$name])) { + return $this->functions[$name]; + } + + foreach ($this->functions as $pattern => $function) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $function->setArguments($matches); + + return $function; + } + } + + foreach ($this->functionCallbacks as $callback) { + if (false !== $function = $callback($name)) { + return $function; + } + } + + return false; + } + + public function registerUndefinedFunctionCallback(callable $callable) + { + $this->functionCallbacks[] = $callable; + } + + public function addFilter(TwigFilter $filter) + { + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $filter->getName())); + } + + $this->staging->addFilter($filter); + } + + /** + * @return TwigFilter[] + */ + public function getFilters(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->filters; + } + + /** + * @return TwigFilter|false + */ + public function getFilter(string $name) + { + if (!$this->initialized) { + $this->initExtensions(); + } + + if (isset($this->filters[$name])) { + return $this->filters[$name]; + } + + foreach ($this->filters as $pattern => $filter) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $filter->setArguments($matches); + + return $filter; + } + } + + foreach ($this->filterCallbacks as $callback) { + if (false !== $filter = $callback($name)) { + return $filter; + } + } + + return false; + } + + public function registerUndefinedFilterCallback(callable $callable) + { + $this->filterCallbacks[] = $callable; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + if ($this->initialized) { + throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.'); + } + + $this->staging->addNodeVisitor($visitor); + } + + /** + * @return NodeVisitorInterface[] + */ + public function getNodeVisitors(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->visitors; + } + + public function addTokenParser(TokenParserInterface $parser) + { + if ($this->initialized) { + throw new \LogicException('Unable to add a token parser as extensions have already been initialized.'); + } + + $this->staging->addTokenParser($parser); + } + + /** + * @return TokenParserInterface[] + */ + public function getTokenParsers(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->parsers; + } + + public function getGlobals(): array + { + if (null !== $this->globals) { + return $this->globals; + } + + $globals = []; + foreach ($this->extensions as $extension) { + if (!$extension instanceof GlobalsInterface) { + continue; + } + + $extGlobals = $extension->getGlobals(); + if (!\is_array($extGlobals)) { + throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension))); + } + + $globals = array_merge($globals, $extGlobals); + } + + if ($this->initialized) { + $this->globals = $globals; + } + + return $globals; + } + + public function addTest(TwigTest $test) + { + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $test->getName())); + } + + $this->staging->addTest($test); + } + + /** + * @return TwigTest[] + */ + public function getTests(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->tests; + } + + /** + * @return TwigTest|false + */ + public function getTest(string $name) + { + if (!$this->initialized) { + $this->initExtensions(); + } + + if (isset($this->tests[$name])) { + return $this->tests[$name]; + } + + foreach ($this->tests as $pattern => $test) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count) { + if (preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $test->setArguments($matches); + + return $test; + } + } + } + + return false; + } + + public function getUnaryOperators(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->unaryOperators; + } + + public function getBinaryOperators(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->binaryOperators; + } + + private function initExtensions() + { + $this->parsers = []; + $this->filters = []; + $this->functions = []; + $this->tests = []; + $this->visitors = []; + $this->unaryOperators = []; + $this->binaryOperators = []; + + foreach ($this->extensions as $extension) { + $this->initExtension($extension); + } + $this->initExtension($this->staging); + // Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception + $this->initialized = true; + } + + private function initExtension(ExtensionInterface $extension) + { + // filters + foreach ($extension->getFilters() as $filter) { + $this->filters[$filter->getName()] = $filter; + } + + // functions + foreach ($extension->getFunctions() as $function) { + $this->functions[$function->getName()] = $function; + } + + // tests + foreach ($extension->getTests() as $test) { + $this->tests[$test->getName()] = $test; + } + + // token parsers + foreach ($extension->getTokenParsers() as $parser) { + if (!$parser instanceof TokenParserInterface) { + throw new \LogicException('getTokenParsers() must return an array of \Twig\TokenParser\TokenParserInterface.'); + } + + $this->parsers[] = $parser; + } + + // node visitors + foreach ($extension->getNodeVisitors() as $visitor) { + $this->visitors[] = $visitor; + } + + // operators + if ($operators = $extension->getOperators()) { + if (!\is_array($operators)) { + 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))); + } + + if (2 !== \count($operators)) { + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators))); + } + + $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); + $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]); + } + } +} + +class_alias('Twig\ExtensionSet', 'Twig_ExtensionSet'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/FileExtensionEscapingStrategy.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/FileExtensionEscapingStrategy.php new file mode 100644 index 0000000..bc95f33 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/FileExtensionEscapingStrategy.php @@ -0,0 +1,62 @@ + + */ +class FileExtensionEscapingStrategy +{ + /** + * Guesses the best autoescaping strategy based on the file name. + * + * @param string $name The template name + * + * @return string|false The escaping strategy name to use or false to disable + */ + public static function guess($name) + { + if (\in_array(substr($name, -1), ['/', '\\'])) { + return 'html'; // return html for directories + } + + if ('.twig' === substr($name, -5)) { + $name = substr($name, 0, -5); + } + + $extension = pathinfo($name, PATHINFO_EXTENSION); + + switch ($extension) { + case 'js': + return 'js'; + + case 'css': + return 'css'; + + case 'txt': + return false; + + default: + return 'html'; + } + } +} + +class_alias('Twig\FileExtensionEscapingStrategy', 'Twig_FileExtensionEscapingStrategy'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Lexer.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Lexer.php new file mode 100644 index 0000000..45c7290 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Lexer.php @@ -0,0 +1,501 @@ + + */ +class Lexer +{ + private $tokens; + private $code; + private $cursor; + private $lineno; + private $end; + private $state; + private $states; + private $brackets; + private $env; + private $source; + private $options; + private $regexes; + private $position; + private $positions; + private $currentVarBlockLine; + + const STATE_DATA = 0; + const STATE_BLOCK = 1; + const STATE_VAR = 2; + const STATE_STRING = 3; + const STATE_INTERPOLATION = 4; + + const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; + const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; + const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; + const REGEX_DQ_STRING_DELIM = '/"/A'; + const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; + const PUNCTUATION = '()[]{}?:.,|'; + + public function __construct(Environment $env, array $options = []) + { + $this->env = $env; + + $this->options = array_merge([ + 'tag_comment' => ['{#', '#}'], + 'tag_block' => ['{%', '%}'], + 'tag_variable' => ['{{', '}}'], + 'whitespace_trim' => '-', + 'whitespace_line_trim' => '~', + 'whitespace_line_chars' => ' \t\0\x0B', + 'interpolation' => ['#{', '}'], + ], $options); + + // when PHP 7.3 is the min version, we will be able to remove the '#' part in preg_quote as it's part of the default + $this->regexes = [ + // }} + 'lex_var' => '{ + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '#').'\s*'. // -}}\s* + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_variable'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~}}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_variable'][1], '#'). // }} + ') + }Ax', + + // %} + 'lex_block' => '{ + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*\n?'. // -%}\s*\n? + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#').'\n?'. // %}\n? + ') + }Ax', + + // {% endverbatim %} + 'lex_raw_data' => '{'. + preg_quote($this->options['tag_block'][0], '#'). // {% + '('. + $this->options['whitespace_trim']. // - + '|'. + $this->options['whitespace_line_trim']. // ~ + ')?\s*endverbatim\s*'. + '(?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%} + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#'). // %} + ') + }sx', + + 'operator' => $this->getOperatorRegex(), + + // #} + 'lex_comment' => '{ + (?:'. + preg_quote($this->options['whitespace_trim']).preg_quote($this->options['tag_comment'][1], '#').'\s*\n?'. // -#}\s*\n? + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_comment'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~#}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_comment'][1], '#').'\n?'. // #}\n? + ') + }sx', + + // verbatim %} + 'lex_block_raw' => '{ + \s*verbatim\s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}\s* + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#'). // %} + ') + }Asx', + + 'lex_block_line' => '{\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '#').'}As', + + // {{ or {% or {# + 'lex_tokens_start' => '{ + ('. + preg_quote($this->options['tag_variable'][0], '#'). // {{ + '|'. + preg_quote($this->options['tag_block'][0], '#'). // {% + '|'. + preg_quote($this->options['tag_comment'][0], '#'). // {# + ')('. + preg_quote($this->options['whitespace_trim'], '#'). // - + '|'. + preg_quote($this->options['whitespace_line_trim'], '#'). // ~ + ')? + }sx', + 'interpolation_start' => '{'.preg_quote($this->options['interpolation'][0], '#').'\s*}A', + 'interpolation_end' => '{\s*'.preg_quote($this->options['interpolation'][1], '#').'}A', + ]; + } + + public function tokenize(Source $source) + { + $this->source = $source; + $this->code = str_replace(["\r\n", "\r"], "\n", $source->getCode()); + $this->cursor = 0; + $this->lineno = 1; + $this->end = \strlen($this->code); + $this->tokens = []; + $this->state = self::STATE_DATA; + $this->states = []; + $this->brackets = []; + $this->position = -1; + + // find all token starts in one go + preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); + $this->positions = $matches; + + while ($this->cursor < $this->end) { + // dispatch to the lexing functions depending + // on the current state + switch ($this->state) { + case self::STATE_DATA: + $this->lexData(); + break; + + case self::STATE_BLOCK: + $this->lexBlock(); + break; + + case self::STATE_VAR: + $this->lexVar(); + break; + + case self::STATE_STRING: + $this->lexString(); + break; + + case self::STATE_INTERPOLATION: + $this->lexInterpolation(); + break; + } + } + + $this->pushToken(/* Token::EOF_TYPE */ -1); + + if (!empty($this->brackets)) { + list($expect, $lineno) = array_pop($this->brackets); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + + return new TokenStream($this->tokens, $this->source); + } + + private function lexData() + { + // if no matches are left we return the rest of the template as simple text token + if ($this->position == \count($this->positions[0]) - 1) { + $this->pushToken(/* Token::TEXT_TYPE */ 0, substr($this->code, $this->cursor)); + $this->cursor = $this->end; + + return; + } + + // Find the first token after the current cursor + $position = $this->positions[0][++$this->position]; + while ($position[1] < $this->cursor) { + if ($this->position == \count($this->positions[0]) - 1) { + return; + } + $position = $this->positions[0][++$this->position]; + } + + // push the template text first + $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor); + + // trim? + if (isset($this->positions[2][$this->position][0])) { + if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) { + // whitespace_trim detected ({%-, {{- or {#-) + $text = rtrim($text); + } elseif ($this->options['whitespace_line_trim'] === $this->positions[2][$this->position][0]) { + // whitespace_line_trim detected ({%~, {{~ or {#~) + // don't trim \r and \n + $text = rtrim($text, " \t\0\x0B"); + } + } + $this->pushToken(/* Token::TEXT_TYPE */ 0, $text); + $this->moveCursor($textContent.$position[0]); + + switch ($this->positions[1][$this->position][0]) { + case $this->options['tag_comment'][0]: + $this->lexComment(); + break; + + case $this->options['tag_block'][0]: + // raw data? + if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + $this->lexRawData(); + // {% line \d+ %} + } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + $this->lineno = (int) $match[1]; + } else { + $this->pushToken(/* Token::BLOCK_START_TYPE */ 1); + $this->pushState(self::STATE_BLOCK); + $this->currentVarBlockLine = $this->lineno; + } + break; + + case $this->options['tag_variable'][0]: + $this->pushToken(/* Token::VAR_START_TYPE */ 2); + $this->pushState(self::STATE_VAR); + $this->currentVarBlockLine = $this->lineno; + break; + } + } + + private function lexBlock() + { + if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::BLOCK_END_TYPE */ 3); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + private function lexVar() + { + if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::VAR_END_TYPE */ 4); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + private function lexExpression() + { + // whitespace + if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + + if ($this->cursor >= $this->end) { + throw new SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); + } + } + + // arrow function + if ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) { + $this->pushToken(Token::ARROW_TYPE, '=>'); + $this->moveCursor('=>'); + } + // operators + elseif (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::OPERATOR_TYPE */ 8, preg_replace('/\s+/', ' ', $match[0])); + $this->moveCursor($match[0]); + } + // names + elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::NAME_TYPE */ 5, $match[0]); + $this->moveCursor($match[0]); + } + // numbers + elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) { + $number = (float) $match[0]; // floats + if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { + $number = (int) $match[0]; // integers lower than the maximum + } + $this->pushToken(/* Token::NUMBER_TYPE */ 6, $number); + $this->moveCursor($match[0]); + } + // punctuation + elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) { + // opening bracket + if (false !== strpos('([{', $this->code[$this->cursor])) { + $this->brackets[] = [$this->code[$this->cursor], $this->lineno]; + } + // closing bracket + elseif (false !== strpos(')]}', $this->code[$this->cursor])) { + if (empty($this->brackets)) { + throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + + list($expect, $lineno) = array_pop($this->brackets); + if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + } + + $this->pushToken(/* Token::PUNCTUATION_TYPE */ 9, $this->code[$this->cursor]); + ++$this->cursor; + } + // strings + elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes(substr($match[0], 1, -1))); + $this->moveCursor($match[0]); + } + // opening double quoted string + elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { + $this->brackets[] = ['"', $this->lineno]; + $this->pushState(self::STATE_STRING); + $this->moveCursor($match[0]); + } + // unlexable + else { + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + } + + private function lexRawData() + { + if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new SyntaxError('Unexpected end of file: Unclosed "verbatim" block.', $this->lineno, $this->source); + } + + $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); + $this->moveCursor($text.$match[0][0]); + + // trim? + if (isset($match[1][0])) { + if ($this->options['whitespace_trim'] === $match[1][0]) { + // whitespace_trim detected ({%-, {{- or {#-) + $text = rtrim($text); + } else { + // whitespace_line_trim detected ({%~, {{~ or {#~) + // don't trim \r and \n + $text = rtrim($text, " \t\0\x0B"); + } + } + + $this->pushToken(/* Token::TEXT_TYPE */ 0, $text); + } + + private function lexComment() + { + if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source); + } + + $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); + } + + private function lexString() + { + if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) { + $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; + $this->pushToken(/* Token::INTERPOLATION_START_TYPE */ 10); + $this->moveCursor($match[0]); + $this->pushState(self::STATE_INTERPOLATION); + } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) { + $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes($match[0])); + $this->moveCursor($match[0]); + } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { + list($expect, $lineno) = array_pop($this->brackets); + if ('"' != $this->code[$this->cursor]) { + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + + $this->popState(); + ++$this->cursor; + } else { + // unlexable + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + } + + private function lexInterpolation() + { + $bracket = end($this->brackets); + if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) { + array_pop($this->brackets); + $this->pushToken(/* Token::INTERPOLATION_END_TYPE */ 11); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + private function pushToken($type, $value = '') + { + // do not push empty text tokens + if (/* Token::TEXT_TYPE */ 0 === $type && '' === $value) { + return; + } + + $this->tokens[] = new Token($type, $value, $this->lineno); + } + + private function moveCursor($text) + { + $this->cursor += \strlen($text); + $this->lineno += substr_count($text, "\n"); + } + + private function getOperatorRegex() + { + $operators = array_merge( + ['='], + array_keys($this->env->getUnaryOperators()), + array_keys($this->env->getBinaryOperators()) + ); + + $operators = array_combine($operators, array_map('strlen', $operators)); + arsort($operators); + + $regex = []; + foreach ($operators as $operator => $length) { + // an operator that ends with a character must be followed by + // a whitespace or a parenthesis + if (ctype_alpha($operator[$length - 1])) { + $r = preg_quote($operator, '/').'(?=[\s()])'; + } else { + $r = preg_quote($operator, '/'); + } + + // an operator with a space can be any amount of whitespaces + $r = preg_replace('/\s+/', '\s+', $r); + + $regex[] = $r; + } + + return '/'.implode('|', $regex).'/A'; + } + + private function pushState($state) + { + $this->states[] = $this->state; + $this->state = $state; + } + + private function popState() + { + if (0 === \count($this->states)) { + throw new \LogicException('Cannot pop state without a previous state.'); + } + + $this->state = array_pop($this->states); + } +} + +class_alias('Twig\Lexer', 'Twig_Lexer'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ArrayLoader.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ArrayLoader.php new file mode 100644 index 0000000..b03170b --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ArrayLoader.php @@ -0,0 +1,86 @@ + + */ +final class ArrayLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + private $templates = []; + + /** + * @param array $templates An array of templates (keys are the names, and values are the source code) + */ + public function __construct(array $templates = []) + { + $this->templates = $templates; + } + + /** + * Adds or overrides a template. + * + * @param string $name The template name + * @param string $template The template source + */ + public function setTemplate($name, $template) + { + $this->templates[$name] = $template; + } + + public function getSourceContext($name) + { + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return new Source($this->templates[$name], $name); + } + + public function exists($name) + { + return isset($this->templates[$name]); + } + + public function getCacheKey($name) + { + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return $name.':'.$this->templates[$name]; + } + + public function isFresh($name, $time) + { + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return true; + } +} + +class_alias('Twig\Loader\ArrayLoader', 'Twig_Loader_Array'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ChainLoader.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ChainLoader.php new file mode 100644 index 0000000..edb9df8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ChainLoader.php @@ -0,0 +1,120 @@ + + */ +final class ChainLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + private $hasSourceCache = []; + private $loaders = []; + + /** + * @param LoaderInterface[] $loaders + */ + public function __construct(array $loaders = []) + { + foreach ($loaders as $loader) { + $this->addLoader($loader); + } + } + + public function addLoader(LoaderInterface $loader) + { + $this->loaders[] = $loader; + $this->hasSourceCache = []; + } + + /** + * @return LoaderInterface[] + */ + public function getLoaders() + { + return $this->loaders; + } + + public function getSourceContext($name) + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if (!$loader->exists($name)) { + continue; + } + + try { + return $loader->getSourceContext($name); + } catch (LoaderError $e) { + $exceptions[] = $e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function exists($name) + { + if (isset($this->hasSourceCache[$name])) { + return $this->hasSourceCache[$name]; + } + + foreach ($this->loaders as $loader) { + if ($loader->exists($name)) { + return $this->hasSourceCache[$name] = true; + } + } + + return $this->hasSourceCache[$name] = false; + } + + public function getCacheKey($name) + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if (!$loader->exists($name)) { + continue; + } + + try { + return $loader->getCacheKey($name); + } catch (LoaderError $e) { + $exceptions[] = \get_class($loader).': '.$e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function isFresh($name, $time) + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if (!$loader->exists($name)) { + continue; + } + + try { + return $loader->isFresh($name, $time); + } catch (LoaderError $e) { + $exceptions[] = \get_class($loader).': '.$e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } +} + +class_alias('Twig\Loader\ChainLoader', 'Twig_Loader_Chain'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ExistsLoaderInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ExistsLoaderInterface.php new file mode 100644 index 0000000..aab8bd8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/ExistsLoaderInterface.php @@ -0,0 +1,23 @@ + + */ +class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface +{ + /** Identifier of the main namespace. */ + const MAIN_NAMESPACE = '__main__'; + + protected $paths = []; + protected $cache = []; + protected $errorCache = []; + + private $rootPath; + + /** + * @param string|array $paths A path or an array of paths where to look for templates + * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) + */ + public function __construct($paths = [], string $rootPath = null) + { + $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR; + if (false !== $realPath = realpath($rootPath)) { + $this->rootPath = $realPath.\DIRECTORY_SEPARATOR; + } + + if ($paths) { + $this->setPaths($paths); + } + } + + /** + * Returns the paths to the templates. + * + * @param string $namespace A path namespace + * + * @return array The array of paths where to look for templates + */ + public function getPaths($namespace = self::MAIN_NAMESPACE) + { + return isset($this->paths[$namespace]) ? $this->paths[$namespace] : []; + } + + /** + * Returns the path namespaces. + * + * The main namespace is always defined. + * + * @return array The array of defined namespaces + */ + public function getNamespaces() + { + return array_keys($this->paths); + } + + /** + * Sets the paths where templates are stored. + * + * @param string|array $paths A path or an array of paths where to look for templates + * @param string $namespace A path namespace + */ + public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) + { + if (!\is_array($paths)) { + $paths = [$paths]; + } + + $this->paths[$namespace] = []; + foreach ($paths as $path) { + $this->addPath($path, $namespace); + } + } + + /** + * Adds a path where templates are stored. + * + * @param string $path A path where to look for templates + * @param string $namespace A path namespace + * + * @throws LoaderError + */ + public function addPath($path, $namespace = self::MAIN_NAMESPACE) + { + // invalidate the cache + $this->cache = $this->errorCache = []; + + $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; + if (!is_dir($checkPath)) { + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + } + + $this->paths[$namespace][] = rtrim($path, '/\\'); + } + + /** + * Prepends a path where templates are stored. + * + * @param string $path A path where to look for templates + * @param string $namespace A path namespace + * + * @throws LoaderError + */ + public function prependPath($path, $namespace = self::MAIN_NAMESPACE) + { + // invalidate the cache + $this->cache = $this->errorCache = []; + + $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; + if (!is_dir($checkPath)) { + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + } + + $path = rtrim($path, '/\\'); + + if (!isset($this->paths[$namespace])) { + $this->paths[$namespace][] = $path; + } else { + array_unshift($this->paths[$namespace], $path); + } + } + + public function getSourceContext($name) + { + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return new Source('', $name, ''); + } + + return new Source(file_get_contents($path), $name, $path); + } + + public function getCacheKey($name) + { + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return ''; + } + $len = \strlen($this->rootPath); + if (0 === strncmp($this->rootPath, $path, $len)) { + return substr($path, $len); + } + + return $path; + } + + public function exists($name) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return true; + } + + return null !== ($path = $this->findTemplate($name, false)) && false !== $path; + } + + public function isFresh($name, $time) + { + // false support to be removed in 3.0 + if (null === ($path = $this->findTemplate($name)) || false === $path) { + return false; + } + + return filemtime($path) < $time; + } + + /** + * Checks if the template can be found. + * + * In Twig 3.0, findTemplate must return a string or null (returning false won't work anymore). + * + * @param string $name The template name + * @param bool $throw Whether to throw an exception when an error occurs + * + * @return string|false|null The template name or false/null + */ + protected function findTemplate($name, $throw = true) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } + + if (isset($this->errorCache[$name])) { + if (!$throw) { + return false; + } + + throw new LoaderError($this->errorCache[$name]); + } + + try { + $this->validateName($name); + + list($namespace, $shortname) = $this->parseName($name); + } catch (LoaderError $e) { + if (!$throw) { + return false; + } + + throw $e; + } + + if (!isset($this->paths[$namespace])) { + $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace); + + if (!$throw) { + return false; + } + + throw new LoaderError($this->errorCache[$name]); + } + + foreach ($this->paths[$namespace] as $path) { + if (!$this->isAbsolutePath($path)) { + $path = $this->rootPath.$path; + } + + if (is_file($path.'/'.$shortname)) { + if (false !== $realpath = realpath($path.'/'.$shortname)) { + return $this->cache[$name] = $realpath; + } + + return $this->cache[$name] = $path.'/'.$shortname; + } + } + + $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])); + + if (!$throw) { + return false; + } + + throw new LoaderError($this->errorCache[$name]); + } + + private function normalizeName($name) + { + return preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name)); + } + + private function parseName($name, $default = self::MAIN_NAMESPACE) + { + if (isset($name[0]) && '@' == $name[0]) { + if (false === $pos = strpos($name, '/')) { + throw new LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + } + + $namespace = substr($name, 1, $pos - 1); + $shortname = substr($name, $pos + 1); + + return [$namespace, $shortname]; + } + + return [$default, $name]; + } + + private function validateName($name) + { + if (false !== strpos($name, "\0")) { + throw new LoaderError('A template name cannot contain NUL bytes.'); + } + + $name = ltrim($name, '/'); + $parts = explode('/', $name); + $level = 0; + foreach ($parts as $part) { + if ('..' === $part) { + --$level; + } elseif ('.' !== $part) { + ++$level; + } + + if ($level < 0) { + throw new LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); + } + } + } + + private function isAbsolutePath($file) + { + return strspn($file, '/\\', 0, 1) + || (\strlen($file) > 3 && ctype_alpha($file[0]) + && ':' === $file[1] + && strspn($file, '/\\', 2, 1) + ) + || null !== parse_url($file, PHP_URL_SCHEME) + ; + } +} + +class_alias('Twig\Loader\FilesystemLoader', 'Twig_Loader_Filesystem'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/LoaderInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/LoaderInterface.php new file mode 100644 index 0000000..5ccd2c7 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/LoaderInterface.php @@ -0,0 +1,69 @@ + + */ +interface LoaderInterface +{ + /** + * Returns the source context for a given template logical name. + * + * @param string $name The template logical name + * + * @return Source + * + * @throws LoaderError When $name is not found + */ + public function getSourceContext($name); + + /** + * Gets the cache key to use for the cache for a given template name. + * + * @param string $name The name of the template to load + * + * @return string The cache key + * + * @throws LoaderError When $name is not found + */ + public function getCacheKey($name); + + /** + * Returns true if the template is still fresh. + * + * @param string $name The template name + * @param int $time Timestamp of the last modification time of the + * cached template + * + * @return bool true if the template is fresh, false otherwise + * + * @throws LoaderError When $name is not found + */ + public function isFresh($name, $time); + + /** + * Check if we have the source code of a template, given its name. + * + * @param string $name The name of the template to check if we can load + * + * @return bool If the template source code is handled by this loader or not + */ + public function exists($name); +} + +class_alias('Twig\Loader\LoaderInterface', 'Twig_LoaderInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/SourceContextLoaderInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/SourceContextLoaderInterface.php new file mode 100644 index 0000000..4fdb17e --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Loader/SourceContextLoaderInterface.php @@ -0,0 +1,21 @@ + + */ +class Markup implements \Countable, \JsonSerializable +{ + private $content; + private $charset; + + public function __construct($content, $charset) + { + $this->content = (string) $content; + $this->charset = $charset; + } + + public function __toString() + { + return $this->content; + } + + public function count() + { + return mb_strlen($this->content, $this->charset); + } + + public function jsonSerialize() + { + return $this->content; + } +} + +class_alias('Twig\Markup', 'Twig_Markup'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/AutoEscapeNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/AutoEscapeNode.php new file mode 100644 index 0000000..0bd5ae1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/AutoEscapeNode.php @@ -0,0 +1,40 @@ + + */ +class AutoEscapeNode extends Node +{ + public function __construct($value, Node $body, int $lineno, string $tag = 'autoescape') + { + parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->subcompile($this->getNode('body')); + } +} + +class_alias('Twig\Node\AutoEscapeNode', 'Twig_Node_AutoEscape'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockNode.php new file mode 100644 index 0000000..4da6e6f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockNode.php @@ -0,0 +1,46 @@ + + */ +class BlockNode extends Node +{ + public function __construct(string $name, Node $body, int $lineno, string $tag = null) + { + parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n") + ->indent() + ->write("\$macros = \$this->macros;\n") + ; + + $compiler + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n\n") + ; + } +} + +class_alias('Twig\Node\BlockNode', 'Twig_Node_Block'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockReferenceNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockReferenceNode.php new file mode 100644 index 0000000..c46d8b3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BlockReferenceNode.php @@ -0,0 +1,38 @@ + + */ +class BlockReferenceNode extends Node implements NodeOutputInterface +{ + public function __construct(string $name, int $lineno, string $tag = null) + { + parent::__construct([], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) + ; + } +} + +class_alias('Twig\Node\BlockReferenceNode', 'Twig_Node_BlockReference'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BodyNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BodyNode.php new file mode 100644 index 0000000..5290be5 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/BodyNode.php @@ -0,0 +1,23 @@ + + */ +class BodyNode extends Node +{ +} + +class_alias('Twig\Node\BodyNode', 'Twig_Node_Body'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckSecurityNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckSecurityNode.php new file mode 100644 index 0000000..59857ca --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckSecurityNode.php @@ -0,0 +1,85 @@ + + */ +class CheckSecurityNode extends Node +{ + private $usedFilters; + private $usedTags; + private $usedFunctions; + + public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) + { + $this->usedFilters = $usedFilters; + $this->usedTags = $usedTags; + $this->usedFunctions = $usedFunctions; + + parent::__construct(); + } + + public function compile(Compiler $compiler) + { + $tags = $filters = $functions = []; + foreach (['tags', 'filters', 'functions'] as $type) { + foreach ($this->{'used'.ucfirst($type)} as $name => $node) { + if ($node instanceof Node) { + ${$type}[$name] = $node->getTemplateLine(); + } else { + ${$type}[$node] = null; + } + } + } + + $compiler + ->write("\$this->sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n") + ->write('$tags = ')->repr(array_filter($tags))->raw(";\n") + ->write('$filters = ')->repr(array_filter($filters))->raw(";\n") + ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n") + ->write("try {\n") + ->indent() + ->write("\$this->sandbox->checkSecurity(\n") + ->indent() + ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n") + ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n") + ->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n") + ->outdent() + ->write(");\n") + ->outdent() + ->write("} catch (SecurityError \$e) {\n") + ->indent() + ->write("\$e->setSourceContext(\$this->source);\n\n") + ->write("if (\$e instanceof SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") + ->outdent() + ->write("}\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("}\n\n") + ; + } +} + +class_alias('Twig\Node\CheckSecurityNode', 'Twig_Node_CheckSecurity'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckToStringNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckToStringNode.php new file mode 100644 index 0000000..02b42fc --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/CheckToStringNode.php @@ -0,0 +1,45 @@ + + */ +class CheckToStringNode extends AbstractExpression +{ + public function __construct(AbstractExpression $expr) + { + parent::__construct(['expr' => $expr], [], $expr->getTemplateLine(), $expr->getNodeTag()); + } + + public function compile(Compiler $compiler) + { + $expr = $this->getNode('expr'); + $compiler + ->raw('$this->sandbox->ensureToStringAllowed(') + ->subcompile($expr) + ->raw(', ') + ->repr($expr->getTemplateLine()) + ->raw(', $this->source)') + ; + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DeprecatedNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DeprecatedNode.php new file mode 100644 index 0000000..accd768 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DeprecatedNode.php @@ -0,0 +1,55 @@ + + */ +class DeprecatedNode extends Node +{ + public function __construct(AbstractExpression $expr, int $lineno, string $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $expr = $this->getNode('expr'); + + if ($expr instanceof ConstantExpression) { + $compiler->write('@trigger_error(') + ->subcompile($expr); + } else { + $varName = $compiler->getVarName(); + $compiler->write(sprintf('$%s = ', $varName)) + ->subcompile($expr) + ->raw(";\n") + ->write(sprintf('@trigger_error($%s', $varName)); + } + + $compiler + ->raw('.') + ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine())) + ->raw(", E_USER_DEPRECATED);\n") + ; + } +} + +class_alias('Twig\Node\DeprecatedNode', 'Twig_Node_Deprecated'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DoNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DoNode.php new file mode 100644 index 0000000..d74804c --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/DoNode.php @@ -0,0 +1,40 @@ + + */ +class DoNode extends Node +{ + public function __construct(AbstractExpression $expr, int $lineno, string $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} + +class_alias('Twig\Node\DoNode', 'Twig_Node_Do'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/EmbedNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/EmbedNode.php new file mode 100644 index 0000000..4a1ef6f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/EmbedNode.php @@ -0,0 +1,50 @@ + + */ +class EmbedNode extends IncludeNode +{ + // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) + public function __construct(string $name, int $index, AbstractExpression $variables = null, bool $only = false, bool $ignoreMissing = false, int $lineno, string $tag = null) + { + parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); + + $this->setAttribute('name', $name); + $this->setAttribute('index', $index); + } + + protected function addGetTemplate(Compiler $compiler) + { + $compiler + ->write('$this->loadTemplate(') + ->string($this->getAttribute('name')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(', ') + ->string($this->getAttribute('index')) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\EmbedNode', 'Twig_Node_Embed'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AbstractExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AbstractExpression.php new file mode 100644 index 0000000..a352892 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AbstractExpression.php @@ -0,0 +1,26 @@ + + */ +abstract class AbstractExpression extends Node +{ +} + +class_alias('Twig\Node\Expression\AbstractExpression', 'Twig_Node_Expression'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrayExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrayExpression.php new file mode 100644 index 0000000..917675d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrayExpression.php @@ -0,0 +1,88 @@ +index = -1; + foreach ($this->getKeyValuePairs() as $pair) { + if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { + $this->index = $pair['key']->getAttribute('value'); + } + } + } + + public function getKeyValuePairs() + { + $pairs = []; + + foreach (array_chunk($this->nodes, 2) as $pair) { + $pairs[] = [ + 'key' => $pair[0], + 'value' => $pair[1], + ]; + } + + return $pairs; + } + + public function hasElement(AbstractExpression $key) + { + foreach ($this->getKeyValuePairs() as $pair) { + // we compare the string representation of the keys + // to avoid comparing the line numbers which are not relevant here. + if ((string) $key === (string) $pair['key']) { + return true; + } + } + + return false; + } + + public function addElement(AbstractExpression $value, AbstractExpression $key = null) + { + if (null === $key) { + $key = new ConstantExpression(++$this->index, $value->getTemplateLine()); + } + + array_push($this->nodes, $key, $value); + } + + public function compile(Compiler $compiler) + { + $compiler->raw('['); + $first = true; + foreach ($this->getKeyValuePairs() as $pair) { + if (!$first) { + $compiler->raw(', '); + } + $first = false; + + $compiler + ->subcompile($pair['key']) + ->raw(' => ') + ->subcompile($pair['value']) + ; + } + $compiler->raw(']'); + } +} + +class_alias('Twig\Node\Expression\ArrayExpression', 'Twig_Node_Expression_Array'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php new file mode 100644 index 0000000..b5b720e --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php @@ -0,0 +1,64 @@ + + */ +class ArrowFunctionExpression extends AbstractExpression +{ + public function __construct(AbstractExpression $expr, Node $names, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr, 'names' => $names], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->raw('function (') + ; + foreach ($this->getNode('names') as $i => $name) { + if ($i) { + $compiler->raw(', '); + } + + $compiler + ->raw('$__') + ->raw($name->getAttribute('name')) + ->raw('__') + ; + } + $compiler + ->raw(') use ($context, $macros) { ') + ; + foreach ($this->getNode('names') as $name) { + $compiler + ->raw('$context["') + ->raw($name->getAttribute('name')) + ->raw('"] = $__') + ->raw($name->getAttribute('name')) + ->raw('__; ') + ; + } + $compiler + ->raw('return ') + ->subcompile($this->getNode('expr')) + ->raw('; }') + ; + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AssignNameExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AssignNameExpression.php new file mode 100644 index 0000000..62c4ac0 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/AssignNameExpression.php @@ -0,0 +1,29 @@ +raw('$context[') + ->string($this->getAttribute('name')) + ->raw(']') + ; + } +} + +class_alias('Twig\Node\Expression\AssignNameExpression', 'Twig_Node_Expression_AssignName'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php new file mode 100644 index 0000000..67c388a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php @@ -0,0 +1,44 @@ + $left, 'right' => $right], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('left')) + ->raw(' ') + ; + $this->operator($compiler); + $compiler + ->raw(' ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + abstract public function operator(Compiler $compiler); +} + +class_alias('Twig\Node\Expression\Binary\AbstractBinary', 'Twig_Node_Expression_Binary'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AddBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AddBinary.php new file mode 100644 index 0000000..f7719a1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AddBinary.php @@ -0,0 +1,25 @@ +raw('+'); + } +} + +class_alias('Twig\Node\Expression\Binary\AddBinary', 'Twig_Node_Expression_Binary_Add'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AndBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AndBinary.php new file mode 100644 index 0000000..484597d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/AndBinary.php @@ -0,0 +1,25 @@ +raw('&&'); + } +} + +class_alias('Twig\Node\Expression\Binary\AndBinary', 'Twig_Node_Expression_Binary_And'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php new file mode 100644 index 0000000..cf28691 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php @@ -0,0 +1,25 @@ +raw('&'); + } +} + +class_alias('Twig\Node\Expression\Binary\BitwiseAndBinary', 'Twig_Node_Expression_Binary_BitwiseAnd'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php new file mode 100644 index 0000000..7d5d260 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php @@ -0,0 +1,25 @@ +raw('|'); + } +} + +class_alias('Twig\Node\Expression\Binary\BitwiseOrBinary', 'Twig_Node_Expression_Binary_BitwiseOr'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php new file mode 100644 index 0000000..7291987 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php @@ -0,0 +1,25 @@ +raw('^'); + } +} + +class_alias('Twig\Node\Expression\Binary\BitwiseXorBinary', 'Twig_Node_Expression_Binary_BitwiseXor'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php new file mode 100644 index 0000000..f6e5938 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php @@ -0,0 +1,25 @@ +raw('.'); + } +} + +class_alias('Twig\Node\Expression\Binary\ConcatBinary', 'Twig_Node_Expression_Binary_Concat'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/DivBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/DivBinary.php new file mode 100644 index 0000000..ebfcc75 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/DivBinary.php @@ -0,0 +1,25 @@ +raw('/'); + } +} + +class_alias('Twig\Node\Expression\Binary\DivBinary', 'Twig_Node_Expression_Binary_Div'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php new file mode 100644 index 0000000..41a0065 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php @@ -0,0 +1,37 @@ +getVarName(); + $right = $compiler->getVarName(); + $compiler + ->raw(sprintf('(is_string($%s = ', $left)) + ->subcompile($this->getNode('left')) + ->raw(sprintf(') && is_string($%s = ', $right)) + ->subcompile($this->getNode('right')) + ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right)) + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw(''); + } +} + +class_alias('Twig\Node\Expression\Binary\EndsWithBinary', 'Twig_Node_Expression_Binary_EndsWith'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EqualBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EqualBinary.php new file mode 100644 index 0000000..84904c3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/EqualBinary.php @@ -0,0 +1,24 @@ +raw('=='); + } +} + +class_alias('Twig\Node\Expression\Binary\EqualBinary', 'Twig_Node_Expression_Binary_Equal'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php new file mode 100644 index 0000000..4dd5e3d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php @@ -0,0 +1,31 @@ +raw('(int) floor('); + parent::compile($compiler); + $compiler->raw(')'); + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('/'); + } +} + +class_alias('Twig\Node\Expression\Binary\FloorDivBinary', 'Twig_Node_Expression_Binary_FloorDiv'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php new file mode 100644 index 0000000..be73001 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php @@ -0,0 +1,24 @@ +raw('>'); + } +} + +class_alias('Twig\Node\Expression\Binary\GreaterBinary', 'Twig_Node_Expression_Binary_Greater'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php new file mode 100644 index 0000000..5c2ae72 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php @@ -0,0 +1,24 @@ +raw('>='); + } +} + +class_alias('Twig\Node\Expression\Binary\GreaterEqualBinary', 'Twig_Node_Expression_Binary_GreaterEqual'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/InBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/InBinary.php new file mode 100644 index 0000000..f00b230 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/InBinary.php @@ -0,0 +1,35 @@ +raw('twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('in'); + } +} + +class_alias('Twig\Node\Expression\Binary\InBinary', 'Twig_Node_Expression_Binary_In'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessBinary.php new file mode 100644 index 0000000..2b202da --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessBinary.php @@ -0,0 +1,24 @@ +raw('<'); + } +} + +class_alias('Twig\Node\Expression\Binary\LessBinary', 'Twig_Node_Expression_Binary_Less'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php new file mode 100644 index 0000000..4fffafe --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php @@ -0,0 +1,24 @@ +raw('<='); + } +} + +class_alias('Twig\Node\Expression\Binary\LessEqualBinary', 'Twig_Node_Expression_Binary_LessEqual'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php new file mode 100644 index 0000000..ae810b2 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php @@ -0,0 +1,35 @@ +raw('preg_match(') + ->subcompile($this->getNode('right')) + ->raw(', ') + ->subcompile($this->getNode('left')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw(''); + } +} + +class_alias('Twig\Node\Expression\Binary\MatchesBinary', 'Twig_Node_Expression_Binary_Matches'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ModBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ModBinary.php new file mode 100644 index 0000000..e6a2b36 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/ModBinary.php @@ -0,0 +1,25 @@ +raw('%'); + } +} + +class_alias('Twig\Node\Expression\Binary\ModBinary', 'Twig_Node_Expression_Binary_Mod'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MulBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MulBinary.php new file mode 100644 index 0000000..cd65f5d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/MulBinary.php @@ -0,0 +1,25 @@ +raw('*'); + } +} + +class_alias('Twig\Node\Expression\Binary\MulBinary', 'Twig_Node_Expression_Binary_Mul'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php new file mode 100644 index 0000000..df5c6a2 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php @@ -0,0 +1,24 @@ +raw('!='); + } +} + +class_alias('Twig\Node\Expression\Binary\NotEqualBinary', 'Twig_Node_Expression_Binary_NotEqual'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotInBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotInBinary.php new file mode 100644 index 0000000..ed2034e --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/NotInBinary.php @@ -0,0 +1,35 @@ +raw('!twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('not in'); + } +} + +class_alias('Twig\Node\Expression\Binary\NotInBinary', 'Twig_Node_Expression_Binary_NotIn'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/OrBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/OrBinary.php new file mode 100644 index 0000000..8f9da43 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/OrBinary.php @@ -0,0 +1,25 @@ +raw('||'); + } +} + +class_alias('Twig\Node\Expression\Binary\OrBinary', 'Twig_Node_Expression_Binary_Or'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/PowerBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/PowerBinary.php new file mode 100644 index 0000000..32d0214 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/PowerBinary.php @@ -0,0 +1,24 @@ +raw('**'); + } +} + +class_alias('Twig\Node\Expression\Binary\PowerBinary', 'Twig_Node_Expression_Binary_Power'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/RangeBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/RangeBinary.php new file mode 100644 index 0000000..e9c0cdf --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/RangeBinary.php @@ -0,0 +1,35 @@ +raw('range(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw('..'); + } +} + +class_alias('Twig\Node\Expression\Binary\RangeBinary', 'Twig_Node_Expression_Binary_Range'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php new file mode 100644 index 0000000..5245e40 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php @@ -0,0 +1,22 @@ +raw('<=>'); + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php new file mode 100644 index 0000000..1fe59fb --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php @@ -0,0 +1,37 @@ +getVarName(); + $right = $compiler->getVarName(); + $compiler + ->raw(sprintf('(is_string($%s = ', $left)) + ->subcompile($this->getNode('left')) + ->raw(sprintf(') && is_string($%s = ', $right)) + ->subcompile($this->getNode('right')) + ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) + ; + } + + public function operator(Compiler $compiler) + { + return $compiler->raw(''); + } +} + +class_alias('Twig\Node\Expression\Binary\StartsWithBinary', 'Twig_Node_Expression_Binary_StartsWith'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SubBinary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SubBinary.php new file mode 100644 index 0000000..2546975 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Binary/SubBinary.php @@ -0,0 +1,25 @@ +raw('-'); + } +} + +class_alias('Twig\Node\Expression\Binary\SubBinary', 'Twig_Node_Expression_Binary_Sub'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/BlockReferenceExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/BlockReferenceExpression.php new file mode 100644 index 0000000..c68989a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/BlockReferenceExpression.php @@ -0,0 +1,88 @@ + + */ +class BlockReferenceExpression extends AbstractExpression +{ + public function __construct(Node $name, Node $template = null, int $lineno, string $tag = null) + { + $nodes = ['name' => $name]; + if (null !== $template) { + $nodes['template'] = $template; + } + + parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('is_defined_test')) { + $this->compileTemplateCall($compiler, 'hasBlock'); + } else { + if ($this->getAttribute('output')) { + $compiler->addDebugInfo($this); + + $this + ->compileTemplateCall($compiler, 'displayBlock') + ->raw(";\n"); + } else { + $this->compileTemplateCall($compiler, 'renderBlock'); + } + } + } + + private function compileTemplateCall(Compiler $compiler, string $method): Compiler + { + if (!$this->hasNode('template')) { + $compiler->write('$this'); + } else { + $compiler + ->write('$this->loadTemplate(') + ->subcompile($this->getNode('template')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')') + ; + } + + $compiler->raw(sprintf('->%s', $method)); + + return $this->compileBlockArguments($compiler); + } + + private function compileBlockArguments(Compiler $compiler): Compiler + { + $compiler + ->raw('(') + ->subcompile($this->getNode('name')) + ->raw(', $context'); + + if (!$this->hasNode('template')) { + $compiler->raw(', $blocks'); + } + + return $compiler->raw(')'); + } +} + +class_alias('Twig\Node\Expression\BlockReferenceExpression', 'Twig_Node_Expression_BlockReference'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/CallExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/CallExpression.php new file mode 100644 index 0000000..4ecd2c1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/CallExpression.php @@ -0,0 +1,313 @@ +getAttribute('callable'); + + $closingParenthesis = false; + $isArray = false; + if (\is_string($callable) && false === strpos($callable, '::')) { + $compiler->raw($callable); + } else { + list($r, $callable) = $this->reflectCallable($callable); + if ($r instanceof \ReflectionMethod && \is_string($callable[0])) { + if ($r->isStatic()) { + $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1])); + } else { + $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); + } + } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) { + // For BC/FC with namespaced aliases + $class = (new \ReflectionClass(\get_class($callable[0])))->name; + if (!$compiler->getEnvironment()->hasExtension($class)) { + // Compile a non-optimized call to trigger a \Twig\Error\RuntimeError, which cannot be a compile-time error + $compiler->raw(sprintf('$this->env->getExtension(\'%s\')', $class)); + } else { + $compiler->raw(sprintf('$this->extensions[\'%s\']', ltrim($class, '\\'))); + } + + $compiler->raw(sprintf('->%s', $callable[1])); + } else { + $closingParenthesis = true; + $isArray = true; + $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', ucfirst($this->getAttribute('type')), $this->getAttribute('name'))); + } + } + + $this->compileArguments($compiler, $isArray); + + if ($closingParenthesis) { + $compiler->raw(')'); + } + } + + protected function compileArguments(Compiler $compiler, $isArray = false) + { + $compiler->raw($isArray ? '[' : '('); + + $first = true; + + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + $compiler->raw('$this->env'); + $first = false; + } + + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->raw('$context'); + $first = false; + } + + if ($this->hasAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->string($argument); + $first = false; + } + } + + if ($this->hasNode('node')) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->subcompile($this->getNode('node')); + $first = false; + } + + if ($this->hasNode('arguments')) { + $callable = $this->getAttribute('callable'); + $arguments = $this->getArguments($callable, $this->getNode('arguments')); + foreach ($arguments as $node) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->subcompile($node); + $first = false; + } + } + + $compiler->raw($isArray ? ']' : ')'); + } + + protected function getArguments($callable = null, $arguments) + { + $callType = $this->getAttribute('type'); + $callName = $this->getAttribute('name'); + + $parameters = []; + $named = false; + foreach ($arguments as $name => $node) { + if (!\is_int($name)) { + $named = true; + $name = $this->normalizeName($name); + } elseif ($named) { + throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + + $parameters[$name] = $node; + } + + $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic'); + if (!$named && !$isVariadic) { + return $parameters; + } + + if (!$callable) { + if ($named) { + $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName); + } else { + $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName); + } + + throw new \LogicException($message); + } + + list($callableParameters, $isPhpVariadic) = $this->getCallableParameters($callable, $isVariadic); + $arguments = []; + $names = []; + $missingArguments = []; + $optionalArguments = []; + $pos = 0; + foreach ($callableParameters as $callableParameter) { + $names[] = $name = $this->normalizeName($callableParameter->name); + + if (\array_key_exists($name, $parameters)) { + if (\array_key_exists($pos, $parameters)) { + throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + + if (\count($missingArguments)) { + throw new SyntaxError(sprintf( + 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', + $name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) + ), $this->getTemplateLine(), $this->getSourceContext()); + } + + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$name]; + unset($parameters[$name]); + $optionalArguments = []; + } elseif (\array_key_exists($pos, $parameters)) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$pos]; + unset($parameters[$pos]); + $optionalArguments = []; + ++$pos; + } elseif ($callableParameter->isDefaultValueAvailable()) { + $optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1); + } elseif ($callableParameter->isOptional()) { + if (empty($parameters)) { + break; + } else { + $missingArguments[] = $name; + } + } else { + throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + } + + if ($isVariadic) { + $arbitraryArguments = $isPhpVariadic ? new VariadicExpression([], -1) : new ArrayExpression([], -1); + foreach ($parameters as $key => $value) { + if (\is_int($key)) { + $arbitraryArguments->addElement($value); + } else { + $arbitraryArguments->addElement($value, new ConstantExpression($key, -1)); + } + unset($parameters[$key]); + } + + if ($arbitraryArguments->count()) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $arbitraryArguments; + } + } + + if (!empty($parameters)) { + $unknownParameter = null; + foreach ($parameters as $parameter) { + if ($parameter instanceof Node) { + $unknownParameter = $parameter; + break; + } + } + + throw new SyntaxError( + sprintf( + 'Unknown argument%s "%s" for %s "%s(%s)".', + \count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) + ), + $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(), + $unknownParameter ? $unknownParameter->getSourceContext() : $this->getSourceContext() + ); + } + + return $arguments; + } + + protected function normalizeName($name) + { + return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); + } + + private function getCallableParameters($callable, bool $isVariadic): array + { + list($r) = $this->reflectCallable($callable); + if (null === $r) { + return [[], false]; + } + + $parameters = $r->getParameters(); + if ($this->hasNode('node')) { + array_shift($parameters); + } + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + array_shift($parameters); + } + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + array_shift($parameters); + } + if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + array_shift($parameters); + } + } + $isPhpVariadic = false; + if ($isVariadic) { + $argument = end($parameters); + if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { + array_pop($parameters); + } elseif ($argument && $argument->isVariadic()) { + array_pop($parameters); + $isPhpVariadic = true; + } else { + $callableName = $r->name; + if ($r instanceof \ReflectionMethod) { + $callableName = $r->getDeclaringClass()->name.'::'.$callableName; + } + + throw new \LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); + } + } + + return [$parameters, $isPhpVariadic]; + } + + private function reflectCallable($callable) + { + if (null !== $this->reflector) { + return $this->reflector; + } + + if (\is_array($callable)) { + if (!method_exists($callable[0], $callable[1])) { + // __call() + return [null, []]; + } + $r = new \ReflectionMethod($callable[0], $callable[1]); + } elseif (\is_object($callable) && !$callable instanceof \Closure) { + $r = new \ReflectionObject($callable); + $r = $r->getMethod('__invoke'); + $callable = [$callable, '__invoke']; + } elseif (\is_string($callable) && false !== $pos = strpos($callable, '::')) { + $class = substr($callable, 0, $pos); + $method = substr($callable, $pos + 2); + if (!method_exists($class, $method)) { + // __staticCall() + return [null, []]; + } + $r = new \ReflectionMethod($callable); + $callable = [$class, $method]; + } else { + $r = new \ReflectionFunction($callable); + } + + return $this->reflector = [$r, $callable]; + } +} + +class_alias('Twig\Node\Expression\CallExpression', 'Twig_Node_Expression_Call'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConditionalExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConditionalExpression.php new file mode 100644 index 0000000..8c367d3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConditionalExpression.php @@ -0,0 +1,38 @@ + $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('((') + ->subcompile($this->getNode('expr1')) + ->raw(') ? (') + ->subcompile($this->getNode('expr2')) + ->raw(') : (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } +} + +class_alias('Twig\Node\Expression\ConditionalExpression', 'Twig_Node_Expression_Conditional'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConstantExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConstantExpression.php new file mode 100644 index 0000000..46e0ac3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ConstantExpression.php @@ -0,0 +1,30 @@ + $value], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler->repr($this->getAttribute('value')); + } +} + +class_alias('Twig\Node\Expression\ConstantExpression', 'Twig_Node_Expression_Constant'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php new file mode 100644 index 0000000..0dacae8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php @@ -0,0 +1,54 @@ + + */ +class DefaultFilter extends FilterExpression +{ + public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null) + { + $default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); + + if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) { + $test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine()); + $false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine()); + + $node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine()); + } else { + $node = $default; + } + + parent::__construct($node, $filterName, $arguments, $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->subcompile($this->getNode('node')); + } +} + +class_alias('Twig\Node\Expression\Filter\DefaultFilter', 'Twig_Node_Expression_Filter_Default'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FilterExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FilterExpression.php new file mode 100644 index 0000000..41b0734 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FilterExpression.php @@ -0,0 +1,42 @@ + $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $name = $this->getNode('filter')->getAttribute('value'); + $filter = $compiler->getEnvironment()->getFilter($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'filter'); + $this->setAttribute('needs_environment', $filter->needsEnvironment()); + $this->setAttribute('needs_context', $filter->needsContext()); + $this->setAttribute('arguments', $filter->getArguments()); + $this->setAttribute('callable', $filter->getCallable()); + $this->setAttribute('is_variadic', $filter->isVariadic()); + + $this->compileCallable($compiler); + } +} + +class_alias('Twig\Node\Expression\FilterExpression', 'Twig_Node_Expression_Filter'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FunctionExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FunctionExpression.php new file mode 100644 index 0000000..429dbb9 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/FunctionExpression.php @@ -0,0 +1,45 @@ + $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + $function = $compiler->getEnvironment()->getFunction($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'function'); + $this->setAttribute('needs_environment', $function->needsEnvironment()); + $this->setAttribute('needs_context', $function->needsContext()); + $this->setAttribute('arguments', $function->getArguments()); + $callable = $function->getCallable(); + if ('constant' === $name && $this->getAttribute('is_defined_test')) { + $callable = 'twig_constant_is_defined'; + } + $this->setAttribute('callable', $callable); + $this->setAttribute('is_variadic', $function->isVariadic()); + + $this->compileCallable($compiler); + } +} + +class_alias('Twig\Node\Expression\FunctionExpression', 'Twig_Node_Expression_Function'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/GetAttrExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/GetAttrExpression.php new file mode 100644 index 0000000..7b06617 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/GetAttrExpression.php @@ -0,0 +1,89 @@ + $node, 'attribute' => $attribute]; + if (null !== $arguments) { + $nodes['arguments'] = $arguments; + } + + parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'optimizable' => true], $lineno); + } + + public function compile(Compiler $compiler) + { + $env = $compiler->getEnvironment(); + + // optimize array calls + if ( + $this->getAttribute('optimizable') + && (!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check')) + && !$this->getAttribute('is_defined_test') + && Template::ARRAY_CALL === $this->getAttribute('type') + ) { + $var = '$'.$compiler->getVarName(); + $compiler + ->raw('(('.$var.' = ') + ->subcompile($this->getNode('node')) + ->raw(') && is_array(') + ->raw($var) + ->raw(') || ') + ->raw($var) + ->raw(' instanceof ArrayAccess ? (') + ->raw($var) + ->raw('[') + ->subcompile($this->getNode('attribute')) + ->raw('] ?? null) : null)') + ; + + return; + } + + $compiler->raw('twig_get_attribute($this->env, $this->source, '); + + if ($this->getAttribute('ignore_strict_check')) { + $this->getNode('node')->setAttribute('ignore_strict_check', true); + } + + $compiler + ->subcompile($this->getNode('node')) + ->raw(', ') + ->subcompile($this->getNode('attribute')) + ; + + if ($this->hasNode('arguments')) { + $compiler->raw(', ')->subcompile($this->getNode('arguments')); + } else { + $compiler->raw(', []'); + } + + $compiler->raw(', ') + ->repr($this->getAttribute('type')) + ->raw(', ')->repr($this->getAttribute('is_defined_test')) + ->raw(', ')->repr($this->getAttribute('ignore_strict_check')) + ->raw(', ')->repr($env->hasExtension(SandboxExtension::class)) + ->raw(', ')->repr($this->getNode('node')->getTemplateLine()) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\GetAttrExpression', 'Twig_Node_Expression_GetAttr'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/InlinePrint.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/InlinePrint.php new file mode 100644 index 0000000..469e736 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/InlinePrint.php @@ -0,0 +1,35 @@ + $node], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('print (') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/MethodCallExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/MethodCallExpression.php new file mode 100644 index 0000000..d5287f8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/MethodCallExpression.php @@ -0,0 +1,64 @@ + $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false, 'is_defined_test' => false], $lineno); + + if ($node instanceof NameExpression) { + $node->setAttribute('always_defined', true); + } + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('is_defined_test')) { + $compiler + ->raw('method_exists($macros[') + ->repr($this->getNode('node')->getAttribute('name')) + ->raw('], ') + ->repr($this->getAttribute('method')) + ->raw(')') + ; + + return; + } + + $compiler + ->raw('twig_call_macro($macros[') + ->repr($this->getNode('node')->getAttribute('name')) + ->raw('], ') + ->repr($this->getAttribute('method')) + ->raw(', [') + ; + $first = true; + foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { + if (!$first) { + $compiler->raw(', '); + } + $first = false; + + $compiler->subcompile($pair['value']); + } + $compiler + ->raw('], ') + ->repr($this->getTemplateLine()) + ->raw(', $context, $this->getSourceContext())'); + } +} + +class_alias('Twig\Node\Expression\MethodCallExpression', 'Twig_Node_Expression_MethodCall'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NameExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NameExpression.php new file mode 100644 index 0000000..ff7a046 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NameExpression.php @@ -0,0 +1,99 @@ + '$this->getTemplateName()', + '_context' => '$context', + '_charset' => '$this->env->getCharset()', + ]; + + public function __construct(string $name, int $lineno) + { + parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + + $compiler->addDebugInfo($this); + + if ($this->getAttribute('is_defined_test')) { + if ($this->isSpecial()) { + $compiler->repr(true); + } elseif (\PHP_VERSION_ID >= 700400) { + $compiler + ->raw('array_key_exists(') + ->string($name) + ->raw(', $context)') + ; + } else { + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) || array_key_exists(') + ->string($name) + ->raw(', $context))') + ; + } + } elseif ($this->isSpecial()) { + $compiler->raw($this->specialVars[$name]); + } elseif ($this->getAttribute('always_defined')) { + $compiler + ->raw('$context[') + ->string($name) + ->raw(']') + ; + } else { + if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { + $compiler + ->raw('($context[') + ->string($name) + ->raw('] ?? null)') + ; + } else { + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) || array_key_exists(') + ->string($name) + ->raw(', $context) ? $context[') + ->string($name) + ->raw('] : (function () { throw new RuntimeError(\'Variable ') + ->string($name) + ->raw(' does not exist.\', ') + ->repr($this->lineno) + ->raw(', $this->source); })()') + ->raw(')') + ; + } + } + } + + public function isSpecial() + { + return isset($this->specialVars[$this->getAttribute('name')]); + } + + public function isSimple() + { + return !$this->isSpecial() && !$this->getAttribute('is_defined_test'); + } +} + +class_alias('Twig\Node\Expression\NameExpression', 'Twig_Node_Expression_Name'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NullCoalesceExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NullCoalesceExpression.php new file mode 100644 index 0000000..de03ff2 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/NullCoalesceExpression.php @@ -0,0 +1,62 @@ +getTemplateLine()); + // for "block()", we don't need the null test as the return value is always a string + if (!$left instanceof BlockReferenceExpression) { + $test = new AndBinary( + $test, + new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()), + $left->getTemplateLine() + ); + } + + parent::__construct($test, $left, $right, $lineno); + } + + public function compile(Compiler $compiler) + { + /* + * This optimizes only one case. PHP 7 also supports more complex expressions + * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works, + * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced + * cases might be implemented as an optimizer node visitor, but has not been done + * as benefits are probably not worth the added complexity. + */ + if ($this->getNode('expr2') instanceof NameExpression) { + $this->getNode('expr2')->setAttribute('always_defined', true); + $compiler + ->raw('((') + ->subcompile($this->getNode('expr2')) + ->raw(') ?? (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } else { + parent::compile($compiler); + } + } +} + +class_alias('Twig\Node\Expression\NullCoalesceExpression', 'Twig_Node_Expression_NullCoalesce'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ParentExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ParentExpression.php new file mode 100644 index 0000000..294ab39 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/ParentExpression.php @@ -0,0 +1,48 @@ + + */ +class ParentExpression extends AbstractExpression +{ + public function __construct(string $name, int $lineno, string $tag = null) + { + parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('output')) { + $compiler + ->addDebugInfo($this) + ->write('$this->displayParentBlock(') + ->string($this->getAttribute('name')) + ->raw(", \$context, \$blocks);\n") + ; + } else { + $compiler + ->raw('$this->renderParentBlock(') + ->string($this->getAttribute('name')) + ->raw(', $context, $blocks)') + ; + } + } +} + +class_alias('Twig\Node\Expression\ParentExpression', 'Twig_Node_Expression_Parent'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TempNameExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TempNameExpression.php new file mode 100644 index 0000000..e7a1a89 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TempNameExpression.php @@ -0,0 +1,33 @@ + $name], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->raw('$_') + ->raw($this->getAttribute('name')) + ->raw('_') + ; + } +} + +class_alias('Twig\Node\Expression\TempNameExpression', 'Twig_Node_Expression_TempName'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/ConstantTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/ConstantTest.php new file mode 100644 index 0000000..78353a8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/ConstantTest.php @@ -0,0 +1,51 @@ + + */ +class ConstantTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === constant(') + ; + + if ($this->getNode('arguments')->hasNode(1)) { + $compiler + ->raw('get_class(') + ->subcompile($this->getNode('arguments')->getNode(1)) + ->raw(')."::".') + ; + } + + $compiler + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw('))') + ; + } +} + +class_alias('Twig\Node\Expression\Test\ConstantTest', 'Twig_Node_Expression_Test_Constant'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DefinedTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DefinedTest.php new file mode 100644 index 0000000..7a89840 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DefinedTest.php @@ -0,0 +1,76 @@ + + */ +class DefinedTest extends TestExpression +{ + public function __construct(Node $node, string $name, Node $arguments = null, int $lineno) + { + if ($node instanceof NameExpression) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof GetAttrExpression) { + $node->setAttribute('is_defined_test', true); + $this->changeIgnoreStrictCheck($node); + } elseif ($node instanceof BlockReferenceExpression) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) { + $node = new ConstantExpression(true, $node->getTemplateLine()); + } elseif ($node instanceof MethodCallExpression) { + $node->setAttribute('is_defined_test', true); + } else { + throw new SyntaxError('The "defined" test only works with simple variables.', $lineno); + } + + parent::__construct($node, $name, $arguments, $lineno); + } + + private function changeIgnoreStrictCheck(GetAttrExpression $node) + { + $node->setAttribute('optimizable', false); + $node->setAttribute('ignore_strict_check', true); + + if ($node->getNode('node') instanceof GetAttrExpression) { + $this->changeIgnoreStrictCheck($node->getNode('node')); + } + } + + public function compile(Compiler $compiler) + { + $compiler->subcompile($this->getNode('node')); + } +} + +class_alias('Twig\Node\Expression\Test\DefinedTest', 'Twig_Node_Expression_Test_Defined'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php new file mode 100644 index 0000000..05c8ad8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php @@ -0,0 +1,38 @@ + + */ +class DivisiblebyTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(0 == ') + ->subcompile($this->getNode('node')) + ->raw(' % ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\DivisiblebyTest', 'Twig_Node_Expression_Test_Divisibleby'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/EvenTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/EvenTest.php new file mode 100644 index 0000000..3b955d2 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/EvenTest.php @@ -0,0 +1,37 @@ + + */ +class EvenTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 0') + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\EvenTest', 'Twig_Node_Expression_Test_Even'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/NullTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/NullTest.php new file mode 100644 index 0000000..24d3997 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/NullTest.php @@ -0,0 +1,36 @@ + + */ +class NullTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(null === ') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\NullTest', 'Twig_Node_Expression_Test_Null'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/OddTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/OddTest.php new file mode 100644 index 0000000..2dc693a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/OddTest.php @@ -0,0 +1,37 @@ + + */ +class OddTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 1') + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\OddTest', 'Twig_Node_Expression_Test_Odd'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/SameasTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/SameasTest.php new file mode 100644 index 0000000..75f2b82 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Test/SameasTest.php @@ -0,0 +1,36 @@ + + */ +class SameasTest extends TestExpression +{ + public function compile(Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} + +class_alias('Twig\Node\Expression\Test\SameasTest', 'Twig_Node_Expression_Test_Sameas'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TestExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TestExpression.php new file mode 100644 index 0000000..50aab05 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/TestExpression.php @@ -0,0 +1,44 @@ + $node]; + if (null !== $arguments) { + $nodes['arguments'] = $arguments; + } + + parent::__construct($nodes, ['name' => $name], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + $test = $compiler->getEnvironment()->getTest($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'test'); + $this->setAttribute('arguments', $test->getArguments()); + $this->setAttribute('callable', $test->getCallable()); + $this->setAttribute('is_variadic', $test->isVariadic()); + + $this->compileCallable($compiler); + } +} + +class_alias('Twig\Node\Expression\TestExpression', 'Twig_Node_Expression_Test'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php new file mode 100644 index 0000000..4896280 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php @@ -0,0 +1,36 @@ + $node], [], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler->raw(' '); + $this->operator($compiler); + $compiler->subcompile($this->getNode('node')); + } + + abstract public function operator(Compiler $compiler); +} + +class_alias('Twig\Node\Expression\Unary\AbstractUnary', 'Twig_Node_Expression_Unary'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NegUnary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NegUnary.php new file mode 100644 index 0000000..dfb6f54 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NegUnary.php @@ -0,0 +1,25 @@ +raw('-'); + } +} + +class_alias('Twig\Node\Expression\Unary\NegUnary', 'Twig_Node_Expression_Unary_Neg'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NotUnary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NotUnary.php new file mode 100644 index 0000000..7bdde96 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/NotUnary.php @@ -0,0 +1,25 @@ +raw('!'); + } +} + +class_alias('Twig\Node\Expression\Unary\NotUnary', 'Twig_Node_Expression_Unary_Not'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/PosUnary.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/PosUnary.php new file mode 100644 index 0000000..52d5d0c --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/Unary/PosUnary.php @@ -0,0 +1,25 @@ +raw('+'); + } +} + +class_alias('Twig\Node\Expression\Unary\PosUnary', 'Twig_Node_Expression_Unary_Pos'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/VariadicExpression.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/VariadicExpression.php new file mode 100644 index 0000000..3351e1a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Expression/VariadicExpression.php @@ -0,0 +1,24 @@ +raw('...'); + + parent::compile($compiler); + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/FlushNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/FlushNode.php new file mode 100644 index 0000000..b88f340 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/FlushNode.php @@ -0,0 +1,37 @@ + + */ +class FlushNode extends Node +{ + public function __construct(int $lineno, string $tag) + { + parent::__construct([], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("flush();\n") + ; + } +} + +class_alias('Twig\Node\FlushNode', 'Twig_Node_Flush'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForLoopNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForLoopNode.php new file mode 100644 index 0000000..42aedd7 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForLoopNode.php @@ -0,0 +1,56 @@ + + */ +class ForLoopNode extends Node +{ + public function __construct(int $lineno, string $tag = null) + { + parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + if ($this->getAttribute('else')) { + $compiler->write("\$context['_iterated'] = true;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("++\$context['loop']['index0'];\n") + ->write("++\$context['loop']['index'];\n") + ->write("\$context['loop']['first'] = false;\n") + ; + + if (!$this->getAttribute('ifexpr')) { + $compiler + ->write("if (isset(\$context['loop']['length'])) {\n") + ->indent() + ->write("--\$context['loop']['revindex0'];\n") + ->write("--\$context['loop']['revindex'];\n") + ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") + ->outdent() + ->write("}\n") + ; + } + } + } +} + +class_alias('Twig\Node\ForLoopNode', 'Twig_Node_ForLoop'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForNode.php new file mode 100644 index 0000000..54afe93 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ForNode.php @@ -0,0 +1,119 @@ + + */ +class ForNode extends Node +{ + private $loop; + + public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, Node $body, Node $else = null, int $lineno, string $tag = null) + { + $body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]); + + if (null !== $ifexpr) { + $body = new IfNode(new Node([$ifexpr, $body]), null, $lineno, $tag); + } + + $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; + if (null !== $else) { + $nodes['else'] = $else; + } + + parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("\$context['_parent'] = \$context;\n") + ->write("\$context['_seq'] = twig_ensure_traversable(") + ->subcompile($this->getNode('seq')) + ->raw(");\n") + ; + + if ($this->hasNode('else')) { + $compiler->write("\$context['_iterated'] = false;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("\$context['loop'] = [\n") + ->write(" 'parent' => \$context['_parent'],\n") + ->write(" 'index0' => 0,\n") + ->write(" 'index' => 1,\n") + ->write(" 'first' => true,\n") + ->write("];\n") + ; + + if (!$this->getAttribute('ifexpr')) { + $compiler + ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \Countable)) {\n") + ->indent() + ->write("\$length = count(\$context['_seq']);\n") + ->write("\$context['loop']['revindex0'] = \$length - 1;\n") + ->write("\$context['loop']['revindex'] = \$length;\n") + ->write("\$context['loop']['length'] = \$length;\n") + ->write("\$context['loop']['last'] = 1 === \$length;\n") + ->outdent() + ->write("}\n") + ; + } + } + + $this->loop->setAttribute('else', $this->hasNode('else')); + $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop')); + $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr')); + + $compiler + ->write("foreach (\$context['_seq'] as ") + ->subcompile($this->getNode('key_target')) + ->raw(' => ') + ->subcompile($this->getNode('value_target')) + ->raw(") {\n") + ->indent() + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n") + ; + + if ($this->hasNode('else')) { + $compiler + ->write("if (!\$context['_iterated']) {\n") + ->indent() + ->subcompile($this->getNode('else')) + ->outdent() + ->write("}\n") + ; + } + + $compiler->write("\$_parent = \$context['_parent'];\n"); + + // remove some "private" loop variables (needed for nested loops) + $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); + + // keep the values set in the inner context for variables defined in the outer context + $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n"); + } +} + +class_alias('Twig\Node\ForNode', 'Twig_Node_For'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IfNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IfNode.php new file mode 100644 index 0000000..814a6f3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IfNode.php @@ -0,0 +1,72 @@ + + */ +class IfNode extends Node +{ + public function __construct(Node $tests, Node $else = null, int $lineno, string $tag = null) + { + $nodes = ['tests' => $tests]; + if (null !== $else) { + $nodes['else'] = $else; + } + + parent::__construct($nodes, [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) { + if ($i > 0) { + $compiler + ->outdent() + ->write('} elseif (') + ; + } else { + $compiler + ->write('if (') + ; + } + + $compiler + ->subcompile($this->getNode('tests')->getNode($i)) + ->raw(") {\n") + ->indent() + ->subcompile($this->getNode('tests')->getNode($i + 1)) + ; + } + + if ($this->hasNode('else')) { + $compiler + ->outdent() + ->write("} else {\n") + ->indent() + ->subcompile($this->getNode('else')) + ; + } + + $compiler + ->outdent() + ->write("}\n"); + } +} + +class_alias('Twig\Node\IfNode', 'Twig_Node_If'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ImportNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ImportNode.php new file mode 100644 index 0000000..b661f43 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ImportNode.php @@ -0,0 +1,65 @@ + + */ +class ImportNode extends Node +{ + public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, string $tag = null, bool $global = true) + { + parent::__construct(['expr' => $expr, 'var' => $var], ['global' => $global], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('$macros[') + ->repr($this->getNode('var')->getAttribute('name')) + ->raw('] = ') + ; + + if ($this->getAttribute('global')) { + $compiler + ->raw('$this->macros[') + ->repr($this->getNode('var')->getAttribute('name')) + ->raw('] = ') + ; + } + + if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) { + $compiler->raw('$this'); + } else { + $compiler + ->raw('$this->loadTemplate(') + ->subcompile($this->getNode('expr')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')->unwrap()') + ; + } + + $compiler->raw(";\n"); + } +} + +class_alias('Twig\Node\ImportNode', 'Twig_Node_Import'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IncludeNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IncludeNode.php new file mode 100644 index 0000000..d453030 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/IncludeNode.php @@ -0,0 +1,108 @@ + + */ +class IncludeNode extends Node implements NodeOutputInterface +{ + public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, bool $only = false, bool $ignoreMissing = false, int $lineno, string $tag = null) + { + $nodes = ['expr' => $expr]; + if (null !== $variables) { + $nodes['variables'] = $variables; + } + + parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if ($this->getAttribute('ignore_missing')) { + $template = $compiler->getVarName(); + + $compiler + ->write(sprintf("$%s = null;\n", $template)) + ->write("try {\n") + ->indent() + ->write(sprintf('$%s = ', $template)) + ; + + $this->addGetTemplate($compiler); + + $compiler + ->raw(";\n") + ->outdent() + ->write("} catch (LoaderError \$e) {\n") + ->indent() + ->write("// ignore missing template\n") + ->outdent() + ->write("}\n") + ->write(sprintf("if ($%s) {\n", $template)) + ->indent() + ->write(sprintf('$%s->display(', $template)) + ; + $this->addTemplateArguments($compiler); + $compiler + ->raw(");\n") + ->outdent() + ->write("}\n") + ; + } else { + $this->addGetTemplate($compiler); + $compiler->raw('->display('); + $this->addTemplateArguments($compiler); + $compiler->raw(");\n"); + } + } + + protected function addGetTemplate(Compiler $compiler) + { + $compiler + ->write('$this->loadTemplate(') + ->subcompile($this->getNode('expr')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')') + ; + } + + protected function addTemplateArguments(Compiler $compiler) + { + if (!$this->hasNode('variables')) { + $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('twig_array_merge($context, ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; + } else { + $compiler->raw('twig_to_array('); + $compiler->subcompile($this->getNode('variables')); + $compiler->raw(')'); + } + } +} + +class_alias('Twig\Node\IncludeNode', 'Twig_Node_Include'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/MacroNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/MacroNode.php new file mode 100644 index 0000000..a133720 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/MacroNode.php @@ -0,0 +1,115 @@ + + */ +class MacroNode extends Node +{ + const VARARGS_NAME = 'varargs'; + + public function __construct(string $name, Node $body, Node $arguments, int $lineno, string $tag = null) + { + foreach ($arguments as $argumentName => $argument) { + if (self::VARARGS_NAME === $argumentName) { + throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine(), $argument->getSourceContext()); + } + } + + parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf('public function macro_%s(', $this->getAttribute('name'))) + ; + + $count = \count($this->getNode('arguments')); + $pos = 0; + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->raw('$__'.$name.'__ = ') + ->subcompile($default) + ; + + if (++$pos < $count) { + $compiler->raw(', '); + } + } + + if ($count) { + $compiler->raw(', '); + } + + $compiler + ->raw('...$__varargs__') + ->raw(")\n") + ->write("{\n") + ->indent() + ->write("\$macros = \$this->macros;\n") + ->write("\$context = \$this->env->mergeGlobals([\n") + ->indent() + ; + + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->write('') + ->string($name) + ->raw(' => $__'.$name.'__') + ->raw(",\n") + ; + } + + $compiler + ->write('') + ->string(self::VARARGS_NAME) + ->raw(' => ') + ; + + $compiler + ->raw("\$__varargs__,\n") + ->outdent() + ->write("]);\n\n") + ->write("\$blocks = [];\n\n") + ; + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->write("try {\n") + ->indent() + ->subcompile($this->getNode('body')) + ->raw("\n") + ->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n") + ->outdent() + ->write("} finally {\n") + ->indent() + ->write("ob_end_clean();\n") + ->outdent() + ->write("}\n") + ->outdent() + ->write("}\n\n") + ; + } +} + +class_alias('Twig\Node\MacroNode', 'Twig_Node_Macro'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ModuleNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ModuleNode.php new file mode 100644 index 0000000..b23a342 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/ModuleNode.php @@ -0,0 +1,472 @@ + + * + * @final since Twig 2.4.0 + */ +class ModuleNode extends Node +{ + public function __construct(Node $body, AbstractExpression $parent = null, Node $blocks, Node $macros, Node $traits, $embeddedTemplates, Source $source) + { + if (__CLASS__ !== \get_class($this)) { + @trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); + } + + $nodes = [ + 'body' => $body, + 'blocks' => $blocks, + 'macros' => $macros, + 'traits' => $traits, + 'display_start' => new Node(), + 'display_end' => new Node(), + 'constructor_start' => new Node(), + 'constructor_end' => new Node(), + 'class_end' => new Node(), + ]; + if (null !== $parent) { + $nodes['parent'] = $parent; + } + + // embedded templates are set as attributes so that they are only visited once by the visitors + parent::__construct($nodes, [ + 'index' => null, + 'embedded_templates' => $embeddedTemplates, + ], 1); + + // populate the template name of all node children + $this->setSourceContext($source); + } + + public function setIndex($index) + { + $this->setAttribute('index', $index); + } + + public function compile(Compiler $compiler) + { + $this->compileTemplate($compiler); + + foreach ($this->getAttribute('embedded_templates') as $template) { + $compiler->subcompile($template); + } + } + + protected function compileTemplate(Compiler $compiler) + { + if (!$this->getAttribute('index')) { + $compiler->write('compileClassHeader($compiler); + + $this->compileConstructor($compiler); + + $this->compileGetParent($compiler); + + $this->compileDisplay($compiler); + + $compiler->subcompile($this->getNode('blocks')); + + $this->compileMacros($compiler); + + $this->compileGetTemplateName($compiler); + + $this->compileIsTraitable($compiler); + + $this->compileDebugInfo($compiler); + + $this->compileGetSourceContext($compiler); + + $this->compileClassFooter($compiler); + } + + protected function compileGetParent(Compiler $compiler) + { + if (!$this->hasNode('parent')) { + return; + } + $parent = $this->getNode('parent'); + + $compiler + ->write("protected function doGetParent(array \$context)\n", "{\n") + ->indent() + ->addDebugInfo($parent) + ->write('return ') + ; + + if ($parent instanceof ConstantExpression) { + $compiler->subcompile($parent); + } else { + $compiler + ->raw('$this->loadTemplate(') + ->subcompile($parent) + ->raw(', ') + ->repr($this->getSourceContext()->getName()) + ->raw(', ') + ->repr($parent->getTemplateLine()) + ->raw(')') + ; + } + + $compiler + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassHeader(Compiler $compiler) + { + $compiler + ->write("\n\n") + ; + if (!$this->getAttribute('index')) { + $compiler + ->write("use Twig\Environment;\n") + ->write("use Twig\Error\LoaderError;\n") + ->write("use Twig\Error\RuntimeError;\n") + ->write("use Twig\Extension\SandboxExtension;\n") + ->write("use Twig\Markup;\n") + ->write("use Twig\Sandbox\SecurityError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedTagError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n") + ->write("use Twig\Source;\n") + ->write("use Twig\Template;\n\n") + ; + } + $compiler + // if the template name contains */, add a blank to avoid a PHP parse error + ->write('/* '.str_replace('*/', '* /', $this->getSourceContext()->getName())." */\n") + ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index'))) + ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass(false))) + ->write("{\n") + ->indent() + ->write("private \$source;\n") + ->write("private \$macros = [];\n\n") + ; + } + + protected function compileConstructor(Compiler $compiler) + { + $compiler + ->write("public function __construct(Environment \$env)\n", "{\n") + ->indent() + ->subcompile($this->getNode('constructor_start')) + ->write("parent::__construct(\$env);\n\n") + ->write("\$this->source = \$this->getSourceContext();\n\n") + ; + + // parent + if (!$this->hasNode('parent')) { + $compiler->write("\$this->parent = false;\n\n"); + } + + $countTraits = \count($this->getNode('traits')); + if ($countTraits) { + // traits + foreach ($this->getNode('traits') as $i => $trait) { + $node = $trait->getNode('template'); + + $compiler + ->addDebugInfo($node) + ->write(sprintf('$_trait_%s = $this->loadTemplate(', $i)) + ->subcompile($node) + ->raw(', ') + ->repr($node->getTemplateName()) + ->raw(', ') + ->repr($node->getTemplateLine()) + ->raw(");\n") + ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) + ->indent() + ->write("throw new RuntimeError('Template \"'.") + ->subcompile($trait->getNode('template')) + ->raw(".'\" cannot be used as a trait.', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->source);\n") + ->outdent() + ->write("}\n") + ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i)) + ; + + foreach ($trait->getNode('targets') as $key => $value) { + $compiler + ->write(sprintf('if (!isset($_trait_%s_blocks[', $i)) + ->string($key) + ->raw("])) {\n") + ->indent() + ->write("throw new RuntimeError('Block ") + ->string($key) + ->raw(' is not defined in trait ') + ->subcompile($trait->getNode('template')) + ->raw(".', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->source);\n") + ->outdent() + ->write("}\n\n") + + ->write(sprintf('$_trait_%s_blocks[', $i)) + ->subcompile($value) + ->raw(sprintf('] = $_trait_%s_blocks[', $i)) + ->string($key) + ->raw(sprintf(']; unset($_trait_%s_blocks[', $i)) + ->string($key) + ->raw("]);\n\n") + ; + } + } + + if ($countTraits > 1) { + $compiler + ->write("\$this->traits = array_merge(\n") + ->indent() + ; + + for ($i = 0; $i < $countTraits; ++$i) { + $compiler + ->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i)) + ; + } + + $compiler + ->outdent() + ->write(");\n\n") + ; + } else { + $compiler + ->write("\$this->traits = \$_trait_0_blocks;\n\n") + ; + } + + $compiler + ->write("\$this->blocks = array_merge(\n") + ->indent() + ->write("\$this->traits,\n") + ->write("[\n") + ; + } else { + $compiler + ->write("\$this->blocks = [\n") + ; + } + + // blocks + $compiler + ->indent() + ; + + foreach ($this->getNode('blocks') as $name => $node) { + $compiler + ->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name)) + ; + } + + if ($countTraits) { + $compiler + ->outdent() + ->write("]\n") + ->outdent() + ->write(");\n") + ; + } else { + $compiler + ->outdent() + ->write("];\n") + ; + } + + $compiler + ->subcompile($this->getNode('constructor_end')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileDisplay(Compiler $compiler) + { + $compiler + ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") + ->indent() + ->write("\$macros = \$this->macros;\n") + ->subcompile($this->getNode('display_start')) + ->subcompile($this->getNode('body')) + ; + + if ($this->hasNode('parent')) { + $parent = $this->getNode('parent'); + + $compiler->addDebugInfo($parent); + if ($parent instanceof ConstantExpression) { + $compiler + ->write('$this->parent = $this->loadTemplate(') + ->subcompile($parent) + ->raw(', ') + ->repr($this->getSourceContext()->getName()) + ->raw(', ') + ->repr($parent->getTemplateLine()) + ->raw(");\n") + ; + $compiler->write('$this->parent'); + } else { + $compiler->write('$this->getParent($context)'); + } + $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n"); + } + + $compiler + ->subcompile($this->getNode('display_end')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassFooter(Compiler $compiler) + { + $compiler + ->subcompile($this->getNode('class_end')) + ->outdent() + ->write("}\n") + ; + } + + protected function compileMacros(Compiler $compiler) + { + $compiler->subcompile($this->getNode('macros')); + } + + protected function compileGetTemplateName(Compiler $compiler) + { + $compiler + ->write("public function getTemplateName()\n", "{\n") + ->indent() + ->write('return ') + ->repr($this->getSourceContext()->getName()) + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileIsTraitable(Compiler $compiler) + { + // A template can be used as a trait if: + // * it has no parent + // * it has no macros + // * it has no body + // + // Put another way, a template can be used as a trait if it + // only contains blocks and use statements. + $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros')); + if ($traitable) { + if ($this->getNode('body') instanceof BodyNode) { + $nodes = $this->getNode('body')->getNode(0); + } else { + $nodes = $this->getNode('body'); + } + + if (!\count($nodes)) { + $nodes = new Node([$nodes]); + } + + foreach ($nodes as $node) { + if (!\count($node)) { + continue; + } + + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { + continue; + } + + if ($node instanceof BlockReferenceNode) { + continue; + } + + $traitable = false; + break; + } + } + + if ($traitable) { + return; + } + + $compiler + ->write("public function isTraitable()\n", "{\n") + ->indent() + ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileDebugInfo(Compiler $compiler) + { + $compiler + ->write("public function getDebugInfo()\n", "{\n") + ->indent() + ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true)))) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileGetSourceContext(Compiler $compiler) + { + $compiler + ->write("public function getSourceContext()\n", "{\n") + ->indent() + ->write('return new Source(') + ->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '') + ->raw(', ') + ->string($this->getSourceContext()->getName()) + ->raw(', ') + ->string($this->getSourceContext()->getPath()) + ->raw(");\n") + ->outdent() + ->write("}\n") + ; + } + + protected function compileLoadTemplate(Compiler $compiler, $node, $var) + { + if ($node instanceof ConstantExpression) { + $compiler + ->write(sprintf('%s = $this->loadTemplate(', $var)) + ->subcompile($node) + ->raw(', ') + ->repr($node->getTemplateName()) + ->raw(', ') + ->repr($node->getTemplateLine()) + ->raw(");\n") + ; + } else { + throw new \LogicException('Trait templates can only be constant nodes.'); + } + } +} + +class_alias('Twig\Node\ModuleNode', 'Twig_Node_Module'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Node.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Node.php new file mode 100644 index 0000000..909a687 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/Node.php @@ -0,0 +1,211 @@ + + */ +class Node implements \Countable, \IteratorAggregate +{ + protected $nodes; + protected $attributes; + protected $lineno; + protected $tag; + + private $name; + private $sourceContext; + + /** + * @param array $nodes An array of named nodes + * @param array $attributes An array of attributes (should not be nodes) + * @param int $lineno The line number + * @param string $tag The tag name associated with the Node + */ + public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0, string $tag = null) + { + foreach ($nodes as $name => $node) { + if (!$node instanceof self) { + throw new \InvalidArgumentException(sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, \get_class($this))); + } + } + $this->nodes = $nodes; + $this->attributes = $attributes; + $this->lineno = $lineno; + $this->tag = $tag; + } + + public function __toString() + { + $attributes = []; + foreach ($this->attributes as $name => $value) { + $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); + } + + $repr = [\get_class($this).'('.implode(', ', $attributes)]; + + if (\count($this->nodes)) { + foreach ($this->nodes as $name => $node) { + $len = \strlen($name) + 4; + $noderepr = []; + foreach (explode("\n", (string) $node) as $line) { + $noderepr[] = str_repeat(' ', $len).$line; + } + + $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr))); + } + + $repr[] = ')'; + } else { + $repr[0] .= ')'; + } + + return implode("\n", $repr); + } + + public function compile(Compiler $compiler) + { + foreach ($this->nodes as $node) { + $node->compile($compiler); + } + } + + public function getTemplateLine() + { + return $this->lineno; + } + + public function getNodeTag() + { + return $this->tag; + } + + /** + * @return bool + */ + public function hasAttribute($name) + { + return \array_key_exists($name, $this->attributes); + } + + /** + * @return mixed + */ + public function getAttribute($name) + { + if (!\array_key_exists($name, $this->attributes)) { + throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, \get_class($this))); + } + + return $this->attributes[$name]; + } + + /** + * @param string $name + * @param mixed $value + */ + public function setAttribute($name, $value) + { + $this->attributes[$name] = $value; + } + + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + + /** + * @return bool + */ + public function hasNode($name) + { + return isset($this->nodes[$name]); + } + + /** + * @return Node + */ + public function getNode($name) + { + if (!isset($this->nodes[$name])) { + throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, \get_class($this))); + } + + return $this->nodes[$name]; + } + + public function setNode($name, self $node) + { + $this->nodes[$name] = $node; + } + + public function removeNode($name) + { + unset($this->nodes[$name]); + } + + public function count() + { + return \count($this->nodes); + } + + public function getIterator() + { + return new \ArrayIterator($this->nodes); + } + + /** + * @deprecated since 2.8 (to be removed in 3.0) + */ + public function setTemplateName($name/*, $triggerDeprecation = true */) + { + $triggerDeprecation = 2 > \func_num_args() || \func_get_arg(1); + if ($triggerDeprecation) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use setSourceContext() instead.', E_USER_DEPRECATED); + } + + $this->name = $name; + foreach ($this->nodes as $node) { + $node->setTemplateName($name, $triggerDeprecation); + } + } + + public function getTemplateName() + { + return $this->sourceContext ? $this->sourceContext->getName() : null; + } + + public function setSourceContext(Source $source) + { + $this->sourceContext = $source; + foreach ($this->nodes as $node) { + $node->setSourceContext($source); + } + + $this->setTemplateName($source->getName(), false); + } + + public function getSourceContext() + { + return $this->sourceContext; + } +} + +class_alias('Twig\Node\Node', 'Twig_Node'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Compiler'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeCaptureInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeCaptureInterface.php new file mode 100644 index 0000000..474003f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeCaptureInterface.php @@ -0,0 +1,23 @@ + + */ +interface NodeCaptureInterface +{ +} + +class_alias('Twig\Node\NodeCaptureInterface', 'Twig_NodeCaptureInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeOutputInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeOutputInterface.php new file mode 100644 index 0000000..8b046ee --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/NodeOutputInterface.php @@ -0,0 +1,23 @@ + + */ +interface NodeOutputInterface +{ +} + +class_alias('Twig\Node\NodeOutputInterface', 'Twig_NodeOutputInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/PrintNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/PrintNode.php new file mode 100644 index 0000000..fcc086a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/PrintNode.php @@ -0,0 +1,41 @@ + + */ +class PrintNode extends Node implements NodeOutputInterface +{ + public function __construct(AbstractExpression $expr, int $lineno, string $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} + +class_alias('Twig\Node\PrintNode', 'Twig_Node_Print'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxNode.php new file mode 100644 index 0000000..fe59313 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxNode.php @@ -0,0 +1,47 @@ + + */ +class SandboxNode extends Node +{ + public function __construct(Node $body, int $lineno, string $tag = null) + { + parent::__construct(['body' => $body], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {\n") + ->indent() + ->write("\$this->sandbox->enableSandbox();\n") + ->outdent() + ->write("}\n") + ->subcompile($this->getNode('body')) + ->write("if (!\$alreadySandboxed) {\n") + ->indent() + ->write("\$this->sandbox->disableSandbox();\n") + ->outdent() + ->write("}\n") + ; + } +} + +class_alias('Twig\Node\SandboxNode', 'Twig_Node_Sandbox'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxedPrintNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxedPrintNode.php new file mode 100644 index 0000000..54e92e6 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SandboxedPrintNode.php @@ -0,0 +1,54 @@ + + */ +class SandboxedPrintNode extends PrintNode +{ + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ; + $expr = $this->getNode('expr'); + if ($expr instanceof ConstantExpression) { + $compiler + ->subcompile($expr) + ->raw(";\n") + ; + } else { + $compiler + ->write('$this->extensions[SandboxExtension::class]->ensureToStringAllowed(') + ->subcompile($expr) + ->raw(', ') + ->repr($expr->getTemplateLine()) + ->raw(", \$this->source);\n") + ; + } + } +} + +class_alias('Twig\Node\SandboxedPrintNode', 'Twig_Node_SandboxedPrint'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SetNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SetNode.php new file mode 100644 index 0000000..3cf4615 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SetNode.php @@ -0,0 +1,107 @@ + + */ +class SetNode extends Node implements NodeCaptureInterface +{ + public function __construct(bool $capture, Node $names, Node $values, int $lineno, string $tag = null) + { + parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag); + + /* + * Optimizes the node when capture is used for a large block of text. + * + * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig\Markup("foo"); + */ + if ($this->getAttribute('capture')) { + $this->setAttribute('safe', true); + + $values = $this->getNode('values'); + if ($values instanceof TextNode) { + $this->setNode('values', new ConstantExpression($values->getAttribute('data'), $values->getTemplateLine())); + $this->setAttribute('capture', false); + } + } + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if (\count($this->getNode('names')) > 1) { + $compiler->write('list('); + foreach ($this->getNode('names') as $idx => $node) { + if ($idx) { + $compiler->raw(', '); + } + + $compiler->subcompile($node); + } + $compiler->raw(')'); + } else { + if ($this->getAttribute('capture')) { + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->subcompile($this->getNode('values')) + ; + } + + $compiler->subcompile($this->getNode('names'), false); + + if ($this->getAttribute('capture')) { + $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset())"); + } + } + + if (!$this->getAttribute('capture')) { + $compiler->raw(' = '); + + if (\count($this->getNode('names')) > 1) { + $compiler->write('['); + foreach ($this->getNode('values') as $idx => $value) { + if ($idx) { + $compiler->raw(', '); + } + + $compiler->subcompile($value); + } + $compiler->raw(']'); + } else { + if ($this->getAttribute('safe')) { + $compiler + ->raw("('' === \$tmp = ") + ->subcompile($this->getNode('values')) + ->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())") + ; + } else { + $compiler->subcompile($this->getNode('values')); + } + } + } + + $compiler->raw(";\n"); + } +} + +class_alias('Twig\Node\SetNode', 'Twig_Node_Set'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SpacelessNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SpacelessNode.php new file mode 100644 index 0000000..8fc4a2d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/SpacelessNode.php @@ -0,0 +1,49 @@ + + */ +class SpacelessNode extends Node implements NodeOutputInterface +{ + public function __construct(Node $body, int $lineno, string $tag = 'spaceless') + { + parent::__construct(['body' => $body], [], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ; + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->subcompile($this->getNode('body')) + ->write("echo trim(preg_replace('/>\s+<', ob_get_clean()));\n") + ; + } +} + +class_alias('Twig\Node\SpacelessNode', 'Twig_Node_Spaceless'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/TextNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/TextNode.php new file mode 100644 index 0000000..85640a5 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/TextNode.php @@ -0,0 +1,40 @@ + + */ +class TextNode extends Node implements NodeOutputInterface +{ + public function __construct(string $data, int $lineno) + { + parent::__construct([], ['data' => $data], $lineno); + } + + public function compile(Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->string($this->getAttribute('data')) + ->raw(";\n") + ; + } +} + +class_alias('Twig\Node\TextNode', 'Twig_Node_Text'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/WithNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/WithNode.php new file mode 100644 index 0000000..74d1ea0 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Node/WithNode.php @@ -0,0 +1,72 @@ + + */ +class WithNode extends Node +{ + public function __construct(Node $body, Node $variables = null, bool $only = false, int $lineno, string $tag = null) + { + $nodes = ['body' => $body]; + if (null !== $variables) { + $nodes['variables'] = $variables; + } + + parent::__construct($nodes, ['only' => $only], $lineno, $tag); + } + + public function compile(Compiler $compiler) + { + $compiler->addDebugInfo($this); + + if ($this->hasNode('variables')) { + $node = $this->getNode('variables'); + $varsName = $compiler->getVarName(); + $compiler + ->write(sprintf('$%s = ', $varsName)) + ->subcompile($node) + ->raw(";\n") + ->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName)) + ->indent() + ->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->getSourceContext());\n") + ->outdent() + ->write("}\n") + ->write(sprintf("\$%s = twig_to_array(\$%s);\n", $varsName, $varsName)) + ; + + if ($this->getAttribute('only')) { + $compiler->write("\$context = ['_parent' => \$context];\n"); + } else { + $compiler->write("\$context['_parent'] = \$context;\n"); + } + + $compiler->write(sprintf("\$context = \$this->env->mergeGlobals(array_merge(\$context, \$%s));\n", $varsName)); + } else { + $compiler->write("\$context['_parent'] = \$context;\n"); + } + + $compiler + ->subcompile($this->getNode('body')) + ->write("\$context = \$context['_parent'];\n") + ; + } +} + +class_alias('Twig\Node\WithNode', 'Twig_Node_With'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeTraverser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeTraverser.php new file mode 100644 index 0000000..625b049 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeTraverser.php @@ -0,0 +1,85 @@ + + */ +final class NodeTraverser +{ + private $env; + private $visitors = []; + + /** + * @param NodeVisitorInterface[] $visitors + */ + public function __construct(Environment $env, array $visitors = []) + { + $this->env = $env; + foreach ($visitors as $visitor) { + $this->addVisitor($visitor); + } + } + + public function addVisitor(NodeVisitorInterface $visitor) + { + $this->visitors[$visitor->getPriority()][] = $visitor; + } + + /** + * Traverses a node and calls the registered visitors. + */ + public function traverse(Node $node): Node + { + ksort($this->visitors); + foreach ($this->visitors as $visitors) { + foreach ($visitors as $visitor) { + $node = $this->traverseForVisitor($visitor, $node); + } + } + + return $node; + } + + /** + * @return Node|null + */ + private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node) + { + $node = $visitor->enterNode($node, $this->env); + + foreach ($node as $k => $n) { + if (false !== ($m = $this->traverseForVisitor($visitor, $n)) && null !== $m) { + if ($m !== $n) { + $node->setNode($k, $m); + } + } else { + if (false === $m) { + @trigger_error('Returning "false" to remove a Node from NodeVisitorInterface::leaveNode() is deprecated since Twig version 2.9; return "null" instead.', E_USER_DEPRECATED); + } + + $node->removeNode($k); + } + } + + return $visitor->leaveNode($node, $this->env); + } +} + +class_alias('Twig\NodeTraverser', 'Twig_NodeTraverser'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php new file mode 100644 index 0000000..9c6cb12 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php @@ -0,0 +1,51 @@ + + */ +abstract class AbstractNodeVisitor implements NodeVisitorInterface +{ + final public function enterNode(Node $node, Environment $env) + { + return $this->doEnterNode($node, $env); + } + + final public function leaveNode(Node $node, Environment $env) + { + return $this->doLeaveNode($node, $env); + } + + /** + * Called before child nodes are visited. + * + * @return Node The modified node + */ + abstract protected function doEnterNode(Node $node, Environment $env); + + /** + * Called after child nodes are visited. + * + * @return Node|null The modified node or null if the node must be removed + */ + abstract protected function doLeaveNode(Node $node, Environment $env); +} + +class_alias('Twig\NodeVisitor\AbstractNodeVisitor', 'Twig_BaseNodeVisitor'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php new file mode 100644 index 0000000..bfbfdc9 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php @@ -0,0 +1,208 @@ + + */ +final class EscaperNodeVisitor extends AbstractNodeVisitor +{ + private $statusStack = []; + private $blocks = []; + private $safeAnalysis; + private $traverser; + private $defaultStrategy = false; + private $safeVars = []; + + public function __construct() + { + $this->safeAnalysis = new SafeAnalysisNodeVisitor(); + } + + protected function doEnterNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + if ($env->hasExtension(EscaperExtension::class) && $defaultStrategy = $env->getExtension(EscaperExtension::class)->getDefaultStrategy($node->getTemplateName())) { + $this->defaultStrategy = $defaultStrategy; + } + $this->safeVars = []; + $this->blocks = []; + } elseif ($node instanceof AutoEscapeNode) { + $this->statusStack[] = $node->getAttribute('value'); + } elseif ($node instanceof BlockNode) { + $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); + } elseif ($node instanceof ImportNode) { + $this->safeVars[] = $node->getNode('var')->getAttribute('name'); + } + + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->defaultStrategy = false; + $this->safeVars = []; + $this->blocks = []; + } elseif ($node instanceof FilterExpression) { + return $this->preEscapeFilterNode($node, $env); + } elseif ($node instanceof PrintNode && false !== $type = $this->needEscaping($env)) { + $expression = $node->getNode('expr'); + if ($expression instanceof ConditionalExpression && $this->shouldUnwrapConditional($expression, $env, $type)) { + return new DoNode($this->unwrapConditional($expression, $env, $type), $expression->getTemplateLine()); + } + + return $this->escapePrintNode($node, $env, $type); + } + + if ($node instanceof AutoEscapeNode || $node instanceof BlockNode) { + array_pop($this->statusStack); + } elseif ($node instanceof BlockReferenceNode) { + $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); + } + + return $node; + } + + private function shouldUnwrapConditional(ConditionalExpression $expression, Environment $env, $type) + { + $expr2Safe = $this->isSafeFor($type, $expression->getNode('expr2'), $env); + $expr3Safe = $this->isSafeFor($type, $expression->getNode('expr3'), $env); + + return $expr2Safe !== $expr3Safe; + } + + private function unwrapConditional(ConditionalExpression $expression, Environment $env, $type) + { + // convert "echo a ? b : c" to "a ? echo b : echo c" recursively + $expr2 = $expression->getNode('expr2'); + if ($expr2 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr2, $env, $type)) { + $expr2 = $this->unwrapConditional($expr2, $env, $type); + } else { + $expr2 = $this->escapeInlinePrintNode(new InlinePrint($expr2, $expr2->getTemplateLine()), $env, $type); + } + $expr3 = $expression->getNode('expr3'); + if ($expr3 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr3, $env, $type)) { + $expr3 = $this->unwrapConditional($expr3, $env, $type); + } else { + $expr3 = $this->escapeInlinePrintNode(new InlinePrint($expr3, $expr3->getTemplateLine()), $env, $type); + } + + return new ConditionalExpression($expression->getNode('expr1'), $expr2, $expr3, $expression->getTemplateLine()); + } + + private function escapeInlinePrintNode(InlinePrint $node, Environment $env, $type) + { + $expression = $node->getNode('node'); + + if ($this->isSafeFor($type, $expression, $env)) { + return $node; + } + + return new InlinePrint($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); + } + + private function escapePrintNode(PrintNode $node, Environment $env, $type) + { + if (false === $type) { + return $node; + } + + $expression = $node->getNode('expr'); + + if ($this->isSafeFor($type, $expression, $env)) { + return $node; + } + + $class = \get_class($node); + + return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); + } + + private function preEscapeFilterNode(FilterExpression $filter, Environment $env) + { + $name = $filter->getNode('filter')->getAttribute('value'); + + $type = $env->getFilter($name)->getPreEscape(); + if (null === $type) { + return $filter; + } + + $node = $filter->getNode('node'); + if ($this->isSafeFor($type, $node, $env)) { + return $filter; + } + + $filter->setNode('node', $this->getEscaperFilter($type, $node)); + + return $filter; + } + + private function isSafeFor($type, Node $expression, $env) + { + $safe = $this->safeAnalysis->getSafe($expression); + + if (null === $safe) { + if (null === $this->traverser) { + $this->traverser = new NodeTraverser($env, [$this->safeAnalysis]); + } + + $this->safeAnalysis->setSafeVars($this->safeVars); + + $this->traverser->traverse($expression); + $safe = $this->safeAnalysis->getSafe($expression); + } + + return \in_array($type, $safe) || \in_array('all', $safe); + } + + private function needEscaping(Environment $env) + { + if (\count($this->statusStack)) { + return $this->statusStack[\count($this->statusStack) - 1]; + } + + return $this->defaultStrategy ? $this->defaultStrategy : false; + } + + private function getEscaperFilter(string $type, Node $node): FilterExpression + { + $line = $node->getTemplateLine(); + $name = new ConstantExpression('escape', $line); + $args = new Node([new ConstantExpression((string) $type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]); + + return new FilterExpression($node, $name, $args, $line); + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\NodeVisitor\EscaperNodeVisitor', 'Twig_NodeVisitor_Escaper'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php new file mode 100644 index 0000000..f41d463 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php @@ -0,0 +1,72 @@ + + */ +final class MacroAutoImportNodeVisitor implements NodeVisitorInterface +{ + private $inAModule = false; + private $hasMacroCalls = false; + + public function enterNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->inAModule = true; + $this->hasMacroCalls = false; + } + + return $node; + } + + public function leaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->inAModule = false; + if ($this->hasMacroCalls) { + $node->getNode('constructor_end')->setNode('_auto_macro_import', new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, 'import', true)); + } + } elseif ($this->inAModule) { + if ( + $node instanceof GetAttrExpression && + $node->getNode('node') instanceof NameExpression && + '_self' === $node->getNode('node')->getAttribute('name') && + $node->getNode('attribute') instanceof ConstantExpression + ) { + $this->hasMacroCalls = true; + + $name = $node->getNode('attribute')->getAttribute('value'); + $node = new MethodCallExpression($node->getNode('node'), 'macro_'.$name, $node->getNode('arguments'), $node->getTemplateLine()); + $node->setAttribute('safe', true); + } + } + + return $node; + } + + public function getPriority() + { + // we must be ran before auto-escaping + return -10; + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php new file mode 100644 index 0000000..e0ffae2 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php @@ -0,0 +1,51 @@ + + */ +interface NodeVisitorInterface +{ + /** + * Called before child nodes are visited. + * + * @return Node The modified node + */ + public function enterNode(Node $node, Environment $env); + + /** + * Called after child nodes are visited. + * + * @return Node|null The modified node or null if the node must be removed + */ + public function leaveNode(Node $node, Environment $env); + + /** + * Returns the priority for this visitor. + * + * Priority should be between -10 and 10 (0 is the default). + * + * @return int The priority level + */ + public function getPriority(); +} + +class_alias('Twig\NodeVisitor\NodeVisitorInterface', 'Twig_NodeVisitorInterface'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Environment'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php new file mode 100644 index 0000000..9f7cae4 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php @@ -0,0 +1,219 @@ + + */ +final class OptimizerNodeVisitor extends AbstractNodeVisitor +{ + const OPTIMIZE_ALL = -1; + const OPTIMIZE_NONE = 0; + const OPTIMIZE_FOR = 2; + const OPTIMIZE_RAW_FILTER = 4; + // obsolete, does not do anything + const OPTIMIZE_VAR_ACCESS = 8; + + private $loops = []; + private $loopsTargets = []; + private $optimizers; + + /** + * @param int $optimizers The optimizer mode + */ + public function __construct(int $optimizers = -1) + { + if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) { + throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers)); + } + + $this->optimizers = $optimizers; + } + + protected function doEnterNode(Node $node, Environment $env) + { + if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { + $this->enterOptimizeFor($node, $env); + } + + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { + $this->leaveOptimizeFor($node, $env); + } + + if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) { + $node = $this->optimizeRawFilter($node, $env); + } + + $node = $this->optimizePrintNode($node, $env); + + return $node; + } + + /** + * Optimizes print nodes. + * + * It replaces: + * + * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" + */ + private function optimizePrintNode(Node $node, Environment $env): Node + { + if (!$node instanceof PrintNode) { + return $node; + } + + $exprNode = $node->getNode('expr'); + if ( + $exprNode instanceof BlockReferenceExpression || + $exprNode instanceof ParentExpression + ) { + $exprNode->setAttribute('output', true); + + return $exprNode; + } + + return $node; + } + + /** + * Removes "raw" filters. + */ + private function optimizeRawFilter(Node $node, Environment $env): Node + { + if ($node instanceof FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { + return $node->getNode('node'); + } + + return $node; + } + + /** + * Optimizes "for" tag by removing the "loop" variable creation whenever possible. + */ + private function enterOptimizeFor(Node $node, Environment $env) + { + if ($node instanceof ForNode) { + // disable the loop variable by default + $node->setAttribute('with_loop', false); + array_unshift($this->loops, $node); + array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); + array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); + } elseif (!$this->loops) { + // we are outside a loop + return; + } + + // when do we need to add the loop variable back? + + // the loop variable is referenced for the current loop + elseif ($node instanceof NameExpression && 'loop' === $node->getAttribute('name')) { + $node->setAttribute('always_defined', true); + $this->addLoopToCurrent(); + } + + // optimize access to loop targets + elseif ($node instanceof NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) { + $node->setAttribute('always_defined', true); + } + + // block reference + elseif ($node instanceof BlockReferenceNode || $node instanceof BlockReferenceExpression) { + $this->addLoopToCurrent(); + } + + // include without the only attribute + elseif ($node instanceof IncludeNode && !$node->getAttribute('only')) { + $this->addLoopToAll(); + } + + // include function without the with_context=false parameter + elseif ($node instanceof FunctionExpression + && 'include' === $node->getAttribute('name') + && (!$node->getNode('arguments')->hasNode('with_context') + || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') + ) + ) { + $this->addLoopToAll(); + } + + // the loop variable is referenced via an attribute + elseif ($node instanceof GetAttrExpression + && (!$node->getNode('attribute') instanceof ConstantExpression + || 'parent' === $node->getNode('attribute')->getAttribute('value') + ) + && (true === $this->loops[0]->getAttribute('with_loop') + || ($node->getNode('node') instanceof NameExpression + && 'loop' === $node->getNode('node')->getAttribute('name') + ) + ) + ) { + $this->addLoopToAll(); + } + } + + /** + * Optimizes "for" tag by removing the "loop" variable creation whenever possible. + */ + private function leaveOptimizeFor(Node $node, Environment $env) + { + if ($node instanceof ForNode) { + array_shift($this->loops); + array_shift($this->loopsTargets); + array_shift($this->loopsTargets); + } + } + + private function addLoopToCurrent() + { + $this->loops[0]->setAttribute('with_loop', true); + } + + private function addLoopToAll() + { + foreach ($this->loops as $loop) { + $loop->setAttribute('with_loop', true); + } + } + + public function getPriority() + { + return 255; + } +} + +class_alias('Twig\NodeVisitor\OptimizerNodeVisitor', 'Twig_NodeVisitor_Optimizer'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php new file mode 100644 index 0000000..02a2af4 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php @@ -0,0 +1,160 @@ +safeVars = $safeVars; + } + + public function getSafe(Node $node) + { + $hash = spl_object_hash($node); + if (!isset($this->data[$hash])) { + return; + } + + foreach ($this->data[$hash] as $bucket) { + if ($bucket['key'] !== $node) { + continue; + } + + if (\in_array('html_attr', $bucket['value'])) { + $bucket['value'][] = 'html'; + } + + return $bucket['value']; + } + } + + private function setSafe(Node $node, array $safe) + { + $hash = spl_object_hash($node); + if (isset($this->data[$hash])) { + foreach ($this->data[$hash] as &$bucket) { + if ($bucket['key'] === $node) { + $bucket['value'] = $safe; + + return; + } + } + } + $this->data[$hash][] = [ + 'key' => $node, + 'value' => $safe, + ]; + } + + protected function doEnterNode(Node $node, Environment $env) + { + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ConstantExpression) { + // constants are marked safe for all + $this->setSafe($node, ['all']); + } elseif ($node instanceof BlockReferenceExpression) { + // blocks are safe by definition + $this->setSafe($node, ['all']); + } elseif ($node instanceof ParentExpression) { + // parent block is safe by definition + $this->setSafe($node, ['all']); + } elseif ($node instanceof ConditionalExpression) { + // intersect safeness of both operands + $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); + $this->setSafe($node, $safe); + } elseif ($node instanceof FilterExpression) { + // filter expression is safe when the filter is safe + $name = $node->getNode('filter')->getAttribute('value'); + $args = $node->getNode('arguments'); + if (false !== $filter = $env->getFilter($name)) { + $safe = $filter->getSafe($args); + if (null === $safe) { + $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety()); + } + $this->setSafe($node, $safe); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof FunctionExpression) { + // function expression is safe when the function is safe + $name = $node->getAttribute('name'); + $args = $node->getNode('arguments'); + $function = $env->getFunction($name); + if (false !== $function) { + $this->setSafe($node, $function->getSafe($args)); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof MethodCallExpression) { + if ($node->getAttribute('safe')) { + $this->setSafe($node, ['all']); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) { + $name = $node->getNode('node')->getAttribute('name'); + if (\in_array($name, $this->safeVars)) { + $this->setSafe($node, ['all']); + } else { + $this->setSafe($node, []); + } + } else { + $this->setSafe($node, []); + } + + return $node; + } + + private function intersectSafe(array $a = null, array $b = null): array + { + if (null === $a || null === $b) { + return []; + } + + if (\in_array('all', $a)) { + return $b; + } + + if (\in_array('all', $b)) { + return $a; + } + + return array_intersect($a, $b); + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\NodeVisitor\SafeAnalysisNodeVisitor', 'Twig_NodeVisitor_SafeAnalysis'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php new file mode 100644 index 0000000..3e8d0bc --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php @@ -0,0 +1,135 @@ + + */ +final class SandboxNodeVisitor extends AbstractNodeVisitor +{ + private $inAModule = false; + private $tags; + private $filters; + private $functions; + + private $needsToStringWrap = false; + + protected function doEnterNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->inAModule = true; + $this->tags = []; + $this->filters = []; + $this->functions = []; + + return $node; + } elseif ($this->inAModule) { + // look for tags + if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { + $this->tags[$node->getNodeTag()] = $node; + } + + // look for filters + if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { + $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; + } + + // look for functions + if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { + $this->functions[$node->getAttribute('name')] = $node; + } + + // the .. operator is equivalent to the range() function + if ($node instanceof RangeBinary && !isset($this->functions['range'])) { + $this->functions['range'] = $node; + } + + if ($node instanceof PrintNode) { + $this->needsToStringWrap = true; + $this->wrapNode($node, 'expr'); + } + + if ($node instanceof SetNode && !$node->getAttribute('capture')) { + $this->needsToStringWrap = true; + } + + // wrap outer nodes that can implicitly call __toString() + if ($this->needsToStringWrap) { + if ($node instanceof ConcatBinary) { + $this->wrapNode($node, 'left'); + $this->wrapNode($node, 'right'); + } + if ($node instanceof FilterExpression) { + $this->wrapNode($node, 'node'); + $this->wrapArrayNode($node, 'arguments'); + } + if ($node instanceof FunctionExpression) { + $this->wrapArrayNode($node, 'arguments'); + } + } + } + + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $this->inAModule = false; + + $node->getNode('constructor_end')->setNode('_security_check', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); + } elseif ($this->inAModule) { + if ($node instanceof PrintNode || $node instanceof SetNode) { + $this->needsToStringWrap = false; + } + } + + return $node; + } + + private function wrapNode(Node $node, string $name) + { + $expr = $node->getNode($name); + if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) { + $node->setNode($name, new CheckToStringNode($expr)); + } + } + + private function wrapArrayNode(Node $node, string $name) + { + $args = $node->getNode($name); + foreach ($args as $name => $_) { + $this->wrapNode($args, $name); + } + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\NodeVisitor\SandboxNodeVisitor', 'Twig_NodeVisitor_Sandbox'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Parser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Parser.php new file mode 100644 index 0000000..8a937e3 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Parser.php @@ -0,0 +1,394 @@ + + */ +class Parser +{ + private $stack = []; + private $stream; + private $parent; + private $handlers; + private $visitors; + private $expressionParser; + private $blocks; + private $blockStack; + private $macros; + private $env; + private $importedSymbols; + private $traits; + private $embeddedTemplates = []; + private $varNameSalt = 0; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + public function getVarName() + { + return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++)); + } + + public function parse(TokenStream $stream, $test = null, $dropNeedle = false) + { + $vars = get_object_vars($this); + unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']); + $this->stack[] = $vars; + + // tag handlers + if (null === $this->handlers) { + $this->handlers = []; + foreach ($this->env->getTokenParsers() as $handler) { + $handler->setParser($this); + + $this->handlers[$handler->getTag()] = $handler; + } + } + + // node visitors + if (null === $this->visitors) { + $this->visitors = $this->env->getNodeVisitors(); + } + + if (null === $this->expressionParser) { + $this->expressionParser = new ExpressionParser($this, $this->env); + } + + $this->stream = $stream; + $this->parent = null; + $this->blocks = []; + $this->macros = []; + $this->traits = []; + $this->blockStack = []; + $this->importedSymbols = [[]]; + $this->embeddedTemplates = []; + $this->varNameSalt = 0; + + try { + $body = $this->subparse($test, $dropNeedle); + + if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { + $body = new Node(); + } + } catch (SyntaxError $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($this->stream->getSourceContext()); + } + + if (!$e->getTemplateLine()) { + $e->setTemplateLine($this->stream->getCurrent()->getLine()); + } + + throw $e; + } + + $node = new ModuleNode(new BodyNode([$body]), $this->parent, new Node($this->blocks), new Node($this->macros), new Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); + + $traverser = new NodeTraverser($this->env, $this->visitors); + + $node = $traverser->traverse($node); + + // restore previous stack so previous parse() call can resume working + foreach (array_pop($this->stack) as $key => $val) { + $this->$key = $val; + } + + return $node; + } + + public function subparse($test, $dropNeedle = false) + { + $lineno = $this->getCurrentToken()->getLine(); + $rv = []; + while (!$this->stream->isEOF()) { + switch ($this->getCurrentToken()->getType()) { + case /* Token::TEXT_TYPE */ 0: + $token = $this->stream->next(); + $rv[] = new TextNode($token->getValue(), $token->getLine()); + break; + + case /* Token::VAR_START_TYPE */ 2: + $token = $this->stream->next(); + $expr = $this->expressionParser->parseExpression(); + $this->stream->expect(/* Token::VAR_END_TYPE */ 4); + $rv[] = new PrintNode($expr, $token->getLine()); + break; + + case /* Token::BLOCK_START_TYPE */ 1: + $this->stream->next(); + $token = $this->getCurrentToken(); + + if (/* Token::NAME_TYPE */ 5 !== $token->getType()) { + throw new SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); + } + + if (null !== $test && $test($token)) { + if ($dropNeedle) { + $this->stream->next(); + } + + if (1 === \count($rv)) { + return $rv[0]; + } + + return new Node($rv, [], $lineno); + } + + if (!isset($this->handlers[$token->getValue()])) { + if (null !== $test) { + $e = new SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + + if (\is_array($test) && isset($test[0]) && $test[0] instanceof TokenParserInterface) { + $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); + } + } else { + $e = new SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); + } + + throw $e; + } + + $this->stream->next(); + + $subparser = $this->handlers[$token->getValue()]; + $node = $subparser->parse($token); + if (null !== $node) { + $rv[] = $node; + } + break; + + default: + throw new SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); + } + } + + if (1 === \count($rv)) { + return $rv[0]; + } + + return new Node($rv, [], $lineno); + } + + public function getBlockStack() + { + return $this->blockStack; + } + + public function peekBlockStack() + { + return isset($this->blockStack[\count($this->blockStack) - 1]) ? $this->blockStack[\count($this->blockStack) - 1] : null; + } + + public function popBlockStack() + { + array_pop($this->blockStack); + } + + public function pushBlockStack($name) + { + $this->blockStack[] = $name; + } + + public function hasBlock($name) + { + return isset($this->blocks[$name]); + } + + public function getBlock($name) + { + return $this->blocks[$name]; + } + + public function setBlock($name, BlockNode $value) + { + $this->blocks[$name] = new BodyNode([$value], [], $value->getTemplateLine()); + } + + public function hasMacro($name) + { + return isset($this->macros[$name]); + } + + public function setMacro($name, MacroNode $node) + { + $this->macros[$name] = $node; + } + + /** + * @deprecated since Twig 2.7 as there are no reserved macro names anymore, will be removed in 3.0. + */ + public function isReservedMacroName($name) + { + @trigger_error(sprintf('The "%s" method is deprecated since Twig 2.7 and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED); + + return false; + } + + public function addTrait($trait) + { + $this->traits[] = $trait; + } + + public function hasTraits() + { + return \count($this->traits) > 0; + } + + public function embedTemplate(ModuleNode $template) + { + $template->setIndex(mt_rand()); + + $this->embeddedTemplates[] = $template; + } + + public function addImportedSymbol($type, $alias, $name = null, AbstractExpression $node = null) + { + $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; + } + + public function getImportedSymbol($type, $alias) + { + // if the symbol does not exist in the current scope (0), try in the main/global scope (last index) + return $this->importedSymbols[0][$type][$alias] ?? ($this->importedSymbols[\count($this->importedSymbols) - 1][$type][$alias] ?? null); + } + + public function isMainScope() + { + return 1 === \count($this->importedSymbols); + } + + public function pushLocalScope() + { + array_unshift($this->importedSymbols, []); + } + + public function popLocalScope() + { + array_shift($this->importedSymbols); + } + + /** + * @return ExpressionParser + */ + public function getExpressionParser() + { + return $this->expressionParser; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + } + + /** + * @return TokenStream + */ + public function getStream() + { + return $this->stream; + } + + /** + * @return Token + */ + public function getCurrentToken() + { + return $this->stream->getCurrent(); + } + + private function filterBodyNodes(Node $node, bool $nested = false) + { + // check that the body does not contain non-empty output nodes + if ( + ($node instanceof TextNode && !ctype_space($node->getAttribute('data'))) + || + // the "&& !$node instanceof SpacelessNode" part of the condition must be removed in 3.0 + (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && ($node instanceof NodeOutputInterface && !$node instanceof SpacelessNode)) + ) { + if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { + $t = substr($node->getAttribute('data'), 3); + if ('' === $t || ctype_space($t)) { + // bypass empty nodes starting with a BOM + return; + } + } + + throw new SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); + } + + // bypass nodes that "capture" the output + if ($node instanceof NodeCaptureInterface) { + // a "block" tag in such a node will serve as a block definition AND be displayed in place as well + return $node; + } + + // to be removed completely in Twig 3.0 + if (!$nested && $node instanceof SpacelessNode) { + @trigger_error(sprintf('Using the spaceless tag at the root level of a child template in "%s" at line %d is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.', $this->stream->getSourceContext()->getName(), $node->getTemplateLine()), E_USER_DEPRECATED); + } + + // "block" tags that are not captured (see above) are only used for defining + // the content of the block. In such a case, nesting it does not work as + // expected as the definition is not part of the default template code flow. + if ($nested && ($node instanceof BlockReferenceNode || $node instanceof \Twig_Node_BlockReference)) { + //throw new SyntaxError('A block definition cannot be nested under non-capturing nodes.', $node->getTemplateLine(), $this->stream->getSourceContext()); + @trigger_error(sprintf('Nesting a block definition under a non-capturing node in "%s" at line %d is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.', $this->stream->getSourceContext()->getName(), $node->getTemplateLine()), E_USER_DEPRECATED); + + return; + } + + // the "&& !$node instanceof SpacelessNode" part of the condition must be removed in 3.0 + if ($node instanceof NodeOutputInterface && !$node instanceof SpacelessNode) { + return; + } + + // here, $nested means "being at the root level of a child template" + // we need to discard the wrapping "Twig_Node" for the "body" node + $nested = $nested || ('Twig_Node' !== \get_class($node) && Node::class !== \get_class($node)); + foreach ($node as $k => $n) { + if (null !== $n && null === $this->filterBodyNodes($n, $nested)) { + $node->removeNode($k); + } + } + + return $node; + } +} + +class_alias('Twig\Parser', 'Twig_Parser'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BaseDumper.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BaseDumper.php new file mode 100644 index 0000000..1631987 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BaseDumper.php @@ -0,0 +1,65 @@ + + */ +abstract class BaseDumper +{ + private $root; + + public function dump(Profile $profile) + { + return $this->dumpProfile($profile); + } + + abstract protected function formatTemplate(Profile $profile, $prefix); + + abstract protected function formatNonTemplate(Profile $profile, $prefix); + + abstract protected function formatTime(Profile $profile, $percent); + + private function dumpProfile(Profile $profile, $prefix = '', $sibling = false): string + { + if ($profile->isRoot()) { + $this->root = $profile->getDuration(); + $start = $profile->getName(); + } else { + if ($profile->isTemplate()) { + $start = $this->formatTemplate($profile, $prefix); + } else { + $start = $this->formatNonTemplate($profile, $prefix); + } + $prefix .= $sibling ? '│ ' : ' '; + } + + $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0; + + if ($profile->getDuration() * 1000 < 1) { + $str = $start."\n"; + } else { + $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent)); + } + + $nCount = \count($profile->getProfiles()); + foreach ($profile as $i => $p) { + $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount); + } + + return $str; + } +} + +class_alias('Twig\Profiler\Dumper\BaseDumper', 'Twig_Profiler_Dumper_Base'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php new file mode 100644 index 0000000..f333429 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php @@ -0,0 +1,74 @@ + + */ +final class BlackfireDumper +{ + public function dump(Profile $profile) + { + $data = []; + $this->dumpProfile('main()', $profile, $data); + $this->dumpChildren('main()', $profile, $data); + + $start = sprintf('%f', microtime(true)); + $str = << $values) { + $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; + } + + return $str; + } + + private function dumpChildren(string $parent, Profile $profile, &$data) + { + foreach ($profile as $p) { + if ($p->isTemplate()) { + $name = $p->getTemplate(); + } else { + $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName()); + } + $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data); + $this->dumpChildren($name, $p, $data); + } + } + + private function dumpProfile(string $edge, Profile $profile, &$data) + { + if (isset($data[$edge])) { + ++$data[$edge]['ct']; + $data[$edge]['wt'] += floor($profile->getDuration() * 1000000); + $data[$edge]['mu'] += $profile->getMemoryUsage(); + $data[$edge]['pmu'] += $profile->getPeakMemoryUsage(); + } else { + $data[$edge] = [ + 'ct' => 1, + 'wt' => floor($profile->getDuration() * 1000000), + 'mu' => $profile->getMemoryUsage(), + 'pmu' => $profile->getPeakMemoryUsage(), + ]; + } + } +} + +class_alias('Twig\Profiler\Dumper\BlackfireDumper', 'Twig_Profiler_Dumper_Blackfire'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/HtmlDumper.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/HtmlDumper.php new file mode 100644 index 0000000..5be5abe --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/HtmlDumper.php @@ -0,0 +1,49 @@ + + */ +final class HtmlDumper extends BaseDumper +{ + private static $colors = [ + 'block' => '#dfd', + 'macro' => '#ddf', + 'template' => '#ffd', + 'big' => '#d44', + ]; + + public function dump(Profile $profile) + { + return '
    '.parent::dump($profile).'
    '; + } + + protected function formatTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); + } + + protected function formatNonTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); + } + + protected function formatTime(Profile $profile, $percent) + { + return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); + } +} + +class_alias('Twig\Profiler\Dumper\HtmlDumper', 'Twig_Profiler_Dumper_Html'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/TextDumper.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/TextDumper.php new file mode 100644 index 0000000..395ef9d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Dumper/TextDumper.php @@ -0,0 +1,37 @@ + + */ +final class TextDumper extends BaseDumper +{ + protected function formatTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s', $prefix, $profile->getTemplate()); + } + + protected function formatNonTemplate(Profile $profile, $prefix) + { + return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); + } + + protected function formatTime(Profile $profile, $percent) + { + return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); + } +} + +class_alias('Twig\Profiler\Dumper\TextDumper', 'Twig_Profiler_Dumper_Text'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/EnterProfileNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/EnterProfileNode.php new file mode 100644 index 0000000..91de5ff --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/EnterProfileNode.php @@ -0,0 +1,44 @@ + + */ +class EnterProfileNode extends Node +{ + public function __construct(string $extensionName, string $type, string $name, string $varName) + { + parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); + } + + public function compile(Compiler $compiler) + { + $compiler + ->write(sprintf('$%s = $this->extensions[', $this->getAttribute('var_name'))) + ->repr($this->getAttribute('extension_name')) + ->raw("];\n") + ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ->repr($this->getAttribute('type')) + ->raw(', ') + ->repr($this->getAttribute('name')) + ->raw("));\n\n") + ; + } +} + +class_alias('Twig\Profiler\Node\EnterProfileNode', 'Twig_Profiler_Node_EnterProfile'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/LeaveProfileNode.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/LeaveProfileNode.php new file mode 100644 index 0000000..7fbf435 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Node/LeaveProfileNode.php @@ -0,0 +1,38 @@ + + */ +class LeaveProfileNode extends Node +{ + public function __construct(string $varName) + { + parent::__construct([], ['var_name' => $varName]); + } + + public function compile(Compiler $compiler) + { + $compiler + ->write("\n") + ->write(sprintf("\$%s->leave(\$%s);\n\n", $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ; + } +} + +class_alias('Twig\Profiler\Node\LeaveProfileNode', 'Twig_Profiler_Node_LeaveProfile'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php new file mode 100644 index 0000000..f19f6b7 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php @@ -0,0 +1,78 @@ + + */ +final class ProfilerNodeVisitor extends AbstractNodeVisitor +{ + private $extensionName; + + public function __construct(string $extensionName) + { + $this->extensionName = $extensionName; + } + + protected function doEnterNode(Node $node, Environment $env) + { + return $node; + } + + protected function doLeaveNode(Node $node, Environment $env) + { + if ($node instanceof ModuleNode) { + $varName = $this->getVarName(); + $node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); + $node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')])); + } elseif ($node instanceof BlockNode) { + $varName = $this->getVarName(); + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName), + $node->getNode('body'), + new LeaveProfileNode($varName), + ])); + } elseif ($node instanceof MacroNode) { + $varName = $this->getVarName(); + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName), + $node->getNode('body'), + new LeaveProfileNode($varName), + ])); + } + + return $node; + } + + private function getVarName(): string + { + return sprintf('__internal_%s', hash('sha256', $this->extensionName)); + } + + public function getPriority() + { + return 0; + } +} + +class_alias('Twig\Profiler\NodeVisitor\ProfilerNodeVisitor', 'Twig_Profiler_NodeVisitor_Profiler'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Profile.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Profile.php new file mode 100644 index 0000000..e9726d6 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Profiler/Profile.php @@ -0,0 +1,192 @@ + + * + * @final since Twig 2.4.0 + */ +class Profile implements \IteratorAggregate, \Serializable +{ + const ROOT = 'ROOT'; + const BLOCK = 'block'; + const TEMPLATE = 'template'; + const MACRO = 'macro'; + + private $template; + private $name; + private $type; + private $starts = []; + private $ends = []; + private $profiles = []; + + public function __construct(string $template = 'main', string $type = self::ROOT, string $name = 'main') + { + if (__CLASS__ !== \get_class($this)) { + @trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); + } + + $this->template = $template; + $this->type = $type; + $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name; + $this->enter(); + } + + public function getTemplate() + { + return $this->template; + } + + public function getType() + { + return $this->type; + } + + public function getName() + { + return $this->name; + } + + public function isRoot() + { + return self::ROOT === $this->type; + } + + public function isTemplate() + { + return self::TEMPLATE === $this->type; + } + + public function isBlock() + { + return self::BLOCK === $this->type; + } + + public function isMacro() + { + return self::MACRO === $this->type; + } + + public function getProfiles() + { + return $this->profiles; + } + + public function addProfile(self $profile) + { + $this->profiles[] = $profile; + } + + /** + * Returns the duration in microseconds. + * + * @return float + */ + public function getDuration() + { + if ($this->isRoot() && $this->profiles) { + // for the root node with children, duration is the sum of all child durations + $duration = 0; + foreach ($this->profiles as $profile) { + $duration += $profile->getDuration(); + } + + return $duration; + } + + return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0; + } + + /** + * Returns the memory usage in bytes. + * + * @return int + */ + public function getMemoryUsage() + { + return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0; + } + + /** + * Returns the peak memory usage in bytes. + * + * @return int + */ + public function getPeakMemoryUsage() + { + return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0; + } + + /** + * Starts the profiling. + */ + public function enter() + { + $this->starts = [ + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ]; + } + + /** + * Stops the profiling. + */ + public function leave() + { + $this->ends = [ + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ]; + } + + public function reset() + { + $this->starts = $this->ends = $this->profiles = []; + $this->enter(); + } + + public function getIterator() + { + return new \ArrayIterator($this->profiles); + } + + public function serialize() + { + return serialize($this->__serialize()); + } + + public function unserialize($data) + { + $this->__unserialize(unserialize($data)); + } + + /** + * @internal + */ + public function __serialize() + { + return [$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles]; + } + + /** + * @internal + */ + public function __unserialize(array $data) + { + list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = $data; + } +} + +class_alias('Twig\Profiler\Profile', 'Twig_Profiler_Profile'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php new file mode 100644 index 0000000..04a6602 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php @@ -0,0 +1,41 @@ + + * @author Robin Chalas + */ +class ContainerRuntimeLoader implements RuntimeLoaderInterface +{ + private $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + public function load($class) + { + if ($this->container->has($class)) { + return $this->container->get($class); + } + } +} + +class_alias('Twig\RuntimeLoader\ContainerRuntimeLoader', 'Twig_ContainerRuntimeLoader'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php new file mode 100644 index 0000000..e4676f7 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php @@ -0,0 +1,41 @@ + + */ +class FactoryRuntimeLoader implements RuntimeLoaderInterface +{ + private $map; + + /** + * @param array $map An array where keys are class names and values factory callables + */ + public function __construct(array $map = []) + { + $this->map = $map; + } + + public function load($class) + { + if (isset($this->map[$class])) { + $runtimeFactory = $this->map[$class]; + + return $runtimeFactory(); + } + } +} + +class_alias('Twig\RuntimeLoader\FactoryRuntimeLoader', 'Twig_FactoryRuntimeLoader'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php new file mode 100644 index 0000000..4eb5ad8 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php @@ -0,0 +1,31 @@ + + */ +interface RuntimeLoaderInterface +{ + /** + * Creates the runtime implementation of a Twig element (filter/function/test). + * + * @param string $class A runtime class + * + * @return object|null The runtime instance or null if the loader does not know how to create the runtime for this class + */ + public function load($class); +} + +class_alias('Twig\RuntimeLoader\RuntimeLoaderInterface', 'Twig_RuntimeLoaderInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityError.php new file mode 100644 index 0000000..5f96d46 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityError.php @@ -0,0 +1,25 @@ + + */ +class SecurityError extends Error +{ +} + +class_alias('Twig\Sandbox\SecurityError', 'Twig_Sandbox_SecurityError'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php new file mode 100644 index 0000000..767ec5b --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php @@ -0,0 +1,46 @@ + + * + * @final + */ +class SecurityNotAllowedFilterError extends SecurityError +{ + private $filterName; + + public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null) + { + if (-1 !== $lineno) { + @trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $filename) { + @trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $previous) { + @trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + parent::__construct($message, $lineno, $filename, $previous); + $this->filterName = $functionName; + } + + public function getFilterName() + { + return $this->filterName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedFilterError', 'Twig_Sandbox_SecurityNotAllowedFilterError'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php new file mode 100644 index 0000000..5a30139 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php @@ -0,0 +1,46 @@ + + * + * @final + */ +class SecurityNotAllowedFunctionError extends SecurityError +{ + private $functionName; + + public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null) + { + if (-1 !== $lineno) { + @trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $filename) { + @trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $previous) { + @trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + parent::__construct($message, $lineno, $filename, $previous); + $this->functionName = $functionName; + } + + public function getFunctionName() + { + return $this->functionName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedFunctionError', 'Twig_Sandbox_SecurityNotAllowedFunctionError'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php new file mode 100644 index 0000000..c8103ea --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php @@ -0,0 +1,53 @@ + + * + * @final + */ +class SecurityNotAllowedMethodError extends SecurityError +{ + private $className; + private $methodName; + + public function __construct(string $message, string $className, string $methodName, int $lineno = -1, string $filename = null, \Exception $previous = null) + { + if (-1 !== $lineno) { + @trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $filename) { + @trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $previous) { + @trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + parent::__construct($message, $lineno, $filename, $previous); + $this->className = $className; + $this->methodName = $methodName; + } + + public function getClassName() + { + return $this->className; + } + + public function getMethodName() + { + return $this->methodName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedMethodError', 'Twig_Sandbox_SecurityNotAllowedMethodError'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php new file mode 100644 index 0000000..d148f08 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php @@ -0,0 +1,53 @@ + + * + * @final + */ +class SecurityNotAllowedPropertyError extends SecurityError +{ + private $className; + private $propertyName; + + public function __construct(string $message, string $className, string $propertyName, int $lineno = -1, string $filename = null, \Exception $previous = null) + { + if (-1 !== $lineno) { + @trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $filename) { + @trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $previous) { + @trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + parent::__construct($message, $lineno, $filename, $previous); + $this->className = $className; + $this->propertyName = $propertyName; + } + + public function getClassName() + { + return $this->className; + } + + public function getPropertyName() + { + return $this->propertyName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedPropertyError', 'Twig_Sandbox_SecurityNotAllowedPropertyError'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php new file mode 100644 index 0000000..25f6361 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php @@ -0,0 +1,46 @@ + + * + * @final + */ +class SecurityNotAllowedTagError extends SecurityError +{ + private $tagName; + + public function __construct(string $message, string $tagName, int $lineno = -1, string $filename = null, \Exception $previous = null) + { + if (-1 !== $lineno) { + @trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $filename) { + @trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + if (null !== $previous) { + @trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED); + } + parent::__construct($message, $lineno, $filename, $previous); + $this->tagName = $tagName; + } + + public function getTagName() + { + return $this->tagName; + } +} + +class_alias('Twig\Sandbox\SecurityNotAllowedTagError', 'Twig_Sandbox_SecurityNotAllowedTagError'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicy.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicy.php new file mode 100644 index 0000000..1406e80 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicy.php @@ -0,0 +1,128 @@ + + */ +final class SecurityPolicy implements SecurityPolicyInterface +{ + private $allowedTags; + private $allowedFilters; + private $allowedMethods; + private $allowedProperties; + private $allowedFunctions; + + public function __construct(array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = []) + { + $this->allowedTags = $allowedTags; + $this->allowedFilters = $allowedFilters; + $this->setAllowedMethods($allowedMethods); + $this->allowedProperties = $allowedProperties; + $this->allowedFunctions = $allowedFunctions; + } + + public function setAllowedTags(array $tags) + { + $this->allowedTags = $tags; + } + + public function setAllowedFilters(array $filters) + { + $this->allowedFilters = $filters; + } + + public function setAllowedMethods(array $methods) + { + $this->allowedMethods = []; + foreach ($methods as $class => $m) { + $this->allowedMethods[$class] = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]); + } + } + + public function setAllowedProperties(array $properties) + { + $this->allowedProperties = $properties; + } + + public function setAllowedFunctions(array $functions) + { + $this->allowedFunctions = $functions; + } + + public function checkSecurity($tags, $filters, $functions) + { + foreach ($tags as $tag) { + if (!\in_array($tag, $this->allowedTags)) { + throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); + } + } + + foreach ($filters as $filter) { + if (!\in_array($filter, $this->allowedFilters)) { + throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); + } + } + + foreach ($functions as $function) { + if (!\in_array($function, $this->allowedFunctions)) { + throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); + } + } + } + + public function checkMethodAllowed($obj, $method) + { + if ($obj instanceof Template || $obj instanceof Markup) { + return; + } + + $allowed = false; + $method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); + foreach ($this->allowedMethods as $class => $methods) { + if ($obj instanceof $class) { + $allowed = \in_array($method, $methods); + + break; + } + } + + if (!$allowed) { + $class = \get_class($obj); + throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); + } + } + + public function checkPropertyAllowed($obj, $property) + { + $allowed = false; + foreach ($this->allowedProperties as $class => $properties) { + if ($obj instanceof $class) { + $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]); + + break; + } + } + + if (!$allowed) { + $class = \get_class($obj); + throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); + } + } +} + +class_alias('Twig\Sandbox\SecurityPolicy', 'Twig_Sandbox_SecurityPolicy'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicyInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicyInterface.php new file mode 100644 index 0000000..8b2ab4a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Sandbox/SecurityPolicyInterface.php @@ -0,0 +1,37 @@ + + */ +interface SecurityPolicyInterface +{ + /** + * @throws SecurityError + */ + public function checkSecurity($tags, $filters, $functions); + + /** + * @throws SecurityNotAllowedMethodError + */ + public function checkMethodAllowed($obj, $method); + + /** + * @throws SecurityNotAllowedPropertyError + */ + public function checkPropertyAllowed($obj, $method); +} + +class_alias('Twig\Sandbox\SecurityPolicyInterface', 'Twig_Sandbox_SecurityPolicyInterface'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Source.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Source.php new file mode 100644 index 0000000..a728778 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Source.php @@ -0,0 +1,53 @@ + + */ +final class Source +{ + private $code; + private $name; + private $path; + + /** + * @param string $code The template source code + * @param string $name The template logical name + * @param string $path The filesystem path of the template if any + */ + public function __construct(string $code, string $name, string $path = '') + { + $this->code = $code; + $this->name = $name; + $this->path = $path; + } + + public function getCode(): string + { + return $this->code; + } + + public function getName() + { + return $this->name; + } + + public function getPath(): string + { + return $this->path; + } +} + +class_alias('Twig\Source', 'Twig_Source'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Template.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Template.php new file mode 100644 index 0000000..0f09e19 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Template.php @@ -0,0 +1,437 @@ +load() + * instead, which returns an instance of \Twig\TemplateWrapper. + * + * @author Fabien Potencier + * + * @internal + */ +abstract class Template +{ + const ANY_CALL = 'any'; + const ARRAY_CALL = 'array'; + const METHOD_CALL = 'method'; + + protected $parent; + protected $parents = []; + protected $env; + protected $blocks = []; + protected $traits = []; + protected $extensions = []; + protected $sandbox; + + public function __construct(Environment $env) + { + $this->env = $env; + $this->extensions = $env->getExtensions(); + } + + /** + * @internal this method will be removed in 3.0 and is only used internally to provide an upgrade path from 1.x to 2.0 + */ + public function __toString() + { + return $this->getTemplateName(); + } + + /** + * Returns the template name. + * + * @return string The template name + */ + abstract public function getTemplateName(); + + /** + * Returns debug information about the template. + * + * @return array Debug information + */ + abstract public function getDebugInfo(); + + /** + * Returns information about the original template source code. + * + * @return Source + */ + public function getSourceContext() + { + return new Source('', $this->getTemplateName()); + } + + /** + * Returns the parent template. + * + * This method is for internal use only and should never be called + * directly. + * + * @param array $context + * + * @return Template|TemplateWrapper|false The parent template or false if there is no parent + */ + public function getParent(array $context) + { + if (null !== $this->parent) { + return $this->parent; + } + + try { + $parent = $this->doGetParent($context); + + if (false === $parent) { + return false; + } + + if ($parent instanceof self || $parent instanceof TemplateWrapper) { + return $this->parents[$parent->getSourceContext()->getName()] = $parent; + } + + if (!isset($this->parents[$parent])) { + $this->parents[$parent] = $this->loadTemplate($parent); + } + } catch (LoaderError $e) { + $e->setSourceContext(null); + $e->guess(); + + throw $e; + } + + return $this->parents[$parent]; + } + + protected function doGetParent(array $context) + { + return false; + } + + public function isTraitable() + { + return true; + } + + /** + * Displays a parent block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to display from the parent + * @param array $context The context + * @param array $blocks The current set of blocks + */ + public function displayParentBlock($name, array $context, array $blocks = []) + { + if (isset($this->traits[$name])) { + $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, $blocks, false); + } else { + throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); + } + } + + /** + * Displays a block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to display + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks + */ + public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, self $templateContext = null) + { + if ($useBlocks && isset($blocks[$name])) { + $template = $blocks[$name][0]; + $block = $blocks[$name][1]; + } elseif (isset($this->blocks[$name])) { + $template = $this->blocks[$name][0]; + $block = $this->blocks[$name][1]; + } else { + $template = null; + $block = null; + } + + // avoid RCEs when sandbox is enabled + if (null !== $template && !$template instanceof self) { + throw new \LogicException('A block must be a method on a \Twig\Template instance.'); + } + + if (null !== $template) { + try { + $template->$block($context, $blocks); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($template->getSourceContext()); + } + + // this is mostly useful for \Twig\Error\LoaderError exceptions + // see \Twig\Error\LoaderError + if (-1 === $e->getTemplateLine()) { + $e->guess(); + } + + throw $e; + } catch (\Exception $e) { + $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); + $e->guess(); + + throw $e; + } + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this); + } elseif (isset($blocks[$name])) { + throw new RuntimeError(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getSourceContext()); + } else { + throw new RuntimeError(sprintf('Block "%s" on template "%s" does not exist.', $name, $this->getTemplateName()), -1, ($templateContext ?? $this)->getSourceContext()); + } + } + + /** + * Renders a parent block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to render from the parent + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return string The rendered block + */ + public function renderParentBlock($name, array $context, array $blocks = []) + { + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + $this->displayParentBlock($name, $context, $blocks); + + return ob_get_clean(); + } + + /** + * Renders a block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to render + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks + * + * @return string The rendered block + */ + public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true) + { + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + $this->displayBlock($name, $context, $blocks, $useBlocks); + + return ob_get_clean(); + } + + /** + * Returns whether a block exists or not in the current context of the template. + * + * This method checks blocks defined in the current template + * or defined in "used" traits or defined in parent templates. + * + * @param string $name The block name + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return bool true if the block exists, false otherwise + */ + public function hasBlock($name, array $context, array $blocks = []) + { + if (isset($blocks[$name])) { + return $blocks[$name][0] instanceof self; + } + + if (isset($this->blocks[$name])) { + return true; + } + + if (false !== $parent = $this->getParent($context)) { + return $parent->hasBlock($name, $context); + } + + return false; + } + + /** + * Returns all block names in the current context of the template. + * + * This method checks blocks defined in the current template + * or defined in "used" traits or defined in parent templates. + * + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return array An array of block names + */ + public function getBlockNames(array $context, array $blocks = []) + { + $names = array_merge(array_keys($blocks), array_keys($this->blocks)); + + if (false !== $parent = $this->getParent($context)) { + $names = array_merge($names, $parent->getBlockNames($context)); + } + + return array_unique($names); + } + + /** + * @return Template|TemplateWrapper + */ + protected function loadTemplate($template, $templateName = null, $line = null, $index = null) + { + try { + if (\is_array($template)) { + return $this->env->resolveTemplate($template); + } + + if ($template instanceof self || $template instanceof TemplateWrapper) { + return $template; + } + + if ($template === $this->getTemplateName()) { + $class = \get_class($this); + if (false !== $pos = strrpos($class, '___', -1)) { + $class = substr($class, 0, $pos); + } + + return $this->env->loadClass($class, $template, $index); + } + + return $this->env->loadTemplate($template, $index); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext()); + } + + if ($e->getTemplateLine() > 0) { + throw $e; + } + + if (!$line) { + $e->guess(); + } else { + $e->setTemplateLine($line); + } + + throw $e; + } + } + + /** + * @internal + * + * @return Template + */ + protected function unwrap() + { + return $this; + } + + /** + * Returns all blocks. + * + * This method is for internal use only and should never be called + * directly. + * + * @return array An array of blocks + */ + public function getBlocks() + { + return $this->blocks; + } + + public function display(array $context, array $blocks = []) + { + $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); + } + + public function render(array $context) + { + $level = ob_get_level(); + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + try { + $this->display($context); + } catch (\Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + + return ob_get_clean(); + } + + protected function displayWithErrorHandling(array $context, array $blocks = []) + { + try { + $this->doDisplay($context, $blocks); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($this->getSourceContext()); + } + + // this is mostly useful for \Twig\Error\LoaderError exceptions + // see \Twig\Error\LoaderError + if (-1 === $e->getTemplateLine()) { + $e->guess(); + } + + throw $e; + } catch (\Exception $e) { + $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); + $e->guess(); + + throw $e; + } + } + + /** + * Auto-generated method to display the template with the given context. + * + * @param array $context An array of parameters to pass to the template + * @param array $blocks An array of blocks to pass to the template + */ + abstract protected function doDisplay(array $context, array $blocks = []); +} + +class_alias('Twig\Template', 'Twig_Template'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TemplateWrapper.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TemplateWrapper.php new file mode 100644 index 0000000..8b44815 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TemplateWrapper.php @@ -0,0 +1,145 @@ + + */ +final class TemplateWrapper +{ + private $env; + private $template; + + /** + * This method is for internal use only and should never be called + * directly (use Twig\Environment::load() instead). + * + * @internal + */ + public function __construct(Environment $env, Template $template) + { + $this->env = $env; + $this->template = $template; + } + + /** + * Renders the template. + * + * @param array $context An array of parameters to pass to the template + */ + public function render(array $context = []): string + { + // using func_get_args() allows to not expose the blocks argument + // as it should only be used by internal code + return $this->template->render($context, \func_get_args()[1] ?? []); + } + + /** + * Displays the template. + * + * @param array $context An array of parameters to pass to the template + */ + public function display(array $context = []) + { + // using func_get_args() allows to not expose the blocks argument + // as it should only be used by internal code + $this->template->display($context, \func_get_args()[1] ?? []); + } + + /** + * Checks if a block is defined. + * + * @param string $name The block name + * @param array $context An array of parameters to pass to the template + */ + public function hasBlock(string $name, array $context = []): bool + { + return $this->template->hasBlock($name, $context); + } + + /** + * Returns defined block names in the template. + * + * @param array $context An array of parameters to pass to the template + * + * @return string[] An array of defined template block names + */ + public function getBlockNames(array $context = []): array + { + return $this->template->getBlockNames($context); + } + + /** + * Renders a template block. + * + * @param string $name The block name to render + * @param array $context An array of parameters to pass to the template + * + * @return string The rendered block + */ + public function renderBlock(string $name, array $context = []): string + { + $context = $this->env->mergeGlobals($context); + $level = ob_get_level(); + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + try { + $this->template->displayBlock($name, $context); + } catch (\Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + + return ob_get_clean(); + } + + /** + * Displays a template block. + * + * @param string $name The block name to render + * @param array $context An array of parameters to pass to the template + */ + public function displayBlock(string $name, array $context = []) + { + $this->template->displayBlock($name, $this->env->mergeGlobals($context)); + } + + public function getSourceContext(): Source + { + return $this->template->getSourceContext(); + } + + public function getTemplateName(): string + { + return $this->template->getTemplateName(); + } + + /** + * @internal + * + * @return Template + */ + public function unwrap() + { + return $this->template; + } +} + +class_alias('Twig\TemplateWrapper', 'Twig_TemplateWrapper'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Test/IntegrationTestCase.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Test/IntegrationTestCase.php new file mode 100644 index 0000000..d9c3290 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Test/IntegrationTestCase.php @@ -0,0 +1,267 @@ + + * @author Karma Dordrak + */ +abstract class IntegrationTestCase extends TestCase +{ + /** + * @return string + */ + abstract protected function getFixturesDir(); + + /** + * @return RuntimeLoaderInterface[] + */ + protected function getRuntimeLoaders() + { + return []; + } + + /** + * @return ExtensionInterface[] + */ + protected function getExtensions() + { + return []; + } + + /** + * @return TwigFilter[] + */ + protected function getTwigFilters() + { + return []; + } + + /** + * @return TwigFunction[] + */ + protected function getTwigFunctions() + { + return []; + } + + /** + * @return TwigTest[] + */ + protected function getTwigTests() + { + return []; + } + + /** + * @dataProvider getTests + */ + public function testIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); + } + + /** + * @dataProvider getLegacyTests + * @group legacy + */ + public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); + } + + public function getTests($name, $legacyTests = false) + { + $fixturesDir = realpath($this->getFixturesDir()); + $tests = []; + + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if (!preg_match('/\.test$/', $file)) { + continue; + } + + if ($legacyTests xor false !== strpos($file->getRealpath(), '.legacy.test')) { + continue; + } + + $test = file_get_contents($file->getRealpath()); + + if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*(?:--DEPRECATION--\s*(.*?))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { + $message = $match[1]; + $condition = $match[2]; + $deprecation = $match[3]; + $templates = self::parseTemplates($match[4]); + $exception = $match[6]; + $outputs = [[null, $match[5], null, '']]; + } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*(?:--DEPRECATION--\s*(.*?))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { + $message = $match[1]; + $condition = $match[2]; + $deprecation = $match[3]; + $templates = self::parseTemplates($match[4]); + $exception = false; + preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); + } else { + throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); + } + + $tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs, $deprecation]; + } + + if ($legacyTests && empty($tests)) { + // add a dummy test to avoid a PHPUnit message + return [['not', '-', '', [], '', []]]; + } + + return $tests; + } + + public function getLegacyTests() + { + return $this->getTests('testLegacyIntegration', true); + } + + protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + if (!$outputs) { + $this->markTestSkipped('no tests to run'); + } + + if ($condition) { + eval('$ret = '.$condition.';'); + if (!$ret) { + $this->markTestSkipped($condition); + } + } + + $loader = new ArrayLoader($templates); + + foreach ($outputs as $i => $match) { + $config = array_merge([ + 'cache' => false, + 'strict_variables' => true, + ], $match[2] ? eval($match[2].';') : []); + $twig = new Environment($loader, $config); + $twig->addGlobal('global', 'global'); + foreach ($this->getRuntimeLoaders() as $runtimeLoader) { + $twig->addRuntimeLoader($runtimeLoader); + } + + foreach ($this->getExtensions() as $extension) { + $twig->addExtension($extension); + } + + foreach ($this->getTwigFilters() as $filter) { + $twig->addFilter($filter); + } + + foreach ($this->getTwigTests() as $test) { + $twig->addTest($test); + } + + foreach ($this->getTwigFunctions() as $function) { + $twig->addFunction($function); + } + + // avoid using the same PHP class name for different cases + $p = new \ReflectionProperty($twig, 'templateClassPrefix'); + $p->setAccessible(true); + $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); + + $deprecations = []; + try { + $prevHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) { + if (E_USER_DEPRECATED === $type) { + $deprecations[] = $msg; + + return true; + } + + return $prevHandler ? $prevHandler($type, $msg, $file, $line, $context) : false; + }); + + $template = $twig->load('index.twig'); + } catch (\Exception $e) { + if (false !== $exception) { + $message = $e->getMessage(); + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message))); + $last = substr($message, \strlen($message) - 1); + $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.'); + + return; + } + + throw new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + } finally { + restore_error_handler(); + } + + $this->assertSame($deprecation, implode("\n", $deprecations)); + + try { + $output = trim($template->render(eval($match[1].';')), "\n "); + } catch (\Exception $e) { + if (false !== $exception) { + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $e->getMessage()))); + + return; + } + + $e = new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + + $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); + } + + if (false !== $exception) { + list($class) = explode(':', $exception); + $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception'; + $this->assertThat(null, new $constraintClass($class)); + } + + $expected = trim($match[3], "\n "); + + if ($expected !== $output) { + printf("Compiled templates that failed on case %d:\n", $i + 1); + + foreach (array_keys($templates) as $name) { + echo "Template: $name\n"; + echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext($name)))); + } + } + $this->assertEquals($expected, $output, $message.' (in '.$file.')'); + } + } + + protected static function parseTemplates($test) + { + $templates = []; + preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; + } + + return $templates; + } +} + +class_alias('Twig\Test\IntegrationTestCase', 'Twig_Test_IntegrationTestCase'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Test/NodeTestCase.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Test/NodeTestCase.php new file mode 100644 index 0000000..368ceb1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Test/NodeTestCase.php @@ -0,0 +1,67 @@ +assertNodeCompilation($source, $node, $environment, $isPattern); + } + + public function assertNodeCompilation($source, Node $node, Environment $environment = null, $isPattern = false) + { + $compiler = $this->getCompiler($environment); + $compiler->compile($node); + + if ($isPattern) { + $this->assertStringMatchesFormat($source, trim($compiler->getSource())); + } else { + $this->assertEquals($source, trim($compiler->getSource())); + } + } + + protected function getCompiler(Environment $environment = null) + { + return new Compiler(null === $environment ? $this->getEnvironment() : $environment); + } + + protected function getEnvironment() + { + return new Environment(new ArrayLoader([])); + } + + protected function getVariableGetter($name, $line = false) + { + $line = $line > 0 ? "// line {$line}\n" : ''; + + return sprintf('%s($context["%s"] ?? null)', $line, $name); + } + + protected function getAttributeGetter() + { + return 'twig_get_attribute($this->env, $this->source, '; + } +} + +class_alias('Twig\Test\NodeTestCase', 'Twig_Test_NodeTestCase'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Token.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Token.php new file mode 100644 index 0000000..262fa48 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Token.php @@ -0,0 +1,213 @@ + + */ +final class Token +{ + private $value; + private $type; + private $lineno; + + const EOF_TYPE = -1; + const TEXT_TYPE = 0; + const BLOCK_START_TYPE = 1; + const VAR_START_TYPE = 2; + const BLOCK_END_TYPE = 3; + const VAR_END_TYPE = 4; + const NAME_TYPE = 5; + const NUMBER_TYPE = 6; + const STRING_TYPE = 7; + const OPERATOR_TYPE = 8; + const PUNCTUATION_TYPE = 9; + const INTERPOLATION_START_TYPE = 10; + const INTERPOLATION_END_TYPE = 11; + const ARROW_TYPE = 12; + + /** + * @param int $type The type of the token + * @param string $value The token value + * @param int $lineno The line position in the source + */ + public function __construct($type, $value, $lineno) + { + $this->type = $type; + $this->value = $value; + $this->lineno = $lineno; + } + + public function __toString() + { + return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value); + } + + /** + * Tests the current token for a type and/or a value. + * + * Parameters may be: + * * just type + * * type and value (or array of possible values) + * * just value (or array of possible values) (NAME_TYPE is used as type) + * + * @param array|string|int $type The type to test + * @param array|string|null $values The token value + * + * @return bool + */ + public function test($type, $values = null) + { + if (null === $values && !\is_int($type)) { + $values = $type; + $type = self::NAME_TYPE; + } + + return ($this->type === $type) && ( + null === $values || + (\is_array($values) && \in_array($this->value, $values)) || + $this->value == $values + ); + } + + /** + * @return int + */ + public function getLine() + { + return $this->lineno; + } + + /** + * @return int + */ + public function getType() + { + return $this->type; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Returns the constant representation (internal) of a given type. + * + * @param int $type The type as an integer + * @param bool $short Whether to return a short representation or not + * + * @return string The string representation + */ + public static function typeToString($type, $short = false) + { + switch ($type) { + case self::EOF_TYPE: + $name = 'EOF_TYPE'; + break; + case self::TEXT_TYPE: + $name = 'TEXT_TYPE'; + break; + case self::BLOCK_START_TYPE: + $name = 'BLOCK_START_TYPE'; + break; + case self::VAR_START_TYPE: + $name = 'VAR_START_TYPE'; + break; + case self::BLOCK_END_TYPE: + $name = 'BLOCK_END_TYPE'; + break; + case self::VAR_END_TYPE: + $name = 'VAR_END_TYPE'; + break; + case self::NAME_TYPE: + $name = 'NAME_TYPE'; + break; + case self::NUMBER_TYPE: + $name = 'NUMBER_TYPE'; + break; + case self::STRING_TYPE: + $name = 'STRING_TYPE'; + break; + case self::OPERATOR_TYPE: + $name = 'OPERATOR_TYPE'; + break; + case self::PUNCTUATION_TYPE: + $name = 'PUNCTUATION_TYPE'; + break; + case self::INTERPOLATION_START_TYPE: + $name = 'INTERPOLATION_START_TYPE'; + break; + case self::INTERPOLATION_END_TYPE: + $name = 'INTERPOLATION_END_TYPE'; + break; + case self::ARROW_TYPE: + $name = 'ARROW_TYPE'; + break; + default: + throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); + } + + return $short ? $name : 'Twig\Token::'.$name; + } + + /** + * Returns the English representation of a given type. + * + * @param int $type The type as an integer + * + * @return string The string representation + */ + public static function typeToEnglish($type) + { + switch ($type) { + case self::EOF_TYPE: + return 'end of template'; + case self::TEXT_TYPE: + return 'text'; + case self::BLOCK_START_TYPE: + return 'begin of statement block'; + case self::VAR_START_TYPE: + return 'begin of print statement'; + case self::BLOCK_END_TYPE: + return 'end of statement block'; + case self::VAR_END_TYPE: + return 'end of print statement'; + case self::NAME_TYPE: + return 'name'; + case self::NUMBER_TYPE: + return 'number'; + case self::STRING_TYPE: + return 'string'; + case self::OPERATOR_TYPE: + return 'operator'; + case self::PUNCTUATION_TYPE: + return 'punctuation'; + case self::INTERPOLATION_START_TYPE: + return 'begin of string interpolation'; + case self::INTERPOLATION_END_TYPE: + return 'end of string interpolation'; + case self::ARROW_TYPE: + return 'arrow function'; + default: + throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); + } + } +} + +class_alias('Twig\Token', 'Twig_Token'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AbstractTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AbstractTokenParser.php new file mode 100644 index 0000000..2c2f90b --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AbstractTokenParser.php @@ -0,0 +1,34 @@ + + */ +abstract class AbstractTokenParser implements TokenParserInterface +{ + /** + * @var Parser + */ + protected $parser; + + public function setParser(Parser $parser) + { + $this->parser = $parser; + } +} + +class_alias('Twig\TokenParser\AbstractTokenParser', 'Twig_TokenParser'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ApplyTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ApplyTokenParser.php new file mode 100644 index 0000000..879879a --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ApplyTokenParser.php @@ -0,0 +1,58 @@ +getLine(); + $name = $this->parser->getVarName(); + + $ref = new TempNameExpression($name, $lineno); + $ref->setAttribute('always_defined', true); + + $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideApplyEnd'], true); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new Node([ + new SetNode(true, $ref, $body, $lineno, $this->getTag()), + new PrintNode($filter, $lineno, $this->getTag()), + ]); + } + + public function decideApplyEnd(Token $token) + { + return $token->test('endapply'); + } + + public function getTag() + { + return 'apply'; + } +} diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php new file mode 100644 index 0000000..10fdb81 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php @@ -0,0 +1,57 @@ +getLine(); + $stream = $this->parser->getStream(); + + if ($stream->test(/* Token::BLOCK_END_TYPE */ 3)) { + $value = 'html'; + } else { + $expr = $this->parser->getExpressionParser()->parseExpression(); + if (!$expr instanceof ConstantExpression) { + throw new SyntaxError('An escaping strategy must be a string or false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + $value = $expr->getAttribute('value'); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new AutoEscapeNode($value, $body, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endautoescape'); + } + + public function getTag() + { + return 'autoescape'; + } +} + +class_alias('Twig\TokenParser\AutoEscapeTokenParser', 'Twig_TokenParser_AutoEscape'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/BlockTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/BlockTokenParser.php new file mode 100644 index 0000000..449a2c0 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/BlockTokenParser.php @@ -0,0 +1,78 @@ + + * {% block title %}{% endblock %} - My Webpage + * {% endblock %} + */ +final class BlockTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + if ($this->parser->hasBlock($name)) { + throw new SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + $this->parser->setBlock($name, $block = new BlockNode($name, new Node([]), $lineno)); + $this->parser->pushLocalScope(); + $this->parser->pushBlockStack($name); + + if ($stream->nextIf(/* Token::BLOCK_END_TYPE */ 3)) { + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + if ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) { + $value = $token->getValue(); + + if ($value != $name) { + throw new SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + } else { + $body = new Node([ + new PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno), + ]); + } + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $block->setNode('body', $body); + $this->parser->popBlockStack(); + $this->parser->popLocalScope(); + + return new BlockReferenceNode($name, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endblock'); + } + + public function getTag() + { + return 'block'; + } +} + +class_alias('Twig\TokenParser\BlockTokenParser', 'Twig_TokenParser_Block'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DeprecatedTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DeprecatedTokenParser.php new file mode 100644 index 0000000..6575cff --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DeprecatedTokenParser.php @@ -0,0 +1,44 @@ + + * + * @final + */ +class DeprecatedTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $expr = $this->parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new DeprecatedNode($expr, $token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'deprecated'; + } +} + +class_alias('Twig\TokenParser\DeprecatedTokenParser', 'Twig_TokenParser_Deprecated'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DoTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DoTokenParser.php new file mode 100644 index 0000000..e5a07d6 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/DoTokenParser.php @@ -0,0 +1,37 @@ +parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new DoNode($expr, $token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'do'; + } +} + +class_alias('Twig\TokenParser\DoTokenParser', 'Twig_TokenParser_Do'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/EmbedTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/EmbedTokenParser.php new file mode 100644 index 0000000..83a545e --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/EmbedTokenParser.php @@ -0,0 +1,72 @@ +parser->getStream(); + + $parent = $this->parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + $parentToken = $fakeParentToken = new Token(/* Token::STRING_TYPE */ 7, '__parent__', $token->getLine()); + if ($parent instanceof ConstantExpression) { + $parentToken = new Token(/* Token::STRING_TYPE */ 7, $parent->getAttribute('value'), $token->getLine()); + } elseif ($parent instanceof NameExpression) { + $parentToken = new Token(/* Token::NAME_TYPE */ 5, $parent->getAttribute('name'), $token->getLine()); + } + + // inject a fake parent to make the parent() function work + $stream->injectTokens([ + new Token(/* Token::BLOCK_START_TYPE */ 1, '', $token->getLine()), + new Token(/* Token::NAME_TYPE */ 5, 'extends', $token->getLine()), + $parentToken, + new Token(/* Token::BLOCK_END_TYPE */ 3, '', $token->getLine()), + ]); + + $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); + + // override the parent with the correct one + if ($fakeParentToken === $parentToken) { + $module->setNode('parent', $parent); + } + + $this->parser->embedTemplate($module); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endembed'); + } + + public function getTag() + { + return 'embed'; + } +} + +class_alias('Twig\TokenParser\EmbedTokenParser', 'Twig_TokenParser_Embed'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ExtendsTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ExtendsTokenParser.php new file mode 100644 index 0000000..a44980f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ExtendsTokenParser.php @@ -0,0 +1,52 @@ +parser->getStream(); + + if ($this->parser->peekBlockStack()) { + throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext()); + } elseif (!$this->parser->isMainScope()) { + throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext()); + } + + if (null !== $this->parser->getParent()) { + throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); + } + $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); + + $stream->expect(Token::BLOCK_END_TYPE); + + return new Node(); + } + + public function getTag() + { + return 'extends'; + } +} + +class_alias('Twig\TokenParser\ExtendsTokenParser', 'Twig_TokenParser_Extends'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FilterTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FilterTokenParser.php new file mode 100644 index 0000000..e57fc90 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FilterTokenParser.php @@ -0,0 +1,64 @@ +parser->getStream(); + $lineno = $token->getLine(); + + @trigger_error(sprintf('The "filter" tag in "%s" at line %d is deprecated since Twig 2.9, use the "apply" tag instead.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED); + + $name = $this->parser->getVarName(); + $ref = new BlockReferenceExpression(new ConstantExpression($name, $lineno), null, $lineno, $this->getTag()); + + $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $block = new BlockNode($name, $body, $lineno); + $this->parser->setBlock($name, $block); + + return new PrintNode($filter, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endfilter'); + } + + public function getTag() + { + return 'filter'; + } +} + +class_alias('Twig\TokenParser\FilterTokenParser', 'Twig_TokenParser_Filter'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FlushTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FlushTokenParser.php new file mode 100644 index 0000000..70f4339 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FlushTokenParser.php @@ -0,0 +1,37 @@ +parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new FlushNode($token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'flush'; + } +} + +class_alias('Twig\TokenParser\FlushTokenParser', 'Twig_TokenParser_Flush'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ForTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ForTokenParser.php new file mode 100644 index 0000000..34430f0 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ForTokenParser.php @@ -0,0 +1,137 @@ + + * {% for user in users %} + *
  • {{ user.username|e }}
  • + * {% endfor %} + * + */ +final class ForTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); + $stream->expect(/* Token::OPERATOR_TYPE */ 8, 'in'); + $seq = $this->parser->getExpressionParser()->parseExpression(); + + $ifexpr = null; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'if')) { + @trigger_error(sprintf('Using an "if" condition on "for" tag in "%s" at line %d is deprecated since Twig 2.10.0, use a "filter" filter or an "if" condition inside the "for" body instead (if your condition depends on a variable updated inside the loop).', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED); + + $ifexpr = $this->parser->getExpressionParser()->parseExpression(); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideForFork']); + if ('else' == $stream->next()->getValue()) { + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $else = $this->parser->subparse([$this, 'decideForEnd'], true); + } else { + $else = null; + } + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + if (\count($targets) > 1) { + $keyTarget = $targets->getNode(0); + $keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); + $valueTarget = $targets->getNode(1); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + } else { + $keyTarget = new AssignNameExpression('_key', $lineno); + $valueTarget = $targets->getNode(0); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + } + + if ($ifexpr) { + $this->checkLoopUsageCondition($stream, $ifexpr); + $this->checkLoopUsageBody($stream, $body); + } + + return new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); + } + + public function decideForFork(Token $token) + { + return $token->test(['else', 'endfor']); + } + + public function decideForEnd(Token $token) + { + return $token->test('endfor'); + } + + // the loop variable cannot be used in the condition + private function checkLoopUsageCondition(TokenStream $stream, Node $node) + { + if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + throw new SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); + } + + foreach ($node as $n) { + if (!$n) { + continue; + } + + $this->checkLoopUsageCondition($stream, $n); + } + } + + // check usage of non-defined loop-items + // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) + private function checkLoopUsageBody(TokenStream $stream, Node $node) + { + if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + $attribute = $node->getNode('attribute'); + if ($attribute instanceof ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { + throw new SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); + } + } + + // should check for parent.loop.XXX usage + if ($node instanceof ForNode) { + return; + } + + foreach ($node as $n) { + if (!$n) { + continue; + } + + $this->checkLoopUsageBody($stream, $n); + } + } + + public function getTag() + { + return 'for'; + } +} + +class_alias('Twig\TokenParser\ForTokenParser', 'Twig_TokenParser_For'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FromTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FromTokenParser.php new file mode 100644 index 0000000..dd49f2f --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/FromTokenParser.php @@ -0,0 +1,65 @@ +parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect(/* Token::NAME_TYPE */ 5, 'import'); + + $targets = []; + do { + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + $alias = $name; + if ($stream->nextIf('as')) { + $alias = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + } + + $targets[$name] = $alias; + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } while (true); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $var = new AssignNameExpression($this->parser->getVarName(), $token->getLine()); + $node = new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope()); + + foreach ($targets as $name => $alias) { + $this->parser->addImportedSymbol('function', $alias, 'macro_'.$name, $var); + } + + return $node; + } + + public function getTag() + { + return 'from'; + } +} + +class_alias('Twig\TokenParser\FromTokenParser', 'Twig_TokenParser_From'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IfTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IfTokenParser.php new file mode 100644 index 0000000..8ad99f0 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IfTokenParser.php @@ -0,0 +1,89 @@ + + * {% for user in users %} + *
  • {{ user.username|e }}
  • + * {% endfor %} + * + * {% endif %} + */ +final class IfTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideIfFork']); + $tests = [$expr, $body]; + $else = null; + + $end = false; + while (!$end) { + switch ($stream->next()->getValue()) { + case 'else': + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $else = $this->parser->subparse([$this, 'decideIfEnd']); + break; + + case 'elseif': + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideIfFork']); + $tests[] = $expr; + $tests[] = $body; + break; + + case 'endif': + $end = true; + break; + + default: + throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new IfNode(new Node($tests), $else, $lineno, $this->getTag()); + } + + public function decideIfFork(Token $token) + { + return $token->test(['elseif', 'else', 'endif']); + } + + public function decideIfEnd(Token $token) + { + return $token->test(['endif']); + } + + public function getTag() + { + return 'if'; + } +} + +class_alias('Twig\TokenParser\IfTokenParser', 'Twig_TokenParser_If'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ImportTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ImportTokenParser.php new file mode 100644 index 0000000..b5674c1 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/ImportTokenParser.php @@ -0,0 +1,43 @@ +parser->getExpressionParser()->parseExpression(); + $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5, 'as'); + $var = new AssignNameExpression($this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5)->getValue(), $token->getLine()); + $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); + + $this->parser->addImportedSymbol('template', $var->getAttribute('name')); + + return new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope()); + } + + public function getTag() + { + return 'import'; + } +} + +class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IncludeTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IncludeTokenParser.php new file mode 100644 index 0000000..e1e95da --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/IncludeTokenParser.php @@ -0,0 +1,68 @@ +parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + protected function parseArguments() + { + $stream = $this->parser->getStream(); + + $ignoreMissing = false; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'ignore')) { + $stream->expect(/* Token::NAME_TYPE */ 5, 'missing'); + + $ignoreMissing = true; + } + + $variables = null; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'with')) { + $variables = $this->parser->getExpressionParser()->parseExpression(); + } + + $only = false; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'only')) { + $only = true; + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return [$variables, $only, $ignoreMissing]; + } + + public function getTag() + { + return 'include'; + } +} + +class_alias('Twig\TokenParser\IncludeTokenParser', 'Twig_TokenParser_Include'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/MacroTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/MacroTokenParser.php new file mode 100644 index 0000000..d267387 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/MacroTokenParser.php @@ -0,0 +1,66 @@ + + * {% endmacro %} + */ +final class MacroTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $this->parser->pushLocalScope(); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + if ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) { + $value = $token->getValue(); + + if ($value != $name) { + throw new SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + $this->parser->popLocalScope(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $this->parser->setMacro($name, new MacroNode($name, new BodyNode([$body]), $arguments, $lineno, $this->getTag())); + + return new Node(); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endmacro'); + } + + public function getTag() + { + return 'macro'; + } +} + +class_alias('Twig\TokenParser\MacroTokenParser', 'Twig_TokenParser_Macro'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SandboxTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SandboxTokenParser.php new file mode 100644 index 0000000..1f57987 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SandboxTokenParser.php @@ -0,0 +1,65 @@ +parser->getStream(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + // in a sandbox tag, only include tags are allowed + if (!$body instanceof IncludeNode) { + foreach ($body as $node) { + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { + continue; + } + + if (!$node instanceof IncludeNode) { + throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); + } + } + } + + return new SandboxNode($body, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endsandbox'); + } + + public function getTag() + { + return 'sandbox'; + } +} + +class_alias('Twig\TokenParser\SandboxTokenParser', 'Twig_TokenParser_Sandbox'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SetTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SetTokenParser.php new file mode 100644 index 0000000..82fee26 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SetTokenParser.php @@ -0,0 +1,72 @@ +getLine(); + $stream = $this->parser->getStream(); + $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); + + $capture = false; + if ($stream->nextIf(/* Token::OPERATOR_TYPE */ 8, '=')) { + $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + if (\count($names) !== \count($values)) { + throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } else { + $capture = true; + + if (\count($names) > 1) { + throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + } + + return new SetNode($capture, $names, $values, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token) + { + return $token->test('endset'); + } + + public function getTag() + { + return 'set'; + } +} + +class_alias('Twig\TokenParser\SetTokenParser', 'Twig_TokenParser_Set'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SpacelessTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SpacelessTokenParser.php new file mode 100644 index 0000000..b58624d --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/SpacelessTokenParser.php @@ -0,0 +1,56 @@ + + * foo + * + * {% endspaceless %} + * {# output will be
    foo
    #} + * + * @deprecated since Twig 2.7, to be removed in 3.0 (use the "spaceless" filter with the "apply" tag instead) + */ +final class SpacelessTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $stream = $this->parser->getStream(); + $lineno = $token->getLine(); + + @trigger_error(sprintf('The spaceless tag in "%s" at line %d is deprecated since Twig 2.7, use the "spaceless" filter with the "apply" tag instead.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new SpacelessNode($body, $lineno, $this->getTag()); + } + + public function decideSpacelessEnd(Token $token) + { + return $token->test('endspaceless'); + } + + public function getTag() + { + return 'spaceless'; + } +} + +class_alias('Twig\TokenParser\SpacelessTokenParser', 'Twig_TokenParser_Spaceless'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/TokenParserInterface.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/TokenParserInterface.php new file mode 100644 index 0000000..6f34106 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/TokenParserInterface.php @@ -0,0 +1,52 @@ + + */ +interface TokenParserInterface +{ + /** + * Sets the parser associated with this token parser. + */ + public function setParser(Parser $parser); + + /** + * Parses a token and returns a node. + * + * @return Node + * + * @throws SyntaxError + */ + public function parse(Token $token); + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag(); +} + +class_alias('Twig\TokenParser\TokenParserInterface', 'Twig_TokenParserInterface'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Token'); +class_exists('Twig\Parser'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/UseTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/UseTokenParser.php new file mode 100644 index 0000000..266efe5 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/UseTokenParser.php @@ -0,0 +1,73 @@ +parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + + if (!$template instanceof ConstantExpression) { + throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $targets = []; + if ($stream->nextIf('with')) { + do { + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + $alias = $name; + if ($stream->nextIf('as')) { + $alias = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + } + + $targets[$name] = new ConstantExpression($alias, -1); + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } while (true); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)])); + + return new Node(); + } + + public function getTag() + { + return 'use'; + } +} + +class_alias('Twig\TokenParser\UseTokenParser', 'Twig_TokenParser_Use'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/WithTokenParser.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/WithTokenParser.php new file mode 100644 index 0000000..c184fd7 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenParser/WithTokenParser.php @@ -0,0 +1,55 @@ + + */ +final class WithTokenParser extends AbstractTokenParser +{ + public function parse(Token $token) + { + $stream = $this->parser->getStream(); + + $variables = null; + $only = false; + if (!$stream->test(/* Token::BLOCK_END_TYPE */ 3)) { + $variables = $this->parser->getExpressionParser()->parseExpression(); + $only = (bool) $stream->nextIf(/* Token::NAME_TYPE */ 5, 'only'); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $body = $this->parser->subparse([$this, 'decideWithEnd'], true); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag()); + } + + public function decideWithEnd(Token $token) + { + return $token->test('endwith'); + } + + public function getTag() + { + return 'with'; + } +} + +class_alias('Twig\TokenParser\WithTokenParser', 'Twig_TokenParser_With'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenStream.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenStream.php new file mode 100644 index 0000000..3fb9e86 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TokenStream.php @@ -0,0 +1,134 @@ + + */ +final class TokenStream +{ + private $tokens; + private $current = 0; + private $source; + + public function __construct(array $tokens, Source $source = null) + { + $this->tokens = $tokens; + $this->source = $source ?: new Source('', ''); + } + + public function __toString() + { + return implode("\n", $this->tokens); + } + + public function injectTokens(array $tokens) + { + $this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current)); + } + + /** + * Sets the pointer to the next token and returns the old one. + */ + public function next(): Token + { + if (!isset($this->tokens[++$this->current])) { + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); + } + + return $this->tokens[$this->current - 1]; + } + + /** + * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. + * + * @return Token|null The next token if the condition is true, null otherwise + */ + public function nextIf($primary, $secondary = null) + { + if ($this->tokens[$this->current]->test($primary, $secondary)) { + return $this->next(); + } + } + + /** + * Tests a token and returns it or throws a syntax error. + */ + public function expect($type, $value = null, string $message = null): Token + { + $token = $this->tokens[$this->current]; + if (!$token->test($type, $value)) { + $line = $token->getLine(); + throw new SyntaxError(sprintf('%sUnexpected token "%s"%s ("%s" expected%s).', + $message ? $message.'. ' : '', + Token::typeToEnglish($token->getType()), + $token->getValue() ? sprintf(' of value "%s"', $token->getValue()) : '', + Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), + $line, + $this->source + ); + } + $this->next(); + + return $token; + } + + /** + * Looks at the next token. + */ + public function look(int $number = 1): Token + { + if (!isset($this->tokens[$this->current + $number])) { + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); + } + + return $this->tokens[$this->current + $number]; + } + + /** + * Tests the current token. + */ + public function test($primary, $secondary = null): bool + { + return $this->tokens[$this->current]->test($primary, $secondary); + } + + /** + * Checks if end of stream was reached. + */ + public function isEOF(): bool + { + return /* Token::EOF_TYPE */ -1 === $this->tokens[$this->current]->getType(); + } + + public function getCurrent(): Token + { + return $this->tokens[$this->current]; + } + + /** + * Gets the source associated with this stream. + * + * @internal + */ + public function getSourceContext(): Source + { + return $this->source; + } +} + +class_alias('Twig\TokenStream', 'Twig_TokenStream'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFilter.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFilter.php new file mode 100644 index 0000000..9e7b838 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFilter.php @@ -0,0 +1,150 @@ + + * + * @see https://twig.symfony.com/doc/templates.html#filters + */ +class TwigFilter +{ + private $name; + private $callable; + private $options; + private $arguments = []; + + /** + * Creates a template filter. + * + * @param string $name Name of this filter + * @param callable|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation. + * @param array $options Options array + */ + public function __construct(string $name, $callable = null, array $options = []) + { + if (__CLASS__ !== \get_class($this)) { + @trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); + } + + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'pre_escape' => null, + 'preserves_safety' => null, + 'node_class' => FilterExpression::class, + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName() + { + return $this->name; + } + + /** + * Returns the callable to execute for this filter. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Node $filterArgs) + { + if (null !== $this->options['is_safe']) { + return $this->options['is_safe']; + } + + if (null !== $this->options['is_safe_callback']) { + return $this->options['is_safe_callback']($filterArgs); + } + } + + public function getPreservesSafety() + { + return $this->options['preserves_safety']; + } + + public function getPreEscape() + { + return $this->options['pre_escape']; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } +} + +// For Twig 1.x compatibility +class_alias('Twig\TwigFilter', 'Twig_SimpleFilter', false); + +class_alias('Twig\TwigFilter', 'Twig_Filter'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Node\Node'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFunction.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFunction.php new file mode 100644 index 0000000..c5779af --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigFunction.php @@ -0,0 +1,140 @@ + + * + * @see https://twig.symfony.com/doc/templates.html#functions + */ +class TwigFunction +{ + private $name; + private $callable; + private $options; + private $arguments = []; + + /** + * Creates a template function. + * + * @param string $name Name of this function + * @param callable|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation. + * @param array $options Options array + */ + public function __construct(string $name, $callable = null, array $options = []) + { + if (__CLASS__ !== \get_class($this)) { + @trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); + } + + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'node_class' => FunctionExpression::class, + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName() + { + return $this->name; + } + + /** + * Returns the callable to execute for this function. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Node $functionArgs) + { + if (null !== $this->options['is_safe']) { + return $this->options['is_safe']; + } + + if (null !== $this->options['is_safe_callback']) { + return $this->options['is_safe_callback']($functionArgs); + } + + return []; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } +} + +// For Twig 1.x compatibility +class_alias('Twig\TwigFunction', 'Twig_SimpleFunction', false); + +class_alias('Twig\TwigFunction', 'Twig_Function'); + +// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name. +class_exists('Twig\Node\Node'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigTest.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigTest.php new file mode 100644 index 0000000..e15da41 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/TwigTest.php @@ -0,0 +1,109 @@ + + * + * @see https://twig.symfony.com/doc/templates.html#test-operator + */ +class TwigTest +{ + private $name; + private $callable; + private $options; + private $arguments = []; + + /** + * Creates a template test. + * + * @param string $name Name of this test + * @param callable|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation. + * @param array $options Options array + */ + public function __construct(string $name, $callable = null, array $options = []) + { + if (__CLASS__ !== \get_class($this)) { + @trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED); + } + + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'is_variadic' => false, + 'node_class' => TestExpression::class, + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName() + { + return $this->name; + } + + /** + * Returns the callable to execute for this test. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + + public function setArguments($arguments) + { + $this->arguments = $arguments; + } + + public function getArguments() + { + return $this->arguments; + } + + public function isVariadic() + { + return $this->options['is_variadic']; + } + + public function isDeprecated() + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } +} + +// For Twig 1.x compatibility +class_alias('Twig\TwigTest', 'Twig_SimpleTest', false); + +class_alias('Twig\TwigTest', 'Twig_Test'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Util/DeprecationCollector.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Util/DeprecationCollector.php new file mode 100644 index 0000000..d373698 --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Util/DeprecationCollector.php @@ -0,0 +1,79 @@ + + */ +final class DeprecationCollector +{ + private $twig; + + public function __construct(Environment $twig) + { + $this->twig = $twig; + } + + /** + * Returns deprecations for templates contained in a directory. + * + * @param string $dir A directory where templates are stored + * @param string $ext Limit the loaded templates by extension + * + * @return array An array of deprecations + */ + public function collectDir($dir, $ext = '.twig') + { + $iterator = new \RegexIterator( + new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY + ), '{'.preg_quote($ext).'$}' + ); + + return $this->collect(new TemplateDirIterator($iterator)); + } + + /** + * Returns deprecations for passed templates. + * + * @param \Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) + * + * @return array An array of deprecations + */ + public function collect(\Traversable $iterator) + { + $deprecations = []; + set_error_handler(function ($type, $msg) use (&$deprecations) { + if (E_USER_DEPRECATED === $type) { + $deprecations[] = $msg; + } + }); + + foreach ($iterator as $name => $contents) { + try { + $this->twig->parse($this->twig->tokenize(new Source($contents, $name))); + } catch (SyntaxError $e) { + // ignore templates containing syntax errors + } + } + + restore_error_handler(); + + return $deprecations; + } +} + +class_alias('Twig\Util\DeprecationCollector', 'Twig_Util_DeprecationCollector'); diff --git a/system/templateEngines/Twig/Twig2x/twig/twig/src/Util/TemplateDirIterator.php b/system/templateEngines/Twig/Twig2x/twig/twig/src/Util/TemplateDirIterator.php new file mode 100644 index 0000000..1ab0dac --- /dev/null +++ b/system/templateEngines/Twig/Twig2x/twig/twig/src/Util/TemplateDirIterator.php @@ -0,0 +1,30 @@ + + */ +class TemplateDirIterator extends \IteratorIterator +{ + public function current() + { + return file_get_contents(parent::current()); + } + + public function key() + { + return (string) parent::key(); + } +} + +class_alias('Twig\Util\TemplateDirIterator', 'Twig_Util_TemplateDirIterator'); diff --git a/system/templateEngines/Twig/Twig3x/autoload.php b/system/templateEngines/Twig/Twig3x/autoload.php new file mode 100644 index 0000000..b50fdd5 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/system/templateEngines/Twig/Twig3x/composer/LICENSE b/system/templateEngines/Twig/Twig3x/composer/LICENSE new file mode 100644 index 0000000..f27399a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/system/templateEngines/Twig/Twig3x/composer/autoload_classmap.php b/system/templateEngines/Twig/Twig3x/composer/autoload_classmap.php new file mode 100644 index 0000000..7a91153 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', +); diff --git a/system/templateEngines/Twig/Twig3x/composer/autoload_namespaces.php b/system/templateEngines/Twig/Twig3x/composer/autoload_namespaces.php new file mode 100644 index 0000000..b7fc012 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ + array($vendorDir . '/twig/twig/src'), + 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), + 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), +); diff --git a/system/templateEngines/Twig/Twig3x/composer/autoload_real.php b/system/templateEngines/Twig/Twig3x/composer/autoload_real.php new file mode 100644 index 0000000..8241014 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/composer/autoload_real.php @@ -0,0 +1,70 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit0954af8c5efdf1293c217a08878bc70b::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + if ($useStaticLoader) { + $includeFiles = Composer\Autoload\ComposerStaticInit0954af8c5efdf1293c217a08878bc70b::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } + foreach ($includeFiles as $fileIdentifier => $file) { + composerRequire0954af8c5efdf1293c217a08878bc70b($fileIdentifier, $file); + } + + return $loader; + } +} + +function composerRequire0954af8c5efdf1293c217a08878bc70b($fileIdentifier, $file) +{ + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { + require $file; + + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + } +} diff --git a/system/templateEngines/Twig/Twig3x/composer/autoload_static.php b/system/templateEngines/Twig/Twig3x/composer/autoload_static.php new file mode 100644 index 0000000..188a6c9 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/composer/autoload_static.php @@ -0,0 +1,49 @@ + __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', + '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', + ); + + public static $prefixLengthsPsr4 = array ( + 'T' => + array ( + 'Twig\\' => 5, + ), + 'S' => + array ( + 'Symfony\\Polyfill\\Mbstring\\' => 26, + 'Symfony\\Polyfill\\Ctype\\' => 23, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Twig\\' => + array ( + 0 => __DIR__ . '/..' . '/twig/twig/src', + ), + 'Symfony\\Polyfill\\Mbstring\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring', + ), + 'Symfony\\Polyfill\\Ctype\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit0954af8c5efdf1293c217a08878bc70b::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit0954af8c5efdf1293c217a08878bc70b::$prefixDirsPsr4; + + }, null, ClassLoader::class); + } +} diff --git a/system/templateEngines/Twig/Twig3x/composer/installed.json b/system/templateEngines/Twig/Twig3x/composer/installed.json new file mode 100644 index 0000000..3f98788 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/composer/installed.json @@ -0,0 +1,187 @@ +[ + { + "name": "symfony/polyfill-ctype", + "version": "v1.14.0", + "version_normalized": "1.14.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "time": "2020-01-13T11:15:53+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ] + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.14.0", + "version_normalized": "1.14.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/34094cfa9abe1f0f14f48f490772db7a775559f2", + "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "time": "2020-01-13T11:15:53+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ] + }, + { + "name": "twig/twig", + "version": "v3.0.3", + "version_normalized": "3.0.3.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "3b88ccd180a6b61ebb517aea3b1a8906762a1dc2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3b88ccd180a6b61ebb517aea3b1a8906762a1dc2", + "reference": "3b88ccd180a6b61ebb517aea3b1a8906762a1dc2", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/phpunit-bridge": "^4.4|^5.0" + }, + "time": "2020-02-11T15:33:47+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ] + } +] diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/Ctype.php b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/Ctype.php new file mode 100644 index 0000000..58414dc --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/Ctype.php @@ -0,0 +1,227 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Ctype; + +/** + * Ctype implementation through regex. + * + * @internal + * + * @author Gert de Pagter + */ +final class Ctype +{ + /** + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. + * + * @see https://php.net/ctype-alnum + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alnum($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is a letter, FALSE otherwise. + * + * @see https://php.net/ctype-alpha + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alpha($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); + } + + /** + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. + * + * @see https://php.net/ctype-cntrl + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_cntrl($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); + } + + /** + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. + * + * @see https://php.net/ctype-digit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_digit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. + * + * @see https://php.net/ctype-graph + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_graph($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); + } + + /** + * Returns TRUE if every character in text is a lowercase letter. + * + * @see https://php.net/ctype-lower + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_lower($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-print + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_print($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); + } + + /** + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. + * + * @see https://php.net/ctype-punct + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_punct($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-space + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_space($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); + } + + /** + * Returns TRUE if every character in text is an uppercase letter. + * + * @see https://php.net/ctype-upper + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_upper($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); + } + + /** + * 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. + * + * @see https://php.net/ctype-xdigit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_xdigit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); + } + + /** + * Converts integers to their char versions according to normal ctype behaviour, if needed. + * + * If an integer between -128 and 255 inclusive is provided, + * it is interpreted as the ASCII value of a single character + * (negative values have 256 added in order to allow characters in the Extended ASCII range). + * Any other integer is interpreted as a string containing the decimal digits of the integer. + * + * @param string|int $int + * + * @return mixed + */ + private static function convert_int_to_char_for_ctype($int) + { + if (!\is_int($int)) { + return $int; + } + + if ($int < -128 || $int > 255) { + return (string) $int; + } + + if ($int < 0) { + $int += 256; + } + + return \chr($int); + } +} diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/LICENSE b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/LICENSE new file mode 100644 index 0000000..3f853aa --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/README.md b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/README.md new file mode 100644 index 0000000..8add1ab --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/README.md @@ -0,0 +1,12 @@ +Symfony Polyfill / Ctype +======================== + +This component provides `ctype_*` functions to users who run php versions without the ctype extension. + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/bootstrap.php b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/bootstrap.php new file mode 100644 index 0000000..14d1d0f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/bootstrap.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (!function_exists('ctype_alnum')) { + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } + function ctype_print($text) { return p\Ctype::ctype_print($text); } + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } + function ctype_space($text) { return p\Ctype::ctype_space($text); } + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } +} diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/composer.json b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/composer.json new file mode 100644 index 0000000..2596c74 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-ctype/composer.json @@ -0,0 +1,34 @@ +{ + "name": "symfony/polyfill-ctype", + "type": "library", + "description": "Symfony polyfill for ctype functions", + "keywords": ["polyfill", "compatibility", "portable", "ctype"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.3" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Ctype\\": "" }, + "files": [ "bootstrap.php" ] + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/LICENSE b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/LICENSE new file mode 100644 index 0000000..4cd8bdd --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015-2019 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Mbstring.php b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Mbstring.php new file mode 100644 index 0000000..15503bc --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Mbstring.php @@ -0,0 +1,847 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Mbstring; + +/** + * Partial mbstring implementation in PHP, iconv based, UTF-8 centric. + * + * Implemented: + * - mb_chr - Returns a specific character from its Unicode code point + * - mb_convert_encoding - Convert character encoding + * - mb_convert_variables - Convert character code in variable(s) + * - mb_decode_mimeheader - Decode string in MIME header field + * - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED + * - mb_decode_numericentity - Decode HTML numeric string reference to character + * - mb_encode_numericentity - Encode character to HTML numeric string reference + * - mb_convert_case - Perform case folding on a string + * - mb_detect_encoding - Detect character encoding + * - mb_get_info - Get internal settings of mbstring + * - mb_http_input - Detect HTTP input character encoding + * - mb_http_output - Set/Get HTTP output character encoding + * - mb_internal_encoding - Set/Get internal character encoding + * - mb_list_encodings - Returns an array of all supported encodings + * - mb_ord - Returns the Unicode code point of a character + * - mb_output_handler - Callback function converts character encoding in output buffer + * - mb_scrub - Replaces ill-formed byte sequences with substitute characters + * - mb_strlen - Get string length + * - mb_strpos - Find position of first occurrence of string in a string + * - mb_strrpos - Find position of last occurrence of a string in a string + * - mb_str_split - Convert a string to an array + * - mb_strtolower - Make a string lowercase + * - mb_strtoupper - Make a string uppercase + * - mb_substitute_character - Set/Get substitution character + * - mb_substr - Get part of string + * - mb_stripos - Finds position of first occurrence of a string within another, case insensitive + * - mb_stristr - Finds first occurrence of a string within another, case insensitive + * - mb_strrchr - Finds the last occurrence of a character in a string within another + * - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive + * - mb_strripos - Finds position of last occurrence of a string within another, case insensitive + * - mb_strstr - Finds first occurrence of a string within another + * - mb_strwidth - Return width of string + * - mb_substr_count - Count the number of substring occurrences + * + * Not implemented: + * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more) + * - mb_ereg_* - Regular expression with multibyte support + * - mb_parse_str - Parse GET/POST/COOKIE data and set global variable + * - mb_preferred_mime_name - Get MIME charset string + * - mb_regex_encoding - Returns current encoding for multibyte regex as string + * - mb_regex_set_options - Set/Get the default options for mbregex functions + * - mb_send_mail - Send encoded mail + * - mb_split - Split multibyte string using regular expression + * - mb_strcut - Get part of string + * - mb_strimwidth - Get truncated string with specified width + * + * @author Nicolas Grekas + * + * @internal + */ +final class Mbstring +{ + const MB_CASE_FOLD = PHP_INT_MAX; + + private static $encodingList = array('ASCII', 'UTF-8'); + private static $language = 'neutral'; + private static $internalEncoding = 'UTF-8'; + private static $caseFold = array( + array('µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"), + array('μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'), + ); + + public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) + { + if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) { + $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); + } else { + $fromEncoding = self::getEncoding($fromEncoding); + } + + $toEncoding = self::getEncoding($toEncoding); + + if ('BASE64' === $fromEncoding) { + $s = base64_decode($s); + $fromEncoding = $toEncoding; + } + + if ('BASE64' === $toEncoding) { + return base64_encode($s); + } + + if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) { + if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) { + $fromEncoding = 'Windows-1252'; + } + if ('UTF-8' !== $fromEncoding) { + $s = iconv($fromEncoding, 'UTF-8//IGNORE', $s); + } + + return preg_replace_callback('/[\x80-\xFF]+/', array(__CLASS__, 'html_encoding_callback'), $s); + } + + if ('HTML-ENTITIES' === $fromEncoding) { + $s = html_entity_decode($s, ENT_COMPAT, 'UTF-8'); + $fromEncoding = 'UTF-8'; + } + + return iconv($fromEncoding, $toEncoding.'//IGNORE', $s); + } + + public static function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null) + { + $vars = array(&$a, &$b, &$c, &$d, &$e, &$f); + + $ok = true; + array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) { + if (false === $v = Mbstring::mb_convert_encoding($v, $toEncoding, $fromEncoding)) { + $ok = false; + } + }); + + return $ok ? $fromEncoding : false; + } + + public static function mb_decode_mimeheader($s) + { + return iconv_mime_decode($s, 2, self::$internalEncoding); + } + + public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null) + { + trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING); + } + + public static function mb_decode_numericentity($s, $convmap, $encoding = null) + { + if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { + trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return null; + } + + if (!\is_array($convmap) || !$convmap) { + return false; + } + + if (null !== $encoding && !\is_scalar($encoding)) { + trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return ''; // Instead of null (cf. mb_encode_numericentity). + } + + $s = (string) $s; + if ('' === $s) { + return ''; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding) { + $encoding = null; + if (!preg_match('//u', $s)) { + $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s); + } + } else { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + $cnt = floor(\count($convmap) / 4) * 4; + + for ($i = 0; $i < $cnt; $i += 4) { + // collector_decode_htmlnumericentity ignores $convmap[$i + 3] + $convmap[$i] += $convmap[$i + 2]; + $convmap[$i + 1] += $convmap[$i + 2]; + } + + $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) { + $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1]; + for ($i = 0; $i < $cnt; $i += 4) { + if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { + return Mbstring::mb_chr($c - $convmap[$i + 2]); + } + } + + return $m[0]; + }, $s); + + if (null === $encoding) { + return $s; + } + + return iconv('UTF-8', $encoding.'//IGNORE', $s); + } + + public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) + { + if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) { + trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return null; + } + + if (!\is_array($convmap) || !$convmap) { + return false; + } + + if (null !== $encoding && !\is_scalar($encoding)) { + trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', E_USER_WARNING); + + return null; // Instead of '' (cf. mb_decode_numericentity). + } + + if (null !== $is_hex && !\is_scalar($is_hex)) { + trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', E_USER_WARNING); + + return null; + } + + $s = (string) $s; + if ('' === $s) { + return ''; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding) { + $encoding = null; + if (!preg_match('//u', $s)) { + $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s); + } + } else { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); + + $cnt = floor(\count($convmap) / 4) * 4; + $i = 0; + $len = \strlen($s); + $result = ''; + + while ($i < $len) { + $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; + $uchr = substr($s, $i, $ulen); + $i += $ulen; + $c = self::mb_ord($uchr); + + for ($j = 0; $j < $cnt; $j += 4) { + if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) { + $cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3]; + $result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';'; + continue 2; + } + } + $result .= $uchr; + } + + if (null === $encoding) { + return $result; + } + + return iconv('UTF-8', $encoding.'//IGNORE', $result); + } + + public static function mb_convert_case($s, $mode, $encoding = null) + { + $s = (string) $s; + if ('' === $s) { + return ''; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding) { + $encoding = null; + if (!preg_match('//u', $s)) { + $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s); + } + } else { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + if (MB_CASE_TITLE == $mode) { + static $titleRegexp = null; + if (null === $titleRegexp) { + $titleRegexp = self::getData('titleCaseRegexp'); + } + $s = preg_replace_callback($titleRegexp, array(__CLASS__, 'title_case'), $s); + } else { + if (MB_CASE_UPPER == $mode) { + static $upper = null; + if (null === $upper) { + $upper = self::getData('upperCase'); + } + $map = $upper; + } else { + if (self::MB_CASE_FOLD === $mode) { + $s = str_replace(self::$caseFold[0], self::$caseFold[1], $s); + } + + static $lower = null; + if (null === $lower) { + $lower = self::getData('lowerCase'); + } + $map = $lower; + } + + static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4); + + $i = 0; + $len = \strlen($s); + + while ($i < $len) { + $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; + $uchr = substr($s, $i, $ulen); + $i += $ulen; + + if (isset($map[$uchr])) { + $uchr = $map[$uchr]; + $nlen = \strlen($uchr); + + if ($nlen == $ulen) { + $nlen = $i; + do { + $s[--$nlen] = $uchr[--$ulen]; + } while ($ulen); + } else { + $s = substr_replace($s, $uchr, $i - $ulen, $ulen); + $len += $nlen - $ulen; + $i += $nlen - $ulen; + } + } + } + } + + if (null === $encoding) { + return $s; + } + + return iconv('UTF-8', $encoding.'//IGNORE', $s); + } + + public static function mb_internal_encoding($encoding = null) + { + if (null === $encoding) { + return self::$internalEncoding; + } + + $encoding = self::getEncoding($encoding); + + if ('UTF-8' === $encoding || false !== @iconv($encoding, $encoding, ' ')) { + self::$internalEncoding = $encoding; + + return true; + } + + return false; + } + + public static function mb_language($lang = null) + { + if (null === $lang) { + return self::$language; + } + + switch ($lang = strtolower($lang)) { + case 'uni': + case 'neutral': + self::$language = $lang; + + return true; + } + + return false; + } + + public static function mb_list_encodings() + { + return array('UTF-8'); + } + + public static function mb_encoding_aliases($encoding) + { + switch (strtoupper($encoding)) { + case 'UTF8': + case 'UTF-8': + return array('utf8'); + } + + return false; + } + + public static function mb_check_encoding($var = null, $encoding = null) + { + if (null === $encoding) { + if (null === $var) { + return false; + } + $encoding = self::$internalEncoding; + } + + return self::mb_detect_encoding($var, array($encoding)) || false !== @iconv($encoding, $encoding, $var); + } + + public static function mb_detect_encoding($str, $encodingList = null, $strict = false) + { + if (null === $encodingList) { + $encodingList = self::$encodingList; + } else { + if (!\is_array($encodingList)) { + $encodingList = array_map('trim', explode(',', $encodingList)); + } + $encodingList = array_map('strtoupper', $encodingList); + } + + foreach ($encodingList as $enc) { + switch ($enc) { + case 'ASCII': + if (!preg_match('/[\x80-\xFF]/', $str)) { + return $enc; + } + break; + + case 'UTF8': + case 'UTF-8': + if (preg_match('//u', $str)) { + return 'UTF-8'; + } + break; + + default: + if (0 === strncmp($enc, 'ISO-8859-', 9)) { + return $enc; + } + } + } + + return false; + } + + public static function mb_detect_order($encodingList = null) + { + if (null === $encodingList) { + return self::$encodingList; + } + + if (!\is_array($encodingList)) { + $encodingList = array_map('trim', explode(',', $encodingList)); + } + $encodingList = array_map('strtoupper', $encodingList); + + foreach ($encodingList as $enc) { + switch ($enc) { + default: + if (strncmp($enc, 'ISO-8859-', 9)) { + return false; + } + // no break + case 'ASCII': + case 'UTF8': + case 'UTF-8': + } + } + + self::$encodingList = $encodingList; + + return true; + } + + public static function mb_strlen($s, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return \strlen($s); + } + + return @iconv_strlen($s, $encoding); + } + + public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return strpos($haystack, $needle, $offset); + } + + $needle = (string) $needle; + if ('' === $needle) { + trigger_error(__METHOD__.': Empty delimiter', E_USER_WARNING); + + return false; + } + + return iconv_strpos($haystack, $needle, $offset, $encoding); + } + + public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return strrpos($haystack, $needle, $offset); + } + + if ($offset != (int) $offset) { + $offset = 0; + } elseif ($offset = (int) $offset) { + if ($offset < 0) { + if (0 > $offset += self::mb_strlen($needle)) { + $haystack = self::mb_substr($haystack, 0, $offset, $encoding); + } + $offset = 0; + } else { + $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding); + } + } + + $pos = iconv_strrpos($haystack, $needle, $encoding); + + return false !== $pos ? $offset + $pos : false; + } + + public static function mb_str_split($string, $split_length = 1, $encoding = null) + { + if (null !== $string && !\is_scalar($string) && !(\is_object($string) && \method_exists($string, '__toString'))) { + trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', E_USER_WARNING); + + return null; + } + + if (1 > $split_length = (int) $split_length) { + trigger_error('The length of each segment must be greater than zero', E_USER_WARNING); + + return false; + } + + if (null === $encoding) { + $encoding = mb_internal_encoding(); + } + + if ('UTF-8' === $encoding = self::getEncoding($encoding)) { + $rx = '/('; + while (65535 < $split_length) { + $rx .= '.{65535}'; + $split_length -= 65535; + } + $rx .= '.{'.$split_length.'})/us'; + + return preg_split($rx, $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + } + + $result = array(); + $length = mb_strlen($string, $encoding); + + for ($i = 0; $i < $length; $i += $split_length) { + $result[] = mb_substr($string, $i, $split_length, $encoding); + } + + return $result; + } + + public static function mb_strtolower($s, $encoding = null) + { + return self::mb_convert_case($s, MB_CASE_LOWER, $encoding); + } + + public static function mb_strtoupper($s, $encoding = null) + { + return self::mb_convert_case($s, MB_CASE_UPPER, $encoding); + } + + public static function mb_substitute_character($c = null) + { + if (0 === strcasecmp($c, 'none')) { + return true; + } + + return null !== $c ? false : 'none'; + } + + public static function mb_substr($s, $start, $length = null, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return (string) substr($s, $start, null === $length ? 2147483647 : $length); + } + + if ($start < 0) { + $start = iconv_strlen($s, $encoding) + $start; + if ($start < 0) { + $start = 0; + } + } + + if (null === $length) { + $length = 2147483647; + } elseif ($length < 0) { + $length = iconv_strlen($s, $encoding) + $length - $start; + if ($length < 0) { + return ''; + } + } + + return (string) iconv_substr($s, $start, $length, $encoding); + } + + public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) + { + $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); + $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); + + return self::mb_strpos($haystack, $needle, $offset, $encoding); + } + + public static function mb_stristr($haystack, $needle, $part = false, $encoding = null) + { + $pos = self::mb_stripos($haystack, $needle, 0, $encoding); + + return self::getSubpart($pos, $part, $haystack, $encoding); + } + + public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null) + { + $encoding = self::getEncoding($encoding); + if ('CP850' === $encoding || 'ASCII' === $encoding) { + return strrchr($haystack, $needle, $part); + } + $needle = self::mb_substr($needle, 0, 1, $encoding); + $pos = iconv_strrpos($haystack, $needle, $encoding); + + return self::getSubpart($pos, $part, $haystack, $encoding); + } + + public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null) + { + $needle = self::mb_substr($needle, 0, 1, $encoding); + $pos = self::mb_strripos($haystack, $needle, $encoding); + + return self::getSubpart($pos, $part, $haystack, $encoding); + } + + public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) + { + $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); + $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); + + return self::mb_strrpos($haystack, $needle, $offset, $encoding); + } + + public static function mb_strstr($haystack, $needle, $part = false, $encoding = null) + { + $pos = strpos($haystack, $needle); + if (false === $pos) { + return false; + } + if ($part) { + return substr($haystack, 0, $pos); + } + + return substr($haystack, $pos); + } + + public static function mb_get_info($type = 'all') + { + $info = array( + 'internal_encoding' => self::$internalEncoding, + 'http_output' => 'pass', + 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)', + 'func_overload' => 0, + 'func_overload_list' => 'no overload', + 'mail_charset' => 'UTF-8', + 'mail_header_encoding' => 'BASE64', + 'mail_body_encoding' => 'BASE64', + 'illegal_chars' => 0, + 'encoding_translation' => 'Off', + 'language' => self::$language, + 'detect_order' => self::$encodingList, + 'substitute_character' => 'none', + 'strict_detection' => 'Off', + ); + + if ('all' === $type) { + return $info; + } + if (isset($info[$type])) { + return $info[$type]; + } + + return false; + } + + public static function mb_http_input($type = '') + { + return false; + } + + public static function mb_http_output($encoding = null) + { + return null !== $encoding ? 'pass' === $encoding : 'pass'; + } + + public static function mb_strwidth($s, $encoding = null) + { + $encoding = self::getEncoding($encoding); + + if ('UTF-8' !== $encoding) { + $s = iconv($encoding, 'UTF-8//IGNORE', $s); + } + + $s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide); + + return ($wide << 1) + iconv_strlen($s, 'UTF-8'); + } + + public static function mb_substr_count($haystack, $needle, $encoding = null) + { + return substr_count($haystack, $needle); + } + + public static function mb_output_handler($contents, $status) + { + return $contents; + } + + public static function mb_chr($code, $encoding = null) + { + if (0x80 > $code %= 0x200000) { + $s = \chr($code); + } elseif (0x800 > $code) { + $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); + } elseif (0x10000 > $code) { + $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); + } else { + $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); + } + + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { + $s = mb_convert_encoding($s, $encoding, 'UTF-8'); + } + + return $s; + } + + public static function mb_ord($s, $encoding = null) + { + if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { + $s = mb_convert_encoding($s, 'UTF-8', $encoding); + } + + if (1 === \strlen($s)) { + return \ord($s); + } + + $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; + if (0xF0 <= $code) { + return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; + } + if (0xE0 <= $code) { + return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; + } + if (0xC0 <= $code) { + return (($code - 0xC0) << 6) + $s[2] - 0x80; + } + + return $code; + } + + private static function getSubpart($pos, $part, $haystack, $encoding) + { + if (false === $pos) { + return false; + } + if ($part) { + return self::mb_substr($haystack, 0, $pos, $encoding); + } + + return self::mb_substr($haystack, $pos, null, $encoding); + } + + private static function html_encoding_callback(array $m) + { + $i = 1; + $entities = ''; + $m = unpack('C*', htmlentities($m[0], ENT_COMPAT, 'UTF-8')); + + while (isset($m[$i])) { + if (0x80 > $m[$i]) { + $entities .= \chr($m[$i++]); + continue; + } + if (0xF0 <= $m[$i]) { + $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; + } elseif (0xE0 <= $m[$i]) { + $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; + } else { + $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; + } + + $entities .= '&#'.$c.';'; + } + + return $entities; + } + + private static function title_case(array $s) + { + return self::mb_convert_case($s[1], MB_CASE_UPPER, 'UTF-8').self::mb_convert_case($s[2], MB_CASE_LOWER, 'UTF-8'); + } + + private static function getData($file) + { + if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) { + return require $file; + } + + return false; + } + + private static function getEncoding($encoding) + { + if (null === $encoding) { + return self::$internalEncoding; + } + + if ('UTF-8' === $encoding) { + return 'UTF-8'; + } + + $encoding = strtoupper($encoding); + + if ('8BIT' === $encoding || 'BINARY' === $encoding) { + return 'CP850'; + } + + if ('UTF8' === $encoding) { + return 'UTF-8'; + } + + return $encoding; + } +} diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/README.md b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/README.md new file mode 100644 index 0000000..342e828 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/README.md @@ -0,0 +1,13 @@ +Symfony Polyfill / Mbstring +=========================== + +This component provides a partial, native PHP implementation for the +[Mbstring](http://php.net/mbstring) extension. + +More information can be found in the +[main Polyfill README](https://github.com/symfony/polyfill/blob/master/README.md). + +License +======= + +This library is released under the [MIT license](LICENSE). diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php new file mode 100644 index 0000000..e6fbfa6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php @@ -0,0 +1,1096 @@ + 'a', + 'B' => 'b', + 'C' => 'c', + 'D' => 'd', + 'E' => 'e', + 'F' => 'f', + 'G' => 'g', + 'H' => 'h', + 'I' => 'i', + 'J' => 'j', + 'K' => 'k', + 'L' => 'l', + 'M' => 'm', + 'N' => 'n', + 'O' => 'o', + 'P' => 'p', + 'Q' => 'q', + 'R' => 'r', + 'S' => 's', + 'T' => 't', + 'U' => 'u', + 'V' => 'v', + 'W' => 'w', + 'X' => 'x', + 'Y' => 'y', + 'Z' => 'z', + 'À' => 'à', + 'Á' => 'á', + 'Â' => 'â', + 'Ã' => 'ã', + 'Ä' => 'ä', + 'Å' => 'å', + 'Æ' => 'æ', + 'Ç' => 'ç', + 'È' => 'è', + 'É' => 'é', + 'Ê' => 'ê', + 'Ë' => 'ë', + 'Ì' => 'ì', + 'Í' => 'í', + 'Î' => 'î', + 'Ï' => 'ï', + 'Ð' => 'ð', + 'Ñ' => 'ñ', + 'Ò' => 'ò', + 'Ó' => 'ó', + 'Ô' => 'ô', + 'Õ' => 'õ', + 'Ö' => 'ö', + 'Ø' => 'ø', + 'Ù' => 'ù', + 'Ú' => 'ú', + 'Û' => 'û', + 'Ü' => 'ü', + 'Ý' => 'ý', + 'Þ' => 'þ', + 'Ā' => 'ā', + 'Ă' => 'ă', + 'Ą' => 'ą', + 'Ć' => 'ć', + 'Ĉ' => 'ĉ', + 'Ċ' => 'ċ', + 'Č' => 'č', + 'Ď' => 'ď', + 'Đ' => 'đ', + 'Ē' => 'ē', + 'Ĕ' => 'ĕ', + 'Ė' => 'ė', + 'Ę' => 'ę', + 'Ě' => 'ě', + 'Ĝ' => 'ĝ', + 'Ğ' => 'ğ', + 'Ġ' => 'ġ', + 'Ģ' => 'ģ', + 'Ĥ' => 'ĥ', + 'Ħ' => 'ħ', + 'Ĩ' => 'ĩ', + 'Ī' => 'ī', + 'Ĭ' => 'ĭ', + 'Į' => 'į', + 'İ' => 'i', + 'IJ' => 'ij', + 'Ĵ' => 'ĵ', + 'Ķ' => 'ķ', + 'Ĺ' => 'ĺ', + 'Ļ' => 'ļ', + 'Ľ' => 'ľ', + 'Ŀ' => 'ŀ', + 'Ł' => 'ł', + 'Ń' => 'ń', + 'Ņ' => 'ņ', + 'Ň' => 'ň', + 'Ŋ' => 'ŋ', + 'Ō' => 'ō', + 'Ŏ' => 'ŏ', + 'Ő' => 'ő', + 'Œ' => 'œ', + 'Ŕ' => 'ŕ', + 'Ŗ' => 'ŗ', + 'Ř' => 'ř', + 'Ś' => 'ś', + 'Ŝ' => 'ŝ', + 'Ş' => 'ş', + 'Š' => 'š', + 'Ţ' => 'ţ', + 'Ť' => 'ť', + 'Ŧ' => 'ŧ', + 'Ũ' => 'ũ', + 'Ū' => 'ū', + 'Ŭ' => 'ŭ', + 'Ů' => 'ů', + 'Ű' => 'ű', + 'Ų' => 'ų', + 'Ŵ' => 'ŵ', + 'Ŷ' => 'ŷ', + 'Ÿ' => 'ÿ', + 'Ź' => 'ź', + 'Ż' => 'ż', + 'Ž' => 'ž', + 'Ɓ' => 'ɓ', + 'Ƃ' => 'ƃ', + 'Ƅ' => 'ƅ', + 'Ɔ' => 'ɔ', + 'Ƈ' => 'ƈ', + 'Ɖ' => 'ɖ', + 'Ɗ' => 'ɗ', + 'Ƌ' => 'ƌ', + 'Ǝ' => 'ǝ', + 'Ə' => 'ə', + 'Ɛ' => 'ɛ', + 'Ƒ' => 'ƒ', + 'Ɠ' => 'ɠ', + 'Ɣ' => 'ɣ', + 'Ɩ' => 'ɩ', + 'Ɨ' => 'ɨ', + 'Ƙ' => 'ƙ', + 'Ɯ' => 'ɯ', + 'Ɲ' => 'ɲ', + 'Ɵ' => 'ɵ', + 'Ơ' => 'ơ', + 'Ƣ' => 'ƣ', + 'Ƥ' => 'ƥ', + 'Ʀ' => 'ʀ', + 'Ƨ' => 'ƨ', + 'Ʃ' => 'ʃ', + 'Ƭ' => 'ƭ', + 'Ʈ' => 'ʈ', + 'Ư' => 'ư', + 'Ʊ' => 'ʊ', + 'Ʋ' => 'ʋ', + 'Ƴ' => 'ƴ', + 'Ƶ' => 'ƶ', + 'Ʒ' => 'ʒ', + 'Ƹ' => 'ƹ', + 'Ƽ' => 'ƽ', + 'DŽ' => 'dž', + 'Dž' => 'dž', + 'LJ' => 'lj', + 'Lj' => 'lj', + 'NJ' => 'nj', + 'Nj' => 'nj', + 'Ǎ' => 'ǎ', + 'Ǐ' => 'ǐ', + 'Ǒ' => 'ǒ', + 'Ǔ' => 'ǔ', + 'Ǖ' => 'ǖ', + 'Ǘ' => 'ǘ', + 'Ǚ' => 'ǚ', + 'Ǜ' => 'ǜ', + 'Ǟ' => 'ǟ', + 'Ǡ' => 'ǡ', + 'Ǣ' => 'ǣ', + 'Ǥ' => 'ǥ', + 'Ǧ' => 'ǧ', + 'Ǩ' => 'ǩ', + 'Ǫ' => 'ǫ', + 'Ǭ' => 'ǭ', + 'Ǯ' => 'ǯ', + 'DZ' => 'dz', + 'Dz' => 'dz', + 'Ǵ' => 'ǵ', + 'Ƕ' => 'ƕ', + 'Ƿ' => 'ƿ', + 'Ǹ' => 'ǹ', + 'Ǻ' => 'ǻ', + 'Ǽ' => 'ǽ', + 'Ǿ' => 'ǿ', + 'Ȁ' => 'ȁ', + 'Ȃ' => 'ȃ', + 'Ȅ' => 'ȅ', + 'Ȇ' => 'ȇ', + 'Ȉ' => 'ȉ', + 'Ȋ' => 'ȋ', + 'Ȍ' => 'ȍ', + 'Ȏ' => 'ȏ', + 'Ȑ' => 'ȑ', + 'Ȓ' => 'ȓ', + 'Ȕ' => 'ȕ', + 'Ȗ' => 'ȗ', + 'Ș' => 'ș', + 'Ț' => 'ț', + 'Ȝ' => 'ȝ', + 'Ȟ' => 'ȟ', + 'Ƞ' => 'ƞ', + 'Ȣ' => 'ȣ', + 'Ȥ' => 'ȥ', + 'Ȧ' => 'ȧ', + 'Ȩ' => 'ȩ', + 'Ȫ' => 'ȫ', + 'Ȭ' => 'ȭ', + 'Ȯ' => 'ȯ', + 'Ȱ' => 'ȱ', + 'Ȳ' => 'ȳ', + 'Ⱥ' => 'ⱥ', + 'Ȼ' => 'ȼ', + 'Ƚ' => 'ƚ', + 'Ⱦ' => 'ⱦ', + 'Ɂ' => 'ɂ', + 'Ƀ' => 'ƀ', + 'Ʉ' => 'ʉ', + 'Ʌ' => 'ʌ', + 'Ɇ' => 'ɇ', + 'Ɉ' => 'ɉ', + 'Ɋ' => 'ɋ', + 'Ɍ' => 'ɍ', + 'Ɏ' => 'ɏ', + 'Ͱ' => 'ͱ', + 'Ͳ' => 'ͳ', + 'Ͷ' => 'ͷ', + 'Ϳ' => 'ϳ', + 'Ά' => 'ά', + 'Έ' => 'έ', + 'Ή' => 'ή', + 'Ί' => 'ί', + 'Ό' => 'ό', + 'Ύ' => 'ύ', + 'Ώ' => 'ώ', + 'Α' => 'α', + 'Β' => 'β', + 'Γ' => 'γ', + 'Δ' => 'δ', + 'Ε' => 'ε', + 'Ζ' => 'ζ', + 'Η' => 'η', + 'Θ' => 'θ', + 'Ι' => 'ι', + 'Κ' => 'κ', + 'Λ' => 'λ', + 'Μ' => 'μ', + 'Ν' => 'ν', + 'Ξ' => 'ξ', + 'Ο' => 'ο', + 'Π' => 'π', + 'Ρ' => 'ρ', + 'Σ' => 'σ', + 'Τ' => 'τ', + 'Υ' => 'υ', + 'Φ' => 'φ', + 'Χ' => 'χ', + 'Ψ' => 'ψ', + 'Ω' => 'ω', + 'Ϊ' => 'ϊ', + 'Ϋ' => 'ϋ', + 'Ϗ' => 'ϗ', + 'Ϙ' => 'ϙ', + 'Ϛ' => 'ϛ', + 'Ϝ' => 'ϝ', + 'Ϟ' => 'ϟ', + 'Ϡ' => 'ϡ', + 'Ϣ' => 'ϣ', + 'Ϥ' => 'ϥ', + 'Ϧ' => 'ϧ', + 'Ϩ' => 'ϩ', + 'Ϫ' => 'ϫ', + 'Ϭ' => 'ϭ', + 'Ϯ' => 'ϯ', + 'ϴ' => 'θ', + 'Ϸ' => 'ϸ', + 'Ϲ' => 'ϲ', + 'Ϻ' => 'ϻ', + 'Ͻ' => 'ͻ', + 'Ͼ' => 'ͼ', + 'Ͽ' => 'ͽ', + 'Ѐ' => 'ѐ', + 'Ё' => 'ё', + 'Ђ' => 'ђ', + 'Ѓ' => 'ѓ', + 'Є' => 'є', + 'Ѕ' => 'ѕ', + 'І' => 'і', + 'Ї' => 'ї', + 'Ј' => 'ј', + 'Љ' => 'љ', + 'Њ' => 'њ', + 'Ћ' => 'ћ', + 'Ќ' => 'ќ', + 'Ѝ' => 'ѝ', + 'Ў' => 'ў', + 'Џ' => 'џ', + 'А' => 'а', + 'Б' => 'б', + 'В' => 'в', + 'Г' => 'г', + 'Д' => 'д', + 'Е' => 'е', + 'Ж' => 'ж', + 'З' => 'з', + 'И' => 'и', + 'Й' => 'й', + 'К' => 'к', + 'Л' => 'л', + 'М' => 'м', + 'Н' => 'н', + 'О' => 'о', + 'П' => 'п', + 'Р' => 'р', + 'С' => 'с', + 'Т' => 'т', + 'У' => 'у', + 'Ф' => 'ф', + 'Х' => 'х', + 'Ц' => 'ц', + 'Ч' => 'ч', + 'Ш' => 'ш', + 'Щ' => 'щ', + 'Ъ' => 'ъ', + 'Ы' => 'ы', + 'Ь' => 'ь', + 'Э' => 'э', + 'Ю' => 'ю', + 'Я' => 'я', + 'Ѡ' => 'ѡ', + 'Ѣ' => 'ѣ', + 'Ѥ' => 'ѥ', + 'Ѧ' => 'ѧ', + 'Ѩ' => 'ѩ', + 'Ѫ' => 'ѫ', + 'Ѭ' => 'ѭ', + 'Ѯ' => 'ѯ', + 'Ѱ' => 'ѱ', + 'Ѳ' => 'ѳ', + 'Ѵ' => 'ѵ', + 'Ѷ' => 'ѷ', + 'Ѹ' => 'ѹ', + 'Ѻ' => 'ѻ', + 'Ѽ' => 'ѽ', + 'Ѿ' => 'ѿ', + 'Ҁ' => 'ҁ', + 'Ҋ' => 'ҋ', + 'Ҍ' => 'ҍ', + 'Ҏ' => 'ҏ', + 'Ґ' => 'ґ', + 'Ғ' => 'ғ', + 'Ҕ' => 'ҕ', + 'Җ' => 'җ', + 'Ҙ' => 'ҙ', + 'Қ' => 'қ', + 'Ҝ' => 'ҝ', + 'Ҟ' => 'ҟ', + 'Ҡ' => 'ҡ', + 'Ң' => 'ң', + 'Ҥ' => 'ҥ', + 'Ҧ' => 'ҧ', + 'Ҩ' => 'ҩ', + 'Ҫ' => 'ҫ', + 'Ҭ' => 'ҭ', + 'Ү' => 'ү', + 'Ұ' => 'ұ', + 'Ҳ' => 'ҳ', + 'Ҵ' => 'ҵ', + 'Ҷ' => 'ҷ', + 'Ҹ' => 'ҹ', + 'Һ' => 'һ', + 'Ҽ' => 'ҽ', + 'Ҿ' => 'ҿ', + 'Ӏ' => 'ӏ', + 'Ӂ' => 'ӂ', + 'Ӄ' => 'ӄ', + 'Ӆ' => 'ӆ', + 'Ӈ' => 'ӈ', + 'Ӊ' => 'ӊ', + 'Ӌ' => 'ӌ', + 'Ӎ' => 'ӎ', + 'Ӑ' => 'ӑ', + 'Ӓ' => 'ӓ', + 'Ӕ' => 'ӕ', + 'Ӗ' => 'ӗ', + 'Ә' => 'ә', + 'Ӛ' => 'ӛ', + 'Ӝ' => 'ӝ', + 'Ӟ' => 'ӟ', + 'Ӡ' => 'ӡ', + 'Ӣ' => 'ӣ', + 'Ӥ' => 'ӥ', + 'Ӧ' => 'ӧ', + 'Ө' => 'ө', + 'Ӫ' => 'ӫ', + 'Ӭ' => 'ӭ', + 'Ӯ' => 'ӯ', + 'Ӱ' => 'ӱ', + 'Ӳ' => 'ӳ', + 'Ӵ' => 'ӵ', + 'Ӷ' => 'ӷ', + 'Ӹ' => 'ӹ', + 'Ӻ' => 'ӻ', + 'Ӽ' => 'ӽ', + 'Ӿ' => 'ӿ', + 'Ԁ' => 'ԁ', + 'Ԃ' => 'ԃ', + 'Ԅ' => 'ԅ', + 'Ԇ' => 'ԇ', + 'Ԉ' => 'ԉ', + 'Ԋ' => 'ԋ', + 'Ԍ' => 'ԍ', + 'Ԏ' => 'ԏ', + 'Ԑ' => 'ԑ', + 'Ԓ' => 'ԓ', + 'Ԕ' => 'ԕ', + 'Ԗ' => 'ԗ', + 'Ԙ' => 'ԙ', + 'Ԛ' => 'ԛ', + 'Ԝ' => 'ԝ', + 'Ԟ' => 'ԟ', + 'Ԡ' => 'ԡ', + 'Ԣ' => 'ԣ', + 'Ԥ' => 'ԥ', + 'Ԧ' => 'ԧ', + 'Ԩ' => 'ԩ', + 'Ԫ' => 'ԫ', + 'Ԭ' => 'ԭ', + 'Ԯ' => 'ԯ', + 'Ա' => 'ա', + 'Բ' => 'բ', + 'Գ' => 'գ', + 'Դ' => 'դ', + 'Ե' => 'ե', + 'Զ' => 'զ', + 'Է' => 'է', + 'Ը' => 'ը', + 'Թ' => 'թ', + 'Ժ' => 'ժ', + 'Ի' => 'ի', + 'Լ' => 'լ', + 'Խ' => 'խ', + 'Ծ' => 'ծ', + 'Կ' => 'կ', + 'Հ' => 'հ', + 'Ձ' => 'ձ', + 'Ղ' => 'ղ', + 'Ճ' => 'ճ', + 'Մ' => 'մ', + 'Յ' => 'յ', + 'Ն' => 'ն', + 'Շ' => 'շ', + 'Ո' => 'ո', + 'Չ' => 'չ', + 'Պ' => 'պ', + 'Ջ' => 'ջ', + 'Ռ' => 'ռ', + 'Ս' => 'ս', + 'Վ' => 'վ', + 'Տ' => 'տ', + 'Ր' => 'ր', + 'Ց' => 'ց', + 'Ւ' => 'ւ', + 'Փ' => 'փ', + 'Ք' => 'ք', + 'Օ' => 'օ', + 'Ֆ' => 'ֆ', + 'Ⴀ' => 'ⴀ', + 'Ⴁ' => 'ⴁ', + 'Ⴂ' => 'ⴂ', + 'Ⴃ' => 'ⴃ', + 'Ⴄ' => 'ⴄ', + 'Ⴅ' => 'ⴅ', + 'Ⴆ' => 'ⴆ', + 'Ⴇ' => 'ⴇ', + 'Ⴈ' => 'ⴈ', + 'Ⴉ' => 'ⴉ', + 'Ⴊ' => 'ⴊ', + 'Ⴋ' => 'ⴋ', + 'Ⴌ' => 'ⴌ', + 'Ⴍ' => 'ⴍ', + 'Ⴎ' => 'ⴎ', + 'Ⴏ' => 'ⴏ', + 'Ⴐ' => 'ⴐ', + 'Ⴑ' => 'ⴑ', + 'Ⴒ' => 'ⴒ', + 'Ⴓ' => 'ⴓ', + 'Ⴔ' => 'ⴔ', + 'Ⴕ' => 'ⴕ', + 'Ⴖ' => 'ⴖ', + 'Ⴗ' => 'ⴗ', + 'Ⴘ' => 'ⴘ', + 'Ⴙ' => 'ⴙ', + 'Ⴚ' => 'ⴚ', + 'Ⴛ' => 'ⴛ', + 'Ⴜ' => 'ⴜ', + 'Ⴝ' => 'ⴝ', + 'Ⴞ' => 'ⴞ', + 'Ⴟ' => 'ⴟ', + 'Ⴠ' => 'ⴠ', + 'Ⴡ' => 'ⴡ', + 'Ⴢ' => 'ⴢ', + 'Ⴣ' => 'ⴣ', + 'Ⴤ' => 'ⴤ', + 'Ⴥ' => 'ⴥ', + 'Ⴧ' => 'ⴧ', + 'Ⴭ' => 'ⴭ', + 'Ḁ' => 'ḁ', + 'Ḃ' => 'ḃ', + 'Ḅ' => 'ḅ', + 'Ḇ' => 'ḇ', + 'Ḉ' => 'ḉ', + 'Ḋ' => 'ḋ', + 'Ḍ' => 'ḍ', + 'Ḏ' => 'ḏ', + 'Ḑ' => 'ḑ', + 'Ḓ' => 'ḓ', + 'Ḕ' => 'ḕ', + 'Ḗ' => 'ḗ', + 'Ḙ' => 'ḙ', + 'Ḛ' => 'ḛ', + 'Ḝ' => 'ḝ', + 'Ḟ' => 'ḟ', + 'Ḡ' => 'ḡ', + 'Ḣ' => 'ḣ', + 'Ḥ' => 'ḥ', + 'Ḧ' => 'ḧ', + 'Ḩ' => 'ḩ', + 'Ḫ' => 'ḫ', + 'Ḭ' => 'ḭ', + 'Ḯ' => 'ḯ', + 'Ḱ' => 'ḱ', + 'Ḳ' => 'ḳ', + 'Ḵ' => 'ḵ', + 'Ḷ' => 'ḷ', + 'Ḹ' => 'ḹ', + 'Ḻ' => 'ḻ', + 'Ḽ' => 'ḽ', + 'Ḿ' => 'ḿ', + 'Ṁ' => 'ṁ', + 'Ṃ' => 'ṃ', + 'Ṅ' => 'ṅ', + 'Ṇ' => 'ṇ', + 'Ṉ' => 'ṉ', + 'Ṋ' => 'ṋ', + 'Ṍ' => 'ṍ', + 'Ṏ' => 'ṏ', + 'Ṑ' => 'ṑ', + 'Ṓ' => 'ṓ', + 'Ṕ' => 'ṕ', + 'Ṗ' => 'ṗ', + 'Ṙ' => 'ṙ', + 'Ṛ' => 'ṛ', + 'Ṝ' => 'ṝ', + 'Ṟ' => 'ṟ', + 'Ṡ' => 'ṡ', + 'Ṣ' => 'ṣ', + 'Ṥ' => 'ṥ', + 'Ṧ' => 'ṧ', + 'Ṩ' => 'ṩ', + 'Ṫ' => 'ṫ', + 'Ṭ' => 'ṭ', + 'Ṯ' => 'ṯ', + 'Ṱ' => 'ṱ', + 'Ṳ' => 'ṳ', + 'Ṵ' => 'ṵ', + 'Ṷ' => 'ṷ', + 'Ṹ' => 'ṹ', + 'Ṻ' => 'ṻ', + 'Ṽ' => 'ṽ', + 'Ṿ' => 'ṿ', + 'Ẁ' => 'ẁ', + 'Ẃ' => 'ẃ', + 'Ẅ' => 'ẅ', + 'Ẇ' => 'ẇ', + 'Ẉ' => 'ẉ', + 'Ẋ' => 'ẋ', + 'Ẍ' => 'ẍ', + 'Ẏ' => 'ẏ', + 'Ẑ' => 'ẑ', + 'Ẓ' => 'ẓ', + 'Ẕ' => 'ẕ', + 'ẞ' => 'ß', + 'Ạ' => 'ạ', + 'Ả' => 'ả', + 'Ấ' => 'ấ', + 'Ầ' => 'ầ', + 'Ẩ' => 'ẩ', + 'Ẫ' => 'ẫ', + 'Ậ' => 'ậ', + 'Ắ' => 'ắ', + 'Ằ' => 'ằ', + 'Ẳ' => 'ẳ', + 'Ẵ' => 'ẵ', + 'Ặ' => 'ặ', + 'Ẹ' => 'ẹ', + 'Ẻ' => 'ẻ', + 'Ẽ' => 'ẽ', + 'Ế' => 'ế', + 'Ề' => 'ề', + 'Ể' => 'ể', + 'Ễ' => 'ễ', + 'Ệ' => 'ệ', + 'Ỉ' => 'ỉ', + 'Ị' => 'ị', + 'Ọ' => 'ọ', + 'Ỏ' => 'ỏ', + 'Ố' => 'ố', + 'Ồ' => 'ồ', + 'Ổ' => 'ổ', + 'Ỗ' => 'ỗ', + 'Ộ' => 'ộ', + 'Ớ' => 'ớ', + 'Ờ' => 'ờ', + 'Ở' => 'ở', + 'Ỡ' => 'ỡ', + 'Ợ' => 'ợ', + 'Ụ' => 'ụ', + 'Ủ' => 'ủ', + 'Ứ' => 'ứ', + 'Ừ' => 'ừ', + 'Ử' => 'ử', + 'Ữ' => 'ữ', + 'Ự' => 'ự', + 'Ỳ' => 'ỳ', + 'Ỵ' => 'ỵ', + 'Ỷ' => 'ỷ', + 'Ỹ' => 'ỹ', + 'Ỻ' => 'ỻ', + 'Ỽ' => 'ỽ', + 'Ỿ' => 'ỿ', + 'Ἀ' => 'ἀ', + 'Ἁ' => 'ἁ', + 'Ἂ' => 'ἂ', + 'Ἃ' => 'ἃ', + 'Ἄ' => 'ἄ', + 'Ἅ' => 'ἅ', + 'Ἆ' => 'ἆ', + 'Ἇ' => 'ἇ', + 'Ἐ' => 'ἐ', + 'Ἑ' => 'ἑ', + 'Ἒ' => 'ἒ', + 'Ἓ' => 'ἓ', + 'Ἔ' => 'ἔ', + 'Ἕ' => 'ἕ', + 'Ἠ' => 'ἠ', + 'Ἡ' => 'ἡ', + 'Ἢ' => 'ἢ', + 'Ἣ' => 'ἣ', + 'Ἤ' => 'ἤ', + 'Ἥ' => 'ἥ', + 'Ἦ' => 'ἦ', + 'Ἧ' => 'ἧ', + 'Ἰ' => 'ἰ', + 'Ἱ' => 'ἱ', + 'Ἲ' => 'ἲ', + 'Ἳ' => 'ἳ', + 'Ἴ' => 'ἴ', + 'Ἵ' => 'ἵ', + 'Ἶ' => 'ἶ', + 'Ἷ' => 'ἷ', + 'Ὀ' => 'ὀ', + 'Ὁ' => 'ὁ', + 'Ὂ' => 'ὂ', + 'Ὃ' => 'ὃ', + 'Ὄ' => 'ὄ', + 'Ὅ' => 'ὅ', + 'Ὑ' => 'ὑ', + 'Ὓ' => 'ὓ', + 'Ὕ' => 'ὕ', + 'Ὗ' => 'ὗ', + 'Ὠ' => 'ὠ', + 'Ὡ' => 'ὡ', + 'Ὢ' => 'ὢ', + 'Ὣ' => 'ὣ', + 'Ὤ' => 'ὤ', + 'Ὥ' => 'ὥ', + 'Ὦ' => 'ὦ', + 'Ὧ' => 'ὧ', + 'ᾈ' => 'ᾀ', + 'ᾉ' => 'ᾁ', + 'ᾊ' => 'ᾂ', + 'ᾋ' => 'ᾃ', + 'ᾌ' => 'ᾄ', + 'ᾍ' => 'ᾅ', + 'ᾎ' => 'ᾆ', + 'ᾏ' => 'ᾇ', + 'ᾘ' => 'ᾐ', + 'ᾙ' => 'ᾑ', + 'ᾚ' => 'ᾒ', + 'ᾛ' => 'ᾓ', + 'ᾜ' => 'ᾔ', + 'ᾝ' => 'ᾕ', + 'ᾞ' => 'ᾖ', + 'ᾟ' => 'ᾗ', + 'ᾨ' => 'ᾠ', + 'ᾩ' => 'ᾡ', + 'ᾪ' => 'ᾢ', + 'ᾫ' => 'ᾣ', + 'ᾬ' => 'ᾤ', + 'ᾭ' => 'ᾥ', + 'ᾮ' => 'ᾦ', + 'ᾯ' => 'ᾧ', + 'Ᾰ' => 'ᾰ', + 'Ᾱ' => 'ᾱ', + 'Ὰ' => 'ὰ', + 'Ά' => 'ά', + 'ᾼ' => 'ᾳ', + 'Ὲ' => 'ὲ', + 'Έ' => 'έ', + 'Ὴ' => 'ὴ', + 'Ή' => 'ή', + 'ῌ' => 'ῃ', + 'Ῐ' => 'ῐ', + 'Ῑ' => 'ῑ', + 'Ὶ' => 'ὶ', + 'Ί' => 'ί', + 'Ῠ' => 'ῠ', + 'Ῡ' => 'ῡ', + 'Ὺ' => 'ὺ', + 'Ύ' => 'ύ', + 'Ῥ' => 'ῥ', + 'Ὸ' => 'ὸ', + 'Ό' => 'ό', + 'Ὼ' => 'ὼ', + 'Ώ' => 'ώ', + 'ῼ' => 'ῳ', + 'Ω' => 'ω', + 'K' => 'k', + 'Å' => 'å', + 'Ⅎ' => 'ⅎ', + 'Ⅰ' => 'ⅰ', + 'Ⅱ' => 'ⅱ', + 'Ⅲ' => 'ⅲ', + 'Ⅳ' => 'ⅳ', + 'Ⅴ' => 'ⅴ', + 'Ⅵ' => 'ⅵ', + 'Ⅶ' => 'ⅶ', + 'Ⅷ' => 'ⅷ', + 'Ⅸ' => 'ⅸ', + 'Ⅹ' => 'ⅹ', + 'Ⅺ' => 'ⅺ', + 'Ⅻ' => 'ⅻ', + 'Ⅼ' => 'ⅼ', + 'Ⅽ' => 'ⅽ', + 'Ⅾ' => 'ⅾ', + 'Ⅿ' => 'ⅿ', + 'Ↄ' => 'ↄ', + 'Ⓐ' => 'ⓐ', + 'Ⓑ' => 'ⓑ', + 'Ⓒ' => 'ⓒ', + 'Ⓓ' => 'ⓓ', + 'Ⓔ' => 'ⓔ', + 'Ⓕ' => 'ⓕ', + 'Ⓖ' => 'ⓖ', + 'Ⓗ' => 'ⓗ', + 'Ⓘ' => 'ⓘ', + 'Ⓙ' => 'ⓙ', + 'Ⓚ' => 'ⓚ', + 'Ⓛ' => 'ⓛ', + 'Ⓜ' => 'ⓜ', + 'Ⓝ' => 'ⓝ', + 'Ⓞ' => 'ⓞ', + 'Ⓟ' => 'ⓟ', + 'Ⓠ' => 'ⓠ', + 'Ⓡ' => 'ⓡ', + 'Ⓢ' => 'ⓢ', + 'Ⓣ' => 'ⓣ', + 'Ⓤ' => 'ⓤ', + 'Ⓥ' => 'ⓥ', + 'Ⓦ' => 'ⓦ', + 'Ⓧ' => 'ⓧ', + 'Ⓨ' => 'ⓨ', + 'Ⓩ' => 'ⓩ', + 'Ⰰ' => 'ⰰ', + 'Ⰱ' => 'ⰱ', + 'Ⰲ' => 'ⰲ', + 'Ⰳ' => 'ⰳ', + 'Ⰴ' => 'ⰴ', + 'Ⰵ' => 'ⰵ', + 'Ⰶ' => 'ⰶ', + 'Ⰷ' => 'ⰷ', + 'Ⰸ' => 'ⰸ', + 'Ⰹ' => 'ⰹ', + 'Ⰺ' => 'ⰺ', + 'Ⰻ' => 'ⰻ', + 'Ⰼ' => 'ⰼ', + 'Ⰽ' => 'ⰽ', + 'Ⰾ' => 'ⰾ', + 'Ⰿ' => 'ⰿ', + 'Ⱀ' => 'ⱀ', + 'Ⱁ' => 'ⱁ', + 'Ⱂ' => 'ⱂ', + 'Ⱃ' => 'ⱃ', + 'Ⱄ' => 'ⱄ', + 'Ⱅ' => 'ⱅ', + 'Ⱆ' => 'ⱆ', + 'Ⱇ' => 'ⱇ', + 'Ⱈ' => 'ⱈ', + 'Ⱉ' => 'ⱉ', + 'Ⱊ' => 'ⱊ', + 'Ⱋ' => 'ⱋ', + 'Ⱌ' => 'ⱌ', + 'Ⱍ' => 'ⱍ', + 'Ⱎ' => 'ⱎ', + 'Ⱏ' => 'ⱏ', + 'Ⱐ' => 'ⱐ', + 'Ⱑ' => 'ⱑ', + 'Ⱒ' => 'ⱒ', + 'Ⱓ' => 'ⱓ', + 'Ⱔ' => 'ⱔ', + 'Ⱕ' => 'ⱕ', + 'Ⱖ' => 'ⱖ', + 'Ⱗ' => 'ⱗ', + 'Ⱘ' => 'ⱘ', + 'Ⱙ' => 'ⱙ', + 'Ⱚ' => 'ⱚ', + 'Ⱛ' => 'ⱛ', + 'Ⱜ' => 'ⱜ', + 'Ⱝ' => 'ⱝ', + 'Ⱞ' => 'ⱞ', + 'Ⱡ' => 'ⱡ', + 'Ɫ' => 'ɫ', + 'Ᵽ' => 'ᵽ', + 'Ɽ' => 'ɽ', + 'Ⱨ' => 'ⱨ', + 'Ⱪ' => 'ⱪ', + 'Ⱬ' => 'ⱬ', + 'Ɑ' => 'ɑ', + 'Ɱ' => 'ɱ', + 'Ɐ' => 'ɐ', + 'Ɒ' => 'ɒ', + 'Ⱳ' => 'ⱳ', + 'Ⱶ' => 'ⱶ', + 'Ȿ' => 'ȿ', + 'Ɀ' => 'ɀ', + 'Ⲁ' => 'ⲁ', + 'Ⲃ' => 'ⲃ', + 'Ⲅ' => 'ⲅ', + 'Ⲇ' => 'ⲇ', + 'Ⲉ' => 'ⲉ', + 'Ⲋ' => 'ⲋ', + 'Ⲍ' => 'ⲍ', + 'Ⲏ' => 'ⲏ', + 'Ⲑ' => 'ⲑ', + 'Ⲓ' => 'ⲓ', + 'Ⲕ' => 'ⲕ', + 'Ⲗ' => 'ⲗ', + 'Ⲙ' => 'ⲙ', + 'Ⲛ' => 'ⲛ', + 'Ⲝ' => 'ⲝ', + 'Ⲟ' => 'ⲟ', + 'Ⲡ' => 'ⲡ', + 'Ⲣ' => 'ⲣ', + 'Ⲥ' => 'ⲥ', + 'Ⲧ' => 'ⲧ', + 'Ⲩ' => 'ⲩ', + 'Ⲫ' => 'ⲫ', + 'Ⲭ' => 'ⲭ', + 'Ⲯ' => 'ⲯ', + 'Ⲱ' => 'ⲱ', + 'Ⲳ' => 'ⲳ', + 'Ⲵ' => 'ⲵ', + 'Ⲷ' => 'ⲷ', + 'Ⲹ' => 'ⲹ', + 'Ⲻ' => 'ⲻ', + 'Ⲽ' => 'ⲽ', + 'Ⲿ' => 'ⲿ', + 'Ⳁ' => 'ⳁ', + 'Ⳃ' => 'ⳃ', + 'Ⳅ' => 'ⳅ', + 'Ⳇ' => 'ⳇ', + 'Ⳉ' => 'ⳉ', + 'Ⳋ' => 'ⳋ', + 'Ⳍ' => 'ⳍ', + 'Ⳏ' => 'ⳏ', + 'Ⳑ' => 'ⳑ', + 'Ⳓ' => 'ⳓ', + 'Ⳕ' => 'ⳕ', + 'Ⳗ' => 'ⳗ', + 'Ⳙ' => 'ⳙ', + 'Ⳛ' => 'ⳛ', + 'Ⳝ' => 'ⳝ', + 'Ⳟ' => 'ⳟ', + 'Ⳡ' => 'ⳡ', + 'Ⳣ' => 'ⳣ', + 'Ⳬ' => 'ⳬ', + 'Ⳮ' => 'ⳮ', + 'Ⳳ' => 'ⳳ', + 'Ꙁ' => 'ꙁ', + 'Ꙃ' => 'ꙃ', + 'Ꙅ' => 'ꙅ', + 'Ꙇ' => 'ꙇ', + 'Ꙉ' => 'ꙉ', + 'Ꙋ' => 'ꙋ', + 'Ꙍ' => 'ꙍ', + 'Ꙏ' => 'ꙏ', + 'Ꙑ' => 'ꙑ', + 'Ꙓ' => 'ꙓ', + 'Ꙕ' => 'ꙕ', + 'Ꙗ' => 'ꙗ', + 'Ꙙ' => 'ꙙ', + 'Ꙛ' => 'ꙛ', + 'Ꙝ' => 'ꙝ', + 'Ꙟ' => 'ꙟ', + 'Ꙡ' => 'ꙡ', + 'Ꙣ' => 'ꙣ', + 'Ꙥ' => 'ꙥ', + 'Ꙧ' => 'ꙧ', + 'Ꙩ' => 'ꙩ', + 'Ꙫ' => 'ꙫ', + 'Ꙭ' => 'ꙭ', + 'Ꚁ' => 'ꚁ', + 'Ꚃ' => 'ꚃ', + 'Ꚅ' => 'ꚅ', + 'Ꚇ' => 'ꚇ', + 'Ꚉ' => 'ꚉ', + 'Ꚋ' => 'ꚋ', + 'Ꚍ' => 'ꚍ', + 'Ꚏ' => 'ꚏ', + 'Ꚑ' => 'ꚑ', + 'Ꚓ' => 'ꚓ', + 'Ꚕ' => 'ꚕ', + 'Ꚗ' => 'ꚗ', + 'Ꚙ' => 'ꚙ', + 'Ꚛ' => 'ꚛ', + 'Ꜣ' => 'ꜣ', + 'Ꜥ' => 'ꜥ', + 'Ꜧ' => 'ꜧ', + 'Ꜩ' => 'ꜩ', + 'Ꜫ' => 'ꜫ', + 'Ꜭ' => 'ꜭ', + 'Ꜯ' => 'ꜯ', + 'Ꜳ' => 'ꜳ', + 'Ꜵ' => 'ꜵ', + 'Ꜷ' => 'ꜷ', + 'Ꜹ' => 'ꜹ', + 'Ꜻ' => 'ꜻ', + 'Ꜽ' => 'ꜽ', + 'Ꜿ' => 'ꜿ', + 'Ꝁ' => 'ꝁ', + 'Ꝃ' => 'ꝃ', + 'Ꝅ' => 'ꝅ', + 'Ꝇ' => 'ꝇ', + 'Ꝉ' => 'ꝉ', + 'Ꝋ' => 'ꝋ', + 'Ꝍ' => 'ꝍ', + 'Ꝏ' => 'ꝏ', + 'Ꝑ' => 'ꝑ', + 'Ꝓ' => 'ꝓ', + 'Ꝕ' => 'ꝕ', + 'Ꝗ' => 'ꝗ', + 'Ꝙ' => 'ꝙ', + 'Ꝛ' => 'ꝛ', + 'Ꝝ' => 'ꝝ', + 'Ꝟ' => 'ꝟ', + 'Ꝡ' => 'ꝡ', + 'Ꝣ' => 'ꝣ', + 'Ꝥ' => 'ꝥ', + 'Ꝧ' => 'ꝧ', + 'Ꝩ' => 'ꝩ', + 'Ꝫ' => 'ꝫ', + 'Ꝭ' => 'ꝭ', + 'Ꝯ' => 'ꝯ', + 'Ꝺ' => 'ꝺ', + 'Ꝼ' => 'ꝼ', + 'Ᵹ' => 'ᵹ', + 'Ꝿ' => 'ꝿ', + 'Ꞁ' => 'ꞁ', + 'Ꞃ' => 'ꞃ', + 'Ꞅ' => 'ꞅ', + 'Ꞇ' => 'ꞇ', + 'Ꞌ' => 'ꞌ', + 'Ɥ' => 'ɥ', + 'Ꞑ' => 'ꞑ', + 'Ꞓ' => 'ꞓ', + 'Ꞗ' => 'ꞗ', + 'Ꞙ' => 'ꞙ', + 'Ꞛ' => 'ꞛ', + 'Ꞝ' => 'ꞝ', + 'Ꞟ' => 'ꞟ', + 'Ꞡ' => 'ꞡ', + 'Ꞣ' => 'ꞣ', + 'Ꞥ' => 'ꞥ', + 'Ꞧ' => 'ꞧ', + 'Ꞩ' => 'ꞩ', + 'Ɦ' => 'ɦ', + 'Ɜ' => 'ɜ', + 'Ɡ' => 'ɡ', + 'Ɬ' => 'ɬ', + 'Ʞ' => 'ʞ', + 'Ʇ' => 'ʇ', + 'A' => 'a', + 'B' => 'b', + 'C' => 'c', + 'D' => 'd', + 'E' => 'e', + 'F' => 'f', + 'G' => 'g', + 'H' => 'h', + 'I' => 'i', + 'J' => 'j', + 'K' => 'k', + 'L' => 'l', + 'M' => 'm', + 'N' => 'n', + 'O' => 'o', + 'P' => 'p', + 'Q' => 'q', + 'R' => 'r', + 'S' => 's', + 'T' => 't', + 'U' => 'u', + 'V' => 'v', + 'W' => 'w', + 'X' => 'x', + 'Y' => 'y', + 'Z' => 'z', + '𐐀' => '𐐨', + '𐐁' => '𐐩', + '𐐂' => '𐐪', + '𐐃' => '𐐫', + '𐐄' => '𐐬', + '𐐅' => '𐐭', + '𐐆' => '𐐮', + '𐐇' => '𐐯', + '𐐈' => '𐐰', + '𐐉' => '𐐱', + '𐐊' => '𐐲', + '𐐋' => '𐐳', + '𐐌' => '𐐴', + '𐐍' => '𐐵', + '𐐎' => '𐐶', + '𐐏' => '𐐷', + '𐐐' => '𐐸', + '𐐑' => '𐐹', + '𐐒' => '𐐺', + '𐐓' => '𐐻', + '𐐔' => '𐐼', + '𐐕' => '𐐽', + '𐐖' => '𐐾', + '𐐗' => '𐐿', + '𐐘' => '𐑀', + '𐐙' => '𐑁', + '𐐚' => '𐑂', + '𐐛' => '𐑃', + '𐐜' => '𐑄', + '𐐝' => '𐑅', + '𐐞' => '𐑆', + '𐐟' => '𐑇', + '𐐠' => '𐑈', + '𐐡' => '𐑉', + '𐐢' => '𐑊', + '𐐣' => '𐑋', + '𐐤' => '𐑌', + '𐐥' => '𐑍', + '𐐦' => '𐑎', + '𐐧' => '𐑏', + '𑢠' => '𑣀', + '𑢡' => '𑣁', + '𑢢' => '𑣂', + '𑢣' => '𑣃', + '𑢤' => '𑣄', + '𑢥' => '𑣅', + '𑢦' => '𑣆', + '𑢧' => '𑣇', + '𑢨' => '𑣈', + '𑢩' => '𑣉', + '𑢪' => '𑣊', + '𑢫' => '𑣋', + '𑢬' => '𑣌', + '𑢭' => '𑣍', + '𑢮' => '𑣎', + '𑢯' => '𑣏', + '𑢰' => '𑣐', + '𑢱' => '𑣑', + '𑢲' => '𑣒', + '𑢳' => '𑣓', + '𑢴' => '𑣔', + '𑢵' => '𑣕', + '𑢶' => '𑣖', + '𑢷' => '𑣗', + '𑢸' => '𑣘', + '𑢹' => '𑣙', + '𑢺' => '𑣚', + '𑢻' => '𑣛', + '𑢼' => '𑣜', + '𑢽' => '𑣝', + '𑢾' => '𑣞', + '𑢿' => '𑣟', +); diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php new file mode 100644 index 0000000..2a8f6e7 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php @@ -0,0 +1,5 @@ + 'A', + 'b' => 'B', + 'c' => 'C', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + 'k' => 'K', + 'l' => 'L', + 'm' => 'M', + 'n' => 'N', + 'o' => 'O', + 'p' => 'P', + 'q' => 'Q', + 'r' => 'R', + 's' => 'S', + 't' => 'T', + 'u' => 'U', + 'v' => 'V', + 'w' => 'W', + 'x' => 'X', + 'y' => 'Y', + 'z' => 'Z', + 'µ' => 'Μ', + 'à' => 'À', + 'á' => 'Á', + 'â' => 'Â', + 'ã' => 'Ã', + 'ä' => 'Ä', + 'å' => 'Å', + 'æ' => 'Æ', + 'ç' => 'Ç', + 'è' => 'È', + 'é' => 'É', + 'ê' => 'Ê', + 'ë' => 'Ë', + 'ì' => 'Ì', + 'í' => 'Í', + 'î' => 'Î', + 'ï' => 'Ï', + 'ð' => 'Ð', + 'ñ' => 'Ñ', + 'ò' => 'Ò', + 'ó' => 'Ó', + 'ô' => 'Ô', + 'õ' => 'Õ', + 'ö' => 'Ö', + 'ø' => 'Ø', + 'ù' => 'Ù', + 'ú' => 'Ú', + 'û' => 'Û', + 'ü' => 'Ü', + 'ý' => 'Ý', + 'þ' => 'Þ', + 'ÿ' => 'Ÿ', + 'ā' => 'Ā', + 'ă' => 'Ă', + 'ą' => 'Ą', + 'ć' => 'Ć', + 'ĉ' => 'Ĉ', + 'ċ' => 'Ċ', + 'č' => 'Č', + 'ď' => 'Ď', + 'đ' => 'Đ', + 'ē' => 'Ē', + 'ĕ' => 'Ĕ', + 'ė' => 'Ė', + 'ę' => 'Ę', + 'ě' => 'Ě', + 'ĝ' => 'Ĝ', + 'ğ' => 'Ğ', + 'ġ' => 'Ġ', + 'ģ' => 'Ģ', + 'ĥ' => 'Ĥ', + 'ħ' => 'Ħ', + 'ĩ' => 'Ĩ', + 'ī' => 'Ī', + 'ĭ' => 'Ĭ', + 'į' => 'Į', + 'ı' => 'I', + 'ij' => 'IJ', + 'ĵ' => 'Ĵ', + 'ķ' => 'Ķ', + 'ĺ' => 'Ĺ', + 'ļ' => 'Ļ', + 'ľ' => 'Ľ', + 'ŀ' => 'Ŀ', + 'ł' => 'Ł', + 'ń' => 'Ń', + 'ņ' => 'Ņ', + 'ň' => 'Ň', + 'ŋ' => 'Ŋ', + 'ō' => 'Ō', + 'ŏ' => 'Ŏ', + 'ő' => 'Ő', + 'œ' => 'Œ', + 'ŕ' => 'Ŕ', + 'ŗ' => 'Ŗ', + 'ř' => 'Ř', + 'ś' => 'Ś', + 'ŝ' => 'Ŝ', + 'ş' => 'Ş', + 'š' => 'Š', + 'ţ' => 'Ţ', + 'ť' => 'Ť', + 'ŧ' => 'Ŧ', + 'ũ' => 'Ũ', + 'ū' => 'Ū', + 'ŭ' => 'Ŭ', + 'ů' => 'Ů', + 'ű' => 'Ű', + 'ų' => 'Ų', + 'ŵ' => 'Ŵ', + 'ŷ' => 'Ŷ', + 'ź' => 'Ź', + 'ż' => 'Ż', + 'ž' => 'Ž', + 'ſ' => 'S', + 'ƀ' => 'Ƀ', + 'ƃ' => 'Ƃ', + 'ƅ' => 'Ƅ', + 'ƈ' => 'Ƈ', + 'ƌ' => 'Ƌ', + 'ƒ' => 'Ƒ', + 'ƕ' => 'Ƕ', + 'ƙ' => 'Ƙ', + 'ƚ' => 'Ƚ', + 'ƞ' => 'Ƞ', + 'ơ' => 'Ơ', + 'ƣ' => 'Ƣ', + 'ƥ' => 'Ƥ', + 'ƨ' => 'Ƨ', + 'ƭ' => 'Ƭ', + 'ư' => 'Ư', + 'ƴ' => 'Ƴ', + 'ƶ' => 'Ƶ', + 'ƹ' => 'Ƹ', + 'ƽ' => 'Ƽ', + 'ƿ' => 'Ƿ', + 'Dž' => 'DŽ', + 'dž' => 'DŽ', + 'Lj' => 'LJ', + 'lj' => 'LJ', + 'Nj' => 'NJ', + 'nj' => 'NJ', + 'ǎ' => 'Ǎ', + 'ǐ' => 'Ǐ', + 'ǒ' => 'Ǒ', + 'ǔ' => 'Ǔ', + 'ǖ' => 'Ǖ', + 'ǘ' => 'Ǘ', + 'ǚ' => 'Ǚ', + 'ǜ' => 'Ǜ', + 'ǝ' => 'Ǝ', + 'ǟ' => 'Ǟ', + 'ǡ' => 'Ǡ', + 'ǣ' => 'Ǣ', + 'ǥ' => 'Ǥ', + 'ǧ' => 'Ǧ', + 'ǩ' => 'Ǩ', + 'ǫ' => 'Ǫ', + 'ǭ' => 'Ǭ', + 'ǯ' => 'Ǯ', + 'Dz' => 'DZ', + 'dz' => 'DZ', + 'ǵ' => 'Ǵ', + 'ǹ' => 'Ǹ', + 'ǻ' => 'Ǻ', + 'ǽ' => 'Ǽ', + 'ǿ' => 'Ǿ', + 'ȁ' => 'Ȁ', + 'ȃ' => 'Ȃ', + 'ȅ' => 'Ȅ', + 'ȇ' => 'Ȇ', + 'ȉ' => 'Ȉ', + 'ȋ' => 'Ȋ', + 'ȍ' => 'Ȍ', + 'ȏ' => 'Ȏ', + 'ȑ' => 'Ȑ', + 'ȓ' => 'Ȓ', + 'ȕ' => 'Ȕ', + 'ȗ' => 'Ȗ', + 'ș' => 'Ș', + 'ț' => 'Ț', + 'ȝ' => 'Ȝ', + 'ȟ' => 'Ȟ', + 'ȣ' => 'Ȣ', + 'ȥ' => 'Ȥ', + 'ȧ' => 'Ȧ', + 'ȩ' => 'Ȩ', + 'ȫ' => 'Ȫ', + 'ȭ' => 'Ȭ', + 'ȯ' => 'Ȯ', + 'ȱ' => 'Ȱ', + 'ȳ' => 'Ȳ', + 'ȼ' => 'Ȼ', + 'ȿ' => 'Ȿ', + 'ɀ' => 'Ɀ', + 'ɂ' => 'Ɂ', + 'ɇ' => 'Ɇ', + 'ɉ' => 'Ɉ', + 'ɋ' => 'Ɋ', + 'ɍ' => 'Ɍ', + 'ɏ' => 'Ɏ', + 'ɐ' => 'Ɐ', + 'ɑ' => 'Ɑ', + 'ɒ' => 'Ɒ', + 'ɓ' => 'Ɓ', + 'ɔ' => 'Ɔ', + 'ɖ' => 'Ɖ', + 'ɗ' => 'Ɗ', + 'ə' => 'Ə', + 'ɛ' => 'Ɛ', + 'ɜ' => 'Ɜ', + 'ɠ' => 'Ɠ', + 'ɡ' => 'Ɡ', + 'ɣ' => 'Ɣ', + 'ɥ' => 'Ɥ', + 'ɦ' => 'Ɦ', + 'ɨ' => 'Ɨ', + 'ɩ' => 'Ɩ', + 'ɫ' => 'Ɫ', + 'ɬ' => 'Ɬ', + 'ɯ' => 'Ɯ', + 'ɱ' => 'Ɱ', + 'ɲ' => 'Ɲ', + 'ɵ' => 'Ɵ', + 'ɽ' => 'Ɽ', + 'ʀ' => 'Ʀ', + 'ʃ' => 'Ʃ', + 'ʇ' => 'Ʇ', + 'ʈ' => 'Ʈ', + 'ʉ' => 'Ʉ', + 'ʊ' => 'Ʊ', + 'ʋ' => 'Ʋ', + 'ʌ' => 'Ʌ', + 'ʒ' => 'Ʒ', + 'ʞ' => 'Ʞ', + 'ͅ' => 'Ι', + 'ͱ' => 'Ͱ', + 'ͳ' => 'Ͳ', + 'ͷ' => 'Ͷ', + 'ͻ' => 'Ͻ', + 'ͼ' => 'Ͼ', + 'ͽ' => 'Ͽ', + 'ά' => 'Ά', + 'έ' => 'Έ', + 'ή' => 'Ή', + 'ί' => 'Ί', + 'α' => 'Α', + 'β' => 'Β', + 'γ' => 'Γ', + 'δ' => 'Δ', + 'ε' => 'Ε', + 'ζ' => 'Ζ', + 'η' => 'Η', + 'θ' => 'Θ', + 'ι' => 'Ι', + 'κ' => 'Κ', + 'λ' => 'Λ', + 'μ' => 'Μ', + 'ν' => 'Ν', + 'ξ' => 'Ξ', + 'ο' => 'Ο', + 'π' => 'Π', + 'ρ' => 'Ρ', + 'ς' => 'Σ', + 'σ' => 'Σ', + 'τ' => 'Τ', + 'υ' => 'Υ', + 'φ' => 'Φ', + 'χ' => 'Χ', + 'ψ' => 'Ψ', + 'ω' => 'Ω', + 'ϊ' => 'Ϊ', + 'ϋ' => 'Ϋ', + 'ό' => 'Ό', + 'ύ' => 'Ύ', + 'ώ' => 'Ώ', + 'ϐ' => 'Β', + 'ϑ' => 'Θ', + 'ϕ' => 'Φ', + 'ϖ' => 'Π', + 'ϗ' => 'Ϗ', + 'ϙ' => 'Ϙ', + 'ϛ' => 'Ϛ', + 'ϝ' => 'Ϝ', + 'ϟ' => 'Ϟ', + 'ϡ' => 'Ϡ', + 'ϣ' => 'Ϣ', + 'ϥ' => 'Ϥ', + 'ϧ' => 'Ϧ', + 'ϩ' => 'Ϩ', + 'ϫ' => 'Ϫ', + 'ϭ' => 'Ϭ', + 'ϯ' => 'Ϯ', + 'ϰ' => 'Κ', + 'ϱ' => 'Ρ', + 'ϲ' => 'Ϲ', + 'ϳ' => 'Ϳ', + 'ϵ' => 'Ε', + 'ϸ' => 'Ϸ', + 'ϻ' => 'Ϻ', + 'а' => 'А', + 'б' => 'Б', + 'в' => 'В', + 'г' => 'Г', + 'д' => 'Д', + 'е' => 'Е', + 'ж' => 'Ж', + 'з' => 'З', + 'и' => 'И', + 'й' => 'Й', + 'к' => 'К', + 'л' => 'Л', + 'м' => 'М', + 'н' => 'Н', + 'о' => 'О', + 'п' => 'П', + 'р' => 'Р', + 'с' => 'С', + 'т' => 'Т', + 'у' => 'У', + 'ф' => 'Ф', + 'х' => 'Х', + 'ц' => 'Ц', + 'ч' => 'Ч', + 'ш' => 'Ш', + 'щ' => 'Щ', + 'ъ' => 'Ъ', + 'ы' => 'Ы', + 'ь' => 'Ь', + 'э' => 'Э', + 'ю' => 'Ю', + 'я' => 'Я', + 'ѐ' => 'Ѐ', + 'ё' => 'Ё', + 'ђ' => 'Ђ', + 'ѓ' => 'Ѓ', + 'є' => 'Є', + 'ѕ' => 'Ѕ', + 'і' => 'І', + 'ї' => 'Ї', + 'ј' => 'Ј', + 'љ' => 'Љ', + 'њ' => 'Њ', + 'ћ' => 'Ћ', + 'ќ' => 'Ќ', + 'ѝ' => 'Ѝ', + 'ў' => 'Ў', + 'џ' => 'Џ', + 'ѡ' => 'Ѡ', + 'ѣ' => 'Ѣ', + 'ѥ' => 'Ѥ', + 'ѧ' => 'Ѧ', + 'ѩ' => 'Ѩ', + 'ѫ' => 'Ѫ', + 'ѭ' => 'Ѭ', + 'ѯ' => 'Ѯ', + 'ѱ' => 'Ѱ', + 'ѳ' => 'Ѳ', + 'ѵ' => 'Ѵ', + 'ѷ' => 'Ѷ', + 'ѹ' => 'Ѹ', + 'ѻ' => 'Ѻ', + 'ѽ' => 'Ѽ', + 'ѿ' => 'Ѿ', + 'ҁ' => 'Ҁ', + 'ҋ' => 'Ҋ', + 'ҍ' => 'Ҍ', + 'ҏ' => 'Ҏ', + 'ґ' => 'Ґ', + 'ғ' => 'Ғ', + 'ҕ' => 'Ҕ', + 'җ' => 'Җ', + 'ҙ' => 'Ҙ', + 'қ' => 'Қ', + 'ҝ' => 'Ҝ', + 'ҟ' => 'Ҟ', + 'ҡ' => 'Ҡ', + 'ң' => 'Ң', + 'ҥ' => 'Ҥ', + 'ҧ' => 'Ҧ', + 'ҩ' => 'Ҩ', + 'ҫ' => 'Ҫ', + 'ҭ' => 'Ҭ', + 'ү' => 'Ү', + 'ұ' => 'Ұ', + 'ҳ' => 'Ҳ', + 'ҵ' => 'Ҵ', + 'ҷ' => 'Ҷ', + 'ҹ' => 'Ҹ', + 'һ' => 'Һ', + 'ҽ' => 'Ҽ', + 'ҿ' => 'Ҿ', + 'ӂ' => 'Ӂ', + 'ӄ' => 'Ӄ', + 'ӆ' => 'Ӆ', + 'ӈ' => 'Ӈ', + 'ӊ' => 'Ӊ', + 'ӌ' => 'Ӌ', + 'ӎ' => 'Ӎ', + 'ӏ' => 'Ӏ', + 'ӑ' => 'Ӑ', + 'ӓ' => 'Ӓ', + 'ӕ' => 'Ӕ', + 'ӗ' => 'Ӗ', + 'ә' => 'Ә', + 'ӛ' => 'Ӛ', + 'ӝ' => 'Ӝ', + 'ӟ' => 'Ӟ', + 'ӡ' => 'Ӡ', + 'ӣ' => 'Ӣ', + 'ӥ' => 'Ӥ', + 'ӧ' => 'Ӧ', + 'ө' => 'Ө', + 'ӫ' => 'Ӫ', + 'ӭ' => 'Ӭ', + 'ӯ' => 'Ӯ', + 'ӱ' => 'Ӱ', + 'ӳ' => 'Ӳ', + 'ӵ' => 'Ӵ', + 'ӷ' => 'Ӷ', + 'ӹ' => 'Ӹ', + 'ӻ' => 'Ӻ', + 'ӽ' => 'Ӽ', + 'ӿ' => 'Ӿ', + 'ԁ' => 'Ԁ', + 'ԃ' => 'Ԃ', + 'ԅ' => 'Ԅ', + 'ԇ' => 'Ԇ', + 'ԉ' => 'Ԉ', + 'ԋ' => 'Ԋ', + 'ԍ' => 'Ԍ', + 'ԏ' => 'Ԏ', + 'ԑ' => 'Ԑ', + 'ԓ' => 'Ԓ', + 'ԕ' => 'Ԕ', + 'ԗ' => 'Ԗ', + 'ԙ' => 'Ԙ', + 'ԛ' => 'Ԛ', + 'ԝ' => 'Ԝ', + 'ԟ' => 'Ԟ', + 'ԡ' => 'Ԡ', + 'ԣ' => 'Ԣ', + 'ԥ' => 'Ԥ', + 'ԧ' => 'Ԧ', + 'ԩ' => 'Ԩ', + 'ԫ' => 'Ԫ', + 'ԭ' => 'Ԭ', + 'ԯ' => 'Ԯ', + 'ա' => 'Ա', + 'բ' => 'Բ', + 'գ' => 'Գ', + 'դ' => 'Դ', + 'ե' => 'Ե', + 'զ' => 'Զ', + 'է' => 'Է', + 'ը' => 'Ը', + 'թ' => 'Թ', + 'ժ' => 'Ժ', + 'ի' => 'Ի', + 'լ' => 'Լ', + 'խ' => 'Խ', + 'ծ' => 'Ծ', + 'կ' => 'Կ', + 'հ' => 'Հ', + 'ձ' => 'Ձ', + 'ղ' => 'Ղ', + 'ճ' => 'Ճ', + 'մ' => 'Մ', + 'յ' => 'Յ', + 'ն' => 'Ն', + 'շ' => 'Շ', + 'ո' => 'Ո', + 'չ' => 'Չ', + 'պ' => 'Պ', + 'ջ' => 'Ջ', + 'ռ' => 'Ռ', + 'ս' => 'Ս', + 'վ' => 'Վ', + 'տ' => 'Տ', + 'ր' => 'Ր', + 'ց' => 'Ց', + 'ւ' => 'Ւ', + 'փ' => 'Փ', + 'ք' => 'Ք', + 'օ' => 'Օ', + 'ֆ' => 'Ֆ', + 'ᵹ' => 'Ᵹ', + 'ᵽ' => 'Ᵽ', + 'ḁ' => 'Ḁ', + 'ḃ' => 'Ḃ', + 'ḅ' => 'Ḅ', + 'ḇ' => 'Ḇ', + 'ḉ' => 'Ḉ', + 'ḋ' => 'Ḋ', + 'ḍ' => 'Ḍ', + 'ḏ' => 'Ḏ', + 'ḑ' => 'Ḑ', + 'ḓ' => 'Ḓ', + 'ḕ' => 'Ḕ', + 'ḗ' => 'Ḗ', + 'ḙ' => 'Ḙ', + 'ḛ' => 'Ḛ', + 'ḝ' => 'Ḝ', + 'ḟ' => 'Ḟ', + 'ḡ' => 'Ḡ', + 'ḣ' => 'Ḣ', + 'ḥ' => 'Ḥ', + 'ḧ' => 'Ḧ', + 'ḩ' => 'Ḩ', + 'ḫ' => 'Ḫ', + 'ḭ' => 'Ḭ', + 'ḯ' => 'Ḯ', + 'ḱ' => 'Ḱ', + 'ḳ' => 'Ḳ', + 'ḵ' => 'Ḵ', + 'ḷ' => 'Ḷ', + 'ḹ' => 'Ḹ', + 'ḻ' => 'Ḻ', + 'ḽ' => 'Ḽ', + 'ḿ' => 'Ḿ', + 'ṁ' => 'Ṁ', + 'ṃ' => 'Ṃ', + 'ṅ' => 'Ṅ', + 'ṇ' => 'Ṇ', + 'ṉ' => 'Ṉ', + 'ṋ' => 'Ṋ', + 'ṍ' => 'Ṍ', + 'ṏ' => 'Ṏ', + 'ṑ' => 'Ṑ', + 'ṓ' => 'Ṓ', + 'ṕ' => 'Ṕ', + 'ṗ' => 'Ṗ', + 'ṙ' => 'Ṙ', + 'ṛ' => 'Ṛ', + 'ṝ' => 'Ṝ', + 'ṟ' => 'Ṟ', + 'ṡ' => 'Ṡ', + 'ṣ' => 'Ṣ', + 'ṥ' => 'Ṥ', + 'ṧ' => 'Ṧ', + 'ṩ' => 'Ṩ', + 'ṫ' => 'Ṫ', + 'ṭ' => 'Ṭ', + 'ṯ' => 'Ṯ', + 'ṱ' => 'Ṱ', + 'ṳ' => 'Ṳ', + 'ṵ' => 'Ṵ', + 'ṷ' => 'Ṷ', + 'ṹ' => 'Ṹ', + 'ṻ' => 'Ṻ', + 'ṽ' => 'Ṽ', + 'ṿ' => 'Ṿ', + 'ẁ' => 'Ẁ', + 'ẃ' => 'Ẃ', + 'ẅ' => 'Ẅ', + 'ẇ' => 'Ẇ', + 'ẉ' => 'Ẉ', + 'ẋ' => 'Ẋ', + 'ẍ' => 'Ẍ', + 'ẏ' => 'Ẏ', + 'ẑ' => 'Ẑ', + 'ẓ' => 'Ẓ', + 'ẕ' => 'Ẕ', + 'ẛ' => 'Ṡ', + 'ạ' => 'Ạ', + 'ả' => 'Ả', + 'ấ' => 'Ấ', + 'ầ' => 'Ầ', + 'ẩ' => 'Ẩ', + 'ẫ' => 'Ẫ', + 'ậ' => 'Ậ', + 'ắ' => 'Ắ', + 'ằ' => 'Ằ', + 'ẳ' => 'Ẳ', + 'ẵ' => 'Ẵ', + 'ặ' => 'Ặ', + 'ẹ' => 'Ẹ', + 'ẻ' => 'Ẻ', + 'ẽ' => 'Ẽ', + 'ế' => 'Ế', + 'ề' => 'Ề', + 'ể' => 'Ể', + 'ễ' => 'Ễ', + 'ệ' => 'Ệ', + 'ỉ' => 'Ỉ', + 'ị' => 'Ị', + 'ọ' => 'Ọ', + 'ỏ' => 'Ỏ', + 'ố' => 'Ố', + 'ồ' => 'Ồ', + 'ổ' => 'Ổ', + 'ỗ' => 'Ỗ', + 'ộ' => 'Ộ', + 'ớ' => 'Ớ', + 'ờ' => 'Ờ', + 'ở' => 'Ở', + 'ỡ' => 'Ỡ', + 'ợ' => 'Ợ', + 'ụ' => 'Ụ', + 'ủ' => 'Ủ', + 'ứ' => 'Ứ', + 'ừ' => 'Ừ', + 'ử' => 'Ử', + 'ữ' => 'Ữ', + 'ự' => 'Ự', + 'ỳ' => 'Ỳ', + 'ỵ' => 'Ỵ', + 'ỷ' => 'Ỷ', + 'ỹ' => 'Ỹ', + 'ỻ' => 'Ỻ', + 'ỽ' => 'Ỽ', + 'ỿ' => 'Ỿ', + 'ἀ' => 'Ἀ', + 'ἁ' => 'Ἁ', + 'ἂ' => 'Ἂ', + 'ἃ' => 'Ἃ', + 'ἄ' => 'Ἄ', + 'ἅ' => 'Ἅ', + 'ἆ' => 'Ἆ', + 'ἇ' => 'Ἇ', + 'ἐ' => 'Ἐ', + 'ἑ' => 'Ἑ', + 'ἒ' => 'Ἒ', + 'ἓ' => 'Ἓ', + 'ἔ' => 'Ἔ', + 'ἕ' => 'Ἕ', + 'ἠ' => 'Ἠ', + 'ἡ' => 'Ἡ', + 'ἢ' => 'Ἢ', + 'ἣ' => 'Ἣ', + 'ἤ' => 'Ἤ', + 'ἥ' => 'Ἥ', + 'ἦ' => 'Ἦ', + 'ἧ' => 'Ἧ', + 'ἰ' => 'Ἰ', + 'ἱ' => 'Ἱ', + 'ἲ' => 'Ἲ', + 'ἳ' => 'Ἳ', + 'ἴ' => 'Ἴ', + 'ἵ' => 'Ἵ', + 'ἶ' => 'Ἶ', + 'ἷ' => 'Ἷ', + 'ὀ' => 'Ὀ', + 'ὁ' => 'Ὁ', + 'ὂ' => 'Ὂ', + 'ὃ' => 'Ὃ', + 'ὄ' => 'Ὄ', + 'ὅ' => 'Ὅ', + 'ὑ' => 'Ὑ', + 'ὓ' => 'Ὓ', + 'ὕ' => 'Ὕ', + 'ὗ' => 'Ὗ', + 'ὠ' => 'Ὠ', + 'ὡ' => 'Ὡ', + 'ὢ' => 'Ὢ', + 'ὣ' => 'Ὣ', + 'ὤ' => 'Ὤ', + 'ὥ' => 'Ὥ', + 'ὦ' => 'Ὦ', + 'ὧ' => 'Ὧ', + 'ὰ' => 'Ὰ', + 'ά' => 'Ά', + 'ὲ' => 'Ὲ', + 'έ' => 'Έ', + 'ὴ' => 'Ὴ', + 'ή' => 'Ή', + 'ὶ' => 'Ὶ', + 'ί' => 'Ί', + 'ὸ' => 'Ὸ', + 'ό' => 'Ό', + 'ὺ' => 'Ὺ', + 'ύ' => 'Ύ', + 'ὼ' => 'Ὼ', + 'ώ' => 'Ώ', + 'ᾀ' => 'ᾈ', + 'ᾁ' => 'ᾉ', + 'ᾂ' => 'ᾊ', + 'ᾃ' => 'ᾋ', + 'ᾄ' => 'ᾌ', + 'ᾅ' => 'ᾍ', + 'ᾆ' => 'ᾎ', + 'ᾇ' => 'ᾏ', + 'ᾐ' => 'ᾘ', + 'ᾑ' => 'ᾙ', + 'ᾒ' => 'ᾚ', + 'ᾓ' => 'ᾛ', + 'ᾔ' => 'ᾜ', + 'ᾕ' => 'ᾝ', + 'ᾖ' => 'ᾞ', + 'ᾗ' => 'ᾟ', + 'ᾠ' => 'ᾨ', + 'ᾡ' => 'ᾩ', + 'ᾢ' => 'ᾪ', + 'ᾣ' => 'ᾫ', + 'ᾤ' => 'ᾬ', + 'ᾥ' => 'ᾭ', + 'ᾦ' => 'ᾮ', + 'ᾧ' => 'ᾯ', + 'ᾰ' => 'Ᾰ', + 'ᾱ' => 'Ᾱ', + 'ᾳ' => 'ᾼ', + 'ι' => 'Ι', + 'ῃ' => 'ῌ', + 'ῐ' => 'Ῐ', + 'ῑ' => 'Ῑ', + 'ῠ' => 'Ῠ', + 'ῡ' => 'Ῡ', + 'ῥ' => 'Ῥ', + 'ῳ' => 'ῼ', + 'ⅎ' => 'Ⅎ', + 'ⅰ' => 'Ⅰ', + 'ⅱ' => 'Ⅱ', + 'ⅲ' => 'Ⅲ', + 'ⅳ' => 'Ⅳ', + 'ⅴ' => 'Ⅴ', + 'ⅵ' => 'Ⅵ', + 'ⅶ' => 'Ⅶ', + 'ⅷ' => 'Ⅷ', + 'ⅸ' => 'Ⅸ', + 'ⅹ' => 'Ⅹ', + 'ⅺ' => 'Ⅺ', + 'ⅻ' => 'Ⅻ', + 'ⅼ' => 'Ⅼ', + 'ⅽ' => 'Ⅽ', + 'ⅾ' => 'Ⅾ', + 'ⅿ' => 'Ⅿ', + 'ↄ' => 'Ↄ', + 'ⓐ' => 'Ⓐ', + 'ⓑ' => 'Ⓑ', + 'ⓒ' => 'Ⓒ', + 'ⓓ' => 'Ⓓ', + 'ⓔ' => 'Ⓔ', + 'ⓕ' => 'Ⓕ', + 'ⓖ' => 'Ⓖ', + 'ⓗ' => 'Ⓗ', + 'ⓘ' => 'Ⓘ', + 'ⓙ' => 'Ⓙ', + 'ⓚ' => 'Ⓚ', + 'ⓛ' => 'Ⓛ', + 'ⓜ' => 'Ⓜ', + 'ⓝ' => 'Ⓝ', + 'ⓞ' => 'Ⓞ', + 'ⓟ' => 'Ⓟ', + 'ⓠ' => 'Ⓠ', + 'ⓡ' => 'Ⓡ', + 'ⓢ' => 'Ⓢ', + 'ⓣ' => 'Ⓣ', + 'ⓤ' => 'Ⓤ', + 'ⓥ' => 'Ⓥ', + 'ⓦ' => 'Ⓦ', + 'ⓧ' => 'Ⓧ', + 'ⓨ' => 'Ⓨ', + 'ⓩ' => 'Ⓩ', + 'ⰰ' => 'Ⰰ', + 'ⰱ' => 'Ⰱ', + 'ⰲ' => 'Ⰲ', + 'ⰳ' => 'Ⰳ', + 'ⰴ' => 'Ⰴ', + 'ⰵ' => 'Ⰵ', + 'ⰶ' => 'Ⰶ', + 'ⰷ' => 'Ⰷ', + 'ⰸ' => 'Ⰸ', + 'ⰹ' => 'Ⰹ', + 'ⰺ' => 'Ⰺ', + 'ⰻ' => 'Ⰻ', + 'ⰼ' => 'Ⰼ', + 'ⰽ' => 'Ⰽ', + 'ⰾ' => 'Ⰾ', + 'ⰿ' => 'Ⰿ', + 'ⱀ' => 'Ⱀ', + 'ⱁ' => 'Ⱁ', + 'ⱂ' => 'Ⱂ', + 'ⱃ' => 'Ⱃ', + 'ⱄ' => 'Ⱄ', + 'ⱅ' => 'Ⱅ', + 'ⱆ' => 'Ⱆ', + 'ⱇ' => 'Ⱇ', + 'ⱈ' => 'Ⱈ', + 'ⱉ' => 'Ⱉ', + 'ⱊ' => 'Ⱊ', + 'ⱋ' => 'Ⱋ', + 'ⱌ' => 'Ⱌ', + 'ⱍ' => 'Ⱍ', + 'ⱎ' => 'Ⱎ', + 'ⱏ' => 'Ⱏ', + 'ⱐ' => 'Ⱐ', + 'ⱑ' => 'Ⱑ', + 'ⱒ' => 'Ⱒ', + 'ⱓ' => 'Ⱓ', + 'ⱔ' => 'Ⱔ', + 'ⱕ' => 'Ⱕ', + 'ⱖ' => 'Ⱖ', + 'ⱗ' => 'Ⱗ', + 'ⱘ' => 'Ⱘ', + 'ⱙ' => 'Ⱙ', + 'ⱚ' => 'Ⱚ', + 'ⱛ' => 'Ⱛ', + 'ⱜ' => 'Ⱜ', + 'ⱝ' => 'Ⱝ', + 'ⱞ' => 'Ⱞ', + 'ⱡ' => 'Ⱡ', + 'ⱥ' => 'Ⱥ', + 'ⱦ' => 'Ⱦ', + 'ⱨ' => 'Ⱨ', + 'ⱪ' => 'Ⱪ', + 'ⱬ' => 'Ⱬ', + 'ⱳ' => 'Ⱳ', + 'ⱶ' => 'Ⱶ', + 'ⲁ' => 'Ⲁ', + 'ⲃ' => 'Ⲃ', + 'ⲅ' => 'Ⲅ', + 'ⲇ' => 'Ⲇ', + 'ⲉ' => 'Ⲉ', + 'ⲋ' => 'Ⲋ', + 'ⲍ' => 'Ⲍ', + 'ⲏ' => 'Ⲏ', + 'ⲑ' => 'Ⲑ', + 'ⲓ' => 'Ⲓ', + 'ⲕ' => 'Ⲕ', + 'ⲗ' => 'Ⲗ', + 'ⲙ' => 'Ⲙ', + 'ⲛ' => 'Ⲛ', + 'ⲝ' => 'Ⲝ', + 'ⲟ' => 'Ⲟ', + 'ⲡ' => 'Ⲡ', + 'ⲣ' => 'Ⲣ', + 'ⲥ' => 'Ⲥ', + 'ⲧ' => 'Ⲧ', + 'ⲩ' => 'Ⲩ', + 'ⲫ' => 'Ⲫ', + 'ⲭ' => 'Ⲭ', + 'ⲯ' => 'Ⲯ', + 'ⲱ' => 'Ⲱ', + 'ⲳ' => 'Ⲳ', + 'ⲵ' => 'Ⲵ', + 'ⲷ' => 'Ⲷ', + 'ⲹ' => 'Ⲹ', + 'ⲻ' => 'Ⲻ', + 'ⲽ' => 'Ⲽ', + 'ⲿ' => 'Ⲿ', + 'ⳁ' => 'Ⳁ', + 'ⳃ' => 'Ⳃ', + 'ⳅ' => 'Ⳅ', + 'ⳇ' => 'Ⳇ', + 'ⳉ' => 'Ⳉ', + 'ⳋ' => 'Ⳋ', + 'ⳍ' => 'Ⳍ', + 'ⳏ' => 'Ⳏ', + 'ⳑ' => 'Ⳑ', + 'ⳓ' => 'Ⳓ', + 'ⳕ' => 'Ⳕ', + 'ⳗ' => 'Ⳗ', + 'ⳙ' => 'Ⳙ', + 'ⳛ' => 'Ⳛ', + 'ⳝ' => 'Ⳝ', + 'ⳟ' => 'Ⳟ', + 'ⳡ' => 'Ⳡ', + 'ⳣ' => 'Ⳣ', + 'ⳬ' => 'Ⳬ', + 'ⳮ' => 'Ⳮ', + 'ⳳ' => 'Ⳳ', + 'ⴀ' => 'Ⴀ', + 'ⴁ' => 'Ⴁ', + 'ⴂ' => 'Ⴂ', + 'ⴃ' => 'Ⴃ', + 'ⴄ' => 'Ⴄ', + 'ⴅ' => 'Ⴅ', + 'ⴆ' => 'Ⴆ', + 'ⴇ' => 'Ⴇ', + 'ⴈ' => 'Ⴈ', + 'ⴉ' => 'Ⴉ', + 'ⴊ' => 'Ⴊ', + 'ⴋ' => 'Ⴋ', + 'ⴌ' => 'Ⴌ', + 'ⴍ' => 'Ⴍ', + 'ⴎ' => 'Ⴎ', + 'ⴏ' => 'Ⴏ', + 'ⴐ' => 'Ⴐ', + 'ⴑ' => 'Ⴑ', + 'ⴒ' => 'Ⴒ', + 'ⴓ' => 'Ⴓ', + 'ⴔ' => 'Ⴔ', + 'ⴕ' => 'Ⴕ', + 'ⴖ' => 'Ⴖ', + 'ⴗ' => 'Ⴗ', + 'ⴘ' => 'Ⴘ', + 'ⴙ' => 'Ⴙ', + 'ⴚ' => 'Ⴚ', + 'ⴛ' => 'Ⴛ', + 'ⴜ' => 'Ⴜ', + 'ⴝ' => 'Ⴝ', + 'ⴞ' => 'Ⴞ', + 'ⴟ' => 'Ⴟ', + 'ⴠ' => 'Ⴠ', + 'ⴡ' => 'Ⴡ', + 'ⴢ' => 'Ⴢ', + 'ⴣ' => 'Ⴣ', + 'ⴤ' => 'Ⴤ', + 'ⴥ' => 'Ⴥ', + 'ⴧ' => 'Ⴧ', + 'ⴭ' => 'Ⴭ', + 'ꙁ' => 'Ꙁ', + 'ꙃ' => 'Ꙃ', + 'ꙅ' => 'Ꙅ', + 'ꙇ' => 'Ꙇ', + 'ꙉ' => 'Ꙉ', + 'ꙋ' => 'Ꙋ', + 'ꙍ' => 'Ꙍ', + 'ꙏ' => 'Ꙏ', + 'ꙑ' => 'Ꙑ', + 'ꙓ' => 'Ꙓ', + 'ꙕ' => 'Ꙕ', + 'ꙗ' => 'Ꙗ', + 'ꙙ' => 'Ꙙ', + 'ꙛ' => 'Ꙛ', + 'ꙝ' => 'Ꙝ', + 'ꙟ' => 'Ꙟ', + 'ꙡ' => 'Ꙡ', + 'ꙣ' => 'Ꙣ', + 'ꙥ' => 'Ꙥ', + 'ꙧ' => 'Ꙧ', + 'ꙩ' => 'Ꙩ', + 'ꙫ' => 'Ꙫ', + 'ꙭ' => 'Ꙭ', + 'ꚁ' => 'Ꚁ', + 'ꚃ' => 'Ꚃ', + 'ꚅ' => 'Ꚅ', + 'ꚇ' => 'Ꚇ', + 'ꚉ' => 'Ꚉ', + 'ꚋ' => 'Ꚋ', + 'ꚍ' => 'Ꚍ', + 'ꚏ' => 'Ꚏ', + 'ꚑ' => 'Ꚑ', + 'ꚓ' => 'Ꚓ', + 'ꚕ' => 'Ꚕ', + 'ꚗ' => 'Ꚗ', + 'ꚙ' => 'Ꚙ', + 'ꚛ' => 'Ꚛ', + 'ꜣ' => 'Ꜣ', + 'ꜥ' => 'Ꜥ', + 'ꜧ' => 'Ꜧ', + 'ꜩ' => 'Ꜩ', + 'ꜫ' => 'Ꜫ', + 'ꜭ' => 'Ꜭ', + 'ꜯ' => 'Ꜯ', + 'ꜳ' => 'Ꜳ', + 'ꜵ' => 'Ꜵ', + 'ꜷ' => 'Ꜷ', + 'ꜹ' => 'Ꜹ', + 'ꜻ' => 'Ꜻ', + 'ꜽ' => 'Ꜽ', + 'ꜿ' => 'Ꜿ', + 'ꝁ' => 'Ꝁ', + 'ꝃ' => 'Ꝃ', + 'ꝅ' => 'Ꝅ', + 'ꝇ' => 'Ꝇ', + 'ꝉ' => 'Ꝉ', + 'ꝋ' => 'Ꝋ', + 'ꝍ' => 'Ꝍ', + 'ꝏ' => 'Ꝏ', + 'ꝑ' => 'Ꝑ', + 'ꝓ' => 'Ꝓ', + 'ꝕ' => 'Ꝕ', + 'ꝗ' => 'Ꝗ', + 'ꝙ' => 'Ꝙ', + 'ꝛ' => 'Ꝛ', + 'ꝝ' => 'Ꝝ', + 'ꝟ' => 'Ꝟ', + 'ꝡ' => 'Ꝡ', + 'ꝣ' => 'Ꝣ', + 'ꝥ' => 'Ꝥ', + 'ꝧ' => 'Ꝧ', + 'ꝩ' => 'Ꝩ', + 'ꝫ' => 'Ꝫ', + 'ꝭ' => 'Ꝭ', + 'ꝯ' => 'Ꝯ', + 'ꝺ' => 'Ꝺ', + 'ꝼ' => 'Ꝼ', + 'ꝿ' => 'Ꝿ', + 'ꞁ' => 'Ꞁ', + 'ꞃ' => 'Ꞃ', + 'ꞅ' => 'Ꞅ', + 'ꞇ' => 'Ꞇ', + 'ꞌ' => 'Ꞌ', + 'ꞑ' => 'Ꞑ', + 'ꞓ' => 'Ꞓ', + 'ꞗ' => 'Ꞗ', + 'ꞙ' => 'Ꞙ', + 'ꞛ' => 'Ꞛ', + 'ꞝ' => 'Ꞝ', + 'ꞟ' => 'Ꞟ', + 'ꞡ' => 'Ꞡ', + 'ꞣ' => 'Ꞣ', + 'ꞥ' => 'Ꞥ', + 'ꞧ' => 'Ꞧ', + 'ꞩ' => 'Ꞩ', + 'a' => 'A', + 'b' => 'B', + 'c' => 'C', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + 'k' => 'K', + 'l' => 'L', + 'm' => 'M', + 'n' => 'N', + 'o' => 'O', + 'p' => 'P', + 'q' => 'Q', + 'r' => 'R', + 's' => 'S', + 't' => 'T', + 'u' => 'U', + 'v' => 'V', + 'w' => 'W', + 'x' => 'X', + 'y' => 'Y', + 'z' => 'Z', + '𐐨' => '𐐀', + '𐐩' => '𐐁', + '𐐪' => '𐐂', + '𐐫' => '𐐃', + '𐐬' => '𐐄', + '𐐭' => '𐐅', + '𐐮' => '𐐆', + '𐐯' => '𐐇', + '𐐰' => '𐐈', + '𐐱' => '𐐉', + '𐐲' => '𐐊', + '𐐳' => '𐐋', + '𐐴' => '𐐌', + '𐐵' => '𐐍', + '𐐶' => '𐐎', + '𐐷' => '𐐏', + '𐐸' => '𐐐', + '𐐹' => '𐐑', + '𐐺' => '𐐒', + '𐐻' => '𐐓', + '𐐼' => '𐐔', + '𐐽' => '𐐕', + '𐐾' => '𐐖', + '𐐿' => '𐐗', + '𐑀' => '𐐘', + '𐑁' => '𐐙', + '𐑂' => '𐐚', + '𐑃' => '𐐛', + '𐑄' => '𐐜', + '𐑅' => '𐐝', + '𐑆' => '𐐞', + '𐑇' => '𐐟', + '𐑈' => '𐐠', + '𐑉' => '𐐡', + '𐑊' => '𐐢', + '𐑋' => '𐐣', + '𐑌' => '𐐤', + '𐑍' => '𐐥', + '𐑎' => '𐐦', + '𐑏' => '𐐧', + '𑣀' => '𑢠', + '𑣁' => '𑢡', + '𑣂' => '𑢢', + '𑣃' => '𑢣', + '𑣄' => '𑢤', + '𑣅' => '𑢥', + '𑣆' => '𑢦', + '𑣇' => '𑢧', + '𑣈' => '𑢨', + '𑣉' => '𑢩', + '𑣊' => '𑢪', + '𑣋' => '𑢫', + '𑣌' => '𑢬', + '𑣍' => '𑢭', + '𑣎' => '𑢮', + '𑣏' => '𑢯', + '𑣐' => '𑢰', + '𑣑' => '𑢱', + '𑣒' => '𑢲', + '𑣓' => '𑢳', + '𑣔' => '𑢴', + '𑣕' => '𑢵', + '𑣖' => '𑢶', + '𑣗' => '𑢷', + '𑣘' => '𑢸', + '𑣙' => '𑢹', + '𑣚' => '𑢺', + '𑣛' => '𑢻', + '𑣜' => '𑢼', + '𑣝' => '𑢽', + '𑣞' => '𑢾', + '𑣟' => '𑢿', +); diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/bootstrap.php b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/bootstrap.php new file mode 100644 index 0000000..204a41b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/bootstrap.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Mbstring as p; + +if (!function_exists('mb_strlen')) { + define('MB_CASE_UPPER', 0); + define('MB_CASE_LOWER', 1); + define('MB_CASE_TITLE', 2); + + function mb_convert_encoding($s, $to, $from = null) { return p\Mbstring::mb_convert_encoding($s, $to, $from); } + function mb_decode_mimeheader($s) { return p\Mbstring::mb_decode_mimeheader($s); } + function mb_encode_mimeheader($s, $charset = null, $transferEnc = null, $lf = null, $indent = null) { return p\Mbstring::mb_encode_mimeheader($s, $charset, $transferEnc, $lf, $indent); } + function mb_decode_numericentity($s, $convmap, $enc = null) { return p\Mbstring::mb_decode_numericentity($s, $convmap, $enc); } + function mb_encode_numericentity($s, $convmap, $enc = null, $is_hex = false) { return p\Mbstring::mb_encode_numericentity($s, $convmap, $enc, $is_hex); } + function mb_convert_case($s, $mode, $enc = null) { return p\Mbstring::mb_convert_case($s, $mode, $enc); } + function mb_internal_encoding($enc = null) { return p\Mbstring::mb_internal_encoding($enc); } + function mb_language($lang = null) { return p\Mbstring::mb_language($lang); } + function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } + function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } + function mb_check_encoding($var = null, $encoding = null) { return p\Mbstring::mb_check_encoding($var, $encoding); } + function mb_detect_encoding($str, $encodingList = null, $strict = false) { return p\Mbstring::mb_detect_encoding($str, $encodingList, $strict); } + function mb_detect_order($encodingList = null) { return p\Mbstring::mb_detect_order($encodingList); } + function mb_parse_str($s, &$result = array()) { parse_str($s, $result); } + function mb_strlen($s, $enc = null) { return p\Mbstring::mb_strlen($s, $enc); } + function mb_strpos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strpos($s, $needle, $offset, $enc); } + function mb_strtolower($s, $enc = null) { return p\Mbstring::mb_strtolower($s, $enc); } + function mb_strtoupper($s, $enc = null) { return p\Mbstring::mb_strtoupper($s, $enc); } + function mb_substitute_character($char = null) { return p\Mbstring::mb_substitute_character($char); } + function mb_substr($s, $start, $length = 2147483647, $enc = null) { return p\Mbstring::mb_substr($s, $start, $length, $enc); } + function mb_stripos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_stripos($s, $needle, $offset, $enc); } + function mb_stristr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_stristr($s, $needle, $part, $enc); } + function mb_strrchr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strrchr($s, $needle, $part, $enc); } + function mb_strrichr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strrichr($s, $needle, $part, $enc); } + function mb_strripos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strripos($s, $needle, $offset, $enc); } + function mb_strrpos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strrpos($s, $needle, $offset, $enc); } + function mb_strstr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strstr($s, $needle, $part, $enc); } + function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } + function mb_http_output($enc = null) { return p\Mbstring::mb_http_output($enc); } + function mb_strwidth($s, $enc = null) { return p\Mbstring::mb_strwidth($s, $enc); } + function mb_substr_count($haystack, $needle, $enc = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $enc); } + function mb_output_handler($contents, $status) { return p\Mbstring::mb_output_handler($contents, $status); } + function mb_http_input($type = '') { return p\Mbstring::mb_http_input($type); } + function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null) { return p\Mbstring::mb_convert_variables($toEncoding, $fromEncoding, $a, $b, $c, $d, $e, $f); } +} +if (!function_exists('mb_chr')) { + function mb_ord($s, $enc = null) { return p\Mbstring::mb_ord($s, $enc); } + function mb_chr($code, $enc = null) { return p\Mbstring::mb_chr($code, $enc); } + function mb_scrub($s, $enc = null) { $enc = null === $enc ? mb_internal_encoding() : $enc; return mb_convert_encoding($s, $enc, $enc); } +} + +if (!function_exists('mb_str_split')) { + function mb_str_split($string, $split_length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $split_length, $encoding); } +} diff --git a/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/composer.json b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/composer.json new file mode 100644 index 0000000..1a8bec5 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/symfony/polyfill-mbstring/composer.json @@ -0,0 +1,34 @@ +{ + "name": "symfony/polyfill-mbstring", + "type": "library", + "description": "Symfony polyfill for the Mbstring extension", + "keywords": ["polyfill", "shim", "compatibility", "portable", "mbstring"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.3" + }, + "autoload": { + "psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" }, + "files": [ "bootstrap.php" ] + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/.editorconfig b/system/templateEngines/Twig/Twig3x/twig/twig/.editorconfig new file mode 100644 index 0000000..270f1d1 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/.editorconfig @@ -0,0 +1,18 @@ +; top-most EditorConfig file +root = true + +; Unix-style newlines +[*] +end_of_line = LF + +[*.php] +indent_style = space +indent_size = 4 + +[*.test] +indent_style = space +indent_size = 4 + +[*.rst] +indent_style = space +indent_size = 4 diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/.gitattributes b/system/templateEngines/Twig/Twig3x/twig/twig/.gitattributes new file mode 100644 index 0000000..75e18f8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/.gitattributes @@ -0,0 +1,3 @@ +/extra/** export-ignore +/tests export-ignore +/phpunit.xml.dist export-ignore diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/.gitignore b/system/templateEngines/Twig/Twig3x/twig/twig/.gitignore new file mode 100644 index 0000000..cd52aea --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/.gitignore @@ -0,0 +1,4 @@ +/composer.lock +/phpunit.xml +/vendor +.phpunit.result.cache diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/.php_cs.dist b/system/templateEngines/Twig/Twig3x/twig/twig/.php_cs.dist new file mode 100644 index 0000000..b81882f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/.php_cs.dist @@ -0,0 +1,20 @@ +setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + '@PHPUnit75Migration:risky' => true, + 'php_unit_dedicate_assert' => ['target' => '5.6'], + 'array_syntax' => ['syntax' => 'short'], + 'php_unit_fqcn_annotation' => true, + 'no_unreachable_default_argument_value' => false, + 'braces' => ['allow_single_line_closure' => true], + 'heredoc_to_nowdoc' => false, + 'ordered_imports' => true, + 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'], + ]) + ->setRiskyAllowed(true) + ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)) +; diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/.travis.yml b/system/templateEngines/Twig/Twig3x/twig/twig/.travis.yml new file mode 100644 index 0000000..5441a49 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/.travis.yml @@ -0,0 +1,43 @@ +language: php + +cache: + directories: + - vendor + - extra/*/vendor + - $HOME/.composer/cache/files + +env: + global: + - SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE=1 + +before_install: + - phpenv config-rm xdebug.ini || return 0 + +install: + - travis_retry composer install + - (cd extra/cssinliner-extra && travis_retry composer install) + - (cd extra/html-extra && travis_retry composer install) + - (cd extra/inky-extra && travis_retry composer install) + - (cd extra/intl-extra && travis_retry composer install) + - (cd extra/markdown-extra && travis_retry composer install) + - (cd extra/string-extra && travis_retry composer install) + +script: + - ./vendor/bin/simple-phpunit + - (cd extra/cssinliner-extra && ./vendor/bin/simple-phpunit) + - (cd extra/html-extra && ./vendor/bin/simple-phpunit) + - (cd extra/inky-extra && ./vendor/bin/simple-phpunit) + - (cd extra/intl-extra && ./vendor/bin/simple-phpunit) + - (cd extra/markdown-extra && ./vendor/bin/simple-phpunit) + - (cd extra/string-extra && ./vendor/bin/simple-phpunit) + +jobs: + fast_finish: true + include: + - php: 7.2 + - php: 7.3 + - php: 7.4 + # Drupal does not support 3.x yet + #- stage: integration tests + # php: 7.3 + # script: ./drupal_test.sh diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/LICENSE b/system/templateEngines/Twig/Twig3x/twig/twig/LICENSE new file mode 100644 index 0000000..5e8a0b8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/LICENSE @@ -0,0 +1,29 @@ +Copyright (c) 2009-2020 by the Twig Team. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/README.rst b/system/templateEngines/Twig/Twig3x/twig/twig/README.rst new file mode 100644 index 0000000..d896ff5 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/README.rst @@ -0,0 +1,24 @@ +Twig, the flexible, fast, and secure template language for PHP +============================================================== + +Twig is a template language for PHP, released under the new BSD license (code +and documentation). + +Twig uses a syntax similar to the Django and Jinja template languages which +inspired the Twig runtime environment. + +Sponsors +-------- + +.. raw:: html + + + Blackfire.io + + +More Information +---------------- + +Read the `documentation`_ for more information. + +.. _documentation: https://twig.symfony.com/documentation diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/CacheInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/CacheInterface.php new file mode 100644 index 0000000..6e8c409 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/CacheInterface.php @@ -0,0 +1,46 @@ + + */ +interface CacheInterface +{ + /** + * Generates a cache key for the given template class name. + */ + public function generateKey(string $name, string $className): string; + + /** + * Writes the compiled template to cache. + * + * @param string $content The template representation as a PHP class + */ + public function write(string $key, string $content): void; + + /** + * Loads a template from the cache. + */ + public function load(string $key): void; + + /** + * Returns the modification timestamp of a key. + */ + public function getTimestamp(string $key): int; +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/FilesystemCache.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/FilesystemCache.php new file mode 100644 index 0000000..34c5d0f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/FilesystemCache.php @@ -0,0 +1,87 @@ + + */ +class FilesystemCache implements CacheInterface +{ + const FORCE_BYTECODE_INVALIDATION = 1; + + private $directory; + private $options; + + public function __construct(string $directory, int $options = 0) + { + $this->directory = rtrim($directory, '\/').'/'; + $this->options = $options; + } + + public function generateKey(string $name, string $className): string + { + $hash = hash('sha256', $className); + + return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; + } + + public function load(string $key): void + { + if (file_exists($key)) { + @include_once $key; + } + } + + public function write(string $key, string $content): void + { + $dir = \dirname($key); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true)) { + clearstatcache(true, $dir); + if (!is_dir($dir)) { + throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); + } + } + } elseif (!is_writable($dir)) { + throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); + } + + $tmpFile = tempnam($dir, basename($key)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { + @chmod($key, 0666 & ~umask()); + + if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { + // Compile cached file into bytecode cache + if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { + @opcache_invalidate($key, true); + } elseif (\function_exists('apc_compile_file')) { + apc_compile_file($key); + } + } + + return; + } + + throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $key)); + } + + public function getTimestamp(string $key): int + { + if (!file_exists($key)) { + return 0; + } + + return (int) @filemtime($key); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/NullCache.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/NullCache.php new file mode 100644 index 0000000..8d20d59 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Cache/NullCache.php @@ -0,0 +1,38 @@ + + */ +final class NullCache implements CacheInterface +{ + public function generateKey(string $name, string $className): string + { + return ''; + } + + public function write(string $key, string $content): void + { + } + + public function load(string $key): void + { + } + + public function getTimestamp(string $key): int + { + return 0; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Compiler.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Compiler.php new file mode 100644 index 0000000..7754c08 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Compiler.php @@ -0,0 +1,214 @@ + + */ +class Compiler +{ + private $lastLine; + private $source; + private $indentation; + private $env; + private $debugInfo = []; + private $sourceOffset; + private $sourceLine; + private $varNameSalt = 0; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + public function getEnvironment(): Environment + { + return $this->env; + } + + public function getSource(): string + { + return $this->source; + } + + /** + * @return $this + */ + public function compile(Node $node, int $indentation = 0) + { + $this->lastLine = null; + $this->source = ''; + $this->debugInfo = []; + $this->sourceOffset = 0; + // source code starts at 1 (as we then increment it when we encounter new lines) + $this->sourceLine = 1; + $this->indentation = $indentation; + $this->varNameSalt = 0; + + $node->compile($this); + + return $this; + } + + /** + * @return $this + */ + public function subcompile(Node $node, bool $raw = true) + { + if (false === $raw) { + $this->source .= str_repeat(' ', $this->indentation * 4); + } + + $node->compile($this); + + return $this; + } + + /** + * Adds a raw string to the compiled code. + * + * @return $this + */ + public function raw(string $string) + { + $this->source .= $string; + + return $this; + } + + /** + * Writes a string to the compiled code by adding indentation. + * + * @return $this + */ + public function write(...$strings) + { + foreach ($strings as $string) { + $this->source .= str_repeat(' ', $this->indentation * 4).$string; + } + + return $this; + } + + /** + * Adds a quoted string to the compiled code. + * + * @return $this + */ + public function string(string $value) + { + $this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\")); + + return $this; + } + + /** + * Returns a PHP representation of a given value. + * + * @return $this + */ + public function repr($value) + { + if (\is_int($value) || \is_float($value)) { + if (false !== $locale = setlocale(LC_NUMERIC, '0')) { + setlocale(LC_NUMERIC, 'C'); + } + + $this->raw(var_export($value, true)); + + if (false !== $locale) { + setlocale(LC_NUMERIC, $locale); + } + } elseif (null === $value) { + $this->raw('null'); + } elseif (\is_bool($value)) { + $this->raw($value ? 'true' : 'false'); + } elseif (\is_array($value)) { + $this->raw('array('); + $first = true; + foreach ($value as $key => $v) { + if (!$first) { + $this->raw(', '); + } + $first = false; + $this->repr($key); + $this->raw(' => '); + $this->repr($v); + } + $this->raw(')'); + } else { + $this->string($value); + } + + return $this; + } + + /** + * @return $this + */ + public function addDebugInfo(Node $node) + { + if ($node->getTemplateLine() != $this->lastLine) { + $this->write(sprintf("// line %d\n", $node->getTemplateLine())); + + $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); + $this->sourceOffset = \strlen($this->source); + $this->debugInfo[$this->sourceLine] = $node->getTemplateLine(); + + $this->lastLine = $node->getTemplateLine(); + } + + return $this; + } + + public function getDebugInfo(): array + { + ksort($this->debugInfo); + + return $this->debugInfo; + } + + /** + * @return $this + */ + public function indent(int $step = 1) + { + $this->indentation += $step; + + return $this; + } + + /** + * @return $this + * + * @throws \LogicException When trying to outdent too much so the indentation would become negative + */ + public function outdent(int $step = 1) + { + // can't outdent by more steps than the current indentation level + if ($this->indentation < $step) { + throw new \LogicException('Unable to call outdent() as the indentation would become negative.'); + } + + $this->indentation -= $step; + + return $this; + } + + public function getVarName(): string + { + return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++)); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Environment.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Environment.php new file mode 100644 index 0000000..9ea3ceb --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Environment.php @@ -0,0 +1,816 @@ + + */ +class Environment +{ + const VERSION = '3.0.3'; + const VERSION_ID = 30003; + const MAJOR_VERSION = 3; + const MINOR_VERSION = 0; + const RELEASE_VERSION = 3; + const EXTRA_VERSION = ''; + + private $charset; + private $loader; + private $debug; + private $autoReload; + private $cache; + private $lexer; + private $parser; + private $compiler; + private $globals = []; + private $resolvedGlobals; + private $loadedTemplates; + private $strictVariables; + private $templateClassPrefix = '__TwigTemplate_'; + private $originalCache; + private $extensionSet; + private $runtimeLoaders = []; + private $runtimes = []; + private $optionsHash; + + /** + * Constructor. + * + * Available options: + * + * * debug: When set to true, it automatically set "auto_reload" to true as + * well (default to false). + * + * * charset: The charset used by the templates (default to UTF-8). + * + * * cache: An absolute path where to store the compiled templates, + * a \Twig\Cache\CacheInterface implementation, + * or false to disable compilation cache (default). + * + * * auto_reload: Whether to reload the template if the original source changed. + * If you don't provide the auto_reload option, it will be + * determined automatically based on the debug value. + * + * * strict_variables: Whether to ignore invalid variables in templates + * (default to false). + * + * * autoescape: Whether to enable auto-escaping (default to html): + * * false: disable auto-escaping + * * html, js: set the autoescaping to one of the supported strategies + * * name: set the autoescaping strategy based on the template name extension + * * PHP callback: a PHP callback that returns an escaping strategy based on the template "name" + * + * * optimizations: A flag that indicates which optimizations to apply + * (default to -1 which means that all optimizations are enabled; + * set it to 0 to disable). + */ + public function __construct(LoaderInterface $loader, $options = []) + { + $this->setLoader($loader); + + $options = array_merge([ + 'debug' => false, + 'charset' => 'UTF-8', + 'strict_variables' => false, + 'autoescape' => 'html', + 'cache' => false, + 'auto_reload' => null, + 'optimizations' => -1, + ], $options); + + $this->debug = (bool) $options['debug']; + $this->setCharset($options['charset'] ?? 'UTF-8'); + $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload']; + $this->strictVariables = (bool) $options['strict_variables']; + $this->setCache($options['cache']); + $this->extensionSet = new ExtensionSet(); + + $this->addExtension(new CoreExtension()); + $this->addExtension(new EscaperExtension($options['autoescape'])); + $this->addExtension(new OptimizerExtension($options['optimizations'])); + } + + /** + * Enables debugging mode. + */ + public function enableDebug() + { + $this->debug = true; + $this->updateOptionsHash(); + } + + /** + * Disables debugging mode. + */ + public function disableDebug() + { + $this->debug = false; + $this->updateOptionsHash(); + } + + /** + * Checks if debug mode is enabled. + * + * @return bool true if debug mode is enabled, false otherwise + */ + public function isDebug() + { + return $this->debug; + } + + /** + * Enables the auto_reload option. + */ + public function enableAutoReload() + { + $this->autoReload = true; + } + + /** + * Disables the auto_reload option. + */ + public function disableAutoReload() + { + $this->autoReload = false; + } + + /** + * Checks if the auto_reload option is enabled. + * + * @return bool true if auto_reload is enabled, false otherwise + */ + public function isAutoReload() + { + return $this->autoReload; + } + + /** + * Enables the strict_variables option. + */ + public function enableStrictVariables() + { + $this->strictVariables = true; + $this->updateOptionsHash(); + } + + /** + * Disables the strict_variables option. + */ + public function disableStrictVariables() + { + $this->strictVariables = false; + $this->updateOptionsHash(); + } + + /** + * Checks if the strict_variables option is enabled. + * + * @return bool true if strict_variables is enabled, false otherwise + */ + public function isStrictVariables() + { + return $this->strictVariables; + } + + /** + * Gets the current cache implementation. + * + * @param bool $original Whether to return the original cache option or the real cache instance + * + * @return CacheInterface|string|false A Twig\Cache\CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache + */ + public function getCache($original = true) + { + return $original ? $this->originalCache : $this->cache; + } + + /** + * Sets the current cache implementation. + * + * @param CacheInterface|string|false $cache A Twig\Cache\CacheInterface implementation, + * an absolute path to the compiled templates, + * or false to disable cache + */ + public function setCache($cache) + { + if (\is_string($cache)) { + $this->originalCache = $cache; + $this->cache = new FilesystemCache($cache); + } elseif (false === $cache) { + $this->originalCache = $cache; + $this->cache = new NullCache(); + } elseif ($cache instanceof CacheInterface) { + $this->originalCache = $this->cache = $cache; + } else { + throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.')); + } + } + + /** + * Gets the template class associated with the given string. + * + * The generated template class is based on the following parameters: + * + * * The cache key for the given template; + * * The currently enabled extensions; + * * Whether the Twig C extension is available or not; + * * PHP version; + * * Twig version; + * * Options with what environment was created. + * + * @param string $name The name for which to calculate the template class name + * @param int|null $index The index if it is an embedded template + * + * @internal + */ + public function getTemplateClass(string $name, int $index = null): string + { + $key = $this->getLoader()->getCacheKey($name).$this->optionsHash; + + return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '___'.$index); + } + + /** + * Renders a template. + * + * @param string|TemplateWrapper $name The template name + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering + */ + public function render($name, array $context = []): string + { + return $this->load($name)->render($context); + } + + /** + * Displays a template. + * + * @param string|TemplateWrapper $name The template name + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering + */ + public function display($name, array $context = []): void + { + $this->load($name)->display($context); + } + + /** + * Loads a template. + * + * @param string|TemplateWrapper $name The template name + * + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation + */ + public function load($name): TemplateWrapper + { + if ($name instanceof TemplateWrapper) { + return $name; + } + + return new TemplateWrapper($this, $this->loadTemplate($this->getTemplateClass($name), $name)); + } + + /** + * Loads a template internal representation. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The template name + * @param int $index The index if it is an embedded template + * + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation + * + * @internal + */ + public function loadTemplate(string $cls, string $name, int $index = null): Template + { + $mainCls = $cls; + if (null !== $index) { + $cls .= '___'.$index; + } + + if (isset($this->loadedTemplates[$cls])) { + return $this->loadedTemplates[$cls]; + } + + if (!class_exists($cls, false)) { + $key = $this->cache->generateKey($name, $mainCls); + + if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) { + $this->cache->load($key); + } + + $source = null; + if (!class_exists($cls, false)) { + $source = $this->getLoader()->getSourceContext($name); + $content = $this->compileSource($source); + $this->cache->write($key, $content); + $this->cache->load($key); + + if (!class_exists($mainCls, false)) { + /* Last line of defense if either $this->bcWriteCacheFile was used, + * $this->cache is implemented as a no-op or we have a race condition + * where the cache was cleared between the above calls to write to and load from + * the cache. + */ + eval('?>'.$content); + } + + if (!class_exists($cls, false)) { + throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source); + } + } + } + + $this->extensionSet->initRuntime(); + + return $this->loadedTemplates[$cls] = new $cls($this); + } + + /** + * Creates a template from source. + * + * This method should not be used as a generic way to load templates. + * + * @param string $template The template source + * @param string $name An optional name of the template to be used in error messages + * + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + */ + public function createTemplate(string $template, string $name = null): TemplateWrapper + { + $hash = hash('sha256', $template, false); + if (null !== $name) { + $name = sprintf('%s (string template %s)', $name, $hash); + } else { + $name = sprintf('__string_template__%s', $hash); + } + + $loader = new ChainLoader([ + new ArrayLoader([$name => $template]), + $current = $this->getLoader(), + ]); + + $this->setLoader($loader); + try { + return new TemplateWrapper($this, $this->loadTemplate($this->getTemplateClass($name), $name)); + } finally { + $this->setLoader($current); + } + } + + /** + * Returns true if the template is still fresh. + * + * Besides checking the loader for freshness information, + * this method also checks if the enabled extensions have + * not changed. + * + * @param int $time The last modification time of the cached template + */ + public function isTemplateFresh(string $name, int $time): bool + { + return $this->extensionSet->getLastModified() <= $time && $this->getLoader()->isFresh($name, $time); + } + + /** + * Tries to load a template consecutively from an array. + * + * Similar to load() but it also accepts instances of \Twig\Template and + * \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded. + * + * @param string|TemplateWrapper|array $names A template or an array of templates to try consecutively + * + * @throws LoaderError When none of the templates can be found + * @throws SyntaxError When an error occurred during compilation + */ + public function resolveTemplate($names): TemplateWrapper + { + if (!\is_array($names)) { + return $this->load($names); + } + + foreach ($names as $name) { + try { + return $this->load($name); + } catch (LoaderError $e) { + } + } + + throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); + } + + public function setLexer(Lexer $lexer) + { + $this->lexer = $lexer; + } + + /** + * @throws SyntaxError When the code is syntactically wrong + */ + public function tokenize(Source $source): TokenStream + { + if (null === $this->lexer) { + $this->lexer = new Lexer($this); + } + + return $this->lexer->tokenize($source); + } + + public function setParser(Parser $parser) + { + $this->parser = $parser; + } + + /** + * Converts a token stream to a node tree. + * + * @throws SyntaxError When the token stream is syntactically or semantically wrong + */ + public function parse(TokenStream $stream): ModuleNode + { + if (null === $this->parser) { + $this->parser = new Parser($this); + } + + return $this->parser->parse($stream); + } + + public function setCompiler(Compiler $compiler) + { + $this->compiler = $compiler; + } + + /** + * Compiles a node and returns the PHP code. + */ + public function compile(Node $node): string + { + if (null === $this->compiler) { + $this->compiler = new Compiler($this); + } + + return $this->compiler->compile($node)->getSource(); + } + + /** + * Compiles a template source code. + * + * @throws SyntaxError When there was an error during tokenizing, parsing or compiling + */ + public function compileSource(Source $source): string + { + try { + return $this->compile($this->parse($this->tokenize($source))); + } catch (Error $e) { + $e->setSourceContext($source); + throw $e; + } catch (\Exception $e) { + throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); + } + } + + public function setLoader(LoaderInterface $loader) + { + $this->loader = $loader; + } + + public function getLoader(): LoaderInterface + { + return $this->loader; + } + + public function setCharset(string $charset) + { + if ('UTF8' === $charset = strtoupper($charset)) { + // iconv on Windows requires "UTF-8" instead of "UTF8" + $charset = 'UTF-8'; + } + + $this->charset = $charset; + } + + public function getCharset(): string + { + return $this->charset; + } + + public function hasExtension(string $class): bool + { + return $this->extensionSet->hasExtension($class); + } + + public function addRuntimeLoader(RuntimeLoaderInterface $loader) + { + $this->runtimeLoaders[] = $loader; + } + + public function getExtension(string $class): ExtensionInterface + { + return $this->extensionSet->getExtension($class); + } + + /** + * Returns the runtime implementation of a Twig element (filter/function/test). + * + * @param string $class A runtime class name + * + * @return object The runtime implementation + * + * @throws RuntimeError When the template cannot be found + */ + public function getRuntime(string $class) + { + if (isset($this->runtimes[$class])) { + return $this->runtimes[$class]; + } + + foreach ($this->runtimeLoaders as $loader) { + if (null !== $runtime = $loader->load($class)) { + return $this->runtimes[$class] = $runtime; + } + } + + throw new RuntimeError(sprintf('Unable to load the "%s" runtime.', $class)); + } + + public function addExtension(ExtensionInterface $extension) + { + $this->extensionSet->addExtension($extension); + $this->updateOptionsHash(); + } + + /** + * @param ExtensionInterface[] $extensions An array of extensions + */ + public function setExtensions(array $extensions) + { + $this->extensionSet->setExtensions($extensions); + $this->updateOptionsHash(); + } + + /** + * @return ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) + */ + public function getExtensions(): array + { + return $this->extensionSet->getExtensions(); + } + + public function addTokenParser(TokenParserInterface $parser) + { + $this->extensionSet->addTokenParser($parser); + } + + /** + * @return TokenParserInterface[] + * + * @internal + */ + public function getTokenParsers(): array + { + return $this->extensionSet->getTokenParsers(); + } + + /** + * @return TokenParserInterface[] + * + * @internal + */ + public function getTags(): array + { + $tags = []; + foreach ($this->getTokenParsers() as $parser) { + $tags[$parser->getTag()] = $parser; + } + + return $tags; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor) + { + $this->extensionSet->addNodeVisitor($visitor); + } + + /** + * @return NodeVisitorInterface[] + * + * @internal + */ + public function getNodeVisitors(): array + { + return $this->extensionSet->getNodeVisitors(); + } + + public function addFilter(TwigFilter $filter) + { + $this->extensionSet->addFilter($filter); + } + + /** + * @internal + */ + public function getFilter(string $name): ?TwigFilter + { + return $this->extensionSet->getFilter($name); + } + + public function registerUndefinedFilterCallback(callable $callable) + { + $this->extensionSet->registerUndefinedFilterCallback($callable); + } + + /** + * Gets the registered Filters. + * + * Be warned that this method cannot return filters defined with registerUndefinedFilterCallback. + * + * @return TwigFilter[] + * + * @see registerUndefinedFilterCallback + * + * @internal + */ + public function getFilters(): array + { + return $this->extensionSet->getFilters(); + } + + public function addTest(TwigTest $test) + { + $this->extensionSet->addTest($test); + } + + /** + * @return TwigTest[] + * + * @internal + */ + public function getTests(): array + { + return $this->extensionSet->getTests(); + } + + /** + * @internal + */ + public function getTest(string $name): ?TwigTest + { + return $this->extensionSet->getTest($name); + } + + public function addFunction(TwigFunction $function) + { + $this->extensionSet->addFunction($function); + } + + /** + * @internal + */ + public function getFunction(string $name): ?TwigFunction + { + return $this->extensionSet->getFunction($name); + } + + public function registerUndefinedFunctionCallback(callable $callable) + { + $this->extensionSet->registerUndefinedFunctionCallback($callable); + } + + /** + * Gets registered functions. + * + * Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback. + * + * @return TwigFunction[] + * + * @see registerUndefinedFunctionCallback + * + * @internal + */ + public function getFunctions(): array + { + return $this->extensionSet->getFunctions(); + } + + /** + * Registers a Global. + * + * New globals can be added before compiling or rendering a template; + * but after, you can only update existing globals. + * + * @param mixed $value The global value + */ + public function addGlobal(string $name, $value) + { + if ($this->extensionSet->isInitialized() && !\array_key_exists($name, $this->getGlobals())) { + throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); + } + + if (null !== $this->resolvedGlobals) { + $this->resolvedGlobals[$name] = $value; + } else { + $this->globals[$name] = $value; + } + } + + /** + * @internal + */ + public function getGlobals(): array + { + if ($this->extensionSet->isInitialized()) { + if (null === $this->resolvedGlobals) { + $this->resolvedGlobals = array_merge($this->extensionSet->getGlobals(), $this->globals); + } + + return $this->resolvedGlobals; + } + + return array_merge($this->extensionSet->getGlobals(), $this->globals); + } + + public function mergeGlobals(array $context): array + { + // we don't use array_merge as the context being generally + // bigger than globals, this code is faster. + foreach ($this->getGlobals() as $key => $value) { + if (!\array_key_exists($key, $context)) { + $context[$key] = $value; + } + } + + return $context; + } + + /** + * @internal + */ + public function getUnaryOperators(): array + { + return $this->extensionSet->getUnaryOperators(); + } + + /** + * @internal + */ + public function getBinaryOperators(): array + { + return $this->extensionSet->getBinaryOperators(); + } + + private function updateOptionsHash(): void + { + $this->optionsHash = implode(':', [ + $this->extensionSet->getSignature(), + PHP_MAJOR_VERSION, + PHP_MINOR_VERSION, + self::VERSION, + (int) $this->debug, + (int) $this->strictVariables, + ]); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/Error.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/Error.php new file mode 100644 index 0000000..d8a30c5 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/Error.php @@ -0,0 +1,227 @@ + + */ +class Error extends \Exception +{ + private $lineno; + private $name; + private $rawMessage; + private $sourcePath; + private $sourceCode; + + /** + * Constructor. + * + * By default, automatic guessing is enabled. + * + * @param string $message The error message + * @param int $lineno The template line where the error occurred + * @param Source|null $source The source context where the error occurred + */ + public function __construct(string $message, int $lineno = -1, Source $source = null, \Exception $previous = null) + { + parent::__construct('', 0, $previous); + + if (null === $source) { + $name = null; + } else { + $name = $source->getName(); + $this->sourceCode = $source->getCode(); + $this->sourcePath = $source->getPath(); + } + + $this->lineno = $lineno; + $this->name = $name; + $this->rawMessage = $message; + $this->updateRepr(); + } + + public function getRawMessage(): string + { + return $this->rawMessage; + } + + public function getTemplateLine(): int + { + return $this->lineno; + } + + public function setTemplateLine(int $lineno): void + { + $this->lineno = $lineno; + + $this->updateRepr(); + } + + public function getSourceContext(): ?Source + { + return $this->name ? new Source($this->sourceCode, $this->name, $this->sourcePath) : null; + } + + public function setSourceContext(Source $source = null): void + { + if (null === $source) { + $this->sourceCode = $this->name = $this->sourcePath = null; + } else { + $this->sourceCode = $source->getCode(); + $this->name = $source->getName(); + $this->sourcePath = $source->getPath(); + } + + $this->updateRepr(); + } + + public function guess(): void + { + $this->guessTemplateInfo(); + $this->updateRepr(); + } + + public function appendMessage($rawMessage): void + { + $this->rawMessage .= $rawMessage; + $this->updateRepr(); + } + + private function updateRepr(): void + { + $this->message = $this->rawMessage; + + if ($this->sourcePath && $this->lineno > 0) { + $this->file = $this->sourcePath; + $this->line = $this->lineno; + + return; + } + + $dot = false; + if ('.' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $dot = true; + } + + $questionMark = false; + if ('?' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $questionMark = true; + } + + if ($this->name) { + if (\is_string($this->name) || (\is_object($this->name) && method_exists($this->name, '__toString'))) { + $name = sprintf('"%s"', $this->name); + } else { + $name = json_encode($this->name); + } + $this->message .= sprintf(' in %s', $name); + } + + if ($this->lineno && $this->lineno >= 0) { + $this->message .= sprintf(' at line %d', $this->lineno); + } + + if ($dot) { + $this->message .= '.'; + } + + if ($questionMark) { + $this->message .= '?'; + } + } + + private function guessTemplateInfo(): void + { + $template = null; + $templateClass = null; + + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + foreach ($backtrace as $trace) { + if (isset($trace['object']) && $trace['object'] instanceof Template) { + $currentClass = \get_class($trace['object']); + $isEmbedContainer = 0 === strpos($templateClass, $currentClass); + if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) { + $template = $trace['object']; + $templateClass = \get_class($trace['object']); + } + } + } + + // update template name + if (null !== $template && null === $this->name) { + $this->name = $template->getTemplateName(); + } + + // update template path if any + if (null !== $template && null === $this->sourcePath) { + $src = $template->getSourceContext(); + $this->sourceCode = $src->getCode(); + $this->sourcePath = $src->getPath(); + } + + if (null === $template || $this->lineno > -1) { + return; + } + + $r = new \ReflectionObject($template); + $file = $r->getFileName(); + + $exceptions = [$e = $this]; + while ($e = $e->getPrevious()) { + $exceptions[] = $e; + } + + while ($e = array_pop($exceptions)) { + $traces = $e->getTrace(); + array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]); + + while ($trace = array_shift($traces)) { + if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) { + continue; + } + + foreach ($template->getDebugInfo() as $codeLine => $templateLine) { + if ($codeLine <= $trace['line']) { + // update template line + $this->lineno = $templateLine; + + return; + } + } + } + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/LoaderError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/LoaderError.php new file mode 100644 index 0000000..7c8c23c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/LoaderError.php @@ -0,0 +1,21 @@ + + */ +class LoaderError extends Error +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/RuntimeError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/RuntimeError.php new file mode 100644 index 0000000..f6b8476 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/RuntimeError.php @@ -0,0 +1,22 @@ + + */ +class RuntimeError extends Error +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/SyntaxError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/SyntaxError.php new file mode 100644 index 0000000..726b330 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Error/SyntaxError.php @@ -0,0 +1,46 @@ + + */ +class SyntaxError extends Error +{ + /** + * Tweaks the error message to include suggestions. + * + * @param string $name The original name of the item that does not exist + * @param array $items An array of possible items + */ + public function addSuggestions(string $name, array $items): void + { + $alternatives = []; + foreach ($items as $item) { + $lev = levenshtein($name, $item); + if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) { + $alternatives[$item] = $lev; + } + } + + if (!$alternatives) { + return; + } + + asort($alternatives); + + $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives)))); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/ExpressionParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/ExpressionParser.php new file mode 100644 index 0000000..6784ebf --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/ExpressionParser.php @@ -0,0 +1,807 @@ + + * + * @internal + */ +class ExpressionParser +{ + const OPERATOR_LEFT = 1; + const OPERATOR_RIGHT = 2; + + private $parser; + private $env; + private $unaryOperators; + private $binaryOperators; + + public function __construct(Parser $parser, Environment $env) + { + $this->parser = $parser; + $this->env = $env; + $this->unaryOperators = $env->getUnaryOperators(); + $this->binaryOperators = $env->getBinaryOperators(); + } + + public function parseExpression($precedence = 0, $allowArrow = false) + { + if ($allowArrow && $arrow = $this->parseArrow()) { + return $arrow; + } + + $expr = $this->getPrimary(); + $token = $this->parser->getCurrentToken(); + while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) { + $op = $this->binaryOperators[$token->getValue()]; + $this->parser->getStream()->next(); + + if ('is not' === $token->getValue()) { + $expr = $this->parseNotTestExpression($expr); + } elseif ('is' === $token->getValue()) { + $expr = $this->parseTestExpression($expr); + } elseif (isset($op['callable'])) { + $expr = $op['callable']($this->parser, $expr); + } else { + $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); + $class = $op['class']; + $expr = new $class($expr, $expr1, $token->getLine()); + } + + $token = $this->parser->getCurrentToken(); + } + + if (0 === $precedence) { + return $this->parseConditionalExpression($expr); + } + + return $expr; + } + + /** + * @return ArrowFunctionExpression|null + */ + private function parseArrow() + { + $stream = $this->parser->getStream(); + + // short array syntax (one argument, no parentheses)? + if ($stream->look(1)->test(/* Token::ARROW_TYPE */ 12)) { + $line = $stream->getCurrent()->getLine(); + $token = $stream->expect(/* Token::NAME_TYPE */ 5); + $names = [new AssignNameExpression($token->getValue(), $token->getLine())]; + $stream->expect(/* Token::ARROW_TYPE */ 12); + + return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line); + } + + // first, determine if we are parsing an arrow function by finding => (long form) + $i = 0; + if (!$stream->look($i)->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + return null; + } + ++$i; + while (true) { + // variable name + ++$i; + if (!$stream->look($i)->test(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + ++$i; + } + if (!$stream->look($i)->test(/* Token::PUNCTUATION_TYPE */ 9, ')')) { + return null; + } + ++$i; + if (!$stream->look($i)->test(/* Token::ARROW_TYPE */ 12)) { + return null; + } + + // yes, let's parse it properly + $token = $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '('); + $line = $token->getLine(); + + $names = []; + while (true) { + $token = $stream->expect(/* Token::NAME_TYPE */ 5); + $names[] = new AssignNameExpression($token->getValue(), $token->getLine()); + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ')'); + $stream->expect(/* Token::ARROW_TYPE */ 12); + + return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line); + } + + private function getPrimary(): AbstractExpression + { + $token = $this->parser->getCurrentToken(); + + if ($this->isUnary($token)) { + $operator = $this->unaryOperators[$token->getValue()]; + $this->parser->getStream()->next(); + $expr = $this->parseExpression($operator['precedence']); + $class = $operator['class']; + + return $this->parsePostfixExpression(new $class($expr, $token->getLine())); + } elseif ($token->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $this->parser->getStream()->next(); + $expr = $this->parseExpression(); + $this->parser->getStream()->expect(/* Token::PUNCTUATION_TYPE */ 9, ')', 'An opened parenthesis is not properly closed'); + + return $this->parsePostfixExpression($expr); + } + + return $this->parsePrimaryExpression(); + } + + private function parseConditionalExpression($expr): AbstractExpression + { + while ($this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, '?')) { + if (!$this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $expr2 = $this->parseExpression(); + if ($this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $expr3 = $this->parseExpression(); + } else { + $expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine()); + } + } else { + $expr2 = $expr; + $expr3 = $this->parseExpression(); + } + + $expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); + } + + return $expr; + } + + private function isUnary(Token $token): bool + { + return $token->test(/* Token::OPERATOR_TYPE */ 8) && isset($this->unaryOperators[$token->getValue()]); + } + + private function isBinary(Token $token): bool + { + return $token->test(/* Token::OPERATOR_TYPE */ 8) && isset($this->binaryOperators[$token->getValue()]); + } + + public function parsePrimaryExpression() + { + $token = $this->parser->getCurrentToken(); + switch ($token->getType()) { + case /* Token::NAME_TYPE */ 5: + $this->parser->getStream()->next(); + switch ($token->getValue()) { + case 'true': + case 'TRUE': + $node = new ConstantExpression(true, $token->getLine()); + break; + + case 'false': + case 'FALSE': + $node = new ConstantExpression(false, $token->getLine()); + break; + + case 'none': + case 'NONE': + case 'null': + case 'NULL': + $node = new ConstantExpression(null, $token->getLine()); + break; + + default: + if ('(' === $this->parser->getCurrentToken()->getValue()) { + $node = $this->getFunctionNode($token->getValue(), $token->getLine()); + } else { + $node = new NameExpression($token->getValue(), $token->getLine()); + } + } + break; + + case /* Token::NUMBER_TYPE */ 6: + $this->parser->getStream()->next(); + $node = new ConstantExpression($token->getValue(), $token->getLine()); + break; + + case /* Token::STRING_TYPE */ 7: + case /* Token::INTERPOLATION_START_TYPE */ 10: + $node = $this->parseStringExpression(); + break; + + case /* Token::OPERATOR_TYPE */ 8: + if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { + // in this context, string operators are variable names + $this->parser->getStream()->next(); + $node = new NameExpression($token->getValue(), $token->getLine()); + break; + } elseif (isset($this->unaryOperators[$token->getValue()])) { + $class = $this->unaryOperators[$token->getValue()]['class']; + if (!\in_array($class, [NegUnary::class, PosUnary::class])) { + throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } + + $this->parser->getStream()->next(); + $expr = $this->parsePrimaryExpression(); + + $node = new $class($expr, $token->getLine()); + break; + } + + // no break + default: + if ($token->test(/* Token::PUNCTUATION_TYPE */ 9, '[')) { + $node = $this->parseArrayExpression(); + } elseif ($token->test(/* Token::PUNCTUATION_TYPE */ 9, '{')) { + $node = $this->parseHashExpression(); + } elseif ($token->test(/* Token::OPERATOR_TYPE */ 8, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { + 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()); + } else { + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } + } + + return $this->parsePostfixExpression($node); + } + + public function parseStringExpression() + { + $stream = $this->parser->getStream(); + + $nodes = []; + // a string cannot be followed by another string in a single expression + $nextCanBeString = true; + while (true) { + if ($nextCanBeString && $token = $stream->nextIf(/* Token::STRING_TYPE */ 7)) { + $nodes[] = new ConstantExpression($token->getValue(), $token->getLine()); + $nextCanBeString = false; + } elseif ($stream->nextIf(/* Token::INTERPOLATION_START_TYPE */ 10)) { + $nodes[] = $this->parseExpression(); + $stream->expect(/* Token::INTERPOLATION_END_TYPE */ 11); + $nextCanBeString = true; + } else { + break; + } + } + + $expr = array_shift($nodes); + foreach ($nodes as $node) { + $expr = new ConcatBinary($expr, $node, $node->getTemplateLine()); + } + + return $expr; + } + + public function parseArrayExpression() + { + $stream = $this->parser->getStream(); + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '[', 'An array element was expected'); + + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); + $first = true; + while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) { + if (!$first) { + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'An array element must be followed by a comma'); + + // trailing ,? + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) { + break; + } + } + $first = false; + + $node->addElement($this->parseExpression()); + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']', 'An opened array is not properly closed'); + + return $node; + } + + public function parseHashExpression() + { + $stream = $this->parser->getStream(); + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '{', 'A hash element was expected'); + + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); + $first = true; + while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, '}')) { + if (!$first) { + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'A hash value must be followed by a comma'); + + // trailing ,? + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '}')) { + break; + } + } + $first = false; + + // a hash key can be: + // + // * a number -- 12 + // * a string -- 'a' + // * a name, which is equivalent to a string -- a + // * an expression, which must be enclosed in parentheses -- (1 + 2) + if (($token = $stream->nextIf(/* Token::STRING_TYPE */ 7)) || ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) || $token = $stream->nextIf(/* Token::NUMBER_TYPE */ 6)) { + $key = new ConstantExpression($token->getValue(), $token->getLine()); + } elseif ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $key = $this->parseExpression(); + } else { + $current = $stream->getCurrent(); + + 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()); + } + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ':', 'A hash key must be followed by a colon (:)'); + $value = $this->parseExpression(); + + $node->addElement($value, $key); + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '}', 'An opened hash is not properly closed'); + + return $node; + } + + public function parsePostfixExpression($node) + { + while (true) { + $token = $this->parser->getCurrentToken(); + if (/* Token::PUNCTUATION_TYPE */ 9 == $token->getType()) { + if ('.' == $token->getValue() || '[' == $token->getValue()) { + $node = $this->parseSubscriptExpression($node); + } elseif ('|' == $token->getValue()) { + $node = $this->parseFilterExpression($node); + } else { + break; + } + } else { + break; + } + } + + return $node; + } + + public function getFunctionNode($name, $line) + { + switch ($name) { + case 'parent': + $this->parseArguments(); + if (!\count($this->parser->getBlockStack())) { + throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + } + + if (!$this->parser->getParent() && !$this->parser->hasTraits()) { + throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + } + + return new ParentExpression($this->parser->peekBlockStack(), $line); + case 'block': + $args = $this->parseArguments(); + if (\count($args) < 1) { + throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); + } + + return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); + case 'attribute': + $args = $this->parseArguments(); + if (\count($args) < 2) { + throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); + } + + return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line); + default: + if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { + $arguments = new ArrayExpression([], $line); + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + + $node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line); + $node->setAttribute('safe', true); + + return $node; + } + + $args = $this->parseArguments(true); + $class = $this->getFunctionNodeClass($name, $line); + + return new $class($name, $args, $line); + } + } + + public function parseSubscriptExpression($node) + { + $stream = $this->parser->getStream(); + $token = $stream->next(); + $lineno = $token->getLine(); + $arguments = new ArrayExpression([], $lineno); + $type = Template::ANY_CALL; + if ('.' == $token->getValue()) { + $token = $stream->next(); + if ( + /* Token::NAME_TYPE */ 5 == $token->getType() + || + /* Token::NUMBER_TYPE */ 6 == $token->getType() + || + (/* Token::OPERATOR_TYPE */ 8 == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue())) + ) { + $arg = new ConstantExpression($token->getValue(), $lineno); + + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $type = Template::METHOD_CALL; + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + } + } else { + throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext()); + } + + if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { + if (!$arg instanceof ConstantExpression) { + throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); + } + + $name = $arg->getAttribute('value'); + + $node = new MethodCallExpression($node, 'macro_'.$name, $arguments, $lineno); + $node->setAttribute('safe', true); + + return $node; + } + } else { + $type = Template::ARRAY_CALL; + + // slice? + $slice = false; + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $slice = true; + $arg = new ConstantExpression(0, $token->getLine()); + } else { + $arg = $this->parseExpression(); + } + + if ($stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { + $slice = true; + } + + if ($slice) { + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, ']')) { + $length = new ConstantExpression(null, $token->getLine()); + } else { + $length = $this->parseExpression(); + } + + $class = $this->getFilterNodeClass('slice', $token->getLine()); + $arguments = new Node([$arg, $length]); + $filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine()); + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']'); + + return $filter; + } + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']'); + } + + return new GetAttrExpression($node, $arg, $arguments, $type, $lineno); + } + + public function parseFilterExpression($node) + { + $this->parser->getStream()->next(); + + return $this->parseFilterExpressionRaw($node); + } + + public function parseFilterExpressionRaw($node, $tag = null) + { + while (true) { + $token = $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5); + + $name = new ConstantExpression($token->getValue(), $token->getLine()); + if (!$this->parser->getStream()->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $arguments = new Node(); + } else { + $arguments = $this->parseArguments(true, false, true); + } + + $class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine()); + + $node = new $class($node, $name, $arguments, $token->getLine(), $tag); + + if (!$this->parser->getStream()->test(/* Token::PUNCTUATION_TYPE */ 9, '|')) { + break; + } + + $this->parser->getStream()->next(); + } + + return $node; + } + + /** + * Parses arguments. + * + * @param bool $namedArguments Whether to allow named arguments or not + * @param bool $definition Whether we are parsing arguments for a function definition + * + * @return Node + * + * @throws SyntaxError + */ + public function parseArguments($namedArguments = false, $definition = false, $allowArrow = false) + { + $args = []; + $stream = $this->parser->getStream(); + + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, '(', 'A list of arguments must begin with an opening parenthesis'); + while (!$stream->test(/* Token::PUNCTUATION_TYPE */ 9, ')')) { + if (!empty($args)) { + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ',', 'Arguments must be separated by a comma'); + } + + if ($definition) { + $token = $stream->expect(/* Token::NAME_TYPE */ 5, null, 'An argument must be a name'); + $value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine()); + } else { + $value = $this->parseExpression(0, $allowArrow); + } + + $name = null; + if ($namedArguments && $token = $stream->nextIf(/* Token::OPERATOR_TYPE */ 8, '=')) { + if (!$value instanceof NameExpression) { + throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); + } + $name = $value->getAttribute('name'); + + if ($definition) { + $value = $this->parsePrimaryExpression(); + + if (!$this->checkConstantExpression($value)) { + 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()); + } + } else { + $value = $this->parseExpression(0, $allowArrow); + } + } + + if ($definition) { + if (null === $name) { + $name = $value->getAttribute('name'); + $value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine()); + } + $args[$name] = $value; + } else { + if (null === $name) { + $args[] = $value; + } else { + $args[$name] = $value; + } + } + } + $stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ')', 'A list of arguments must be closed by a parenthesis'); + + return new Node($args); + } + + public function parseAssignmentExpression() + { + $stream = $this->parser->getStream(); + $targets = []; + while (true) { + $token = $this->parser->getCurrentToken(); + if ($stream->test(/* Token::OPERATOR_TYPE */ 8) && preg_match(Lexer::REGEX_NAME, $token->getValue())) { + // in this context, string operators are variable names + $this->parser->getStream()->next(); + } else { + $stream->expect(/* Token::NAME_TYPE */ 5, null, 'Only variables can be assigned to'); + } + $value = $token->getValue(); + if (\in_array(strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), ['true', 'false', 'none', 'null'])) { + throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); + } + $targets[] = new AssignNameExpression($value, $token->getLine()); + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } + + return new Node($targets); + } + + public function parseMultitargetExpression() + { + $targets = []; + while (true) { + $targets[] = $this->parseExpression(); + if (!$this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } + + return new Node($targets); + } + + private function parseNotTestExpression(Node $node): NotUnary + { + return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); + } + + private function parseTestExpression(Node $node): TestExpression + { + $stream = $this->parser->getStream(); + list($name, $test) = $this->getTest($node->getTemplateLine()); + + $class = $this->getTestNodeClass($test); + $arguments = null; + if ($stream->test(/* Token::PUNCTUATION_TYPE */ 9, '(')) { + $arguments = $this->parseArguments(true); + } + + if ('defined' === $name && $node instanceof NameExpression && null !== $alias = $this->parser->getImportedSymbol('function', $node->getAttribute('name'))) { + $node = new MethodCallExpression($alias['node'], $alias['name'], new ArrayExpression([], $node->getTemplateLine()), $node->getTemplateLine()); + $node->setAttribute('safe', true); + } + + return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine()); + } + + private function getTest(int $line): array + { + $stream = $this->parser->getStream(); + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + if ($test = $this->env->getTest($name)) { + return [$name, $test]; + } + + if ($stream->test(/* Token::NAME_TYPE */ 5)) { + // try 2-words tests + $name = $name.' '.$this->parser->getCurrentToken()->getValue(); + + if ($test = $this->env->getTest($name)) { + $stream->next(); + + return [$name, $test]; + } + } + + $e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getTests())); + + throw $e; + } + + private function getTestNodeClass(TwigTest $test): string + { + if ($test->isDeprecated()) { + $stream = $this->parser->getStream(); + $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); + + if ($test->getDeprecatedVersion()) { + $message .= sprintf(' since version %s', $test->getDeprecatedVersion()); + } + if ($test->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $test->getAlternative()); + } + $src = $stream->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $stream->getCurrent()->getLine()); + + @trigger_error($message, E_USER_DEPRECATED); + } + + return $test->getNodeClass(); + } + + private function getFunctionNodeClass(string $name, int $line): string + { + if (!$function = $this->env->getFunction($name)) { + $e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getFunctions())); + + throw $e; + } + + if ($function->isDeprecated()) { + $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); + if ($function->getDeprecatedVersion()) { + $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); + } + if ($function->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $function->getAlternative()); + } + $src = $this->parser->getStream()->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + + return $function->getNodeClass(); + } + + private function getFilterNodeClass(string $name, int $line): string + { + if (!$filter = $this->env->getFilter($name)) { + $e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e->addSuggestions($name, array_keys($this->env->getFilters())); + + throw $e; + } + + if ($filter->isDeprecated()) { + $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); + if ($filter->getDeprecatedVersion()) { + $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); + } + if ($filter->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); + } + $src = $this->parser->getStream()->getSourceContext(); + $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + + return $filter->getNodeClass(); + } + + // checks that the node only contains "constant" elements + private function checkConstantExpression(Node $node): bool + { + if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression + || $node instanceof NegUnary || $node instanceof PosUnary + )) { + return false; + } + + foreach ($node as $n) { + if (!$this->checkConstantExpression($n)) { + return false; + } + } + + return true; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/AbstractExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/AbstractExtension.php new file mode 100644 index 0000000..422925f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/AbstractExtension.php @@ -0,0 +1,45 @@ +dateFormats[0] = $format; + } + + if (null !== $dateIntervalFormat) { + $this->dateFormats[1] = $dateIntervalFormat; + } + } + + /** + * Gets the default format to be used by the date filter. + * + * @return array The default date format string and the default date interval format string + */ + public function getDateFormat() + { + return $this->dateFormats; + } + + /** + * Sets the default timezone to be used by the date filter. + * + * @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object + */ + public function setTimezone($timezone) + { + $this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone); + } + + /** + * Gets the default timezone to be used by the date filter. + * + * @return \DateTimeZone The default timezone currently in use + */ + public function getTimezone() + { + if (null === $this->timezone) { + $this->timezone = new \DateTimeZone(date_default_timezone_get()); + } + + return $this->timezone; + } + + /** + * Sets the default format to be used by the number_format filter. + * + * @param int $decimal the number of decimal places to use + * @param string $decimalPoint the character(s) to use for the decimal point + * @param string $thousandSep the character(s) to use for the thousands separator + */ + public function setNumberFormat($decimal, $decimalPoint, $thousandSep) + { + $this->numberFormat = [$decimal, $decimalPoint, $thousandSep]; + } + + /** + * Get the default format used by the number_format filter. + * + * @return array The arguments for number_format() + */ + public function getNumberFormat() + { + return $this->numberFormat; + } + + public function getTokenParsers(): array + { + return [ + new ApplyTokenParser(), + new ForTokenParser(), + new IfTokenParser(), + new ExtendsTokenParser(), + new IncludeTokenParser(), + new BlockTokenParser(), + new UseTokenParser(), + new MacroTokenParser(), + new ImportTokenParser(), + new FromTokenParser(), + new SetTokenParser(), + new FlushTokenParser(), + new DoTokenParser(), + new EmbedTokenParser(), + new WithTokenParser(), + new DeprecatedTokenParser(), + ]; + } + + public function getFilters(): array + { + return [ + // formatting filters + new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), + new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), + new TwigFilter('format', 'sprintf'), + new TwigFilter('replace', 'twig_replace_filter'), + new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), + new TwigFilter('abs', 'abs'), + new TwigFilter('round', 'twig_round'), + + // encoding + new TwigFilter('url_encode', 'twig_urlencode_filter'), + new TwigFilter('json_encode', 'json_encode'), + new TwigFilter('convert_encoding', 'twig_convert_encoding'), + + // string filters + new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), + new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), + new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]), + new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]), + new TwigFilter('striptags', 'strip_tags'), + new TwigFilter('trim', 'twig_trim_filter'), + new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), + new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]), + + // array helpers + new TwigFilter('join', 'twig_join_filter'), + new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]), + new TwigFilter('sort', 'twig_sort_filter'), + new TwigFilter('merge', 'twig_array_merge'), + new TwigFilter('batch', 'twig_array_batch'), + new TwigFilter('column', 'twig_array_column'), + new TwigFilter('filter', 'twig_array_filter'), + new TwigFilter('map', 'twig_array_map'), + new TwigFilter('reduce', 'twig_array_reduce'), + + // string/array filters + new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), + new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]), + new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]), + new TwigFilter('first', 'twig_first', ['needs_environment' => true]), + new TwigFilter('last', 'twig_last', ['needs_environment' => true]), + + // iteration and runtime + new TwigFilter('default', '_twig_default_filter', ['node_class' => DefaultFilter::class]), + new TwigFilter('keys', 'twig_get_array_keys_filter'), + ]; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('max', 'max'), + new TwigFunction('min', 'min'), + new TwigFunction('range', 'range'), + new TwigFunction('constant', 'twig_constant'), + new TwigFunction('cycle', 'twig_cycle'), + new TwigFunction('random', 'twig_random', ['needs_environment' => true]), + new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]), + new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), + new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), + ]; + } + + public function getTests(): array + { + return [ + new TwigTest('even', null, ['node_class' => EvenTest::class]), + new TwigTest('odd', null, ['node_class' => OddTest::class]), + new TwigTest('defined', null, ['node_class' => DefinedTest::class]), + new TwigTest('same as', null, ['node_class' => SameasTest::class]), + new TwigTest('none', null, ['node_class' => NullTest::class]), + new TwigTest('null', null, ['node_class' => NullTest::class]), + new TwigTest('divisible by', null, ['node_class' => DivisiblebyTest::class]), + new TwigTest('constant', null, ['node_class' => ConstantTest::class]), + new TwigTest('empty', 'twig_test_empty'), + new TwigTest('iterable', 'twig_test_iterable'), + ]; + } + + public function getNodeVisitors(): array + { + return [new MacroAutoImportNodeVisitor()]; + } + + public function getOperators(): array + { + return [ + [ + 'not' => ['precedence' => 50, 'class' => NotUnary::class], + '-' => ['precedence' => 500, 'class' => NegUnary::class], + '+' => ['precedence' => 500, 'class' => PosUnary::class], + ], + [ + 'or' => ['precedence' => 10, 'class' => OrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'and' => ['precedence' => 15, 'class' => AndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-or' => ['precedence' => 16, 'class' => BitwiseOrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-xor' => ['precedence' => 17, 'class' => BitwiseXorBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-and' => ['precedence' => 18, 'class' => BitwiseAndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '==' => ['precedence' => 20, 'class' => EqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '!=' => ['precedence' => 20, 'class' => NotEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<=>' => ['precedence' => 20, 'class' => SpaceshipBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<' => ['precedence' => 20, 'class' => LessBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>' => ['precedence' => 20, 'class' => GreaterBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>=' => ['precedence' => 20, 'class' => GreaterEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<=' => ['precedence' => 20, 'class' => LessEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'not in' => ['precedence' => 20, 'class' => NotInBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'in' => ['precedence' => 20, 'class' => InBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'matches' => ['precedence' => 20, 'class' => MatchesBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'starts with' => ['precedence' => 20, 'class' => StartsWithBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'ends with' => ['precedence' => 20, 'class' => EndsWithBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '..' => ['precedence' => 25, 'class' => RangeBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '+' => ['precedence' => 30, 'class' => AddBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '-' => ['precedence' => 30, 'class' => SubBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '~' => ['precedence' => 40, 'class' => ConcatBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '*' => ['precedence' => 60, 'class' => MulBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '/' => ['precedence' => 60, 'class' => DivBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '//' => ['precedence' => 60, 'class' => FloorDivBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '%' => ['precedence' => 60, 'class' => ModBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '**' => ['precedence' => 200, 'class' => PowerBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], + '??' => ['precedence' => 300, 'class' => NullCoalesceExpression::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], + ], + ]; + } +} +} + +namespace { + use Twig\Environment; + use Twig\Error\LoaderError; + use Twig\Error\RuntimeError; + use Twig\Extension\CoreExtension; + use Twig\Extension\SandboxExtension; + use Twig\Markup; + use Twig\Source; + use Twig\Template; + + /** + * Cycles over a value. + * + * @param \ArrayAccess|array $values + * @param int $position The cycle position + * + * @return string The next value in the cycle + */ +function twig_cycle($values, $position) +{ + if (!\is_array($values) && !$values instanceof \ArrayAccess) { + return $values; + } + + return $values[$position % \count($values)]; +} + +/** + * Returns a random value depending on the supplied parameter type: + * - a random item from a \Traversable or array + * - a random character from a string + * - a random integer between 0 and the integer parameter. + * + * @param \Traversable|array|int|float|string $values The values to pick a random item from + * @param int|null $max Maximum value used when $values is an int + * + * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) + * + * @return mixed A random value from the given sequence + */ +function twig_random(Environment $env, $values = null, $max = null) +{ + if (null === $values) { + return null === $max ? mt_rand() : mt_rand(0, $max); + } + + if (\is_int($values) || \is_float($values)) { + if (null === $max) { + if ($values < 0) { + $max = 0; + $min = $values; + } else { + $max = $values; + $min = 0; + } + } else { + $min = $values; + $max = $max; + } + + return mt_rand($min, $max); + } + + if (\is_string($values)) { + if ('' === $values) { + return ''; + } + + $charset = $env->getCharset(); + + if ('UTF-8' !== $charset) { + $values = twig_convert_encoding($values, 'UTF-8', $charset); + } + + // unicode version of str_split() + // split at all positions, but not after the start and not before the end + $values = preg_split('/(? $value) { + $values[$i] = twig_convert_encoding($value, $charset, 'UTF-8'); + } + } + } + + if (!twig_test_iterable($values)) { + return $values; + } + + $values = twig_to_array($values); + + if (0 === \count($values)) { + throw new RuntimeError('The random function cannot pick from an empty array.'); + } + + return $values[array_rand($values, 1)]; +} + +/** + * Converts a date to the given format. + * + * {{ post.published_at|date("m/d/Y") }} + * + * @param \DateTimeInterface|\DateInterval|string $date A date + * @param string|null $format The target format, null to use the default + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * + * @return string The formatted date + */ +function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null) +{ + if (null === $format) { + $formats = $env->getExtension(CoreExtension::class)->getDateFormat(); + $format = $date instanceof \DateInterval ? $formats[1] : $formats[0]; + } + + if ($date instanceof \DateInterval) { + return $date->format($format); + } + + return twig_date_converter($env, $date, $timezone)->format($format); +} + +/** + * Returns a new date object modified. + * + * {{ post.published_at|date_modify("-1day")|date("m/d/Y") }} + * + * @param \DateTimeInterface|string $date A date + * @param string $modifier A modifier string + * + * @return \DateTimeInterface + */ +function twig_date_modify_filter(Environment $env, $date, $modifier) +{ + $date = twig_date_converter($env, $date, false); + + return $date->modify($modifier); +} + +/** + * Converts an input to a \DateTime instance. + * + * {% if date(user.created_at) < date('+2days') %} + * {# do something #} + * {% endif %} + * + * @param \DateTimeInterface|string|null $date A date or null to use the current time + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * + * @return \DateTimeInterface + */ +function twig_date_converter(Environment $env, $date = null, $timezone = null) +{ + // determine the timezone + if (false !== $timezone) { + if (null === $timezone) { + $timezone = $env->getExtension(CoreExtension::class)->getTimezone(); + } elseif (!$timezone instanceof \DateTimeZone) { + $timezone = new \DateTimeZone($timezone); + } + } + + // immutable dates + if ($date instanceof \DateTimeImmutable) { + return false !== $timezone ? $date->setTimezone($timezone) : $date; + } + + if ($date instanceof \DateTimeInterface) { + $date = clone $date; + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; + } + + if (null === $date || 'now' === $date) { + return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension(CoreExtension::class)->getTimezone()); + } + + $asString = (string) $date; + if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { + $date = new \DateTime('@'.$date); + } else { + $date = new \DateTime($date, $env->getExtension(CoreExtension::class)->getTimezone()); + } + + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; +} + +/** + * Replaces strings within a string. + * + * @param string $str String to replace in + * @param array|\Traversable $from Replace values + * + * @return string + */ +function twig_replace_filter($str, $from) +{ + if (!twig_test_iterable($from)) { + 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))); + } + + return strtr($str, twig_to_array($from)); +} + +/** + * Rounds a number. + * + * @param int|float $value The value to round + * @param int|float $precision The rounding precision + * @param string $method The method to use for rounding + * + * @return int|float The rounded number + */ +function twig_round($value, $precision = 0, $method = 'common') +{ + if ('common' == $method) { + return round($value, $precision); + } + + if ('ceil' != $method && 'floor' != $method) { + throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); + } + + return $method($value * pow(10, $precision)) / pow(10, $precision); +} + +/** + * Number format filter. + * + * All of the formatting options can be left null, in that case the defaults will + * be used. Supplying any of the parameters will override the defaults set in the + * environment object. + * + * @param mixed $number A float/int/string of the number to format + * @param int $decimal the number of decimal points to display + * @param string $decimalPoint the character(s) to use for the decimal point + * @param string $thousandSep the character(s) to use for the thousands separator + * + * @return string The formatted number + */ +function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) +{ + $defaults = $env->getExtension(CoreExtension::class)->getNumberFormat(); + if (null === $decimal) { + $decimal = $defaults[0]; + } + + if (null === $decimalPoint) { + $decimalPoint = $defaults[1]; + } + + if (null === $thousandSep) { + $thousandSep = $defaults[2]; + } + + return number_format((float) $number, $decimal, $decimalPoint, $thousandSep); +} + +/** + * URL encodes (RFC 3986) a string as a path segment or an array as a query string. + * + * @param string|array $url A URL or an array of query parameters + * + * @return string The URL encoded value + */ +function twig_urlencode_filter($url) +{ + if (\is_array($url)) { + return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + } + + return rawurlencode($url); +} + +/** + * Merges an array with another one. + * + * {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %} + * + * {% set items = items|merge({ 'peugeot': 'car' }) %} + * + * {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #} + * + * @param array|\Traversable $arr1 An array + * @param array|\Traversable $arr2 An array + * + * @return array The merged array + */ +function twig_array_merge($arr1, $arr2) +{ + if (!twig_test_iterable($arr1)) { + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); + } + + if (!twig_test_iterable($arr2)) { + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); + } + + return array_merge(twig_to_array($arr1), twig_to_array($arr2)); +} + +/** + * Slices a variable. + * + * @param mixed $item A variable + * @param int $start Start of the slice + * @param int $length Size of the slice + * @param bool $preserveKeys Whether to preserve key or not (when the input is an array) + * + * @return mixed The sliced variable + */ +function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false) +{ + if ($item instanceof \Traversable) { + while ($item instanceof \IteratorAggregate) { + $item = $item->getIterator(); + } + + if ($start >= 0 && $length >= 0 && $item instanceof \Iterator) { + try { + return iterator_to_array(new \LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys); + } catch (\OutOfBoundsException $e) { + return []; + } + } + + $item = iterator_to_array($item, $preserveKeys); + } + + if (\is_array($item)) { + return \array_slice($item, $start, $length, $preserveKeys); + } + + $item = (string) $item; + + return (string) mb_substr($item, $start, $length, $env->getCharset()); +} + +/** + * Returns the first element of the item. + * + * @param mixed $item A variable + * + * @return mixed The first element of the item + */ +function twig_first(Environment $env, $item) +{ + $elements = twig_slice($env, $item, 0, 1, false); + + return \is_string($elements) ? $elements : current($elements); +} + +/** + * Returns the last element of the item. + * + * @param mixed $item A variable + * + * @return mixed The last element of the item + */ +function twig_last(Environment $env, $item) +{ + $elements = twig_slice($env, $item, -1, 1, false); + + return \is_string($elements) ? $elements : current($elements); +} + +/** + * Joins the values to a string. + * + * The separators between elements are empty strings per default, you can define them with the optional parameters. + * + * {{ [1, 2, 3]|join(', ', ' and ') }} + * {# returns 1, 2 and 3 #} + * + * {{ [1, 2, 3]|join('|') }} + * {# returns 1|2|3 #} + * + * {{ [1, 2, 3]|join }} + * {# returns 123 #} + * + * @param array $value An array + * @param string $glue The separator + * @param string|null $and The separator for the last pair + * + * @return string The concatenated string + */ +function twig_join_filter($value, $glue = '', $and = null) +{ + if (!twig_test_iterable($value)) { + $value = (array) $value; + } + + $value = twig_to_array($value, false); + + if (0 === \count($value)) { + return ''; + } + + if (null === $and || $and === $glue) { + return implode($glue, $value); + } + + if (1 === \count($value)) { + return $value[0]; + } + + return implode($glue, \array_slice($value, 0, -1)).$and.$value[\count($value) - 1]; +} + +/** + * Splits the string into an array. + * + * {{ "one,two,three"|split(',') }} + * {# returns [one, two, three] #} + * + * {{ "one,two,three,four,five"|split(',', 3) }} + * {# returns [one, two, "three,four,five"] #} + * + * {{ "123"|split('') }} + * {# returns [1, 2, 3] #} + * + * {{ "aabbcc"|split('', 2) }} + * {# returns [aa, bb, cc] #} + * + * @param string $value A string + * @param string $delimiter The delimiter + * @param int $limit The limit + * + * @return array The split string as an array + */ +function twig_split_filter(Environment $env, $value, $delimiter, $limit = null) +{ + if (\strlen($delimiter) > 0) { + return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); + } + + if ($limit <= 1) { + return preg_split('/(?getCharset()); + if ($length < $limit) { + return [$value]; + } + + $r = []; + for ($i = 0; $i < $length; $i += $limit) { + $r[] = mb_substr($value, $i, $limit, $env->getCharset()); + } + + return $r; +} + +// The '_default' filter is used internally to avoid using the ternary operator +// which costs a lot for big contexts (before PHP 5.4). So, on average, +// a function call is cheaper. +/** + * @internal + */ +function _twig_default_filter($value, $default = '') +{ + if (twig_test_empty($value)) { + return $default; + } + + return $value; +} + +/** + * Returns the keys for the given array. + * + * It is useful when you want to iterate over the keys of an array: + * + * {% for key in array|keys %} + * {# ... #} + * {% endfor %} + * + * @param array $array An array + * + * @return array The keys + */ +function twig_get_array_keys_filter($array) +{ + if ($array instanceof \Traversable) { + while ($array instanceof \IteratorAggregate) { + $array = $array->getIterator(); + } + + if ($array instanceof \Iterator) { + $keys = []; + $array->rewind(); + while ($array->valid()) { + $keys[] = $array->key(); + $array->next(); + } + + return $keys; + } + + $keys = []; + foreach ($array as $key => $item) { + $keys[] = $key; + } + + return $keys; + } + + if (!\is_array($array)) { + return []; + } + + return array_keys($array); +} + +/** + * Reverses a variable. + * + * @param array|\Traversable|string $item An array, a \Traversable instance, or a string + * @param bool $preserveKeys Whether to preserve key or not + * + * @return mixed The reversed input + */ +function twig_reverse_filter(Environment $env, $item, $preserveKeys = false) +{ + if ($item instanceof \Traversable) { + return array_reverse(iterator_to_array($item), $preserveKeys); + } + + if (\is_array($item)) { + return array_reverse($item, $preserveKeys); + } + + $string = (string) $item; + + $charset = $env->getCharset(); + + if ('UTF-8' !== $charset) { + $item = twig_convert_encoding($string, 'UTF-8', $charset); + } + + preg_match_all('/./us', $item, $matches); + + $string = implode('', array_reverse($matches[0])); + + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, $charset, 'UTF-8'); + } + + return $string; +} + +/** + * Sorts an array. + * + * @param array|\Traversable $array + * + * @return array + */ +function twig_sort_filter($array, $arrow = null) +{ + if ($array instanceof \Traversable) { + $array = iterator_to_array($array); + } elseif (!\is_array($array)) { + throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); + } + + if (null !== $arrow) { + uasort($array, $arrow); + } else { + asort($array); + } + + return $array; +} + +/** + * @internal + */ +function twig_in_filter($value, $compare) +{ + if ($value instanceof Markup) { + $value = (string) $value; + } + if ($compare instanceof Markup) { + $compare = (string) $compare; + } + + if (\is_string($compare)) { + if (\is_string($value) || \is_int($value) || \is_float($value)) { + return '' === $value || false !== strpos($compare, (string) $value); + } + + return false; + } + + if (!is_iterable($compare)) { + return false; + } + + if (\is_object($value) || \is_resource($value)) { + if (!\is_array($compare)) { + foreach ($compare as $item) { + if ($item === $value) { + return true; + } + } + + return false; + } + + return \in_array($value, $compare, true); + } + + foreach ($compare as $item) { + if (0 === twig_compare($value, $item)) { + return true; + } + } + + return false; +} + +/** + * Compares two values using a more strict version of the PHP non-strict comparison operator. + * + * @see https://wiki.php.net/rfc/string_to_number_comparison + * @see https://wiki.php.net/rfc/trailing_whitespace_numerics + * + * @internal + */ +function twig_compare($a, $b) +{ + // int <=> string + if (\is_int($a) && \is_string($b)) { + $b = trim($b); + if (!is_numeric($b)) { + return (string) $a <=> $b; + } + if ((int) $b == $b) { + return $a <=> (int) $b; + } else { + return (float) $a <=> (float) $b; + } + } + if (\is_string($a) && \is_int($b)) { + $a = trim($a); + if (!is_numeric($a)) { + return $a <=> (string) $b; + } + if ((int) $a == $a) { + return (int) $a <=> $b; + } else { + return (float) $a <=> (float) $b; + } + } + + // float <=> string + if (\is_float($a) && \is_string($b)) { + if (is_nan($a)) { + return 1; + } + if (!is_numeric($b)) { + return (string) $a <=> $b; + } + + return (float) $a <=> $b; + } + if (\is_float($b) && \is_string($a)) { + if (is_nan($b)) { + return 1; + } + if (!is_numeric($a)) { + return $a <=> (string) $b; + } + + return (float) $a <=> $b; + } + + // fallback to <=> + return $a <=> $b; +} + +/** + * Returns a trimmed string. + * + * @return string + * + * @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') + */ +function twig_trim_filter($string, $characterMask = null, $side = 'both') +{ + if (null === $characterMask) { + $characterMask = " \t\n\r\0\x0B"; + } + + switch ($side) { + case 'both': + return trim($string, $characterMask); + case 'left': + return ltrim($string, $characterMask); + case 'right': + return rtrim($string, $characterMask); + default: + throw new RuntimeError('Trimming side must be "left", "right" or "both".'); + } +} + +/** + * Removes whitespaces between HTML tags. + * + * @return string + */ +function twig_spaceless($content) +{ + return trim(preg_replace('/>\s+<', $content)); +} + +function twig_convert_encoding($string, $to, $from) +{ + if (!function_exists('iconv')) { + throw new RuntimeError('Unable to convert encoding: required function iconv() does not exist. You should install ext-iconv or symfony/polyfill-iconv.'); + } + + return iconv($from, $to, $string); +} + +/** + * Returns the length of a variable. + * + * @param mixed $thing A variable + * + * @return int The length of the value + */ +function twig_length_filter(Environment $env, $thing) +{ + if (null === $thing) { + return 0; + } + + if (is_scalar($thing)) { + return mb_strlen($thing, $env->getCharset()); + } + + if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) { + return \count($thing); + } + + if ($thing instanceof \Traversable) { + return iterator_count($thing); + } + + if (method_exists($thing, '__toString') && !$thing instanceof \Countable) { + return mb_strlen((string) $thing, $env->getCharset()); + } + + return 1; +} + +/** + * Converts a string to uppercase. + * + * @param string $string A string + * + * @return string The uppercased string + */ +function twig_upper_filter(Environment $env, $string) +{ + return mb_strtoupper($string, $env->getCharset()); +} + +/** + * Converts a string to lowercase. + * + * @param string $string A string + * + * @return string The lowercased string + */ +function twig_lower_filter(Environment $env, $string) +{ + return mb_strtolower($string, $env->getCharset()); +} + +/** + * Returns a titlecased string. + * + * @param string $string A string + * + * @return string The titlecased string + */ +function twig_title_string_filter(Environment $env, $string) +{ + if (null !== $charset = $env->getCharset()) { + return mb_convert_case($string, MB_CASE_TITLE, $charset); + } + + return ucwords(strtolower($string)); +} + +/** + * Returns a capitalized string. + * + * @param string $string A string + * + * @return string The capitalized string + */ +function twig_capitalize_string_filter(Environment $env, $string) +{ + $charset = $env->getCharset(); + + return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, null, $charset), $charset); +} + +/** + * @internal + */ +function twig_call_macro(Template $template, string $method, array $args, int $lineno, array $context, Source $source) +{ + if (!method_exists($template, $method)) { + $parent = $template; + while ($parent = $parent->getParent($context)) { + if (method_exists($parent, $method)) { + return $parent->$method(...$args); + } + } + + throw new RuntimeError(sprintf('Macro "%s" is not defined in template "%s".', substr($method, \strlen('macro_')), $template->getTemplateName()), $lineno, $source); + } + + return $template->$method(...$args); +} + +/** + * @internal + */ +function twig_ensure_traversable($seq) +{ + if ($seq instanceof \Traversable || \is_array($seq)) { + return $seq; + } + + return []; +} + +/** + * @internal + */ +function twig_to_array($seq, $preserveKeys = true) +{ + if ($seq instanceof \Traversable) { + return iterator_to_array($seq, $preserveKeys); + } + + if (!\is_array($seq)) { + return $seq; + } + + return $preserveKeys ? $seq : array_values($seq); +} + +/** + * Checks if a variable is empty. + * + * {# evaluates to true if the foo variable is null, false, or the empty string #} + * {% if foo is empty %} + * {# ... #} + * {% endif %} + * + * @param mixed $value A variable + * + * @return bool true if the value is empty, false otherwise + */ +function twig_test_empty($value) +{ + if ($value instanceof \Countable) { + return 0 == \count($value); + } + + if ($value instanceof \Traversable) { + return !iterator_count($value); + } + + if (\is_object($value) && method_exists($value, '__toString')) { + return '' === (string) $value; + } + + return '' === $value || false === $value || null === $value || [] === $value; +} + +/** + * Checks if a variable is traversable. + * + * {# evaluates to true if the foo variable is an array or a traversable object #} + * {% if foo is iterable %} + * {# ... #} + * {% endif %} + * + * @param mixed $value A variable + * + * @return bool true if the value is traversable + */ +function twig_test_iterable($value) +{ + return $value instanceof \Traversable || \is_array($value); +} + +/** + * Renders a template. + * + * @param array $context + * @param string|array $template The template to render or an array of templates to try consecutively + * @param array $variables The variables to pass to the template + * @param bool $withContext + * @param bool $ignoreMissing Whether to ignore missing templates or not + * @param bool $sandboxed Whether to sandbox the template or not + * + * @return string The rendered template + */ +function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) +{ + $alreadySandboxed = false; + $sandbox = null; + if ($withContext) { + $variables = array_merge($context, $variables); + } + + if ($isSandboxed = $sandboxed && $env->hasExtension(SandboxExtension::class)) { + $sandbox = $env->getExtension(SandboxExtension::class); + if (!$alreadySandboxed = $sandbox->isSandboxed()) { + $sandbox->enableSandbox(); + } + } + + try { + $loaded = null; + try { + $loaded = $env->resolveTemplate($template); + } catch (LoaderError $e) { + if (!$ignoreMissing) { + throw $e; + } + } + + return $loaded ? $loaded->render($variables) : ''; + } finally { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + } +} + +/** + * Returns a template content without rendering it. + * + * @param string $name The template name + * @param bool $ignoreMissing Whether to ignore missing templates or not + * + * @return string The template source + */ +function twig_source(Environment $env, $name, $ignoreMissing = false) +{ + $loader = $env->getLoader(); + try { + return $loader->getSourceContext($name)->getCode(); + } catch (LoaderError $e) { + if (!$ignoreMissing) { + throw $e; + } + } +} + +/** + * Provides the ability to get constants from instances as well as class/global constants. + * + * @param string $constant The name of the constant + * @param object|null $object The object to get the constant from + * + * @return string + */ +function twig_constant($constant, $object = null) +{ + if (null !== $object) { + $constant = \get_class($object).'::'.$constant; + } + + return \constant($constant); +} + +/** + * Checks if a constant exists. + * + * @param string $constant The name of the constant + * @param object|null $object The object to get the constant from + * + * @return bool + */ +function twig_constant_is_defined($constant, $object = null) +{ + if (null !== $object) { + $constant = \get_class($object).'::'.$constant; + } + + return \defined($constant); +} + +/** + * Batches item. + * + * @param array $items An array of items + * @param int $size The size of the batch + * @param mixed $fill A value used to fill missing items + * + * @return array + */ +function twig_array_batch($items, $size, $fill = null, $preserveKeys = true) +{ + if (!twig_test_iterable($items)) { + throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); + } + + $size = ceil($size); + + $result = array_chunk(twig_to_array($items, $preserveKeys), $size, $preserveKeys); + + if (null !== $fill && $result) { + $last = \count($result) - 1; + if ($fillCount = $size - \count($result[$last])) { + for ($i = 0; $i < $fillCount; ++$i) { + $result[$last][] = $fill; + } + } + } + + return $result; +} + +/** + * Returns the attribute value for a given array/object. + * + * @param mixed $object The object or array from where to get the item + * @param mixed $item The item to get from the array or object + * @param array $arguments An array of arguments to pass if the item is an object method + * @param string $type The type of attribute (@see \Twig\Template constants) + * @param bool $isDefinedTest Whether this is only a defined check + * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not + * @param int $lineno The template line where the attribute was called + * + * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true + * + * @throws RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false + * + * @internal + */ +function twig_get_attribute(Environment $env, Source $source, $object, $item, array $arguments = [], $type = /* Template::ANY_CALL */ 'any', $isDefinedTest = false, $ignoreStrictCheck = false, $sandboxed = false, int $lineno = -1) +{ + // array + if (/* Template::METHOD_CALL */ 'method' !== $type) { + $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; + + if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object))) + || ($object instanceof ArrayAccess && isset($object[$arrayItem])) + ) { + if ($isDefinedTest) { + return true; + } + + return $object[$arrayItem]; + } + + if (/* Template::ARRAY_CALL */ 'array' === $type || !\is_object($object)) { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$env->isStrictVariables()) { + return; + } + + if ($object instanceof ArrayAccess) { + $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object)); + } elseif (\is_object($object)) { + $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object)); + } elseif (\is_array($object)) { + if (empty($object)) { + $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); + } else { + $message = sprintf('Key "%s" for array with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object))); + } + } elseif (/* Template::ARRAY_CALL */ 'array' === $type) { + if (null === $object) { + $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); + } else { + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + } elseif (null === $object) { + $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); + } else { + $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + + throw new RuntimeError($message, $lineno, $source); + } + } + + if (!\is_object($object)) { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$env->isStrictVariables()) { + return; + } + + if (null === $object) { + $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); + } elseif (\is_array($object)) { + $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); + } else { + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); + } + + throw new RuntimeError($message, $lineno, $source); + } + + if ($object instanceof Template) { + throw new RuntimeError('Accessing \Twig\Template attributes is forbidden.', $lineno, $source); + } + + // object property + if (/* Template::METHOD_CALL */ 'method' !== $type) { + if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) { + if ($isDefinedTest) { + return true; + } + + if ($sandboxed) { + $env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $item, $lineno, $source); + } + + return $object->$item; + } + } + + static $cache = []; + + $class = \get_class($object); + + // object method + // precedence: getXxx() > isXxx() > hasXxx() + if (!isset($cache[$class])) { + $methods = get_class_methods($object); + sort($methods); + $lcMethods = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, $methods); + $classCache = []; + foreach ($methods as $i => $method) { + $classCache[$method] = $method; + $classCache[$lcName = $lcMethods[$i]] = $method; + + if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) { + $name = substr($method, 3); + $lcName = substr($lcName, 3); + } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) { + $name = substr($method, 2); + $lcName = substr($lcName, 2); + } elseif ('h' === $lcName[0] && 0 === strpos($lcName, 'has')) { + $name = substr($method, 3); + $lcName = substr($lcName, 3); + if (\in_array('is'.$lcName, $lcMethods)) { + continue; + } + } else { + continue; + } + + // skip get() and is() methods (in which case, $name is empty) + if ($name) { + if (!isset($classCache[$name])) { + $classCache[$name] = $method; + } + + if (!isset($classCache[$lcName])) { + $classCache[$lcName] = $method; + } + } + } + $cache[$class] = $classCache; + } + + $call = false; + if (isset($cache[$class][$item])) { + $method = $cache[$class][$item]; + } elseif (isset($cache[$class][$lcItem = strtr($item, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')])) { + $method = $cache[$class][$lcItem]; + } elseif (isset($cache[$class]['__call'])) { + $method = $item; + $call = true; + } else { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$env->isStrictVariables()) { + return; + } + + throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()"/"has%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), $lineno, $source); + } + + if ($isDefinedTest) { + return true; + } + + if ($sandboxed) { + $env->getExtension(SandboxExtension::class)->checkMethodAllowed($object, $method, $lineno, $source); + } + + // Some objects throw exceptions when they have __call, and the method we try + // to call is not supported. If ignoreStrictCheck is true, we should return null. + try { + $ret = $object->$method(...$arguments); + } catch (\BadMethodCallException $e) { + if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) { + return; + } + throw $e; + } + + return $ret; +} + +/** + * Returns the values from a single column in the input array. + * + *
    + *  {% set items = [{ 'fruit' : 'apple'}, {'fruit' : 'orange' }] %}
    + *
    + *  {% set fruits = items|column('fruit') %}
    + *
    + *  {# fruits now contains ['apple', 'orange'] #}
    + * 
    + * + * @param array|Traversable $array An array + * @param mixed $name The column name + * @param mixed $index The column to use as the index/keys for the returned array + * + * @return array The array of values + */ +function twig_array_column($array, $name, $index = null): array +{ + if ($array instanceof Traversable) { + $array = iterator_to_array($array); + } elseif (!\is_array($array)) { + throw new RuntimeError(sprintf('The column filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($array))); + } + + return array_column($array, $name, $index); +} + +function twig_array_filter($array, $arrow) +{ + if (\is_array($array)) { + return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH); + } + + // the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator + return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow); +} + +function twig_array_map($array, $arrow) +{ + $r = []; + foreach ($array as $k => $v) { + $r[$k] = $arrow($v, $k); + } + + return $r; +} + +function twig_array_reduce($array, $arrow, $initial = null) +{ + if (!\is_array($array)) { + $array = iterator_to_array($array); + } + + return array_reduce($array, $arrow, $initial); +} +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/DebugExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/DebugExtension.php new file mode 100644 index 0000000..bfb23d7 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/DebugExtension.php @@ -0,0 +1,64 @@ + $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]), + ]; + } +} +} + +namespace { +use Twig\Environment; +use Twig\Template; +use Twig\TemplateWrapper; + +function twig_var_dump(Environment $env, $context, ...$vars) +{ + if (!$env->isDebug()) { + return; + } + + ob_start(); + + if (!$vars) { + $vars = []; + foreach ($context as $key => $value) { + if (!$value instanceof Template && !$value instanceof TemplateWrapper) { + $vars[$key] = $value; + } + } + + var_dump($vars); + } else { + var_dump(...$vars); + } + + return ob_get_clean(); +} +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/EscaperExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/EscaperExtension.php new file mode 100644 index 0000000..015c904 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/EscaperExtension.php @@ -0,0 +1,418 @@ +setDefaultStrategy($defaultStrategy); + } + + public function getTokenParsers(): array + { + return [new AutoEscapeTokenParser()]; + } + + public function getNodeVisitors(): array + { + return [new EscaperNodeVisitor()]; + } + + public function getFilters(): array + { + return [ + new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), + ]; + } + + /** + * Sets the default strategy to use when not defined by the user. + * + * The strategy can be a valid PHP callback that takes the template + * name as an argument and returns the strategy to use. + * + * @param string|false|callable $defaultStrategy An escaping strategy + */ + public function setDefaultStrategy($defaultStrategy): void + { + if ('name' === $defaultStrategy) { + $defaultStrategy = [FileExtensionEscapingStrategy::class, 'guess']; + } + + $this->defaultStrategy = $defaultStrategy; + } + + /** + * Gets the default strategy to use when not defined by the user. + * + * @param string $name The template name + * + * @return string|false The default strategy to use for the template + */ + public function getDefaultStrategy(string $name) + { + // disable string callables to avoid calling a function named html or js, + // or any other upcoming escaping strategy + if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { + return \call_user_func($this->defaultStrategy, $name); + } + + return $this->defaultStrategy; + } + + /** + * Defines a new escaper to be used via the escape filter. + * + * @param string $strategy The strategy name that should be used as a strategy in the escape call + * @param callable $callable A valid PHP callable + */ + public function setEscaper($strategy, callable $callable) + { + $this->escapers[$strategy] = $callable; + } + + /** + * Gets all defined escapers. + * + * @return callable[] An array of escapers + */ + public function getEscapers() + { + return $this->escapers; + } + + public function setSafeClasses(array $safeClasses = []) + { + $this->safeClasses = []; + $this->safeLookup = []; + foreach ($safeClasses as $class => $strategies) { + $this->addSafeClass($class, $strategies); + } + } + + public function addSafeClass(string $class, array $strategies) + { + $class = ltrim($class, '\\'); + if (!isset($this->safeClasses[$class])) { + $this->safeClasses[$class] = []; + } + $this->safeClasses[$class] = array_merge($this->safeClasses[$class], $strategies); + + foreach ($strategies as $strategy) { + $this->safeLookup[$strategy][$class] = true; + } + } +} +} + +namespace { +use Twig\Environment; +use Twig\Error\RuntimeError; +use Twig\Extension\EscaperExtension; +use Twig\Markup; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; + +/** + * Marks a variable as being safe. + * + * @param string $string A PHP variable + */ +function twig_raw_filter($string) +{ + return $string; +} + +/** + * Escapes a string. + * + * @param mixed $string The value to be escaped + * @param string $strategy The escaping strategy + * @param string $charset The charset + * @param bool $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false) + * + * @return string + */ +function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) +{ + if ($autoescape && $string instanceof Markup) { + return $string; + } + + if (!\is_string($string)) { + if (\is_object($string) && method_exists($string, '__toString')) { + if ($autoescape) { + $c = \get_class($string); + $ext = $env->getExtension(EscaperExtension::class); + if (!isset($ext->safeClasses[$c])) { + $ext->safeClasses[$c] = []; + foreach (class_parents($string) + class_implements($string) as $class) { + if (isset($ext->safeClasses[$class])) { + $ext->safeClasses[$c] = array_unique(array_merge($ext->safeClasses[$c], $ext->safeClasses[$class])); + foreach ($ext->safeClasses[$class] as $s) { + $ext->safeLookup[$s][$c] = true; + } + } + } + } + if (isset($ext->safeLookup[$strategy][$c]) || isset($ext->safeLookup['all'][$c])) { + return (string) $string; + } + } + + $string = (string) $string; + } elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { + return $string; + } + } + + if ('' === $string) { + return ''; + } + + if (null === $charset) { + $charset = $env->getCharset(); + } + + switch ($strategy) { + case 'html': + // see https://secure.php.net/htmlspecialchars + + // Using a static variable to avoid initializing the array + // each time the function is called. Moving the declaration on the + // top of the function slow downs other escaping strategies. + static $htmlspecialcharsCharsets = [ + 'ISO-8859-1' => true, 'ISO8859-1' => true, + 'ISO-8859-15' => true, 'ISO8859-15' => true, + 'utf-8' => true, 'UTF-8' => true, + 'CP866' => true, 'IBM866' => true, '866' => true, + 'CP1251' => true, 'WINDOWS-1251' => true, 'WIN-1251' => true, + '1251' => true, + 'CP1252' => true, 'WINDOWS-1252' => true, '1252' => true, + 'KOI8-R' => true, 'KOI8-RU' => true, 'KOI8R' => true, + 'BIG5' => true, '950' => true, + 'GB2312' => true, '936' => true, + 'BIG5-HKSCS' => true, + 'SHIFT_JIS' => true, 'SJIS' => true, '932' => true, + 'EUC-JP' => true, 'EUCJP' => true, + 'ISO8859-5' => true, 'ISO-8859-5' => true, 'MACROMAN' => true, + ]; + + if (isset($htmlspecialcharsCharsets[$charset])) { + return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + } + + if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { + // cache the lowercase variant for future iterations + $htmlspecialcharsCharsets[$charset] = true; + + return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + } + + $string = twig_convert_encoding($string, 'UTF-8', $charset); + $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); + + return iconv('UTF-8', $charset, $string); + + case 'js': + // escape all non-alphanumeric characters + // into their \x or \uHHHH representations + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', function ($matches) { + $char = $matches[0]; + + /* + * A few characters have short escape sequences in JSON and JavaScript. + * Escape sequences supported only by JavaScript, not JSON, are ommitted. + * \" is also supported but omitted, because the resulting string is not HTML safe. + */ + static $shortMap = [ + '\\' => '\\\\', + '/' => '\\/', + "\x08" => '\b', + "\x0C" => '\f', + "\x0A" => '\n', + "\x0D" => '\r', + "\x09" => '\t', + ]; + + if (isset($shortMap[$char])) { + return $shortMap[$char]; + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + $char = strtoupper(bin2hex($char)); + + if (4 >= \strlen($char)) { + return sprintf('\u%04s', $char); + } + + return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4)); + }, $string); + + if ('UTF-8' !== $charset) { + $string = iconv('UTF-8', $charset, $string); + } + + return $string; + + case 'css': + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', function ($matches) { + $char = $matches[0]; + + return sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : mb_ord($char, 'UTF-8')); + }, $string); + + if ('UTF-8' !== $charset) { + $string = iconv('UTF-8', $charset, $string); + } + + return $string; + + case 'html_attr': + if ('UTF-8' !== $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (!preg_match('//u', $string)) { + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); + } + + $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', function ($matches) { + /** + * This function is adapted from code coming from Zend Framework. + * + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (https://www.zend.com) + * @license https://framework.zend.com/license/new-bsd New BSD License + */ + $chr = $matches[0]; + $ord = \ord($chr); + + /* + * The following replaces characters undefined in HTML with the + * hex entity for the Unicode replacement character. + */ + if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) { + return '�'; + } + + /* + * Check if the current character to escape has a name entity we should + * replace it with while grabbing the hex value of the character. + */ + if (1 === \strlen($chr)) { + /* + * While HTML supports far more named entities, the lowest common denominator + * has become HTML5's XML Serialisation which is restricted to the those named + * entities that XML supports. Using HTML entities would result in this error: + * XML Parsing Error: undefined entity + */ + static $entityMap = [ + 34 => '"', /* quotation mark */ + 38 => '&', /* ampersand */ + 60 => '<', /* less-than sign */ + 62 => '>', /* greater-than sign */ + ]; + + if (isset($entityMap[$ord])) { + return $entityMap[$ord]; + } + + return sprintf('&#x%02X;', $ord); + } + + /* + * Per OWASP recommendations, we'll use hex entities for any other + * characters where a named entity does not exist. + */ + return sprintf('&#x%04X;', mb_ord($chr, 'UTF-8')); + }, $string); + + if ('UTF-8' !== $charset) { + $string = iconv('UTF-8', $charset, $string); + } + + return $string; + + case 'url': + return rawurlencode($string); + + default: + static $escapers; + + if (null === $escapers) { + $escapers = $env->getExtension(EscaperExtension::class)->getEscapers(); + } + + if (isset($escapers[$strategy])) { + return $escapers[$strategy]($env, $string, $charset); + } + + $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); + + throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); + } +} + +/** + * @internal + */ +function twig_escape_filter_is_safe(Node $filterArgs) +{ + foreach ($filterArgs as $arg) { + if ($arg instanceof ConstantExpression) { + return [$arg->getAttribute('value')]; + } + + return []; + } + + return ['html']; +} +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ExtensionInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ExtensionInterface.php new file mode 100644 index 0000000..75fa237 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ExtensionInterface.php @@ -0,0 +1,68 @@ + + */ +interface ExtensionInterface +{ + /** + * Returns the token parser instances to add to the existing list. + * + * @return TokenParserInterface[] + */ + public function getTokenParsers(); + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return NodeVisitorInterface[] + */ + public function getNodeVisitors(); + + /** + * Returns a list of filters to add to the existing list. + * + * @return TwigFilter[] + */ + public function getFilters(); + + /** + * Returns a list of tests to add to the existing list. + * + * @return TwigTest[] + */ + public function getTests(); + + /** + * Returns a list of functions to add to the existing list. + * + * @return TwigFunction[] + */ + public function getFunctions(); + + /** + * Returns a list of operators to add to the existing list. + * + * @return array First array of unary operators, second array of binary operators + */ + public function getOperators(); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/GlobalsInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/GlobalsInterface.php new file mode 100644 index 0000000..ec0c682 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/GlobalsInterface.php @@ -0,0 +1,25 @@ + + */ +interface GlobalsInterface +{ + public function getGlobals(): array; +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/OptimizerExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/OptimizerExtension.php new file mode 100644 index 0000000..965bfdb --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/OptimizerExtension.php @@ -0,0 +1,29 @@ +optimizers = $optimizers; + } + + public function getNodeVisitors(): array + { + return [new OptimizerNodeVisitor($this->optimizers)]; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ProfilerExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ProfilerExtension.php new file mode 100644 index 0000000..d8125b2 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/ProfilerExtension.php @@ -0,0 +1,52 @@ +actives[] = $profile; + } + + /** + * @return void + */ + public function enter(Profile $profile) + { + $this->actives[0]->addProfile($profile); + array_unshift($this->actives, $profile); + } + + /** + * @return void + */ + public function leave(Profile $profile) + { + $profile->leave(); + array_shift($this->actives); + + if (1 === \count($this->actives)) { + $this->actives[0]->leave(); + } + } + + public function getNodeVisitors(): array + { + return [new ProfilerNodeVisitor(\get_class($this))]; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/RuntimeExtensionInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/RuntimeExtensionInterface.php new file mode 100644 index 0000000..63bc3b1 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/RuntimeExtensionInterface.php @@ -0,0 +1,19 @@ + + */ +interface RuntimeExtensionInterface +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/SandboxExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/SandboxExtension.php new file mode 100644 index 0000000..0a28cab --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/SandboxExtension.php @@ -0,0 +1,123 @@ +policy = $policy; + $this->sandboxedGlobally = $sandboxed; + } + + public function getTokenParsers(): array + { + return [new SandboxTokenParser()]; + } + + public function getNodeVisitors(): array + { + return [new SandboxNodeVisitor()]; + } + + public function enableSandbox(): void + { + $this->sandboxed = true; + } + + public function disableSandbox(): void + { + $this->sandboxed = false; + } + + public function isSandboxed(): bool + { + return $this->sandboxedGlobally || $this->sandboxed; + } + + public function isSandboxedGlobally(): bool + { + return $this->sandboxedGlobally; + } + + public function setSecurityPolicy(SecurityPolicyInterface $policy) + { + $this->policy = $policy; + } + + public function getSecurityPolicy(): SecurityPolicyInterface + { + return $this->policy; + } + + public function checkSecurity($tags, $filters, $functions): void + { + if ($this->isSandboxed()) { + $this->policy->checkSecurity($tags, $filters, $functions); + } + } + + public function checkMethodAllowed($obj, $method, int $lineno = -1, Source $source = null): void + { + if ($this->isSandboxed()) { + try { + $this->policy->checkMethodAllowed($obj, $method); + } catch (SecurityNotAllowedMethodError $e) { + $e->setSourceContext($source); + $e->setTemplateLine($lineno); + + throw $e; + } + } + } + + public function checkPropertyAllowed($obj, $method, int $lineno = -1, Source $source = null): void + { + if ($this->isSandboxed()) { + try { + $this->policy->checkPropertyAllowed($obj, $method); + } catch (SecurityNotAllowedPropertyError $e) { + $e->setSourceContext($source); + $e->setTemplateLine($lineno); + + throw $e; + } + } + } + + public function ensureToStringAllowed($obj, int $lineno = -1, Source $source = null) + { + if ($this->isSandboxed() && \is_object($obj) && method_exists($obj, '__toString')) { + try { + $this->policy->checkMethodAllowed($obj, '__toString'); + } catch (SecurityNotAllowedMethodError $e) { + $e->setSourceContext($source); + $e->setTemplateLine($lineno); + + throw $e; + } + } + + return $obj; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StagingExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StagingExtension.php new file mode 100644 index 0000000..0ea47f9 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StagingExtension.php @@ -0,0 +1,100 @@ + + * + * @internal + */ +final class StagingExtension extends AbstractExtension +{ + private $functions = []; + private $filters = []; + private $visitors = []; + private $tokenParsers = []; + private $tests = []; + + public function addFunction(TwigFunction $function): void + { + if (isset($this->functions[$function->getName()])) { + throw new \LogicException(sprintf('Function "%s" is already registered.', $function->getName())); + } + + $this->functions[$function->getName()] = $function; + } + + public function getFunctions(): array + { + return $this->functions; + } + + public function addFilter(TwigFilter $filter): void + { + if (isset($this->filters[$filter->getName()])) { + throw new \LogicException(sprintf('Filter "%s" is already registered.', $filter->getName())); + } + + $this->filters[$filter->getName()] = $filter; + } + + public function getFilters(): array + { + return $this->filters; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor): void + { + $this->visitors[] = $visitor; + } + + public function getNodeVisitors(): array + { + return $this->visitors; + } + + public function addTokenParser(TokenParserInterface $parser): void + { + if (isset($this->tokenParsers[$parser->getTag()])) { + throw new \LogicException(sprintf('Tag "%s" is already registered.', $parser->getTag())); + } + + $this->tokenParsers[$parser->getTag()] = $parser; + } + + public function getTokenParsers(): array + { + return $this->tokenParsers; + } + + public function addTest(TwigTest $test): void + { + if (isset($this->tests[$test->getName()])) { + throw new \LogicException(sprintf('Test "%s" is already registered.', $test->getName())); + } + + $this->tests[$test->getName()] = $test; + } + + public function getTests(): array + { + return $this->tests; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StringLoaderExtension.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StringLoaderExtension.php new file mode 100644 index 0000000..7b45147 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Extension/StringLoaderExtension.php @@ -0,0 +1,42 @@ + true]), + ]; + } +} +} + +namespace { +use Twig\Environment; +use Twig\TemplateWrapper; + +/** + * Loads a template from a string. + * + * {{ include(template_from_string("Hello {{ name }}")) }} + * + * @param string $template A template as a string or object implementing __toString() + * @param string $name An optional name of the template to be used in error messages + */ +function twig_template_from_string(Environment $env, $template, string $name = null): TemplateWrapper +{ + return $env->createTemplate((string) $template, $name); +} +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/ExtensionSet.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/ExtensionSet.php new file mode 100644 index 0000000..38b6ab8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/ExtensionSet.php @@ -0,0 +1,438 @@ + + * + * @internal + */ +final class ExtensionSet +{ + private $extensions; + private $initialized = false; + private $runtimeInitialized = false; + private $staging; + private $parsers; + private $visitors; + private $filters; + private $tests; + private $functions; + private $unaryOperators; + private $binaryOperators; + private $globals; + private $functionCallbacks = []; + private $filterCallbacks = []; + private $lastModified = 0; + + public function __construct() + { + $this->staging = new StagingExtension(); + } + + public function initRuntime() + { + $this->runtimeInitialized = true; + } + + public function hasExtension(string $class): bool + { + return isset($this->extensions[ltrim($class, '\\')]); + } + + public function getExtension(string $class): ExtensionInterface + { + $class = ltrim($class, '\\'); + + if (!isset($this->extensions[$class])) { + throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class)); + } + + return $this->extensions[$class]; + } + + /** + * @param ExtensionInterface[] $extensions + */ + public function setExtensions(array $extensions): void + { + foreach ($extensions as $extension) { + $this->addExtension($extension); + } + } + + /** + * @return ExtensionInterface[] + */ + public function getExtensions(): array + { + return $this->extensions; + } + + public function getSignature(): string + { + return json_encode(array_keys($this->extensions)); + } + + public function isInitialized(): bool + { + return $this->initialized || $this->runtimeInitialized; + } + + public function getLastModified(): int + { + if (0 !== $this->lastModified) { + return $this->lastModified; + } + + foreach ($this->extensions as $extension) { + $r = new \ReflectionObject($extension); + if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModified) { + $this->lastModified = $extensionTime; + } + } + + return $this->lastModified; + } + + public function addExtension(ExtensionInterface $extension): void + { + $class = \get_class($extension); + + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class)); + } + + if (isset($this->extensions[$class])) { + throw new \LogicException(sprintf('Unable to register extension "%s" as it is already registered.', $class)); + } + + $this->extensions[$class] = $extension; + } + + public function addFunction(TwigFunction $function): void + { + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $function->getName())); + } + + $this->staging->addFunction($function); + } + + /** + * @return TwigFunction[] + */ + public function getFunctions(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->functions; + } + + public function getFunction(string $name): ?TwigFunction + { + if (!$this->initialized) { + $this->initExtensions(); + } + + if (isset($this->functions[$name])) { + return $this->functions[$name]; + } + + foreach ($this->functions as $pattern => $function) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $function->setArguments($matches); + + return $function; + } + } + + foreach ($this->functionCallbacks as $callback) { + if (false !== $function = $callback($name)) { + return $function; + } + } + + return null; + } + + public function registerUndefinedFunctionCallback(callable $callable): void + { + $this->functionCallbacks[] = $callable; + } + + public function addFilter(TwigFilter $filter): void + { + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $filter->getName())); + } + + $this->staging->addFilter($filter); + } + + /** + * @return TwigFilter[] + */ + public function getFilters(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->filters; + } + + public function getFilter(string $name): ?TwigFilter + { + if (!$this->initialized) { + $this->initExtensions(); + } + + if (isset($this->filters[$name])) { + return $this->filters[$name]; + } + + foreach ($this->filters as $pattern => $filter) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count && preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $filter->setArguments($matches); + + return $filter; + } + } + + foreach ($this->filterCallbacks as $callback) { + if (false !== $filter = $callback($name)) { + return $filter; + } + } + + return null; + } + + public function registerUndefinedFilterCallback(callable $callable): void + { + $this->filterCallbacks[] = $callable; + } + + public function addNodeVisitor(NodeVisitorInterface $visitor): void + { + if ($this->initialized) { + throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.'); + } + + $this->staging->addNodeVisitor($visitor); + } + + /** + * @return NodeVisitorInterface[] + */ + public function getNodeVisitors(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->visitors; + } + + public function addTokenParser(TokenParserInterface $parser): void + { + if ($this->initialized) { + throw new \LogicException('Unable to add a token parser as extensions have already been initialized.'); + } + + $this->staging->addTokenParser($parser); + } + + /** + * @return TokenParserInterface[] + */ + public function getTokenParsers(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->parsers; + } + + public function getGlobals(): array + { + if (null !== $this->globals) { + return $this->globals; + } + + $globals = []; + foreach ($this->extensions as $extension) { + if (!$extension instanceof GlobalsInterface) { + continue; + } + + $extGlobals = $extension->getGlobals(); + if (!\is_array($extGlobals)) { + throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension))); + } + + $globals = array_merge($globals, $extGlobals); + } + + if ($this->initialized) { + $this->globals = $globals; + } + + return $globals; + } + + public function addTest(TwigTest $test): void + { + if ($this->initialized) { + throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $test->getName())); + } + + $this->staging->addTest($test); + } + + /** + * @return TwigTest[] + */ + public function getTests(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->tests; + } + + public function getTest(string $name): ?TwigTest + { + if (!$this->initialized) { + $this->initExtensions(); + } + + if (isset($this->tests[$name])) { + return $this->tests[$name]; + } + + foreach ($this->tests as $pattern => $test) { + $pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count); + + if ($count) { + if (preg_match('#^'.$pattern.'$#', $name, $matches)) { + array_shift($matches); + $test->setArguments($matches); + + return $test; + } + } + } + + return null; + } + + public function getUnaryOperators(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->unaryOperators; + } + + public function getBinaryOperators(): array + { + if (!$this->initialized) { + $this->initExtensions(); + } + + return $this->binaryOperators; + } + + private function initExtensions(): void + { + $this->parsers = []; + $this->filters = []; + $this->functions = []; + $this->tests = []; + $this->visitors = []; + $this->unaryOperators = []; + $this->binaryOperators = []; + + foreach ($this->extensions as $extension) { + $this->initExtension($extension); + } + $this->initExtension($this->staging); + // Done at the end only, so that an exception during initialization does not mark the environment as initialized when catching the exception + $this->initialized = true; + } + + private function initExtension(ExtensionInterface $extension): void + { + // filters + foreach ($extension->getFilters() as $filter) { + $this->filters[$filter->getName()] = $filter; + } + + // functions + foreach ($extension->getFunctions() as $function) { + $this->functions[$function->getName()] = $function; + } + + // tests + foreach ($extension->getTests() as $test) { + $this->tests[$test->getName()] = $test; + } + + // token parsers + foreach ($extension->getTokenParsers() as $parser) { + if (!$parser instanceof TokenParserInterface) { + throw new \LogicException('getTokenParsers() must return an array of \Twig\TokenParser\TokenParserInterface.'); + } + + $this->parsers[] = $parser; + } + + // node visitors + foreach ($extension->getNodeVisitors() as $visitor) { + $this->visitors[] = $visitor; + } + + // operators + if ($operators = $extension->getOperators()) { + if (!\is_array($operators)) { + 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))); + } + + if (2 !== \count($operators)) { + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators))); + } + + $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); + $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]); + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/FileExtensionEscapingStrategy.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/FileExtensionEscapingStrategy.php new file mode 100644 index 0000000..28579c3 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/FileExtensionEscapingStrategy.php @@ -0,0 +1,60 @@ + + */ +class FileExtensionEscapingStrategy +{ + /** + * Guesses the best autoescaping strategy based on the file name. + * + * @param string $name The template name + * + * @return string|false The escaping strategy name to use or false to disable + */ + public static function guess(string $name) + { + if (\in_array(substr($name, -1), ['/', '\\'])) { + return 'html'; // return html for directories + } + + if ('.twig' === substr($name, -5)) { + $name = substr($name, 0, -5); + } + + $extension = pathinfo($name, PATHINFO_EXTENSION); + + switch ($extension) { + case 'js': + return 'js'; + + case 'css': + return 'css'; + + case 'txt': + return false; + + default: + return 'html'; + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Lexer.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Lexer.php new file mode 100644 index 0000000..3cfcccf --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Lexer.php @@ -0,0 +1,497 @@ + + */ +class Lexer +{ + private $tokens; + private $code; + private $cursor; + private $lineno; + private $end; + private $state; + private $states; + private $brackets; + private $env; + private $source; + private $options; + private $regexes; + private $position; + private $positions; + private $currentVarBlockLine; + + const STATE_DATA = 0; + const STATE_BLOCK = 1; + const STATE_VAR = 2; + const STATE_STRING = 3; + const STATE_INTERPOLATION = 4; + + const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; + const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; + const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; + const REGEX_DQ_STRING_DELIM = '/"/A'; + const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; + const PUNCTUATION = '()[]{}?:.,|'; + + public function __construct(Environment $env, array $options = []) + { + $this->env = $env; + + $this->options = array_merge([ + 'tag_comment' => ['{#', '#}'], + 'tag_block' => ['{%', '%}'], + 'tag_variable' => ['{{', '}}'], + 'whitespace_trim' => '-', + 'whitespace_line_trim' => '~', + 'whitespace_line_chars' => ' \t\0\x0B', + 'interpolation' => ['#{', '}'], + ], $options); + + // when PHP 7.3 is the min version, we will be able to remove the '#' part in preg_quote as it's part of the default + $this->regexes = [ + // }} + 'lex_var' => '{ + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '#').'\s*'. // -}}\s* + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_variable'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~}}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_variable'][1], '#'). // }} + ') + }Ax', + + // %} + 'lex_block' => '{ + \s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*\n?'. // -%}\s*\n? + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#').'\n?'. // %}\n? + ') + }Ax', + + // {% endverbatim %} + 'lex_raw_data' => '{'. + preg_quote($this->options['tag_block'][0], '#'). // {% + '('. + $this->options['whitespace_trim']. // - + '|'. + $this->options['whitespace_line_trim']. // ~ + ')?\s*endverbatim\s*'. + '(?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%} + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#'). // %} + ') + }sx', + + 'operator' => $this->getOperatorRegex(), + + // #} + 'lex_comment' => '{ + (?:'. + preg_quote($this->options['whitespace_trim']).preg_quote($this->options['tag_comment'][1], '#').'\s*\n?'. // -#}\s*\n? + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_comment'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~#}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_comment'][1], '#').'\n?'. // #}\n? + ') + }sx', + + // verbatim %} + 'lex_block_raw' => '{ + \s*verbatim\s* + (?:'. + preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}\s* + '|'. + preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]* + '|'. + preg_quote($this->options['tag_block'][1], '#'). // %} + ') + }Asx', + + 'lex_block_line' => '{\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '#').'}As', + + // {{ or {% or {# + 'lex_tokens_start' => '{ + ('. + preg_quote($this->options['tag_variable'][0], '#'). // {{ + '|'. + preg_quote($this->options['tag_block'][0], '#'). // {% + '|'. + preg_quote($this->options['tag_comment'][0], '#'). // {# + ')('. + preg_quote($this->options['whitespace_trim'], '#'). // - + '|'. + preg_quote($this->options['whitespace_line_trim'], '#'). // ~ + ')? + }sx', + 'interpolation_start' => '{'.preg_quote($this->options['interpolation'][0], '#').'\s*}A', + 'interpolation_end' => '{\s*'.preg_quote($this->options['interpolation'][1], '#').'}A', + ]; + } + + public function tokenize(Source $source): TokenStream + { + $this->source = $source; + $this->code = str_replace(["\r\n", "\r"], "\n", $source->getCode()); + $this->cursor = 0; + $this->lineno = 1; + $this->end = \strlen($this->code); + $this->tokens = []; + $this->state = self::STATE_DATA; + $this->states = []; + $this->brackets = []; + $this->position = -1; + + // find all token starts in one go + preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); + $this->positions = $matches; + + while ($this->cursor < $this->end) { + // dispatch to the lexing functions depending + // on the current state + switch ($this->state) { + case self::STATE_DATA: + $this->lexData(); + break; + + case self::STATE_BLOCK: + $this->lexBlock(); + break; + + case self::STATE_VAR: + $this->lexVar(); + break; + + case self::STATE_STRING: + $this->lexString(); + break; + + case self::STATE_INTERPOLATION: + $this->lexInterpolation(); + break; + } + } + + $this->pushToken(/* Token::EOF_TYPE */ -1); + + if (!empty($this->brackets)) { + list($expect, $lineno) = array_pop($this->brackets); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + + return new TokenStream($this->tokens, $this->source); + } + + private function lexData(): void + { + // if no matches are left we return the rest of the template as simple text token + if ($this->position == \count($this->positions[0]) - 1) { + $this->pushToken(/* Token::TEXT_TYPE */ 0, substr($this->code, $this->cursor)); + $this->cursor = $this->end; + + return; + } + + // Find the first token after the current cursor + $position = $this->positions[0][++$this->position]; + while ($position[1] < $this->cursor) { + if ($this->position == \count($this->positions[0]) - 1) { + return; + } + $position = $this->positions[0][++$this->position]; + } + + // push the template text first + $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor); + + // trim? + if (isset($this->positions[2][$this->position][0])) { + if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) { + // whitespace_trim detected ({%-, {{- or {#-) + $text = rtrim($text); + } elseif ($this->options['whitespace_line_trim'] === $this->positions[2][$this->position][0]) { + // whitespace_line_trim detected ({%~, {{~ or {#~) + // don't trim \r and \n + $text = rtrim($text, " \t\0\x0B"); + } + } + $this->pushToken(/* Token::TEXT_TYPE */ 0, $text); + $this->moveCursor($textContent.$position[0]); + + switch ($this->positions[1][$this->position][0]) { + case $this->options['tag_comment'][0]: + $this->lexComment(); + break; + + case $this->options['tag_block'][0]: + // raw data? + if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + $this->lexRawData(); + // {% line \d+ %} + } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + $this->lineno = (int) $match[1]; + } else { + $this->pushToken(/* Token::BLOCK_START_TYPE */ 1); + $this->pushState(self::STATE_BLOCK); + $this->currentVarBlockLine = $this->lineno; + } + break; + + case $this->options['tag_variable'][0]: + $this->pushToken(/* Token::VAR_START_TYPE */ 2); + $this->pushState(self::STATE_VAR); + $this->currentVarBlockLine = $this->lineno; + break; + } + } + + private function lexBlock(): void + { + if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::BLOCK_END_TYPE */ 3); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + private function lexVar(): void + { + if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::VAR_END_TYPE */ 4); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + private function lexExpression(): void + { + // whitespace + if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) { + $this->moveCursor($match[0]); + + if ($this->cursor >= $this->end) { + throw new SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); + } + } + + // arrow function + if ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) { + $this->pushToken(Token::ARROW_TYPE, '=>'); + $this->moveCursor('=>'); + } + // operators + elseif (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::OPERATOR_TYPE */ 8, preg_replace('/\s+/', ' ', $match[0])); + $this->moveCursor($match[0]); + } + // names + elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::NAME_TYPE */ 5, $match[0]); + $this->moveCursor($match[0]); + } + // numbers + elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) { + $number = (float) $match[0]; // floats + if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { + $number = (int) $match[0]; // integers lower than the maximum + } + $this->pushToken(/* Token::NUMBER_TYPE */ 6, $number); + $this->moveCursor($match[0]); + } + // punctuation + elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) { + // opening bracket + if (false !== strpos('([{', $this->code[$this->cursor])) { + $this->brackets[] = [$this->code[$this->cursor], $this->lineno]; + } + // closing bracket + elseif (false !== strpos(')]}', $this->code[$this->cursor])) { + if (empty($this->brackets)) { + throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + + list($expect, $lineno) = array_pop($this->brackets); + if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + } + + $this->pushToken(/* Token::PUNCTUATION_TYPE */ 9, $this->code[$this->cursor]); + ++$this->cursor; + } + // strings + elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) { + $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes(substr($match[0], 1, -1))); + $this->moveCursor($match[0]); + } + // opening double quoted string + elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { + $this->brackets[] = ['"', $this->lineno]; + $this->pushState(self::STATE_STRING); + $this->moveCursor($match[0]); + } + // unlexable + else { + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + } + + private function lexRawData(): void + { + if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new SyntaxError('Unexpected end of file: Unclosed "verbatim" block.', $this->lineno, $this->source); + } + + $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); + $this->moveCursor($text.$match[0][0]); + + // trim? + if (isset($match[1][0])) { + if ($this->options['whitespace_trim'] === $match[1][0]) { + // whitespace_trim detected ({%-, {{- or {#-) + $text = rtrim($text); + } else { + // whitespace_line_trim detected ({%~, {{~ or {#~) + // don't trim \r and \n + $text = rtrim($text, " \t\0\x0B"); + } + } + + $this->pushToken(/* Token::TEXT_TYPE */ 0, $text); + } + + private function lexComment(): void + { + if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source); + } + + $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); + } + + private function lexString(): void + { + if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) { + $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; + $this->pushToken(/* Token::INTERPOLATION_START_TYPE */ 10); + $this->moveCursor($match[0]); + $this->pushState(self::STATE_INTERPOLATION); + } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) { + $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes($match[0])); + $this->moveCursor($match[0]); + } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { + list($expect, $lineno) = array_pop($this->brackets); + if ('"' != $this->code[$this->cursor]) { + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + } + + $this->popState(); + ++$this->cursor; + } else { + // unlexable + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + } + } + + private function lexInterpolation(): void + { + $bracket = end($this->brackets); + if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) { + array_pop($this->brackets); + $this->pushToken(/* Token::INTERPOLATION_END_TYPE */ 11); + $this->moveCursor($match[0]); + $this->popState(); + } else { + $this->lexExpression(); + } + } + + private function pushToken($type, $value = ''): void + { + // do not push empty text tokens + if (/* Token::TEXT_TYPE */ 0 === $type && '' === $value) { + return; + } + + $this->tokens[] = new Token($type, $value, $this->lineno); + } + + private function moveCursor($text): void + { + $this->cursor += \strlen($text); + $this->lineno += substr_count($text, "\n"); + } + + private function getOperatorRegex(): string + { + $operators = array_merge( + ['='], + array_keys($this->env->getUnaryOperators()), + array_keys($this->env->getBinaryOperators()) + ); + + $operators = array_combine($operators, array_map('strlen', $operators)); + arsort($operators); + + $regex = []; + foreach ($operators as $operator => $length) { + // an operator that ends with a character must be followed by + // a whitespace or a parenthesis + if (ctype_alpha($operator[$length - 1])) { + $r = preg_quote($operator, '/').'(?=[\s()])'; + } else { + $r = preg_quote($operator, '/'); + } + + // an operator with a space can be any amount of whitespaces + $r = preg_replace('/\s+/', '\s+', $r); + + $regex[] = $r; + } + + return '/'.implode('|', $regex).'/A'; + } + + private function pushState($state): void + { + $this->states[] = $this->state; + $this->state = $state; + } + + private function popState(): void + { + if (0 === \count($this->states)) { + throw new \LogicException('Cannot pop state without a previous state.'); + } + + $this->state = array_pop($this->states); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ArrayLoader.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ArrayLoader.php new file mode 100644 index 0000000..a6164bb --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ArrayLoader.php @@ -0,0 +1,78 @@ + + */ +final class ArrayLoader implements LoaderInterface +{ + private $templates = []; + + /** + * @param array $templates An array of templates (keys are the names, and values are the source code) + */ + public function __construct(array $templates = []) + { + $this->templates = $templates; + } + + public function setTemplate(string $name, string $template): void + { + $this->templates[$name] = $template; + } + + public function getSourceContext(string $name): Source + { + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return new Source($this->templates[$name], $name); + } + + public function exists(string $name): bool + { + return isset($this->templates[$name]); + } + + public function getCacheKey(string $name): string + { + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return $name.':'.$this->templates[$name]; + } + + public function isFresh(string $name, int $time): bool + { + if (!isset($this->templates[$name])) { + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); + } + + return true; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ChainLoader.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ChainLoader.php new file mode 100644 index 0000000..fbf4f3a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/ChainLoader.php @@ -0,0 +1,119 @@ + + */ +final class ChainLoader implements LoaderInterface +{ + private $hasSourceCache = []; + private $loaders = []; + + /** + * @param LoaderInterface[] $loaders + */ + public function __construct(array $loaders = []) + { + foreach ($loaders as $loader) { + $this->addLoader($loader); + } + } + + public function addLoader(LoaderInterface $loader): void + { + $this->loaders[] = $loader; + $this->hasSourceCache = []; + } + + /** + * @return LoaderInterface[] + */ + public function getLoaders(): array + { + return $this->loaders; + } + + public function getSourceContext(string $name): Source + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if (!$loader->exists($name)) { + continue; + } + + try { + return $loader->getSourceContext($name); + } catch (LoaderError $e) { + $exceptions[] = $e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function exists(string $name): bool + { + if (isset($this->hasSourceCache[$name])) { + return $this->hasSourceCache[$name]; + } + + foreach ($this->loaders as $loader) { + if ($loader->exists($name)) { + return $this->hasSourceCache[$name] = true; + } + } + + return $this->hasSourceCache[$name] = false; + } + + public function getCacheKey(string $name): string + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if (!$loader->exists($name)) { + continue; + } + + try { + return $loader->getCacheKey($name); + } catch (LoaderError $e) { + $exceptions[] = \get_class($loader).': '.$e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } + + public function isFresh(string $name, int $time): bool + { + $exceptions = []; + foreach ($this->loaders as $loader) { + if (!$loader->exists($name)) { + continue; + } + + try { + return $loader->isFresh($name, $time); + } catch (LoaderError $e) { + $exceptions[] = \get_class($loader).': '.$e->getMessage(); + } + } + + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/FilesystemLoader.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/FilesystemLoader.php new file mode 100644 index 0000000..e55943d --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/FilesystemLoader.php @@ -0,0 +1,283 @@ + + */ +class FilesystemLoader implements LoaderInterface +{ + /** Identifier of the main namespace. */ + const MAIN_NAMESPACE = '__main__'; + + protected $paths = []; + protected $cache = []; + protected $errorCache = []; + + private $rootPath; + + /** + * @param string|array $paths A path or an array of paths where to look for templates + * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) + */ + public function __construct($paths = [], string $rootPath = null) + { + $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR; + if (false !== $realPath = realpath($rootPath)) { + $this->rootPath = $realPath.\DIRECTORY_SEPARATOR; + } + + if ($paths) { + $this->setPaths($paths); + } + } + + /** + * Returns the paths to the templates. + */ + public function getPaths(string $namespace = self::MAIN_NAMESPACE): array + { + return isset($this->paths[$namespace]) ? $this->paths[$namespace] : []; + } + + /** + * Returns the path namespaces. + * + * The main namespace is always defined. + */ + public function getNamespaces(): array + { + return array_keys($this->paths); + } + + /** + * @param string|array $paths A path or an array of paths where to look for templates + */ + public function setPaths($paths, string $namespace = self::MAIN_NAMESPACE): void + { + if (!\is_array($paths)) { + $paths = [$paths]; + } + + $this->paths[$namespace] = []; + foreach ($paths as $path) { + $this->addPath($path, $namespace); + } + } + + /** + * @throws LoaderError + */ + public function addPath(string $path, string $namespace = self::MAIN_NAMESPACE): void + { + // invalidate the cache + $this->cache = $this->errorCache = []; + + $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; + if (!is_dir($checkPath)) { + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + } + + $this->paths[$namespace][] = rtrim($path, '/\\'); + } + + /** + * @throws LoaderError + */ + public function prependPath(string $path, string $namespace = self::MAIN_NAMESPACE): void + { + // invalidate the cache + $this->cache = $this->errorCache = []; + + $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; + if (!is_dir($checkPath)) { + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + } + + $path = rtrim($path, '/\\'); + + if (!isset($this->paths[$namespace])) { + $this->paths[$namespace][] = $path; + } else { + array_unshift($this->paths[$namespace], $path); + } + } + + public function getSourceContext(string $name): Source + { + if (null === $path = $this->findTemplate($name)) { + return new Source('', $name, ''); + } + + return new Source(file_get_contents($path), $name, $path); + } + + public function getCacheKey(string $name): string + { + if (null === $path = $this->findTemplate($name)) { + return ''; + } + $len = \strlen($this->rootPath); + if (0 === strncmp($this->rootPath, $path, $len)) { + return substr($path, $len); + } + + return $path; + } + + /** + * @return bool + */ + public function exists(string $name) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return true; + } + + return null !== $this->findTemplate($name, false); + } + + public function isFresh(string $name, int $time): bool + { + // false support to be removed in 3.0 + if (null === $path = $this->findTemplate($name)) { + return false; + } + + return filemtime($path) < $time; + } + + /** + * @return string|null + */ + protected function findTemplate(string $name, bool $throw = true) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } + + if (isset($this->errorCache[$name])) { + if (!$throw) { + return null; + } + + throw new LoaderError($this->errorCache[$name]); + } + + try { + $this->validateName($name); + + list($namespace, $shortname) = $this->parseName($name); + } catch (LoaderError $e) { + if (!$throw) { + return null; + } + + throw $e; + } + + if (!isset($this->paths[$namespace])) { + $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace); + + if (!$throw) { + return null; + } + + throw new LoaderError($this->errorCache[$name]); + } + + foreach ($this->paths[$namespace] as $path) { + if (!$this->isAbsolutePath($path)) { + $path = $this->rootPath.$path; + } + + if (is_file($path.'/'.$shortname)) { + if (false !== $realpath = realpath($path.'/'.$shortname)) { + return $this->cache[$name] = $realpath; + } + + return $this->cache[$name] = $path.'/'.$shortname; + } + } + + $this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])); + + if (!$throw) { + return null; + } + + throw new LoaderError($this->errorCache[$name]); + } + + private function normalizeName(string $name): string + { + return preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name)); + } + + private function parseName(string $name, string $default = self::MAIN_NAMESPACE): array + { + if (isset($name[0]) && '@' == $name[0]) { + if (false === $pos = strpos($name, '/')) { + throw new LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + } + + $namespace = substr($name, 1, $pos - 1); + $shortname = substr($name, $pos + 1); + + return [$namespace, $shortname]; + } + + return [$default, $name]; + } + + private function validateName(string $name): void + { + if (false !== strpos($name, "\0")) { + throw new LoaderError('A template name cannot contain NUL bytes.'); + } + + $name = ltrim($name, '/'); + $parts = explode('/', $name); + $level = 0; + foreach ($parts as $part) { + if ('..' === $part) { + --$level; + } elseif ('.' !== $part) { + ++$level; + } + + if ($level < 0) { + throw new LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); + } + } + } + + private function isAbsolutePath(string $file): bool + { + return strspn($file, '/\\', 0, 1) + || (\strlen($file) > 3 && ctype_alpha($file[0]) + && ':' === $file[1] + && strspn($file, '/\\', 2, 1) + ) + || null !== parse_url($file, PHP_URL_SCHEME) + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/LoaderInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/LoaderInterface.php new file mode 100644 index 0000000..fec7e85 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Loader/LoaderInterface.php @@ -0,0 +1,49 @@ + + */ +interface LoaderInterface +{ + /** + * Returns the source context for a given template logical name. + * + * @throws LoaderError When $name is not found + */ + public function getSourceContext(string $name): Source; + + /** + * Gets the cache key to use for the cache for a given template name. + * + * @throws LoaderError When $name is not found + */ + public function getCacheKey(string $name): string; + + /** + * @param int $time Timestamp of the last modification time of the cached template + * + * @throws LoaderError When $name is not found + */ + public function isFresh(string $name, int $time): bool; + + /** + * @return bool + */ + public function exists(string $name); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Markup.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Markup.php new file mode 100644 index 0000000..c48268a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Markup.php @@ -0,0 +1,44 @@ + + */ +class Markup implements \Countable, \JsonSerializable +{ + private $content; + private $charset; + + public function __construct($content, $charset) + { + $this->content = (string) $content; + $this->charset = $charset; + } + + public function __toString() + { + return $this->content; + } + + public function count() + { + return mb_strlen($this->content, $this->charset); + } + + public function jsonSerialize() + { + return $this->content; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/AutoEscapeNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/AutoEscapeNode.php new file mode 100644 index 0000000..cd97041 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/AutoEscapeNode.php @@ -0,0 +1,38 @@ + + */ +class AutoEscapeNode extends Node +{ + public function __construct($value, Node $body, int $lineno, string $tag = 'autoescape') + { + parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler->subcompile($this->getNode('body')); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockNode.php new file mode 100644 index 0000000..0632ba7 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockNode.php @@ -0,0 +1,44 @@ + + */ +class BlockNode extends Node +{ + public function __construct(string $name, Node $body, int $lineno, string $tag = null) + { + parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n") + ->indent() + ->write("\$macros = \$this->macros;\n") + ; + + $compiler + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockReferenceNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockReferenceNode.php new file mode 100644 index 0000000..cc8af5b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BlockReferenceNode.php @@ -0,0 +1,36 @@ + + */ +class BlockReferenceNode extends Node implements NodeOutputInterface +{ + public function __construct(string $name, int $lineno, string $tag = null) + { + parent::__construct([], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BodyNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BodyNode.php new file mode 100644 index 0000000..041cbf6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/BodyNode.php @@ -0,0 +1,21 @@ + + */ +class BodyNode extends Node +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckSecurityNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckSecurityNode.php new file mode 100644 index 0000000..5bdff09 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckSecurityNode.php @@ -0,0 +1,83 @@ + + */ +class CheckSecurityNode extends Node +{ + private $usedFilters; + private $usedTags; + private $usedFunctions; + + public function __construct(array $usedFilters, array $usedTags, array $usedFunctions) + { + $this->usedFilters = $usedFilters; + $this->usedTags = $usedTags; + $this->usedFunctions = $usedFunctions; + + parent::__construct(); + } + + public function compile(Compiler $compiler): void + { + $tags = $filters = $functions = []; + foreach (['tags', 'filters', 'functions'] as $type) { + foreach ($this->{'used'.ucfirst($type)} as $name => $node) { + if ($node instanceof Node) { + ${$type}[$name] = $node->getTemplateLine(); + } else { + ${$type}[$node] = null; + } + } + } + + $compiler + ->write("\$this->sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n") + ->write('$tags = ')->repr(array_filter($tags))->raw(";\n") + ->write('$filters = ')->repr(array_filter($filters))->raw(";\n") + ->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n") + ->write("try {\n") + ->indent() + ->write("\$this->sandbox->checkSecurity(\n") + ->indent() + ->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n") + ->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n") + ->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n") + ->outdent() + ->write(");\n") + ->outdent() + ->write("} catch (SecurityError \$e) {\n") + ->indent() + ->write("\$e->setSourceContext(\$this->source);\n\n") + ->write("if (\$e instanceof SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") + ->outdent() + ->write("}\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("}\n\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckToStringNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckToStringNode.php new file mode 100644 index 0000000..c7a9d69 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/CheckToStringNode.php @@ -0,0 +1,45 @@ + + */ +class CheckToStringNode extends AbstractExpression +{ + public function __construct(AbstractExpression $expr) + { + parent::__construct(['expr' => $expr], [], $expr->getTemplateLine(), $expr->getNodeTag()); + } + + public function compile(Compiler $compiler): void + { + $expr = $this->getNode('expr'); + $compiler + ->raw('$this->sandbox->ensureToStringAllowed(') + ->subcompile($expr) + ->raw(', ') + ->repr($expr->getTemplateLine()) + ->raw(', $this->source)') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DeprecatedNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DeprecatedNode.php new file mode 100644 index 0000000..5ff4430 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DeprecatedNode.php @@ -0,0 +1,53 @@ + + */ +class DeprecatedNode extends Node +{ + public function __construct(AbstractExpression $expr, int $lineno, string $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler->addDebugInfo($this); + + $expr = $this->getNode('expr'); + + if ($expr instanceof ConstantExpression) { + $compiler->write('@trigger_error(') + ->subcompile($expr); + } else { + $varName = $compiler->getVarName(); + $compiler->write(sprintf('$%s = ', $varName)) + ->subcompile($expr) + ->raw(";\n") + ->write(sprintf('@trigger_error($%s', $varName)); + } + + $compiler + ->raw('.') + ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine())) + ->raw(", E_USER_DEPRECATED);\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DoNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DoNode.php new file mode 100644 index 0000000..f7783d1 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/DoNode.php @@ -0,0 +1,38 @@ + + */ +class DoNode extends Node +{ + public function __construct(AbstractExpression $expr, int $lineno, string $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write('') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/EmbedNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/EmbedNode.php new file mode 100644 index 0000000..68f5791 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/EmbedNode.php @@ -0,0 +1,48 @@ + + */ +class EmbedNode extends IncludeNode +{ + // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) + public function __construct(string $name, int $index, AbstractExpression $variables = null, bool $only = false, bool $ignoreMissing = false, int $lineno, string $tag = null) + { + parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); + + $this->setAttribute('name', $name); + $this->setAttribute('index', $index); + } + + protected function addGetTemplate(Compiler $compiler): void + { + $compiler + ->write('$this->loadTemplate(') + ->string($this->getAttribute('name')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(', ') + ->string($this->getAttribute('index')) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AbstractExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AbstractExpression.php new file mode 100644 index 0000000..42da055 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AbstractExpression.php @@ -0,0 +1,24 @@ + + */ +abstract class AbstractExpression extends Node +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrayExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrayExpression.php new file mode 100644 index 0000000..0e25fe4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrayExpression.php @@ -0,0 +1,85 @@ +index = -1; + foreach ($this->getKeyValuePairs() as $pair) { + if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { + $this->index = $pair['key']->getAttribute('value'); + } + } + } + + public function getKeyValuePairs(): array + { + $pairs = []; + foreach (array_chunk($this->nodes, 2) as $pair) { + $pairs[] = [ + 'key' => $pair[0], + 'value' => $pair[1], + ]; + } + + return $pairs; + } + + public function hasElement(AbstractExpression $key): bool + { + foreach ($this->getKeyValuePairs() as $pair) { + // we compare the string representation of the keys + // to avoid comparing the line numbers which are not relevant here. + if ((string) $key === (string) $pair['key']) { + return true; + } + } + + return false; + } + + public function addElement(AbstractExpression $value, AbstractExpression $key = null): void + { + if (null === $key) { + $key = new ConstantExpression(++$this->index, $value->getTemplateLine()); + } + + array_push($this->nodes, $key, $value); + } + + public function compile(Compiler $compiler): void + { + $compiler->raw('['); + $first = true; + foreach ($this->getKeyValuePairs() as $pair) { + if (!$first) { + $compiler->raw(', '); + } + $first = false; + + $compiler + ->subcompile($pair['key']) + ->raw(' => ') + ->subcompile($pair['value']) + ; + } + $compiler->raw(']'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php new file mode 100644 index 0000000..eaad03c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ArrowFunctionExpression.php @@ -0,0 +1,64 @@ + + */ +class ArrowFunctionExpression extends AbstractExpression +{ + public function __construct(AbstractExpression $expr, Node $names, $lineno, $tag = null) + { + parent::__construct(['expr' => $expr, 'names' => $names], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->raw('function (') + ; + foreach ($this->getNode('names') as $i => $name) { + if ($i) { + $compiler->raw(', '); + } + + $compiler + ->raw('$__') + ->raw($name->getAttribute('name')) + ->raw('__') + ; + } + $compiler + ->raw(') use ($context, $macros) { ') + ; + foreach ($this->getNode('names') as $name) { + $compiler + ->raw('$context["') + ->raw($name->getAttribute('name')) + ->raw('"] = $__') + ->raw($name->getAttribute('name')) + ->raw('__; ') + ; + } + $compiler + ->raw('return ') + ->subcompile($this->getNode('expr')) + ->raw('; }') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AssignNameExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AssignNameExpression.php new file mode 100644 index 0000000..7dd1bc4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/AssignNameExpression.php @@ -0,0 +1,27 @@ +raw('$context[') + ->string($this->getAttribute('name')) + ->raw(']') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php new file mode 100644 index 0000000..c424e5c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AbstractBinary.php @@ -0,0 +1,42 @@ + $left, 'right' => $right], [], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(') + ->subcompile($this->getNode('left')) + ->raw(' ') + ; + $this->operator($compiler); + $compiler + ->raw(' ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + abstract public function operator(Compiler $compiler): Compiler; +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AddBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AddBinary.php new file mode 100644 index 0000000..ee4307e --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AddBinary.php @@ -0,0 +1,23 @@ +raw('+'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AndBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AndBinary.php new file mode 100644 index 0000000..5f2380d --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/AndBinary.php @@ -0,0 +1,23 @@ +raw('&&'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php new file mode 100644 index 0000000..db7d6d6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseAndBinary.php @@ -0,0 +1,23 @@ +raw('&'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php new file mode 100644 index 0000000..ce803dd --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseOrBinary.php @@ -0,0 +1,23 @@ +raw('|'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php new file mode 100644 index 0000000..5c29785 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/BitwiseXorBinary.php @@ -0,0 +1,23 @@ +raw('^'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php new file mode 100644 index 0000000..f825ab8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ConcatBinary.php @@ -0,0 +1,23 @@ +raw('.'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/DivBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/DivBinary.php new file mode 100644 index 0000000..e3817d1 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/DivBinary.php @@ -0,0 +1,23 @@ +raw('/'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php new file mode 100644 index 0000000..c3516b8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EndsWithBinary.php @@ -0,0 +1,35 @@ +getVarName(); + $right = $compiler->getVarName(); + $compiler + ->raw(sprintf('(is_string($%s = ', $left)) + ->subcompile($this->getNode('left')) + ->raw(sprintf(') && is_string($%s = ', $right)) + ->subcompile($this->getNode('right')) + ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right)) + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw(''); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EqualBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EqualBinary.php new file mode 100644 index 0000000..80ca264 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/EqualBinary.php @@ -0,0 +1,39 @@ += 80000) { + parent::compile($compiler); + + return; + } + + $compiler + ->raw('0 === twig_compare(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('=='); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php new file mode 100644 index 0000000..d7e7980 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/FloorDivBinary.php @@ -0,0 +1,29 @@ +raw('(int) floor('); + parent::compile($compiler); + $compiler->raw(')'); + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('/'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php new file mode 100644 index 0000000..f1af127 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterBinary.php @@ -0,0 +1,39 @@ += 80000) { + parent::compile($compiler); + + return; + } + + $compiler + ->raw('1 === twig_compare(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('>'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php new file mode 100644 index 0000000..7d206f7 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/GreaterEqualBinary.php @@ -0,0 +1,39 @@ += 80000) { + parent::compile($compiler); + + return; + } + + $compiler + ->raw('0 <= twig_compare(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('>='); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/InBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/InBinary.php new file mode 100644 index 0000000..6dbfa97 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/InBinary.php @@ -0,0 +1,33 @@ +raw('twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('in'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessBinary.php new file mode 100644 index 0000000..e851933 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessBinary.php @@ -0,0 +1,39 @@ += 80000) { + parent::compile($compiler); + + return; + } + + $compiler + ->raw('-1 === twig_compare(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('<'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php new file mode 100644 index 0000000..dccaf31 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/LessEqualBinary.php @@ -0,0 +1,39 @@ += 80000) { + parent::compile($compiler); + + return; + } + + $compiler + ->raw('0 >= twig_compare(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('<='); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php new file mode 100644 index 0000000..bc97292 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MatchesBinary.php @@ -0,0 +1,33 @@ +raw('preg_match(') + ->subcompile($this->getNode('right')) + ->raw(', ') + ->subcompile($this->getNode('left')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw(''); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ModBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ModBinary.php new file mode 100644 index 0000000..271b45c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/ModBinary.php @@ -0,0 +1,23 @@ +raw('%'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MulBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MulBinary.php new file mode 100644 index 0000000..6d4c1e0 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/MulBinary.php @@ -0,0 +1,23 @@ +raw('*'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php new file mode 100644 index 0000000..04eb546 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotEqualBinary.php @@ -0,0 +1,39 @@ += 80000) { + parent::compile($compiler); + + return; + } + + $compiler + ->raw('0 !== twig_compare(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('!='); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotInBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotInBinary.php new file mode 100644 index 0000000..fcba6cc --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/NotInBinary.php @@ -0,0 +1,33 @@ +raw('!twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('not in'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/OrBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/OrBinary.php new file mode 100644 index 0000000..21f87c9 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/OrBinary.php @@ -0,0 +1,23 @@ +raw('||'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/PowerBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/PowerBinary.php new file mode 100644 index 0000000..c9f4c66 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/PowerBinary.php @@ -0,0 +1,22 @@ +raw('**'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/RangeBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/RangeBinary.php new file mode 100644 index 0000000..55982c8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/RangeBinary.php @@ -0,0 +1,33 @@ +raw('range(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw('..'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php new file mode 100644 index 0000000..ae5a4a4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SpaceshipBinary.php @@ -0,0 +1,22 @@ +raw('<=>'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php new file mode 100644 index 0000000..d0df1c4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/StartsWithBinary.php @@ -0,0 +1,35 @@ +getVarName(); + $right = $compiler->getVarName(); + $compiler + ->raw(sprintf('(is_string($%s = ', $left)) + ->subcompile($this->getNode('left')) + ->raw(sprintf(') && is_string($%s = ', $right)) + ->subcompile($this->getNode('right')) + ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) + ; + } + + public function operator(Compiler $compiler): Compiler + { + return $compiler->raw(''); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SubBinary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SubBinary.php new file mode 100644 index 0000000..eeb87fa --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Binary/SubBinary.php @@ -0,0 +1,23 @@ +raw('-'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/BlockReferenceExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/BlockReferenceExpression.php new file mode 100644 index 0000000..4362be9 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/BlockReferenceExpression.php @@ -0,0 +1,86 @@ + + */ +class BlockReferenceExpression extends AbstractExpression +{ + public function __construct(Node $name, Node $template = null, int $lineno, string $tag = null) + { + $nodes = ['name' => $name]; + if (null !== $template) { + $nodes['template'] = $template; + } + + parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + if ($this->getAttribute('is_defined_test')) { + $this->compileTemplateCall($compiler, 'hasBlock'); + } else { + if ($this->getAttribute('output')) { + $compiler->addDebugInfo($this); + + $this + ->compileTemplateCall($compiler, 'displayBlock') + ->raw(";\n"); + } else { + $this->compileTemplateCall($compiler, 'renderBlock'); + } + } + } + + private function compileTemplateCall(Compiler $compiler, string $method): Compiler + { + if (!$this->hasNode('template')) { + $compiler->write('$this'); + } else { + $compiler + ->write('$this->loadTemplate(') + ->subcompile($this->getNode('template')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')') + ; + } + + $compiler->raw(sprintf('->%s', $method)); + + return $this->compileBlockArguments($compiler); + } + + private function compileBlockArguments(Compiler $compiler): Compiler + { + $compiler + ->raw('(') + ->subcompile($this->getNode('name')) + ->raw(', $context'); + + if (!$this->hasNode('template')) { + $compiler->raw(', $blocks'); + } + + return $compiler->raw(')'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/CallExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/CallExpression.php new file mode 100644 index 0000000..27b290b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/CallExpression.php @@ -0,0 +1,310 @@ +getAttribute('callable'); + + $closingParenthesis = false; + $isArray = false; + if (\is_string($callable) && false === strpos($callable, '::')) { + $compiler->raw($callable); + } else { + list($r, $callable) = $this->reflectCallable($callable); + if ($r instanceof \ReflectionMethod && \is_string($callable[0])) { + if ($r->isStatic()) { + $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1])); + } else { + $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); + } + } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) { + $class = \get_class($callable[0]); + if (!$compiler->getEnvironment()->hasExtension($class)) { + // Compile a non-optimized call to trigger a \Twig\Error\RuntimeError, which cannot be a compile-time error + $compiler->raw(sprintf('$this->env->getExtension(\'%s\')', $class)); + } else { + $compiler->raw(sprintf('$this->extensions[\'%s\']', ltrim($class, '\\'))); + } + + $compiler->raw(sprintf('->%s', $callable[1])); + } else { + $closingParenthesis = true; + $isArray = true; + $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', ucfirst($this->getAttribute('type')), $this->getAttribute('name'))); + } + } + + $this->compileArguments($compiler, $isArray); + + if ($closingParenthesis) { + $compiler->raw(')'); + } + } + + protected function compileArguments(Compiler $compiler, $isArray = false): void + { + $compiler->raw($isArray ? '[' : '('); + + $first = true; + + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + $compiler->raw('$this->env'); + $first = false; + } + + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->raw('$context'); + $first = false; + } + + if ($this->hasAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->string($argument); + $first = false; + } + } + + if ($this->hasNode('node')) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->subcompile($this->getNode('node')); + $first = false; + } + + if ($this->hasNode('arguments')) { + $callable = $this->getAttribute('callable'); + $arguments = $this->getArguments($callable, $this->getNode('arguments')); + foreach ($arguments as $node) { + if (!$first) { + $compiler->raw(', '); + } + $compiler->subcompile($node); + $first = false; + } + } + + $compiler->raw($isArray ? ']' : ')'); + } + + protected function getArguments($callable = null, $arguments) + { + $callType = $this->getAttribute('type'); + $callName = $this->getAttribute('name'); + + $parameters = []; + $named = false; + foreach ($arguments as $name => $node) { + if (!\is_int($name)) { + $named = true; + $name = $this->normalizeName($name); + } elseif ($named) { + throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + + $parameters[$name] = $node; + } + + $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic'); + if (!$named && !$isVariadic) { + return $parameters; + } + + if (!$callable) { + if ($named) { + $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName); + } else { + $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName); + } + + throw new \LogicException($message); + } + + list($callableParameters, $isPhpVariadic) = $this->getCallableParameters($callable, $isVariadic); + $arguments = []; + $names = []; + $missingArguments = []; + $optionalArguments = []; + $pos = 0; + foreach ($callableParameters as $callableParameter) { + $names[] = $name = $this->normalizeName($callableParameter->name); + + if (\array_key_exists($name, $parameters)) { + if (\array_key_exists($pos, $parameters)) { + throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + + if (\count($missingArguments)) { + throw new SyntaxError(sprintf( + 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', + $name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) + ), $this->getTemplateLine(), $this->getSourceContext()); + } + + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$name]; + unset($parameters[$name]); + $optionalArguments = []; + } elseif (\array_key_exists($pos, $parameters)) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$pos]; + unset($parameters[$pos]); + $optionalArguments = []; + ++$pos; + } elseif ($callableParameter->isDefaultValueAvailable()) { + $optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1); + } elseif ($callableParameter->isOptional()) { + if (empty($parameters)) { + break; + } else { + $missingArguments[] = $name; + } + } else { + throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); + } + } + + if ($isVariadic) { + $arbitraryArguments = $isPhpVariadic ? new VariadicExpression([], -1) : new ArrayExpression([], -1); + foreach ($parameters as $key => $value) { + if (\is_int($key)) { + $arbitraryArguments->addElement($value); + } else { + $arbitraryArguments->addElement($value, new ConstantExpression($key, -1)); + } + unset($parameters[$key]); + } + + if ($arbitraryArguments->count()) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $arbitraryArguments; + } + } + + if (!empty($parameters)) { + $unknownParameter = null; + foreach ($parameters as $parameter) { + if ($parameter instanceof Node) { + $unknownParameter = $parameter; + break; + } + } + + throw new SyntaxError( + sprintf( + 'Unknown argument%s "%s" for %s "%s(%s)".', + \count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) + ), + $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(), + $unknownParameter ? $unknownParameter->getSourceContext() : $this->getSourceContext() + ); + } + + return $arguments; + } + + protected function normalizeName(string $name): string + { + return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); + } + + private function getCallableParameters($callable, bool $isVariadic): array + { + list($r) = $this->reflectCallable($callable); + if (null === $r) { + return [[], false]; + } + + $parameters = $r->getParameters(); + if ($this->hasNode('node')) { + array_shift($parameters); + } + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + array_shift($parameters); + } + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + array_shift($parameters); + } + if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + array_shift($parameters); + } + } + $isPhpVariadic = false; + if ($isVariadic) { + $argument = end($parameters); + if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { + array_pop($parameters); + } elseif ($argument && $argument->isVariadic()) { + array_pop($parameters); + $isPhpVariadic = true; + } else { + $callableName = $r->name; + if ($r instanceof \ReflectionMethod) { + $callableName = $r->getDeclaringClass()->name.'::'.$callableName; + } + + throw new \LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); + } + } + + return [$parameters, $isPhpVariadic]; + } + + private function reflectCallable($callable) + { + if (null !== $this->reflector) { + return $this->reflector; + } + + if (\is_array($callable)) { + if (!method_exists($callable[0], $callable[1])) { + // __call() + return [null, []]; + } + $r = new \ReflectionMethod($callable[0], $callable[1]); + } elseif (\is_object($callable) && !$callable instanceof \Closure) { + $r = new \ReflectionObject($callable); + $r = $r->getMethod('__invoke'); + $callable = [$callable, '__invoke']; + } elseif (\is_string($callable) && false !== $pos = strpos($callable, '::')) { + $class = substr($callable, 0, $pos); + $method = substr($callable, $pos + 2); + if (!method_exists($class, $method)) { + // __staticCall() + return [null, []]; + } + $r = new \ReflectionMethod($callable); + $callable = [$class, $method]; + } else { + $r = new \ReflectionFunction($callable); + } + + return $this->reflector = [$r, $callable]; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConditionalExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConditionalExpression.php new file mode 100644 index 0000000..2c7bd0a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConditionalExpression.php @@ -0,0 +1,36 @@ + $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->raw('((') + ->subcompile($this->getNode('expr1')) + ->raw(') ? (') + ->subcompile($this->getNode('expr2')) + ->raw(') : (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConstantExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConstantExpression.php new file mode 100644 index 0000000..7ddbcc6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ConstantExpression.php @@ -0,0 +1,28 @@ + $value], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler->repr($this->getAttribute('value')); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php new file mode 100644 index 0000000..6a572d4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Filter/DefaultFilter.php @@ -0,0 +1,52 @@ + + */ +class DefaultFilter extends FilterExpression +{ + public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null) + { + $default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); + + if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) { + $test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine()); + $false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine()); + + $node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine()); + } else { + $node = $default; + } + + parent::__construct($node, $filterName, $arguments, $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler->subcompile($this->getNode('node')); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FilterExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FilterExpression.php new file mode 100644 index 0000000..0fc1588 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FilterExpression.php @@ -0,0 +1,40 @@ + $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $name = $this->getNode('filter')->getAttribute('value'); + $filter = $compiler->getEnvironment()->getFilter($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'filter'); + $this->setAttribute('needs_environment', $filter->needsEnvironment()); + $this->setAttribute('needs_context', $filter->needsContext()); + $this->setAttribute('arguments', $filter->getArguments()); + $this->setAttribute('callable', $filter->getCallable()); + $this->setAttribute('is_variadic', $filter->isVariadic()); + + $this->compileCallable($compiler); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FunctionExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FunctionExpression.php new file mode 100644 index 0000000..7126977 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/FunctionExpression.php @@ -0,0 +1,43 @@ + $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); + } + + public function compile(Compiler $compiler) + { + $name = $this->getAttribute('name'); + $function = $compiler->getEnvironment()->getFunction($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'function'); + $this->setAttribute('needs_environment', $function->needsEnvironment()); + $this->setAttribute('needs_context', $function->needsContext()); + $this->setAttribute('arguments', $function->getArguments()); + $callable = $function->getCallable(); + if ('constant' === $name && $this->getAttribute('is_defined_test')) { + $callable = 'twig_constant_is_defined'; + } + $this->setAttribute('callable', $callable); + $this->setAttribute('is_variadic', $function->isVariadic()); + + $this->compileCallable($compiler); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/GetAttrExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/GetAttrExpression.php new file mode 100644 index 0000000..6527af1 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/GetAttrExpression.php @@ -0,0 +1,87 @@ + $node, 'attribute' => $attribute]; + if (null !== $arguments) { + $nodes['arguments'] = $arguments; + } + + parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'optimizable' => true], $lineno); + } + + public function compile(Compiler $compiler): void + { + $env = $compiler->getEnvironment(); + + // optimize array calls + if ( + $this->getAttribute('optimizable') + && (!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check')) + && !$this->getAttribute('is_defined_test') + && Template::ARRAY_CALL === $this->getAttribute('type') + ) { + $var = '$'.$compiler->getVarName(); + $compiler + ->raw('(('.$var.' = ') + ->subcompile($this->getNode('node')) + ->raw(') && is_array(') + ->raw($var) + ->raw(') || ') + ->raw($var) + ->raw(' instanceof ArrayAccess ? (') + ->raw($var) + ->raw('[') + ->subcompile($this->getNode('attribute')) + ->raw('] ?? null) : null)') + ; + + return; + } + + $compiler->raw('twig_get_attribute($this->env, $this->source, '); + + if ($this->getAttribute('ignore_strict_check')) { + $this->getNode('node')->setAttribute('ignore_strict_check', true); + } + + $compiler + ->subcompile($this->getNode('node')) + ->raw(', ') + ->subcompile($this->getNode('attribute')) + ; + + if ($this->hasNode('arguments')) { + $compiler->raw(', ')->subcompile($this->getNode('arguments')); + } else { + $compiler->raw(', []'); + } + + $compiler->raw(', ') + ->repr($this->getAttribute('type')) + ->raw(', ')->repr($this->getAttribute('is_defined_test')) + ->raw(', ')->repr($this->getAttribute('ignore_strict_check')) + ->raw(', ')->repr($env->hasExtension(SandboxExtension::class)) + ->raw(', ')->repr($this->getNode('node')->getTemplateLine()) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/InlinePrint.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/InlinePrint.php new file mode 100644 index 0000000..1ad4751 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/InlinePrint.php @@ -0,0 +1,35 @@ + $node], [], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->raw('print (') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/MethodCallExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/MethodCallExpression.php new file mode 100644 index 0000000..d5ec0b6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/MethodCallExpression.php @@ -0,0 +1,62 @@ + $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false, 'is_defined_test' => false], $lineno); + + if ($node instanceof NameExpression) { + $node->setAttribute('always_defined', true); + } + } + + public function compile(Compiler $compiler): void + { + if ($this->getAttribute('is_defined_test')) { + $compiler + ->raw('method_exists($macros[') + ->repr($this->getNode('node')->getAttribute('name')) + ->raw('], ') + ->repr($this->getAttribute('method')) + ->raw(')') + ; + + return; + } + + $compiler + ->raw('twig_call_macro($macros[') + ->repr($this->getNode('node')->getAttribute('name')) + ->raw('], ') + ->repr($this->getAttribute('method')) + ->raw(', [') + ; + $first = true; + foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { + if (!$first) { + $compiler->raw(', '); + } + $first = false; + + $compiler->subcompile($pair['value']); + } + $compiler + ->raw('], ') + ->repr($this->getTemplateLine()) + ->raw(', $context, $this->getSourceContext())'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NameExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NameExpression.php new file mode 100644 index 0000000..017e831 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NameExpression.php @@ -0,0 +1,97 @@ + '$this->getTemplateName()', + '_context' => '$context', + '_charset' => '$this->env->getCharset()', + ]; + + public function __construct(string $name, int $lineno) + { + parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); + } + + public function compile(Compiler $compiler): void + { + $name = $this->getAttribute('name'); + + $compiler->addDebugInfo($this); + + if ($this->getAttribute('is_defined_test')) { + if ($this->isSpecial()) { + $compiler->repr(true); + } elseif (\PHP_VERSION_ID >= 700400) { + $compiler + ->raw('array_key_exists(') + ->string($name) + ->raw(', $context)') + ; + } else { + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) || array_key_exists(') + ->string($name) + ->raw(', $context))') + ; + } + } elseif ($this->isSpecial()) { + $compiler->raw($this->specialVars[$name]); + } elseif ($this->getAttribute('always_defined')) { + $compiler + ->raw('$context[') + ->string($name) + ->raw(']') + ; + } else { + if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { + $compiler + ->raw('($context[') + ->string($name) + ->raw('] ?? null)') + ; + } else { + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) || array_key_exists(') + ->string($name) + ->raw(', $context) ? $context[') + ->string($name) + ->raw('] : (function () { throw new RuntimeError(\'Variable ') + ->string($name) + ->raw(' does not exist.\', ') + ->repr($this->lineno) + ->raw(', $this->source); })()') + ->raw(')') + ; + } + } + } + + public function isSpecial() + { + return isset($this->specialVars[$this->getAttribute('name')]); + } + + public function isSimple() + { + return !$this->isSpecial() && !$this->getAttribute('is_defined_test'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NullCoalesceExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NullCoalesceExpression.php new file mode 100644 index 0000000..a72bc4f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/NullCoalesceExpression.php @@ -0,0 +1,60 @@ +getTemplateLine()); + // for "block()", we don't need the null test as the return value is always a string + if (!$left instanceof BlockReferenceExpression) { + $test = new AndBinary( + $test, + new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()), + $left->getTemplateLine() + ); + } + + parent::__construct($test, $left, $right, $lineno); + } + + public function compile(Compiler $compiler): void + { + /* + * This optimizes only one case. PHP 7 also supports more complex expressions + * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works, + * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced + * cases might be implemented as an optimizer node visitor, but has not been done + * as benefits are probably not worth the added complexity. + */ + if ($this->getNode('expr2') instanceof NameExpression) { + $this->getNode('expr2')->setAttribute('always_defined', true); + $compiler + ->raw('((') + ->subcompile($this->getNode('expr2')) + ->raw(') ?? (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } else { + parent::compile($compiler); + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ParentExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ParentExpression.php new file mode 100644 index 0000000..2549197 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/ParentExpression.php @@ -0,0 +1,46 @@ + + */ +class ParentExpression extends AbstractExpression +{ + public function __construct(string $name, int $lineno, string $tag = null) + { + parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + if ($this->getAttribute('output')) { + $compiler + ->addDebugInfo($this) + ->write('$this->displayParentBlock(') + ->string($this->getAttribute('name')) + ->raw(", \$context, \$blocks);\n") + ; + } else { + $compiler + ->raw('$this->renderParentBlock(') + ->string($this->getAttribute('name')) + ->raw(', $context, $blocks)') + ; + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TempNameExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TempNameExpression.php new file mode 100644 index 0000000..004c704 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TempNameExpression.php @@ -0,0 +1,31 @@ + $name], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->raw('$_') + ->raw($this->getAttribute('name')) + ->raw('_') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/ConstantTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/ConstantTest.php new file mode 100644 index 0000000..57e9319 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/ConstantTest.php @@ -0,0 +1,49 @@ + + */ +class ConstantTest extends TestExpression +{ + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === constant(') + ; + + if ($this->getNode('arguments')->hasNode(1)) { + $compiler + ->raw('get_class(') + ->subcompile($this->getNode('arguments')->getNode(1)) + ->raw(')."::".') + ; + } + + $compiler + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw('))') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DefinedTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DefinedTest.php new file mode 100644 index 0000000..8ccfc8e --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DefinedTest.php @@ -0,0 +1,74 @@ + + */ +class DefinedTest extends TestExpression +{ + public function __construct(Node $node, string $name, Node $arguments = null, int $lineno) + { + if ($node instanceof NameExpression) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof GetAttrExpression) { + $node->setAttribute('is_defined_test', true); + $this->changeIgnoreStrictCheck($node); + } elseif ($node instanceof BlockReferenceExpression) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) { + $node = new ConstantExpression(true, $node->getTemplateLine()); + } elseif ($node instanceof MethodCallExpression) { + $node->setAttribute('is_defined_test', true); + } else { + throw new SyntaxError('The "defined" test only works with simple variables.', $lineno); + } + + parent::__construct($node, $name, $arguments, $lineno); + } + + private function changeIgnoreStrictCheck(GetAttrExpression $node) + { + $node->setAttribute('optimizable', false); + $node->setAttribute('ignore_strict_check', true); + + if ($node->getNode('node') instanceof GetAttrExpression) { + $this->changeIgnoreStrictCheck($node->getNode('node')); + } + } + + public function compile(Compiler $compiler): void + { + $compiler->subcompile($this->getNode('node')); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php new file mode 100644 index 0000000..4cb3ee0 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php @@ -0,0 +1,36 @@ + + */ +class DivisiblebyTest extends TestExpression +{ + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(0 == ') + ->subcompile($this->getNode('node')) + ->raw(' % ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/EvenTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/EvenTest.php new file mode 100644 index 0000000..a0e3ed6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/EvenTest.php @@ -0,0 +1,35 @@ + + */ +class EvenTest extends TestExpression +{ + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 0') + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/NullTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/NullTest.php new file mode 100644 index 0000000..45b54ae --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/NullTest.php @@ -0,0 +1,34 @@ + + */ +class NullTest extends TestExpression +{ + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(null === ') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/OddTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/OddTest.php new file mode 100644 index 0000000..daeec6c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/OddTest.php @@ -0,0 +1,35 @@ + + */ +class OddTest extends TestExpression +{ + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 1') + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/SameasTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/SameasTest.php new file mode 100644 index 0000000..c96d2bc --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Test/SameasTest.php @@ -0,0 +1,34 @@ + + */ +class SameasTest extends TestExpression +{ + public function compile(Compiler $compiler): void + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TestExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TestExpression.php new file mode 100644 index 0000000..e0c90c3 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/TestExpression.php @@ -0,0 +1,42 @@ + $node]; + if (null !== $arguments) { + $nodes['arguments'] = $arguments; + } + + parent::__construct($nodes, ['name' => $name], $lineno); + } + + public function compile(Compiler $compiler): void + { + $name = $this->getAttribute('name'); + $test = $compiler->getEnvironment()->getTest($name); + + $this->setAttribute('name', $name); + $this->setAttribute('type', 'test'); + $this->setAttribute('arguments', $test->getArguments()); + $this->setAttribute('callable', $test->getCallable()); + $this->setAttribute('is_variadic', $test->isVariadic()); + + $this->compileCallable($compiler); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php new file mode 100644 index 0000000..e31e3f8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/AbstractUnary.php @@ -0,0 +1,34 @@ + $node], [], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler->raw(' '); + $this->operator($compiler); + $compiler->subcompile($this->getNode('node')); + } + + abstract public function operator(Compiler $compiler): Compiler; +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NegUnary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NegUnary.php new file mode 100644 index 0000000..dc2f235 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NegUnary.php @@ -0,0 +1,23 @@ +raw('-'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NotUnary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NotUnary.php new file mode 100644 index 0000000..55c11ba --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/NotUnary.php @@ -0,0 +1,23 @@ +raw('!'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/PosUnary.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/PosUnary.php new file mode 100644 index 0000000..4b0a062 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/Unary/PosUnary.php @@ -0,0 +1,23 @@ +raw('+'); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/VariadicExpression.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/VariadicExpression.php new file mode 100644 index 0000000..a1bdb48 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Expression/VariadicExpression.php @@ -0,0 +1,24 @@ +raw('...'); + + parent::compile($compiler); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/FlushNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/FlushNode.php new file mode 100644 index 0000000..fa50a88 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/FlushNode.php @@ -0,0 +1,35 @@ + + */ +class FlushNode extends Node +{ + public function __construct(int $lineno, string $tag) + { + parent::__construct([], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write("flush();\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForLoopNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForLoopNode.php new file mode 100644 index 0000000..d5ce845 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForLoopNode.php @@ -0,0 +1,49 @@ + + */ +class ForLoopNode extends Node +{ + public function __construct(int $lineno, string $tag = null) + { + parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + if ($this->getAttribute('else')) { + $compiler->write("\$context['_iterated'] = true;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("++\$context['loop']['index0'];\n") + ->write("++\$context['loop']['index'];\n") + ->write("\$context['loop']['first'] = false;\n") + ->write("if (isset(\$context['loop']['length'])) {\n") + ->indent() + ->write("--\$context['loop']['revindex0'];\n") + ->write("--\$context['loop']['revindex'];\n") + ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") + ->outdent() + ->write("}\n") + ; + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForNode.php new file mode 100644 index 0000000..fd7ea68 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ForNode.php @@ -0,0 +1,107 @@ + + */ +class ForNode extends Node +{ + private $loop; + + public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, $ifexpr = null, Node $body, Node $else = null, int $lineno, string $tag = null) + { + $body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]); + + $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; + if (null !== $else) { + $nodes['else'] = $else; + } + + parent::__construct($nodes, ['with_loop' => true], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write("\$context['_parent'] = \$context;\n") + ->write("\$context['_seq'] = twig_ensure_traversable(") + ->subcompile($this->getNode('seq')) + ->raw(");\n") + ; + + if ($this->hasNode('else')) { + $compiler->write("\$context['_iterated'] = false;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("\$context['loop'] = [\n") + ->write(" 'parent' => \$context['_parent'],\n") + ->write(" 'index0' => 0,\n") + ->write(" 'index' => 1,\n") + ->write(" 'first' => true,\n") + ->write("];\n") + ->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof \Countable)) {\n") + ->indent() + ->write("\$length = count(\$context['_seq']);\n") + ->write("\$context['loop']['revindex0'] = \$length - 1;\n") + ->write("\$context['loop']['revindex'] = \$length;\n") + ->write("\$context['loop']['length'] = \$length;\n") + ->write("\$context['loop']['last'] = 1 === \$length;\n") + ->outdent() + ->write("}\n") + ; + } + + $this->loop->setAttribute('else', $this->hasNode('else')); + $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop')); + + $compiler + ->write("foreach (\$context['_seq'] as ") + ->subcompile($this->getNode('key_target')) + ->raw(' => ') + ->subcompile($this->getNode('value_target')) + ->raw(") {\n") + ->indent() + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n") + ; + + if ($this->hasNode('else')) { + $compiler + ->write("if (!\$context['_iterated']) {\n") + ->indent() + ->subcompile($this->getNode('else')) + ->outdent() + ->write("}\n") + ; + } + + $compiler->write("\$_parent = \$context['_parent'];\n"); + + // remove some "private" loop variables (needed for nested loops) + $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); + + // keep the values set in the inner context for variables defined in the outer context + $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n"); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IfNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IfNode.php new file mode 100644 index 0000000..bfc5371 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IfNode.php @@ -0,0 +1,70 @@ + + */ +class IfNode extends Node +{ + public function __construct(Node $tests, Node $else = null, int $lineno, string $tag = null) + { + $nodes = ['tests' => $tests]; + if (null !== $else) { + $nodes['else'] = $else; + } + + parent::__construct($nodes, [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler->addDebugInfo($this); + for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) { + if ($i > 0) { + $compiler + ->outdent() + ->write('} elseif (') + ; + } else { + $compiler + ->write('if (') + ; + } + + $compiler + ->subcompile($this->getNode('tests')->getNode($i)) + ->raw(") {\n") + ->indent() + ->subcompile($this->getNode('tests')->getNode($i + 1)) + ; + } + + if ($this->hasNode('else')) { + $compiler + ->outdent() + ->write("} else {\n") + ->indent() + ->subcompile($this->getNode('else')) + ; + } + + $compiler + ->outdent() + ->write("}\n"); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ImportNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ImportNode.php new file mode 100644 index 0000000..5378d79 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ImportNode.php @@ -0,0 +1,63 @@ + + */ +class ImportNode extends Node +{ + public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, string $tag = null, bool $global = true) + { + parent::__construct(['expr' => $expr, 'var' => $var], ['global' => $global], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write('$macros[') + ->repr($this->getNode('var')->getAttribute('name')) + ->raw('] = ') + ; + + if ($this->getAttribute('global')) { + $compiler + ->raw('$this->macros[') + ->repr($this->getNode('var')->getAttribute('name')) + ->raw('] = ') + ; + } + + if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) { + $compiler->raw('$this'); + } else { + $compiler + ->raw('$this->loadTemplate(') + ->subcompile($this->getNode('expr')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')->unwrap()') + ; + } + + $compiler->raw(";\n"); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IncludeNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IncludeNode.php new file mode 100644 index 0000000..c592353 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/IncludeNode.php @@ -0,0 +1,106 @@ + + */ +class IncludeNode extends Node implements NodeOutputInterface +{ + public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, bool $only = false, bool $ignoreMissing = false, int $lineno, string $tag = null) + { + $nodes = ['expr' => $expr]; + if (null !== $variables) { + $nodes['variables'] = $variables; + } + + parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler->addDebugInfo($this); + + if ($this->getAttribute('ignore_missing')) { + $template = $compiler->getVarName(); + + $compiler + ->write(sprintf("$%s = null;\n", $template)) + ->write("try {\n") + ->indent() + ->write(sprintf('$%s = ', $template)) + ; + + $this->addGetTemplate($compiler); + + $compiler + ->raw(";\n") + ->outdent() + ->write("} catch (LoaderError \$e) {\n") + ->indent() + ->write("// ignore missing template\n") + ->outdent() + ->write("}\n") + ->write(sprintf("if ($%s) {\n", $template)) + ->indent() + ->write(sprintf('$%s->display(', $template)) + ; + $this->addTemplateArguments($compiler); + $compiler + ->raw(");\n") + ->outdent() + ->write("}\n") + ; + } else { + $this->addGetTemplate($compiler); + $compiler->raw('->display('); + $this->addTemplateArguments($compiler); + $compiler->raw(");\n"); + } + } + + protected function addGetTemplate(Compiler $compiler) + { + $compiler + ->write('$this->loadTemplate(') + ->subcompile($this->getNode('expr')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(')') + ; + } + + protected function addTemplateArguments(Compiler $compiler) + { + if (!$this->hasNode('variables')) { + $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('twig_array_merge($context, ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; + } else { + $compiler->raw('twig_to_array('); + $compiler->subcompile($this->getNode('variables')); + $compiler->raw(')'); + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/MacroNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/MacroNode.php new file mode 100644 index 0000000..cfe38f8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/MacroNode.php @@ -0,0 +1,113 @@ + + */ +class MacroNode extends Node +{ + const VARARGS_NAME = 'varargs'; + + public function __construct(string $name, Node $body, Node $arguments, int $lineno, string $tag = null) + { + foreach ($arguments as $argumentName => $argument) { + if (self::VARARGS_NAME === $argumentName) { + throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine(), $argument->getSourceContext()); + } + } + + parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write(sprintf('public function macro_%s(', $this->getAttribute('name'))) + ; + + $count = \count($this->getNode('arguments')); + $pos = 0; + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->raw('$__'.$name.'__ = ') + ->subcompile($default) + ; + + if (++$pos < $count) { + $compiler->raw(', '); + } + } + + if ($count) { + $compiler->raw(', '); + } + + $compiler + ->raw('...$__varargs__') + ->raw(")\n") + ->write("{\n") + ->indent() + ->write("\$macros = \$this->macros;\n") + ->write("\$context = \$this->env->mergeGlobals([\n") + ->indent() + ; + + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->write('') + ->string($name) + ->raw(' => $__'.$name.'__') + ->raw(",\n") + ; + } + + $compiler + ->write('') + ->string(self::VARARGS_NAME) + ->raw(' => ') + ; + + $compiler + ->raw("\$__varargs__,\n") + ->outdent() + ->write("]);\n\n") + ->write("\$blocks = [];\n\n") + ; + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->write("try {\n") + ->indent() + ->subcompile($this->getNode('body')) + ->raw("\n") + ->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n") + ->outdent() + ->write("} finally {\n") + ->indent() + ->write("ob_end_clean();\n") + ->outdent() + ->write("}\n") + ->outdent() + ->write("}\n\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ModuleNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ModuleNode.php new file mode 100644 index 0000000..93eef12 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/ModuleNode.php @@ -0,0 +1,464 @@ + + */ +final class ModuleNode extends Node +{ + public function __construct(Node $body, AbstractExpression $parent = null, Node $blocks, Node $macros, Node $traits, $embeddedTemplates, Source $source) + { + $nodes = [ + 'body' => $body, + 'blocks' => $blocks, + 'macros' => $macros, + 'traits' => $traits, + 'display_start' => new Node(), + 'display_end' => new Node(), + 'constructor_start' => new Node(), + 'constructor_end' => new Node(), + 'class_end' => new Node(), + ]; + if (null !== $parent) { + $nodes['parent'] = $parent; + } + + // embedded templates are set as attributes so that they are only visited once by the visitors + parent::__construct($nodes, [ + 'index' => null, + 'embedded_templates' => $embeddedTemplates, + ], 1); + + // populate the template name of all node children + $this->setSourceContext($source); + } + + public function setIndex($index) + { + $this->setAttribute('index', $index); + } + + public function compile(Compiler $compiler): void + { + $this->compileTemplate($compiler); + + foreach ($this->getAttribute('embedded_templates') as $template) { + $compiler->subcompile($template); + } + } + + protected function compileTemplate(Compiler $compiler) + { + if (!$this->getAttribute('index')) { + $compiler->write('compileClassHeader($compiler); + + $this->compileConstructor($compiler); + + $this->compileGetParent($compiler); + + $this->compileDisplay($compiler); + + $compiler->subcompile($this->getNode('blocks')); + + $this->compileMacros($compiler); + + $this->compileGetTemplateName($compiler); + + $this->compileIsTraitable($compiler); + + $this->compileDebugInfo($compiler); + + $this->compileGetSourceContext($compiler); + + $this->compileClassFooter($compiler); + } + + protected function compileGetParent(Compiler $compiler) + { + if (!$this->hasNode('parent')) { + return; + } + $parent = $this->getNode('parent'); + + $compiler + ->write("protected function doGetParent(array \$context)\n", "{\n") + ->indent() + ->addDebugInfo($parent) + ->write('return ') + ; + + if ($parent instanceof ConstantExpression) { + $compiler->subcompile($parent); + } else { + $compiler + ->raw('$this->loadTemplate(') + ->subcompile($parent) + ->raw(', ') + ->repr($this->getSourceContext()->getName()) + ->raw(', ') + ->repr($parent->getTemplateLine()) + ->raw(')') + ; + } + + $compiler + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassHeader(Compiler $compiler) + { + $compiler + ->write("\n\n") + ; + if (!$this->getAttribute('index')) { + $compiler + ->write("use Twig\Environment;\n") + ->write("use Twig\Error\LoaderError;\n") + ->write("use Twig\Error\RuntimeError;\n") + ->write("use Twig\Extension\SandboxExtension;\n") + ->write("use Twig\Markup;\n") + ->write("use Twig\Sandbox\SecurityError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedTagError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n") + ->write("use Twig\Source;\n") + ->write("use Twig\Template;\n\n") + ; + } + $compiler + // if the template name contains */, add a blank to avoid a PHP parse error + ->write('/* '.str_replace('*/', '* /', $this->getSourceContext()->getName())." */\n") + ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index'))) + ->raw(" extends Template\n") + ->write("{\n") + ->indent() + ->write("private \$source;\n") + ->write("private \$macros = [];\n\n") + ; + } + + protected function compileConstructor(Compiler $compiler) + { + $compiler + ->write("public function __construct(Environment \$env)\n", "{\n") + ->indent() + ->subcompile($this->getNode('constructor_start')) + ->write("parent::__construct(\$env);\n\n") + ->write("\$this->source = \$this->getSourceContext();\n\n") + ; + + // parent + if (!$this->hasNode('parent')) { + $compiler->write("\$this->parent = false;\n\n"); + } + + $countTraits = \count($this->getNode('traits')); + if ($countTraits) { + // traits + foreach ($this->getNode('traits') as $i => $trait) { + $node = $trait->getNode('template'); + + $compiler + ->addDebugInfo($node) + ->write(sprintf('$_trait_%s = $this->loadTemplate(', $i)) + ->subcompile($node) + ->raw(', ') + ->repr($node->getTemplateName()) + ->raw(', ') + ->repr($node->getTemplateLine()) + ->raw(");\n") + ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) + ->indent() + ->write("throw new RuntimeError('Template \"'.") + ->subcompile($trait->getNode('template')) + ->raw(".'\" cannot be used as a trait.', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->source);\n") + ->outdent() + ->write("}\n") + ->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i)) + ; + + foreach ($trait->getNode('targets') as $key => $value) { + $compiler + ->write(sprintf('if (!isset($_trait_%s_blocks[', $i)) + ->string($key) + ->raw("])) {\n") + ->indent() + ->write("throw new RuntimeError('Block ") + ->string($key) + ->raw(' is not defined in trait ') + ->subcompile($trait->getNode('template')) + ->raw(".', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->source);\n") + ->outdent() + ->write("}\n\n") + + ->write(sprintf('$_trait_%s_blocks[', $i)) + ->subcompile($value) + ->raw(sprintf('] = $_trait_%s_blocks[', $i)) + ->string($key) + ->raw(sprintf(']; unset($_trait_%s_blocks[', $i)) + ->string($key) + ->raw("]);\n\n") + ; + } + } + + if ($countTraits > 1) { + $compiler + ->write("\$this->traits = array_merge(\n") + ->indent() + ; + + for ($i = 0; $i < $countTraits; ++$i) { + $compiler + ->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i)) + ; + } + + $compiler + ->outdent() + ->write(");\n\n") + ; + } else { + $compiler + ->write("\$this->traits = \$_trait_0_blocks;\n\n") + ; + } + + $compiler + ->write("\$this->blocks = array_merge(\n") + ->indent() + ->write("\$this->traits,\n") + ->write("[\n") + ; + } else { + $compiler + ->write("\$this->blocks = [\n") + ; + } + + // blocks + $compiler + ->indent() + ; + + foreach ($this->getNode('blocks') as $name => $node) { + $compiler + ->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name)) + ; + } + + if ($countTraits) { + $compiler + ->outdent() + ->write("]\n") + ->outdent() + ->write(");\n") + ; + } else { + $compiler + ->outdent() + ->write("];\n") + ; + } + + $compiler + ->subcompile($this->getNode('constructor_end')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileDisplay(Compiler $compiler) + { + $compiler + ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") + ->indent() + ->write("\$macros = \$this->macros;\n") + ->subcompile($this->getNode('display_start')) + ->subcompile($this->getNode('body')) + ; + + if ($this->hasNode('parent')) { + $parent = $this->getNode('parent'); + + $compiler->addDebugInfo($parent); + if ($parent instanceof ConstantExpression) { + $compiler + ->write('$this->parent = $this->loadTemplate(') + ->subcompile($parent) + ->raw(', ') + ->repr($this->getSourceContext()->getName()) + ->raw(', ') + ->repr($parent->getTemplateLine()) + ->raw(");\n") + ; + $compiler->write('$this->parent'); + } else { + $compiler->write('$this->getParent($context)'); + } + $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n"); + } + + $compiler + ->subcompile($this->getNode('display_end')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassFooter(Compiler $compiler) + { + $compiler + ->subcompile($this->getNode('class_end')) + ->outdent() + ->write("}\n") + ; + } + + protected function compileMacros(Compiler $compiler) + { + $compiler->subcompile($this->getNode('macros')); + } + + protected function compileGetTemplateName(Compiler $compiler) + { + $compiler + ->write("public function getTemplateName()\n", "{\n") + ->indent() + ->write('return ') + ->repr($this->getSourceContext()->getName()) + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileIsTraitable(Compiler $compiler) + { + // A template can be used as a trait if: + // * it has no parent + // * it has no macros + // * it has no body + // + // Put another way, a template can be used as a trait if it + // only contains blocks and use statements. + $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros')); + if ($traitable) { + if ($this->getNode('body') instanceof BodyNode) { + $nodes = $this->getNode('body')->getNode(0); + } else { + $nodes = $this->getNode('body'); + } + + if (!\count($nodes)) { + $nodes = new Node([$nodes]); + } + + foreach ($nodes as $node) { + if (!\count($node)) { + continue; + } + + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { + continue; + } + + if ($node instanceof BlockReferenceNode) { + continue; + } + + $traitable = false; + break; + } + } + + if ($traitable) { + return; + } + + $compiler + ->write("public function isTraitable()\n", "{\n") + ->indent() + ->write(sprintf("return %s;\n", $traitable ? 'true' : 'false')) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileDebugInfo(Compiler $compiler) + { + $compiler + ->write("public function getDebugInfo()\n", "{\n") + ->indent() + ->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true)))) + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileGetSourceContext(Compiler $compiler) + { + $compiler + ->write("public function getSourceContext()\n", "{\n") + ->indent() + ->write('return new Source(') + ->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '') + ->raw(', ') + ->string($this->getSourceContext()->getName()) + ->raw(', ') + ->string($this->getSourceContext()->getPath()) + ->raw(");\n") + ->outdent() + ->write("}\n") + ; + } + + protected function compileLoadTemplate(Compiler $compiler, $node, $var) + { + if ($node instanceof ConstantExpression) { + $compiler + ->write(sprintf('%s = $this->loadTemplate(', $var)) + ->subcompile($node) + ->raw(', ') + ->repr($node->getTemplateName()) + ->raw(', ') + ->repr($node->getTemplateLine()) + ->raw(");\n") + ; + } else { + throw new \LogicException('Trait templates can only be constant nodes.'); + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Node.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Node.php new file mode 100644 index 0000000..6895a21 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/Node.php @@ -0,0 +1,175 @@ + + */ +class Node implements \Countable, \IteratorAggregate +{ + protected $nodes; + protected $attributes; + protected $lineno; + protected $tag; + + private $name; + private $sourceContext; + + /** + * @param array $nodes An array of named nodes + * @param array $attributes An array of attributes (should not be nodes) + * @param int $lineno The line number + * @param string $tag The tag name associated with the Node + */ + public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0, string $tag = null) + { + foreach ($nodes as $name => $node) { + if (!$node instanceof self) { + throw new \InvalidArgumentException(sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, \get_class($this))); + } + } + $this->nodes = $nodes; + $this->attributes = $attributes; + $this->lineno = $lineno; + $this->tag = $tag; + } + + public function __toString() + { + $attributes = []; + foreach ($this->attributes as $name => $value) { + $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); + } + + $repr = [\get_class($this).'('.implode(', ', $attributes)]; + + if (\count($this->nodes)) { + foreach ($this->nodes as $name => $node) { + $len = \strlen($name) + 4; + $noderepr = []; + foreach (explode("\n", (string) $node) as $line) { + $noderepr[] = str_repeat(' ', $len).$line; + } + + $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr))); + } + + $repr[] = ')'; + } else { + $repr[0] .= ')'; + } + + return implode("\n", $repr); + } + + /** + * @return void + */ + public function compile(Compiler $compiler) + { + foreach ($this->nodes as $node) { + $node->compile($compiler); + } + } + + public function getTemplateLine(): int + { + return $this->lineno; + } + + public function getNodeTag(): ?string + { + return $this->tag; + } + + public function hasAttribute(string $name): bool + { + return \array_key_exists($name, $this->attributes); + } + + public function getAttribute(string $name) + { + if (!\array_key_exists($name, $this->attributes)) { + throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, \get_class($this))); + } + + return $this->attributes[$name]; + } + + public function setAttribute(string $name, $value): void + { + $this->attributes[$name] = $value; + } + + public function removeAttribute(string $name): void + { + unset($this->attributes[$name]); + } + + public function hasNode(string $name): bool + { + return isset($this->nodes[$name]); + } + + public function getNode(string $name): self + { + if (!isset($this->nodes[$name])) { + throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, \get_class($this))); + } + + return $this->nodes[$name]; + } + + public function setNode(string $name, self $node): void + { + $this->nodes[$name] = $node; + } + + public function removeNode(string $name): void + { + unset($this->nodes[$name]); + } + + public function count() + { + return \count($this->nodes); + } + + public function getIterator(): \Traversable + { + return new \ArrayIterator($this->nodes); + } + + public function getTemplateName(): ?string + { + return $this->sourceContext ? $this->sourceContext->getName() : null; + } + + public function setSourceContext(Source $source): void + { + $this->sourceContext = $source; + foreach ($this->nodes as $node) { + $node->setSourceContext($source); + } + } + + public function getSourceContext(): ?Source + { + return $this->sourceContext; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeCaptureInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeCaptureInterface.php new file mode 100644 index 0000000..9fb6a0c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeCaptureInterface.php @@ -0,0 +1,21 @@ + + */ +interface NodeCaptureInterface +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeOutputInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeOutputInterface.php new file mode 100644 index 0000000..5e35b40 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/NodeOutputInterface.php @@ -0,0 +1,21 @@ + + */ +interface NodeOutputInterface +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/PrintNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/PrintNode.php new file mode 100644 index 0000000..60386d2 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/PrintNode.php @@ -0,0 +1,39 @@ + + */ +class PrintNode extends Node implements NodeOutputInterface +{ + public function __construct(AbstractExpression $expr, int $lineno, string $tag = null) + { + parent::__construct(['expr' => $expr], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SandboxNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SandboxNode.php new file mode 100644 index 0000000..3dd1b4b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SandboxNode.php @@ -0,0 +1,45 @@ + + */ +class SandboxNode extends Node +{ + public function __construct(Node $body, int $lineno, string $tag = null) + { + parent::__construct(['body' => $body], [], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write("if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {\n") + ->indent() + ->write("\$this->sandbox->enableSandbox();\n") + ->outdent() + ->write("}\n") + ->subcompile($this->getNode('body')) + ->write("if (!\$alreadySandboxed) {\n") + ->indent() + ->write("\$this->sandbox->disableSandbox();\n") + ->outdent() + ->write("}\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SetNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SetNode.php new file mode 100644 index 0000000..96b6bd8 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/SetNode.php @@ -0,0 +1,105 @@ + + */ +class SetNode extends Node implements NodeCaptureInterface +{ + public function __construct(bool $capture, Node $names, Node $values, int $lineno, string $tag = null) + { + parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag); + + /* + * Optimizes the node when capture is used for a large block of text. + * + * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig\Markup("foo"); + */ + if ($this->getAttribute('capture')) { + $this->setAttribute('safe', true); + + $values = $this->getNode('values'); + if ($values instanceof TextNode) { + $this->setNode('values', new ConstantExpression($values->getAttribute('data'), $values->getTemplateLine())); + $this->setAttribute('capture', false); + } + } + } + + public function compile(Compiler $compiler): void + { + $compiler->addDebugInfo($this); + + if (\count($this->getNode('names')) > 1) { + $compiler->write('list('); + foreach ($this->getNode('names') as $idx => $node) { + if ($idx) { + $compiler->raw(', '); + } + + $compiler->subcompile($node); + } + $compiler->raw(')'); + } else { + if ($this->getAttribute('capture')) { + if ($compiler->getEnvironment()->isDebug()) { + $compiler->write("ob_start();\n"); + } else { + $compiler->write("ob_start(function () { return ''; });\n"); + } + $compiler + ->subcompile($this->getNode('values')) + ; + } + + $compiler->subcompile($this->getNode('names'), false); + + if ($this->getAttribute('capture')) { + $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset())"); + } + } + + if (!$this->getAttribute('capture')) { + $compiler->raw(' = '); + + if (\count($this->getNode('names')) > 1) { + $compiler->write('['); + foreach ($this->getNode('values') as $idx => $value) { + if ($idx) { + $compiler->raw(', '); + } + + $compiler->subcompile($value); + } + $compiler->raw(']'); + } else { + if ($this->getAttribute('safe')) { + $compiler + ->raw("('' === \$tmp = ") + ->subcompile($this->getNode('values')) + ->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())") + ; + } else { + $compiler->subcompile($this->getNode('values')); + } + } + } + + $compiler->raw(";\n"); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/TextNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/TextNode.php new file mode 100644 index 0000000..d74ebe6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/TextNode.php @@ -0,0 +1,38 @@ + + */ +class TextNode extends Node implements NodeOutputInterface +{ + public function __construct(string $data, int $lineno) + { + parent::__construct([], ['data' => $data], $lineno); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->string($this->getAttribute('data')) + ->raw(";\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/WithNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/WithNode.php new file mode 100644 index 0000000..ec3f069 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Node/WithNode.php @@ -0,0 +1,70 @@ + + */ +class WithNode extends Node +{ + public function __construct(Node $body, Node $variables = null, bool $only = false, int $lineno, string $tag = null) + { + $nodes = ['body' => $body]; + if (null !== $variables) { + $nodes['variables'] = $variables; + } + + parent::__construct($nodes, ['only' => $only], $lineno, $tag); + } + + public function compile(Compiler $compiler): void + { + $compiler->addDebugInfo($this); + + $parentContextName = $compiler->getVarName(); + + $compiler->write(sprintf("\$%s = \$context;\n", $parentContextName)); + + if ($this->hasNode('variables')) { + $node = $this->getNode('variables'); + $varsName = $compiler->getVarName(); + $compiler + ->write(sprintf('$%s = ', $varsName)) + ->subcompile($node) + ->raw(";\n") + ->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName)) + ->indent() + ->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ") + ->repr($node->getTemplateLine()) + ->raw(", \$this->getSourceContext());\n") + ->outdent() + ->write("}\n") + ->write(sprintf("\$%s = twig_to_array(\$%s);\n", $varsName, $varsName)) + ; + + if ($this->getAttribute('only')) { + $compiler->write("\$context = [];\n"); + } + + $compiler->write(sprintf("\$context = \$this->env->mergeGlobals(array_merge(\$context, \$%s));\n", $varsName)); + } + + $compiler + ->subcompile($this->getNode('body')) + ->write(sprintf("\$context = \$%s;\n", $parentContextName)) + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeTraverser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeTraverser.php new file mode 100644 index 0000000..47a2d5c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeTraverser.php @@ -0,0 +1,76 @@ + + */ +final class NodeTraverser +{ + private $env; + private $visitors = []; + + /** + * @param NodeVisitorInterface[] $visitors + */ + public function __construct(Environment $env, array $visitors = []) + { + $this->env = $env; + foreach ($visitors as $visitor) { + $this->addVisitor($visitor); + } + } + + public function addVisitor(NodeVisitorInterface $visitor): void + { + $this->visitors[$visitor->getPriority()][] = $visitor; + } + + /** + * Traverses a node and calls the registered visitors. + */ + public function traverse(Node $node): Node + { + ksort($this->visitors); + foreach ($this->visitors as $visitors) { + foreach ($visitors as $visitor) { + $node = $this->traverseForVisitor($visitor, $node); + } + } + + return $node; + } + + private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node): ?Node + { + $node = $visitor->enterNode($node, $this->env); + + foreach ($node as $k => $n) { + if (null !== $m = $this->traverseForVisitor($visitor, $n)) { + if ($m !== $n) { + $node->setNode($k, $m); + } + } else { + $node->removeNode($k); + } + } + + return $visitor->leaveNode($node, $this->env); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php new file mode 100644 index 0000000..d7036ae --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php @@ -0,0 +1,49 @@ + + */ +abstract class AbstractNodeVisitor implements NodeVisitorInterface +{ + final public function enterNode(Node $node, Environment $env): Node + { + return $this->doEnterNode($node, $env); + } + + final public function leaveNode(Node $node, Environment $env): ?Node + { + return $this->doLeaveNode($node, $env); + } + + /** + * Called before child nodes are visited. + * + * @return Node The modified node + */ + abstract protected function doEnterNode(Node $node, Environment $env); + + /** + * Called after child nodes are visited. + * + * @return Node|null The modified node or null if the node must be removed + */ + abstract protected function doLeaveNode(Node $node, Environment $env); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php new file mode 100644 index 0000000..aa8df91 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php @@ -0,0 +1,206 @@ + + */ +final class EscaperNodeVisitor implements NodeVisitorInterface +{ + private $statusStack = []; + private $blocks = []; + private $safeAnalysis; + private $traverser; + private $defaultStrategy = false; + private $safeVars = []; + + public function __construct() + { + $this->safeAnalysis = new SafeAnalysisNodeVisitor(); + } + + public function enterNode(Node $node, Environment $env): Node + { + if ($node instanceof ModuleNode) { + if ($env->hasExtension(EscaperExtension::class) && $defaultStrategy = $env->getExtension(EscaperExtension::class)->getDefaultStrategy($node->getTemplateName())) { + $this->defaultStrategy = $defaultStrategy; + } + $this->safeVars = []; + $this->blocks = []; + } elseif ($node instanceof AutoEscapeNode) { + $this->statusStack[] = $node->getAttribute('value'); + } elseif ($node instanceof BlockNode) { + $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); + } elseif ($node instanceof ImportNode) { + $this->safeVars[] = $node->getNode('var')->getAttribute('name'); + } + + return $node; + } + + public function leaveNode(Node $node, Environment $env): ?Node + { + if ($node instanceof ModuleNode) { + $this->defaultStrategy = false; + $this->safeVars = []; + $this->blocks = []; + } elseif ($node instanceof FilterExpression) { + return $this->preEscapeFilterNode($node, $env); + } elseif ($node instanceof PrintNode && false !== $type = $this->needEscaping($env)) { + $expression = $node->getNode('expr'); + if ($expression instanceof ConditionalExpression && $this->shouldUnwrapConditional($expression, $env, $type)) { + return new DoNode($this->unwrapConditional($expression, $env, $type), $expression->getTemplateLine()); + } + + return $this->escapePrintNode($node, $env, $type); + } + + if ($node instanceof AutoEscapeNode || $node instanceof BlockNode) { + array_pop($this->statusStack); + } elseif ($node instanceof BlockReferenceNode) { + $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); + } + + return $node; + } + + private function shouldUnwrapConditional(ConditionalExpression $expression, Environment $env, string $type): bool + { + $expr2Safe = $this->isSafeFor($type, $expression->getNode('expr2'), $env); + $expr3Safe = $this->isSafeFor($type, $expression->getNode('expr3'), $env); + + return $expr2Safe !== $expr3Safe; + } + + private function unwrapConditional(ConditionalExpression $expression, Environment $env, string $type): ConditionalExpression + { + // convert "echo a ? b : c" to "a ? echo b : echo c" recursively + $expr2 = $expression->getNode('expr2'); + if ($expr2 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr2, $env, $type)) { + $expr2 = $this->unwrapConditional($expr2, $env, $type); + } else { + $expr2 = $this->escapeInlinePrintNode(new InlinePrint($expr2, $expr2->getTemplateLine()), $env, $type); + } + $expr3 = $expression->getNode('expr3'); + if ($expr3 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr3, $env, $type)) { + $expr3 = $this->unwrapConditional($expr3, $env, $type); + } else { + $expr3 = $this->escapeInlinePrintNode(new InlinePrint($expr3, $expr3->getTemplateLine()), $env, $type); + } + + return new ConditionalExpression($expression->getNode('expr1'), $expr2, $expr3, $expression->getTemplateLine()); + } + + private function escapeInlinePrintNode(InlinePrint $node, Environment $env, string $type): Node + { + $expression = $node->getNode('node'); + + if ($this->isSafeFor($type, $expression, $env)) { + return $node; + } + + return new InlinePrint($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); + } + + private function escapePrintNode(PrintNode $node, Environment $env, string $type): Node + { + if (false === $type) { + return $node; + } + + $expression = $node->getNode('expr'); + + if ($this->isSafeFor($type, $expression, $env)) { + return $node; + } + + $class = \get_class($node); + + return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); + } + + private function preEscapeFilterNode(FilterExpression $filter, Environment $env): FilterExpression + { + $name = $filter->getNode('filter')->getAttribute('value'); + + $type = $env->getFilter($name)->getPreEscape(); + if (null === $type) { + return $filter; + } + + $node = $filter->getNode('node'); + if ($this->isSafeFor($type, $node, $env)) { + return $filter; + } + + $filter->setNode('node', $this->getEscaperFilter($type, $node)); + + return $filter; + } + + private function isSafeFor(string $type, Node $expression, Environment $env): bool + { + $safe = $this->safeAnalysis->getSafe($expression); + + if (null === $safe) { + if (null === $this->traverser) { + $this->traverser = new NodeTraverser($env, [$this->safeAnalysis]); + } + + $this->safeAnalysis->setSafeVars($this->safeVars); + + $this->traverser->traverse($expression); + $safe = $this->safeAnalysis->getSafe($expression); + } + + return \in_array($type, $safe) || \in_array('all', $safe); + } + + private function needEscaping(Environment $env) + { + if (\count($this->statusStack)) { + return $this->statusStack[\count($this->statusStack) - 1]; + } + + return $this->defaultStrategy ? $this->defaultStrategy : false; + } + + private function getEscaperFilter(string $type, Node $node): FilterExpression + { + $line = $node->getTemplateLine(); + $name = new ConstantExpression('escape', $line); + $args = new Node([new ConstantExpression((string) $type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]); + + return new FilterExpression($node, $name, $args, $line); + } + + public function getPriority(): int + { + return 0; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php new file mode 100644 index 0000000..4c717fa --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/MacroAutoImportNodeVisitor.php @@ -0,0 +1,72 @@ + + */ +final class MacroAutoImportNodeVisitor implements NodeVisitorInterface +{ + private $inAModule = false; + private $hasMacroCalls = false; + + public function enterNode(Node $node, Environment $env): Node + { + if ($node instanceof ModuleNode) { + $this->inAModule = true; + $this->hasMacroCalls = false; + } + + return $node; + } + + public function leaveNode(Node $node, Environment $env): Node + { + if ($node instanceof ModuleNode) { + $this->inAModule = false; + if ($this->hasMacroCalls) { + $node->getNode('constructor_end')->setNode('_auto_macro_import', new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, 'import', true)); + } + } elseif ($this->inAModule) { + if ( + $node instanceof GetAttrExpression && + $node->getNode('node') instanceof NameExpression && + '_self' === $node->getNode('node')->getAttribute('name') && + $node->getNode('attribute') instanceof ConstantExpression + ) { + $this->hasMacroCalls = true; + + $name = $node->getNode('attribute')->getAttribute('value'); + $node = new MethodCallExpression($node->getNode('node'), 'macro_'.$name, $node->getNode('arguments'), $node->getTemplateLine()); + $node->setAttribute('safe', true); + } + } + + return $node; + } + + public function getPriority(): int + { + // we must be ran before auto-escaping + return -10; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php new file mode 100644 index 0000000..59e836d --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/NodeVisitorInterface.php @@ -0,0 +1,46 @@ + + */ +interface NodeVisitorInterface +{ + /** + * Called before child nodes are visited. + * + * @return Node The modified node + */ + public function enterNode(Node $node, Environment $env): Node; + + /** + * Called after child nodes are visited. + * + * @return Node|null The modified node or null if the node must be removed + */ + public function leaveNode(Node $node, Environment $env): ?Node; + + /** + * Returns the priority for this visitor. + * + * Priority should be between -10 and 10 (0 is the default). + * + * @return int The priority level + */ + public function getPriority(); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php new file mode 100644 index 0000000..a847841 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/OptimizerNodeVisitor.php @@ -0,0 +1,215 @@ + + */ +final class OptimizerNodeVisitor implements NodeVisitorInterface +{ + const OPTIMIZE_ALL = -1; + const OPTIMIZE_NONE = 0; + const OPTIMIZE_FOR = 2; + const OPTIMIZE_RAW_FILTER = 4; + + private $loops = []; + private $loopsTargets = []; + private $optimizers; + + /** + * @param int $optimizers The optimizer mode + */ + public function __construct(int $optimizers = -1) + { + if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER)) { + throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers)); + } + + $this->optimizers = $optimizers; + } + + public function enterNode(Node $node, Environment $env): Node + { + if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { + $this->enterOptimizeFor($node, $env); + } + + return $node; + } + + public function leaveNode(Node $node, Environment $env): ?Node + { + if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { + $this->leaveOptimizeFor($node, $env); + } + + if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) { + $node = $this->optimizeRawFilter($node, $env); + } + + $node = $this->optimizePrintNode($node, $env); + + return $node; + } + + /** + * Optimizes print nodes. + * + * It replaces: + * + * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" + */ + private function optimizePrintNode(Node $node, Environment $env): Node + { + if (!$node instanceof PrintNode) { + return $node; + } + + $exprNode = $node->getNode('expr'); + if ( + $exprNode instanceof BlockReferenceExpression || + $exprNode instanceof ParentExpression + ) { + $exprNode->setAttribute('output', true); + + return $exprNode; + } + + return $node; + } + + /** + * Removes "raw" filters. + */ + private function optimizeRawFilter(Node $node, Environment $env): Node + { + if ($node instanceof FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { + return $node->getNode('node'); + } + + return $node; + } + + /** + * Optimizes "for" tag by removing the "loop" variable creation whenever possible. + */ + private function enterOptimizeFor(Node $node, Environment $env): void + { + if ($node instanceof ForNode) { + // disable the loop variable by default + $node->setAttribute('with_loop', false); + array_unshift($this->loops, $node); + array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); + array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); + } elseif (!$this->loops) { + // we are outside a loop + return; + } + + // when do we need to add the loop variable back? + + // the loop variable is referenced for the current loop + elseif ($node instanceof NameExpression && 'loop' === $node->getAttribute('name')) { + $node->setAttribute('always_defined', true); + $this->addLoopToCurrent(); + } + + // optimize access to loop targets + elseif ($node instanceof NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) { + $node->setAttribute('always_defined', true); + } + + // block reference + elseif ($node instanceof BlockReferenceNode || $node instanceof BlockReferenceExpression) { + $this->addLoopToCurrent(); + } + + // include without the only attribute + elseif ($node instanceof IncludeNode && !$node->getAttribute('only')) { + $this->addLoopToAll(); + } + + // include function without the with_context=false parameter + elseif ($node instanceof FunctionExpression + && 'include' === $node->getAttribute('name') + && (!$node->getNode('arguments')->hasNode('with_context') + || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') + ) + ) { + $this->addLoopToAll(); + } + + // the loop variable is referenced via an attribute + elseif ($node instanceof GetAttrExpression + && (!$node->getNode('attribute') instanceof ConstantExpression + || 'parent' === $node->getNode('attribute')->getAttribute('value') + ) + && (true === $this->loops[0]->getAttribute('with_loop') + || ($node->getNode('node') instanceof NameExpression + && 'loop' === $node->getNode('node')->getAttribute('name') + ) + ) + ) { + $this->addLoopToAll(); + } + } + + /** + * Optimizes "for" tag by removing the "loop" variable creation whenever possible. + */ + private function leaveOptimizeFor(Node $node, Environment $env): void + { + if ($node instanceof ForNode) { + array_shift($this->loops); + array_shift($this->loopsTargets); + array_shift($this->loopsTargets); + } + } + + private function addLoopToCurrent(): void + { + $this->loops[0]->setAttribute('with_loop', true); + } + + private function addLoopToAll(): void + { + foreach ($this->loops as $loop) { + $loop->setAttribute('with_loop', true); + } + } + + public function getPriority(): int + { + return 255; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php new file mode 100644 index 0000000..95fc652 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SafeAnalysisNodeVisitor.php @@ -0,0 +1,157 @@ +safeVars = $safeVars; + } + + public function getSafe(Node $node) + { + $hash = spl_object_hash($node); + if (!isset($this->data[$hash])) { + return; + } + + foreach ($this->data[$hash] as $bucket) { + if ($bucket['key'] !== $node) { + continue; + } + + if (\in_array('html_attr', $bucket['value'])) { + $bucket['value'][] = 'html'; + } + + return $bucket['value']; + } + } + + private function setSafe(Node $node, array $safe): void + { + $hash = spl_object_hash($node); + if (isset($this->data[$hash])) { + foreach ($this->data[$hash] as &$bucket) { + if ($bucket['key'] === $node) { + $bucket['value'] = $safe; + + return; + } + } + } + $this->data[$hash][] = [ + 'key' => $node, + 'value' => $safe, + ]; + } + + public function enterNode(Node $node, Environment $env): Node + { + return $node; + } + + public function leaveNode(Node $node, Environment $env): ?Node + { + if ($node instanceof ConstantExpression) { + // constants are marked safe for all + $this->setSafe($node, ['all']); + } elseif ($node instanceof BlockReferenceExpression) { + // blocks are safe by definition + $this->setSafe($node, ['all']); + } elseif ($node instanceof ParentExpression) { + // parent block is safe by definition + $this->setSafe($node, ['all']); + } elseif ($node instanceof ConditionalExpression) { + // intersect safeness of both operands + $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); + $this->setSafe($node, $safe); + } elseif ($node instanceof FilterExpression) { + // filter expression is safe when the filter is safe + $name = $node->getNode('filter')->getAttribute('value'); + $args = $node->getNode('arguments'); + if ($filter = $env->getFilter($name)) { + $safe = $filter->getSafe($args); + if (null === $safe) { + $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety()); + } + $this->setSafe($node, $safe); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof FunctionExpression) { + // function expression is safe when the function is safe + $name = $node->getAttribute('name'); + $args = $node->getNode('arguments'); + if ($function = $env->getFunction($name)) { + $this->setSafe($node, $function->getSafe($args)); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof MethodCallExpression) { + if ($node->getAttribute('safe')) { + $this->setSafe($node, ['all']); + } else { + $this->setSafe($node, []); + } + } elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) { + $name = $node->getNode('node')->getAttribute('name'); + if (\in_array($name, $this->safeVars)) { + $this->setSafe($node, ['all']); + } else { + $this->setSafe($node, []); + } + } else { + $this->setSafe($node, []); + } + + return $node; + } + + private function intersectSafe(array $a = null, array $b = null): array + { + if (null === $a || null === $b) { + return []; + } + + if (\in_array('all', $a)) { + return $b; + } + + if (\in_array('all', $b)) { + return $a; + } + + return array_intersect($a, $b); + } + + public function getPriority(): int + { + return 0; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php new file mode 100644 index 0000000..5aac52c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php @@ -0,0 +1,132 @@ + + */ +final class SandboxNodeVisitor implements NodeVisitorInterface +{ + private $inAModule = false; + private $tags; + private $filters; + private $functions; + private $needsToStringWrap = false; + + public function enterNode(Node $node, Environment $env): Node + { + if ($node instanceof ModuleNode) { + $this->inAModule = true; + $this->tags = []; + $this->filters = []; + $this->functions = []; + + return $node; + } elseif ($this->inAModule) { + // look for tags + if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { + $this->tags[$node->getNodeTag()] = $node; + } + + // look for filters + if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { + $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; + } + + // look for functions + if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { + $this->functions[$node->getAttribute('name')] = $node; + } + + // the .. operator is equivalent to the range() function + if ($node instanceof RangeBinary && !isset($this->functions['range'])) { + $this->functions['range'] = $node; + } + + if ($node instanceof PrintNode) { + $this->needsToStringWrap = true; + $this->wrapNode($node, 'expr'); + } + + if ($node instanceof SetNode && !$node->getAttribute('capture')) { + $this->needsToStringWrap = true; + } + + // wrap outer nodes that can implicitly call __toString() + if ($this->needsToStringWrap) { + if ($node instanceof ConcatBinary) { + $this->wrapNode($node, 'left'); + $this->wrapNode($node, 'right'); + } + if ($node instanceof FilterExpression) { + $this->wrapNode($node, 'node'); + $this->wrapArrayNode($node, 'arguments'); + } + if ($node instanceof FunctionExpression) { + $this->wrapArrayNode($node, 'arguments'); + } + } + } + + return $node; + } + + public function leaveNode(Node $node, Environment $env): ?Node + { + if ($node instanceof ModuleNode) { + $this->inAModule = false; + + $node->getNode('constructor_end')->setNode('_security_check', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); + } elseif ($this->inAModule) { + if ($node instanceof PrintNode || $node instanceof SetNode) { + $this->needsToStringWrap = false; + } + } + + return $node; + } + + private function wrapNode(Node $node, string $name): void + { + $expr = $node->getNode($name); + if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) { + $node->setNode($name, new CheckToStringNode($expr)); + } + } + + private function wrapArrayNode(Node $node, string $name): void + { + $args = $node->getNode($name); + foreach ($args as $name => $_) { + $this->wrapNode($args, $name); + } + } + + public function getPriority(): int + { + return 0; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Parser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Parser.php new file mode 100644 index 0000000..aaa6af6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Parser.php @@ -0,0 +1,360 @@ + + */ +class Parser +{ + private $stack = []; + private $stream; + private $parent; + private $handlers; + private $visitors; + private $expressionParser; + private $blocks; + private $blockStack; + private $macros; + private $env; + private $importedSymbols; + private $traits; + private $embeddedTemplates = []; + private $varNameSalt = 0; + + public function __construct(Environment $env) + { + $this->env = $env; + } + + public function getVarName(): string + { + return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++)); + } + + public function parse(TokenStream $stream, $test = null, bool $dropNeedle = false): ModuleNode + { + $vars = get_object_vars($this); + unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']); + $this->stack[] = $vars; + + // tag handlers + if (null === $this->handlers) { + $this->handlers = []; + foreach ($this->env->getTokenParsers() as $handler) { + $handler->setParser($this); + + $this->handlers[$handler->getTag()] = $handler; + } + } + + // node visitors + if (null === $this->visitors) { + $this->visitors = $this->env->getNodeVisitors(); + } + + if (null === $this->expressionParser) { + $this->expressionParser = new ExpressionParser($this, $this->env); + } + + $this->stream = $stream; + $this->parent = null; + $this->blocks = []; + $this->macros = []; + $this->traits = []; + $this->blockStack = []; + $this->importedSymbols = [[]]; + $this->embeddedTemplates = []; + $this->varNameSalt = 0; + + try { + $body = $this->subparse($test, $dropNeedle); + + if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { + $body = new Node(); + } + } catch (SyntaxError $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($this->stream->getSourceContext()); + } + + if (!$e->getTemplateLine()) { + $e->setTemplateLine($this->stream->getCurrent()->getLine()); + } + + throw $e; + } + + $node = new ModuleNode(new BodyNode([$body]), $this->parent, new Node($this->blocks), new Node($this->macros), new Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); + + $traverser = new NodeTraverser($this->env, $this->visitors); + + $node = $traverser->traverse($node); + + // restore previous stack so previous parse() call can resume working + foreach (array_pop($this->stack) as $key => $val) { + $this->$key = $val; + } + + return $node; + } + + public function subparse($test, bool $dropNeedle = false): Node + { + $lineno = $this->getCurrentToken()->getLine(); + $rv = []; + while (!$this->stream->isEOF()) { + switch ($this->getCurrentToken()->getType()) { + case /* Token::TEXT_TYPE */ 0: + $token = $this->stream->next(); + $rv[] = new TextNode($token->getValue(), $token->getLine()); + break; + + case /* Token::VAR_START_TYPE */ 2: + $token = $this->stream->next(); + $expr = $this->expressionParser->parseExpression(); + $this->stream->expect(/* Token::VAR_END_TYPE */ 4); + $rv[] = new PrintNode($expr, $token->getLine()); + break; + + case /* Token::BLOCK_START_TYPE */ 1: + $this->stream->next(); + $token = $this->getCurrentToken(); + + if (/* Token::NAME_TYPE */ 5 !== $token->getType()) { + throw new SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); + } + + if (null !== $test && $test($token)) { + if ($dropNeedle) { + $this->stream->next(); + } + + if (1 === \count($rv)) { + return $rv[0]; + } + + return new Node($rv, [], $lineno); + } + + if (!isset($this->handlers[$token->getValue()])) { + if (null !== $test) { + $e = new SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + + if (\is_array($test) && isset($test[0]) && $test[0] instanceof TokenParserInterface) { + $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); + } + } else { + $e = new SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); + } + + throw $e; + } + + $this->stream->next(); + + $subparser = $this->handlers[$token->getValue()]; + $node = $subparser->parse($token); + if (null !== $node) { + $rv[] = $node; + } + break; + + default: + throw new SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); + } + } + + if (1 === \count($rv)) { + return $rv[0]; + } + + return new Node($rv, [], $lineno); + } + + public function getBlockStack(): array + { + return $this->blockStack; + } + + public function peekBlockStack() + { + return isset($this->blockStack[\count($this->blockStack) - 1]) ? $this->blockStack[\count($this->blockStack) - 1] : null; + } + + public function popBlockStack(): void + { + array_pop($this->blockStack); + } + + public function pushBlockStack($name): void + { + $this->blockStack[] = $name; + } + + public function hasBlock(string $name): bool + { + return isset($this->blocks[$name]); + } + + public function getBlock(string $name): Node + { + return $this->blocks[$name]; + } + + public function setBlock(string $name, BlockNode $value): void + { + $this->blocks[$name] = new BodyNode([$value], [], $value->getTemplateLine()); + } + + public function hasMacro(string $name): bool + { + return isset($this->macros[$name]); + } + + public function setMacro(string $name, MacroNode $node): void + { + $this->macros[$name] = $node; + } + + public function addTrait($trait): void + { + $this->traits[] = $trait; + } + + public function hasTraits(): bool + { + return \count($this->traits) > 0; + } + + public function embedTemplate(ModuleNode $template) + { + $template->setIndex(mt_rand()); + + $this->embeddedTemplates[] = $template; + } + + public function addImportedSymbol(string $type, string $alias, string $name = null, AbstractExpression $node = null): void + { + $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; + } + + public function getImportedSymbol(string $type, string $alias) + { + // if the symbol does not exist in the current scope (0), try in the main/global scope (last index) + return $this->importedSymbols[0][$type][$alias] ?? ($this->importedSymbols[\count($this->importedSymbols) - 1][$type][$alias] ?? null); + } + + public function isMainScope(): bool + { + return 1 === \count($this->importedSymbols); + } + + public function pushLocalScope(): void + { + array_unshift($this->importedSymbols, []); + } + + public function popLocalScope(): void + { + array_shift($this->importedSymbols); + } + + public function getExpressionParser(): ExpressionParser + { + return $this->expressionParser; + } + + public function getParent(): ?Node + { + return $this->parent; + } + + public function setParent(?Node $parent): void + { + $this->parent = $parent; + } + + public function getStream(): TokenStream + { + return $this->stream; + } + + public function getCurrentToken(): Token + { + return $this->stream->getCurrent(); + } + + private function filterBodyNodes(Node $node, bool $nested = false): ?Node + { + // check that the body does not contain non-empty output nodes + if ( + ($node instanceof TextNode && !ctype_space($node->getAttribute('data'))) + || + (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface) + ) { + if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { + $t = substr($node->getAttribute('data'), 3); + if ('' === $t || ctype_space($t)) { + // bypass empty nodes starting with a BOM + return null; + } + } + + throw new SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); + } + + // bypass nodes that "capture" the output + if ($node instanceof NodeCaptureInterface) { + // a "block" tag in such a node will serve as a block definition AND be displayed in place as well + return $node; + } + + // "block" tags that are not captured (see above) are only used for defining + // the content of the block. In such a case, nesting it does not work as + // expected as the definition is not part of the default template code flow. + if ($nested && $node instanceof BlockReferenceNode) { + throw new SyntaxError('A block definition cannot be nested under non-capturing nodes.', $node->getTemplateLine(), $this->stream->getSourceContext()); + } + + if ($node instanceof NodeOutputInterface) { + return null; + } + + // here, $nested means "being at the root level of a child template" + // we need to discard the wrapping "Node" for the "body" node + $nested = $nested || Node::class !== \get_class($node); + foreach ($node as $k => $n) { + if (null !== $n && null === $this->filterBodyNodes($n, $nested)) { + $node->removeNode($k); + } + } + + return $node; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BaseDumper.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BaseDumper.php new file mode 100644 index 0000000..4da43e4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BaseDumper.php @@ -0,0 +1,63 @@ + + */ +abstract class BaseDumper +{ + private $root; + + public function dump(Profile $profile): string + { + return $this->dumpProfile($profile); + } + + abstract protected function formatTemplate(Profile $profile, $prefix): string; + + abstract protected function formatNonTemplate(Profile $profile, $prefix): string; + + abstract protected function formatTime(Profile $profile, $percent): string; + + private function dumpProfile(Profile $profile, $prefix = '', $sibling = false): string + { + if ($profile->isRoot()) { + $this->root = $profile->getDuration(); + $start = $profile->getName(); + } else { + if ($profile->isTemplate()) { + $start = $this->formatTemplate($profile, $prefix); + } else { + $start = $this->formatNonTemplate($profile, $prefix); + } + $prefix .= $sibling ? '│ ' : ' '; + } + + $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0; + + if ($profile->getDuration() * 1000 < 1) { + $str = $start."\n"; + } else { + $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent)); + } + + $nCount = \count($profile->getProfiles()); + foreach ($profile as $i => $p) { + $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount); + } + + return $str; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php new file mode 100644 index 0000000..3fab5db --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/BlackfireDumper.php @@ -0,0 +1,72 @@ + + */ +final class BlackfireDumper +{ + public function dump(Profile $profile): string + { + $data = []; + $this->dumpProfile('main()', $profile, $data); + $this->dumpChildren('main()', $profile, $data); + + $start = sprintf('%f', microtime(true)); + $str = << $values) { + $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; + } + + return $str; + } + + private function dumpChildren(string $parent, Profile $profile, &$data) + { + foreach ($profile as $p) { + if ($p->isTemplate()) { + $name = $p->getTemplate(); + } else { + $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName()); + } + $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data); + $this->dumpChildren($name, $p, $data); + } + } + + private function dumpProfile(string $edge, Profile $profile, &$data) + { + if (isset($data[$edge])) { + ++$data[$edge]['ct']; + $data[$edge]['wt'] += floor($profile->getDuration() * 1000000); + $data[$edge]['mu'] += $profile->getMemoryUsage(); + $data[$edge]['pmu'] += $profile->getPeakMemoryUsage(); + } else { + $data[$edge] = [ + 'ct' => 1, + 'wt' => floor($profile->getDuration() * 1000000), + 'mu' => $profile->getMemoryUsage(), + 'pmu' => $profile->getPeakMemoryUsage(), + ]; + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/HtmlDumper.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/HtmlDumper.php new file mode 100644 index 0000000..1f2433b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/HtmlDumper.php @@ -0,0 +1,47 @@ + + */ +final class HtmlDumper extends BaseDumper +{ + private static $colors = [ + 'block' => '#dfd', + 'macro' => '#ddf', + 'template' => '#ffd', + 'big' => '#d44', + ]; + + public function dump(Profile $profile): string + { + return '
    '.parent::dump($profile).'
    '; + } + + protected function formatTemplate(Profile $profile, $prefix): string + { + return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); + } + + protected function formatNonTemplate(Profile $profile, $prefix): string + { + return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); + } + + protected function formatTime(Profile $profile, $percent): string + { + return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/TextDumper.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/TextDumper.php new file mode 100644 index 0000000..31561c4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Dumper/TextDumper.php @@ -0,0 +1,35 @@ + + */ +final class TextDumper extends BaseDumper +{ + protected function formatTemplate(Profile $profile, $prefix): string + { + return sprintf('%s└ %s', $prefix, $profile->getTemplate()); + } + + protected function formatNonTemplate(Profile $profile, $prefix): string + { + return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); + } + + protected function formatTime(Profile $profile, $percent): string + { + return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/EnterProfileNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/EnterProfileNode.php new file mode 100644 index 0000000..1494baf --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/EnterProfileNode.php @@ -0,0 +1,42 @@ + + */ +class EnterProfileNode extends Node +{ + public function __construct(string $extensionName, string $type, string $name, string $varName) + { + parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->write(sprintf('$%s = $this->extensions[', $this->getAttribute('var_name'))) + ->repr($this->getAttribute('extension_name')) + ->raw("];\n") + ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ->repr($this->getAttribute('type')) + ->raw(', ') + ->repr($this->getAttribute('name')) + ->raw("));\n\n") + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/LeaveProfileNode.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/LeaveProfileNode.php new file mode 100644 index 0000000..94cebba --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Node/LeaveProfileNode.php @@ -0,0 +1,36 @@ + + */ +class LeaveProfileNode extends Node +{ + public function __construct(string $varName) + { + parent::__construct([], ['var_name' => $varName]); + } + + public function compile(Compiler $compiler): void + { + $compiler + ->write("\n") + ->write(sprintf("\$%s->leave(\$%s);\n\n", $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php new file mode 100644 index 0000000..bd23b20 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php @@ -0,0 +1,76 @@ + + */ +final class ProfilerNodeVisitor implements NodeVisitorInterface +{ + private $extensionName; + + public function __construct(string $extensionName) + { + $this->extensionName = $extensionName; + } + + public function enterNode(Node $node, Environment $env): Node + { + return $node; + } + + public function leaveNode(Node $node, Environment $env): ?Node + { + if ($node instanceof ModuleNode) { + $varName = $this->getVarName(); + $node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); + $node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')])); + } elseif ($node instanceof BlockNode) { + $varName = $this->getVarName(); + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName), + $node->getNode('body'), + new LeaveProfileNode($varName), + ])); + } elseif ($node instanceof MacroNode) { + $varName = $this->getVarName(); + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName), + $node->getNode('body'), + new LeaveProfileNode($varName), + ])); + } + + return $node; + } + + private function getVarName(): string + { + return sprintf('__internal_%s', hash('sha256', $this->extensionName)); + } + + public function getPriority(): int + { + return 0; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Profile.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Profile.php new file mode 100644 index 0000000..36b39e1 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Profiler/Profile.php @@ -0,0 +1,181 @@ + + */ +final class Profile implements \IteratorAggregate, \Serializable +{ + const ROOT = 'ROOT'; + const BLOCK = 'block'; + const TEMPLATE = 'template'; + const MACRO = 'macro'; + + private $template; + private $name; + private $type; + private $starts = []; + private $ends = []; + private $profiles = []; + + public function __construct(string $template = 'main', string $type = self::ROOT, string $name = 'main') + { + $this->template = $template; + $this->type = $type; + $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name; + $this->enter(); + } + + public function getTemplate(): string + { + return $this->template; + } + + public function getType(): string + { + return $this->type; + } + + public function getName(): string + { + return $this->name; + } + + public function isRoot(): bool + { + return self::ROOT === $this->type; + } + + public function isTemplate(): bool + { + return self::TEMPLATE === $this->type; + } + + public function isBlock(): bool + { + return self::BLOCK === $this->type; + } + + public function isMacro(): bool + { + return self::MACRO === $this->type; + } + + /** + * @return Profile[] + */ + public function getProfiles(): array + { + return $this->profiles; + } + + public function addProfile(self $profile): void + { + $this->profiles[] = $profile; + } + + /** + * Returns the duration in microseconds. + */ + public function getDuration(): float + { + if ($this->isRoot() && $this->profiles) { + // for the root node with children, duration is the sum of all child durations + $duration = 0; + foreach ($this->profiles as $profile) { + $duration += $profile->getDuration(); + } + + return $duration; + } + + return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0; + } + + /** + * Returns the memory usage in bytes. + */ + public function getMemoryUsage(): int + { + return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0; + } + + /** + * Returns the peak memory usage in bytes. + */ + public function getPeakMemoryUsage(): int + { + return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0; + } + + /** + * Starts the profiling. + */ + public function enter(): void + { + $this->starts = [ + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ]; + } + + /** + * Stops the profiling. + */ + public function leave(): void + { + $this->ends = [ + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ]; + } + + public function reset(): void + { + $this->starts = $this->ends = $this->profiles = []; + $this->enter(); + } + + public function getIterator(): \Traversable + { + return new \ArrayIterator($this->profiles); + } + + public function serialize() + { + return serialize($this->__serialize()); + } + + public function unserialize($data) + { + $this->__unserialize(unserialize($data)); + } + + /** + * @internal + */ + public function __serialize() + { + return [$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles]; + } + + /** + * @internal + */ + public function __unserialize(array $data) + { + list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = $data; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php new file mode 100644 index 0000000..b360d7b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/ContainerRuntimeLoader.php @@ -0,0 +1,37 @@ + + * @author Robin Chalas + */ +class ContainerRuntimeLoader implements RuntimeLoaderInterface +{ + private $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + public function load(string $class) + { + return $this->container->has($class) ? $this->container->get($class) : null; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php new file mode 100644 index 0000000..1306483 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/FactoryRuntimeLoader.php @@ -0,0 +1,41 @@ + + */ +class FactoryRuntimeLoader implements RuntimeLoaderInterface +{ + private $map; + + /** + * @param array $map An array where keys are class names and values factory callables + */ + public function __construct(array $map = []) + { + $this->map = $map; + } + + public function load(string $class) + { + if (!isset($this->map[$class])) { + return null; + } + + $runtimeFactory = $this->map[$class]; + + return $runtimeFactory(); + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php new file mode 100644 index 0000000..9e5b204 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/RuntimeLoader/RuntimeLoaderInterface.php @@ -0,0 +1,27 @@ + + */ +interface RuntimeLoaderInterface +{ + /** + * Creates the runtime implementation of a Twig element (filter/function/test). + * + * @return object|null The runtime instance or null if the loader does not know how to create the runtime for this class + */ + public function load(string $class); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityError.php new file mode 100644 index 0000000..30a404f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityError.php @@ -0,0 +1,23 @@ + + */ +class SecurityError extends Error +{ +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php new file mode 100644 index 0000000..02d3063 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFilterError.php @@ -0,0 +1,33 @@ + + */ +final class SecurityNotAllowedFilterError extends SecurityError +{ + private $filterName; + + public function __construct(string $message, string $functionName) + { + parent::__construct($message); + $this->filterName = $functionName; + } + + public function getFilterName(): string + { + return $this->filterName; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php new file mode 100644 index 0000000..4f76dc6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedFunctionError.php @@ -0,0 +1,33 @@ + + */ +final class SecurityNotAllowedFunctionError extends SecurityError +{ + private $functionName; + + public function __construct(string $message, string $functionName) + { + parent::__construct($message); + $this->functionName = $functionName; + } + + public function getFunctionName(): string + { + return $this->functionName; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php new file mode 100644 index 0000000..8df9d0b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedMethodError.php @@ -0,0 +1,40 @@ + + */ +final class SecurityNotAllowedMethodError extends SecurityError +{ + private $className; + private $methodName; + + public function __construct(string $message, string $className, string $methodName) + { + parent::__construct($message); + $this->className = $className; + $this->methodName = $methodName; + } + + public function getClassName(): string + { + return $this->className; + } + + public function getMethodName() + { + return $this->methodName; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php new file mode 100644 index 0000000..42ec4f3 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedPropertyError.php @@ -0,0 +1,40 @@ + + */ +final class SecurityNotAllowedPropertyError extends SecurityError +{ + private $className; + private $propertyName; + + public function __construct(string $message, string $className, string $propertyName) + { + parent::__construct($message); + $this->className = $className; + $this->propertyName = $propertyName; + } + + public function getClassName(): string + { + return $this->className; + } + + public function getPropertyName() + { + return $this->propertyName; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php new file mode 100644 index 0000000..4522150 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityNotAllowedTagError.php @@ -0,0 +1,33 @@ + + */ +final class SecurityNotAllowedTagError extends SecurityError +{ + private $tagName; + + public function __construct(string $message, string $tagName) + { + parent::__construct($message); + $this->tagName = $tagName; + } + + public function getTagName(): string + { + return $this->tagName; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicy.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicy.php new file mode 100644 index 0000000..2fc0d01 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicy.php @@ -0,0 +1,126 @@ + + */ +final class SecurityPolicy implements SecurityPolicyInterface +{ + private $allowedTags; + private $allowedFilters; + private $allowedMethods; + private $allowedProperties; + private $allowedFunctions; + + public function __construct(array $allowedTags = [], array $allowedFilters = [], array $allowedMethods = [], array $allowedProperties = [], array $allowedFunctions = []) + { + $this->allowedTags = $allowedTags; + $this->allowedFilters = $allowedFilters; + $this->setAllowedMethods($allowedMethods); + $this->allowedProperties = $allowedProperties; + $this->allowedFunctions = $allowedFunctions; + } + + public function setAllowedTags(array $tags): void + { + $this->allowedTags = $tags; + } + + public function setAllowedFilters(array $filters): void + { + $this->allowedFilters = $filters; + } + + public function setAllowedMethods(array $methods): void + { + $this->allowedMethods = []; + foreach ($methods as $class => $m) { + $this->allowedMethods[$class] = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]); + } + } + + public function setAllowedProperties(array $properties): void + { + $this->allowedProperties = $properties; + } + + public function setAllowedFunctions(array $functions): void + { + $this->allowedFunctions = $functions; + } + + public function checkSecurity($tags, $filters, $functions): void + { + foreach ($tags as $tag) { + if (!\in_array($tag, $this->allowedTags)) { + throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); + } + } + + foreach ($filters as $filter) { + if (!\in_array($filter, $this->allowedFilters)) { + throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); + } + } + + foreach ($functions as $function) { + if (!\in_array($function, $this->allowedFunctions)) { + throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); + } + } + } + + public function checkMethodAllowed($obj, $method): void + { + if ($obj instanceof Template || $obj instanceof Markup) { + return; + } + + $allowed = false; + $method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); + foreach ($this->allowedMethods as $class => $methods) { + if ($obj instanceof $class) { + $allowed = \in_array($method, $methods); + + break; + } + } + + if (!$allowed) { + $class = \get_class($obj); + throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); + } + } + + public function checkPropertyAllowed($obj, $property): void + { + $allowed = false; + foreach ($this->allowedProperties as $class => $properties) { + if ($obj instanceof $class) { + $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]); + + break; + } + } + + if (!$allowed) { + $class = \get_class($obj); + throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicyInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicyInterface.php new file mode 100644 index 0000000..4cb479d --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Sandbox/SecurityPolicyInterface.php @@ -0,0 +1,35 @@ + + */ +interface SecurityPolicyInterface +{ + /** + * @throws SecurityError + */ + public function checkSecurity($tags, $filters, $functions): void; + + /** + * @throws SecurityNotAllowedMethodError + */ + public function checkMethodAllowed($obj, $method): void; + + /** + * @throws SecurityNotAllowedPropertyError + */ + public function checkPropertyAllowed($obj, $method): void; +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Source.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Source.php new file mode 100644 index 0000000..3cb0240 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Source.php @@ -0,0 +1,51 @@ + + */ +final class Source +{ + private $code; + private $name; + private $path; + + /** + * @param string $code The template source code + * @param string $name The template logical name + * @param string $path The filesystem path of the template if any + */ + public function __construct(string $code, string $name, string $path = '') + { + $this->code = $code; + $this->name = $name; + $this->path = $path; + } + + public function getCode(): string + { + return $this->code; + } + + public function getName(): string + { + return $this->name; + } + + public function getPath(): string + { + return $this->path; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Template.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Template.php new file mode 100644 index 0000000..98ca631 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Template.php @@ -0,0 +1,424 @@ +load() + * instead, which returns an instance of \Twig\TemplateWrapper. + * + * @author Fabien Potencier + * + * @internal + */ +abstract class Template +{ + const ANY_CALL = 'any'; + const ARRAY_CALL = 'array'; + const METHOD_CALL = 'method'; + + protected $parent; + protected $parents = []; + protected $env; + protected $blocks = []; + protected $traits = []; + protected $extensions = []; + protected $sandbox; + + public function __construct(Environment $env) + { + $this->env = $env; + $this->extensions = $env->getExtensions(); + } + + /** + * Returns the template name. + * + * @return string The template name + */ + abstract public function getTemplateName(); + + /** + * Returns debug information about the template. + * + * @return array Debug information + */ + abstract public function getDebugInfo(); + + /** + * Returns information about the original template source code. + * + * @return Source + */ + abstract public function getSourceContext(); + + /** + * Returns the parent template. + * + * This method is for internal use only and should never be called + * directly. + * + * @param array $context + * + * @return Template|TemplateWrapper|false The parent template or false if there is no parent + */ + public function getParent(array $context) + { + if (null !== $this->parent) { + return $this->parent; + } + + try { + $parent = $this->doGetParent($context); + + if (false === $parent) { + return false; + } + + if ($parent instanceof self || $parent instanceof TemplateWrapper) { + return $this->parents[$parent->getSourceContext()->getName()] = $parent; + } + + if (!isset($this->parents[$parent])) { + $this->parents[$parent] = $this->loadTemplate($parent); + } + } catch (LoaderError $e) { + $e->setSourceContext(null); + $e->guess(); + + throw $e; + } + + return $this->parents[$parent]; + } + + protected function doGetParent(array $context) + { + return false; + } + + public function isTraitable() + { + return true; + } + + /** + * Displays a parent block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to display from the parent + * @param array $context The context + * @param array $blocks The current set of blocks + */ + public function displayParentBlock($name, array $context, array $blocks = []) + { + if (isset($this->traits[$name])) { + $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, $blocks, false); + } else { + throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); + } + } + + /** + * Displays a block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to display + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks + */ + public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, self $templateContext = null) + { + if ($useBlocks && isset($blocks[$name])) { + $template = $blocks[$name][0]; + $block = $blocks[$name][1]; + } elseif (isset($this->blocks[$name])) { + $template = $this->blocks[$name][0]; + $block = $this->blocks[$name][1]; + } else { + $template = null; + $block = null; + } + + // avoid RCEs when sandbox is enabled + if (null !== $template && !$template instanceof self) { + throw new \LogicException('A block must be a method on a \Twig\Template instance.'); + } + + if (null !== $template) { + try { + $template->$block($context, $blocks); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($template->getSourceContext()); + } + + // this is mostly useful for \Twig\Error\LoaderError exceptions + // see \Twig\Error\LoaderError + if (-1 === $e->getTemplateLine()) { + $e->guess(); + } + + throw $e; + } catch (\Exception $e) { + $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); + $e->guess(); + + throw $e; + } + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this); + } elseif (isset($blocks[$name])) { + throw new RuntimeError(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getSourceContext()); + } else { + throw new RuntimeError(sprintf('Block "%s" on template "%s" does not exist.', $name, $this->getTemplateName()), -1, ($templateContext ?? $this)->getSourceContext()); + } + } + + /** + * Renders a parent block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to render from the parent + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return string The rendered block + */ + public function renderParentBlock($name, array $context, array $blocks = []) + { + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + $this->displayParentBlock($name, $context, $blocks); + + return ob_get_clean(); + } + + /** + * Renders a block. + * + * This method is for internal use only and should never be called + * directly. + * + * @param string $name The block name to render + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks + * + * @return string The rendered block + */ + public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true) + { + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + $this->displayBlock($name, $context, $blocks, $useBlocks); + + return ob_get_clean(); + } + + /** + * Returns whether a block exists or not in the current context of the template. + * + * This method checks blocks defined in the current template + * or defined in "used" traits or defined in parent templates. + * + * @param string $name The block name + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return bool true if the block exists, false otherwise + */ + public function hasBlock($name, array $context, array $blocks = []) + { + if (isset($blocks[$name])) { + return $blocks[$name][0] instanceof self; + } + + if (isset($this->blocks[$name])) { + return true; + } + + if (false !== $parent = $this->getParent($context)) { + return $parent->hasBlock($name, $context); + } + + return false; + } + + /** + * Returns all block names in the current context of the template. + * + * This method checks blocks defined in the current template + * or defined in "used" traits or defined in parent templates. + * + * @param array $context The context + * @param array $blocks The current set of blocks + * + * @return array An array of block names + */ + public function getBlockNames(array $context, array $blocks = []) + { + $names = array_merge(array_keys($blocks), array_keys($this->blocks)); + + if (false !== $parent = $this->getParent($context)) { + $names = array_merge($names, $parent->getBlockNames($context)); + } + + return array_unique($names); + } + + /** + * @return Template|TemplateWrapper + */ + protected function loadTemplate($template, $templateName = null, $line = null, $index = null) + { + try { + if (\is_array($template)) { + return $this->env->resolveTemplate($template); + } + + if ($template instanceof self || $template instanceof TemplateWrapper) { + return $template; + } + + if ($template === $this->getTemplateName()) { + $class = \get_class($this); + if (false !== $pos = strrpos($class, '___', -1)) { + $class = substr($class, 0, $pos); + } + } else { + $class = $this->env->getTemplateClass($template); + } + + return $this->env->loadTemplate($class, $template, $index); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext()); + } + + if ($e->getTemplateLine() > 0) { + throw $e; + } + + if (!$line) { + $e->guess(); + } else { + $e->setTemplateLine($line); + } + + throw $e; + } + } + + /** + * @internal + * + * @return Template + */ + protected function unwrap() + { + return $this; + } + + /** + * Returns all blocks. + * + * This method is for internal use only and should never be called + * directly. + * + * @return array An array of blocks + */ + public function getBlocks() + { + return $this->blocks; + } + + public function display(array $context, array $blocks = []) + { + $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); + } + + public function render(array $context) + { + $level = ob_get_level(); + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + try { + $this->display($context); + } catch (\Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + + return ob_get_clean(); + } + + protected function displayWithErrorHandling(array $context, array $blocks = []) + { + try { + $this->doDisplay($context, $blocks); + } catch (Error $e) { + if (!$e->getSourceContext()) { + $e->setSourceContext($this->getSourceContext()); + } + + // this is mostly useful for \Twig\Error\LoaderError exceptions + // see \Twig\Error\LoaderError + if (-1 === $e->getTemplateLine()) { + $e->guess(); + } + + throw $e; + } catch (\Exception $e) { + $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); + $e->guess(); + + throw $e; + } + } + + /** + * Auto-generated method to display the template with the given context. + * + * @param array $context An array of parameters to pass to the template + * @param array $blocks An array of blocks to pass to the template + */ + abstract protected function doDisplay(array $context, array $blocks = []); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TemplateWrapper.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TemplateWrapper.php new file mode 100644 index 0000000..c9c6b07 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TemplateWrapper.php @@ -0,0 +1,109 @@ + + */ +final class TemplateWrapper +{ + private $env; + private $template; + + /** + * This method is for internal use only and should never be called + * directly (use Twig\Environment::load() instead). + * + * @internal + */ + public function __construct(Environment $env, Template $template) + { + $this->env = $env; + $this->template = $template; + } + + public function render(array $context = []): string + { + // using func_get_args() allows to not expose the blocks argument + // as it should only be used by internal code + return $this->template->render($context, \func_get_args()[1] ?? []); + } + + public function display(array $context = []) + { + // using func_get_args() allows to not expose the blocks argument + // as it should only be used by internal code + $this->template->display($context, \func_get_args()[1] ?? []); + } + + public function hasBlock(string $name, array $context = []): bool + { + return $this->template->hasBlock($name, $context); + } + + /** + * @return string[] An array of defined template block names + */ + public function getBlockNames(array $context = []): array + { + return $this->template->getBlockNames($context); + } + + public function renderBlock(string $name, array $context = []): string + { + $context = $this->env->mergeGlobals($context); + $level = ob_get_level(); + if ($this->env->isDebug()) { + ob_start(); + } else { + ob_start(function () { return ''; }); + } + try { + $this->template->displayBlock($name, $context); + } catch (\Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + + return ob_get_clean(); + } + + public function displayBlock(string $name, array $context = []) + { + $this->template->displayBlock($name, $this->env->mergeGlobals($context)); + } + + public function getSourceContext(): Source + { + return $this->template->getSourceContext(); + } + + public function getTemplateName(): string + { + return $this->template->getTemplateName(); + } + + /** + * @internal + * + * @return Template + */ + public function unwrap() + { + return $this->template; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Test/IntegrationTestCase.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Test/IntegrationTestCase.php new file mode 100644 index 0000000..1bad549 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Test/IntegrationTestCase.php @@ -0,0 +1,265 @@ + + * @author Karma Dordrak + */ +abstract class IntegrationTestCase extends TestCase +{ + /** + * @return string + */ + abstract protected function getFixturesDir(); + + /** + * @return RuntimeLoaderInterface[] + */ + protected function getRuntimeLoaders() + { + return []; + } + + /** + * @return ExtensionInterface[] + */ + protected function getExtensions() + { + return []; + } + + /** + * @return TwigFilter[] + */ + protected function getTwigFilters() + { + return []; + } + + /** + * @return TwigFunction[] + */ + protected function getTwigFunctions() + { + return []; + } + + /** + * @return TwigTest[] + */ + protected function getTwigTests() + { + return []; + } + + /** + * @dataProvider getTests + */ + public function testIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); + } + + /** + * @dataProvider getLegacyTests + * @group legacy + */ + public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); + } + + public function getTests($name, $legacyTests = false) + { + $fixturesDir = realpath($this->getFixturesDir()); + $tests = []; + + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if (!preg_match('/\.test$/', $file)) { + continue; + } + + if ($legacyTests xor false !== strpos($file->getRealpath(), '.legacy.test')) { + continue; + } + + $test = file_get_contents($file->getRealpath()); + + if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*(?:--DEPRECATION--\s*(.*?))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { + $message = $match[1]; + $condition = $match[2]; + $deprecation = $match[3]; + $templates = self::parseTemplates($match[4]); + $exception = $match[6]; + $outputs = [[null, $match[5], null, '']]; + } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*(?:--DEPRECATION--\s*(.*?))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { + $message = $match[1]; + $condition = $match[2]; + $deprecation = $match[3]; + $templates = self::parseTemplates($match[4]); + $exception = false; + preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); + } else { + throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); + } + + $tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs, $deprecation]; + } + + if ($legacyTests && empty($tests)) { + // add a dummy test to avoid a PHPUnit message + return [['not', '-', '', [], '', []]]; + } + + return $tests; + } + + public function getLegacyTests() + { + return $this->getTests('testLegacyIntegration', true); + } + + protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + if (!$outputs) { + $this->markTestSkipped('no tests to run'); + } + + if ($condition) { + eval('$ret = '.$condition.';'); + if (!$ret) { + $this->markTestSkipped($condition); + } + } + + $loader = new ArrayLoader($templates); + + foreach ($outputs as $i => $match) { + $config = array_merge([ + 'cache' => false, + 'strict_variables' => true, + ], $match[2] ? eval($match[2].';') : []); + $twig = new Environment($loader, $config); + $twig->addGlobal('global', 'global'); + foreach ($this->getRuntimeLoaders() as $runtimeLoader) { + $twig->addRuntimeLoader($runtimeLoader); + } + + foreach ($this->getExtensions() as $extension) { + $twig->addExtension($extension); + } + + foreach ($this->getTwigFilters() as $filter) { + $twig->addFilter($filter); + } + + foreach ($this->getTwigTests() as $test) { + $twig->addTest($test); + } + + foreach ($this->getTwigFunctions() as $function) { + $twig->addFunction($function); + } + + // avoid using the same PHP class name for different cases + $p = new \ReflectionProperty($twig, 'templateClassPrefix'); + $p->setAccessible(true); + $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); + + $deprecations = []; + try { + $prevHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) { + if (E_USER_DEPRECATED === $type) { + $deprecations[] = $msg; + + return true; + } + + return $prevHandler ? $prevHandler($type, $msg, $file, $line, $context) : false; + }); + + $template = $twig->load('index.twig'); + } catch (\Exception $e) { + if (false !== $exception) { + $message = $e->getMessage(); + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message))); + $last = substr($message, \strlen($message) - 1); + $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.'); + + return; + } + + throw new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + } finally { + restore_error_handler(); + } + + $this->assertSame($deprecation, implode("\n", $deprecations)); + + try { + $output = trim($template->render(eval($match[1].';')), "\n "); + } catch (\Exception $e) { + if (false !== $exception) { + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $e->getMessage()))); + + return; + } + + $e = new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + + $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); + } + + if (false !== $exception) { + list($class) = explode(':', $exception); + $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception'; + $this->assertThat(null, new $constraintClass($class)); + } + + $expected = trim($match[3], "\n "); + + if ($expected !== $output) { + printf("Compiled templates that failed on case %d:\n", $i + 1); + + foreach (array_keys($templates) as $name) { + echo "Template: $name\n"; + echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext($name)))); + } + } + $this->assertEquals($expected, $output, $message.' (in '.$file.')'); + } + } + + protected static function parseTemplates($test) + { + $templates = []; + preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; + } + + return $templates; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Test/NodeTestCase.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Test/NodeTestCase.php new file mode 100644 index 0000000..6464024 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Test/NodeTestCase.php @@ -0,0 +1,65 @@ +assertNodeCompilation($source, $node, $environment, $isPattern); + } + + public function assertNodeCompilation($source, Node $node, Environment $environment = null, $isPattern = false) + { + $compiler = $this->getCompiler($environment); + $compiler->compile($node); + + if ($isPattern) { + $this->assertStringMatchesFormat($source, trim($compiler->getSource())); + } else { + $this->assertEquals($source, trim($compiler->getSource())); + } + } + + protected function getCompiler(Environment $environment = null) + { + return new Compiler(null === $environment ? $this->getEnvironment() : $environment); + } + + protected function getEnvironment() + { + return new Environment(new ArrayLoader([])); + } + + protected function getVariableGetter($name, $line = false) + { + $line = $line > 0 ? "// line {$line}\n" : ''; + + return sprintf('%s($context["%s"] ?? null)', $line, $name); + } + + protected function getAttributeGetter() + { + return 'twig_get_attribute($this->env, $this->source, '; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Token.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Token.php new file mode 100644 index 0000000..7640fc5 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Token.php @@ -0,0 +1,178 @@ + + */ +final class Token +{ + private $value; + private $type; + private $lineno; + + const EOF_TYPE = -1; + const TEXT_TYPE = 0; + const BLOCK_START_TYPE = 1; + const VAR_START_TYPE = 2; + const BLOCK_END_TYPE = 3; + const VAR_END_TYPE = 4; + const NAME_TYPE = 5; + const NUMBER_TYPE = 6; + const STRING_TYPE = 7; + const OPERATOR_TYPE = 8; + const PUNCTUATION_TYPE = 9; + const INTERPOLATION_START_TYPE = 10; + const INTERPOLATION_END_TYPE = 11; + const ARROW_TYPE = 12; + + public function __construct(int $type, $value, int $lineno) + { + $this->type = $type; + $this->value = $value; + $this->lineno = $lineno; + } + + public function __toString() + { + return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value); + } + + /** + * Tests the current token for a type and/or a value. + * + * Parameters may be: + * * just type + * * type and value (or array of possible values) + * * just value (or array of possible values) (NAME_TYPE is used as type) + * + * @param array|string|int $type The type to test + * @param array|string|null $values The token value + */ + public function test($type, $values = null): bool + { + if (null === $values && !\is_int($type)) { + $values = $type; + $type = self::NAME_TYPE; + } + + return ($this->type === $type) && ( + null === $values || + (\is_array($values) && \in_array($this->value, $values)) || + $this->value == $values + ); + } + + public function getLine(): int + { + return $this->lineno; + } + + public function getType(): int + { + return $this->type; + } + + public function getValue() + { + return $this->value; + } + + public static function typeToString(int $type, bool $short = false): string + { + switch ($type) { + case self::EOF_TYPE: + $name = 'EOF_TYPE'; + break; + case self::TEXT_TYPE: + $name = 'TEXT_TYPE'; + break; + case self::BLOCK_START_TYPE: + $name = 'BLOCK_START_TYPE'; + break; + case self::VAR_START_TYPE: + $name = 'VAR_START_TYPE'; + break; + case self::BLOCK_END_TYPE: + $name = 'BLOCK_END_TYPE'; + break; + case self::VAR_END_TYPE: + $name = 'VAR_END_TYPE'; + break; + case self::NAME_TYPE: + $name = 'NAME_TYPE'; + break; + case self::NUMBER_TYPE: + $name = 'NUMBER_TYPE'; + break; + case self::STRING_TYPE: + $name = 'STRING_TYPE'; + break; + case self::OPERATOR_TYPE: + $name = 'OPERATOR_TYPE'; + break; + case self::PUNCTUATION_TYPE: + $name = 'PUNCTUATION_TYPE'; + break; + case self::INTERPOLATION_START_TYPE: + $name = 'INTERPOLATION_START_TYPE'; + break; + case self::INTERPOLATION_END_TYPE: + $name = 'INTERPOLATION_END_TYPE'; + break; + case self::ARROW_TYPE: + $name = 'ARROW_TYPE'; + break; + default: + throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); + } + + return $short ? $name : 'Twig\Token::'.$name; + } + + public static function typeToEnglish(int $type): string + { + switch ($type) { + case self::EOF_TYPE: + return 'end of template'; + case self::TEXT_TYPE: + return 'text'; + case self::BLOCK_START_TYPE: + return 'begin of statement block'; + case self::VAR_START_TYPE: + return 'begin of print statement'; + case self::BLOCK_END_TYPE: + return 'end of statement block'; + case self::VAR_END_TYPE: + return 'end of print statement'; + case self::NAME_TYPE: + return 'name'; + case self::NUMBER_TYPE: + return 'number'; + case self::STRING_TYPE: + return 'string'; + case self::OPERATOR_TYPE: + return 'operator'; + case self::PUNCTUATION_TYPE: + return 'punctuation'; + case self::INTERPOLATION_START_TYPE: + return 'begin of string interpolation'; + case self::INTERPOLATION_END_TYPE: + return 'end of string interpolation'; + case self::ARROW_TYPE: + return 'arrow function'; + default: + throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); + } + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AbstractTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AbstractTokenParser.php new file mode 100644 index 0000000..720ea67 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AbstractTokenParser.php @@ -0,0 +1,32 @@ + + */ +abstract class AbstractTokenParser implements TokenParserInterface +{ + /** + * @var Parser + */ + protected $parser; + + public function setParser(Parser $parser): void + { + $this->parser = $parser; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ApplyTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ApplyTokenParser.php new file mode 100644 index 0000000..f360cf9 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ApplyTokenParser.php @@ -0,0 +1,58 @@ +getLine(); + $name = $this->parser->getVarName(); + + $ref = new TempNameExpression($name, $lineno); + $ref->setAttribute('always_defined', true); + + $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + $body = $this->parser->subparse([$this, 'decideApplyEnd'], true); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new Node([ + new SetNode(true, $ref, $body, $lineno, $this->getTag()), + new PrintNode($filter, $lineno, $this->getTag()), + ]); + } + + public function decideApplyEnd(Token $token): bool + { + return $token->test('endapply'); + } + + public function getTag(): string + { + return 'apply'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php new file mode 100644 index 0000000..de54837 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/AutoEscapeTokenParser.php @@ -0,0 +1,56 @@ +getLine(); + $stream = $this->parser->getStream(); + + if ($stream->test(/* Token::BLOCK_END_TYPE */ 3)) { + $value = 'html'; + } else { + $expr = $this->parser->getExpressionParser()->parseExpression(); + if (!$expr instanceof ConstantExpression) { + throw new SyntaxError('An escaping strategy must be a string or false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + $value = $expr->getAttribute('value'); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new AutoEscapeNode($value, $body, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token): bool + { + return $token->test('endautoescape'); + } + + public function getTag(): string + { + return 'autoescape'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/BlockTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/BlockTokenParser.php new file mode 100644 index 0000000..e915b77 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/BlockTokenParser.php @@ -0,0 +1,76 @@ + + * {% block title %}{% endblock %} - My Webpage + * {% endblock %} + */ +final class BlockTokenParser extends AbstractTokenParser +{ + public function parse(Token $token): Node + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + if ($this->parser->hasBlock($name)) { + throw new SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + $this->parser->setBlock($name, $block = new BlockNode($name, new Node([]), $lineno)); + $this->parser->pushLocalScope(); + $this->parser->pushBlockStack($name); + + if ($stream->nextIf(/* Token::BLOCK_END_TYPE */ 3)) { + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + if ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) { + $value = $token->getValue(); + + if ($value != $name) { + throw new SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + } else { + $body = new Node([ + new PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno), + ]); + } + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $block->setNode('body', $body); + $this->parser->popBlockStack(); + $this->parser->popLocalScope(); + + return new BlockReferenceNode($name, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token): bool + { + return $token->test('endblock'); + } + + public function getTag(): string + { + return 'block'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DeprecatedTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DeprecatedTokenParser.php new file mode 100644 index 0000000..aaf610f --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DeprecatedTokenParser.php @@ -0,0 +1,41 @@ + + */ +final class DeprecatedTokenParser extends AbstractTokenParser +{ + public function parse(Token $token): Node + { + $expr = $this->parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); + + return new DeprecatedNode($expr, $token->getLine(), $this->getTag()); + } + + public function getTag(): string + { + return 'deprecated'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DoTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DoTokenParser.php new file mode 100644 index 0000000..050608a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/DoTokenParser.php @@ -0,0 +1,36 @@ +parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new DoNode($expr, $token->getLine(), $this->getTag()); + } + + public function getTag(): string + { + return 'do'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/EmbedTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/EmbedTokenParser.php new file mode 100644 index 0000000..30df689 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/EmbedTokenParser.php @@ -0,0 +1,71 @@ +parser->getStream(); + + $parent = $this->parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + $parentToken = $fakeParentToken = new Token(/* Token::STRING_TYPE */ 7, '__parent__', $token->getLine()); + if ($parent instanceof ConstantExpression) { + $parentToken = new Token(/* Token::STRING_TYPE */ 7, $parent->getAttribute('value'), $token->getLine()); + } elseif ($parent instanceof NameExpression) { + $parentToken = new Token(/* Token::NAME_TYPE */ 5, $parent->getAttribute('name'), $token->getLine()); + } + + // inject a fake parent to make the parent() function work + $stream->injectTokens([ + new Token(/* Token::BLOCK_START_TYPE */ 1, '', $token->getLine()), + new Token(/* Token::NAME_TYPE */ 5, 'extends', $token->getLine()), + $parentToken, + new Token(/* Token::BLOCK_END_TYPE */ 3, '', $token->getLine()), + ]); + + $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); + + // override the parent with the correct one + if ($fakeParentToken === $parentToken) { + $module->setNode('parent', $parent); + } + + $this->parser->embedTemplate($module); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token): bool + { + return $token->test('endembed'); + } + + public function getTag(): string + { + return 'embed'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ExtendsTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ExtendsTokenParser.php new file mode 100644 index 0000000..fd27514 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ExtendsTokenParser.php @@ -0,0 +1,50 @@ +parser->getStream(); + + if ($this->parser->peekBlockStack()) { + throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext()); + } elseif (!$this->parser->isMainScope()) { + throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext()); + } + + if (null !== $this->parser->getParent()) { + throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); + } + $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new Node(); + } + + public function getTag(): string + { + return 'extends'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FlushTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FlushTokenParser.php new file mode 100644 index 0000000..44e13f6 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FlushTokenParser.php @@ -0,0 +1,36 @@ +parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new FlushNode($token->getLine(), $this->getTag()); + } + + public function getTag(): string + { + return 'flush'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ForTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ForTokenParser.php new file mode 100644 index 0000000..0a6b740 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ForTokenParser.php @@ -0,0 +1,77 @@ + + * {% for user in users %} + *
  • {{ user.username|e }}
  • + * {% endfor %} + * + */ +final class ForTokenParser extends AbstractTokenParser +{ + public function parse(Token $token): Node + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); + $stream->expect(/* Token::OPERATOR_TYPE */ 8, 'in'); + $seq = $this->parser->getExpressionParser()->parseExpression(); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideForFork']); + if ('else' == $stream->next()->getValue()) { + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $else = $this->parser->subparse([$this, 'decideForEnd'], true); + } else { + $else = null; + } + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + if (\count($targets) > 1) { + $keyTarget = $targets->getNode(0); + $keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); + $valueTarget = $targets->getNode(1); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + } else { + $keyTarget = new AssignNameExpression('_key', $lineno); + $valueTarget = $targets->getNode(0); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + } + + return new ForNode($keyTarget, $valueTarget, $seq, null, $body, $else, $lineno, $this->getTag()); + } + + public function decideForFork(Token $token): bool + { + return $token->test(['else', 'endfor']); + } + + public function decideForEnd(Token $token): bool + { + return $token->test('endfor'); + } + + public function getTag(): string + { + return 'for'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FromTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FromTokenParser.php new file mode 100644 index 0000000..c1d1f4c --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/FromTokenParser.php @@ -0,0 +1,64 @@ +parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect(/* Token::NAME_TYPE */ 5, 'import'); + + $targets = []; + do { + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + $alias = $name; + if ($stream->nextIf('as')) { + $alias = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + } + + $targets[$name] = $alias; + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } while (true); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $var = new AssignNameExpression($this->parser->getVarName(), $token->getLine()); + $node = new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope()); + + foreach ($targets as $name => $alias) { + $this->parser->addImportedSymbol('function', $alias, 'macro_'.$name, $var); + } + + return $node; + } + + public function getTag(): string + { + return 'from'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IfTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IfTokenParser.php new file mode 100644 index 0000000..b84e1fa --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IfTokenParser.php @@ -0,0 +1,87 @@ + + * {% for user in users %} + *
  • {{ user.username|e }}
  • + * {% endfor %} + * + * {% endif %} + */ +final class IfTokenParser extends AbstractTokenParser +{ + public function parse(Token $token): Node + { + $lineno = $token->getLine(); + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideIfFork']); + $tests = [$expr, $body]; + $else = null; + + $end = false; + while (!$end) { + switch ($stream->next()->getValue()) { + case 'else': + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $else = $this->parser->subparse([$this, 'decideIfEnd']); + break; + + case 'elseif': + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideIfFork']); + $tests[] = $expr; + $tests[] = $body; + break; + + case 'endif': + $end = true; + break; + + default: + throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new IfNode(new Node($tests), $else, $lineno, $this->getTag()); + } + + public function decideIfFork(Token $token): bool + { + return $token->test(['elseif', 'else', 'endif']); + } + + public function decideIfEnd(Token $token): bool + { + return $token->test(['endif']); + } + + public function getTag(): string + { + return 'if'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ImportTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ImportTokenParser.php new file mode 100644 index 0000000..ca18193 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/ImportTokenParser.php @@ -0,0 +1,42 @@ +parser->getExpressionParser()->parseExpression(); + $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5, 'as'); + $var = new AssignNameExpression($this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5)->getValue(), $token->getLine()); + $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3); + + $this->parser->addImportedSymbol('template', $var->getAttribute('name')); + + return new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope()); + } + + public function getTag(): string + { + return 'import'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IncludeTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IncludeTokenParser.php new file mode 100644 index 0000000..47d25da --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/IncludeTokenParser.php @@ -0,0 +1,67 @@ +parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + protected function parseArguments() + { + $stream = $this->parser->getStream(); + + $ignoreMissing = false; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'ignore')) { + $stream->expect(/* Token::NAME_TYPE */ 5, 'missing'); + + $ignoreMissing = true; + } + + $variables = null; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'with')) { + $variables = $this->parser->getExpressionParser()->parseExpression(); + } + + $only = false; + if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'only')) { + $only = true; + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return [$variables, $only, $ignoreMissing]; + } + + public function getTag(): string + { + return 'include'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/MacroTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/MacroTokenParser.php new file mode 100644 index 0000000..0487ef4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/MacroTokenParser.php @@ -0,0 +1,64 @@ + + * {% endmacro %} + */ +final class MacroTokenParser extends AbstractTokenParser +{ + public function parse(Token $token): Node + { + $lineno = $token->getLine(); + $stream = $this->parser->getStream(); + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $this->parser->pushLocalScope(); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + if ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) { + $value = $token->getValue(); + + if ($value != $name) { + throw new SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } + $this->parser->popLocalScope(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $this->parser->setMacro($name, new MacroNode($name, new BodyNode([$body]), $arguments, $lineno, $this->getTag())); + + return new Node(); + } + + public function decideBlockEnd(Token $token): bool + { + return $token->test('endmacro'); + } + + public function getTag(): string + { + return 'macro'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SandboxTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SandboxTokenParser.php new file mode 100644 index 0000000..b6cb530 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SandboxTokenParser.php @@ -0,0 +1,64 @@ +parser->getStream(); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + // in a sandbox tag, only include tags are allowed + if (!$body instanceof IncludeNode) { + foreach ($body as $node) { + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { + continue; + } + + if (!$node instanceof IncludeNode) { + throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); + } + } + } + + return new SandboxNode($body, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Token $token): bool + { + return $token->test('endsandbox'); + } + + public function getTag(): string + { + return 'sandbox'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SetTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SetTokenParser.php new file mode 100644 index 0000000..a9fb75a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/SetTokenParser.php @@ -0,0 +1,71 @@ +getLine(); + $stream = $this->parser->getStream(); + $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); + + $capture = false; + if ($stream->nextIf(/* Token::OPERATOR_TYPE */ 8, '=')) { + $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + if (\count($names) !== \count($values)) { + throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + } else { + $capture = true; + + if (\count($names) > 1) { + throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + } + + return new SetNode($capture, $names, $values, $lineno, $this->getTag()); + } + + public function decideBlockEnd(Token $token): bool + { + return $token->test('endset'); + } + + public function getTag(): string + { + return 'set'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/TokenParserInterface.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/TokenParserInterface.php new file mode 100644 index 0000000..bb8db3e --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/TokenParserInterface.php @@ -0,0 +1,46 @@ + + */ +interface TokenParserInterface +{ + /** + * Sets the parser associated with this token parser. + */ + public function setParser(Parser $parser): void; + + /** + * Parses a token and returns a node. + * + * @return Node + * + * @throws SyntaxError + */ + public function parse(Token $token); + + /** + * Gets the tag name associated with this token parser. + * + * @return string + */ + public function getTag(); +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/UseTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/UseTokenParser.php new file mode 100644 index 0000000..c0dba78 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/UseTokenParser.php @@ -0,0 +1,71 @@ +parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + + if (!$template instanceof ConstantExpression) { + throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + } + + $targets = []; + if ($stream->nextIf('with')) { + do { + $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + + $alias = $name; + if ($stream->nextIf('as')) { + $alias = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); + } + + $targets[$name] = new ConstantExpression($alias, -1); + + if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { + break; + } + } while (true); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)])); + + return new Node(); + } + + public function getTag(): string + { + return 'use'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/WithTokenParser.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/WithTokenParser.php new file mode 100644 index 0000000..fd548b0 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenParser/WithTokenParser.php @@ -0,0 +1,54 @@ + + */ +final class WithTokenParser extends AbstractTokenParser +{ + public function parse(Token $token): Node + { + $stream = $this->parser->getStream(); + + $variables = null; + $only = false; + if (!$stream->test(/* Token::BLOCK_END_TYPE */ 3)) { + $variables = $this->parser->getExpressionParser()->parseExpression(); + $only = (bool) $stream->nextIf(/* Token::NAME_TYPE */ 5, 'only'); + } + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + $body = $this->parser->subparse([$this, 'decideWithEnd'], true); + + $stream->expect(/* Token::BLOCK_END_TYPE */ 3); + + return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag()); + } + + public function decideWithEnd(Token $token): bool + { + return $token->test('endwith'); + } + + public function getTag(): string + { + return 'with'; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenStream.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenStream.php new file mode 100644 index 0000000..1eac11a --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TokenStream.php @@ -0,0 +1,132 @@ + + */ +final class TokenStream +{ + private $tokens; + private $current = 0; + private $source; + + public function __construct(array $tokens, Source $source = null) + { + $this->tokens = $tokens; + $this->source = $source ?: new Source('', ''); + } + + public function __toString() + { + return implode("\n", $this->tokens); + } + + public function injectTokens(array $tokens) + { + $this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current)); + } + + /** + * Sets the pointer to the next token and returns the old one. + */ + public function next(): Token + { + if (!isset($this->tokens[++$this->current])) { + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); + } + + return $this->tokens[$this->current - 1]; + } + + /** + * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. + * + * @return Token|null The next token if the condition is true, null otherwise + */ + public function nextIf($primary, $secondary = null) + { + if ($this->tokens[$this->current]->test($primary, $secondary)) { + return $this->next(); + } + } + + /** + * Tests a token and returns it or throws a syntax error. + */ + public function expect($type, $value = null, string $message = null): Token + { + $token = $this->tokens[$this->current]; + if (!$token->test($type, $value)) { + $line = $token->getLine(); + throw new SyntaxError(sprintf('%sUnexpected token "%s"%s ("%s" expected%s).', + $message ? $message.'. ' : '', + Token::typeToEnglish($token->getType()), + $token->getValue() ? sprintf(' of value "%s"', $token->getValue()) : '', + Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), + $line, + $this->source + ); + } + $this->next(); + + return $token; + } + + /** + * Looks at the next token. + */ + public function look(int $number = 1): Token + { + if (!isset($this->tokens[$this->current + $number])) { + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); + } + + return $this->tokens[$this->current + $number]; + } + + /** + * Tests the current token. + */ + public function test($primary, $secondary = null): bool + { + return $this->tokens[$this->current]->test($primary, $secondary); + } + + /** + * Checks if end of stream was reached. + */ + public function isEOF(): bool + { + return /* Token::EOF_TYPE */ -1 === $this->tokens[$this->current]->getType(); + } + + public function getCurrent(): Token + { + return $this->tokens[$this->current]; + } + + /** + * Gets the source associated with this stream. + * + * @internal + */ + public function getSourceContext(): Source + { + return $this->source; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFilter.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFilter.php new file mode 100644 index 0000000..94e5f9b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFilter.php @@ -0,0 +1,134 @@ + + * + * @see https://twig.symfony.com/doc/templates.html#filters + */ +final class TwigFilter +{ + private $name; + private $callable; + private $options; + private $arguments = []; + + /** + * @param callable|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation. + */ + public function __construct(string $name, $callable = null, array $options = []) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'pre_escape' => null, + 'preserves_safety' => null, + 'node_class' => FilterExpression::class, + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName(): string + { + return $this->name; + } + + /** + * Returns the callable to execute for this filter. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass(): string + { + return $this->options['node_class']; + } + + public function setArguments(array $arguments): void + { + $this->arguments = $arguments; + } + + public function getArguments(): array + { + return $this->arguments; + } + + public function needsEnvironment(): bool + { + return $this->options['needs_environment']; + } + + public function needsContext(): bool + { + return $this->options['needs_context']; + } + + public function getSafe(Node $filterArgs): ?array + { + if (null !== $this->options['is_safe']) { + return $this->options['is_safe']; + } + + if (null !== $this->options['is_safe_callback']) { + return $this->options['is_safe_callback']($filterArgs); + } + + return null; + } + + public function getPreservesSafety(): ?array + { + return $this->options['preserves_safety']; + } + + public function getPreEscape(): ?string + { + return $this->options['pre_escape']; + } + + public function isVariadic(): bool + { + return $this->options['is_variadic']; + } + + public function isDeprecated(): bool + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion(): string + { + return \is_bool($this->options['deprecated']) ? '' : $this->options['deprecated']; + } + + public function getAlternative(): ?string + { + return $this->options['alternative']; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFunction.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFunction.php new file mode 100644 index 0000000..494d45b --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigFunction.php @@ -0,0 +1,122 @@ + + * + * @see https://twig.symfony.com/doc/templates.html#functions + */ +final class TwigFunction +{ + private $name; + private $callable; + private $options; + private $arguments = []; + + /** + * @param callable|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation. + */ + public function __construct(string $name, $callable = null, array $options = []) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'needs_environment' => false, + 'needs_context' => false, + 'is_variadic' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'node_class' => FunctionExpression::class, + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName(): string + { + return $this->name; + } + + /** + * Returns the callable to execute for this function. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass(): string + { + return $this->options['node_class']; + } + + public function setArguments(array $arguments): void + { + $this->arguments = $arguments; + } + + public function getArguments(): array + { + return $this->arguments; + } + + public function needsEnvironment(): bool + { + return $this->options['needs_environment']; + } + + public function needsContext(): bool + { + return $this->options['needs_context']; + } + + public function getSafe(Node $functionArgs): ?array + { + if (null !== $this->options['is_safe']) { + return $this->options['is_safe']; + } + + if (null !== $this->options['is_safe_callback']) { + return $this->options['is_safe_callback']($functionArgs); + } + + return []; + } + + public function isVariadic(): bool + { + return (bool) $this->options['is_variadic']; + } + + public function isDeprecated(): bool + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion(): string + { + return \is_bool($this->options['deprecated']) ? '' : $this->options['deprecated']; + } + + public function getAlternative(): ?string + { + return $this->options['alternative']; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigTest.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigTest.php new file mode 100644 index 0000000..170bba4 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/TwigTest.php @@ -0,0 +1,94 @@ + + * + * @see https://twig.symfony.com/doc/templates.html#test-operator + */ +final class TwigTest +{ + private $name; + private $callable; + private $options; + private $arguments = []; + + /** + * @param callable|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation. + */ + public function __construct(string $name, $callable = null, array $options = []) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge([ + 'is_variadic' => false, + 'node_class' => TestExpression::class, + 'deprecated' => false, + 'alternative' => null, + ], $options); + } + + public function getName(): string + { + return $this->name; + } + + /** + * Returns the callable to execute for this test. + * + * @return callable|null + */ + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass(): string + { + return $this->options['node_class']; + } + + public function setArguments(array $arguments): void + { + $this->arguments = $arguments; + } + + public function getArguments(): array + { + return $this->arguments; + } + + public function isVariadic(): bool + { + return (bool) $this->options['is_variadic']; + } + + public function isDeprecated(): bool + { + return (bool) $this->options['deprecated']; + } + + public function getDeprecatedVersion(): string + { + return \is_bool($this->options['deprecated']) ? '' : $this->options['deprecated']; + } + + public function getAlternative(): ?string + { + return $this->options['alternative']; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Util/DeprecationCollector.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Util/DeprecationCollector.php new file mode 100644 index 0000000..51345e0 --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Util/DeprecationCollector.php @@ -0,0 +1,77 @@ + + */ +final class DeprecationCollector +{ + private $twig; + + public function __construct(Environment $twig) + { + $this->twig = $twig; + } + + /** + * Returns deprecations for templates contained in a directory. + * + * @param string $dir A directory where templates are stored + * @param string $ext Limit the loaded templates by extension + * + * @return array An array of deprecations + */ + public function collectDir(string $dir, string $ext = '.twig'): array + { + $iterator = new \RegexIterator( + new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY + ), '{'.preg_quote($ext).'$}' + ); + + return $this->collect(new TemplateDirIterator($iterator)); + } + + /** + * Returns deprecations for passed templates. + * + * @param \Traversable $iterator An iterator of templates (where keys are template names and values the contents of the template) + * + * @return array An array of deprecations + */ + public function collect(\Traversable $iterator): array + { + $deprecations = []; + set_error_handler(function ($type, $msg) use (&$deprecations) { + if (E_USER_DEPRECATED === $type) { + $deprecations[] = $msg; + } + }); + + foreach ($iterator as $name => $contents) { + try { + $this->twig->parse($this->twig->tokenize(new Source($contents, $name))); + } catch (SyntaxError $e) { + // ignore templates containing syntax errors + } + } + + restore_error_handler(); + + return $deprecations; + } +} diff --git a/system/templateEngines/Twig/Twig3x/twig/twig/src/Util/TemplateDirIterator.php b/system/templateEngines/Twig/Twig3x/twig/twig/src/Util/TemplateDirIterator.php new file mode 100644 index 0000000..c7339fd --- /dev/null +++ b/system/templateEngines/Twig/Twig3x/twig/twig/src/Util/TemplateDirIterator.php @@ -0,0 +1,28 @@ + + */ +class TemplateDirIterator extends \IteratorIterator +{ + public function current() + { + return file_get_contents(parent::current()); + } + + public function key() + { + return (string) parent::key(); + } +} diff --git a/system/templateEngines/Twig/autoload.php b/system/templateEngines/Twig/autoload.php index a1f1e4a..afb7ebe 100644 --- a/system/templateEngines/Twig/autoload.php +++ b/system/templateEngines/Twig/autoload.php @@ -1,31 +1,29 @@ ') == false) { - $folderLoad = 'Twig1x'; - } else { - $folderLoad = 'Twig2x'; - } - // base directory for the namespace prefix - $base_dir = __DIR__ . '/'.$folderLoad.'/'; - // does the class use the namespace prefix? - $len = strlen($prefix); - if (strncmp($prefix, $class, $len) !== 0) { - // no, move to the next registered autoloader - return; - } - // get the relative class name - $relative_class = substr($class, $len); - // replace the namespace prefix with the base directory, replace namespace - // separators with directory separators in the relative class name, append - // with .php - $file = $base_dir . str_replace('_', '/', $relative_class) . '.php'; - // if the file exists, require it - if (file_exists($file)) { - require $file; +if (version_compare(phpversion(), '7.0.0', '>') == false) { + define('TwigFolderLoad', 'Twig1x'); + define('TwigLoaderFilesystem', 'Twig_Loader_Filesystem'); + define('TwigEnvironment', 'Twig_Environment'); + define('TwigSimpleFilter', 'Twig_SimpleFilter'); + define('TwigExtensionDebug', 'Twig_Extension_Debug'); + +} else { + define('TwigLoaderFilesystem', '\Twig\Loader\FilesystemLoader'); + define('TwigEnvironment', '\Twig\Environment'); + define('TwigSimpleFilter', '\Twig\TwigFilter'); + define('TwigExtensionDebug', '\Twig\Extension\DebugExtension'); + + if (version_compare(phpversion(), '7.2.0', '>') == false) { + define('TwigFolderLoad', 'Twig2x'); + } else { + define('TwigFolderLoad', 'Twig3x'); } -}); +} + +include_once TwigFolderLoad."/autoload.php"; + -include __DIR__."/Extension/ExacTITranslate.php"; \ No newline at end of file +if(TwigFolderLoad == 'Twig1x') { + if (file_exists(__DIR__ . "/Extension/ExacTITranslate1x.php")) include __DIR__ . "/Extension/ExacTITranslate1x.php"; +} else { + if (file_exists(__DIR__ . "/Extension/ExacTITranslate.php")) include __DIR__ . "/Extension/ExacTITranslate.php"; +} \ No newline at end of file diff --git a/system/templateEngines/smarty/Autoloader.php b/system/templateEngines/smarty/Autoloader.php index e4dc450..c09361b 100644 --- a/system/templateEngines/smarty/Autoloader.php +++ b/system/templateEngines/smarty/Autoloader.php @@ -90,7 +90,7 @@ class Smarty_Autoloader */ public static function autoload($class) { - if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) { + if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) { return; } $_class = strtolower($class); diff --git a/system/templateEngines/smarty/Smarty.class.php b/system/templateEngines/smarty/Smarty.class.php index a896992..44b77a8 100644 --- a/system/templateEngines/smarty/Smarty.class.php +++ b/system/templateEngines/smarty/Smarty.class.php @@ -27,7 +27,7 @@ * @author Uwe Tews * @author Rodney Rehm * @package Smarty - * @version 3.1.33 + * @version 3.1.34-dev */ /** * set SMARTY_DIR to absolute path to Smarty library files. @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.33'; + const SMARTY_VERSION = '3.1.34-dev-7'; /** * define variable scopes */ diff --git a/system/templateEngines/smarty/plugins/modifier.date_format.php b/system/templateEngines/smarty/plugins/modifier.date_format.php index 23b6943..c8e88c5 100644 --- a/system/templateEngines/smarty/plugins/modifier.date_format.php +++ b/system/templateEngines/smarty/plugins/modifier.date_format.php @@ -41,9 +41,9 @@ function smarty_modifier_date_format($string, $format = null, $default_date = '' } $is_loaded = true; } - if ($string !== '' && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') { + if (!empty($string) && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') { $timestamp = smarty_make_timestamp($string); - } elseif ($default_date !== '') { + } elseif (!empty($default_date)) { $timestamp = smarty_make_timestamp($default_date); } else { return; diff --git a/system/templateEngines/smarty/sysplugins/smarty_internal_compile_insert.php b/system/templateEngines/smarty/sysplugins/smarty_internal_compile_insert.php index 56fbc56..4bdc395 100644 --- a/system/templateEngines/smarty/sysplugins/smarty_internal_compile_insert.php +++ b/system/templateEngines/smarty/sysplugins/smarty_internal_compile_insert.php @@ -151,6 +151,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; } } + $compiler->template->compiled->has_nocache_code = true; return $_output; } } diff --git a/system/templateEngines/smarty/sysplugins/smarty_internal_compile_private_php.php b/system/templateEngines/smarty/sysplugins/smarty_internal_compile_private_php.php index a3cf0a2..ff48c6f 100644 --- a/system/templateEngines/smarty/sysplugins/smarty_internal_compile_private_php.php +++ b/system/templateEngines/smarty/sysplugins/smarty_internal_compile_private_php.php @@ -47,7 +47,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase new Smarty_Internal_ParseTree_Tag( $compiler->parser, $compiler->processNocacheCode( - "", + "\n", true ) ) @@ -77,7 +77,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase new Smarty_Internal_ParseTree_Tag( $compiler->parser, $compiler->processNocacheCode( - "", + "\n", true ) ) diff --git a/system/templateEngines/smarty/sysplugins/smarty_internal_runtime_inheritance.php b/system/templateEngines/smarty/sysplugins/smarty_internal_runtime_inheritance.php index 6392d4c..8f7f02d 100644 --- a/system/templateEngines/smarty/sysplugins/smarty_internal_runtime_inheritance.php +++ b/system/templateEngines/smarty/sysplugins/smarty_internal_runtime_inheritance.php @@ -150,7 +150,7 @@ class Smarty_Internal_Runtime_Inheritance return; } // make sure we got child block of child template of current block - while ($block->child && $block->tplIndex <= $block->child->tplIndex) { + while ($block->child && $block->child->child && $block->tplIndex <= $block->child->tplIndex) { $block->child = $block->child->child; } $this->process($tpl, $block); diff --git a/system/templateEngines/smarty/sysplugins/smarty_internal_templatelexer.php b/system/templateEngines/smarty/sysplugins/smarty_internal_templatelexer.php index c6c49ef..d29c39b 100644 --- a/system/templateEngines/smarty/sysplugins/smarty_internal_templatelexer.php +++ b/system/templateEngines/smarty/sysplugins/smarty_internal_templatelexer.php @@ -215,9 +215,23 @@ class Smarty_Internal_Templatelexer */ private $yy_global_pattern5 = null; - private $_yy_state = 1; + /** + * preg token pattern for text + * + * @var null + */ + private $yy_global_text = null; + + /** + * preg token pattern for literal + * + * @var null + */ + private $yy_global_literal = null; - private $_yy_stack = array(); + private $_yy_state = 1; + + private $_yy_stack = array(); /** * constructor @@ -319,7 +333,7 @@ class Smarty_Internal_Templatelexer { if (!isset($this->yy_global_pattern1)) { $this->yy_global_pattern1 = - $this->replace("/\G([{][}])|\G((SMARTYldel)SMARTYal[*])|\G((SMARTYldel)SMARTYalphp([ ].*?)?SMARTYrdel|(SMARTYldel)SMARTYal[\/]phpSMARTYrdel)|\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([<][?]((php\\s+|=)|\\s+)|[<][%]|[<][?]xml\\s+|[<]script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*[>]|[?][>]|[%][>])|\G((.*?)(?=((SMARTYldel)SMARTYal|[<][?]((php\\s+|=)|\\s+)|[<][%]|[<][?]xml\\s+|[<]script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*[>]|[?][>]|[%][>]SMARTYliteral))|[\s\S]+)/isS"); + $this->replace("/\G([{][}])|\G((SMARTYldel)SMARTYal[*])|\G((SMARTYldel)SMARTYalphp([ ].*?)?SMARTYrdel|(SMARTYldel)SMARTYal[\/]phpSMARTYrdel)|\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([<][?]((php\\s+|=)|\\s+)|[<][%]|[<][?]xml\\s+|[<]script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*[>]|[?][>]|[%][>])|\G([\S\s])/isS"); } if (!isset($this->dataLength)) { $this->dataLength = strlen($this->data); @@ -336,11 +350,8 @@ class Smarty_Internal_Templatelexer } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr( - $this->data, - $this->counter, - 5 - ) . '... state TEXT'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state TEXT'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number @@ -379,6 +390,7 @@ class Smarty_Internal_Templatelexer public function yy_r1_2() { + $to = $this->dataLength; preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[ 0 ][ 1 ])) { @@ -425,6 +437,16 @@ class Smarty_Internal_Templatelexer public function yy_r1_19() { + if (!isset($this->yy_global_text)) { + $this->yy_global_text = + $this->replace('/(SMARTYldel)SMARTYal|[<][?]((php\s+|=)|\s+)|[<][%]|[<][?]xml\s+|[<]script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*[>]|[?][>]|[%][>]SMARTYliteral/isS'); + } + $to = $this->dataLength; + preg_match($this->yy_global_text, $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); + if (isset($match[ 0 ][ 1 ])) { + $to = $match[ 0 ][ 1 ]; + } + $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_TEXT; } @@ -449,11 +471,8 @@ class Smarty_Internal_Templatelexer } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr( - $this->data, - $this->counter, - 5 - ) . '... state TAG'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state TAG'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number @@ -573,7 +592,7 @@ class Smarty_Internal_Templatelexer { if (!isset($this->yy_global_pattern3)) { $this->yy_global_pattern3 = - $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS"); + $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G(array\\s*[(]\\s*)|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS"); } if (!isset($this->dataLength)) { $this->dataLength = strlen($this->data); @@ -590,11 +609,8 @@ class Smarty_Internal_Templatelexer } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr( - $this->data, - $this->counter, - 5 - ) . '... state TAGBODY'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state TAGBODY'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number @@ -772,10 +788,15 @@ class Smarty_Internal_Templatelexer public function yy_r3_42() { - $this->token = Smarty_Internal_Templateparser::TP_HATCH; + $this->token = Smarty_Internal_Templateparser::TP_ARRAYOPEN; } public function yy_r3_43() + { + $this->token = Smarty_Internal_Templateparser::TP_HATCH; + } + + public function yy_r3_44() { // resolve conflicts with shorttag and right_delimiter starting with '=' if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === @@ -788,73 +809,73 @@ class Smarty_Internal_Templatelexer } } - public function yy_r3_44() + public function yy_r3_45() { $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE; } - public function yy_r3_47() + public function yy_r3_48() { $this->token = Smarty_Internal_Templateparser::TP_ID; } - public function yy_r3_48() + public function yy_r3_49() { $this->token = Smarty_Internal_Templateparser::TP_INTEGER; } - public function yy_r3_49() + public function yy_r3_50() { $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; $this->yypopstate(); } - public function yy_r3_50() + public function yy_r3_51() { $this->token = Smarty_Internal_Templateparser::TP_VERT; } - public function yy_r3_51() + public function yy_r3_52() { $this->token = Smarty_Internal_Templateparser::TP_DOT; } - public function yy_r3_52() + public function yy_r3_53() { $this->token = Smarty_Internal_Templateparser::TP_COMMA; } - public function yy_r3_53() + public function yy_r3_54() { $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; } - public function yy_r3_54() + public function yy_r3_55() { $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; } - public function yy_r3_55() + public function yy_r3_56() { $this->token = Smarty_Internal_Templateparser::TP_COLON; } - public function yy_r3_56() + public function yy_r3_57() { $this->token = Smarty_Internal_Templateparser::TP_QMARK; } - public function yy_r3_57() + public function yy_r3_58() { $this->token = Smarty_Internal_Templateparser::TP_HEX; } - public function yy_r3_58() + public function yy_r3_59() { $this->token = Smarty_Internal_Templateparser::TP_SPACE; } // end function - public function yy_r3_59() + public function yy_r3_60() { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } @@ -863,7 +884,7 @@ class Smarty_Internal_Templatelexer { if (!isset($this->yy_global_pattern4)) { $this->yy_global_pattern4 = - $this->replace("/\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((.*?)(?=(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel))/isS"); + $this->replace("/\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G([\S\s])/isS"); } if (!isset($this->dataLength)) { $this->dataLength = strlen($this->data); @@ -880,11 +901,8 @@ class Smarty_Internal_Templatelexer } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr( - $this->data, - $this->counter, - 5 - ) . '... state LITERAL'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state LITERAL'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number @@ -935,6 +953,17 @@ class Smarty_Internal_Templatelexer public function yy_r4_5() { + if (!isset($this->yy_global_literal)) { + $this->yy_global_literal = $this->replace('/(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel/isS'); + } + $to = $this->dataLength; + preg_match($this->yy_global_literal, $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); + if (isset($match[ 0 ][ 1 ])) { + $to = $match[ 0 ][ 1 ]; + } else { + $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); + } + $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_LITERAL; } // end function @@ -942,7 +971,7 @@ class Smarty_Internal_Templatelexer { if (!isset($this->yy_global_pattern5)) { $this->yy_global_pattern5 = - $this->replace("/\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=((SMARTYldel)SMARTYal|\\$|`\\$|\"SMARTYliteral)))/isS"); + $this->replace("/\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=((SMARTYldel)SMARTYal|\\$|`\\$|\"SMARTYliteral)))|\G([\S\s])/isS"); } if (!isset($this->dataLength)) { $this->dataLength = strlen($this->data); @@ -959,11 +988,8 @@ class Smarty_Internal_Templatelexer } if (empty($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr( - $this->data, - $this->counter, - 5 - ) . '... state DOUBLEQUOTEDSTRING'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number @@ -1057,4 +1083,13 @@ class Smarty_Internal_Templatelexer { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } + + public function yy_r5_22() + { + $to = $this->dataLength; + $this->value = substr($this->data, $this->counter, $to - $this->counter); + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } } + + \ No newline at end of file diff --git a/system/templateEngines/smarty/sysplugins/smarty_internal_templateparser.php b/system/templateEngines/smarty/sysplugins/smarty_internal_templateparser.php index b008715..a26e7a1 100644 --- a/system/templateEngines/smarty/sysplugins/smarty_internal_templateparser.php +++ b/system/templateEngines/smarty/sysplugins/smarty_internal_templateparser.php @@ -4,11 +4,9 @@ class TP_yyStackEntry { public $stateno; /* The state-number */ public $major; /* The major token value. This is the code - * number for the token at this stack level - */ - public $minor; /* The user-supplied minor token value. This - * is the value of the token - */ + ** number for the token at this stack level */ + public $minor; /* The user-supplied minor token value. This + ** is the value of the token */ } // line 11 "../smarty/lexer/smarty_internal_templateparser.y" @@ -29,43 +27,43 @@ class Smarty_Internal_Templateparser const ERR3 = 'PHP in template not allowed. Use SmartyBC to enable it'; const TP_VERT = 1; const TP_COLON = 2; - const TP_UNIMATH = 3; - const TP_PHP = 4; - const TP_TEXT = 5; - const TP_STRIPON = 6; - const TP_STRIPOFF = 7; - const TP_LITERALSTART = 8; - const TP_LITERALEND = 9; - const TP_LITERAL = 10; - const TP_SIMPELOUTPUT = 11; - const TP_SIMPLETAG = 12; - const TP_SMARTYBLOCKCHILDPARENT = 13; - const TP_LDEL = 14; - const TP_RDEL = 15; - const TP_DOLLARID = 16; - const TP_EQUAL = 17; - const TP_ID = 18; - const TP_PTR = 19; - const TP_LDELMAKENOCACHE = 20; - const TP_LDELIF = 21; - const TP_LDELFOR = 22; - const TP_SEMICOLON = 23; - const TP_INCDEC = 24; - const TP_TO = 25; - const TP_STEP = 26; - const TP_LDELFOREACH = 27; - const TP_SPACE = 28; - const TP_AS = 29; - const TP_APTR = 30; - const TP_LDELSETFILTER = 31; - const TP_CLOSETAG = 32; - const TP_LDELSLASH = 33; - const TP_ATTR = 34; - const TP_INTEGER = 35; - const TP_COMMA = 36; - const TP_OPENP = 37; - const TP_CLOSEP = 38; - const TP_MATH = 39; + const TP_PHP = 3; + const TP_TEXT = 4; + const TP_STRIPON = 5; + const TP_STRIPOFF = 6; + const TP_LITERALSTART = 7; + const TP_LITERALEND = 8; + const TP_LITERAL = 9; + const TP_SIMPELOUTPUT = 10; + const TP_SIMPLETAG = 11; + const TP_SMARTYBLOCKCHILDPARENT = 12; + const TP_LDEL = 13; + const TP_RDEL = 14; + const TP_DOLLARID = 15; + const TP_EQUAL = 16; + const TP_ID = 17; + const TP_PTR = 18; + const TP_LDELMAKENOCACHE = 19; + const TP_LDELIF = 20; + const TP_LDELFOR = 21; + const TP_SEMICOLON = 22; + const TP_INCDEC = 23; + const TP_TO = 24; + const TP_STEP = 25; + const TP_LDELFOREACH = 26; + const TP_SPACE = 27; + const TP_AS = 28; + const TP_APTR = 29; + const TP_LDELSETFILTER = 30; + const TP_CLOSETAG = 31; + const TP_LDELSLASH = 32; + const TP_ATTR = 33; + const TP_INTEGER = 34; + const TP_COMMA = 35; + const TP_OPENP = 36; + const TP_CLOSEP = 37; + const TP_MATH = 38; + const TP_UNIMATH = 39; const TP_ISIN = 40; const TP_QMARK = 41; const TP_NOT = 42; @@ -85,724 +83,819 @@ class Smarty_Internal_Templateparser const TP_SLOGOP = 56; const TP_TLOGOP = 57; const TP_SINGLECOND = 58; - const TP_QUOTE = 59; - const TP_BACKTICK = 60; - const YY_NO_ACTION = 511; - const YY_ACCEPT_ACTION = 510; - const YY_ERROR_ACTION = 509; - const YY_SZ_ACTTAB = 2076; - const YY_SHIFT_USE_DFLT = -23; - const YY_SHIFT_MAX = 227; - const YY_REDUCE_USE_DFLT = -68; - const YY_REDUCE_MAX = 176; - const YYNOCODE = 108; + const TP_ARRAYOPEN = 59; + const TP_QUOTE = 60; + const TP_BACKTICK = 61; + const YY_NO_ACTION = 516; + const YY_ACCEPT_ACTION = 515; + const YY_ERROR_ACTION = 514; + const YY_SZ_ACTTAB = 2071; + const YY_SHIFT_USE_DFLT = -31; + const YY_SHIFT_MAX = 230; + const YY_REDUCE_USE_DFLT = -91; + const YY_REDUCE_MAX = 178; + const YYNOCODE = 110; const YYSTACKDEPTH = 500; - const YYNSTATE = 323; - const YYNRULE = 186; - const YYERRORSYMBOL = 61; + const YYNSTATE = 327; + const YYNRULE = 187; + const YYERRORSYMBOL = 62; const YYERRSYMDT = 'yy0'; const YYFALLBACK = 0; public static $yy_action = array( - 42, 266, 267, 379, 115, 202, 27, 204, 260, 235, - 237, 1, 17, 125, 94, 182, 379, 215, 10, 79, - 317, 168, 379, 12, 107, 425, 308, 318, 224, 298, - 218, 129, 189, 292, 21, 203, 425, 27, 11, 39, - 38, 299, 219, 17, 213, 385, 191, 245, 77, 3, - 303, 315, 42, 385, 160, 385, 75, 29, 385, 95, - 260, 235, 237, 1, 385, 126, 385, 193, 385, 215, - 10, 79, 80, 290, 145, 226, 107, 148, 172, 150, - 224, 298, 218, 85, 217, 315, 21, 280, 101, 280, - 141, 39, 38, 299, 219, 20, 287, 183, 191, 232, - 77, 3, 42, 315, 16, 176, 316, 172, 75, 275, - 260, 235, 237, 1, 167, 128, 236, 193, 319, 215, - 10, 79, 345, 40, 14, 257, 107, 319, 345, 5, - 224, 298, 218, 89, 217, 315, 30, 292, 172, 203, - 74, 39, 38, 299, 219, 132, 287, 205, 191, 74, - 77, 3, 42, 315, 210, 194, 310, 99, 75, 345, - 260, 235, 237, 1, 425, 126, 87, 179, 319, 215, - 10, 79, 345, 95, 195, 425, 107, 272, 345, 176, - 224, 298, 218, 315, 199, 115, 21, 128, 278, 209, - 74, 39, 38, 299, 219, 94, 287, 226, 191, 129, - 77, 3, 42, 315, 277, 309, 11, 308, 75, 13, - 260, 235, 237, 1, 163, 127, 425, 193, 319, 215, - 10, 79, 77, 254, 19, 315, 107, 425, 137, 34, - 224, 298, 218, 196, 217, 33, 21, 220, 280, 159, - 74, 39, 38, 299, 219, 196, 287, 8, 191, 162, - 77, 3, 42, 315, 294, 222, 196, 438, 75, 378, - 260, 235, 237, 1, 438, 126, 16, 193, 271, 215, - 10, 79, 378, 172, 302, 315, 107, 175, 378, 267, - 224, 298, 218, 27, 178, 252, 21, 164, 296, 17, - 83, 39, 38, 299, 219, 196, 287, 205, 191, 170, - 77, 3, 42, 315, 270, 18, 144, 99, 75, 346, - 260, 235, 237, 1, 142, 126, 280, 177, 84, 215, - 10, 79, 346, 172, 280, 4, 107, 95, 346, 321, - 224, 298, 218, 438, 217, 131, 21, 321, 426, 24, - 438, 39, 38, 299, 219, 196, 287, 205, 191, 426, - 77, 3, 42, 315, 201, 9, 101, 99, 75, 381, - 260, 235, 237, 1, 149, 124, 102, 193, 22, 215, - 10, 79, 381, 315, 99, 231, 107, 311, 381, 425, - 224, 298, 218, 23, 217, 319, 7, 207, 196, 17, - 425, 39, 38, 299, 219, 307, 287, 36, 191, 154, - 77, 3, 42, 315, 161, 296, 227, 74, 75, 280, - 260, 235, 237, 1, 16, 91, 273, 76, 312, 215, - 10, 79, 317, 208, 190, 12, 107, 176, 196, 318, - 224, 298, 218, 135, 217, 321, 21, 196, 35, 95, - 263, 39, 38, 299, 219, 157, 287, 111, 191, 88, - 77, 3, 42, 315, 169, 280, 225, 15, 75, 285, - 260, 235, 237, 1, 155, 126, 226, 184, 101, 215, - 10, 79, 454, 172, 280, 454, 107, 246, 253, 454, - 224, 298, 218, 152, 217, 111, 21, 161, 296, 265, - 6, 39, 38, 299, 219, 269, 287, 203, 191, 119, - 77, 3, 42, 315, 158, 262, 321, 274, 75, 97, - 260, 235, 237, 1, 153, 128, 165, 193, 151, 215, - 10, 79, 317, 43, 280, 12, 107, 320, 280, 318, - 224, 298, 218, 8, 217, 171, 30, 306, 196, 36, - 172, 39, 38, 299, 219, 264, 287, 256, 191, 128, - 77, 288, 78, 315, 510, 90, 166, 296, 75, 41, - 37, 223, 104, 228, 250, 251, 255, 122, 226, 289, - 260, 235, 237, 1, 239, 233, 238, 240, 241, 215, - 10, 79, 229, 305, 77, 304, 107, 315, 281, 300, - 224, 298, 218, 261, 211, 203, 314, 28, 86, 108, - 140, 181, 96, 61, 214, 247, 317, 454, 94, 12, - 454, 297, 322, 318, 454, 29, 259, 192, 249, 248, - 308, 313, 138, 27, 302, 143, 130, 82, 95, 17, - 261, 211, 203, 314, 252, 86, 108, 286, 180, 96, - 50, 136, 139, 100, 152, 94, 454, 81, 297, 322, - 295, 321, 146, 259, 192, 249, 295, 308, 261, 295, - 203, 295, 295, 110, 295, 295, 197, 105, 64, 295, - 295, 295, 295, 94, 295, 295, 297, 322, 295, 295, - 295, 259, 192, 249, 261, 308, 203, 276, 295, 110, - 108, 295, 181, 96, 61, 187, 282, 295, 317, 94, - 295, 12, 297, 322, 295, 318, 295, 259, 192, 249, - 295, 308, 295, 291, 295, 295, 295, 295, 295, 260, - 235, 237, 2, 295, 293, 295, 295, 295, 215, 10, - 79, 295, 295, 295, 295, 107, 291, 206, 295, 224, - 298, 218, 260, 235, 237, 2, 295, 293, 295, 295, - 295, 215, 10, 79, 295, 295, 295, 295, 107, 295, - 295, 295, 224, 298, 218, 295, 295, 295, 26, 261, - 295, 203, 295, 295, 110, 295, 295, 197, 113, 60, - 295, 295, 295, 295, 94, 156, 295, 297, 322, 167, - 284, 26, 259, 192, 249, 280, 308, 295, 40, 14, - 257, 295, 261, 200, 203, 295, 295, 110, 295, 295, - 197, 105, 64, 172, 295, 295, 295, 94, 295, 295, - 297, 322, 295, 295, 295, 259, 192, 249, 295, 308, - 295, 295, 295, 295, 261, 295, 203, 295, 295, 98, - 283, 295, 197, 113, 51, 295, 201, 295, 295, 94, - 295, 295, 297, 322, 295, 295, 295, 259, 192, 249, - 261, 308, 203, 295, 295, 110, 295, 295, 197, 113, - 60, 295, 295, 295, 295, 94, 295, 295, 297, 322, - 295, 295, 295, 259, 192, 249, 295, 308, 261, 295, - 203, 295, 295, 110, 188, 295, 197, 113, 60, 196, - 31, 43, 295, 94, 295, 295, 297, 322, 295, 295, - 295, 259, 192, 249, 295, 308, 261, 295, 203, 295, - 295, 98, 198, 295, 197, 113, 45, 295, 109, 295, - 295, 94, 295, 295, 297, 322, 295, 41, 37, 259, - 192, 249, 261, 308, 203, 295, 295, 110, 295, 295, - 197, 113, 67, 233, 238, 240, 241, 94, 295, 295, - 297, 322, 295, 295, 295, 259, 192, 249, 295, 308, - 261, 295, 203, 295, 295, 110, 295, 295, 197, 113, - 57, 196, 295, 43, 295, 94, 295, 295, 297, 322, - 295, 295, 295, 259, 192, 249, 295, 308, 261, 295, - 203, 295, 295, 110, 295, 295, 197, 113, 46, 295, - 295, 295, 295, 94, 295, 295, 297, 322, 295, 41, - 37, 259, 192, 249, 261, 308, 203, 295, 295, 110, - 295, 295, 197, 113, 66, 233, 238, 240, 241, 94, - 301, 295, 297, 322, 295, 295, 295, 259, 192, 249, - 295, 308, 261, 295, 203, 295, 295, 110, 295, 295, - 197, 113, 72, 196, 295, 43, 295, 94, 295, 295, - 297, 322, 295, 295, 295, 259, 192, 249, 295, 308, - 261, 295, 203, 295, 295, 110, 295, 295, 197, 113, - 53, 295, 295, 295, 295, 94, 295, 295, 297, 322, - 230, 41, 37, 259, 192, 249, 261, 308, 203, 295, - 295, 110, 295, 295, 197, 113, 48, 233, 238, 240, - 241, 94, 295, 295, 297, 322, 295, 295, 295, 259, - 192, 249, 295, 308, 261, 295, 203, 295, 295, 110, - 295, 295, 185, 103, 49, 196, 295, 43, 295, 94, - 295, 295, 297, 322, 295, 295, 295, 259, 192, 249, - 295, 308, 261, 295, 203, 295, 295, 110, 295, 295, - 197, 113, 55, 134, 295, 295, 295, 94, 295, 295, - 297, 322, 295, 41, 37, 259, 192, 249, 261, 308, - 203, 295, 295, 110, 295, 295, 197, 113, 71, 233, - 238, 240, 241, 94, 295, 295, 297, 322, 295, 295, - 295, 259, 192, 249, 295, 308, 261, 295, 203, 295, - 295, 110, 295, 295, 197, 113, 59, 196, 295, 43, - 295, 94, 295, 295, 297, 322, 295, 295, 295, 259, - 192, 249, 295, 308, 261, 295, 203, 295, 295, 110, - 295, 295, 197, 113, 63, 295, 295, 295, 295, 94, - 295, 295, 297, 322, 216, 41, 37, 259, 192, 249, - 261, 308, 203, 295, 295, 110, 295, 295, 197, 113, - 62, 233, 238, 240, 241, 94, 295, 295, 297, 322, - 295, 295, 295, 259, 192, 249, 295, 308, 261, 295, - 203, 295, 295, 110, 295, 295, 197, 92, 69, 196, - 295, 43, 295, 94, 295, 295, 297, 322, 295, 295, - 295, 259, 192, 249, 295, 308, 261, 295, 203, 295, - 295, 110, 295, 295, 197, 113, 52, 295, 295, 295, - 295, 94, 295, 295, 297, 322, 295, 41, 37, 259, - 192, 249, 261, 308, 203, 295, 295, 110, 295, 295, - 197, 113, 65, 233, 238, 240, 241, 94, 295, 295, - 297, 322, 295, 196, 295, 259, 192, 249, 295, 308, - 261, 295, 203, 295, 295, 110, 295, 349, 197, 113, - 58, 221, 295, 295, 295, 94, 295, 295, 297, 322, - 27, 295, 295, 259, 192, 249, 17, 308, 261, 425, - 203, 295, 295, 110, 295, 295, 197, 113, 56, 295, - 425, 295, 295, 94, 295, 295, 297, 322, 295, 295, - 295, 259, 192, 249, 261, 308, 203, 295, 295, 110, - 295, 295, 197, 113, 44, 295, 295, 295, 295, 94, - 295, 295, 297, 322, 295, 295, 295, 259, 192, 249, - 295, 308, 261, 295, 203, 295, 295, 110, 295, 295, - 197, 93, 70, 295, 295, 295, 295, 94, 295, 295, - 297, 322, 295, 295, 295, 259, 192, 249, 295, 308, - 261, 295, 203, 295, 295, 110, 295, 295, 186, 113, - 54, 295, 295, 295, 295, 94, 295, 295, 297, 322, - 295, 295, 295, 259, 192, 249, 261, 308, 203, 295, - 295, 110, 295, 295, 197, 113, 73, 295, 295, 295, - 295, 94, 295, 295, 297, 322, 295, 295, 295, 259, - 192, 249, 295, 308, 261, 295, 203, 295, 295, 110, - 295, 295, 197, 113, 68, 295, 295, 295, 295, 94, - 295, 295, 297, 322, 295, 295, 295, 259, 192, 249, - 295, 308, 261, 295, 203, 295, 295, 110, 295, 295, - 197, 93, 47, 295, 295, 295, 295, 94, 295, 295, - 297, 322, 391, 391, 391, 259, 192, 249, 261, 308, - 203, 295, 295, 110, 295, 295, 197, 113, 51, 295, - 295, 295, 295, 94, 295, 295, 297, 322, 196, 295, - 43, 259, 192, 249, 295, 308, 295, 295, 425, 295, - 391, 391, 295, 295, 295, 261, 295, 203, 295, 425, - 110, 295, 295, 197, 118, 27, 391, 391, 391, 391, - 94, 17, 295, 295, 258, 295, 41, 37, 259, 192, - 249, 261, 308, 203, 295, 196, 110, 43, 295, 197, - 120, 295, 233, 238, 240, 241, 94, 295, 295, 295, - 243, 295, 295, 295, 259, 192, 249, 295, 308, 295, - 32, 295, 27, 212, 295, 295, 295, 295, 17, 295, - 295, 295, 454, 41, 37, 454, 295, 295, 295, 454, - 438, 295, 295, 295, 295, 295, 295, 295, 295, 233, - 238, 240, 241, 295, 295, 261, 295, 203, 295, 295, - 110, 295, 295, 197, 112, 295, 438, 295, 295, 438, - 94, 454, 212, 438, 268, 295, 295, 295, 259, 192, - 249, 454, 308, 212, 454, 295, 295, 34, 454, 438, - 295, 295, 454, 295, 295, 454, 295, 133, 4, 454, - 438, 167, 295, 295, 295, 295, 295, 280, 295, 295, - 40, 14, 257, 295, 295, 438, 295, 295, 438, 261, - 454, 203, 438, 295, 110, 172, 438, 197, 121, 438, - 261, 454, 203, 438, 94, 110, 295, 295, 197, 117, - 295, 295, 259, 192, 249, 94, 308, 295, 295, 295, - 295, 295, 295, 259, 192, 249, 261, 308, 203, 295, - 295, 110, 295, 295, 197, 116, 295, 261, 295, 203, - 295, 94, 110, 295, 295, 197, 114, 295, 295, 259, - 192, 249, 94, 308, 196, 295, 43, 295, 295, 295, - 259, 192, 249, 261, 308, 203, 295, 196, 110, 43, - 295, 197, 123, 295, 295, 295, 106, 295, 94, 295, - 196, 174, 43, 295, 295, 295, 259, 192, 249, 196, - 308, 43, 41, 37, 244, 295, 295, 295, 295, 295, - 295, 295, 295, 234, 295, 41, 37, 295, 233, 238, - 240, 241, 295, 295, 295, 295, 295, 295, 41, 37, - 295, 233, 238, 240, 241, 295, 295, 41, 37, 295, - 295, 295, 295, 295, 233, 238, 240, 241, 25, 196, - 295, 43, 295, 233, 238, 240, 241, 454, 295, 295, - 454, 295, 295, 279, 454, 438, 212, 295, 295, 295, - 295, 295, 295, 295, 295, 454, 295, 295, 454, 295, - 295, 295, 454, 438, 196, 295, 43, 41, 37, 295, - 295, 438, 295, 196, 438, 43, 454, 295, 438, 295, - 295, 295, 295, 233, 238, 240, 241, 173, 295, 438, - 295, 295, 438, 295, 454, 295, 438, 454, 295, 295, - 454, 295, 41, 37, 454, 438, 295, 295, 295, 295, - 295, 41, 37, 295, 295, 295, 242, 295, 233, 238, - 240, 241, 295, 295, 295, 295, 295, 233, 238, 240, - 241, 438, 295, 295, 438, 295, 454, 147, 438, 295, - 295, 167, 295, 295, 295, 295, 295, 280, 295, 295, - 40, 14, 257, 295, 295, 295, 295, 295, 295, 295, - 295, 295, 295, 295, 295, 172, + 251, 234, 237, 1, 144, 127, 428, 184, 199, 212, + 10, 54, 19, 175, 282, 215, 109, 389, 428, 428, + 224, 321, 223, 303, 203, 389, 13, 389, 281, 43, + 389, 428, 41, 40, 266, 225, 389, 213, 389, 194, + 389, 52, 4, 308, 301, 383, 34, 209, 222, 3, + 50, 153, 251, 234, 237, 1, 199, 131, 383, 198, + 305, 212, 10, 54, 383, 16, 199, 428, 109, 385, + 132, 18, 224, 321, 223, 222, 221, 12, 32, 428, + 116, 43, 385, 262, 41, 40, 266, 225, 385, 233, + 95, 194, 16, 52, 4, 131, 301, 252, 18, 265, + 164, 3, 50, 324, 251, 234, 237, 1, 23, 130, + 229, 198, 150, 212, 10, 54, 326, 11, 170, 284, + 109, 42, 22, 239, 224, 321, 223, 193, 221, 261, + 13, 52, 157, 43, 301, 286, 41, 40, 266, 225, + 205, 233, 5, 194, 96, 52, 4, 263, 301, 301, + 99, 349, 96, 3, 50, 199, 251, 234, 237, 1, + 238, 130, 241, 181, 349, 212, 10, 54, 382, 240, + 349, 36, 109, 185, 104, 256, 224, 321, 223, 132, + 191, 382, 13, 49, 91, 43, 12, 382, 41, 40, + 266, 225, 257, 233, 152, 194, 457, 52, 4, 457, + 301, 301, 228, 457, 282, 3, 50, 285, 251, 234, + 237, 1, 301, 131, 441, 198, 238, 212, 10, 54, + 349, 441, 325, 175, 109, 30, 349, 273, 224, 321, + 223, 20, 221, 295, 32, 211, 457, 39, 166, 49, + 41, 40, 266, 225, 87, 233, 205, 194, 279, 52, + 4, 24, 301, 204, 200, 280, 99, 3, 50, 199, + 251, 234, 237, 1, 31, 130, 96, 198, 205, 212, + 10, 54, 350, 55, 293, 207, 109, 283, 99, 96, + 224, 321, 223, 199, 180, 350, 13, 134, 230, 43, + 222, 350, 41, 40, 266, 225, 104, 233, 316, 194, + 279, 52, 4, 24, 301, 165, 284, 280, 85, 3, + 50, 25, 251, 234, 237, 1, 131, 129, 210, 198, + 14, 212, 10, 54, 269, 270, 301, 116, 109, 295, + 216, 211, 224, 321, 223, 171, 221, 95, 13, 28, + 219, 43, 323, 9, 41, 40, 266, 225, 151, 233, + 324, 194, 52, 52, 4, 301, 301, 30, 282, 302, + 178, 3, 50, 7, 251, 234, 237, 1, 136, 130, + 304, 179, 238, 212, 10, 54, 279, 175, 282, 24, + 109, 238, 429, 280, 224, 321, 223, 177, 221, 270, + 13, 255, 281, 43, 429, 49, 41, 40, 266, 225, + 275, 233, 318, 194, 49, 52, 4, 276, 301, 163, + 26, 199, 8, 3, 50, 119, 251, 234, 237, 1, + 11, 93, 291, 51, 107, 212, 10, 54, 226, 428, + 206, 201, 109, 148, 178, 322, 224, 321, 223, 441, + 221, 428, 13, 282, 9, 43, 441, 115, 41, 40, + 266, 225, 167, 233, 227, 194, 457, 52, 4, 457, + 301, 96, 158, 457, 101, 3, 50, 271, 251, 234, + 237, 1, 282, 130, 235, 186, 135, 212, 10, 54, + 199, 37, 119, 315, 109, 165, 284, 176, 224, 321, + 223, 104, 221, 149, 13, 281, 146, 43, 281, 300, + 41, 40, 266, 225, 30, 233, 289, 194, 21, 52, + 4, 272, 301, 211, 18, 301, 161, 3, 50, 110, + 251, 234, 237, 1, 137, 128, 282, 198, 268, 212, + 10, 54, 222, 169, 515, 92, 109, 172, 284, 31, + 224, 321, 223, 29, 221, 238, 6, 260, 53, 43, + 232, 139, 41, 40, 266, 225, 154, 233, 178, 194, + 168, 52, 4, 214, 301, 145, 99, 33, 49, 3, + 50, 245, 208, 211, 320, 282, 90, 111, 311, 183, + 98, 70, 309, 297, 236, 178, 95, 319, 142, 258, + 247, 267, 249, 264, 250, 195, 231, 199, 246, 324, + 317, 253, 254, 259, 126, 137, 133, 251, 234, 237, + 1, 326, 290, 105, 143, 156, 212, 10, 54, 88, + 84, 83, 484, 109, 322, 282, 37, 224, 321, 223, + 245, 208, 211, 320, 281, 90, 111, 298, 182, 98, + 56, 245, 298, 211, 178, 95, 103, 147, 258, 197, + 102, 75, 141, 250, 195, 231, 95, 246, 324, 258, + 279, 242, 89, 24, 250, 195, 231, 280, 246, 324, + 298, 298, 298, 298, 298, 298, 298, 16, 298, 192, + 277, 298, 298, 18, 294, 44, 45, 38, 298, 298, + 251, 234, 237, 2, 298, 296, 298, 298, 298, 212, + 10, 54, 310, 312, 313, 314, 109, 162, 298, 298, + 224, 321, 223, 298, 298, 298, 294, 282, 298, 42, + 22, 239, 251, 234, 237, 2, 298, 296, 298, 298, + 298, 212, 10, 54, 298, 159, 298, 298, 109, 298, + 298, 17, 224, 321, 223, 282, 298, 42, 22, 239, + 298, 298, 245, 298, 211, 278, 298, 103, 111, 298, + 183, 98, 70, 298, 298, 298, 298, 95, 298, 298, + 258, 298, 292, 17, 298, 250, 195, 231, 279, 246, + 324, 24, 298, 395, 245, 280, 211, 298, 298, 103, + 298, 298, 197, 102, 75, 16, 298, 140, 298, 95, + 298, 18, 258, 298, 298, 298, 298, 250, 195, 231, + 298, 246, 324, 298, 298, 298, 298, 428, 298, 395, + 395, 395, 202, 277, 298, 245, 298, 211, 298, 428, + 103, 298, 298, 197, 120, 69, 395, 395, 395, 395, + 95, 298, 298, 258, 298, 298, 298, 160, 250, 195, + 231, 86, 246, 324, 245, 16, 211, 282, 298, 103, + 196, 18, 197, 120, 69, 298, 44, 45, 38, 95, + 298, 298, 258, 298, 298, 298, 178, 250, 195, 231, + 298, 246, 324, 310, 312, 313, 314, 298, 298, 190, + 245, 298, 211, 298, 298, 103, 298, 298, 197, 102, + 75, 298, 298, 298, 298, 95, 298, 298, 258, 298, + 298, 298, 298, 250, 195, 231, 298, 246, 324, 298, + 298, 298, 245, 298, 211, 298, 199, 100, 298, 288, + 197, 120, 47, 298, 106, 298, 298, 95, 298, 353, + 258, 155, 298, 218, 298, 250, 195, 231, 298, 246, + 324, 282, 16, 42, 22, 239, 298, 245, 18, 211, + 298, 428, 103, 298, 298, 197, 120, 69, 298, 298, + 298, 298, 95, 428, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 100, 189, 298, 197, 120, 59, 245, 207, 211, + 298, 95, 103, 298, 258, 197, 120, 81, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 120, 80, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 67, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 120, 57, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 120, 58, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 82, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 97, 76, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 120, 71, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 187, 120, 61, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 120, 63, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 94, 79, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 59, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 120, 77, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 188, 108, 64, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 65, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 97, 66, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 120, 68, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 62, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 120, 60, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 120, 74, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 72, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 120, 48, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 120, 46, 298, 298, + 298, 298, 95, 298, 298, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 120, 78, 245, 298, 211, + 298, 95, 103, 298, 258, 197, 120, 73, 298, 250, + 195, 231, 95, 246, 324, 258, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 125, 298, 298, 298, + 298, 298, 95, 298, 298, 298, 298, 298, 298, 244, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 114, 298, 245, 298, 211, + 298, 95, 103, 298, 298, 197, 122, 298, 243, 250, + 195, 231, 95, 246, 324, 298, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 117, 298, 298, 298, + 298, 298, 95, 298, 298, 298, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 121, 298, 245, 298, 211, + 298, 95, 103, 298, 298, 197, 124, 298, 298, 250, + 195, 231, 95, 246, 324, 298, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 298, 245, 298, 211, + 298, 298, 103, 298, 298, 197, 118, 298, 298, 298, + 298, 298, 95, 298, 298, 298, 298, 298, 298, 298, + 250, 195, 231, 298, 246, 324, 245, 298, 211, 298, + 298, 103, 298, 298, 197, 123, 298, 245, 298, 211, + 298, 95, 103, 298, 298, 197, 113, 298, 298, 250, + 195, 231, 95, 246, 324, 298, 298, 298, 298, 298, + 250, 195, 231, 220, 246, 324, 298, 27, 298, 16, + 298, 457, 298, 298, 457, 18, 298, 26, 457, 441, + 44, 45, 38, 217, 44, 45, 38, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 310, 312, 313, + 314, 310, 312, 313, 314, 298, 441, 298, 298, 441, + 298, 457, 220, 441, 457, 298, 298, 457, 298, 298, + 457, 457, 441, 457, 298, 298, 220, 457, 441, 298, + 298, 298, 298, 298, 457, 298, 298, 457, 298, 298, + 5, 457, 441, 298, 298, 298, 298, 298, 298, 441, + 298, 298, 441, 298, 457, 441, 441, 298, 441, 298, + 457, 298, 441, 306, 298, 298, 298, 298, 298, 441, + 298, 298, 441, 298, 457, 220, 441, 298, 298, 298, + 298, 298, 298, 457, 298, 298, 457, 298, 298, 15, + 457, 441, 35, 274, 44, 45, 38, 457, 298, 298, + 457, 298, 298, 298, 457, 441, 298, 298, 298, 298, + 298, 310, 312, 313, 314, 298, 298, 298, 441, 298, + 298, 441, 298, 457, 298, 441, 287, 298, 44, 45, + 38, 298, 441, 298, 298, 441, 298, 457, 298, 441, + 248, 298, 298, 298, 298, 310, 312, 313, 314, 298, + 44, 45, 38, 298, 298, 112, 298, 44, 45, 38, + 298, 173, 298, 298, 44, 45, 38, 310, 312, 313, + 314, 44, 45, 38, 310, 312, 313, 314, 298, 298, + 299, 310, 312, 313, 314, 44, 45, 38, 310, 312, + 313, 314, 174, 298, 298, 298, 138, 298, 298, 298, + 298, 298, 310, 312, 313, 314, 44, 45, 38, 298, + 298, 298, 44, 45, 38, 298, 44, 45, 38, 298, + 44, 45, 38, 310, 312, 313, 314, 307, 298, 310, + 312, 313, 314, 310, 312, 313, 314, 310, 312, 313, + 314, ); public static $yy_lookahead = array( - 3, 9, 10, 15, 71, 17, 28, 74, 11, 12, - 13, 14, 34, 16, 81, 18, 28, 20, 21, 22, - 11, 82, 34, 14, 27, 37, 93, 18, 31, 32, - 33, 45, 35, 66, 37, 68, 48, 28, 52, 42, - 43, 44, 45, 34, 47, 15, 49, 16, 51, 52, - 53, 54, 3, 23, 77, 25, 59, 17, 28, 19, - 11, 12, 13, 14, 34, 16, 36, 18, 38, 20, - 21, 22, 105, 106, 94, 45, 27, 73, 101, 73, - 31, 32, 33, 77, 35, 54, 37, 83, 48, 83, - 94, 42, 43, 44, 45, 14, 47, 16, 49, 18, - 51, 52, 3, 54, 36, 101, 38, 101, 59, 15, - 11, 12, 13, 14, 77, 16, 35, 18, 24, 20, - 21, 22, 28, 86, 87, 88, 27, 24, 34, 37, - 31, 32, 33, 82, 35, 54, 37, 66, 101, 68, - 46, 42, 43, 44, 45, 16, 47, 71, 49, 46, - 51, 52, 3, 54, 78, 79, 53, 81, 59, 15, - 11, 12, 13, 14, 37, 16, 37, 18, 24, 20, - 21, 22, 28, 19, 65, 48, 27, 106, 34, 101, - 31, 32, 33, 54, 35, 71, 37, 16, 74, 18, - 46, 42, 43, 44, 45, 81, 47, 45, 49, 45, - 51, 52, 3, 54, 90, 53, 52, 93, 59, 30, - 11, 12, 13, 14, 82, 16, 37, 18, 24, 20, - 21, 22, 51, 18, 14, 54, 27, 48, 73, 17, - 31, 32, 33, 1, 35, 14, 37, 16, 83, 18, - 46, 42, 43, 44, 45, 1, 47, 37, 49, 77, - 51, 52, 3, 54, 60, 50, 1, 45, 59, 15, - 11, 12, 13, 14, 52, 16, 36, 18, 38, 20, - 21, 22, 28, 101, 102, 54, 27, 8, 34, 10, - 31, 32, 33, 28, 35, 95, 37, 97, 98, 34, - 94, 42, 43, 44, 45, 1, 47, 71, 49, 77, - 51, 52, 3, 54, 78, 23, 73, 81, 59, 15, - 11, 12, 13, 14, 73, 16, 83, 18, 36, 20, - 21, 22, 28, 101, 83, 17, 27, 19, 34, 96, - 31, 32, 33, 45, 35, 16, 37, 96, 37, 41, - 52, 42, 43, 44, 45, 1, 47, 71, 49, 48, - 51, 52, 3, 54, 78, 37, 48, 81, 59, 15, - 11, 12, 13, 14, 71, 16, 48, 18, 17, 20, - 21, 22, 28, 54, 81, 24, 27, 70, 34, 37, - 31, 32, 33, 28, 35, 24, 37, 45, 1, 34, - 48, 42, 43, 44, 45, 53, 47, 2, 49, 73, - 51, 52, 3, 54, 97, 98, 19, 46, 59, 83, - 11, 12, 13, 14, 36, 16, 38, 18, 98, 20, - 21, 22, 11, 64, 65, 14, 27, 101, 1, 18, - 31, 32, 33, 94, 35, 96, 37, 1, 17, 19, - 92, 42, 43, 44, 45, 73, 47, 99, 49, 77, - 51, 52, 3, 54, 16, 83, 18, 30, 59, 70, - 11, 12, 13, 14, 73, 16, 45, 18, 48, 20, - 21, 22, 11, 101, 83, 14, 27, 35, 92, 18, - 31, 32, 33, 94, 35, 99, 37, 97, 98, 53, - 36, 42, 43, 44, 45, 66, 47, 68, 49, 18, - 51, 52, 3, 54, 94, 38, 96, 53, 59, 81, - 11, 12, 13, 14, 73, 16, 77, 18, 73, 20, - 21, 22, 11, 3, 83, 14, 27, 99, 83, 18, - 31, 32, 33, 37, 35, 18, 37, 18, 1, 2, - 101, 42, 43, 44, 45, 35, 47, 18, 49, 16, - 51, 18, 18, 54, 62, 63, 97, 98, 59, 39, - 40, 50, 18, 4, 5, 6, 7, 8, 45, 16, - 11, 12, 13, 14, 18, 55, 56, 57, 58, 20, - 21, 22, 49, 53, 51, 53, 27, 54, 18, 15, - 31, 32, 33, 66, 67, 68, 69, 25, 71, 72, - 51, 74, 75, 76, 18, 18, 11, 11, 81, 14, - 14, 84, 85, 18, 18, 17, 89, 90, 91, 9, - 93, 15, 51, 28, 102, 30, 81, 81, 19, 34, - 66, 67, 68, 69, 95, 71, 72, 83, 74, 75, - 76, 94, 94, 80, 94, 81, 50, 81, 84, 85, - 107, 96, 94, 89, 90, 91, 107, 93, 66, 107, - 68, 107, 107, 71, 107, 107, 74, 75, 76, 107, - 107, 107, 107, 81, 107, 107, 84, 85, 107, 107, - 107, 89, 90, 91, 66, 93, 68, 69, 107, 71, - 72, 107, 74, 75, 76, 103, 104, 107, 11, 81, - 107, 14, 84, 85, 107, 18, 107, 89, 90, 91, - 107, 93, 107, 5, 107, 107, 107, 107, 107, 11, - 12, 13, 14, 107, 16, 107, 107, 107, 20, 21, - 22, 107, 107, 107, 107, 27, 5, 50, 107, 31, - 32, 33, 11, 12, 13, 14, 107, 16, 107, 107, - 107, 20, 21, 22, 107, 107, 107, 107, 27, 107, - 107, 107, 31, 32, 33, 107, 107, 59, 60, 66, - 107, 68, 107, 107, 71, 107, 107, 74, 75, 76, - 107, 107, 107, 107, 81, 73, 107, 84, 85, 77, - 59, 60, 89, 90, 91, 83, 93, 107, 86, 87, - 88, 107, 66, 100, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 101, 107, 107, 107, 81, 107, 107, - 84, 85, 107, 107, 107, 89, 90, 91, 107, 93, - 107, 107, 107, 107, 66, 107, 68, 107, 107, 71, - 104, 107, 74, 75, 76, 107, 78, 107, 107, 81, - 107, 107, 84, 85, 107, 107, 107, 89, 90, 91, - 66, 93, 68, 107, 107, 71, 107, 107, 74, 75, - 76, 107, 107, 107, 107, 81, 107, 107, 84, 85, - 107, 107, 107, 89, 90, 91, 107, 93, 66, 107, - 68, 107, 107, 71, 100, 107, 74, 75, 76, 1, - 2, 3, 107, 81, 107, 107, 84, 85, 107, 107, - 107, 89, 90, 91, 107, 93, 66, 107, 68, 107, - 107, 71, 100, 107, 74, 75, 76, 107, 78, 107, - 107, 81, 107, 107, 84, 85, 107, 39, 40, 89, - 90, 91, 66, 93, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 55, 56, 57, 58, 81, 107, 107, - 84, 85, 107, 107, 107, 89, 90, 91, 107, 93, - 66, 107, 68, 107, 107, 71, 107, 107, 74, 75, - 76, 1, 107, 3, 107, 81, 107, 107, 84, 85, - 107, 107, 107, 89, 90, 91, 107, 93, 66, 107, - 68, 107, 107, 71, 107, 107, 74, 75, 76, 107, - 107, 107, 107, 81, 107, 107, 84, 85, 107, 39, - 40, 89, 90, 91, 66, 93, 68, 107, 107, 71, - 107, 107, 74, 75, 76, 55, 56, 57, 58, 81, - 60, 107, 84, 85, 107, 107, 107, 89, 90, 91, - 107, 93, 66, 107, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 1, 107, 3, 107, 81, 107, 107, - 84, 85, 107, 107, 107, 89, 90, 91, 107, 93, - 66, 107, 68, 107, 107, 71, 107, 107, 74, 75, - 76, 107, 107, 107, 107, 81, 107, 107, 84, 85, - 38, 39, 40, 89, 90, 91, 66, 93, 68, 107, - 107, 71, 107, 107, 74, 75, 76, 55, 56, 57, - 58, 81, 107, 107, 84, 85, 107, 107, 107, 89, - 90, 91, 107, 93, 66, 107, 68, 107, 107, 71, - 107, 107, 74, 75, 76, 1, 107, 3, 107, 81, - 107, 107, 84, 85, 107, 107, 107, 89, 90, 91, - 107, 93, 66, 107, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 29, 107, 107, 107, 81, 107, 107, - 84, 85, 107, 39, 40, 89, 90, 91, 66, 93, - 68, 107, 107, 71, 107, 107, 74, 75, 76, 55, - 56, 57, 58, 81, 107, 107, 84, 85, 107, 107, - 107, 89, 90, 91, 107, 93, 66, 107, 68, 107, - 107, 71, 107, 107, 74, 75, 76, 1, 107, 3, - 107, 81, 107, 107, 84, 85, 107, 107, 107, 89, - 90, 91, 107, 93, 66, 107, 68, 107, 107, 71, - 107, 107, 74, 75, 76, 107, 107, 107, 107, 81, - 107, 107, 84, 85, 38, 39, 40, 89, 90, 91, - 66, 93, 68, 107, 107, 71, 107, 107, 74, 75, - 76, 55, 56, 57, 58, 81, 107, 107, 84, 85, - 107, 107, 107, 89, 90, 91, 107, 93, 66, 107, - 68, 107, 107, 71, 107, 107, 74, 75, 76, 1, - 107, 3, 107, 81, 107, 107, 84, 85, 107, 107, - 107, 89, 90, 91, 107, 93, 66, 107, 68, 107, - 107, 71, 107, 107, 74, 75, 76, 107, 107, 107, - 107, 81, 107, 107, 84, 85, 107, 39, 40, 89, - 90, 91, 66, 93, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 55, 56, 57, 58, 81, 107, 107, - 84, 85, 107, 1, 107, 89, 90, 91, 107, 93, - 66, 107, 68, 107, 107, 71, 107, 15, 74, 75, - 76, 19, 107, 107, 107, 81, 107, 107, 84, 85, - 28, 107, 107, 89, 90, 91, 34, 93, 66, 37, - 68, 107, 107, 71, 107, 107, 74, 75, 76, 107, - 48, 107, 107, 81, 107, 107, 84, 85, 107, 107, - 107, 89, 90, 91, 66, 93, 68, 107, 107, 71, - 107, 107, 74, 75, 76, 107, 107, 107, 107, 81, - 107, 107, 84, 85, 107, 107, 107, 89, 90, 91, - 107, 93, 66, 107, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 107, 107, 107, 107, 81, 107, 107, - 84, 85, 107, 107, 107, 89, 90, 91, 107, 93, - 66, 107, 68, 107, 107, 71, 107, 107, 74, 75, - 76, 107, 107, 107, 107, 81, 107, 107, 84, 85, - 107, 107, 107, 89, 90, 91, 66, 93, 68, 107, - 107, 71, 107, 107, 74, 75, 76, 107, 107, 107, - 107, 81, 107, 107, 84, 85, 107, 107, 107, 89, - 90, 91, 107, 93, 66, 107, 68, 107, 107, 71, - 107, 107, 74, 75, 76, 107, 107, 107, 107, 81, - 107, 107, 84, 85, 107, 107, 107, 89, 90, 91, - 107, 93, 66, 107, 68, 107, 107, 71, 107, 107, - 74, 75, 76, 107, 107, 107, 107, 81, 107, 107, - 84, 85, 1, 2, 3, 89, 90, 91, 66, 93, - 68, 107, 107, 71, 107, 107, 74, 75, 76, 107, - 107, 107, 107, 81, 107, 107, 84, 85, 1, 107, - 3, 89, 90, 91, 107, 93, 107, 107, 37, 107, - 39, 40, 107, 107, 107, 66, 107, 68, 107, 48, - 71, 107, 107, 74, 75, 28, 55, 56, 57, 58, - 81, 34, 107, 107, 85, 107, 39, 40, 89, 90, - 91, 66, 93, 68, 107, 1, 71, 3, 107, 74, - 75, 107, 55, 56, 57, 58, 81, 107, 107, 107, - 85, 107, 107, 107, 89, 90, 91, 107, 93, 107, - 26, 107, 28, 2, 107, 107, 107, 107, 34, 107, - 107, 107, 11, 39, 40, 14, 107, 107, 107, 18, - 19, 107, 107, 107, 107, 107, 107, 107, 107, 55, - 56, 57, 58, 107, 107, 66, 107, 68, 107, 107, - 71, 107, 107, 74, 75, 107, 45, 107, 107, 48, - 81, 50, 2, 52, 53, 107, 107, 107, 89, 90, - 91, 11, 93, 2, 14, 107, 107, 17, 18, 19, - 107, 107, 11, 107, 107, 14, 107, 73, 17, 18, - 19, 77, 107, 107, 107, 107, 107, 83, 107, 107, - 86, 87, 88, 107, 107, 45, 107, 107, 48, 66, - 50, 68, 52, 107, 71, 101, 45, 74, 75, 48, - 66, 50, 68, 52, 81, 71, 107, 107, 74, 75, - 107, 107, 89, 90, 91, 81, 93, 107, 107, 107, - 107, 107, 107, 89, 90, 91, 66, 93, 68, 107, - 107, 71, 107, 107, 74, 75, 107, 66, 107, 68, - 107, 81, 71, 107, 107, 74, 75, 107, 107, 89, - 90, 91, 81, 93, 1, 107, 3, 107, 107, 107, - 89, 90, 91, 66, 93, 68, 107, 1, 71, 3, - 107, 74, 75, 107, 107, 107, 23, 107, 81, 107, - 1, 15, 3, 107, 107, 107, 89, 90, 91, 1, - 93, 3, 39, 40, 15, 107, 107, 107, 107, 107, - 107, 107, 107, 15, 107, 39, 40, 107, 55, 56, - 57, 58, 107, 107, 107, 107, 107, 107, 39, 40, - 107, 55, 56, 57, 58, 107, 107, 39, 40, 107, - 107, 107, 107, 107, 55, 56, 57, 58, 2, 1, - 107, 3, 107, 55, 56, 57, 58, 11, 107, 107, - 14, 107, 107, 15, 18, 19, 2, 107, 107, 107, - 107, 107, 107, 107, 107, 11, 107, 107, 14, 107, - 107, 107, 18, 19, 1, 107, 3, 39, 40, 107, - 107, 45, 107, 1, 48, 3, 50, 107, 52, 107, - 107, 107, 107, 55, 56, 57, 58, 15, 107, 45, - 107, 107, 48, 107, 50, 107, 52, 11, 107, 107, - 14, 107, 39, 40, 18, 19, 107, 107, 107, 107, - 107, 39, 40, 107, 107, 107, 53, 107, 55, 56, - 57, 58, 107, 107, 107, 107, 107, 55, 56, 57, - 58, 45, 107, 107, 48, 107, 50, 73, 52, 107, - 107, 77, 107, 107, 107, 107, 107, 83, 107, 107, - 86, 87, 88, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 101, + 10, 11, 12, 13, 74, 15, 36, 17, 1, 19, + 20, 21, 29, 103, 84, 45, 26, 14, 48, 36, + 30, 31, 32, 53, 34, 22, 36, 24, 98, 39, + 27, 48, 42, 43, 44, 45, 33, 47, 35, 49, + 37, 51, 52, 53, 54, 14, 16, 16, 45, 59, + 60, 96, 10, 11, 12, 13, 1, 15, 27, 17, + 53, 19, 20, 21, 33, 27, 1, 36, 26, 14, + 45, 33, 30, 31, 32, 45, 34, 52, 36, 48, + 72, 39, 27, 75, 42, 43, 44, 45, 33, 47, + 82, 49, 27, 51, 52, 15, 54, 17, 33, 91, + 83, 59, 60, 95, 10, 11, 12, 13, 13, 15, + 15, 17, 17, 19, 20, 21, 97, 35, 99, 100, + 26, 86, 87, 88, 30, 31, 32, 66, 34, 49, + 36, 51, 96, 39, 54, 53, 42, 43, 44, 45, + 72, 47, 16, 49, 18, 51, 52, 79, 54, 54, + 82, 14, 18, 59, 60, 1, 10, 11, 12, 13, + 23, 15, 15, 17, 27, 19, 20, 21, 14, 17, + 33, 13, 26, 15, 48, 17, 30, 31, 32, 45, + 34, 27, 36, 46, 83, 39, 52, 33, 42, 43, + 44, 45, 34, 47, 74, 49, 10, 51, 52, 13, + 54, 54, 50, 17, 84, 59, 60, 14, 10, 11, + 12, 13, 54, 15, 45, 17, 23, 19, 20, 21, + 27, 52, 100, 103, 26, 35, 33, 37, 30, 31, + 32, 22, 34, 67, 36, 69, 50, 39, 83, 46, + 42, 43, 44, 45, 35, 47, 72, 49, 10, 51, + 52, 13, 54, 79, 80, 17, 82, 59, 60, 1, + 10, 11, 12, 13, 16, 15, 18, 17, 72, 19, + 20, 21, 14, 107, 108, 79, 26, 71, 82, 18, + 30, 31, 32, 1, 34, 27, 36, 15, 50, 39, + 45, 33, 42, 43, 44, 45, 48, 47, 53, 49, + 10, 51, 52, 13, 54, 99, 100, 17, 36, 59, + 60, 29, 10, 11, 12, 13, 15, 15, 17, 17, + 13, 19, 20, 21, 8, 9, 54, 72, 26, 67, + 75, 69, 30, 31, 32, 78, 34, 82, 36, 24, + 50, 39, 17, 36, 42, 43, 44, 45, 74, 47, + 95, 49, 51, 51, 52, 54, 54, 35, 84, 37, + 103, 59, 60, 36, 10, 11, 12, 13, 74, 15, + 108, 17, 23, 19, 20, 21, 10, 103, 84, 13, + 26, 23, 36, 17, 30, 31, 32, 7, 34, 9, + 36, 17, 98, 39, 48, 46, 42, 43, 44, 45, + 17, 47, 53, 49, 46, 51, 52, 93, 54, 78, + 16, 1, 36, 59, 60, 101, 10, 11, 12, 13, + 35, 15, 37, 17, 48, 19, 20, 21, 18, 36, + 65, 66, 26, 74, 103, 104, 30, 31, 32, 45, + 34, 48, 36, 84, 36, 39, 52, 17, 42, 43, + 44, 45, 15, 47, 17, 49, 10, 51, 52, 13, + 54, 18, 74, 17, 82, 59, 60, 34, 10, 11, + 12, 13, 84, 15, 93, 17, 15, 19, 20, 21, + 1, 2, 101, 101, 26, 99, 100, 17, 30, 31, + 32, 48, 34, 96, 36, 98, 96, 39, 98, 71, + 42, 43, 44, 45, 35, 47, 37, 49, 27, 51, + 52, 67, 54, 69, 33, 54, 74, 59, 60, 17, + 10, 11, 12, 13, 96, 15, 84, 17, 34, 19, + 20, 21, 45, 78, 63, 64, 26, 99, 100, 16, + 30, 31, 32, 16, 34, 23, 36, 17, 17, 39, + 23, 51, 42, 43, 44, 45, 72, 47, 103, 49, + 78, 51, 52, 17, 54, 74, 82, 41, 46, 59, + 60, 67, 68, 69, 70, 84, 72, 73, 53, 75, + 76, 77, 53, 61, 15, 103, 82, 14, 51, 85, + 14, 37, 17, 8, 90, 91, 92, 1, 94, 95, + 3, 4, 5, 6, 7, 96, 82, 10, 11, 12, + 13, 97, 84, 81, 96, 74, 19, 20, 21, 78, + 82, 82, 1, 26, 104, 84, 2, 30, 31, 32, + 67, 68, 69, 70, 98, 72, 73, 109, 75, 76, + 77, 67, 109, 69, 103, 82, 72, 96, 85, 75, + 76, 77, 96, 90, 91, 92, 82, 94, 95, 85, + 10, 14, 96, 13, 90, 91, 92, 17, 94, 95, + 109, 109, 109, 109, 109, 109, 109, 27, 109, 105, + 106, 109, 109, 33, 4, 38, 39, 40, 109, 109, + 10, 11, 12, 13, 109, 15, 109, 109, 109, 19, + 20, 21, 55, 56, 57, 58, 26, 74, 109, 109, + 30, 31, 32, 109, 109, 109, 4, 84, 109, 86, + 87, 88, 10, 11, 12, 13, 109, 15, 109, 109, + 109, 19, 20, 21, 109, 74, 109, 109, 26, 109, + 60, 61, 30, 31, 32, 84, 109, 86, 87, 88, + 109, 109, 67, 109, 69, 70, 109, 72, 73, 109, + 75, 76, 77, 109, 109, 109, 109, 82, 109, 109, + 85, 109, 60, 61, 109, 90, 91, 92, 10, 94, + 95, 13, 109, 2, 67, 17, 69, 109, 109, 72, + 109, 109, 75, 76, 77, 27, 109, 29, 109, 82, + 109, 33, 85, 109, 109, 109, 109, 90, 91, 92, + 109, 94, 95, 109, 109, 109, 109, 36, 109, 38, + 39, 40, 105, 106, 109, 67, 109, 69, 109, 48, + 72, 109, 109, 75, 76, 77, 55, 56, 57, 58, + 82, 109, 109, 85, 109, 109, 109, 74, 90, 91, + 92, 78, 94, 95, 67, 27, 69, 84, 109, 72, + 102, 33, 75, 76, 77, 109, 38, 39, 40, 82, + 109, 109, 85, 109, 109, 109, 103, 90, 91, 92, + 109, 94, 95, 55, 56, 57, 58, 109, 109, 102, + 67, 109, 69, 109, 109, 72, 109, 109, 75, 76, + 77, 109, 109, 109, 109, 82, 109, 109, 85, 109, + 109, 109, 109, 90, 91, 92, 109, 94, 95, 109, + 109, 109, 67, 109, 69, 109, 1, 72, 109, 106, + 75, 76, 77, 109, 79, 109, 109, 82, 109, 14, + 85, 74, 109, 18, 109, 90, 91, 92, 109, 94, + 95, 84, 27, 86, 87, 88, 109, 67, 33, 69, + 109, 36, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 48, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 102, 109, 75, 76, 77, 67, 79, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 77, 109, 109, + 109, 109, 82, 109, 109, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 77, 67, 109, 69, + 109, 82, 72, 109, 85, 75, 76, 77, 109, 90, + 91, 92, 82, 94, 95, 85, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 109, 109, 109, + 109, 109, 82, 109, 109, 109, 109, 109, 109, 89, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 109, 67, 109, 69, + 109, 82, 72, 109, 109, 75, 76, 109, 89, 90, + 91, 92, 82, 94, 95, 109, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 109, 109, 109, + 109, 109, 82, 109, 109, 109, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 109, 67, 109, 69, + 109, 82, 72, 109, 109, 75, 76, 109, 109, 90, + 91, 92, 82, 94, 95, 109, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 109, 67, 109, 69, + 109, 109, 72, 109, 109, 75, 76, 109, 109, 109, + 109, 109, 82, 109, 109, 109, 109, 109, 109, 109, + 90, 91, 92, 109, 94, 95, 67, 109, 69, 109, + 109, 72, 109, 109, 75, 76, 109, 67, 109, 69, + 109, 82, 72, 109, 109, 75, 76, 109, 109, 90, + 91, 92, 82, 94, 95, 109, 109, 109, 109, 109, + 90, 91, 92, 2, 94, 95, 109, 25, 109, 27, + 109, 10, 109, 109, 13, 33, 109, 16, 17, 18, + 38, 39, 40, 37, 38, 39, 40, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 55, 56, 57, + 58, 55, 56, 57, 58, 109, 45, 109, 109, 48, + 109, 50, 2, 52, 10, 109, 109, 13, 109, 109, + 10, 17, 18, 13, 109, 109, 2, 17, 18, 109, + 109, 109, 109, 109, 10, 109, 109, 13, 109, 109, + 16, 17, 18, 109, 109, 109, 109, 109, 109, 45, + 109, 109, 48, 109, 50, 45, 52, 109, 48, 109, + 50, 109, 52, 53, 109, 109, 109, 109, 109, 45, + 109, 109, 48, 109, 50, 2, 52, 109, 109, 109, + 109, 109, 109, 10, 109, 109, 13, 109, 109, 2, + 17, 18, 2, 37, 38, 39, 40, 10, 109, 109, + 13, 109, 109, 109, 17, 18, 109, 109, 109, 109, + 109, 55, 56, 57, 58, 109, 109, 109, 45, 109, + 109, 48, 109, 50, 109, 52, 14, 109, 38, 39, + 40, 109, 45, 109, 109, 48, 109, 50, 109, 52, + 14, 109, 109, 109, 109, 55, 56, 57, 58, 109, + 38, 39, 40, 109, 109, 22, 109, 38, 39, 40, + 109, 14, 109, 109, 38, 39, 40, 55, 56, 57, + 58, 38, 39, 40, 55, 56, 57, 58, 109, 109, + 61, 55, 56, 57, 58, 38, 39, 40, 55, 56, + 57, 58, 14, 109, 109, 109, 28, 109, 109, 109, + 109, 109, 55, 56, 57, 58, 38, 39, 40, 109, + 109, 109, 38, 39, 40, 109, 38, 39, 40, 109, + 38, 39, 40, 55, 56, 57, 58, 53, 109, 55, + 56, 57, 58, 55, 56, 57, 58, 55, 56, 57, + 58, ); public static $yy_shift_ofst = array( - -23, 399, 399, 449, 49, 49, 449, 349, 49, 49, - 349, -3, 49, 49, 49, 49, 49, 49, 49, 49, - 49, 49, 49, 149, 199, 299, 49, 149, 49, 49, - 49, 49, 49, 49, 249, 49, 99, 99, 499, 499, - 499, 499, 499, 499, 1664, 1617, 1617, 1144, 1982, 1973, - 1938, 1226, 1853, 1062, 980, 1879, 898, 1866, 1888, 1308, - 1308, 1308, 1308, 1308, 1308, 1308, 1308, 1308, 1308, 1308, - 1308, 1308, 520, 520, 533, 731, 1372, 171, 255, 129, - 708, 595, 9, 154, 129, 255, 308, 129, 255, 537, - 559, 1751, 244, 344, 511, 221, 294, 411, 40, 411, - -22, 438, 438, 436, 387, 427, 319, 355, -22, -22, - 420, 609, 232, 232, 232, 609, 232, 232, 232, 232, - -23, -23, -23, -23, 1740, 1691, 1954, 1936, 1996, 81, - 687, 461, 212, -22, 31, -14, -14, -22, 288, -14, - 288, -14, -22, 31, -22, -14, -14, -22, -22, 351, - -22, -22, -14, -22, -22, -22, -22, -22, -14, 210, - 232, 609, 232, 395, 609, 232, 609, 232, 395, 92, - 232, -23, -23, -23, -23, -23, -23, 1591, 30, -12, - 94, 144, 342, 596, 179, 103, 194, 454, 230, 152, - 269, 301, 318, 127, 282, -8, 205, 361, 378, 421, - 68, 467, 556, 606, 571, 598, 587, 586, 610, 549, - 572, 574, 570, 532, 530, 553, 298, 523, 544, 510, - 92, 534, 529, 519, 517, 496, 442, 481, + -31, 406, 406, 458, 458, 94, 510, 94, 94, 94, + 510, 458, -10, 94, 94, 354, 146, 94, 94, 94, + 94, 146, 94, 94, 94, 94, 250, 94, 94, 94, + 94, 94, 94, 302, 94, 94, 94, 198, 42, 42, + 42, 42, 42, 42, 42, 42, 1772, 828, 828, 80, + 712, 925, 301, 65, 272, 680, 1942, 1920, 1886, 1776, + 647, 1949, 1977, 2008, 2004, 1963, 1998, 1956, 2012, 2012, + 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, 2012, + 2012, 2012, 2012, 768, 650, 272, 65, 272, 65, 134, + 126, 479, 597, 1854, 154, 290, 95, 55, 258, 366, + 248, 366, 282, 443, 437, 38, 38, 437, 7, 481, + 410, 38, 461, 621, 596, 596, 261, 596, 596, 261, + 596, 596, 596, 596, 596, -31, -31, 1840, 1791, 1917, + 1903, 1834, 158, 238, 394, 446, 38, 25, 147, 169, + 147, 25, 169, 25, 38, 38, 25, 25, 38, 25, + 307, 38, 38, 25, 527, 38, 38, 25, 38, 38, + 38, 38, 38, 596, 624, 261, 624, 327, 596, 596, + 261, 596, 261, -31, -31, -31, -31, -31, -31, 781, + 3, 31, 193, 137, -30, 186, -17, 522, 349, 469, + 322, 30, 82, 316, 346, 376, 190, 358, 393, 152, + 209, 380, 385, 245, 315, 523, 585, 554, 576, 575, + 537, 573, 569, 529, 525, 546, 500, 526, 531, 325, + 530, 487, 494, 502, 470, 433, 430, 408, 383, 327, + 374, ); public static $yy_reduce_ofst = array( - 492, 527, 564, 592, 618, 703, 736, 768, 794, 822, - 850, 1068, 1096, 1122, 1150, 1286, 1204, 1232, 1260, 1040, - 1314, 1532, 1478, 1506, 1342, 1450, 1424, 1396, 1368, 1178, - 1014, 986, 932, 904, 876, 958, 1595, 1569, 1771, 1659, - 1760, 1734, 1723, 1797, 712, 1694, 1974, 37, 37, 37, - 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, - 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, - 37, 37, 37, 37, 114, -33, 372, -67, 6, 76, - 71, 233, 241, 190, 226, 4, 307, 276, 326, 172, - 429, 389, -23, -23, 339, 428, -23, 410, 390, 339, - 391, 386, 348, -23, 222, -23, 293, 155, 441, 445, - 390, 459, -23, -23, -23, 390, -23, -23, -23, 439, - -23, -23, 359, -23, 550, 550, 550, 550, 550, 545, - 555, 550, 550, 554, 566, 539, 539, 554, 547, 539, - 548, 539, 554, 546, 554, 539, 539, 554, 554, 563, - 554, 554, 539, 554, 554, 554, 554, 554, 539, 558, - 78, 320, 78, 522, 320, 78, 320, 78, 522, 196, - 78, 51, -61, -20, -4, 109, 132, + 471, 504, 563, 717, 574, 685, 919, 890, 787, 758, + 855, 823, 1240, 1199, 1140, 1100, 1070, 1129, 1170, 1210, + 1269, 1280, 1310, 1339, 1350, 1380, 1409, 1420, 1450, 1479, + 1490, 1059, 1030, 1000, 930, 960, 989, 1520, 1549, 1700, + 1619, 1689, 1660, 1630, 1590, 1560, 633, 661, 867, 8, + 166, 773, 255, 541, 174, 262, 35, 35, 35, 35, + 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, + 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, + 35, 35, 35, 294, -70, 196, 120, 68, 274, 19, + 206, 331, 444, 428, 257, 400, 382, 257, 257, 400, + 386, 397, 257, 386, 381, 388, 359, 314, 257, 442, + 482, 491, 484, 257, 257, 455, 386, 257, 257, 438, + 257, 257, 257, 257, 257, 257, 365, 509, 509, 509, + 509, 509, 524, 536, 509, 509, 528, 514, 539, 551, + 538, 514, 556, 514, 528, 528, 514, 514, 528, 514, + 518, 528, 528, 514, 532, 528, 528, 514, 528, 528, + 528, 528, 528, -90, 520, 122, 520, 566, -90, -90, + 122, -90, 122, -45, 36, 155, 101, 61, 17, ); public static $yyExpectedTokens = array( array(), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), array( - 3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 53, 54, 59, + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, ), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 54, 59,), - array(3, 11, 12, 13, 14, 16, 18, 20, 21, 22, 27, 31, 32, 33, 35, 37, 42, 43, 44, 45, 47, 49, 51, 54, 59,), - array(1, 3, 26, 28, 34, 39, 40, 55, 56, 57, 58,), - array(1, 3, 28, 34, 39, 40, 55, 56, 57, 58,), - array(1, 3, 28, 34, 39, 40, 55, 56, 57, 58,), - array(1, 3, 29, 39, 40, 55, 56, 57, 58,), - array(1, 3, 15, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 53, 55, 56, 57, 58,), - array(1, 3, 15, 39, 40, 55, 56, 57, 58,), - array(1, 3, 38, 39, 40, 55, 56, 57, 58,), - array(1, 3, 23, 39, 40, 55, 56, 57, 58,), - array(1, 3, 38, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58, 60,), - array(1, 3, 15, 39, 40, 55, 56, 57, 58,), - array(1, 2, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 15, 39, 40, 55, 56, 57, 58,), - array(1, 3, 15, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(1, 3, 39, 40, 55, 56, 57, 58,), - array(3, 39, 40, 55, 56, 57, 58,), - array(3, 39, 40, 55, 56, 57, 58,), - array(16, 18, 49, 51, 54,), - array(5, 11, 12, 13, 14, 16, 20, 21, 22, 27, 31, 32, 33, 59, 60,), - array(1, 15, 19, 28, 34, 37, 48,), - array(16, 18, 51, 54,), - array(1, 28, 34,), - array(16, 37, 54,), - array(5, 11, 12, 13, 14, 16, 20, 21, 22, 27, 31, 32, 33, 59, 60,), - array(11, 14, 18, 28, 30, 34,), - array(11, 14, 18, 28, 34,), - array(19, 45, 52,), - array(16, 37, 54,), - array(1, 28, 34,), - array(17, 19, 48,), - array(16, 37, 54,), - array(1, 28, 34,), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 53, 54, 59, + 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array( + 10, 11, 12, 13, 15, 17, 19, 20, 21, 26, 30, 31, 32, 34, 36, 39, 42, 43, 44, 45, 47, 49, 51, 52, 54, 59, 60, + ), + array(25, 27, 33, 38, 39, 40, 55, 56, 57, 58,), + array(27, 33, 38, 39, 40, 55, 56, 57, 58,), + array(27, 33, 38, 39, 40, 55, 56, 57, 58,), + array(15, 17, 49, 51, 54,), + array(4, 10, 11, 12, 13, 15, 19, 20, 21, 26, 30, 31, 32, 60, 61,), + array(1, 14, 18, 27, 33, 36, 48,), + array(15, 17, 51, 54,), + array(1, 27, 33,), + array(15, 36, 54,), + array(4, 10, 11, 12, 13, 15, 19, 20, 21, 26, 30, 31, 32, 60, 61,), + array(14, 38, 39, 40, 55, 56, 57, 58,), + array(2, 38, 39, 40, 55, 56, 57, 58,), + array(37, 38, 39, 40, 55, 56, 57, 58,), + array(37, 38, 39, 40, 55, 56, 57, 58,), + array(14, 38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58, 61,), + array(14, 38, 39, 40, 55, 56, 57, 58,), + array(14, 38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 53, 55, 56, 57, 58,), + array(22, 38, 39, 40, 55, 56, 57, 58,), + array(28, 38, 39, 40, 55, 56, 57, 58,), + array(14, 38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(38, 39, 40, 55, 56, 57, 58,), + array(10, 13, 17, 27, 29, 33,), + array(10, 13, 17, 27, 33,), + array(15, 36, 54,), + array(1, 27, 33,), + array(15, 36, 54,), + array(1, 27, 33,), + array(18, 45, 52,), + array(16, 18, 48,), array(1, 2,), - array(4, 5, 6, 7, 8, 11, 12, 13, 14, 20, 21, 22, 27, 31, 32, 33,), - array(2, 11, 14, 17, 18, 19, 45, 48, 50, 52,), - array(1, 15, 28, 34,), - array(1, 15, 28, 34,), - array(11, 14, 18, 50,), - array(14, 16, 18, 54,), - array(1, 15, 28, 34,), - array(11, 14, 18,), - array(17, 19, 48,), - array(11, 14, 18,), - array(28, 34,), - array(16, 18,), - array(16, 18,), + array(3, 4, 5, 6, 7, 10, 11, 12, 13, 19, 20, 21, 26, 30, 31, 32,), + array(2, 10, 13, 16, 17, 18, 45, 48, 50, 52,), + array(1, 14, 27, 33,), + array(10, 13, 17, 50,), + array(13, 15, 17, 54,), + array(1, 14, 27, 33,), + array(1, 14, 27, 33,), + array(10, 13, 17,), + array(16, 18, 48,), + array(10, 13, 17,), + array(1, 29,), + array(18, 48,), + array(15, 17,), + array(27, 33,), + array(27, 33,), + array(15, 17,), array(1, 53,), - array(1, 19,), - array(1, 30,), - array(16, 54,), - array(28, 34,), - array(28, 34,), - array(28, 34,), - array(19, 48,), - array(19,), + array(27, 33,), + array(1, 18,), + array(27, 33,), + array(15, 54,), array(1,), array(1,), array(1,), - array(19,), + array(18,), + array(1,), + array(1,), + array(18,), + array(1,), array(1,), array(1,), array(1,), array(1,), array(), array(), - array(), - array(), - array(2, 11, 14, 17, 18, 19, 45, 48, 50, 52,), - array(2, 11, 14, 18, 19, 45, 48, 50, 52, 53,), - array(2, 11, 14, 18, 19, 45, 48, 50, 52,), - array(2, 11, 14, 18, 19, 45, 48, 50, 52,), - array(11, 14, 18, 19, 45, 48, 50, 52,), - array(14, 16, 18, 35, 54,), - array(11, 14, 18, 50,), - array(11, 14, 18,), - array(17, 45, 52,), - array(28, 34,), - array(16, 54,), + array(2, 10, 13, 17, 18, 45, 48, 50, 52, 53,), + array(2, 10, 13, 16, 17, 18, 45, 48, 50, 52,), + array(2, 10, 13, 17, 18, 45, 48, 50, 52,), + array(2, 10, 13, 17, 18, 45, 48, 50, 52,), + array(10, 13, 17, 18, 45, 48, 50, 52,), + array(13, 15, 17, 34, 54,), + array(10, 13, 17, 50,), + array(16, 45, 52,), + array(10, 13, 17,), + array(27, 33,), array(45, 52,), + array(15, 54,), array(45, 52,), - array(28, 34,), + array(15, 54,), array(45, 52,), array(45, 52,), array(45, 52,), + array(27, 33,), + array(27, 33,), array(45, 52,), - array(28, 34,), - array(16, 54,), - array(28, 34,), array(45, 52,), + array(27, 33,), array(45, 52,), - array(28, 34,), - array(28, 34,), - array(17, 24,), - array(28, 34,), - array(28, 34,), + array(13, 36,), + array(27, 33,), + array(27, 33,), array(45, 52,), - array(28, 34,), - array(28, 34,), - array(28, 34,), - array(28, 34,), - array(28, 34,), + array(16, 23,), + array(27, 33,), + array(27, 33,), array(45, 52,), - array(14, 37,), - array(1,), - array(19,), + array(27, 33,), + array(27, 33,), + array(27, 33,), + array(27, 33,), + array(27, 33,), array(1,), array(2,), - array(19,), + array(18,), + array(2,), + array(36,), array(1,), - array(19,), array(1,), - array(2,), - array(37,), + array(18,), array(1,), + array(18,), array(), array(), array(), array(), array(), array(), - array(1, 2, 3, 37, 39, 40, 48, 55, 56, 57, 58,), - array(15, 23, 25, 28, 34, 36, 38, 45,), - array(15, 17, 28, 34, 37, 48,), - array(15, 24, 28, 34, 46,), - array(15, 24, 28, 34, 46,), - array(37, 45, 48, 53,), - array(11, 14, 18, 50,), - array(30, 37, 48,), - array(24, 46, 53,), - array(24, 46, 60,), - array(36, 53,), - array(36, 38,), + array(2, 36, 38, 39, 40, 48, 55, 56, 57, 58,), + array(14, 22, 24, 27, 33, 35, 37, 45,), + array(14, 16, 27, 33, 36, 48,), + array(14, 23, 27, 33, 46,), + array(14, 23, 27, 33, 46,), + array(36, 45, 48, 53,), + array(10, 13, 17, 50,), + array(29, 36, 48,), + array(23, 46, 61,), + array(23, 46, 53,), + array(35, 37,), + array(35, 37,), + array(16, 45,), + array(35, 53,), + array(8, 9,), + array(36, 48,), + array(36, 48,), + array(35, 37,), + array(23, 46,), + array(36, 48,), + array(17, 50,), + array(22, 35,), + array(7, 9,), + array(35, 37,), array(45, 53,), - array(8, 10,), - array(37, 48,), - array(37, 48,), - array(37, 48,), - array(23, 36,), - array(9, 10,), - array(18, 50,), - array(24, 46,), - array(36, 38,), - array(17, 45,), - array(36, 38,), - array(38,), - array(18,), - array(15,), - array(51,), + array(24,), + array(16,), + array(8,), + array(37,), + array(14,), array(17,), - array(18,), - array(18,), - array(9,), array(51,), - array(25,), + array(14,), array(15,), - array(18,), array(53,), array(53,), - array(16,), + array(17,), + array(51,), array(41,), + array(17,), + array(17,), + array(17,), array(45,), - array(18,), - array(35,), - array(37,), - array(18,), - array(18,), - array(18,), - array(18,), - array(37,), - array(35,), - array(18,), + array(34,), + array(17,), + array(17,), + array(34,), + array(17,), + array(36,), + array(17,), + array(36,), + array(17,), + array(), array(), array(), array(), @@ -901,39 +994,39 @@ class Smarty_Internal_Templateparser ); public static $yy_default = array( - 334, 509, 509, 494, 509, 473, 509, 509, 473, 473, - 509, 509, 509, 509, 509, 509, 509, 509, 509, 509, - 509, 509, 509, 509, 509, 509, 509, 509, 509, 509, - 509, 509, 509, 509, 509, 509, 509, 509, 509, 509, - 509, 509, 509, 509, 375, 354, 375, 380, 509, 509, - 347, 509, 509, 509, 509, 509, 509, 509, 509, 397, - 472, 347, 471, 387, 497, 495, 382, 386, 359, 377, - 380, 496, 402, 401, 509, 509, 413, 509, 375, 509, - 509, 375, 375, 485, 509, 375, 428, 509, 375, 366, - 323, 427, 389, 389, 438, 509, 389, 438, 428, 438, - 375, 509, 509, 389, 369, 389, 509, 375, 375, 356, - 428, 482, 405, 389, 406, 428, 396, 392, 400, 371, - 480, 404, 332, 393, 427, 427, 427, 427, 427, 509, - 440, 438, 454, 355, 509, 436, 434, 365, 433, 432, - 431, 465, 364, 509, 363, 466, 463, 362, 352, 509, - 351, 357, 435, 344, 350, 358, 361, 348, 464, 438, - 422, 460, 367, 474, 486, 372, 483, 395, 475, 438, - 370, 479, 479, 438, 438, 332, 479, 413, 409, 413, - 403, 403, 413, 439, 413, 403, 403, 509, 509, 409, - 330, 423, 509, 413, 509, 509, 509, 403, 509, 409, - 509, 509, 509, 509, 509, 509, 509, 509, 509, 509, - 383, 509, 509, 418, 509, 509, 415, 409, 509, 509, - 454, 509, 509, 509, 509, 484, 411, 509, 324, 426, - 415, 360, 442, 487, 444, 336, 443, 337, 488, 376, - 489, 490, 452, 481, 459, 454, 410, 441, 328, 419, - 325, 326, 437, 420, 477, 327, 476, 398, 399, 414, - 335, 421, 388, 424, 412, 451, 329, 331, 449, 333, - 384, 469, 500, 468, 491, 505, 343, 416, 417, 506, - 374, 391, 492, 493, 498, 341, 373, 418, 425, 353, - 501, 508, 507, 504, 502, 499, 461, 390, 368, 408, - 338, 503, 478, 453, 447, 446, 429, 445, 430, 448, - 450, 342, 462, 339, 340, 455, 470, 458, 457, 407, - 467, 456, 394, + 338, 514, 514, 499, 499, 514, 514, 476, 476, 476, + 514, 514, 514, 514, 514, 514, 514, 514, 514, 514, + 514, 514, 514, 514, 514, 514, 514, 514, 514, 514, + 514, 514, 514, 514, 514, 514, 514, 514, 514, 514, + 514, 514, 514, 514, 514, 514, 379, 358, 379, 514, + 514, 415, 514, 379, 514, 514, 351, 514, 514, 514, + 514, 514, 514, 514, 514, 514, 384, 514, 399, 475, + 351, 403, 390, 474, 500, 502, 384, 501, 363, 381, + 404, 386, 391, 379, 379, 514, 379, 514, 379, 489, + 431, 370, 327, 430, 393, 441, 514, 393, 393, 441, + 431, 441, 393, 431, 514, 379, 360, 514, 393, 379, + 373, 379, 514, 406, 402, 375, 431, 396, 398, 486, + 393, 408, 397, 407, 406, 483, 336, 430, 430, 430, + 430, 430, 514, 443, 457, 441, 367, 438, 514, 436, + 514, 435, 434, 466, 368, 348, 439, 437, 361, 467, + 441, 356, 354, 468, 514, 366, 355, 469, 362, 359, + 352, 369, 365, 371, 478, 463, 477, 441, 374, 376, + 490, 424, 487, 441, 441, 482, 482, 336, 482, 415, + 411, 415, 405, 405, 415, 442, 415, 405, 405, 514, + 514, 411, 514, 514, 425, 514, 514, 405, 415, 514, + 514, 334, 514, 411, 387, 514, 514, 514, 514, 514, + 514, 514, 514, 420, 514, 514, 514, 417, 514, 514, + 514, 411, 413, 514, 514, 514, 514, 488, 514, 457, + 514, 421, 364, 420, 340, 422, 357, 341, 409, 400, + 480, 457, 462, 401, 485, 423, 426, 342, 447, 380, + 416, 339, 428, 329, 330, 444, 445, 446, 394, 331, + 395, 429, 419, 388, 332, 418, 410, 392, 412, 333, + 335, 414, 337, 472, 417, 479, 427, 497, 347, 461, + 460, 459, 378, 346, 464, 510, 495, 511, 498, 473, + 377, 496, 503, 506, 513, 512, 509, 507, 504, 508, + 345, 458, 471, 448, 505, 454, 452, 455, 456, 450, + 491, 449, 492, 493, 494, 470, 451, 328, 453, 343, + 344, 372, 481, 432, 433, 465, 440, ); public static $yyFallback = array(); @@ -1010,8 +1103,6 @@ class Smarty_Internal_Templateparser 'expr ::= DOLLARID COLON ID', 'expr ::= expr MATH value', 'expr ::= expr UNIMATH value', - 'expr ::= array', - 'expr ::= expr modifierlist', 'expr ::= expr tlop value', 'expr ::= expr lop expr', 'expr ::= expr scond', @@ -1040,6 +1131,7 @@ class Smarty_Internal_Templateparser 'value ::= smartytag', 'value ::= value modifierlist', 'value ::= NAMESPACE', + 'value ::= arraydef', 'value ::= ns1 DOUBLECOLON static_class_access', 'ns1 ::= ID', 'ns1 ::= NAMESPACE', @@ -1097,6 +1189,7 @@ class Smarty_Internal_Templateparser 'modparameters ::= modparameters modparameter', 'modparameters ::=', 'modparameter ::= COLON value', + 'modparameter ::= COLON UNIMATH value', 'modparameter ::= COLON array', 'static_class_access ::= method', 'static_class_access ::= method objectchain', @@ -1107,7 +1200,8 @@ class Smarty_Internal_Templateparser 'lop ::= SLOGOP', 'tlop ::= TLOGOP', 'scond ::= SINGLECOND', - 'array ::= OPENB arrayelements CLOSEB', + 'arraydef ::= OPENB arrayelements CLOSEB', + 'arraydef ::= ARRAYOPEN arrayelements CLOSEP', 'arrayelements ::= arrayelement', 'arrayelements ::= arrayelements COMMA arrayelement', 'arrayelements ::=', @@ -1128,192 +1222,193 @@ class Smarty_Internal_Templateparser ); public static $yyRuleInfo = array( - array(0 => 62, 1 => 1), - array(0 => 63, 1 => 2), - array(0 => 63, 1 => 2), - array(0 => 63, 1 => 2), - array(0 => 63, 1 => 2), - array(0 => 63, 1 => 4), + array(0 => 63, 1 => 1), + array(0 => 64, 1 => 2), + array(0 => 64, 1 => 2), + array(0 => 64, 1 => 2), + array(0 => 64, 1 => 2), array(0 => 64, 1 => 4), - array(0 => 64, 1 => 1), - array(0 => 65, 1 => 2), - array(0 => 65, 1 => 0), - array(0 => 63, 1 => 2), - array(0 => 63, 1 => 0), - array(0 => 66, 1 => 1), - array(0 => 66, 1 => 1), - array(0 => 66, 1 => 1), - array(0 => 66, 1 => 3), + array(0 => 65, 1 => 4), + array(0 => 65, 1 => 1), array(0 => 66, 1 => 2), + array(0 => 66, 1 => 0), + array(0 => 64, 1 => 2), + array(0 => 64, 1 => 0), array(0 => 67, 1 => 1), + array(0 => 67, 1 => 1), + array(0 => 67, 1 => 1), + array(0 => 67, 1 => 3), array(0 => 67, 1 => 2), - array(0 => 67, 1 => 2), - array(0 => 70, 1 => 2), - array(0 => 69, 1 => 2), - array(0 => 72, 1 => 1), - array(0 => 72, 1 => 1), - array(0 => 72, 1 => 1), - array(0 => 68, 1 => 3), + array(0 => 68, 1 => 1), array(0 => 68, 1 => 2), - array(0 => 68, 1 => 4), - array(0 => 68, 1 => 5), - array(0 => 68, 1 => 6), array(0 => 68, 1 => 2), - array(0 => 68, 1 => 2), - array(0 => 68, 1 => 3), - array(0 => 68, 1 => 2), - array(0 => 68, 1 => 3), - array(0 => 68, 1 => 8), - array(0 => 80, 1 => 2), - array(0 => 80, 1 => 1), - array(0 => 68, 1 => 5), - array(0 => 68, 1 => 7), - array(0 => 68, 1 => 6), - array(0 => 68, 1 => 8), - array(0 => 68, 1 => 2), - array(0 => 68, 1 => 3), - array(0 => 68, 1 => 4), - array(0 => 66, 1 => 1), - array(0 => 68, 1 => 2), - array(0 => 68, 1 => 3), - array(0 => 68, 1 => 4), - array(0 => 68, 1 => 5), - array(0 => 73, 1 => 2), + array(0 => 71, 1 => 2), + array(0 => 70, 1 => 2), array(0 => 73, 1 => 1), - array(0 => 73, 1 => 0), - array(0 => 83, 1 => 4), - array(0 => 83, 1 => 2), - array(0 => 83, 1 => 2), - array(0 => 83, 1 => 2), - array(0 => 83, 1 => 2), - array(0 => 83, 1 => 2), - array(0 => 83, 1 => 4), - array(0 => 79, 1 => 1), + array(0 => 73, 1 => 1), + array(0 => 73, 1 => 1), + array(0 => 69, 1 => 3), + array(0 => 69, 1 => 2), + array(0 => 69, 1 => 4), + array(0 => 69, 1 => 5), + array(0 => 69, 1 => 6), + array(0 => 69, 1 => 2), + array(0 => 69, 1 => 2), + array(0 => 69, 1 => 3), + array(0 => 69, 1 => 2), + array(0 => 69, 1 => 3), + array(0 => 69, 1 => 8), + array(0 => 81, 1 => 2), + array(0 => 81, 1 => 1), + array(0 => 69, 1 => 5), + array(0 => 69, 1 => 7), + array(0 => 69, 1 => 6), + array(0 => 69, 1 => 8), + array(0 => 69, 1 => 2), + array(0 => 69, 1 => 3), + array(0 => 69, 1 => 4), + array(0 => 67, 1 => 1), + array(0 => 69, 1 => 2), + array(0 => 69, 1 => 3), + array(0 => 69, 1 => 4), + array(0 => 69, 1 => 5), + array(0 => 74, 1 => 2), + array(0 => 74, 1 => 1), + array(0 => 74, 1 => 0), + array(0 => 84, 1 => 4), + array(0 => 84, 1 => 2), + array(0 => 84, 1 => 2), + array(0 => 84, 1 => 2), + array(0 => 84, 1 => 2), + array(0 => 84, 1 => 2), + array(0 => 84, 1 => 4), + array(0 => 80, 1 => 1), + array(0 => 80, 1 => 3), array(0 => 79, 1 => 3), - array(0 => 78, 1 => 3), - array(0 => 78, 1 => 3), - array(0 => 78, 1 => 3), - array(0 => 78, 1 => 3), + array(0 => 79, 1 => 3), + array(0 => 79, 1 => 3), + array(0 => 79, 1 => 3), + array(0 => 77, 1 => 1), + array(0 => 77, 1 => 1), + array(0 => 77, 1 => 3), + array(0 => 77, 1 => 3), + array(0 => 77, 1 => 3), + array(0 => 77, 1 => 3), + array(0 => 77, 1 => 3), + array(0 => 77, 1 => 2), + array(0 => 77, 1 => 3), + array(0 => 77, 1 => 3), + array(0 => 85, 1 => 7), + array(0 => 85, 1 => 7), + array(0 => 76, 1 => 1), + array(0 => 76, 1 => 2), + array(0 => 76, 1 => 2), + array(0 => 76, 1 => 2), + array(0 => 76, 1 => 2), + array(0 => 76, 1 => 1), + array(0 => 76, 1 => 1), + array(0 => 76, 1 => 3), + array(0 => 76, 1 => 2), + array(0 => 76, 1 => 2), array(0 => 76, 1 => 1), array(0 => 76, 1 => 1), array(0 => 76, 1 => 3), array(0 => 76, 1 => 3), array(0 => 76, 1 => 3), array(0 => 76, 1 => 1), - array(0 => 76, 1 => 2), - array(0 => 76, 1 => 3), + array(0 => 76, 1 => 1), array(0 => 76, 1 => 3), + array(0 => 76, 1 => 1), array(0 => 76, 1 => 2), + array(0 => 76, 1 => 1), + array(0 => 76, 1 => 1), array(0 => 76, 1 => 3), - array(0 => 76, 1 => 3), - array(0 => 84, 1 => 7), - array(0 => 84, 1 => 7), - array(0 => 75, 1 => 1), - array(0 => 75, 1 => 2), - array(0 => 75, 1 => 2), - array(0 => 75, 1 => 2), - array(0 => 75, 1 => 2), + array(0 => 91, 1 => 1), + array(0 => 91, 1 => 1), array(0 => 75, 1 => 1), array(0 => 75, 1 => 1), array(0 => 75, 1 => 3), - array(0 => 75, 1 => 2), - array(0 => 75, 1 => 2), - array(0 => 75, 1 => 1), - array(0 => 75, 1 => 1), - array(0 => 75, 1 => 3), - array(0 => 75, 1 => 3), - array(0 => 75, 1 => 3), - array(0 => 75, 1 => 1), array(0 => 75, 1 => 1), array(0 => 75, 1 => 3), - array(0 => 75, 1 => 1), - array(0 => 75, 1 => 2), - array(0 => 75, 1 => 1), + array(0 => 75, 1 => 4), array(0 => 75, 1 => 3), - array(0 => 90, 1 => 1), - array(0 => 90, 1 => 1), - array(0 => 74, 1 => 1), - array(0 => 74, 1 => 1), - array(0 => 74, 1 => 3), - array(0 => 74, 1 => 1), - array(0 => 74, 1 => 3), - array(0 => 74, 1 => 4), - array(0 => 74, 1 => 3), - array(0 => 74, 1 => 4), - array(0 => 71, 1 => 2), - array(0 => 71, 1 => 2), - array(0 => 94, 1 => 2), - array(0 => 94, 1 => 0), - array(0 => 95, 1 => 2), - array(0 => 95, 1 => 2), - array(0 => 95, 1 => 4), - array(0 => 95, 1 => 2), - array(0 => 95, 1 => 2), - array(0 => 95, 1 => 4), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 5), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 3), - array(0 => 95, 1 => 2), - array(0 => 81, 1 => 1), - array(0 => 81, 1 => 1), - array(0 => 81, 1 => 2), - array(0 => 96, 1 => 1), - array(0 => 96, 1 => 1), - array(0 => 96, 1 => 3), - array(0 => 93, 1 => 2), - array(0 => 97, 1 => 1), + array(0 => 75, 1 => 4), + array(0 => 72, 1 => 2), + array(0 => 72, 1 => 2), + array(0 => 96, 1 => 2), + array(0 => 96, 1 => 0), array(0 => 97, 1 => 2), + array(0 => 97, 1 => 2), + array(0 => 97, 1 => 4), + array(0 => 97, 1 => 2), + array(0 => 97, 1 => 2), + array(0 => 97, 1 => 4), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 5), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 3), + array(0 => 97, 1 => 2), + array(0 => 82, 1 => 1), + array(0 => 82, 1 => 1), + array(0 => 82, 1 => 2), + array(0 => 98, 1 => 1), + array(0 => 98, 1 => 1), array(0 => 98, 1 => 3), - array(0 => 98, 1 => 3), - array(0 => 98, 1 => 5), - array(0 => 98, 1 => 6), - array(0 => 98, 1 => 2), - array(0 => 89, 1 => 4), - array(0 => 99, 1 => 4), - array(0 => 99, 1 => 4), + array(0 => 95, 1 => 2), + array(0 => 99, 1 => 1), + array(0 => 99, 1 => 2), array(0 => 100, 1 => 3), - array(0 => 100, 1 => 1), - array(0 => 100, 1 => 0), - array(0 => 77, 1 => 3), - array(0 => 77, 1 => 2), - array(0 => 101, 1 => 3), - array(0 => 101, 1 => 2), - array(0 => 82, 1 => 2), - array(0 => 82, 1 => 0), - array(0 => 102, 1 => 2), - array(0 => 102, 1 => 2), - array(0 => 92, 1 => 1), - array(0 => 92, 1 => 2), - array(0 => 92, 1 => 1), - array(0 => 92, 1 => 2), - array(0 => 92, 1 => 3), + array(0 => 100, 1 => 3), + array(0 => 100, 1 => 5), + array(0 => 100, 1 => 6), + array(0 => 100, 1 => 2), + array(0 => 90, 1 => 4), + array(0 => 101, 1 => 4), + array(0 => 101, 1 => 4), + array(0 => 102, 1 => 3), + array(0 => 102, 1 => 1), + array(0 => 102, 1 => 0), + array(0 => 78, 1 => 3), + array(0 => 78, 1 => 2), + array(0 => 103, 1 => 3), + array(0 => 103, 1 => 2), + array(0 => 83, 1 => 2), + array(0 => 83, 1 => 0), + array(0 => 104, 1 => 2), + array(0 => 104, 1 => 3), + array(0 => 104, 1 => 2), + array(0 => 93, 1 => 1), + array(0 => 93, 1 => 2), + array(0 => 93, 1 => 1), + array(0 => 93, 1 => 2), + array(0 => 93, 1 => 3), array(0 => 87, 1 => 1), array(0 => 87, 1 => 1), array(0 => 86, 1 => 1), array(0 => 88, 1 => 1), - array(0 => 85, 1 => 3), - array(0 => 103, 1 => 1), - array(0 => 103, 1 => 3), - array(0 => 103, 1 => 0), - array(0 => 104, 1 => 3), - array(0 => 104, 1 => 3), - array(0 => 104, 1 => 1), - array(0 => 91, 1 => 2), - array(0 => 91, 1 => 3), - array(0 => 105, 1 => 2), + array(0 => 94, 1 => 3), + array(0 => 94, 1 => 3), array(0 => 105, 1 => 1), + array(0 => 105, 1 => 3), + array(0 => 105, 1 => 0), array(0 => 106, 1 => 3), array(0 => 106, 1 => 3), array(0 => 106, 1 => 1), - array(0 => 106, 1 => 3), - array(0 => 106, 1 => 3), - array(0 => 106, 1 => 1), - array(0 => 106, 1 => 1), + array(0 => 92, 1 => 2), + array(0 => 92, 1 => 3), + array(0 => 107, 1 => 2), + array(0 => 107, 1 => 1), + array(0 => 108, 1 => 3), + array(0 => 108, 1 => 3), + array(0 => 108, 1 => 1), + array(0 => 108, 1 => 3), + array(0 => 108, 1 => 3), + array(0 => 108, 1 => 1), + array(0 => 108, 1 => 1), ); public static $yyReduceMap = array( @@ -1333,18 +1428,18 @@ class Smarty_Internal_Templateparser 58 => 7, 66 => 7, 67 => 7, - 71 => 7, - 80 => 7, - 85 => 7, - 86 => 7, - 91 => 7, - 95 => 7, - 96 => 7, - 100 => 7, - 102 => 7, - 107 => 7, - 169 => 7, - 174 => 7, + 78 => 7, + 83 => 7, + 84 => 7, + 89 => 7, + 93 => 7, + 94 => 7, + 98 => 7, + 99 => 7, + 101 => 7, + 106 => 7, + 170 => 7, + 175 => 7, 8 => 8, 9 => 9, 10 => 10, @@ -1385,18 +1480,18 @@ class Smarty_Internal_Templateparser 50 => 50, 51 => 51, 60 => 51, - 149 => 51, - 153 => 51, - 157 => 51, + 148 => 51, + 152 => 51, + 156 => 51, 158 => 51, 52 => 52, - 150 => 52, - 156 => 52, + 149 => 52, + 155 => 52, 53 => 53, 54 => 54, 55 => 54, 56 => 56, - 134 => 56, + 133 => 56, 59 => 59, 61 => 61, 62 => 62, @@ -1406,61 +1501,61 @@ class Smarty_Internal_Templateparser 68 => 68, 69 => 69, 70 => 69, + 71 => 71, 72 => 72, - 99 => 72, 73 => 73, 74 => 74, 75 => 75, 76 => 76, 77 => 77, - 78 => 78, 79 => 79, - 81 => 81, - 83 => 81, - 84 => 81, - 114 => 81, - 82 => 82, + 81 => 79, + 82 => 79, + 113 => 79, + 80 => 80, + 85 => 85, + 86 => 86, 87 => 87, 88 => 88, - 89 => 89, 90 => 90, - 92 => 92, - 93 => 93, - 94 => 93, + 91 => 91, + 92 => 91, + 95 => 95, + 96 => 96, 97 => 97, - 98 => 98, - 101 => 101, + 100 => 100, + 102 => 102, 103 => 103, 104 => 104, 105 => 105, - 106 => 106, + 107 => 107, 108 => 108, 109 => 109, 110 => 110, 111 => 111, 112 => 112, - 113 => 113, + 114 => 114, + 172 => 114, 115 => 115, - 171 => 115, 116 => 116, 117 => 117, 118 => 118, 119 => 119, 120 => 120, + 128 => 120, 121 => 121, - 129 => 121, 122 => 122, 123 => 123, - 124 => 124, - 125 => 124, - 127 => 124, - 128 => 124, - 126 => 126, + 124 => 123, + 126 => 123, + 127 => 123, + 125 => 125, + 129 => 129, 130 => 130, 131 => 131, + 176 => 131, 132 => 132, - 175 => 132, - 133 => 133, + 134 => 134, 135 => 135, 136 => 136, 137 => 137, @@ -1474,11 +1569,11 @@ class Smarty_Internal_Templateparser 145 => 145, 146 => 146, 147 => 147, - 148 => 148, + 150 => 150, 151 => 151, - 152 => 152, + 153 => 153, 154 => 154, - 155 => 155, + 157 => 157, 159 => 159, 160 => 160, 161 => 161, @@ -1489,19 +1584,20 @@ class Smarty_Internal_Templateparser 166 => 166, 167 => 167, 168 => 168, - 170 => 170, - 172 => 172, + 169 => 168, + 171 => 171, 173 => 173, - 176 => 176, + 174 => 174, 177 => 177, 178 => 178, 179 => 179, - 182 => 179, 180 => 180, 183 => 180, 181 => 181, - 184 => 184, + 184 => 181, + 182 => 182, 185 => 185, + 186 => 186, ); /** @@ -1625,33 +1721,34 @@ class Smarty_Internal_Templateparser public $yystack = array(); public $yyTokenName = array( - '$', 'VERT', 'COLON', 'UNIMATH', - 'PHP', 'TEXT', 'STRIPON', 'STRIPOFF', - 'LITERALSTART', 'LITERALEND', 'LITERAL', 'SIMPELOUTPUT', - 'SIMPLETAG', 'SMARTYBLOCKCHILDPARENT', 'LDEL', 'RDEL', - 'DOLLARID', 'EQUAL', 'ID', 'PTR', - 'LDELMAKENOCACHE', 'LDELIF', 'LDELFOR', 'SEMICOLON', - 'INCDEC', 'TO', 'STEP', 'LDELFOREACH', - 'SPACE', 'AS', 'APTR', 'LDELSETFILTER', - 'CLOSETAG', 'LDELSLASH', 'ATTR', 'INTEGER', - 'COMMA', 'OPENP', 'CLOSEP', 'MATH', + '$', 'VERT', 'COLON', 'PHP', + 'TEXT', 'STRIPON', 'STRIPOFF', 'LITERALSTART', + 'LITERALEND', 'LITERAL', 'SIMPELOUTPUT', 'SIMPLETAG', + 'SMARTYBLOCKCHILDPARENT', 'LDEL', 'RDEL', 'DOLLARID', + 'EQUAL', 'ID', 'PTR', 'LDELMAKENOCACHE', + 'LDELIF', 'LDELFOR', 'SEMICOLON', 'INCDEC', + 'TO', 'STEP', 'LDELFOREACH', 'SPACE', + 'AS', 'APTR', 'LDELSETFILTER', 'CLOSETAG', + 'LDELSLASH', 'ATTR', 'INTEGER', 'COMMA', + 'OPENP', 'CLOSEP', 'MATH', 'UNIMATH', 'ISIN', 'QMARK', 'NOT', 'TYPECAST', 'HEX', 'DOT', 'INSTANCEOF', 'SINGLEQUOTESTRING', 'DOUBLECOLON', 'NAMESPACE', 'AT', 'HATCH', 'OPENB', 'CLOSEB', 'DOLLAR', 'LOGOP', - 'SLOGOP', 'TLOGOP', 'SINGLECOND', 'QUOTE', - 'BACKTICK', 'error', 'start', 'template', - 'literal_e2', 'literal_e1', 'smartytag', 'tagbody', - 'tag', 'outattr', 'eqoutattr', 'varindexed', - 'output', 'attributes', 'variable', 'value', - 'expr', 'modifierlist', 'statement', 'statements', - 'foraction', 'varvar', 'modparameters', 'attribute', - 'ternary', 'array', 'tlop', 'lop', - 'scond', 'function', 'ns1', 'doublequoted_with_quotes', - 'static_class_access', 'object', 'arrayindex', 'indexdef', - 'varvarele', 'objectchain', 'objectelement', 'method', - 'params', 'modifier', 'modparameter', 'arrayelements', - 'arrayelement', 'doublequoted', 'doublequotedcontent', + 'SLOGOP', 'TLOGOP', 'SINGLECOND', 'ARRAYOPEN', + 'QUOTE', 'BACKTICK', 'error', 'start', + 'template', 'literal_e2', 'literal_e1', 'smartytag', + 'tagbody', 'tag', 'outattr', 'eqoutattr', + 'varindexed', 'output', 'attributes', 'variable', + 'value', 'expr', 'modifierlist', 'statement', + 'statements', 'foraction', 'varvar', 'modparameters', + 'attribute', 'ternary', 'tlop', 'lop', + 'scond', 'array', 'function', 'ns1', + 'doublequoted_with_quotes', 'static_class_access', 'arraydef', 'object', + 'arrayindex', 'indexdef', 'varvarele', 'objectchain', + 'objectelement', 'method', 'params', 'modifier', + 'modparameter', 'arrayelements', 'arrayelement', 'doublequoted', + 'doublequotedcontent', ); /** @@ -1762,11 +1859,9 @@ class Smarty_Internal_Templateparser } $yytos = array_pop($this->yystack); if ($this->yyTraceFILE && $this->yyidx >= 0) { - fwrite( - $this->yyTraceFILE, + fwrite($this->yyTraceFILE, $this->yyTracePrompt . 'Popping ' . $this->yyTokenName[ $yytos->major ] . - "\n" - ); + "\n"); } $yymajor = $yytos->major; self::yy_destructor($yymajor, $yytos->minor); @@ -1818,8 +1913,7 @@ class Smarty_Internal_Templateparser $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ]; $nextstate = $this->yy_find_reduce_action( $this->yystack[ $this->yyidx ]->stateno, - self::$yyRuleInfo[ $yyruleno ][ 0 ] - ); + self::$yyRuleInfo[ $yyruleno ][ 0 ]); if (isset(self::$yyExpectedTokens[ $nextstate ])) { $expected = array_merge($expected, self::$yyExpectedTokens[ $nextstate ]); if (isset($res4[ $nextstate ][ $token ])) { @@ -1905,8 +1999,7 @@ class Smarty_Internal_Templateparser $this->yyidx -= self::$yyRuleInfo[ $yyruleno ][ 1 ]; $nextstate = $this->yy_find_reduce_action( $this->yystack[ $this->yyidx ]->stateno, - self::$yyRuleInfo[ $yyruleno ][ 0 ] - ); + self::$yyRuleInfo[ $yyruleno ][ 0 ]); if (isset($res2[ $nextstate ][ $token ])) { if ($res2[ $nextstate ][ $token ]) { $this->yyidx = $yyidx; @@ -2036,19 +2129,12 @@ class Smarty_Internal_Templateparser $yytos->minor = $yypMinor; $this->yystack[] = $yytos; if ($this->yyTraceFILE && $this->yyidx > 0) { - fprintf( - $this->yyTraceFILE, - "%sShift %d\n", - $this->yyTracePrompt, - $yyNewState - ); + fprintf($this->yyTraceFILE, "%sShift %d\n", $this->yyTracePrompt, + $yyNewState); fprintf($this->yyTraceFILE, "%sStack:", $this->yyTracePrompt); for ($i = 1; $i <= $this->yyidx; $i++) { - fprintf( - $this->yyTraceFILE, - " %s", - $this->yyTokenName[ $this->yystack[ $i ]->major ] - ); + fprintf($this->yyTraceFILE, " %s", + $this->yyTokenName[ $this->yystack[ $i ]->major ]); } fwrite($this->yyTraceFILE, "\n"); } @@ -2606,7 +2692,7 @@ class Smarty_Internal_Templateparser '\')'; } - // line 642 "../smarty/lexer/smarty_internal_templateparser.y" + // line 638 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r69() { $this->_retvalue = @@ -2615,18 +2701,8 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 648 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r72() - { - $this->_retvalue = - $this->compiler->compileTag('private_modifier', array(), array( - 'value' => $this->yystack[ $this->yyidx + -1 ]->minor, - 'modifierlist' => $this->yystack[ $this->yyidx + 0 ]->minor - )); - } - - // line 652 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r73() + // line 642 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r71() { $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor[ 'pre' ] . @@ -2636,8 +2712,8 @@ class Smarty_Internal_Templateparser ')'; } - // line 656 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r74() + // line 646 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r72() { $this->_retvalue = $this->yystack[ $this->yyidx + -2 ]->minor . @@ -2645,14 +2721,14 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 660 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r75() + // line 650 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r73() { $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor . $this->yystack[ $this->yyidx + -1 ]->minor . ')'; } - // line 664 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r76() + // line 654 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r74() { $this->_retvalue = 'in_array(' . @@ -2662,8 +2738,8 @@ class Smarty_Internal_Templateparser ')'; } - // line 672 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r77() + // line 662 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r75() { $this->_retvalue = 'in_array(' . @@ -2673,8 +2749,8 @@ class Smarty_Internal_Templateparser ')'; } - // line 676 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r78() + // line 666 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r76() { $this->_retvalue = $this->yystack[ $this->yyidx + -5 ]->minor . @@ -2684,8 +2760,8 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 686 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r79() + // line 676 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r77() { $this->_retvalue = $this->yystack[ $this->yyidx + -5 ]->minor . @@ -2695,38 +2771,38 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 691 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r81() + // line 681 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r79() { $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 712 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r82() + // line 702 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r80() { $this->_retvalue = '!' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 716 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r87() + // line 706 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r85() { $this->_retvalue = $this->yystack[ $this->yyidx + -2 ]->minor . '.' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 720 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r88() + // line 710 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r86() { $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor . '.'; } - // line 725 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r89() + // line 715 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r87() { $this->_retvalue = '.' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 742 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r90() + // line 732 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r88() { if (defined($this->yystack[ $this->yyidx + 0 ]->minor)) { if ($this->security) { @@ -2738,14 +2814,14 @@ class Smarty_Internal_Templateparser } } - // line 746 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r92() + // line 736 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r90() { $this->_retvalue = '(' . $this->yystack[ $this->yyidx + -1 ]->minor . ')'; } - // line 764 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r93() + // line 754 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r91() { $this->_retvalue = $this->yystack[ $this->yyidx + -2 ]->minor . @@ -2753,8 +2829,8 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 775 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r97() + // line 765 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r95() { $prefixVar = $this->compiler->getNewPrefixVariable(); if ($this->yystack[ $this->yyidx + -2 ]->minor[ 'var' ] === '\'smarty\'') { @@ -2777,8 +2853,8 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor[ 1 ]; } - // line 792 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r98() + // line 772 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r96() { $prefixVar = $this->compiler->getNewPrefixVariable(); $tmp = $this->compiler->appendCode('', $this->yystack[ $this->yyidx + 0 ]->minor); @@ -2786,8 +2862,18 @@ class Smarty_Internal_Templateparser $this->_retvalue = $prefixVar; } - // line 811 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r101() + // line 785 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r97() + { + $this->_retvalue = + $this->compiler->compileTag('private_modifier', array(), array( + 'value' => $this->yystack[ $this->yyidx + -1 ]->minor, + 'modifierlist' => $this->yystack[ $this->yyidx + 0 ]->minor + )); + } + + // line 804 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r100() { if (!in_array(strtolower($this->yystack[ $this->yyidx + -2 ]->minor), array('self', 'parent')) && (!$this->security || @@ -2813,21 +2899,21 @@ class Smarty_Internal_Templateparser } } - // line 822 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r103() + // line 815 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r102() { $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 825 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r104() + // line 818 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r103() { $this->_retvalue = $this->compiler->compileVariable('\'' . substr($this->yystack[ $this->yyidx + 0 ]->minor, 1) . '\''); } - // line 838 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r105() + // line 831 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r104() { if ($this->yystack[ $this->yyidx + 0 ]->minor[ 'var' ] === '\'smarty\'') { $smarty_var = @@ -2844,8 +2930,8 @@ class Smarty_Internal_Templateparser } } - // line 848 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r106() + // line 841 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r105() { $this->_retvalue = '$_smarty_tpl->tpl_vars[' . @@ -2854,15 +2940,15 @@ class Smarty_Internal_Templateparser $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 852 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r108() + // line 845 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r107() { $this->_retvalue = $this->compiler->compileConfigVariable('\'' . $this->yystack[ $this->yyidx + -1 ]->minor . '\''); } - // line 856 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r109() + // line 849 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r108() { $this->_retvalue = '(is_array($tmp = ' . @@ -2872,14 +2958,14 @@ class Smarty_Internal_Templateparser ' :null)'; } - // line 860 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r110() + // line 853 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r109() { $this->_retvalue = $this->compiler->compileConfigVariable($this->yystack[ $this->yyidx + -1 ]->minor); } - // line 864 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r111() + // line 857 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r110() { $this->_retvalue = '(is_array($tmp = ' . @@ -2889,8 +2975,8 @@ class Smarty_Internal_Templateparser ' : null)'; } - // line 867 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r112() + // line 860 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r111() { $this->_retvalue = array( @@ -2899,8 +2985,8 @@ class Smarty_Internal_Templateparser ); } - // line 880 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r113() + // line 873 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r112() { $this->_retvalue = array( @@ -2909,14 +2995,14 @@ class Smarty_Internal_Templateparser ); } - // line 886 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r115() + // line 879 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r114() { return; } - // line 889 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r116() + // line 882 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r115() { $this->_retvalue = '[' . @@ -2924,14 +3010,14 @@ class Smarty_Internal_Templateparser ']'; } - // line 893 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r117() + // line 886 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r116() { $this->_retvalue = '[' . $this->compiler->compileVariable($this->yystack[ $this->yyidx + 0 ]->minor) . ']'; } - // line 897 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r118() + // line 890 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r117() { $this->_retvalue = '[' . @@ -2941,26 +3027,26 @@ class Smarty_Internal_Templateparser ']'; } - // line 901 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r119() + // line 894 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r118() { $this->_retvalue = '[\'' . $this->yystack[ $this->yyidx + 0 ]->minor . '\']'; } - // line 906 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r120() + // line 899 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r119() { $this->_retvalue = '[' . $this->yystack[ $this->yyidx + 0 ]->minor . ']'; } - // line 911 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r121() + // line 904 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r120() { $this->_retvalue = '[' . $this->yystack[ $this->yyidx + -1 ]->minor . ']'; } - // line 915 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r122() + // line 908 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r121() { $this->_retvalue = '[' . @@ -2969,8 +3055,8 @@ class Smarty_Internal_Templateparser ']'; } - // line 918 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r123() + // line 911 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r122() { $this->_retvalue = '[' . @@ -2984,14 +3070,14 @@ class Smarty_Internal_Templateparser ']'; } - // line 924 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r124() + // line 917 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r123() { $this->_retvalue = '[' . $this->yystack[ $this->yyidx + -1 ]->minor . ']'; } - // line 940 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r126() + // line 933 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r125() { $this->_retvalue = '[' . @@ -2999,32 +3085,32 @@ class Smarty_Internal_Templateparser ']'; } - // line 950 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r130() + // line 943 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r129() { $this->_retvalue = '[]'; } - // line 954 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r131() + // line 947 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r130() { $this->_retvalue = '\'' . substr($this->yystack[ $this->yyidx + 0 ]->minor, 1) . '\''; } - // line 959 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r132() + // line 952 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r131() { $this->_retvalue = '\'\''; } - // line 967 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r133() + // line 960 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r132() { $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor . '.' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 973 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r135() + // line 966 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r134() { $var = trim(substr($this->yystack[ $this->yyidx + 0 ]->minor, $this->compiler->getLdelLength(), @@ -3032,14 +3118,14 @@ class Smarty_Internal_Templateparser $this->_retvalue = $this->compiler->compileVariable('\'' . $var . '\''); } - // line 980 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r136() + // line 973 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r135() { $this->_retvalue = '(' . $this->yystack[ $this->yyidx + -1 ]->minor . ')'; } - // line 989 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r137() + // line 982 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r136() { if ($this->yystack[ $this->yyidx + -1 ]->minor[ 'var' ] === '\'smarty\'') { $this->_retvalue = @@ -3054,20 +3140,20 @@ class Smarty_Internal_Templateparser } } - // line 994 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r138() + // line 987 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r137() { $this->_retvalue = $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 999 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r139() + // line 992 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r138() { $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 1006 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r140() + // line 999 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r139() { if ($this->security && substr($this->yystack[ $this->yyidx + -1 ]->minor, 0, 1) === '_') { $this->compiler->trigger_template_error(self::ERR1); @@ -3076,8 +3162,8 @@ class Smarty_Internal_Templateparser '->' . $this->yystack[ $this->yyidx + -1 ]->minor . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 1013 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r141() + // line 1006 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r140() { if ($this->security) { $this->compiler->trigger_template_error(self::ERR2); @@ -3089,8 +3175,8 @@ class Smarty_Internal_Templateparser '}'; } - // line 1020 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r142() + // line 1013 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r141() { if ($this->security) { $this->compiler->trigger_template_error(self::ERR2); @@ -3099,8 +3185,8 @@ class Smarty_Internal_Templateparser '->{' . $this->yystack[ $this->yyidx + -2 ]->minor . $this->yystack[ $this->yyidx + 0 ]->minor . '}'; } - // line 1028 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r143() + // line 1021 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r142() { if ($this->security) { $this->compiler->trigger_template_error(self::ERR2); @@ -3114,22 +3200,22 @@ class Smarty_Internal_Templateparser '}'; } - // line 1036 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r144() + // line 1029 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r143() { $this->_retvalue = '->' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 1044 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r145() + // line 1037 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r144() { $this->_retvalue = $this->compiler->compilePHPFunctionCall($this->yystack[ $this->yyidx + -3 ]->minor, $this->yystack[ $this->yyidx + -1 ]->minor); } - // line 1051 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r146() + // line 1044 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r145() { if ($this->security && substr($this->yystack[ $this->yyidx + -3 ]->minor, 0, 1) === '_') { $this->compiler->trigger_template_error(self::ERR1); @@ -3141,8 +3227,8 @@ class Smarty_Internal_Templateparser ')'; } - // line 1062 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r147() + // line 1055 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r146() { if ($this->security) { $this->compiler->trigger_template_error(self::ERR2); @@ -3157,15 +3243,15 @@ class Smarty_Internal_Templateparser $this->_retvalue = $prefixVar . '(' . implode(',', $this->yystack[ $this->yyidx + -1 ]->minor) . ')'; } - // line 1079 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r148() + // line 1072 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r147() { $this->_retvalue = array_merge($this->yystack[ $this->yyidx + -2 ]->minor, array($this->yystack[ $this->yyidx + 0 ]->minor)); } - // line 1083 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r151() + // line 1076 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r150() { $this->_retvalue = array_merge($this->yystack[ $this->yyidx + -2 ]->minor, array( @@ -3173,53 +3259,60 @@ class Smarty_Internal_Templateparser )); } - // line 1091 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r152() + // line 1084 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r151() { $this->_retvalue = array(array_merge($this->yystack[ $this->yyidx + -1 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor)); } - // line 1099 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r154() + // line 1092 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r153() { $this->_retvalue = array($this->yystack[ $this->yyidx + 0 ]->minor); } - // line 1118 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r155() + // line 1105 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r154() { $this->_retvalue = array_merge($this->yystack[ $this->yyidx + -1 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor); } - // line 1123 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1114 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r157() + { + $this->_retvalue = + array(trim($this->yystack[ $this->yyidx + -1 ]->minor) . $this->yystack[ $this->yyidx + 0 ]->minor); + } + + // line 1119 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r159() { $this->_retvalue = array($this->yystack[ $this->yyidx + 0 ]->minor, '', 'method'); } - // line 1128 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1124 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r160() { $this->_retvalue = array($this->yystack[ $this->yyidx + -1 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor, 'method'); } - // line 1133 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1129 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r161() { $this->_retvalue = array($this->yystack[ $this->yyidx + 0 ]->minor, ''); } - // line 1138 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1134 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r162() { $this->_retvalue = array($this->yystack[ $this->yyidx + -1 ]->minor, $this->yystack[ $this->yyidx + 0 ]->minor, 'property'); } - // line 1144 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1140 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r163() { $this->_retvalue = @@ -3229,13 +3322,13 @@ class Smarty_Internal_Templateparser ); } - // line 1148 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1144 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r164() { $this->_retvalue = ' ' . trim($this->yystack[ $this->yyidx + 0 ]->minor) . ' '; } - // line 1167 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1163 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r165() { static $lops = array( @@ -3257,7 +3350,7 @@ class Smarty_Internal_Templateparser $this->_retvalue = $lops[ $op ]; } - // line 1180 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1176 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r166() { static $tlops = array( @@ -3272,7 +3365,7 @@ class Smarty_Internal_Templateparser $this->_retvalue = $tlops[ $op ]; } - // line 1194 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1190 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r167() { static $scond = array( @@ -3285,67 +3378,67 @@ class Smarty_Internal_Templateparser $this->_retvalue = $scond[ $op ]; } - // line 1202 "../smarty/lexer/smarty_internal_templateparser.y" + // line 1201 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r168() { $this->_retvalue = 'array(' . $this->yystack[ $this->yyidx + -1 ]->minor . ')'; } - // line 1210 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r170() + // line 1209 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r171() { $this->_retvalue = $this->yystack[ $this->yyidx + -2 ]->minor . ',' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 1214 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r172() + // line 1213 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r173() { $this->_retvalue = $this->yystack[ $this->yyidx + -2 ]->minor . '=>' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 1230 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r173() + // line 1229 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r174() { $this->_retvalue = '\'' . $this->yystack[ $this->yyidx + -2 ]->minor . '\'=>' . $this->yystack[ $this->yyidx + 0 ]->minor; } - // line 1236 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r176() + // line 1235 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r177() { $this->compiler->leaveDoubleQuote(); $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor->to_smarty_php($this); } - // line 1241 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r177() + // line 1240 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r178() { $this->yystack[ $this->yyidx + -1 ]->minor->append_subtree($this, $this->yystack[ $this->yyidx + 0 ]->minor); $this->_retvalue = $this->yystack[ $this->yyidx + -1 ]->minor; } - // line 1245 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r178() + // line 1244 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r179() { $this->_retvalue = new Smarty_Internal_ParseTree_Dq($this, $this->yystack[ $this->yyidx + 0 ]->minor); } - // line 1249 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r179() + // line 1248 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r180() { $this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)' . $this->yystack[ $this->yyidx + -1 ]->minor); } - // line 1253 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r180() + // line 1252 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r181() { $this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)(' . $this->yystack[ $this->yyidx + -1 ]->minor . ')'); } - // line 1265 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r181() + // line 1264 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r182() { $this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)$_smarty_tpl->tpl_vars[\'' . @@ -3353,13 +3446,13 @@ class Smarty_Internal_Templateparser '\']->value'); } - // line 1269 "../smarty/lexer/smarty_internal_templateparser.y" - public function yy_r184() + // line 1268 "../smarty/lexer/smarty_internal_templateparser.y" + public function yy_r185() { $this->_retvalue = new Smarty_Internal_ParseTree_Tag($this, $this->yystack[ $this->yyidx + 0 ]->minor); } - public function yy_r185() + public function yy_r186() { $this->_retvalue = new Smarty_Internal_ParseTree_DqContent($this->yystack[ $this->yyidx + 0 ]->minor); } @@ -3368,13 +3461,9 @@ class Smarty_Internal_Templateparser { if ($this->yyTraceFILE && $yyruleno >= 0 && $yyruleno < count(self::$yyRuleName)) { - fprintf( - $this->yyTraceFILE, - "%sReduce (%d) [%s].\n", - $this->yyTracePrompt, - $yyruleno, - self::$yyRuleName[ $yyruleno ] - ); + fprintf($this->yyTraceFILE, "%sReduce (%d) [%s].\n", + $this->yyTracePrompt, $yyruleno, + self::$yyRuleName[ $yyruleno ]); } $this->_retvalue = $yy_lefthand_side = null; if (isset(self::$yyReduceMap[ $yyruleno ])) { @@ -3453,12 +3542,8 @@ class Smarty_Internal_Templateparser } $yyendofinput = ($yymajor == 0); if ($this->yyTraceFILE) { - fprintf( - $this->yyTraceFILE, - "%sInput %s\n", - $this->yyTracePrompt, - $this->yyTokenName[ $yymajor ] - ); + fprintf($this->yyTraceFILE, "%sInput %s\n", + $this->yyTracePrompt, $this->yyTokenName[ $yymajor ]); } do { $yyact = $this->yy_find_shift_action($yymajor); @@ -3479,11 +3564,8 @@ class Smarty_Internal_Templateparser $this->yy_reduce($yyact - self::YYNSTATE); } elseif ($yyact === self::YY_ERROR_ACTION) { if ($this->yyTraceFILE) { - fprintf( - $this->yyTraceFILE, - "%sSyntax Error!\n", - $this->yyTracePrompt - ); + fprintf($this->yyTraceFILE, "%sSyntax Error!\n", + $this->yyTracePrompt); } if (self::YYERRORSYMBOL) { if ($this->yyerrcnt < 0) { @@ -3492,12 +3574,8 @@ class Smarty_Internal_Templateparser $yymx = $this->yystack[ $this->yyidx ]->major; if ($yymx === self::YYERRORSYMBOL || $yyerrorhit) { if ($this->yyTraceFILE) { - fprintf( - $this->yyTraceFILE, - "%sDiscard input token %s\n", - $this->yyTracePrompt, - $this->yyTokenName[ $yymajor ] - ); + fprintf($this->yyTraceFILE, "%sDiscard input token %s\n", + $this->yyTracePrompt, $this->yyTokenName[ $yymajor ]); } $this->yy_destructor($yymajor, $yytokenvalue); $yymajor = self::YYNOCODE; @@ -3537,3 +3615,4 @@ class Smarty_Internal_Templateparser } while ($yymajor !== self::YYNOCODE && $this->yyidx >= 0); } } + diff --git a/system/token/autoload.php b/system/token/autoload.php index 1f5097f..d38f535 100644 --- a/system/token/autoload.php +++ b/system/token/autoload.php @@ -1,17 +1,38 @@ = 0; $i--) $ret |= ord($res[$i]); + + return !$ret; + } + } +} \ No newline at end of file