From b66a773ed8fddab6fffce1f1af4f38bdea6b61fb Mon Sep 17 00:00:00 2001 From: Ascendings Date: Sun, 30 Aug 2015 12:33:20 -0400 Subject: [PATCH] Added vendor/ directory for Composer's installed files --- vendor/alexgarrett/violin/README.md | 262 ++ vendor/alexgarrett/violin/composer.json | 27 + .../violin/examples/advanced/extending.php | 77 + vendor/alexgarrett/violin/examples/basic.php | 28 + .../violin/examples/basic_two_array.php | 37 + .../violin/examples/errors/errors_all.php | 21 + .../violin/examples/errors/errors_field.php | 22 + .../violin/examples/errors/errors_first.php | 25 + .../messages/custom_field_message.php | 29 + .../messages/custom_field_messages.php | 40 + .../examples/messages/custom_rule_message.php | 28 + .../messages/custom_rule_messages.php | 34 + .../examples/messages/field_aliases.php | 26 + .../messages/placeholders/placeholders.php | 27 + .../placeholders/placeholders_all.php | 31 + .../violin/examples/rules/custom_rule.php | 32 + .../examples/rules/custom_rule_arguments.php | 35 + vendor/alexgarrett/violin/phpunit.xml | 18 + .../src/Contracts/MessageBagContract.php | 12 + .../violin/src/Contracts/RuleContract.php | 33 + .../src/Contracts/ValidatorContract.php | 18 + .../violin/src/Rules/AlnumDashRule.php | 23 + .../violin/src/Rules/AlnumRule.php | 23 + .../violin/src/Rules/AlphaRule.php | 23 + .../violin/src/Rules/ArrayRule.php | 23 + .../violin/src/Rules/BetweenRule.php | 23 + .../alexgarrett/violin/src/Rules/BoolRule.php | 23 + .../violin/src/Rules/CheckedRule.php | 23 + .../alexgarrett/violin/src/Rules/DateRule.php | 33 + .../violin/src/Rules/EmailRule.php | 23 + .../alexgarrett/violin/src/Rules/IntRule.php | 23 + .../alexgarrett/violin/src/Rules/IpRule.php | 23 + .../violin/src/Rules/MatchesRule.php | 23 + .../alexgarrett/violin/src/Rules/MaxRule.php | 29 + .../alexgarrett/violin/src/Rules/MinRule.php | 29 + .../violin/src/Rules/NumberRule.php | 23 + .../violin/src/Rules/RegexRule.php | 23 + .../violin/src/Rules/RequiredRule.php | 25 + .../alexgarrett/violin/src/Rules/UrlRule.php | 23 + .../violin/src/Support/MessageBag.php | 96 + vendor/alexgarrett/violin/src/Violin.php | 506 +++ .../violin/tests/MessageBagTest.php | 68 + vendor/alexgarrett/violin/tests/RulesTest.php | 567 +++ .../violin/tests/ValidatorTest.php | 272 ++ vendor/autoload.php | 7 + vendor/composer/ClassLoader.php | 413 ++ vendor/composer/autoload_classmap.php | 9 + vendor/composer/autoload_files.php | 11 + vendor/composer/autoload_namespaces.php | 13 + vendor/composer/autoload_psr4.php | 18 + vendor/composer/autoload_real.php | 55 + vendor/composer/installed.json | 711 ++++ vendor/danielstjules/stringy/CHANGELOG.md | 110 + vendor/danielstjules/stringy/LICENSE.txt | 19 + vendor/danielstjules/stringy/README.md | 1077 ++++++ vendor/danielstjules/stringy/composer.json | 35 + vendor/danielstjules/stringy/phpunit.xml.dist | 14 + vendor/danielstjules/stringy/src/Create.php | 19 + .../stringy/src/StaticStringy.php | 869 +++++ vendor/danielstjules/stringy/src/Stringy.php | 1464 +++++++ .../stringy/tests/CommonTest.php | 1026 +++++ .../stringy/tests/CreateTest.php | 16 + .../stringy/tests/StaticStringyTest.php | 650 ++++ .../stringy/tests/StringyTest.php | 914 +++++ vendor/doctrine/inflector/LICENSE | 19 + vendor/doctrine/inflector/README.md | 6 + vendor/doctrine/inflector/composer.json | 29 + .../Doctrine/Common/Inflector/Inflector.php | 415 ++ vendor/doctrine/inflector/phpunit.xml.dist | 31 + .../Tests/Common/Inflector/InflectorTest.php | 210 + .../tests/Doctrine/Tests/DoctrineTestCase.php | 10 + .../tests/Doctrine/Tests/TestInit.php | 27 + vendor/hassankhan/config/CHANGELOG.md | 99 + vendor/hassankhan/config/CONTRIBUTING.md | 32 + vendor/hassankhan/config/LICENSE.md | 8 + vendor/hassankhan/config/composer.json | 36 + .../hassankhan/config/src/AbstractConfig.php | 159 + vendor/hassankhan/config/src/Config.php | 157 + .../hassankhan/config/src/ConfigInterface.php | 38 + .../src/Exception/EmptyDirectoryException.php | 9 + .../src/Exception/FileNotFoundException.php | 9 + .../config/src/Exception/ParseException.php | 20 + .../Exception/UnsupportedFormatException.php | 9 + .../src/FileParser/AbstractFileParser.php | 28 + .../src/FileParser/FileParserInterface.php | 31 + .../hassankhan/config/src/FileParser/Ini.php | 43 + .../hassankhan/config/src/FileParser/Json.php | 53 + .../hassankhan/config/src/FileParser/Php.php | 61 + .../hassankhan/config/src/FileParser/Xml.php | 55 + .../hassankhan/config/src/FileParser/Yaml.php | 49 + .../container/BindingResolutionException.php | 5 + vendor/illuminate/container/Container.php | 1291 +++++++ .../container/ContextualBindingBuilder.php | 58 + vendor/illuminate/container/composer.json | 31 + .../contracts/Auth/Authenticatable.php | 41 + .../contracts/Auth/CanResetPassword.php | 12 + vendor/illuminate/contracts/Auth/Guard.php | 100 + .../contracts/Auth/PasswordBroker.php | 76 + .../illuminate/contracts/Auth/Registrar.php | 21 + .../contracts/Auth/UserProvider.php | 48 + .../illuminate/contracts/Bus/Dispatcher.php | 45 + .../contracts/Bus/HandlerResolver.php | 47 + .../contracts/Bus/QueueingDispatcher.php | 13 + .../illuminate/contracts/Bus/SelfHandling.php | 3 + vendor/illuminate/contracts/Cache/Factory.php | 13 + .../illuminate/contracts/Cache/Repository.php | 98 + vendor/illuminate/contracts/Cache/Store.php | 72 + .../contracts/Config/Repository.php | 49 + .../contracts/Console/Application.php | 21 + .../illuminate/contracts/Console/Kernel.php | 46 + .../contracts/Container/Container.php | 143 + .../Container/ContextualBindingBuilder.php | 21 + .../illuminate/contracts/Cookie/Factory.php | 42 + .../contracts/Cookie/QueueingFactory.php | 27 + .../contracts/Database/ModelIdentifier.php | 32 + .../contracts/Debug/ExceptionHandler.php | 33 + .../contracts/Encryption/DecryptException.php | 5 + .../contracts/Encryption/Encrypter.php | 37 + .../contracts/Events/Dispatcher.php | 64 + .../illuminate/contracts/Filesystem/Cloud.php | 3 + .../contracts/Filesystem/Factory.php | 13 + .../Filesystem/FileNotFoundException.php | 5 + .../contracts/Filesystem/Filesystem.php | 174 + .../contracts/Foundation/Application.php | 78 + .../illuminate/contracts/Hashing/Hasher.php | 33 + vendor/illuminate/contracts/Http/Kernel.php | 36 + vendor/illuminate/contracts/Logging/Log.php | 97 + .../illuminate/contracts/Mail/MailQueue.php | 28 + vendor/illuminate/contracts/Mail/Mailer.php | 31 + .../Pagination/LengthAwarePaginator.php | 19 + .../contracts/Pagination/Paginator.php | 108 + .../contracts/Pagination/Presenter.php | 19 + vendor/illuminate/contracts/Pipeline/Hub.php | 14 + .../contracts/Pipeline/Pipeline.php | 39 + .../Queue/EntityNotFoundException.php | 21 + .../contracts/Queue/EntityResolver.php | 14 + vendor/illuminate/contracts/Queue/Factory.php | 13 + vendor/illuminate/contracts/Queue/Job.php | 48 + vendor/illuminate/contracts/Queue/Monitor.php | 29 + vendor/illuminate/contracts/Queue/Queue.php | 65 + .../contracts/Queue/QueueableEntity.php | 12 + .../contracts/Queue/ShouldBeQueued.php | 3 + .../illuminate/contracts/Redis/Database.php | 14 + .../contracts/Routing/Middleware.php | 16 + .../contracts/Routing/Registrar.php | 115 + .../contracts/Routing/ResponseFactory.php | 125 + .../Routing/TerminableMiddleware.php | 14 + .../contracts/Routing/UrlGenerator.php | 63 + .../contracts/Routing/UrlRoutable.php | 19 + .../contracts/Support/Arrayable.php | 12 + .../illuminate/contracts/Support/Jsonable.php | 13 + .../contracts/Support/MessageBag.php | 99 + .../contracts/Support/MessageProvider.php | 12 + .../contracts/Support/Renderable.php | 12 + .../contracts/Validation/Factory.php | 45 + .../Validation/UnauthorizedException.php | 5 + .../Validation/ValidatesWhenResolved.php | 12 + .../Validation/ValidationException.php | 46 + .../contracts/Validation/Validator.php | 39 + vendor/illuminate/contracts/View/Factory.php | 70 + vendor/illuminate/contracts/View/View.php | 23 + vendor/illuminate/contracts/composer.json | 25 + .../illuminate/database/Capsule/Manager.php | 202 + vendor/illuminate/database/Connection.php | 1126 ++++++ .../database/ConnectionInterface.php | 148 + .../database/ConnectionResolver.php | 90 + .../database/ConnectionResolverInterface.php | 28 + .../database/Connectors/ConnectionFactory.php | 231 ++ .../database/Connectors/Connector.php | 71 + .../Connectors/ConnectorInterface.php | 13 + .../database/Connectors/MySqlConnector.php | 112 + .../database/Connectors/PostgresConnector.php | 96 + .../database/Connectors/SQLiteConnector.php | 40 + .../Connectors/SqlServerConnector.php | 142 + .../Console/Migrations/BaseCommand.php | 17 + .../Console/Migrations/InstallCommand.php | 69 + .../Console/Migrations/MigrateCommand.php | 129 + .../Console/Migrations/MigrateMakeCommand.php | 120 + .../Console/Migrations/RefreshCommand.php | 96 + .../Console/Migrations/ResetCommand.php | 86 + .../Console/Migrations/RollbackCommand.php | 86 + .../Console/Migrations/StatusCommand.php | 82 + .../database/Console/SeedCommand.php | 100 + .../illuminate/database/DatabaseManager.php | 307 ++ .../database/DatabaseServiceProvider.php | 61 + .../illuminate/database/Eloquent/Builder.php | 948 +++++ .../database/Eloquent/Collection.php | 266 ++ .../Eloquent/MassAssignmentException.php | 5 + vendor/illuminate/database/Eloquent/Model.php | 3399 +++++++++++++++++ .../Eloquent/ModelNotFoundException.php | 39 + .../database/Eloquent/QueueEntityResolver.php | 27 + .../database/Eloquent/Relations/BelongsTo.php | 310 ++ .../Eloquent/Relations/BelongsToMany.php | 1195 ++++++ .../database/Eloquent/Relations/HasMany.php | 47 + .../Eloquent/Relations/HasManyThrough.php | 340 ++ .../database/Eloquent/Relations/HasOne.php | 47 + .../Eloquent/Relations/HasOneOrMany.php | 412 ++ .../database/Eloquent/Relations/MorphMany.php | 47 + .../database/Eloquent/Relations/MorphOne.php | 47 + .../Eloquent/Relations/MorphOneOrMany.php | 236 ++ .../Eloquent/Relations/MorphPivot.php | 78 + .../database/Eloquent/Relations/MorphTo.php | 247 ++ .../Eloquent/Relations/MorphToMany.php | 158 + .../database/Eloquent/Relations/Pivot.php | 171 + .../database/Eloquent/Relations/Relation.php | 290 ++ .../database/Eloquent/ScopeInterface.php | 24 + .../database/Eloquent/SoftDeletes.php | 170 + .../database/Eloquent/SoftDeletingScope.php | 164 + vendor/illuminate/database/Grammar.php | 184 + .../database/MigrationServiceProvider.php | 226 ++ .../DatabaseMigrationRepository.php | 181 + .../database/Migrations/Migration.php | 22 + .../database/Migrations/MigrationCreator.php | 183 + .../MigrationRepositoryInterface.php | 65 + .../database/Migrations/Migrator.php | 411 ++ .../database/Migrations/stubs/blank.stub | 28 + .../database/Migrations/stubs/create.stub | 32 + .../database/Migrations/stubs/update.stub | 34 + .../illuminate/database/MySqlConnection.php | 63 + .../database/PostgresConnection.php | 50 + vendor/illuminate/database/Query/Builder.php | 1995 ++++++++++ .../illuminate/database/Query/Expression.php | 43 + .../database/Query/Grammars/Grammar.php | 758 ++++ .../database/Query/Grammars/MySqlGrammar.php | 144 + .../Query/Grammars/PostgresGrammar.php | 174 + .../database/Query/Grammars/SQLiteGrammar.php | 130 + .../Query/Grammars/SqlServerGrammar.php | 224 ++ .../illuminate/database/Query/JoinClause.php | 151 + .../Query/Processors/MySqlProcessor.php | 23 + .../Query/Processors/PostgresProcessor.php | 47 + .../database/Query/Processors/Processor.php | 48 + .../Query/Processors/SQLiteProcessor.php | 23 + .../Query/Processors/SqlServerProcessor.php | 41 + vendor/illuminate/database/QueryException.php | 78 + vendor/illuminate/database/README.md | 70 + .../illuminate/database/SQLiteConnection.php | 50 + .../illuminate/database/Schema/Blueprint.php | 923 +++++ vendor/illuminate/database/Schema/Builder.php | 242 ++ .../database/Schema/Grammars/Grammar.php | 458 +++ .../database/Schema/Grammars/MySqlGrammar.php | 652 ++++ .../Schema/Grammars/PostgresGrammar.php | 544 +++ .../Schema/Grammars/SQLiteGrammar.php | 611 +++ .../Schema/Grammars/SqlServerGrammar.php | 552 +++ .../database/Schema/MySqlBuilder.php | 41 + .../database/SeedServiceProvider.php | 55 + vendor/illuminate/database/Seeder.php | 101 + .../database/SqlServerConnection.php | 92 + vendor/illuminate/database/composer.json | 41 + .../support/AggregateServiceProvider.php | 53 + vendor/illuminate/support/Arr.php | 410 ++ vendor/illuminate/support/ClassLoader.php | 107 + vendor/illuminate/support/Collection.php | 907 +++++ vendor/illuminate/support/Debug/Dumper.php | 21 + .../illuminate/support/Debug/HtmlDumper.php | 28 + vendor/illuminate/support/Facades/App.php | 18 + vendor/illuminate/support/Facades/Artisan.php | 18 + vendor/illuminate/support/Facades/Auth.php | 19 + vendor/illuminate/support/Facades/Blade.php | 18 + vendor/illuminate/support/Facades/Bus.php | 18 + vendor/illuminate/support/Facades/Cache.php | 19 + vendor/illuminate/support/Facades/Config.php | 18 + vendor/illuminate/support/Facades/Cookie.php | 41 + vendor/illuminate/support/Facades/Crypt.php | 18 + vendor/illuminate/support/Facades/DB.php | 19 + vendor/illuminate/support/Facades/Event.php | 18 + vendor/illuminate/support/Facades/Facade.php | 226 ++ vendor/illuminate/support/Facades/File.php | 18 + vendor/illuminate/support/Facades/Hash.php | 18 + vendor/illuminate/support/Facades/Input.php | 32 + vendor/illuminate/support/Facades/Lang.php | 18 + vendor/illuminate/support/Facades/Log.php | 18 + vendor/illuminate/support/Facades/Mail.php | 18 + .../illuminate/support/Facades/Password.php | 53 + vendor/illuminate/support/Facades/Queue.php | 19 + .../illuminate/support/Facades/Redirect.php | 18 + vendor/illuminate/support/Facades/Redis.php | 18 + vendor/illuminate/support/Facades/Request.php | 18 + .../illuminate/support/Facades/Response.php | 18 + vendor/illuminate/support/Facades/Route.php | 18 + vendor/illuminate/support/Facades/Schema.php | 29 + vendor/illuminate/support/Facades/Session.php | 19 + vendor/illuminate/support/Facades/Storage.php | 18 + vendor/illuminate/support/Facades/URL.php | 18 + .../illuminate/support/Facades/Validator.php | 18 + vendor/illuminate/support/Facades/View.php | 18 + vendor/illuminate/support/Fluent.php | 193 + vendor/illuminate/support/Manager.php | 142 + vendor/illuminate/support/MessageBag.php | 314 ++ .../support/NamespacedItemResolver.php | 109 + vendor/illuminate/support/Pluralizer.php | 103 + vendor/illuminate/support/ServiceProvider.php | 229 ++ vendor/illuminate/support/Str.php | 365 ++ .../support/Traits/CapsuleManagerTrait.php | 69 + .../illuminate/support/Traits/Macroable.php | 90 + vendor/illuminate/support/ViewErrorBag.php | 106 + vendor/illuminate/support/composer.json | 40 + vendor/illuminate/support/helpers.php | 800 ++++ vendor/nesbot/carbon/LICENSE | 19 + vendor/nesbot/carbon/composer.json | 31 + vendor/nesbot/carbon/phpunit.xml.dist | 25 + vendor/nesbot/carbon/readme.md | 81 + vendor/nesbot/carbon/src/Carbon/Carbon.php | 2359 ++++++++++++ .../carbon/src/Carbon/CarbonInterval.php | 509 +++ vendor/nesbot/carbon/src/Carbon/Lang/ar.php | 32 + vendor/nesbot/carbon/src/Carbon/Lang/az.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/bg.php | 32 + vendor/nesbot/carbon/src/Carbon/Lang/ca.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/cs.php | 37 + vendor/nesbot/carbon/src/Carbon/Lang/da.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/de.php | 39 + vendor/nesbot/carbon/src/Carbon/Lang/el.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/en.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/eo.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/es.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/eu | 30 + vendor/nesbot/carbon/src/Carbon/Lang/fa.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/fi.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/fr.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/hr.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/hu.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/id.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/it.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/ja.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/ko.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/lt.php | 27 + vendor/nesbot/carbon/src/Carbon/Lang/nl.php | 27 + vendor/nesbot/carbon/src/Carbon/Lang/no.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/pl.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/pt.php | 30 + .../nesbot/carbon/src/Carbon/Lang/pt_BR.php | 27 + vendor/nesbot/carbon/src/Carbon/Lang/ro.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/ru.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/sk.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/sl.php | 37 + vendor/nesbot/carbon/src/Carbon/Lang/sr.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/sv.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/th.php | 31 + vendor/nesbot/carbon/src/Carbon/Lang/tr.php | 29 + vendor/nesbot/carbon/src/Carbon/Lang/uk.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/vi.php | 30 + .../nesbot/carbon/src/Carbon/Lang/zh-TW.php | 30 + vendor/nesbot/carbon/src/Carbon/Lang/zh.php | 30 + vendor/nesbot/carbon/tests/AddTest.php | 241 ++ .../carbon/tests/CarbonIntervalAddTest.php | 36 + .../tests/CarbonIntervalConstructTest.php | 224 ++ .../tests/CarbonIntervalForHumansTest.php | 107 + .../tests/CarbonIntervalGettersTest.php | 70 + .../tests/CarbonIntervalSettersTest.php | 99 + vendor/nesbot/carbon/tests/ComparisonTest.php | 200 + vendor/nesbot/carbon/tests/ConstructTest.php | 105 + vendor/nesbot/carbon/tests/CopyTest.php | 38 + .../carbon/tests/CreateFromDateTest.php | 59 + .../carbon/tests/CreateFromFormatTest.php | 42 + .../carbon/tests/CreateFromTimeTest.php | 61 + .../carbon/tests/CreateFromTimestampTest.php | 52 + vendor/nesbot/carbon/tests/CreateTest.php | 142 + .../carbon/tests/DayOfWeekModifiersTest.php | 288 ++ vendor/nesbot/carbon/tests/DiffTest.php | 1042 +++++ .../nesbot/carbon/tests/FluidSettersTest.php | 113 + vendor/nesbot/carbon/tests/GettersTest.php | 285 ++ vendor/nesbot/carbon/tests/InstanceTest.php | 35 + vendor/nesbot/carbon/tests/IsTest.php | 133 + vendor/nesbot/carbon/tests/IssetTest.php | 49 + .../nesbot/carbon/tests/LocalizationTest.php | 411 ++ .../tests/NowAndOtherStaticHelpersTest.php | 79 + vendor/nesbot/carbon/tests/RelativeTest.php | 45 + vendor/nesbot/carbon/tests/SettersTest.php | 253 ++ vendor/nesbot/carbon/tests/StartEndOfTest.php | 236 ++ vendor/nesbot/carbon/tests/StringsTest.php | 157 + vendor/nesbot/carbon/tests/SubTest.php | 214 ++ vendor/nesbot/carbon/tests/TestFixture.php | 87 + .../nesbot/carbon/tests/TestingAidsTest.php | 124 + vendor/slim/slim/CONTRIBUTING.md | 20 + vendor/slim/slim/LICENSE | 19 + vendor/slim/slim/README.markdown | 208 + vendor/slim/slim/Slim/Environment.php | 228 ++ vendor/slim/slim/Slim/Exception/Pass.php | 49 + vendor/slim/slim/Slim/Exception/Stop.php | 47 + vendor/slim/slim/Slim/Helper/Set.php | 246 ++ vendor/slim/slim/Slim/Http/Cookies.php | 91 + vendor/slim/slim/Slim/Http/Headers.php | 104 + vendor/slim/slim/Slim/Http/Request.php | 617 +++ vendor/slim/slim/Slim/Http/Response.php | 520 +++ vendor/slim/slim/Slim/Http/Util.php | 434 +++ vendor/slim/slim/Slim/Log.php | 354 ++ vendor/slim/slim/Slim/LogWriter.php | 75 + vendor/slim/slim/Slim/Middleware.php | 114 + .../slim/Slim/Middleware/ContentTypes.php | 174 + vendor/slim/slim/Slim/Middleware/Flash.php | 212 + .../slim/Slim/Middleware/MethodOverride.php | 94 + .../slim/Slim/Middleware/PrettyExceptions.php | 116 + .../slim/Slim/Middleware/SessionCookie.php | 205 + vendor/slim/slim/Slim/Route.php | 471 +++ vendor/slim/slim/Slim/Router.php | 257 ++ vendor/slim/slim/Slim/Slim.php | 1444 +++++++ vendor/slim/slim/Slim/View.php | 282 ++ vendor/slim/slim/composer.json | 24 + vendor/slim/slim/index.php | 169 + vendor/slim/slim/phpunit.xml.dist | 25 + vendor/slim/slim/tests/EnvironmentTest.php | 376 ++ vendor/slim/slim/tests/Foo.php | 7 + vendor/slim/slim/tests/Helper/SetTest.php | 241 ++ vendor/slim/slim/tests/Http/CookiesTest.php | 92 + vendor/slim/slim/tests/Http/HeadersTest.php | 59 + vendor/slim/slim/tests/Http/RequestTest.php | 949 +++++ vendor/slim/slim/tests/Http/ResponseTest.php | 271 ++ vendor/slim/slim/tests/Http/UtilTest.php | 445 +++ vendor/slim/slim/tests/LogTest.php | 208 + vendor/slim/slim/tests/LogWriterTest.php | 48 + .../tests/Middleware/ContentTypesTest.php | 162 + .../slim/slim/tests/Middleware/FlashTest.php | 141 + .../tests/Middleware/MethodOverrideTest.php | 149 + .../tests/Middleware/PrettyExceptionsTest.php | 153 + .../tests/Middleware/SessionCookieTest.php | 463 +++ vendor/slim/slim/tests/MiddlewareTest.php | 79 + vendor/slim/slim/tests/README | 18 + vendor/slim/slim/tests/RouteTest.php | 617 +++ vendor/slim/slim/tests/RouterTest.php | 250 ++ vendor/slim/slim/tests/SlimTest.php | 1657 ++++++++ vendor/slim/slim/tests/ViewTest.php | 199 + vendor/slim/slim/tests/bootstrap.php | 22 + vendor/slim/slim/tests/templates/test.php | 1 + vendor/slim/views/README.md | 181 + vendor/slim/views/Smarty.php | 124 + .../views/SmartyPlugins/function.baseUrl.php | 26 + .../SmartyPlugins/function.currentUrl.php | 31 + .../views/SmartyPlugins/function.siteUrl.php | 27 + .../views/SmartyPlugins/function.urlFor.php | 42 + vendor/slim/views/Twig.php | 153 + vendor/slim/views/TwigExtension.php | 91 + vendor/slim/views/composer.json | 33 + vendor/symfony/translation/CHANGELOG.md | 47 + .../Catalogue/AbstractOperation.php | 146 + .../translation/Catalogue/DiffOperation.php | 55 + .../translation/Catalogue/MergeOperation.php | 51 + .../Catalogue/OperationInterface.php | 63 + .../TranslationDataCollector.php | 145 + .../translation/DataCollectorTranslator.php | 152 + .../translation/Dumper/CsvFileDumper.php | 63 + .../translation/Dumper/DumperInterface.php | 31 + .../symfony/translation/Dumper/FileDumper.php | 122 + .../translation/Dumper/IcuResFileDumper.php | 112 + .../translation/Dumper/IniFileDumper.php | 45 + .../translation/Dumper/JsonFileDumper.php | 38 + .../translation/Dumper/MoFileDumper.php | 82 + .../translation/Dumper/PhpFileDumper.php | 40 + .../translation/Dumper/PoFileDumper.php | 61 + .../translation/Dumper/QtFileDumper.php | 50 + .../translation/Dumper/XliffFileDumper.php | 109 + .../translation/Dumper/YamlFileDumper.php | 43 + .../Exception/ExceptionInterface.php | 23 + .../Exception/InvalidResourceException.php | 23 + .../Exception/NotFoundResourceException.php | 23 + .../Extractor/AbstractFileExtractor.php | 83 + .../translation/Extractor/ChainExtractor.php | 60 + .../Extractor/ExtractorInterface.php | 38 + .../translation/IdentityTranslator.php | 77 + vendor/symfony/translation/Interval.php | 107 + vendor/symfony/translation/LICENSE | 19 + .../translation/Loader/ArrayLoader.php | 70 + .../translation/Loader/CsvFileLoader.php | 95 + .../translation/Loader/IcuDatFileLoader.php | 62 + .../translation/Loader/IcuResFileLoader.php | 92 + .../translation/Loader/IniFileLoader.php | 48 + .../translation/Loader/JsonFileLoader.php | 81 + .../translation/Loader/LoaderInterface.php | 42 + .../translation/Loader/MoFileLoader.php | 191 + .../translation/Loader/PhpFileLoader.php | 52 + .../translation/Loader/PoFileLoader.php | 180 + .../translation/Loader/QtFileLoader.php | 81 + .../translation/Loader/XliffFileLoader.php | 188 + .../translation/Loader/YamlFileLoader.php | 78 + .../dic/xliff-core/xliff-core-1.2-strict.xsd | 2223 +++++++++++ .../Loader/schema/dic/xliff-core/xml.xsd | 309 ++ .../symfony/translation/LoggingTranslator.php | 128 + .../symfony/translation/MessageCatalogue.php | 293 ++ .../translation/MessageCatalogueInterface.php | 172 + .../symfony/translation/MessageSelector.php | 90 + .../translation/MetadataAwareInterface.php | 54 + .../translation/PluralizationRules.php | 214 ++ vendor/symfony/translation/README.md | 37 + .../Tests/Catalogue/AbstractOperationTest.php | 73 + .../Tests/Catalogue/DiffOperationTest.php | 82 + .../Tests/Catalogue/MergeOperationTest.php | 83 + .../TranslationDataCollectorTest.php | 121 + .../Tests/DataCollectorTranslatorTest.php | 81 + .../Tests/Dumper/CsvFileDumperTest.php | 33 + .../Tests/Dumper/FileDumperTest.php | 70 + .../Tests/Dumper/IcuResFileDumperTest.php | 38 + .../Tests/Dumper/IniFileDumperTest.php | 32 + .../Tests/Dumper/JsonFileDumperTest.php | 36 + .../Tests/Dumper/MoFileDumperTest.php | 31 + .../Tests/Dumper/PhpFileDumperTest.php | 32 + .../Tests/Dumper/PoFileDumperTest.php | 31 + .../Tests/Dumper/QtFileDumperTest.php | 32 + .../Tests/Dumper/XliffFileDumperTest.php | 41 + .../Tests/Dumper/YamlFileDumperTest.php | 32 + .../Tests/IdentityTranslatorTest.php | 95 + .../translation/Tests/IntervalTest.php | 48 + .../Tests/Loader/CsvFileLoaderTest.php | 60 + .../Tests/Loader/IcuDatFileLoaderTest.php | 68 + .../Tests/Loader/IcuResFileLoaderTest.php | 55 + .../Tests/Loader/IniFileLoaderTest.php | 50 + .../Tests/Loader/JsonFileLoaderTest.php | 68 + .../Tests/Loader/LocalizedTestCase.php | 22 + .../Tests/Loader/MoFileLoaderTest.php | 71 + .../Tests/Loader/PhpFileLoaderTest.php | 49 + .../Tests/Loader/PoFileLoaderTest.php | 96 + .../Tests/Loader/QtFileLoaderTest.php | 67 + .../Tests/Loader/XliffFileLoaderTest.php | 142 + .../Tests/Loader/YamlFileLoaderTest.php | 70 + .../Tests/LoggingTranslatorTest.php | 56 + .../Tests/MessageCatalogueTest.php | 200 + .../translation/Tests/MessageSelectorTest.php | 98 + .../Tests/PluralizationRulesTest.php | 123 + .../translation/Tests/TranslatorCacheTest.php | 360 ++ .../translation/Tests/TranslatorTest.php | 627 +++ .../Tests/fixtures/empty-translation.mo | Bin 0 -> 49 bytes .../Tests/fixtures/empty-translation.po | 3 + .../translation/Tests/fixtures/empty.csv | 0 .../translation/Tests/fixtures/empty.ini | 0 .../translation/Tests/fixtures/empty.json | 0 .../translation/Tests/fixtures/empty.mo | 0 .../translation/Tests/fixtures/empty.po | 0 .../translation/Tests/fixtures/empty.xlf | 0 .../translation/Tests/fixtures/empty.yml | 0 .../translation/Tests/fixtures/encoding.xlf | 16 + .../Tests/fixtures/escaped-id-plurals.po | 10 + .../translation/Tests/fixtures/escaped-id.po | 8 + .../Tests/fixtures/invalid-xml-resources.xlf | 23 + .../translation/Tests/fixtures/malformed.json | 3 + .../translation/Tests/fixtures/non-valid.xlf | 11 + .../translation/Tests/fixtures/non-valid.yml | 1 + .../translation/Tests/fixtures/plurals.mo | Bin 0 -> 74 bytes .../translation/Tests/fixtures/plurals.po | 5 + .../translation/Tests/fixtures/resname.xlf | 19 + .../resourcebundle/corrupted/resources.dat | 1 + .../Tests/fixtures/resourcebundle/dat/en.res | Bin 0 -> 120 bytes .../Tests/fixtures/resourcebundle/dat/en.txt | 3 + .../Tests/fixtures/resourcebundle/dat/fr.res | Bin 0 -> 124 bytes .../Tests/fixtures/resourcebundle/dat/fr.txt | 3 + .../resourcebundle/dat/packagelist.txt | 2 + .../fixtures/resourcebundle/dat/resources.dat | Bin 0 -> 352 bytes .../Tests/fixtures/resourcebundle/res/en.res | Bin 0 -> 84 bytes .../Tests/fixtures/resources-clean.xlf | 22 + .../translation/Tests/fixtures/resources.csv | 4 + .../translation/Tests/fixtures/resources.ini | 1 + .../translation/Tests/fixtures/resources.json | 3 + .../translation/Tests/fixtures/resources.mo | Bin 0 -> 52 bytes .../translation/Tests/fixtures/resources.php | 5 + .../translation/Tests/fixtures/resources.po | 8 + .../translation/Tests/fixtures/resources.ts | 10 + .../translation/Tests/fixtures/resources.xlf | 23 + .../translation/Tests/fixtures/resources.yml | 1 + .../translation/Tests/fixtures/valid.csv | 4 + .../Tests/fixtures/withdoctype.xlf | 12 + .../translation/Tests/fixtures/withnote.xlf | 22 + vendor/symfony/translation/Translator.php | 504 +++ .../translation/TranslatorBagInterface.php | 31 + .../translation/TranslatorInterface.php | 75 + .../translation/Writer/TranslationWriter.php | 87 + vendor/symfony/translation/composer.json | 45 + vendor/symfony/translation/phpunit.xml.dist | 28 + vendor/twig/twig/CHANGELOG | 736 ++++ vendor/twig/twig/LICENSE | 31 + vendor/twig/twig/README.rst | 15 + vendor/twig/twig/composer.json | 42 + vendor/twig/twig/doc/advanced.rst | 834 ++++ vendor/twig/twig/doc/advanced_legacy.rst | 887 +++++ vendor/twig/twig/doc/api.rst | 552 +++ vendor/twig/twig/doc/coding_standards.rst | 101 + vendor/twig/twig/doc/deprecated.rst | 115 + vendor/twig/twig/doc/filters/abs.rst | 18 + vendor/twig/twig/doc/filters/batch.rst | 45 + vendor/twig/twig/doc/filters/capitalize.rst | 11 + .../twig/doc/filters/convert_encoding.rst | 28 + vendor/twig/twig/doc/filters/date.rst | 94 + vendor/twig/twig/doc/filters/date_modify.rst | 23 + vendor/twig/twig/doc/filters/default.rst | 33 + vendor/twig/twig/doc/filters/escape.rst | 116 + vendor/twig/twig/doc/filters/first.rst | 25 + vendor/twig/twig/doc/filters/format.rst | 16 + vendor/twig/twig/doc/filters/index.rst | 37 + vendor/twig/twig/doc/filters/join.rst | 23 + vendor/twig/twig/doc/filters/json_encode.rst | 21 + vendor/twig/twig/doc/filters/keys.rst | 11 + vendor/twig/twig/doc/filters/last.rst | 25 + vendor/twig/twig/doc/filters/length.rst | 11 + vendor/twig/twig/doc/filters/lower.rst | 10 + vendor/twig/twig/doc/filters/merge.rst | 47 + vendor/twig/twig/doc/filters/nl2br.rst | 22 + .../twig/twig/doc/filters/number_format.rst | 45 + vendor/twig/twig/doc/filters/raw.rst | 36 + vendor/twig/twig/doc/filters/replace.rst | 19 + vendor/twig/twig/doc/filters/reverse.rst | 47 + vendor/twig/twig/doc/filters/round.rst | 37 + vendor/twig/twig/doc/filters/slice.rst | 71 + vendor/twig/twig/doc/filters/sort.rst | 17 + vendor/twig/twig/doc/filters/split.rst | 53 + vendor/twig/twig/doc/filters/striptags.rst | 15 + vendor/twig/twig/doc/filters/title.rst | 11 + vendor/twig/twig/doc/filters/trim.rst | 29 + vendor/twig/twig/doc/filters/upper.rst | 10 + vendor/twig/twig/doc/filters/url_encode.rst | 34 + vendor/twig/twig/doc/functions/attribute.rst | 26 + vendor/twig/twig/doc/functions/block.rst | 15 + vendor/twig/twig/doc/functions/constant.rst | 18 + vendor/twig/twig/doc/functions/cycle.rst | 28 + vendor/twig/twig/doc/functions/date.rst | 52 + vendor/twig/twig/doc/functions/dump.rst | 69 + vendor/twig/twig/doc/functions/include.rst | 80 + vendor/twig/twig/doc/functions/index.rst | 20 + vendor/twig/twig/doc/functions/max.rst | 20 + vendor/twig/twig/doc/functions/min.rst | 20 + vendor/twig/twig/doc/functions/parent.rst | 20 + vendor/twig/twig/doc/functions/random.rst | 29 + vendor/twig/twig/doc/functions/range.rst | 45 + vendor/twig/twig/doc/functions/source.rst | 21 + .../doc/functions/template_from_string.rst | 32 + vendor/twig/twig/doc/index.rst | 19 + vendor/twig/twig/doc/installation.rst | 116 + vendor/twig/twig/doc/internals.rst | 138 + vendor/twig/twig/doc/intro.rst | 81 + vendor/twig/twig/doc/recipes.rst | 425 +++ vendor/twig/twig/doc/tags/autoescape.rst | 83 + vendor/twig/twig/doc/tags/block.rst | 11 + vendor/twig/twig/doc/tags/do.rst | 12 + vendor/twig/twig/doc/tags/embed.rst | 178 + vendor/twig/twig/doc/tags/extends.rst | 268 ++ vendor/twig/twig/doc/tags/filter.rst | 21 + vendor/twig/twig/doc/tags/flush.rst | 17 + vendor/twig/twig/doc/tags/for.rst | 172 + vendor/twig/twig/doc/tags/from.rst | 8 + vendor/twig/twig/doc/tags/if.rst | 76 + vendor/twig/twig/doc/tags/import.rst | 57 + vendor/twig/twig/doc/tags/include.rst | 86 + vendor/twig/twig/doc/tags/index.rst | 24 + vendor/twig/twig/doc/tags/macro.rst | 83 + vendor/twig/twig/doc/tags/sandbox.rst | 30 + vendor/twig/twig/doc/tags/set.rst | 78 + vendor/twig/twig/doc/tags/spaceless.rst | 37 + vendor/twig/twig/doc/tags/use.rst | 124 + vendor/twig/twig/doc/tags/verbatim.rst | 24 + vendor/twig/twig/doc/templates.rst | 881 +++++ vendor/twig/twig/doc/tests/constant.rst | 22 + vendor/twig/twig/doc/tests/defined.rst | 30 + vendor/twig/twig/doc/tests/divisibleby.rst | 14 + vendor/twig/twig/doc/tests/empty.rst | 11 + vendor/twig/twig/doc/tests/even.rst | 10 + vendor/twig/twig/doc/tests/index.rst | 15 + vendor/twig/twig/doc/tests/iterable.rst | 19 + vendor/twig/twig/doc/tests/null.rst | 12 + vendor/twig/twig/doc/tests/odd.rst | 10 + vendor/twig/twig/doc/tests/sameas.rst | 14 + vendor/twig/twig/ext/twig/config.m4 | 8 + vendor/twig/twig/ext/twig/config.w32 | 8 + vendor/twig/twig/ext/twig/php_twig.h | 35 + vendor/twig/twig/ext/twig/twig.c | 1099 ++++++ vendor/twig/twig/lib/Twig/Autoloader.php | 48 + vendor/twig/twig/lib/Twig/Compiler.php | 278 ++ .../twig/twig/lib/Twig/CompilerInterface.php | 36 + vendor/twig/twig/lib/Twig/Environment.php | 1292 +++++++ vendor/twig/twig/lib/Twig/Error.php | 250 ++ vendor/twig/twig/lib/Twig/Error/Loader.php | 31 + vendor/twig/twig/lib/Twig/Error/Runtime.php | 20 + vendor/twig/twig/lib/Twig/Error/Syntax.php | 20 + .../twig/lib/Twig/ExistsLoaderInterface.php | 29 + .../twig/twig/lib/Twig/ExpressionParser.php | 619 +++ vendor/twig/twig/lib/Twig/Extension.php | 93 + vendor/twig/twig/lib/Twig/Extension/Core.php | 1502 ++++++++ vendor/twig/twig/lib/Twig/Extension/Debug.php | 71 + .../twig/twig/lib/Twig/Extension/Escaper.php | 113 + .../twig/lib/Twig/Extension/Optimizer.php | 35 + .../twig/twig/lib/Twig/Extension/Profiler.php | 52 + .../twig/twig/lib/Twig/Extension/Sandbox.php | 112 + .../twig/twig/lib/Twig/Extension/Staging.php | 113 + .../twig/lib/Twig/Extension/StringLoader.php | 47 + .../twig/twig/lib/Twig/ExtensionInterface.php | 83 + .../Twig/FileExtensionEscapingStrategy.php | 49 + vendor/twig/twig/lib/Twig/Filter.php | 81 + vendor/twig/twig/lib/Twig/Filter/Function.php | 37 + vendor/twig/twig/lib/Twig/Filter/Method.php | 39 + vendor/twig/twig/lib/Twig/Filter/Node.php | 39 + .../twig/lib/Twig/FilterCallableInterface.php | 23 + vendor/twig/twig/lib/Twig/FilterInterface.php | 42 + vendor/twig/twig/lib/Twig/Function.php | 71 + .../twig/twig/lib/Twig/Function/Function.php | 38 + vendor/twig/twig/lib/Twig/Function/Method.php | 40 + vendor/twig/twig/lib/Twig/Function/Node.php | 39 + .../lib/Twig/FunctionCallableInterface.php | 23 + .../twig/twig/lib/Twig/FunctionInterface.php | 39 + vendor/twig/twig/lib/Twig/Lexer.php | 407 ++ vendor/twig/twig/lib/Twig/LexerInterface.php | 32 + vendor/twig/twig/lib/Twig/Loader/Array.php | 97 + vendor/twig/twig/lib/Twig/Loader/Chain.php | 138 + .../twig/twig/lib/Twig/Loader/Filesystem.php | 240 ++ vendor/twig/twig/lib/Twig/Loader/String.php | 59 + vendor/twig/twig/lib/Twig/LoaderInterface.php | 53 + vendor/twig/twig/lib/Twig/Markup.php | 37 + vendor/twig/twig/lib/Twig/Node.php | 229 ++ vendor/twig/twig/lib/Twig/Node/AutoEscape.php | 39 + vendor/twig/twig/lib/Twig/Node/Block.php | 44 + .../twig/lib/Twig/Node/BlockReference.php | 37 + vendor/twig/twig/lib/Twig/Node/Body.php | 19 + .../twig/twig/lib/Twig/Node/CheckSecurity.php | 78 + vendor/twig/twig/lib/Twig/Node/Do.php | 38 + vendor/twig/twig/lib/Twig/Node/Embed.php | 42 + vendor/twig/twig/lib/Twig/Node/Expression.php | 20 + .../twig/lib/Twig/Node/Expression/Array.php | 86 + .../lib/Twig/Node/Expression/AssignName.php | 28 + .../twig/lib/Twig/Node/Expression/Binary.php | 40 + .../lib/Twig/Node/Expression/Binary/Add.php | 18 + .../lib/Twig/Node/Expression/Binary/And.php | 18 + .../Node/Expression/Binary/BitwiseAnd.php | 18 + .../Twig/Node/Expression/Binary/BitwiseOr.php | 18 + .../Node/Expression/Binary/BitwiseXor.php | 18 + .../Twig/Node/Expression/Binary/Concat.php | 18 + .../lib/Twig/Node/Expression/Binary/Div.php | 18 + .../Twig/Node/Expression/Binary/EndsWith.php | 30 + .../lib/Twig/Node/Expression/Binary/Equal.php | 17 + .../Twig/Node/Expression/Binary/FloorDiv.php | 29 + .../Twig/Node/Expression/Binary/Greater.php | 17 + .../Node/Expression/Binary/GreaterEqual.php | 17 + .../lib/Twig/Node/Expression/Binary/In.php | 33 + .../lib/Twig/Node/Expression/Binary/Less.php | 17 + .../Twig/Node/Expression/Binary/LessEqual.php | 17 + .../Twig/Node/Expression/Binary/Matches.php | 28 + .../lib/Twig/Node/Expression/Binary/Mod.php | 18 + .../lib/Twig/Node/Expression/Binary/Mul.php | 18 + .../Twig/Node/Expression/Binary/NotEqual.php | 17 + .../lib/Twig/Node/Expression/Binary/NotIn.php | 33 + .../lib/Twig/Node/Expression/Binary/Or.php | 18 + .../lib/Twig/Node/Expression/Binary/Power.php | 33 + .../lib/Twig/Node/Expression/Binary/Range.php | 33 + .../Node/Expression/Binary/StartsWith.php | 30 + .../lib/Twig/Node/Expression/Binary/Sub.php | 18 + .../Twig/Node/Expression/BlockReference.php | 51 + .../twig/lib/Twig/Node/Expression/Call.php | 210 + .../lib/Twig/Node/Expression/Conditional.php | 31 + .../lib/Twig/Node/Expression/Constant.php | 23 + .../Node/Expression/ExtensionReference.php | 33 + .../twig/lib/Twig/Node/Expression/Filter.php | 36 + .../Twig/Node/Expression/Filter/Default.php | 43 + .../lib/Twig/Node/Expression/Function.php | 35 + .../twig/lib/Twig/Node/Expression/GetAttr.php | 63 + .../lib/Twig/Node/Expression/MethodCall.php | 41 + .../twig/lib/Twig/Node/Expression/Name.php | 90 + .../twig/lib/Twig/Node/Expression/Parent.php | 47 + .../lib/Twig/Node/Expression/TempName.php | 26 + .../twig/lib/Twig/Node/Expression/Test.php | 32 + .../Twig/Node/Expression/Test/Constant.php | 46 + .../lib/Twig/Node/Expression/Test/Defined.php | 54 + .../Twig/Node/Expression/Test/Divisibleby.php | 33 + .../lib/Twig/Node/Expression/Test/Even.php | 32 + .../lib/Twig/Node/Expression/Test/Null.php | 31 + .../lib/Twig/Node/Expression/Test/Odd.php | 32 + .../lib/Twig/Node/Expression/Test/Sameas.php | 29 + .../twig/lib/Twig/Node/Expression/Unary.php | 27 + .../lib/Twig/Node/Expression/Unary/Neg.php | 18 + .../lib/Twig/Node/Expression/Unary/Not.php | 18 + .../lib/Twig/Node/Expression/Unary/Pos.php | 18 + vendor/twig/twig/lib/Twig/Node/Flush.php | 36 + vendor/twig/twig/lib/Twig/Node/For.php | 112 + vendor/twig/twig/lib/Twig/Node/ForLoop.php | 55 + vendor/twig/twig/lib/Twig/Node/If.php | 66 + vendor/twig/twig/lib/Twig/Node/Import.php | 54 + vendor/twig/twig/lib/Twig/Node/Include.php | 88 + vendor/twig/twig/lib/Twig/Node/Macro.php | 96 + vendor/twig/twig/lib/Twig/Node/Module.php | 423 ++ vendor/twig/twig/lib/Twig/Node/Print.php | 39 + vendor/twig/twig/lib/Twig/Node/Sandbox.php | 47 + .../twig/lib/Twig/Node/SandboxedPrint.php | 61 + vendor/twig/twig/lib/Twig/Node/Set.php | 101 + vendor/twig/twig/lib/Twig/Node/SetTemp.php | 35 + vendor/twig/twig/lib/Twig/Node/Spaceless.php | 40 + vendor/twig/twig/lib/Twig/Node/Text.php | 39 + vendor/twig/twig/lib/Twig/NodeInterface.php | 31 + .../twig/lib/Twig/NodeOutputInterface.php | 19 + vendor/twig/twig/lib/Twig/NodeTraverser.php | 90 + .../twig/lib/Twig/NodeVisitor/Escaper.php | 167 + .../twig/lib/Twig/NodeVisitor/Optimizer.php | 271 ++ .../lib/Twig/NodeVisitor/SafeAnalysis.php | 139 + .../twig/lib/Twig/NodeVisitor/Sandbox.php | 92 + .../twig/lib/Twig/NodeVisitorInterface.php | 47 + vendor/twig/twig/lib/Twig/Parser.php | 390 ++ vendor/twig/twig/lib/Twig/ParserInterface.php | 31 + .../lib/Twig/Profiler/Dumper/Blackfire.php | 68 + .../twig/lib/Twig/Profiler/Dumper/Html.php | 43 + .../twig/lib/Twig/Profiler/Dumper/Text.php | 68 + .../lib/Twig/Profiler/Node/EnterProfile.php | 40 + .../lib/Twig/Profiler/Node/LeaveProfile.php | 34 + .../Twig/Profiler/NodeVisitor/Profiler.php | 72 + .../twig/twig/lib/Twig/Profiler/Profile.php | 150 + .../twig/lib/Twig/Sandbox/SecurityError.php | 19 + .../Sandbox/SecurityNotAllowedFilterError.php | 31 + .../SecurityNotAllowedFunctionError.php | 31 + .../Sandbox/SecurityNotAllowedTagError.php | 31 + .../twig/lib/Twig/Sandbox/SecurityPolicy.php | 119 + .../Twig/Sandbox/SecurityPolicyInterface.php | 24 + vendor/twig/twig/lib/Twig/SimpleFilter.php | 94 + vendor/twig/twig/lib/Twig/SimpleFunction.php | 84 + vendor/twig/twig/lib/Twig/SimpleTest.php | 46 + vendor/twig/twig/lib/Twig/Template.php | 536 +++ .../twig/twig/lib/Twig/TemplateInterface.php | 48 + vendor/twig/twig/lib/Twig/Test.php | 34 + vendor/twig/twig/lib/Twig/Test/Function.php | 35 + .../lib/Twig/Test/IntegrationTestCase.php | 154 + vendor/twig/twig/lib/Twig/Test/Method.php | 37 + vendor/twig/twig/lib/Twig/Test/Node.php | 37 + .../twig/twig/lib/Twig/Test/NodeTestCase.php | 60 + .../twig/lib/Twig/TestCallableInterface.php | 21 + vendor/twig/twig/lib/Twig/TestInterface.php | 26 + vendor/twig/twig/lib/Twig/Token.php | 216 ++ vendor/twig/twig/lib/Twig/TokenParser.php | 33 + .../twig/lib/Twig/TokenParser/AutoEscape.php | 89 + .../twig/twig/lib/Twig/TokenParser/Block.php | 81 + vendor/twig/twig/lib/Twig/TokenParser/Do.php | 42 + .../twig/twig/lib/Twig/TokenParser/Embed.php | 66 + .../twig/lib/Twig/TokenParser/Extends.php | 52 + .../twig/twig/lib/Twig/TokenParser/Filter.php | 61 + .../twig/twig/lib/Twig/TokenParser/Flush.php | 42 + vendor/twig/twig/lib/Twig/TokenParser/For.php | 135 + .../twig/twig/lib/Twig/TokenParser/From.php | 70 + vendor/twig/twig/lib/Twig/TokenParser/If.php | 94 + .../twig/twig/lib/Twig/TokenParser/Import.php | 49 + .../twig/lib/Twig/TokenParser/Include.php | 75 + .../twig/twig/lib/Twig/TokenParser/Macro.php | 68 + .../twig/lib/Twig/TokenParser/Sandbox.php | 68 + vendor/twig/twig/lib/Twig/TokenParser/Set.php | 83 + .../twig/lib/Twig/TokenParser/Spaceless.php | 59 + vendor/twig/twig/lib/Twig/TokenParser/Use.php | 76 + .../twig/twig/lib/Twig/TokenParserBroker.php | 136 + .../lib/Twig/TokenParserBrokerInterface.php | 45 + .../twig/lib/Twig/TokenParserInterface.php | 43 + vendor/twig/twig/lib/Twig/TokenStream.php | 156 + vendor/twig/twig/phpunit.xml.dist | 25 + .../twig/test/Twig/Tests/AutoloaderTest.php | 21 + .../twig/test/Twig/Tests/CompilerTest.php | 33 + .../twig/test/Twig/Tests/EnvironmentTest.php | 288 ++ .../twig/twig/test/Twig/Tests/ErrorTest.php | 144 + .../test/Twig/Tests/ExpressionParserTest.php | 332 ++ .../test/Twig/Tests/Extension/CoreTest.php | 156 + .../test/Twig/Tests/Extension/SandboxTest.php | 220 ++ .../twig/test/Twig/Tests/FileCachingTest.php | 79 + .../FileExtensionEscapingStrategyTest.php | 49 + .../Tests/Fixtures/autoescape/filename.test | 18 + .../test/Twig/Tests/Fixtures/errors/base.html | 1 + .../Twig/Tests/Fixtures/errors/index.html | 7 + ...ltiline_array_with_undefined_variable.test | 18 + ...e_array_with_undefined_variable_again.test | 18 + ...line_function_with_undefined_variable.test | 12 + ...tiline_function_with_unknown_argument.test | 9 + ...multiline_tag_with_undefined_variable.test | 12 + .../syntax_error_in_reused_template.test | 10 + .../Fixtures/exceptions/unclosed_tag.test | 20 + .../Fixtures/exceptions/undefined_parent.test | 8 + .../Fixtures/exceptions/undefined_trait.test | 9 + .../Tests/Fixtures/expressions/array.test | 61 + .../Fixtures/expressions/array_call.test | 14 + .../Tests/Fixtures/expressions/binary.test | 46 + .../Tests/Fixtures/expressions/bitwise.test | 14 + .../Fixtures/expressions/comparison.test | 14 + .../Fixtures/expressions/divisibleby.test | 17 + .../Tests/Fixtures/expressions/dotdot.test | 20 + .../Tests/Fixtures/expressions/ends_with.test | 26 + .../Tests/Fixtures/expressions/grouping.test | 8 + .../Tests/Fixtures/expressions/literals.test | 22 + .../Fixtures/expressions/magic_call.test | 27 + .../Tests/Fixtures/expressions/matches.test | 12 + .../Fixtures/expressions/method_call.test | 28 + .../expressions/negative_numbers.test | 18 + .../expressions/operators_as_variables.test | 16 + .../Tests/Fixtures/expressions/postfix.test | 22 + .../Tests/Fixtures/expressions/sameas.test | 21 + .../Fixtures/expressions/starts_with.test | 27 + .../Tests/Fixtures/expressions/strings.test | 10 + .../expressions/ternary_operator.test | 18 + .../expressions/ternary_operator_noelse.test | 10 + .../expressions/ternary_operator_nothen.test | 10 + .../two_word_operators_as_variables.test | 8 + .../Tests/Fixtures/expressions/unary.test | 12 + .../expressions/unary_macro_arguments.test | 22 + .../expressions/unary_precedence.test | 14 + .../test/Twig/Tests/Fixtures/filters/abs.test | 30 + .../Twig/Tests/Fixtures/filters/batch.test | 31 + .../Tests/Fixtures/filters/batch_float.test | 29 + .../filters/batch_with_empty_fill.test | 37 + .../filters/batch_with_exact_elements.test | 33 + .../Fixtures/filters/batch_with_fill.test | 37 + .../Fixtures/filters/convert_encoding.test | 10 + .../Twig/Tests/Fixtures/filters/date.test | 90 + .../Fixtures/filters/date_default_format.test | 14 + .../filters/date_default_format_interval.test | 16 + .../Fixtures/filters/date_immutable.test | 37 + .../Tests/Fixtures/filters/date_interval.test | 19 + .../Tests/Fixtures/filters/date_modify.test | 14 + .../Fixtures/filters/date_namedargs.test | 13 + .../Twig/Tests/Fixtures/filters/default.test | 150 + .../Fixtures/filters/dynamic_filter.test | 10 + .../Twig/Tests/Fixtures/filters/escape.test | 8 + .../Fixtures/filters/escape_html_attr.test | 8 + .../filters/escape_non_supported_charset.test | 8 + .../Twig/Tests/Fixtures/filters/first.test | 17 + .../Tests/Fixtures/filters/force_escape.test | 18 + .../Twig/Tests/Fixtures/filters/format.test | 8 + .../Twig/Tests/Fixtures/filters/join.test | 12 + .../Tests/Fixtures/filters/json_encode.test | 12 + .../Twig/Tests/Fixtures/filters/last.test | 17 + .../Twig/Tests/Fixtures/filters/length.test | 14 + .../Tests/Fixtures/filters/length_utf8.test | 12 + .../Twig/Tests/Fixtures/filters/merge.test | 16 + .../Twig/Tests/Fixtures/filters/nl2br.test | 14 + .../Tests/Fixtures/filters/number_format.test | 18 + .../filters/number_format_default.test | 21 + .../Twig/Tests/Fixtures/filters/replace.test | 8 + .../Twig/Tests/Fixtures/filters/reverse.test | 18 + .../Twig/Tests/Fixtures/filters/round.test | 22 + .../Twig/Tests/Fixtures/filters/slice.test | 54 + .../Twig/Tests/Fixtures/filters/sort.test | 10 + .../Tests/Fixtures/filters/special_chars.test | 8 + .../Twig/Tests/Fixtures/filters/split.test | 20 + .../Tests/Fixtures/filters/split_utf8.test | 24 + .../Twig/Tests/Fixtures/filters/trim.test | 12 + .../Tests/Fixtures/filters/urlencode.test | 16 + .../filters/urlencode_deprecated.test | 16 + .../Tests/Fixtures/functions/attribute.test | 18 + .../Twig/Tests/Fixtures/functions/block.test | 12 + .../Tests/Fixtures/functions/constant.test | 10 + .../Twig/Tests/Fixtures/functions/cycle.test | 16 + .../Twig/Tests/Fixtures/functions/date.test | 25 + .../Fixtures/functions/date_namedargs.test | 11 + .../Twig/Tests/Fixtures/functions/dump.test | 16 + .../Tests/Fixtures/functions/dump_array.test | 19 + .../Fixtures/functions/dynamic_function.test | 10 + .../functions/include/assignment.test | 13 + .../functions/include/autoescaping.test | 10 + .../Fixtures/functions/include/basic.test | 17 + .../functions/include/expression.test | 17 + .../functions/include/ignore_missing.test | 10 + .../Fixtures/functions/include/missing.test | 8 + .../functions/include/missing_nested.test | 16 + .../Fixtures/functions/include/sandbox.test | 13 + .../functions/include/template_instance.test | 10 + .../functions/include/templates_as_array.test | 12 + .../functions/include/with_context.test | 16 + .../functions/include/with_variables.test | 12 + .../Twig/Tests/Fixtures/functions/max.test | 12 + .../Twig/Tests/Fixtures/functions/min.test | 12 + .../Twig/Tests/Fixtures/functions/range.test | 8 + .../recursive_block_with_inheritance.test | 21 + .../Twig/Tests/Fixtures/functions/source.test | 17 + .../Fixtures/functions/special_chars.test | 8 + .../functions/template_from_string.test | 15 + .../Tests/Fixtures/macros/default_values.test | 16 + .../Tests/Fixtures/macros/nested_calls.test | 18 + .../Fixtures/macros/reserved_variables.test | 14 + .../Twig/Tests/Fixtures/macros/simple.test | 22 + .../Tests/Fixtures/macros/with_filters.test | 14 + .../regression/combined_debug_info.test | 15 + .../Fixtures/regression/empty_token.test | 8 + .../Tests/Fixtures/regression/issue_1143.test | 23 + .../Fixtures/regression/multi_word_tests.test | 10 + .../regression/simple_xml_element.test | 19 + .../regression/strings_like_numbers.test | 8 + .../Tests/Fixtures/tags/autoescape/basic.test | 26 + .../Fixtures/tags/autoescape/blocks.test | 12 + .../tags/autoescape/double_escaping.test | 10 + .../Fixtures/tags/autoescape/functions.test | 83 + .../Fixtures/tags/autoescape/literal.test | 45 + .../Fixtures/tags/autoescape/nested.test | 26 + .../Fixtures/tags/autoescape/objects.test | 26 + .../Tests/Fixtures/tags/autoescape/raw.test | 10 + .../Fixtures/tags/autoescape/strategy.test | 17 + .../Tests/Fixtures/tags/autoescape/type.test | 69 + .../tags/autoescape/with_filters.test | 131 + .../autoescape/with_filters_arguments.test | 23 + .../autoescape/with_pre_escape_filters.test | 68 + .../with_preserves_safety_filters.test | 50 + .../Twig/Tests/Fixtures/tags/block/basic.test | 11 + .../tags/block/block_unique_name.test | 11 + .../Fixtures/tags/block/special_chars.test | 10 + .../Twig/Tests/Fixtures/tags/embed/basic.test | 35 + .../Tests/Fixtures/tags/embed/error_line.test | 16 + .../Tests/Fixtures/tags/embed/multiple.test | 50 + .../Tests/Fixtures/tags/embed/nested.test | 42 + .../Fixtures/tags/embed/with_extends.test | 57 + .../Tests/Fixtures/tags/filter/basic.test | 10 + .../Fixtures/tags/filter/json_encode.test | 8 + .../Tests/Fixtures/tags/filter/multiple.test | 10 + .../Tests/Fixtures/tags/filter/nested.test | 16 + .../Fixtures/tags/filter/with_for_tag.test | 13 + .../Fixtures/tags/filter/with_if_tag.test | 29 + .../Tests/Fixtures/tags/for/condition.test | 14 + .../Twig/Tests/Fixtures/tags/for/context.test | 18 + .../Twig/Tests/Fixtures/tags/for/else.test | 23 + .../Fixtures/tags/for/inner_variables.test | 17 + .../Twig/Tests/Fixtures/tags/for/keys.test | 11 + .../Fixtures/tags/for/keys_and_values.test | 11 + .../Tests/Fixtures/tags/for/loop_context.test | 19 + .../Fixtures/tags/for/loop_context_local.test | 10 + .../Fixtures/tags/for/loop_not_defined.test | 10 + .../tags/for/loop_not_defined_cond.test | 9 + .../Tests/Fixtures/tags/for/nested_else.test | 17 + .../Twig/Tests/Fixtures/tags/for/objects.test | 43 + .../Fixtures/tags/for/objects_countable.test | 47 + .../Tests/Fixtures/tags/for/recursive.test | 18 + .../Twig/Tests/Fixtures/tags/for/values.test | 11 + .../test/Twig/Tests/Fixtures/tags/from.test | 14 + .../Twig/Tests/Fixtures/tags/if/basic.test | 22 + .../Tests/Fixtures/tags/if/expression.test | 22 + .../Tests/Fixtures/tags/include/basic.test | 16 + .../Fixtures/tags/include/expression.test | 16 + .../Fixtures/tags/include/ignore_missing.test | 10 + .../Tests/Fixtures/tags/include/missing.test | 8 + .../Fixtures/tags/include/missing_nested.test | 16 + .../Tests/Fixtures/tags/include/only.test | 16 + .../tags/include/template_instance.test | 10 + .../tags/include/templates_as_array.test | 12 + .../Fixtures/tags/include/with_variables.test | 12 + .../Fixtures/tags/inheritance/basic.test | 14 + .../Fixtures/tags/inheritance/block_expr.test | 32 + .../tags/inheritance/block_expr2.test | 34 + .../tags/inheritance/conditional.test | 14 + .../Fixtures/tags/inheritance/dynamic.test | 14 + .../Fixtures/tags/inheritance/empty.test | 10 + .../tags/inheritance/extends_as_array.test | 12 + .../extends_as_array_with_empty_name.test | 12 + .../extends_as_array_with_null_name.test | 12 + .../Fixtures/tags/inheritance/multiple.test | 12 + .../tags/inheritance/multiple_dynamic.test | 22 + .../tags/inheritance/nested_blocks.test | 22 + .../nested_blocks_parent_only.test | 15 + .../tags/inheritance/nested_inheritance.test | 16 + .../Fixtures/tags/inheritance/parent.test | 12 + .../tags/inheritance/parent_change.test | 16 + .../tags/inheritance/parent_in_a_block.test | 8 + .../tags/inheritance/parent_isolation.test | 20 + .../tags/inheritance/parent_nested.test | 28 + .../inheritance/parent_without_extends.test | 8 + .../parent_without_extends_but_traits.test | 14 + .../tags/inheritance/template_instance.test | 14 + .../Tests/Fixtures/tags/inheritance/use.test | 44 + .../Twig/Tests/Fixtures/tags/macro/basic.test | 17 + .../Fixtures/tags/macro/endmacro_name.test | 16 + .../Tests/Fixtures/tags/macro/external.test | 17 + .../Twig/Tests/Fixtures/tags/macro/from.test | 18 + .../Tests/Fixtures/tags/macro/global.test | 14 + .../Fixtures/tags/macro/self_import.test | 17 + .../Fixtures/tags/macro/special_chars.test | 14 + .../Fixtures/tags/macro/super_globals.test | 14 + .../Twig/Tests/Fixtures/tags/raw/basic.test | 10 + .../tags/raw/mixed_usage_with_raw.test | 10 + .../Fixtures/tags/raw/whitespace_control.test | 56 + .../Fixtures/tags/sandbox/not_valid1.test | 11 + .../Fixtures/tags/sandbox/not_valid2.test | 14 + .../Tests/Fixtures/tags/sandbox/simple.test | 22 + .../Twig/Tests/Fixtures/tags/set/basic.test | 20 + .../Fixtures/tags/set/capture-empty.test | 9 + .../Twig/Tests/Fixtures/tags/set/capture.test | 10 + .../Tests/Fixtures/tags/set/expression.test | 12 + .../Tests/Fixtures/tags/spaceless/simple.test | 12 + .../Tests/Fixtures/tags/special_chars.test | 8 + .../Twig/Tests/Fixtures/tags/trim_block.test | 74 + .../Twig/Tests/Fixtures/tags/use/aliases.test | 12 + .../Twig/Tests/Fixtures/tags/use/basic.test | 12 + .../Twig/Tests/Fixtures/tags/use/deep.test | 22 + .../Tests/Fixtures/tags/use/deep_empty.test | 10 + .../Tests/Fixtures/tags/use/inheritance.test | 25 + .../Tests/Fixtures/tags/use/inheritance2.test | 24 + .../Tests/Fixtures/tags/use/multiple.test | 21 + .../Fixtures/tags/use/multiple_aliases.test | 23 + .../Tests/Fixtures/tags/use/parent_block.test | 24 + .../Fixtures/tags/use/parent_block2.test | 24 + .../Fixtures/tags/use/parent_block3.test | 38 + .../Tests/Fixtures/tags/verbatim/basic.test | 10 + .../tags/verbatim/mixed_usage_with_raw.test | 10 + .../tags/verbatim/whitespace_control.test | 56 + .../test/Twig/Tests/Fixtures/tests/array.test | 24 + .../Twig/Tests/Fixtures/tests/constant.test | 14 + .../Twig/Tests/Fixtures/tests/defined.test | 108 + .../test/Twig/Tests/Fixtures/tests/empty.test | 45 + .../test/Twig/Tests/Fixtures/tests/even.test | 14 + .../test/Twig/Tests/Fixtures/tests/in.test | 128 + .../Tests/Fixtures/tests/in_with_objects.test | 19 + .../Twig/Tests/Fixtures/tests/iterable.test | 19 + .../test/Twig/Tests/Fixtures/tests/odd.test | 10 + .../twig/test/Twig/Tests/IntegrationTest.php | 229 ++ .../twig/twig/test/Twig/Tests/LexerTest.php | 300 ++ .../twig/test/Twig/Tests/Loader/ArrayTest.php | 97 + .../twig/test/Twig/Tests/Loader/ChainTest.php | 79 + .../test/Twig/Tests/Loader/FilesystemTest.php | 175 + .../array_inheritance_empty_parent.html.twig | 3 + ...y_inheritance_nonexistent_parent.html.twig | 3 + .../array_inheritance_null_parent.html.twig | 3 + .../array_inheritance_valid_parent.html.twig | 3 + .../Fixtures/inheritance/parent.html.twig | 1 + .../inheritance/spare_parent.html.twig | 1 + .../Tests/Loader/Fixtures/named/index.html | 1 + .../Loader/Fixtures/named_bis/index.html | 1 + .../Loader/Fixtures/named_final/index.html | 1 + .../Fixtures/named_quater/named_absolute.html | 1 + .../Loader/Fixtures/named_ter/index.html | 1 + .../Tests/Loader/Fixtures/normal/index.html | 1 + .../Loader/Fixtures/normal_bis/index.html | 1 + .../Loader/Fixtures/normal_final/index.html | 1 + .../Loader/Fixtures/normal_ter/index.html | 1 + .../Fixtures/themes/theme1/blocks.html.twig | 3 + .../Fixtures/themes/theme2/blocks.html.twig | 3 + .../test/Twig/Tests/NativeExtensionTest.php | 33 + .../test/Twig/Tests/Node/AutoEscapeTest.php | 32 + .../Twig/Tests/Node/BlockReferenceTest.php | 31 + .../twig/test/Twig/Tests/Node/BlockTest.php | 39 + .../twig/twig/test/Twig/Tests/Node/DoTest.php | 32 + .../Twig/Tests/Node/Expression/ArrayTest.php | 37 + .../Tests/Node/Expression/AssignNameTest.php | 29 + .../Tests/Node/Expression/Binary/AddTest.php | 34 + .../Tests/Node/Expression/Binary/AndTest.php | 34 + .../Node/Expression/Binary/ConcatTest.php | 34 + .../Tests/Node/Expression/Binary/DivTest.php | 34 + .../Node/Expression/Binary/FloorDivTest.php | 34 + .../Tests/Node/Expression/Binary/ModTest.php | 34 + .../Tests/Node/Expression/Binary/MulTest.php | 34 + .../Tests/Node/Expression/Binary/OrTest.php | 34 + .../Tests/Node/Expression/Binary/SubTest.php | 34 + .../Twig/Tests/Node/Expression/CallTest.php | 102 + .../Tests/Node/Expression/ConditionalTest.php | 38 + .../Tests/Node/Expression/ConstantTest.php | 30 + .../Twig/Tests/Node/Expression/FilterTest.php | 121 + .../Tests/Node/Expression/FunctionTest.php | 87 + .../Tests/Node/Expression/GetAttrTest.php | 50 + .../Twig/Tests/Node/Expression/NameTest.php | 37 + .../Node/Expression/PHP53/FilterInclude.php | 6 + .../Node/Expression/PHP53/FunctionInclude.php | 6 + .../Node/Expression/PHP53/TestInclude.php | 6 + .../Twig/Tests/Node/Expression/ParentTest.php | 28 + .../Twig/Tests/Node/Expression/TestTest.php | 56 + .../Tests/Node/Expression/Unary/NegTest.php | 32 + .../Tests/Node/Expression/Unary/NotTest.php | 31 + .../Tests/Node/Expression/Unary/PosTest.php | 31 + .../twig/test/Twig/Tests/Node/ForTest.php | 191 + .../twig/twig/test/Twig/Tests/Node/IfTest.php | 88 + .../twig/test/Twig/Tests/Node/ImportTest.php | 40 + .../twig/test/Twig/Tests/Node/IncludeTest.php | 83 + .../twig/test/Twig/Tests/Node/MacroTest.php | 61 + .../twig/test/Twig/Tests/Node/ModuleTest.php | 183 + .../twig/test/Twig/Tests/Node/PrintTest.php | 29 + .../twig/test/Twig/Tests/Node/SandboxTest.php | 44 + .../Twig/Tests/Node/SandboxedPrintTest.php | 33 + .../twig/test/Twig/Tests/Node/SetTest.php | 69 + .../test/Twig/Tests/Node/SpacelessTest.php | 37 + .../twig/test/Twig/Tests/Node/TextTest.php | 28 + .../Twig/Tests/NodeVisitor/OptimizerTest.php | 124 + .../twig/twig/test/Twig/Tests/ParserTest.php | 180 + .../Tests/Profiler/Dumper/AbstractTest.php | 101 + .../Tests/Profiler/Dumper/BlackfireTest.php | 32 + .../Twig/Tests/Profiler/Dumper/HtmlTest.php | 30 + .../Twig/Tests/Profiler/Dumper/TextTest.php | 30 + .../test/Twig/Tests/Profiler/ProfileTest.php | 100 + .../twig/test/Twig/Tests/TemplateTest.php | 670 ++++ .../twig/test/Twig/Tests/TokenStreamTest.php | 70 + .../twig/test/Twig/Tests/escapingTest.php | 320 ++ vendor/twig/twig/test/bootstrap.php | 13 + 1162 files changed, 112457 insertions(+) create mode 100755 vendor/alexgarrett/violin/README.md create mode 100755 vendor/alexgarrett/violin/composer.json create mode 100755 vendor/alexgarrett/violin/examples/advanced/extending.php create mode 100755 vendor/alexgarrett/violin/examples/basic.php create mode 100755 vendor/alexgarrett/violin/examples/basic_two_array.php create mode 100755 vendor/alexgarrett/violin/examples/errors/errors_all.php create mode 100755 vendor/alexgarrett/violin/examples/errors/errors_field.php create mode 100755 vendor/alexgarrett/violin/examples/errors/errors_first.php create mode 100755 vendor/alexgarrett/violin/examples/messages/custom_field_message.php create mode 100755 vendor/alexgarrett/violin/examples/messages/custom_field_messages.php create mode 100755 vendor/alexgarrett/violin/examples/messages/custom_rule_message.php create mode 100755 vendor/alexgarrett/violin/examples/messages/custom_rule_messages.php create mode 100755 vendor/alexgarrett/violin/examples/messages/field_aliases.php create mode 100755 vendor/alexgarrett/violin/examples/messages/placeholders/placeholders.php create mode 100755 vendor/alexgarrett/violin/examples/messages/placeholders/placeholders_all.php create mode 100755 vendor/alexgarrett/violin/examples/rules/custom_rule.php create mode 100755 vendor/alexgarrett/violin/examples/rules/custom_rule_arguments.php create mode 100755 vendor/alexgarrett/violin/phpunit.xml create mode 100755 vendor/alexgarrett/violin/src/Contracts/MessageBagContract.php create mode 100755 vendor/alexgarrett/violin/src/Contracts/RuleContract.php create mode 100755 vendor/alexgarrett/violin/src/Contracts/ValidatorContract.php create mode 100755 vendor/alexgarrett/violin/src/Rules/AlnumDashRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/AlnumRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/AlphaRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/ArrayRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/BetweenRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/BoolRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/CheckedRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/DateRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/EmailRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/IntRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/IpRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/MatchesRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/MaxRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/MinRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/NumberRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/RegexRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/RequiredRule.php create mode 100755 vendor/alexgarrett/violin/src/Rules/UrlRule.php create mode 100755 vendor/alexgarrett/violin/src/Support/MessageBag.php create mode 100755 vendor/alexgarrett/violin/src/Violin.php create mode 100755 vendor/alexgarrett/violin/tests/MessageBagTest.php create mode 100755 vendor/alexgarrett/violin/tests/RulesTest.php create mode 100755 vendor/alexgarrett/violin/tests/ValidatorTest.php create mode 100755 vendor/autoload.php create mode 100755 vendor/composer/ClassLoader.php create mode 100755 vendor/composer/autoload_classmap.php create mode 100755 vendor/composer/autoload_files.php create mode 100755 vendor/composer/autoload_namespaces.php create mode 100755 vendor/composer/autoload_psr4.php create mode 100755 vendor/composer/autoload_real.php create mode 100755 vendor/composer/installed.json create mode 100755 vendor/danielstjules/stringy/CHANGELOG.md create mode 100755 vendor/danielstjules/stringy/LICENSE.txt create mode 100755 vendor/danielstjules/stringy/README.md create mode 100755 vendor/danielstjules/stringy/composer.json create mode 100755 vendor/danielstjules/stringy/phpunit.xml.dist create mode 100755 vendor/danielstjules/stringy/src/Create.php create mode 100755 vendor/danielstjules/stringy/src/StaticStringy.php create mode 100755 vendor/danielstjules/stringy/src/Stringy.php create mode 100755 vendor/danielstjules/stringy/tests/CommonTest.php create mode 100755 vendor/danielstjules/stringy/tests/CreateTest.php create mode 100755 vendor/danielstjules/stringy/tests/StaticStringyTest.php create mode 100755 vendor/danielstjules/stringy/tests/StringyTest.php create mode 100755 vendor/doctrine/inflector/LICENSE create mode 100755 vendor/doctrine/inflector/README.md create mode 100755 vendor/doctrine/inflector/composer.json create mode 100755 vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php create mode 100755 vendor/doctrine/inflector/phpunit.xml.dist create mode 100755 vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php create mode 100755 vendor/doctrine/inflector/tests/Doctrine/Tests/DoctrineTestCase.php create mode 100755 vendor/doctrine/inflector/tests/Doctrine/Tests/TestInit.php create mode 100755 vendor/hassankhan/config/CHANGELOG.md create mode 100755 vendor/hassankhan/config/CONTRIBUTING.md create mode 100755 vendor/hassankhan/config/LICENSE.md create mode 100755 vendor/hassankhan/config/composer.json create mode 100755 vendor/hassankhan/config/src/AbstractConfig.php create mode 100755 vendor/hassankhan/config/src/Config.php create mode 100755 vendor/hassankhan/config/src/ConfigInterface.php create mode 100755 vendor/hassankhan/config/src/Exception/EmptyDirectoryException.php create mode 100755 vendor/hassankhan/config/src/Exception/FileNotFoundException.php create mode 100755 vendor/hassankhan/config/src/Exception/ParseException.php create mode 100755 vendor/hassankhan/config/src/Exception/UnsupportedFormatException.php create mode 100755 vendor/hassankhan/config/src/FileParser/AbstractFileParser.php create mode 100755 vendor/hassankhan/config/src/FileParser/FileParserInterface.php create mode 100755 vendor/hassankhan/config/src/FileParser/Ini.php create mode 100755 vendor/hassankhan/config/src/FileParser/Json.php create mode 100755 vendor/hassankhan/config/src/FileParser/Php.php create mode 100755 vendor/hassankhan/config/src/FileParser/Xml.php create mode 100755 vendor/hassankhan/config/src/FileParser/Yaml.php create mode 100755 vendor/illuminate/container/BindingResolutionException.php create mode 100755 vendor/illuminate/container/Container.php create mode 100755 vendor/illuminate/container/ContextualBindingBuilder.php create mode 100755 vendor/illuminate/container/composer.json create mode 100755 vendor/illuminate/contracts/Auth/Authenticatable.php create mode 100755 vendor/illuminate/contracts/Auth/CanResetPassword.php create mode 100755 vendor/illuminate/contracts/Auth/Guard.php create mode 100755 vendor/illuminate/contracts/Auth/PasswordBroker.php create mode 100755 vendor/illuminate/contracts/Auth/Registrar.php create mode 100755 vendor/illuminate/contracts/Auth/UserProvider.php create mode 100755 vendor/illuminate/contracts/Bus/Dispatcher.php create mode 100755 vendor/illuminate/contracts/Bus/HandlerResolver.php create mode 100755 vendor/illuminate/contracts/Bus/QueueingDispatcher.php create mode 100755 vendor/illuminate/contracts/Bus/SelfHandling.php create mode 100755 vendor/illuminate/contracts/Cache/Factory.php create mode 100755 vendor/illuminate/contracts/Cache/Repository.php create mode 100755 vendor/illuminate/contracts/Cache/Store.php create mode 100755 vendor/illuminate/contracts/Config/Repository.php create mode 100755 vendor/illuminate/contracts/Console/Application.php create mode 100755 vendor/illuminate/contracts/Console/Kernel.php create mode 100755 vendor/illuminate/contracts/Container/Container.php create mode 100755 vendor/illuminate/contracts/Container/ContextualBindingBuilder.php create mode 100755 vendor/illuminate/contracts/Cookie/Factory.php create mode 100755 vendor/illuminate/contracts/Cookie/QueueingFactory.php create mode 100755 vendor/illuminate/contracts/Database/ModelIdentifier.php create mode 100755 vendor/illuminate/contracts/Debug/ExceptionHandler.php create mode 100755 vendor/illuminate/contracts/Encryption/DecryptException.php create mode 100755 vendor/illuminate/contracts/Encryption/Encrypter.php create mode 100755 vendor/illuminate/contracts/Events/Dispatcher.php create mode 100755 vendor/illuminate/contracts/Filesystem/Cloud.php create mode 100755 vendor/illuminate/contracts/Filesystem/Factory.php create mode 100755 vendor/illuminate/contracts/Filesystem/FileNotFoundException.php create mode 100755 vendor/illuminate/contracts/Filesystem/Filesystem.php create mode 100755 vendor/illuminate/contracts/Foundation/Application.php create mode 100755 vendor/illuminate/contracts/Hashing/Hasher.php create mode 100755 vendor/illuminate/contracts/Http/Kernel.php create mode 100755 vendor/illuminate/contracts/Logging/Log.php create mode 100755 vendor/illuminate/contracts/Mail/MailQueue.php create mode 100755 vendor/illuminate/contracts/Mail/Mailer.php create mode 100755 vendor/illuminate/contracts/Pagination/LengthAwarePaginator.php create mode 100755 vendor/illuminate/contracts/Pagination/Paginator.php create mode 100755 vendor/illuminate/contracts/Pagination/Presenter.php create mode 100755 vendor/illuminate/contracts/Pipeline/Hub.php create mode 100755 vendor/illuminate/contracts/Pipeline/Pipeline.php create mode 100755 vendor/illuminate/contracts/Queue/EntityNotFoundException.php create mode 100755 vendor/illuminate/contracts/Queue/EntityResolver.php create mode 100755 vendor/illuminate/contracts/Queue/Factory.php create mode 100755 vendor/illuminate/contracts/Queue/Job.php create mode 100755 vendor/illuminate/contracts/Queue/Monitor.php create mode 100755 vendor/illuminate/contracts/Queue/Queue.php create mode 100755 vendor/illuminate/contracts/Queue/QueueableEntity.php create mode 100755 vendor/illuminate/contracts/Queue/ShouldBeQueued.php create mode 100755 vendor/illuminate/contracts/Redis/Database.php create mode 100755 vendor/illuminate/contracts/Routing/Middleware.php create mode 100755 vendor/illuminate/contracts/Routing/Registrar.php create mode 100755 vendor/illuminate/contracts/Routing/ResponseFactory.php create mode 100755 vendor/illuminate/contracts/Routing/TerminableMiddleware.php create mode 100755 vendor/illuminate/contracts/Routing/UrlGenerator.php create mode 100755 vendor/illuminate/contracts/Routing/UrlRoutable.php create mode 100755 vendor/illuminate/contracts/Support/Arrayable.php create mode 100755 vendor/illuminate/contracts/Support/Jsonable.php create mode 100755 vendor/illuminate/contracts/Support/MessageBag.php create mode 100755 vendor/illuminate/contracts/Support/MessageProvider.php create mode 100755 vendor/illuminate/contracts/Support/Renderable.php create mode 100755 vendor/illuminate/contracts/Validation/Factory.php create mode 100755 vendor/illuminate/contracts/Validation/UnauthorizedException.php create mode 100755 vendor/illuminate/contracts/Validation/ValidatesWhenResolved.php create mode 100755 vendor/illuminate/contracts/Validation/ValidationException.php create mode 100755 vendor/illuminate/contracts/Validation/Validator.php create mode 100755 vendor/illuminate/contracts/View/Factory.php create mode 100755 vendor/illuminate/contracts/View/View.php create mode 100755 vendor/illuminate/contracts/composer.json create mode 100755 vendor/illuminate/database/Capsule/Manager.php create mode 100755 vendor/illuminate/database/Connection.php create mode 100755 vendor/illuminate/database/ConnectionInterface.php create mode 100755 vendor/illuminate/database/ConnectionResolver.php create mode 100755 vendor/illuminate/database/ConnectionResolverInterface.php create mode 100755 vendor/illuminate/database/Connectors/ConnectionFactory.php create mode 100755 vendor/illuminate/database/Connectors/Connector.php create mode 100755 vendor/illuminate/database/Connectors/ConnectorInterface.php create mode 100755 vendor/illuminate/database/Connectors/MySqlConnector.php create mode 100755 vendor/illuminate/database/Connectors/PostgresConnector.php create mode 100755 vendor/illuminate/database/Connectors/SQLiteConnector.php create mode 100755 vendor/illuminate/database/Connectors/SqlServerConnector.php create mode 100755 vendor/illuminate/database/Console/Migrations/BaseCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/InstallCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/MigrateCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/MigrateMakeCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/RefreshCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/ResetCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/RollbackCommand.php create mode 100755 vendor/illuminate/database/Console/Migrations/StatusCommand.php create mode 100755 vendor/illuminate/database/Console/SeedCommand.php create mode 100755 vendor/illuminate/database/DatabaseManager.php create mode 100755 vendor/illuminate/database/DatabaseServiceProvider.php create mode 100755 vendor/illuminate/database/Eloquent/Builder.php create mode 100755 vendor/illuminate/database/Eloquent/Collection.php create mode 100755 vendor/illuminate/database/Eloquent/MassAssignmentException.php create mode 100755 vendor/illuminate/database/Eloquent/Model.php create mode 100755 vendor/illuminate/database/Eloquent/ModelNotFoundException.php create mode 100755 vendor/illuminate/database/Eloquent/QueueEntityResolver.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/BelongsTo.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/HasMany.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/HasManyThrough.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/HasOne.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/HasOneOrMany.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/MorphMany.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/MorphOne.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/MorphOneOrMany.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/MorphPivot.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/MorphTo.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/MorphToMany.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/Pivot.php create mode 100755 vendor/illuminate/database/Eloquent/Relations/Relation.php create mode 100755 vendor/illuminate/database/Eloquent/ScopeInterface.php create mode 100755 vendor/illuminate/database/Eloquent/SoftDeletes.php create mode 100755 vendor/illuminate/database/Eloquent/SoftDeletingScope.php create mode 100755 vendor/illuminate/database/Grammar.php create mode 100755 vendor/illuminate/database/MigrationServiceProvider.php create mode 100755 vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php create mode 100755 vendor/illuminate/database/Migrations/Migration.php create mode 100755 vendor/illuminate/database/Migrations/MigrationCreator.php create mode 100755 vendor/illuminate/database/Migrations/MigrationRepositoryInterface.php create mode 100755 vendor/illuminate/database/Migrations/Migrator.php create mode 100755 vendor/illuminate/database/Migrations/stubs/blank.stub create mode 100755 vendor/illuminate/database/Migrations/stubs/create.stub create mode 100755 vendor/illuminate/database/Migrations/stubs/update.stub create mode 100755 vendor/illuminate/database/MySqlConnection.php create mode 100755 vendor/illuminate/database/PostgresConnection.php create mode 100755 vendor/illuminate/database/Query/Builder.php create mode 100755 vendor/illuminate/database/Query/Expression.php create mode 100755 vendor/illuminate/database/Query/Grammars/Grammar.php create mode 100755 vendor/illuminate/database/Query/Grammars/MySqlGrammar.php create mode 100755 vendor/illuminate/database/Query/Grammars/PostgresGrammar.php create mode 100755 vendor/illuminate/database/Query/Grammars/SQLiteGrammar.php create mode 100755 vendor/illuminate/database/Query/Grammars/SqlServerGrammar.php create mode 100755 vendor/illuminate/database/Query/JoinClause.php create mode 100755 vendor/illuminate/database/Query/Processors/MySqlProcessor.php create mode 100755 vendor/illuminate/database/Query/Processors/PostgresProcessor.php create mode 100755 vendor/illuminate/database/Query/Processors/Processor.php create mode 100755 vendor/illuminate/database/Query/Processors/SQLiteProcessor.php create mode 100755 vendor/illuminate/database/Query/Processors/SqlServerProcessor.php create mode 100755 vendor/illuminate/database/QueryException.php create mode 100755 vendor/illuminate/database/README.md create mode 100755 vendor/illuminate/database/SQLiteConnection.php create mode 100755 vendor/illuminate/database/Schema/Blueprint.php create mode 100755 vendor/illuminate/database/Schema/Builder.php create mode 100755 vendor/illuminate/database/Schema/Grammars/Grammar.php create mode 100755 vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php create mode 100755 vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php create mode 100755 vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php create mode 100755 vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php create mode 100755 vendor/illuminate/database/Schema/MySqlBuilder.php create mode 100755 vendor/illuminate/database/SeedServiceProvider.php create mode 100755 vendor/illuminate/database/Seeder.php create mode 100755 vendor/illuminate/database/SqlServerConnection.php create mode 100755 vendor/illuminate/database/composer.json create mode 100755 vendor/illuminate/support/AggregateServiceProvider.php create mode 100755 vendor/illuminate/support/Arr.php create mode 100755 vendor/illuminate/support/ClassLoader.php create mode 100755 vendor/illuminate/support/Collection.php create mode 100755 vendor/illuminate/support/Debug/Dumper.php create mode 100755 vendor/illuminate/support/Debug/HtmlDumper.php create mode 100755 vendor/illuminate/support/Facades/App.php create mode 100755 vendor/illuminate/support/Facades/Artisan.php create mode 100755 vendor/illuminate/support/Facades/Auth.php create mode 100755 vendor/illuminate/support/Facades/Blade.php create mode 100755 vendor/illuminate/support/Facades/Bus.php create mode 100755 vendor/illuminate/support/Facades/Cache.php create mode 100755 vendor/illuminate/support/Facades/Config.php create mode 100755 vendor/illuminate/support/Facades/Cookie.php create mode 100755 vendor/illuminate/support/Facades/Crypt.php create mode 100755 vendor/illuminate/support/Facades/DB.php create mode 100755 vendor/illuminate/support/Facades/Event.php create mode 100755 vendor/illuminate/support/Facades/Facade.php create mode 100755 vendor/illuminate/support/Facades/File.php create mode 100755 vendor/illuminate/support/Facades/Hash.php create mode 100755 vendor/illuminate/support/Facades/Input.php create mode 100755 vendor/illuminate/support/Facades/Lang.php create mode 100755 vendor/illuminate/support/Facades/Log.php create mode 100755 vendor/illuminate/support/Facades/Mail.php create mode 100755 vendor/illuminate/support/Facades/Password.php create mode 100755 vendor/illuminate/support/Facades/Queue.php create mode 100755 vendor/illuminate/support/Facades/Redirect.php create mode 100755 vendor/illuminate/support/Facades/Redis.php create mode 100755 vendor/illuminate/support/Facades/Request.php create mode 100755 vendor/illuminate/support/Facades/Response.php create mode 100755 vendor/illuminate/support/Facades/Route.php create mode 100755 vendor/illuminate/support/Facades/Schema.php create mode 100755 vendor/illuminate/support/Facades/Session.php create mode 100755 vendor/illuminate/support/Facades/Storage.php create mode 100755 vendor/illuminate/support/Facades/URL.php create mode 100755 vendor/illuminate/support/Facades/Validator.php create mode 100755 vendor/illuminate/support/Facades/View.php create mode 100755 vendor/illuminate/support/Fluent.php create mode 100755 vendor/illuminate/support/Manager.php create mode 100755 vendor/illuminate/support/MessageBag.php create mode 100755 vendor/illuminate/support/NamespacedItemResolver.php create mode 100755 vendor/illuminate/support/Pluralizer.php create mode 100755 vendor/illuminate/support/ServiceProvider.php create mode 100755 vendor/illuminate/support/Str.php create mode 100755 vendor/illuminate/support/Traits/CapsuleManagerTrait.php create mode 100755 vendor/illuminate/support/Traits/Macroable.php create mode 100755 vendor/illuminate/support/ViewErrorBag.php create mode 100755 vendor/illuminate/support/composer.json create mode 100755 vendor/illuminate/support/helpers.php create mode 100755 vendor/nesbot/carbon/LICENSE create mode 100755 vendor/nesbot/carbon/composer.json create mode 100755 vendor/nesbot/carbon/phpunit.xml.dist create mode 100755 vendor/nesbot/carbon/readme.md create mode 100755 vendor/nesbot/carbon/src/Carbon/Carbon.php create mode 100755 vendor/nesbot/carbon/src/Carbon/CarbonInterval.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/ar.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/az.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/bg.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/ca.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/cs.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/da.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/de.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/el.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/en.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/eo.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/es.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/eu create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/fa.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/fi.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/fr.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/hr.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/hu.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/id.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/it.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/ja.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/ko.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/lt.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/nl.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/no.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/pl.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/pt.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/pt_BR.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/ro.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/ru.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/sk.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/sl.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/sr.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/sv.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/th.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/tr.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/uk.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/vi.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/zh-TW.php create mode 100755 vendor/nesbot/carbon/src/Carbon/Lang/zh.php create mode 100755 vendor/nesbot/carbon/tests/AddTest.php create mode 100755 vendor/nesbot/carbon/tests/CarbonIntervalAddTest.php create mode 100755 vendor/nesbot/carbon/tests/CarbonIntervalConstructTest.php create mode 100755 vendor/nesbot/carbon/tests/CarbonIntervalForHumansTest.php create mode 100755 vendor/nesbot/carbon/tests/CarbonIntervalGettersTest.php create mode 100755 vendor/nesbot/carbon/tests/CarbonIntervalSettersTest.php create mode 100755 vendor/nesbot/carbon/tests/ComparisonTest.php create mode 100755 vendor/nesbot/carbon/tests/ConstructTest.php create mode 100755 vendor/nesbot/carbon/tests/CopyTest.php create mode 100755 vendor/nesbot/carbon/tests/CreateFromDateTest.php create mode 100755 vendor/nesbot/carbon/tests/CreateFromFormatTest.php create mode 100755 vendor/nesbot/carbon/tests/CreateFromTimeTest.php create mode 100755 vendor/nesbot/carbon/tests/CreateFromTimestampTest.php create mode 100755 vendor/nesbot/carbon/tests/CreateTest.php create mode 100755 vendor/nesbot/carbon/tests/DayOfWeekModifiersTest.php create mode 100755 vendor/nesbot/carbon/tests/DiffTest.php create mode 100755 vendor/nesbot/carbon/tests/FluidSettersTest.php create mode 100755 vendor/nesbot/carbon/tests/GettersTest.php create mode 100755 vendor/nesbot/carbon/tests/InstanceTest.php create mode 100755 vendor/nesbot/carbon/tests/IsTest.php create mode 100755 vendor/nesbot/carbon/tests/IssetTest.php create mode 100755 vendor/nesbot/carbon/tests/LocalizationTest.php create mode 100755 vendor/nesbot/carbon/tests/NowAndOtherStaticHelpersTest.php create mode 100755 vendor/nesbot/carbon/tests/RelativeTest.php create mode 100755 vendor/nesbot/carbon/tests/SettersTest.php create mode 100755 vendor/nesbot/carbon/tests/StartEndOfTest.php create mode 100755 vendor/nesbot/carbon/tests/StringsTest.php create mode 100755 vendor/nesbot/carbon/tests/SubTest.php create mode 100755 vendor/nesbot/carbon/tests/TestFixture.php create mode 100755 vendor/nesbot/carbon/tests/TestingAidsTest.php create mode 100755 vendor/slim/slim/CONTRIBUTING.md create mode 100755 vendor/slim/slim/LICENSE create mode 100755 vendor/slim/slim/README.markdown create mode 100755 vendor/slim/slim/Slim/Environment.php create mode 100755 vendor/slim/slim/Slim/Exception/Pass.php create mode 100755 vendor/slim/slim/Slim/Exception/Stop.php create mode 100755 vendor/slim/slim/Slim/Helper/Set.php create mode 100755 vendor/slim/slim/Slim/Http/Cookies.php create mode 100755 vendor/slim/slim/Slim/Http/Headers.php create mode 100755 vendor/slim/slim/Slim/Http/Request.php create mode 100755 vendor/slim/slim/Slim/Http/Response.php create mode 100755 vendor/slim/slim/Slim/Http/Util.php create mode 100755 vendor/slim/slim/Slim/Log.php create mode 100755 vendor/slim/slim/Slim/LogWriter.php create mode 100755 vendor/slim/slim/Slim/Middleware.php create mode 100755 vendor/slim/slim/Slim/Middleware/ContentTypes.php create mode 100755 vendor/slim/slim/Slim/Middleware/Flash.php create mode 100755 vendor/slim/slim/Slim/Middleware/MethodOverride.php create mode 100755 vendor/slim/slim/Slim/Middleware/PrettyExceptions.php create mode 100755 vendor/slim/slim/Slim/Middleware/SessionCookie.php create mode 100755 vendor/slim/slim/Slim/Route.php create mode 100755 vendor/slim/slim/Slim/Router.php create mode 100755 vendor/slim/slim/Slim/Slim.php create mode 100755 vendor/slim/slim/Slim/View.php create mode 100755 vendor/slim/slim/composer.json create mode 100755 vendor/slim/slim/index.php create mode 100755 vendor/slim/slim/phpunit.xml.dist create mode 100755 vendor/slim/slim/tests/EnvironmentTest.php create mode 100755 vendor/slim/slim/tests/Foo.php create mode 100755 vendor/slim/slim/tests/Helper/SetTest.php create mode 100755 vendor/slim/slim/tests/Http/CookiesTest.php create mode 100755 vendor/slim/slim/tests/Http/HeadersTest.php create mode 100755 vendor/slim/slim/tests/Http/RequestTest.php create mode 100755 vendor/slim/slim/tests/Http/ResponseTest.php create mode 100755 vendor/slim/slim/tests/Http/UtilTest.php create mode 100755 vendor/slim/slim/tests/LogTest.php create mode 100755 vendor/slim/slim/tests/LogWriterTest.php create mode 100755 vendor/slim/slim/tests/Middleware/ContentTypesTest.php create mode 100755 vendor/slim/slim/tests/Middleware/FlashTest.php create mode 100755 vendor/slim/slim/tests/Middleware/MethodOverrideTest.php create mode 100755 vendor/slim/slim/tests/Middleware/PrettyExceptionsTest.php create mode 100755 vendor/slim/slim/tests/Middleware/SessionCookieTest.php create mode 100755 vendor/slim/slim/tests/MiddlewareTest.php create mode 100755 vendor/slim/slim/tests/README create mode 100755 vendor/slim/slim/tests/RouteTest.php create mode 100755 vendor/slim/slim/tests/RouterTest.php create mode 100755 vendor/slim/slim/tests/SlimTest.php create mode 100755 vendor/slim/slim/tests/ViewTest.php create mode 100755 vendor/slim/slim/tests/bootstrap.php create mode 100755 vendor/slim/slim/tests/templates/test.php create mode 100755 vendor/slim/views/README.md create mode 100755 vendor/slim/views/Smarty.php create mode 100755 vendor/slim/views/SmartyPlugins/function.baseUrl.php create mode 100755 vendor/slim/views/SmartyPlugins/function.currentUrl.php create mode 100755 vendor/slim/views/SmartyPlugins/function.siteUrl.php create mode 100755 vendor/slim/views/SmartyPlugins/function.urlFor.php create mode 100755 vendor/slim/views/Twig.php create mode 100755 vendor/slim/views/TwigExtension.php create mode 100755 vendor/slim/views/composer.json create mode 100755 vendor/symfony/translation/CHANGELOG.md create mode 100755 vendor/symfony/translation/Catalogue/AbstractOperation.php create mode 100755 vendor/symfony/translation/Catalogue/DiffOperation.php create mode 100755 vendor/symfony/translation/Catalogue/MergeOperation.php create mode 100755 vendor/symfony/translation/Catalogue/OperationInterface.php create mode 100755 vendor/symfony/translation/DataCollector/TranslationDataCollector.php create mode 100755 vendor/symfony/translation/DataCollectorTranslator.php create mode 100755 vendor/symfony/translation/Dumper/CsvFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/DumperInterface.php create mode 100755 vendor/symfony/translation/Dumper/FileDumper.php create mode 100755 vendor/symfony/translation/Dumper/IcuResFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/IniFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/JsonFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/MoFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/PhpFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/PoFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/QtFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/XliffFileDumper.php create mode 100755 vendor/symfony/translation/Dumper/YamlFileDumper.php create mode 100755 vendor/symfony/translation/Exception/ExceptionInterface.php create mode 100755 vendor/symfony/translation/Exception/InvalidResourceException.php create mode 100755 vendor/symfony/translation/Exception/NotFoundResourceException.php create mode 100755 vendor/symfony/translation/Extractor/AbstractFileExtractor.php create mode 100755 vendor/symfony/translation/Extractor/ChainExtractor.php create mode 100755 vendor/symfony/translation/Extractor/ExtractorInterface.php create mode 100755 vendor/symfony/translation/IdentityTranslator.php create mode 100755 vendor/symfony/translation/Interval.php create mode 100755 vendor/symfony/translation/LICENSE create mode 100755 vendor/symfony/translation/Loader/ArrayLoader.php create mode 100755 vendor/symfony/translation/Loader/CsvFileLoader.php create mode 100755 vendor/symfony/translation/Loader/IcuDatFileLoader.php create mode 100755 vendor/symfony/translation/Loader/IcuResFileLoader.php create mode 100755 vendor/symfony/translation/Loader/IniFileLoader.php create mode 100755 vendor/symfony/translation/Loader/JsonFileLoader.php create mode 100755 vendor/symfony/translation/Loader/LoaderInterface.php create mode 100755 vendor/symfony/translation/Loader/MoFileLoader.php create mode 100755 vendor/symfony/translation/Loader/PhpFileLoader.php create mode 100755 vendor/symfony/translation/Loader/PoFileLoader.php create mode 100755 vendor/symfony/translation/Loader/QtFileLoader.php create mode 100755 vendor/symfony/translation/Loader/XliffFileLoader.php create mode 100755 vendor/symfony/translation/Loader/YamlFileLoader.php create mode 100755 vendor/symfony/translation/Loader/schema/dic/xliff-core/xliff-core-1.2-strict.xsd create mode 100755 vendor/symfony/translation/Loader/schema/dic/xliff-core/xml.xsd create mode 100755 vendor/symfony/translation/LoggingTranslator.php create mode 100755 vendor/symfony/translation/MessageCatalogue.php create mode 100755 vendor/symfony/translation/MessageCatalogueInterface.php create mode 100755 vendor/symfony/translation/MessageSelector.php create mode 100755 vendor/symfony/translation/MetadataAwareInterface.php create mode 100755 vendor/symfony/translation/PluralizationRules.php create mode 100755 vendor/symfony/translation/README.md create mode 100755 vendor/symfony/translation/Tests/Catalogue/AbstractOperationTest.php create mode 100755 vendor/symfony/translation/Tests/Catalogue/DiffOperationTest.php create mode 100755 vendor/symfony/translation/Tests/Catalogue/MergeOperationTest.php create mode 100755 vendor/symfony/translation/Tests/DataCollector/TranslationDataCollectorTest.php create mode 100755 vendor/symfony/translation/Tests/DataCollectorTranslatorTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/CsvFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/FileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/IcuResFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/IniFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/JsonFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/MoFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/PhpFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/PoFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/QtFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/XliffFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/Dumper/YamlFileDumperTest.php create mode 100755 vendor/symfony/translation/Tests/IdentityTranslatorTest.php create mode 100755 vendor/symfony/translation/Tests/IntervalTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/CsvFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/IcuDatFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/IcuResFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/IniFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/JsonFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/LocalizedTestCase.php create mode 100755 vendor/symfony/translation/Tests/Loader/MoFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/PhpFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/PoFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/QtFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/XliffFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/Loader/YamlFileLoaderTest.php create mode 100755 vendor/symfony/translation/Tests/LoggingTranslatorTest.php create mode 100755 vendor/symfony/translation/Tests/MessageCatalogueTest.php create mode 100755 vendor/symfony/translation/Tests/MessageSelectorTest.php create mode 100755 vendor/symfony/translation/Tests/PluralizationRulesTest.php create mode 100755 vendor/symfony/translation/Tests/TranslatorCacheTest.php create mode 100755 vendor/symfony/translation/Tests/TranslatorTest.php create mode 100755 vendor/symfony/translation/Tests/fixtures/empty-translation.mo create mode 100755 vendor/symfony/translation/Tests/fixtures/empty-translation.po create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.csv create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.ini create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.json create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.mo create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.po create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/empty.yml create mode 100755 vendor/symfony/translation/Tests/fixtures/encoding.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/escaped-id-plurals.po create mode 100755 vendor/symfony/translation/Tests/fixtures/escaped-id.po create mode 100755 vendor/symfony/translation/Tests/fixtures/invalid-xml-resources.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/malformed.json create mode 100755 vendor/symfony/translation/Tests/fixtures/non-valid.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/non-valid.yml create mode 100755 vendor/symfony/translation/Tests/fixtures/plurals.mo create mode 100755 vendor/symfony/translation/Tests/fixtures/plurals.po create mode 100755 vendor/symfony/translation/Tests/fixtures/resname.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/corrupted/resources.dat create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.res create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.txt create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.res create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.txt create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/packagelist.txt create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/resources.dat create mode 100755 vendor/symfony/translation/Tests/fixtures/resourcebundle/res/en.res create mode 100755 vendor/symfony/translation/Tests/fixtures/resources-clean.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.csv create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.ini create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.json create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.mo create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.php create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.po create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.ts create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/resources.yml create mode 100755 vendor/symfony/translation/Tests/fixtures/valid.csv create mode 100755 vendor/symfony/translation/Tests/fixtures/withdoctype.xlf create mode 100755 vendor/symfony/translation/Tests/fixtures/withnote.xlf create mode 100755 vendor/symfony/translation/Translator.php create mode 100755 vendor/symfony/translation/TranslatorBagInterface.php create mode 100755 vendor/symfony/translation/TranslatorInterface.php create mode 100755 vendor/symfony/translation/Writer/TranslationWriter.php create mode 100755 vendor/symfony/translation/composer.json create mode 100755 vendor/symfony/translation/phpunit.xml.dist create mode 100755 vendor/twig/twig/CHANGELOG create mode 100755 vendor/twig/twig/LICENSE create mode 100755 vendor/twig/twig/README.rst create mode 100755 vendor/twig/twig/composer.json create mode 100755 vendor/twig/twig/doc/advanced.rst create mode 100755 vendor/twig/twig/doc/advanced_legacy.rst create mode 100755 vendor/twig/twig/doc/api.rst create mode 100755 vendor/twig/twig/doc/coding_standards.rst create mode 100755 vendor/twig/twig/doc/deprecated.rst create mode 100755 vendor/twig/twig/doc/filters/abs.rst create mode 100755 vendor/twig/twig/doc/filters/batch.rst create mode 100755 vendor/twig/twig/doc/filters/capitalize.rst create mode 100755 vendor/twig/twig/doc/filters/convert_encoding.rst create mode 100755 vendor/twig/twig/doc/filters/date.rst create mode 100755 vendor/twig/twig/doc/filters/date_modify.rst create mode 100755 vendor/twig/twig/doc/filters/default.rst create mode 100755 vendor/twig/twig/doc/filters/escape.rst create mode 100755 vendor/twig/twig/doc/filters/first.rst create mode 100755 vendor/twig/twig/doc/filters/format.rst create mode 100755 vendor/twig/twig/doc/filters/index.rst create mode 100755 vendor/twig/twig/doc/filters/join.rst create mode 100755 vendor/twig/twig/doc/filters/json_encode.rst create mode 100755 vendor/twig/twig/doc/filters/keys.rst create mode 100755 vendor/twig/twig/doc/filters/last.rst create mode 100755 vendor/twig/twig/doc/filters/length.rst create mode 100755 vendor/twig/twig/doc/filters/lower.rst create mode 100755 vendor/twig/twig/doc/filters/merge.rst create mode 100755 vendor/twig/twig/doc/filters/nl2br.rst create mode 100755 vendor/twig/twig/doc/filters/number_format.rst create mode 100755 vendor/twig/twig/doc/filters/raw.rst create mode 100755 vendor/twig/twig/doc/filters/replace.rst create mode 100755 vendor/twig/twig/doc/filters/reverse.rst create mode 100755 vendor/twig/twig/doc/filters/round.rst create mode 100755 vendor/twig/twig/doc/filters/slice.rst create mode 100755 vendor/twig/twig/doc/filters/sort.rst create mode 100755 vendor/twig/twig/doc/filters/split.rst create mode 100755 vendor/twig/twig/doc/filters/striptags.rst create mode 100755 vendor/twig/twig/doc/filters/title.rst create mode 100755 vendor/twig/twig/doc/filters/trim.rst create mode 100755 vendor/twig/twig/doc/filters/upper.rst create mode 100755 vendor/twig/twig/doc/filters/url_encode.rst create mode 100755 vendor/twig/twig/doc/functions/attribute.rst create mode 100755 vendor/twig/twig/doc/functions/block.rst create mode 100755 vendor/twig/twig/doc/functions/constant.rst create mode 100755 vendor/twig/twig/doc/functions/cycle.rst create mode 100755 vendor/twig/twig/doc/functions/date.rst create mode 100755 vendor/twig/twig/doc/functions/dump.rst create mode 100755 vendor/twig/twig/doc/functions/include.rst create mode 100755 vendor/twig/twig/doc/functions/index.rst create mode 100755 vendor/twig/twig/doc/functions/max.rst create mode 100755 vendor/twig/twig/doc/functions/min.rst create mode 100755 vendor/twig/twig/doc/functions/parent.rst create mode 100755 vendor/twig/twig/doc/functions/random.rst create mode 100755 vendor/twig/twig/doc/functions/range.rst create mode 100755 vendor/twig/twig/doc/functions/source.rst create mode 100755 vendor/twig/twig/doc/functions/template_from_string.rst create mode 100755 vendor/twig/twig/doc/index.rst create mode 100755 vendor/twig/twig/doc/installation.rst create mode 100755 vendor/twig/twig/doc/internals.rst create mode 100755 vendor/twig/twig/doc/intro.rst create mode 100755 vendor/twig/twig/doc/recipes.rst create mode 100755 vendor/twig/twig/doc/tags/autoescape.rst create mode 100755 vendor/twig/twig/doc/tags/block.rst create mode 100755 vendor/twig/twig/doc/tags/do.rst create mode 100755 vendor/twig/twig/doc/tags/embed.rst create mode 100755 vendor/twig/twig/doc/tags/extends.rst create mode 100755 vendor/twig/twig/doc/tags/filter.rst create mode 100755 vendor/twig/twig/doc/tags/flush.rst create mode 100755 vendor/twig/twig/doc/tags/for.rst create mode 100755 vendor/twig/twig/doc/tags/from.rst create mode 100755 vendor/twig/twig/doc/tags/if.rst create mode 100755 vendor/twig/twig/doc/tags/import.rst create mode 100755 vendor/twig/twig/doc/tags/include.rst create mode 100755 vendor/twig/twig/doc/tags/index.rst create mode 100755 vendor/twig/twig/doc/tags/macro.rst create mode 100755 vendor/twig/twig/doc/tags/sandbox.rst create mode 100755 vendor/twig/twig/doc/tags/set.rst create mode 100755 vendor/twig/twig/doc/tags/spaceless.rst create mode 100755 vendor/twig/twig/doc/tags/use.rst create mode 100755 vendor/twig/twig/doc/tags/verbatim.rst create mode 100755 vendor/twig/twig/doc/templates.rst create mode 100755 vendor/twig/twig/doc/tests/constant.rst create mode 100755 vendor/twig/twig/doc/tests/defined.rst create mode 100755 vendor/twig/twig/doc/tests/divisibleby.rst create mode 100755 vendor/twig/twig/doc/tests/empty.rst create mode 100755 vendor/twig/twig/doc/tests/even.rst create mode 100755 vendor/twig/twig/doc/tests/index.rst create mode 100755 vendor/twig/twig/doc/tests/iterable.rst create mode 100755 vendor/twig/twig/doc/tests/null.rst create mode 100755 vendor/twig/twig/doc/tests/odd.rst create mode 100755 vendor/twig/twig/doc/tests/sameas.rst create mode 100755 vendor/twig/twig/ext/twig/config.m4 create mode 100755 vendor/twig/twig/ext/twig/config.w32 create mode 100755 vendor/twig/twig/ext/twig/php_twig.h create mode 100755 vendor/twig/twig/ext/twig/twig.c create mode 100755 vendor/twig/twig/lib/Twig/Autoloader.php create mode 100755 vendor/twig/twig/lib/Twig/Compiler.php create mode 100755 vendor/twig/twig/lib/Twig/CompilerInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Environment.php create mode 100755 vendor/twig/twig/lib/Twig/Error.php create mode 100755 vendor/twig/twig/lib/Twig/Error/Loader.php create mode 100755 vendor/twig/twig/lib/Twig/Error/Runtime.php create mode 100755 vendor/twig/twig/lib/Twig/Error/Syntax.php create mode 100755 vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php create mode 100755 vendor/twig/twig/lib/Twig/ExpressionParser.php create mode 100755 vendor/twig/twig/lib/Twig/Extension.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Core.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Debug.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Escaper.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Optimizer.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Profiler.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Sandbox.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/Staging.php create mode 100755 vendor/twig/twig/lib/Twig/Extension/StringLoader.php create mode 100755 vendor/twig/twig/lib/Twig/ExtensionInterface.php create mode 100755 vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php create mode 100755 vendor/twig/twig/lib/Twig/Filter.php create mode 100755 vendor/twig/twig/lib/Twig/Filter/Function.php create mode 100755 vendor/twig/twig/lib/Twig/Filter/Method.php create mode 100755 vendor/twig/twig/lib/Twig/Filter/Node.php create mode 100755 vendor/twig/twig/lib/Twig/FilterCallableInterface.php create mode 100755 vendor/twig/twig/lib/Twig/FilterInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Function.php create mode 100755 vendor/twig/twig/lib/Twig/Function/Function.php create mode 100755 vendor/twig/twig/lib/Twig/Function/Method.php create mode 100755 vendor/twig/twig/lib/Twig/Function/Node.php create mode 100755 vendor/twig/twig/lib/Twig/FunctionCallableInterface.php create mode 100755 vendor/twig/twig/lib/Twig/FunctionInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Lexer.php create mode 100755 vendor/twig/twig/lib/Twig/LexerInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Loader/Array.php create mode 100755 vendor/twig/twig/lib/Twig/Loader/Chain.php create mode 100755 vendor/twig/twig/lib/Twig/Loader/Filesystem.php create mode 100755 vendor/twig/twig/lib/Twig/Loader/String.php create mode 100755 vendor/twig/twig/lib/Twig/LoaderInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Markup.php create mode 100755 vendor/twig/twig/lib/Twig/Node.php create mode 100755 vendor/twig/twig/lib/Twig/Node/AutoEscape.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Block.php create mode 100755 vendor/twig/twig/lib/Twig/Node/BlockReference.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Body.php create mode 100755 vendor/twig/twig/lib/Twig/Node/CheckSecurity.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Do.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Embed.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Array.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Add.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/And.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Concat.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Div.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Equal.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Greater.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Less.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/LessEqual.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Matches.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mod.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mul.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotEqual.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Or.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Binary/Sub.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Call.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Conditional.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Constant.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Filter.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Function.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/MethodCall.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Name.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Parent.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/TempName.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Constant.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Even.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Null.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Odd.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Test/Sameas.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Unary.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Unary/Neg.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Unary/Not.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Expression/Unary/Pos.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Flush.php create mode 100755 vendor/twig/twig/lib/Twig/Node/For.php create mode 100755 vendor/twig/twig/lib/Twig/Node/ForLoop.php create mode 100755 vendor/twig/twig/lib/Twig/Node/If.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Import.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Include.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Macro.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Module.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Print.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Sandbox.php create mode 100755 vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Set.php create mode 100755 vendor/twig/twig/lib/Twig/Node/SetTemp.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Spaceless.php create mode 100755 vendor/twig/twig/lib/Twig/Node/Text.php create mode 100755 vendor/twig/twig/lib/Twig/NodeInterface.php create mode 100755 vendor/twig/twig/lib/Twig/NodeOutputInterface.php create mode 100755 vendor/twig/twig/lib/Twig/NodeTraverser.php create mode 100755 vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php create mode 100755 vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php create mode 100755 vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php create mode 100755 vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php create mode 100755 vendor/twig/twig/lib/Twig/NodeVisitorInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Parser.php create mode 100755 vendor/twig/twig/lib/Twig/ParserInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/Dumper/Blackfire.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/Dumper/Html.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/Dumper/Text.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/Node/EnterProfile.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/Node/LeaveProfile.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php create mode 100755 vendor/twig/twig/lib/Twig/Profiler/Profile.php create mode 100755 vendor/twig/twig/lib/Twig/Sandbox/SecurityError.php create mode 100755 vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php create mode 100755 vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php create mode 100755 vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php create mode 100755 vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php create mode 100755 vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicyInterface.php create mode 100755 vendor/twig/twig/lib/Twig/SimpleFilter.php create mode 100755 vendor/twig/twig/lib/Twig/SimpleFunction.php create mode 100755 vendor/twig/twig/lib/Twig/SimpleTest.php create mode 100755 vendor/twig/twig/lib/Twig/Template.php create mode 100755 vendor/twig/twig/lib/Twig/TemplateInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Test.php create mode 100755 vendor/twig/twig/lib/Twig/Test/Function.php create mode 100755 vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php create mode 100755 vendor/twig/twig/lib/Twig/Test/Method.php create mode 100755 vendor/twig/twig/lib/Twig/Test/Node.php create mode 100755 vendor/twig/twig/lib/Twig/Test/NodeTestCase.php create mode 100755 vendor/twig/twig/lib/Twig/TestCallableInterface.php create mode 100755 vendor/twig/twig/lib/Twig/TestInterface.php create mode 100755 vendor/twig/twig/lib/Twig/Token.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Block.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Do.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Embed.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Extends.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Filter.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Flush.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/For.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/From.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/If.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Import.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Include.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Macro.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Set.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParser/Use.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParserBroker.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php create mode 100755 vendor/twig/twig/lib/Twig/TokenParserInterface.php create mode 100755 vendor/twig/twig/lib/Twig/TokenStream.php create mode 100755 vendor/twig/twig/phpunit.xml.dist create mode 100755 vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/CompilerTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/ErrorTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/ExpressionParserTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/FileCachingTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/autoescape/filename.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/errors/base.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/errors/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_unknown_argument.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_parent.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array_call.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/binary.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/comparison.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/dotdot.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/grouping.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/literals.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/magic_call.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/matches.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/method_call.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/negative_numbers.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/operators_as_variables.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/postfix.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/strings.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_noelse.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_nothen.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/two_word_operators_as_variables.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_macro_arguments.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_precedence.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/abs.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_empty_fill.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_exact_elements.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_fill.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/convert_encoding.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_modify.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_namedargs.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/dynamic_filter.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_html_attr.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_non_supported_charset.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/force_escape.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/format.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/join.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/json_encode.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length_utf8.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/nl2br.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format_default.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reverse.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/round.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/special_chars.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/trim.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/block.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/constant.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/cycle.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date_namedargs.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump_array.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dynamic_function.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/assignment.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/autoescaping.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/expression.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing_nested.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/template_instance.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/templates_as_array.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_context.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_variables.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/max.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/min.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/range.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/source.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/special_chars.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/macros/default_values.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/macros/nested_calls.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/macros/reserved_variables.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/macros/simple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/macros/with_filters.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/regression/empty_token.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/regression/issue_1143.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/functions.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/literal.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/nested.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/objects.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/raw.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/type.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/block_unique_name.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/special_chars.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/error_line.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/multiple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/nested.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/with_extends.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/json_encode.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/multiple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/nested.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_for_tag.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_if_tag.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/condition.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/context.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/else.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/inner_variables.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys_and_values.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context_local.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined_cond.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/nested_else.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/recursive.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/values.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/from.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/expression.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/expression.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing_nested.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/only.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/template_instance.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/templates_as_array.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/with_variables.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/conditional.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/dynamic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/empty.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_empty_name.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_null_name.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple_dynamic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks_parent_only.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_inheritance.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_change.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_in_a_block.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_nested.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends_but_traits.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/use.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/external.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/global.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/self_import.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/special_chars.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid1.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid2.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/simple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture-empty.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/expression.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/spaceless/simple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/special_chars.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/trim_block.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/aliases.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep_empty.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple_aliases.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/basic.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/array.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/constant.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/empty.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/even.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in_with_objects.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/iterable.test create mode 100755 vendor/twig/twig/test/Twig/Tests/Fixtures/tests/odd.test create mode 100755 vendor/twig/twig/test/Twig/Tests/IntegrationTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/LexerTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_empty_parent.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_nonexistent_parent.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_null_parent.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_valid_parent.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/parent.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/spare_parent.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_bis/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_final/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_ter/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_bis/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_final/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_ter/index.html create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig create mode 100755 vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/AutoEscapeTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/BlockReferenceTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/BlockTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/DoTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/ArrayTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/AssignNameTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AddTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AndTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/DivTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ModTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/MulTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/OrTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/SubTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/ConditionalTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/ConstantTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/ParentTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NegTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NotTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/PosTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/ForTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/IfTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/ImportTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/PrintTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/SandboxTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/SandboxedPrintTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/SetTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/SpacelessTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Node/TextTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/ParserTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/AbstractTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/HtmlTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/TextTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/Profiler/ProfileTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/TemplateTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/TokenStreamTest.php create mode 100755 vendor/twig/twig/test/Twig/Tests/escapingTest.php create mode 100755 vendor/twig/twig/test/bootstrap.php diff --git a/vendor/alexgarrett/violin/README.md b/vendor/alexgarrett/violin/README.md new file mode 100755 index 0000000..6291020 --- /dev/null +++ b/vendor/alexgarrett/violin/README.md @@ -0,0 +1,262 @@ +# violin + +[![Build Status](https://travis-ci.org/alexgarrett/violin.svg?branch=master)](https://travis-ci.org/alexgarrett/violin) + +Violin is an easy to use, highly customisable PHP validator. + +**Note: This package is under heavy development and is not recommended for production.** + +## Installing + +Install using Composer. + +```json +{ + "require": { + "alexgarrett/violin": "2.*" + } +} +``` + +## Basic usage + +```php +use Violin\Violin; + +$v = new Violin; + +$v->validate([ + 'name' => ['billy', 'required'], + 'age' => [20, 'required|int'] +]); + +if($v->passes()) { + echo 'Validation passed, woo!'; +} else { + echo '
', var_dump($v->errors()->all()), '
'; +} +``` + +## Adding custom rules + +Adding custom rules is simple. If the closure returns false, the rule fails. + +```php +$v->addRuleMessage('isbanana', 'The {field} field expects "banana", found "{value}" instead.'); + +$v->addRule('isbanana', function($value, $input, $args) { + return $value === 'banana'; +}); + +$v->validate([ + 'fruit' => ['apple', 'isbanana'] +]); +``` + +## Adding custom error messages + +You can add rule messages, or field messages for total flexibility. + +### Adding a rule message + +```php +$v->addRuleMessage('required', 'You better fill in the {field} field, or else.'); +``` + +### Adding rule messages in bulk + +```php +$v->addRuleMessages([ + 'required' => 'You better fill in the {field} field, or else.', + 'int' => 'The {field} needs to be an integer, but I found {value}.', +]); +``` + +### Adding a field message + +Any field messages you add are used before any default or custom rule messages. + +```php +$v->addFieldMessage('username', 'required', 'You need to enter a username to sign up.'); +``` + +### Adding field messages in bulk + +```php +$v->addFieldMessages([ + 'username' => [ + 'required' => 'You need to enter a username to sign up.' + ], + 'age' => [ + 'required' => 'I need your age.', + 'int' => 'Your age needs to be an integer.', + ] +]); +``` + +### Using Field Aliases + +Field Aliases helps you format any error messages without showing weird form names or the need to create a custom error. + +```php +$v->validate([ + 'username_box|Username' => ['' => 'required'] +]); + +// Error output: "Username is required." +``` +### Extending Violin + +You can extend the Violin class to add custom rules, rule messages and field messages. This way, you can keep a tidy class to handle custom validation if you have any dependencies, like a database connection or language files. + +```php +class MyValidator extends Violin +{ + protected $db; + + public function __construct(PDO $db) + { + $this->db = $db; + + // Add rule message for custom rule method. + $this->addRuleMessage('uniqueUsername', 'That username is taken.'); + } + + // Custom rule method for checking a unique username in our database. + // Just prepend custom rules with validate_ + public function validate_uniqueUsername($value, $input, $args) + { + $user = $this->db->prepare(" + SELECT count(*) as count + FROM users + WHERE username = :username + "); + + $user->execute(['username' => $value]); + + if($user->fetchObject()->count) { + return false; // Username exists, so return false. + } + + return true; + } +} + +// A database connection. +$db = new PDO('mysql:host=127.0.0.1;dbname=website', 'root', 'root'); + +// Instantiate your custom class with dependencies. +$v = new MyValidator($db); + +$v->validate([ + 'username' => ['billy', 'required|uniqueUsername'] +]); +``` + +## Rules + +This list of rules are **in progress**. Of course, you can always contribute to the project if you'd like to add more to the base ruleset. + +#### alnum + +If the value is alphanumeric. + +#### alnumDash + +If the value is alphanumeric. Dashes and underscores are permitted. + +#### alpha + +If the value is alphabetic letters only. + +#### alphaDash + +If the value is alphabetic letters only. Dashes and underscores are permitted. + +#### array + +If the value is an array. + +#### between(int, int) + +Checks if the value is within the intervals defined. This check is inclusive, so 5 is between 5 and 10. + +#### bool + +If the value is a boolean. + +#### email + +If the value is a valid email. + +#### int + +If the value is an integer, including numbers within strings. 1 and '1' are both classed as integers. + +#### number + +If the value is a number, including numbers within strings. + +> Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal (e.g. 0xf4c3b00c), Binary (e.g. 0b10100111001), Octal (e.g. 0777) notation is allowed too but only without sign, decimal and exponential part. + +#### ip + +If the value is a valid IP address. + +#### min(int, [number]) + +Check if string length is greater than or equal to given `int`. To check the size of a number, pass the optional `number` option. + +```php +$v->validate([ + 'username' => ['billy', 'required|min(3)|max(20)'], + 'age' => ['20', 'required|min(18, number)|max(100, number)'] +]); +``` + +#### max(int, [number]) + +Check if string length is less than or equal to given `int`. To check the size of a number, pass the optional `number` option. + +#### required + +If the value is present. + +#### url + +If the value is formatted as a valid URL. + +#### matches(field) + +Checks if one given input matches the other. For example, checking if *password* matches *password_confirm*. + +#### date + +If the given input is a valid date. + +You can validate human readable dates like '25th October 1961' and instances of `DateTime`. For example: + +```php +$twoDaysAgo = new DateTime('2 days ago'); +$date = $twoDaysAgo->format('d M Y'); + +$v->validate([ + 'date' => [$date, 'required|date'] +]); +``` + +#### checked + +If a field has been 'checked' or not, meaning it contains one of the following values: *'yes'*, *'on'*, *'1'*, *1*, *true*, or *'true'*. This can be used for determining if an HTML checkbox has been checked. + +#### regex(expression) + +If the given input has a match for the regular expression given. + +## Contributing + +Please file issues under GitHub, or submit a pull request if you'd like to directly contribute. + +### Running tests + +Tests are run with phpunit. Run `./vendor/bin/phpunit` to run tests. diff --git a/vendor/alexgarrett/violin/composer.json b/vendor/alexgarrett/violin/composer.json new file mode 100755 index 0000000..edb6e07 --- /dev/null +++ b/vendor/alexgarrett/violin/composer.json @@ -0,0 +1,27 @@ +{ + "name": "alexgarrett/violin", + "type": "library", + "description": "Violin is an easy to use, highly customisable PHP validator.", + "keywords": ["validation"], + "homepage": "https://github.com/alexgarrett/violin", + "license": "MIT", + "authors": [ + { + "name": "Alex Garrett", + "email": "alex@codecourse.com", + "homepage": "http://itsmealex.com" + } + ], + "require": { + "php": ">=5.4" + }, + "require-dev": { + "squizlabs/php_codesniffer": "2.1.*", + "phpunit/phpunit": "~4.5" + }, + "autoload": { + "psr-4": { + "Violin\\": "src/" + } + } +} diff --git a/vendor/alexgarrett/violin/examples/advanced/extending.php b/vendor/alexgarrett/violin/examples/advanced/extending.php new file mode 100755 index 0000000..f983a3b --- /dev/null +++ b/vendor/alexgarrett/violin/examples/advanced/extending.php @@ -0,0 +1,77 @@ +db = $db; + + $this->addRuleMessage('unique', 'That {field} is already taken.'); + } + + /** + * Check if a value already exists in a database table. + * + * @param mixed $value + * @param array $input + * @param array $args + * + * @return bool + */ + public function validate_unique($value, $input, $args) + { + $table = $args[0]; + $column = $args[1]; + $value = trim($value); + + $exists = $this->db->prepare(" + SELECT count(*) as count + FROM {$table} + WHERE {$column} = :value + "); + + $exists->execute([ + 'value' => $value + ]); + + return ! (bool) $exists->fetchObject()->count; + } +} + +//-- Any other file + +// Some database dependency +$db = new PDO('mysql:dbname=project;host=localhost', 'root', 'root'); + +$v = new Validator($db); + +$v->validate([ + 'username' => ['alex', 'required|alpha|min(3)|max(20)|unique(users, username)'], + 'email' => ['alex@codecourse.com', 'required|email|unique(users, email)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/basic.php b/vendor/alexgarrett/violin/examples/basic.php new file mode 100755 index 0000000..28703ed --- /dev/null +++ b/vendor/alexgarrett/violin/examples/basic.php @@ -0,0 +1,28 @@ +validate([ + 'username' => ['dale', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale@codecourse.com', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_confirm' => ['ilovecats', 'required|matches(password)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/basic_two_array.php b/vendor/alexgarrett/violin/examples/basic_two_array.php new file mode 100755 index 0000000..a1ccd8a --- /dev/null +++ b/vendor/alexgarrett/violin/examples/basic_two_array.php @@ -0,0 +1,37 @@ + 'dale', + 'email' => 'dale@codecourse.com', + 'password' => 'ilovecats', + 'password_confirm' => 'ilovecats' +]; + +$rules = [ + 'username' => 'required|alpha|min(3)|max(20)', + 'email' => 'required|email', + 'password' => 'required', + 'password_confirm' => 'required|matches(password)' +]; + +$v->validate($data, $rules); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/errors/errors_all.php b/vendor/alexgarrett/violin/examples/errors/errors_all.php new file mode 100755 index 0000000..c850331 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/errors/errors_all.php @@ -0,0 +1,21 @@ +validate([ + 'username' => ['dalegarrett1234567890', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale.codecourse.com', 'required|email'] +]); + +var_dump($v->errors()->all()); // Array of all errors. diff --git a/vendor/alexgarrett/violin/examples/errors/errors_field.php b/vendor/alexgarrett/violin/examples/errors/errors_field.php new file mode 100755 index 0000000..c882fd9 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/errors/errors_field.php @@ -0,0 +1,22 @@ +validate([ + 'username' => ['dalegarrett1234567890', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale.codecourse.com', 'required|email'] +]); + +var_dump($v->errors()->get('username')); // Array of all 'username' errors. diff --git a/vendor/alexgarrett/violin/examples/errors/errors_first.php b/vendor/alexgarrett/violin/examples/errors/errors_first.php new file mode 100755 index 0000000..2d50bc6 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/errors/errors_first.php @@ -0,0 +1,25 @@ +validate([ + 'username' => ['dalegarrett1234567890', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale.codecourse.com', 'required|email'] +]); + +if ($v->errors()->has('email')) { // Check if any errors exist for 'email'. + echo $v->errors()->first('email'); // First 'email' error (string). +} diff --git a/vendor/alexgarrett/violin/examples/messages/custom_field_message.php b/vendor/alexgarrett/violin/examples/messages/custom_field_message.php new file mode 100755 index 0000000..e120dfe --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/custom_field_message.php @@ -0,0 +1,29 @@ +addFieldMessage('username', 'required', 'We need a username to sign you up.'); + +$v->validate([ + 'username' => ['', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale@codecourse.com', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_confirm' => ['ilovecats', 'required|matches(password)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/messages/custom_field_messages.php b/vendor/alexgarrett/violin/examples/messages/custom_field_messages.php new file mode 100755 index 0000000..45be55a --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/custom_field_messages.php @@ -0,0 +1,40 @@ +addFieldMessages([ + 'username' => [ + 'required' => 'We need a username to sign you up.', + 'alpha' => 'Your username can only contain letters.' + ], + 'email' => [ + 'email' => 'That email doesn\'t look valid.' + ] +]); + +$v->validate([ + 'username' => ['cats4life', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale.codecourse.com', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_confirm' => ['ilovecats', 'required|matches(password)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/messages/custom_rule_message.php b/vendor/alexgarrett/violin/examples/messages/custom_rule_message.php new file mode 100755 index 0000000..451a476 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/custom_rule_message.php @@ -0,0 +1,28 @@ +addRuleMessage('required', 'Hold up, the {field} field is required!'); + +$v->validate([ + 'username' => ['', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale@codecourse.com', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_confirm' => ['ilovecats', 'required|matches(password)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/messages/custom_rule_messages.php b/vendor/alexgarrett/violin/examples/messages/custom_rule_messages.php new file mode 100755 index 0000000..6729187 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/custom_rule_messages.php @@ -0,0 +1,34 @@ +addRuleMessages([ + 'required' => 'Hold up, the {field} field is required!', + 'email' => 'That doesn\'t look like a valid email address to me.' +]); + +$v->validate([ + 'username' => ['', 'required|alpha|min(3)|max(20)'], + 'email' => ['dale.codecourse.com', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_confirm' => ['ilovecats', 'required|matches(password)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/messages/field_aliases.php b/vendor/alexgarrett/violin/examples/messages/field_aliases.php new file mode 100755 index 0000000..75e4e4a --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/field_aliases.php @@ -0,0 +1,26 @@ +validate([ + 'username|Username' => ['', 'required'], + 'password|Password' => ['', 'required'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders.php b/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders.php new file mode 100755 index 0000000..249ba43 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders.php @@ -0,0 +1,27 @@ +addRuleMessage('between', 'The {field} must be between {$0} and {$1}, you gave {value}'); + +$v->validate([ + 'age' => ['82', 'required|between(18, 35)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders_all.php b/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders_all.php new file mode 100755 index 0000000..34e2036 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders_all.php @@ -0,0 +1,31 @@ +addRuleMessage('isoneof', '{field} must be one of {$*}'); + +$v->addRule('isoneof', function($value, $input, $args) { + $value = trim($value); + return in_array($value, $args); +}); + +$v->validate([ + 'age' => ['sheep', 'required|isoneof(apples, pears)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/rules/custom_rule.php b/vendor/alexgarrett/violin/examples/rules/custom_rule.php new file mode 100755 index 0000000..512ba08 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/rules/custom_rule.php @@ -0,0 +1,32 @@ +addRuleMessage('startsWithNumber', 'The {field} must start with a number.'); + +$v->addRule('startsWithNumber', function($value, $input, $args) { + $value = trim($value); + return is_numeric($value[0]); +}); + +$v->validate([ + 'username' => ['dale', 'required|min(3)|max(20)|startsWithNumber'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/examples/rules/custom_rule_arguments.php b/vendor/alexgarrett/violin/examples/rules/custom_rule_arguments.php new file mode 100755 index 0000000..d19c8c9 --- /dev/null +++ b/vendor/alexgarrett/violin/examples/rules/custom_rule_arguments.php @@ -0,0 +1,35 @@ +addRuleMessage('startsWith', 'The {field} must start with "{$0}".'); + +$v->addRule('startsWith', function($value, $input, $args) { + $value = trim($value); + return $value[0] === $args[0]; +}); + +$v->validate([ + 'username' => ['dale', 'required|min(3)|max(20)|startsWith(a)'] +]); + +if ($v->passes()) { + // Passed +} else { + var_dump($v->errors()->all()); +} diff --git a/vendor/alexgarrett/violin/phpunit.xml b/vendor/alexgarrett/violin/phpunit.xml new file mode 100755 index 0000000..28ad02e --- /dev/null +++ b/vendor/alexgarrett/violin/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + diff --git a/vendor/alexgarrett/violin/src/Contracts/MessageBagContract.php b/vendor/alexgarrett/violin/src/Contracts/MessageBagContract.php new file mode 100755 index 0000000..9585af6 --- /dev/null +++ b/vendor/alexgarrett/violin/src/Contracts/MessageBagContract.php @@ -0,0 +1,12 @@ += $args[0] && $value <= $args[1]) ? true : false; + } + + public function error() + { + return '{field} must be between {$0} and {$1}.'; + } + + public function canSkip() + { + return true; + } +} diff --git a/vendor/alexgarrett/violin/src/Rules/BoolRule.php b/vendor/alexgarrett/violin/src/Rules/BoolRule.php new file mode 100755 index 0000000..6933633 --- /dev/null +++ b/vendor/alexgarrett/violin/src/Rules/BoolRule.php @@ -0,0 +1,23 @@ += (float) $args[0]; + } + + return mb_strlen($value) >= (int) $args[0]; + } + + public function error() + { + return '{field} must be a minimum of {$0}.'; + } + + public function canSkip() + { + return true; + } +} diff --git a/vendor/alexgarrett/violin/src/Rules/NumberRule.php b/vendor/alexgarrett/violin/src/Rules/NumberRule.php new file mode 100755 index 0000000..65d5363 --- /dev/null +++ b/vendor/alexgarrett/violin/src/Rules/NumberRule.php @@ -0,0 +1,23 @@ + $value) { + $this->messages[$key] = (array) $value; + } + } + + /** + * Checks if the bag has messages for a given key. + * + * @param string $key + * @return boolean + */ + public function has($key) + { + return ! is_null($this->first($key)); + } + + /** + * Get the first message with a given key. + * If the given key doesn't exist, it returns the first + * message of the bag. + * Returns null if the bag is empty. + * + * @param string $key + * @return string|null + */ + public function first($key = null) + { + $messages = is_null($key) ? $this->all() : $this->get($key); + return (count($messages) > 0) ? $messages[0] : null; + } + + /** + * Get all of the messages from a given key. + * Returns null if the given key is empty, or + * if it doesn't exist. + * + * @param string $key + * @return array|null + */ + public function get($key) + { + if (array_key_exists($key, $this->messages)) { + return !empty($this->messages[$key]) ? $this->messages[$key] : null; + } + + return null; + } + + /** + * Get all of the messages in the bag. + * + * @return array + */ + public function all() + { + return iterator_to_array(new RecursiveIteratorIterator( + new RecursiveArrayIterator($this->messages) + ), false); + } + + /** + * Return all of the keys in the bag. + * + * @return array + */ + public function keys() + { + return array_keys($this->messages); + } +} diff --git a/vendor/alexgarrett/violin/src/Violin.php b/vendor/alexgarrett/violin/src/Violin.php new file mode 100755 index 0000000..1ea764b --- /dev/null +++ b/vendor/alexgarrett/violin/src/Violin.php @@ -0,0 +1,506 @@ +clearErrors(); + $this->clearFieldAliases(); + + $data = $this->extractFieldAliases($data); + + // If the rules array is empty, then it means we are + // receiving the rules directly with the input, so we need + // to extract the information. + if (empty($rules)) { + $rules = $this->extractRules($data); + $data = $this->extractInput($data); + } + + $this->input = $data; + + foreach ($data as $field => $value) { + $fieldRules = explode('|', $rules[$field]); + + foreach ($fieldRules as $rule) { + $this->validateAgainstRule( + $field, + $value, + $this->getRuleName($rule), + $this->getRuleArgs($rule) + ); + } + } + + return $this; + } + + /** + * Checks if validation has passed. + * + * @return bool + */ + public function passes() + { + return empty($this->errors); + } + + /** + * Checks if validation has failed. + * + * @return bool + */ + public function fails() + { + return ! $this->passes(); + } + + /** + * Gather errors, format them and return them. + * + * @return array + */ + public function errors() + { + $messages = []; + + foreach ($this->errors as $rule => $items) { + foreach ($items as $item) { + $field = $item['field']; + + $message = $this->fetchMessage($field, $rule); + + // If there is any alias for the current field, swap it. + if (isset($this->fieldAliases[$field])) { + $item['field'] = $this->fieldAliases[$field]; + } + + $messages[$field][] = $this->replaceMessageFormat($message, $item); + } + } + + return new MessageBag($messages); + } + + /** + * Adds a custom rule message. + * + * @param string $rule + * @param string $message + */ + public function addRuleMessage($rule, $message) + { + $this->ruleMessages[$rule] = $message; + } + + /** + * Adds custom rule messages. + * + * @param array $messages + */ + public function addRuleMessages(array $messages) + { + $this->ruleMessages = array_merge($this->ruleMessages, $messages); + } + + /** + * Adds a custom field message. + * + * @param string $field + * @param string $rule + * @param string $message + */ + public function addFieldMessage($field, $rule, $message) + { + $this->fieldMessages[$field][$rule] = $message; + } + + /** + * Adds custom field messages + * + * @param array $messages + */ + public function addFieldMessages(array $messages) + { + $this->fieldMessages = $messages; + } + + /** + * Add a custom rule + * + * @param string $name + * @param Closure $callback + */ + public function addRule($name, Closure $callback) + { + $this->customRules[$name] = $callback; + } + + /** + * Fetch the message for an error by field or rule type. + * + * @param string $field + * @param string $rule + * + * @return string + */ + protected function fetchMessage($field, $rule) + { + if (isset($this->fieldMessages[$field][$rule])) { + return $this->fieldMessages[$field][$rule]; + } + + if (isset($this->ruleMessages[$rule])) { + return $this->ruleMessages[$rule]; + } + + return $this->usedRules[$rule]->error(); + } + + /** + * Replaces message variables. + * + * @param string $message + * @param array $item + * + * @return string + */ + protected function replaceMessageFormat($message, array $item) + { + $keys = array_keys($item); + + if (!empty($item['args'])) { + $args = $item['args']; + + $argReplace = array_map(function($i) { + return "{\${$i}}"; + }, array_keys($args)); + + // Number of arguments + $args[] = count($item['args']); + $argReplace[] = '{$#}'; + + // All arguments + $args[] = implode(', ', $item['args']); + $argReplace[] = '{$*}'; + + // Replace arguments + $message = str_replace($argReplace, $args, $message); + } + + // Replace field and value + $message = str_replace( + ['{field}', '{value}'], + [$item['field'], $item['value']], + $message + ); + + return $message; + } + + /** + * Validates value against a specific rule and handles + * errors if the rule validation fails. + * + * @param string $field + * @param string $value + * @param string $rule + * @param array $args + * + * @return void + */ + protected function validateAgainstRule($field, $value, $rule, array $args) + { + $ruleToCall = $this->getRuleToCall($rule); + + if ($this->canSkipRule($ruleToCall, $value)) { + return; + } + + $passed = call_user_func_array($ruleToCall, [ + $value, + $this->input, + $args + ]); + + if (!$passed) { + $this->handleError($field, $value, $rule, $args); + } + } + + /** + * Method to help skip a rule if a value is empty, since we + * don't need to validate an empty value. If the rule to + * call specifically doesn't allowing skipping, then + * we don't want skip the rule. + * + * @param array $ruleToCall + * @param mixed $value + * + * @return null + */ + protected function canSkipRule($ruleToCall, $value) + { + return ( + (is_array($ruleToCall) && + method_exists($ruleToCall[0], 'canSkip') && + $ruleToCall[0]->canSkip()) && + empty($value) && + !is_array($value) + ); + } + + /** + * Clears all previously stored errors. + * + * @return void + */ + protected function clearErrors() + { + $this->errors = []; + } + + /** + * Stores an error. + * + * @param string $field + * @param string $value + * @param string $rule + * @param array $args + * + * @return void + */ + protected function handleError($field, $value, $rule, array $args) + { + $this->errors[$rule][] = [ + 'field' => $field, + 'value' => $value, + 'args' => $args, + ]; + } + + /** + * Gets and instantiates a rule object, e.g. IntRule. If it has + * already been used, it pulls from the stored rule objects. + * + * @param string $rule + * + * @return mixed + */ + protected function getRuleToCall($rule) + { + if (isset($this->customRules[$rule])) { + return $this->customRules[$rule]; + } + + if (method_exists($this, 'validate_' . $rule)) { + return [$this, 'validate_' . $rule]; + } + + if (isset($this->usedRules[$rule])) { + return [$this->usedRules[$rule], 'run']; + } + + $ruleClass = 'Violin\\Rules\\' . ucfirst($rule) . 'Rule'; + $ruleObject = new $ruleClass(); + + $this->usedRules[$rule] = $ruleObject; + + return [$ruleObject, 'run']; + } + + /** + * Determine whether a rule has arguments. + * + * @param string $rule + * + * @return bool + */ + protected function ruleHasArgs($rule) + { + return isset(explode('(', $rule)[1]); + } + + /** + * Get rule arguments. + * + * @param string $rule + * + * @return array + */ + protected function getRuleArgs($rule) + { + if (!$this->ruleHasArgs($rule)) { + return []; + } + + list($ruleName, $argsWithBracketAtTheEnd) = explode('(', $rule); + + $args = rtrim($argsWithBracketAtTheEnd, ')'); + $args = preg_replace('/\s+/', '', $args); + $args = explode(',', $args); + + return $args; + } + + /** + * Gets a rule name. + * + * @param string $rule + * + * @return string + */ + protected function getRuleName($rule) + { + return explode('(', $rule)[0]; + } + + /** + * Flatten an array. + * + * @param array $args + * + * @return array + */ + protected function flattenArray(array $args) + { + return iterator_to_array(new RecursiveIteratorIterator( + new RecursiveArrayIterator($args) + ), false); + } + + /** + * Extracts field aliases from an input. + * + * @param array $data + * + * @return array + */ + protected function extractFieldAliases(array $data) + { + foreach ($data as $field => $fieldRules) { + $extraction = explode('|', $field); + + if (isset($extraction[1])) { + $updatedField = $extraction[0]; + $alias = $extraction[1]; + + $this->fieldAliases[$updatedField] = $alias; + $data[$updatedField] = $data[$field]; + unset($data[$field]); + } + } + + return $data; + } + + /** + * Clears all field aliases. + * + * @return void + */ + protected function clearFieldAliases() + { + $this->fieldAliases = []; + } + + /** + * Extract the field input from the data array. + * @param array $data + * @return array + */ + protected function extractInput(array $data) + { + $input = []; + + foreach ($data as $field => $fieldData) { + $input[$field] = $fieldData[0]; + } + + return $input; + } + + /** + * Extract the field ruleset from the data array. + * + * @param array $data + * @return array + */ + protected function extractRules(array $data) + { + $rules = []; + + foreach ($data as $field => $fieldData) { + $rules[$field] = $fieldData[1]; + } + + return $rules; + } +} diff --git a/vendor/alexgarrett/violin/tests/MessageBagTest.php b/vendor/alexgarrett/violin/tests/MessageBagTest.php new file mode 100755 index 0000000..3b724c9 --- /dev/null +++ b/vendor/alexgarrett/violin/tests/MessageBagTest.php @@ -0,0 +1,68 @@ + [ + 'You must fill in the name field.', + 'Your name must only be letters.', + ], + 'username' => [ + 'Your username is required.', + 'Your username must be alphanumeric (with dashes and underscores permitted)' + ], + 'password' => [ + 'Your password must be greater than 6 characters.' + ] + ]; + + public function setUp() + { + $this->mb = new MessageBag($this->messages); + } + + public function testMessageBagContainsCorrectKeys() + { + $keys = $this->mb->keys(); + + $this->assertContains('name', $keys); + $this->assertContains('username', $keys); + $this->assertContains('password', $keys); + } + + public function testFirstErrorForFieldExists() + { + $this->assertEquals( + $this->mb->first('name'), + $this->messages['name'][0] + ); + } + + public function testAllErrorsForFieldExist() + { + $this->assertEquals( + $this->mb->get('name'), + $this->messages['name'] + ); + } + + public function testAllErrorsExist() + { + $flatMessages = iterator_to_array(new RecursiveIteratorIterator( + new RecursiveArrayIterator($this->messages) + ), false); + + $this->assertEquals($flatMessages, $this->mb->all()); + } + + public function testMessageBagHasError() + { + $this->assertTrue($this->mb->has('name')); + $this->assertTrue($this->mb->has('username')); + $this->assertTrue($this->mb->has('password')); + } +} diff --git a/vendor/alexgarrett/violin/tests/RulesTest.php b/vendor/alexgarrett/violin/tests/RulesTest.php new file mode 100755 index 0000000..bfb212c --- /dev/null +++ b/vendor/alexgarrett/violin/tests/RulesTest.php @@ -0,0 +1,567 @@ +assertFalse( + $betweenRule->run('5', [], [10, 15]) + ); + + $this->assertFalse( + $betweenRule->run(5, [], [10, 15]) + ); + + $this->assertTrue( + $betweenRule->run('100', [], [100, 500]) + ); + + $this->assertTrue( + $betweenRule->run(499, [], [100, 500]) + ); + + $this->assertTrue( + $betweenRule->run('300', [], [100, 500]) + ); + } + + public function testIntRule() + { + $intRule = new IntRule; + + $this->assertFalse( + $intRule->run('two', [], []) + ); + + $this->assertTrue( + $intRule->run('2', [], []) + ); + + $this->assertTrue( + $intRule->run(10, [], []) + ); + } + + public function testNumberRule() + { + $numberRule = new NumberRule; + + $this->assertFalse( + $numberRule->run('dale', [], []) + ); + + $this->assertFalse( + $numberRule->run('', [], []) + ); + + $this->assertFalse( + $numberRule->run('three', [], []) + ); + + $this->assertTrue( + $numberRule->run('1', [], []) + ); + + $this->assertTrue( + $numberRule->run('3.14159265359', [], []) + ); + + $this->assertTrue( + $numberRule->run(3.14159265359, [], []) + ); + } + + public function testMatchesRule() + { + $matchesRule = new MatchesRule; + + $this->assertFalse( + $matchesRule->run('cats', [ + 'password' => 'cats', + 'password_again' => 'catz', + ], ['password_again']) + ); + + $this->assertTrue( + $matchesRule->run('cats', [ + 'password' => 'cats', + 'password_again' => 'cats', + ], ['password_again']) + ); + } + + public function testRequiredRule() + { + $requiredRule = new RequiredRule; + + $this->assertFalse( + $requiredRule->run('', [], []) + ); + + $this->assertFalse( + $requiredRule->run(' ', [], []) + ); + + $this->assertFalse( + $requiredRule->run(' ', [], []) + ); // Contains whitespace character + + $this->assertTrue( + $requiredRule->run('cats', [], []) + ); + + $this->assertTrue( + $requiredRule->run(' cats ', [], []) + ); + } + + public function testAlnumRule() + { + $alnumRule = new AlnumRule; + + $this->assertFalse( + $alnumRule->run('cats_123', [], []) + ); + + $this->assertFalse( + $alnumRule->run('cats-_123', [], []) + ); + + $this->assertFalse( + $alnumRule->run('cats123!', [], []) + ); + + $this->assertTrue( + $alnumRule->run('cats123', [], []) + ); + + $this->assertTrue( + $alnumRule->run('cats', [], []) + ); + } + + public function testAlnumDashRule() + { + $alnumDashRule = new AlnumDashRule; + + $this->assertFalse( + $alnumDashRule->run('cats123!', [], []) + ); + + $this->assertFalse( + $alnumDashRule->run('cats(123)', [], []) + ); + + $this->assertTrue( + $alnumDashRule->run('cats_123', [], []) + ); + + $this->assertTrue( + $alnumDashRule->run('i_love-cats', [], []) + ); + + $this->assertTrue( + $alnumDashRule->run('cat__love', [], []) + ); + + $this->assertTrue( + $alnumDashRule->run('cat--love', [], []) + ); + } + + public function testAlphaRule() + { + $alphaRule = new AlphaRule; + + $this->assertFalse( + $alphaRule->run('cats123', [], []) + ); + + $this->assertFalse( + $alphaRule->run('cats!', [], []) + ); + + $this->assertFalse( + $alphaRule->run(' cats ', [], []) + ); + + $this->assertTrue( + $alphaRule->run('cats', [], []) + ); + } + + public function testArrayRule() + { + $arrayRule = new ArrayRule; + + $this->assertFalse( + $arrayRule->run('not an array', [], []) + ); + + $this->assertFalse( + $arrayRule->run("['not', 'an', 'array']", [], []) + ); + + $this->assertTrue( + $arrayRule->run(['an', 'array'], [], []) + ); + + $this->assertTrue( + $arrayRule->run([], [], []) + ); + } + + public function testBoolRule() + { + $boolRule = new BoolRule; + + $this->assertFalse( + $boolRule->run('false', [], []) + ); + + $this->assertFalse( + $boolRule->run('true', [], []) + ); + + $this->assertFalse( + $boolRule->run(1, [], []) + ); + + $this->assertFalse( + $boolRule->run(0, [], []) + ); + + $this->assertTrue( + $boolRule->run(true, [], []) + ); + + $this->assertTrue( + $boolRule->run(false, [], []) + ); + } + + public function testEmailRule() + { + $emailRule = new EmailRule; + + $this->assertFalse( + $emailRule->run('ilove@', [], []) + ); + + $this->assertFalse( + $emailRule->run('ilove@cats', [], []) + ); + + $this->assertTrue( + $emailRule->run('ilove@cats.com', [], []) + ); + } + + public function testIpRule() + { + $ipRule = new IpRule; + + $this->assertFalse( + $ipRule->run('127', [], []) + ); + + $this->assertFalse( + $ipRule->run('127.0.0', [], []) + ); + + $this->assertFalse( + $ipRule->run('www.duckduckgo.com', [], []) + ); + + $this->assertTrue( + $ipRule->run('0.0.0.0', [], []) + ); + + $this->assertTrue( + $ipRule->run('127.0.0.1', [], []) + ); + + $this->assertTrue( + $ipRule->run('FE80:0000:0000:0000:0202:B3FF:FE1E:8329', [], []) + ); + + $this->assertTrue( + $ipRule->run('FE80::0202:B3FF:FE1E:8329', [], []) + ); + + $this->assertTrue( + $ipRule->run('::1', [], []) + ); + } + + public function testMaxRuleWithNumbers() + { + $maxRule = new MaxRule; + + $this->assertFalse( + $maxRule->run('100', [], ['10', 'number']) + ); + + $this->assertFalse( + $maxRule->run(100, [], ['99', 'number']) + ); + + $this->assertFalse( + $maxRule->run(3.14, [], ['3.10', 'number']) + ); + + $this->assertTrue( + $maxRule->run('50', [], ['100', 'number']) + ); + + $this->assertTrue( + $maxRule->run(50, [], ['100', 'number']) + ); + + $this->assertTrue( + $maxRule->run('5.5', [], ['100', 'number']) + ); + } + + public function testMinRuleWithNumbers() + { + $minRule = new MinRule; + + $this->assertFalse( + $minRule->run('10', [], ['100', 'number']) + ); + + $this->assertFalse( + $minRule->run(99, [], ['100', 'number']) + ); + + $this->assertFalse( + $minRule->run(3.10, [], ['3.14', 'number']) + ); + + $this->assertTrue( + $minRule->run('100', [], ['50', 'number']) + ); + + $this->assertTrue( + $minRule->run(100, [], ['50', 'number']) + ); + + $this->assertTrue( + $minRule->run('100', [], ['5.5', 'number']) + ); + } + + public function testMaxRuleWithStrings() + { + $maxRule = new MaxRule; + + $this->assertFalse( + $maxRule->run('william', [], ['5']) + ); + + $this->assertFalse( + $maxRule->run('100000', [], ['5']) + ); + + $this->assertTrue( + $maxRule->run('billy', [], ['5']) + ); + + $this->assertTrue( + $maxRule->run('100', [], ['5']) + ); + + $this->assertTrue( + $maxRule->run('99999', [], ['5']) + ); + } + + public function testMinRuleWithStrings() + { + $minRule = new MinRule; + + $this->assertFalse( + $minRule->run('billy', [], ['10']) + ); + + $this->assertFalse( + $minRule->run('5', [], ['10']) + ); + + $this->assertFalse( + $minRule->run('10', [], ['10']) + ); + + $this->assertTrue( + $minRule->run('william', [], ['5']) + ); + + $this->assertTrue( + $minRule->run('99999', [], ['5']) + ); + } + + public function testUrlRule() + { + $urlRule = new UrlRule; + + $this->assertFalse( + $urlRule->run('www.com', [], []) + ); + + $this->assertFalse( + $urlRule->run('duckduckgo.com', [], []) + ); + + $this->assertFalse( + $urlRule->run('www.duckduckgo', [], []) + ); + + $this->assertFalse( + $urlRule->run('127.0.0.1', [], []) + ); + + $this->assertTrue( + $urlRule->run('http://www.duckduckgo.com', [], []) + ); + + $this->assertTrue( + $urlRule->run('http://127.0.0.1', [], []) + ); + + $this->assertTrue( + $urlRule->run('ftp://127.0.0.1', [], []) + ); + + $this->assertTrue( + $urlRule->run('ssl://codecourse.com', [], []) + ); + + $this->assertTrue( + $urlRule->run('ssl://127.0.0.1', [], []) + ); + + $this->assertTrue( + $urlRule->run('http://codecourse.com', [], []) + ); + } + + public function testDateRule() + { + $dateRule = new DateRule; + + $this->assertFalse( + $dateRule->run('', [], []) + ); + + $this->assertFalse( + $dateRule->run('0000-00-00', [], []) + ); + + $this->assertFalse( + $dateRule->run('40th November 1989', [], []) + ); + + $this->assertTrue( + $dateRule->run('16th November 1989', [], []) + ); + + $this->assertTrue( + $dateRule->run('1989-11-16', [], []) + ); + + $this->assertTrue( + $dateRule->run('16-11-1989', [], []) + ); + + $dateTime = new DateTime('2 days ago'); + + $this->assertFalse( + $dateRule->run($dateTime->format('x y z'), [], []) + ); + + $this->assertTrue( + $dateRule->run($dateTime->format('d M Y'), [], []) + ); + } + + public function testCheckedRule() + { + $checkedRule = new CheckedRule; + + $this->assertFalse( + $checkedRule->run('', [], []) + ); + + $this->assertFalse( + $checkedRule->run(' ', [], []) + ); + + $this->assertTrue( + $checkedRule->run('on', [], []) + ); + + $this->assertTrue( + $checkedRule->run('yes', [], []) + ); + + $this->assertTrue( + $checkedRule->run(1, [], []) + ); + + $this->assertTrue( + $checkedRule->run('1', [], []) + ); + + $this->assertTrue( + $checkedRule->run(true, [], []) + ); + + $this->assertTrue( + $checkedRule->run('true', [], []) + ); + } + + public function testRegexRule() + { + $regexRule = new RegexRule; + + $exampleRegex = '/b[aeiou]g/'; + + $this->assertFalse( + $regexRule->run('banter', [], [$exampleRegex]) + ); + + $this->assertTrue( + $regexRule->run('bag', [], [$exampleRegex]) + ); + + $this->assertTrue( + $regexRule->run('big', [], [$exampleRegex]) + ); + } +} diff --git a/vendor/alexgarrett/violin/tests/ValidatorTest.php b/vendor/alexgarrett/violin/tests/ValidatorTest.php new file mode 100755 index 0000000..668b1f1 --- /dev/null +++ b/vendor/alexgarrett/violin/tests/ValidatorTest.php @@ -0,0 +1,272 @@ +v = new Violin; + } + + public function testBasicValidValidation() + { + $this->v->validate([ + 'first_name' => ['Billy', 'required|alpha|max(20)'], + 'last_name' => ['Garrett', 'required|alpha|max(20)'], + 'email|Email' => ['billy@codecourse.com', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_again' => ['ilovecats', 'required|matches(password)'] + ]); + + $this->assertTrue($this->v->passes()); + $this->assertFalse($this->v->fails()); + + $input = [ + 'first_name' => 'Billy', + 'last_name' => 'Garrett', + 'email|Email' => 'billy@codecourse.com', + 'password' => 'ilovecats', + 'password' => 'ilovecats' + ]; + + $rules = [ + 'first_name' => 'required|alpha|max(20)', + 'last_name' => 'required|alpha|max(20)', + 'email' => 'required|email', + 'password' => 'required', + 'password_again' => 'required|matches(password)' + ]; + + $this->v->validate($input, $rules); + + $this->assertTrue($this->v->passes()); + $this->assertFalse($this->v->fails()); + } + + public function testBasicInvalidValidation() + { + $this->v->validate([ + 'first_name' => ['Billy', 'required|alpha|max(20)'], + 'last_name' => ['', 'required|alpha|max(20)'], + 'email' => ['billy@codecourse', 'required|email'], + 'password' => ['ilovecats', 'required'], + 'password_again' => ['ilovecatsanddogs' , 'required|matches(password)'] + ]); + + $this->assertTrue($this->v->fails()); + $this->assertFalse($this->v->passes()); + } + + public function testRuleMessage() + { + $this->v->addRuleMessage('required', 'This field is required!'); + + $this->v->validate([ + 'username' => ['', 'required'] + ]); + + $this->assertEquals( + $this->v->errors()->first('username'), + 'This field is required!' + ); + } + + public function testReplaceMessageFormatOnError() + { + $this->v->addRule('testRule', function($value, $input, $args) { + return false; + }); + + $this->v->addRuleMessage('testRule', 'We got {$#} arguments: {$*}.'); + + $this->v->validate([ + 'age' => [0, 'testRule(1, 2, 3)'] + ]); + + $this->assertEquals( + $this->v->errors()->first(), + 'We got 3 arguments: 1, 2, 3.' + ); + } + + public function testRuleMessages() + { + $this->v->addRuleMessages([ + 'required' => 'This field is required!', + 'alpha' => 'Only alpha characters please!', + 'email' => 'Enter a valid email!' + ]); + + $this->v->validate([ + 'username' => ['', 'required|alpha'], + 'name' => ['123', 'alpha'], + 'email' => ['notanemail', 'required|email'] + ]); + + $errors = $this->v->errors(); + + $this->assertEquals( + $errors->get('username'), + ['This field is required!'] + ); + + $this->assertEquals( + $errors->first('name'), + 'Only alpha characters please!' + ); + + $this->assertEquals( + $errors->first('email'), + 'Enter a valid email!' + ); + } + + public function testFieldMessage() + { + $this->v->addFieldMessage('username', 'required', 'We need a username, please.'); + + $this->v->validate([ + 'username' => ['', 'required'] + ]); + + $this->assertEquals( + $this->v->errors()->first('username'), + 'We need a username, please.' + ); + } + + public function testFieldMessages() + { + $this->v->addFieldMessages([ + 'username' => [ + 'required' => 'We need a username, please.' + ], + 'email' => [ + 'required' => 'How do you expect us to contact you without an email?' + ] + ]); + + $this->v->validate([ + 'username' => ['', 'required|alpha'], + 'email' => ['', 'required|email'] + ]); + + $errors = $this->v->errors(); + + $this->assertEquals( + $errors->get('username'), + ['We need a username, please.'] + ); + + $this->assertEquals( + $errors->first('email'), + 'How do you expect us to contact you without an email?' + ); + } + + public function testPassingCustomRule() + { + $this->v->addRule('isbanana', function($value, $input, $args) { + return $value === 'banana'; + }); + + $this->v->validate([ + 'fruit' => ['apple', 'isbanana'] + ]); + + $this->assertFalse($this->v->passes()); + } + + public function testFailingCustomRule() + { + $this->v->addRule('isbanana', function($value, $input, $args) { + return $value === 'banana'; + }); + + $this->v->validate([ + 'fruit' => ['banana', 'isbanana'] + ]); + + $this->assertTrue($this->v->passes()); + } + + public function testMultipleCustomRules() + { + $this->v->addRule('isbanana', function($value, $input, $args) { + return $value === 'banana'; + }); + + $this->v->addRule('isapple', function($value, $input, $args) { + return $value === 'apple'; + }); + + $this->v->validate([ + 'fruit_one' => ['banana', 'isbanana'], + 'fruit_two' => ['apple', 'isapple'] + ]); + + $this->assertTrue($this->v->passes()); + } + + public function testPassingCustomRuleWithArguments() + { + $this->v->addRule('isoneof', function($value, $input, $args) { + return in_array($value, $args); + }); + + $this->v->validate([ + 'items' => ['seeds', 'isoneof(seeds, nuts, fruit)'] + ]); + + $this->assertTrue($this->v->passes()); + } + + public function testFailingCustomRuleWithArguments() + { + $this->v->addRule('isoneof', function($value, $input, $args) { + return in_array($value, $args); + }); + + $this->v->validate([ + 'items' => ['burger', 'isoneof(seeds, nuts, fruit)'] + ]); + + $this->assertFalse($this->v->passes()); + } + + public function testValidationWithAliases() + { + $this->v->addFieldMessages([ + 'username_box' => [ + 'required' => 'We need a username in the {field} field, please.' + ] + ]); + + $this->v->validate([ + 'username_box|Username' => ['', 'required'], + 'password' => ['secret', 'required|alpha'] + ]); + + $errors = $this->v->errors(); + + $this->assertFalse($this->v->passes()); + $this->assertTrue($this->v->fails()); + $this->assertEquals( + $errors->first('username_box'), + 'We need a username in the Username field, please.' + ); + } + + public function testSkippingOtherRulesIfNotRequired() + { + $this->v->validate([ + 'username' => ['alex', 'required|alpha'], + 'email' => ['', 'alpha|email'] + ]); + + $this->assertEmpty($this->v->errors()->all()); + } +} diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100755 index 0000000..bcef840 --- /dev/null +++ b/vendor/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 class loader + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * + * $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 + */ +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; + + 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-0 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; + } + + /** + * 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) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative) { + return false; + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if ($file === null && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if ($file === null) { + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (is_file($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 (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100755 index 0000000..7a91153 --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + array($vendorDir . '/twig/twig/lib'), + 'Slim' => array($vendorDir . '/slim/slim'), + 'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'), + 'Carbon' => array($vendorDir . '/nesbot/carbon/src'), +); diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php new file mode 100755 index 0000000..0811892 --- /dev/null +++ b/vendor/composer/autoload_psr4.php @@ -0,0 +1,18 @@ + array($vendorDir . '/alexgarrett/violin/src'), + 'Symfony\\Component\\Translation\\' => array($vendorDir . '/symfony/translation'), + 'Stringy\\' => array($vendorDir . '/danielstjules/stringy/src'), + 'Slim\\Views\\' => array($vendorDir . '/slim/views'), + 'Noodlehaus\\' => array($vendorDir . '/hassankhan/config/src'), + 'Illuminate\\Support\\' => array($vendorDir . '/illuminate/support'), + 'Illuminate\\Database\\' => array($vendorDir . '/illuminate/database'), + 'Illuminate\\Contracts\\' => array($vendorDir . '/illuminate/contracts'), + 'Illuminate\\Container\\' => array($vendorDir . '/illuminate/container'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100755 index 0000000..d38788c --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,55 @@ + $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); + + $includeFiles = require __DIR__ . '/autoload_files.php'; + foreach ($includeFiles as $file) { + composerRequire83835b20f568ce9cd62f0e1edc75fa23($file); + } + + return $loader; + } +} + +function composerRequire83835b20f568ce9cd62f0e1edc75fa23($file) +{ + require $file; +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100755 index 0000000..f4a1dcd --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,711 @@ +[ + { + "name": "slim/slim", + "version": "2.6.2", + "version_normalized": "2.6.2.0", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim.git", + "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/20a02782f76830b67ae56a5c08eb1f563c351a37", + "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "suggest": { + "ext-mcrypt": "Required for HTTP cookie encryption" + }, + "time": "2015-03-08 18:41:17", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Slim": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + } + ], + "description": "Slim Framework, a PHP micro framework", + "homepage": "http://github.com/codeguy/Slim", + "keywords": [ + "microframework", + "rest", + "router" + ] + }, + { + "name": "slim/views", + "version": "0.1.3", + "version_normalized": "0.1.3.0", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim-Views.git", + "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim-Views/zipball/8561c785e55a39df6cb6f95c3aba3281a60ed5b0", + "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "slim/slim": ">=2.4.0" + }, + "suggest": { + "smarty/smarty": "Smarty templating system", + "twig/twig": "Twig templating system" + }, + "time": "2014-12-09 23:48:51", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Slim\\Views\\": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://thoughts.silentworks.co.uk/" + } + ], + "description": "Smarty and Twig View Parser package for the Slim Framework", + "homepage": "http://github.com/codeguy/Slim-Views", + "keywords": [ + "extensions", + "slimphp", + "templating" + ] + }, + { + "name": "twig/twig", + "version": "v1.18.2", + "version_normalized": "1.18.2.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "e8e6575abf6102af53ec283f7f14b89e304fa602" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/e8e6575abf6102af53ec283f7f14b89e304fa602", + "reference": "e8e6575abf6102af53ec283f7f14b89e304fa602", + "shasum": "" + }, + "require": { + "php": ">=5.2.7" + }, + "time": "2015-06-06 23:31:24", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "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": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "http://twig.sensiolabs.org/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ] + }, + { + "name": "symfony/translation", + "version": "v2.7.0", + "version_normalized": "2.7.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/Translation.git", + "reference": "cc1907bbeacfcc703c031b67545400d6e7d1eb79" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Translation/zipball/cc1907bbeacfcc703c031b67545400d6e7d1eb79", + "reference": "cc1907bbeacfcc703c031b67545400d6e7d1eb79", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "conflict": { + "symfony/config": "<2.7" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.7", + "symfony/intl": "~2.3", + "symfony/phpunit-bridge": "~2.7", + "symfony/yaml": "~2.2" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "time": "2015-05-29 14:44:44", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com" + }, + { + "name": "nesbot/carbon", + "version": "1.19.0", + "version_normalized": "1.19.0.0", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "68868e0b02d2d803d0052a59d4e5003cccf87320" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/68868e0b02d2d803d0052a59d4e5003cccf87320", + "reference": "68868e0b02d2d803d0052a59d4e5003cccf87320", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "symfony/translation": "~2.6" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "time": "2015-05-09 03:23:44", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Carbon": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ] + }, + { + "name": "danielstjules/stringy", + "version": "1.9.0", + "version_normalized": "1.9.0.0", + "source": { + "type": "git", + "url": "https://github.com/danielstjules/Stringy.git", + "reference": "3cf18e9e424a6dedc38b7eb7ef580edb0929461b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/danielstjules/Stringy/zipball/3cf18e9e424a6dedc38b7eb7ef580edb0929461b", + "reference": "3cf18e9e424a6dedc38b7eb7ef580edb0929461b", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "time": "2015-02-10 06:19:18", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Stringy\\": "src/" + }, + "files": [ + "src/Create.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel St. Jules", + "email": "danielst.jules@gmail.com", + "homepage": "http://www.danielstjules.com" + } + ], + "description": "A string manipulation library with multibyte support", + "homepage": "https://github.com/danielstjules/Stringy", + "keywords": [ + "UTF", + "helpers", + "manipulation", + "methods", + "multibyte", + "string", + "utf-8", + "utility", + "utils" + ] + }, + { + "name": "doctrine/inflector", + "version": "v1.0.1", + "version_normalized": "1.0.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "0bcb2e79d8571787f18b7eb036ed3d004908e604" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/0bcb2e79d8571787f18b7eb036ed3d004908e604", + "reference": "0bcb2e79d8571787f18b7eb036ed3d004908e604", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "time": "2014-12-20 21:24:13", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Doctrine\\Common\\Inflector\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ] + }, + { + "name": "illuminate/contracts", + "version": "v5.0.0", + "version_normalized": "5.0.0.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "78f1dba092d5fcb6d3a19537662abe31c4d128fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/78f1dba092d5fcb6d3a19537662abe31c4d128fd", + "reference": "78f1dba092d5fcb6d3a19537662abe31c4d128fd", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "time": "2015-01-30 16:27:08", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Contracts package." + }, + { + "name": "illuminate/support", + "version": "v5.0.28", + "version_normalized": "5.0.28.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "b6d68e1f2a7053bf4c755c5e6b15fcfb700e14e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/support/zipball/b6d68e1f2a7053bf4c755c5e6b15fcfb700e14e7", + "reference": "b6d68e1f2a7053bf4c755c5e6b15fcfb700e14e7", + "shasum": "" + }, + "require": { + "danielstjules/stringy": "~1.8", + "doctrine/inflector": "~1.0", + "ext-mbstring": "*", + "illuminate/contracts": "5.0.*", + "php": ">=5.4.0" + }, + "suggest": { + "jeremeamia/superclosure": "Required to be able to serialize closures (~2.0)." + }, + "time": "2015-04-15 19:26:55", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Support package.", + "homepage": "http://laravel.com" + }, + { + "name": "illuminate/container", + "version": "v5.0.28", + "version_normalized": "5.0.28.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/container.git", + "reference": "a11c01c1d8b6941bd7ef2f104749ada5e34f146e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/container/zipball/a11c01c1d8b6941bd7ef2f104749ada5e34f146e", + "reference": "a11c01c1d8b6941bd7ef2f104749ada5e34f146e", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.0.*", + "php": ">=5.4.0" + }, + "time": "2015-03-25 17:06:14", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Illuminate\\Container\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Container package.", + "homepage": "http://laravel.com" + }, + { + "name": "illuminate/database", + "version": "v5.0.28", + "version_normalized": "5.0.28.0", + "source": { + "type": "git", + "url": "https://github.com/illuminate/database.git", + "reference": "dd7bd24a0240607e1de36cfe8d43335653d1536c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/database/zipball/dd7bd24a0240607e1de36cfe8d43335653d1536c", + "reference": "dd7bd24a0240607e1de36cfe8d43335653d1536c", + "shasum": "" + }, + "require": { + "illuminate/container": "5.0.*", + "illuminate/contracts": "5.0.*", + "illuminate/support": "5.0.*", + "nesbot/carbon": "~1.0", + "php": ">=5.4.0" + }, + "suggest": { + "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).", + "illuminate/console": "Required to use the database commands (5.0.*).", + "illuminate/events": "Required to use the observers with Eloquent (5.0.*).", + "illuminate/filesystem": "Required to use the migrations (5.0.*)." + }, + "time": "2015-04-19 09:23:09", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Illuminate\\Database\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Database package.", + "homepage": "http://laravel.com", + "keywords": [ + "database", + "laravel", + "orm", + "sql" + ] + }, + { + "name": "hassankhan/config", + "version": "0.8.2", + "version_normalized": "0.8.2.0", + "source": { + "type": "git", + "url": "https://github.com/hassankhan/config.git", + "reference": "42ba051954745b565306f0f82c57814f54579f8d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hassankhan/config/zipball/42ba051954745b565306f0f82c57814f54579f8d", + "reference": "42ba051954745b565306f0f82c57814f54579f8d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "scrutinizer/ocular": "~1.1", + "squizlabs/php_codesniffer": "~2.2" + }, + "suggest": { + "symfony/yaml": "~2.5" + }, + "time": "2015-03-21 11:21:39", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Noodlehaus\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Hassan Khan", + "homepage": "http://hassankhan.me/", + "role": "Developer" + } + ], + "description": "Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files", + "homepage": "http://hassankhan.me/config/", + "keywords": [ + "config", + "configuration", + "ini", + "json", + "microphp", + "unframework", + "xml", + "yaml", + "yml" + ] + }, + { + "name": "alexgarrett/violin", + "version": "2.2.2", + "version_normalized": "2.2.2.0", + "source": { + "type": "git", + "url": "https://github.com/alexgarrett/violin.git", + "reference": "92d0ee5d0e7cc1703fe937772c313721fdb86cdc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/alexgarrett/violin/zipball/92d0ee5d0e7cc1703fe937772c313721fdb86cdc", + "reference": "92d0ee5d0e7cc1703fe937772c313721fdb86cdc", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.5", + "squizlabs/php_codesniffer": "2.1.*" + }, + "time": "2015-04-11 22:58:34", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Violin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alex Garrett", + "email": "alex@codecourse.com", + "homepage": "http://itsmealex.com" + } + ], + "description": "Violin is an easy to use, highly customisable PHP validator.", + "homepage": "https://github.com/alexgarrett/violin", + "keywords": [ + "validation" + ] + } +] diff --git a/vendor/danielstjules/stringy/CHANGELOG.md b/vendor/danielstjules/stringy/CHANGELOG.md new file mode 100755 index 0000000..03a1097 --- /dev/null +++ b/vendor/danielstjules/stringy/CHANGELOG.md @@ -0,0 +1,110 @@ +### 1.9.0 (2015-02-09) + + * Added hasUpperCase and hasLowerCase + * Added $removeUnsupported parameter to toAscii() + * Improved toAscii support with additional Unicode spaces, Vietnamese chars, + and numerous other characters + * Separated the charsArray from toAscii as a protected method that may be + extended by inheriting classes + * Chars array is cached for better performance + +### 1.8.1 (2015-01-08) + + * Optimized chars() + * Added "ä Ä Ö Ü"" in toAscii() + * Added support for Unicode spaces in toAscii() + * Replaced instances of self::create() with static::create() + * Added missing test cases for safeTruncate() and longestCommonSuffix() + * Updated Stringy\create() to avoid collision when it already exists + +### 1.8.0 (2015-01-03) + + * Listed ext-mbstring in composer.json + * Added Stringy\create function for PHP 5.6 + +### 1.7.0 (2014-10-14) + + * Added containsAll and containsAny + * Light cleanup + +### 1.6.0 (2014-09-14) + + * Added toTitleCase + +### 1.5.2 (2014-07-09) + + * Announced support for HHVM + +### 1.5.1 (2014-04-19) + + * Fixed toAscii() failing to remove remaining non-ascii characters + * Updated slugify() to treat dash and underscore as delimiters by default + * Updated slugify() to remove leading and trailing delimiter, if present + +### 1.5.0 (2014-03-19) + + * Made both str and encoding protected, giving property access to subclasses + * Added getEncoding() + * Fixed isJSON() giving false negatives + * Cleaned up and simplified: replace(), collapseWhitespace(), underscored(), + dasherize(), pad(), padLeft(), padRight() and padBoth() + * Fixed handling consecutive invalid chars in slugify() + * Removed conflicting hard sign transliteration in toAscii() + +### 1.4.0 (2014-02-12) + + * Implemented the IteratorAggregate interface, added chars() + * Renamed count() to countSubstr() + * Updated count() to implement Countable interface + * Implemented the ArrayAccess interface with positive and negative indices + * Switched from PSR-0 to PSR-4 autoloading + +### 1.3.0 (2013-12-16) + + * Additional Bulgarian support for toAscii + * str property made private + * Constructor casts first argument to string + * Constructor throws an InvalidArgumentException when given an array + * Constructor throws an InvalidArgumentException when given an object without + a __toString method + +### 1.2.2 (2013-12-04) + + * Updated create function to use late static binding + * Added optional $replacement param to slugify + +### 1.2.1 (2013-10-11) + + * Cleaned up tests + * Added homepage to composer.json + +### 1.2.0 (2013-09-15) + + * Fixed pad's use of InvalidArgumentException + * Fixed replace(). It now correctly treats regex special chars as normal chars + * Added additional Cyrillic letters to toAscii + * Added $caseSensitive to contains() and count() + * Added toLowerCase() + * Added toUpperCase() + * Added regexReplace() + +### 1.1.0 (2013-08-31) + + * Fix for collapseWhitespace() + * Added isHexadecimal() + * Added constructor to Stringy\Stringy + * Added isSerialized() + * Added isJson() + +### 1.0.0 (2013-08-1) + + * 1.0.0 release + * Added test coverage for Stringy::create and method chaining + * Added tests for returned type + * Fixed StaticStringy::replace(). It was returning a Stringy object instead of string + * Renamed standardize() to the more appropriate toAscii() + * Cleaned up comments and README + +### 1.0.0-rc.1 (2013-07-28) + + * Release candidate diff --git a/vendor/danielstjules/stringy/LICENSE.txt b/vendor/danielstjules/stringy/LICENSE.txt new file mode 100755 index 0000000..0b70302 --- /dev/null +++ b/vendor/danielstjules/stringy/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (C) 2013 Daniel St. Jules + +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/vendor/danielstjules/stringy/README.md b/vendor/danielstjules/stringy/README.md new file mode 100755 index 0000000..3dbb7d9 --- /dev/null +++ b/vendor/danielstjules/stringy/README.md @@ -0,0 +1,1077 @@ +![Stringy](http://danielstjules.com/github/stringy-logo.png) + +A PHP string manipulation library with multibyte support. Offers both OO method +chaining and a procedural-style static wrapper. Tested and compatible with +PHP 5.3+ and HHVM. Inspired by underscore.string.js. + +[![Build Status](https://api.travis-ci.org/danielstjules/Stringy.svg?branch=master)](https://travis-ci.org/danielstjules/Stringy) + +* [Requiring/Loading](#requiringloading) +* [OO and Procedural](#oo-and-procedural) +* [Implemented Interfaces](#implemented-interfaces) +* [PHP 5.6 Creation](#php-56-creation) +* [Methods](#methods) + * [at](#at) + * [camelize](#camelize) + * [chars](#chars) + * [collapseWhitespace](#collapsewhitespace) + * [contains](#contains) + * [containsAll](#containsall) + * [containsAny](#containsany) + * [countSubstr](#countsubstr) + * [create](#create) + * [dasherize](#dasherize) + * [endsWith](#endswith) + * [ensureLeft](#ensureleft) + * [ensureRight](#ensureright) + * [first](#first) + * [getEncoding](#getencoding) + * [hasLowerCase](#haslowercase) + * [hasUpperCase](#hasuppercase) + * [humanize](#humanize) + * [insert](#insert) + * [isAlpha](#isalpha) + * [isAlphanumeric](#isalphanumeric) + * [isBlank](#isblank) + * [isHexadecimal](#ishexadecimal) + * [isJson](#isjson) + * [isLowerCase](#islowercase) + * [isSerialized](#isserialized) + * [isUpperCase](#isuppercase) + * [last](#last) + * [length](#length) + * [longestCommonPrefix](#longestcommonprefix) + * [longestCommonSuffix](#longestcommonsuffix) + * [longestCommonSubstring](#longestcommonsubstring) + * [lowerCaseFirst](#lowercasefirst) + * [pad](#pad) + * [padBoth](#padboth) + * [padLeft](#padleft) + * [padRight](#padright) + * [regexReplace](#regexreplace) + * [removeLeft](#removeleft) + * [removeRight](#removeright) + * [replace](#replace) + * [reverse](#reverse) + * [safeTruncate](#safetruncate) + * [shuffle](#shuffle) + * [slugify](#slugify) + * [startsWith](#startswith) + * [substr](#substr) + * [surround](#surround) + * [swapCase](#swapcase) + * [tidy](#tidy) + * [titleize](#titleize) + * [toAscii](#toascii) + * [toLowerCase](#tolowercase) + * [toSpaces](#tospaces) + * [toTabs](#totabs) + * [toTitleCase](#totitlecase) + * [toUpperCase](#touppercase) + * [trim](#trim) + * [truncate](#truncate) + * [underscored](#underscored) + * [upperCamelize](#uppercamelize) + * [upperCaseFirst](#uppercasefirst) +* [Links](#links) +* [Tests](#tests) +* [License](#license) + +## Requiring/Loading + +If you're using Composer to manage dependencies, you can include the following +in your composer.json file: + +```json +{ + "require": { + "danielstjules/stringy": "~1.9" + } +} +``` + +Then, after running `composer update` or `php composer.phar update`, you can +load the class using Composer's autoloading: + +```php +require 'vendor/autoload.php'; +``` + +Otherwise, you can simply require the file directly: + +```php +require_once 'path/to/Stringy/src/Stringy.php'; +// or +require_once 'path/to/Stringy/src/StaticStringy.php'; +``` + +And in either case, I'd suggest using an alias. + +```php +use Stringy\Stringy as S; +// or +use Stringy\StaticStringy as S; +``` + +## OO and Procedural + +The library offers both OO method chaining with `Stringy\Stringy`, as well as +procedural-style static method calls with `Stringy\StaticStringy`. An example +of the former is the following: + +```php +use Stringy\Stringy as S; +echo S::create('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase(); // 'fÒÔ bÀŘ' +``` + +`Stringy\Stringy` has a __toString() method, which returns the current string +when the object is used in a string context, ie: +`(string) S::create('foo') // 'foo'` + +Using the static wrapper, an alternative is the following: + +```php +use Stringy\StaticStringy as S; +$string = S::collapseWhitespace('Fòô Bàř', 'UTF-8'); +echo S::swapCase($string, 'UTF-8'); // 'fÒÔ bÀŘ' +``` + +## Implemented Interfaces + +`Stringy\Stringy` implements the `IteratorAggregate` interface, meaning that +`foreach` can be used with an instance of the class: + +``` php +$stringy = S::create('Fòô Bàř', 'UTF-8'); +foreach ($stringy as $char) { + echo $char; +} +// 'Fòô Bàř' +``` + +It implements the `Countable` interface, enabling the use of `count()` to +retrieve the number of characters in the string: + +``` php +$stringy = S::create('Fòô', 'UTF-8'); +count($stringy); // 3 +``` + +Furthermore, the `ArrayAccess` interface has been implemented. As a result, +`isset()` can be used to check if a character at a specific index exists. And +since `Stringy\Stringy` is immutable, any call to `offsetSet` or `offsetUnset` +will throw an exception. `offsetGet` has been implemented, however, and accepts +both positive and negative indexes. Invalid indexes result in an +`OutOfBoundsException`. + +``` php +$stringy = S::create('Bàř', 'UTF-8'); +echo $stringy[2]; // 'ř' +echo $stringy[-2]; // 'à' +isset($stringy[-4]); // false + +$stringy[3]; // OutOfBoundsException +$stringy[2] = 'a'; // Exception +``` + +## PHP 5.6 Creation + +As of PHP 5.6, [`use function`](https://wiki.php.net/rfc/use_function) is +available for importing functions. Stringy exposes a namespaced function, +`Stringy\create`, which emits the same behaviour as `Stringy\Stringy::create()`. +If running PHP 5.6, or another runtime that supports the `use function` syntax, +you can take advantage of an even simpler API as seen below: + +``` php +use function Stringy\create as s; + +// Instead of: S::create('Fòô Bàř', 'UTF-8') +s('Fòô Bàř', 'UTF-8')->collapseWhitespace()->swapCase(); +``` + +## Methods + +In the list below, any static method other than S::create refers to a method in +`Stringy\StaticStringy`. For all others, they're found in `Stringy\Stringy`. +Furthermore, all methods that return a Stringy object or string do not modify +the original. Stringy objects are immutable. + +*Note: If `$encoding` is not given, it defaults to `mb_internal_encoding()`.* + +#### at + +$stringy->at(int $index) + +S::at(int $index [, string $encoding ]) + +Returns the character at $index, with indexes starting at 0. + +```php +S::create('fòô bàř', 'UTF-8')->at(6); +S::at('fòô bàř', 6, 'UTF-8'); // 'ř' +``` + +#### camelize + +$stringy->camelize(); + +S::camelize(string $str [, string $encoding ]) + +Returns a camelCase version of the string. Trims surrounding spaces, +capitalizes letters following digits, spaces, dashes and underscores, +and removes spaces, dashes, as well as underscores. + +```php +S::create('Camel-Case')->camelize(); +S::camelize('Camel-Case'); // 'camelCase' +``` + +#### chars + +$stringy->chars(); + +S::chars(string $str [, string $encoding ]) + +Returns an array consisting of the characters in the string. + +```php +S::create('Fòô Bàř', 'UTF-8')->chars(); +S::chars('Fòô Bàř', 'UTF-8'); // array(F', 'ò', 'ô', ' ', 'B', 'à', 'ř') +``` + +#### collapseWhitespace + +$stringy->collapseWhitespace() + +S::collapseWhitespace(string $str [, string $encoding ]) + +Trims the string and replaces consecutive whitespace characters with a +single space. This includes tabs and newline characters, as well as +multibyte whitespace such as the thin space and ideographic space. + +```php +S::create(' Ο συγγραφέας ')->collapseWhitespace(); +S::collapseWhitespace(' Ο συγγραφέας '); // 'Ο συγγραφέας' +``` + +#### contains + +$stringy->contains(string $needle [, boolean $caseSensitive = true ]) + +S::contains(string $haystack, string $needle [, boolean $caseSensitive = true [, string $encoding ]]) + +Returns true if the string contains $needle, false otherwise. By default, +the comparison is case-sensitive, but can be made insensitive +by setting $caseSensitive to false. + +```php +S::create('Ο συγγραφέας είπε', 'UTF-8')->contains('συγγραφέας'); +S::contains('Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'); // true +``` + +#### containsAll + +$stringy->containsAll(array $needles [, boolean $caseSensitive = true ]) + +S::containsAll(string $haystack, array $needles [, boolean $caseSensitive = true [, string $encoding ]]) + +Returns true if the string contains all $needles, false otherwise. By +default the comparison is case-sensitive, but can be made insensitive by +setting $caseSensitive to false. + +```php +S::create('Str contains foo and bar')->containsAll(array('foo', 'bar')); +S::containsAll('Str contains foo and bar', array('foo', 'bar')); // true +``` + +#### containsAny + +$stringy->containsAny(array $needles [, boolean $caseSensitive = true ]) + +S::containsAny(string $haystack, array $needles [, boolean $caseSensitive = true [, string $encoding ]]) + +Returns true if the string contains any $needles, false otherwise. By +default the comparison is case-sensitive, but can be made insensitive by +setting $caseSensitive to false. + +```php +S::create('Str contains foo')->containsAny(array('foo', 'bar')); +S::containsAny('Str contains foo', array('foo', 'bar')); // true +``` + +#### countSubstr + +$stringy->countSubstr(string $substring [, boolean $caseSensitive = true ]) + +S::countSubstr(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]]) + +Returns the number of occurrences of $substring in the given string. +By default, the comparison is case-sensitive, but can be made insensitive +by setting $caseSensitive to false. + +```php +S::create('Ο συγγραφέας είπε', 'UTF-8')->countSubstr('α'); +S::countSubstr('Ο συγγραφέας είπε', 'α', 'UTF-8'); // 2 +``` + +#### create + +S::create(mixed $str [, $encoding ]) + +Creates a Stringy object and assigns both str and encoding properties +the supplied values. $str is cast to a string prior to assignment, and if +$encoding is not specified, it defaults to mb_internal_encoding(). It +then returns the initialized object. Throws an InvalidArgumentException +if the first argument is an array or object without a __toString method. + +```php +$stringy = S::create('fòô bàř', 'UTF-8'); // 'fòô bàř' +``` + +#### dasherize + +$stringy->dasherize(); + +S::dasherize(string $str [, string $encoding ]) + +Returns a lowercase and trimmed string separated by dashes. Dashes are +inserted before uppercase characters (with the exception of the first +character of the string), and in place of spaces as well as underscores. + +```php +S::create('TestDCase')->dasherize(); +S::dasherize('TestDCase'); // 'test-d-case' +``` + +#### endsWith + +$stringy->endsWith(string $substring [, boolean $caseSensitive = true ]) + +S::endsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]]) + +Returns true if the string ends with $substring, false otherwise. By +default, the comparison is case-sensitive, but can be made insensitive by +setting $caseSensitive to false. + +```php +S::create('FÒÔ bàřs', 'UTF-8')->endsWith('àřs', true); +S::endsWith('FÒÔ bàřs', 'àřs', true, 'UTF-8'); // true +``` + +#### ensureLeft + +$stringy->ensureLeft(string $substring) + +S::ensureLeft(string $substring [, string $encoding ]) + +Ensures that the string begins with $substring. If it doesn't, it's prepended. + +```php +S::create('foobar')->ensureLeft('http://'); +S::ensureLeft('foobar', 'http://'); // 'http://foobar' +``` + +#### ensureRight + +$stringy->ensureRight(string $substring) + +S::ensureRight(string $substring [, string $encoding ]) + +Ensures that the string begins with $substring. If it doesn't, it's appended. + +```php +S::create('foobar')->ensureRight('.com'); +S::ensureRight('foobar', '.com'); // 'foobar.com' +``` + +#### first + +$stringy->first(int $n) + +S::first(int $n [, string $encoding ]) + +Returns the first $n characters of the string. + +```php +S::create('fòô bàř', 'UTF-8')->first(3); +S::first('fòô bàř', 3, 'UTF-8'); // 'fòô' +``` + +#### getEncoding + +$stringy->getEncoding() + +Returns the encoding used by the Stringy object. + +```php +S::create('fòô bàř', 'UTF-8')->getEncoding(); // 'UTF-8' +``` + +#### hasLowerCase + +$stringy->hasLowerCase() + +S::hasLowerCase(string $str [, string $encoding ]) + +Returns true if the string contains a lower case char, false otherwise. + +```php +S::create('fòô bàř', 'UTF-8')->hasLowerCase(); +S::hasLowerCase('fòô bàř', 'UTF-8'); // true +``` + +#### hasUpperCase + +$stringy->hasUpperCase() + +S::hasUpperCase(string $str [, string $encoding ]) + +Returns true if the string contains an upper case char, false otherwise. + +```php +S::create('fòô bàř', 'UTF-8')->hasUpperCase(); +S::hasUpperCase('fòô bàř', 'UTF-8'); // false +``` + +#### humanize + +$stringy->humanize() + +S::humanize(string $str [, string $encoding ]) + +Capitalizes the first word of the string, replaces underscores with +spaces, and strips '_id'. + +```php +S::create('author_id')->humanize(); +S::humanize('author_id'); // 'Author' +``` + +#### insert + +$stringy->insert(int $index, string $substring) + +S::insert(string $str, int $index, string $substring [, string $encoding ]) + +Inserts $substring into the string at the $index provided. + +```php +S::create('fòô bà', 'UTF-8')->insert('ř', 6); +S::insert('fòô bà', 'ř', 6, 'UTF-8'); // 'fòô bàř' +``` + +#### isAlpha + +$stringy->isAlpha() + +S::isAlpha(string $str [, string $encoding ]) + +Returns true if the string contains only alphabetic chars, false otherwise. + +```php +S::create('丹尼爾', 'UTF-8')->isAlpha(); +S::isAlpha('丹尼爾', 'UTF-8'); // true +``` + +#### isAlphanumeric + +$stringy->isAlphanumeric() + +S::isAlphanumeric(string $str [, string $encoding ]) + +Returns true if the string contains only alphabetic and numeric chars, false +otherwise. + +```php +S::create('دانيال1', 'UTF-8')->isAlphanumeric(); +S::isAlphanumeric('دانيال1', 'UTF-8'); // true +``` + +#### isBlank + +$stringy->isBlank() + +S::isBlank(string $str [, string $encoding ]) + +Returns true if the string contains only whitespace chars, false otherwise. + +```php +S::create("\n\t \v\f")->isBlank(); +S::isBlank("\n\t \v\f"); // true +``` + +#### isHexadecimal + +$stringy->isHexadecimal() + +S::isHexadecimal(string $str [, string $encoding ]) + +Returns true if the string contains only hexadecimal chars, false otherwise. + +```php +S::create('A102F')->isHexadecimal(); +S::isHexadecimal('A102F'); // true +``` + +#### isJson + +$stringy->isJson() + +S::isJson(string $str [, string $encoding ]) + +Returns true if the string is JSON, false otherwise. + +```php +S::create('{"foo":"bar"}')->isJson(); +S::isJson('{"foo":"bar"}'); // true +``` + +#### isLowerCase + +$stringy->isLowerCase() + +S::isLowerCase(string $str [, string $encoding ]) + +Returns true if the string contains only lower case chars, false otherwise. + +```php +S::create('fòô bàř', 'UTF-8')->isLowerCase(); +S::isLowerCase('fòô bàř', 'UTF-8'); // true +``` + +#### isSerialized + +$stringy->isSerialized() + +S::isSerialized(string $str [, string $encoding ]) + +Returns true if the string is serialized, false otherwise. + +```php +S::create('a:1:{s:3:"foo";s:3:"bar";}', 'UTF-8')->isSerialized(); +S::isSerialized('a:1:{s:3:"foo";s:3:"bar";}', 'UTF-8'); // true +``` + +#### isUpperCase + +$stringy->isUpperCase() + +S::isUpperCase(string $str [, string $encoding ]) + +Returns true if the string contains only upper case chars, false otherwise. + +```php +S::create('FÒÔBÀŘ', 'UTF-8')->isUpperCase(); +S::isUpperCase('FÒÔBÀŘ', 'UTF-8'); // true +``` + +#### last + +$stringy->last(int $n) + +S::last(int $n [, string $encoding ]) + +Returns the last $n characters of the string. + +```php +S::create('fòô bàř', 'UTF-8')->last(3); +S::last('fòô bàř', 3, 'UTF-8'); // 'bàř' +``` + +#### length + +$stringy->length() + +S::length(string $str [, string $encoding ]) + +Returns the length of the string. An alias for PHP's mb_strlen() function. + +```php +S::create('fòô bàř', 'UTF-8')->length(); +S::length('fòô bàř', 'UTF-8'); // 7 +``` + +#### longestCommonPrefix + +$stringy->longestCommonPrefix(string $otherStr) + +S::longestCommonPrefix(string $str, string $otherStr [, $encoding ]) + +Returns the longest common prefix between the string and $otherStr. + +```php +S::create('fòô bar', 'UTF-8')->longestCommonPrefix('fòr bar'); +S::longestCommonPrefix('fòô bar', 'fòr bar', 'UTF-8'); // 'fò' +``` + +#### longestCommonSuffix + +$stringy->longestCommonSuffix(string $otherStr) + +S::longestCommonSuffix(string $str, string $otherStr [, $encoding ]) + +Returns the longest common suffix between the string and $otherStr. + +```php +S::create('fòô bàř', 'UTF-8')->longestCommonSuffix('fòr bàř'); +S::longestCommonSuffix('fòô bàř', 'fòr bàř', 'UTF-8'); // ' bàř' +``` + +#### longestCommonSubstring + +$stringy->longestCommonSubstring(string $otherStr) + +S::longestCommonSubstring(string $str, string $otherStr [, $encoding ]) + +Returns the longest common substring between the string and $otherStr. In the +case of ties, it returns that which occurs first. + +```php +S::create('foo bar')->longestCommonSubstring('boo far'); +S::longestCommonSubstring('foo bar', 'boo far'); // 'oo ' +``` + +#### lowerCaseFirst + +$stringy->lowerCaseFirst(); + +S::lowerCaseFirst(string $str [, string $encoding ]) + +Converts the first character of the supplied string to lower case. + +```php +S::create('Σ test', 'UTF-8')->lowerCaseFirst(); +S::lowerCaseFirst('Σ test', 'UTF-8'); // 'σ test' +``` + +#### pad + +$stringy->pad(int $length [, string $padStr = ' ' [, string $padType = 'right' ]]) + +S::pad(string $str , int $length [, string $padStr = ' ' [, string $padType = 'right' [, string $encoding ]]]) + +Pads the string to a given length with $padStr. If length is less than +or equal to the length of the string, no padding takes places. The default +string used for padding is a space, and the default type (one of 'left', +'right', 'both') is 'right'. Throws an InvalidArgumentException if +$padType isn't one of those 3 values. + +```php +S::create('fòô bàř', 'UTF-8')->pad( 10, '¬ø', 'left'); +S::pad('fòô bàř', 10, '¬ø', 'left', 'UTF-8'); // '¬ø¬fòô bàř' +``` + +#### padBoth + +$stringy->padBoth(int $length [, string $padStr = ' ' ]) + +S::padBoth(string $str , int $length [, string $padStr = ' ' [, string $encoding ]]) + +Returns a new string of a given length such that both sides of the string +string are padded. Alias for pad() with a $padType of 'both'. + +```php +S::create('foo bar')->padBoth(9, ' '); +S::padBoth('foo bar', 9, ' '); // ' foo bar ' +``` + +#### padLeft + +$stringy->padLeft(int $length [, string $padStr = ' ' ]) + +S::padLeft(string $str , int $length [, string $padStr = ' ' [, string $encoding ]]) + +Returns a new string of a given length such that the beginning of the +string is padded. Alias for pad() with a $padType of 'left'. + +```php +S::create($str, $encoding)->padLeft($length, $padStr); +S::padLeft('foo bar', 9, ' '); // ' foo bar' +``` + +#### padRight + +$stringy->padRight(int $length [, string $padStr = ' ' ]) + +S::padRight(string $str , int $length [, string $padStr = ' ' [, string $encoding ]]) + +Returns a new string of a given length such that the end of the string is +padded. Alias for pad() with a $padType of 'right'. + +```php +S::create('foo bar')->padRight(10, '_*'); +S::padRight('foo bar', 10, '_*'); // 'foo bar_*_' +``` + +#### regexReplace + +$stringy->regexReplace(string $pattern, string $replacement [, string $options = 'msr']) + +S::regexReplace(string $str, string $pattern, string $replacement [, string $options = 'msr' [, string $encoding ]]) + +Replaces all occurrences of $pattern in $str by $replacement. An alias +for mb_ereg_replace(). Note that the 'i' option with multibyte patterns +in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support +in the bundled version of Oniguruma in PHP 5.3. + +```php +S::create('fòô ', 'UTF-8')->regexReplace('f[òô]+\s', 'bàř', 'msr'); +S::regexReplace('fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'); // 'bàř' +``` + +#### removeLeft + +$stringy->removeLeft(string $substring) + +S::removeLeft(string $str, string $substring [, string $encoding ]) + +Returns a new string with the prefix $substring removed, if present. + +```php +S::create('fòô bàř', 'UTF-8')->removeLeft('fòô '); +S::removeLeft('fòô bàř', 'fòô ', 'UTF-8'); // 'bàř' +``` + +#### removeRight + +$stringy->removeRight(string $substring) + +S::removeRight(string $str, string $substring [, string $encoding ]) + +Returns a new string with the suffix $substring removed, if present. + +```php +S::create('fòô bàř', 'UTF-8')->removeRight(' bàř'); +S::removeRight('fòô bàř', ' bàř', 'UTF-8'); // 'fòô' +``` + +#### replace + +$stringy->replace(string $search, string $replacement) + +S::replace(string $str, string $search, string $replacement [, string $encoding ]) + +Replaces all occurrences of $search in $str by $replacement. + +```php +S::create('fòô bàř fòô bàř', 'UTF-8')->replace('fòô ', ''); +S::replace('fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'); // 'bàř bàř' +``` + +#### reverse + +$stringy->reverse() + +S::reverse(string $str [, string $encoding ]) + +Returns a reversed string. A multibyte version of strrev(). + +```php +S::create('fòô bàř', 'UTF-8')->reverse(); +S::reverse('fòô bàř', 'UTF-8'); // 'řàb ôòf' +``` + +#### safeTruncate + +$stringy->safeTruncate(int $length [, string $substring = '' ]) + +S::safeTruncate(string $str, int $length [, string $substring = '' [, string $encoding ]]) + +Truncates the string to a given length, while ensuring that it does not +split words. If $substring is provided, and truncating occurs, the +string is further truncated so that the substring may be appended without +exceeding the desired length. + +```php +S::create('What are your plans today?')->safeTruncate(22, '...'); +S::safeTruncate('What are your plans today?', 22, '...'); // 'What are your plans...' +``` + +#### shuffle + +$stringy->shuffle() + +S::shuffle(string $str [, string $encoding ]) + +A multibyte str_shuffle() function. It returns a string with its characters in +random order. + +```php +S::create('fòô bàř', 'UTF-8')->shuffle(); +S::shuffle('fòô bàř', 'UTF-8'); // 'àôřb òf' +``` + +#### slugify + +$stringy->slugify([ string $replacement = '-' ]) + +S::slugify(string $str [, string $replacement = '-' ]) + +Converts the string into an URL slug. This includes replacing non-ASCII +characters with their closest ASCII equivalents, removing remaining +non-ASCII and non-alphanumeric characters, and replacing whitespace with +$replacement. The replacement defaults to a single dash, and the string +is also converted to lowercase. + +```php +S::create('Using strings like fòô bàř')->slugify(); +S::slugify('Using strings like fòô bàř'); // 'using-strings-like-foo-bar' +``` + +#### startsWith + +$stringy->startsWith(string $substring [, boolean $caseSensitive = true ]) + +S::startsWith(string $str, string $substring [, boolean $caseSensitive = true [, string $encoding ]]) + +Returns true if the string begins with $substring, false otherwise. +By default, the comparison is case-sensitive, but can be made insensitive +by setting $caseSensitive to false. + +```php +S::create('FÒÔ bàřs', 'UTF-8')->startsWith('fòô bàř', false); +S::startsWith('FÒÔ bàřs', 'fòô bàř', false, 'UTF-8'); // true +``` + +#### substr + +$stringy->substr(int $start [, int $length ]) + +S::substr(string $str, int $start [, int $length [, string $encoding ]]) + +Returns the substring beginning at $start with the specified $length. +It differs from the mb_substr() function in that providing a $length of +null will return the rest of the string, rather than an empty string. + +```php +S::create('fòô bàř', 'UTF-8')->substr(2, 3); +S::substr('fòô bàř', 2, 3, 'UTF-8'); // 'ô b' +``` + +#### surround + +$stringy->surround(string $substring) + +S::surround(string $str, string $substring) + +Surrounds a string with the given substring. + +```php +S::create(' ͜ ')->surround('ʘ'); +S::surround(' ͜ ', 'ʘ'); // 'ʘ ͜ ʘ' +``` + +#### swapCase + +$stringy->swapCase(); + +S::swapCase(string $str [, string $encoding ]) + +Returns a case swapped version of the string. + +```php +S::create('Ντανιλ', 'UTF-8')->swapCase(); +S::swapCase('Ντανιλ', 'UTF-8'); // 'νΤΑΝΙΛ' +``` + +#### tidy + +$stringy->tidy() + +S::tidy(string $str) + +Returns a string with smart quotes, ellipsis characters, and dashes from +Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents. + +```php +S::create('“I see…”')->tidy(); +S::tidy('“I see…”'); // '"I see..."' +``` + +#### titleize + +$stringy->titleize([ string $encoding ]) + +S::titleize(string $str [, array $ignore [, string $encoding ]]) + +Returns a trimmed string with the first letter of each word capitalized. +Ignores the case of other letters, preserving any acronyms. Also accepts +an array, $ignore, allowing you to list words not to be capitalized. + +```php +$ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'); +S::create('i like to watch DVDs at home', 'UTF-8')->titleize($ignore); +S::titleize('i like to watch DVDs at home', $ignore, 'UTF-8'); +// 'I Like to Watch DVDs at Home' +``` + +#### toAscii + +$stringy->toAscii() + +S::toAscii(string $str [, boolean $removeUnsupported = true]) + +Returns an ASCII version of the string. A set of non-ASCII characters are +replaced with their closest ASCII counterparts, and the rest are removed +unless instructed otherwise. + +```php +S::create('fòô bàř')->toAscii(); +S::toAscii('fòô bàř'); // 'foo bar' +``` + +#### toLowerCase + +$stringy->toLowerCase() + +S::toLowerCase(string $str [, string $encoding ]) + +Converts all characters in the string to lowercase. An alias for PHP's +mb_strtolower(). + +```php +S::create('FÒÔ BÀŘ', 'UTF-8')->toLowerCase(); +S::toLowerCase('FÒÔ BÀŘ', 'UTF-8'); // 'fòô bàř' +``` + +#### toSpaces + +$stringy->toSpaces([ tabLength = 4 ]) + +S::toSpaces(string $str [, int $tabLength = 4 ]) + +Converts each tab in the string to some number of spaces, as defined by +$tabLength. By default, each tab is converted to 4 consecutive spaces. + +```php +S::create(' String speech = "Hi"')->toSpaces(); +S::toSpaces(' String speech = "Hi"'); // ' String speech = "Hi"' +``` + +#### toTabs + +$stringy->toTabs([ tabLength = 4 ]) + +S::toTabs(string $str [, int $tabLength = 4 ]) + +Converts each occurrence of some consecutive number of spaces, as defined +by $tabLength, to a tab. By default, each 4 consecutive spaces are +converted to a tab. + +```php +S::create(' fòô bàř')->toTabs(); +S::toTabs(' fòô bàř'); // ' fòô bàř' +``` + +#### toTitleCase + +$stringy->toTitleCase() + +S::toTitleCase(string $str [, string $encoding ]) + +Converts the first character of each word in the string to uppercase. + +```php +S::create('fòô bàř', 'UTF-8')->toTitleCase(); +S::toTitleCase('fòô bàř', 'UTF-8'); // 'Fòô Bàř' +``` + +#### toUpperCase + +$stringy->toUpperCase() + +S::toUpperCase(string $str [, string $encoding ]) + +Converts all characters in the string to uppercase. An alias for PHP's +mb_strtoupper(). + +```php +S::create('fòô bàř', 'UTF-8')->toUpperCase(); +S::toUpperCase('fòô bàř', 'UTF-8'); // 'FÒÔ BÀŘ' +``` + +#### trim + +$stringy->trim() + +S::trim(string $str) + +Returns the trimmed string. An alias for PHP's trim() function. + +```php +S::create('fòô bàř', 'UTF-8')->trim(); +S::trim(' fòô bàř '); // 'fòô bàř' +``` + +#### truncate + +$stringy->truncate(int $length [, string $substring = '' ]) + +S::truncate(string $str, int $length [, string $substring = '' [, string $encoding ]]) + +Truncates the string to a given length. If $substring is provided, and +truncating occurs, the string is further truncated so that the substring +may be appended without exceeding the desired length. + +```php +S::create('What are your plans today?')->truncate(19, '...'); +S::truncate('What are your plans today?', 19, '...'); // 'What are your pl...' +``` + +#### underscored + +$stringy->underscored(); + +S::underscored(string $str [, string $encoding ]) + +Returns a lowercase and trimmed string separated by underscores. +Underscores are inserted before uppercase characters (with the exception +of the first character of the string), and in place of spaces as well as dashes. + +```php +S::create('TestUCase')->underscored(); +S::underscored('TestUCase'); // 'test_u_case' +``` + +#### upperCamelize + +$stringy->upperCamelize(); + +S::upperCamelize(string $str [, string $encoding ]) + +Returns an UpperCamelCase version of the supplied string. It trims +surrounding spaces, capitalizes letters following digits, spaces, dashes +and underscores, and removes spaces, dashes, underscores. + +```php +S::create('Upper Camel-Case')->upperCamelize(); +S::upperCamelize('Upper Camel-Case'); // 'UpperCamelCase' +``` + +#### upperCaseFirst + +$stringy->upperCaseFirst(); + +S::upperCaseFirst(string $str [, string $encoding ]) + +Converts the first character of the supplied string to upper case. + +```php +S::create('σ test', 'UTF-8')->upperCaseFirst(); +S::upperCaseFirst('σ test', 'UTF-8'); // 'Σ test' +``` + +## Links + +The following is a list of libraries that extend Stringy: + + * [SliceableStringy](https://github.com/danielstjules/SliceableStringy): +Python-like string slices in PHP + +## Tests + +From the project directory, tests can be ran using `phpunit` + +## License + +Released under the MIT License - see `LICENSE.txt` for details. diff --git a/vendor/danielstjules/stringy/composer.json b/vendor/danielstjules/stringy/composer.json new file mode 100755 index 0000000..f71f252 --- /dev/null +++ b/vendor/danielstjules/stringy/composer.json @@ -0,0 +1,35 @@ +{ + "name": "danielstjules/stringy", + "description": "A string manipulation library with multibyte support", + "keywords": [ + "multibyte", "string", "manipulation", "utility", "methods", "utf-8", + "helpers", "utils", "utf" + ], + "homepage": "https://github.com/danielstjules/Stringy", + "license": "MIT", + "authors": [ + { + "name": "Daniel St. Jules", + "email": "danielst.jules@gmail.com", + "homepage": "http://www.danielstjules.com" + } + ], + "require": { + "php": ">=5.3.0", + "ext-mbstring": "*" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "support": { + "issues": "https://github.com/danielstjules/Stringy/issues", + "source": "https://github.com/danielstjules/Stringy" + }, + "autoload": { + "psr-4": { "Stringy\\": "src/" }, + "files": ["src/Create.php"] + }, + "autoload-dev": { + "classmap": [ "tests" ] + } +} diff --git a/vendor/danielstjules/stringy/phpunit.xml.dist b/vendor/danielstjules/stringy/phpunit.xml.dist new file mode 100755 index 0000000..987dbbf --- /dev/null +++ b/vendor/danielstjules/stringy/phpunit.xml.dist @@ -0,0 +1,14 @@ + + + + + + tests/CommonTest.php + tests/StringyTest.php + tests/StaticStringyTest.php + tests/CreateTest.php + + + diff --git a/vendor/danielstjules/stringy/src/Create.php b/vendor/danielstjules/stringy/src/Create.php new file mode 100755 index 0000000..c6a2f44 --- /dev/null +++ b/vendor/danielstjules/stringy/src/Create.php @@ -0,0 +1,19 @@ +chars(); + } + + /** + * Converts the first character of the supplied string to upper case. + * + * @param string $str String to modify + * @param string $encoding The character encoding + * @return string String with the first character being upper case + */ + public static function upperCaseFirst($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->upperCaseFirst(); + } + + /** + * Converts the first character of the supplied string to lower case. + * + * @param string $str String to modify + * @param string $encoding The character encoding + * @return string String with the first character being lower case + */ + public static function lowerCaseFirst($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->lowerCaseFirst(); + } + + /** + * Returns a camelCase version of the string. Trims surrounding spaces, + * capitalizes letters following digits, spaces, dashes and underscores, + * and removes spaces, dashes, as well as underscores. + * + * @param string $str String to convert to camelCase + * @param string $encoding The character encoding + * @return string String in camelCase + */ + public static function camelize($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->camelize(); + } + + /** + * Returns an UpperCamelCase version of the supplied string. It trims + * surrounding spaces, capitalizes letters following digits, spaces, dashes + * and underscores, and removes spaces, dashes, underscores. + * + * @param string $str String to convert to UpperCamelCase + * @param string $encoding The character encoding + * @return string String in UpperCamelCase + */ + public static function upperCamelize($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->upperCamelize(); + } + + /** + * Returns a lowercase and trimmed string separated by dashes. Dashes are + * inserted before uppercase characters (with the exception of the first + * character of the string), and in place of spaces as well as underscores. + * + * @param string $str String to convert + * @param string $encoding The character encoding + * @return string Dasherized string + */ + public static function dasherize($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->dasherize(); + } + + /** + * Returns a lowercase and trimmed string separated by underscores. + * Underscores are inserted before uppercase characters (with the exception + * of the first character of the string), and in place of spaces as well as + * dashes. + * + * @param string $str String to convert + * @param string $encoding The character encoding + * @return string Underscored string + */ + public static function underscored($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->underscored(); + } + + /** + * Returns a case swapped version of the string. + * + * @param string $str String to swap case + * @param string $encoding The character encoding + * @return string String with each character's case swapped + */ + public static function swapCase($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->swapCase(); + } + + /** + * Returns a trimmed string with the first letter of each word capitalized. + * Ignores the case of other letters, preserving any acronyms. Also accepts + * an array, $ignore, allowing you to list words not to be capitalized. + * + * @param string $str String to titleize + * @param string $encoding The character encoding + * @param array $ignore An array of words not to capitalize + * @return string Titleized string + */ + public static function titleize($str, $ignore = null, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->titleize($ignore); + } + + /** + * Capitalizes the first word of the string, replaces underscores with + * spaces, and strips '_id'. + * + * @param string $str String to humanize + * @param string $encoding The character encoding + * @return string A humanized string + */ + public static function humanize($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->humanize(); + } + + /** + * Returns a string with smart quotes, ellipsis characters, and dashes from + * Windows-1252 (commonly used in Word documents) replaced by their ASCII + * equivalents. + * + * @param string $str String to remove special chars + * @return string String with those characters removed + */ + public static function tidy($str) + { + return (string) Stringy::create($str)->tidy(); + } + + /** + * Trims the string and replaces consecutive whitespace characters with a + * single space. This includes tabs and newline characters, as well as + * multibyte whitespace such as the thin space and ideographic space. + * + * @param string $str The string to cleanup whitespace + * @param string $encoding The character encoding + * @return string The trimmed string with condensed whitespace + */ + public static function collapseWhitespace($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->collapseWhitespace(); + } + + /** + * Returns an ASCII version of the string. A set of non-ASCII characters are + * replaced with their closest ASCII counterparts, and the rest are removed + * unless instructed otherwise. + * + * @param string $str A string with non-ASCII characters + * @param bool $removeUnsupported Whether or not to remove the + * unsupported characters + * @return string A string containing only ASCII characters + */ + public static function toAscii($str, $removeUnsupported = true) + { + return (string) Stringy::create($str)->toAscii($removeUnsupported); + } + + /** + * Pads the string to a given length with $padStr. If length is less than + * or equal to the length of the string, no padding takes places. The + * default string used for padding is a space, and the default type (one of + * 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException + * if $padType isn't one of those 3 values. + * + * @param string $str String to pad + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @param string $padType One of 'left', 'right', 'both' + * @param string $encoding The character encoding + * @return string The padded string + * @throws \InvalidArgumentException If $padType isn't one of 'right', + * 'left' or 'both' + */ + public static function pad($str, $length, $padStr = ' ', $padType = 'right', + $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->pad($length, $padStr, $padType); + } + + /** + * Returns a new string of a given length such that the beginning of the + * string is padded. Alias for pad() with a $padType of 'left'. + * + * @param string $str String to pad + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @param string $encoding The character encoding + * @return string The padded string + */ + public static function padLeft($str, $length, $padStr = ' ', $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->padLeft($length, $padStr); + } + + /** + * Returns a new string of a given length such that the end of the string + * is padded. Alias for pad() with a $padType of 'right'. + * + * @param string $str String to pad + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @param string $encoding The character encoding + * @return string The padded string + */ + public static function padRight($str, $length, $padStr = ' ', $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->padRight($length, $padStr); + } + + /** + * Returns a new string of a given length such that both sides of the + * string are padded. Alias for pad() with a $padType of 'both'. + * + * @param string $str String to pad + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @param string $encoding The character encoding + * @return string The padded string + */ + public static function padBoth($str, $length, $padStr = ' ', $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->padBoth($length, $padStr); + } + + /** + * Returns true if the string begins with $substring, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $str String to check the start of + * @param string $substring The substring to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @param string $encoding The character encoding + * @return bool Whether or not $str starts with $substring + */ + public static function startsWith($str, $substring, $caseSensitive = true, + $encoding = null) + { + return Stringy::create($str, $encoding) + ->startsWith($substring, $caseSensitive); + } + + /** + * Returns true if the string ends with $substring, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $str String to check the end of + * @param string $substring The substring to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @param string $encoding The character encoding + * @return bool Whether or not $str ends with $substring + */ + public static function endsWith($str, $substring, $caseSensitive = true, + $encoding = null) + { + return Stringy::create($str, $encoding) + ->endsWith($substring, $caseSensitive); + } + + /** + * Converts each tab in the string to some number of spaces, as defined by + * $tabLength. By default, each tab is converted to 4 consecutive spaces. + * + * @param string $str String to convert tabs to spaces + * @param int $tabLength Number of spaces to replace each tab with + * @return string String with tabs switched to spaces + */ + public static function toSpaces($str, $tabLength = 4) + { + return (string) Stringy::create($str)->toSpaces($tabLength); + } + + /** + * Converts each occurrence of some consecutive number of spaces, as + * defined by $tabLength, to a tab. By default, each 4 consecutive spaces + * are converted to a tab. + * + * @param string $str String to convert spaces to tabs + * @param int $tabLength Number of spaces to replace with a tab + * @return string String with spaces switched to tabs + */ + public static function toTabs($str, $tabLength = 4) + { + return (string) Stringy::create($str)->toTabs($tabLength); + } + + /** + * Converts all characters in the string to lowercase. An alias for PHP's + * mb_strtolower(). + * + * @param string $str String to convert case + * @param string $encoding The character encoding + * @return string The lowercase string + */ + public static function toLowerCase($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->toLowerCase(); + } + + /** + * Converts the first character of each word in the string to uppercase. + * + * @param string $str String to convert case + * @param string $encoding The character encoding + * @return string The title-cased string + */ + public static function toTitleCase($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->toTitleCase(); + } + + /** + * Converts all characters in the string to uppercase. An alias for PHP's + * mb_strtoupper(). + * + * @param string $str String to convert case + * @param string $encoding The character encoding + * @return string The uppercase string + */ + public static function toUpperCase($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->toUpperCase(); + } + + /** + * Converts the string into an URL slug. This includes replacing non-ASCII + * characters with their closest ASCII equivalents, removing remaining + * non-ASCII and non-alphanumeric characters, and replacing whitespace with + * $replacement. The replacement defaults to a single dash, and the string + * is also converted to lowercase. + * + * @param string $str Text to transform into an URL slug + * @param string $replacement The string used to replace whitespace + * @return string The corresponding URL slug + */ + public static function slugify($str, $replacement = '-') + { + return (string) Stringy::create($str)->slugify($replacement); + } + + /** + * Returns true if the string contains $needle, false otherwise. By default, + * the comparison is case-sensitive, but can be made insensitive by setting + * $caseSensitive to false. + * + * @param string $haystack String being checked + * @param string $needle Substring to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @param string $encoding The character encoding + * @return bool Whether or not $haystack contains $needle + */ + public static function contains($haystack, $needle, $caseSensitive = true, + $encoding = null) + { + return Stringy::create($haystack, $encoding) + ->contains($needle, $caseSensitive); + } + + /** + * Returns true if the string contains any $needles, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $haystack String being checked + * @param array $needles Substrings to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @param string $encoding The character encoding + * @return bool Whether or not $haystack contains any $needles + */ + public static function containsAny($haystack, $needles, + $caseSensitive = true, $encoding = null) + { + return Stringy::create($haystack, $encoding) + ->containsAny($needles, $caseSensitive); + } + + /** + * Returns true if the string contains all $needles, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $haystack String being checked + * @param array $needles Substrings to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @param string $encoding The character encoding + * @return bool Whether or not $haystack contains all $needles + */ + public static function containsAll($haystack, $needles, + $caseSensitive = true, $encoding = null) + { + return Stringy::create($haystack, $encoding) + ->containsAll($needles, $caseSensitive); + } + + /** + * Surrounds a string with the given substring. + * + * @param string $str The string to surround + * @param string $substring The substring to add to both sides + * @return string The string with the substring prepended and appended + */ + public static function surround($str, $substring) + { + return (string) Stringy::create($str)->surround($substring); + } + + /** + * Inserts $substring into the string at the $index provided. + * + * @param string $str String to insert into + * @param string $substring String to be inserted + * @param int $index The index at which to insert the substring + * @param string $encoding The character encoding + * @return string The resulting string after the insertion + */ + public static function insert($str, $substring, $index, $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->insert($substring, $index); + } + + /** + * Truncates the string to a given length. If $substring is provided, and + * truncating occurs, the string is further truncated so that the substring + * may be appended without exceeding the desired length. + * + * @param string $str String to truncate + * @param int $length Desired length of the truncated string + * @param string $substring The substring to append if it can fit + * @param string $encoding The character encoding + * @return string The resulting string after truncating + */ + public static function truncate($str, $length, $substring = '', + $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->truncate($length, $substring); + } + + /** + * Truncates the string to a given length, while ensuring that it does not + * split words. If $substring is provided, and truncating occurs, the + * string is further truncated so that the substring may be appended without + * exceeding the desired length. + * + * @param string $str String to truncate + * @param int $length Desired length of the truncated string + * @param string $substring The substring to append if it can fit + * @param string $encoding The character encoding + * @return string The resulting string after truncating + */ + public static function safeTruncate($str, $length, $substring = '', + $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->safeTruncate($length, $substring); + } + + /** + * Returns a reversed string. A multibyte version of strrev(). + * + * @param string $str String to reverse + * @param string $encoding The character encoding + * @return string The reversed string + */ + public static function reverse($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->reverse(); + } + + /** + * A multibyte str_shuffle() function. It returns a string with its + * characters in random order. + * + * @param string $str String to shuffle + * @param string $encoding The character encoding + * @return string The shuffled string + */ + public static function shuffle($str, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->shuffle(); + } + + /** + * Returns the trimmed string. An alias for PHP's trim() function. + * + * @param string $str String to trim + * @return string Trimmed $str + */ + public static function trim($str) + { + return trim($str); + } + + /** + * Returns the longest common prefix between the string and $otherStr. + * + * @param string $str First string for comparison + * @param string $otherStr Second string for comparison + * @param string $encoding The character encoding + * @return string The longest common prefix + */ + public static function longestCommonPrefix($str, $otherStr, $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->longestCommonPrefix($otherStr); + } + + /** + * Returns the longest common suffix between the string and $otherStr. + * + * @param string $str First string for comparison + * @param string $otherStr Second string for comparison + * @param string $encoding The character encoding + * @return string The longest common suffix + */ + public static function longestCommonSuffix($str, $otherStr, $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->longestCommonSuffix($otherStr); + } + + /** + * Returns the longest common substring between the string and $otherStr. + * In the case of ties, it returns that which occurs first. + * + * @param string $str First string for comparison + * @param string $otherStr Second string for comparison + * @param string $encoding The character encoding + * @return string The longest common substring + */ + public static function longestCommonSubstring($str, $otherStr, + $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->longestCommonSubstring($otherStr); + } + + /** + * Returns the length of the string. An alias for PHP's mb_strlen() function. + * + * @param string $str The string to get the length of + * @param string $encoding The character encoding + * @return int The number of characters in $str given the encoding + */ + public static function length($str, $encoding = null) + { + return Stringy::create($str, $encoding)->length(); + } + + /** + * Returns the substring beginning at $start with the specified $length. + * It differs from the mb_substr() function in that providing a $length of + * null will return the rest of the string, rather than an empty string. + * + * @param string $str The string to get the length of + * @param int $start Position of the first character to use + * @param int $length Maximum number of characters used + * @param string $encoding The character encoding + * @return string The substring of $str + */ + public static function substr($str, $start, $length = null, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->substr($start, $length); + } + + /** + * Returns the character at $index, with indexes starting at 0. + * + * @param string $str The string from which to get the char + * @param int $index Position of the character + * @param string $encoding The character encoding + * @return string The character at $index + */ + public static function at($str, $index, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->at($index); + } + + /** + * Returns the first $n characters of the string. + * + * @param string $str The string from which to get the substring + * @param int $n Number of chars to retrieve from the start + * @param string $encoding The character encoding + * @return string The first $n characters + */ + public static function first($str, $n, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->first($n); + } + + /** + * Returns the last $n characters of the string. + * + * @param string $str The string from which to get the substring + * @param int $n Number of chars to retrieve from the end + * @param string $encoding The character encoding + * @return string The last $n characters + */ + public static function last($str, $n, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->last($n); + } + + /** + * Ensures that the string begins with $substring. If it doesn't, it's + * prepended. + * + * @param string $str The string to modify + * @param string $substring The substring to add if not present + * @param string $encoding The character encoding + * @return string The string prefixed by the $substring + */ + public static function ensureLeft($str, $substring, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->ensureLeft($substring); + } + + /** + * Ensures that the string begins with $substring. If it doesn't, it's + * appended. + * + * @param string $str The string to modify + * @param string $substring The substring to add if not present + * @param string $encoding The character encoding + * @return string The string suffixed by the $substring + */ + public static function ensureRight($str, $substring, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->ensureRight($substring); + } + + /** + * Returns a new string with the prefix $substring removed, if present. + * + * @param string $str String from which to remove the prefix + * @param string $substring The prefix to remove + * @param string $encoding The character encoding + * @return string The string without the prefix $substring + */ + public static function removeLeft($str, $substring, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->removeLeft($substring); + } + + /** + * Returns a new string with the suffix $substring removed, if present. + * + * @param string $str String from which to remove the suffix + * @param string $substring The suffix to remove + * @param string $encoding The character encoding + * @return string The string without the suffix $substring + */ + public static function removeRight($str, $substring, $encoding = null) + { + return (string) Stringy::create($str, $encoding)->removeRight($substring); + } + + /** + * Returns true if the string contains a lower case char, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains a lower case character. + */ + public static function hasLowerCase($str, $encoding = null) + { + return Stringy::create($str, $encoding)->hasLowerCase(); + } + + /** + * Returns true if the string contains an upper case char, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains an upper case character. + */ + public static function hasUpperCase($str, $encoding = null) + { + return Stringy::create($str, $encoding)->hasUpperCase(); + } + + /** + * Returns true if the string contains only alphabetic chars, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains only alphabetic chars + */ + public static function isAlpha($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isAlpha(); + } + + /** + * Returns true if the string contains only alphabetic and numeric chars, + * false otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains only alphanumeric chars + */ + public static function isAlphanumeric($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isAlphanumeric(); + } + + /** + * Returns true if the string contains only whitespace chars, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains only whitespace characters + */ + public static function isBlank($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isBlank(); + } + + /** + * Returns true if the string is JSON, false otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str is JSON + */ + public static function isJson($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isJson(); + } + + /** + * Returns true if the string contains only lower case chars, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains only lower case characters + */ + public static function isLowerCase($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isLowerCase(); + } + + /** + * Returns true if the string is serialized, false otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str is serialized + */ + public static function isSerialized($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isSerialized(); + } + + /** + * Returns true if the string contains only upper case chars, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains only upper case characters + */ + public static function isUpperCase($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isUpperCase(); + } + + /** + * Returns true if the string contains only hexadecimal chars, false + * otherwise. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains only hexadecimal characters + */ + public static function isHexadecimal($str, $encoding = null) + { + return Stringy::create($str, $encoding)->isHexadecimal(); + } + + /** + * Returns the number of occurrences of $substring in the given string. + * By default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $str The string to search through + * @param string $substring The substring to search for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @param string $encoding The character encoding + * @return int The number of $substring occurrences + */ + public static function countSubstr($str, $substring, $caseSensitive = true, + $encoding = null) + { + return Stringy::create($str, $encoding) + ->countSubstr($substring, $caseSensitive); + } + + /** + * Replaces all occurrences of $search in $str by $replacement. + * + * @param string $str The haystack to search through + * @param string $search The needle to search for + * @param string $replacement The string to replace with + * @param string $encoding The character encoding + * @return string The resulting string after the replacements + */ + public static function replace($str, $search, $replacement, $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->replace($search, $replacement); + } + + /** + * Replaces all occurrences of $pattern in $str by $replacement. An alias + * for mb_ereg_replace(). Note that the 'i' option with multibyte patterns + * in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support + * in the bundled version of Oniguruma in PHP 5.3. + * + * @param string $str The haystack to search through + * @param string $pattern The regular expression pattern + * @param string $replacement The string to replace with + * @param string $options Matching conditions to be used + * @param string $encoding The character encoding + * @return string The resulting string after the replacements + */ + public static function regexReplace($str, $pattern, $replacement, + $options = 'msr', $encoding = null) + { + return (string) Stringy::create($str, $encoding) + ->regexReplace($pattern, $replacement, $options, $encoding); + } +} diff --git a/vendor/danielstjules/stringy/src/Stringy.php b/vendor/danielstjules/stringy/src/Stringy.php new file mode 100755 index 0000000..785145a --- /dev/null +++ b/vendor/danielstjules/stringy/src/Stringy.php @@ -0,0 +1,1464 @@ +str = (string) $str; + $this->encoding = $encoding ?: mb_internal_encoding(); + } + + /** + * Creates a Stringy object and assigns both str and encoding properties + * the supplied values. $str is cast to a string prior to assignment, and if + * $encoding is not specified, it defaults to mb_internal_encoding(). It + * then returns the initialized object. Throws an InvalidArgumentException + * if the first argument is an array or object without a __toString method. + * + * @param mixed $str Value to modify, after being cast to string + * @param string $encoding The character encoding + * @return Stringy A Stringy object + * @throws \InvalidArgumentException if an array or object without a + * __toString method is passed as the first argument + */ + public static function create($str, $encoding = null) + { + return new static($str, $encoding); + } + + /** + * Returns the value in $str. + * + * @return string The current value of the $str property + */ + public function __toString() + { + return $this->str; + } + + /** + * Returns the encoding used by the Stringy object. + * + * @return string The current value of the $encoding property + */ + public function getEncoding() + { + return $this->encoding; + } + + /** + * Returns the length of the string, implementing the countable interface. + * + * @return int The number of characters in the string, given the encoding + */ + public function count() + { + return $this->length(); + } + + /** + * Returns a new ArrayIterator, thus implementing the IteratorAggregate + * interface. The ArrayIterator's constructor is passed an array of chars + * in the multibyte string. This enables the use of foreach with instances + * of Stringy\Stringy. + * + * @return \ArrayIterator An iterator for the characters in the string + */ + public function getIterator() + { + return new \ArrayIterator($this->chars()); + } + + /** + * Returns whether or not a character exists at an index. Offsets may be + * negative to count from the last character in the string. Implements + * part of the ArrayAccess interface. + * + * @param mixed $offset The index to check + * @return boolean Whether or not the index exists + */ + public function offsetExists($offset) + { + $length = $this->length(); + $offset = (int) $offset; + + if ($offset >= 0) { + return ($length > $offset); + } + + return ($length >= abs($offset)); + } + + /** + * Returns the character at the given index. Offsets may be negative to + * count from the last character in the string. Implements part of the + * ArrayAccess interface, and throws an OutOfBoundsException if the index + * does not exist. + * + * @param mixed $offset The index from which to retrieve the char + * @return mixed The character at the specified index + * @throws \OutOfBoundsException If the positive or negative offset does + * not exist + */ + public function offsetGet($offset) + { + $offset = (int) $offset; + $length = $this->length(); + + if (($offset >= 0 && $length <= $offset) || $length < abs($offset)) { + throw new \OutOfBoundsException('No character exists at the index'); + } + + return mb_substr($this->str, $offset, 1, $this->encoding); + } + + /** + * Implements part of the ArrayAccess interface, but throws an exception + * when called. This maintains the immutability of Stringy objects. + * + * @param mixed $offset The index of the character + * @param mixed $value Value to set + * @throws \Exception When called + */ + public function offsetSet($offset, $value) + { + // Stringy is immutable, cannot directly set char + throw new \Exception('Stringy object is immutable, cannot modify char'); + } + + /** + * Implements part of the ArrayAccess interface, but throws an exception + * when called. This maintains the immutability of Stringy objects. + * + * @param mixed $offset The index of the character + * @throws \Exception When called + */ + public function offsetUnset($offset) + { + // Don't allow directly modifying the string + throw new \Exception('Stringy object is immutable, cannot unset char'); + } + + /** + * Returns an array consisting of the characters in the string. + * + * @return array An array of string chars + */ + public function chars() + { + $chars = array(); + for ($i = 0, $l = $this->length(); $i < $l; $i++) { + $chars[] = $this->at($i)->str; + } + + return $chars; + } + + /** + * Converts the first character of the supplied string to upper case. + * + * @return Stringy Object with the first character of $str being upper case + */ + public function upperCaseFirst() + { + $first = mb_substr($this->str, 0, 1, $this->encoding); + $rest = mb_substr($this->str, 1, $this->length() - 1, + $this->encoding); + + $str = mb_strtoupper($first, $this->encoding) . $rest; + + return static::create($str, $this->encoding); + } + + /** + * Converts the first character of the string to lower case. + * + * @return Stringy Object with the first character of $str being lower case + */ + public function lowerCaseFirst() + { + $first = mb_substr($this->str, 0, 1, $this->encoding); + $rest = mb_substr($this->str, 1, $this->length() - 1, + $this->encoding); + + $str = mb_strtolower($first, $this->encoding) . $rest; + + return static::create($str, $this->encoding); + } + + /** + * Returns a camelCase version of the string. Trims surrounding spaces, + * capitalizes letters following digits, spaces, dashes and underscores, + * and removes spaces, dashes, as well as underscores. + * + * @return Stringy Object with $str in camelCase + */ + public function camelize() + { + $encoding = $this->encoding; + $stringy = $this->trim()->lowerCaseFirst(); + + $camelCase = preg_replace_callback( + '/[-_\s]+(.)?/u', + function ($match) use ($encoding) { + return $match[1] ? mb_strtoupper($match[1], $encoding) : ''; + }, + $stringy->str + ); + + $stringy->str = preg_replace_callback( + '/[\d]+(.)?/u', + function ($match) use ($encoding) { + return mb_strtoupper($match[0], $encoding); + }, + $camelCase + ); + + return $stringy; + } + + /** + * Returns an UpperCamelCase version of the supplied string. It trims + * surrounding spaces, capitalizes letters following digits, spaces, dashes + * and underscores, and removes spaces, dashes, underscores. + * + * @return Stringy Object with $str in UpperCamelCase + */ + public function upperCamelize() + { + return $this->camelize()->upperCaseFirst(); + } + + /** + * Returns a lowercase and trimmed string separated by dashes. Dashes are + * inserted before uppercase characters (with the exception of the first + * character of the string), and in place of spaces as well as underscores. + * + * @return Stringy Object with a dasherized $str + */ + public function dasherize() + { + return $this->applyDelimiter('-'); + } + + /** + * Returns a lowercase and trimmed string separated by underscores. + * Underscores are inserted before uppercase characters (with the exception + * of the first character of the string), and in place of spaces as well as + * dashes. + * + * @return Stringy Object with an underscored $str + */ + public function underscored() + { + return $this->applyDelimiter('_'); + } + + /** + * Returns a lowercase and trimmed string separated by the given delimiter. + * + * @param string $delimiter Sequence used to separate parts of the string + * @return Stringy Object with a delimited $str + */ + protected function applyDelimiter($delimiter) + { + // Save current regex encoding so we can reset it after + $regexEncoding = mb_regex_encoding(); + mb_regex_encoding($this->encoding); + + $str = mb_ereg_replace('\B([A-Z])', $delimiter .'\1', $this->trim()); + $str = mb_ereg_replace('[-_\s]+', $delimiter, $str); + $str = mb_strtolower($str, $this->encoding); + + mb_regex_encoding($regexEncoding); + + return static::create($str, $this->encoding); + } + + /** + * Returns a case swapped version of the string. + * + * @return Stringy Object whose $str has each character's case swapped + */ + public function swapCase() + { + $stringy = static::create($this->str, $this->encoding); + $encoding = $stringy->encoding; + + $stringy->str = preg_replace_callback( + '/[\S]/u', + function ($match) use ($encoding) { + if ($match[0] == mb_strtoupper($match[0], $encoding)) { + return mb_strtolower($match[0], $encoding); + } else { + return mb_strtoupper($match[0], $encoding); + } + }, + $stringy->str + ); + + return $stringy; + } + + /** + * Returns a trimmed string with the first letter of each word capitalized. + * Ignores the case of other letters, preserving any acronyms. Also accepts + * an array, $ignore, allowing you to list words not to be capitalized. + * + * @param array $ignore An array of words not to capitalize + * @return Stringy Object with a titleized $str + */ + public function titleize($ignore = null) + { + $buffer = $this->trim(); + $encoding = $this->encoding; + + $buffer = preg_replace_callback( + '/([\S]+)/u', + function ($match) use ($encoding, $ignore) { + if ($ignore && in_array($match[0], $ignore)) { + return $match[0]; + } else { + $stringy = new Stringy($match[0], $encoding); + return (string) $stringy->upperCaseFirst(); + } + }, + $buffer + ); + + return new Stringy($buffer, $encoding); + } + + /** + * Capitalizes the first word of the string, replaces underscores with + * spaces, and strips '_id'. + * + * @return Stringy Object with a humanized $str + */ + public function humanize() + { + $str = str_replace(array('_id', '_'), array('', ' '), $this->str); + + return static::create($str, $this->encoding)->trim()->upperCaseFirst(); + } + + /** + * Returns a string with smart quotes, ellipsis characters, and dashes from + * Windows-1252 (commonly used in Word documents) replaced by their ASCII + * equivalents. + * + * @return Stringy Object whose $str has those characters removed + */ + public function tidy() + { + $str = preg_replace(array( + '/\x{2026}/u', + '/[\x{201C}\x{201D}]/u', + '/[\x{2018}\x{2019}]/u', + '/[\x{2013}\x{2014}]/u', + ), array( + '...', + '"', + "'", + '-', + ), $this->str); + + return static::create($str, $this->encoding); + } + + /** + * Trims the string and replaces consecutive whitespace characters with a + * single space. This includes tabs and newline characters, as well as + * multibyte whitespace such as the thin space and ideographic space. + * + * @return Stringy Object with a trimmed $str and condensed whitespace + */ + public function collapseWhitespace() + { + return $this->regexReplace('[[:space:]]+', ' ')->trim(); + } + + /** + * Returns an ASCII version of the string. A set of non-ASCII characters are + * replaced with their closest ASCII counterparts, and the rest are removed + * unless instructed otherwise. + * + * @param bool $removeUnsupported Whether or not to remove the + * unsupported characters + * @return Stringy Object whose $str contains only ASCII characters + */ + public function toAscii($removeUnsupported = true) + { + $str = $this->str; + + foreach ($this->charsArray() as $key => $value) { + $str = str_replace($value, $key, $str); + } + + if ($removeUnsupported) { + $str = preg_replace('/[^\x20-\x7E]/u', '', $str); + } + + return static::create($str, $this->encoding); + } + + /** + * Returns the replacements for the toAscii() method. + * + * @return array An array of replacements. + */ + protected function charsArray() + { + static $charsArray; + if (isset($charsArray)) return $charsArray; + + return $charsArray = array( + 'a' => array( + 'à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', + 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ä', 'ā', 'ą', + 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', + 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', + 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ'), + 'b' => array('б', 'β', 'Ъ', 'Ь', 'ب'), + 'c' => array('ç', 'ć', 'č', 'ĉ', 'ċ'), + 'd' => array('ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', + 'д', 'δ', 'د', 'ض'), + 'e' => array('é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', + 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', + 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', + 'є', 'ə'), + 'f' => array('ф', 'φ', 'ف'), + 'g' => array('ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ج'), + 'h' => array('ĥ', 'ħ', 'η', 'ή', 'ح', 'ه'), + 'i' => array('í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', + 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', + 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', + 'ῗ', 'і', 'ї', 'и'), + 'j' => array('ĵ', 'ј', 'Ј'), + 'k' => array('ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك'), + 'l' => array('ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل'), + 'm' => array('м', 'μ', 'م'), + 'n' => array('ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن'), + 'o' => array('ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', + 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', + 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', + 'ö', 'о', 'و', 'θ'), + 'p' => array('п', 'π'), + 'r' => array('ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر'), + 's' => array('ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص'), + 't' => array('ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط'), + 'u' => array('ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', + 'ự', 'ü', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у'), + 'v' => array('в'), + 'w' => array('ŵ', 'ω', 'ώ'), + 'x' => array('χ'), + 'y' => array('ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', + 'ϋ', 'ύ', 'ΰ', 'ي'), + 'z' => array('ź', 'ž', 'ż', 'з', 'ζ', 'ز'), + 'aa' => array('ع'), + 'ae' => array('æ'), + 'ch' => array('ч'), + 'dj' => array('ђ', 'đ'), + 'dz' => array('џ'), + 'gh' => array('غ'), + 'kh' => array('х', 'خ'), + 'lj' => array('љ'), + 'nj' => array('њ'), + 'oe' => array('œ'), + 'ps' => array('ψ'), + 'sh' => array('ш'), + 'shch' => array('щ'), + 'ss' => array('ß'), + 'th' => array('þ', 'ث', 'ذ', 'ظ'), + 'ts' => array('ц'), + 'ya' => array('я'), + 'yu' => array('ю'), + 'zh' => array('ж'), + '(c)' => array('©'), + 'A' => array('Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', + 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Ä', 'Å', 'Ā', + 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', + 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', + 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'), + 'B' => array('Б', 'Β'), + 'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'), + 'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'), + 'E' => array('É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', + 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', + 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', + 'Є', 'Ə'), + 'F' => array('Ф', 'Φ'), + 'G' => array('Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'), + 'H' => array('Η', 'Ή'), + 'I' => array('Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', + 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', + 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї'), + 'K' => array('К', 'Κ'), + 'L' => array('Ĺ', 'Ł', 'Л', 'Λ', 'Ļ'), + 'M' => array('М', 'Μ'), + 'N' => array('Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'), + 'O' => array('Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', + 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ö', 'Ø', 'Ō', + 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', + 'Ὸ', 'Ό', 'О', 'Θ', 'Ө'), + 'P' => array('П', 'Π'), + 'R' => array('Ř', 'Ŕ', 'Р', 'Ρ'), + 'S' => array('Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'), + 'T' => array('Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'), + 'U' => array('Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', + 'Ự', 'Û', 'Ü', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У'), + 'V' => array('В'), + 'W' => array('Ω', 'Ώ'), + 'X' => array('Χ'), + 'Y' => array('Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', + 'Ы', 'Й', 'Υ', 'Ϋ'), + 'Z' => array('Ź', 'Ž', 'Ż', 'З', 'Ζ'), + 'AE' => array('Æ'), + 'CH' => array('Ч'), + 'DJ' => array('Ђ'), + 'DZ' => array('Џ'), + 'KH' => array('Х'), + 'LJ' => array('Љ'), + 'NJ' => array('Њ'), + 'PS' => array('Ψ'), + 'SH' => array('Ш'), + 'SHCH' => array('Щ'), + 'SS' => array('ẞ'), + 'TH' => array('Þ'), + 'TS' => array('Ц'), + 'YA' => array('Я'), + 'YU' => array('Ю'), + 'ZH' => array('Ж'), + ' ' => array("\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", + "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", + "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", + "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", + "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"), + ); + } + + /** + * Pads the string to a given length with $padStr. If length is less than + * or equal to the length of the string, no padding takes places. The + * default string used for padding is a space, and the default type (one of + * 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException + * if $padType isn't one of those 3 values. + * + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @param string $padType One of 'left', 'right', 'both' + * @return Stringy Object with a padded $str + * @throws InvalidArgumentException If $padType isn't one of 'right', + * 'left' or 'both' + */ + public function pad($length, $padStr = ' ', $padType = 'right') + { + if (!in_array($padType, array('left', 'right', 'both'))) { + throw new \InvalidArgumentException('Pad expects $padType ' . + "to be one of 'left', 'right' or 'both'"); + } + + switch ($padType) { + case 'left': + return $this->padLeft($length, $padStr); + case 'right': + return $this->padRight($length, $padStr); + default: + return $this->padBoth($length, $padStr); + } + } + + /** + * Returns a new string of a given length such that the beginning of the + * string is padded. Alias for pad() with a $padType of 'left'. + * + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @return Stringy String with left padding + */ + public function padLeft($length, $padStr = ' ') + { + return $this->applyPadding($length - $this->length(), 0, $padStr); + } + + /** + * Returns a new string of a given length such that the end of the string + * is padded. Alias for pad() with a $padType of 'right'. + * + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @return Stringy String with right padding + */ + public function padRight($length, $padStr = ' ') + { + return $this->applyPadding(0, $length - $this->length(), $padStr); + } + + /** + * Returns a new string of a given length such that both sides of the + * string are padded. Alias for pad() with a $padType of 'both'. + * + * @param int $length Desired string length after padding + * @param string $padStr String used to pad, defaults to space + * @return Stringy String with padding applied + */ + public function padBoth($length, $padStr = ' ') + { + $padding = $length - $this->length(); + + return $this->applyPadding(floor($padding / 2), ceil($padding / 2), + $padStr); + } + + /** + * Adds the specified amount of left and right padding to the given string. + * The default character used is a space. + * + * @param int $left Length of left padding + * @param int $right Length of right padding + * @param string $padStr String used to pad + * @return Stringy String with padding applied + */ + private function applyPadding($left = 0, $right = 0, $padStr = ' ') + { + $stringy = static::create($this->str, $this->encoding); + $length = mb_strlen($padStr, $stringy->encoding); + + $strLength = $stringy->length(); + $paddedLength = $strLength + $left + $right; + + if (!$length || $paddedLength <= $strLength) { + return $stringy; + } + + $leftPadding = mb_substr(str_repeat($padStr, ceil($left / $length)), 0, + $left, $stringy->encoding); + $rightPadding = mb_substr(str_repeat($padStr, ceil($right / $length)), + 0, $right, $stringy->encoding); + + $stringy->str = $leftPadding . $stringy->str . $rightPadding; + + return $stringy; + } + + /** + * Returns true if the string begins with $substring, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $substring The substring to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @return bool Whether or not $str starts with $substring + */ + public function startsWith($substring, $caseSensitive = true) + { + $substringLength = mb_strlen($substring, $this->encoding); + $startOfStr = mb_substr($this->str, 0, $substringLength, + $this->encoding); + + if (!$caseSensitive) { + $substring = mb_strtolower($substring, $this->encoding); + $startOfStr = mb_strtolower($startOfStr, $this->encoding); + } + + return (string) $substring === $startOfStr; + } + + /** + * Returns true if the string ends with $substring, false otherwise. By + * default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $substring The substring to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @return bool Whether or not $str ends with $substring + */ + public function endsWith($substring, $caseSensitive = true) + { + $substringLength = mb_strlen($substring, $this->encoding); + $strLength = $this->length(); + + $endOfStr = mb_substr($this->str, $strLength - $substringLength, + $substringLength, $this->encoding); + + if (!$caseSensitive) { + $substring = mb_strtolower($substring, $this->encoding); + $endOfStr = mb_strtolower($endOfStr, $this->encoding); + } + + return (string) $substring === $endOfStr; + } + + /** + * Converts each tab in the string to some number of spaces, as defined by + * $tabLength. By default, each tab is converted to 4 consecutive spaces. + * + * @param int $tabLength Number of spaces to replace each tab with + * @return Stringy Object whose $str has had tabs switched to spaces + */ + public function toSpaces($tabLength = 4) + { + $spaces = str_repeat(' ', $tabLength); + $str = str_replace("\t", $spaces, $this->str); + + return static::create($str, $this->encoding); + } + + /** + * Converts each occurrence of some consecutive number of spaces, as + * defined by $tabLength, to a tab. By default, each 4 consecutive spaces + * are converted to a tab. + * + * @param int $tabLength Number of spaces to replace with a tab + * @return Stringy Object whose $str has had spaces switched to tabs + */ + public function toTabs($tabLength = 4) + { + $spaces = str_repeat(' ', $tabLength); + $str = str_replace($spaces, "\t", $this->str); + + return static::create($str, $this->encoding); + } + + /** + * Converts the first character of each word in the string to uppercase. + * + * @return Stringy Object with all characters of $str being title-cased + */ + public function toTitleCase() + { + $str = mb_convert_case($this->str, MB_CASE_TITLE, $this->encoding); + + return static::create($str, $this->encoding); + } + + /** + * Converts all characters in the string to lowercase. An alias for PHP's + * mb_strtolower(). + * + * @return Stringy Object with all characters of $str being lowercase + */ + public function toLowerCase() + { + $str = mb_strtolower($this->str, $this->encoding); + + return static::create($str, $this->encoding); + } + + /** + * Converts all characters in the string to uppercase. An alias for PHP's + * mb_strtoupper(). + * + * @return Stringy Object with all characters of $str being uppercase + */ + public function toUpperCase() + { + $str = mb_strtoupper($this->str, $this->encoding); + + return static::create($str, $this->encoding); + } + + /** + * Converts the string into an URL slug. This includes replacing non-ASCII + * characters with their closest ASCII equivalents, removing remaining + * non-ASCII and non-alphanumeric characters, and replacing whitespace with + * $replacement. The replacement defaults to a single dash, and the string + * is also converted to lowercase. + * + * @param string $replacement The string used to replace whitespace + * @return Stringy Object whose $str has been converted to an URL slug + */ + public function slugify($replacement = '-') + { + $stringy = $this->toAscii(); + + $quotedReplacement = preg_quote($replacement); + $pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u"; + $stringy->str = preg_replace($pattern, '', $stringy); + + return $stringy->toLowerCase()->applyDelimiter($replacement) + ->removeLeft($replacement)->removeRight($replacement); + } + + /** + * Returns true if the string contains $needle, false otherwise. By default + * the comparison is case-sensitive, but can be made insensitive by setting + * $caseSensitive to false. + * + * @param string $needle Substring to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @return bool Whether or not $str contains $needle + */ + public function contains($needle, $caseSensitive = true) + { + $encoding = $this->encoding; + + if ($caseSensitive) { + return (mb_strpos($this->str, $needle, 0, $encoding) !== false); + } else { + return (mb_stripos($this->str, $needle, 0, $encoding) !== false); + } + } + + /** + * Returns true if the string contains any $needles, false otherwise. By + * default the comparison is case-sensitive, but can be made insensitive by + * setting $caseSensitive to false. + * + * @param array $needles Substrings to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @return bool Whether or not $str contains $needle + */ + public function containsAny($needles, $caseSensitive = true) + { + if (empty($needles)) { + return false; + } + + foreach ($needles as $needle) { + if ($this->contains($needle, $caseSensitive)) { + return true; + } + } + + return false; + } + + /** + * Returns true if the string contains all $needles, false otherwise. By + * default the comparison is case-sensitive, but can be made insensitive by + * setting $caseSensitive to false. + * + * @param array $needles Substrings to look for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @return bool Whether or not $str contains $needle + */ + public function containsAll($needles, $caseSensitive = true) + { + if (empty($needles)) { + return false; + } + + foreach ($needles as $needle) { + if (!$this->contains($needle, $caseSensitive)) { + return false; + } + } + + return true; + } + + /** + * Surrounds $str with the given substring. + * + * @param string $substring The substring to add to both sides + * @return Stringy Object whose $str had the substring both prepended and + * appended + */ + public function surround($substring) + { + $str = implode('', array($substring, $this->str, $substring)); + + return static::create($str, $this->encoding); + } + + /** + * Inserts $substring into the string at the $index provided. + * + * @param string $substring String to be inserted + * @param int $index The index at which to insert the substring + * @return Stringy Object with the resulting $str after the insertion + */ + public function insert($substring, $index) + { + $stringy = static::create($this->str, $this->encoding); + if ($index > $stringy->length()) { + return $stringy; + } + + $start = mb_substr($stringy->str, 0, $index, $stringy->encoding); + $end = mb_substr($stringy->str, $index, $stringy->length(), + $stringy->encoding); + + $stringy->str = $start . $substring . $end; + + return $stringy; + } + + /** + * Truncates the string to a given length. If $substring is provided, and + * truncating occurs, the string is further truncated so that the substring + * may be appended without exceeding the desired length. + * + * @param int $length Desired length of the truncated string + * @param string $substring The substring to append if it can fit + * @return Stringy Object with the resulting $str after truncating + */ + public function truncate($length, $substring = '') + { + $stringy = static::create($this->str, $this->encoding); + if ($length >= $stringy->length()) { + return $stringy; + } + + // Need to further trim the string so we can append the substring + $substringLength = mb_strlen($substring, $stringy->encoding); + $length = $length - $substringLength; + + $truncated = mb_substr($stringy->str, 0, $length, $stringy->encoding); + $stringy->str = $truncated . $substring; + + return $stringy; + } + + /** + * Truncates the string to a given length, while ensuring that it does not + * split words. If $substring is provided, and truncating occurs, the + * string is further truncated so that the substring may be appended without + * exceeding the desired length. + * + * @param int $length Desired length of the truncated string + * @param string $substring The substring to append if it can fit + * @return Stringy Object with the resulting $str after truncating + */ + public function safeTruncate($length, $substring = '') + { + $stringy = static::create($this->str, $this->encoding); + if ($length >= $stringy->length()) { + return $stringy; + } + + // Need to further trim the string so we can append the substring + $encoding = $stringy->encoding; + $substringLength = mb_strlen($substring, $encoding); + $length = $length - $substringLength; + + $truncated = mb_substr($stringy->str, 0, $length, $encoding); + + // If the last word was truncated + if (mb_strpos($stringy->str, ' ', $length - 1, $encoding) != $length) { + // Find pos of the last occurrence of a space, get up to that + $lastPos = mb_strrpos($truncated, ' ', 0, $encoding); + $truncated = mb_substr($truncated, 0, $lastPos, $encoding); + } + + $stringy->str = $truncated . $substring; + + return $stringy; + } + + /** + * Returns a reversed string. A multibyte version of strrev(). + * + * @return Stringy Object with a reversed $str + */ + public function reverse() + { + $strLength = $this->length(); + $reversed = ''; + + // Loop from last index of string to first + for ($i = $strLength - 1; $i >= 0; $i--) { + $reversed .= mb_substr($this->str, $i, 1, $this->encoding); + } + + return static::create($reversed, $this->encoding); + } + + /** + * A multibyte str_shuffle() function. It returns a string with its + * characters in random order. + * + * @return Stringy Object with a shuffled $str + */ + public function shuffle() + { + $indexes = range(0, $this->length() - 1); + shuffle($indexes); + + $shuffledStr = ''; + foreach ($indexes as $i) { + $shuffledStr .= mb_substr($this->str, $i, 1, $this->encoding); + } + + return static::create($shuffledStr, $this->encoding); + } + + /** + * Returns the trimmed string. An alias for PHP's trim() function. + * + * @return Stringy Object with a trimmed $str + */ + public function trim() + { + return static::create(trim($this->str), $this->encoding); + } + + /** + * Returns the longest common prefix between the string and $otherStr. + * + * @param string $otherStr Second string for comparison + * @return Stringy Object with its $str being the longest common prefix + */ + public function longestCommonPrefix($otherStr) + { + $encoding = $this->encoding; + $maxLength = min($this->length(), mb_strlen($otherStr, $encoding)); + + $longestCommonPrefix = ''; + for ($i = 0; $i < $maxLength; $i++) { + $char = mb_substr($this->str, $i, 1, $encoding); + + if ($char == mb_substr($otherStr, $i, 1, $encoding)) { + $longestCommonPrefix .= $char; + } else { + break; + } + } + + return static::create($longestCommonPrefix, $encoding); + } + + /** + * Returns the longest common suffix between the string and $otherStr. + * + * @param string $otherStr Second string for comparison + * @return Stringy Object with its $str being the longest common suffix + */ + public function longestCommonSuffix($otherStr) + { + $encoding = $this->encoding; + $maxLength = min($this->length(), mb_strlen($otherStr, $encoding)); + + $longestCommonSuffix = ''; + for ($i = 1; $i <= $maxLength; $i++) { + $char = mb_substr($this->str, -$i, 1, $encoding); + + if ($char == mb_substr($otherStr, -$i, 1, $encoding)) { + $longestCommonSuffix = $char . $longestCommonSuffix; + } else { + break; + } + } + + return static::create($longestCommonSuffix, $encoding); + } + + /** + * Returns the longest common substring between the string and $otherStr. + * In the case of ties, it returns that which occurs first. + * + * @param string $otherStr Second string for comparison + * @return Stringy Object with its $str being the longest common substring + */ + public function longestCommonSubstring($otherStr) + { + // Uses dynamic programming to solve + // http://en.wikipedia.org/wiki/Longest_common_substring_problem + $encoding = $this->encoding; + $stringy = static::create($this->str, $encoding); + $strLength = $stringy->length(); + $otherLength = mb_strlen($otherStr, $encoding); + + // Return if either string is empty + if ($strLength == 0 || $otherLength == 0) { + $stringy->str = ''; + return $stringy; + } + + $len = 0; + $end = 0; + $table = array_fill(0, $strLength + 1, + array_fill(0, $otherLength + 1, 0)); + + for ($i = 1; $i <= $strLength; $i++) { + for ($j = 1; $j <= $otherLength; $j++) { + $strChar = mb_substr($stringy->str, $i - 1, 1, $encoding); + $otherChar = mb_substr($otherStr, $j - 1, 1, $encoding); + + if ($strChar == $otherChar) { + $table[$i][$j] = $table[$i - 1][$j - 1] + 1; + if ($table[$i][$j] > $len) { + $len = $table[$i][$j]; + $end = $i; + } + } else { + $table[$i][$j] = 0; + } + } + } + + $stringy->str = mb_substr($stringy->str, $end - $len, $len, $encoding); + + return $stringy; + } + + /** + * Returns the length of the string. An alias for PHP's mb_strlen() function. + * + * @return int The number of characters in $str given the encoding + */ + public function length() + { + return mb_strlen($this->str, $this->encoding); + } + + /** + * Returns the substring beginning at $start with the specified $length. + * It differs from the mb_substr() function in that providing a $length of + * null will return the rest of the string, rather than an empty string. + * + * @param int $start Position of the first character to use + * @param int $length Maximum number of characters used + * @return Stringy Object with its $str being the substring + */ + public function substr($start, $length = null) + { + $length = $length === null ? $this->length() : $length; + $str = mb_substr($this->str, $start, $length, $this->encoding); + + return static::create($str, $this->encoding); + } + + /** + * Returns the character at $index, with indexes starting at 0. + * + * @param int $index Position of the character + * @return Stringy The character at $index + */ + public function at($index) + { + return $this->substr($index, 1); + } + + /** + * Returns the first $n characters of the string. + * + * @param int $n Number of characters to retrieve from the start + * @return Stringy Object with its $str being the first $n chars + */ + public function first($n) + { + $stringy = static::create($this->str, $this->encoding); + + if ($n < 0) { + $stringy->str = ''; + } else { + return $stringy->substr(0, $n); + } + + return $stringy; + } + + /** + * Returns the last $n characters of the string. + * + * @param int $n Number of characters to retrieve from the end + * @return Stringy Object with its $str being the last $n chars + */ + public function last($n) + { + $stringy = static::create($this->str, $this->encoding); + + if ($n <= 0) { + $stringy->str = ''; + } else { + return $stringy->substr(-$n); + } + + return $stringy; + } + + /** + * Ensures that the string begins with $substring. If it doesn't, it's + * prepended. + * + * @param string $substring The substring to add if not present + * @return Stringy Object with its $str prefixed by the $substring + */ + public function ensureLeft($substring) + { + $stringy = static::create($this->str, $this->encoding); + + if (!$stringy->startsWith($substring)) { + $stringy->str = $substring . $stringy->str; + } + + return $stringy; + } + + /** + * Ensures that the string begins with $substring. If it doesn't, it's + * appended. + * + * @param string $substring The substring to add if not present + * @return Stringy Object with its $str suffixed by the $substring + */ + public function ensureRight($substring) + { + $stringy = static::create($this->str, $this->encoding); + + if (!$stringy->endsWith($substring)) { + $stringy->str .= $substring; + } + + return $stringy; + } + + /** + * Returns a new string with the prefix $substring removed, if present. + * + * @param string $substring The prefix to remove + * @return Stringy Object having a $str without the prefix $substring + */ + public function removeLeft($substring) + { + $stringy = static::create($this->str, $this->encoding); + + if ($stringy->startsWith($substring)) { + $substringLength = mb_strlen($substring, $stringy->encoding); + return $stringy->substr($substringLength); + } + + return $stringy; + } + + /** + * Returns a new string with the suffix $substring removed, if present. + * + * @param string $substring The suffix to remove + * @return Stringy Object having a $str without the suffix $substring + */ + public function removeRight($substring) + { + $stringy = static::create($this->str, $this->encoding); + + if ($stringy->endsWith($substring)) { + $substringLength = mb_strlen($substring, $stringy->encoding); + return $stringy->substr(0, $stringy->length() - $substringLength); + } + + return $stringy; + } + + /** + * Returns true if $str matches the supplied pattern, false otherwise. + * + * @param string $pattern Regex pattern to match against + * @return bool Whether or not $str matches the pattern + */ + private function matchesPattern($pattern) + { + $regexEncoding = mb_regex_encoding(); + mb_regex_encoding($this->encoding); + + $match = mb_ereg_match($pattern, $this->str); + mb_regex_encoding($regexEncoding); + + return $match; + } + + /** + * Returns true if the string contains a lower case char, false + * otherwise. + * + * @return bool Whether or not the string contains a lower case character. + */ + public function hasLowerCase() + { + return $this->matchesPattern('.*[[:lower:]]'); + } + + /** + * Returns true if the string contains an upper case char, false + * otherwise. + * + * @return bool Whether or not the string contains an upper case character. + */ + public function hasUpperCase() + { + return $this->matchesPattern('.*[[:upper:]]'); + } + + /** + * Returns true if the string contains only alphabetic chars, false + * otherwise. + * + * @return bool Whether or not $str contains only alphabetic chars + */ + public function isAlpha() + { + return $this->matchesPattern('^[[:alpha:]]*$'); + } + + /** + * Returns true if the string contains only alphabetic and numeric chars, + * false otherwise. + * + * @return bool Whether or not $str contains only alphanumeric chars + */ + public function isAlphanumeric() + { + return $this->matchesPattern('^[[:alnum:]]*$'); + } + + /** + * Returns true if the string contains only hexadecimal chars, false + * otherwise. + * + * @return bool Whether or not $str contains only hexadecimal chars + */ + public function isHexadecimal() + { + return $this->matchesPattern('^[[:xdigit:]]*$'); + } + + /** + * Returns true if the string contains only whitespace chars, false + * otherwise. + * + * @return bool Whether or not $str contains only whitespace characters + */ + public function isBlank() + { + return $this->matchesPattern('^[[:space:]]*$'); + } + + /** + * Returns true if the string is JSON, false otherwise. + * + * @return bool Whether or not $str is JSON + */ + public function isJson() + { + json_decode($this->str); + + return (json_last_error() === JSON_ERROR_NONE); + } + + /** + * Returns true if the string contains only lower case chars, false + * otherwise. + * + * @return bool Whether or not $str contains only lower case characters + */ + public function isLowerCase() + { + return $this->matchesPattern('^[[:lower:]]*$'); + } + + /** + * Returns true if the string contains only lower case chars, false + * otherwise. + * + * @return bool Whether or not $str contains only lower case characters + */ + public function isUpperCase() + { + return $this->matchesPattern('^[[:upper:]]*$'); + } + + /** + * Returns true if the string is serialized, false otherwise. + * + * @return bool Whether or not $str is serialized + */ + public function isSerialized() + { + return $this->str === 'b:0;' || @unserialize($this->str) !== false; + } + + /** + * Returns the number of occurrences of $substring in the given string. + * By default, the comparison is case-sensitive, but can be made insensitive + * by setting $caseSensitive to false. + * + * @param string $substring The substring to search for + * @param bool $caseSensitive Whether or not to enforce case-sensitivity + * @return int The number of $substring occurrences + */ + public function countSubstr($substring, $caseSensitive = true) + { + if ($caseSensitive) { + return mb_substr_count($this->str, $substring, $this->encoding); + } + + $str = mb_strtoupper($this->str, $this->encoding); + $substring = mb_strtoupper($substring, $this->encoding); + + return mb_substr_count($str, $substring, $this->encoding); + } + + /** + * Replaces all occurrences of $search in $str by $replacement. + * + * @param string $search The needle to search for + * @param string $replacement The string to replace with + * @return Stringy Object with the resulting $str after the replacements + */ + public function replace($search, $replacement) + { + return $this->regexReplace(preg_quote($search), $replacement); + } + + /** + * Replaces all occurrences of $pattern in $str by $replacement. An alias + * for mb_ereg_replace(). Note that the 'i' option with multibyte patterns + * in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support + * in the bundled version of Oniguruma in PHP 5.3. + * + * @param string $pattern The regular expression pattern + * @param string $replacement The string to replace with + * @param string $options Matching conditions to be used + * @return Stringy Object with the resulting $str after the replacements + */ + public function regexReplace($pattern, $replacement, $options = 'msr') + { + $regexEncoding = mb_regex_encoding(); + mb_regex_encoding($this->encoding); + + $str = mb_ereg_replace($pattern, $replacement, $this->str, $options); + mb_regex_encoding($regexEncoding); + + return static::create($str, $this->encoding); + } +} diff --git a/vendor/danielstjules/stringy/tests/CommonTest.php b/vendor/danielstjules/stringy/tests/CommonTest.php new file mode 100755 index 0000000..9795702 --- /dev/null +++ b/vendor/danielstjules/stringy/tests/CommonTest.php @@ -0,0 +1,1026 @@ +assertInstanceOf('Stringy\Stringy', $actual); + } + + public function charsProvider() + { + return array( + array(array(), ''), + array(array('T', 'e', 's', 't'), 'Test'), + array(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), 'Fòô Bàř', 'UTF-8') + ); + } + + public function upperCaseFirstProvider() + { + return array( + array('Test', 'Test'), + array('Test', 'test'), + array('1a', '1a'), + array('Σ test', 'σ test', 'UTF-8'), + array(' σ test', ' σ test', 'UTF-8') + ); + } + + public function lowerCaseFirstProvider() + { + return array( + array('test', 'Test'), + array('test', 'test'), + array('1a', '1a'), + array('σ test', 'Σ test', 'UTF-8'), + array(' Σ test', ' Σ test', 'UTF-8') + ); + } + + public function camelizeProvider() + { + return array( + array('camelCase', 'CamelCase'), + array('camelCase', 'Camel-Case'), + array('camelCase', 'camel case'), + array('camelCase', 'camel -case'), + array('camelCase', 'camel - case'), + array('camelCase', 'camel_case'), + array('camelCTest', 'camel c test'), + array('stringWith1Number', 'string_with1number'), + array('stringWith22Numbers', 'string-with-2-2 numbers'), + array('1Camel2Case', '1camel2case'), + array('camelΣase', 'camel σase', 'UTF-8'), + array('στανιλCase', 'Στανιλ case', 'UTF-8'), + array('σamelCase', 'σamel Case', 'UTF-8') + ); + } + + public function upperCamelizeProvider() + { + return array( + array('CamelCase', 'camelCase'), + array('CamelCase', 'Camel-Case'), + array('CamelCase', 'camel case'), + array('CamelCase', 'camel -case'), + array('CamelCase', 'camel - case'), + array('CamelCase', 'camel_case'), + array('CamelCTest', 'camel c test'), + array('StringWith1Number', 'string_with1number'), + array('StringWith22Numbers', 'string-with-2-2 numbers'), + array('1Camel2Case', '1camel2case'), + array('CamelΣase', 'camel σase', 'UTF-8'), + array('ΣτανιλCase', 'στανιλ case', 'UTF-8'), + array('ΣamelCase', 'Σamel Case', 'UTF-8') + ); + } + + public function dasherizeProvider() + { + return array( + array('test-case', 'testCase'), + array('test-case', 'Test-Case'), + array('test-case', 'test case'), + array('-test-case', '-test -case'), + array('test-case', 'test - case'), + array('test-case', 'test_case'), + array('test-c-test', 'test c test'), + array('test-d-case', 'TestDCase'), + array('test-c-c-test', 'TestCCTest'), + array('string-with1number', 'string_with1number'), + array('string-with-2-2-numbers', 'String-with_2_2 numbers'), + array('1test2case', '1test2case'), + array('dash-σase', 'dash Σase', 'UTF-8'), + array('στανιλ-case', 'Στανιλ case', 'UTF-8'), + array('σash-case', 'Σash Case', 'UTF-8') + ); + } + + public function underscoredProvider() + { + return array( + array('test_case', 'testCase'), + array('test_case', 'Test-Case'), + array('test_case', 'test case'), + array('test_case', 'test -case'), + array('_test_case', '-test - case'), + array('test_case', 'test_case'), + array('test_c_test', ' test c test'), + array('test_u_case', 'TestUCase'), + array('test_c_c_test', 'TestCCTest'), + array('string_with1number', 'string_with1number'), + array('string_with_2_2_numbers', 'String-with_2_2 numbers'), + array('1test2case', '1test2case'), + array('test_σase', 'test Σase', 'UTF-8'), + array('στανιλ_case', 'Στανιλ case', 'UTF-8'), + array('σash_case', 'Σash Case', 'UTF-8') + ); + } + + public function swapCaseProvider() + { + return array( + array('TESTcASE', 'testCase'), + array('tEST-cASE', 'Test-Case'), + array(' - σASH cASE', ' - Σash Case', 'UTF-8'), + array('νΤΑΝΙΛ', 'Ντανιλ', 'UTF-8') + ); + } + + public function titleizeProvider() + { + $ignore = array('at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'); + + return array( + array('Testing The Method', 'testing the method'), + array('Testing the Method', 'testing the method', $ignore, 'UTF-8'), + array('I Like to Watch DVDs at Home', 'i like to watch DVDs at home', + $ignore, 'UTF-8'), + array('Θα Ήθελα Να Φύγει', ' Θα ήθελα να φύγει ', null, 'UTF-8') + ); + } + + public function humanizeProvider() + { + return array( + array('Author', 'author_id'), + array('Test user', ' _test_user_'), + array('Συγγραφέας', ' συγγραφέας_id ', 'UTF-8') + ); + } + + public function tidyProvider() + { + return array( + array('"I see..."', '“I see…”'), + array("'This too'", "‘This too’"), + array('test-dash', 'test—dash'), + array('Ο συγγραφέας είπε...', 'Ο συγγραφέας είπε…') + ); + } + + public function collapseWhitespaceProvider() + { + return array( + array('foo bar', ' foo bar '), + array('test string', 'test string'), + array('Ο συγγραφέας', ' Ο συγγραφέας '), + array('123', ' 123 '), + array('', ' ', 'UTF-8'), // no-break space (U+00A0) + array('', '           ', 'UTF-8'), // spaces U+2000 to U+200A + array('', ' ', 'UTF-8'), // narrow no-break space (U+202F) + array('', ' ', 'UTF-8'), // medium mathematical space (U+205F) + array('', ' ', 'UTF-8'), // ideographic space (U+3000) + array('1 2 3', '  1  2  3  ', 'UTF-8'), + array('', ' '), + array('', ''), + ); + } + + public function toAsciiProvider() + { + return array( + array('foo bar', 'fòô bàř'), + array(' TEST ', ' ŤÉŚŢ '), + array('f = z = 3', 'φ = ź = 3'), + array('perevirka', 'перевірка'), + array('lysaya gora', 'лысая гора'), + array('shchuka', 'щука'), + array('', '漢字'), + array('xin chao the gioi', 'xin chào thế giới'), + array('XIN CHAO THE GIOI', 'XIN CHÀO THẾ GIỚI'), + array('dam phat chet luon', 'đấm phát chết luôn'), + array(' ', ' '), // no-break space (U+00A0) + array(' ', '           '), // spaces U+2000 to U+200A + array(' ', ' '), // narrow no-break space (U+202F) + array(' ', ' '), // medium mathematical space (U+205F) + array(' ', ' '), // ideographic space (U+3000) + array('', '𐍉'), // some uncommon, unsupported character (U+10349) + array('𐍉', '𐍉', false), + ); + } + + public function padProvider() + { + return array( + // length <= str + array('foo bar', 'foo bar', -1), + array('foo bar', 'foo bar', 7), + array('fòô bàř', 'fòô bàř', 7, ' ', 'right', 'UTF-8'), + + // right + array('foo bar ', 'foo bar', 9), + array('foo bar_*', 'foo bar', 9, '_*', 'right'), + array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'right', 'UTF-8'), + + // left + array(' foo bar', 'foo bar', 9, ' ', 'left'), + array('_*foo bar', 'foo bar', 9, '_*', 'left'), + array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'left', 'UTF-8'), + + // both + array('foo bar ', 'foo bar', 8, ' ', 'both'), + array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'both', 'UTF-8'), + array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'both', 'UTF-8') + ); + } + + public function padLeftProvider() + { + return array( + array(' foo bar', 'foo bar', 9), + array('_*foo bar', 'foo bar', 9, '_*'), + array('_*_foo bar', 'foo bar', 10, '_*'), + array(' fòô bàř', 'fòô bàř', 9, ' ', 'UTF-8'), + array('¬øfòô bàř', 'fòô bàř', 9, '¬ø', 'UTF-8'), + array('¬ø¬fòô bàř', 'fòô bàř', 10, '¬ø', 'UTF-8'), + array('¬ø¬øfòô bàř', 'fòô bàř', 11, '¬ø', 'UTF-8'), + ); + } + + public function padRightProvider() + { + return array( + array('foo bar ', 'foo bar', 9), + array('foo bar_*', 'foo bar', 9, '_*'), + array('foo bar_*_', 'foo bar', 10, '_*'), + array('fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), + array('fòô bàř¬ø', 'fòô bàř', 9, '¬ø', 'UTF-8'), + array('fòô bàř¬ø¬', 'fòô bàř', 10, '¬ø', 'UTF-8'), + array('fòô bàř¬ø¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), + ); + } + + public function padBothProvider() + { + return array( + array('foo bar ', 'foo bar', 8), + array(' foo bar ', 'foo bar', 9, ' '), + array('fòô bàř ', 'fòô bàř', 8, ' ', 'UTF-8'), + array(' fòô bàř ', 'fòô bàř', 9, ' ', 'UTF-8'), + array('fòô bàř¬', 'fòô bàř', 8, '¬ø', 'UTF-8'), + array('¬fòô bàř¬', 'fòô bàř', 9, '¬ø', 'UTF-8'), + array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬ø', 'UTF-8'), + array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬ø', 'UTF-8'), + array('¬fòô bàř¬ø', 'fòô bàř', 10, '¬øÿ', 'UTF-8'), + array('¬øfòô bàř¬ø', 'fòô bàř', 11, '¬øÿ', 'UTF-8'), + array('¬øfòô bàř¬øÿ', 'fòô bàř', 12, '¬øÿ', 'UTF-8') + ); + } + + public function startsWithProvider() + { + return array( + array(true, 'foo bars', 'foo bar'), + array(true, 'FOO bars', 'foo bar', false), + array(true, 'FOO bars', 'foo BAR', false), + array(true, 'FÒÔ bàřs', 'fòô bàř', false, 'UTF-8'), + array(true, 'fòô bàřs', 'fòô BÀŘ', false, 'UTF-8'), + array(false, 'foo bar', 'bar'), + array(false, 'foo bar', 'foo bars'), + array(false, 'FOO bar', 'foo bars'), + array(false, 'FOO bars', 'foo BAR'), + array(false, 'FÒÔ bàřs', 'fòô bàř', true, 'UTF-8'), + array(false, 'fòô bàřs', 'fòô BÀŘ', true, 'UTF-8'), + ); + } + + public function endsWithProvider() + { + return array( + array(true, 'foo bars', 'o bars'), + array(true, 'FOO bars', 'o bars', false), + array(true, 'FOO bars', 'o BARs', false), + array(true, 'FÒÔ bàřs', 'ô bàřs', false, 'UTF-8'), + array(true, 'fòô bàřs', 'ô BÀŘs', false, 'UTF-8'), + array(false, 'foo bar', 'foo'), + array(false, 'foo bar', 'foo bars'), + array(false, 'FOO bar', 'foo bars'), + array(false, 'FOO bars', 'foo BARS'), + array(false, 'FÒÔ bàřs', 'fòô bàřs', true, 'UTF-8'), + array(false, 'fòô bàřs', 'fòô BÀŘS', true, 'UTF-8'), + ); + } + + public function toSpacesProvider() + { + return array( + array(' foo bar ', ' foo bar '), + array(' foo bar ', ' foo bar ', 5), + array(' foo bar ', ' foo bar ', 2), + array('foobar', ' foo bar ', 0), + array(" foo\n bar", " foo\n bar"), + array(" fòô\n bàř", " fòô\n bàř") + ); + } + + public function toTabsProvider() + { + return array( + array(' foo bar ', ' foo bar '), + array(' foo bar ', ' foo bar ', 5), + array(' foo bar ', ' foo bar ', 2), + array(" foo\n bar", " foo\n bar"), + array(" fòô\n bàř", " fòô\n bàř") + ); + } + + public function toLowerCaseProvider() + { + return array( + array('foo bar', 'FOO BAR'), + array(' foo_bar ', ' FOO_bar '), + array('fòô bàř', 'FÒÔ BÀŘ', 'UTF-8'), + array(' fòô_bàř ', ' FÒÔ_bàř ', 'UTF-8'), + array('αυτοκίνητο', 'ΑΥΤΟΚΊΝΗΤΟ', 'UTF-8'), + ); + } + + public function toTitleCaseProvider() + { + return array( + array('Foo Bar', 'foo bar'), + array(' Foo_Bar ', ' foo_bar '), + array('Fòô Bàř', 'fòô bàř', 'UTF-8'), + array(' Fòô_Bàř ', ' fòô_bàř ', 'UTF-8'), + array('Αυτοκίνητο Αυτοκίνητο', 'αυτοκίνητο αυτοκίνητο', 'UTF-8'), + ); + } + + public function toUpperCaseProvider() + { + return array( + array('FOO BAR', 'foo bar'), + array(' FOO_BAR ', ' FOO_bar '), + array('FÒÔ BÀŘ', 'fòô bàř', 'UTF-8'), + array(' FÒÔ_BÀŘ ', ' FÒÔ_bàř ', 'UTF-8'), + array('ΑΥΤΟΚΊΝΗΤΟ', 'αυτοκίνητο', 'UTF-8'), + ); + } + + public function slugifyProvider() + { + return array( + array('foo-bar', ' foo bar '), + array('foo-bar', 'foo -.-"-...bar'), + array('another-foo-bar', 'another..& foo -.-"-...bar'), + array('foo-dbar', " Foo d'Bar "), + array('a-string-with-dashes', 'A string-with-dashes'), + array('using-strings-like-foo-bar', 'Using strings like fòô bàř'), + array('numbers-1234', 'numbers 1234'), + array('perevirka-ryadka', 'перевірка рядка'), + array('bukvar-s-bukvoy-y', 'букварь с буквой ы'), + array('podekhal-k-podezdu-moego-doma', 'подъехал к подъезду моего дома'), + array('foo:bar:baz', 'Foo bar baz', ':'), + array('a_string_with_underscores', 'A_string with_underscores', '_'), + array('a_string_with_dashes', 'A string-with-dashes', '_'), + array('a\string\with\dashes', 'A string-with-dashes', '\\'), + array('an_odd_string', '-- An odd__ string-_', '_') + ); + } + + public function containsProvider() + { + return array( + array(true, 'Str contains foo bar', 'foo bar'), + array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%'), + array(true, 'Ο συγγραφέας είπε', 'συγγραφέας', 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å´¥©', true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'å˚ ∆', true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'øœ¬', true, 'UTF-8'), + array(false, 'Str contains foo bar', 'Foo bar'), + array(false, 'Str contains foo bar', 'foobar'), + array(false, 'Str contains foo bar', 'foo bar '), + array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', true, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßå˚', true, 'UTF-8'), + array(true, 'Str contains foo bar', 'Foo bar', false), + array(true, '12398!@(*%!@# @!%#*&^%', ' @!%#*&^%', false), + array(true, 'Ο συγγραφέας είπε', 'ΣΥΓΓΡΑΦΈΑΣ', false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å´¥©', false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'Å˚ ∆', false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'ØŒ¬', false, 'UTF-8'), + array(false, 'Str contains foo bar', 'foobar', false), + array(false, 'Str contains foo bar', 'foo bar ', false), + array(false, 'Ο συγγραφέας είπε', ' συγγραφέας ', false, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', ' ßÅ˚', false, 'UTF-8') + ); + } + + public function containsAnyProvider() + { + // One needle + $singleNeedle = array_map(function ($array) { + $array[2] = array($array[2]); + return $array; + }, $this->containsProvider()); + + $provider = array( + // No needles + array(false, 'Str contains foo bar', array()), + // Multiple needles + array(true, 'Str contains foo bar', array('foo', 'bar')), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), + array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), + array(false, 'Str contains foo bar', array('Foo', 'Bar')), + array(false, 'Str contains foo bar', array('foobar', 'bar ')), + array(false, 'Str contains foo bar', array('foo bar ', ' foo')), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), + array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), + array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), + array(false, 'Str contains foo bar', array('foobar', 'none'), false), + array(false, 'Str contains foo bar', array('foo bar ', ' ba '), false), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), + ); + + return array_merge($singleNeedle, $provider); + } + + public function containsAllProvider() + { + // One needle + $singleNeedle = array_map(function ($array) { + $array[2] = array($array[2]); + return $array; + }, $this->containsProvider()); + + $provider = array( + // One needle + array(false, 'Str contains foo bar', array()), + // Multiple needles + array(true, 'Str contains foo bar', array('foo', 'bar')), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*', '&^%')), + array(true, 'Ο συγγραφέας είπε', array('συγγρ', 'αφέας'), 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å´¥', '©'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('å˚ ', '∆'), true, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('øœ', '¬'), true, 'UTF-8'), + array(false, 'Str contains foo bar', array('Foo', 'bar')), + array(false, 'Str contains foo bar', array('foobar', 'bar')), + array(false, 'Str contains foo bar', array('foo bar ', 'bar')), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' συγγραφ '), true, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßå˚', ' ß '), true, 'UTF-8'), + array(true, 'Str contains foo bar', array('Foo bar', 'bar'), false), + array(true, '12398!@(*%!@# @!%#*&^%', array(' @!%#*&^%', '*&^%'), false), + array(true, 'Ο συγγραφέας είπε', array('ΣΥΓΓΡΑΦΈΑΣ', 'ΑΦΈΑ'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å´¥©', '¥©'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('Å˚ ∆', ' ∆'), false, 'UTF-8'), + array(true, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array('ØŒ¬', 'Œ'), false, 'UTF-8'), + array(false, 'Str contains foo bar', array('foobar', 'none'), false), + array(false, 'Str contains foo bar', array('foo bar ', ' ba'), false), + array(false, 'Ο συγγραφέας είπε', array(' συγγραφέας ', ' ραφέ '), false, 'UTF-8'), + array(false, 'å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', array(' ßÅ˚', ' Å˚ '), false, 'UTF-8'), + ); + + return array_merge($singleNeedle, $provider); + } + + public function surroundProvider() + { + return array( + array('__foobar__', 'foobar', '__'), + array('test', 'test', ''), + array('**', '', '*'), + array('¬fòô bàř¬', 'fòô bàř', '¬'), + array('ßå∆˚ test ßå∆˚', ' test ', 'ßå∆˚') + ); + } + + public function insertProvider() + { + return array( + array('foo bar', 'oo bar', 'f', 0), + array('foo bar', 'f bar', 'oo', 1), + array('f bar', 'f bar', 'oo', 20), + array('foo bar', 'foo ba', 'r', 6), + array('fòô bàř', 'òô bàř', 'f', 0, 'UTF-8'), + array('fòô bàř', 'f bàř', 'òô', 1, 'UTF-8'), + array('fòô bàř', 'fòô bà', 'ř', 6, 'UTF-8') + ); + } + + public function truncateProvider() + { + return array( + array('Test foo bar', 'Test foo bar', 12), + array('Test foo ba', 'Test foo bar', 11), + array('Test foo', 'Test foo bar', 8), + array('Test fo', 'Test foo bar', 7), + array('Test', 'Test foo bar', 4), + array('Test foo bar', 'Test foo bar', 12, '...'), + array('Test foo...', 'Test foo bar', 11, '...'), + array('Test ...', 'Test foo bar', 8, '...'), + array('Test...', 'Test foo bar', 7, '...'), + array('T...', 'Test foo bar', 4, '...'), + array('Test fo....', 'Test foo bar', 11, '....'), + array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), + array('Test fòô bà', 'Test fòô bàř', 11, '', 'UTF-8'), + array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), + array('Test fò', 'Test fòô bàř', 7, '', 'UTF-8'), + array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), + array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), + array('Test fòô ϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), + array('Test fϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), + array('Test ϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), + array('Teϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), + array('What are your pl...', 'What are your plans today?', 19, '...') + ); + } + + public function safeTruncateProvider() + { + return array( + array('Test foo bar', 'Test foo bar', 12), + array('Test foo', 'Test foo bar', 11), + array('Test foo', 'Test foo bar', 8), + array('Test', 'Test foo bar', 7), + array('Test', 'Test foo bar', 4), + array('Test foo bar', 'Test foo bar', 12, '...'), + array('Test foo...', 'Test foo bar', 11, '...'), + array('Test...', 'Test foo bar', 8, '...'), + array('Test...', 'Test foo bar', 7, '...'), + array('...', 'Test foo bar', 4, '...'), + array('Test....', 'Test foo bar', 11, '....'), + array('Test fòô bàř', 'Test fòô bàř', 12, '', 'UTF-8'), + array('Test fòô', 'Test fòô bàř', 11, '', 'UTF-8'), + array('Test fòô', 'Test fòô bàř', 8, '', 'UTF-8'), + array('Test', 'Test fòô bàř', 7, '', 'UTF-8'), + array('Test', 'Test fòô bàř', 4, '', 'UTF-8'), + array('Test fòô bàř', 'Test fòô bàř', 12, 'ϰϰ', 'UTF-8'), + array('Test fòôϰϰ', 'Test fòô bàř', 11, 'ϰϰ', 'UTF-8'), + array('Testϰϰ', 'Test fòô bàř', 8, 'ϰϰ', 'UTF-8'), + array('Testϰϰ', 'Test fòô bàř', 7, 'ϰϰ', 'UTF-8'), + array('ϰϰ', 'Test fòô bàř', 4, 'ϰϰ', 'UTF-8'), + array('What are your plans...', 'What are your plans today?', 22, '...') + ); + } + + public function reverseProvider() + { + return array( + array('', ''), + array('raboof', 'foobar'), + array('řàbôòf', 'fòôbàř', 'UTF-8'), + array('řàb ôòf', 'fòô bàř', 'UTF-8'), + array('∂∆ ˚åß', 'ßå˚ ∆∂', 'UTF-8') + ); + } + + public function shuffleProvider() + { + return array( + array('foo bar'), + array('∂∆ ˚åß', 'UTF-8'), + array('å´¥©¨ˆßå˚ ∆∂˙©å∑¥øœ¬', 'UTF-8') + ); + } + + public function trimProvider() + { + return array( + array('foo bar', ' foo bar '), + array('foo bar', ' foo bar'), + array('foo bar', 'foo bar '), + array('foo bar', "\n\t foo bar \n\t"), + array('fòô bàř', ' fòô bàř '), + array('fòô bàř', ' fòô bàř'), + array('fòô bàř', 'fòô bàř '), + array('fòô bàř', "\n\t fòô bàř \n\t") + ); + } + + public function longestCommonPrefixProvider() + { + return array( + array('foo', 'foobar', 'foo bar'), + array('foo bar', 'foo bar', 'foo bar'), + array('f', 'foo bar', 'far boo'), + array('', 'toy car', 'foo bar'), + array('', 'foo bar', ''), + array('fòô', 'fòôbar', 'fòô bar', 'UTF-8'), + array('fòô bar', 'fòô bar', 'fòô bar', 'UTF-8'), + array('fò', 'fòô bar', 'fòr bar', 'UTF-8'), + array('', 'toy car', 'fòô bar', 'UTF-8'), + array('', 'fòô bar', '', 'UTF-8'), + ); + } + + public function longestCommonSuffixProvider() + { + return array( + array('bar', 'foobar', 'foo bar'), + array('foo bar', 'foo bar', 'foo bar'), + array('ar', 'foo bar', 'boo far'), + array('', 'foo bad', 'foo bar'), + array('', 'foo bar', ''), + array('bàř', 'fòôbàř', 'fòô bàř', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), + array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), + array('', 'toy car', 'fòô bàř', 'UTF-8'), + array('', 'fòô bàř', '', 'UTF-8'), + ); + } + + public function longestCommonSubstringProvider() + { + return array( + array('foo', 'foobar', 'foo bar'), + array('foo bar', 'foo bar', 'foo bar'), + array('oo ', 'foo bar', 'boo far'), + array('foo ba', 'foo bad', 'foo bar'), + array('', 'foo bar', ''), + array('fòô', 'fòôbàř', 'fòô bàř', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'), + array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'), + array(' ', 'toy car', 'fòô bàř', 'UTF-8'), + array('', 'fòô bàř', '', 'UTF-8'), + ); + } + + public function lengthProvider() + { + return array( + array(11, ' foo bar '), + array(1, 'f'), + array(0, ''), + array(7, 'fòô bàř', 'UTF-8') + ); + } + + public function substrProvider() + { + return array( + array('foo bar', 'foo bar', 0), + array('bar', 'foo bar', 4), + array('bar', 'foo bar', 4, null), + array('o b', 'foo bar', 2, 3), + array('', 'foo bar', 4, 0), + array('fòô bàř', 'fòô bàř', 0, null, 'UTF-8'), + array('bàř', 'fòô bàř', 4, null, 'UTF-8'), + array('ô b', 'fòô bàř', 2, 3, 'UTF-8'), + array('', 'fòô bàř', 4, 0, 'UTF-8') + ); + } + + public function atProvider() + { + return array( + array('f', 'foo bar', 0), + array('o', 'foo bar', 1), + array('r', 'foo bar', 6), + array('', 'foo bar', 7), + array('f', 'fòô bàř', 0, 'UTF-8'), + array('ò', 'fòô bàř', 1, 'UTF-8'), + array('ř', 'fòô bàř', 6, 'UTF-8'), + array('', 'fòô bàř', 7, 'UTF-8'), + ); + } + + public function firstProvider() + { + return array( + array('', 'foo bar', -5), + array('', 'foo bar', 0), + array('f', 'foo bar', 1), + array('foo', 'foo bar', 3), + array('foo bar', 'foo bar', 7), + array('foo bar', 'foo bar', 8), + array('', 'fòô bàř', -5, 'UTF-8'), + array('', 'fòô bàř', 0, 'UTF-8'), + array('f', 'fòô bàř', 1, 'UTF-8'), + array('fòô', 'fòô bàř', 3, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), + ); + } + + public function lastProvider() + { + return array( + array('', 'foo bar', -5), + array('', 'foo bar', 0), + array('r', 'foo bar', 1), + array('bar', 'foo bar', 3), + array('foo bar', 'foo bar', 7), + array('foo bar', 'foo bar', 8), + array('', 'fòô bàř', -5, 'UTF-8'), + array('', 'fòô bàř', 0, 'UTF-8'), + array('ř', 'fòô bàř', 1, 'UTF-8'), + array('bàř', 'fòô bàř', 3, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 7, 'UTF-8'), + array('fòô bàř', 'fòô bàř', 8, 'UTF-8'), + ); + } + + public function ensureLeftProvider() + { + return array( + array('foobar', 'foobar', 'f'), + array('foobar', 'foobar', 'foo'), + array('foo/foobar', 'foobar', 'foo/'), + array('http://foobar', 'foobar', 'http://'), + array('http://foobar', 'http://foobar', 'http://'), + array('fòôbàř', 'fòôbàř', 'f', 'UTF-8'), + array('fòôbàř', 'fòôbàř', 'fòô', 'UTF-8'), + array('fòô/fòôbàř', 'fòôbàř', 'fòô/', 'UTF-8'), + array('http://fòôbàř', 'fòôbàř', 'http://', 'UTF-8'), + array('http://fòôbàř', 'http://fòôbàř', 'http://', 'UTF-8'), + ); + } + + public function ensureRightProvider() + { + return array( + array('foobar', 'foobar', 'r'), + array('foobar', 'foobar', 'bar'), + array('foobar/bar', 'foobar', '/bar'), + array('foobar.com/', 'foobar', '.com/'), + array('foobar.com/', 'foobar.com/', '.com/'), + array('fòôbàř', 'fòôbàř', 'ř', 'UTF-8'), + array('fòôbàř', 'fòôbàř', 'bàř', 'UTF-8'), + array('fòôbàř/bàř', 'fòôbàř', '/bàř', 'UTF-8'), + array('fòôbàř.com/', 'fòôbàř', '.com/', 'UTF-8'), + array('fòôbàř.com/', 'fòôbàř.com/', '.com/', 'UTF-8'), + ); + } + + public function removeLeftProvider() + { + return array( + array('foo bar', 'foo bar', ''), + array('oo bar', 'foo bar', 'f'), + array('bar', 'foo bar', 'foo '), + array('foo bar', 'foo bar', 'oo'), + array('foo bar', 'foo bar', 'oo bar'), + array('oo bar', 'foo bar', Stringy::create('foo bar')->first(1), 'UTF-8'), + array('oo bar', 'foo bar', Stringy::create('foo bar')->at(0), 'UTF-8'), + array('fòô bàř', 'fòô bàř', '', 'UTF-8'), + array('òô bàř', 'fòô bàř', 'f', 'UTF-8'), + array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8') + ); + } + + public function removeRightProvider() + { + return array( + array('foo bar', 'foo bar', ''), + array('foo ba', 'foo bar', 'r'), + array('foo', 'foo bar', ' bar'), + array('foo bar', 'foo bar', 'ba'), + array('foo bar', 'foo bar', 'foo ba'), + array('foo ba', 'foo bar', Stringy::create('foo bar')->last(1), 'UTF-8'), + array('foo ba', 'foo bar', Stringy::create('foo bar')->at(6), 'UTF-8'), + array('fòô bàř', 'fòô bàř', '', 'UTF-8'), + array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'), + array('fòô', 'fòô bàř', ' bàř', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'), + array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8') + ); + } + + public function isAlphaProvider() + { + return array( + array(true, ''), + array(true, 'foobar'), + array(false, 'foo bar'), + array(false, 'foobar2'), + array(true, 'fòôbàř', 'UTF-8'), + array(false, 'fòô bàř', 'UTF-8'), + array(false, 'fòôbàř2', 'UTF-8'), + array(true, 'ҠѨњфгШ', 'UTF-8'), + array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), + array(true, '丹尼爾', 'UTF-8') + ); + } + + public function isAlphanumericProvider() + { + return array( + array(true, ''), + array(true, 'foobar1'), + array(false, 'foo bar'), + array(false, 'foobar2"'), + array(false, "\nfoobar\n"), + array(true, 'fòôbàř1', 'UTF-8'), + array(false, 'fòô bàř', 'UTF-8'), + array(false, 'fòôbàř2"', 'UTF-8'), + array(true, 'ҠѨњфгШ', 'UTF-8'), + array(false, 'ҠѨњ¨ˆфгШ', 'UTF-8'), + array(true, '丹尼爾111', 'UTF-8'), + array(true, 'دانيال1', 'UTF-8'), + array(false, 'دانيال1 ', 'UTF-8') + ); + } + + public function isBlankProvider() + { + return array( + array(true, ''), + array(true, ' '), + array(true, "\n\t "), + array(true, "\n\t \v\f"), + array(false, "\n\t a \v\f"), + array(false, "\n\t ' \v\f"), + array(false, "\n\t 2 \v\f"), + array(true, '', 'UTF-8'), + array(true, ' ', 'UTF-8'), // no-break space (U+00A0) + array(true, '           ', 'UTF-8'), // spaces U+2000 to U+200A + array(true, ' ', 'UTF-8'), // narrow no-break space (U+202F) + array(true, ' ', 'UTF-8'), // medium mathematical space (U+205F) + array(true, ' ', 'UTF-8'), // ideographic space (U+3000) + array(false, ' z', 'UTF-8'), + array(false, ' 1', 'UTF-8'), + ); + } + + public function isJsonProvider() + { + return array( + array(true, ''), + array(true, '123'), + array(true, '{"foo": "bar"}'), + array(false, '{"foo":"bar",}'), + array(false, '{"foo"}'), + array(true, '["foo"]'), + array(false, '{"foo": "bar"]'), + array(true, '123', 'UTF-8'), + array(true, '{"fòô": "bàř"}', 'UTF-8'), + array(false, '{"fòô":"bàř",}', 'UTF-8'), + array(false, '{"fòô"}', 'UTF-8'), + array(false, '["fòô": "bàř"]', 'UTF-8'), + array(true, '["fòô"]', 'UTF-8'), + array(false, '{"fòô": "bàř"]', 'UTF-8'), + ); + } + + public function isLowerCaseProvider() + { + return array( + array(true, ''), + array(true, 'foobar'), + array(false, 'foo bar'), + array(false, 'Foobar'), + array(true, 'fòôbàř', 'UTF-8'), + array(false, 'fòôbàř2', 'UTF-8'), + array(false, 'fòô bàř', 'UTF-8'), + array(false, 'fòôbÀŘ', 'UTF-8'), + ); + } + + public function hasLowerCaseProvider() + { + return array( + array(false, ''), + array(true, 'foobar'), + array(false, 'FOO BAR'), + array(true, 'fOO BAR'), + array(true, 'foO BAR'), + array(true, 'FOO BAr'), + array(true, 'Foobar'), + array(false, 'FÒÔBÀŘ', 'UTF-8'), + array(true, 'fòôbàř', 'UTF-8'), + array(true, 'fòôbàř2', 'UTF-8'), + array(true, 'Fòô bàř', 'UTF-8'), + array(true, 'fòôbÀŘ', 'UTF-8'), + ); + } + + public function isSerializedProvider() + { + return array( + array(false, ''), + array(true, 'a:1:{s:3:"foo";s:3:"bar";}'), + array(false, 'a:1:{s:3:"foo";s:3:"bar"}'), + array(true, serialize(array('foo' => 'bar'))), + array(true, 'a:1:{s:5:"fòô";s:5:"bàř";}', 'UTF-8'), + array(false, 'a:1:{s:5:"fòô";s:5:"bàř"}', 'UTF-8'), + array(true, serialize(array('fòô' => 'bár')), 'UTF-8'), + ); + } + + public function isUpperCaseProvider() + { + return array( + array(true, ''), + array(true, 'FOOBAR'), + array(false, 'FOO BAR'), + array(false, 'fOOBAR'), + array(true, 'FÒÔBÀŘ', 'UTF-8'), + array(false, 'FÒÔBÀŘ2', 'UTF-8'), + array(false, 'FÒÔ BÀŘ', 'UTF-8'), + array(false, 'FÒÔBàř', 'UTF-8'), + ); + } + + public function hasUpperCaseProvider() + { + return array( + array(false, ''), + array(true, 'FOOBAR'), + array(false, 'foo bar'), + array(true, 'Foo bar'), + array(true, 'FOo bar'), + array(true, 'foo baR'), + array(true, 'fOOBAR'), + array(false, 'fòôbàř', 'UTF-8'), + array(true, 'FÒÔBÀŘ', 'UTF-8'), + array(true, 'FÒÔBÀŘ2', 'UTF-8'), + array(true, 'fÒÔ BÀŘ', 'UTF-8'), + array(true, 'FÒÔBàř', 'UTF-8'), + ); + } + + public function isHexadecimalProvider() + { + return array( + array(true, ''), + array(true, 'abcdef'), + array(true, 'ABCDEF'), + array(true, '0123456789'), + array(true, '0123456789AbCdEf'), + array(false, '0123456789x'), + array(false, 'ABCDEFx'), + array(true, 'abcdef', 'UTF-8'), + array(true, 'ABCDEF', 'UTF-8'), + array(true, '0123456789', 'UTF-8'), + array(true, '0123456789AbCdEf', 'UTF-8'), + array(false, '0123456789x', 'UTF-8'), + array(false, 'ABCDEFx', 'UTF-8'), + ); + } + + public function countSubstrProvider() + { + return array( + array(0, '', 'foo'), + array(0, 'foo', 'bar'), + array(1, 'foo bar', 'foo'), + array(2, 'foo bar', 'o'), + array(0, '', 'fòô', 'UTF-8'), + array(0, 'fòô', 'bàř', 'UTF-8'), + array(1, 'fòô bàř', 'fòô', 'UTF-8'), + array(2, 'fôòô bàř', 'ô', 'UTF-8'), + array(0, 'fÔÒÔ bàř', 'ô', 'UTF-8'), + array(0, 'foo', 'BAR', false), + array(1, 'foo bar', 'FOo', false), + array(2, 'foo bar', 'O', false), + array(1, 'fòô bàř', 'fÒÔ', false, 'UTF-8'), + array(2, 'fôòô bàř', 'Ô', false, 'UTF-8'), + array(2, 'συγγραφέας', 'Σ', false, 'UTF-8') + ); + } + + public function replaceProvider() + { + return array( + array('', '', '', ''), + array('foo', '', '', 'foo'), + array('foo', '\s', '\s', 'foo'), + array('foo bar', 'foo bar', '', ''), + array('foo bar', 'foo bar', 'f(o)o', '\1'), + array('\1 bar', 'foo bar', 'foo', '\1'), + array('bar', 'foo bar', 'foo ', ''), + array('far bar', 'foo bar', 'foo', 'far'), + array('bar bar', 'foo bar foo bar', 'foo ', ''), + array('', '', '', '', 'UTF-8'), + array('fòô', '', '', 'fòô', 'UTF-8'), + array('fòô', '\s', '\s', 'fòô', 'UTF-8'), + array('fòô bàř', 'fòô bàř', '', '', 'UTF-8'), + array('bàř', 'fòô bàř', 'fòô ', '', 'UTF-8'), + array('far bàř', 'fòô bàř', 'fòô', 'far', 'UTF-8'), + array('bàř bàř', 'fòô bàř fòô bàř', 'fòô ', '', 'UTF-8'), + ); + } + + public function regexReplaceProvider() + { + return array( + array('', '', '', ''), + array('bar', 'foo', 'f[o]+', 'bar'), + array('o bar', 'foo bar', 'f(o)o', '\1'), + array('bar', 'foo bar', 'f[O]+\s', '', 'i'), + array('foo', 'bar', '[[:alpha:]]{3}', 'foo'), + array('', '', '', '', 'msr', 'UTF-8'), + array('bàř', 'fòô ', 'f[òô]+\s', 'bàř', 'msr', 'UTF-8'), + array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8') + ); + } +} diff --git a/vendor/danielstjules/stringy/tests/CreateTest.php b/vendor/danielstjules/stringy/tests/CreateTest.php new file mode 100755 index 0000000..aef9c9f --- /dev/null +++ b/vendor/danielstjules/stringy/tests/CreateTest.php @@ -0,0 +1,16 @@ +assertInstanceOf('Stringy\Stringy', $stringy); + $this->assertEquals('foo bar', (string) $stringy); + $this->assertEquals('UTF-8', $stringy->getEncoding()); + } +} diff --git a/vendor/danielstjules/stringy/tests/StaticStringyTest.php b/vendor/danielstjules/stringy/tests/StaticStringyTest.php new file mode 100755 index 0000000..d8a4739 --- /dev/null +++ b/vendor/danielstjules/stringy/tests/StaticStringyTest.php @@ -0,0 +1,650 @@ +assertInternalType('array', $result); + foreach ($result as $char) { + $this->assertInternalType('string', $char); + } + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider upperCaseFirstProvider() + */ + public function testUpperCaseFirst($expected, $str, $encoding = null) + { + $result = S::upperCaseFirst($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider lowerCaseFirstProvider() + */ + public function testLowerCaseFirst($expected, $str, $encoding = null) + { + $result = S::lowerCaseFirst($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider camelizeProvider() + */ + public function testCamelize($expected, $str, $encoding = null) + { + $result = S::camelize($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider upperCamelizeProvider() + */ + public function testUpperCamelize($expected, $str, $encoding = null) + { + $result = S::upperCamelize($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider dasherizeProvider() + */ + public function testDasherize($expected, $str, $encoding = null) + { + $result = S::dasherize($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider underscoredProvider() + */ + public function testUnderscored($expected, $str, $encoding = null) + { + $result = S::underscored($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider swapCaseProvider() + */ + public function testSwapCase($expected, $str, $encoding = null) + { + $result = S::swapCase($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider titleizeProvider() + */ + public function testTitleize($expected, $str, $ignore = null, + $encoding = null) + { + $result = S::titleize($str, $ignore, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider humanizeProvider() + */ + public function testHumanize($expected, $str, $encoding = null) + { + $result = S::humanize($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider tidyProvider() + */ + public function testTidy($expected, $str) + { + $result = S::tidy($str); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider collapseWhitespaceProvider() + */ + public function testCollapseWhitespace($expected, $str, $encoding = null) + { + $result = S::collapseWhitespace($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider toAsciiProvider() + */ + public function testToAscii($expected, $str, $removeUnsupported = true) + { + $result = S::toAscii($str, $removeUnsupported); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider padProvider() + */ + public function testPad($expected, $str, $length, $padStr = ' ', + $padType = 'right', $encoding = null) + { + $result = S::pad($str, $length, $padStr, $padType, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testPadException() + { + $result = S::pad('string', 5, 'foo', 'bar'); + } + + /** + * @dataProvider padLeftProvider() + */ + public function testPadLeft($expected, $str, $length, $padStr = ' ', + $encoding = null) + { + $result = S::padLeft($str, $length, $padStr, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider padRightProvider() + */ + public function testPadRight($expected, $str, $length, $padStr = ' ', + $encoding = null) + { + $result = S::padRight($str, $length, $padStr, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider padBothProvider() + */ + public function testPadBoth($expected, $str, $length, $padStr = ' ', + $encoding = null) + { + $result = S::padBoth($str, $length, $padStr, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider startsWithProvider() + */ + public function testStartsWith($expected, $str, $substring, + $caseSensitive = true, $encoding = null) + { + $result = S::startsWith($str, $substring, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider endsWithProvider() + */ + public function testEndsWith($expected, $str, $substring, + $caseSensitive = true, $encoding = null) + { + $result = S::endsWith($str, $substring, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider toSpacesProvider() + */ + public function testToSpaces($expected, $str, $tabLength = 4) + { + $result = S::toSpaces($str, $tabLength); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider toTabsProvider() + */ + public function testToTabs($expected, $str, $tabLength = 4) + { + $result = S::toTabs($str, $tabLength); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider toLowerCaseProvider() + */ + public function testToLowerCase($expected, $str, $encoding = null) + { + $result = S::toLowerCase($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider toTitleCaseProvider() + */ + public function testToTitleCase($expected, $str, $encoding = null) + { + $result = S::toTitleCase($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider toUpperCaseProvider() + */ + public function testToUpperCase($expected, $str, $encoding = null) + { + $result = S::toUpperCase($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider slugifyProvider() + */ + public function testSlugify($expected, $str, $replacement = '-') + { + $result = S::slugify($str, $replacement); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider containsProvider() + */ + public function testContains($expected, $haystack, $needle, + $caseSensitive = true, $encoding = null) + { + $result = S::contains($haystack, $needle, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider containsAnyProvider() + */ + public function testcontainsAny($expected, $haystack, $needles, + $caseSensitive = true, $encoding = null) + { + $result = S::containsAny($haystack, $needles, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider containsAllProvider() + */ + public function testContainsAll($expected, $haystack, $needles, + $caseSensitive = true, $encoding = null) + { + $result = S::containsAll($haystack, $needles, $caseSensitive, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider surroundProvider() + */ + public function testSurround($expected, $str, $substring) + { + $result = S::surround($str, $substring); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider insertProvider() + */ + public function testInsert($expected, $str, $substring, $index, + $encoding = null) + { + $result = S::insert($str, $substring, $index, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider truncateProvider() + */ + public function testTruncate($expected, $str, $length, $substring = '', + $encoding = null) + { + $result = S::truncate($str, $length, $substring, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider safeTruncateProvider() + */ + public function testSafeTruncate($expected, $str, $length, $substring = '', + $encoding = null) + { + $result = S::safeTruncate($str, $length, $substring, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider reverseProvider() + */ + public function testReverse($expected, $str, $encoding = null) + { + $result = S::reverse($str, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider shuffleProvider() + */ + public function testShuffle($str, $encoding = null) + { + $result = S::shuffle($str, $encoding); + $encoding = $encoding ?: mb_internal_encoding(); + + $this->assertInternalType('string', $result); + $this->assertEquals(mb_strlen($str, $encoding), + mb_strlen($result, $encoding)); + + // We'll make sure that the chars are present after shuffle + for ($i = 0; $i < mb_strlen($str, $encoding); $i++) { + $char = mb_substr($str, $i, 1, $encoding); + $countBefore = mb_substr_count($str, $char, $encoding); + $countAfter = mb_substr_count($result, $char, $encoding); + $this->assertEquals($countBefore, $countAfter); + } + } + + /** + * @dataProvider trimProvider() + */ + public function testTrim($expected, $str) + { + $result = S::trim($str); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider longestCommonPrefixProvider() + */ + public function testLongestCommonPrefix($expected, $str, $otherStr, + $encoding = null) + { + $result = S::longestCommonPrefix($str, $otherStr, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider longestCommonSuffixProvider() + */ + public function testLongestCommonSuffix($expected, $str, $otherStr, + $encoding = null) + { + $result = S::longestCommonSuffix($str, $otherStr, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider longestCommonSubstringProvider() + */ + public function testLongestCommonSubstring($expected, $str, $otherStr, + $encoding = null) + { + $result = S::longestCommonSubstring($str, $otherStr, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider lengthProvider() + */ + public function testLength($expected, $str, $encoding = null) + { + $result = S::length($str, $encoding); + $this->assertEquals($expected, $result); + $this->assertInternalType('int', $result); + } + + /** + * @dataProvider substrProvider() + */ + public function testSubstr($expected, $str, $start, $length = null, + $encoding = null) + { + $result = S::substr($str, $start, $length, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider atProvider() + */ + public function testAt($expected, $str, $index, $encoding = null) + { + $result = S::at($str, $index, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider firstProvider() + */ + public function testFirst($expected, $str, $n, $encoding = null) + { + $result = S::first($str, $n, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider lastProvider() + */ + public function testLast($expected, $str, $n, $encoding = null) + { + $result = S::last($str, $n, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider ensureLeftProvider() + */ + public function testEnsureLeft($expected, $str, $substring, $encoding = null) + { + $result = S::ensureLeft($str, $substring, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider ensureRightProvider() + */ + public function testEnsureRight($expected, $str, $substring, $encoding = null) + { + $result = S::ensureRight($str, $substring, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider removeLeftProvider() + */ + public function testRemoveLeft($expected, $str, $substring, $encoding = null) + { + $result = S::removeLeft($str, $substring, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider removeRightProvider() + */ + public function testRemoveRight($expected, $str, $substring, $encoding = null) + { + $result = S::removeRight($str, $substring, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isAlphaProvider() + */ + public function testIsAlpha($expected, $str, $encoding = null) + { + $result = S::isAlpha($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isAlphanumericProvider() + */ + public function testIsAlphanumeric($expected, $str, $encoding = null) + { + $result = S::isAlphanumeric($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isBlankProvider() + */ + public function testIsBlank($expected, $str, $encoding = null) + { + $result = S::isBlank($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isJsonProvider() + */ + public function testIsJson($expected, $str, $encoding = null) + { + $result = S::isJson($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isLowerCaseProvider() + */ + public function testIsLowerCase($expected, $str, $encoding = null) + { + $result = S::isLowerCase($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider hasLowerCaseProvider() + */ + public function testHasLowerCase($expected, $str, $encoding = null) + { + $result = S::hasLowerCase($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isSerializedProvider() + */ + public function testIsSerialized($expected, $str, $encoding = null) + { + $result = S::isSerialized($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isUpperCaseProvider() + */ + public function testIsUpperCase($expected, $str, $encoding = null) + { + $result = S::isUpperCase($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider hasUpperCaseProvider() + */ + public function testHasUpperCase($expected, $str, $encoding = null) + { + $result = S::hasUpperCase($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider isHexadecimalProvider() + */ + public function testIsHexadecimal($expected, $str, $encoding = null) + { + $result = S::isHexadecimal($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider countSubstrProvider() + */ + public function testCountSubstr($expected, $str, $substring, + $caseSensitive = true, $encoding = null) + { + $result = S::countSubstr($str, $substring, $caseSensitive, $encoding); + $this->assertInternalType('int', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider replaceProvider() + */ + public function testReplace($expected, $str, $search, $replacement, + $encoding = null) + { + $result = S::replace($str, $search, $replacement, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider regexReplaceProvider() + */ + public function testRegexReplace($expected, $str, $pattern, $replacement, + $options = 'msr', $encoding = null) + { + $result = S::regexReplace($str, $pattern, $replacement, $options, $encoding); + $this->assertInternalType('string', $result); + $this->assertEquals($expected, $result); + } +} diff --git a/vendor/danielstjules/stringy/tests/StringyTest.php b/vendor/danielstjules/stringy/tests/StringyTest.php new file mode 100755 index 0000000..617c065 --- /dev/null +++ b/vendor/danielstjules/stringy/tests/StringyTest.php @@ -0,0 +1,914 @@ +assertStringy($stringy); + $this->assertEquals('foo bar', (string) $stringy); + $this->assertEquals('UTF-8', $stringy->getEncoding()); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testConstructWithArray() + { + (string) new S(array()); + $this->fail('Expecting exception when the constructor is passed an array'); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testMissingToString() + { + (string) new S(new stdClass()); + $this->fail('Expecting exception when the constructor is passed an ' . + 'object without a __toString method'); + } + + /** + * @dataProvider toStringProvider() + */ + public function testToString($expected, $str) + { + $this->assertEquals($expected, (string) new S($str)); + } + + public function toStringProvider() + { + return array( + array('', null), + array('', false), + array('1', true), + array('-9', -9), + array('1.18', 1.18), + array(' string ', ' string ') + ); + } + + public function testCreate() + { + $stringy = S::create('foo bar', 'UTF-8'); + $this->assertStringy($stringy); + $this->assertEquals('foo bar', (string) $stringy); + $this->assertEquals('UTF-8', $stringy->getEncoding()); + } + + public function testChaining() + { + $stringy = S::create("Fòô Bàř", 'UTF-8'); + $this->assertStringy($stringy); + $result = $stringy->collapseWhitespace()->swapCase()->upperCaseFirst(); + $this->assertEquals('FÒÔ bÀŘ', $result); + } + + public function testCount() + { + $stringy = S::create('Fòô', 'UTF-8'); + $this->assertEquals(3, $stringy->count()); + $this->assertEquals(3, count($stringy)); + } + + public function testGetIterator() + { + $stringy = S::create('Fòô Bàř', 'UTF-8'); + + $valResult = array(); + foreach ($stringy as $char) { + $valResult[] = $char; + } + + $keyValResult = array(); + foreach ($stringy as $pos => $char) { + $keyValResult[$pos] = $char; + } + + $this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $valResult); + $this->assertEquals(array('F', 'ò', 'ô', ' ', 'B', 'à', 'ř'), $keyValResult); + } + + /** + * @dataProvider offsetExistsProvider() + */ + public function testOffsetExists($expected, $offset) + { + $stringy = S::create('fòô', 'UTF-8'); + $this->assertEquals($expected, $stringy->offsetExists($offset)); + $this->assertEquals($expected, isset($stringy[$offset])); + } + + public function offsetExistsProvider() + { + return array( + array(true, 0), + array(true, 2), + array(false, 3), + array(true, -1), + array(true, -3), + array(false, -4) + ); + } + + public function testOffsetGet() + { + $stringy = S::create('fòô', 'UTF-8'); + + $this->assertEquals('f', $stringy->offsetGet(0)); + $this->assertEquals('ô', $stringy->offsetGet(2)); + + $this->assertEquals('ô', $stringy[2]); + } + + /** + * @expectedException \OutOfBoundsException + */ + public function testOffsetGetOutOfBounds() + { + $stringy = S::create('fòô', 'UTF-8'); + $test = $stringy[3]; + } + + /** + * @expectedException \Exception + */ + public function testOffsetSet() + { + $stringy = S::create('fòô', 'UTF-8'); + $stringy[1] = 'invalid'; + } + + /** + * @expectedException \Exception + */ + public function testOffsetUnset() + { + $stringy = S::create('fòô', 'UTF-8'); + unset($stringy[1]); + } + + /** + * @dataProvider charsProvider() + */ + public function testChars($expected, $str, $encoding = null) + { + $result = S::create($str, $encoding)->chars(); + $this->assertInternalType('array', $result); + foreach ($result as $char) { + $this->assertInternalType('string', $char); + } + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider upperCaseFirstProvider() + */ + public function testUpperCaseFirst($expected, $str, $encoding = null) + { + $result = S::create($str, $encoding)->upperCaseFirst(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider lowerCaseFirstProvider() + */ + public function testLowerCaseFirst($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->lowerCaseFirst(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider camelizeProvider() + */ + public function testCamelize($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->camelize(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider upperCamelizeProvider() + */ + public function testUpperCamelize($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->upperCamelize(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider dasherizeProvider() + */ + public function testDasherize($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->dasherize(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider underscoredProvider() + */ + public function testUnderscored($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->underscored(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider swapCaseProvider() + */ + public function testSwapCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->swapCase(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider titleizeProvider() + */ + public function testTitleize($expected, $str, $ignore = null, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->titleize($ignore); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider humanizeProvider() + */ + public function testHumanize($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->humanize(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider tidyProvider() + */ + public function testTidy($expected, $str) + { + $stringy = S::create($str); + $result = $stringy->tidy(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider collapseWhitespaceProvider() + */ + public function testCollapseWhitespace($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->collapseWhitespace(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider toAsciiProvider() + */ + public function testToAscii($expected, $str, $removeUnsupported = true) + { + $stringy = S::create($str); + $result = $stringy->toAscii($removeUnsupported); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider padProvider() + */ + public function testPad($expected, $str, $length, $padStr = ' ', + $padType = 'right', $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->pad($length, $padStr, $padType); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testPadException() + { + $stringy = S::create('foo'); + $result = $stringy->pad(5, 'foo', 'bar'); + } + + /** + * @dataProvider padLeftProvider() + */ + public function testPadLeft($expected, $str, $length, $padStr = ' ', + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->padLeft($length, $padStr); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider padRightProvider() + */ + public function testPadRight($expected, $str, $length, $padStr = ' ', + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->padRight($length, $padStr); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider padBothProvider() + */ + public function testPadBoth($expected, $str, $length, $padStr = ' ', + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->padBoth($length, $padStr); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider startsWithProvider() + */ + public function testStartsWith($expected, $str, $substring, + $caseSensitive = true, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->startsWith($substring, $caseSensitive); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider endsWithProvider() + */ + public function testEndsWith($expected, $str, $substring, + $caseSensitive = true, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->endsWith($substring, $caseSensitive); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider toSpacesProvider() + */ + public function testToSpaces($expected, $str, $tabLength = 4) + { + $stringy = S::create($str); + $result = $stringy->toSpaces($tabLength); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider toTabsProvider() + */ + public function testToTabs($expected, $str, $tabLength = 4) + { + $stringy = S::create($str); + $result = $stringy->toTabs($tabLength); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider toLowerCaseProvider() + */ + public function testToLowerCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->toLowerCase(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider toTitleCaseProvider() + */ + public function testToTitleCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->toTitleCase(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider toUpperCaseProvider() + */ + public function testToUpperCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->toUpperCase(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider slugifyProvider() + */ + public function testSlugify($expected, $str, $replacement = '-') + { + $stringy = S::create($str); + $result = $stringy->slugify($replacement); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider containsProvider() + */ + public function testContains($expected, $haystack, $needle, + $caseSensitive = true, $encoding = null) + { + $stringy = S::create($haystack, $encoding); + $result = $stringy->contains($needle, $caseSensitive); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($haystack, $stringy); + } + + /** + * @dataProvider containsAnyProvider() + */ + public function testcontainsAny($expected, $haystack, $needles, + $caseSensitive = true, $encoding = null) + { + $stringy = S::create($haystack, $encoding); + $result = $stringy->containsAny($needles, $caseSensitive); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($haystack, $stringy); + } + + /** + * @dataProvider containsAllProvider() + */ + public function testContainsAll($expected, $haystack, $needles, + $caseSensitive = true, $encoding = null) + { + $stringy = S::create($haystack, $encoding); + $result = $stringy->containsAll($needles, $caseSensitive); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($haystack, $stringy); + } + + /** + * @dataProvider surroundProvider() + */ + public function testSurround($expected, $str, $substring) + { + $stringy = S::create($str); + $result = $stringy->surround($substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider insertProvider() + */ + public function testInsert($expected, $str, $substring, $index, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->insert($substring, $index); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider truncateProvider() + */ + public function testTruncate($expected, $str, $length, $substring = '', + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->truncate($length, $substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider safeTruncateProvider() + */ + public function testSafeTruncate($expected, $str, $length, $substring = '', + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->safeTruncate($length, $substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider reverseProvider() + */ + public function testReverse($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->reverse(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider shuffleProvider() + */ + public function testShuffle($str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $encoding = $encoding ?: mb_internal_encoding(); + $result = $stringy->shuffle(); + + $this->assertStringy($result); + $this->assertEquals($str, $stringy); + $this->assertEquals(mb_strlen($str, $encoding), + mb_strlen($result, $encoding)); + + // We'll make sure that the chars are present after shuffle + for ($i = 0; $i < mb_strlen($str, $encoding); $i++) { + $char = mb_substr($str, $i, 1, $encoding); + $countBefore = mb_substr_count($str, $char, $encoding); + $countAfter = mb_substr_count($result, $char, $encoding); + $this->assertEquals($countBefore, $countAfter); + } + } + + /** + * @dataProvider trimProvider() + */ + public function testTrim($expected, $str) + { + $stringy = S::create($str); + $result = $stringy->trim(); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider longestCommonPrefixProvider() + */ + public function testLongestCommonPrefix($expected, $str, $otherStr, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->longestCommonPrefix($otherStr); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider longestCommonSuffixProvider() + */ + public function testLongestCommonSuffix($expected, $str, $otherStr, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->longestCommonSuffix($otherStr); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider longestCommonSubstringProvider() + */ + public function testLongestCommonSubstring($expected, $str, $otherStr, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->longestCommonSubstring($otherStr); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider lengthProvider() + */ + public function testLength($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->length(); + $this->assertInternalType('int', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider substrProvider() + */ + public function testSubstr($expected, $str, $start, $length = null, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->substr($start, $length); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider atProvider() + */ + public function testAt($expected, $str, $index, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->at($index); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider firstProvider() + */ + public function testFirst($expected, $str, $n, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->first($n); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider lastProvider() + */ + public function testLast($expected, $str, $n, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->last($n); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider ensureLeftProvider() + */ + public function testEnsureLeft($expected, $str, $substring, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->ensureLeft($substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider ensureRightProvider() + */ + public function testEnsureRight($expected, $str, $substring, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->ensureRight($substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider removeLeftProvider() + */ + public function testRemoveLeft($expected, $str, $substring, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->removeLeft($substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider removeRightProvider() + */ + public function testRemoveRight($expected, $str, $substring, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->removeRight($substring); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isAlphaProvider() + */ + public function testIsAlpha($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isAlpha(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isAlphanumericProvider() + */ + public function testIsAlphanumeric($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isAlphanumeric(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isBlankProvider() + */ + public function testIsBlank($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isBlank(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isJsonProvider() + */ + public function testIsJson($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isJson(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isLowerCaseProvider() + */ + public function testIsLowerCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isLowerCase(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider hasLowerCaseProvider() + */ + public function testHasLowerCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->hasLowerCase(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isSerializedProvider() + */ + public function testIsSerialized($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isSerialized(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isUpperCaseProvider() + */ + public function testIsUpperCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isUpperCase(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider hasUpperCaseProvider() + */ + public function testHasUpperCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->hasUpperCase(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider isHexadecimalProvider() + */ + public function testIsHexadecimal($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->isHexadecimal(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider countSubstrProvider() + */ + public function testCountSubstr($expected, $str, $substring, + $caseSensitive = true, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->countSubstr($substring, $caseSensitive); + $this->assertInternalType('int', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider replaceProvider() + */ + public function testReplace($expected, $str, $search, $replacement, + $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->replace($search, $replacement); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + + /** + * @dataProvider regexReplaceProvider() + */ + public function testregexReplace($expected, $str, $pattern, $replacement, + $options = 'msr', $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->regexReplace($pattern, $replacement, $options); + $this->assertStringy($result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } +} diff --git a/vendor/doctrine/inflector/LICENSE b/vendor/doctrine/inflector/LICENSE new file mode 100755 index 0000000..5e781fc --- /dev/null +++ b/vendor/doctrine/inflector/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2006-2013 Doctrine Project + +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/vendor/doctrine/inflector/README.md b/vendor/doctrine/inflector/README.md new file mode 100755 index 0000000..acb55a0 --- /dev/null +++ b/vendor/doctrine/inflector/README.md @@ -0,0 +1,6 @@ +# Doctrine Inflector + +Doctrine Inflector is a small library that can perform string manipulations +with regard to upper-/lowercase and singular/plural forms of words. + +[![Build Status](https://travis-ci.org/doctrine/inflector.svg?branch=master)](https://travis-ci.org/doctrine/inflector) diff --git a/vendor/doctrine/inflector/composer.json b/vendor/doctrine/inflector/composer.json new file mode 100755 index 0000000..a29c68c --- /dev/null +++ b/vendor/doctrine/inflector/composer.json @@ -0,0 +1,29 @@ +{ + "name": "doctrine/inflector", + "type": "library", + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "keywords": ["string", "inflection", "singularize", "pluralize"], + "homepage": "http://www.doctrine-project.org", + "license": "MIT", + "authors": [ + {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"}, + {"name": "Roman Borschel", "email": "roman@code-factory.org"}, + {"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"}, + {"name": "Jonathan Wage", "email": "jonwage@gmail.com"}, + {"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"} + ], + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "autoload": { + "psr-0": { "Doctrine\\Common\\Inflector\\": "lib/" } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php b/vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php new file mode 100755 index 0000000..b007b21 --- /dev/null +++ b/vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php @@ -0,0 +1,415 @@ +. + */ + +namespace Doctrine\Common\Inflector; + +/** + * Doctrine inflector has static methods for inflecting text. + * + * The methods in these classes are from several different sources collected + * across several different php projects and several different authors. The + * original author names and emails are not known. + * + * Pluralize & Singularize implementation are borrowed from CakePHP with some modifications. + * + * @link www.doctrine-project.org + * @since 1.0 + * @author Konsta Vesterinen + * @author Jonathan H. Wage + */ +class Inflector +{ + /** + * Plural inflector rules. + * + * @var array + */ + private static $plural = array( + 'rules' => array( + '/(s)tatus$/i' => '\1\2tatuses', + '/(quiz)$/i' => '\1zes', + '/^(ox)$/i' => '\1\2en', + '/([m|l])ouse$/i' => '\1ice', + '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', + '/(x|ch|ss|sh)$/i' => '\1es', + '/([^aeiouy]|qu)y$/i' => '\1ies', + '/(hive)$/i' => '\1s', + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', + '/sis$/i' => 'ses', + '/([ti])um$/i' => '\1a', + '/(p)erson$/i' => '\1eople', + '/(m)an$/i' => '\1en', + '/(c)hild$/i' => '\1hildren', + '/(buffal|tomat)o$/i' => '\1\2oes', + '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', + '/us$/i' => 'uses', + '/(alias)$/i' => '\1es', + '/(ax|cris|test)is$/i' => '\1es', + '/s$/' => 's', + '/^$/' => '', + '/$/' => 's', + ), + 'uninflected' => array( + '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie' + ), + 'irregular' => array( + 'atlas' => 'atlases', + 'beef' => 'beefs', + 'brother' => 'brothers', + 'cafe' => 'cafes', + 'child' => 'children', + 'cookie' => 'cookies', + 'corpus' => 'corpuses', + 'cow' => 'cows', + 'criteria' => 'criterion', + 'ganglion' => 'ganglions', + 'genie' => 'genies', + 'genus' => 'genera', + 'graffito' => 'graffiti', + 'hoof' => 'hoofs', + 'human' => 'humans', + 'loaf' => 'loaves', + 'man' => 'men', + 'money' => 'monies', + 'mongoose' => 'mongooses', + 'move' => 'moves', + 'mythos' => 'mythoi', + 'niche' => 'niches', + 'numen' => 'numina', + 'occiput' => 'occiputs', + 'octopus' => 'octopuses', + 'opus' => 'opuses', + 'ox' => 'oxen', + 'penis' => 'penises', + 'person' => 'people', + 'sex' => 'sexes', + 'soliloquy' => 'soliloquies', + 'testis' => 'testes', + 'trilby' => 'trilbys', + 'turf' => 'turfs', + ) + ); + + /** + * Singular inflector rules. + * + * @var array + */ + private static $singular = array( + 'rules' => array( + '/(s)tatuses$/i' => '\1\2tatus', + '/^(.*)(menu)s$/i' => '\1\2', + '/(quiz)zes$/i' => '\\1', + '/(matr)ices$/i' => '\1ix', + '/(vert|ind)ices$/i' => '\1ex', + '/^(ox)en/i' => '\1', + '/(alias)(es)*$/i' => '\1', + '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', + '/([ftw]ax)es/i' => '\1', + '/(cris|ax|test)es$/i' => '\1is', + '/(shoe|slave)s$/i' => '\1', + '/(o)es$/i' => '\1', + '/ouses$/' => 'ouse', + '/([^a])uses$/' => '\1us', + '/([m|l])ice$/i' => '\1ouse', + '/(x|ch|ss|sh)es$/i' => '\1', + '/(m)ovies$/i' => '\1\2ovie', + '/(s)eries$/i' => '\1\2eries', + '/([^aeiouy]|qu)ies$/i' => '\1y', + '/([lr])ves$/i' => '\1f', + '/(tive)s$/i' => '\1', + '/(hive)s$/i' => '\1', + '/(drive)s$/i' => '\1', + '/([^fo])ves$/i' => '\1fe', + '/(^analy)ses$/i' => '\1sis', + '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', + '/([ti])a$/i' => '\1um', + '/(p)eople$/i' => '\1\2erson', + '/(m)en$/i' => '\1an', + '/(c)hildren$/i' => '\1\2hild', + '/(n)ews$/i' => '\1\2ews', + '/eaus$/' => 'eau', + '/^(.*us)$/' => '\\1', + '/s$/i' => '', + ), + 'uninflected' => array( + '.*[nrlm]ese', + '.*deer', + '.*fish', + '.*measles', + '.*ois', + '.*pox', + '.*sheep', + '.*ss', + ), + 'irregular' => array( + 'criterion' => 'criteria', + 'curves' => 'curve', + 'foes' => 'foe', + 'waves' => 'wave', + ) + ); + + /** + * Words that should not be inflected. + * + * @var array + */ + private static $uninflected = array( + 'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', + 'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps', + 'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder', + 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti', + 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', + 'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media', + 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese', + 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', + 'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', + 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'staff', 'swine', + 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', + 'wildebeest', 'Yengeese' + ); + + /** + * Method cache array. + * + * @var array + */ + private static $cache = array(); + + /** + * The initial state of Inflector so reset() works. + * + * @var array + */ + private static $initialState = array(); + + /** + * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. + * + * @param string $word The word to tableize. + * + * @return string The tableized word. + */ + public static function tableize($word) + { + return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); + } + + /** + * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. + * + * @param string $word The word to classify. + * + * @return string The classified word. + */ + public static function classify($word) + { + return str_replace(" ", "", ucwords(strtr($word, "_-", " "))); + } + + /** + * Camelizes a word. This uses the classify() method and turns the first character to lowercase. + * + * @param string $word The word to camelize. + * + * @return string The camelized word. + */ + public static function camelize($word) + { + return lcfirst(self::classify($word)); + } + + /** + * Clears Inflectors inflected value caches, and resets the inflection + * rules to the initial values. + * + * @return void + */ + public static function reset() + { + if (empty(self::$initialState)) { + self::$initialState = get_class_vars('Inflector'); + + return; + } + + foreach (self::$initialState as $key => $val) { + if ($key != 'initialState') { + self::${$key} = $val; + } + } + } + + /** + * Adds custom inflection $rules, of either 'plural' or 'singular' $type. + * + * ### Usage: + * + * {{{ + * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); + * Inflector::rules('plural', array( + * 'rules' => array('/^(inflect)ors$/i' => '\1ables'), + * 'uninflected' => array('dontinflectme'), + * 'irregular' => array('red' => 'redlings') + * )); + * }}} + * + * @param string $type The type of inflection, either 'plural' or 'singular' + * @param array $rules An array of rules to be added. + * @param boolean $reset If true, will unset default inflections for all + * new rules that are being defined in $rules. + * + * @return void + */ + public static function rules($type, $rules, $reset = false) + { + foreach ($rules as $rule => $pattern) { + if ( ! is_array($pattern)) { + continue; + } + + if ($reset) { + self::${$type}[$rule] = $pattern; + } else { + self::${$type}[$rule] = ($rule === 'uninflected') + ? array_merge($pattern, self::${$type}[$rule]) + : $pattern + self::${$type}[$rule]; + } + + unset($rules[$rule], self::${$type}['cache' . ucfirst($rule)]); + + if (isset(self::${$type}['merged'][$rule])) { + unset(self::${$type}['merged'][$rule]); + } + + if ($type === 'plural') { + self::$cache['pluralize'] = self::$cache['tableize'] = array(); + } elseif ($type === 'singular') { + self::$cache['singularize'] = array(); + } + } + + self::${$type}['rules'] = $rules + self::${$type}['rules']; + } + + /** + * Returns a word in plural form. + * + * @param string $word The word in singular form. + * + * @return string The word in plural form. + */ + public static function pluralize($word) + { + if (isset(self::$cache['pluralize'][$word])) { + return self::$cache['pluralize'][$word]; + } + + if (!isset(self::$plural['merged']['irregular'])) { + self::$plural['merged']['irregular'] = self::$plural['irregular']; + } + + if (!isset(self::$plural['merged']['uninflected'])) { + self::$plural['merged']['uninflected'] = array_merge(self::$plural['uninflected'], self::$uninflected); + } + + if (!isset(self::$plural['cacheUninflected']) || !isset(self::$plural['cacheIrregular'])) { + self::$plural['cacheUninflected'] = '(?:' . implode('|', self::$plural['merged']['uninflected']) . ')'; + self::$plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$plural['merged']['irregular'])) . ')'; + } + + if (preg_match('/(.*)\\b(' . self::$plural['cacheIrregular'] . ')$/i', $word, $regs)) { + self::$cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$plural['merged']['irregular'][strtolower($regs[2])], 1); + + return self::$cache['pluralize'][$word]; + } + + if (preg_match('/^(' . self::$plural['cacheUninflected'] . ')$/i', $word, $regs)) { + self::$cache['pluralize'][$word] = $word; + + return $word; + } + + foreach (self::$plural['rules'] as $rule => $replacement) { + if (preg_match($rule, $word)) { + self::$cache['pluralize'][$word] = preg_replace($rule, $replacement, $word); + + return self::$cache['pluralize'][$word]; + } + } + } + + /** + * Returns a word in singular form. + * + * @param string $word The word in plural form. + * + * @return string The word in singular form. + */ + public static function singularize($word) + { + if (isset(self::$cache['singularize'][$word])) { + return self::$cache['singularize'][$word]; + } + + if (!isset(self::$singular['merged']['uninflected'])) { + self::$singular['merged']['uninflected'] = array_merge( + self::$singular['uninflected'], + self::$uninflected + ); + } + + if (!isset(self::$singular['merged']['irregular'])) { + self::$singular['merged']['irregular'] = array_merge( + self::$singular['irregular'], + array_flip(self::$plural['irregular']) + ); + } + + if (!isset(self::$singular['cacheUninflected']) || !isset(self::$singular['cacheIrregular'])) { + self::$singular['cacheUninflected'] = '(?:' . join('|', self::$singular['merged']['uninflected']) . ')'; + self::$singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$singular['merged']['irregular'])) . ')'; + } + + if (preg_match('/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs)) { + self::$cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$singular['merged']['irregular'][strtolower($regs[2])], 1); + + return self::$cache['singularize'][$word]; + } + + if (preg_match('/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs)) { + self::$cache['singularize'][$word] = $word; + + return $word; + } + + foreach (self::$singular['rules'] as $rule => $replacement) { + if (preg_match($rule, $word)) { + self::$cache['singularize'][$word] = preg_replace($rule, $replacement, $word); + + return self::$cache['singularize'][$word]; + } + } + + self::$cache['singularize'][$word] = $word; + + return $word; + } +} diff --git a/vendor/doctrine/inflector/phpunit.xml.dist b/vendor/doctrine/inflector/phpunit.xml.dist new file mode 100755 index 0000000..ef07faa --- /dev/null +++ b/vendor/doctrine/inflector/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + ./tests/Doctrine/ + + + + + + ./lib/Doctrine/ + + + + + + performance + + + diff --git a/vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php b/vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php new file mode 100755 index 0000000..a8a075d --- /dev/null +++ b/vendor/doctrine/inflector/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php @@ -0,0 +1,210 @@ +assertEquals( + $singular, + Inflector::singularize($plural), + "'$plural' should be singularized to '$singular'" + ); + } + + /** + * testInflectingPlurals method + * + * @dataProvider dataSampleWords + * @return void + */ + public function testInflectingPlurals($singular, $plural) + { + $this->assertEquals( + $plural, + Inflector::pluralize($singular), + "'$singular' should be pluralized to '$plural'" + ); + } + + /** + * testCustomPluralRule method + * + * @return void + */ + public function testCustomPluralRule() + { + Inflector::reset(); + Inflector::rules('plural', array('/^(custom)$/i' => '\1izables')); + + $this->assertEquals(Inflector::pluralize('custom'), 'customizables'); + + Inflector::rules('plural', array('uninflected' => array('uninflectable'))); + + $this->assertEquals(Inflector::pluralize('uninflectable'), 'uninflectable'); + + Inflector::rules('plural', array( + 'rules' => array('/^(alert)$/i' => '\1ables'), + 'uninflected' => array('noflect', 'abtuse'), + 'irregular' => array('amaze' => 'amazable', 'phone' => 'phonezes') + )); + + $this->assertEquals(Inflector::pluralize('noflect'), 'noflect'); + $this->assertEquals(Inflector::pluralize('abtuse'), 'abtuse'); + $this->assertEquals(Inflector::pluralize('alert'), 'alertables'); + $this->assertEquals(Inflector::pluralize('amaze'), 'amazable'); + $this->assertEquals(Inflector::pluralize('phone'), 'phonezes'); + } + + /** + * testCustomSingularRule method + * + * @return void + */ + public function testCustomSingularRule() + { + Inflector::reset(); + Inflector::rules('singular', array('/(eple)r$/i' => '\1', '/(jente)r$/i' => '\1')); + + $this->assertEquals(Inflector::singularize('epler'), 'eple'); + $this->assertEquals(Inflector::singularize('jenter'), 'jente'); + + Inflector::rules('singular', array( + 'rules' => array('/^(bil)er$/i' => '\1', '/^(inflec|contribu)tors$/i' => '\1ta'), + 'uninflected' => array('singulars'), + 'irregular' => array('spins' => 'spinor') + )); + + $this->assertEquals(Inflector::singularize('inflectors'), 'inflecta'); + $this->assertEquals(Inflector::singularize('contributors'), 'contributa'); + $this->assertEquals(Inflector::singularize('spins'), 'spinor'); + $this->assertEquals(Inflector::singularize('singulars'), 'singulars'); + } + + /** + * test that setting new rules clears the inflector caches. + * + * @return void + */ + public function testRulesClearsCaches() + { + Inflector::reset(); + + $this->assertEquals(Inflector::singularize('Bananas'), 'Banana'); + $this->assertEquals(Inflector::pluralize('Banana'), 'Bananas'); + + Inflector::rules('singular', array( + 'rules' => array('/(.*)nas$/i' => '\1zzz') + )); + + $this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.'); + + Inflector::rules('plural', array( + 'rules' => array('/(.*)na$/i' => '\1zzz'), + 'irregular' => array('corpus' => 'corpora') + )); + + $this->assertEquals(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules.'); + $this->assertEquals(Inflector::pluralize('corpus'), 'corpora', 'Was inflected with old irregular form.'); + } + + /** + * Test resetting inflection rules. + * + * @return void + */ + public function testCustomRuleWithReset() + { + Inflector::reset(); + + $uninflected = array('atlas', 'lapis', 'onibus', 'pires', 'virus', '.*x'); + $pluralIrregular = array('as' => 'ases'); + + Inflector::rules('singular', array( + 'rules' => array('/^(.*)(a|e|o|u)is$/i' => '\1\2l'), + 'uninflected' => $uninflected, + ), true); + + Inflector::rules('plural', array( + 'rules' => array( + '/^(.*)(a|e|o|u)l$/i' => '\1\2is', + ), + 'uninflected' => $uninflected, + 'irregular' => $pluralIrregular + ), true); + + $this->assertEquals(Inflector::pluralize('Alcool'), 'Alcoois'); + $this->assertEquals(Inflector::pluralize('Atlas'), 'Atlas'); + $this->assertEquals(Inflector::singularize('Alcoois'), 'Alcool'); + $this->assertEquals(Inflector::singularize('Atlas'), 'Atlas'); + } +} + diff --git a/vendor/doctrine/inflector/tests/Doctrine/Tests/DoctrineTestCase.php b/vendor/doctrine/inflector/tests/Doctrine/Tests/DoctrineTestCase.php new file mode 100755 index 0000000..e8323d2 --- /dev/null +++ b/vendor/doctrine/inflector/tests/Doctrine/Tests/DoctrineTestCase.php @@ -0,0 +1,10 @@ + + +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/vendor/hassankhan/config/composer.json b/vendor/hassankhan/config/composer.json new file mode 100755 index 0000000..73e3eba --- /dev/null +++ b/vendor/hassankhan/config/composer.json @@ -0,0 +1,36 @@ +{ + "name": "hassankhan/config", + "type": "library", + "description": "Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files", + "keywords": ["configuration", "config", "json", "yaml", "yml", "ini", "xml", "unframework", "microphp"], + "homepage": "http://hassankhan.me/config/", + "license": "MIT", + "authors": [ + { + "name": "Hassan Khan", + "role": "Developer", + "homepage": "http://hassankhan.me/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "scrutinizer/ocular": "~1.1", + "squizlabs/php_codesniffer": "~2.2" + }, + "suggest": { + "symfony/yaml": "~2.5" + }, + "autoload": { + "psr-4": { + "Noodlehaus\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Noodlehaus\\Test\\": "tests" + } + } +} diff --git a/vendor/hassankhan/config/src/AbstractConfig.php b/vendor/hassankhan/config/src/AbstractConfig.php new file mode 100755 index 0000000..12e47e7 --- /dev/null +++ b/vendor/hassankhan/config/src/AbstractConfig.php @@ -0,0 +1,159 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +abstract class AbstractConfig implements ArrayAccess, ConfigInterface +{ + /** + * Stores the configuration data + * + * @var array|null + */ + protected $data = null; + + /** + * Caches the configuration data + * + * @var array + */ + protected $cache = array(); + + /** + * Constructor method and sets default options, if any + * + * @param array $data + */ + public function __construct($data) + { + $this->data = array_merge($this->getDefaults(), $data); + } + + /** + * Override this method in your own subclass to provide an array of default + * options and values + * + * @return array + * + * @codeCoverageIgnore + */ + protected function getDefaults() + { + return array(); + } + + /** + * ConfigInterface Methods + */ + + /** + * {@inheritDoc} + */ + public function get($key, $default = null) + { + // Check if already cached + if (isset($this->cache[$key])) { + return $this->cache[$key]; + } + + $segs = explode('.', $key); + $root = $this->data; + + // nested case + foreach ($segs as $part) { + if (isset($root[$part])) { + $root = $root[$part]; + continue; + } else { + $root = $default; + break; + } + } + + // whatever we have is what we needed + return ($this->cache[$key] = $root); + } + + /** + * {@inheritDoc} + */ + public function set($key, $value) + { + $segs = explode('.', $key); + $root = &$this->data; + + // Look for the key, creating nested keys if needed + while ($part = array_shift($segs)) { + if (!isset($root[$part]) && count($segs)) { + $root[$part] = array(); + } + $root = &$root[$part]; + } + + // Assign value at target node + $this->cache[$key] = $root = $value; + } + + /** + * ArrayAccess Methods + */ + + /** + * Gets a value using the offset as a key + * + * @param string $offset + * + * @return mixed + */ + public function offsetGet($offset) + { + return $this->get($offset); + } + + /** + * Checks if a key exists + * + * @param string $offset + * + * @return bool + */ + public function offsetExists($offset) + { + return !is_null($this->get($offset)); + } + + /** + * Sets a value using the offset as a key + * + * @param string $offset + * @param mixed $value + * + * @return void + */ + public function offsetSet($offset, $value) + { + $this->set($offset, $value); + } + + /** + * Deletes a key and its value + * + * @param string $offset + * + * @return void + */ + public function offsetUnset($offset) + { + $this->set($offset, null); + } +} diff --git a/vendor/hassankhan/config/src/Config.php b/vendor/hassankhan/config/src/Config.php new file mode 100755 index 0000000..568d298 --- /dev/null +++ b/vendor/hassankhan/config/src/Config.php @@ -0,0 +1,157 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +class Config extends AbstractConfig +{ + /** + * All file formats supported by Config + * + * @var array + */ + private $supportedFileParsers = array( + 'Noodlehaus\FileParser\Php', + 'Noodlehaus\FileParser\Ini', + 'Noodlehaus\FileParser\Json', + 'Noodlehaus\FileParser\Xml', + 'Noodlehaus\FileParser\Yaml' + ); + + /** + * Static method for loading a Config instance. + * + * @param string|array $path + * + * @return Config + */ + public static function load($path) + { + return new static($path); + } + + /** + * Loads a supported configuration file format. + * + * @param string|array $path + * + * @throws EmptyDirectoryException If `$path` is an empty directory + */ + public function __construct($path) + { + $paths = $this->getValidPath($path); + $this->data = array(); + + foreach ($paths as $path) { + + // Get file information + $info = pathinfo($path); + $extension = isset($info['extension']) ? $info['extension'] : ''; + $parser = $this->getParser($extension); + + // Try and load file + $this->data = array_replace_recursive($this->data, $parser->parse($path)); + } + + parent::__construct($this->data); + } + + /** + * Gets a parser for a given file extension + * + * @param string $extension + * + * @return Noodlehaus\File\FileInterface + * + * @throws UnsupportedFormatException If `$path` is an unsupported file format + */ + private function getParser($extension) + { + $parser = null; + + foreach ($this->supportedFileParsers as $fileParser) { + $tempParser = new $fileParser; + + if (in_array($extension, $tempParser->getSupportedExtensions($extension))) { + $parser = $tempParser; + continue; + } + + } + + // If none exist, then throw an exception + if ($parser === null) { + throw new UnsupportedFormatException('Unsupported configuration format'); + } + + return $parser; + } + + /** + * Checks `$path` to see if it is either an array, a directory, or a file + * + * @param string|array $path + * + * @return array + * + * @throws EmptyDirectoryException If `$path` is an empty directory + * + * @throws FileNotFoundException If a file is not found at `$path` + */ + private function getValidPath($path) + { + // If `$path` is array + if (is_array($path)) { + $paths = array(); + foreach ($path as $unverifiedPath) { + try { + // Check if `$unverifiedPath` is optional + // If it exists, then it's added to the list + // If it doesn't, it throws an exception which we catch + if ($unverifiedPath[0] !== '?') { + $paths = array_merge($paths, $this->getValidPath($unverifiedPath)); + continue; + } + $optionalPath = ltrim($unverifiedPath, '?'); + $paths = array_merge($paths, $this->getValidPath($optionalPath)); + + } catch (FileNotFoundException $e) { + // If `$unverifiedPath` is optional, then skip it + if ($unverifiedPath[0] === '?') { + continue; + } + // Otherwise rethrow the exception + throw $e; + } + } + return $paths; + } + + // If `$path` is a directory + if (is_dir($path)) { + $paths = glob($path . '/*.*'); + if (empty($paths)) { + throw new EmptyDirectoryException("Configuration directory: [$path] is empty"); + } + return $paths; + } + + // If `$path` is not a file, throw an exception + if (!file_exists($path)) { + throw new FileNotFoundException("Configuration file: [$path] cannot be found"); + } + return array($path); + } +} diff --git a/vendor/hassankhan/config/src/ConfigInterface.php b/vendor/hassankhan/config/src/ConfigInterface.php new file mode 100755 index 0000000..03c48f8 --- /dev/null +++ b/vendor/hassankhan/config/src/ConfigInterface.php @@ -0,0 +1,38 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +interface ConfigInterface +{ + /** + * Gets a configuration setting using a simple or nested key. + * Nested keys are similar to JSON paths that use the dot + * dot notation. + * + * @param string $key + * @param mixed $default + * + * @return mixed + */ + public function get($key, $default = null); + + /** + * Function for setting configuration values, using + * either simple or nested keys. + * + * @param string $key + * @param mixed $value + * + * @return void + */ + public function set($key, $value); +} diff --git a/vendor/hassankhan/config/src/Exception/EmptyDirectoryException.php b/vendor/hassankhan/config/src/Exception/EmptyDirectoryException.php new file mode 100755 index 0000000..8e95656 --- /dev/null +++ b/vendor/hassankhan/config/src/Exception/EmptyDirectoryException.php @@ -0,0 +1,9 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +abstract class AbstractFileParser implements FileParserInterface +{ + + /** + * Path to the config file + * + * @var string + */ + protected $path; + + public function __construct($path) + { + $this->path = $path; + } +} diff --git a/vendor/hassankhan/config/src/FileParser/FileParserInterface.php b/vendor/hassankhan/config/src/FileParser/FileParserInterface.php new file mode 100755 index 0000000..e14c848 --- /dev/null +++ b/vendor/hassankhan/config/src/FileParser/FileParserInterface.php @@ -0,0 +1,31 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +interface FileParserInterface +{ + /** + * Parses a file from `$path` and gets its contents as an array + * + * @param string $path + * + * @return array + */ + public function parse($path); + + /** + * Returns an array of allowed file extensions for this parser + * + * @return array + */ + public function getSupportedExtensions(); +} diff --git a/vendor/hassankhan/config/src/FileParser/Ini.php b/vendor/hassankhan/config/src/FileParser/Ini.php new file mode 100755 index 0000000..0eb22ce --- /dev/null +++ b/vendor/hassankhan/config/src/FileParser/Ini.php @@ -0,0 +1,43 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +class Ini implements FileParserInterface +{ + /** + * {@inheritDoc} + * Parses an INI file as an array + * + * @throws ParseException If there is an error parsing the INI file + */ + public function parse($path) + { + $data = @parse_ini_file($path, true); + + if (!$data) { + $error = error_get_last(); + throw new ParseException($error); + } + + return $data; + } + + /** + * {@inheritDoc} + */ + public function getSupportedExtensions() + { + return array('ini'); + } +} diff --git a/vendor/hassankhan/config/src/FileParser/Json.php b/vendor/hassankhan/config/src/FileParser/Json.php new file mode 100755 index 0000000..c2451db --- /dev/null +++ b/vendor/hassankhan/config/src/FileParser/Json.php @@ -0,0 +1,53 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +class Json implements FileParserInterface +{ + /** + * {@inheritDoc} + * Loads a JSON file as an array + * + * @throws ParseException If there is an error parsing the JSON file + */ + public function parse($path) + { + $data = json_decode(file_get_contents($path), true); + + if (function_exists('json_last_error_msg')) { + $error_message = json_last_error_msg(); + } else { + $error_message = 'Syntax error'; + } + + if (json_last_error() !== JSON_ERROR_NONE) { + $error = array( + 'message' => $error_message, + 'type' => json_last_error(), + 'file' => $path, + ); + throw new ParseException($error); + } + + return $data; + } + + /** + * {@inheritDoc} + */ + public function getSupportedExtensions() + { + return array('json'); + } +} diff --git a/vendor/hassankhan/config/src/FileParser/Php.php b/vendor/hassankhan/config/src/FileParser/Php.php new file mode 100755 index 0000000..ba8f3bc --- /dev/null +++ b/vendor/hassankhan/config/src/FileParser/Php.php @@ -0,0 +1,61 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +class Php implements FileParserInterface +{ + /** + * {@inheritDoc} + * Loads a PHP file and gets its' contents as an array + * + * @throws ParseException If the PHP file throws an exception + * @throws UnsupportedFormatException If the PHP file does not return an array + */ + public function parse($path) + { + // Require the file, if it throws an exception, rethrow it + try { + $temp = require $path; + } catch (Exception $exception) { + throw new ParseException( + array( + 'message' => 'PHP file threw an exception', + 'exception' => $exception, + ) + ); + } + + // If we have a callable, run it and expect an array back + if (is_callable($temp)) { + $temp = call_user_func($temp); + } + + // Check for array, if its anything else, throw an exception + if (!$temp || !is_array($temp)) { + throw new UnsupportedFormatException('PHP file does not return an array'); + } + + return $temp; + } + + /** + * {@inheritDoc} + */ + public function getSupportedExtensions() + { + return array('php'); + } +} diff --git a/vendor/hassankhan/config/src/FileParser/Xml.php b/vendor/hassankhan/config/src/FileParser/Xml.php new file mode 100755 index 0000000..9532f1b --- /dev/null +++ b/vendor/hassankhan/config/src/FileParser/Xml.php @@ -0,0 +1,55 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +class Xml implements FileParserInterface +{ + /** + * {@inheritDoc} + * Parses an XML file as an array + * + * @throws ParseException If there is an error parsing the XML file + */ + public function parse($path) + { + libxml_use_internal_errors(true); + + $data = simplexml_load_file($path, null, LIBXML_NOERROR); + + if ($data === false) { + $errors = libxml_get_errors(); + $latestError = array_pop($errors); + $error = array( + 'message' => $latestError->message, + 'type' => $latestError->level, + 'code' => $latestError->code, + 'file' => $latestError->file, + 'line' => $latestError->line, + ); + throw new ParseException($error); + } + + $data = json_decode(json_encode($data), true); + + return $data; + } + + /** + * {@inheritDoc} + */ + public function getSupportedExtensions() + { + return array('xml'); + } +} diff --git a/vendor/hassankhan/config/src/FileParser/Yaml.php b/vendor/hassankhan/config/src/FileParser/Yaml.php new file mode 100755 index 0000000..88904bf --- /dev/null +++ b/vendor/hassankhan/config/src/FileParser/Yaml.php @@ -0,0 +1,49 @@ + + * @author Hassan Khan + * @link https://github.com/noodlehaus/config + * @license MIT + */ +class Yaml implements FileParserInterface +{ + /** + * {@inheritDoc} + * Loads a YAML/YML file as an array + * + * @throws ParseException If If there is an error parsing the YAML file + */ + public function parse($path) + { + try { + $data = YamlParser::parse($path); + } catch (Exception $exception) { + throw new ParseException( + array( + 'message' => 'Error parsing YAML file', + 'exception' => $exception, + ) + ); + } + + return $data; + } + + /** + * {@inheritDoc} + */ + public function getSupportedExtensions() + { + return array('yaml', 'yml'); + } +} diff --git a/vendor/illuminate/container/BindingResolutionException.php b/vendor/illuminate/container/BindingResolutionException.php new file mode 100755 index 0000000..105c018 --- /dev/null +++ b/vendor/illuminate/container/BindingResolutionException.php @@ -0,0 +1,5 @@ +bound($abstract); + } + + /** + * Determine if the given abstract type has been bound. + * + * @param string $abstract + * @return bool + */ + public function bound($abstract) + { + return isset($this->bindings[$abstract]) || isset($this->instances[$abstract]) || $this->isAlias($abstract); + } + + /** + * Determine if the given abstract type has been resolved. + * + * @param string $abstract + * @return bool + */ + public function resolved($abstract) + { + return isset($this->resolved[$abstract]) || isset($this->instances[$abstract]); + } + + /** + * Determine if a given string is an alias. + * + * @param string $name + * @return bool + */ + public function isAlias($name) + { + return isset($this->aliases[$name]); + } + + /** + * Register a binding with the container. + * + * @param string|array $abstract + * @param \Closure|string|null $concrete + * @param bool $shared + * @return void + */ + public function bind($abstract, $concrete = null, $shared = false) + { + // If the given types are actually an array, we will assume an alias is being + // defined and will grab this "real" abstract class name and register this + // alias with the container so that it can be used as a shortcut for it. + if (is_array($abstract)) + { + list($abstract, $alias) = $this->extractAlias($abstract); + + $this->alias($abstract, $alias); + } + + // If no concrete type was given, we will simply set the concrete type to the + // abstract type. This will allow concrete type to be registered as shared + // without being forced to state their classes in both of the parameter. + $this->dropStaleInstances($abstract); + + if (is_null($concrete)) + { + $concrete = $abstract; + } + + // If the factory is not a Closure, it means it is just a class name which is + // is bound into this container to the abstract type and we will just wrap + // it up inside a Closure to make things more convenient when extending. + if ( ! $concrete instanceof Closure) + { + $concrete = $this->getClosure($abstract, $concrete); + } + + $this->bindings[$abstract] = compact('concrete', 'shared'); + + // If the abstract type was already resolved in this container we'll fire the + // rebound listener so that any objects which have already gotten resolved + // can have their copy of the object updated via the listener callbacks. + if ($this->resolved($abstract)) + { + $this->rebound($abstract); + } + } + + /** + * Get the Closure to be used when building a type. + * + * @param string $abstract + * @param string $concrete + * @return \Closure + */ + protected function getClosure($abstract, $concrete) + { + return function($c, $parameters = []) use ($abstract, $concrete) + { + $method = ($abstract == $concrete) ? 'build' : 'make'; + + return $c->$method($concrete, $parameters); + }; + } + + /** + * Add a contextual binding to the container. + * + * @param string $concrete + * @param string $abstract + * @param \Closure|string $implementation + */ + public function addContextualBinding($concrete, $abstract, $implementation) + { + $this->contextual[$concrete][$abstract] = $implementation; + } + + /** + * Register a binding if it hasn't already been registered. + * + * @param string $abstract + * @param \Closure|string|null $concrete + * @param bool $shared + * @return void + */ + public function bindIf($abstract, $concrete = null, $shared = false) + { + if ( ! $this->bound($abstract)) + { + $this->bind($abstract, $concrete, $shared); + } + } + + /** + * Register a shared binding in the container. + * + * @param string $abstract + * @param \Closure|string|null $concrete + * @return void + */ + public function singleton($abstract, $concrete = null) + { + $this->bind($abstract, $concrete, true); + } + + /** + * Wrap a Closure such that it is shared. + * + * @param \Closure $closure + * @return \Closure + */ + public function share(Closure $closure) + { + return function($container) use ($closure) + { + // We'll simply declare a static variable within the Closures and if it has + // not been set we will execute the given Closures to resolve this value + // and return it back to these consumers of the method as an instance. + static $object; + + if (is_null($object)) + { + $object = $closure($container); + } + + return $object; + }; + } + + /** + * Bind a shared Closure into the container. + * + * @param string $abstract + * @param \Closure $closure + * @return void + */ + public function bindShared($abstract, Closure $closure) + { + $this->bind($abstract, $this->share($closure), true); + } + + /** + * "Extend" an abstract type in the container. + * + * @param string $abstract + * @param \Closure $closure + * @return void + * + * @throws \InvalidArgumentException + */ + public function extend($abstract, Closure $closure) + { + if (isset($this->instances[$abstract])) + { + $this->instances[$abstract] = $closure($this->instances[$abstract], $this); + + $this->rebound($abstract); + } + else + { + $this->extenders[$abstract][] = $closure; + } + } + + /** + * Register an existing instance as shared in the container. + * + * @param string $abstract + * @param mixed $instance + * @return void + */ + public function instance($abstract, $instance) + { + // First, we will extract the alias from the abstract if it is an array so we + // are using the correct name when binding the type. If we get an alias it + // will be registered with the container so we can resolve it out later. + if (is_array($abstract)) + { + list($abstract, $alias) = $this->extractAlias($abstract); + + $this->alias($abstract, $alias); + } + + unset($this->aliases[$abstract]); + + // We'll check to determine if this type has been bound before, and if it has + // we will fire the rebound callbacks registered with the container and it + // can be updated with consuming classes that have gotten resolved here. + $bound = $this->bound($abstract); + + $this->instances[$abstract] = $instance; + + if ($bound) + { + $this->rebound($abstract); + } + } + + /** + * Assign a set of tags to a given binding. + * + * @param array|string $abstracts + * @param array|mixed ...$tags + * @return void + */ + public function tag($abstracts, $tags) + { + $tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1); + + foreach ($tags as $tag) + { + if ( ! isset($this->tags[$tag])) $this->tags[$tag] = []; + + foreach ((array) $abstracts as $abstract) + { + $this->tags[$tag][] = $abstract; + } + } + } + + /** + * Resolve all of the bindings for a given tag. + * + * @param string $tag + * @return array + */ + public function tagged($tag) + { + $results = []; + + foreach ($this->tags[$tag] as $abstract) + { + $results[] = $this->make($abstract); + } + + return $results; + } + + /** + * Alias a type to a different name. + * + * @param string $abstract + * @param string $alias + * @return void + */ + public function alias($abstract, $alias) + { + $this->aliases[$alias] = $abstract; + } + + /** + * Extract the type and alias from a given definition. + * + * @param array $definition + * @return array + */ + protected function extractAlias(array $definition) + { + return [key($definition), current($definition)]; + } + + /** + * Bind a new callback to an abstract's rebind event. + * + * @param string $abstract + * @param \Closure $callback + * @return mixed + */ + public function rebinding($abstract, Closure $callback) + { + $this->reboundCallbacks[$abstract][] = $callback; + + if ($this->bound($abstract)) return $this->make($abstract); + } + + /** + * Refresh an instance on the given target and method. + * + * @param string $abstract + * @param mixed $target + * @param string $method + * @return mixed + */ + public function refresh($abstract, $target, $method) + { + return $this->rebinding($abstract, function($app, $instance) use ($target, $method) + { + $target->{$method}($instance); + }); + } + + /** + * Fire the "rebound" callbacks for the given abstract type. + * + * @param string $abstract + * @return void + */ + protected function rebound($abstract) + { + $instance = $this->make($abstract); + + foreach ($this->getReboundCallbacks($abstract) as $callback) + { + call_user_func($callback, $this, $instance); + } + } + + /** + * Get the rebound callbacks for a given type. + * + * @param string $abstract + * @return array + */ + protected function getReboundCallbacks($abstract) + { + if (isset($this->reboundCallbacks[$abstract])) + { + return $this->reboundCallbacks[$abstract]; + } + + return []; + } + + /** + * Wrap the given closure such that its dependencies will be injected when executed. + * + * @param \Closure $callback + * @param array $parameters + * @return \Closure + */ + public function wrap(Closure $callback, array $parameters = []) + { + return function() use ($callback, $parameters) + { + return $this->call($callback, $parameters); + }; + } + + /** + * Call the given Closure / class@method and inject its dependencies. + * + * @param callable|string $callback + * @param array $parameters + * @param string|null $defaultMethod + * @return mixed + */ + public function call($callback, array $parameters = [], $defaultMethod = null) + { + if ($this->isCallableWithAtSign($callback) || $defaultMethod) + { + return $this->callClass($callback, $parameters, $defaultMethod); + } + + $dependencies = $this->getMethodDependencies($callback, $parameters); + + return call_user_func_array($callback, $dependencies); + } + + /** + * Determine if the given string is in Class@method syntax. + * + * @param mixed $callback + * @return bool + */ + protected function isCallableWithAtSign($callback) + { + if ( ! is_string($callback)) return false; + + return strpos($callback, '@') !== false; + } + + /** + * Get all dependencies for a given method. + * + * @param callable|string $callback + * @param array $parameters + * @return array + */ + protected function getMethodDependencies($callback, $parameters = []) + { + $dependencies = []; + + foreach ($this->getCallReflector($callback)->getParameters() as $key => $parameter) + { + $this->addDependencyForCallParameter($parameter, $parameters, $dependencies); + } + + return array_merge($dependencies, $parameters); + } + + /** + * Get the proper reflection instance for the given callback. + * + * @param callable|string $callback + * @return \ReflectionFunctionAbstract + */ + protected function getCallReflector($callback) + { + if (is_string($callback) && strpos($callback, '::') !== false) + { + $callback = explode('::', $callback); + } + + if (is_array($callback)) + { + return new ReflectionMethod($callback[0], $callback[1]); + } + + return new ReflectionFunction($callback); + } + + /** + * Get the dependency for the given call parameter. + * + * @param \ReflectionParameter $parameter + * @param array $parameters + * @param array $dependencies + * @return mixed + */ + protected function addDependencyForCallParameter(ReflectionParameter $parameter, array &$parameters, &$dependencies) + { + if (array_key_exists($parameter->name, $parameters)) + { + $dependencies[] = $parameters[$parameter->name]; + + unset($parameters[$parameter->name]); + } + elseif ($parameter->getClass()) + { + $dependencies[] = $this->make($parameter->getClass()->name); + } + elseif ($parameter->isDefaultValueAvailable()) + { + $dependencies[] = $parameter->getDefaultValue(); + } + } + + /** + * Call a string reference to a class using Class@method syntax. + * + * @param string $target + * @param array $parameters + * @param string|null $defaultMethod + * @return mixed + */ + protected function callClass($target, array $parameters = [], $defaultMethod = null) + { + $segments = explode('@', $target); + + // If the listener has an @ sign, we will assume it is being used to delimit + // the class name from the handle method name. This allows for handlers + // to run multiple handler methods in a single class for convenience. + $method = count($segments) == 2 ? $segments[1] : $defaultMethod; + + if (is_null($method)) + { + throw new InvalidArgumentException("Method not provided."); + } + + return $this->call([$this->make($segments[0]), $method], $parameters); + } + + /** + * Resolve the given type from the container. + * + * @param string $abstract + * @param array $parameters + * @return mixed + */ + public function make($abstract, $parameters = []) + { + $abstract = $this->getAlias($abstract); + + // If an instance of the type is currently being managed as a singleton we'll + // just return an existing instance instead of instantiating new instances + // so the developer can keep using the same objects instance every time. + if (isset($this->instances[$abstract])) + { + return $this->instances[$abstract]; + } + + $concrete = $this->getConcrete($abstract); + + // We're ready to instantiate an instance of the concrete type registered for + // the binding. This will instantiate the types, as well as resolve any of + // its "nested" dependencies recursively until all have gotten resolved. + if ($this->isBuildable($concrete, $abstract)) + { + $object = $this->build($concrete, $parameters); + } + else + { + $object = $this->make($concrete, $parameters); + } + + // If we defined any extenders for this type, we'll need to spin through them + // and apply them to the object being built. This allows for the extension + // of services, such as changing configuration or decorating the object. + foreach ($this->getExtenders($abstract) as $extender) + { + $object = $extender($object, $this); + } + + // If the requested type is registered as a singleton we'll want to cache off + // the instances in "memory" so we can return it later without creating an + // entirely new instance of an object on each subsequent request for it. + if ($this->isShared($abstract)) + { + $this->instances[$abstract] = $object; + } + + $this->fireResolvingCallbacks($abstract, $object); + + $this->resolved[$abstract] = true; + + return $object; + } + + /** + * Get the concrete type for a given abstract. + * + * @param string $abstract + * @return mixed $concrete + */ + protected function getConcrete($abstract) + { + if ( ! is_null($concrete = $this->getContextualConcrete($abstract))) + { + return $concrete; + } + + // If we don't have a registered resolver or concrete for the type, we'll just + // assume each type is a concrete name and will attempt to resolve it as is + // since the container should be able to resolve concretes automatically. + if ( ! isset($this->bindings[$abstract])) + { + if ($this->missingLeadingSlash($abstract) && + isset($this->bindings['\\'.$abstract])) + { + $abstract = '\\'.$abstract; + } + + return $abstract; + } + + return $this->bindings[$abstract]['concrete']; + } + + /** + * Get the contextual concrete binding for the given abstract. + * + * @param string $abstract + * @return string + */ + protected function getContextualConcrete($abstract) + { + if (isset($this->contextual[end($this->buildStack)][$abstract])) + { + return $this->contextual[end($this->buildStack)][$abstract]; + } + } + + /** + * Determine if the given abstract has a leading slash. + * + * @param string $abstract + * @return bool + */ + protected function missingLeadingSlash($abstract) + { + return is_string($abstract) && strpos($abstract, '\\') !== 0; + } + + /** + * Get the extender callbacks for a given type. + * + * @param string $abstract + * @return array + */ + protected function getExtenders($abstract) + { + if (isset($this->extenders[$abstract])) + { + return $this->extenders[$abstract]; + } + + return []; + } + + /** + * Instantiate a concrete instance of the given type. + * + * @param string $concrete + * @param array $parameters + * @return mixed + * + * @throws BindingResolutionException + */ + public function build($concrete, $parameters = []) + { + // If the concrete type is actually a Closure, we will just execute it and + // hand back the results of the functions, which allows functions to be + // used as resolvers for more fine-tuned resolution of these objects. + if ($concrete instanceof Closure) + { + return $concrete($this, $parameters); + } + + $reflector = new ReflectionClass($concrete); + + // If the type is not instantiable, the developer is attempting to resolve + // an abstract type such as an Interface of Abstract Class and there is + // no binding registered for the abstractions so we need to bail out. + if ( ! $reflector->isInstantiable()) + { + $message = "Target [$concrete] is not instantiable."; + + throw new BindingResolutionException($message); + } + + $this->buildStack[] = $concrete; + + $constructor = $reflector->getConstructor(); + + // If there are no constructors, that means there are no dependencies then + // we can just resolve the instances of the objects right away, without + // resolving any other types or dependencies out of these containers. + if (is_null($constructor)) + { + array_pop($this->buildStack); + + return new $concrete; + } + + $dependencies = $constructor->getParameters(); + + // Once we have all the constructor's parameters we can create each of the + // dependency instances and then use the reflection instances to make a + // new instance of this class, injecting the created dependencies in. + $parameters = $this->keyParametersByArgument( + $dependencies, $parameters + ); + + $instances = $this->getDependencies( + $dependencies, $parameters + ); + + array_pop($this->buildStack); + + return $reflector->newInstanceArgs($instances); + } + + /** + * Resolve all of the dependencies from the ReflectionParameters. + * + * @param array $parameters + * @param array $primitives + * @return array + */ + protected function getDependencies($parameters, array $primitives = []) + { + $dependencies = []; + + foreach ($parameters as $parameter) + { + $dependency = $parameter->getClass(); + + // If the class is null, it means the dependency is a string or some other + // primitive type which we can not resolve since it is not a class and + // we will just bomb out with an error since we have no-where to go. + if (array_key_exists($parameter->name, $primitives)) + { + $dependencies[] = $primitives[$parameter->name]; + } + elseif (is_null($dependency)) + { + $dependencies[] = $this->resolveNonClass($parameter); + } + else + { + $dependencies[] = $this->resolveClass($parameter); + } + } + + return (array) $dependencies; + } + + /** + * Resolve a non-class hinted dependency. + * + * @param \ReflectionParameter $parameter + * @return mixed + * + * @throws BindingResolutionException + */ + protected function resolveNonClass(ReflectionParameter $parameter) + { + if ($parameter->isDefaultValueAvailable()) + { + return $parameter->getDefaultValue(); + } + + $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}"; + + throw new BindingResolutionException($message); + } + + /** + * Resolve a class based dependency from the container. + * + * @param \ReflectionParameter $parameter + * @return mixed + * + * @throws BindingResolutionException + */ + protected function resolveClass(ReflectionParameter $parameter) + { + try + { + return $this->make($parameter->getClass()->name); + } + + // If we can not resolve the class instance, we will check to see if the value + // is optional, and if it is we will return the optional parameter value as + // the value of the dependency, similarly to how we do this with scalars. + catch (BindingResolutionException $e) + { + if ($parameter->isOptional()) + { + return $parameter->getDefaultValue(); + } + + throw $e; + } + } + + /** + * If extra parameters are passed by numeric ID, rekey them by argument name. + * + * @param array $dependencies + * @param array $parameters + * @return array + */ + protected function keyParametersByArgument(array $dependencies, array $parameters) + { + foreach ($parameters as $key => $value) + { + if (is_numeric($key)) + { + unset($parameters[$key]); + + $parameters[$dependencies[$key]->name] = $value; + } + } + + return $parameters; + } + + /** + * Register a new resolving callback. + * + * @param string $abstract + * @param \Closure $callback + * @return void + */ + public function resolving($abstract, Closure $callback = null) + { + if ($callback === null && $abstract instanceof Closure) + { + $this->resolvingCallback($abstract); + } + else + { + $this->resolvingCallbacks[$abstract][] = $callback; + } + } + + /** + * Register a new after resolving callback for all types. + * + * @param string $abstract + * @param \Closure $callback + * @return void + */ + public function afterResolving($abstract, Closure $callback = null) + { + if ($abstract instanceof Closure && $callback === null) + { + $this->afterResolvingCallback($abstract); + } + else + { + $this->afterResolvingCallbacks[$abstract][] = $callback; + } + } + + /** + * Register a new resolving callback by type of its first argument. + * + * @param \Closure $callback + * @return void + */ + protected function resolvingCallback(Closure $callback) + { + $abstract = $this->getFunctionHint($callback); + + if ($abstract) + { + $this->resolvingCallbacks[$abstract][] = $callback; + } + else + { + $this->globalResolvingCallbacks[] = $callback; + } + } + + /** + * Register a new after resolving callback by type of its first argument. + * + * @param \Closure $callback + * @return void + */ + protected function afterResolvingCallback(Closure $callback) + { + $abstract = $this->getFunctionHint($callback); + + if ($abstract) + { + $this->afterResolvingCallbacks[$abstract][] = $callback; + } + else + { + $this->globalAfterResolvingCallbacks[] = $callback; + } + } + + /** + * Get the type hint for this closure's first argument. + * + * @param \Closure $callback + * @return mixed + */ + protected function getFunctionHint(Closure $callback) + { + $function = new ReflectionFunction($callback); + + if ($function->getNumberOfParameters() == 0) + { + return; + } + + $expected = $function->getParameters()[0]; + + if ( ! $expected->getClass()) + { + return; + } + + return $expected->getClass()->name; + } + + /** + * Fire all of the resolving callbacks. + * + * @param string $abstract + * @param mixed $object + * @return void + */ + protected function fireResolvingCallbacks($abstract, $object) + { + $this->fireCallbackArray($object, $this->globalResolvingCallbacks); + + $this->fireCallbackArray( + $object, $this->getCallbacksForType( + $abstract, $object, $this->resolvingCallbacks + ) + ); + + $this->fireCallbackArray($object, $this->globalAfterResolvingCallbacks); + + $this->fireCallbackArray( + $object, $this->getCallbacksForType( + $abstract, $object, $this->afterResolvingCallbacks + ) + ); + } + + /** + * Get all callbacks for a given type. + * + * @param string $abstract + * @param object $object + * @param array $callbacksPerType + * + * @return array + */ + protected function getCallbacksForType($abstract, $object, array $callbacksPerType) + { + $results = []; + + foreach ($callbacksPerType as $type => $callbacks) + { + if ($type === $abstract || $object instanceof $type) + { + $results = array_merge($results, $callbacks); + } + } + + return $results; + } + + /** + * Fire an array of callbacks with an object. + * + * @param mixed $object + * @param array $callbacks + */ + protected function fireCallbackArray($object, array $callbacks) + { + foreach ($callbacks as $callback) + { + $callback($object, $this); + } + } + + /** + * Determine if a given type is shared. + * + * @param string $abstract + * @return bool + */ + public function isShared($abstract) + { + if (isset($this->bindings[$abstract]['shared'])) + { + $shared = $this->bindings[$abstract]['shared']; + } + else + { + $shared = false; + } + + return isset($this->instances[$abstract]) || $shared === true; + } + + /** + * Determine if the given concrete is buildable. + * + * @param mixed $concrete + * @param string $abstract + * @return bool + */ + protected function isBuildable($concrete, $abstract) + { + return $concrete === $abstract || $concrete instanceof Closure; + } + + /** + * Get the alias for an abstract if available. + * + * @param string $abstract + * @return string + */ + protected function getAlias($abstract) + { + return isset($this->aliases[$abstract]) ? $this->aliases[$abstract] : $abstract; + } + + /** + * Get the container's bindings. + * + * @return array + */ + public function getBindings() + { + return $this->bindings; + } + + /** + * Drop all of the stale instances and aliases. + * + * @param string $abstract + * @return void + */ + protected function dropStaleInstances($abstract) + { + unset($this->instances[$abstract], $this->aliases[$abstract]); + } + + /** + * Remove a resolved instance from the instance cache. + * + * @param string $abstract + * @return void + */ + public function forgetInstance($abstract) + { + unset($this->instances[$abstract]); + } + + /** + * Clear all of the instances from the container. + * + * @return void + */ + public function forgetInstances() + { + $this->instances = []; + } + + /** + * Flush the container of all bindings and resolved instances. + * + * @return void + */ + public function flush() + { + $this->aliases = []; + $this->resolved = []; + $this->bindings = []; + $this->instances = []; + } + + /** + * Set the globally available instance of the container. + * + * @return static + */ + public static function getInstance() + { + return static::$instance; + } + + /** + * Set the shared instance of the container. + * + * @param \Illuminate\Contracts\Container\Container $container + * @return void + */ + public static function setInstance(ContainerContract $container) + { + static::$instance = $container; + } + + /** + * Determine if a given offset exists. + * + * @param string $key + * @return bool + */ + public function offsetExists($key) + { + return isset($this->bindings[$key]); + } + + /** + * Get the value at a given offset. + * + * @param string $key + * @return mixed + */ + public function offsetGet($key) + { + return $this->make($key); + } + + /** + * Set the value at a given offset. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value) + { + // If the value is not a Closure, we will make it one. This simply gives + // more "drop-in" replacement functionality for the Pimple which this + // container's simplest functions are base modeled and built after. + if ( ! $value instanceof Closure) + { + $value = function() use ($value) + { + return $value; + }; + } + + $this->bind($key, $value); + } + + /** + * Unset the value at a given offset. + * + * @param string $key + * @return void + */ + public function offsetUnset($key) + { + unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]); + } + + /** + * Dynamically access container services. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + return $this[$key]; + } + + /** + * Dynamically set container services. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function __set($key, $value) + { + $this[$key] = $value; + } + +} diff --git a/vendor/illuminate/container/ContextualBindingBuilder.php b/vendor/illuminate/container/ContextualBindingBuilder.php new file mode 100755 index 0000000..c96d56b --- /dev/null +++ b/vendor/illuminate/container/ContextualBindingBuilder.php @@ -0,0 +1,58 @@ +concrete = $concrete; + $this->container = $container; + } + + /** + * Define the abstract target that depends on the context. + * + * @param string $abstract + * @return $this + */ + public function needs($abstract) + { + $this->needs = $abstract; + + return $this; + } + + /** + * Define the implementation for the contextual binding. + * + * @param \Closure|string $implementation + * @return void + */ + public function give($implementation) + { + $this->container->addContextualBinding($this->concrete, $this->needs, $implementation); + } + +} diff --git a/vendor/illuminate/container/composer.json b/vendor/illuminate/container/composer.json new file mode 100755 index 0000000..3ebb17d --- /dev/null +++ b/vendor/illuminate/container/composer.json @@ -0,0 +1,31 @@ +{ + "name": "illuminate/container", + "description": "The Illuminate Container package.", + "license": "MIT", + "homepage": "http://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "require": { + "php": ">=5.4.0", + "illuminate/contracts": "5.0.*" + }, + "autoload": { + "psr-4": { + "Illuminate\\Container\\": "" + } + }, + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "minimum-stability": "dev" +} diff --git a/vendor/illuminate/contracts/Auth/Authenticatable.php b/vendor/illuminate/contracts/Auth/Authenticatable.php new file mode 100755 index 0000000..f0e889c --- /dev/null +++ b/vendor/illuminate/contracts/Auth/Authenticatable.php @@ -0,0 +1,41 @@ +id = $id; + $this->class = $class; + } + +} diff --git a/vendor/illuminate/contracts/Debug/ExceptionHandler.php b/vendor/illuminate/contracts/Debug/ExceptionHandler.php new file mode 100755 index 0000000..d85fff5 --- /dev/null +++ b/vendor/illuminate/contracts/Debug/ExceptionHandler.php @@ -0,0 +1,33 @@ +provider = $provider; + } + + /** + * Get the validation error message provider. + * + * @return \Illuminate\Contracts\Support\MessageProvider + */ + public function errors() + { + return $this->provider->getMessageBag(); + } + + /** + * Get the validation error message provider. + * + * @return \Illuminate\Contracts\Support\MessageProvider + */ + public function getMessageProvider() + { + return $this->provider; + } + +} diff --git a/vendor/illuminate/contracts/Validation/Validator.php b/vendor/illuminate/contracts/Validation/Validator.php new file mode 100755 index 0000000..8cc736f --- /dev/null +++ b/vendor/illuminate/contracts/Validation/Validator.php @@ -0,0 +1,39 @@ +=5.4.0" + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "minimum-stability": "dev" +} diff --git a/vendor/illuminate/database/Capsule/Manager.php b/vendor/illuminate/database/Capsule/Manager.php new file mode 100755 index 0000000..aa272fa --- /dev/null +++ b/vendor/illuminate/database/Capsule/Manager.php @@ -0,0 +1,202 @@ +setupContainer($container ?: new Container); + + // Once we have the container setup, we will setup the default configuration + // options in the container "config" binding. This will make the database + // manager behave correctly since all the correct binding are in place. + $this->setupDefaultConfiguration(); + + $this->setupManager(); + } + + /** + * Setup the default database configuration options. + * + * @return void + */ + protected function setupDefaultConfiguration() + { + $this->container['config']['database.fetch'] = PDO::FETCH_ASSOC; + + $this->container['config']['database.default'] = 'default'; + } + + /** + * Build the database manager instance. + * + * @return void + */ + protected function setupManager() + { + $factory = new ConnectionFactory($this->container); + + $this->manager = new DatabaseManager($this->container, $factory); + } + + /** + * Get a connection instance from the global manager. + * + * @param string $connection + * @return \Illuminate\Database\Connection + */ + public static function connection($connection = null) + { + return static::$instance->getConnection($connection); + } + + /** + * Get a fluent query builder instance. + * + * @param string $table + * @param string $connection + * @return \Illuminate\Database\Query\Builder + */ + public static function table($table, $connection = null) + { + return static::$instance->connection($connection)->table($table); + } + + /** + * Get a schema builder instance. + * + * @param string $connection + * @return \Illuminate\Database\Schema\Builder + */ + public static function schema($connection = null) + { + return static::$instance->connection($connection)->getSchemaBuilder(); + } + + /** + * Get a registered connection instance. + * + * @param string $name + * @return \Illuminate\Database\Connection + */ + public function getConnection($name = null) + { + return $this->manager->connection($name); + } + + /** + * Register a connection with the manager. + * + * @param array $config + * @param string $name + * @return void + */ + public function addConnection(array $config, $name = 'default') + { + $connections = $this->container['config']['database.connections']; + + $connections[$name] = $config; + + $this->container['config']['database.connections'] = $connections; + } + + /** + * Bootstrap Eloquent so it is ready for usage. + * + * @return void + */ + public function bootEloquent() + { + Eloquent::setConnectionResolver($this->manager); + + // If we have an event dispatcher instance, we will go ahead and register it + // with the Eloquent ORM, allowing for model callbacks while creating and + // updating "model" instances; however, if it not necessary to operate. + if ($dispatcher = $this->getEventDispatcher()) + { + Eloquent::setEventDispatcher($dispatcher); + } + } + + /** + * Set the fetch mode for the database connections. + * + * @param int $fetchMode + * @return $this + */ + public function setFetchMode($fetchMode) + { + $this->container['config']['database.fetch'] = $fetchMode; + + return $this; + } + + /** + * Get the database manager instance. + * + * @return \Illuminate\Database\DatabaseManager + */ + public function getDatabaseManager() + { + return $this->manager; + } + + /** + * Get the current event dispatcher instance. + * + * @return \Illuminate\Contracts\Events\Dispatcher + */ + public function getEventDispatcher() + { + if ($this->container->bound('events')) + { + return $this->container['events']; + } + } + + /** + * Set the event dispatcher instance to be used by connections. + * + * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher + * @return void + */ + public function setEventDispatcher(Dispatcher $dispatcher) + { + $this->container->instance('events', $dispatcher); + } + + /** + * Dynamically pass methods to the default connection. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public static function __callStatic($method, $parameters) + { + return call_user_func_array(array(static::connection(), $method), $parameters); + } + +} diff --git a/vendor/illuminate/database/Connection.php b/vendor/illuminate/database/Connection.php new file mode 100755 index 0000000..42d86ea --- /dev/null +++ b/vendor/illuminate/database/Connection.php @@ -0,0 +1,1126 @@ +pdo = $pdo; + + // First we will setup the default properties. We keep track of the DB + // name we are connected to since it is needed when some reflective + // type commands are run such as checking whether a table exists. + $this->database = $database; + + $this->tablePrefix = $tablePrefix; + + $this->config = $config; + + // We need to initialize a query grammar and the query post processors + // which are both very important parts of the database abstractions + // so we initialize these to their default values while starting. + $this->useDefaultQueryGrammar(); + + $this->useDefaultPostProcessor(); + } + + /** + * Set the query grammar to the default implementation. + * + * @return void + */ + public function useDefaultQueryGrammar() + { + $this->queryGrammar = $this->getDefaultQueryGrammar(); + } + + /** + * Get the default query grammar instance. + * + * @return \Illuminate\Database\Query\Grammars\Grammar + */ + protected function getDefaultQueryGrammar() + { + return new QueryGrammar; + } + + /** + * Set the schema grammar to the default implementation. + * + * @return void + */ + public function useDefaultSchemaGrammar() + { + $this->schemaGrammar = $this->getDefaultSchemaGrammar(); + } + + /** + * Get the default schema grammar instance. + * + * @return \Illuminate\Database\Schema\Grammars\Grammar + */ + protected function getDefaultSchemaGrammar() + { + // + } + + /** + * Set the query post processor to the default implementation. + * + * @return void + */ + public function useDefaultPostProcessor() + { + $this->postProcessor = $this->getDefaultPostProcessor(); + } + + /** + * Get the default post processor instance. + * + * @return \Illuminate\Database\Query\Processors\Processor + */ + protected function getDefaultPostProcessor() + { + return new Query\Processors\Processor; + } + + /** + * Get a schema builder instance for the connection. + * + * @return \Illuminate\Database\Schema\Builder + */ + public function getSchemaBuilder() + { + if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); } + + return new Schema\Builder($this); + } + + /** + * Begin a fluent query against a database table. + * + * @param string $table + * @return \Illuminate\Database\Query\Builder + */ + public function table($table) + { + $processor = $this->getPostProcessor(); + + $query = new Query\Builder($this, $this->getQueryGrammar(), $processor); + + return $query->from($table); + } + + /** + * Get a new raw query expression. + * + * @param mixed $value + * @return \Illuminate\Database\Query\Expression + */ + public function raw($value) + { + return new Query\Expression($value); + } + + /** + * Run a select statement and return a single result. + * + * @param string $query + * @param array $bindings + * @return mixed + */ + public function selectOne($query, $bindings = array()) + { + $records = $this->select($query, $bindings); + + return count($records) > 0 ? reset($records) : null; + } + + /** + * Run a select statement against the database. + * + * @param string $query + * @param array $bindings + * @return array + */ + public function selectFromWriteConnection($query, $bindings = array()) + { + return $this->select($query, $bindings, false); + } + + /** + * Run a select statement against the database. + * + * @param string $query + * @param array $bindings + * @param bool $useReadPdo + * @return array + */ + public function select($query, $bindings = array(), $useReadPdo = true) + { + return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo) + { + if ($me->pretending()) return array(); + + // For select statements, we'll simply execute the query and return an array + // of the database result set. Each element in the array will be a single + // row from the database table, and will either be an array or objects. + $statement = $this->getPdoForSelect($useReadPdo)->prepare($query); + + $statement->execute($me->prepareBindings($bindings)); + + return $statement->fetchAll($me->getFetchMode()); + }); + } + + /** + * Get the PDO connection to use for a select query. + * + * @param bool $useReadPdo + * @return \PDO + */ + protected function getPdoForSelect($useReadPdo = true) + { + return $useReadPdo ? $this->getReadPdo() : $this->getPdo(); + } + + /** + * Run an insert statement against the database. + * + * @param string $query + * @param array $bindings + * @return bool + */ + public function insert($query, $bindings = array()) + { + return $this->statement($query, $bindings); + } + + /** + * Run an update statement against the database. + * + * @param string $query + * @param array $bindings + * @return int + */ + public function update($query, $bindings = array()) + { + return $this->affectingStatement($query, $bindings); + } + + /** + * Run a delete statement against the database. + * + * @param string $query + * @param array $bindings + * @return int + */ + public function delete($query, $bindings = array()) + { + return $this->affectingStatement($query, $bindings); + } + + /** + * Execute an SQL statement and return the boolean result. + * + * @param string $query + * @param array $bindings + * @return bool + */ + public function statement($query, $bindings = array()) + { + return $this->run($query, $bindings, function($me, $query, $bindings) + { + if ($me->pretending()) return true; + + $bindings = $me->prepareBindings($bindings); + + return $me->getPdo()->prepare($query)->execute($bindings); + }); + } + + /** + * Run an SQL statement and get the number of rows affected. + * + * @param string $query + * @param array $bindings + * @return int + */ + public function affectingStatement($query, $bindings = array()) + { + return $this->run($query, $bindings, function($me, $query, $bindings) + { + if ($me->pretending()) return 0; + + // For update or delete statements, we want to get the number of rows affected + // by the statement and return that back to the developer. We'll first need + // to execute the statement and then we'll use PDO to fetch the affected. + $statement = $me->getPdo()->prepare($query); + + $statement->execute($me->prepareBindings($bindings)); + + return $statement->rowCount(); + }); + } + + /** + * Run a raw, unprepared query against the PDO connection. + * + * @param string $query + * @return bool + */ + public function unprepared($query) + { + return $this->run($query, array(), function($me, $query) + { + if ($me->pretending()) return true; + + return (bool) $me->getPdo()->exec($query); + }); + } + + /** + * Prepare the query bindings for execution. + * + * @param array $bindings + * @return array + */ + public function prepareBindings(array $bindings) + { + $grammar = $this->getQueryGrammar(); + + foreach ($bindings as $key => $value) + { + // We need to transform all instances of the DateTime class into an actual + // date string. Each query grammar maintains its own date string format + // so we'll just ask the grammar for the format to get from the date. + if ($value instanceof DateTime) + { + $bindings[$key] = $value->format($grammar->getDateFormat()); + } + elseif ($value === false) + { + $bindings[$key] = 0; + } + } + + return $bindings; + } + + /** + * Execute a Closure within a transaction. + * + * @param \Closure $callback + * @return mixed + * + * @throws \Exception + */ + public function transaction(Closure $callback) + { + $this->beginTransaction(); + + // We'll simply execute the given callback within a try / catch block + // and if we catch any exception we can rollback the transaction + // so that none of the changes are persisted to the database. + try + { + $result = $callback($this); + + $this->commit(); + } + + // If we catch an exception, we will roll back so nothing gets messed + // up in the database. Then we'll re-throw the exception so it can + // be handled how the developer sees fit for their applications. + catch (Exception $e) + { + $this->rollBack(); + + throw $e; + } + + return $result; + } + + /** + * Start a new database transaction. + * + * @return void + */ + public function beginTransaction() + { + ++$this->transactions; + + if ($this->transactions == 1) + { + $this->pdo->beginTransaction(); + } + + $this->fireConnectionEvent('beganTransaction'); + } + + /** + * Commit the active database transaction. + * + * @return void + */ + public function commit() + { + if ($this->transactions == 1) $this->pdo->commit(); + + --$this->transactions; + + $this->fireConnectionEvent('committed'); + } + + /** + * Rollback the active database transaction. + * + * @return void + */ + public function rollBack() + { + if ($this->transactions == 1) + { + $this->transactions = 0; + + $this->pdo->rollBack(); + } + else + { + --$this->transactions; + } + + $this->fireConnectionEvent('rollingBack'); + } + + /** + * Get the number of active transactions. + * + * @return int + */ + public function transactionLevel() + { + return $this->transactions; + } + + /** + * Execute the given callback in "dry run" mode. + * + * @param \Closure $callback + * @return array + */ + public function pretend(Closure $callback) + { + $loggingQueries = $this->loggingQueries; + + $this->enableQueryLog(); + + $this->pretending = true; + + $this->queryLog = []; + + // Basically to make the database connection "pretend", we will just return + // the default values for all the query methods, then we will return an + // array of queries that were "executed" within the Closure callback. + $callback($this); + + $this->pretending = false; + + $this->loggingQueries = $loggingQueries; + + return $this->queryLog; + } + + /** + * Run a SQL statement and log its execution context. + * + * @param string $query + * @param array $bindings + * @param \Closure $callback + * @return mixed + * + * @throws \Illuminate\Database\QueryException + */ + protected function run($query, $bindings, Closure $callback) + { + $this->reconnectIfMissingConnection(); + + $start = microtime(true); + + // Here we will run this query. If an exception occurs we'll determine if it was + // caused by a connection that has been lost. If that is the cause, we'll try + // to re-establish connection and re-run the query with a fresh connection. + try + { + $result = $this->runQueryCallback($query, $bindings, $callback); + } + catch (QueryException $e) + { + $result = $this->tryAgainIfCausedByLostConnection( + $e, $query, $bindings, $callback + ); + } + + // Once we have run the query we will calculate the time that it took to run and + // then log the query, bindings, and execution time so we will report them on + // the event that the developer needs them. We'll log time in milliseconds. + $time = $this->getElapsedTime($start); + + $this->logQuery($query, $bindings, $time); + + return $result; + } + + /** + * Run a SQL statement. + * + * @param string $query + * @param array $bindings + * @param \Closure $callback + * @return mixed + * + * @throws \Illuminate\Database\QueryException + */ + protected function runQueryCallback($query, $bindings, Closure $callback) + { + // To execute the statement, we'll simply call the callback, which will actually + // run the SQL against the PDO connection. Then we can calculate the time it + // took to execute and log the query SQL, bindings and time in our memory. + try + { + $result = $callback($this, $query, $bindings); + } + + // If an exception occurs when attempting to run a query, we'll format the error + // message to include the bindings with SQL, which will make this exception a + // lot more helpful to the developer instead of just the database's errors. + catch (Exception $e) + { + throw new QueryException( + $query, $this->prepareBindings($bindings), $e + ); + } + + return $result; + } + + /** + * Handle a query exception that occurred during query execution. + * + * @param \Illuminate\Database\QueryException $e + * @param string $query + * @param array $bindings + * @param \Closure $callback + * @return mixed + * + * @throws \Illuminate\Database\QueryException + */ + protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback) + { + if ($this->causedByLostConnection($e)) + { + $this->reconnect(); + + return $this->runQueryCallback($query, $bindings, $callback); + } + + throw $e; + } + + /** + * Determine if the given exception was caused by a lost connection. + * + * @param \Illuminate\Database\QueryException $e + * @return bool + */ + protected function causedByLostConnection(QueryException $e) + { + $message = $e->getPrevious()->getMessage(); + + return str_contains($message, [ + 'server has gone away', + 'no connection to the server', + 'Lost connection', + ]); + } + + /** + * Disconnect from the underlying PDO connection. + * + * @return void + */ + public function disconnect() + { + $this->setPdo(null)->setReadPdo(null); + } + + /** + * Reconnect to the database. + * + * @return void + * + * @throws \LogicException + */ + public function reconnect() + { + if (is_callable($this->reconnector)) + { + return call_user_func($this->reconnector, $this); + } + + throw new LogicException("Lost connection and no reconnector available."); + } + + /** + * Reconnect to the database if a PDO connection is missing. + * + * @return void + */ + protected function reconnectIfMissingConnection() + { + if (is_null($this->getPdo()) || is_null($this->getReadPdo())) + { + $this->reconnect(); + } + } + + /** + * Log a query in the connection's query log. + * + * @param string $query + * @param array $bindings + * @param float|null $time + * @return void + */ + public function logQuery($query, $bindings, $time = null) + { + if (isset($this->events)) + { + $this->events->fire('illuminate.query', array($query, $bindings, $time, $this->getName())); + } + + if ( ! $this->loggingQueries) return; + + $this->queryLog[] = compact('query', 'bindings', 'time'); + } + + /** + * Register a database query listener with the connection. + * + * @param \Closure $callback + * @return void + */ + public function listen(Closure $callback) + { + if (isset($this->events)) + { + $this->events->listen('illuminate.query', $callback); + } + } + + /** + * Fire an event for this connection. + * + * @param string $event + * @return void + */ + protected function fireConnectionEvent($event) + { + if (isset($this->events)) + { + $this->events->fire('connection.'.$this->getName().'.'.$event, $this); + } + } + + /** + * Get the elapsed time since a given starting point. + * + * @param int $start + * @return float + */ + protected function getElapsedTime($start) + { + return round((microtime(true) - $start) * 1000, 2); + } + + /** + * Get a Doctrine Schema Column instance. + * + * @param string $table + * @param string $column + * @return \Doctrine\DBAL\Schema\Column + */ + public function getDoctrineColumn($table, $column) + { + $schema = $this->getDoctrineSchemaManager(); + + return $schema->listTableDetails($table)->getColumn($column); + } + + /** + * Get the Doctrine DBAL schema manager for the connection. + * + * @return \Doctrine\DBAL\Schema\AbstractSchemaManager + */ + public function getDoctrineSchemaManager() + { + return $this->getDoctrineDriver()->getSchemaManager($this->getDoctrineConnection()); + } + + /** + * Get the Doctrine DBAL database connection instance. + * + * @return \Doctrine\DBAL\Connection + */ + public function getDoctrineConnection() + { + $driver = $this->getDoctrineDriver(); + + $data = array('pdo' => $this->pdo, 'dbname' => $this->getConfig('database')); + + return new DoctrineConnection($data, $driver); + } + + /** + * Get the current PDO connection. + * + * @return \PDO + */ + public function getPdo() + { + return $this->pdo; + } + + /** + * Get the current PDO connection used for reading. + * + * @return \PDO + */ + public function getReadPdo() + { + if ($this->transactions >= 1) return $this->getPdo(); + + return $this->readPdo ?: $this->pdo; + } + + /** + * Set the PDO connection. + * + * @param \PDO|null $pdo + * @return $this + */ + public function setPdo($pdo) + { + if ($this->transactions >= 1) + throw new RuntimeException("Can't swap PDO instance while within transaction."); + + $this->pdo = $pdo; + + return $this; + } + + /** + * Set the PDO connection used for reading. + * + * @param \PDO|null $pdo + * @return $this + */ + public function setReadPdo($pdo) + { + $this->readPdo = $pdo; + + return $this; + } + + /** + * Set the reconnect instance on the connection. + * + * @param callable $reconnector + * @return $this + */ + public function setReconnector(callable $reconnector) + { + $this->reconnector = $reconnector; + + return $this; + } + + /** + * Get the database connection name. + * + * @return string|null + */ + public function getName() + { + return $this->getConfig('name'); + } + + /** + * Get an option from the configuration options. + * + * @param string $option + * @return mixed + */ + public function getConfig($option) + { + return array_get($this->config, $option); + } + + /** + * Get the PDO driver name. + * + * @return string + */ + public function getDriverName() + { + return $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME); + } + + /** + * Get the query grammar used by the connection. + * + * @return \Illuminate\Database\Query\Grammars\Grammar + */ + public function getQueryGrammar() + { + return $this->queryGrammar; + } + + /** + * Set the query grammar used by the connection. + * + * @param \Illuminate\Database\Query\Grammars\Grammar + * @return void + */ + public function setQueryGrammar(Query\Grammars\Grammar $grammar) + { + $this->queryGrammar = $grammar; + } + + /** + * Get the schema grammar used by the connection. + * + * @return \Illuminate\Database\Schema\Grammars\Grammar + */ + public function getSchemaGrammar() + { + return $this->schemaGrammar; + } + + /** + * Set the schema grammar used by the connection. + * + * @param \Illuminate\Database\Schema\Grammars\Grammar + * @return void + */ + public function setSchemaGrammar(Schema\Grammars\Grammar $grammar) + { + $this->schemaGrammar = $grammar; + } + + /** + * Get the query post processor used by the connection. + * + * @return \Illuminate\Database\Query\Processors\Processor + */ + public function getPostProcessor() + { + return $this->postProcessor; + } + + /** + * Set the query post processor used by the connection. + * + * @param \Illuminate\Database\Query\Processors\Processor + * @return void + */ + public function setPostProcessor(Processor $processor) + { + $this->postProcessor = $processor; + } + + /** + * Get the event dispatcher used by the connection. + * + * @return \Illuminate\Contracts\Events\Dispatcher + */ + public function getEventDispatcher() + { + return $this->events; + } + + /** + * Set the event dispatcher instance on the connection. + * + * @param \Illuminate\Contracts\Events\Dispatcher + * @return void + */ + public function setEventDispatcher(Dispatcher $events) + { + $this->events = $events; + } + + /** + * Determine if the connection in a "dry run". + * + * @return bool + */ + public function pretending() + { + return $this->pretending === true; + } + + /** + * Get the default fetch mode for the connection. + * + * @return int + */ + public function getFetchMode() + { + return $this->fetchMode; + } + + /** + * Set the default fetch mode for the connection. + * + * @param int $fetchMode + * @return int + */ + public function setFetchMode($fetchMode) + { + $this->fetchMode = $fetchMode; + } + + /** + * Get the connection query log. + * + * @return array + */ + public function getQueryLog() + { + return $this->queryLog; + } + + /** + * Clear the query log. + * + * @return void + */ + public function flushQueryLog() + { + $this->queryLog = array(); + } + + /** + * Enable the query log on the connection. + * + * @return void + */ + public function enableQueryLog() + { + $this->loggingQueries = true; + } + + /** + * Disable the query log on the connection. + * + * @return void + */ + public function disableQueryLog() + { + $this->loggingQueries = false; + } + + /** + * Determine whether we're logging queries. + * + * @return bool + */ + public function logging() + { + return $this->loggingQueries; + } + + /** + * Get the name of the connected database. + * + * @return string + */ + public function getDatabaseName() + { + return $this->database; + } + + /** + * Set the name of the connected database. + * + * @param string $database + * @return string + */ + public function setDatabaseName($database) + { + $this->database = $database; + } + + /** + * Get the table prefix for the connection. + * + * @return string + */ + public function getTablePrefix() + { + return $this->tablePrefix; + } + + /** + * Set the table prefix in use by the connection. + * + * @param string $prefix + * @return void + */ + public function setTablePrefix($prefix) + { + $this->tablePrefix = $prefix; + + $this->getQueryGrammar()->setTablePrefix($prefix); + } + + /** + * Set the table prefix and return the grammar. + * + * @param \Illuminate\Database\Grammar $grammar + * @return \Illuminate\Database\Grammar + */ + public function withTablePrefix(Grammar $grammar) + { + $grammar->setTablePrefix($this->tablePrefix); + + return $grammar; + } + +} diff --git a/vendor/illuminate/database/ConnectionInterface.php b/vendor/illuminate/database/ConnectionInterface.php new file mode 100755 index 0000000..48d69b3 --- /dev/null +++ b/vendor/illuminate/database/ConnectionInterface.php @@ -0,0 +1,148 @@ + $connection) + { + $this->addConnection($name, $connection); + } + } + + /** + * Get a database connection instance. + * + * @param string $name + * @return \Illuminate\Database\ConnectionInterface + */ + public function connection($name = null) + { + if (is_null($name)) $name = $this->getDefaultConnection(); + + return $this->connections[$name]; + } + + /** + * Add a connection to the resolver. + * + * @param string $name + * @param \Illuminate\Database\ConnectionInterface $connection + * @return void + */ + public function addConnection($name, ConnectionInterface $connection) + { + $this->connections[$name] = $connection; + } + + /** + * Check if a connection has been registered. + * + * @param string $name + * @return bool + */ + public function hasConnection($name) + { + return isset($this->connections[$name]); + } + + /** + * Get the default connection name. + * + * @return string + */ + public function getDefaultConnection() + { + return $this->default; + } + + /** + * Set the default connection name. + * + * @param string $name + * @return void + */ + public function setDefaultConnection($name) + { + $this->default = $name; + } + +} diff --git a/vendor/illuminate/database/ConnectionResolverInterface.php b/vendor/illuminate/database/ConnectionResolverInterface.php new file mode 100755 index 0000000..46abdc0 --- /dev/null +++ b/vendor/illuminate/database/ConnectionResolverInterface.php @@ -0,0 +1,28 @@ +container = $container; + } + + /** + * Establish a PDO connection based on the configuration. + * + * @param array $config + * @param string $name + * @return \Illuminate\Database\Connection + */ + public function make(array $config, $name = null) + { + $config = $this->parseConfig($config, $name); + + if (isset($config['read'])) + { + return $this->createReadWriteConnection($config); + } + + return $this->createSingleConnection($config); + } + + /** + * Create a single database connection instance. + * + * @param array $config + * @return \Illuminate\Database\Connection + */ + protected function createSingleConnection(array $config) + { + $pdo = $this->createConnector($config)->connect($config); + + return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config); + } + + /** + * Create a single database connection instance. + * + * @param array $config + * @return \Illuminate\Database\Connection + */ + protected function createReadWriteConnection(array $config) + { + $connection = $this->createSingleConnection($this->getWriteConfig($config)); + + return $connection->setReadPdo($this->createReadPdo($config)); + } + + /** + * Create a new PDO instance for reading. + * + * @param array $config + * @return \PDO + */ + protected function createReadPdo(array $config) + { + $readConfig = $this->getReadConfig($config); + + return $this->createConnector($readConfig)->connect($readConfig); + } + + /** + * Get the read configuration for a read / write connection. + * + * @param array $config + * @return array + */ + protected function getReadConfig(array $config) + { + $readConfig = $this->getReadWriteConfig($config, 'read'); + + return $this->mergeReadWriteConfig($config, $readConfig); + } + + /** + * Get the read configuration for a read / write connection. + * + * @param array $config + * @return array + */ + protected function getWriteConfig(array $config) + { + $writeConfig = $this->getReadWriteConfig($config, 'write'); + + return $this->mergeReadWriteConfig($config, $writeConfig); + } + + /** + * Get a read / write level configuration. + * + * @param array $config + * @param string $type + * @return array + */ + protected function getReadWriteConfig(array $config, $type) + { + if (isset($config[$type][0])) + { + return $config[$type][array_rand($config[$type])]; + } + + return $config[$type]; + } + + /** + * Merge a configuration for a read / write connection. + * + * @param array $config + * @param array $merge + * @return array + */ + protected function mergeReadWriteConfig(array $config, array $merge) + { + return array_except(array_merge($config, $merge), array('read', 'write')); + } + + /** + * Parse and prepare the database configuration. + * + * @param array $config + * @param string $name + * @return array + */ + protected function parseConfig(array $config, $name) + { + return array_add(array_add($config, 'prefix', ''), 'name', $name); + } + + /** + * Create a connector instance based on the configuration. + * + * @param array $config + * @return \Illuminate\Database\Connectors\ConnectorInterface + * + * @throws \InvalidArgumentException + */ + public function createConnector(array $config) + { + if ( ! isset($config['driver'])) + { + throw new InvalidArgumentException("A driver must be specified."); + } + + if ($this->container->bound($key = "db.connector.{$config['driver']}")) + { + return $this->container->make($key); + } + + switch ($config['driver']) + { + case 'mysql': + return new MySqlConnector; + + case 'pgsql': + return new PostgresConnector; + + case 'sqlite': + return new SQLiteConnector; + + case 'sqlsrv': + return new SqlServerConnector; + } + + throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]"); + } + + /** + * Create a new connection instance. + * + * @param string $driver + * @param \PDO $connection + * @param string $database + * @param string $prefix + * @param array $config + * @return \Illuminate\Database\Connection + * + * @throws \InvalidArgumentException + */ + protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array()) + { + if ($this->container->bound($key = "db.connection.{$driver}")) + { + return $this->container->make($key, array($connection, $database, $prefix, $config)); + } + + switch ($driver) + { + case 'mysql': + return new MySqlConnection($connection, $database, $prefix, $config); + + case 'pgsql': + return new PostgresConnection($connection, $database, $prefix, $config); + + case 'sqlite': + return new SQLiteConnection($connection, $database, $prefix, $config); + + case 'sqlsrv': + return new SqlServerConnection($connection, $database, $prefix, $config); + } + + throw new InvalidArgumentException("Unsupported driver [$driver]"); + } + +} diff --git a/vendor/illuminate/database/Connectors/Connector.php b/vendor/illuminate/database/Connectors/Connector.php new file mode 100755 index 0000000..6c388e0 --- /dev/null +++ b/vendor/illuminate/database/Connectors/Connector.php @@ -0,0 +1,71 @@ + PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_EMULATE_PREPARES => false, + ); + + /** + * Get the PDO options based on the configuration. + * + * @param array $config + * @return array + */ + public function getOptions(array $config) + { + $options = array_get($config, 'options', array()); + + return array_diff_key($this->options, $options) + $options; + } + + /** + * Create a new PDO connection. + * + * @param string $dsn + * @param array $config + * @param array $options + * @return \PDO + */ + public function createConnection($dsn, array $config, array $options) + { + $username = array_get($config, 'username'); + + $password = array_get($config, 'password'); + + return new PDO($dsn, $username, $password, $options); + } + + /** + * Get the default PDO connection options. + * + * @return array + */ + public function getDefaultOptions() + { + return $this->options; + } + + /** + * Set the default PDO connection options. + * + * @param array $options + * @return void + */ + public function setDefaultOptions(array $options) + { + $this->options = $options; + } + +} diff --git a/vendor/illuminate/database/Connectors/ConnectorInterface.php b/vendor/illuminate/database/Connectors/ConnectorInterface.php new file mode 100755 index 0000000..c2c76a5 --- /dev/null +++ b/vendor/illuminate/database/Connectors/ConnectorInterface.php @@ -0,0 +1,13 @@ +getDsn($config); + + $options = $this->getOptions($config); + + // We need to grab the PDO options that should be used while making the brand + // new connection instance. The PDO options control various aspects of the + // connection's behavior, and some might be specified by the developers. + $connection = $this->createConnection($dsn, $config, $options); + + if (isset($config['unix_socket'])) + { + $connection->exec("use `{$config['database']}`;"); + } + + $collation = $config['collation']; + + // Next we will set the "names" and "collation" on the clients connections so + // a correct character set will be used by this client. The collation also + // is set on the server but needs to be set here on this client objects. + $charset = $config['charset']; + + $names = "set names '$charset'". + ( ! is_null($collation) ? " collate '$collation'" : ''); + + $connection->prepare($names)->execute(); + + // Next, we will check to see if a timezone has been specified in this config + // and if it has we will issue a statement to modify the timezone with the + // database. Setting this DB timezone is an optional configuration item. + if (isset($config['timezone'])) + { + $connection->prepare( + 'set time_zone="'.$config['timezone'].'"' + )->execute(); + } + + // If the "strict" option has been configured for the connection we'll enable + // strict mode on all of these tables. This enforces some extra rules when + // using the MySQL database system and is a quicker way to enforce them. + if (isset($config['strict']) && $config['strict']) + { + $connection->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute(); + } + + return $connection; + } + + /** + * Create a DSN string from a configuration. + * + * Chooses socket or host/port based on the 'unix_socket' config value. + * + * @param array $config + * @return string + */ + protected function getDsn(array $config) + { + return $this->configHasSocket($config) ? $this->getSocketDsn($config) : $this->getHostDsn($config); + } + + /** + * Determine if the given configuration array has a UNIX socket value. + * + * @param array $config + * @return bool + */ + protected function configHasSocket(array $config) + { + return isset($config['unix_socket']) && ! empty($config['unix_socket']); + } + + /** + * Get the DSN string for a socket configuration. + * + * @param array $config + * @return string + */ + protected function getSocketDsn(array $config) + { + extract($config); + + return "mysql:unix_socket={$config['unix_socket']};dbname={$database}"; + } + + /** + * Get the DSN string for a host / port configuration. + * + * @param array $config + * @return string + */ + protected function getHostDsn(array $config) + { + extract($config); + + return isset($config['port']) + ? "mysql:host={$host};port={$port};dbname={$database}" + : "mysql:host={$host};dbname={$database}"; + } + +} diff --git a/vendor/illuminate/database/Connectors/PostgresConnector.php b/vendor/illuminate/database/Connectors/PostgresConnector.php new file mode 100755 index 0000000..d725d72 --- /dev/null +++ b/vendor/illuminate/database/Connectors/PostgresConnector.php @@ -0,0 +1,96 @@ + PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + ); + + /** + * Establish a database connection. + * + * @param array $config + * @return \PDO + */ + public function connect(array $config) + { + // First we'll create the basic DSN and connection instance connecting to the + // using the configuration option specified by the developer. We will also + // set the default character set on the connections to UTF-8 by default. + $dsn = $this->getDsn($config); + + $options = $this->getOptions($config); + + $connection = $this->createConnection($dsn, $config, $options); + + $charset = $config['charset']; + + $connection->prepare("set names '$charset'")->execute(); + + // Next, we will check to see if a timezone has been specified in this config + // and if it has we will issue a statement to modify the timezone with the + // database. Setting this DB timezone is an optional configuration item. + if (isset($config['timezone'])) + { + $timezone = $config['timezone']; + + $connection->prepare("set time zone '$timezone'")->execute(); + } + + // Unlike MySQL, Postgres allows the concept of "schema" and a default schema + // may have been specified on the connections. If that is the case we will + // set the default schema search paths to the specified database schema. + if (isset($config['schema'])) + { + $schema = $config['schema']; + + $connection->prepare("set search_path to \"{$schema}\"")->execute(); + } + + return $connection; + } + + /** + * Create a DSN string from a configuration. + * + * @param array $config + * @return string + */ + protected function getDsn(array $config) + { + // First we will create the basic DSN setup as well as the port if it is in + // in the configuration options. This will give us the basic DSN we will + // need to establish the PDO connections and return them back for use. + extract($config); + + $host = isset($host) ? "host={$host};" : ''; + + $dsn = "pgsql:{$host}dbname={$database}"; + + // If a port was specified, we will add it to this Postgres DSN connections + // format. Once we have done that we are ready to return this connection + // string back out for usage, as this has been fully constructed here. + if (isset($config['port'])) + { + $dsn .= ";port={$port}"; + } + + if (isset($config['sslmode'])) + { + $dsn .= ";sslmode={$sslmode}"; + } + + return $dsn; + } + +} diff --git a/vendor/illuminate/database/Connectors/SQLiteConnector.php b/vendor/illuminate/database/Connectors/SQLiteConnector.php new file mode 100755 index 0000000..697a72b --- /dev/null +++ b/vendor/illuminate/database/Connectors/SQLiteConnector.php @@ -0,0 +1,40 @@ +getOptions($config); + + // SQLite supports "in-memory" databases that only last as long as the owning + // connection does. These are useful for tests or for short lifetime store + // querying. In-memory databases may only have a single open connection. + if ($config['database'] == ':memory:') + { + return $this->createConnection('sqlite::memory:', $config, $options); + } + + $path = realpath($config['database']); + + // Here we'll verify that the SQLite database exists before going any further + // as the developer probably wants to know if the database exists and this + // SQLite driver will not throw any exception if it does not by default. + if ($path === false) + { + throw new InvalidArgumentException("Database does not exist."); + } + + return $this->createConnection("sqlite:{$path}", $config, $options); + } + +} diff --git a/vendor/illuminate/database/Connectors/SqlServerConnector.php b/vendor/illuminate/database/Connectors/SqlServerConnector.php new file mode 100755 index 0000000..020cbaf --- /dev/null +++ b/vendor/illuminate/database/Connectors/SqlServerConnector.php @@ -0,0 +1,142 @@ + PDO::CASE_NATURAL, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + ); + + /** + * Establish a database connection. + * + * @param array $config + * @return \PDO + */ + public function connect(array $config) + { + $options = $this->getOptions($config); + + return $this->createConnection($this->getDsn($config), $config, $options); + } + + /** + * Create a DSN string from a configuration. + * + * @param array $config + * @return string + */ + protected function getDsn(array $config) + { + // First we will create the basic DSN setup as well as the port if it is in + // in the configuration options. This will give us the basic DSN we will + // need to establish the PDO connections and return them back for use. + if (in_array('dblib', $this->getAvailableDrivers())) + { + return $this->getDblibDsn($config); + } + else + { + return $this->getSqlSrvDsn($config); + } + } + + /** + * Get the DSN string for a DbLib connection. + * + * @param array $config + * @return string + */ + protected function getDblibDsn(array $config) + { + $arguments = array( + 'host' => $this->buildHostString($config, ':'), + 'dbname' => $config['database'] + ); + + $arguments = array_merge( + $arguments, array_only($config, ['appname', 'charset']) + ); + + return $this->buildConnectString('dblib', $arguments); + } + + /** + * Get the DSN string for a SqlSrv connection. + * + * @param array $config + * @return string + */ + protected function getSqlSrvDsn(array $config) + { + $arguments = array( + 'Server' => $this->buildHostString($config, ',') + ); + + if (isset($config['database'])) { + $arguments['Database'] = $config['database']; + } + + if (isset($config['appname'])) { + $arguments['APP'] = $config['appname']; + } + + return $this->buildConnectString('sqlsrv', $arguments); + } + + /** + * Build a connection string from the given arguments. + * + * @param string $driver + * @param array $arguments + * @return string + */ + protected function buildConnectString($driver, array $arguments) + { + $options = array_map(function($key) use ($arguments) + { + return sprintf("%s=%s", $key, $arguments[$key]); + }, array_keys($arguments)); + + return $driver.":".implode(';', $options); + } + + /** + * Build a host string from the given configuration. + * + * @param array $config + * @param string $separator + * @return string + */ + protected function buildHostString(array $config, $separator) + { + if(isset($config['port'])) + { + return $config['host'].$separator.$config['port']; + } + else + { + return $config['host']; + } + } + + /** + * Get the available PDO drivers. + * + * @return array + */ + protected function getAvailableDrivers() + { + return PDO::getAvailableDrivers(); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/BaseCommand.php b/vendor/illuminate/database/Console/Migrations/BaseCommand.php new file mode 100755 index 0000000..6300755 --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/BaseCommand.php @@ -0,0 +1,17 @@ +laravel->databasePath().'/migrations'; + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/InstallCommand.php b/vendor/illuminate/database/Console/Migrations/InstallCommand.php new file mode 100755 index 0000000..d89c0c4 --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/InstallCommand.php @@ -0,0 +1,69 @@ +repository = $repository; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + $this->repository->setSource($this->input->getOption('database')); + + $this->repository->createRepository(); + + $this->info("Migration table created successfully."); + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + ); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/MigrateCommand.php b/vendor/illuminate/database/Console/Migrations/MigrateCommand.php new file mode 100755 index 0000000..148325c --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/MigrateCommand.php @@ -0,0 +1,129 @@ +migrator = $migrator; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + if ( ! $this->confirmToProceed()) return; + + $this->prepareDatabase(); + + // The pretend option can be used for "simulating" the migration and grabbing + // the SQL queries that would fire if the migration were to be run against + // a database for real, which is helpful for double checking migrations. + $pretend = $this->input->getOption('pretend'); + + // Next, we will check to see if a path option has been defined. If it has + // we will use the path relative to the root of this installation folder + // so that migrations may be run for any path within the applications. + if ( ! is_null($path = $this->input->getOption('path'))) + { + $path = $this->laravel->basePath().'/'.$path; + } + else + { + $path = $this->getMigrationPath(); + } + + $this->migrator->run($path, $pretend); + + // Once the migrator has run we will grab the note output and send it out to + // the console screen, since the migrator itself functions without having + // any instances of the OutputInterface contract passed into the class. + foreach ($this->migrator->getNotes() as $note) + { + $this->output->writeln($note); + } + + // Finally, if the "seed" option has been given, we will re-run the database + // seed task to re-populate the database, which is convenient when adding + // a migration and a seed at the same time, as it is only this command. + if ($this->input->getOption('seed')) + { + $this->call('db:seed', ['--force' => true]); + } + } + + /** + * Prepare the migration database for running. + * + * @return void + */ + protected function prepareDatabase() + { + $this->migrator->setConnection($this->input->getOption('database')); + + if ( ! $this->migrator->repositoryExists()) + { + $options = array('--database' => $this->input->getOption('database')); + + $this->call('migrate:install', $options); + } + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + + array('path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'), + + array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), + + array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), + ); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/MigrateMakeCommand.php b/vendor/illuminate/database/Console/Migrations/MigrateMakeCommand.php new file mode 100755 index 0000000..2aafca6 --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/MigrateMakeCommand.php @@ -0,0 +1,120 @@ +creator = $creator; + $this->composer = $composer; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + // It's possible for the developer to specify the tables to modify in this + // schema operation. The developer may also specify if this table needs + // to be freshly created so we can create the appropriate migrations. + $name = $this->input->getArgument('name'); + + $table = $this->input->getOption('table'); + + $create = $this->input->getOption('create'); + + if ( ! $table && is_string($create)) $table = $create; + + // Now we are ready to write the migration out to disk. Once we've written + // the migration out, we will dump-autoload for the entire framework to + // make sure that the migrations are registered by the class loaders. + $this->writeMigration($name, $table, $create); + + $this->composer->dumpAutoloads(); + } + + /** + * Write the migration file to disk. + * + * @param string $name + * @param string $table + * @param bool $create + * @return string + */ + protected function writeMigration($name, $table, $create) + { + $path = $this->getMigrationPath(); + + $file = pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME); + + $this->line("Created Migration: $file"); + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return array( + array('name', InputArgument::REQUIRED, 'The name of the migration'), + ); + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('create', null, InputOption::VALUE_OPTIONAL, 'The table to be created.'), + + array('table', null, InputOption::VALUE_OPTIONAL, 'The table to migrate.'), + ); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/RefreshCommand.php b/vendor/illuminate/database/Console/Migrations/RefreshCommand.php new file mode 100755 index 0000000..baaf292 --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/RefreshCommand.php @@ -0,0 +1,96 @@ +confirmToProceed()) return; + + $database = $this->input->getOption('database'); + + $force = $this->input->getOption('force'); + + $this->call('migrate:reset', array( + '--database' => $database, '--force' => $force, + )); + + // The refresh command is essentially just a brief aggregate of a few other of + // the migration commands and just provides a convenient wrapper to execute + // them in succession. We'll also see if we need to re-seed the database. + $this->call('migrate', array( + '--database' => $database, '--force' => $force, + )); + + if ($this->needsSeeding()) + { + $this->runSeeder($database); + } + } + + /** + * Determine if the developer has requested database seeding. + * + * @return bool + */ + protected function needsSeeding() + { + return $this->option('seed') || $this->option('seeder'); + } + + /** + * Run the database seeder command. + * + * @param string $database + * @return void + */ + protected function runSeeder($database) + { + $class = $this->option('seeder') ?: 'DatabaseSeeder'; + + $this->call('db:seed', array('--database' => $database, '--class' => $class)); + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + + array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), + + array('seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'), + ); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/ResetCommand.php b/vendor/illuminate/database/Console/Migrations/ResetCommand.php new file mode 100755 index 0000000..42e3dfa --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/ResetCommand.php @@ -0,0 +1,86 @@ +migrator = $migrator; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + if ( ! $this->confirmToProceed()) return; + + $this->migrator->setConnection($this->input->getOption('database')); + + $pretend = $this->input->getOption('pretend'); + + $this->migrator->reset($pretend); + + // Once the migrator has run we will grab the note output and send it out to + // the console screen, since the migrator itself functions without having + // any instances of the OutputInterface contract passed into the class. + foreach ($this->migrator->getNotes() as $note) + { + $this->output->writeln($note); + } + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + + array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), + ); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/RollbackCommand.php b/vendor/illuminate/database/Console/Migrations/RollbackCommand.php new file mode 100755 index 0000000..c11198f --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/RollbackCommand.php @@ -0,0 +1,86 @@ +migrator = $migrator; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + if ( ! $this->confirmToProceed()) return; + + $this->migrator->setConnection($this->input->getOption('database')); + + $pretend = $this->input->getOption('pretend'); + + $this->migrator->rollback($pretend); + + // Once the migrator has run we will grab the note output and send it out to + // the console screen, since the migrator itself functions without having + // any instances of the OutputInterface contract passed into the class. + foreach ($this->migrator->getNotes() as $note) + { + $this->output->writeln($note); + } + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), + + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + + array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'), + ); + } + +} diff --git a/vendor/illuminate/database/Console/Migrations/StatusCommand.php b/vendor/illuminate/database/Console/Migrations/StatusCommand.php new file mode 100755 index 0000000..5405ac9 --- /dev/null +++ b/vendor/illuminate/database/Console/Migrations/StatusCommand.php @@ -0,0 +1,82 @@ +migrator = $migrator; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + if ( ! $this->migrator->repositoryExists()) + { + return $this->error('No migrations found.'); + } + + $ran = $this->migrator->getRepository()->getRan(); + + $migrations = []; + + foreach ($this->getAllMigrationFiles() as $migration) + { + $migrations[] = in_array($migration, $ran) ? ['Y', $migration] : ['N', $migration]; + } + + if (count($migrations) > 0) + { + $this->table(['Ran?', 'Migration'], $migrations); + } + else + { + $this->error('No migrations found'); + } + } + + /** + * Get all of the migration files. + * + * @return array + */ + protected function getAllMigrationFiles() + { + return $this->migrator->getMigrationFiles($this->getMigrationPath()); + } + +} diff --git a/vendor/illuminate/database/Console/SeedCommand.php b/vendor/illuminate/database/Console/SeedCommand.php new file mode 100755 index 0000000..cba115b --- /dev/null +++ b/vendor/illuminate/database/Console/SeedCommand.php @@ -0,0 +1,100 @@ +resolver = $resolver; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + if ( ! $this->confirmToProceed()) return; + + $this->resolver->setDefaultConnection($this->getDatabase()); + + $this->getSeeder()->run(); + } + + /** + * Get a seeder instance from the container. + * + * @return \Illuminate\Database\Seeder + */ + protected function getSeeder() + { + $class = $this->laravel->make($this->input->getOption('class')); + + return $class->setContainer($this->laravel)->setCommand($this); + } + + /** + * Get the name of the database connection to use. + * + * @return string + */ + protected function getDatabase() + { + $database = $this->input->getOption('database'); + + return $database ?: $this->laravel['config']['database.default']; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array( + array('class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'DatabaseSeeder'), + + array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed'), + + array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), + ); + } + +} diff --git a/vendor/illuminate/database/DatabaseManager.php b/vendor/illuminate/database/DatabaseManager.php new file mode 100755 index 0000000..cd8b7b7 --- /dev/null +++ b/vendor/illuminate/database/DatabaseManager.php @@ -0,0 +1,307 @@ +app = $app; + $this->factory = $factory; + } + + /** + * Get a database connection instance. + * + * @param string $name + * @return \Illuminate\Database\Connection + */ + public function connection($name = null) + { + list($name, $type) = $this->parseConnectionName($name); + + // If we haven't created this connection, we'll create it based on the config + // provided in the application. Once we've created the connections we will + // set the "fetch mode" for PDO which determines the query return types. + if ( ! isset($this->connections[$name])) + { + $connection = $this->makeConnection($name); + + $this->setPdoForType($connection, $type); + + $this->connections[$name] = $this->prepare($connection); + } + + return $this->connections[$name]; + } + + /** + * Parse the connection into an array of the name and read / write type. + * + * @param string $name + * @return array + */ + protected function parseConnectionName($name) + { + $name = $name ?: $this->getDefaultConnection(); + + return Str::endsWith($name, ['::read', '::write']) + ? explode('::', $name, 2) : [$name, null]; + } + + /** + * Disconnect from the given database and remove from local cache. + * + * @param string $name + * @return void + */ + public function purge($name = null) + { + $this->disconnect($name); + + unset($this->connections[$name]); + } + + /** + * Disconnect from the given database. + * + * @param string $name + * @return void + */ + public function disconnect($name = null) + { + if (isset($this->connections[$name = $name ?: $this->getDefaultConnection()])) + { + $this->connections[$name]->disconnect(); + } + } + + /** + * Reconnect to the given database. + * + * @param string $name + * @return \Illuminate\Database\Connection + */ + public function reconnect($name = null) + { + $this->disconnect($name = $name ?: $this->getDefaultConnection()); + + if ( ! isset($this->connections[$name])) + { + return $this->connection($name); + } + + return $this->refreshPdoConnections($name); + } + + /** + * Refresh the PDO connections on a given connection. + * + * @param string $name + * @return \Illuminate\Database\Connection + */ + protected function refreshPdoConnections($name) + { + $fresh = $this->makeConnection($name); + + return $this->connections[$name] + ->setPdo($fresh->getPdo()) + ->setReadPdo($fresh->getReadPdo()); + } + + /** + * Make the database connection instance. + * + * @param string $name + * @return \Illuminate\Database\Connection + */ + protected function makeConnection($name) + { + $config = $this->getConfig($name); + + // First we will check by the connection name to see if an extension has been + // registered specifically for that connection. If it has we will call the + // Closure and pass it the config allowing it to resolve the connection. + if (isset($this->extensions[$name])) + { + return call_user_func($this->extensions[$name], $config, $name); + } + + $driver = $config['driver']; + + // Next we will check to see if an extension has been registered for a driver + // and will call the Closure if so, which allows us to have a more generic + // resolver for the drivers themselves which applies to all connections. + if (isset($this->extensions[$driver])) + { + return call_user_func($this->extensions[$driver], $config, $name); + } + + return $this->factory->make($config, $name); + } + + /** + * Prepare the database connection instance. + * + * @param \Illuminate\Database\Connection $connection + * @return \Illuminate\Database\Connection + */ + protected function prepare(Connection $connection) + { + $connection->setFetchMode($this->app['config']['database.fetch']); + + if ($this->app->bound('events')) + { + $connection->setEventDispatcher($this->app['events']); + } + + // Here we'll set a reconnector callback. This reconnector can be any callable + // so we will set a Closure to reconnect from this manager with the name of + // the connection, which will allow us to reconnect from the connections. + $connection->setReconnector(function($connection) + { + $this->reconnect($connection->getName()); + }); + + return $connection; + } + + /** + * Prepare the read write mode for database connection instance. + * + * @param \Illuminate\Database\Connection $connection + * @param string $type + * @return \Illuminate\Database\Connection + */ + protected function setPdoForType(Connection $connection, $type = null) + { + if ($type == 'read') + { + $connection->setPdo($connection->getReadPdo()); + } + elseif ($type == 'write') + { + $connection->setReadPdo($connection->getPdo()); + } + + return $connection; + } + + /** + * Get the configuration for a connection. + * + * @param string $name + * @return array + * + * @throws \InvalidArgumentException + */ + protected function getConfig($name) + { + $name = $name ?: $this->getDefaultConnection(); + + // To get the database connection configuration, we will just pull each of the + // connection configurations and get the configurations for the given name. + // If the configuration doesn't exist, we'll throw an exception and bail. + $connections = $this->app['config']['database.connections']; + + if (is_null($config = array_get($connections, $name))) + { + throw new InvalidArgumentException("Database [$name] not configured."); + } + + return $config; + } + + /** + * Get the default connection name. + * + * @return string + */ + public function getDefaultConnection() + { + return $this->app['config']['database.default']; + } + + /** + * Set the default connection name. + * + * @param string $name + * @return void + */ + public function setDefaultConnection($name) + { + $this->app['config']['database.default'] = $name; + } + + /** + * Register an extension connection resolver. + * + * @param string $name + * @param callable $resolver + * @return void + */ + public function extend($name, callable $resolver) + { + $this->extensions[$name] = $resolver; + } + + /** + * Return all of the created connections. + * + * @return array + */ + public function getConnections() + { + return $this->connections; + } + + /** + * Dynamically pass methods to the default connection. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return call_user_func_array(array($this->connection(), $method), $parameters); + } + +} diff --git a/vendor/illuminate/database/DatabaseServiceProvider.php b/vendor/illuminate/database/DatabaseServiceProvider.php new file mode 100755 index 0000000..adb10b0 --- /dev/null +++ b/vendor/illuminate/database/DatabaseServiceProvider.php @@ -0,0 +1,61 @@ +app['db']); + + Model::setEventDispatcher($this->app['events']); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerQueueableEntityResolver(); + + // The connection factory is used to create the actual connection instances on + // the database. We will inject the factory into the manager so that it may + // make the connections while they are actually needed and not of before. + $this->app->singleton('db.factory', function($app) + { + return new ConnectionFactory($app); + }); + + // The database manager is used to resolve various connections, since multiple + // connections might be managed. It also implements the connection resolver + // interface which may be used by other components requiring connections. + $this->app->singleton('db', function($app) + { + return new DatabaseManager($app, $app['db.factory']); + }); + } + + /** + * Register the queueable entity resolver implementation. + * + * @return void + */ + protected function registerQueueableEntityResolver() + { + $this->app->singleton('Illuminate\Contracts\Queue\EntityResolver', function() + { + return new QueueEntityResolver; + }); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Builder.php b/vendor/illuminate/database/Eloquent/Builder.php new file mode 100755 index 0000000..4ea4ab3 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Builder.php @@ -0,0 +1,948 @@ +query = $query; + } + + /** + * Find a model by its primary key. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null + */ + public function find($id, $columns = array('*')) + { + if (is_array($id)) + { + return $this->findMany($id, $columns); + } + + $this->query->where($this->model->getQualifiedKeyName(), '=', $id); + + return $this->first($columns); + } + + /** + * Find a model by its primary key. + * + * @param array $ids + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection + */ + public function findMany($ids, $columns = array('*')) + { + if (empty($ids)) return $this->model->newCollection(); + + $this->query->whereIn($this->model->getQualifiedKeyName(), $ids); + + return $this->get($columns); + } + + /** + * Find a model by its primary key or throw an exception. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection + * + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ + public function findOrFail($id, $columns = array('*')) + { + $result = $this->find($id, $columns); + + if (is_array($id)) + { + if (count($result) == count(array_unique($id))) return $result; + } + elseif ( ! is_null($result)) + { + return $result; + } + + throw (new ModelNotFoundException)->setModel(get_class($this->model)); + } + + /** + * Execute the query and get the first result. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|static|null + */ + public function first($columns = array('*')) + { + return $this->take(1)->get($columns)->first(); + } + + /** + * Execute the query and get the first result or throw an exception. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|static + * + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ + public function firstOrFail($columns = array('*')) + { + if ( ! is_null($model = $this->first($columns))) return $model; + + throw (new ModelNotFoundException)->setModel(get_class($this->model)); + } + + /** + * Execute the query as a "select" statement. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection|static[] + */ + public function get($columns = array('*')) + { + $models = $this->getModels($columns); + + // If we actually found models we will also eager load any relationships that + // have been specified as needing to be eager loaded, which will solve the + // n+1 query issue for the developers to avoid running a lot of queries. + if (count($models) > 0) + { + $models = $this->eagerLoadRelations($models); + } + + return $this->model->newCollection($models); + } + + /** + * Pluck a single column from the database. + * + * @param string $column + * @return mixed + */ + public function pluck($column) + { + $result = $this->first(array($column)); + + if ($result) return $result->{$column}; + } + + /** + * Chunk the results of the query. + * + * @param int $count + * @param callable $callback + * @return void + */ + public function chunk($count, callable $callback) + { + $results = $this->forPage($page = 1, $count)->get(); + + while (count($results) > 0) + { + // On each chunk result set, we will pass them to the callback and then let the + // developer take care of everything within the callback, which allows us to + // keep the memory low for spinning through large result sets for working. + call_user_func($callback, $results); + + $page++; + + $results = $this->forPage($page, $count)->get(); + } + } + + /** + * Get an array with the values of a given column. + * + * @param string $column + * @param string $key + * @return array + */ + public function lists($column, $key = null) + { + $results = $this->query->lists($column, $key); + + // If the model has a mutator for the requested column, we will spin through + // the results and mutate the values so that the mutated version of these + // columns are returned as you would expect from these Eloquent models. + if ($this->model->hasGetMutator($column)) + { + foreach ($results as $key => &$value) + { + $fill = array($column => $value); + + $value = $this->model->newFromBuilder($fill)->$column; + } + } + + return $results; + } + + /** + * Paginate the given query. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function paginate($perPage = null, $columns = ['*']) + { + $total = $this->query->getCountForPagination(); + + $this->query->forPage( + $page = Paginator::resolveCurrentPage(), + $perPage = $perPage ?: $this->model->getPerPage() + ); + + return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [ + 'path' => Paginator::resolveCurrentPath(), + ]); + } + + /** + * Paginate the given query into a simple paginator. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\Paginator + */ + public function simplePaginate($perPage = null, $columns = ['*']) + { + $page = Paginator::resolveCurrentPage(); + + $perPage = $perPage ?: $this->model->getPerPage(); + + $this->skip(($page - 1) * $perPage)->take($perPage + 1); + + return new Paginator($this->get($columns), $perPage, $page, [ + 'path' => Paginator::resolveCurrentPath(), + ]); + } + + /** + * Update a record in the database. + * + * @param array $values + * @return int + */ + public function update(array $values) + { + return $this->query->update($this->addUpdatedAtColumn($values)); + } + + /** + * Increment a column's value by a given amount. + * + * @param string $column + * @param int $amount + * @param array $extra + * @return int + */ + public function increment($column, $amount = 1, array $extra = array()) + { + $extra = $this->addUpdatedAtColumn($extra); + + return $this->query->increment($column, $amount, $extra); + } + + /** + * Decrement a column's value by a given amount. + * + * @param string $column + * @param int $amount + * @param array $extra + * @return int + */ + public function decrement($column, $amount = 1, array $extra = array()) + { + $extra = $this->addUpdatedAtColumn($extra); + + return $this->query->decrement($column, $amount, $extra); + } + + /** + * Add the "updated at" column to an array of values. + * + * @param array $values + * @return array + */ + protected function addUpdatedAtColumn(array $values) + { + if ( ! $this->model->usesTimestamps()) return $values; + + $column = $this->model->getUpdatedAtColumn(); + + return array_add($values, $column, $this->model->freshTimestampString()); + } + + /** + * Delete a record from the database. + * + * @return mixed + */ + public function delete() + { + if (isset($this->onDelete)) + { + return call_user_func($this->onDelete, $this); + } + + return $this->query->delete(); + } + + /** + * Run the default delete function on the builder. + * + * @return mixed + */ + public function forceDelete() + { + return $this->query->delete(); + } + + /** + * Register a replacement for the default delete function. + * + * @param \Closure $callback + * @return void + */ + public function onDelete(Closure $callback) + { + $this->onDelete = $callback; + } + + /** + * Get the hydrated models without eager loading. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model[] + */ + public function getModels($columns = array('*')) + { + $results = $this->query->get($columns); + + $connection = $this->model->getConnectionName(); + + return $this->model->hydrate($results, $connection)->all(); + } + + /** + * Eager load the relationships for the models. + * + * @param array $models + * @return array + */ + public function eagerLoadRelations(array $models) + { + foreach ($this->eagerLoad as $name => $constraints) + { + // For nested eager loads we'll skip loading them here and they will be set as an + // eager load on the query to retrieve the relation so that they will be eager + // loaded on that query, because that is where they get hydrated as models. + if (strpos($name, '.') === false) + { + $models = $this->loadRelation($models, $name, $constraints); + } + } + + return $models; + } + + /** + * Eagerly load the relationship on a set of models. + * + * @param array $models + * @param string $name + * @param \Closure $constraints + * @return array + */ + protected function loadRelation(array $models, $name, Closure $constraints) + { + // First we will "back up" the existing where conditions on the query so we can + // add our eager constraints. Then we will merge the wheres that were on the + // query back to it in order that any where conditions might be specified. + $relation = $this->getRelation($name); + + $relation->addEagerConstraints($models); + + call_user_func($constraints, $relation); + + $models = $relation->initRelation($models, $name); + + // Once we have the results, we just match those back up to their parent models + // using the relationship instance. Then we just return the finished arrays + // of models which have been eagerly hydrated and are readied for return. + $results = $relation->getEager(); + + return $relation->match($models, $results, $name); + } + + /** + * Get the relation instance for the given relation name. + * + * @param string $relation + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function getRelation($relation) + { + // We want to run a relationship query without any constrains so that we will + // not have to remove these where clauses manually which gets really hacky + // and is error prone while we remove the developer's own where clauses. + $query = Relation::noConstraints(function() use ($relation) + { + return $this->getModel()->$relation(); + }); + + $nested = $this->nestedRelations($relation); + + // If there are nested relationships set on the query, we will put those onto + // the query instances so that they can be handled after this relationship + // is loaded. In this way they will all trickle down as they are loaded. + if (count($nested) > 0) + { + $query->getQuery()->with($nested); + } + + return $query; + } + + /** + * Get the deeply nested relations for a given top-level relation. + * + * @param string $relation + * @return array + */ + protected function nestedRelations($relation) + { + $nested = array(); + + // We are basically looking for any relationships that are nested deeper than + // the given top-level relationship. We will just check for any relations + // that start with the given top relations and adds them to our arrays. + foreach ($this->eagerLoad as $name => $constraints) + { + if ($this->isNested($name, $relation)) + { + $nested[substr($name, strlen($relation.'.'))] = $constraints; + } + } + + return $nested; + } + + /** + * Determine if the relationship is nested. + * + * @param string $name + * @param string $relation + * @return bool + */ + protected function isNested($name, $relation) + { + $dots = str_contains($name, '.'); + + return $dots && starts_with($name, $relation.'.'); + } + + /** + * Add a basic where clause to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @param string $boolean + * @return $this + */ + public function where($column, $operator = null, $value = null, $boolean = 'and') + { + if ($column instanceof Closure) + { + $query = $this->model->newQueryWithoutScopes(); + + call_user_func($column, $query); + + $this->query->addNestedWhereQuery($query->getQuery(), $boolean); + } + else + { + call_user_func_array(array($this->query, 'where'), func_get_args()); + } + + return $this; + } + + /** + * Add an "or where" clause to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function orWhere($column, $operator = null, $value = null) + { + return $this->where($column, $operator, $value, 'or'); + } + + /** + * Add a relationship count condition to the query. + * + * @param string $relation + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure|null $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null) + { + if (strpos($relation, '.') !== false) + { + return $this->hasNested($relation, $operator, $count, $boolean, $callback); + } + + $relation = $this->getHasRelationQuery($relation); + + $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this); + + if ($callback) call_user_func($callback, $query); + + return $this->addHasWhere($query, $relation, $operator, $count, $boolean); + } + + /** + * Add nested relationship count conditions to the query. + * + * @param string $relations + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + protected function hasNested($relations, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) + { + $relations = explode('.', $relations); + + // In order to nest "has", we need to add count relation constraints on the + // callback Closure. We'll do this by simply passing the Closure its own + // reference to itself so it calls itself recursively on each segment. + $closure = function ($q) use (&$closure, &$relations, $operator, $count, $boolean, $callback) + { + if (count($relations) > 1) + { + $q->whereHas(array_shift($relations), $closure); + } + else + { + $q->has(array_shift($relations), $operator, $count, 'and', $callback); + } + }; + + return $this->has(array_shift($relations), '>=', 1, $boolean, $closure); + } + + /** + * Add a relationship count condition to the query. + * + * @param string $relation + * @param string $boolean + * @param \Closure|null $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function doesntHave($relation, $boolean = 'and', Closure $callback = null) + { + return $this->has($relation, '<', 1, $boolean, $callback); + } + + /** + * Add a relationship count condition to the query with where clauses. + * + * @param string $relation + * @param \Closure $callback + * @param string $operator + * @param int $count + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function whereHas($relation, Closure $callback, $operator = '>=', $count = 1) + { + return $this->has($relation, $operator, $count, 'and', $callback); + } + + /** + * Add a relationship count condition to the query with where clauses. + * + * @param string $relation + * @param \Closure|null $callback + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function whereDoesntHave($relation, Closure $callback = null) + { + return $this->doesntHave($relation, 'and', $callback); + } + + /** + * Add a relationship count condition to the query with an "or". + * + * @param string $relation + * @param string $operator + * @param int $count + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function orHas($relation, $operator = '>=', $count = 1) + { + return $this->has($relation, $operator, $count, 'or'); + } + + /** + * Add a relationship count condition to the query with where clauses and an "or". + * + * @param string $relation + * @param \Closure $callback + * @param string $operator + * @param int $count + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function orWhereHas($relation, Closure $callback, $operator = '>=', $count = 1) + { + return $this->has($relation, $operator, $count, 'or', $callback); + } + + /** + * Add the "has" condition where clause to the query. + * + * @param \Illuminate\Database\Eloquent\Builder $hasQuery + * @param \Illuminate\Database\Eloquent\Relations\Relation $relation + * @param string $operator + * @param int $count + * @param string $boolean + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean) + { + $this->mergeWheresToHas($hasQuery, $relation); + + if (is_numeric($count)) + { + $count = new Expression($count); + } + + return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean); + } + + /** + * Merge the "wheres" from a relation query to a has query. + * + * @param \Illuminate\Database\Eloquent\Builder $hasQuery + * @param \Illuminate\Database\Eloquent\Relations\Relation $relation + * @return void + */ + protected function mergeWheresToHas(Builder $hasQuery, Relation $relation) + { + // Here we have the "has" query and the original relation. We need to copy over any + // where clauses the developer may have put in the relationship function over to + // the has query, and then copy the bindings from the "has" query to the main. + $relationQuery = $relation->getBaseQuery(); + + $hasQuery = $hasQuery->getModel()->removeGlobalScopes($hasQuery); + + $hasQuery->mergeWheres( + $relationQuery->wheres, $relationQuery->getBindings() + ); + + $this->query->mergeBindings($hasQuery->getQuery()); + } + + /** + * Get the "has relation" base query instance. + * + * @param string $relation + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function getHasRelationQuery($relation) + { + return Relation::noConstraints(function() use ($relation) + { + return $this->getModel()->$relation(); + }); + } + + /** + * Set the relationships that should be eager loaded. + * + * @param mixed $relations + * @return $this + */ + public function with($relations) + { + if (is_string($relations)) $relations = func_get_args(); + + $eagers = $this->parseRelations($relations); + + $this->eagerLoad = array_merge($this->eagerLoad, $eagers); + + return $this; + } + + /** + * Parse a list of relations into individuals. + * + * @param array $relations + * @return array + */ + protected function parseRelations(array $relations) + { + $results = array(); + + foreach ($relations as $name => $constraints) + { + // If the "relation" value is actually a numeric key, we can assume that no + // constraints have been specified for the eager load and we'll just put + // an empty Closure with the loader so that we can treat all the same. + if (is_numeric($name)) + { + $f = function() {}; + + list($name, $constraints) = array($constraints, $f); + } + + // We need to separate out any nested includes. Which allows the developers + // to load deep relationships using "dots" without stating each level of + // the relationship with its own key in the array of eager load names. + $results = $this->parseNested($name, $results); + + $results[$name] = $constraints; + } + + return $results; + } + + /** + * Parse the nested relationships in a relation. + * + * @param string $name + * @param array $results + * @return array + */ + protected function parseNested($name, $results) + { + $progress = array(); + + // If the relation has already been set on the result array, we will not set it + // again, since that would override any constraints that were already placed + // on the relationships. We will only set the ones that are not specified. + foreach (explode('.', $name) as $segment) + { + $progress[] = $segment; + + if ( ! isset($results[$last = implode('.', $progress)])) + { + $results[$last] = function() {}; + } + } + + return $results; + } + + /** + * Call the given model scope on the underlying model. + * + * @param string $scope + * @param array $parameters + * @return \Illuminate\Database\Query\Builder + */ + protected function callScope($scope, $parameters) + { + array_unshift($parameters, $this); + + return call_user_func_array(array($this->model, $scope), $parameters) ?: $this; + } + + /** + * Get the underlying query builder instance. + * + * @return \Illuminate\Database\Query\Builder|static + */ + public function getQuery() + { + return $this->query; + } + + /** + * Set the underlying query builder instance. + * + * @param \Illuminate\Database\Query\Builder $query + * @return $this + */ + public function setQuery($query) + { + $this->query = $query; + + return $this; + } + + /** + * Get the relationships being eagerly loaded. + * + * @return array + */ + public function getEagerLoads() + { + return $this->eagerLoad; + } + + /** + * Set the relationships being eagerly loaded. + * + * @param array $eagerLoad + * @return $this + */ + public function setEagerLoads(array $eagerLoad) + { + $this->eagerLoad = $eagerLoad; + + return $this; + } + + /** + * Get the model instance being queried. + * + * @return \Illuminate\Database\Eloquent\Model + */ + public function getModel() + { + return $this->model; + } + + /** + * Set a model instance for the model being queried. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return $this + */ + public function setModel(Model $model) + { + $this->model = $model; + + $this->query->from($model->getTable()); + + return $this; + } + + /** + * Extend the builder with a given callback. + * + * @param string $name + * @param \Closure $callback + * @return void + */ + public function macro($name, Closure $callback) + { + $this->macros[$name] = $callback; + } + + /** + * Get the given macro by name. + * + * @param string $name + * @return \Closure + */ + public function getMacro($name) + { + return array_get($this->macros, $name); + } + + /** + * Dynamically handle calls into the query instance. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + if (isset($this->macros[$method])) + { + array_unshift($parameters, $this); + + return call_user_func_array($this->macros[$method], $parameters); + } + elseif (method_exists($this->model, $scope = 'scope'.ucfirst($method))) + { + return $this->callScope($scope, $parameters); + } + + $result = call_user_func_array(array($this->query, $method), $parameters); + + return in_array($method, $this->passthru) ? $result : $this; + } + + /** + * Force a clone of the underlying query builder when cloning. + * + * @return void + */ + public function __clone() + { + $this->query = clone $this->query; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Collection.php b/vendor/illuminate/database/Eloquent/Collection.php new file mode 100755 index 0000000..ac9a160 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Collection.php @@ -0,0 +1,266 @@ +getKey(); + } + + return array_first($this->items, function($itemKey, $model) use ($key) + { + return $model->getKey() == $key; + + }, $default); + } + + /** + * Load a set of relationships onto the collection. + * + * @param mixed $relations + * @return $this + */ + public function load($relations) + { + if (count($this->items) > 0) + { + if (is_string($relations)) $relations = func_get_args(); + + $query = $this->first()->newQuery()->with($relations); + + $this->items = $query->eagerLoadRelations($this->items); + } + + return $this; + } + + /** + * Add an item to the collection. + * + * @param mixed $item + * @return $this + */ + public function add($item) + { + $this->items[] = $item; + + return $this; + } + + /** + * Determine if a key exists in the collection. + * + * @param mixed $key + * @param mixed $value + * @return bool + */ + public function contains($key, $value = null) + { + if (func_num_args() == 2) return parent::contains($key, $value); + + if ( ! $this->useAsCallable($key)) + { + $key = $key instanceof Model ? $key->getKey() : $key; + + return parent::contains(function($k, $m) use ($key) + { + return $m->getKey() == $key; + }); + } + + return parent::contains($key); + } + + /** + * Fetch a nested element of the collection. + * + * @param string $key + * @return static + */ + public function fetch($key) + { + return new static(array_fetch($this->toArray(), $key)); + } + + /** + * Get the max value of a given key. + * + * @param string $key + * @return mixed + */ + public function max($key) + { + return $this->reduce(function($result, $item) use ($key) + { + return is_null($result) || $item->{$key} > $result ? $item->{$key} : $result; + }); + } + + /** + * Get the min value of a given key. + * + * @param string $key + * @return mixed + */ + public function min($key) + { + return $this->reduce(function($result, $item) use ($key) + { + return is_null($result) || $item->{$key} < $result ? $item->{$key} : $result; + }); + } + + /** + * Get the array of primary keys. + * + * @return array + */ + public function modelKeys() + { + return array_map(function($m) { return $m->getKey(); }, $this->items); + } + + /** + * Merge the collection with the given items. + * + * @param \ArrayAccess|array $items + * @return static + */ + public function merge($items) + { + $dictionary = $this->getDictionary(); + + foreach ($items as $item) + { + $dictionary[$item->getKey()] = $item; + } + + return new static(array_values($dictionary)); + } + + /** + * Diff the collection with the given items. + * + * @param \ArrayAccess|array $items + * @return static + */ + public function diff($items) + { + $diff = new static; + + $dictionary = $this->getDictionary($items); + + foreach ($this->items as $item) + { + if ( ! isset($dictionary[$item->getKey()])) + { + $diff->add($item); + } + } + + return $diff; + } + + /** + * Intersect the collection with the given items. + * + * @param \ArrayAccess|array $items + * @return static + */ + public function intersect($items) + { + $intersect = new static; + + $dictionary = $this->getDictionary($items); + + foreach ($this->items as $item) + { + if (isset($dictionary[$item->getKey()])) + { + $intersect->add($item); + } + } + + return $intersect; + } + + /** + * Return only unique items from the collection. + * + * @return static + */ + public function unique() + { + $dictionary = $this->getDictionary(); + + return new static(array_values($dictionary)); + } + + /** + * Returns only the models from the collection with the specified keys. + * + * @param mixed $keys + * @return static + */ + public function only($keys) + { + $dictionary = array_only($this->getDictionary(), $keys); + + return new static(array_values($dictionary)); + } + + /** + * Returns all models in the collection except the models with specified keys. + * + * @param mixed $keys + * @return static + */ + public function except($keys) + { + $dictionary = array_except($this->getDictionary(), $keys); + + return new static(array_values($dictionary)); + } + + /** + * Get a dictionary keyed by primary keys. + * + * @param \ArrayAccess|array $items + * @return array + */ + public function getDictionary($items = null) + { + $items = is_null($items) ? $this->items : $items; + + $dictionary = array(); + + foreach ($items as $value) + { + $dictionary[$value->getKey()] = $value; + } + + return $dictionary; + } + + /** + * Get a base Support collection instance from this collection. + * + * @return \Illuminate\Support\Collection + */ + public function toBase() + { + return new BaseCollection($this->items); + } + +} diff --git a/vendor/illuminate/database/Eloquent/MassAssignmentException.php b/vendor/illuminate/database/Eloquent/MassAssignmentException.php new file mode 100755 index 0000000..8874c7c --- /dev/null +++ b/vendor/illuminate/database/Eloquent/MassAssignmentException.php @@ -0,0 +1,5 @@ +bootIfNotBooted(); + + $this->syncOriginal(); + + $this->fill($attributes); + } + + /** + * Check if the model needs to be booted and if so, do it. + * + * @return void + */ + protected function bootIfNotBooted() + { + $class = get_class($this); + + if ( ! isset(static::$booted[$class])) + { + static::$booted[$class] = true; + + $this->fireModelEvent('booting', false); + + static::boot(); + + $this->fireModelEvent('booted', false); + } + } + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + static::bootTraits(); + } + + /** + * Boot all of the bootable traits on the model. + * + * @return void + */ + protected static function bootTraits() + { + foreach (class_uses_recursive(get_called_class()) as $trait) + { + if (method_exists(get_called_class(), $method = 'boot'.class_basename($trait))) + { + forward_static_call([get_called_class(), $method]); + } + } + } + + /** + * Register a new global scope on the model. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return void + */ + public static function addGlobalScope(ScopeInterface $scope) + { + static::$globalScopes[get_called_class()][get_class($scope)] = $scope; + } + + /** + * Determine if a model has a global scope. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return bool + */ + public static function hasGlobalScope($scope) + { + return ! is_null(static::getGlobalScope($scope)); + } + + /** + * Get a global scope registered with the model. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return \Illuminate\Database\Eloquent\ScopeInterface|null + */ + public static function getGlobalScope($scope) + { + return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope) + { + return $scope instanceof $value; + }); + } + + /** + * Get the global scopes for this class instance. + * + * @return \Illuminate\Database\Eloquent\ScopeInterface[] + */ + public function getGlobalScopes() + { + return array_get(static::$globalScopes, get_class($this), []); + } + + /** + * Register an observer with the Model. + * + * @param object|string $class + * @return void + */ + public static function observe($class) + { + $instance = new static; + + $className = is_string($class) ? $class : get_class($class); + + // When registering a model observer, we will spin through the possible events + // and determine if this observer has that method. If it does, we will hook + // it into the model's event system, making it convenient to watch these. + foreach ($instance->getObservableEvents() as $event) + { + if (method_exists($class, $event)) + { + static::registerModelEvent($event, $className.'@'.$event); + } + } + } + + /** + * Fill the model with an array of attributes. + * + * @param array $attributes + * @return $this + * + * @throws \Illuminate\Database\Eloquent\MassAssignmentException + */ + public function fill(array $attributes) + { + $totallyGuarded = $this->totallyGuarded(); + + foreach ($this->fillableFromArray($attributes) as $key => $value) + { + $key = $this->removeTableFromKey($key); + + // The developers may choose to place some attributes in the "fillable" + // array, which means only those attributes may be set through mass + // assignment to the model, and all others will just be ignored. + if ($this->isFillable($key)) + { + $this->setAttribute($key, $value); + } + elseif ($totallyGuarded) + { + throw new MassAssignmentException($key); + } + } + + return $this; + } + + /** + * Fill the model with an array of attributes. Force mass assignment. + * + * @param array $attributes + * @return $this + */ + public function forceFill(array $attributes) + { + // Since some versions of PHP have a bug that prevents it from properly + // binding the late static context in a closure, we will first store + // the model in a variable, which we will then use in the closure. + $model = $this; + + return static::unguarded(function() use ($model, $attributes) + { + return $model->fill($attributes); + }); + } + + /** + * Get the fillable attributes of a given array. + * + * @param array $attributes + * @return array + */ + protected function fillableFromArray(array $attributes) + { + if (count($this->fillable) > 0 && ! static::$unguarded) + { + return array_intersect_key($attributes, array_flip($this->fillable)); + } + + return $attributes; + } + + /** + * Create a new instance of the given model. + * + * @param array $attributes + * @param bool $exists + * @return static + */ + public function newInstance($attributes = array(), $exists = false) + { + // This method just provides a convenient way for us to generate fresh model + // instances of this current model. It is particularly useful during the + // hydration of new objects via the Eloquent query builder instances. + $model = new static((array) $attributes); + + $model->exists = $exists; + + return $model; + } + + /** + * Create a new model instance that is existing. + * + * @param array $attributes + * @param string|null $connection + * @return static + */ + public function newFromBuilder($attributes = array(), $connection = null) + { + $model = $this->newInstance(array(), true); + + $model->setRawAttributes((array) $attributes, true); + + $model->setConnection($connection ?: $this->connection); + + return $model; + } + + /** + * Create a collection of models from plain arrays. + * + * @param array $items + * @param string|null $connection + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function hydrate(array $items, $connection = null) + { + $instance = (new static)->setConnection($connection); + + $items = array_map(function ($item) use ($instance) + { + return $instance->newFromBuilder($item); + }, $items); + + return $instance->newCollection($items); + } + + /** + * Create a collection of models from a raw query. + * + * @param string $query + * @param array $bindings + * @param string|null $connection + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function hydrateRaw($query, $bindings = array(), $connection = null) + { + $instance = (new static)->setConnection($connection); + + $items = $instance->getConnection()->select($query, $bindings); + + return static::hydrate($items, $connection); + } + + /** + * Save a new model and return the instance. + * + * @param array $attributes + * @return static + */ + public static function create(array $attributes) + { + $model = new static($attributes); + + $model->save(); + + return $model; + } + + /** + * Save a new model and return the instance. Allow mass-assignment. + * + * @param array $attributes + * @return static + */ + public static function forceCreate(array $attributes) + { + // Since some versions of PHP have a bug that prevents it from properly + // binding the late static context in a closure, we will first store + // the model in a variable, which we will then use in the closure. + $model = new static; + + return static::unguarded(function() use ($model, $attributes) + { + return $model->create($attributes); + }); + } + + /** + * Get the first record matching the attributes or create it. + * + * @param array $attributes + * @return static + */ + public static function firstOrCreate(array $attributes) + { + if ( ! is_null($instance = static::where($attributes)->first())) + { + return $instance; + } + + return static::create($attributes); + } + + /** + * Get the first record matching the attributes or instantiate it. + * + * @param array $attributes + * @return static + */ + public static function firstOrNew(array $attributes) + { + if ( ! is_null($instance = static::where($attributes)->first())) + { + return $instance; + } + + return new static($attributes); + } + + /** + * Create or update a record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return static + */ + public static function updateOrCreate(array $attributes, array $values = array()) + { + $instance = static::firstOrNew($attributes); + + $instance->fill($values)->save(); + + return $instance; + } + + /** + * Get the first model for the given attributes. + * + * @param array $attributes + * @return static|null + */ + protected static function firstByAttributes($attributes) + { + return static::where($attributes)->first(); + } + + /** + * Begin querying the model. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function query() + { + return (new static)->newQuery(); + } + + /** + * Begin querying the model on a given connection. + * + * @param string|null $connection + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function on($connection = null) + { + // First we will just create a fresh instance of this model, and then we can + // set the connection on the model so that it is be used for the queries + // we execute, as well as being set on each relationship we retrieve. + $instance = new static; + + $instance->setConnection($connection); + + return $instance->newQuery(); + } + + /** + * Begin querying the model on the write connection. + * + * @return \Illuminate\Database\Query\Builder + */ + public static function onWriteConnection() + { + $instance = new static; + + return $instance->newQuery()->useWritePdo(); + } + + /** + * Get all of the models from the database. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection|static[] + */ + public static function all($columns = array('*')) + { + $instance = new static; + + return $instance->newQuery()->get($columns); + } + + /** + * Find a model by its primary key. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|static|null + */ + public static function find($id, $columns = array('*')) + { + return static::query()->find($id, $columns); + } + + /** + * Find a model by its primary key or return new static. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|static + */ + public static function findOrNew($id, $columns = array('*')) + { + if ( ! is_null($model = static::find($id, $columns))) return $model; + + return new static; + } + + /** + * Reload a fresh model instance from the database. + * + * @param array $with + * @return $this + */ + public function fresh(array $with = array()) + { + if ( ! $this->exists) return; + + $key = $this->getKeyName(); + + return static::with($with)->where($key, $this->getKey())->first(); + } + + /** + * Eager load relations on the model. + * + * @param array|string $relations + * @return $this + */ + public function load($relations) + { + if (is_string($relations)) $relations = func_get_args(); + + $query = $this->newQuery()->with($relations); + + $query->eagerLoadRelations(array($this)); + + return $this; + } + + /** + * Being querying a model with eager loading. + * + * @param array|string $relations + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public static function with($relations) + { + if (is_string($relations)) $relations = func_get_args(); + + $instance = new static; + + return $instance->newQuery()->with($relations); + } + + /** + * Define a one-to-one relationship. + * + * @param string $related + * @param string $foreignKey + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function hasOne($related, $foreignKey = null, $localKey = null) + { + $foreignKey = $foreignKey ?: $this->getForeignKey(); + + $instance = new $related; + + $localKey = $localKey ?: $this->getKeyName(); + + return new HasOne($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey); + } + + /** + * Define a polymorphic one-to-one relationship. + * + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\MorphOne + */ + public function morphOne($related, $name, $type = null, $id = null, $localKey = null) + { + $instance = new $related; + + list($type, $id) = $this->getMorphs($name, $type, $id); + + $table = $instance->getTable(); + + $localKey = $localKey ?: $this->getKeyName(); + + return new MorphOne($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey); + } + + /** + * Define an inverse one-to-one or many relationship. + * + * @param string $related + * @param string $foreignKey + * @param string $otherKey + * @param string $relation + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) + { + // If no relation name was given, we will use this debug backtrace to extract + // the calling method's name and use that as the relationship name as most + // of the time this will be what we desire to use for the relationships. + if (is_null($relation)) + { + list(, $caller) = debug_backtrace(false, 2); + + $relation = $caller['function']; + } + + // If no foreign key was supplied, we can use a backtrace to guess the proper + // foreign key name by using the name of the relationship function, which + // when combined with an "_id" should conventionally match the columns. + if (is_null($foreignKey)) + { + $foreignKey = snake_case($relation).'_id'; + } + + $instance = new $related; + + // Once we have the foreign key names, we'll just create a new Eloquent query + // for the related models and returns the relationship instance which will + // actually be responsible for retrieving and hydrating every relations. + $query = $instance->newQuery(); + + $otherKey = $otherKey ?: $instance->getKeyName(); + + return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation); + } + + /** + * Define a polymorphic, inverse one-to-one or many relationship. + * + * @param string $name + * @param string $type + * @param string $id + * @return \Illuminate\Database\Eloquent\Relations\MorphTo + */ + public function morphTo($name = null, $type = null, $id = null) + { + // If no name is provided, we will use the backtrace to get the function name + // since that is most likely the name of the polymorphic interface. We can + // use that to get both the class and foreign key that will be utilized. + if (is_null($name)) + { + list(, $caller) = debug_backtrace(false, 2); + + $name = snake_case($caller['function']); + } + + list($type, $id) = $this->getMorphs($name, $type, $id); + + // If the type value is null it is probably safe to assume we're eager loading + // the relationship. When that is the case we will pass in a dummy query as + // there are multiple types in the morph and we can't use single queries. + if (is_null($class = $this->$type)) + { + return new MorphTo( + $this->newQuery(), $this, $id, null, $type, $name + ); + } + + // If we are not eager loading the relationship we will essentially treat this + // as a belongs-to style relationship since morph-to extends that class and + // we will pass in the appropriate values so that it behaves as expected. + else + { + $instance = new $class; + + return new MorphTo( + $instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name + ); + } + } + + /** + * Define a one-to-many relationship. + * + * @param string $related + * @param string $foreignKey + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function hasMany($related, $foreignKey = null, $localKey = null) + { + $foreignKey = $foreignKey ?: $this->getForeignKey(); + + $instance = new $related; + + $localKey = $localKey ?: $this->getKeyName(); + + return new HasMany($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey); + } + + /** + * Define a has-many-through relationship. + * + * @param string $related + * @param string $through + * @param string|null $firstKey + * @param string|null $secondKey + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough + */ + public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null) + { + $through = new $through; + + $firstKey = $firstKey ?: $this->getForeignKey(); + + $secondKey = $secondKey ?: $through->getForeignKey(); + + return new HasManyThrough((new $related)->newQuery(), $this, $through, $firstKey, $secondKey); + } + + /** + * Define a polymorphic one-to-many relationship. + * + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\MorphMany + */ + public function morphMany($related, $name, $type = null, $id = null, $localKey = null) + { + $instance = new $related; + + // Here we will gather up the morph type and ID for the relationship so that we + // can properly query the intermediate table of a relation. Finally, we will + // get the table and create the relationship instances for the developers. + list($type, $id) = $this->getMorphs($name, $type, $id); + + $table = $instance->getTable(); + + $localKey = $localKey ?: $this->getKeyName(); + + return new MorphMany($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey); + } + + /** + * Define a many-to-many relationship. + * + * @param string $related + * @param string $table + * @param string $foreignKey + * @param string $otherKey + * @param string $relation + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null) + { + // If no relationship name was passed, we will pull backtraces to get the + // name of the calling function. We will use that function name as the + // title of this relation since that is a great convention to apply. + if (is_null($relation)) + { + $relation = $this->getBelongsToManyCaller(); + } + + // First, we'll need to determine the foreign key and "other key" for the + // relationship. Once we have determined the keys we'll make the query + // instances as well as the relationship instances we need for this. + $foreignKey = $foreignKey ?: $this->getForeignKey(); + + $instance = new $related; + + $otherKey = $otherKey ?: $instance->getForeignKey(); + + // If no table name was provided, we can guess it by concatenating the two + // models using underscores in alphabetical order. The two model names + // are transformed to snake case from their default CamelCase also. + if (is_null($table)) + { + $table = $this->joiningTable($related); + } + + // Now we're ready to create a new query builder for the related model and + // the relationship instances for the relation. The relations will set + // appropriate query constraint and entirely manages the hydrations. + $query = $instance->newQuery(); + + return new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation); + } + + /** + * Define a polymorphic many-to-many relationship. + * + * @param string $related + * @param string $name + * @param string $table + * @param string $foreignKey + * @param string $otherKey + * @param bool $inverse + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + */ + public function morphToMany($related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false) + { + $caller = $this->getBelongsToManyCaller(); + + // First, we will need to determine the foreign key and "other key" for the + // relationship. Once we have determined the keys we will make the query + // instances, as well as the relationship instances we need for these. + $foreignKey = $foreignKey ?: $name.'_id'; + + $instance = new $related; + + $otherKey = $otherKey ?: $instance->getForeignKey(); + + // Now we're ready to create a new query builder for this related model and + // the relationship instances for this relation. This relations will set + // appropriate query constraints then entirely manages the hydrations. + $query = $instance->newQuery(); + + $table = $table ?: str_plural($name); + + return new MorphToMany( + $query, $this, $name, $table, $foreignKey, + $otherKey, $caller, $inverse + ); + } + + /** + * Define a polymorphic, inverse many-to-many relationship. + * + * @param string $related + * @param string $name + * @param string $table + * @param string $foreignKey + * @param string $otherKey + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + */ + public function morphedByMany($related, $name, $table = null, $foreignKey = null, $otherKey = null) + { + $foreignKey = $foreignKey ?: $this->getForeignKey(); + + // For the inverse of the polymorphic many-to-many relations, we will change + // the way we determine the foreign and other keys, as it is the opposite + // of the morph-to-many method since we're figuring out these inverses. + $otherKey = $otherKey ?: $name.'_id'; + + return $this->morphToMany($related, $name, $table, $foreignKey, $otherKey, true); + } + + /** + * Get the relationship name of the belongs to many. + * + * @return string + */ + protected function getBelongsToManyCaller() + { + $self = __FUNCTION__; + + $caller = array_first(debug_backtrace(false), function($key, $trace) use ($self) + { + $caller = $trace['function']; + + return ! in_array($caller, Model::$manyMethods) && $caller != $self; + }); + + return ! is_null($caller) ? $caller['function'] : null; + } + + /** + * Get the joining table name for a many-to-many relation. + * + * @param string $related + * @return string + */ + public function joiningTable($related) + { + // The joining table name, by convention, is simply the snake cased models + // sorted alphabetically and concatenated with an underscore, so we can + // just sort the models and join them together to get the table name. + $base = snake_case(class_basename($this)); + + $related = snake_case(class_basename($related)); + + $models = array($related, $base); + + // Now that we have the model names in an array we can just sort them and + // use the implode function to join them together with an underscores, + // which is typically used by convention within the database system. + sort($models); + + return strtolower(implode('_', $models)); + } + + /** + * Destroy the models for the given IDs. + * + * @param array|int $ids + * @return int + */ + public static function destroy($ids) + { + // We'll initialize a count here so we will return the total number of deletes + // for the operation. The developers can then check this number as a boolean + // type value or get this total count of records deleted for logging, etc. + $count = 0; + + $ids = is_array($ids) ? $ids : func_get_args(); + + $instance = new static; + + // We will actually pull the models from the database table and call delete on + // each of them individually so that their events get fired properly with a + // correct set of attributes in case the developers wants to check these. + $key = $instance->getKeyName(); + + foreach ($instance->whereIn($key, $ids)->get() as $model) + { + if ($model->delete()) $count++; + } + + return $count; + } + + /** + * Delete the model from the database. + * + * @return bool|null + * @throws \Exception + */ + public function delete() + { + if (is_null($this->primaryKey)) + { + throw new Exception("No primary key defined on model."); + } + + if ($this->exists) + { + if ($this->fireModelEvent('deleting') === false) return false; + + // Here, we'll touch the owning models, verifying these timestamps get updated + // for the models. This will allow any caching to get broken on the parents + // by the timestamp. Then we will go ahead and delete the model instance. + $this->touchOwners(); + + $this->performDeleteOnModel(); + + $this->exists = false; + + // Once the model has been deleted, we will fire off the deleted event so that + // the developers may hook into post-delete operations. We will then return + // a boolean true as the delete is presumably successful on the database. + $this->fireModelEvent('deleted', false); + + return true; + } + } + + /** + * Force a hard delete on a soft deleted model. + * + * This method protects developers from running forceDelete when trait is missing. + * + * @return void + */ + public function forceDelete() + { + return $this->delete(); + } + + /** + * Perform the actual delete query on this model instance. + * + * @return void + */ + protected function performDeleteOnModel() + { + $this->setKeysForSaveQuery($this->newQuery())->delete(); + } + + /** + * Register a saving model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function saving($callback, $priority = 0) + { + static::registerModelEvent('saving', $callback, $priority); + } + + /** + * Register a saved model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function saved($callback, $priority = 0) + { + static::registerModelEvent('saved', $callback, $priority); + } + + /** + * Register an updating model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function updating($callback, $priority = 0) + { + static::registerModelEvent('updating', $callback, $priority); + } + + /** + * Register an updated model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function updated($callback, $priority = 0) + { + static::registerModelEvent('updated', $callback, $priority); + } + + /** + * Register a creating model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function creating($callback, $priority = 0) + { + static::registerModelEvent('creating', $callback, $priority); + } + + /** + * Register a created model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function created($callback, $priority = 0) + { + static::registerModelEvent('created', $callback, $priority); + } + + /** + * Register a deleting model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function deleting($callback, $priority = 0) + { + static::registerModelEvent('deleting', $callback, $priority); + } + + /** + * Register a deleted model event with the dispatcher. + * + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + public static function deleted($callback, $priority = 0) + { + static::registerModelEvent('deleted', $callback, $priority); + } + + /** + * Remove all of the event listeners for the model. + * + * @return void + */ + public static function flushEventListeners() + { + if ( ! isset(static::$dispatcher)) return; + + $instance = new static; + + foreach ($instance->getObservableEvents() as $event) + { + static::$dispatcher->forget("eloquent.{$event}: ".get_called_class()); + } + } + + /** + * Register a model event with the dispatcher. + * + * @param string $event + * @param \Closure|string $callback + * @param int $priority + * @return void + */ + protected static function registerModelEvent($event, $callback, $priority = 0) + { + if (isset(static::$dispatcher)) + { + $name = get_called_class(); + + static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback, $priority); + } + } + + /** + * Get the observable event names. + * + * @return array + */ + public function getObservableEvents() + { + return array_merge( + array( + 'creating', 'created', 'updating', 'updated', + 'deleting', 'deleted', 'saving', 'saved', + 'restoring', 'restored', + ), + $this->observables + ); + } + + /** + * Set the observable event names. + * + * @param array $observables + * @return void + */ + public function setObservableEvents(array $observables) + { + $this->observables = $observables; + } + + /** + * Add an observable event name. + * + * @param mixed $observables + * @return void + */ + public function addObservableEvents($observables) + { + $observables = is_array($observables) ? $observables : func_get_args(); + + $this->observables = array_unique(array_merge($this->observables, $observables)); + } + + /** + * Remove an observable event name. + * + * @param mixed $observables + * @return void + */ + public function removeObservableEvents($observables) + { + $observables = is_array($observables) ? $observables : func_get_args(); + + $this->observables = array_diff($this->observables, $observables); + } + + /** + * Increment a column's value by a given amount. + * + * @param string $column + * @param int $amount + * @return int + */ + protected function increment($column, $amount = 1) + { + return $this->incrementOrDecrement($column, $amount, 'increment'); + } + + /** + * Decrement a column's value by a given amount. + * + * @param string $column + * @param int $amount + * @return int + */ + protected function decrement($column, $amount = 1) + { + return $this->incrementOrDecrement($column, $amount, 'decrement'); + } + + /** + * Run the increment or decrement method on the model. + * + * @param string $column + * @param int $amount + * @param string $method + * @return int + */ + protected function incrementOrDecrement($column, $amount, $method) + { + $query = $this->newQuery(); + + if ( ! $this->exists) + { + return $query->{$method}($column, $amount); + } + + $this->incrementOrDecrementAttributeValue($column, $amount, $method); + + return $query->where($this->getKeyName(), $this->getKey())->{$method}($column, $amount); + } + + /** + * Increment the underlying attribute value and sync with original. + * + * @param string $column + * @param int $amount + * @param string $method + * @return void + */ + protected function incrementOrDecrementAttributeValue($column, $amount, $method) + { + $this->{$column} = $this->{$column} + ($method == 'increment' ? $amount : $amount * -1); + + $this->syncOriginalAttribute($column); + } + + /** + * Update the model in the database. + * + * @param array $attributes + * @return bool|int + */ + public function update(array $attributes = array()) + { + if ( ! $this->exists) + { + return $this->newQuery()->update($attributes); + } + + return $this->fill($attributes)->save(); + } + + /** + * Save the model and all of its relationships. + * + * @return bool + */ + public function push() + { + if ( ! $this->save()) return false; + + // To sync all of the relationships to the database, we will simply spin through + // the relationships and save each model via this "push" method, which allows + // us to recurse into all of these nested relations for the model instance. + foreach ($this->relations as $models) + { + $models = $models instanceof Collection + ? $models->all() : array($models); + + foreach (array_filter($models) as $model) + { + if ( ! $model->push()) return false; + } + } + + return true; + } + + /** + * Save the model to the database. + * + * @param array $options + * @return bool + */ + public function save(array $options = array()) + { + $query = $this->newQueryWithoutScopes(); + + // If the "saving" event returns false we'll bail out of the save and return + // false, indicating that the save failed. This provides a chance for any + // listeners to cancel save operations if validations fail or whatever. + if ($this->fireModelEvent('saving') === false) + { + return false; + } + + // If the model already exists in the database we can just update our record + // that is already in this database using the current IDs in this "where" + // clause to only update this model. Otherwise, we'll just insert them. + if ($this->exists) + { + $saved = $this->performUpdate($query, $options); + } + + // If the model is brand new, we'll insert it into our database and set the + // ID attribute on the model to the value of the newly inserted row's ID + // which is typically an auto-increment value managed by the database. + else + { + $saved = $this->performInsert($query, $options); + } + + if ($saved) $this->finishSave($options); + + return $saved; + } + + /** + * Finish processing on a successful save operation. + * + * @param array $options + * @return void + */ + protected function finishSave(array $options) + { + $this->fireModelEvent('saved', false); + + $this->syncOriginal(); + + if (array_get($options, 'touch', true)) $this->touchOwners(); + } + + /** + * Perform a model update operation. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $options + * @return bool|null + */ + protected function performUpdate(Builder $query, array $options = []) + { + $dirty = $this->getDirty(); + + if (count($dirty) > 0) + { + // If the updating event returns false, we will cancel the update operation so + // developers can hook Validation systems into their models and cancel this + // operation if the model does not pass validation. Otherwise, we update. + if ($this->fireModelEvent('updating') === false) + { + return false; + } + + // First we need to create a fresh query instance and touch the creation and + // update timestamp on the model which are maintained by us for developer + // convenience. Then we will just continue saving the model instances. + if ($this->timestamps && array_get($options, 'timestamps', true)) + { + $this->updateTimestamps(); + } + + // Once we have run the update operation, we will fire the "updated" event for + // this model instance. This will allow developers to hook into these after + // models are updated, giving them a chance to do any special processing. + $dirty = $this->getDirty(); + + if (count($dirty) > 0) + { + $this->setKeysForSaveQuery($query)->update($dirty); + + $this->fireModelEvent('updated', false); + } + } + + return true; + } + + /** + * Perform a model insert operation. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $options + * @return bool + */ + protected function performInsert(Builder $query, array $options = []) + { + if ($this->fireModelEvent('creating') === false) return false; + + // First we'll need to create a fresh query instance and touch the creation and + // update timestamps on this model, which are maintained by us for developer + // convenience. After, we will just continue saving these model instances. + if ($this->timestamps && array_get($options, 'timestamps', true)) + { + $this->updateTimestamps(); + } + + // If the model has an incrementing key, we can use the "insertGetId" method on + // the query builder, which will give us back the final inserted ID for this + // table from the database. Not all tables have to be incrementing though. + $attributes = $this->attributes; + + if ($this->incrementing) + { + $this->insertAndSetId($query, $attributes); + } + + // If the table is not incrementing we'll simply insert this attributes as they + // are, as this attributes arrays must contain an "id" column already placed + // there by the developer as the manually determined key for these models. + else + { + $query->insert($attributes); + } + + // We will go ahead and set the exists property to true, so that it is set when + // the created event is fired, just in case the developer tries to update it + // during the event. This will allow them to do so and run an update here. + $this->exists = true; + + $this->fireModelEvent('created', false); + + return true; + } + + /** + * Insert the given attributes and set the ID on the model. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $attributes + * @return void + */ + protected function insertAndSetId(Builder $query, $attributes) + { + $id = $query->insertGetId($attributes, $keyName = $this->getKeyName()); + + $this->setAttribute($keyName, $id); + } + + /** + * Touch the owning relations of the model. + * + * @return void + */ + public function touchOwners() + { + foreach ($this->touches as $relation) + { + $this->$relation()->touch(); + + if ($this->$relation instanceof Model) + { + $this->$relation->touchOwners(); + } + elseif ($this->$relation instanceof Collection) + { + $this->$relation->each(function (Model $relation) + { + $relation->touchOwners(); + }); + } + } + } + + /** + * Determine if the model touches a given relation. + * + * @param string $relation + * @return bool + */ + public function touches($relation) + { + return in_array($relation, $this->touches); + } + + /** + * Fire the given event for the model. + * + * @param string $event + * @param bool $halt + * @return mixed + */ + protected function fireModelEvent($event, $halt = true) + { + if ( ! isset(static::$dispatcher)) return true; + + // We will append the names of the class to the event to distinguish it from + // other model events that are fired, allowing us to listen on each model + // event set individually instead of catching event for all the models. + $event = "eloquent.{$event}: ".get_class($this); + + $method = $halt ? 'until' : 'fire'; + + return static::$dispatcher->$method($event, $this); + } + + /** + * Set the keys for a save update query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function setKeysForSaveQuery(Builder $query) + { + $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery()); + + return $query; + } + + /** + * Get the primary key value for a save query. + * + * @return mixed + */ + protected function getKeyForSaveQuery() + { + if (isset($this->original[$this->getKeyName()])) + { + return $this->original[$this->getKeyName()]; + } + + return $this->getAttribute($this->getKeyName()); + } + + /** + * Update the model's update timestamp. + * + * @return bool + */ + public function touch() + { + if ( ! $this->timestamps) return false; + + $this->updateTimestamps(); + + return $this->save(); + } + + /** + * Update the creation and update timestamps. + * + * @return void + */ + protected function updateTimestamps() + { + $time = $this->freshTimestamp(); + + if ( ! $this->isDirty(static::UPDATED_AT)) + { + $this->setUpdatedAt($time); + } + + if ( ! $this->exists && ! $this->isDirty(static::CREATED_AT)) + { + $this->setCreatedAt($time); + } + } + + /** + * Set the value of the "created at" attribute. + * + * @param mixed $value + * @return void + */ + public function setCreatedAt($value) + { + $this->{static::CREATED_AT} = $value; + } + + /** + * Set the value of the "updated at" attribute. + * + * @param mixed $value + * @return void + */ + public function setUpdatedAt($value) + { + $this->{static::UPDATED_AT} = $value; + } + + /** + * Get the name of the "created at" column. + * + * @return string + */ + public function getCreatedAtColumn() + { + return static::CREATED_AT; + } + + /** + * Get the name of the "updated at" column. + * + * @return string + */ + public function getUpdatedAtColumn() + { + return static::UPDATED_AT; + } + + /** + * Get a fresh timestamp for the model. + * + * @return \Carbon\Carbon + */ + public function freshTimestamp() + { + return new Carbon; + } + + /** + * Get a fresh timestamp for the model. + * + * @return string + */ + public function freshTimestampString() + { + return $this->fromDateTime($this->freshTimestamp()); + } + + /** + * Get a new query builder for the model's table. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function newQuery() + { + $builder = $this->newQueryWithoutScopes(); + + return $this->applyGlobalScopes($builder); + } + + /** + * Get a new query instance without a given scope. + * + * @param \Illuminate\Database\Eloquent\ScopeInterface $scope + * @return \Illuminate\Database\Eloquent\Builder + */ + public function newQueryWithoutScope($scope) + { + $this->getGlobalScope($scope)->remove($builder = $this->newQuery(), $this); + + return $builder; + } + + /** + * Get a new query builder that doesn't have any global scopes. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newQueryWithoutScopes() + { + $builder = $this->newEloquentBuilder( + $this->newBaseQueryBuilder() + ); + + // Once we have the query builders, we will set the model instances so the + // builder can easily access any information it may need from the model + // while it is constructing and executing various queries against it. + return $builder->setModel($this)->with($this->with); + } + + /** + * Apply all of the global scopes to an Eloquent builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return \Illuminate\Database\Eloquent\Builder + */ + public function applyGlobalScopes($builder) + { + foreach ($this->getGlobalScopes() as $scope) + { + $scope->apply($builder, $this); + } + + return $builder; + } + + /** + * Remove all of the global scopes from an Eloquent builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return \Illuminate\Database\Eloquent\Builder + */ + public function removeGlobalScopes($builder) + { + foreach ($this->getGlobalScopes() as $scope) + { + $scope->remove($builder, $this); + } + + return $builder; + } + + /** + * Create a new Eloquent query builder for the model. + * + * @param \Illuminate\Database\Query\Builder $query + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function newEloquentBuilder($query) + { + return new Builder($query); + } + + /** + * Get a new query builder instance for the connection. + * + * @return \Illuminate\Database\Query\Builder + */ + protected function newBaseQueryBuilder() + { + $conn = $this->getConnection(); + + $grammar = $conn->getQueryGrammar(); + + return new QueryBuilder($conn, $grammar, $conn->getPostProcessor()); + } + + /** + * Create a new Eloquent Collection instance. + * + * @param array $models + * @return \Illuminate\Database\Eloquent\Collection + */ + public function newCollection(array $models = array()) + { + return new Collection($models); + } + + /** + * Create a new pivot model instance. + * + * @param \Illuminate\Database\Eloquent\Model $parent + * @param array $attributes + * @param string $table + * @param bool $exists + * @return \Illuminate\Database\Eloquent\Relations\Pivot + */ + public function newPivot(Model $parent, array $attributes, $table, $exists) + { + return new Pivot($parent, $attributes, $table, $exists); + } + + /** + * Get the table associated with the model. + * + * @return string + */ + public function getTable() + { + if (isset($this->table)) return $this->table; + + return str_replace('\\', '', snake_case(str_plural(class_basename($this)))); + } + + /** + * Set the table associated with the model. + * + * @param string $table + * @return void + */ + public function setTable($table) + { + $this->table = $table; + } + + /** + * Get the value of the model's primary key. + * + * @return mixed + */ + public function getKey() + { + return $this->getAttribute($this->getKeyName()); + } + + /** + * Get the queueable identity for the entity. + * + * @return mixed + */ + public function getQueueableId() + { + return $this->getKey(); + } + + /** + * Get the primary key for the model. + * + * @return string + */ + public function getKeyName() + { + return $this->primaryKey; + } + + /** + * Set the primary key for the model. + * + * @param string $key + * @return void + */ + public function setKeyName($key) + { + $this->primaryKey = $key; + } + + /** + * Get the table qualified key name. + * + * @return string + */ + public function getQualifiedKeyName() + { + return $this->getTable().'.'.$this->getKeyName(); + } + + /** + * Get the value of the model's route key. + * + * @return mixed + */ + public function getRouteKey() + { + return $this->getAttribute($this->getRouteKeyName()); + } + + /** + * Get the route key for the model. + * + * @return string + */ + public function getRouteKeyName() + { + return $this->getKeyName(); + } + + /** + * Determine if the model uses timestamps. + * + * @return bool + */ + public function usesTimestamps() + { + return $this->timestamps; + } + + /** + * Get the polymorphic relationship columns. + * + * @param string $name + * @param string $type + * @param string $id + * @return array + */ + protected function getMorphs($name, $type, $id) + { + $type = $type ?: $name.'_type'; + + $id = $id ?: $name.'_id'; + + return array($type, $id); + } + + /** + * Get the class name for polymorphic relations. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass ?: get_class($this); + } + + /** + * Get the number of models to return per page. + * + * @return int + */ + public function getPerPage() + { + return $this->perPage; + } + + /** + * Set the number of models to return per page. + * + * @param int $perPage + * @return void + */ + public function setPerPage($perPage) + { + $this->perPage = $perPage; + } + + /** + * Get the default foreign key name for the model. + * + * @return string + */ + public function getForeignKey() + { + return snake_case(class_basename($this)).'_id'; + } + + /** + * Get the hidden attributes for the model. + * + * @return array + */ + public function getHidden() + { + return $this->hidden; + } + + /** + * Set the hidden attributes for the model. + * + * @param array $hidden + * @return void + */ + public function setHidden(array $hidden) + { + $this->hidden = $hidden; + } + + /** + * Add hidden attributes for the model. + * + * @param array|string|null $attributes + * @return void + */ + public function addHidden($attributes = null) + { + $attributes = is_array($attributes) ? $attributes : func_get_args(); + + $this->hidden = array_merge($this->hidden, $attributes); + } + + /** + * Get the visible attributes for the model. + * + * @return array + */ + public function getVisible() + { + return $this->visible; + } + + /** + * Set the visible attributes for the model. + * + * @param array $visible + * @return void + */ + public function setVisible(array $visible) + { + $this->visible = $visible; + } + + /** + * Add visible attributes for the model. + * + * @param array|string|null $attributes + * @return void + */ + public function addVisible($attributes = null) + { + $attributes = is_array($attributes) ? $attributes : func_get_args(); + + $this->visible = array_merge($this->visible, $attributes); + } + + /** + * Set the accessors to append to model arrays. + * + * @param array $appends + * @return void + */ + public function setAppends(array $appends) + { + $this->appends = $appends; + } + + /** + * Get the fillable attributes for the model. + * + * @return array + */ + public function getFillable() + { + return $this->fillable; + } + + /** + * Set the fillable attributes for the model. + * + * @param array $fillable + * @return $this + */ + public function fillable(array $fillable) + { + $this->fillable = $fillable; + + return $this; + } + + /** + * Get the guarded attributes for the model. + * + * @return array + */ + public function getGuarded() + { + return $this->guarded; + } + + /** + * Set the guarded attributes for the model. + * + * @param array $guarded + * @return $this + */ + public function guard(array $guarded) + { + $this->guarded = $guarded; + + return $this; + } + + /** + * Disable all mass assignable restrictions. + * + * @return void + */ + public static function unguard($state = true) + { + static::$unguarded = $state; + } + + /** + * Enable the mass assignment restrictions. + * + * @return void + */ + public static function reguard() + { + static::$unguarded = false; + } + + /** + * Determine if current state is "unguarded". + * + * @return bool + */ + public static function isUnguarded() + { + return static::$unguarded; + } + + /** + * Run the given callable while being unguarded. + * + * @param callable $callback + * @return mixed + */ + public static function unguarded(callable $callback) + { + if (static::$unguarded) return $callback(); + + static::unguard(); + + $result = $callback(); + + static::reguard(); + + return $result; + } + + /** + * Determine if the given attribute may be mass assigned. + * + * @param string $key + * @return bool + */ + public function isFillable($key) + { + if (static::$unguarded) return true; + + // If the key is in the "fillable" array, we can of course assume that it's + // a fillable attribute. Otherwise, we will check the guarded array when + // we need to determine if the attribute is black-listed on the model. + if (in_array($key, $this->fillable)) return true; + + if ($this->isGuarded($key)) return false; + + return empty($this->fillable) && ! starts_with($key, '_'); + } + + /** + * Determine if the given key is guarded. + * + * @param string $key + * @return bool + */ + public function isGuarded($key) + { + return in_array($key, $this->guarded) || $this->guarded == array('*'); + } + + /** + * Determine if the model is totally guarded. + * + * @return bool + */ + public function totallyGuarded() + { + return count($this->fillable) == 0 && $this->guarded == array('*'); + } + + /** + * Remove the table name from a given key. + * + * @param string $key + * @return string + */ + protected function removeTableFromKey($key) + { + if ( ! str_contains($key, '.')) return $key; + + return last(explode('.', $key)); + } + + /** + * Get the relationships that are touched on save. + * + * @return array + */ + public function getTouchedRelations() + { + return $this->touches; + } + + /** + * Set the relationships that are touched on save. + * + * @param array $touches + * @return void + */ + public function setTouchedRelations(array $touches) + { + $this->touches = $touches; + } + + /** + * Get the value indicating whether the IDs are incrementing. + * + * @return bool + */ + public function getIncrementing() + { + return $this->incrementing; + } + + /** + * Set whether IDs are incrementing. + * + * @param bool $value + * @return void + */ + public function setIncrementing($value) + { + $this->incrementing = $value; + } + + /** + * Convert the model instance to JSON. + * + * @param int $options + * @return string + */ + public function toJson($options = 0) + { + return json_encode($this->toArray(), $options); + } + + /** + * Convert the object into something JSON serializable. + * + * @return array + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * Convert the model instance to an array. + * + * @return array + */ + public function toArray() + { + $attributes = $this->attributesToArray(); + + return array_merge($attributes, $this->relationsToArray()); + } + + /** + * Convert the model's attributes to an array. + * + * @return array + */ + public function attributesToArray() + { + $attributes = $this->getArrayableAttributes(); + + // If an attribute is a date, we will cast it to a string after converting it + // to a DateTime / Carbon instance. This is so we will get some consistent + // formatting while accessing attributes vs. arraying / JSONing a model. + foreach ($this->getDates() as $key) + { + if ( ! isset($attributes[$key])) continue; + + $attributes[$key] = (string) $this->asDateTime($attributes[$key]); + } + + $mutatedAttributes = $this->getMutatedAttributes(); + + // We want to spin through all the mutated attributes for this model and call + // the mutator for the attribute. We cache off every mutated attributes so + // we don't have to constantly check on attributes that actually change. + foreach ($mutatedAttributes as $key) + { + if ( ! array_key_exists($key, $attributes)) continue; + + $attributes[$key] = $this->mutateAttributeForArray( + $key, $attributes[$key] + ); + } + + // Next we will handle any casts that have been setup for this model and cast + // the values to their appropriate type. If the attribute has a mutator we + // will not perform the cast on those attributes to avoid any confusion. + foreach ($this->casts as $key => $value) + { + if ( ! array_key_exists($key, $attributes) || + in_array($key, $mutatedAttributes)) continue; + + $attributes[$key] = $this->castAttribute( + $key, $attributes[$key] + ); + } + + // Here we will grab all of the appended, calculated attributes to this model + // as these attributes are not really in the attributes array, but are run + // when we need to array or JSON the model for convenience to the coder. + foreach ($this->getArrayableAppends() as $key) + { + $attributes[$key] = $this->mutateAttributeForArray($key, null); + } + + return $attributes; + } + + /** + * Get an attribute array of all arrayable attributes. + * + * @return array + */ + protected function getArrayableAttributes() + { + return $this->getArrayableItems($this->attributes); + } + + /** + * Get all of the appendable values that are arrayable. + * + * @return array + */ + protected function getArrayableAppends() + { + if ( ! count($this->appends)) return []; + + return $this->getArrayableItems( + array_combine($this->appends, $this->appends) + ); + } + + /** + * Get the model's relationships in array form. + * + * @return array + */ + public function relationsToArray() + { + $attributes = array(); + + foreach ($this->getArrayableRelations() as $key => $value) + { + if (in_array($key, $this->hidden)) continue; + + // If the values implements the Arrayable interface we can just call this + // toArray method on the instances which will convert both models and + // collections to their proper array form and we'll set the values. + if ($value instanceof Arrayable) + { + $relation = $value->toArray(); + } + + // If the value is null, we'll still go ahead and set it in this list of + // attributes since null is used to represent empty relationships if + // if it a has one or belongs to type relationships on the models. + elseif (is_null($value)) + { + $relation = $value; + } + + // If the relationships snake-casing is enabled, we will snake case this + // key so that the relation attribute is snake cased in this returned + // array to the developers, making this consistent with attributes. + if (static::$snakeAttributes) + { + $key = snake_case($key); + } + + // If the relation value has been set, we will set it on this attributes + // list for returning. If it was not arrayable or null, we'll not set + // the value on the array because it is some type of invalid value. + if (isset($relation) || is_null($value)) + { + $attributes[$key] = $relation; + } + + unset($relation); + } + + return $attributes; + } + + /** + * Get an attribute array of all arrayable relations. + * + * @return array + */ + protected function getArrayableRelations() + { + return $this->getArrayableItems($this->relations); + } + + /** + * Get an attribute array of all arrayable values. + * + * @param array $values + * @return array + */ + protected function getArrayableItems(array $values) + { + if (count($this->visible) > 0) + { + return array_intersect_key($values, array_flip($this->visible)); + } + + return array_diff_key($values, array_flip($this->hidden)); + } + + /** + * Get an attribute from the model. + * + * @param string $key + * @return mixed + */ + public function getAttribute($key) + { + $inAttributes = array_key_exists($key, $this->attributes); + + // If the key references an attribute, we can just go ahead and return the + // plain attribute value from the model. This allows every attribute to + // be dynamically accessed through the _get method without accessors. + if ($inAttributes || $this->hasGetMutator($key)) + { + return $this->getAttributeValue($key); + } + + // If the key already exists in the relationships array, it just means the + // relationship has already been loaded, so we'll just return it out of + // here because there is no need to query within the relations twice. + if (array_key_exists($key, $this->relations)) + { + return $this->relations[$key]; + } + + // If the "attribute" exists as a method on the model, we will just assume + // it is a relationship and will load and return results from the query + // and hydrate the relationship's value on the "relationships" array. + if (method_exists($this, $key)) + { + return $this->getRelationshipFromMethod($key); + } + } + + /** + * Get a plain attribute (not a relationship). + * + * @param string $key + * @return mixed + */ + protected function getAttributeValue($key) + { + $value = $this->getAttributeFromArray($key); + + // If the attribute has a get mutator, we will call that then return what + // it returns as the value, which is useful for transforming values on + // retrieval from the model to a form that is more useful for usage. + if ($this->hasGetMutator($key)) + { + return $this->mutateAttribute($key, $value); + } + + // If the attribute exists within the cast array, we will convert it to + // an appropriate native PHP type dependant upon the associated value + // given with the key in the pair. Dayle made this comment line up. + if ($this->hasCast($key)) + { + $value = $this->castAttribute($key, $value); + } + + // If the attribute is listed as a date, we will convert it to a DateTime + // instance on retrieval, which makes it quite convenient to work with + // date fields without having to create a mutator for each property. + elseif (in_array($key, $this->getDates())) + { + if ( ! is_null($value)) return $this->asDateTime($value); + } + + return $value; + } + + /** + * Get an attribute from the $attributes array. + * + * @param string $key + * @return mixed + */ + protected function getAttributeFromArray($key) + { + if (array_key_exists($key, $this->attributes)) + { + return $this->attributes[$key]; + } + } + + /** + * Get a relationship value from a method. + * + * @param string $method + * @return mixed + * + * @throws \LogicException + */ + protected function getRelationshipFromMethod($method) + { + $relations = $this->$method(); + + if ( ! $relations instanceof Relation) + { + throw new LogicException('Relationship method must return an object of type ' + . 'Illuminate\Database\Eloquent\Relations\Relation'); + } + + return $this->relations[$method] = $relations->getResults(); + } + + /** + * Determine if a get mutator exists for an attribute. + * + * @param string $key + * @return bool + */ + public function hasGetMutator($key) + { + return method_exists($this, 'get'.studly_case($key).'Attribute'); + } + + /** + * Get the value of an attribute using its mutator. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function mutateAttribute($key, $value) + { + return $this->{'get'.studly_case($key).'Attribute'}($value); + } + + /** + * Get the value of an attribute using its mutator for array conversion. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function mutateAttributeForArray($key, $value) + { + $value = $this->mutateAttribute($key, $value); + + return $value instanceof Arrayable ? $value->toArray() : $value; + } + + /** + * Determine whether an attribute should be casted to a native type. + * + * @param string $key + * @return bool + */ + protected function hasCast($key) + { + return array_key_exists($key, $this->casts); + } + + /** + * Determine whether a value is JSON castable for inbound manipulation. + * + * @param string $key + * @return bool + */ + protected function isJsonCastable($key) + { + if ($this->hasCast($key)) + { + return in_array( + $this->getCastType($key), ['array', 'json', 'object', 'collection'], true + ); + } + + return false; + } + + /** + * Get the type of cast for a model attribute. + * + * @param string $key + * @return string + */ + protected function getCastType($key) + { + return trim(strtolower($this->casts[$key])); + } + + /** + * Cast an attribute to a native PHP type. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function castAttribute($key, $value) + { + if (is_null($value)) return $value; + + switch ($this->getCastType($key)) + { + case 'int': + case 'integer': + return (int) $value; + case 'real': + case 'float': + case 'double': + return (float) $value; + case 'string': + return (string) $value; + case 'bool': + case 'boolean': + return (bool) $value; + case 'object': + return json_decode($value); + case 'array': + case 'json': + return json_decode($value, true); + case 'collection': + return $this->newCollection(json_decode($value, true)); + default: + return $value; + } + } + + /** + * Set a given attribute on the model. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function setAttribute($key, $value) + { + // First we will check for the presence of a mutator for the set operation + // which simply lets the developers tweak the attribute as it is set on + // the model, such as "json_encoding" an listing of data for storage. + if ($this->hasSetMutator($key)) + { + $method = 'set'.studly_case($key).'Attribute'; + + return $this->{$method}($value); + } + + // If an attribute is listed as a "date", we'll convert it from a DateTime + // instance into a form proper for storage on the database tables using + // the connection grammar's date format. We will auto set the values. + elseif (in_array($key, $this->getDates()) && $value) + { + $value = $this->fromDateTime($value); + } + + if ($this->isJsonCastable($key)) + { + $value = json_encode($value); + } + + $this->attributes[$key] = $value; + } + + /** + * Determine if a set mutator exists for an attribute. + * + * @param string $key + * @return bool + */ + public function hasSetMutator($key) + { + return method_exists($this, 'set'.studly_case($key).'Attribute'); + } + + /** + * Get the attributes that should be converted to dates. + * + * @return array + */ + public function getDates() + { + $defaults = array(static::CREATED_AT, static::UPDATED_AT); + + return array_merge($this->dates, $defaults); + } + + /** + * Convert a DateTime to a storable string. + * + * @param \DateTime|int $value + * @return string + */ + public function fromDateTime($value) + { + $format = $this->getDateFormat(); + + // If the value is already a DateTime instance, we will just skip the rest of + // these checks since they will be a waste of time, and hinder performance + // when checking the field. We will just return the DateTime right away. + if ($value instanceof DateTime) + { + // + } + + // If the value is totally numeric, we will assume it is a UNIX timestamp and + // format the date as such. Once we have the date in DateTime form we will + // format it according to the proper format for the database connection. + elseif (is_numeric($value)) + { + $value = Carbon::createFromTimestamp($value); + } + + // If the value is in simple year, month, day format, we will format it using + // that setup. This is for simple "date" fields which do not have hours on + // the field. This conveniently picks up those dates and format correct. + elseif (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value)) + { + $value = Carbon::createFromFormat('Y-m-d', $value)->startOfDay(); + } + + // If this value is some other type of string, we'll create the DateTime with + // the format used by the database connection. Once we get the instance we + // can return back the finally formatted DateTime instances to the devs. + else + { + $value = Carbon::createFromFormat($format, $value); + } + + return $value->format($format); + } + + /** + * Return a timestamp as DateTime object. + * + * @param mixed $value + * @return \Carbon\Carbon + */ + protected function asDateTime($value) + { + // If this value is an integer, we will assume it is a UNIX timestamp's value + // and format a Carbon object from this timestamp. This allows flexibility + // when defining your date fields as they might be UNIX timestamps here. + if (is_numeric($value)) + { + return Carbon::createFromTimestamp($value); + } + + // If the value is in simply year, month, day format, we will instantiate the + // Carbon instances from that format. Again, this provides for simple date + // fields on the database, while still supporting Carbonized conversion. + elseif (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value)) + { + return Carbon::createFromFormat('Y-m-d', $value)->startOfDay(); + } + + // Finally, we will just assume this date is in the format used by default on + // the database connection and use that format to create the Carbon object + // that is returned back out to the developers after we convert it here. + elseif ( ! $value instanceof DateTime) + { + $format = $this->getDateFormat(); + + return Carbon::createFromFormat($format, $value); + } + + return Carbon::instance($value); + } + + /** + * Get the format for database stored dates. + * + * @return string + */ + protected function getDateFormat() + { + return $this->getConnection()->getQueryGrammar()->getDateFormat(); + } + + /** + * Clone the model into a new, non-existing instance. + * + * @param array $except + * @return \Illuminate\Database\Eloquent\Model + */ + public function replicate(array $except = null) + { + $except = $except ?: [ + $this->getKeyName(), + $this->getCreatedAtColumn(), + $this->getUpdatedAtColumn(), + ]; + + $attributes = array_except($this->attributes, $except); + + with($instance = new static)->setRawAttributes($attributes); + + return $instance->setRelations($this->relations); + } + + /** + * Get all of the current attributes on the model. + * + * @return array + */ + public function getAttributes() + { + return $this->attributes; + } + + /** + * Set the array of model attributes. No checking is done. + * + * @param array $attributes + * @param bool $sync + * @return void + */ + public function setRawAttributes(array $attributes, $sync = false) + { + $this->attributes = $attributes; + + if ($sync) $this->syncOriginal(); + } + + /** + * Get the model's original attribute values. + * + * @param string $key + * @param mixed $default + * @return array + */ + public function getOriginal($key = null, $default = null) + { + return array_get($this->original, $key, $default); + } + + /** + * Sync the original attributes with the current. + * + * @return $this + */ + public function syncOriginal() + { + $this->original = $this->attributes; + + return $this; + } + + /** + * Sync a single original attribute with its current value. + * + * @param string $attribute + * @return $this + */ + public function syncOriginalAttribute($attribute) + { + $this->original[$attribute] = $this->attributes[$attribute]; + + return $this; + } + + /** + * Determine if the model or given attribute(s) have been modified. + * + * @param array|string|null $attributes + * @return bool + */ + public function isDirty($attributes = null) + { + $dirty = $this->getDirty(); + + if (is_null($attributes)) return count($dirty) > 0; + + if ( ! is_array($attributes)) $attributes = func_get_args(); + + foreach ($attributes as $attribute) + { + if (array_key_exists($attribute, $dirty)) return true; + } + + return false; + } + + /** + * Get the attributes that have been changed since last sync. + * + * @return array + */ + public function getDirty() + { + $dirty = array(); + + foreach ($this->attributes as $key => $value) + { + if ( ! array_key_exists($key, $this->original)) + { + $dirty[$key] = $value; + } + elseif ($value !== $this->original[$key] && + ! $this->originalIsNumericallyEquivalent($key)) + { + $dirty[$key] = $value; + } + } + + return $dirty; + } + + /** + * Determine if the new and old values for a given key are numerically equivalent. + * + * @param string $key + * @return bool + */ + protected function originalIsNumericallyEquivalent($key) + { + $current = $this->attributes[$key]; + + $original = $this->original[$key]; + + return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0; + } + + /** + * Get all the loaded relations for the instance. + * + * @return array + */ + public function getRelations() + { + return $this->relations; + } + + /** + * Get a specified relationship. + * + * @param string $relation + * @return mixed + */ + public function getRelation($relation) + { + return $this->relations[$relation]; + } + + /** + * Set the specific relationship in the model. + * + * @param string $relation + * @param mixed $value + * @return $this + */ + public function setRelation($relation, $value) + { + $this->relations[$relation] = $value; + + return $this; + } + + /** + * Set the entire relations array on the model. + * + * @param array $relations + * @return $this + */ + public function setRelations(array $relations) + { + $this->relations = $relations; + + return $this; + } + + /** + * Get the database connection for the model. + * + * @return \Illuminate\Database\Connection + */ + public function getConnection() + { + return static::resolveConnection($this->connection); + } + + /** + * Get the current connection name for the model. + * + * @return string + */ + public function getConnectionName() + { + return $this->connection; + } + + /** + * Set the connection associated with the model. + * + * @param string $name + * @return $this + */ + public function setConnection($name) + { + $this->connection = $name; + + return $this; + } + + /** + * Resolve a connection instance. + * + * @param string $connection + * @return \Illuminate\Database\Connection + */ + public static function resolveConnection($connection = null) + { + return static::$resolver->connection($connection); + } + + /** + * Get the connection resolver instance. + * + * @return \Illuminate\Database\ConnectionResolverInterface + */ + public static function getConnectionResolver() + { + return static::$resolver; + } + + /** + * Set the connection resolver instance. + * + * @param \Illuminate\Database\ConnectionResolverInterface $resolver + * @return void + */ + public static function setConnectionResolver(Resolver $resolver) + { + static::$resolver = $resolver; + } + + /** + * Unset the connection resolver for models. + * + * @return void + */ + public static function unsetConnectionResolver() + { + static::$resolver = null; + } + + /** + * Get the event dispatcher instance. + * + * @return \Illuminate\Contracts\Events\Dispatcher + */ + public static function getEventDispatcher() + { + return static::$dispatcher; + } + + /** + * Set the event dispatcher instance. + * + * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher + * @return void + */ + public static function setEventDispatcher(Dispatcher $dispatcher) + { + static::$dispatcher = $dispatcher; + } + + /** + * Unset the event dispatcher for models. + * + * @return void + */ + public static function unsetEventDispatcher() + { + static::$dispatcher = null; + } + + /** + * Get the mutated attributes for a given instance. + * + * @return array + */ + public function getMutatedAttributes() + { + $class = get_class($this); + + if ( ! isset(static::$mutatorCache[$class])) + { + static::cacheMutatedAttributes($class); + } + + return static::$mutatorCache[$class]; + } + + /** + * Extract and cache all the mutated attributes of a class. + * + * @param string $class + * @return void + */ + public static function cacheMutatedAttributes($class) + { + $mutatedAttributes = array(); + + // Here we will extract all of the mutated attributes so that we can quickly + // spin through them after we export models to their array form, which we + // need to be fast. This'll let us know the attributes that can mutate. + foreach (get_class_methods($class) as $method) + { + if (strpos($method, 'Attribute') !== false && + preg_match('/^get(.+)Attribute$/', $method, $matches)) + { + if (static::$snakeAttributes) $matches[1] = snake_case($matches[1]); + + $mutatedAttributes[] = lcfirst($matches[1]); + } + } + + static::$mutatorCache[$class] = $mutatedAttributes; + } + + /** + * Dynamically retrieve attributes on the model. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + return $this->getAttribute($key); + } + + /** + * Dynamically set attributes on the model. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function __set($key, $value) + { + $this->setAttribute($key, $value); + } + + /** + * Determine if the given attribute exists. + * + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->$offset); + } + + /** + * Get the value for a given offset. + * + * @param mixed $offset + * @return mixed + */ + public function offsetGet($offset) + { + return $this->$offset; + } + + /** + * Set the value for a given offset. + * + * @param mixed $offset + * @param mixed $value + * @return void + */ + public function offsetSet($offset, $value) + { + $this->$offset = $value; + } + + /** + * Unset the value for a given offset. + * + * @param mixed $offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->$offset); + } + + /** + * Determine if an attribute exists on the model. + * + * @param string $key + * @return bool + */ + public function __isset($key) + { + return (isset($this->attributes[$key]) || isset($this->relations[$key])) || + ($this->hasGetMutator($key) && ! is_null($this->getAttributeValue($key))); + } + + /** + * Unset an attribute on the model. + * + * @param string $key + * @return void + */ + public function __unset($key) + { + unset($this->attributes[$key], $this->relations[$key]); + } + + /** + * Handle dynamic method calls into the model. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + if (in_array($method, array('increment', 'decrement'))) + { + return call_user_func_array(array($this, $method), $parameters); + } + + $query = $this->newQuery(); + + return call_user_func_array(array($query, $method), $parameters); + } + + /** + * Handle dynamic static method calls into the method. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public static function __callStatic($method, $parameters) + { + $instance = new static; + + return call_user_func_array(array($instance, $method), $parameters); + } + + /** + * Convert the model to its string representation. + * + * @return string + */ + public function __toString() + { + return $this->toJson(); + } + + /** + * When a model is being unserialized, check if it needs to be booted. + * + * @return void + */ + public function __wakeup() + { + $this->bootIfNotBooted(); + } + +} diff --git a/vendor/illuminate/database/Eloquent/ModelNotFoundException.php b/vendor/illuminate/database/Eloquent/ModelNotFoundException.php new file mode 100755 index 0000000..84be36e --- /dev/null +++ b/vendor/illuminate/database/Eloquent/ModelNotFoundException.php @@ -0,0 +1,39 @@ +model = $model; + + $this->message = "No query results for model [{$model}]."; + + return $this; + } + + /** + * Get the affected Eloquent model. + * + * @return string + */ + public function getModel() + { + return $this->model; + } + +} diff --git a/vendor/illuminate/database/Eloquent/QueueEntityResolver.php b/vendor/illuminate/database/Eloquent/QueueEntityResolver.php new file mode 100755 index 0000000..2dc2be5 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/QueueEntityResolver.php @@ -0,0 +1,27 @@ +find($id); + + if ($instance) + { + return $instance; + } + + throw new EntityNotFoundException($type, $id); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/BelongsTo.php b/vendor/illuminate/database/Eloquent/Relations/BelongsTo.php new file mode 100755 index 0000000..fb5e815 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/BelongsTo.php @@ -0,0 +1,310 @@ +otherKey = $otherKey; + $this->relation = $relation; + $this->foreignKey = $foreignKey; + + parent::__construct($query, $parent); + } + + /** + * Get the results of the relationship. + * + * @return mixed + */ + public function getResults() + { + return $this->query->first(); + } + + /** + * Set the base constraints on the relation query. + * + * @return void + */ + public function addConstraints() + { + if (static::$constraints) + { + // For belongs to relationships, which are essentially the inverse of has one + // or has many relationships, we need to actually query on the primary key + // of the related models matching on the foreign key that's on a parent. + $table = $this->related->getTable(); + + $this->query->where($table.'.'.$this->otherKey, '=', $this->parent->{$this->foreignKey}); + } + } + + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + if ($parent->getQuery()->from == $query->getQuery()->from) + { + return $this->getRelationCountQueryForSelfRelation($query, $parent); + } + + $query->select(new Expression('count(*)')); + + $otherKey = $this->wrap($query->getModel()->getTable().'.'.$this->otherKey); + + return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); + } + + /** + * Add the constraints for a relationship count query on the same table. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent) + { + $query->select(new Expression('count(*)')); + + $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); + + $query->from($query->getModel()->getTable().' as '.$tablePrefix.$hash = $this->getRelationCountHash()); + + $key = $this->wrap($this->getQualifiedForeignKey()); + + return $query->where($hash.'.'.$query->getModel()->getKeyName(), '=', new Expression($key)); + } + + /** + * Get a relationship join table hash. + * + * @return string + */ + public function getRelationCountHash() + { + return 'self_'.md5(microtime(true)); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + // We'll grab the primary key name of the related models since it could be set to + // a non-standard name and not "id". We will then construct the constraint for + // our eagerly loading query so it returns the proper models from execution. + $key = $this->related->getTable().'.'.$this->otherKey; + + $this->query->whereIn($key, $this->getEagerModelKeys($models)); + } + + /** + * Gather the keys from an array of related models. + * + * @param array $models + * @return array + */ + protected function getEagerModelKeys(array $models) + { + $keys = array(); + + // First we need to gather all of the keys from the parent models so we know what + // to query for via the eager loading query. We will add them to an array then + // execute a "where in" statement to gather up all of those related records. + foreach ($models as $model) + { + if ( ! is_null($value = $model->{$this->foreignKey})) + { + $keys[] = $value; + } + } + + // If there are no keys that were not null we will just return an array with 0 in + // it so the query doesn't fail, but will not return any results, which should + // be what this developer is expecting in a case where this happens to them. + if (count($keys) == 0) + { + return array(0); + } + + return array_values(array_unique($keys)); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, null); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + $foreign = $this->foreignKey; + + $other = $this->otherKey; + + // First we will get to build a dictionary of the child models by their primary + // key of the relationship, then we can easily match the children back onto + // the parents using that dictionary and the primary key of the children. + $dictionary = array(); + + foreach ($results as $result) + { + $dictionary[$result->getAttribute($other)] = $result; + } + + // Once we have the dictionary constructed, we can loop through all the parents + // and match back onto their children using these keys of the dictionary and + // the primary key of the children to map them onto the correct instances. + foreach ($models as $model) + { + if (isset($dictionary[$model->$foreign])) + { + $model->setRelation($relation, $dictionary[$model->$foreign]); + } + } + + return $models; + } + + /** + * Associate the model instance to the given parent. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Model + */ + public function associate(Model $model) + { + $this->parent->setAttribute($this->foreignKey, $model->getAttribute($this->otherKey)); + + return $this->parent->setRelation($this->relation, $model); + } + + /** + * Dissociate previously associated model from the given parent. + * + * @return \Illuminate\Database\Eloquent\Model + */ + public function dissociate() + { + $this->parent->setAttribute($this->foreignKey, null); + + return $this->parent->setRelation($this->relation, null); + } + + /** + * Update the parent model on the relationship. + * + * @param array $attributes + * @return mixed + */ + public function update(array $attributes) + { + $instance = $this->getResults(); + + return $instance->fill($attributes)->save(); + } + + /** + * Get the foreign key of the relationship. + * + * @return string + */ + public function getForeignKey() + { + return $this->foreignKey; + } + + /** + * Get the fully qualified foreign key of the relationship. + * + * @return string + */ + public function getQualifiedForeignKey() + { + return $this->parent->getTable().'.'.$this->foreignKey; + } + + /** + * Get the associated key of the relationship. + * + * @return string + */ + public function getOtherKey() + { + return $this->otherKey; + } + + /** + * Get the fully qualified associated key of the relationship. + * + * @return string + */ + public function getQualifiedOtherKeyName() + { + return $this->related->getTable().'.'.$this->otherKey; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php b/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php new file mode 100755 index 0000000..00ec098 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php @@ -0,0 +1,1195 @@ +table = $table; + $this->otherKey = $otherKey; + $this->foreignKey = $foreignKey; + $this->relationName = $relationName; + + parent::__construct($query, $parent); + } + + /** + * Get the results of the relationship. + * + * @return mixed + */ + public function getResults() + { + return $this->get(); + } + + /** + * Set a where clause for a pivot table column. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @param string $boolean + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function wherePivot($column, $operator = null, $value = null, $boolean = 'and') + { + $this->pivotWheres[] = func_get_args(); + + return $this->where($this->table.'.'.$column, $operator, $value, $boolean); + } + + /** + * Set an or where clause for a pivot table column. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function orWherePivot($column, $operator = null, $value = null) + { + return $this->wherePivot($column, $operator, $value, 'or'); + } + + /** + * Execute the query and get the first result. + * + * @param array $columns + * @return mixed + */ + public function first($columns = array('*')) + { + $results = $this->take(1)->get($columns); + + return count($results) > 0 ? $results->first() : null; + } + + /** + * Execute the query and get the first result or throw an exception. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|static + * + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ + public function firstOrFail($columns = array('*')) + { + if ( ! is_null($model = $this->first($columns))) return $model; + + throw new ModelNotFoundException; + } + + /** + * Execute the query as a "select" statement. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection + */ + public function get($columns = array('*')) + { + // First we'll add the proper select columns onto the query so it is run with + // the proper columns. Then, we will get the results and hydrate out pivot + // models with the result of those columns as a separate model relation. + $columns = $this->query->getQuery()->columns ? array() : $columns; + + $select = $this->getSelectColumns($columns); + + $models = $this->query->addSelect($select)->getModels(); + + $this->hydratePivotRelation($models); + + // If we actually found models we will also eager load any relationships that + // have been specified as needing to be eager loaded. This will solve the + // n + 1 query problem for the developer and also increase performance. + if (count($models) > 0) + { + $models = $this->query->eagerLoadRelations($models); + } + + return $this->related->newCollection($models); + } + + /** + * Get a paginator for the "select" statement. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function paginate($perPage = null, $columns = array('*')) + { + $this->query->addSelect($this->getSelectColumns($columns)); + + $paginator = $this->query->paginate($perPage, $columns); + + $this->hydratePivotRelation($paginator->items()); + + return $paginator; + } + + /** + * Paginate the given query into a simple paginator. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\Paginator + */ + public function simplePaginate($perPage = null, $columns = array('*')) + { + $this->query->addSelect($this->getSelectColumns($columns)); + + $paginator = $this->query->simplePaginate($perPage, $columns); + + $this->hydratePivotRelation($paginator->items()); + + return $paginator; + } + + /** + * Chunk the results of the query. + * + * @param int $count + * @param callable $callback + * @return void + */ + public function chunk($count, callable $callback) + { + $this->query->addSelect($this->getSelectColumns()); + + $this->query->chunk($count, function($results) use ($callback) + { + $this->hydratePivotRelation($results->all()); + + call_user_func($callback, $results); + }); + } + + /** + * Hydrate the pivot table relationship on the models. + * + * @param array $models + * @return void + */ + protected function hydratePivotRelation(array $models) + { + // To hydrate the pivot relationship, we will just gather the pivot attributes + // and create a new Pivot model, which is basically a dynamic model that we + // will set the attributes, table, and connections on so it they be used. + foreach ($models as $model) + { + $pivot = $this->newExistingPivot($this->cleanPivotAttributes($model)); + + $model->setRelation('pivot', $pivot); + } + } + + /** + * Get the pivot attributes from a model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return array + */ + protected function cleanPivotAttributes(Model $model) + { + $values = array(); + + foreach ($model->getAttributes() as $key => $value) + { + // To get the pivots attributes we will just take any of the attributes which + // begin with "pivot_" and add those to this arrays, as well as unsetting + // them from the parent's models since they exist in a different table. + if (strpos($key, 'pivot_') === 0) + { + $values[substr($key, 6)] = $value; + + unset($model->$key); + } + } + + return $values; + } + + /** + * Set the base constraints on the relation query. + * + * @return void + */ + public function addConstraints() + { + $this->setJoin(); + + if (static::$constraints) $this->setWhere(); + } + + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + if ($parent->getQuery()->from == $query->getQuery()->from) + { + return $this->getRelationCountQueryForSelfJoin($query, $parent); + } + + $this->setJoin($query); + + return parent::getRelationCountQuery($query, $parent); + } + + /** + * Add the constraints for a relationship count query on the same table. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent) + { + $query->select(new Expression('count(*)')); + + $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); + + $query->from($this->table.' as '.$tablePrefix.$hash = $this->getRelationCountHash()); + + $key = $this->wrap($this->getQualifiedParentKeyName()); + + return $query->where($hash.'.'.$this->foreignKey, '=', new Expression($key)); + } + + /** + * Get a relationship join table hash. + * + * @return string + */ + public function getRelationCountHash() + { + return 'self_'.md5(microtime(true)); + } + + /** + * Set the select clause for the relation query. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + protected function getSelectColumns(array $columns = array('*')) + { + if ($columns == array('*')) + { + $columns = array($this->related->getTable().'.*'); + } + + return array_merge($columns, $this->getAliasedPivotColumns()); + } + + /** + * Get the pivot columns for the relation. + * + * @return array + */ + protected function getAliasedPivotColumns() + { + $defaults = array($this->foreignKey, $this->otherKey); + + // We need to alias all of the pivot columns with the "pivot_" prefix so we + // can easily extract them out of the models and put them into the pivot + // relationships when they are retrieved and hydrated into the models. + $columns = array(); + + foreach (array_merge($defaults, $this->pivotColumns) as $column) + { + $columns[] = $this->table.'.'.$column.' as pivot_'.$column; + } + + return array_unique($columns); + } + + /** + * Determine whether the given column is defined as a pivot column. + * + * @param string $column + * @return bool + */ + protected function hasPivotColumn($column) + { + return in_array($column, $this->pivotColumns); + } + + /** + * Set the join clause for the relation query. + * + * @param \Illuminate\Database\Eloquent\Builder|null + * @return $this + */ + protected function setJoin($query = null) + { + $query = $query ?: $this->query; + + // We need to join to the intermediate table on the related model's primary + // key column with the intermediate table's foreign key for the related + // model instance. Then we can set the "where" for the parent models. + $baseTable = $this->related->getTable(); + + $key = $baseTable.'.'.$this->related->getKeyName(); + + $query->join($this->table, $key, '=', $this->getOtherKey()); + + return $this; + } + + /** + * Set the where clause for the relation query. + * + * @return $this + */ + protected function setWhere() + { + $foreign = $this->getForeignKey(); + + $this->query->where($foreign, '=', $this->parent->getKey()); + + return $this; + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + $this->query->whereIn($this->getForeignKey(), $this->getKeys($models)); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, $this->related->newCollection()); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + $dictionary = $this->buildDictionary($results); + + // Once we have an array dictionary of child objects we can easily match the + // children back to their parent using the dictionary and the keys on the + // the parent models. Then we will return the hydrated models back out. + foreach ($models as $model) + { + if (isset($dictionary[$key = $model->getKey()])) + { + $collection = $this->related->newCollection($dictionary[$key]); + + $model->setRelation($relation, $collection); + } + } + + return $models; + } + + /** + * Build model dictionary keyed by the relation's foreign key. + * + * @param \Illuminate\Database\Eloquent\Collection $results + * @return array + */ + protected function buildDictionary(Collection $results) + { + $foreign = $this->foreignKey; + + // First we will build a dictionary of child models keyed by the foreign key + // of the relation so that we will easily and quickly match them to their + // parents without having a possibly slow inner loops for every models. + $dictionary = array(); + + foreach ($results as $result) + { + $dictionary[$result->pivot->$foreign][] = $result; + } + + return $dictionary; + } + + /** + * Touch all of the related models for the relationship. + * + * E.g.: Touch all roles associated with this user. + * + * @return void + */ + public function touch() + { + $key = $this->getRelated()->getKeyName(); + + $columns = $this->getRelatedFreshUpdate(); + + // If we actually have IDs for the relation, we will run the query to update all + // the related model's timestamps, to make sure these all reflect the changes + // to the parent models. This will help us keep any caching synced up here. + $ids = $this->getRelatedIds(); + + if (count($ids) > 0) + { + $this->getRelated()->newQuery()->whereIn($key, $ids)->update($columns); + } + } + + /** + * Get all of the IDs for the related models. + * + * @return array + */ + public function getRelatedIds() + { + $related = $this->getRelated(); + + $fullKey = $related->getQualifiedKeyName(); + + return $this->getQuery()->select($fullKey)->lists($related->getKeyName()); + } + + /** + * Save a new model and attach it to the parent model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param array $joining + * @param bool $touch + * @return \Illuminate\Database\Eloquent\Model + */ + public function save(Model $model, array $joining = array(), $touch = true) + { + $model->save(array('touch' => false)); + + $this->attach($model->getKey(), $joining, $touch); + + return $model; + } + + /** + * Save an array of new models and attach them to the parent model. + * + * @param array $models + * @param array $joinings + * @return array + */ + public function saveMany(array $models, array $joinings = array()) + { + foreach ($models as $key => $model) + { + $this->save($model, (array) array_get($joinings, $key), false); + } + + $this->touchIfTouching(); + + return $models; + } + + /** + * Find a related model by its primary key. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null + */ + public function find($id, $columns = ['*']) + { + if (is_array($id)) + { + return $this->findMany($id, $columns); + } + + $this->where($this->getRelated()->getQualifiedKeyName(), '=', $id); + + return $this->first($columns); + } + + /** + * Find multiple related models by their primary keys. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection + */ + public function findMany($ids, $columns = ['*']) + { + if (empty($ids)) return $this->getRelated()->newCollection(); + + $this->whereIn($this->getRelated()->getQualifiedKeyName(), $ids); + + return $this->get($columns); + } + + /** + * Find a related model by its primary key or return new instance of the related model. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model + */ + public function findOrNew($id, $columns = ['*']) + { + if (is_null($instance = $this->find($id, $columns))) + { + $instance = $this->getRelated()->newInstance(); + } + + return $instance; + } + + /** + * Get the first related model record matching the attributes or instantiate it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrNew(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->related->newInstance(); + } + + return $instance; + } + + /** + * Get the first related record matching the attributes or create it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrCreate(array $attributes, array $joining = [], $touch = true) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($attributes, $joining, $touch); + } + + return $instance; + } + + /** + * Create or update a related record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public function updateOrCreate(array $attributes, array $values = [], array $joining = [], $touch = true) + { + if (is_null($instance = $this->where($attributes)->first())) + { + return $this->create($values, $joining, $touch); + } + + $instance->fill($values); + + $instance->save(['touch' => false]); + + return $instance; + } + + /** + * Create a new instance of the related model. + * + * @param array $attributes + * @param array $joining + * @param bool $touch + * @return \Illuminate\Database\Eloquent\Model + */ + public function create(array $attributes, array $joining = array(), $touch = true) + { + $instance = $this->related->newInstance($attributes); + + // Once we save the related model, we need to attach it to the base model via + // through intermediate table so we'll use the existing "attach" method to + // accomplish this which will insert the record and any more attributes. + $instance->save(array('touch' => false)); + + $this->attach($instance->getKey(), $joining, $touch); + + return $instance; + } + + /** + * Create an array of new instances of the related models. + * + * @param array $records + * @param array $joinings + * @return \Illuminate\Database\Eloquent\Model + */ + public function createMany(array $records, array $joinings = array()) + { + $instances = array(); + + foreach ($records as $key => $record) + { + $instances[] = $this->create($record, (array) array_get($joinings, $key), false); + } + + $this->touchIfTouching(); + + return $instances; + } + + /** + * Sync the intermediate tables with a list of IDs or collection of models. + * + * @param array $ids + * @param bool $detaching + * @return array + */ + public function sync($ids, $detaching = true) + { + $changes = array( + 'attached' => array(), 'detached' => array(), 'updated' => array(), + ); + + if ($ids instanceof Collection) $ids = $ids->modelKeys(); + + // First we need to attach any of the associated models that are not currently + // in this joining table. We'll spin through the given IDs, checking to see + // if they exist in the array of current ones, and if not we will insert. + $current = $this->newPivotQuery()->lists($this->otherKey); + + $records = $this->formatSyncList($ids); + + $detach = array_diff($current, array_keys($records)); + + // Next, we will take the differences of the currents and given IDs and detach + // all of the entities that exist in the "current" array but are not in the + // the array of the IDs given to the method which will complete the sync. + if ($detaching && count($detach) > 0) + { + $this->detach($detach); + + $changes['detached'] = (array) array_map(function($v) { return (int) $v; }, $detach); + } + + // Now we are finally ready to attach the new records. Note that we'll disable + // touching until after the entire operation is complete so we don't fire a + // ton of touch operations until we are totally done syncing the records. + $changes = array_merge( + $changes, $this->attachNew($records, $current, false) + ); + + if (count($changes['attached']) || count($changes['updated'])) + { + $this->touchIfTouching(); + } + + return $changes; + } + + /** + * Format the sync list so that it is keyed by ID. + * + * @param array $records + * @return array + */ + protected function formatSyncList(array $records) + { + $results = array(); + + foreach ($records as $id => $attributes) + { + if ( ! is_array($attributes)) + { + list($id, $attributes) = array($attributes, array()); + } + + $results[$id] = $attributes; + } + + return $results; + } + + /** + * Attach all of the IDs that aren't in the current array. + * + * @param array $records + * @param array $current + * @param bool $touch + * @return array + */ + protected function attachNew(array $records, array $current, $touch = true) + { + $changes = array('attached' => array(), 'updated' => array()); + + foreach ($records as $id => $attributes) + { + // If the ID is not in the list of existing pivot IDs, we will insert a new pivot + // record, otherwise, we will just update this existing record on this joining + // table, so that the developers will easily update these records pain free. + if ( ! in_array($id, $current)) + { + $this->attach($id, $attributes, $touch); + + $changes['attached'][] = (int) $id; + } + + // Now we'll try to update an existing pivot record with the attributes that were + // given to the method. If the model is actually updated we will add it to the + // list of updated pivot records so we return them back out to the consumer. + elseif (count($attributes) > 0 && + $this->updateExistingPivot($id, $attributes, $touch)) + { + $changes['updated'][] = (int) $id; + } + } + + return $changes; + } + + /** + * Update an existing pivot record on the table. + * + * @param mixed $id + * @param array $attributes + * @param bool $touch + * @return void + */ + public function updateExistingPivot($id, array $attributes, $touch = true) + { + if (in_array($this->updatedAt(), $this->pivotColumns)) + { + $attributes = $this->setTimestampsOnAttach($attributes, true); + } + + $updated = $this->newPivotStatementForId($id)->update($attributes); + + if ($touch) $this->touchIfTouching(); + + return $updated; + } + + /** + * Attach a model to the parent. + * + * @param mixed $id + * @param array $attributes + * @param bool $touch + * @return void + */ + public function attach($id, array $attributes = array(), $touch = true) + { + if ($id instanceof Model) $id = $id->getKey(); + + $query = $this->newPivotStatement(); + + $query->insert($this->createAttachRecords((array) $id, $attributes)); + + if ($touch) $this->touchIfTouching(); + } + + /** + * Create an array of records to insert into the pivot table. + * + * @param array $ids + * @param array $attributes + * @return array + */ + protected function createAttachRecords($ids, array $attributes) + { + $records = array(); + + $timed = ($this->hasPivotColumn($this->createdAt()) || + $this->hasPivotColumn($this->updatedAt())); + + // To create the attachment records, we will simply spin through the IDs given + // and create a new record to insert for each ID. Each ID may actually be a + // key in the array, with extra attributes to be placed in other columns. + foreach ($ids as $key => $value) + { + $records[] = $this->attacher($key, $value, $attributes, $timed); + } + + return $records; + } + + /** + * Create a full attachment record payload. + * + * @param int $key + * @param mixed $value + * @param array $attributes + * @param bool $timed + * @return array + */ + protected function attacher($key, $value, $attributes, $timed) + { + list($id, $extra) = $this->getAttachId($key, $value, $attributes); + + // To create the attachment records, we will simply spin through the IDs given + // and create a new record to insert for each ID. Each ID may actually be a + // key in the array, with extra attributes to be placed in other columns. + $record = $this->createAttachRecord($id, $timed); + + return array_merge($record, $extra); + } + + /** + * Get the attach record ID and extra attributes. + * + * @param mixed $key + * @param mixed $value + * @param array $attributes + * @return array + */ + protected function getAttachId($key, $value, array $attributes) + { + if (is_array($value)) + { + return array($key, array_merge($value, $attributes)); + } + + return array($value, $attributes); + } + + /** + * Create a new pivot attachment record. + * + * @param int $id + * @param bool $timed + * @return array + */ + protected function createAttachRecord($id, $timed) + { + $record[$this->foreignKey] = $this->parent->getKey(); + + $record[$this->otherKey] = $id; + + // If the record needs to have creation and update timestamps, we will make + // them by calling the parent model's "freshTimestamp" method which will + // provide us with a fresh timestamp in this model's preferred format. + if ($timed) + { + $record = $this->setTimestampsOnAttach($record); + } + + return $record; + } + + /** + * Set the creation and update timestamps on an attach record. + * + * @param array $record + * @param bool $exists + * @return array + */ + protected function setTimestampsOnAttach(array $record, $exists = false) + { + $fresh = $this->parent->freshTimestamp(); + + if ( ! $exists && $this->hasPivotColumn($this->createdAt())) + { + $record[$this->createdAt()] = $fresh; + } + + if ($this->hasPivotColumn($this->updatedAt())) + { + $record[$this->updatedAt()] = $fresh; + } + + return $record; + } + + /** + * Detach models from the relationship. + * + * @param int|array $ids + * @param bool $touch + * @return int + */ + public function detach($ids = array(), $touch = true) + { + if ($ids instanceof Model) $ids = (array) $ids->getKey(); + + $query = $this->newPivotQuery(); + + // If associated IDs were passed to the method we will only delete those + // associations, otherwise all of the association ties will be broken. + // We'll return the numbers of affected rows when we do the deletes. + $ids = (array) $ids; + + if (count($ids) > 0) + { + $query->whereIn($this->otherKey, (array) $ids); + } + + if ($touch) $this->touchIfTouching(); + + // Once we have all of the conditions set on the statement, we are ready + // to run the delete on the pivot table. Then, if the touch parameter + // is true, we will go ahead and touch all related models to sync. + $results = $query->delete(); + + return $results; + } + + /** + * If we're touching the parent model, touch. + * + * @return void + */ + public function touchIfTouching() + { + if ($this->touchingParent()) $this->getParent()->touch(); + + if ($this->getParent()->touches($this->relationName)) $this->touch(); + } + + /** + * Determine if we should touch the parent on sync. + * + * @return bool + */ + protected function touchingParent() + { + return $this->getRelated()->touches($this->guessInverseRelation()); + } + + /** + * Attempt to guess the name of the inverse of the relation. + * + * @return string + */ + protected function guessInverseRelation() + { + return camel_case(str_plural(class_basename($this->getParent()))); + } + + /** + * Create a new query builder for the pivot table. + * + * @return \Illuminate\Database\Query\Builder + */ + protected function newPivotQuery() + { + $query = $this->newPivotStatement(); + + foreach ($this->pivotWheres as $whereArgs) + { + call_user_func_array([$query, 'where'], $whereArgs); + } + + return $query->where($this->foreignKey, $this->parent->getKey()); + } + + /** + * Get a new plain query builder for the pivot table. + * + * @return \Illuminate\Database\Query\Builder + */ + public function newPivotStatement() + { + return $this->query->getQuery()->newQuery()->from($this->table); + } + + /** + * Get a new pivot statement for a given "other" ID. + * + * @param mixed $id + * @return \Illuminate\Database\Query\Builder + */ + public function newPivotStatementForId($id) + { + return $this->newPivotQuery()->where($this->otherKey, $id); + } + + /** + * Create a new pivot model instance. + * + * @param array $attributes + * @param bool $exists + * @return \Illuminate\Database\Eloquent\Relations\Pivot + */ + public function newPivot(array $attributes = array(), $exists = false) + { + $pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists); + + return $pivot->setPivotKeys($this->foreignKey, $this->otherKey); + } + + /** + * Create a new existing pivot model instance. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Relations\Pivot + */ + public function newExistingPivot(array $attributes = array()) + { + return $this->newPivot($attributes, true); + } + + /** + * Set the columns on the pivot table to retrieve. + * + * @param mixed $columns + * @return $this + */ + public function withPivot($columns) + { + $columns = is_array($columns) ? $columns : func_get_args(); + + $this->pivotColumns = array_merge($this->pivotColumns, $columns); + + return $this; + } + + /** + * Specify that the pivot table has creation and update timestamps. + * + * @param mixed $createdAt + * @param mixed $updatedAt + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function withTimestamps($createdAt = null, $updatedAt = null) + { + return $this->withPivot($createdAt ?: $this->createdAt(), $updatedAt ?: $this->updatedAt()); + } + + /** + * Get the related model's updated at column name. + * + * @return string + */ + public function getRelatedFreshUpdate() + { + return array($this->related->getUpdatedAtColumn() => $this->related->freshTimestamp()); + } + + /** + * Get the key for comparing against the parent key in "has" query. + * + * @return string + */ + public function getHasCompareKey() + { + return $this->getForeignKey(); + } + + /** + * Get the fully qualified foreign key for the relation. + * + * @return string + */ + public function getForeignKey() + { + return $this->table.'.'.$this->foreignKey; + } + + /** + * Get the fully qualified "other key" for the relation. + * + * @return string + */ + public function getOtherKey() + { + return $this->table.'.'.$this->otherKey; + } + + /** + * Get the intermediate table for the relationship. + * + * @return string + */ + public function getTable() + { + return $this->table; + } + + /** + * Get the relationship name for the relationship. + * + * @return string + */ + public function getRelationName() + { + return $this->relationName; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/HasMany.php b/vendor/illuminate/database/Eloquent/Relations/HasMany.php new file mode 100755 index 0000000..159a658 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/HasMany.php @@ -0,0 +1,47 @@ +query->get(); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, $this->related->newCollection()); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + return $this->matchMany($models, $results, $relation); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/HasManyThrough.php b/vendor/illuminate/database/Eloquent/Relations/HasManyThrough.php new file mode 100755 index 0000000..0560d7b --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/HasManyThrough.php @@ -0,0 +1,340 @@ +firstKey = $firstKey; + $this->secondKey = $secondKey; + $this->farParent = $farParent; + + parent::__construct($query, $parent); + } + + /** + * Set the base constraints on the relation query. + * + * @return void + */ + public function addConstraints() + { + $parentTable = $this->parent->getTable(); + + $this->setJoin(); + + if (static::$constraints) + { + $this->query->where($parentTable.'.'.$this->firstKey, '=', $this->farParent->getKey()); + } + } + + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + $parentTable = $this->parent->getTable(); + + $this->setJoin($query); + + $query->select(new Expression('count(*)')); + + $key = $this->wrap($parentTable.'.'.$this->firstKey); + + return $query->where($this->getHasCompareKey(), '=', new Expression($key)); + } + + /** + * Set the join clause on the query. + * + * @param \Illuminate\Database\Eloquent\Builder|null $query + * @return void + */ + protected function setJoin(Builder $query = null) + { + $query = $query ?: $this->query; + + $foreignKey = $this->related->getTable().'.'.$this->secondKey; + + $query->join($this->parent->getTable(), $this->getQualifiedParentKeyName(), '=', $foreignKey); + + if ($this->parentSoftDeletes()) + { + $query->whereNull($this->parent->getQualifiedDeletedAtColumn()); + } + } + + /** + * Determine whether close parent of the relation uses Soft Deletes. + * + * @return bool + */ + public function parentSoftDeletes() + { + return in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses_recursive(get_class($this->parent))); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + $table = $this->parent->getTable(); + + $this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($models)); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, $this->related->newCollection()); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + $dictionary = $this->buildDictionary($results); + + // Once we have the dictionary we can simply spin through the parent models to + // link them up with their children using the keyed dictionary to make the + // matching very convenient and easy work. Then we'll just return them. + foreach ($models as $model) + { + $key = $model->getKey(); + + if (isset($dictionary[$key])) + { + $value = $this->related->newCollection($dictionary[$key]); + + $model->setRelation($relation, $value); + } + } + + return $models; + } + + /** + * Build model dictionary keyed by the relation's foreign key. + * + * @param \Illuminate\Database\Eloquent\Collection $results + * @return array + */ + protected function buildDictionary(Collection $results) + { + $dictionary = []; + + $foreign = $this->firstKey; + + // First we will create a dictionary of models keyed by the foreign key of the + // relationship as this will allow us to quickly access all of the related + // models without having to do nested looping which will be quite slow. + foreach ($results as $result) + { + $dictionary[$result->{$foreign}][] = $result; + } + + return $dictionary; + } + + /** + * Get the results of the relationship. + * + * @return mixed + */ + public function getResults() + { + return $this->get(); + } + + /** + * Execute the query and get the first related model. + * + * @param array $columns + * @return mixed + */ + public function first($columns = ['*']) + { + $results = $this->take(1)->get($columns); + + return count($results) > 0 ? $results->first() : null; + } + + /** + * Find a related model by its primary key. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null + */ + public function find($id, $columns = ['*']) + { + if (is_array($id)) + { + return $this->findMany($id, $columns); + } + + $this->where($this->getRelated()->getQualifiedKeyName(), '=', $id); + + return $this->first($columns); + } + + /** + * Find multiple related models by their primary keys. + * + * @param mixed $ids + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection + */ + public function findMany($ids, $columns = ['*']) + { + if (empty($ids)) return $this->getRelated()->newCollection(); + + $this->whereIn($this->getRelated()->getQualifiedKeyName(), $ids); + + return $this->get($columns); + } + + /** + * Execute the query as a "select" statement. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Collection + */ + public function get($columns = ['*']) + { + // First we'll add the proper select columns onto the query so it is run with + // the proper columns. Then, we will get the results and hydrate out pivot + // models with the result of those columns as a separate model relation. + $columns = $this->query->getQuery()->columns ? [] : $columns; + + $select = $this->getSelectColumns($columns); + + $models = $this->query->addSelect($select)->getModels(); + + // If we actually found models we will also eager load any relationships that + // have been specified as needing to be eager loaded. This will solve the + // n + 1 query problem for the developer and also increase performance. + if (count($models) > 0) + { + $models = $this->query->eagerLoadRelations($models); + } + + return $this->related->newCollection($models); + } + + /** + * Set the select clause for the relation query. + * + * @param array $columns + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + protected function getSelectColumns(array $columns = ['*']) + { + if ($columns == ['*']) + { + $columns = [$this->related->getTable().'.*']; + } + + return array_merge($columns, [$this->parent->getTable().'.'.$this->firstKey]); + } + + /** + * Get a paginator for the "select" statement. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function paginate($perPage = null, $columns = ['*']) + { + $this->query->addSelect($this->getSelectColumns($columns)); + + return $this->query->paginate($perPage, $columns); + } + + /** + * Paginate the given query into a simple paginator. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\Paginator + */ + public function simplePaginate($perPage = null, $columns = ['*']) + { + $this->query->addSelect($this->getSelectColumns($columns)); + + return $this->query->simplePaginate($perPage, $columns); + } + + /** + * Get the key for comparing against the parent key in "has" query. + * + * @return string + */ + public function getHasCompareKey() + { + return $this->farParent->getQualifiedKeyName(); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/HasOne.php b/vendor/illuminate/database/Eloquent/Relations/HasOne.php new file mode 100755 index 0000000..fd0f9a0 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/HasOne.php @@ -0,0 +1,47 @@ +query->first(); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, null); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + return $this->matchOne($models, $results, $relation); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/HasOneOrMany.php b/vendor/illuminate/database/Eloquent/Relations/HasOneOrMany.php new file mode 100755 index 0000000..4a6542b --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/HasOneOrMany.php @@ -0,0 +1,412 @@ +localKey = $localKey; + $this->foreignKey = $foreignKey; + + parent::__construct($query, $parent); + } + + /** + * Set the base constraints on the relation query. + * + * @return void + */ + public function addConstraints() + { + if (static::$constraints) + { + $this->query->where($this->foreignKey, '=', $this->getParentKey()); + + $this->query->whereNotNull($this->foreignKey); + } + } + + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + if ($parent->getQuery()->from == $query->getQuery()->from) + { + return $this->getRelationCountQueryForSelfRelation($query, $parent); + } + + return parent::getRelationCountQuery($query, $parent); + } + + /** + * Add the constraints for a relationship count query on the same table. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent) + { + $query->select(new Expression('count(*)')); + + $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); + + $query->from($query->getModel()->getTable().' as '.$tablePrefix.$hash = $this->getRelationCountHash()); + + $key = $this->wrap($this->getQualifiedParentKeyName()); + + return $query->where($hash.'.'.$this->getPlainForeignKey(), '=', new Expression($key)); + } + + /** + * Get a relationship join table hash. + * + * @return string + */ + public function getRelationCountHash() + { + return 'self_'.md5(microtime(true)); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + $this->query->whereIn($this->foreignKey, $this->getKeys($models, $this->localKey)); + } + + /** + * Match the eagerly loaded results to their single parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function matchOne(array $models, Collection $results, $relation) + { + return $this->matchOneOrMany($models, $results, $relation, 'one'); + } + + /** + * Match the eagerly loaded results to their many parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function matchMany(array $models, Collection $results, $relation) + { + return $this->matchOneOrMany($models, $results, $relation, 'many'); + } + + /** + * Match the eagerly loaded results to their many parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @param string $type + * @return array + */ + protected function matchOneOrMany(array $models, Collection $results, $relation, $type) + { + $dictionary = $this->buildDictionary($results); + + // Once we have the dictionary we can simply spin through the parent models to + // link them up with their children using the keyed dictionary to make the + // matching very convenient and easy work. Then we'll just return them. + foreach ($models as $model) + { + $key = $model->getAttribute($this->localKey); + + if (isset($dictionary[$key])) + { + $value = $this->getRelationValue($dictionary, $key, $type); + + $model->setRelation($relation, $value); + } + } + + return $models; + } + + /** + * Get the value of a relationship by one or many type. + * + * @param array $dictionary + * @param string $key + * @param string $type + * @return mixed + */ + protected function getRelationValue(array $dictionary, $key, $type) + { + $value = $dictionary[$key]; + + return $type == 'one' ? reset($value) : $this->related->newCollection($value); + } + + /** + * Build model dictionary keyed by the relation's foreign key. + * + * @param \Illuminate\Database\Eloquent\Collection $results + * @return array + */ + protected function buildDictionary(Collection $results) + { + $dictionary = array(); + + $foreign = $this->getPlainForeignKey(); + + // First we will create a dictionary of models keyed by the foreign key of the + // relationship as this will allow us to quickly access all of the related + // models without having to do nested looping which will be quite slow. + foreach ($results as $result) + { + $dictionary[$result->{$foreign}][] = $result; + } + + return $dictionary; + } + + /** + * Attach a model instance to the parent model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Model + */ + public function save(Model $model) + { + $model->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); + + return $model->save() ? $model : false; + } + + /** + * Attach an array of models to the parent instance. + * + * @param array $models + * @return array + */ + public function saveMany(array $models) + { + array_walk($models, array($this, 'save')); + + return $models; + } + + /** + * Find a model by its primary key or return new instance of the related model. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model + */ + public function findOrNew($id, $columns = ['*']) + { + if (is_null($instance = $this->find($id, $columns))) + { + $instance = $this->related->newInstance(); + + $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); + } + + return $instance; + } + + /** + * Get the first related model record matching the attributes or instantiate it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrNew(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->related->newInstance($attributes); + + $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); + } + + return $instance; + } + + /** + * Get the first related record matching the attributes or create it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrCreate(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($attributes); + } + + return $instance; + } + + /** + * Create or update a related record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public function updateOrCreate(array $attributes, array $values = []) + { + $instance = $this->firstOrNew($attributes); + + $instance->fill($values); + + $instance->save(); + + return $instance; + } + + /** + * Create a new instance of the related model. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function create(array $attributes) + { + // Here we will set the raw attributes to avoid hitting the "fill" method so + // that we do not have to worry about a mass accessor rules blocking sets + // on the models. Otherwise, some of these attributes will not get set. + $instance = $this->related->newInstance($attributes); + + $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey()); + + $instance->save(); + + return $instance; + } + + /** + * Create an array of new instances of the related model. + * + * @param array $records + * @return array + */ + public function createMany(array $records) + { + $instances = array(); + + foreach ($records as $record) + { + $instances[] = $this->create($record); + } + + return $instances; + } + + /** + * Perform an update on all the related models. + * + * @param array $attributes + * @return int + */ + public function update(array $attributes) + { + if ($this->related->usesTimestamps()) + { + $attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestampString(); + } + + return $this->query->update($attributes); + } + + /** + * Get the key for comparing against the parent key in "has" query. + * + * @return string + */ + public function getHasCompareKey() + { + return $this->getForeignKey(); + } + + /** + * Get the foreign key for the relationship. + * + * @return string + */ + public function getForeignKey() + { + return $this->foreignKey; + } + + /** + * Get the plain foreign key. + * + * @return string + */ + public function getPlainForeignKey() + { + $segments = explode('.', $this->getForeignKey()); + + return $segments[count($segments) - 1]; + } + + /** + * Get the key value of the parent's local key. + * + * @return mixed + */ + public function getParentKey() + { + return $this->parent->getAttribute($this->localKey); + } + + /** + * Get the fully qualified parent key name. + * + * @return string + */ + public function getQualifiedParentKeyName() + { + return $this->parent->getTable().'.'.$this->localKey; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/MorphMany.php b/vendor/illuminate/database/Eloquent/Relations/MorphMany.php new file mode 100755 index 0000000..1abdf37 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/MorphMany.php @@ -0,0 +1,47 @@ +query->get(); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, $this->related->newCollection()); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + return $this->matchMany($models, $results, $relation); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/MorphOne.php b/vendor/illuminate/database/Eloquent/Relations/MorphOne.php new file mode 100755 index 0000000..fdebc24 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/MorphOne.php @@ -0,0 +1,47 @@ +query->first(); + } + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + public function initRelation(array $models, $relation) + { + foreach ($models as $model) + { + $model->setRelation($relation, null); + } + + return $models; + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + return $this->matchOne($models, $results, $relation); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/MorphOneOrMany.php b/vendor/illuminate/database/Eloquent/Relations/MorphOneOrMany.php new file mode 100755 index 0000000..19a9817 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/MorphOneOrMany.php @@ -0,0 +1,236 @@ +morphType = $type; + + $this->morphClass = $parent->getMorphClass(); + + parent::__construct($query, $parent, $id, $localKey); + } + + /** + * Set the base constraints on the relation query. + * + * @return void + */ + public function addConstraints() + { + if (static::$constraints) + { + parent::addConstraints(); + + $this->query->where($this->morphType, $this->morphClass); + } + } + + /** + * Get the relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + $query = parent::getRelationCountQuery($query, $parent); + + return $query->where($this->morphType, $this->morphClass); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + parent::addEagerConstraints($models); + + $this->query->where($this->morphType, $this->morphClass); + } + + /** + * Attach a model instance to the parent model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Model + */ + public function save(Model $model) + { + $model->setAttribute($this->getPlainMorphType(), $this->morphClass); + + return parent::save($model); + } + + /** + * Find a related model by its primary key or return new instance of the related model. + * + * @param mixed $id + * @param array $columns + * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model + */ + public function findOrNew($id, $columns = ['*']) + { + if (is_null($instance = $this->find($id, $columns))) + { + $instance = $this->related->newInstance(); + + // When saving a polymorphic relationship, we need to set not only the foreign + // key, but also the foreign key type, which is typically the class name of + // the parent model. This makes the polymorphic item unique in the table. + $this->setForeignAttributesForCreate($instance); + } + + return $instance; + } + + /** + * Get the first related model record matching the attributes or instantiate it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrNew(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->related->newInstance(); + + // When saving a polymorphic relationship, we need to set not only the foreign + // key, but also the foreign key type, which is typically the class name of + // the parent model. This makes the polymorphic item unique in the table. + $this->setForeignAttributesForCreate($instance); + } + + return $instance; + } + + /** + * Get the first related record matching the attributes or create it. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function firstOrCreate(array $attributes) + { + if (is_null($instance = $this->where($attributes)->first())) + { + $instance = $this->create($attributes); + } + + return $instance; + } + + /** + * Create or update a related record matching the attributes, and fill it with values. + * + * @param array $attributes + * @param array $values + * @return \Illuminate\Database\Eloquent\Model + */ + public function updateOrCreate(array $attributes, array $values = []) + { + $instance = $this->firstOrNew($attributes); + + $instance->fill($values); + + $instance->save(); + + return $instance; + } + + /** + * Create a new instance of the related model. + * + * @param array $attributes + * @return \Illuminate\Database\Eloquent\Model + */ + public function create(array $attributes) + { + $instance = $this->related->newInstance($attributes); + + // When saving a polymorphic relationship, we need to set not only the foreign + // key, but also the foreign key type, which is typically the class name of + // the parent model. This makes the polymorphic item unique in the table. + $this->setForeignAttributesForCreate($instance); + + $instance->save(); + + return $instance; + } + + /** + * Set the foreign ID and type for creating a related model. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return void + */ + protected function setForeignAttributesForCreate(Model $model) + { + $model->{$this->getPlainForeignKey()} = $this->getParentKey(); + + $model->{last(explode('.', $this->morphType))} = $this->morphClass; + } + + /** + * Get the foreign key "type" name. + * + * @return string + */ + public function getMorphType() + { + return $this->morphType; + } + + /** + * Get the plain morph type name without the table. + * + * @return string + */ + public function getPlainMorphType() + { + return last(explode('.', $this->morphType)); + } + + /** + * Get the class name of the parent model. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/MorphPivot.php b/vendor/illuminate/database/Eloquent/Relations/MorphPivot.php new file mode 100755 index 0000000..fe8c644 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/MorphPivot.php @@ -0,0 +1,78 @@ +where($this->morphType, $this->morphClass); + + return parent::setKeysForSaveQuery($query); + } + + /** + * Delete the pivot model record from the database. + * + * @return int + */ + public function delete() + { + $query = $this->getDeleteQuery(); + + $query->where($this->morphType, $this->morphClass); + + return $query->delete(); + } + + /** + * Set the morph type for the pivot. + * + * @param string $morphType + * @return $this + */ + public function setMorphType($morphType) + { + $this->morphType = $morphType; + + return $this; + } + + /** + * Set the morph class for the pivot. + * + * @param string $morphClass + * @return \Illuminate\Database\Eloquent\Relations\MorphPivot + */ + public function setMorphClass($morphClass) + { + $this->morphClass = $morphClass; + + return $this; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/MorphTo.php b/vendor/illuminate/database/Eloquent/Relations/MorphTo.php new file mode 100755 index 0000000..b736f0c --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/MorphTo.php @@ -0,0 +1,247 @@ +morphType = $type; + + parent::__construct($query, $parent, $foreignKey, $otherKey, $relation); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + $this->buildDictionary($this->models = Collection::make($models)); + } + + /** + * Build a dictionary with the models. + * + * @param \Illuminate\Database\Eloquent\Collection $models + * @return void + */ + protected function buildDictionary(Collection $models) + { + foreach ($models as $model) + { + if ($model->{$this->morphType}) + { + $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model; + } + } + } + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + public function match(array $models, Collection $results, $relation) + { + return $models; + } + + /** + * Associate the model instance to the given parent. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Model + */ + public function associate(Model $model) + { + $this->parent->setAttribute($this->foreignKey, $model->getKey()); + + $this->parent->setAttribute($this->morphType, $model->getMorphClass()); + + return $this->parent->setRelation($this->relation, $model); + } + + /** + * Get the results of the relationship. + * + * Called via eager load method of Eloquent query builder. + * + * @return mixed + */ + public function getEager() + { + foreach (array_keys($this->dictionary) as $type) + { + $this->matchToMorphParents($type, $this->getResultsByType($type)); + } + + return $this->models; + } + + /** + * Match the results for a given type to their parents. + * + * @param string $type + * @param \Illuminate\Database\Eloquent\Collection $results + * @return void + */ + protected function matchToMorphParents($type, Collection $results) + { + foreach ($results as $result) + { + if (isset($this->dictionary[$type][$result->getKey()])) + { + foreach ($this->dictionary[$type][$result->getKey()] as $model) + { + $model->setRelation($this->relation, $result); + } + } + } + } + + /** + * Get all of the relation results for a type. + * + * @param string $type + * @return \Illuminate\Database\Eloquent\Collection + */ + protected function getResultsByType($type) + { + $instance = $this->createModelByType($type); + + $key = $instance->getKeyName(); + + $query = $instance->newQuery(); + + $query = $this->useWithTrashed($query); + + return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get(); + } + + /** + * Gather all of the foreign keys for a given type. + * + * @param string $type + * @return array + */ + protected function gatherKeysByType($type) + { + $foreign = $this->foreignKey; + + return BaseCollection::make($this->dictionary[$type])->map(function($models) use ($foreign) + { + return head($models)->{$foreign}; + + })->unique(); + } + + /** + * Create a new model instance by type. + * + * @param string $type + * @return \Illuminate\Database\Eloquent\Model + */ + public function createModelByType($type) + { + return new $type; + } + + /** + * Get the foreign key "type" name. + * + * @return string + */ + public function getMorphType() + { + return $this->morphType; + } + + /** + * Get the dictionary used by the relationship. + * + * @return array + */ + public function getDictionary() + { + return $this->dictionary; + } + + /** + * Fetch soft-deleted model instances with query. + * + * @return $this + */ + public function withTrashed() + { + $this->withTrashed = true; + + $this->query = $this->useWithTrashed($this->query); + + return $this; + } + + /** + * Return trashed models with query if told so. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function useWithTrashed(Builder $query) + { + if ($this->withTrashed && $query->getMacro('withTrashed') !== null) + { + return $query->withTrashed(); + } + + return $query; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/MorphToMany.php b/vendor/illuminate/database/Eloquent/Relations/MorphToMany.php new file mode 100755 index 0000000..18d970d --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/MorphToMany.php @@ -0,0 +1,158 @@ +inverse = $inverse; + $this->morphType = $name.'_type'; + $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass(); + + parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName); + } + + /** + * Set the where clause for the relation query. + * + * @return $this + */ + protected function setWhere() + { + parent::setWhere(); + + $this->query->where($this->table.'.'.$this->morphType, $this->morphClass); + + return $this; + } + + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + $query = parent::getRelationCountQuery($query, $parent); + + return $query->where($this->table.'.'.$this->morphType, $this->morphClass); + } + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + public function addEagerConstraints(array $models) + { + parent::addEagerConstraints($models); + + $this->query->where($this->table.'.'.$this->morphType, $this->morphClass); + } + + /** + * Create a new pivot attachment record. + * + * @param int $id + * @param bool $timed + * @return array + */ + protected function createAttachRecord($id, $timed) + { + $record = parent::createAttachRecord($id, $timed); + + return array_add($record, $this->morphType, $this->morphClass); + } + + /** + * Create a new query builder for the pivot table. + * + * @return \Illuminate\Database\Query\Builder + */ + protected function newPivotQuery() + { + $query = parent::newPivotQuery(); + + return $query->where($this->morphType, $this->morphClass); + } + + /** + * Create a new pivot model instance. + * + * @param array $attributes + * @param bool $exists + * @return \Illuminate\Database\Eloquent\Relations\Pivot + */ + public function newPivot(array $attributes = array(), $exists = false) + { + $pivot = new MorphPivot($this->parent, $attributes, $this->table, $exists); + + $pivot->setPivotKeys($this->foreignKey, $this->otherKey) + ->setMorphType($this->morphType) + ->setMorphClass($this->morphClass); + + return $pivot; + } + + /** + * Get the foreign key "type" name. + * + * @return string + */ + public function getMorphType() + { + return $this->morphType; + } + + /** + * Get the class name of the parent model. + * + * @return string + */ + public function getMorphClass() + { + return $this->morphClass; + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/Pivot.php b/vendor/illuminate/database/Eloquent/Relations/Pivot.php new file mode 100755 index 0000000..365477e --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/Pivot.php @@ -0,0 +1,171 @@ +setRawAttributes($attributes, true); + + $this->setTable($table); + + $this->setConnection($parent->getConnectionName()); + + // We store off the parent instance so we will access the timestamp column names + // for the model, since the pivot model timestamps aren't easily configurable + // from the developer's point of view. We can use the parents to get these. + $this->parent = $parent; + + $this->exists = $exists; + + $this->timestamps = $this->hasTimestampAttributes(); + } + + /** + * Set the keys for a save update query. + * + * @param \Illuminate\Database\Eloquent\Builder + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function setKeysForSaveQuery(Builder $query) + { + $query->where($this->foreignKey, $this->getAttribute($this->foreignKey)); + + return $query->where($this->otherKey, $this->getAttribute($this->otherKey)); + } + + /** + * Delete the pivot model record from the database. + * + * @return int + */ + public function delete() + { + return $this->getDeleteQuery()->delete(); + } + + /** + * Get the query builder for a delete operation on the pivot. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function getDeleteQuery() + { + $foreign = $this->getAttribute($this->foreignKey); + + $query = $this->newQuery()->where($this->foreignKey, $foreign); + + return $query->where($this->otherKey, $this->getAttribute($this->otherKey)); + } + + /** + * Get the foreign key column name. + * + * @return string + */ + public function getForeignKey() + { + return $this->foreignKey; + } + + /** + * Get the "other key" column name. + * + * @return string + */ + public function getOtherKey() + { + return $this->otherKey; + } + + /** + * Set the key names for the pivot model instance. + * + * @param string $foreignKey + * @param string $otherKey + * @return $this + */ + public function setPivotKeys($foreignKey, $otherKey) + { + $this->foreignKey = $foreignKey; + + $this->otherKey = $otherKey; + + return $this; + } + + /** + * Determine if the pivot model has timestamp attributes. + * + * @return bool + */ + public function hasTimestampAttributes() + { + return array_key_exists($this->getCreatedAtColumn(), $this->attributes); + } + + /** + * Get the name of the "created at" column. + * + * @return string + */ + public function getCreatedAtColumn() + { + return $this->parent->getCreatedAtColumn(); + } + + /** + * Get the name of the "updated at" column. + * + * @return string + */ + public function getUpdatedAtColumn() + { + return $this->parent->getUpdatedAtColumn(); + } + +} diff --git a/vendor/illuminate/database/Eloquent/Relations/Relation.php b/vendor/illuminate/database/Eloquent/Relations/Relation.php new file mode 100755 index 0000000..9525af0 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/Relations/Relation.php @@ -0,0 +1,290 @@ +query = $query; + $this->parent = $parent; + $this->related = $query->getModel(); + + $this->addConstraints(); + } + + /** + * Set the base constraints on the relation query. + * + * @return void + */ + abstract public function addConstraints(); + + /** + * Set the constraints for an eager load of the relation. + * + * @param array $models + * @return void + */ + abstract public function addEagerConstraints(array $models); + + /** + * Initialize the relation on a set of models. + * + * @param array $models + * @param string $relation + * @return array + */ + abstract public function initRelation(array $models, $relation); + + /** + * Match the eagerly loaded results to their parents. + * + * @param array $models + * @param \Illuminate\Database\Eloquent\Collection $results + * @param string $relation + * @return array + */ + abstract public function match(array $models, Collection $results, $relation); + + /** + * Get the results of the relationship. + * + * @return mixed + */ + abstract public function getResults(); + + /** + * Get the relationship for eager loading. + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public function getEager() + { + return $this->get(); + } + + /** + * Touch all of the related models for the relationship. + * + * @return void + */ + public function touch() + { + $column = $this->getRelated()->getUpdatedAtColumn(); + + $this->rawUpdate(array($column => $this->getRelated()->freshTimestampString())); + } + + /** + * Run a raw update against the base query. + * + * @param array $attributes + * @return int + */ + public function rawUpdate(array $attributes = array()) + { + return $this->query->update($attributes); + } + + /** + * Add the constraints for a relationship count query. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $parent + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getRelationCountQuery(Builder $query, Builder $parent) + { + $query->select(new Expression('count(*)')); + + $key = $this->wrap($this->getQualifiedParentKeyName()); + + return $query->where($this->getHasCompareKey(), '=', new Expression($key)); + } + + /** + * Run a callback with constraints disabled on the relation. + * + * @param \Closure $callback + * @return mixed + */ + public static function noConstraints(Closure $callback) + { + $previous = static::$constraints; + + static::$constraints = false; + + // When resetting the relation where clause, we want to shift the first element + // off of the bindings, leaving only the constraints that the developers put + // as "extra" on the relationships, and not original relation constraints. + $results = call_user_func($callback); + + static::$constraints = $previous; + + return $results; + } + + /** + * Get all of the primary keys for an array of models. + * + * @param array $models + * @param string $key + * @return array + */ + protected function getKeys(array $models, $key = null) + { + return array_unique(array_values(array_map(function($value) use ($key) + { + return $key ? $value->getAttribute($key) : $value->getKey(); + + }, $models))); + } + + /** + * Get the underlying query for the relation. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function getQuery() + { + return $this->query; + } + + /** + * Get the base query builder driving the Eloquent builder. + * + * @return \Illuminate\Database\Query\Builder + */ + public function getBaseQuery() + { + return $this->query->getQuery(); + } + + /** + * Get the parent model of the relation. + * + * @return \Illuminate\Database\Eloquent\Model + */ + public function getParent() + { + return $this->parent; + } + + /** + * Get the fully qualified parent key name. + * + * @return string + */ + public function getQualifiedParentKeyName() + { + return $this->parent->getQualifiedKeyName(); + } + + /** + * Get the related model of the relation. + * + * @return \Illuminate\Database\Eloquent\Model + */ + public function getRelated() + { + return $this->related; + } + + /** + * Get the name of the "created at" column. + * + * @return string + */ + public function createdAt() + { + return $this->parent->getCreatedAtColumn(); + } + + /** + * Get the name of the "updated at" column. + * + * @return string + */ + public function updatedAt() + { + return $this->parent->getUpdatedAtColumn(); + } + + /** + * Get the name of the related model's "updated at" column. + * + * @return string + */ + public function relatedUpdatedAt() + { + return $this->related->getUpdatedAtColumn(); + } + + /** + * Wrap the given value with the parent query's grammar. + * + * @param string $value + * @return string + */ + public function wrap($value) + { + return $this->parent->newQueryWithoutScopes()->getQuery()->getGrammar()->wrap($value); + } + + /** + * Handle dynamic method calls to the relationship. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + $result = call_user_func_array(array($this->query, $method), $parameters); + + if ($result === $this->query) return $this; + + return $result; + } + +} diff --git a/vendor/illuminate/database/Eloquent/ScopeInterface.php b/vendor/illuminate/database/Eloquent/ScopeInterface.php new file mode 100755 index 0000000..7cc1349 --- /dev/null +++ b/vendor/illuminate/database/Eloquent/ScopeInterface.php @@ -0,0 +1,24 @@ +forceDeleting = true; + + $this->delete(); + + $this->forceDeleting = false; + } + + /** + * Perform the actual delete query on this model instance. + * + * @return void + */ + protected function performDeleteOnModel() + { + if ($this->forceDeleting) + { + return $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete(); + } + + return $this->runSoftDelete(); + } + + /** + * Perform the actual delete query on this model instance. + * + * @return void + */ + protected function runSoftDelete() + { + $query = $this->newQuery()->where($this->getKeyName(), $this->getKey()); + + $this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp(); + + $query->update(array($this->getDeletedAtColumn() => $this->fromDateTime($time))); + } + + /** + * Restore a soft-deleted model instance. + * + * @return bool|null + */ + public function restore() + { + // If the restoring event does not return false, we will proceed with this + // restore operation. Otherwise, we bail out so the developer will stop + // the restore totally. We will clear the deleted timestamp and save. + if ($this->fireModelEvent('restoring') === false) + { + return false; + } + + $this->{$this->getDeletedAtColumn()} = null; + + // Once we have saved the model, we will fire the "restored" event so this + // developer will do anything they need to after a restore operation is + // totally finished. Then we will return the result of the save call. + $this->exists = true; + + $result = $this->save(); + + $this->fireModelEvent('restored', false); + + return $result; + } + + /** + * Determine if the model instance has been soft-deleted. + * + * @return bool + */ + public function trashed() + { + return ! is_null($this->{$this->getDeletedAtColumn()}); + } + + /** + * Get a new query builder that includes soft deletes. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public static function withTrashed() + { + return (new static)->newQueryWithoutScope(new SoftDeletingScope); + } + + /** + * Get a new query builder that only includes soft deletes. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public static function onlyTrashed() + { + $instance = new static; + + $column = $instance->getQualifiedDeletedAtColumn(); + + return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column); + } + + /** + * Register a restoring model event with the dispatcher. + * + * @param \Closure|string $callback + * @return void + */ + public static function restoring($callback) + { + static::registerModelEvent('restoring', $callback); + } + + /** + * Register a restored model event with the dispatcher. + * + * @param \Closure|string $callback + * @return void + */ + public static function restored($callback) + { + static::registerModelEvent('restored', $callback); + } + + /** + * Get the name of the "deleted at" column. + * + * @return string + */ + public function getDeletedAtColumn() + { + return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at'; + } + + /** + * Get the fully qualified "deleted at" column. + * + * @return string + */ + public function getQualifiedDeletedAtColumn() + { + return $this->getTable().'.'.$this->getDeletedAtColumn(); + } + +} diff --git a/vendor/illuminate/database/Eloquent/SoftDeletingScope.php b/vendor/illuminate/database/Eloquent/SoftDeletingScope.php new file mode 100755 index 0000000..ea6d46e --- /dev/null +++ b/vendor/illuminate/database/Eloquent/SoftDeletingScope.php @@ -0,0 +1,164 @@ +whereNull($model->getQualifiedDeletedAtColumn()); + + $this->extend($builder); + } + + /** + * Remove the scope from the given Eloquent query builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Model $model + * @return void + */ + public function remove(Builder $builder, Model $model) + { + $column = $model->getQualifiedDeletedAtColumn(); + + $query = $builder->getQuery(); + + $query->wheres = collect($query->wheres)->reject(function($where) use ($column) + { + return $this->isSoftDeleteConstraint($where, $column); + })->values()->all(); + } + + /** + * Extend the query builder with the needed functions. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + public function extend(Builder $builder) + { + foreach ($this->extensions as $extension) + { + $this->{"add{$extension}"}($builder); + } + + $builder->onDelete(function(Builder $builder) + { + $column = $this->getDeletedAtColumn($builder); + + return $builder->update(array( + $column => $builder->getModel()->freshTimestampString(), + )); + }); + } + + /** + * Get the "deleted at" column for the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return string + */ + protected function getDeletedAtColumn(Builder $builder) + { + if (count($builder->getQuery()->joins) > 0) + { + return $builder->getModel()->getQualifiedDeletedAtColumn(); + } + else + { + return $builder->getModel()->getDeletedAtColumn(); + } + } + + /** + * Add the force delete extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addForceDelete(Builder $builder) + { + $builder->macro('forceDelete', function(Builder $builder) + { + return $builder->getQuery()->delete(); + }); + } + + /** + * Add the restore extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addRestore(Builder $builder) + { + $builder->macro('restore', function(Builder $builder) + { + $builder->withTrashed(); + + return $builder->update(array($builder->getModel()->getDeletedAtColumn() => null)); + }); + } + + /** + * Add the with-trashed extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addWithTrashed(Builder $builder) + { + $builder->macro('withTrashed', function(Builder $builder) + { + $this->remove($builder, $builder->getModel()); + + return $builder; + }); + } + + /** + * Add the only-trashed extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addOnlyTrashed(Builder $builder) + { + $builder->macro('onlyTrashed', function(Builder $builder) + { + $model = $builder->getModel(); + + $this->remove($builder, $model); + + $builder->getQuery()->whereNotNull($model->getQualifiedDeletedAtColumn()); + + return $builder; + }); + } + + /** + * Determine if the given where clause is a soft delete constraint. + * + * @param array $where + * @param string $column + * @return bool + */ + protected function isSoftDeleteConstraint(array $where, $column) + { + return $where['type'] == 'Null' && $where['column'] == $column; + } + +} diff --git a/vendor/illuminate/database/Grammar.php b/vendor/illuminate/database/Grammar.php new file mode 100755 index 0000000..c3db236 --- /dev/null +++ b/vendor/illuminate/database/Grammar.php @@ -0,0 +1,184 @@ +isExpression($table)) return $this->getValue($table); + + return $this->wrap($this->tablePrefix.$table, true); + } + + /** + * Wrap a value in keyword identifiers. + * + * @param string $value + * @param bool $prefixAlias + * @return string + */ + public function wrap($value, $prefixAlias = false) + { + if ($this->isExpression($value)) return $this->getValue($value); + + // If the value being wrapped has a column alias we will need to separate out + // the pieces so we can wrap each of the segments of the expression on it + // own, and then joins them both back together with the "as" connector. + if (strpos(strtolower($value), ' as ') !== false) + { + $segments = explode(' ', $value); + + if ($prefixAlias) $segments[2] = $this->tablePrefix.$segments[2]; + + return $this->wrap($segments[0]).' as '.$this->wrapValue($segments[2]); + } + + $wrapped = array(); + + $segments = explode('.', $value); + + // If the value is not an aliased table expression, we'll just wrap it like + // normal, so if there is more than one segment, we will wrap the first + // segments as if it was a table and the rest as just regular values. + foreach ($segments as $key => $segment) + { + if ($key == 0 && count($segments) > 1) + { + $wrapped[] = $this->wrapTable($segment); + } + else + { + $wrapped[] = $this->wrapValue($segment); + } + } + + return implode('.', $wrapped); + } + + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '"'.str_replace('"', '""', $value).'"'; + } + + /** + * Convert an array of column names into a delimited string. + * + * @param array $columns + * @return string + */ + public function columnize(array $columns) + { + return implode(', ', array_map(array($this, 'wrap'), $columns)); + } + + /** + * Create query parameter place-holders for an array. + * + * @param array $values + * @return string + */ + public function parameterize(array $values) + { + return implode(', ', array_map(array($this, 'parameter'), $values)); + } + + /** + * Get the appropriate query parameter place-holder for a value. + * + * @param mixed $value + * @return string + */ + public function parameter($value) + { + return $this->isExpression($value) ? $this->getValue($value) : '?'; + } + + /** + * Get the value of a raw expression. + * + * @param \Illuminate\Database\Query\Expression $expression + * @return string + */ + public function getValue($expression) + { + return $expression->getValue(); + } + + /** + * Determine if the given value is a raw expression. + * + * @param mixed $value + * @return bool + */ + public function isExpression($value) + { + return $value instanceof Expression; + } + + /** + * Get the format for database stored dates. + * + * @return string + */ + public function getDateFormat() + { + return 'Y-m-d H:i:s'; + } + + /** + * Get the grammar's table prefix. + * + * @return string + */ + public function getTablePrefix() + { + return $this->tablePrefix; + } + + /** + * Set the grammar's table prefix. + * + * @param string $prefix + * @return $this + */ + public function setTablePrefix($prefix) + { + $this->tablePrefix = $prefix; + + return $this; + } + +} diff --git a/vendor/illuminate/database/MigrationServiceProvider.php b/vendor/illuminate/database/MigrationServiceProvider.php new file mode 100755 index 0000000..aeca8c5 --- /dev/null +++ b/vendor/illuminate/database/MigrationServiceProvider.php @@ -0,0 +1,226 @@ +registerRepository(); + + // Once we have registered the migrator instance we will go ahead and register + // all of the migration related commands that are used by the "Artisan" CLI + // so that they may be easily accessed for registering with the consoles. + $this->registerMigrator(); + + $this->registerCommands(); + } + + /** + * Register the migration repository service. + * + * @return void + */ + protected function registerRepository() + { + $this->app->singleton('migration.repository', function($app) + { + $table = $app['config']['database.migrations']; + + return new DatabaseMigrationRepository($app['db'], $table); + }); + } + + /** + * Register the migrator service. + * + * @return void + */ + protected function registerMigrator() + { + // The migrator is responsible for actually running and rollback the migration + // files in the application. We'll pass in our database connection resolver + // so the migrator can resolve any of these connections when it needs to. + $this->app->singleton('migrator', function($app) + { + $repository = $app['migration.repository']; + + return new Migrator($repository, $app['db'], $app['files']); + }); + } + + /** + * Register all of the migration commands. + * + * @return void + */ + protected function registerCommands() + { + $commands = array('Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make', 'Status'); + + // We'll simply spin through the list of commands that are migration related + // and register each one of them with an application container. They will + // be resolved in the Artisan start file and registered on the console. + foreach ($commands as $command) + { + $this->{'register'.$command.'Command'}(); + } + + // Once the commands are registered in the application IoC container we will + // register them with the Artisan start event so that these are available + // when the Artisan application actually starts up and is getting used. + $this->commands( + 'command.migrate', 'command.migrate.make', + 'command.migrate.install', 'command.migrate.rollback', + 'command.migrate.reset', 'command.migrate.refresh', + 'command.migrate.status' + ); + } + + /** + * Register the "migrate" migration command. + * + * @return void + */ + protected function registerMigrateCommand() + { + $this->app->singleton('command.migrate', function($app) + { + return new MigrateCommand($app['migrator']); + }); + } + + /** + * Register the "rollback" migration command. + * + * @return void + */ + protected function registerRollbackCommand() + { + $this->app->singleton('command.migrate.rollback', function($app) + { + return new RollbackCommand($app['migrator']); + }); + } + + /** + * Register the "reset" migration command. + * + * @return void + */ + protected function registerResetCommand() + { + $this->app->singleton('command.migrate.reset', function($app) + { + return new ResetCommand($app['migrator']); + }); + } + + /** + * Register the "refresh" migration command. + * + * @return void + */ + protected function registerRefreshCommand() + { + $this->app->singleton('command.migrate.refresh', function() + { + return new RefreshCommand; + }); + } + + protected function registerStatusCommand() + { + $this->app->singleton('command.migrate.status', function($app) + { + return new StatusCommand($app['migrator']); + }); + } + + /** + * Register the "install" migration command. + * + * @return void + */ + protected function registerInstallCommand() + { + $this->app->singleton('command.migrate.install', function($app) + { + return new InstallCommand($app['migration.repository']); + }); + } + + /** + * Register the "make" migration command. + * + * @return void + */ + protected function registerMakeCommand() + { + $this->registerCreator(); + + $this->app->singleton('command.migrate.make', function($app) + { + // Once we have the migration creator registered, we will create the command + // and inject the creator. The creator is responsible for the actual file + // creation of the migrations, and may be extended by these developers. + $creator = $app['migration.creator']; + + $composer = $app['composer']; + + return new MigrateMakeCommand($creator, $composer); + }); + } + + /** + * Register the migration creator. + * + * @return void + */ + protected function registerCreator() + { + $this->app->singleton('migration.creator', function($app) + { + return new MigrationCreator($app['files']); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array( + 'migrator', 'migration.repository', 'command.migrate', + 'command.migrate.rollback', 'command.migrate.reset', + 'command.migrate.refresh', 'command.migrate.install', + 'command.migrate.status', 'migration.creator', + 'command.migrate.make', + ); + } + +} diff --git a/vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php b/vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php new file mode 100755 index 0000000..8894710 --- /dev/null +++ b/vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php @@ -0,0 +1,181 @@ +table = $table; + $this->resolver = $resolver; + } + + /** + * Get the ran migrations. + * + * @return array + */ + public function getRan() + { + return $this->table()->lists('migration'); + } + + /** + * Get the last migration batch. + * + * @return array + */ + public function getLast() + { + $query = $this->table()->where('batch', $this->getLastBatchNumber()); + + return $query->orderBy('migration', 'desc')->get(); + } + + /** + * Log that a migration was run. + * + * @param string $file + * @param int $batch + * @return void + */ + public function log($file, $batch) + { + $record = array('migration' => $file, 'batch' => $batch); + + $this->table()->insert($record); + } + + /** + * Remove a migration from the log. + * + * @param object $migration + * @return void + */ + public function delete($migration) + { + $this->table()->where('migration', $migration->migration)->delete(); + } + + /** + * Get the next migration batch number. + * + * @return int + */ + public function getNextBatchNumber() + { + return $this->getLastBatchNumber() + 1; + } + + /** + * Get the last migration batch number. + * + * @return int + */ + public function getLastBatchNumber() + { + return $this->table()->max('batch'); + } + + /** + * Create the migration repository data store. + * + * @return void + */ + public function createRepository() + { + $schema = $this->getConnection()->getSchemaBuilder(); + + $schema->create($this->table, function($table) + { + // The migrations table is responsible for keeping track of which of the + // migrations have actually run for the application. We'll create the + // table to hold the migration file's path as well as the batch ID. + $table->string('migration'); + + $table->integer('batch'); + }); + } + + /** + * Determine if the migration repository exists. + * + * @return bool + */ + public function repositoryExists() + { + $schema = $this->getConnection()->getSchemaBuilder(); + + return $schema->hasTable($this->table); + } + + /** + * Get a query builder for the migration table. + * + * @return \Illuminate\Database\Query\Builder + */ + protected function table() + { + return $this->getConnection()->table($this->table); + } + + /** + * Get the connection resolver instance. + * + * @return \Illuminate\Database\ConnectionResolverInterface + */ + public function getConnectionResolver() + { + return $this->resolver; + } + + /** + * Resolve the database connection instance. + * + * @return \Illuminate\Database\Connection + */ + public function getConnection() + { + return $this->resolver->connection($this->connection); + } + + /** + * Set the information source to gather data. + * + * @param string $name + * @return void + */ + public function setSource($name) + { + $this->connection = $name; + } + +} diff --git a/vendor/illuminate/database/Migrations/Migration.php b/vendor/illuminate/database/Migrations/Migration.php new file mode 100755 index 0000000..eb75d14 --- /dev/null +++ b/vendor/illuminate/database/Migrations/Migration.php @@ -0,0 +1,22 @@ +connection; + } + +} diff --git a/vendor/illuminate/database/Migrations/MigrationCreator.php b/vendor/illuminate/database/Migrations/MigrationCreator.php new file mode 100755 index 0000000..e70b627 --- /dev/null +++ b/vendor/illuminate/database/Migrations/MigrationCreator.php @@ -0,0 +1,183 @@ +files = $files; + } + + /** + * Create a new migration at the given path. + * + * @param string $name + * @param string $path + * @param string $table + * @param bool $create + * @return string + */ + public function create($name, $path, $table = null, $create = false) + { + $path = $this->getPath($name, $path); + + // First we will get the stub file for the migration, which serves as a type + // of template for the migration. Once we have those we will populate the + // various place-holders, save the file, and run the post create event. + $stub = $this->getStub($table, $create); + + $this->files->put($path, $this->populateStub($name, $stub, $table)); + + $this->firePostCreateHooks(); + + return $path; + } + + /** + * Get the migration stub file. + * + * @param string $table + * @param bool $create + * @return string + */ + protected function getStub($table, $create) + { + if (is_null($table)) + { + return $this->files->get($this->getStubPath().'/blank.stub'); + } + + // We also have stubs for creating new tables and modifying existing tables + // to save the developer some typing when they are creating a new tables + // or modifying existing tables. We'll grab the appropriate stub here. + else + { + $stub = $create ? 'create.stub' : 'update.stub'; + + return $this->files->get($this->getStubPath()."/{$stub}"); + } + } + + /** + * Populate the place-holders in the migration stub. + * + * @param string $name + * @param string $stub + * @param string $table + * @return string + */ + protected function populateStub($name, $stub, $table) + { + $stub = str_replace('{{class}}', $this->getClassName($name), $stub); + + // Here we will replace the table place-holders with the table specified by + // the developer, which is useful for quickly creating a tables creation + // or update migration from the console instead of typing it manually. + if ( ! is_null($table)) + { + $stub = str_replace('{{table}}', $table, $stub); + } + + return $stub; + } + + /** + * Get the class name of a migration name. + * + * @param string $name + * @return string + */ + protected function getClassName($name) + { + return studly_case($name); + } + + /** + * Fire the registered post create hooks. + * + * @return void + */ + protected function firePostCreateHooks() + { + foreach ($this->postCreate as $callback) + { + call_user_func($callback); + } + } + + /** + * Register a post migration create hook. + * + * @param \Closure $callback + * @return void + */ + public function afterCreate(Closure $callback) + { + $this->postCreate[] = $callback; + } + + /** + * Get the full path name to the migration. + * + * @param string $name + * @param string $path + * @return string + */ + protected function getPath($name, $path) + { + return $path.'/'.$this->getDatePrefix().'_'.$name.'.php'; + } + + /** + * Get the date prefix for the migration. + * + * @return string + */ + protected function getDatePrefix() + { + return date('Y_m_d_His'); + } + + /** + * Get the path to the stubs. + * + * @return string + */ + public function getStubPath() + { + return __DIR__.'/stubs'; + } + + /** + * Get the filesystem instance. + * + * @return \Illuminate\Filesystem\Filesystem + */ + public function getFilesystem() + { + return $this->files; + } + +} diff --git a/vendor/illuminate/database/Migrations/MigrationRepositoryInterface.php b/vendor/illuminate/database/Migrations/MigrationRepositoryInterface.php new file mode 100755 index 0000000..dfafa15 --- /dev/null +++ b/vendor/illuminate/database/Migrations/MigrationRepositoryInterface.php @@ -0,0 +1,65 @@ +files = $files; + $this->resolver = $resolver; + $this->repository = $repository; + } + + /** + * Run the outstanding migrations at a given path. + * + * @param string $path + * @param bool $pretend + * @return void + */ + public function run($path, $pretend = false) + { + $this->notes = array(); + + $files = $this->getMigrationFiles($path); + + // Once we grab all of the migration files for the path, we will compare them + // against the migrations that have already been run for this package then + // run each of the outstanding migrations against a database connection. + $ran = $this->repository->getRan(); + + $migrations = array_diff($files, $ran); + + $this->requireFiles($path, $migrations); + + $this->runMigrationList($migrations, $pretend); + } + + /** + * Run an array of migrations. + * + * @param array $migrations + * @param bool $pretend + * @return void + */ + public function runMigrationList($migrations, $pretend = false) + { + // First we will just make sure that there are any migrations to run. If there + // aren't, we will just make a note of it to the developer so they're aware + // that all of the migrations have been run against this database system. + if (count($migrations) == 0) + { + $this->note('Nothing to migrate.'); + + return; + } + + $batch = $this->repository->getNextBatchNumber(); + + // Once we have the array of migrations, we will spin through them and run the + // migrations "up" so the changes are made to the databases. We'll then log + // that the migration was run so we don't repeat it next time we execute. + foreach ($migrations as $file) + { + $this->runUp($file, $batch, $pretend); + } + } + + /** + * Run "up" a migration instance. + * + * @param string $file + * @param int $batch + * @param bool $pretend + * @return void + */ + protected function runUp($file, $batch, $pretend) + { + // First we will resolve a "real" instance of the migration class from this + // migration file name. Once we have the instances we can run the actual + // command such as "up" or "down", or we can just simulate the action. + $migration = $this->resolve($file); + + if ($pretend) + { + return $this->pretendToRun($migration, 'up'); + } + + $migration->up(); + + // Once we have run a migrations class, we will log that it was run in this + // repository so that we don't try to run it next time we do a migration + // in the application. A migration repository keeps the migrate order. + $this->repository->log($file, $batch); + + $this->note("Migrated: $file"); + } + + /** + * Rollback the last migration operation. + * + * @param bool $pretend + * @return int + */ + public function rollback($pretend = false) + { + $this->notes = array(); + + // We want to pull in the last batch of migrations that ran on the previous + // migration operation. We'll then reverse those migrations and run each + // of them "down" to reverse the last migration "operation" which ran. + $migrations = $this->repository->getLast(); + + if (count($migrations) == 0) + { + $this->note('Nothing to rollback.'); + + return count($migrations); + } + + // We need to reverse these migrations so that they are "downed" in reverse + // to what they run on "up". It lets us backtrack through the migrations + // and properly reverse the entire database schema operation that ran. + foreach ($migrations as $migration) + { + $this->runDown((object) $migration, $pretend); + } + + return count($migrations); + } + + /** + * Rolls all of the currently applied migrations back. + * + * @param bool $pretend + * @return int + */ + public function reset($pretend = false) + { + $this->notes = []; + + $migrations = array_reverse($this->repository->getRan()); + + if (count($migrations) == 0) + { + $this->note('Nothing to rollback.'); + + return count($migrations); + } + + foreach ($migrations as $migration) + { + $this->runDown((object) ['migration' => $migration], $pretend); + } + + return count($migrations); + } + + /** + * Run "down" a migration instance. + * + * @param object $migration + * @param bool $pretend + * @return void + */ + protected function runDown($migration, $pretend) + { + $file = $migration->migration; + + // First we will get the file name of the migration so we can resolve out an + // instance of the migration. Once we get an instance we can either run a + // pretend execution of the migration or we can run the real migration. + $instance = $this->resolve($file); + + if ($pretend) + { + return $this->pretendToRun($instance, 'down'); + } + + $instance->down(); + + // Once we have successfully run the migration "down" we will remove it from + // the migration repository so it will be considered to have not been run + // by the application then will be able to fire by any later operation. + $this->repository->delete($migration); + + $this->note("Rolled back: $file"); + } + + /** + * Get all of the migration files in a given path. + * + * @param string $path + * @return array + */ + public function getMigrationFiles($path) + { + $files = $this->files->glob($path.'/*_*.php'); + + // Once we have the array of files in the directory we will just remove the + // extension and take the basename of the file which is all we need when + // finding the migrations that haven't been run against the databases. + if ($files === false) return array(); + + $files = array_map(function($file) + { + return str_replace('.php', '', basename($file)); + + }, $files); + + // Once we have all of the formatted file names we will sort them and since + // they all start with a timestamp this should give us the migrations in + // the order they were actually created by the application developers. + sort($files); + + return $files; + } + + /** + * Require in all the migration files in a given path. + * + * @param string $path + * @param array $files + * @return void + */ + public function requireFiles($path, array $files) + { + foreach ($files as $file) $this->files->requireOnce($path.'/'.$file.'.php'); + } + + /** + * Pretend to run the migrations. + * + * @param object $migration + * @param string $method + * @return void + */ + protected function pretendToRun($migration, $method) + { + foreach ($this->getQueries($migration, $method) as $query) + { + $name = get_class($migration); + + $this->note("{$name}: {$query['query']}"); + } + } + + /** + * Get all of the queries that would be run for a migration. + * + * @param object $migration + * @param string $method + * @return array + */ + protected function getQueries($migration, $method) + { + $connection = $migration->getConnection(); + + // Now that we have the connections we can resolve it and pretend to run the + // queries against the database returning the array of raw SQL statements + // that would get fired against the database system for this migration. + $db = $this->resolveConnection($connection); + + return $db->pretend(function() use ($migration, $method) + { + $migration->$method(); + }); + } + + /** + * Resolve a migration instance from a file. + * + * @param string $file + * @return object + */ + public function resolve($file) + { + $file = implode('_', array_slice(explode('_', $file), 4)); + + $class = studly_case($file); + + return new $class; + } + + /** + * Raise a note event for the migrator. + * + * @param string $message + * @return void + */ + protected function note($message) + { + $this->notes[] = $message; + } + + /** + * Get the notes for the last operation. + * + * @return array + */ + public function getNotes() + { + return $this->notes; + } + + /** + * Resolve the database connection instance. + * + * @param string $connection + * @return \Illuminate\Database\Connection + */ + public function resolveConnection($connection) + { + return $this->resolver->connection($connection); + } + + /** + * Set the default connection name. + * + * @param string $name + * @return void + */ + public function setConnection($name) + { + if ( ! is_null($name)) + { + $this->resolver->setDefaultConnection($name); + } + + $this->repository->setSource($name); + + $this->connection = $name; + } + + /** + * Get the migration repository instance. + * + * @return \Illuminate\Database\Migrations\MigrationRepositoryInterface + */ + public function getRepository() + { + return $this->repository; + } + + /** + * Determine if the migration repository exists. + * + * @return bool + */ + public function repositoryExists() + { + return $this->repository->repositoryExists(); + } + + /** + * Get the file system instance. + * + * @return \Illuminate\Filesystem\Filesystem + */ + public function getFilesystem() + { + return $this->files; + } + +} diff --git a/vendor/illuminate/database/Migrations/stubs/blank.stub b/vendor/illuminate/database/Migrations/stubs/blank.stub new file mode 100755 index 0000000..a711201 --- /dev/null +++ b/vendor/illuminate/database/Migrations/stubs/blank.stub @@ -0,0 +1,28 @@ +increments('id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('{{table}}'); + } + +} diff --git a/vendor/illuminate/database/Migrations/stubs/update.stub b/vendor/illuminate/database/Migrations/stubs/update.stub new file mode 100755 index 0000000..cc2c904 --- /dev/null +++ b/vendor/illuminate/database/Migrations/stubs/update.stub @@ -0,0 +1,34 @@ +schemaGrammar)) { $this->useDefaultSchemaGrammar(); } + + return new MySqlBuilder($this); + } + + /** + * Get the default query grammar instance. + * + * @return \Illuminate\Database\Query\Grammars\MySqlGrammar + */ + protected function getDefaultQueryGrammar() + { + return $this->withTablePrefix(new QueryGrammar); + } + + /** + * Get the default schema grammar instance. + * + * @return \Illuminate\Database\Schema\Grammars\MySqlGrammar + */ + protected function getDefaultSchemaGrammar() + { + return $this->withTablePrefix(new SchemaGrammar); + } + + /** + * Get the default post processor instance. + * + * @return \Illuminate\Database\Query\Processors\Processor + */ + protected function getDefaultPostProcessor() + { + return new MySqlProcessor; + } + + /** + * Get the Doctrine DBAL driver. + * + * @return \Doctrine\DBAL\Driver\PDOMySql\Driver + */ + protected function getDoctrineDriver() + { + return new DoctrineDriver; + } + +} diff --git a/vendor/illuminate/database/PostgresConnection.php b/vendor/illuminate/database/PostgresConnection.php new file mode 100755 index 0000000..56b6c4e --- /dev/null +++ b/vendor/illuminate/database/PostgresConnection.php @@ -0,0 +1,50 @@ +withTablePrefix(new QueryGrammar); + } + + /** + * Get the default schema grammar instance. + * + * @return \Illuminate\Database\Schema\Grammars\PostgresGrammar + */ + protected function getDefaultSchemaGrammar() + { + return $this->withTablePrefix(new SchemaGrammar); + } + + /** + * Get the default post processor instance. + * + * @return \Illuminate\Database\Query\Processors\PostgresProcessor + */ + protected function getDefaultPostProcessor() + { + return new PostgresProcessor; + } + + /** + * Get the Doctrine DBAL driver. + * + * @return \Doctrine\DBAL\Driver\PDOPgSql\Driver + */ + protected function getDoctrineDriver() + { + return new DoctrineDriver; + } + +} diff --git a/vendor/illuminate/database/Query/Builder.php b/vendor/illuminate/database/Query/Builder.php new file mode 100755 index 0000000..06532fc --- /dev/null +++ b/vendor/illuminate/database/Query/Builder.php @@ -0,0 +1,1995 @@ + [], + 'join' => [], + 'where' => [], + 'having' => [], + 'order' => [], + ); + + /** + * An aggregate function and column to be run. + * + * @var array + */ + public $aggregate; + + /** + * The columns that should be returned. + * + * @var array + */ + public $columns; + + /** + * Indicates if the query returns distinct results. + * + * @var bool + */ + public $distinct = false; + + /** + * The table which the query is targeting. + * + * @var string + */ + public $from; + + /** + * The table joins for the query. + * + * @var array + */ + public $joins; + + /** + * The where constraints for the query. + * + * @var array + */ + public $wheres; + + /** + * The groupings for the query. + * + * @var array + */ + public $groups; + + /** + * The having constraints for the query. + * + * @var array + */ + public $havings; + + /** + * The orderings for the query. + * + * @var array + */ + public $orders; + + /** + * The maximum number of records to return. + * + * @var int + */ + public $limit; + + /** + * The number of records to skip. + * + * @var int + */ + public $offset; + + /** + * The query union statements. + * + * @var array + */ + public $unions; + + /** + * The maximum number of union records to return. + * + * @var int + */ + public $unionLimit; + + /** + * The number of union records to skip. + * + * @var int + */ + public $unionOffset; + + /** + * The orderings for the union query. + * + * @var array + */ + public $unionOrders; + + /** + * Indicates whether row locking is being used. + * + * @var string|bool + */ + public $lock; + + /** + * The field backups currently in use. + * + * @var array + */ + protected $backups = []; + + /** + * All of the available clause operators. + * + * @var array + */ + protected $operators = array( + '=', '<', '>', '<=', '>=', '<>', '!=', + 'like', 'like binary', 'not like', 'between', 'ilike', + '&', '|', '^', '<<', '>>', + 'rlike', 'regexp', 'not regexp', + '~', '~*', '!~', '!~*', 'similar to', + 'not similar to', + ); + + /** + * Whether use write pdo for select. + * + * @var bool + */ + protected $useWritePdo = false; + + /** + * Create a new query builder instance. + * + * @param \Illuminate\Database\ConnectionInterface $connection + * @param \Illuminate\Database\Query\Grammars\Grammar $grammar + * @param \Illuminate\Database\Query\Processors\Processor $processor + * @return void + */ + public function __construct(ConnectionInterface $connection, + Grammar $grammar, + Processor $processor) + { + $this->grammar = $grammar; + $this->processor = $processor; + $this->connection = $connection; + } + + /** + * Set the columns to be selected. + * + * @param array $columns + * @return $this + */ + public function select($columns = array('*')) + { + $this->columns = is_array($columns) ? $columns : func_get_args(); + + return $this; + } + + /** + * Add a new "raw" select expression to the query. + * + * @param string $expression + * @param array $bindings + * @return \Illuminate\Database\Query\Builder|static + */ + public function selectRaw($expression, array $bindings = array()) + { + $this->addSelect(new Expression($expression)); + + if ($bindings) + { + $this->addBinding($bindings, 'select'); + } + + return $this; + } + + /** + * Add a subselect expression to the query. + * + * @param \Closure|\Illuminate\Database\Query\Builder|string $query + * @param string $as + * @return \Illuminate\Database\Query\Builder|static + */ + public function selectSub($query, $as) + { + if ($query instanceof Closure) + { + $callback = $query; + + $callback($query = $this->newQuery()); + } + + if ($query instanceof Builder) + { + $bindings = $query->getBindings(); + + $query = $query->toSql(); + } + elseif (is_string($query)) + { + $bindings = []; + } + else + { + throw new InvalidArgumentException; + } + + return $this->selectRaw('('.$query.') as '.$this->grammar->wrap($as), $bindings); + } + + /** + * Add a new select column to the query. + * + * @param mixed $column + * @return $this + */ + public function addSelect($column) + { + $column = is_array($column) ? $column : func_get_args(); + + $this->columns = array_merge((array) $this->columns, $column); + + return $this; + } + + /** + * Force the query to only return distinct results. + * + * @return $this + */ + public function distinct() + { + $this->distinct = true; + + return $this; + } + + /** + * Set the table which the query is targeting. + * + * @param string $table + * @return $this + */ + public function from($table) + { + $this->from = $table; + + return $this; + } + + /** + * Add a join clause to the query. + * + * @param string $table + * @param string $one + * @param string $operator + * @param string $two + * @param string $type + * @param bool $where + * @return $this + */ + public function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false) + { + // If the first "column" of the join is really a Closure instance the developer + // is trying to build a join with a complex "on" clause containing more than + // one condition, so we'll add the join and call a Closure with the query. + if ($one instanceof Closure) + { + $this->joins[] = new JoinClause($type, $table); + + call_user_func($one, end($this->joins)); + } + + // If the column is simply a string, we can assume the join simply has a basic + // "on" clause with a single condition. So we will just build the join with + // this simple join clauses attached to it. There is not a join callback. + else + { + $join = new JoinClause($type, $table); + + $this->joins[] = $join->on( + $one, $operator, $two, 'and', $where + ); + } + + return $this; + } + + /** + * Add a "join where" clause to the query. + * + * @param string $table + * @param string $one + * @param string $operator + * @param string $two + * @param string $type + * @return \Illuminate\Database\Query\Builder|static + */ + public function joinWhere($table, $one, $operator, $two, $type = 'inner') + { + return $this->join($table, $one, $operator, $two, $type, true); + } + + /** + * Add a left join to the query. + * + * @param string $table + * @param string $first + * @param string $operator + * @param string $second + * @return \Illuminate\Database\Query\Builder|static + */ + public function leftJoin($table, $first, $operator = null, $second = null) + { + return $this->join($table, $first, $operator, $second, 'left'); + } + + /** + * Add a "join where" clause to the query. + * + * @param string $table + * @param string $one + * @param string $operator + * @param string $two + * @return \Illuminate\Database\Query\Builder|static + */ + public function leftJoinWhere($table, $one, $operator, $two) + { + return $this->joinWhere($table, $one, $operator, $two, 'left'); + } + + /** + * Add a right join to the query. + * + * @param string $table + * @param string $first + * @param string $operator + * @param string $second + * @return \Illuminate\Database\Query\Builder|static + */ + public function rightJoin($table, $first, $operator = null, $second = null) + { + return $this->join($table, $first, $operator, $second, 'right'); + } + + /** + * Add a "right join where" clause to the query. + * + * @param string $table + * @param string $one + * @param string $operator + * @param string $two + * @return \Illuminate\Database\Query\Builder|static + */ + public function rightJoinWhere($table, $one, $operator, $two) + { + return $this->joinWhere($table, $one, $operator, $two, 'right'); + } + + /** + * Add a basic where clause to the query. + * + * @param string|array|\Closure $column + * @param string $operator + * @param mixed $value + * @param string $boolean + * @return $this + * + * @throws \InvalidArgumentException + */ + public function where($column, $operator = null, $value = null, $boolean = 'and') + { + // If the column is an array, we will assume it is an array of key-value pairs + // and can add them each as a where clause. We will maintain the boolean we + // received when the method was called and pass it into the nested where. + if (is_array($column)) + { + return $this->whereNested(function($query) use ($column) + { + foreach ($column as $key => $value) + { + $query->where($key, '=', $value); + } + }, $boolean); + } + + // Here we will make some assumptions about the operator. If only 2 values are + // passed to the method, we will assume that the operator is an equals sign + // and keep going. Otherwise, we'll require the operator to be passed in. + if (func_num_args() == 2) + { + list($value, $operator) = array($operator, '='); + } + elseif ($this->invalidOperatorAndValue($operator, $value)) + { + throw new InvalidArgumentException("Illegal operator and value combination."); + } + + // If the columns is actually a Closure instance, we will assume the developer + // wants to begin a nested where statement which is wrapped in parenthesis. + // We'll add that Closure to the query then return back out immediately. + if ($column instanceof Closure) + { + return $this->whereNested($column, $boolean); + } + + // If the given operator is not found in the list of valid operators we will + // assume that the developer is just short-cutting the '=' operators and + // we will set the operators to '=' and set the values appropriately. + if ( ! in_array(strtolower($operator), $this->operators, true)) + { + list($value, $operator) = array($operator, '='); + } + + // If the value is a Closure, it means the developer is performing an entire + // sub-select within the query and we will need to compile the sub-select + // within the where clause to get the appropriate query record results. + if ($value instanceof Closure) + { + return $this->whereSub($column, $operator, $value, $boolean); + } + + // If the value is "null", we will just assume the developer wants to add a + // where null clause to the query. So, we will allow a short-cut here to + // that method for convenience so the developer doesn't have to check. + if (is_null($value)) + { + return $this->whereNull($column, $boolean, $operator != '='); + } + + // Now that we are working with just a simple query we can put the elements + // in our array and add the query binding to our array of bindings that + // will be bound to each SQL statements when it is finally executed. + $type = 'Basic'; + + $this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean'); + + if ( ! $value instanceof Expression) + { + $this->addBinding($value, 'where'); + } + + return $this; + } + + /** + * Add an "or where" clause to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhere($column, $operator = null, $value = null) + { + return $this->where($column, $operator, $value, 'or'); + } + + /** + * Determine if the given operator and value combination is legal. + * + * @param string $operator + * @param mixed $value + * @return bool + */ + protected function invalidOperatorAndValue($operator, $value) + { + $isOperator = in_array($operator, $this->operators); + + return $isOperator && $operator != '=' && is_null($value); + } + + /** + * Add a raw where clause to the query. + * + * @param string $sql + * @param array $bindings + * @param string $boolean + * @return $this + */ + public function whereRaw($sql, array $bindings = array(), $boolean = 'and') + { + $type = 'raw'; + + $this->wheres[] = compact('type', 'sql', 'boolean'); + + $this->addBinding($bindings, 'where'); + + return $this; + } + + /** + * Add a raw or where clause to the query. + * + * @param string $sql + * @param array $bindings + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereRaw($sql, array $bindings = array()) + { + return $this->whereRaw($sql, $bindings, 'or'); + } + + /** + * Add a where between statement to the query. + * + * @param string $column + * @param array $values + * @param string $boolean + * @param bool $not + * @return $this + */ + public function whereBetween($column, array $values, $boolean = 'and', $not = false) + { + $type = 'between'; + + $this->wheres[] = compact('column', 'type', 'boolean', 'not'); + + $this->addBinding($values, 'where'); + + return $this; + } + + /** + * Add an or where between statement to the query. + * + * @param string $column + * @param array $values + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereBetween($column, array $values) + { + return $this->whereBetween($column, $values, 'or'); + } + + /** + * Add a where not between statement to the query. + * + * @param string $column + * @param array $values + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereNotBetween($column, array $values, $boolean = 'and') + { + return $this->whereBetween($column, $values, $boolean, true); + } + + /** + * Add an or where not between statement to the query. + * + * @param string $column + * @param array $values + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereNotBetween($column, array $values) + { + return $this->whereNotBetween($column, $values, 'or'); + } + + /** + * Add a nested where statement to the query. + * + * @param \Closure $callback + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereNested(Closure $callback, $boolean = 'and') + { + // To handle nested queries we'll actually create a brand new query instance + // and pass it off to the Closure that we have. The Closure can simply do + // do whatever it wants to a query then we will store it for compiling. + $query = $this->newQuery(); + + $query->from($this->from); + + call_user_func($callback, $query); + + return $this->addNestedWhereQuery($query, $boolean); + } + + /** + * Add another query builder as a nested where to the query builder. + * + * @param \Illuminate\Database\Query\Builder|static $query + * @param string $boolean + * @return $this + */ + public function addNestedWhereQuery($query, $boolean = 'and') + { + if (count($query->wheres)) + { + $type = 'Nested'; + + $this->wheres[] = compact('type', 'query', 'boolean'); + + $this->mergeBindings($query); + } + + return $this; + } + + /** + * Add a full sub-select to the query. + * + * @param string $column + * @param string $operator + * @param \Closure $callback + * @param string $boolean + * @return $this + */ + protected function whereSub($column, $operator, Closure $callback, $boolean) + { + $type = 'Sub'; + + $query = $this->newQuery(); + + // Once we have the query instance we can simply execute it so it can add all + // of the sub-select's conditions to itself, and then we can cache it off + // in the array of where clauses for the "main" parent query instance. + call_user_func($callback, $query); + + $this->wheres[] = compact('type', 'column', 'operator', 'query', 'boolean'); + + $this->mergeBindings($query); + + return $this; + } + + /** + * Add an exists clause to the query. + * + * @param \Closure $callback + * @param string $boolean + * @param bool $not + * @return $this + */ + public function whereExists(Closure $callback, $boolean = 'and', $not = false) + { + $type = $not ? 'NotExists' : 'Exists'; + + $query = $this->newQuery(); + + // Similar to the sub-select clause, we will create a new query instance so + // the developer may cleanly specify the entire exists query and we will + // compile the whole thing in the grammar and insert it into the SQL. + call_user_func($callback, $query); + + $this->wheres[] = compact('type', 'operator', 'query', 'boolean'); + + $this->mergeBindings($query); + + return $this; + } + + /** + * Add an or exists clause to the query. + * + * @param \Closure $callback + * @param bool $not + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereExists(Closure $callback, $not = false) + { + return $this->whereExists($callback, 'or', $not); + } + + /** + * Add a where not exists clause to the query. + * + * @param \Closure $callback + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereNotExists(Closure $callback, $boolean = 'and') + { + return $this->whereExists($callback, $boolean, true); + } + + /** + * Add a where not exists clause to the query. + * + * @param \Closure $callback + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereNotExists(Closure $callback) + { + return $this->orWhereExists($callback, true); + } + + /** + * Add a "where in" clause to the query. + * + * @param string $column + * @param mixed $values + * @param string $boolean + * @param bool $not + * @return $this + */ + public function whereIn($column, $values, $boolean = 'and', $not = false) + { + $type = $not ? 'NotIn' : 'In'; + + // If the value of the where in clause is actually a Closure, we will assume that + // the developer is using a full sub-select for this "in" statement, and will + // execute those Closures, then we can re-construct the entire sub-selects. + if ($values instanceof Closure) + { + return $this->whereInSub($column, $values, $boolean, $not); + } + + $this->wheres[] = compact('type', 'column', 'values', 'boolean'); + + $this->addBinding($values, 'where'); + + return $this; + } + + /** + * Add an "or where in" clause to the query. + * + * @param string $column + * @param mixed $values + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereIn($column, $values) + { + return $this->whereIn($column, $values, 'or'); + } + + /** + * Add a "where not in" clause to the query. + * + * @param string $column + * @param mixed $values + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereNotIn($column, $values, $boolean = 'and') + { + return $this->whereIn($column, $values, $boolean, true); + } + + /** + * Add an "or where not in" clause to the query. + * + * @param string $column + * @param mixed $values + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereNotIn($column, $values) + { + return $this->whereNotIn($column, $values, 'or'); + } + + /** + * Add a where in with a sub-select to the query. + * + * @param string $column + * @param \Closure $callback + * @param string $boolean + * @param bool $not + * @return $this + */ + protected function whereInSub($column, Closure $callback, $boolean, $not) + { + $type = $not ? 'NotInSub' : 'InSub'; + + // To create the exists sub-select, we will actually create a query and call the + // provided callback with the query so the developer may set any of the query + // conditions they want for the in clause, then we'll put it in this array. + call_user_func($callback, $query = $this->newQuery()); + + $this->wheres[] = compact('type', 'column', 'query', 'boolean'); + + $this->mergeBindings($query); + + return $this; + } + + /** + * Add a "where null" clause to the query. + * + * @param string $column + * @param string $boolean + * @param bool $not + * @return $this + */ + public function whereNull($column, $boolean = 'and', $not = false) + { + $type = $not ? 'NotNull' : 'Null'; + + $this->wheres[] = compact('type', 'column', 'boolean'); + + return $this; + } + + /** + * Add an "or where null" clause to the query. + * + * @param string $column + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereNull($column) + { + return $this->whereNull($column, 'or'); + } + + /** + * Add a "where not null" clause to the query. + * + * @param string $column + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereNotNull($column, $boolean = 'and') + { + return $this->whereNull($column, $boolean, true); + } + + /** + * Add an "or where not null" clause to the query. + * + * @param string $column + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereNotNull($column) + { + return $this->whereNotNull($column, 'or'); + } + + /** + * Add a "where date" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereDate($column, $operator, $value, $boolean = 'and') + { + return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean); + } + + /** + * Add a "where day" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereDay($column, $operator, $value, $boolean = 'and') + { + return $this->addDateBasedWhere('Day', $column, $operator, $value, $boolean); + } + + /** + * Add a "where month" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereMonth($column, $operator, $value, $boolean = 'and') + { + return $this->addDateBasedWhere('Month', $column, $operator, $value, $boolean); + } + + /** + * Add a "where year" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereYear($column, $operator, $value, $boolean = 'and') + { + return $this->addDateBasedWhere('Year', $column, $operator, $value, $boolean); + } + + /** + * Add a date based (year, month, day) statement to the query. + * + * @param string $type + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return $this + */ + protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and') + { + $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value'); + + $this->addBinding($value, 'where'); + + return $this; + } + + /** + * Handles dynamic "where" clauses to the query. + * + * @param string $method + * @param string $parameters + * @return $this + */ + public function dynamicWhere($method, $parameters) + { + $finder = substr($method, 5); + + $segments = preg_split('/(And|Or)(?=[A-Z])/', $finder, -1, PREG_SPLIT_DELIM_CAPTURE); + + // The connector variable will determine which connector will be used for the + // query condition. We will change it as we come across new boolean values + // in the dynamic method strings, which could contain a number of these. + $connector = 'and'; + + $index = 0; + + foreach ($segments as $segment) + { + // If the segment is not a boolean connector, we can assume it is a column's name + // and we will add it to the query as a new constraint as a where clause, then + // we can keep iterating through the dynamic method string's segments again. + if ($segment != 'And' && $segment != 'Or') + { + $this->addDynamic($segment, $connector, $parameters, $index); + + $index++; + } + + // Otherwise, we will store the connector so we know how the next where clause we + // find in the query should be connected to the previous ones, meaning we will + // have the proper boolean connector to connect the next where clause found. + else + { + $connector = $segment; + } + } + + return $this; + } + + /** + * Add a single dynamic where clause statement to the query. + * + * @param string $segment + * @param string $connector + * @param array $parameters + * @param int $index + * @return void + */ + protected function addDynamic($segment, $connector, $parameters, $index) + { + // Once we have parsed out the columns and formatted the boolean operators we + // are ready to add it to this query as a where clause just like any other + // clause on the query. Then we'll increment the parameter index values. + $bool = strtolower($connector); + + $this->where(snake_case($segment), '=', $parameters[$index], $bool); + } + + /** + * Add a "group by" clause to the query. + * + * @param array|string $column,... + * @return $this + */ + public function groupBy() + { + foreach (func_get_args() as $arg) + { + $this->groups = array_merge((array) $this->groups, is_array($arg) ? $arg : [$arg]); + } + + return $this; + } + + /** + * Add a "having" clause to the query. + * + * @param string $column + * @param string $operator + * @param string $value + * @param string $boolean + * @return $this + */ + public function having($column, $operator = null, $value = null, $boolean = 'and') + { + $type = 'basic'; + + $this->havings[] = compact('type', 'column', 'operator', 'value', 'boolean'); + + if ( ! $value instanceof Expression) + { + $this->addBinding($value, 'having'); + } + + return $this; + } + + /** + * Add a "or having" clause to the query. + * + * @param string $column + * @param string $operator + * @param string $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orHaving($column, $operator = null, $value = null) + { + return $this->having($column, $operator, $value, 'or'); + } + + /** + * Add a raw having clause to the query. + * + * @param string $sql + * @param array $bindings + * @param string $boolean + * @return $this + */ + public function havingRaw($sql, array $bindings = array(), $boolean = 'and') + { + $type = 'raw'; + + $this->havings[] = compact('type', 'sql', 'boolean'); + + $this->addBinding($bindings, 'having'); + + return $this; + } + + /** + * Add a raw or having clause to the query. + * + * @param string $sql + * @param array $bindings + * @return \Illuminate\Database\Query\Builder|static + */ + public function orHavingRaw($sql, array $bindings = array()) + { + return $this->havingRaw($sql, $bindings, 'or'); + } + + /** + * Add an "order by" clause to the query. + * + * @param string $column + * @param string $direction + * @return $this + */ + public function orderBy($column, $direction = 'asc') + { + $property = $this->unions ? 'unionOrders' : 'orders'; + $direction = strtolower($direction) == 'asc' ? 'asc' : 'desc'; + + $this->{$property}[] = compact('column', 'direction'); + + return $this; + } + + /** + * Add an "order by" clause for a timestamp to the query. + * + * @param string $column + * @return \Illuminate\Database\Query\Builder|static + */ + public function latest($column = 'created_at') + { + return $this->orderBy($column, 'desc'); + } + + /** + * Add an "order by" clause for a timestamp to the query. + * + * @param string $column + * @return \Illuminate\Database\Query\Builder|static + */ + public function oldest($column = 'created_at') + { + return $this->orderBy($column, 'asc'); + } + + /** + * Add a raw "order by" clause to the query. + * + * @param string $sql + * @param array $bindings + * @return $this + */ + public function orderByRaw($sql, $bindings = array()) + { + $type = 'raw'; + + $this->orders[] = compact('type', 'sql'); + + $this->addBinding($bindings, 'order'); + + return $this; + } + + /** + * Set the "offset" value of the query. + * + * @param int $value + * @return $this + */ + public function offset($value) + { + $property = $this->unions ? 'unionOffset' : 'offset'; + + $this->$property = max(0, $value); + + return $this; + } + + /** + * Alias to set the "offset" value of the query. + * + * @param int $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function skip($value) + { + return $this->offset($value); + } + + /** + * Set the "limit" value of the query. + * + * @param int $value + * @return $this + */ + public function limit($value) + { + $property = $this->unions ? 'unionLimit' : 'limit'; + + if ($value > 0) $this->$property = $value; + + return $this; + } + + /** + * Alias to set the "limit" value of the query. + * + * @param int $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function take($value) + { + return $this->limit($value); + } + + /** + * Set the limit and offset for a given page. + * + * @param int $page + * @param int $perPage + * @return \Illuminate\Database\Query\Builder|static + */ + public function forPage($page, $perPage = 15) + { + return $this->skip(($page - 1) * $perPage)->take($perPage); + } + + /** + * Add a union statement to the query. + * + * @param \Illuminate\Database\Query\Builder|\Closure $query + * @param bool $all + * @return \Illuminate\Database\Query\Builder|static + */ + public function union($query, $all = false) + { + if ($query instanceof Closure) + { + call_user_func($query, $query = $this->newQuery()); + } + + $this->unions[] = compact('query', 'all'); + + return $this->mergeBindings($query); + } + + /** + * Add a union all statement to the query. + * + * @param \Illuminate\Database\Query\Builder|\Closure $query + * @return \Illuminate\Database\Query\Builder|static + */ + public function unionAll($query) + { + return $this->union($query, true); + } + + /** + * Lock the selected rows in the table. + * + * @param bool $value + * @return $this + */ + public function lock($value = true) + { + $this->lock = $value; + + return $this; + } + + /** + * Lock the selected rows in the table for updating. + * + * @return \Illuminate\Database\Query\Builder + */ + public function lockForUpdate() + { + return $this->lock(true); + } + + /** + * Share lock the selected rows in the table. + * + * @return \Illuminate\Database\Query\Builder + */ + public function sharedLock() + { + return $this->lock(false); + } + + /** + * Get the SQL representation of the query. + * + * @return string + */ + public function toSql() + { + return $this->grammar->compileSelect($this); + } + + /** + * Execute a query for a single record by ID. + * + * @param int $id + * @param array $columns + * @return mixed|static + */ + public function find($id, $columns = array('*')) + { + return $this->where('id', '=', $id)->first($columns); + } + + /** + * Pluck a single column's value from the first result of a query. + * + * @param string $column + * @return mixed + */ + public function pluck($column) + { + $result = (array) $this->first(array($column)); + + return count($result) > 0 ? reset($result) : null; + } + + /** + * Execute the query and get the first result. + * + * @param array $columns + * @return mixed|static + */ + public function first($columns = array('*')) + { + $results = $this->take(1)->get($columns); + + return count($results) > 0 ? reset($results) : null; + } + + /** + * Execute the query as a "select" statement. + * + * @param array $columns + * @return array|static[] + */ + public function get($columns = array('*')) + { + return $this->getFresh($columns); + } + + /** + * Execute the query as a fresh "select" statement. + * + * @param array $columns + * @return array|static[] + */ + public function getFresh($columns = array('*')) + { + if (is_null($this->columns)) $this->columns = $columns; + + return $this->processor->processSelect($this, $this->runSelect()); + } + + /** + * Run the query as a "select" statement against the connection. + * + * @return array + */ + protected function runSelect() + { + return $this->connection->select($this->toSql(), $this->getBindings(), ! $this->useWritePdo); + } + + /** + * Paginate the given query into a simple paginator. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + */ + public function paginate($perPage = 15, $columns = ['*']) + { + $page = Paginator::resolveCurrentPage(); + + $total = $this->getCountForPagination(); + + $results = $this->forPage($page, $perPage)->get($columns); + + return new LengthAwarePaginator($results, $total, $perPage, $page, [ + 'path' => Paginator::resolveCurrentPath(), + ]); + } + + /** + * Get a paginator only supporting simple next and previous links. + * + * This is more efficient on larger data-sets, etc. + * + * @param int $perPage + * @param array $columns + * @return \Illuminate\Contracts\Pagination\Paginator + */ + public function simplePaginate($perPage = 15, $columns = ['*']) + { + $page = Paginator::resolveCurrentPage(); + + $this->skip(($page - 1) * $perPage)->take($perPage + 1); + + return new Paginator($this->get($columns), $perPage, $page, [ + 'path' => Paginator::resolveCurrentPath(), + ]); + } + + /** + * Get the count of the total records for the paginator. + * + * @return int + */ + public function getCountForPagination() + { + $this->backupFieldsForCount(); + + $total = $this->count(); + + $this->restoreFieldsForCount(); + + return $total; + } + + /** + * Backup some fields for the pagination count. + * + * @return void + */ + protected function backupFieldsForCount() + { + foreach (['orders', 'limit', 'offset'] as $field) + { + $this->backups[$field] = $this->{$field}; + + $this->{$field} = null; + } + } + + /** + * Restore some fields after the pagination count. + * + * @return void + */ + protected function restoreFieldsForCount() + { + foreach (['orders', 'limit', 'offset'] as $field) + { + $this->{$field} = $this->backups[$field]; + } + + $this->backups = []; + } + + /** + * Chunk the results of the query. + * + * @param int $count + * @param callable $callback + * @return void + */ + public function chunk($count, callable $callback) + { + $results = $this->forPage($page = 1, $count)->get(); + + while (count($results) > 0) + { + // On each chunk result set, we will pass them to the callback and then let the + // developer take care of everything within the callback, which allows us to + // keep the memory low for spinning through large result sets for working. + if (call_user_func($callback, $results) === false) + { + break; + } + + $page++; + + $results = $this->forPage($page, $count)->get(); + } + } + + /** + * Get an array with the values of a given column. + * + * @param string $column + * @param string $key + * @return array + */ + public function lists($column, $key = null) + { + $columns = $this->getListSelect($column, $key); + + $results = new Collection($this->get($columns)); + + return $results->lists($columns[0], array_get($columns, 1)); + } + + /** + * Get the columns that should be used in a list array. + * + * @param string $column + * @param string $key + * @return array + */ + protected function getListSelect($column, $key) + { + $select = is_null($key) ? array($column) : array($column, $key); + + // If the selected column contains a "dot", we will remove it so that the list + // operation can run normally. Specifying the table is not needed, since we + // really want the names of the columns as it is in this resulting array. + return array_map(function($column) + { + $dot = strpos($column, '.'); + + return $dot === false ? $column : substr($column, $dot + 1); + }, $select); + } + + /** + * Concatenate values of a given column as a string. + * + * @param string $column + * @param string $glue + * @return string + */ + public function implode($column, $glue = null) + { + if (is_null($glue)) return implode($this->lists($column)); + + return implode($glue, $this->lists($column)); + } + + /** + * Determine if any rows exist for the current query. + * + * @return bool + */ + public function exists() + { + $limit = $this->limit; + + $result = $this->limit(1)->count() > 0; + + $this->limit($limit); + + return $result; + } + + /** + * Retrieve the "count" result of the query. + * + * @param string $columns + * @return int + */ + public function count($columns = '*') + { + if ( ! is_array($columns)) + { + $columns = array($columns); + } + + return (int) $this->aggregate(__FUNCTION__, $columns); + } + + /** + * Retrieve the minimum value of a given column. + * + * @param string $column + * @return float|int + */ + public function min($column) + { + return $this->aggregate(__FUNCTION__, array($column)); + } + + /** + * Retrieve the maximum value of a given column. + * + * @param string $column + * @return float|int + */ + public function max($column) + { + return $this->aggregate(__FUNCTION__, array($column)); + } + + /** + * Retrieve the sum of the values of a given column. + * + * @param string $column + * @return float|int + */ + public function sum($column) + { + $result = $this->aggregate(__FUNCTION__, array($column)); + + return $result ?: 0; + } + + /** + * Retrieve the average of the values of a given column. + * + * @param string $column + * @return float|int + */ + public function avg($column) + { + return $this->aggregate(__FUNCTION__, array($column)); + } + + /** + * Execute an aggregate function on the database. + * + * @param string $function + * @param array $columns + * @return float|int + */ + public function aggregate($function, $columns = array('*')) + { + $this->aggregate = compact('function', 'columns'); + + $previousColumns = $this->columns; + + $results = $this->get($columns); + + // Once we have executed the query, we will reset the aggregate property so + // that more select queries can be executed against the database without + // the aggregate value getting in the way when the grammar builds it. + $this->aggregate = null; + + $this->columns = $previousColumns; + + if (isset($results[0])) + { + $result = array_change_key_case((array) $results[0]); + + return $result['aggregate']; + } + } + + /** + * Insert a new record into the database. + * + * @param array $values + * @return bool + */ + public function insert(array $values) + { + if (empty($values)) return true; + + // Since every insert gets treated like a batch insert, we will make sure the + // bindings are structured in a way that is convenient for building these + // inserts statements by verifying the elements are actually an array. + if ( ! is_array(reset($values))) + { + $values = array($values); + } + + // Since every insert gets treated like a batch insert, we will make sure the + // bindings are structured in a way that is convenient for building these + // inserts statements by verifying the elements are actually an array. + else + { + foreach ($values as $key => $value) + { + ksort($value); $values[$key] = $value; + } + } + + // We'll treat every insert like a batch insert so we can easily insert each + // of the records into the database consistently. This will make it much + // easier on the grammars to just handle one type of record insertion. + $bindings = array(); + + foreach ($values as $record) + { + foreach ($record as $value) + { + $bindings[] = $value; + } + } + + $sql = $this->grammar->compileInsert($this, $values); + + // Once we have compiled the insert statement's SQL we can execute it on the + // connection and return a result as a boolean success indicator as that + // is the same type of result returned by the raw connection instance. + $bindings = $this->cleanBindings($bindings); + + return $this->connection->insert($sql, $bindings); + } + + /** + * Insert a new record and get the value of the primary key. + * + * @param array $values + * @param string $sequence + * @return int + */ + public function insertGetId(array $values, $sequence = null) + { + $sql = $this->grammar->compileInsertGetId($this, $values, $sequence); + + $values = $this->cleanBindings($values); + + return $this->processor->processInsertGetId($this, $sql, $values, $sequence); + } + + /** + * Update a record in the database. + * + * @param array $values + * @return int + */ + public function update(array $values) + { + $bindings = array_values(array_merge($values, $this->getBindings())); + + $sql = $this->grammar->compileUpdate($this, $values); + + return $this->connection->update($sql, $this->cleanBindings($bindings)); + } + + /** + * Increment a column's value by a given amount. + * + * @param string $column + * @param int $amount + * @param array $extra + * @return int + */ + public function increment($column, $amount = 1, array $extra = array()) + { + $wrapped = $this->grammar->wrap($column); + + $columns = array_merge(array($column => $this->raw("$wrapped + $amount")), $extra); + + return $this->update($columns); + } + + /** + * Decrement a column's value by a given amount. + * + * @param string $column + * @param int $amount + * @param array $extra + * @return int + */ + public function decrement($column, $amount = 1, array $extra = array()) + { + $wrapped = $this->grammar->wrap($column); + + $columns = array_merge(array($column => $this->raw("$wrapped - $amount")), $extra); + + return $this->update($columns); + } + + /** + * Delete a record from the database. + * + * @param mixed $id + * @return int + */ + public function delete($id = null) + { + // If an ID is passed to the method, we will set the where clause to check + // the ID to allow developers to simply and quickly remove a single row + // from their database without manually specifying the where clauses. + if ( ! is_null($id)) $this->where('id', '=', $id); + + $sql = $this->grammar->compileDelete($this); + + return $this->connection->delete($sql, $this->getBindings()); + } + + /** + * Run a truncate statement on the table. + * + * @return void + */ + public function truncate() + { + foreach ($this->grammar->compileTruncate($this) as $sql => $bindings) + { + $this->connection->statement($sql, $bindings); + } + } + + /** + * Get a new instance of the query builder. + * + * @return \Illuminate\Database\Query\Builder + */ + public function newQuery() + { + return new Builder($this->connection, $this->grammar, $this->processor); + } + + /** + * Merge an array of where clauses and bindings. + * + * @param array $wheres + * @param array $bindings + * @return void + */ + public function mergeWheres($wheres, $bindings) + { + $this->wheres = array_merge((array) $this->wheres, (array) $wheres); + + $this->bindings['where'] = array_values(array_merge($this->bindings['where'], (array) $bindings)); + } + + /** + * Remove all of the expressions from a list of bindings. + * + * @param array $bindings + * @return array + */ + protected function cleanBindings(array $bindings) + { + return array_values(array_filter($bindings, function($binding) + { + return ! $binding instanceof Expression; + })); + } + + /** + * Create a raw database expression. + * + * @param mixed $value + * @return \Illuminate\Database\Query\Expression + */ + public function raw($value) + { + return $this->connection->raw($value); + } + + /** + * Get the current query value bindings in a flattened array. + * + * @return array + */ + public function getBindings() + { + return array_flatten($this->bindings); + } + + /** + * Get the raw array of bindings. + * + * @return array + */ + public function getRawBindings() + { + return $this->bindings; + } + + /** + * Set the bindings on the query builder. + * + * @param array $bindings + * @param string $type + * @return $this + * + * @throws \InvalidArgumentException + */ + public function setBindings(array $bindings, $type = 'where') + { + if ( ! array_key_exists($type, $this->bindings)) + { + throw new InvalidArgumentException("Invalid binding type: {$type}."); + } + + $this->bindings[$type] = $bindings; + + return $this; + } + + /** + * Add a binding to the query. + * + * @param mixed $value + * @param string $type + * @return $this + * + * @throws \InvalidArgumentException + */ + public function addBinding($value, $type = 'where') + { + if ( ! array_key_exists($type, $this->bindings)) + { + throw new InvalidArgumentException("Invalid binding type: {$type}."); + } + + if (is_array($value)) + { + $this->bindings[$type] = array_values(array_merge($this->bindings[$type], $value)); + } + else + { + $this->bindings[$type][] = $value; + } + + return $this; + } + + /** + * Merge an array of bindings into our bindings. + * + * @param \Illuminate\Database\Query\Builder $query + * @return $this + */ + public function mergeBindings(Builder $query) + { + $this->bindings = array_merge_recursive($this->bindings, $query->bindings); + + return $this; + } + + /** + * Get the database connection instance. + * + * @return \Illuminate\Database\ConnectionInterface + */ + public function getConnection() + { + return $this->connection; + } + + /** + * Get the database query processor instance. + * + * @return \Illuminate\Database\Query\Processors\Processor + */ + public function getProcessor() + { + return $this->processor; + } + + /** + * Get the query grammar instance. + * + * @return \Illuminate\Database\Grammar + */ + public function getGrammar() + { + return $this->grammar; + } + + /** + * Use the write pdo for query. + * + * @return $this + */ + public function useWritePdo() + { + $this->useWritePdo = true; + + return $this; + } + + /** + * Handle dynamic method calls into the method. + * + * @param string $method + * @param array $parameters + * @return mixed + * + * @throws \BadMethodCallException + */ + public function __call($method, $parameters) + { + if (starts_with($method, 'where')) + { + return $this->dynamicWhere($method, $parameters); + } + + $className = get_class($this); + + throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); + } + +} diff --git a/vendor/illuminate/database/Query/Expression.php b/vendor/illuminate/database/Query/Expression.php new file mode 100755 index 0000000..68d2236 --- /dev/null +++ b/vendor/illuminate/database/Query/Expression.php @@ -0,0 +1,43 @@ +value = $value; + } + + /** + * Get the value of the expression. + * + * @return mixed + */ + public function getValue() + { + return $this->value; + } + + /** + * Get the value of the expression. + * + * @return string + */ + public function __toString() + { + return (string) $this->getValue(); + } + +} diff --git a/vendor/illuminate/database/Query/Grammars/Grammar.php b/vendor/illuminate/database/Query/Grammars/Grammar.php new file mode 100755 index 0000000..cefdbfc --- /dev/null +++ b/vendor/illuminate/database/Query/Grammars/Grammar.php @@ -0,0 +1,758 @@ +columns)) $query->columns = array('*'); + + return trim($this->concatenate($this->compileComponents($query))); + } + + /** + * Compile the components necessary for a select clause. + * + * @param \Illuminate\Database\Query\Builder + * @return array + */ + protected function compileComponents(Builder $query) + { + $sql = array(); + + foreach ($this->selectComponents as $component) + { + // To compile the query, we'll spin through each component of the query and + // see if that component exists. If it does we'll just call the compiler + // function for the component which is responsible for making the SQL. + if ( ! is_null($query->$component)) + { + $method = 'compile'.ucfirst($component); + + $sql[$component] = $this->$method($query, $query->$component); + } + } + + return $sql; + } + + /** + * Compile an aggregated select clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $aggregate + * @return string + */ + protected function compileAggregate(Builder $query, $aggregate) + { + $column = $this->columnize($aggregate['columns']); + + // If the query has a "distinct" constraint and we're not asking for all columns + // we need to prepend "distinct" onto the column name so that the query takes + // it into account when it performs the aggregating operations on the data. + if ($query->distinct && $column !== '*') + { + $column = 'distinct '.$column; + } + + return 'select '.$aggregate['function'].'('.$column.') as aggregate'; + } + + /** + * Compile the "select *" portion of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $columns + * @return string + */ + protected function compileColumns(Builder $query, $columns) + { + // If the query is actually performing an aggregating select, we will let that + // compiler handle the building of the select clauses, as it will need some + // more syntax that is best handled by that function to keep things neat. + if ( ! is_null($query->aggregate)) return; + + $select = $query->distinct ? 'select distinct ' : 'select '; + + return $select.$this->columnize($columns); + } + + /** + * Compile the "from" portion of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param string $table + * @return string + */ + protected function compileFrom(Builder $query, $table) + { + return 'from '.$this->wrapTable($table); + } + + /** + * Compile the "join" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $joins + * @return string + */ + protected function compileJoins(Builder $query, $joins) + { + $sql = array(); + + $query->setBindings(array(), 'join'); + + foreach ($joins as $join) + { + $table = $this->wrapTable($join->table); + + // First we need to build all of the "on" clauses for the join. There may be many + // of these clauses so we will need to iterate through each one and build them + // separately, then we'll join them up into a single string when we're done. + $clauses = array(); + + foreach ($join->clauses as $clause) + { + $clauses[] = $this->compileJoinConstraint($clause); + } + + foreach ($join->bindings as $binding) + { + $query->addBinding($binding, 'join'); + } + + // Once we have constructed the clauses, we'll need to take the boolean connector + // off of the first clause as it obviously will not be required on that clause + // because it leads the rest of the clauses, thus not requiring any boolean. + $clauses[0] = $this->removeLeadingBoolean($clauses[0]); + + $clauses = implode(' ', $clauses); + + $type = $join->type; + + // Once we have everything ready to go, we will just concatenate all the parts to + // build the final join statement SQL for the query and we can then return the + // final clause back to the callers as a single, stringified join statement. + $sql[] = "$type join $table on $clauses"; + } + + return implode(' ', $sql); + } + + /** + * Create a join clause constraint segment. + * + * @param array $clause + * @return string + */ + protected function compileJoinConstraint(array $clause) + { + $first = $this->wrap($clause['first']); + + $second = $clause['where'] ? '?' : $this->wrap($clause['second']); + + return "{$clause['boolean']} $first {$clause['operator']} $second"; + } + + /** + * Compile the "where" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + protected function compileWheres(Builder $query) + { + $sql = array(); + + if (is_null($query->wheres)) return ''; + + // Each type of where clauses has its own compiler function which is responsible + // for actually creating the where clauses SQL. This helps keep the code nice + // and maintainable since each clause has a very small method that it uses. + foreach ($query->wheres as $where) + { + $method = "where{$where['type']}"; + + $sql[] = $where['boolean'].' '.$this->$method($query, $where); + } + + // If we actually have some where clauses, we will strip off the first boolean + // operator, which is added by the query builders for convenience so we can + // avoid checking for the first clauses in each of the compilers methods. + if (count($sql) > 0) + { + $sql = implode(' ', $sql); + + return 'where '.$this->removeLeadingBoolean($sql); + } + + return ''; + } + + /** + * Compile a nested where clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereNested(Builder $query, $where) + { + $nested = $where['query']; + + return '('.substr($this->compileWheres($nested), 6).')'; + } + + /** + * Compile a where condition with a sub-select. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereSub(Builder $query, $where) + { + $select = $this->compileSelect($where['query']); + + return $this->wrap($where['column']).' '.$where['operator']." ($select)"; + } + + /** + * Compile a basic where clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereBasic(Builder $query, $where) + { + $value = $this->parameter($where['value']); + + return $this->wrap($where['column']).' '.$where['operator'].' '.$value; + } + + /** + * Compile a "between" where clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereBetween(Builder $query, $where) + { + $between = $where['not'] ? 'not between' : 'between'; + + return $this->wrap($where['column']).' '.$between.' ? and ?'; + } + + /** + * Compile a where exists clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereExists(Builder $query, $where) + { + return 'exists ('.$this->compileSelect($where['query']).')'; + } + + /** + * Compile a where exists clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereNotExists(Builder $query, $where) + { + return 'not exists ('.$this->compileSelect($where['query']).')'; + } + + /** + * Compile a "where in" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereIn(Builder $query, $where) + { + if (empty($where['values'])) return '0 = 1'; + + $values = $this->parameterize($where['values']); + + return $this->wrap($where['column']).' in ('.$values.')'; + } + + /** + * Compile a "where not in" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereNotIn(Builder $query, $where) + { + if (empty($where['values'])) return '1 = 1'; + + $values = $this->parameterize($where['values']); + + return $this->wrap($where['column']).' not in ('.$values.')'; + } + + /** + * Compile a where in sub-select clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereInSub(Builder $query, $where) + { + $select = $this->compileSelect($where['query']); + + return $this->wrap($where['column']).' in ('.$select.')'; + } + + /** + * Compile a where not in sub-select clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereNotInSub(Builder $query, $where) + { + $select = $this->compileSelect($where['query']); + + return $this->wrap($where['column']).' not in ('.$select.')'; + } + + /** + * Compile a "where null" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereNull(Builder $query, $where) + { + return $this->wrap($where['column']).' is null'; + } + + /** + * Compile a "where not null" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereNotNull(Builder $query, $where) + { + return $this->wrap($where['column']).' is not null'; + } + + /** + * Compile a "where date" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDate(Builder $query, $where) + { + return $this->dateBasedWhere('date', $query, $where); + } + + /** + * Compile a "where day" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDay(Builder $query, $where) + { + return $this->dateBasedWhere('day', $query, $where); + } + + /** + * Compile a "where month" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereMonth(Builder $query, $where) + { + return $this->dateBasedWhere('month', $query, $where); + } + + /** + * Compile a "where year" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereYear(Builder $query, $where) + { + return $this->dateBasedWhere('year', $query, $where); + } + + /** + * Compile a date based where clause. + * + * @param string $type + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function dateBasedWhere($type, Builder $query, $where) + { + $value = $this->parameter($where['value']); + + return $type.'('.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + + /** + * Compile a raw where clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereRaw(Builder $query, $where) + { + return $where['sql']; + } + + /** + * Compile the "group by" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $groups + * @return string + */ + protected function compileGroups(Builder $query, $groups) + { + return 'group by '.$this->columnize($groups); + } + + /** + * Compile the "having" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $havings + * @return string + */ + protected function compileHavings(Builder $query, $havings) + { + $sql = implode(' ', array_map(array($this, 'compileHaving'), $havings)); + + return 'having '.$this->removeLeadingBoolean($sql); + } + + /** + * Compile a single having clause. + * + * @param array $having + * @return string + */ + protected function compileHaving(array $having) + { + // If the having clause is "raw", we can just return the clause straight away + // without doing any more processing on it. Otherwise, we will compile the + // clause into SQL based on the components that make it up from builder. + if ($having['type'] === 'raw') + { + return $having['boolean'].' '.$having['sql']; + } + + return $this->compileBasicHaving($having); + } + + /** + * Compile a basic having clause. + * + * @param array $having + * @return string + */ + protected function compileBasicHaving($having) + { + $column = $this->wrap($having['column']); + + $parameter = $this->parameter($having['value']); + + return $having['boolean'].' '.$column.' '.$having['operator'].' '.$parameter; + } + + /** + * Compile the "order by" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $orders + * @return string + */ + protected function compileOrders(Builder $query, $orders) + { + return 'order by '.implode(', ', array_map(function($order) + { + if (isset($order['sql'])) return $order['sql']; + + return $this->wrap($order['column']).' '.$order['direction']; + }, $orders)); + } + + /** + * Compile the "limit" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $limit + * @return string + */ + protected function compileLimit(Builder $query, $limit) + { + return 'limit '.(int) $limit; + } + + /** + * Compile the "offset" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $offset + * @return string + */ + protected function compileOffset(Builder $query, $offset) + { + return 'offset '.(int) $offset; + } + + /** + * Compile the "union" queries attached to the main query. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + protected function compileUnions(Builder $query) + { + $sql = ''; + + foreach ($query->unions as $union) + { + $sql .= $this->compileUnion($union); + } + + if (isset($query->unionOrders)) + { + $sql .= ' '.$this->compileOrders($query, $query->unionOrders); + } + + if (isset($query->unionLimit)) + { + $sql .= ' '.$this->compileLimit($query, $query->unionLimit); + } + + if (isset($query->unionOffset)) + { + $sql .= ' '.$this->compileOffset($query, $query->unionOffset); + } + + return ltrim($sql); + } + + /** + * Compile a single union statement. + * + * @param array $union + * @return string + */ + protected function compileUnion(array $union) + { + $joiner = $union['all'] ? ' union all ' : ' union '; + + return $joiner.$union['query']->toSql(); + } + + /** + * Compile an insert statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @return string + */ + public function compileInsert(Builder $query, array $values) + { + // Essentially we will force every insert to be treated as a batch insert which + // simply makes creating the SQL easier for us since we can utilize the same + // basic routine regardless of an amount of records given to us to insert. + $table = $this->wrapTable($query->from); + + if ( ! is_array(reset($values))) + { + $values = array($values); + } + + $columns = $this->columnize(array_keys(reset($values))); + + // We need to build a list of parameter place-holders of values that are bound + // to the query. Each insert should have the exact same amount of parameter + // bindings so we can just go off the first list of values in this array. + $parameters = $this->parameterize(reset($values)); + + $value = array_fill(0, count($values), "($parameters)"); + + $parameters = implode(', ', $value); + + return "insert into $table ($columns) values $parameters"; + } + + /** + * Compile an insert and get ID statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @param string $sequence + * @return string + */ + public function compileInsertGetId(Builder $query, $values, $sequence) + { + return $this->compileInsert($query, $values); + } + + /** + * Compile an update statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @return string + */ + public function compileUpdate(Builder $query, $values) + { + $table = $this->wrapTable($query->from); + + // Each one of the columns in the update statements needs to be wrapped in the + // keyword identifiers, also a place-holder needs to be created for each of + // the values in the list of bindings so we can make the sets statements. + $columns = array(); + + foreach ($values as $key => $value) + { + $columns[] = $this->wrap($key).' = '.$this->parameter($value); + } + + $columns = implode(', ', $columns); + + // If the query has any "join" clauses, we will setup the joins on the builder + // and compile them so we can attach them to this update, as update queries + // can get join statements to attach to other tables when they're needed. + if (isset($query->joins)) + { + $joins = ' '.$this->compileJoins($query, $query->joins); + } + else + { + $joins = ''; + } + + // Of course, update queries may also be constrained by where clauses so we'll + // need to compile the where clauses and attach it to the query so only the + // intended records are updated by the SQL statements we generate to run. + $where = $this->compileWheres($query); + + return trim("update {$table}{$joins} set $columns $where"); + } + + /** + * Compile a delete statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + public function compileDelete(Builder $query) + { + $table = $this->wrapTable($query->from); + + $where = is_array($query->wheres) ? $this->compileWheres($query) : ''; + + return trim("delete from $table ".$where); + } + + /** + * Compile a truncate table statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return array + */ + public function compileTruncate(Builder $query) + { + return array('truncate '.$this->wrapTable($query->from) => array()); + } + + /** + * Compile the lock into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param bool|string $value + * @return string + */ + protected function compileLock(Builder $query, $value) + { + return is_string($value) ? $value : ''; + } + + /** + * Concatenate an array of segments, removing empties. + * + * @param array $segments + * @return string + */ + protected function concatenate($segments) + { + return implode(' ', array_filter($segments, function($value) + { + return (string) $value !== ''; + })); + } + + /** + * Remove the leading boolean from a statement. + * + * @param string $value + * @return string + */ + protected function removeLeadingBoolean($value) + { + return preg_replace('/and |or /', '', $value, 1); + } + +} diff --git a/vendor/illuminate/database/Query/Grammars/MySqlGrammar.php b/vendor/illuminate/database/Query/Grammars/MySqlGrammar.php new file mode 100755 index 0000000..b6a1dbd --- /dev/null +++ b/vendor/illuminate/database/Query/Grammars/MySqlGrammar.php @@ -0,0 +1,144 @@ +unions) + { + $sql = '('.$sql.') '.$this->compileUnions($query); + } + + return $sql; + } + + /** + * Compile a single union statement. + * + * @param array $union + * @return string + */ + protected function compileUnion(array $union) + { + $joiner = $union['all'] ? ' union all ' : ' union '; + + return $joiner.'('.$union['query']->toSql().')'; + } + + /** + * Compile the lock into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param bool|string $value + * @return string + */ + protected function compileLock(Builder $query, $value) + { + if (is_string($value)) return $value; + + return $value ? 'for update' : 'lock in share mode'; + } + + /** + * Compile an update statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @return string + */ + public function compileUpdate(Builder $query, $values) + { + $sql = parent::compileUpdate($query, $values); + + if (isset($query->orders)) + { + $sql .= ' '.$this->compileOrders($query, $query->orders); + } + + if (isset($query->limit)) + { + $sql .= ' '.$this->compileLimit($query, $query->limit); + } + + return rtrim($sql); + } + + /** + * Compile a delete statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + public function compileDelete(Builder $query) + { + $table = $this->wrapTable($query->from); + + $where = is_array($query->wheres) ? $this->compileWheres($query) : ''; + + if (isset($query->joins)) + { + $joins = ' '.$this->compileJoins($query, $query->joins); + + $sql = trim("delete $table from {$table}{$joins} $where"); + } + else + { + $sql = trim("delete from $table $where"); + } + + if (isset($query->orders)) + { + $sql .= ' '.$this->compileOrders($query, $query->orders); + } + + if (isset($query->limit)) + { + $sql .= ' '.$this->compileLimit($query, $query->limit); + } + + return $sql; + } + + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '`'.str_replace('`', '``', $value).'`'; + } + +} diff --git a/vendor/illuminate/database/Query/Grammars/PostgresGrammar.php b/vendor/illuminate/database/Query/Grammars/PostgresGrammar.php new file mode 100755 index 0000000..7a8df9c --- /dev/null +++ b/vendor/illuminate/database/Query/Grammars/PostgresGrammar.php @@ -0,0 +1,174 @@ +', '<=', '>=', '<>', '!=', + 'like', 'not like', 'between', 'ilike', + '&', '|', '#', '<<', '>>', + ); + + /** + * Compile the lock into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param bool|string $value + * @return string + */ + protected function compileLock(Builder $query, $value) + { + if (is_string($value)) return $value; + + return $value ? 'for update' : 'for share'; + } + + /** + * Compile an update statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @return string + */ + public function compileUpdate(Builder $query, $values) + { + $table = $this->wrapTable($query->from); + + // Each one of the columns in the update statements needs to be wrapped in the + // keyword identifiers, also a place-holder needs to be created for each of + // the values in the list of bindings so we can make the sets statements. + $columns = $this->compileUpdateColumns($values); + + $from = $this->compileUpdateFrom($query); + + $where = $this->compileUpdateWheres($query); + + return trim("update {$table} set {$columns}{$from} $where"); + } + + /** + * Compile the columns for the update statement. + * + * @param array $values + * @return string + */ + protected function compileUpdateColumns($values) + { + $columns = array(); + + // When gathering the columns for an update statement, we'll wrap each of the + // columns and convert it to a parameter value. Then we will concatenate a + // list of the columns that can be added into this update query clauses. + foreach ($values as $key => $value) + { + $columns[] = $this->wrap($key).' = '.$this->parameter($value); + } + + return implode(', ', $columns); + } + + /** + * Compile the "from" clause for an update with a join. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + protected function compileUpdateFrom(Builder $query) + { + if ( ! isset($query->joins)) return ''; + + $froms = array(); + + // When using Postgres, updates with joins list the joined tables in the from + // clause, which is different than other systems like MySQL. Here, we will + // compile out the tables that are joined and add them to a from clause. + foreach ($query->joins as $join) + { + $froms[] = $this->wrapTable($join->table); + } + + if (count($froms) > 0) return ' from '.implode(', ', $froms); + } + + /** + * Compile the additional where clauses for updates with joins. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + protected function compileUpdateWheres(Builder $query) + { + $baseWhere = $this->compileWheres($query); + + if ( ! isset($query->joins)) return $baseWhere; + + // Once we compile the join constraints, we will either use them as the where + // clause or append them to the existing base where clauses. If we need to + // strip the leading boolean we will do so when using as the only where. + $joinWhere = $this->compileUpdateJoinWheres($query); + + if (trim($baseWhere) == '') + { + return 'where '.$this->removeLeadingBoolean($joinWhere); + } + + return $baseWhere.' '.$joinWhere; + } + + /** + * Compile the "join" clauses for an update. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + protected function compileUpdateJoinWheres(Builder $query) + { + $joinWheres = array(); + + // Here we will just loop through all of the join constraints and compile them + // all out then implode them. This should give us "where" like syntax after + // everything has been built and then we will join it to the real wheres. + foreach ($query->joins as $join) + { + foreach ($join->clauses as $clause) + { + $joinWheres[] = $this->compileJoinConstraint($clause); + } + } + + return implode(' ', $joinWheres); + } + + /** + * Compile an insert and get ID statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @param string $sequence + * @return string + */ + public function compileInsertGetId(Builder $query, $values, $sequence) + { + if (is_null($sequence)) $sequence = 'id'; + + return $this->compileInsert($query, $values).' returning '.$this->wrap($sequence); + } + + /** + * Compile a truncate table statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return array + */ + public function compileTruncate(Builder $query) + { + return array('truncate '.$this->wrapTable($query->from).' restart identity' => array()); + } + +} diff --git a/vendor/illuminate/database/Query/Grammars/SQLiteGrammar.php b/vendor/illuminate/database/Query/Grammars/SQLiteGrammar.php new file mode 100755 index 0000000..9e47042 --- /dev/null +++ b/vendor/illuminate/database/Query/Grammars/SQLiteGrammar.php @@ -0,0 +1,130 @@ +', '<=', '>=', '<>', '!=', + 'like', 'not like', 'between', 'ilike', + '&', '|', '<<', '>>', + ); + + /** + * Compile an insert statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $values + * @return string + */ + public function compileInsert(Builder $query, array $values) + { + // Essentially we will force every insert to be treated as a batch insert which + // simply makes creating the SQL easier for us since we can utilize the same + // basic routine regardless of an amount of records given to us to insert. + $table = $this->wrapTable($query->from); + + if ( ! is_array(reset($values))) + { + $values = array($values); + } + + // If there is only one record being inserted, we will just use the usual query + // grammar insert builder because no special syntax is needed for the single + // row inserts in SQLite. However, if there are multiples, we'll continue. + if (count($values) == 1) + { + return parent::compileInsert($query, reset($values)); + } + + $names = $this->columnize(array_keys(reset($values))); + + $columns = array(); + + // SQLite requires us to build the multi-row insert as a listing of select with + // unions joining them together. So we'll build out this list of columns and + // then join them all together with select unions to complete the queries. + foreach (array_keys(reset($values)) as $column) + { + $columns[] = '? as '.$this->wrap($column); + } + + $columns = array_fill(0, count($values), implode(', ', $columns)); + + return "insert into $table ($names) select ".implode(' union all select ', $columns); + } + + /** + * Compile a truncate table statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return array + */ + public function compileTruncate(Builder $query) + { + $sql = array('delete from sqlite_sequence where name = ?' => array($query->from)); + + $sql['delete from '.$this->wrapTable($query->from)] = array(); + + return $sql; + } + + /** + * Compile a "where day" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereDay(Builder $query, $where) + { + return $this->dateBasedWhere('%d', $query, $where); + } + + /** + * Compile a "where month" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereMonth(Builder $query, $where) + { + return $this->dateBasedWhere('%m', $query, $where); + } + + /** + * Compile a "where year" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereYear(Builder $query, $where) + { + return $this->dateBasedWhere('%Y', $query, $where); + } + + /** + * Compile a date based where clause. + * + * @param string $type + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function dateBasedWhere($type, Builder $query, $where) + { + $value = str_pad($where['value'], 2, '0', STR_PAD_LEFT); + + $value = $this->parameter($value); + + return 'strftime(\''.$type.'\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value; + } + +} diff --git a/vendor/illuminate/database/Query/Grammars/SqlServerGrammar.php b/vendor/illuminate/database/Query/Grammars/SqlServerGrammar.php new file mode 100755 index 0000000..24fd428 --- /dev/null +++ b/vendor/illuminate/database/Query/Grammars/SqlServerGrammar.php @@ -0,0 +1,224 @@ +', '<=', '>=', '!<', '!>', '<>', '!=', + 'like', 'not like', 'between', 'ilike', + '&', '&=', '|', '|=', '^', '^=', + ); + + /** + * Compile a select query into SQL. + * + * @param \Illuminate\Database\Query\Builder + * @return string + */ + public function compileSelect(Builder $query) + { + $components = $this->compileComponents($query); + + // If an offset is present on the query, we will need to wrap the query in + // a big "ANSI" offset syntax block. This is very nasty compared to the + // other database systems but is necessary for implementing features. + if ($query->offset > 0) + { + return $this->compileAnsiOffset($query, $components); + } + + return $this->concatenate($components); + } + + /** + * Compile the "select *" portion of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $columns + * @return string + */ + protected function compileColumns(Builder $query, $columns) + { + if ( ! is_null($query->aggregate)) return; + + $select = $query->distinct ? 'select distinct ' : 'select '; + + // If there is a limit on the query, but not an offset, we will add the top + // clause to the query, which serves as a "limit" type clause within the + // SQL Server system similar to the limit keywords available in MySQL. + if ($query->limit > 0 && $query->offset <= 0) + { + $select .= 'top '.$query->limit.' '; + } + + return $select.$this->columnize($columns); + } + + /** + * Compile the "from" portion of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param string $table + * @return string + */ + protected function compileFrom(Builder $query, $table) + { + $from = parent::compileFrom($query, $table); + + if (is_string($query->lock)) return $from.' '.$query->lock; + + if ( ! is_null($query->lock)) + { + return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)'; + } + + return $from; + } + + /** + * Create a full ANSI offset clause for the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $components + * @return string + */ + protected function compileAnsiOffset(Builder $query, $components) + { + // An ORDER BY clause is required to make this offset query work, so if one does + // not exist we'll just create a dummy clause to trick the database and so it + // does not complain about the queries for not having an "order by" clause. + if ( ! isset($components['orders'])) + { + $components['orders'] = 'order by (select 0)'; + } + + // We need to add the row number to the query so we can compare it to the offset + // and limit values given for the statements. So we will add an expression to + // the "select" that will give back the row numbers on each of the records. + $orderings = $components['orders']; + + $components['columns'] .= $this->compileOver($orderings); + + unset($components['orders']); + + // Next we need to calculate the constraints that should be placed on the query + // to get the right offset and limit from our query but if there is no limit + // set we will just handle the offset only since that is all that matters. + $constraint = $this->compileRowConstraint($query); + + $sql = $this->concatenate($components); + + // We are now ready to build the final SQL query so we'll create a common table + // expression from the query and get the records with row numbers within our + // given limit and offset value that we just put on as a query constraint. + return $this->compileTableExpression($sql, $constraint); + } + + /** + * Compile the over statement for a table expression. + * + * @param string $orderings + * @return string + */ + protected function compileOver($orderings) + { + return ", row_number() over ({$orderings}) as row_num"; + } + + /** + * Compile the limit / offset row constraint for a query. + * + * @param \Illuminate\Database\Query\Builder $query + * @return string + */ + protected function compileRowConstraint($query) + { + $start = $query->offset + 1; + + if ($query->limit > 0) + { + $finish = $query->offset + $query->limit; + + return "between {$start} and {$finish}"; + } + + return ">= {$start}"; + } + + /** + * Compile a common table expression for a query. + * + * @param string $sql + * @param string $constraint + * @return string + */ + protected function compileTableExpression($sql, $constraint) + { + return "select * from ({$sql}) as temp_table where row_num {$constraint}"; + } + + /** + * Compile the "limit" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $limit + * @return string + */ + protected function compileLimit(Builder $query, $limit) + { + return ''; + } + + /** + * Compile the "offset" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $offset + * @return string + */ + protected function compileOffset(Builder $query, $offset) + { + return ''; + } + + /** + * Compile a truncate table statement into SQL. + * + * @param \Illuminate\Database\Query\Builder $query + * @return array + */ + public function compileTruncate(Builder $query) + { + return array('truncate table '.$this->wrapTable($query->from) => array()); + } + + /** + * Get the format for database stored dates. + * + * @return string + */ + public function getDateFormat() + { + return 'Y-m-d H:i:s.000'; + } + + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '['.str_replace(']', ']]', $value).']'; + } + +} diff --git a/vendor/illuminate/database/Query/JoinClause.php b/vendor/illuminate/database/Query/JoinClause.php new file mode 100755 index 0000000..ea571d3 --- /dev/null +++ b/vendor/illuminate/database/Query/JoinClause.php @@ -0,0 +1,151 @@ +type = $type; + $this->table = $table; + } + + /** + * Add an "on" clause to the join. + * + * @param string $first + * @param string $operator + * @param string $second + * @param string $boolean + * @param bool $where + * @return $this + */ + public function on($first, $operator, $second, $boolean = 'and', $where = false) + { + $this->clauses[] = compact('first', 'operator', 'second', 'boolean', 'where'); + + if ($where) $this->bindings[] = $second; + + return $this; + } + + /** + * Add an "or on" clause to the join. + * + * @param string $first + * @param string $operator + * @param string $second + * @return \Illuminate\Database\Query\JoinClause + */ + public function orOn($first, $operator, $second) + { + return $this->on($first, $operator, $second, 'or'); + } + + /** + * Add an "on where" clause to the join. + * + * @param string $first + * @param string $operator + * @param string $second + * @param string $boolean + * @return \Illuminate\Database\Query\JoinClause + */ + public function where($first, $operator, $second, $boolean = 'and') + { + return $this->on($first, $operator, $second, $boolean, true); + } + + /** + * Add an "or on where" clause to the join. + * + * @param string $first + * @param string $operator + * @param string $second + * @return \Illuminate\Database\Query\JoinClause + */ + public function orWhere($first, $operator, $second) + { + return $this->on($first, $operator, $second, 'or', true); + } + + /** + * Add an "on where is null" clause to the join. + * + * @param string $column + * @param string $boolean + * @return \Illuminate\Database\Query\JoinClause + */ + public function whereNull($column, $boolean = 'and') + { + return $this->on($column, 'is', new Expression('null'), $boolean, false); + } + + /** + * Add an "or on where is null" clause to the join. + * + * @param string $column + * @return \Illuminate\Database\Query\JoinClause + */ + public function orWhereNull($column) + { + return $this->whereNull($column, 'or'); + } + + /** + * Add an "on where is not null" clause to the join. + * + * @param string $column + * @param string $boolean + * @return \Illuminate\Database\Query\JoinClause + */ + public function whereNotNull($column, $boolean = 'and') + { + return $this->on($column, 'is', new Expression('not null'), $boolean, false); + } + + /** + * Add an "or on where is not null" clause to the join. + * + * @param string $column + * @return \Illuminate\Database\Query\JoinClause + */ + public function orWhereNotNull($column) + { + return $this->whereNotNull($column, 'or'); + } + +} diff --git a/vendor/illuminate/database/Query/Processors/MySqlProcessor.php b/vendor/illuminate/database/Query/Processors/MySqlProcessor.php new file mode 100755 index 0000000..1e45ce7 --- /dev/null +++ b/vendor/illuminate/database/Query/Processors/MySqlProcessor.php @@ -0,0 +1,23 @@ +column_name; + }; + + return array_map($mapping, $results); + } + +} diff --git a/vendor/illuminate/database/Query/Processors/PostgresProcessor.php b/vendor/illuminate/database/Query/Processors/PostgresProcessor.php new file mode 100755 index 0000000..775dc8e --- /dev/null +++ b/vendor/illuminate/database/Query/Processors/PostgresProcessor.php @@ -0,0 +1,47 @@ +getConnection()->selectFromWriteConnection($sql, $values); + + $sequence = $sequence ?: 'id'; + + $result = (array) $results[0]; + + $id = $result[$sequence]; + + return is_numeric($id) ? (int) $id : $id; + } + + /** + * Process the results of a column listing query. + * + * @param array $results + * @return array + */ + public function processColumnListing($results) + { + $mapping = function($r) + { + $r = (object) $r; + + return $r->column_name; + }; + + return array_map($mapping, $results); + } + +} diff --git a/vendor/illuminate/database/Query/Processors/Processor.php b/vendor/illuminate/database/Query/Processors/Processor.php new file mode 100755 index 0000000..b960092 --- /dev/null +++ b/vendor/illuminate/database/Query/Processors/Processor.php @@ -0,0 +1,48 @@ +getConnection()->insert($sql, $values); + + $id = $query->getConnection()->getPdo()->lastInsertId($sequence); + + return is_numeric($id) ? (int) $id : $id; + } + + /** + * Process the results of a column listing query. + * + * @param array $results + * @return array + */ + public function processColumnListing($results) + { + return $results; + } + +} diff --git a/vendor/illuminate/database/Query/Processors/SQLiteProcessor.php b/vendor/illuminate/database/Query/Processors/SQLiteProcessor.php new file mode 100755 index 0000000..b1d8e0a --- /dev/null +++ b/vendor/illuminate/database/Query/Processors/SQLiteProcessor.php @@ -0,0 +1,23 @@ +name; + }; + + return array_map($mapping, $results); + } + +} diff --git a/vendor/illuminate/database/Query/Processors/SqlServerProcessor.php b/vendor/illuminate/database/Query/Processors/SqlServerProcessor.php new file mode 100755 index 0000000..38bc25c --- /dev/null +++ b/vendor/illuminate/database/Query/Processors/SqlServerProcessor.php @@ -0,0 +1,41 @@ +getConnection()->insert($sql, $values); + + $id = $query->getConnection()->getPdo()->lastInsertId(); + + return is_numeric($id) ? (int) $id : $id; + } + + /** + * Process the results of a column listing query. + * + * @param array $results + * @return array + */ + public function processColumnListing($results) + { + $mapping = function($r) + { + return $r->name; + }; + + return array_map($mapping, $results); + } + +} diff --git a/vendor/illuminate/database/QueryException.php b/vendor/illuminate/database/QueryException.php new file mode 100755 index 0000000..e3f9cf2 --- /dev/null +++ b/vendor/illuminate/database/QueryException.php @@ -0,0 +1,78 @@ +sql = $sql; + $this->bindings = $bindings; + $this->previous = $previous; + $this->code = $previous->getCode(); + $this->message = $this->formatMessage($sql, $bindings, $previous); + + if ($previous instanceof PDOException) + { + $this->errorInfo = $previous->errorInfo; + } + } + + /** + * Format the SQL error message. + * + * @param string $sql + * @param array $bindings + * @param \Exception $previous + * @return string + */ + protected function formatMessage($sql, $bindings, $previous) + { + return $previous->getMessage().' (SQL: '.str_replace_array('\?', $bindings, $sql).')'; + } + + /** + * Get the SQL for the query. + * + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * Get the bindings for the query. + * + * @return array + */ + public function getBindings() + { + return $this->bindings; + } + +} diff --git a/vendor/illuminate/database/README.md b/vendor/illuminate/database/README.md new file mode 100755 index 0000000..9928a04 --- /dev/null +++ b/vendor/illuminate/database/README.md @@ -0,0 +1,70 @@ +## Illuminate Database + +The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder. It currently supports MySQL, Postgres, SQL Server, and SQLite. It also serves as the database layer of the Laravel PHP framework. + +### Usage Instructions + +First, create a new "Capsule" manager instance. Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible. + +```PHP +use Illuminate\Database\Capsule\Manager as Capsule; + +$capsule = new Capsule; + +$capsule->addConnection([ + 'driver' => 'mysql', + 'host' => 'localhost', + 'database' => 'database', + 'username' => 'root', + 'password' => 'password', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', +]); + +// Set the event dispatcher used by Eloquent models... (optional) +use Illuminate\Events\Dispatcher; +use Illuminate\Container\Container; +$capsule->setEventDispatcher(new Dispatcher(new Container)); + +// Make this Capsule instance available globally via static methods... (optional) +$capsule->setAsGlobal(); + +// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher()) +$capsule->bootEloquent(); +``` + +> `composer require "illuminate/events=5.0.*"` required when you need to use observers with Eloquent. + +Once the Capsule instance has been registered. You may use it like so: + +**Using The Query Builder** + +```PHP +$users = Capsule::table('users')->where('votes', '>', 100)->get(); +``` +Other core methods may be accessed directly from the Capsule in the same manner as from the DB facade: +```PHP +$results = Capsule::select('select * from users where id = ?', array(1)); +``` + +**Using The Schema Builder** + +```PHP +Capsule::schema()->create('users', function($table) +{ + $table->increments('id'); + $table->string('email')->unique(); + $table->timestamps(); +}); +``` + +**Using The Eloquent ORM** + +```PHP +class User extends Illuminate\Database\Eloquent\Model {} + +$users = User::where('votes', '>', 1)->get(); +``` + +For further documentation on using the various database facilities this library provides, consult the [Laravel framework documentation](http://laravel.com/docs). diff --git a/vendor/illuminate/database/SQLiteConnection.php b/vendor/illuminate/database/SQLiteConnection.php new file mode 100755 index 0000000..37978ab --- /dev/null +++ b/vendor/illuminate/database/SQLiteConnection.php @@ -0,0 +1,50 @@ +withTablePrefix(new QueryGrammar); + } + + /** + * Get the default schema grammar instance. + * + * @return \Illuminate\Database\Schema\Grammars\SQLiteGrammar + */ + protected function getDefaultSchemaGrammar() + { + return $this->withTablePrefix(new SchemaGrammar); + } + + /** + * Get the default post processor instance. + * + * @return \Illuminate\Database\Query\Processors\Processor + */ + protected function getDefaultPostProcessor() + { + return new SQLiteProcessor; + } + + /** + * Get the Doctrine DBAL driver. + * + * @return \Doctrine\DBAL\Driver\PDOSqlite\Driver + */ + protected function getDoctrineDriver() + { + return new DoctrineDriver; + } + +} diff --git a/vendor/illuminate/database/Schema/Blueprint.php b/vendor/illuminate/database/Schema/Blueprint.php new file mode 100755 index 0000000..4968406 --- /dev/null +++ b/vendor/illuminate/database/Schema/Blueprint.php @@ -0,0 +1,923 @@ +table = $table; + + if ( ! is_null($callback)) $callback($this); + } + + /** + * Execute the blueprint against the database. + * + * @param \Illuminate\Database\Connection $connection + * @param \Illuminate\Database\Schema\Grammars\Grammar $grammar + * @return void + */ + public function build(Connection $connection, Grammar $grammar) + { + foreach ($this->toSql($connection, $grammar) as $statement) + { + $connection->statement($statement); + } + } + + /** + * Get the raw SQL statements for the blueprint. + * + * @param \Illuminate\Database\Connection $connection + * @param \Illuminate\Database\Schema\Grammars\Grammar $grammar + * @return array + */ + public function toSql(Connection $connection, Grammar $grammar) + { + $this->addImpliedCommands(); + + $statements = array(); + + // Each type of command has a corresponding compiler function on the schema + // grammar which is used to build the necessary SQL statements to build + // the blueprint element, so we'll just call that compilers function. + foreach ($this->commands as $command) + { + $method = 'compile'.ucfirst($command->name); + + if (method_exists($grammar, $method)) + { + if ( ! is_null($sql = $grammar->$method($this, $command, $connection))) + { + $statements = array_merge($statements, (array) $sql); + } + } + } + + return $statements; + } + + /** + * Add the commands that are implied by the blueprint. + * + * @return void + */ + protected function addImpliedCommands() + { + if (count($this->getAddedColumns()) > 0 && ! $this->creating()) + { + array_unshift($this->commands, $this->createCommand('add')); + } + + if (count($this->getChangedColumns()) > 0 && ! $this->creating()) + { + array_unshift($this->commands, $this->createCommand('change')); + } + + $this->addFluentIndexes(); + } + + /** + * Add the index commands fluently specified on columns. + * + * @return void + */ + protected function addFluentIndexes() + { + foreach ($this->columns as $column) + { + foreach (array('primary', 'unique', 'index') as $index) + { + // If the index has been specified on the given column, but is simply + // equal to "true" (boolean), no name has been specified for this + // index, so we will simply call the index methods without one. + if ($column->$index === true) + { + $this->$index($column->name); + + continue 2; + } + + // If the index has been specified on the column and it is something + // other than boolean true, we will assume a name was provided on + // the index specification, and pass in the name to the method. + elseif (isset($column->$index)) + { + $this->$index($column->name, $column->$index); + + continue 2; + } + } + } + } + + /** + * Determine if the blueprint has a create command. + * + * @return bool + */ + protected function creating() + { + foreach ($this->commands as $command) + { + if ($command->name == 'create') return true; + } + + return false; + } + + /** + * Indicate that the table needs to be created. + * + * @return \Illuminate\Support\Fluent + */ + public function create() + { + return $this->addCommand('create'); + } + + /** + * Indicate that the table should be dropped. + * + * @return \Illuminate\Support\Fluent + */ + public function drop() + { + return $this->addCommand('drop'); + } + + /** + * Indicate that the table should be dropped if it exists. + * + * @return \Illuminate\Support\Fluent + */ + public function dropIfExists() + { + return $this->addCommand('dropIfExists'); + } + + /** + * Indicate that the given columns should be dropped. + * + * @param string|array $columns + * @return \Illuminate\Support\Fluent + */ + public function dropColumn($columns) + { + $columns = is_array($columns) ? $columns : (array) func_get_args(); + + return $this->addCommand('dropColumn', compact('columns')); + } + + /** + * Indicate that the given columns should be renamed. + * + * @param string $from + * @param string $to + * @return \Illuminate\Support\Fluent + */ + public function renameColumn($from, $to) + { + return $this->addCommand('renameColumn', compact('from', 'to')); + } + + /** + * Indicate that the given primary key should be dropped. + * + * @param string|array $index + * @return \Illuminate\Support\Fluent + */ + public function dropPrimary($index = null) + { + return $this->dropIndexCommand('dropPrimary', 'primary', $index); + } + + /** + * Indicate that the given unique key should be dropped. + * + * @param string|array $index + * @return \Illuminate\Support\Fluent + */ + public function dropUnique($index) + { + return $this->dropIndexCommand('dropUnique', 'unique', $index); + } + + /** + * Indicate that the given index should be dropped. + * + * @param string|array $index + * @return \Illuminate\Support\Fluent + */ + public function dropIndex($index) + { + return $this->dropIndexCommand('dropIndex', 'index', $index); + } + + /** + * Indicate that the given foreign key should be dropped. + * + * @param string $index + * @return \Illuminate\Support\Fluent + */ + public function dropForeign($index) + { + return $this->dropIndexCommand('dropForeign', 'foreign', $index); + } + + /** + * Indicate that the timestamp columns should be dropped. + * + * @return void + */ + public function dropTimestamps() + { + $this->dropColumn('created_at', 'updated_at'); + } + + /** + * Indicate that the soft delete column should be dropped. + * + * @return void + */ + public function dropSoftDeletes() + { + $this->dropColumn('deleted_at'); + } + + /** + * Rename the table to a given name. + * + * @param string $to + * @return \Illuminate\Support\Fluent + */ + public function rename($to) + { + return $this->addCommand('rename', compact('to')); + } + + /** + * Specify the primary key(s) for the table. + * + * @param string|array $columns + * @param string $name + * @return \Illuminate\Support\Fluent + */ + public function primary($columns, $name = null) + { + return $this->indexCommand('primary', $columns, $name); + } + + /** + * Specify a unique index for the table. + * + * @param string|array $columns + * @param string $name + * @return \Illuminate\Support\Fluent + */ + public function unique($columns, $name = null) + { + return $this->indexCommand('unique', $columns, $name); + } + + /** + * Specify an index for the table. + * + * @param string|array $columns + * @param string $name + * @return \Illuminate\Support\Fluent + */ + public function index($columns, $name = null) + { + return $this->indexCommand('index', $columns, $name); + } + + /** + * Specify a foreign key for the table. + * + * @param string|array $columns + * @param string $name + * @return \Illuminate\Support\Fluent + */ + public function foreign($columns, $name = null) + { + return $this->indexCommand('foreign', $columns, $name); + } + + /** + * Create a new auto-incrementing integer column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function increments($column) + { + return $this->unsignedInteger($column, true); + } + + /** + * Create a new auto-incrementing big integer column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function bigIncrements($column) + { + return $this->unsignedBigInteger($column, true); + } + + /** + * Create a new char column on the table. + * + * @param string $column + * @param int $length + * @return \Illuminate\Support\Fluent + */ + public function char($column, $length = 255) + { + return $this->addColumn('char', $column, compact('length')); + } + + /** + * Create a new string column on the table. + * + * @param string $column + * @param int $length + * @return \Illuminate\Support\Fluent + */ + public function string($column, $length = 255) + { + return $this->addColumn('string', $column, compact('length')); + } + + /** + * Create a new text column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function text($column) + { + return $this->addColumn('text', $column); + } + + /** + * Create a new medium text column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function mediumText($column) + { + return $this->addColumn('mediumText', $column); + } + + /** + * Create a new long text column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function longText($column) + { + return $this->addColumn('longText', $column); + } + + /** + * Create a new integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned + * @return \Illuminate\Support\Fluent + */ + public function integer($column, $autoIncrement = false, $unsigned = false) + { + return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned')); + } + + /** + * Create a new big integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned + * @return \Illuminate\Support\Fluent + */ + public function bigInteger($column, $autoIncrement = false, $unsigned = false) + { + return $this->addColumn('bigInteger', $column, compact('autoIncrement', 'unsigned')); + } + + /** + * Create a new medium integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned + * @return \Illuminate\Support\Fluent + */ + public function mediumInteger($column, $autoIncrement = false, $unsigned = false) + { + return $this->addColumn('mediumInteger', $column, compact('autoIncrement', 'unsigned')); + } + + /** + * Create a new tiny integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned + * @return \Illuminate\Support\Fluent + */ + public function tinyInteger($column, $autoIncrement = false, $unsigned = false) + { + return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned')); + } + + /** + * Create a new small integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @param bool $unsigned + * @return \Illuminate\Support\Fluent + */ + public function smallInteger($column, $autoIncrement = false, $unsigned = false) + { + return $this->addColumn('smallInteger', $column, compact('autoIncrement', 'unsigned')); + } + + /** + * Create a new unsigned integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @return \Illuminate\Support\Fluent + */ + public function unsignedInteger($column, $autoIncrement = false) + { + return $this->integer($column, $autoIncrement, true); + } + + /** + * Create a new unsigned big integer column on the table. + * + * @param string $column + * @param bool $autoIncrement + * @return \Illuminate\Support\Fluent + */ + public function unsignedBigInteger($column, $autoIncrement = false) + { + return $this->bigInteger($column, $autoIncrement, true); + } + + /** + * Create a new float column on the table. + * + * @param string $column + * @param int $total + * @param int $places + * @return \Illuminate\Support\Fluent + */ + public function float($column, $total = 8, $places = 2) + { + return $this->addColumn('float', $column, compact('total', 'places')); + } + + /** + * Create a new double column on the table. + * + * @param string $column + * @param int|null $total + * @param int|null $places + * @return \Illuminate\Support\Fluent + */ + public function double($column, $total = null, $places = null) + { + return $this->addColumn('double', $column, compact('total', 'places')); + } + + /** + * Create a new decimal column on the table. + * + * @param string $column + * @param int $total + * @param int $places + * @return \Illuminate\Support\Fluent + */ + public function decimal($column, $total = 8, $places = 2) + { + return $this->addColumn('decimal', $column, compact('total', 'places')); + } + + /** + * Create a new boolean column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function boolean($column) + { + return $this->addColumn('boolean', $column); + } + + /** + * Create a new enum column on the table. + * + * @param string $column + * @param array $allowed + * @return \Illuminate\Support\Fluent + */ + public function enum($column, array $allowed) + { + return $this->addColumn('enum', $column, compact('allowed')); + } + + /** + * Create a new json column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function json($column) + { + return $this->addColumn('json', $column); + } + + /** + * Create a new jsonb column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function jsonb($column) + { + return $this->addColumn('jsonb', $column); + } + + /** + * Create a new date column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function date($column) + { + return $this->addColumn('date', $column); + } + + /** + * Create a new date-time column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function dateTime($column) + { + return $this->addColumn('dateTime', $column); + } + + /** + * Create a new date-time column (with time zone) on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function dateTimeTz($column) + { + return $this->addColumn('dateTimeTz', $column); + } + + /** + * Create a new time column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function time($column) + { + return $this->addColumn('time', $column); + } + + /** + * Create a new time column (with time zone) on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function timeTz($column) + { + return $this->addColumn('timeTz', $column); + } + + /** + * Create a new timestamp column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function timestamp($column) + { + return $this->addColumn('timestamp', $column); + } + + /** + * Create a new timestamp (with time zone) column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function timestampTz($column) + { + return $this->addColumn('timestampTz', $column); + } + + /** + * Add nullable creation and update timestamps to the table. + * + * @return void + */ + public function nullableTimestamps() + { + $this->timestamp('created_at')->nullable(); + + $this->timestamp('updated_at')->nullable(); + } + + /** + * Add creation and update timestamps to the table. + * + * @return void + */ + public function timestamps() + { + $this->timestamp('created_at'); + + $this->timestamp('updated_at'); + } + + /** + * Add a "deleted at" timestamp for the table. + * + * @return \Illuminate\Support\Fluent + */ + public function softDeletes() + { + return $this->timestamp('deleted_at')->nullable(); + } + + /** + * Create a new binary column on the table. + * + * @param string $column + * @return \Illuminate\Support\Fluent + */ + public function binary($column) + { + return $this->addColumn('binary', $column); + } + + /** + * Add the proper columns for a polymorphic table. + * + * @param string $name + * @param string|null $indexName + * @return void + */ + public function morphs($name, $indexName = null) + { + $this->unsignedInteger("{$name}_id"); + + $this->string("{$name}_type"); + + $this->index(array("{$name}_id", "{$name}_type"), $indexName); + } + + /** + * Adds the `remember_token` column to the table. + * + * @return \Illuminate\Support\Fluent + */ + public function rememberToken() + { + return $this->string('remember_token', 100)->nullable(); + } + + /** + * Create a new drop index command on the blueprint. + * + * @param string $command + * @param string $type + * @param string|array $index + * @return \Illuminate\Support\Fluent + */ + protected function dropIndexCommand($command, $type, $index) + { + $columns = array(); + + // If the given "index" is actually an array of columns, the developer means + // to drop an index merely by specifying the columns involved without the + // conventional name, so we will build the index name from the columns. + if (is_array($index)) + { + $columns = $index; + + $index = $this->createIndexName($type, $columns); + } + + return $this->indexCommand($command, $columns, $index); + } + + /** + * Add a new index command to the blueprint. + * + * @param string $type + * @param string|array $columns + * @param string $index + * @return \Illuminate\Support\Fluent + */ + protected function indexCommand($type, $columns, $index) + { + $columns = (array) $columns; + + // If no name was specified for this index, we will create one using a basic + // convention of the table name, followed by the columns, followed by an + // index type, such as primary or index, which makes the index unique. + if (is_null($index)) + { + $index = $this->createIndexName($type, $columns); + } + + return $this->addCommand($type, compact('index', 'columns')); + } + + /** + * Create a default index name for the table. + * + * @param string $type + * @param array $columns + * @return string + */ + protected function createIndexName($type, array $columns) + { + $index = strtolower($this->table.'_'.implode('_', $columns).'_'.$type); + + return str_replace(array('-', '.'), '_', $index); + } + + /** + * Add a new column to the blueprint. + * + * @param string $type + * @param string $name + * @param array $parameters + * @return \Illuminate\Support\Fluent + */ + protected function addColumn($type, $name, array $parameters = array()) + { + $attributes = array_merge(compact('type', 'name'), $parameters); + + $this->columns[] = $column = new Fluent($attributes); + + return $column; + } + + /** + * Remove a column from the schema blueprint. + * + * @param string $name + * @return $this + */ + public function removeColumn($name) + { + $this->columns = array_values(array_filter($this->columns, function($c) use ($name) + { + return $c['attributes']['name'] != $name; + })); + + return $this; + } + + /** + * Add a new command to the blueprint. + * + * @param string $name + * @param array $parameters + * @return \Illuminate\Support\Fluent + */ + protected function addCommand($name, array $parameters = array()) + { + $this->commands[] = $command = $this->createCommand($name, $parameters); + + return $command; + } + + /** + * Create a new Fluent command. + * + * @param string $name + * @param array $parameters + * @return \Illuminate\Support\Fluent + */ + protected function createCommand($name, array $parameters = array()) + { + return new Fluent(array_merge(compact('name'), $parameters)); + } + + /** + * Get the table the blueprint describes. + * + * @return string + */ + public function getTable() + { + return $this->table; + } + + /** + * Get the columns on the blueprint. + * + * @return array + */ + public function getColumns() + { + return $this->columns; + } + + /** + * Get the commands on the blueprint. + * + * @return array + */ + public function getCommands() + { + return $this->commands; + } + + /** + * Get the columns on the blueprint that should be added. + * + * @return array + */ + public function getAddedColumns() + { + return array_filter($this->columns, function($column) + { + return !$column->change; + }); + } + + /** + * Get the columns on the blueprint that should be changed. + * + * @return array + */ + public function getChangedColumns() + { + return array_filter($this->columns, function($column) + { + return !!$column->change; + }); + } + +} diff --git a/vendor/illuminate/database/Schema/Builder.php b/vendor/illuminate/database/Schema/Builder.php new file mode 100755 index 0000000..cd7521d --- /dev/null +++ b/vendor/illuminate/database/Schema/Builder.php @@ -0,0 +1,242 @@ +connection = $connection; + $this->grammar = $connection->getSchemaGrammar(); + } + + /** + * Determine if the given table exists. + * + * @param string $table + * @return bool + */ + public function hasTable($table) + { + $sql = $this->grammar->compileTableExists(); + + $table = $this->connection->getTablePrefix().$table; + + return count($this->connection->select($sql, array($table))) > 0; + } + + /** + * Determine if the given table has a given column. + * + * @param string $table + * @param string $column + * @return bool + */ + public function hasColumn($table, $column) + { + $column = strtolower($column); + + return in_array($column, array_map('strtolower', $this->getColumnListing($table))); + } + + /** + * Determine if the given table has given columns. + * + * @param string $table + * @param array $columns + * @return bool + */ + public function hasColumns($table, array $columns) + { + $tableColumns = array_map('strtolower', $this->getColumnListing($table)); + + foreach ($columns as $column) + { + if ( ! in_array(strtolower($column), $tableColumns)) return false; + } + + return true; + } + + /** + * Get the column listing for a given table. + * + * @param string $table + * @return array + */ + public function getColumnListing($table) + { + $table = $this->connection->getTablePrefix().$table; + + $results = $this->connection->select($this->grammar->compileColumnExists($table)); + + return $this->connection->getPostProcessor()->processColumnListing($results); + } + + /** + * Modify a table on the schema. + * + * @param string $table + * @param \Closure $callback + * @return \Illuminate\Database\Schema\Blueprint + */ + public function table($table, Closure $callback) + { + $this->build($this->createBlueprint($table, $callback)); + } + + /** + * Create a new table on the schema. + * + * @param string $table + * @param \Closure $callback + * @return \Illuminate\Database\Schema\Blueprint + */ + public function create($table, Closure $callback) + { + $blueprint = $this->createBlueprint($table); + + $blueprint->create(); + + $callback($blueprint); + + $this->build($blueprint); + } + + /** + * Drop a table from the schema. + * + * @param string $table + * @return \Illuminate\Database\Schema\Blueprint + */ + public function drop($table) + { + $blueprint = $this->createBlueprint($table); + + $blueprint->drop(); + + $this->build($blueprint); + } + + /** + * Drop a table from the schema if it exists. + * + * @param string $table + * @return \Illuminate\Database\Schema\Blueprint + */ + public function dropIfExists($table) + { + $blueprint = $this->createBlueprint($table); + + $blueprint->dropIfExists(); + + $this->build($blueprint); + } + + /** + * Rename a table on the schema. + * + * @param string $from + * @param string $to + * @return \Illuminate\Database\Schema\Blueprint + */ + public function rename($from, $to) + { + $blueprint = $this->createBlueprint($from); + + $blueprint->rename($to); + + $this->build($blueprint); + } + + /** + * Execute the blueprint to build / modify the table. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @return void + */ + protected function build(Blueprint $blueprint) + { + $blueprint->build($this->connection, $this->grammar); + } + + /** + * Create a new command set with a Closure. + * + * @param string $table + * @param \Closure|null $callback + * @return \Illuminate\Database\Schema\Blueprint + */ + protected function createBlueprint($table, Closure $callback = null) + { + if (isset($this->resolver)) + { + return call_user_func($this->resolver, $table, $callback); + } + + return new Blueprint($table, $callback); + } + + /** + * Get the database connection instance. + * + * @return \Illuminate\Database\Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * Set the database connection instance. + * + * @param \Illuminate\Database\Connection + * @return $this + */ + public function setConnection(Connection $connection) + { + $this->connection = $connection; + + return $this; + } + + /** + * Set the Schema Blueprint resolver callback. + * + * @param \Closure $resolver + * @return void + */ + public function blueprintResolver(Closure $resolver) + { + $this->resolver = $resolver; + } + +} diff --git a/vendor/illuminate/database/Schema/Grammars/Grammar.php b/vendor/illuminate/database/Schema/Grammars/Grammar.php new file mode 100755 index 0000000..5857daa --- /dev/null +++ b/vendor/illuminate/database/Schema/Grammars/Grammar.php @@ -0,0 +1,458 @@ +getDoctrineSchemaManager(); + + $table = $this->getTablePrefix().$blueprint->getTable(); + + $column = $connection->getDoctrineColumn($table, $command->from); + + $tableDiff = $this->getRenamedDiff($blueprint, $command, $column, $schema); + + return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); + } + + /** + * Get a new column instance with the new column name. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @param \Doctrine\DBAL\Schema\Column $column + * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @return \Doctrine\DBAL\Schema\TableDiff + */ + protected function getRenamedDiff(Blueprint $blueprint, Fluent $command, Column $column, SchemaManager $schema) + { + $tableDiff = $this->getDoctrineTableDiff($blueprint, $schema); + + return $this->setRenamedColumns($tableDiff, $command, $column); + } + + /** + * Set the renamed columns on the table diff. + * + * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff + * @param \Illuminate\Support\Fluent $command + * @param \Doctrine\DBAL\Schema\Column $column + * @return \Doctrine\DBAL\Schema\TableDiff + */ + protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column) + { + $newColumn = new Column($command->to, $column->getType(), $column->toArray()); + + $tableDiff->renamedColumns = array($command->from => $newColumn); + + return $tableDiff; + } + + /** + * Compile a foreign key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileForeign(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $on = $this->wrapTable($command->on); + + // We need to prepare several of the elements of the foreign key definition + // before we can create the SQL, such as wrapping the tables and convert + // an array of columns to comma-delimited strings for the SQL queries. + $columns = $this->columnize($command->columns); + + $onColumns = $this->columnize((array) $command->references); + + $sql = "alter table {$table} add constraint {$command->index} "; + + $sql .= "foreign key ({$columns}) references {$on} ({$onColumns})"; + + // Once we have the basic foreign key creation statement constructed we can + // build out the syntax for what should happen on an update or delete of + // the affected columns, which will get something like "cascade", etc. + if ( ! is_null($command->onDelete)) + { + $sql .= " on delete {$command->onDelete}"; + } + + if ( ! is_null($command->onUpdate)) + { + $sql .= " on update {$command->onUpdate}"; + } + + return $sql; + } + + /** + * Compile the blueprint's column definitions. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @return array + */ + protected function getColumns(Blueprint $blueprint) + { + $columns = array(); + + foreach ($blueprint->getAddedColumns() as $column) + { + // Each of the column types have their own compiler functions which are tasked + // with turning the column definition into its SQL format for this platform + // used by the connection. The column's modifiers are compiled and added. + $sql = $this->wrap($column).' '.$this->getType($column); + + $columns[] = $this->addModifiers($sql, $blueprint, $column); + } + + return $columns; + } + + /** + * Add the column modifiers to the definition. + * + * @param string $sql + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function addModifiers($sql, Blueprint $blueprint, Fluent $column) + { + foreach ($this->modifiers as $modifier) + { + if (method_exists($this, $method = "modify{$modifier}")) + { + $sql .= $this->{$method}($blueprint, $column); + } + } + + return $sql; + } + + /** + * Get the primary key command if it exists on the blueprint. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param string $name + * @return \Illuminate\Support\Fluent|null + */ + protected function getCommandByName(Blueprint $blueprint, $name) + { + $commands = $this->getCommandsByName($blueprint, $name); + + if (count($commands) > 0) + { + return reset($commands); + } + } + + /** + * Get all of the commands with a given name. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param string $name + * @return array + */ + protected function getCommandsByName(Blueprint $blueprint, $name) + { + return array_filter($blueprint->getCommands(), function($value) use ($name) + { + return $value->name == $name; + }); + } + + /** + * Get the SQL for the column data type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function getType(Fluent $column) + { + return $this->{"type".ucfirst($column->type)}($column); + } + + /** + * Add a prefix to an array of values. + * + * @param string $prefix + * @param array $values + * @return array + */ + public function prefixArray($prefix, array $values) + { + return array_map(function($value) use ($prefix) + { + return $prefix.' '.$value; + + }, $values); + } + + /** + * Wrap a table in keyword identifiers. + * + * @param mixed $table + * @return string + */ + public function wrapTable($table) + { + if ($table instanceof Blueprint) $table = $table->getTable(); + + return parent::wrapTable($table); + } + + /** + * {@inheritdoc} + */ + public function wrap($value, $prefixAlias = false) + { + if ($value instanceof Fluent) $value = $value->name; + + return parent::wrap($value, $prefixAlias); + } + + /** + * Format a value so that it can be used in "default" clauses. + * + * @param mixed $value + * @return string + */ + protected function getDefaultValue($value) + { + if ($value instanceof Expression) return $value; + + if (is_bool($value)) return "'".(int) $value."'"; + + return "'".strval($value)."'"; + } + + /** + * Create an empty Doctrine DBAL TableDiff from the Blueprint. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @return \Doctrine\DBAL\Schema\TableDiff + */ + protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema) + { + $table = $this->getTablePrefix().$blueprint->getTable(); + + $tableDiff = new TableDiff($table); + + $tableDiff->fromTable = $schema->listTableDetails($table); + + return $tableDiff; + } + + /** + * Compile a change column command into a series of SQL statements. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @param \Illuminate\Database\Connection $connection + * @return array + */ + public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection) + { + $schema = $connection->getDoctrineSchemaManager(); + + $tableDiff = $this->getChangedDiff($blueprint, $schema); + + if ($tableDiff !== false) + { + return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); + } + + return []; + } + + /** + * Get the Doctrine table difference for the given changes. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @return \Doctrine\DBAL\Schema\TableDiff|bool + */ + protected function getChangedDiff(Blueprint $blueprint, SchemaManager $schema) + { + $table = $schema->listTableDetails($this->getTablePrefix().$blueprint->getTable()); + + return (new Comparator)->diffTable($table, $this->getTableWithColumnChanges($blueprint, $table)); + } + + /** + * Get a copy of the given Doctrine table after making the column changes. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Doctrine\DBAL\Schema\Table $table + * @return \Doctrine\DBAL\Schema\TableDiff + */ + protected function getTableWithColumnChanges(Blueprint $blueprint, Table $table) + { + $table = clone $table; + + foreach($blueprint->getChangedColumns() as $fluent) + { + $column = $this->getDoctrineColumnForChange($table, $fluent); + + // Here we will spin through each fluent column definition and map it to the proper + // Doctrine column definitions, which is necessasry because Laravel and Doctrine + // use some different terminology for various column attributes on the tables. + foreach ($fluent->getAttributes() as $key => $value) + { + if ( ! is_null($option = $this->mapFluentOptionToDoctrine($key))) + { + if (method_exists($column, $method = 'set'.ucfirst($option))) + { + $column->{$method}($this->mapFluentValueToDoctrine($option, $value)); + } + } + } + } + + return $table; + } + + /** + * Get the Doctrine column instance for a column change. + * + * @param \Doctrine\DBAL\Schema\Table $table + * @param \Illuminate\Support\Fluent $fluent + * @return \Doctrine\DBAL\Schema\Column + */ + protected function getDoctrineColumnForChange(Table $table, Fluent $fluent) + { + return $table->changeColumn( + $fluent['name'], $this->getDoctrineColumnChangeOptions($fluent) + )->getColumn($fluent['name']); + } + + /** + * Get the Doctrine column change options. + * + * @param \Illuminate\Support\Fluent $fluent + * @return array + */ + protected function getDoctrineColumnChangeOptions(Fluent $fluent) + { + $options = ['type' => $this->getDoctrineColumnType($fluent['type'])]; + + if (in_array($fluent['type'], ['text', 'mediumText', 'longText'])) + { + $options['length'] = $this->calculateDoctrineTextLength($fluent['type']); + } + + return $options; + } + + /** + * Get the doctrine column type. + * + * @param string $type + * @return \Doctrine\DBAL\Types\Type + */ + protected function getDoctrineColumnType($type) + { + $type = strtolower($type); + + switch ($type) { + case 'biginteger': + $type = 'bigint'; + break; + case 'smallinteger': + $type = 'smallint'; + break; + case 'mediumtext': + case 'longtext': + $type = 'text'; + break; + } + + return Type::getType($type); + } + + /** + * Calculate the proper column length to force the Doctrine text type. + * + * @param string $type + * @return int + */ + protected function calculateDoctrineTextLength($type) + { + switch ($type) + { + case 'mediumText': + return 65535 + 1; + + case 'longText': + return 16777215 + 1; + + default: + return 255 + 1; + } + } + + /** + * Get the matching Doctrine option for a given Fluent attribute name. + * + * @param string $attribute + * @return string + */ + protected function mapFluentOptionToDoctrine($attribute) + { + switch($attribute) + { + case 'type': + case 'name': + return; + + case 'nullable': + return 'notnull'; + + case 'total': + return 'precision'; + + case 'places': + return 'scale'; + + default: + return $attribute; + } + } + + /** + * Get the matching Doctrine value for a given Fluent attribute. + * + * @param string $option + * @param mixed $value + * @return mixed + */ + protected function mapFluentValueToDoctrine($option, $value) + { + return $option == 'notnull' ? ! $value : $value; + } + +} diff --git a/vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php b/vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php new file mode 100755 index 0000000..014dd8a --- /dev/null +++ b/vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php @@ -0,0 +1,652 @@ +getColumns($blueprint)); + + $sql = 'create table '.$this->wrapTable($blueprint)." ($columns)"; + + // Once we have the primary SQL, we can add the encoding option to the SQL for + // the table. Then, we can check if a storage engine has been supplied for + // the table. If so, we will add the engine declaration to the SQL query. + $sql = $this->compileCreateEncoding($sql, $connection); + + if (isset($blueprint->engine)) + { + $sql .= ' engine = '.$blueprint->engine; + } + + return $sql; + } + + /** + * Append the character set specifications to a command. + * + * @param string $sql + * @param \Illuminate\Database\Connection $connection + * @return string + */ + protected function compileCreateEncoding($sql, Connection $connection) + { + if ( ! is_null($charset = $connection->getConfig('charset'))) + { + $sql .= ' default character set '.$charset; + } + + if ( ! is_null($collation = $connection->getConfig('collation'))) + { + $sql .= ' collate '.$collation; + } + + return $sql; + } + + /** + * Compile an add column command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileAdd(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $columns = $this->prefixArray('add', $this->getColumns($blueprint)); + + return 'alter table '.$table.' '.implode(', ', $columns); + } + + /** + * Compile a primary key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compilePrimary(Blueprint $blueprint, Fluent $command) + { + $command->name(null); + + return $this->compileKey($blueprint, $command, 'primary key'); + } + + /** + * Compile a unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileUnique(Blueprint $blueprint, Fluent $command) + { + return $this->compileKey($blueprint, $command, 'unique'); + } + + /** + * Compile a plain index key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileIndex(Blueprint $blueprint, Fluent $command) + { + return $this->compileKey($blueprint, $command, 'index'); + } + + /** + * Compile an index creation command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @param string $type + * @return string + */ + protected function compileKey(Blueprint $blueprint, Fluent $command, $type) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "alter table {$table} add {$type} {$command->index}($columns)"; + } + + /** + * Compile a drop table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDrop(Blueprint $blueprint, Fluent $command) + { + return 'drop table '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop table (if exists) command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIfExists(Blueprint $blueprint, Fluent $command) + { + return 'drop table if exists '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop column command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropColumn(Blueprint $blueprint, Fluent $command) + { + $columns = $this->prefixArray('drop', $this->wrapArray($command->columns)); + + $table = $this->wrapTable($blueprint); + + return 'alter table '.$table.' '.implode(', ', $columns); + } + + /** + * Compile a drop primary key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropPrimary(Blueprint $blueprint, Fluent $command) + { + return 'alter table '.$this->wrapTable($blueprint).' drop primary key'; + } + + /** + * Compile a drop unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropUnique(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop index {$command->index}"; + } + + /** + * Compile a drop index command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIndex(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop index {$command->index}"; + } + + /** + * Compile a drop foreign key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropForeign(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop foreign key {$command->index}"; + } + + /** + * Compile a rename table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileRename(Blueprint $blueprint, Fluent $command) + { + $from = $this->wrapTable($blueprint); + + return "rename table {$from} to ".$this->wrapTable($command->to); + } + + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return "char({$column->length})"; + } + + /** + * Create the column definition for a string type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeString(Fluent $column) + { + return "varchar({$column->length})"; + } + + /** + * Create the column definition for a text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a medium text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumText(Fluent $column) + { + return 'mediumtext'; + } + + /** + * Create the column definition for a long text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeLongText(Fluent $column) + { + return 'longtext'; + } + + /** + * Create the column definition for a big integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBigInteger(Fluent $column) + { + return 'bigint'; + } + + /** + * Create the column definition for a integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeInteger(Fluent $column) + { + return 'int'; + } + + /** + * Create the column definition for a medium integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumInteger(Fluent $column) + { + return 'mediumint'; + } + + /** + * Create the column definition for a tiny integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTinyInteger(Fluent $column) + { + return 'tinyint'; + } + + /** + * Create the column definition for a small integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeSmallInteger(Fluent $column) + { + return 'smallint'; + } + + /** + * Create the column definition for a float type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeFloat(Fluent $column) + { + return $this->typeDouble($column); + } + + /** + * Create the column definition for a double type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDouble(Fluent $column) + { + if ($column->total && $column->places) + { + return "double({$column->total}, {$column->places})"; + } + + return 'double'; + } + + /** + * Create the column definition for a decimal type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDecimal(Fluent $column) + { + return "decimal({$column->total}, {$column->places})"; + } + + /** + * Create the column definition for a boolean type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBoolean(Fluent $column) + { + return 'tinyint(1)'; + } + + /** + * Create the column definition for an enum type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeEnum(Fluent $column) + { + return "enum('".implode("', '", $column->allowed)."')"; + } + + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a jsonb type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJsonb(Fluent $column) + { + return "text"; + } + + /** + * Create the column definition for a date type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDate(Fluent $column) + { + return 'date'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTime(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTimeTz(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTime(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimeTz(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestamp(Fluent $column) + { + if ( ! $column->nullable) return 'timestamp default 0'; + + return 'timestamp'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestampTz(Fluent $column) + { + if ( ! $column->nullable) return 'timestamp default 0'; + + return 'timestamp'; + } + + /** + * Create the column definition for a binary type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBinary(Fluent $column) + { + return 'blob'; + } + + /** + * Get the SQL for an unsigned column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyUnsigned(Blueprint $blueprint, Fluent $column) + { + if ($column->unsigned) return ' unsigned'; + } + + /** + * Get the SQL for a nullable column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyNullable(Blueprint $blueprint, Fluent $column) + { + return $column->nullable ? ' null' : ' not null'; + } + + /** + * Get the SQL for a default column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyDefault(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->default)) + { + return " default ".$this->getDefaultValue($column->default); + } + } + + /** + * Get the SQL for an auto-increment column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyIncrement(Blueprint $blueprint, Fluent $column) + { + if (in_array($column->type, $this->serials) && $column->autoIncrement) + { + return ' auto_increment primary key'; + } + } + + /** + * Get the SQL for an "after" column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyAfter(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->after)) + { + return ' after '.$this->wrap($column->after); + } + } + + /** + * Get the SQL for an "comment" column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyComment(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->comment)) + { + return ' comment "'.$column->comment.'"'; + } + } + + /** + * Wrap a single string in keyword identifiers. + * + * @param string $value + * @return string + */ + protected function wrapValue($value) + { + if ($value === '*') return $value; + + return '`'.str_replace('`', '``', $value).'`'; + } + +} diff --git a/vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php b/vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php new file mode 100755 index 0000000..b24d99d --- /dev/null +++ b/vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php @@ -0,0 +1,544 @@ +getColumns($blueprint)); + + return 'create table '.$this->wrapTable($blueprint)." ($columns)"; + } + + /** + * Compile a create table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileAdd(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $columns = $this->prefixArray('add column', $this->getColumns($blueprint)); + + return 'alter table '.$table.' '.implode(', ', $columns); + } + + /** + * Compile a primary key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compilePrimary(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + return 'alter table '.$this->wrapTable($blueprint)." add primary key ({$columns})"; + } + + /** + * Compile a unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileUnique(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $columns = $this->columnize($command->columns); + + return "alter table $table add constraint {$command->index} unique ($columns)"; + } + + /** + * Compile a plain index key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileIndex(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + return "create index {$command->index} on ".$this->wrapTable($blueprint)." ({$columns})"; + } + + /** + * Compile a drop table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDrop(Blueprint $blueprint, Fluent $command) + { + return 'drop table '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop table (if exists) command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIfExists(Blueprint $blueprint, Fluent $command) + { + return 'drop table if exists '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop column command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropColumn(Blueprint $blueprint, Fluent $command) + { + $columns = $this->prefixArray('drop column', $this->wrapArray($command->columns)); + + $table = $this->wrapTable($blueprint); + + return 'alter table '.$table.' '.implode(', ', $columns); + } + + /** + * Compile a drop primary key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropPrimary(Blueprint $blueprint, Fluent $command) + { + $table = $blueprint->getTable(); + + return 'alter table '.$this->wrapTable($blueprint)." drop constraint {$table}_pkey"; + } + + /** + * Compile a drop unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropUnique(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop constraint {$command->index}"; + } + + /** + * Compile a drop index command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIndex(Blueprint $blueprint, Fluent $command) + { + return "drop index {$command->index}"; + } + + /** + * Compile a drop foreign key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropForeign(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop constraint {$command->index}"; + } + + /** + * Compile a rename table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileRename(Blueprint $blueprint, Fluent $command) + { + $from = $this->wrapTable($blueprint); + + return "alter table {$from} rename to ".$this->wrapTable($command->to); + } + + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return "char({$column->length})"; + } + + /** + * Create the column definition for a string type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeString(Fluent $column) + { + return "varchar({$column->length})"; + } + + /** + * Create the column definition for a text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a medium text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a long text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeLongText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeInteger(Fluent $column) + { + return $column->autoIncrement ? 'serial' : 'integer'; + } + + /** + * Create the column definition for a big integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBigInteger(Fluent $column) + { + return $column->autoIncrement ? 'bigserial' : 'bigint'; + } + + /** + * Create the column definition for a medium integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumInteger(Fluent $column) + { + return $column->autoIncrement ? 'serial' : 'integer'; + } + + /** + * Create the column definition for a tiny integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTinyInteger(Fluent $column) + { + return $column->autoIncrement ? 'smallserial' : 'smallint'; + } + + /** + * Create the column definition for a small integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeSmallInteger(Fluent $column) + { + return $column->autoIncrement ? 'smallserial' : 'smallint'; + } + + /** + * Create the column definition for a float type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeFloat(Fluent $column) + { + return $this->typeDouble($column); + } + + /** + * Create the column definition for a double type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDouble(Fluent $column) + { + return 'double precision'; + } + + /** + * Create the column definition for a decimal type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDecimal(Fluent $column) + { + return "decimal({$column->total}, {$column->places})"; + } + + /** + * Create the column definition for a boolean type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBoolean(Fluent $column) + { + return 'boolean'; + } + + /** + * Create the column definition for an enum type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeEnum(Fluent $column) + { + $allowed = array_map(function($a) { return "'".$a."'"; }, $column->allowed); + + return "varchar(255) check (\"{$column->name}\" in (".implode(', ', $allowed)."))"; + } + + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return "json"; + } + + /** + * Create the column definition for a jsonb type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJsonb(Fluent $column) + { + return "jsonb"; + } + + /** + * Create the column definition for a date type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDate(Fluent $column) + { + return 'date'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTime(Fluent $column) + { + return 'timestamp(0) without time zone'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTimeTz(Fluent $column) + { + return 'timestamp(0) with time zone'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTime(Fluent $column) + { + return 'time(0) without time zone'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimeTz(Fluent $column) + { + return 'time(0) with time zone'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestamp(Fluent $column) + { + return 'timestamp(0) without time zone'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestampTz(Fluent $column) + { + return 'timestamp(0) with time zone'; + } + + /** + * Create the column definition for a binary type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBinary(Fluent $column) + { + return 'bytea'; + } + + /** + * Get the SQL for a nullable column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyNullable(Blueprint $blueprint, Fluent $column) + { + return $column->nullable ? ' null' : ' not null'; + } + + /** + * Get the SQL for a default column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyDefault(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->default)) + { + return " default ".$this->getDefaultValue($column->default); + } + } + + /** + * Get the SQL for an auto-increment column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyIncrement(Blueprint $blueprint, Fluent $column) + { + if (in_array($column->type, $this->serials) && $column->autoIncrement) + { + return ' primary key'; + } + } + +} diff --git a/vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php b/vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php new file mode 100755 index 0000000..25daa74 --- /dev/null +++ b/vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php @@ -0,0 +1,611 @@ +getColumns($blueprint)); + + $sql = 'create table '.$this->wrapTable($blueprint)." ($columns"; + + // SQLite forces primary keys to be added when the table is initially created + // so we will need to check for a primary key commands and add the columns + // to the table's declaration here so they can be created on the tables. + $sql .= (string) $this->addForeignKeys($blueprint); + + $sql .= (string) $this->addPrimaryKeys($blueprint); + + return $sql.')'; + } + + /** + * Get the foreign key syntax for a table creation statement. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @return string|null + */ + protected function addForeignKeys(Blueprint $blueprint) + { + $sql = ''; + + $foreigns = $this->getCommandsByName($blueprint, 'foreign'); + + // Once we have all the foreign key commands for the table creation statement + // we'll loop through each of them and add them to the create table SQL we + // are building, since SQLite needs foreign keys on the tables creation. + foreach ($foreigns as $foreign) + { + $sql .= $this->getForeignKey($foreign); + + if ( ! is_null($foreign->onDelete)) + { + $sql .= " on delete {$foreign->onDelete}"; + } + + if ( ! is_null($foreign->onUpdate)) + { + $sql .= " on update {$foreign->onUpdate}"; + } + } + + return $sql; + } + + /** + * Get the SQL for the foreign key. + * + * @param \Illuminate\Support\Fluent $foreign + * @return string + */ + protected function getForeignKey($foreign) + { + $on = $this->wrapTable($foreign->on); + + // We need to columnize the columns that the foreign key is being defined for + // so that it is a properly formatted list. Once we have done this, we can + // return the foreign key SQL declaration to the calling method for use. + $columns = $this->columnize($foreign->columns); + + $onColumns = $this->columnize((array) $foreign->references); + + return ", foreign key($columns) references $on($onColumns)"; + } + + /** + * Get the primary key syntax for a table creation statement. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @return string|null + */ + protected function addPrimaryKeys(Blueprint $blueprint) + { + $primary = $this->getCommandByName($blueprint, 'primary'); + + if ( ! is_null($primary)) + { + $columns = $this->columnize($primary->columns); + + return ", primary key ({$columns})"; + } + } + + /** + * Compile alter table commands for adding columns. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return array + */ + public function compileAdd(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $columns = $this->prefixArray('add column', $this->getColumns($blueprint)); + + $statements = array(); + + foreach ($columns as $column) + { + $statements[] = 'alter table '.$table.' '.$column; + } + + return $statements; + } + + /** + * Compile a unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileUnique(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "create unique index {$command->index} on {$table} ({$columns})"; + } + + /** + * Compile a plain index key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileIndex(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "create index {$command->index} on {$table} ({$columns})"; + } + + /** + * Compile a foreign key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileForeign(Blueprint $blueprint, Fluent $command) + { + // Handled on table creation... + } + + /** + * Compile a drop table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDrop(Blueprint $blueprint, Fluent $command) + { + return 'drop table '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop table (if exists) command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIfExists(Blueprint $blueprint, Fluent $command) + { + return 'drop table if exists '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop column command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @param \Illuminate\Database\Connection $connection + * @return array + */ + public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection) + { + $schema = $connection->getDoctrineSchemaManager(); + + $tableDiff = $this->getDoctrineTableDiff($blueprint, $schema); + + foreach ($command->columns as $name) + { + $column = $connection->getDoctrineColumn($blueprint->getTable(), $name); + + $tableDiff->removedColumns[$name] = $column; + } + + return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff); + } + + /** + * Compile a drop unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropUnique(Blueprint $blueprint, Fluent $command) + { + return "drop index {$command->index}"; + } + + /** + * Compile a drop index command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIndex(Blueprint $blueprint, Fluent $command) + { + return "drop index {$command->index}"; + } + + /** + * Compile a rename table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileRename(Blueprint $blueprint, Fluent $command) + { + $from = $this->wrapTable($blueprint); + + return "alter table {$from} rename to ".$this->wrapTable($command->to); + } + + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return 'varchar'; + } + + /** + * Create the column definition for a string type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeString(Fluent $column) + { + return 'varchar'; + } + + /** + * Create the column definition for a text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a medium text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a long text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeLongText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeInteger(Fluent $column) + { + return 'integer'; + } + + /** + * Create the column definition for a big integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBigInteger(Fluent $column) + { + return 'integer'; + } + + /** + * Create the column definition for a medium integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumInteger(Fluent $column) + { + return 'integer'; + } + + /** + * Create the column definition for a tiny integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTinyInteger(Fluent $column) + { + return 'integer'; + } + + /** + * Create the column definition for a small integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeSmallInteger(Fluent $column) + { + return 'integer'; + } + + /** + * Create the column definition for a float type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeFloat(Fluent $column) + { + return 'float'; + } + + /** + * Create the column definition for a double type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDouble(Fluent $column) + { + return 'float'; + } + + /** + * Create the column definition for a decimal type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDecimal(Fluent $column) + { + return 'numeric'; + } + + /** + * Create the column definition for a boolean type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBoolean(Fluent $column) + { + return 'tinyint'; + } + + /** + * Create the column definition for an enum type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeEnum(Fluent $column) + { + return 'varchar'; + } + + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a jsonb type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJsonb(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a date type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDate(Fluent $column) + { + return 'date'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTime(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a date-time type. + * + * Note: "SQLite does not have a storage class set aside for storing dates and/or times." + * @link https://www.sqlite.org/datatype3.html + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTimeTz(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTime(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimeTz(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestamp(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestampTz(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a binary type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBinary(Fluent $column) + { + return 'blob'; + } + + /** + * Get the SQL for a nullable column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyNullable(Blueprint $blueprint, Fluent $column) + { + return $column->nullable ? ' null' : ' not null'; + } + + /** + * Get the SQL for a default column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyDefault(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->default)) + { + return " default ".$this->getDefaultValue($column->default); + } + } + + /** + * Get the SQL for an auto-increment column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyIncrement(Blueprint $blueprint, Fluent $column) + { + if (in_array($column->type, $this->serials) && $column->autoIncrement) + { + return ' primary key autoincrement'; + } + } + +} diff --git a/vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php b/vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php new file mode 100755 index 0000000..49f94f1 --- /dev/null +++ b/vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php @@ -0,0 +1,552 @@ +getColumns($blueprint)); + + return 'create table '.$this->wrapTable($blueprint)." ($columns)"; + } + + /** + * Compile a create table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileAdd(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $columns = $this->getColumns($blueprint); + + return 'alter table '.$table.' add '.implode(', ', $columns); + } + + /** + * Compile a primary key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compilePrimary(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "alter table {$table} add constraint {$command->index} primary key ({$columns})"; + } + + /** + * Compile a unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileUnique(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "create unique index {$command->index} on {$table} ({$columns})"; + } + + /** + * Compile a plain index key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileIndex(Blueprint $blueprint, Fluent $command) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "create index {$command->index} on {$table} ({$columns})"; + } + + /** + * Compile a drop table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDrop(Blueprint $blueprint, Fluent $command) + { + return 'drop table '.$this->wrapTable($blueprint); + } + + /** + * Compile a drop table (if exists) command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIfExists(Blueprint $blueprint, Fluent $command) + { + return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \''.$blueprint->getTable().'\') drop table '.$blueprint->getTable(); + } + + /** + * Compile a drop column command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropColumn(Blueprint $blueprint, Fluent $command) + { + $columns = $this->wrapArray($command->columns); + + $table = $this->wrapTable($blueprint); + + return 'alter table '.$table.' drop column '.implode(', ', $columns); + } + + /** + * Compile a drop primary key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropPrimary(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop constraint {$command->index}"; + } + + /** + * Compile a drop unique key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropUnique(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "drop index {$command->index} on {$table}"; + } + + /** + * Compile a drop index command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIndex(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "drop index {$command->index} on {$table}"; + } + + /** + * Compile a drop foreign key command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropForeign(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop constraint {$command->index}"; + } + + /** + * Compile a rename table command. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $command + * @return string + */ + public function compileRename(Blueprint $blueprint, Fluent $command) + { + $from = $this->wrapTable($blueprint); + + return "sp_rename {$from}, ".$this->wrapTable($command->to); + } + + /** + * Create the column definition for a char type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeChar(Fluent $column) + { + return "nchar({$column->length})"; + } + + /** + * Create the column definition for a string type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeString(Fluent $column) + { + return "nvarchar({$column->length})"; + } + + /** + * Create the column definition for a text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeText(Fluent $column) + { + return 'nvarchar(max)'; + } + + /** + * Create the column definition for a medium text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumText(Fluent $column) + { + return 'nvarchar(max)'; + } + + /** + * Create the column definition for a long text type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeLongText(Fluent $column) + { + return 'nvarchar(max)'; + } + + /** + * Create the column definition for a integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeInteger(Fluent $column) + { + return 'int'; + } + + /** + * Create the column definition for a big integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBigInteger(Fluent $column) + { + return 'bigint'; + } + + /** + * Create the column definition for a medium integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeMediumInteger(Fluent $column) + { + return 'int'; + } + + /** + * Create the column definition for a tiny integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTinyInteger(Fluent $column) + { + return 'tinyint'; + } + + /** + * Create the column definition for a small integer type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeSmallInteger(Fluent $column) + { + return 'smallint'; + } + + /** + * Create the column definition for a float type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeFloat(Fluent $column) + { + return 'float'; + } + + /** + * Create the column definition for a double type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDouble(Fluent $column) + { + return 'float'; + } + + /** + * Create the column definition for a decimal type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDecimal(Fluent $column) + { + return "decimal({$column->total}, {$column->places})"; + } + + /** + * Create the column definition for a boolean type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBoolean(Fluent $column) + { + return 'bit'; + } + + /** + * Create the column definition for an enum type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeEnum(Fluent $column) + { + return 'nvarchar(255)'; + } + + /** + * Create the column definition for a json type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJson(Fluent $column) + { + return 'nvarchar(max)'; + } + + /** + * Create the column definition for a jsonb type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeJsonb(Fluent $column) + { + return 'nvarchar(max)'; + } + + /** + * Create the column definition for a date type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDate(Fluent $column) + { + return 'date'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTime(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a date-time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTimeTz(Fluent $column) + { + return 'datetimeoffset(0)'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTime(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a time type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimeTz(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestamp(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a timestamp type. + * + * @link https://msdn.microsoft.com/en-us/library/bb630289(v=sql.120).aspx + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestampTz(Fluent $column) + { + return 'datetimeoffset(0)'; + } + + /** + * Create the column definition for a binary type. + * + * @param \Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBinary(Fluent $column) + { + return 'varbinary(max)'; + } + + /** + * Get the SQL for a nullable column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyNullable(Blueprint $blueprint, Fluent $column) + { + return $column->nullable ? ' null' : ' not null'; + } + + /** + * Get the SQL for a default column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyDefault(Blueprint $blueprint, Fluent $column) + { + if ( ! is_null($column->default)) + { + return " default ".$this->getDefaultValue($column->default); + } + } + + /** + * Get the SQL for an auto-increment column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyIncrement(Blueprint $blueprint, Fluent $column) + { + if (in_array($column->type, $this->serials) && $column->autoIncrement) + { + return ' identity primary key'; + } + } + +} diff --git a/vendor/illuminate/database/Schema/MySqlBuilder.php b/vendor/illuminate/database/Schema/MySqlBuilder.php new file mode 100755 index 0000000..7472681 --- /dev/null +++ b/vendor/illuminate/database/Schema/MySqlBuilder.php @@ -0,0 +1,41 @@ +grammar->compileTableExists(); + + $database = $this->connection->getDatabaseName(); + + $table = $this->connection->getTablePrefix().$table; + + return count($this->connection->select($sql, array($database, $table))) > 0; + } + + /** + * Get the column listing for a given table. + * + * @param string $table + * @return array + */ + public function getColumnListing($table) + { + $sql = $this->grammar->compileColumnExists(); + + $database = $this->connection->getDatabaseName(); + + $table = $this->connection->getTablePrefix().$table; + + $results = $this->connection->select($sql, array($database, $table)); + + return $this->connection->getPostProcessor()->processColumnListing($results); + } + +} diff --git a/vendor/illuminate/database/SeedServiceProvider.php b/vendor/illuminate/database/SeedServiceProvider.php new file mode 100755 index 0000000..26fe80c --- /dev/null +++ b/vendor/illuminate/database/SeedServiceProvider.php @@ -0,0 +1,55 @@ +registerSeedCommand(); + + $this->app->singleton('seeder', function() + { + return new Seeder; + }); + + $this->commands('command.seed'); + } + + /** + * Register the seed console command. + * + * @return void + */ + protected function registerSeedCommand() + { + $this->app->singleton('command.seed', function($app) + { + return new SeedCommand($app['db']); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array('seeder', 'command.seed'); + } + +} diff --git a/vendor/illuminate/database/Seeder.php b/vendor/illuminate/database/Seeder.php new file mode 100755 index 0000000..7fe4c6b --- /dev/null +++ b/vendor/illuminate/database/Seeder.php @@ -0,0 +1,101 @@ +resolve($class)->run(); + + if (isset($this->command)) + { + $this->command->getOutput()->writeln("Seeded: $class"); + } + } + + /** + * Resolve an instance of the given seeder class. + * + * @param string $class + * @return \Illuminate\Database\Seeder + */ + protected function resolve($class) + { + if (isset($this->container)) + { + $instance = $this->container->make($class); + + $instance->setContainer($this->container); + } + else + { + $instance = new $class; + } + + if (isset($this->command)) + { + $instance->setCommand($this->command); + } + + return $instance; + } + + /** + * Set the IoC container instance. + * + * @param \Illuminate\Container\Container $container + * @return $this + */ + public function setContainer(Container $container) + { + $this->container = $container; + + return $this; + } + + /** + * Set the console command instance. + * + * @param \Illuminate\Console\Command $command + * @return $this + */ + public function setCommand(Command $command) + { + $this->command = $command; + + return $this; + } + +} diff --git a/vendor/illuminate/database/SqlServerConnection.php b/vendor/illuminate/database/SqlServerConnection.php new file mode 100755 index 0000000..523f759 --- /dev/null +++ b/vendor/illuminate/database/SqlServerConnection.php @@ -0,0 +1,92 @@ +getDriverName() == 'sqlsrv') + { + return parent::transaction($callback); + } + + $this->pdo->exec('BEGIN TRAN'); + + // We'll simply execute the given callback within a try / catch block + // and if we catch any exception we can rollback the transaction + // so that none of the changes are persisted to the database. + try + { + $result = $callback($this); + + $this->pdo->exec('COMMIT TRAN'); + } + + // If we catch an exception, we will roll back so nothing gets messed + // up in the database. Then we'll re-throw the exception so it can + // be handled how the developer sees fit for their applications. + catch (Exception $e) + { + $this->pdo->exec('ROLLBACK TRAN'); + + throw $e; + } + + return $result; + } + + /** + * Get the default query grammar instance. + * + * @return \Illuminate\Database\Query\Grammars\SqlServerGrammar + */ + protected function getDefaultQueryGrammar() + { + return $this->withTablePrefix(new QueryGrammar); + } + + /** + * Get the default schema grammar instance. + * + * @return \Illuminate\Database\Schema\Grammars\SqlServerGrammar + */ + protected function getDefaultSchemaGrammar() + { + return $this->withTablePrefix(new SchemaGrammar); + } + + /** + * Get the default post processor instance. + * + * @return \Illuminate\Database\Query\Processors\Processor + */ + protected function getDefaultPostProcessor() + { + return new SqlServerProcessor; + } + + /** + * Get the Doctrine DBAL Driver. + * + * @return \Doctrine\DBAL\Driver\PDOSqlsrv\Driver + */ + protected function getDoctrineDriver() + { + return new DoctrineDriver; + } + +} diff --git a/vendor/illuminate/database/composer.json b/vendor/illuminate/database/composer.json new file mode 100755 index 0000000..ac8320c --- /dev/null +++ b/vendor/illuminate/database/composer.json @@ -0,0 +1,41 @@ +{ + "name": "illuminate/database", + "description": "The Illuminate Database package.", + "license": "MIT", + "homepage": "http://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "keywords": ["laravel", "database", "sql", "orm"], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "require": { + "php": ">=5.4.0", + "illuminate/container": "5.0.*", + "illuminate/contracts": "5.0.*", + "illuminate/support": "5.0.*", + "nesbot/carbon": "~1.0" + }, + "autoload": { + "psr-4": { + "Illuminate\\Database\\": "" + } + }, + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "suggest": { + "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).", + "illuminate/console": "Required to use the database commands (5.0.*).", + "illuminate/events": "Required to use the observers with Eloquent (5.0.*).", + "illuminate/filesystem": "Required to use the migrations (5.0.*)." + }, + "minimum-stability": "dev" +} diff --git a/vendor/illuminate/support/AggregateServiceProvider.php b/vendor/illuminate/support/AggregateServiceProvider.php new file mode 100755 index 0000000..26bd250 --- /dev/null +++ b/vendor/illuminate/support/AggregateServiceProvider.php @@ -0,0 +1,53 @@ +instances = []; + + foreach ($this->providers as $provider) + { + $this->instances[] = $this->app->register($provider); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + $provides = []; + + foreach ($this->providers as $provider) + { + $instance = $this->app->resolveProviderClass($provider); + + $provides = array_merge($provides, $instance->provides()); + } + + return $provides; + } + +} diff --git a/vendor/illuminate/support/Arr.php b/vendor/illuminate/support/Arr.php new file mode 100755 index 0000000..e4f6d98 --- /dev/null +++ b/vendor/illuminate/support/Arr.php @@ -0,0 +1,410 @@ + $value) + { + list($innerKey, $innerValue) = call_user_func($callback, $key, $value); + + $results[$innerKey] = $innerValue; + } + + return $results; + } + + /** + * Collapse an array of arrays into a single array. + * + * @param array|\ArrayAccess $array + * @return array + */ + public static function collapse($array) + { + $results = []; + + foreach ($array as $values) + { + if ($values instanceof Collection) $values = $values->all(); + + $results = array_merge($results, $values); + } + + return $results; + } + + /** + * Divide an array into two arrays. One with keys and the other with values. + * + * @param array $array + * @return array + */ + public static function divide($array) + { + return [array_keys($array), array_values($array)]; + } + + /** + * Flatten a multi-dimensional associative array with dots. + * + * @param array $array + * @param string $prepend + * @return array + */ + public static function dot($array, $prepend = '') + { + $results = []; + + foreach ($array as $key => $value) + { + if (is_array($value)) + { + $results = array_merge($results, static::dot($value, $prepend.$key.'.')); + } + else + { + $results[$prepend.$key] = $value; + } + } + + return $results; + } + + /** + * Get all of the given array except for a specified array of items. + * + * @param array $array + * @param array|string $keys + * @return array + */ + public static function except($array, $keys) + { + foreach ((array) $keys as $key) + { + static::forget($array, $key); + } + + return $array; + } + + /** + * Fetch a flattened array of a nested array element. + * + * @param array $array + * @param string $key + * @return array + */ + public static function fetch($array, $key) + { + foreach (explode('.', $key) as $segment) + { + $results = []; + + foreach ($array as $value) + { + if (array_key_exists($segment, $value = (array) $value)) + { + $results[] = $value[$segment]; + } + } + + $array = array_values($results); + } + + return array_values($results); + } + + /** + * Return the first element in an array passing a given truth test. + * + * @param array $array + * @param callable $callback + * @param mixed $default + * @return mixed + */ + public static function first($array, callable $callback, $default = null) + { + foreach ($array as $key => $value) + { + if (call_user_func($callback, $key, $value)) return $value; + } + + return value($default); + } + + /** + * Return the last element in an array passing a given truth test. + * + * @param array $array + * @param callable $callback + * @param mixed $default + * @return mixed + */ + public static function last($array, callable $callback, $default = null) + { + return static::first(array_reverse($array), $callback, $default); + } + + /** + * Flatten a multi-dimensional array into a single level. + * + * @param array $array + * @return array + */ + public static function flatten($array) + { + $return = []; + + array_walk_recursive($array, function($x) use (&$return) { $return[] = $x; }); + + return $return; + } + + /** + * Remove one or many array items from a given array using "dot" notation. + * + * @param array $array + * @param array|string $keys + * @return void + */ + public static function forget(&$array, $keys) + { + $original =& $array; + + foreach ((array) $keys as $key) + { + $parts = explode('.', $key); + + while (count($parts) > 1) + { + $part = array_shift($parts); + + if (isset($array[$part]) && is_array($array[$part])) + { + $array =& $array[$part]; + } + } + + unset($array[array_shift($parts)]); + + // clean up after each pass + $array =& $original; + } + } + + /** + * Get an item from an array using "dot" notation. + * + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed + */ + public static function get($array, $key, $default = null) + { + if (is_null($key)) return $array; + + if (isset($array[$key])) return $array[$key]; + + foreach (explode('.', $key) as $segment) + { + if ( ! is_array($array) || ! array_key_exists($segment, $array)) + { + return value($default); + } + + $array = $array[$segment]; + } + + return $array; + } + + /** + * Check if an item exists in an array using "dot" notation. + * + * @param array $array + * @param string $key + * @return bool + */ + public static function has($array, $key) + { + if (empty($array) || is_null($key)) return false; + + if (array_key_exists($key, $array)) return true; + + foreach (explode('.', $key) as $segment) + { + if ( ! is_array($array) || ! array_key_exists($segment, $array)) + { + return false; + } + + $array = $array[$segment]; + } + + return true; + } + + /** + * Get a subset of the items from the given array. + * + * @param array $array + * @param array|string $keys + * @return array + */ + public static function only($array, $keys) + { + return array_intersect_key($array, array_flip((array) $keys)); + } + + /** + * Pluck an array of values from an array. + * + * @param array $array + * @param string $value + * @param string $key + * @return array + */ + public static function pluck($array, $value, $key = null) + { + $results = []; + + foreach ($array as $item) + { + $itemValue = data_get($item, $value); + + // If the key is "null", we will just append the value to the array and keep + // looping. Otherwise we will key the array using the value of the key we + // received from the developer. Then we'll return the final array form. + if (is_null($key)) + { + $results[] = $itemValue; + } + else + { + $itemKey = data_get($item, $key); + + $results[$itemKey] = $itemValue; + } + } + + return $results; + } + + /** + * Get a value from the array, and remove it. + * + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed + */ + public static function pull(&$array, $key, $default = null) + { + $value = static::get($array, $key, $default); + + static::forget($array, $key); + + return $value; + } + + /** + * Set an array item to a given value using "dot" notation. + * + * If no key is given to the method, the entire array will be replaced. + * + * @param array $array + * @param string $key + * @param mixed $value + * @return array + */ + public static function set(&$array, $key, $value) + { + if (is_null($key)) return $array = $value; + + $keys = explode('.', $key); + + while (count($keys) > 1) + { + $key = array_shift($keys); + + // If the key doesn't exist at this depth, we will just create an empty array + // to hold the next value, allowing us to create the arrays to hold final + // values at the correct depth. Then we'll keep digging into the array. + if ( ! isset($array[$key]) || ! is_array($array[$key])) + { + $array[$key] = []; + } + + $array =& $array[$key]; + } + + $array[array_shift($keys)] = $value; + + return $array; + } + + /** + * Sort the array using the given callback. + * + * @param array $array + * @param callable $callback + * @return array + */ + public static function sort($array, callable $callback) + { + return Collection::make($array)->sortBy($callback)->all(); + } + + /** + * Filter the array using the given callback. + * + * @param array $array + * @param callable $callback + * @return array + */ + public static function where($array, callable $callback) + { + $filtered = []; + + foreach ($array as $key => $value) + { + if (call_user_func($callback, $key, $value)) $filtered[$key] = $value; + } + + return $filtered; + } + +} diff --git a/vendor/illuminate/support/ClassLoader.php b/vendor/illuminate/support/ClassLoader.php new file mode 100755 index 0000000..88cbde6 --- /dev/null +++ b/vendor/illuminate/support/ClassLoader.php @@ -0,0 +1,107 @@ +getArrayableItems($items); + + $this->items = (array) $items; + } + + /** + * Create a new collection instance if the value isn't one already. + * + * @param mixed $items + * @return static + */ + public static function make($items = null) + { + return new static($items); + } + + /** + * Get all of the items in the collection. + * + * @return array + */ + public function all() + { + return $this->items; + } + + /** + * Collapse the collection of items into a single array. + * + * @return static + */ + public function collapse() + { + return new static(array_collapse($this->items)); + } + + /** + * Determine if an item exists in the collection. + * + * @param mixed $key + * @param mixed $value + * @return bool + */ + public function contains($key, $value = null) + { + if (func_num_args() == 2) + { + return $this->contains(function($k, $item) use ($key, $value) + { + return data_get($item, $key) == $value; + }); + } + + if ($this->useAsCallable($key)) + { + return ! is_null($this->first($key)); + } + + return in_array($key, $this->items); + } + + /** + * Diff the collection with the given items. + * + * @param \Illuminate\Support\Collection|\Illuminate\Contracts\Support\Arrayable|array $items + * @return static + */ + public function diff($items) + { + return new static(array_diff($this->items, $this->getArrayableItems($items))); + } + + /** + * Execute a callback over each item. + * + * @param callable $callback + * @return $this + */ + public function each(callable $callback) + { + array_map($callback, $this->items); + + return $this; + } + + /** + * Fetch a nested element of the collection. + * + * @param string $key + * @return static + */ + public function fetch($key) + { + return new static(array_fetch($this->items, $key)); + } + + /** + * Run a filter over each of the items. + * + * @param callable $callback + * @return static + */ + public function filter(callable $callback) + { + return new static(array_filter($this->items, $callback)); + } + + /** + * Filter items by the given key value pair. + * + * @param string $key + * @param mixed $value + * @param bool $strict + * @return static + */ + public function where($key, $value, $strict = true) + { + return $this->filter(function($item) use ($key, $value, $strict) + { + return $strict ? data_get($item, $key) === $value + : data_get($item, $key) == $value; + }); + } + + /** + * Filter items by the given key value pair using loose comparison. + * + * @param string $key + * @param mixed $value + * @return static + */ + public function whereLoose($key, $value) + { + return $this->where($key, $value, false); + } + + /** + * Get the first item from the collection. + * + * @param callable $callback + * @param mixed $default + * @return mixed|null + */ + public function first(callable $callback = null, $default = null) + { + if (is_null($callback)) + { + return count($this->items) > 0 ? reset($this->items) : null; + } + + return array_first($this->items, $callback, $default); + } + + /** + * Get a flattened array of the items in the collection. + * + * @return static + */ + public function flatten() + { + return new static(array_flatten($this->items)); + } + + /** + * Flip the items in the collection. + * + * @return static + */ + public function flip() + { + return new static(array_flip($this->items)); + } + + /** + * Remove an item from the collection by key. + * + * @param mixed $key + * @return void + */ + public function forget($key) + { + $this->offsetUnset($key); + } + + /** + * Get an item from the collection by key. + * + * @param mixed $key + * @param mixed $default + * @return mixed + */ + public function get($key, $default = null) + { + if ($this->offsetExists($key)) + { + return $this->items[$key]; + } + + return value($default); + } + + /** + * Group an associative array by a field or using a callback. + * + * @param callable|string $groupBy + * @return static + */ + public function groupBy($groupBy) + { + if ( ! $this->useAsCallable($groupBy)) + { + return $this->groupBy($this->valueRetriever($groupBy)); + } + + $results = []; + + foreach ($this->items as $key => $value) + { + $results[$groupBy($value, $key)][] = $value; + } + + return new static($results); + } + + /** + * Key an associative array by a field or using a callback. + * + * @param callable|string $keyBy + * @return static + */ + public function keyBy($keyBy) + { + if ( ! $this->useAsCallable($keyBy)) + { + return $this->keyBy($this->valueRetriever($keyBy)); + } + + $results = []; + + foreach ($this->items as $item) + { + $results[$keyBy($item)] = $item; + } + + return new static($results); + } + + /** + * Determine if an item exists in the collection by key. + * + * @param mixed $key + * @return bool + */ + public function has($key) + { + return $this->offsetExists($key); + } + + /** + * Concatenate values of a given key as a string. + * + * @param string $value + * @param string $glue + * @return string + */ + public function implode($value, $glue = null) + { + $first = $this->first(); + + if (is_array($first) || is_object($first)) + { + return implode($glue, $this->lists($value)); + } + + return implode($value, $this->items); + } + + /** + * Intersect the collection with the given items. + * + * @param \Illuminate\Support\Collection|\Illuminate\Contracts\Support\Arrayable|array $items + * @return static + */ + public function intersect($items) + { + return new static(array_intersect($this->items, $this->getArrayableItems($items))); + } + + /** + * Determine if the collection is empty or not. + * + * @return bool + */ + public function isEmpty() + { + return empty($this->items); + } + + /** + * Determine if the given value is callable, but not a string. + * + * @param mixed $value + * @return bool + */ + protected function useAsCallable($value) + { + return ! is_string($value) && is_callable($value); + } + + /** + * Get the keys of the collection items. + * + * @return static + */ + public function keys() + { + return new static(array_keys($this->items)); + } + + /** + * Get the last item from the collection. + * + * @return mixed|null + */ + public function last() + { + return count($this->items) > 0 ? end($this->items) : null; + } + + /** + * Get an array with the values of a given key. + * + * @param string $value + * @param string $key + * @return array + */ + public function lists($value, $key = null) + { + return array_pluck($this->items, $value, $key); + } + + /** + * Run a map over each of the items. + * + * @param callable $callback + * @return static + */ + public function map(callable $callback) + { + return new static(array_map($callback, $this->items, array_keys($this->items))); + } + + /** + * Merge the collection with the given items. + * + * @param \Illuminate\Support\Collection|\Illuminate\Contracts\Support\Arrayable|array $items + * @return static + */ + public function merge($items) + { + return new static(array_merge($this->items, $this->getArrayableItems($items))); + } + + /** + * "Paginate" the collection by slicing it into a smaller collection. + * + * @param int $page + * @param int $perPage + * @return static + */ + public function forPage($page, $perPage) + { + return $this->slice(($page - 1) * $perPage, $perPage); + } + + /** + * Get and remove the last item from the collection. + * + * @return mixed|null + */ + public function pop() + { + return array_pop($this->items); + } + + /** + * Push an item onto the beginning of the collection. + * + * @param mixed $value + * @return void + */ + public function prepend($value) + { + array_unshift($this->items, $value); + } + + /** + * Push an item onto the end of the collection. + * + * @param mixed $value + * @return void + */ + public function push($value) + { + $this->offsetSet(null, $value); + } + + /** + * Pulls an item from the collection. + * + * @param mixed $key + * @param mixed $default + * @return mixed + */ + public function pull($key, $default = null) + { + return array_pull($this->items, $key, $default); + } + + /** + * Put an item in the collection by key. + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function put($key, $value) + { + $this->offsetSet($key, $value); + } + + /** + * Get one or more items randomly from the collection. + * + * @param int $amount + * @return mixed + */ + public function random($amount = 1) + { + if ($this->isEmpty()) return; + + $keys = array_rand($this->items, $amount); + + return is_array($keys) ? array_intersect_key($this->items, array_flip($keys)) : $this->items[$keys]; + } + + /** + * Reduce the collection to a single value. + * + * @param callable $callback + * @param mixed $initial + * @return mixed + */ + public function reduce(callable $callback, $initial = null) + { + return array_reduce($this->items, $callback, $initial); + } + + /** + * Create a collection of all elements that do not pass a given truth test. + * + * @param callable|mixed $callback + * @return static + */ + public function reject($callback) + { + if ($this->useAsCallable($callback)) + { + return $this->filter(function($item) use ($callback) + { + return ! $callback($item); + }); + } + + return $this->filter(function($item) use ($callback) + { + return $item != $callback; + }); + } + + /** + * Reverse items order. + * + * @return static + */ + public function reverse() + { + return new static(array_reverse($this->items)); + } + + /** + * Search the collection for a given value and return the corresponding key if successful. + * + * @param mixed $value + * @param bool $strict + * @return mixed + */ + public function search($value, $strict = false) + { + if ( ! $this->useAsCallable($value)) + { + return array_search($value, $this->items, $strict); + } + + foreach ($this->items as $key => $item) + { + if ($value($item, $key)) return $key; + } + + return false; + } + + /** + * Get and remove the first item from the collection. + * + * @return mixed|null + */ + public function shift() + { + return array_shift($this->items); + } + + /** + * Shuffle the items in the collection. + * + * @return $this + */ + public function shuffle() + { + shuffle($this->items); + + return $this; + } + + /** + * Slice the underlying collection array. + * + * @param int $offset + * @param int $length + * @param bool $preserveKeys + * @return static + */ + public function slice($offset, $length = null, $preserveKeys = false) + { + return new static(array_slice($this->items, $offset, $length, $preserveKeys)); + } + + /** + * Chunk the underlying collection array. + * + * @param int $size + * @param bool $preserveKeys + * @return static + */ + public function chunk($size, $preserveKeys = false) + { + $chunks = []; + + foreach (array_chunk($this->items, $size, $preserveKeys) as $chunk) + { + $chunks[] = new static($chunk); + } + + return new static($chunks); + } + + /** + * Sort through each item with a callback. + * + * @param callable $callback + * @return $this + */ + public function sort(callable $callback) + { + uasort($this->items, $callback); + + return $this; + } + + /** + * Sort the collection using the given callback. + * + * @param callable|string $callback + * @param int $options + * @param bool $descending + * @return $this + */ + public function sortBy($callback, $options = SORT_REGULAR, $descending = false) + { + $results = []; + + if ( ! $this->useAsCallable($callback)) + { + $callback = $this->valueRetriever($callback); + } + + // First we will loop through the items and get the comparator from a callback + // function which we were given. Then, we will sort the returned values and + // and grab the corresponding values for the sorted keys from this array. + foreach ($this->items as $key => $value) + { + $results[$key] = $callback($value, $key); + } + + $descending ? arsort($results, $options) + : asort($results, $options); + + // Once we have sorted all of the keys in the array, we will loop through them + // and grab the corresponding model so we can set the underlying items list + // to the sorted version. Then we'll just return the collection instance. + foreach (array_keys($results) as $key) + { + $results[$key] = $this->items[$key]; + } + + $this->items = $results; + + return $this; + } + + /** + * Sort the collection in descending order using the given callback. + * + * @param callable|string $callback + * @param int $options + * @return $this + */ + public function sortByDesc($callback, $options = SORT_REGULAR) + { + return $this->sortBy($callback, $options, true); + } + + /** + * Splice portion of the underlying collection array. + * + * @param int $offset + * @param int $length + * @param mixed $replacement + * @return static + */ + public function splice($offset, $length = 0, $replacement = []) + { + return new static(array_splice($this->items, $offset, $length, $replacement)); + } + + /** + * Get the sum of the given values. + * + * @param callable|string|null $callback + * @return mixed + */ + public function sum($callback = null) + { + if (is_null($callback)) + { + return array_sum($this->items); + } + + if ( ! $this->useAsCallable($callback)) + { + $callback = $this->valueRetriever($callback); + } + + return $this->reduce(function($result, $item) use ($callback) + { + return $result += $callback($item); + }, 0); + } + + /** + * Take the first or last {$limit} items. + * + * @param int $limit + * @return static + */ + public function take($limit = null) + { + if ($limit < 0) return $this->slice($limit, abs($limit)); + + return $this->slice(0, $limit); + } + + /** + * Transform each item in the collection using a callback. + * + * @param callable $callback + * @return $this + */ + public function transform(callable $callback) + { + $this->items = array_map($callback, $this->items); + + return $this; + } + + /** + * Return only unique items from the collection array. + * + * @return static + */ + public function unique() + { + return new static(array_unique($this->items)); + } + + /** + * Reset the keys on the underlying array. + * + * @return static + */ + public function values() + { + return new static(array_values($this->items)); + } + + /** + * Get a value retrieving callback. + * + * @param string $value + * @return \Closure + */ + protected function valueRetriever($value) + { + return function($item) use ($value) + { + return data_get($item, $value); + }; + } + + /** + * Get the collection of items as a plain array. + * + * @return array + */ + public function toArray() + { + return array_map(function($value) + { + return $value instanceof Arrayable ? $value->toArray() : $value; + + }, $this->items); + } + + /** + * Convert the object into something JSON serializable. + * + * @return array + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * Get the collection of items as JSON. + * + * @param int $options + * @return string + */ + public function toJson($options = 0) + { + return json_encode($this->toArray(), $options); + } + + /** + * Get an iterator for the items. + * + * @return \ArrayIterator + */ + public function getIterator() + { + return new ArrayIterator($this->items); + } + + /** + * Get a CachingIterator instance. + * + * @param int $flags + * @return \CachingIterator + */ + public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING) + { + return new CachingIterator($this->getIterator(), $flags); + } + + /** + * Count the number of items in the collection. + * + * @return int + */ + public function count() + { + return count($this->items); + } + + /** + * Determine if an item exists at an offset. + * + * @param mixed $key + * @return bool + */ + public function offsetExists($key) + { + return array_key_exists($key, $this->items); + } + + /** + * Get an item at a given offset. + * + * @param mixed $key + * @return mixed + */ + public function offsetGet($key) + { + return $this->items[$key]; + } + + /** + * Set the item at a given offset. + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value) + { + if (is_null($key)) + { + $this->items[] = $value; + } + else + { + $this->items[$key] = $value; + } + } + + /** + * Unset the item at a given offset. + * + * @param string $key + * @return void + */ + public function offsetUnset($key) + { + unset($this->items[$key]); + } + + /** + * Convert the collection to its string representation. + * + * @return string + */ + public function __toString() + { + return $this->toJson(); + } + + /** + * Results array of items from Collection or Arrayable. + * + * @param \Illuminate\Support\Collection|\Illuminate\Contracts\Support\Arrayable|array $items + * @return array + */ + protected function getArrayableItems($items) + { + if ($items instanceof Collection) + { + $items = $items->all(); + } + elseif ($items instanceof Arrayable) + { + $items = $items->toArray(); + } + + return $items; + } + +} diff --git a/vendor/illuminate/support/Debug/Dumper.php b/vendor/illuminate/support/Debug/Dumper.php new file mode 100755 index 0000000..f58b7ca --- /dev/null +++ b/vendor/illuminate/support/Debug/Dumper.php @@ -0,0 +1,21 @@ +dump((new VarCloner)->cloneVar($value)); + } + +} diff --git a/vendor/illuminate/support/Debug/HtmlDumper.php b/vendor/illuminate/support/Debug/HtmlDumper.php new file mode 100755 index 0000000..263f5c5 --- /dev/null +++ b/vendor/illuminate/support/Debug/HtmlDumper.php @@ -0,0 +1,28 @@ + 'background-color:#fff; color:#222; line-height:1.2em; font-weight:normal; font:12px Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:100000', + 'num' => 'color:#a71d5d', + 'const' => 'color:#795da3', + 'str' => 'color:#df5000', + 'cchr' => 'color:#222', + 'note' => 'color:#a71d5d', + 'ref' => 'color:#a0a0a0', + 'public' => 'color:#795da3', + 'protected' => 'color:#795da3', + 'private' => 'color:#795da3', + 'meta' => 'color:#b729d9', + 'key' => 'color:#df5000', + 'index' => 'color:#a71d5d', + ); + +} diff --git a/vendor/illuminate/support/Facades/App.php b/vendor/illuminate/support/Facades/App.php new file mode 100755 index 0000000..0ac6479 --- /dev/null +++ b/vendor/illuminate/support/Facades/App.php @@ -0,0 +1,18 @@ +getEngineResolver()->resolve('blade')->getCompiler(); + } + +} diff --git a/vendor/illuminate/support/Facades/Bus.php b/vendor/illuminate/support/Facades/Bus.php new file mode 100755 index 0000000..7b133d1 --- /dev/null +++ b/vendor/illuminate/support/Facades/Bus.php @@ -0,0 +1,18 @@ +cookie($key, null)); + } + + /** + * Retrieve a cookie from the request. + * + * @param string $key + * @param mixed $default + * @return string + */ + public static function get($key = null, $default = null) + { + return static::$app['request']->cookie($key, $default); + } + + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return 'cookie'; + } + +} diff --git a/vendor/illuminate/support/Facades/Crypt.php b/vendor/illuminate/support/Facades/Crypt.php new file mode 100755 index 0000000..ee78888 --- /dev/null +++ b/vendor/illuminate/support/Facades/Crypt.php @@ -0,0 +1,18 @@ +instance(static::getFacadeAccessor(), $instance); + } + + /** + * Initiate a mock expectation on the facade. + * + * @param mixed + * @return \Mockery\Expectation + */ + public static function shouldReceive() + { + $name = static::getFacadeAccessor(); + + if (static::isMock()) + { + $mock = static::$resolvedInstance[$name]; + } + else + { + $mock = static::createFreshMockInstance($name); + } + + return call_user_func_array(array($mock, 'shouldReceive'), func_get_args()); + } + + /** + * Create a fresh mock instance for the given class. + * + * @param string $name + * @return \Mockery\Expectation + */ + protected static function createFreshMockInstance($name) + { + static::$resolvedInstance[$name] = $mock = static::createMockByName($name); + + if (isset(static::$app)) + { + static::$app->instance($name, $mock); + } + + return $mock; + } + + /** + * Create a fresh mock instance for the given class. + * + * @param string $name + * @return \Mockery\Expectation + */ + protected static function createMockByName($name) + { + $class = static::getMockableClass($name); + + return $class ? Mockery::mock($class) : Mockery::mock(); + } + + /** + * Determines whether a mock is set as the instance of the facade. + * + * @return bool + */ + protected static function isMock() + { + $name = static::getFacadeAccessor(); + + return isset(static::$resolvedInstance[$name]) && static::$resolvedInstance[$name] instanceof MockInterface; + } + + /** + * Get the mockable class for the bound instance. + * + * @return string + */ + protected static function getMockableClass() + { + if ($root = static::getFacadeRoot()) return get_class($root); + } + + /** + * Get the root object behind the facade. + * + * @return mixed + */ + public static function getFacadeRoot() + { + return static::resolveFacadeInstance(static::getFacadeAccessor()); + } + + /** + * Get the registered name of the component. + * + * @return string + * + * @throws \RuntimeException + */ + protected static function getFacadeAccessor() + { + throw new RuntimeException("Facade does not implement getFacadeAccessor method."); + } + + /** + * Resolve the facade root instance from the container. + * + * @param string $name + * @return mixed + */ + protected static function resolveFacadeInstance($name) + { + if (is_object($name)) return $name; + + if (isset(static::$resolvedInstance[$name])) + { + return static::$resolvedInstance[$name]; + } + + return static::$resolvedInstance[$name] = static::$app[$name]; + } + + /** + * Clear a resolved facade instance. + * + * @param string $name + * @return void + */ + public static function clearResolvedInstance($name) + { + unset(static::$resolvedInstance[$name]); + } + + /** + * Clear all of the resolved instances. + * + * @return void + */ + public static function clearResolvedInstances() + { + static::$resolvedInstance = array(); + } + + /** + * Get the application instance behind the facade. + * + * @return \Illuminate\Contracts\Foundation\Application + */ + public static function getFacadeApplication() + { + return static::$app; + } + + /** + * Set the application instance. + * + * @param \Illuminate\Contracts\Foundation\Application $app + * @return void + */ + public static function setFacadeApplication($app) + { + static::$app = $app; + } + + /** + * Handle dynamic, static calls to the object. + * + * @param string $method + * @param array $args + * @return mixed + */ + public static function __callStatic($method, $args) + { + $instance = static::getFacadeRoot(); + + switch (count($args)) + { + case 0: + return $instance->$method(); + + case 1: + return $instance->$method($args[0]); + + case 2: + return $instance->$method($args[0], $args[1]); + + case 3: + return $instance->$method($args[0], $args[1], $args[2]); + + case 4: + return $instance->$method($args[0], $args[1], $args[2], $args[3]); + + default: + return call_user_func_array(array($instance, $method), $args); + } + } + +} diff --git a/vendor/illuminate/support/Facades/File.php b/vendor/illuminate/support/Facades/File.php new file mode 100755 index 0000000..122ffb2 --- /dev/null +++ b/vendor/illuminate/support/Facades/File.php @@ -0,0 +1,18 @@ +input($key, $default); + } + + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return 'request'; + } + +} diff --git a/vendor/illuminate/support/Facades/Lang.php b/vendor/illuminate/support/Facades/Lang.php new file mode 100755 index 0000000..5496dfa --- /dev/null +++ b/vendor/illuminate/support/Facades/Lang.php @@ -0,0 +1,18 @@ +connection($name)->getSchemaBuilder(); + } + + /** + * Get the registered name of the component. + * + * @return string + */ + protected static function getFacadeAccessor() + { + return static::$app['db']->connection()->getSchemaBuilder(); + } + +} diff --git a/vendor/illuminate/support/Facades/Session.php b/vendor/illuminate/support/Facades/Session.php new file mode 100755 index 0000000..cde6a87 --- /dev/null +++ b/vendor/illuminate/support/Facades/Session.php @@ -0,0 +1,19 @@ + $value) + { + $this->attributes[$key] = $value; + } + } + + /** + * Get an attribute from the container. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function get($key, $default = null) + { + if (array_key_exists($key, $this->attributes)) + { + return $this->attributes[$key]; + } + + return value($default); + } + + /** + * Get the attributes from the container. + * + * @return array + */ + public function getAttributes() + { + return $this->attributes; + } + + /** + * Convert the Fluent instance to an array. + * + * @return array + */ + public function toArray() + { + return $this->attributes; + } + + /** + * Convert the object into something JSON serializable. + * + * @return array + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * Convert the Fluent instance to JSON. + * + * @param int $options + * @return string + */ + public function toJson($options = 0) + { + return json_encode($this->toArray(), $options); + } + + /** + * Determine if the given offset exists. + * + * @param string $offset + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->{$offset}); + } + + /** + * Get the value for a given offset. + * + * @param string $offset + * @return mixed + */ + public function offsetGet($offset) + { + return $this->{$offset}; + } + + /** + * Set the value at the given offset. + * + * @param string $offset + * @param mixed $value + * @return void + */ + public function offsetSet($offset, $value) + { + $this->{$offset} = $value; + } + + /** + * Unset the value at the given offset. + * + * @param string $offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->{$offset}); + } + + /** + * Handle dynamic calls to the container to set attributes. + * + * @param string $method + * @param array $parameters + * @return $this + */ + public function __call($method, $parameters) + { + $this->attributes[$method] = count($parameters) > 0 ? $parameters[0] : true; + + return $this; + } + + /** + * Dynamically retrieve the value of an attribute. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + return $this->get($key); + } + + /** + * Dynamically set the value of an attribute. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function __set($key, $value) + { + $this->attributes[$key] = $value; + } + + /** + * Dynamically check if an attribute is set. + * + * @param string $key + * @return void + */ + public function __isset($key) + { + return isset($this->attributes[$key]); + } + + /** + * Dynamically unset an attribute. + * + * @param string $key + * @return void + */ + public function __unset($key) + { + unset($this->attributes[$key]); + } + +} diff --git a/vendor/illuminate/support/Manager.php b/vendor/illuminate/support/Manager.php new file mode 100755 index 0000000..aee3c06 --- /dev/null +++ b/vendor/illuminate/support/Manager.php @@ -0,0 +1,142 @@ +app = $app; + } + + /** + * Get the default driver name. + * + * @return string + */ + abstract public function getDefaultDriver(); + + /** + * Get a driver instance. + * + * @param string $driver + * @return mixed + */ + public function driver($driver = null) + { + $driver = $driver ?: $this->getDefaultDriver(); + + // If the given driver has not been created before, we will create the instances + // here and cache it so we can return it next time very quickly. If there is + // already a driver created by this name, we'll just return that instance. + if ( ! isset($this->drivers[$driver])) + { + $this->drivers[$driver] = $this->createDriver($driver); + } + + return $this->drivers[$driver]; + } + + /** + * Create a new driver instance. + * + * @param string $driver + * @return mixed + * + * @throws \InvalidArgumentException + */ + protected function createDriver($driver) + { + $method = 'create'.ucfirst($driver).'Driver'; + + // We'll check to see if a creator method exists for the given driver. If not we + // will check for a custom driver creator, which allows developers to create + // drivers using their own customized driver creator Closure to create it. + if (isset($this->customCreators[$driver])) + { + return $this->callCustomCreator($driver); + } + elseif (method_exists($this, $method)) + { + return $this->$method(); + } + + throw new InvalidArgumentException("Driver [$driver] not supported."); + } + + /** + * Call a custom driver creator. + * + * @param string $driver + * @return mixed + */ + protected function callCustomCreator($driver) + { + return $this->customCreators[$driver]($this->app); + } + + /** + * Register a custom driver creator Closure. + * + * @param string $driver + * @param \Closure $callback + * @return $this + */ + public function extend($driver, Closure $callback) + { + $this->customCreators[$driver] = $callback; + + return $this; + } + + /** + * Get all of the created "drivers". + * + * @return array + */ + public function getDrivers() + { + return $this->drivers; + } + + /** + * Dynamically call the default driver instance. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return call_user_func_array(array($this->driver(), $method), $parameters); + } + +} diff --git a/vendor/illuminate/support/MessageBag.php b/vendor/illuminate/support/MessageBag.php new file mode 100755 index 0000000..770d667 --- /dev/null +++ b/vendor/illuminate/support/MessageBag.php @@ -0,0 +1,314 @@ + $value) + { + $this->messages[$key] = (array) $value; + } + } + + /** + * Get the keys present in the message bag. + * + * @return array + */ + public function keys() + { + return array_keys($this->messages); + } + + /** + * Add a message to the bag. + * + * @param string $key + * @param string $message + * @return $this + */ + public function add($key, $message) + { + if ($this->isUnique($key, $message)) + { + $this->messages[$key][] = $message; + } + + return $this; + } + + /** + * Merge a new array of messages into the bag. + * + * @param \Illuminate\Contracts\Support\MessageProvider|array $messages + * @return $this + */ + public function merge($messages) + { + if ($messages instanceof MessageProvider) + { + $messages = $messages->getMessageBag()->getMessages(); + } + + $this->messages = array_merge_recursive($this->messages, $messages); + + return $this; + } + + /** + * Determine if a key and message combination already exists. + * + * @param string $key + * @param string $message + * @return bool + */ + protected function isUnique($key, $message) + { + $messages = (array) $this->messages; + + return ! isset($messages[$key]) || ! in_array($message, $messages[$key]); + } + + /** + * Determine if messages exist for a given key. + * + * @param string $key + * @return bool + */ + public function has($key = null) + { + return $this->first($key) !== ''; + } + + /** + * Get the first message from the bag for a given key. + * + * @param string $key + * @param string $format + * @return string + */ + public function first($key = null, $format = null) + { + $messages = is_null($key) ? $this->all($format) : $this->get($key, $format); + + return count($messages) > 0 ? $messages[0] : ''; + } + + /** + * Get all of the messages from the bag for a given key. + * + * @param string $key + * @param string $format + * @return array + */ + public function get($key, $format = null) + { + // If the message exists in the container, we will transform it and return + // the message. Otherwise, we'll return an empty array since the entire + // methods is to return back an array of messages in the first place. + if (array_key_exists($key, $this->messages)) + { + return $this->transform($this->messages[$key], $this->checkFormat($format), $key); + } + + return array(); + } + + /** + * Get all of the messages for every key in the bag. + * + * @param string $format + * @return array + */ + public function all($format = null) + { + $format = $this->checkFormat($format); + + $all = array(); + + foreach ($this->messages as $key => $messages) + { + $all = array_merge($all, $this->transform($messages, $format, $key)); + } + + return $all; + } + + /** + * Format an array of messages. + * + * @param array $messages + * @param string $format + * @param string $messageKey + * @return array + */ + protected function transform($messages, $format, $messageKey) + { + $messages = (array) $messages; + + // We will simply spin through the given messages and transform each one + // replacing the :message place holder with the real message allowing + // the messages to be easily formatted to each developer's desires. + $replace = array(':message', ':key'); + + foreach ($messages as &$message) + { + $message = str_replace($replace, array($message, $messageKey), $format); + } + + return $messages; + } + + /** + * Get the appropriate format based on the given format. + * + * @param string $format + * @return string + */ + protected function checkFormat($format) + { + return $format ?: $this->format; + } + + /** + * Get the raw messages in the container. + * + * @return array + */ + public function getMessages() + { + return $this->messages; + } + + /** + * Get the messages for the instance. + * + * @return \Illuminate\Support\MessageBag + */ + public function getMessageBag() + { + return $this; + } + + /** + * Get the default message format. + * + * @return string + */ + public function getFormat() + { + return $this->format; + } + + /** + * Set the default message format. + * + * @param string $format + * @return \Illuminate\Support\MessageBag + */ + public function setFormat($format = ':message') + { + $this->format = $format; + + return $this; + } + + /** + * Determine if the message bag has any messages. + * + * @return bool + */ + public function isEmpty() + { + return ! $this->any(); + } + + /** + * Determine if the message bag has any messages. + * + * @return bool + */ + public function any() + { + return $this->count() > 0; + } + + /** + * Get the number of messages in the container. + * + * @return int + */ + public function count() + { + return count($this->messages, COUNT_RECURSIVE) - count($this->messages); + } + + /** + * Get the instance as an array. + * + * @return array + */ + public function toArray() + { + return $this->getMessages(); + } + + /** + * Convert the object into something JSON serializable. + * + * @return array + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * Convert the object to its JSON representation. + * + * @param int $options + * @return string + */ + public function toJson($options = 0) + { + return json_encode($this->toArray(), $options); + } + + /** + * Convert the message bag to its string representation. + * + * @return string + */ + public function __toString() + { + return $this->toJson(); + } + +} diff --git a/vendor/illuminate/support/NamespacedItemResolver.php b/vendor/illuminate/support/NamespacedItemResolver.php new file mode 100755 index 0000000..6c3366e --- /dev/null +++ b/vendor/illuminate/support/NamespacedItemResolver.php @@ -0,0 +1,109 @@ +parsed[$key])) + { + return $this->parsed[$key]; + } + + // If the key does not contain a double colon, it means the key is not in a + // namespace, and is just a regular configuration item. Namespaces are a + // tool for organizing configuration items for things such as modules. + if (strpos($key, '::') === false) + { + $segments = explode('.', $key); + + $parsed = $this->parseBasicSegments($segments); + } + else + { + $parsed = $this->parseNamespacedSegments($key); + } + + // Once we have the parsed array of this key's elements, such as its groups + // and namespace, we will cache each array inside a simple list that has + // the key and the parsed array for quick look-ups for later requests. + return $this->parsed[$key] = $parsed; + } + + /** + * Parse an array of basic segments. + * + * @param array $segments + * @return array + */ + protected function parseBasicSegments(array $segments) + { + // The first segment in a basic array will always be the group, so we can go + // ahead and grab that segment. If there is only one total segment we are + // just pulling an entire group out of the array and not a single item. + $group = $segments[0]; + + if (count($segments) == 1) + { + return array(null, $group, null); + } + + // If there is more than one segment in this group, it means we are pulling + // a specific item out of a groups and will need to return the item name + // as well as the group so we know which item to pull from the arrays. + else + { + $item = implode('.', array_slice($segments, 1)); + + return array(null, $group, $item); + } + } + + /** + * Parse an array of namespaced segments. + * + * @param string $key + * @return array + */ + protected function parseNamespacedSegments($key) + { + list($namespace, $item) = explode('::', $key); + + // First we'll just explode the first segment to get the namespace and group + // since the item should be in the remaining segments. Once we have these + // two pieces of data we can proceed with parsing out the item's value. + $itemSegments = explode('.', $item); + + $groupAndItem = array_slice($this->parseBasicSegments($itemSegments), 1); + + return array_merge(array($namespace), $groupAndItem); + } + + /** + * Set the parsed value of a key. + * + * @param string $key + * @param array $parsed + * @return void + */ + public function setParsedKey($key, $parsed) + { + $this->parsed[$key] = $parsed; + } + +} diff --git a/vendor/illuminate/support/Pluralizer.php b/vendor/illuminate/support/Pluralizer.php new file mode 100755 index 0000000..8281dc8 --- /dev/null +++ b/vendor/illuminate/support/Pluralizer.php @@ -0,0 +1,103 @@ +app = $app; + } + + /** + * Register the service provider. + * + * @return void + */ + abstract public function register(); + + /** + * Merge the given configuration with the existing configuration. + * + * @param string $path + * @param string $key + * @return void + */ + protected function mergeConfigFrom($path, $key) + { + $config = $this->app['config']->get($key, []); + + $this->app['config']->set($key, array_merge(require $path, $config)); + } + + /** + * Register a view file namespace. + * + * @param string $path + * @param string $namespace + * @return void + */ + protected function loadViewsFrom($path, $namespace) + { + if (is_dir($appPath = $this->app->basePath().'/resources/views/vendor/'.$namespace)) + { + $this->app['view']->addNamespace($namespace, $appPath); + } + + $this->app['view']->addNamespace($namespace, $path); + } + + /** + * Register a translation file namespace. + * + * @param string $path + * @param string $namespace + * @return void + */ + protected function loadTranslationsFrom($path, $namespace) + { + $this->app['translator']->addNamespace($namespace, $path); + } + + /** + * Register paths to be published by the publish command. + * + * @param array $paths + * @param string $group + * @return void + */ + protected function publishes(array $paths, $group = null) + { + $class = get_class($this); + + if ( ! array_key_exists($class, static::$publishes)) + { + static::$publishes[$class] = []; + } + + static::$publishes[$class] = array_merge(static::$publishes[$class], $paths); + + if ($group) + { + static::$publishGroups[$group] = $paths; + } + } + + /** + * Get the paths to publish. + * + * @param string $provider + * @param string $group + * @return array + */ + public static function pathsToPublish($provider = null, $group = null) + { + if ($group && array_key_exists($group, static::$publishGroups)) + { + return static::$publishGroups[$group]; + } + + if ($provider && array_key_exists($provider, static::$publishes)) + { + return static::$publishes[$provider]; + } + + if ($group || $provider) + { + return []; + } + + $paths = []; + + foreach (static::$publishes as $class => $publish) + { + $paths = array_merge($paths, $publish); + } + + return $paths; + } + + /** + * Register the package's custom Artisan commands. + * + * @param array $commands + * @return void + */ + public function commands($commands) + { + $commands = is_array($commands) ? $commands : func_get_args(); + + // To register the commands with Artisan, we will grab each of the arguments + // passed into the method and listen for Artisan "start" event which will + // give us the Artisan console instance which we will give commands to. + $events = $this->app['events']; + + $events->listen('artisan.start', function($artisan) use ($commands) + { + $artisan->resolveCommands($commands); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } + + /** + * Get the events that trigger this service provider to register. + * + * @return array + */ + public function when() + { + return []; + } + + /** + * Determine if the provider is deferred. + * + * @return bool + */ + public function isDeferred() + { + return $this->defer; + } + + /** + * Get a list of files that should be compiled for the package. + * + * @return array + */ + public static function compiles() + { + return []; + } + + /** + * Dynamically handle missing method calls. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + if ($method == 'boot') return; + + throw new BadMethodCallException("Call to undefined method [{$method}]"); + } + +} diff --git a/vendor/illuminate/support/Str.php b/vendor/illuminate/support/Str.php new file mode 100755 index 0000000..6c1f148 --- /dev/null +++ b/vendor/illuminate/support/Str.php @@ -0,0 +1,365 @@ +container = $container; + + if ( ! $this->container->bound('config')) + { + $this->container->instance('config', new Fluent); + } + } + + /** + * Make this capsule instance available globally. + * + * @return void + */ + public function setAsGlobal() + { + static::$instance = $this; + } + + /** + * Get the IoC container instance. + * + * @return \Illuminate\Contracts\Container\Container + */ + public function getContainer() + { + return $this->container; + } + + /** + * Set the IoC container instance. + * + * @param \Illuminate\Contracts\Container\Container $container + * @return void + */ + public function setContainer(Container $container) + { + $this->container = $container; + } + +} diff --git a/vendor/illuminate/support/Traits/Macroable.php b/vendor/illuminate/support/Traits/Macroable.php new file mode 100755 index 0000000..7e8ead5 --- /dev/null +++ b/vendor/illuminate/support/Traits/Macroable.php @@ -0,0 +1,90 @@ +bindTo($this, get_class($this)), $parameters); + } + else + { + return call_user_func_array(static::$macros[$method], $parameters); + } + } + + throw new BadMethodCallException("Method {$method} does not exist."); + } + +} diff --git a/vendor/illuminate/support/ViewErrorBag.php b/vendor/illuminate/support/ViewErrorBag.php new file mode 100755 index 0000000..23e7a1a --- /dev/null +++ b/vendor/illuminate/support/ViewErrorBag.php @@ -0,0 +1,106 @@ +bags[$key]); + } + + /** + * Get a MessageBag instance from the bags. + * + * @param string $key + * @return \Illuminate\Contracts\Support\MessageBag + */ + public function getBag($key) + { + return array_get($this->bags, $key, new MessageBag); + } + + /** + * Get all the bags. + * + * @return array + */ + public function getBags() + { + return $this->bags; + } + + /** + * Add a new MessageBag instance to the bags. + * + * @param string $key + * @param \Illuminate\Contracts\Support\MessageBag $bag + * @return $this + */ + public function put($key, MessageBagContract $bag) + { + $this->bags[$key] = $bag; + + return $this; + } + + /** + * Get the number of messages in the default bag. + * + * @return int + */ + public function count() + { + return $this->default->count(); + } + + /** + * Dynamically call methods on the default bag. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return call_user_func_array(array($this->default, $method), $parameters); + } + + /** + * Dynamically access a view error bag. + * + * @param string $key + * @return \Illuminate\Contracts\Support\MessageBag + */ + public function __get($key) + { + return array_get($this->bags, $key, new MessageBag); + } + + /** + * Dynamically set a view error bag. + * + * @param string $key + * @param \Illuminate\Contracts\Support\MessageBag $value + * @return void + */ + public function __set($key, $value) + { + array_set($this->bags, $key, $value); + } + +} diff --git a/vendor/illuminate/support/composer.json b/vendor/illuminate/support/composer.json new file mode 100755 index 0000000..cba6e57 --- /dev/null +++ b/vendor/illuminate/support/composer.json @@ -0,0 +1,40 @@ +{ + "name": "illuminate/support", + "description": "The Illuminate Support package.", + "license": "MIT", + "homepage": "http://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "require": { + "php": ">=5.4.0", + "ext-mbstring": "*", + "illuminate/contracts": "5.0.*", + "doctrine/inflector": "~1.0", + "danielstjules/stringy": "~1.8" + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "suggest": { + "jeremeamia/superclosure": "Required to be able to serialize closures (~2.0)." + }, + "minimum-stability": "dev" +} diff --git a/vendor/illuminate/support/helpers.php b/vendor/illuminate/support/helpers.php new file mode 100755 index 0000000..4405cc7 --- /dev/null +++ b/vendor/illuminate/support/helpers.php @@ -0,0 +1,800 @@ + $value) + { + if (is_numeric($key)) + { + $start++; + + $array[$start] = array_pull($array, $key); + } + } + + return $array; + } +} + +if ( ! function_exists('array_add')) +{ + /** + * Add an element to an array using "dot" notation if it doesn't exist. + * + * @param array $array + * @param string $key + * @param mixed $value + * @return array + */ + function array_add($array, $key, $value) + { + return Arr::add($array, $key, $value); + } +} + +if ( ! function_exists('array_build')) +{ + /** + * Build a new array using a callback. + * + * @param array $array + * @param callable $callback + * @return array + */ + function array_build($array, callable $callback) + { + return Arr::build($array, $callback); + } +} + +if ( ! function_exists('array_collapse')) +{ + /** + * Collapse an array of arrays into a single array. + * + * @param array|\ArrayAccess $array + * @return array + */ + function array_collapse($array) + { + return Arr::collapse($array); + } +} + +if ( ! function_exists('array_divide')) +{ + /** + * Divide an array into two arrays. One with keys and the other with values. + * + * @param array $array + * @return array + */ + function array_divide($array) + { + return Arr::divide($array); + } +} + +if ( ! function_exists('array_dot')) +{ + /** + * Flatten a multi-dimensional associative array with dots. + * + * @param array $array + * @param string $prepend + * @return array + */ + function array_dot($array, $prepend = '') + { + return Arr::dot($array, $prepend); + } +} + +if ( ! function_exists('array_except')) +{ + /** + * Get all of the given array except for a specified array of items. + * + * @param array $array + * @param array|string $keys + * @return array + */ + function array_except($array, $keys) + { + return Arr::except($array, $keys); + } +} + +if ( ! function_exists('array_fetch')) +{ + /** + * Fetch a flattened array of a nested array element. + * + * @param array $array + * @param string $key + * @return array + */ + function array_fetch($array, $key) + { + return Arr::fetch($array, $key); + } +} + +if ( ! function_exists('array_first')) +{ + /** + * Return the first element in an array passing a given truth test. + * + * @param array $array + * @param callable $callback + * @param mixed $default + * @return mixed + */ + function array_first($array, callable $callback, $default = null) + { + return Arr::first($array, $callback, $default); + } +} + +if ( ! function_exists('array_last')) +{ + /** + * Return the last element in an array passing a given truth test. + * + * @param array $array + * @param callable $callback + * @param mixed $default + * @return mixed + */ + function array_last($array, $callback, $default = null) + { + return Arr::last($array, $callback, $default); + } +} + +if ( ! function_exists('array_flatten')) +{ + /** + * Flatten a multi-dimensional array into a single level. + * + * @param array $array + * @return array + */ + function array_flatten($array) + { + return Arr::flatten($array); + } +} + +if ( ! function_exists('array_forget')) +{ + /** + * Remove one or many array items from a given array using "dot" notation. + * + * @param array $array + * @param array|string $keys + * @return void + */ + function array_forget(&$array, $keys) + { + return Arr::forget($array, $keys); + } +} + +if ( ! function_exists('array_get')) +{ + /** + * Get an item from an array using "dot" notation. + * + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed + */ + function array_get($array, $key, $default = null) + { + return Arr::get($array, $key, $default); + } +} + +if ( ! function_exists('array_has')) +{ + /** + * Check if an item exists in an array using "dot" notation. + * + * @param array $array + * @param string $key + * @return bool + */ + function array_has($array, $key) + { + return Arr::has($array, $key); + } +} + +if ( ! function_exists('array_only')) +{ + /** + * Get a subset of the items from the given array. + * + * @param array $array + * @param array|string $keys + * @return array + */ + function array_only($array, $keys) + { + return Arr::only($array, $keys); + } +} + +if ( ! function_exists('array_pluck')) +{ + /** + * Pluck an array of values from an array. + * + * @param array $array + * @param string $value + * @param string $key + * @return array + */ + function array_pluck($array, $value, $key = null) + { + return Arr::pluck($array, $value, $key); + } +} + +if ( ! function_exists('array_pull')) +{ + /** + * Get a value from the array, and remove it. + * + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed + */ + function array_pull(&$array, $key, $default = null) + { + return Arr::pull($array, $key, $default); + } +} + +if ( ! function_exists('array_set')) +{ + /** + * Set an array item to a given value using "dot" notation. + * + * If no key is given to the method, the entire array will be replaced. + * + * @param array $array + * @param string $key + * @param mixed $value + * @return array + */ + function array_set(&$array, $key, $value) + { + return Arr::set($array, $key, $value); + } +} + +if ( ! function_exists('array_sort')) +{ + /** + * Sort the array using the given callback. + * + * @param array $array + * @param callable $callback + * @return array + */ + function array_sort($array, callable $callback) + { + return Arr::sort($array, $callback); + } +} + +if ( ! function_exists('array_where')) +{ + /** + * Filter the array using the given callback. + * + * @param array $array + * @param callable $callback + * @return array + */ + function array_where($array, callable $callback) + { + return Arr::where($array, $callback); + } +} + +if ( ! function_exists('camel_case')) +{ + /** + * Convert a value to camel case. + * + * @param string $value + * @return string + */ + function camel_case($value) + { + return Str::camel($value); + } +} + +if ( ! function_exists('class_basename')) +{ + /** + * Get the class "basename" of the given object / class. + * + * @param string|object $class + * @return string + */ + function class_basename($class) + { + $class = is_object($class) ? get_class($class) : $class; + + return basename(str_replace('\\', '/', $class)); + } +} + +if ( ! function_exists('class_uses_recursive')) +{ + /** + * Returns all traits used by a class, its subclasses and trait of their traits. + * + * @param string $class + * @return array + */ + function class_uses_recursive($class) + { + $results = []; + + foreach (array_merge([$class => $class], class_parents($class)) as $class) + { + $results += trait_uses_recursive($class); + } + + return array_unique($results); + } +} + +if ( ! function_exists('collect')) +{ + /** + * Create a collection from the given value. + * + * @param mixed $value + * @return \Illuminate\Support\Collection + */ + function collect($value = null) + { + return new Collection($value); + } +} + +if ( ! function_exists('data_get')) +{ + /** + * Get an item from an array or object using "dot" notation. + * + * @param mixed $target + * @param string $key + * @param mixed $default + * @return mixed + */ + function data_get($target, $key, $default = null) + { + if (is_null($key)) return $target; + + foreach (explode('.', $key) as $segment) + { + if (is_array($target)) + { + if ( ! array_key_exists($segment, $target)) + { + return value($default); + } + + $target = $target[$segment]; + } + elseif ($target instanceof ArrayAccess) + { + if ( ! isset($target[$segment])) + { + return value($default); + } + + $target = $target[$segment]; + } + elseif (is_object($target)) + { + if ( ! isset($target->{$segment})) + { + return value($default); + } + + $target = $target->{$segment}; + } + else + { + return value($default); + } + } + + return $target; + } +} + +if ( ! function_exists('dd')) +{ + /** + * Dump the passed variables and end the script. + * + * @param mixed + * @return void + */ + function dd() + { + array_map(function($x) { (new Dumper)->dump($x); }, func_get_args()); + + die; + } +} + +if ( ! function_exists('e')) +{ + /** + * Escape HTML entities in a string. + * + * @param string $value + * @return string + */ + function e($value) + { + return htmlentities($value, ENT_QUOTES, 'UTF-8', false); + } +} + +if ( ! function_exists('ends_with')) +{ + /** + * Determine if a given string ends with a given substring. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ + function ends_with($haystack, $needles) + { + return Str::endsWith($haystack, $needles); + } +} + +if ( ! function_exists('head')) +{ + /** + * Get the first element of an array. Useful for method chaining. + * + * @param array $array + * @return mixed + */ + function head($array) + { + return reset($array); + } +} + +if ( ! function_exists('last')) +{ + /** + * Get the last element from an array. + * + * @param array $array + * @return mixed + */ + function last($array) + { + return end($array); + } +} + +if ( ! function_exists('object_get')) +{ + /** + * Get an item from an object using "dot" notation. + * + * @param object $object + * @param string $key + * @param mixed $default + * @return mixed + */ + function object_get($object, $key, $default = null) + { + if (is_null($key) || trim($key) == '') return $object; + + foreach (explode('.', $key) as $segment) + { + if ( ! is_object($object) || ! isset($object->{$segment})) + { + return value($default); + } + + $object = $object->{$segment}; + } + + return $object; + } +} + +if ( ! function_exists('preg_replace_sub')) +{ + /** + * Replace a given pattern with each value in the array in sequentially. + * + * @param string $pattern + * @param array $replacements + * @param string $subject + * @return string + */ + function preg_replace_sub($pattern, &$replacements, $subject) + { + return preg_replace_callback($pattern, function($match) use (&$replacements) + { + foreach ($replacements as $key => $value) + { + return array_shift($replacements); + } + + }, $subject); + } +} + +if ( ! function_exists('snake_case')) +{ + /** + * Convert a string to snake case. + * + * @param string $value + * @param string $delimiter + * @return string + */ + function snake_case($value, $delimiter = '_') + { + return Str::snake($value, $delimiter); + } +} + +if ( ! function_exists('starts_with')) +{ + /** + * Determine if a given string starts with a given substring. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ + function starts_with($haystack, $needles) + { + return Str::startsWith($haystack, $needles); + } +} + +if ( ! function_exists('str_contains')) +{ + /** + * Determine if a given string contains a given substring. + * + * @param string $haystack + * @param string|array $needles + * @return bool + */ + function str_contains($haystack, $needles) + { + return Str::contains($haystack, $needles); + } +} + +if ( ! function_exists('str_finish')) +{ + /** + * Cap a string with a single instance of a given value. + * + * @param string $value + * @param string $cap + * @return string + */ + function str_finish($value, $cap) + { + return Str::finish($value, $cap); + } +} + +if ( ! function_exists('str_is')) +{ + /** + * Determine if a given string matches a given pattern. + * + * @param string $pattern + * @param string $value + * @return bool + */ + function str_is($pattern, $value) + { + return Str::is($pattern, $value); + } +} + +if ( ! function_exists('str_limit')) +{ + /** + * Limit the number of characters in a string. + * + * @param string $value + * @param int $limit + * @param string $end + * @return string + */ + function str_limit($value, $limit = 100, $end = '...') + { + return Str::limit($value, $limit, $end); + } +} + +if ( ! function_exists('str_plural')) +{ + /** + * Get the plural form of an English word. + * + * @param string $value + * @param int $count + * @return string + */ + function str_plural($value, $count = 2) + { + return Str::plural($value, $count); + } +} + +if ( ! function_exists('str_random')) +{ + /** + * Generate a more truly "random" alpha-numeric string. + * + * @param int $length + * @return string + * + * @throws \RuntimeException + */ + function str_random($length = 16) + { + return Str::random($length); + } +} + +if ( ! function_exists('str_replace_array')) +{ + /** + * Replace a given value in the string sequentially with an array. + * + * @param string $search + * @param array $replace + * @param string $subject + * @return string + */ + function str_replace_array($search, array $replace, $subject) + { + foreach ($replace as $value) + { + $subject = preg_replace('/'.$search.'/', $value, $subject, 1); + } + + return $subject; + } +} + +if ( ! function_exists('str_singular')) +{ + /** + * Get the singular form of an English word. + * + * @param string $value + * @return string + */ + function str_singular($value) + { + return Str::singular($value); + } +} + +if ( ! function_exists('str_slug')) +{ + /** + * Generate a URL friendly "slug" from a given string. + * + * @param string $title + * @param string $separator + * @return string + */ + function str_slug($title, $separator = '-') + { + return Str::slug($title, $separator); + } +} + +if ( ! function_exists('studly_case')) +{ + /** + * Convert a value to studly caps case. + * + * @param string $value + * @return string + */ + function studly_case($value) + { + return Str::studly($value); + } +} + +if ( ! function_exists('trait_uses_recursive')) +{ + /** + * Returns all traits used by a trait and its traits. + * + * @param string $trait + * @return array + */ + function trait_uses_recursive($trait) + { + $traits = class_uses($trait); + + foreach ($traits as $trait) + { + $traits += trait_uses_recursive($trait); + } + + return $traits; + } +} + +if ( ! function_exists('value')) +{ + /** + * Return the default value of the given value. + * + * @param mixed $value + * @return mixed + */ + function value($value) + { + return $value instanceof Closure ? $value() : $value; + } +} + +if ( ! function_exists('with')) +{ + /** + * Return the given object. Useful for chaining. + * + * @param mixed $object + * @return mixed + */ + function with($object) + { + return $object; + } +} diff --git a/vendor/nesbot/carbon/LICENSE b/vendor/nesbot/carbon/LICENSE new file mode 100755 index 0000000..6de45eb --- /dev/null +++ b/vendor/nesbot/carbon/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) Brian Nesbitt + +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/vendor/nesbot/carbon/composer.json b/vendor/nesbot/carbon/composer.json new file mode 100755 index 0000000..f9ddd06 --- /dev/null +++ b/vendor/nesbot/carbon/composer.json @@ -0,0 +1,31 @@ +{ + "name": "nesbot/carbon", + "type": "library", + "description": "A simple API extension for DateTime.", + "keywords": [ + "date", + "time", + "DateTime" + ], + "homepage": "http://carbon.nesbot.com", + "license": "MIT", + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "require": { + "php": ">=5.3.0", + "symfony/translation": "~2.6" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "autoload": { + "psr-0": { + "Carbon": "src" + } + } +} diff --git a/vendor/nesbot/carbon/phpunit.xml.dist b/vendor/nesbot/carbon/phpunit.xml.dist new file mode 100755 index 0000000..dc998e2 --- /dev/null +++ b/vendor/nesbot/carbon/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + + src/Carbon + + + + + + tests + + + diff --git a/vendor/nesbot/carbon/readme.md b/vendor/nesbot/carbon/readme.md new file mode 100755 index 0000000..7fc85c8 --- /dev/null +++ b/vendor/nesbot/carbon/readme.md @@ -0,0 +1,81 @@ +# Carbon + +[![Latest Stable Version](https://poser.pugx.org/nesbot/carbon/v/stable.png)](https://packagist.org/packages/nesbot/carbon) [![Total Downloads](https://poser.pugx.org/nesbot/carbon/downloads.png)](https://packagist.org/packages/nesbot/carbon) [![Build Status](https://secure.travis-ci.org/briannesbitt/Carbon.png)](http://travis-ci.org/briannesbitt/Carbon) + +A simple PHP API extension for DateTime. [http://carbon.nesbot.com](http://carbon.nesbot.com) + +```php +printf("Right now is %s", Carbon::now()->toDateTimeString()); +printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver')); //implicit __toString() +$tomorrow = Carbon::now()->addDay(); +$lastWeek = Carbon::now()->subWeek(); +$nextSummerOlympics = Carbon::createFromDate(2012)->addYears(4); + +$officialDate = Carbon::now()->toRfc2822String(); + +$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age; + +$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London'); + +$worldWillEnd = Carbon::createFromDate(2012, 12, 21, 'GMT'); + +// Don't really want to die so mock now +Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1)); + +// comparisons are always done in UTC +if (Carbon::now()->gte($worldWillEnd)) { + die(); +} + +// Phew! Return to normal behaviour +Carbon::setTestNow(); + +if (Carbon::now()->isWeekend()) { + echo 'Party!'; +} +echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago' + +// ... but also does 'from now', 'after' and 'before' +// rolling up to seconds, minutes, hours, days, months, years + +$daysSinceEpoch = Carbon::createFromTimeStamp(0)->diffInDays(); +``` + +## Installation + +### With Composer + +``` +$ composer require nesbot/carbon +``` + +```json +{ + "require": { + "nesbot/carbon": "~1.14" + } +} +``` + +```php + +### Without Composer + +Why are you not using [composer](http://getcomposer.org/)? Download [Carbon.php](https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Carbon.php) from the repo and save the file into your project path somewhere. + +```php + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Carbon; + +use Closure; +use DateTime; +use DateTimeZone; +use DatePeriod; +use InvalidArgumentException; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\Translation\Loader\ArrayLoader; + +/** + * A simple API extension for DateTime + * + * @property integer $year + * @property integer $yearIso + * @property integer $month + * @property integer $day + * @property integer $hour + * @property integer $minute + * @property integer $second + * @property integer $timestamp seconds since the Unix Epoch + * @property DateTimeZone $timezone the current timezone + * @property DateTimeZone $tz alias of timezone + * @property-read integer $micro + * @property-read integer $dayOfWeek 0 (for Sunday) through 6 (for Saturday) + * @property-read integer $dayOfYear 0 through 365 + * @property-read integer $weekOfMonth 1 through 5 + * @property-read integer $weekOfYear ISO-8601 week number of year, weeks starting on Monday + * @property-read integer $daysInMonth number of days in the given month + * @property-read integer $age does a diffInYears() with default parameters + * @property-read integer $quarter the quarter of this instance, 1 - 4 + * @property-read integer $offset the timezone offset in seconds from UTC + * @property-read integer $offsetHours the timezone offset in hours from UTC + * @property-read boolean $dst daylight savings time indicator, true if DST, false otherwise + * @property-read boolean $local checks if the timezone is local, true if local, false otherwise + * @property-read boolean $utc checks if the timezone is UTC, true if UTC, false otherwise + * @property-read string $timezoneName + * @property-read string $tzName + */ +class Carbon extends DateTime +{ + /** + * The day constants + */ + const SUNDAY = 0; + const MONDAY = 1; + const TUESDAY = 2; + const WEDNESDAY = 3; + const THURSDAY = 4; + const FRIDAY = 5; + const SATURDAY = 6; + + /** + * Names of days of the week. + * + * @var array + */ + protected static $days = array( + self::SUNDAY => 'Sunday', + self::MONDAY => 'Monday', + self::TUESDAY => 'Tuesday', + self::WEDNESDAY => 'Wednesday', + self::THURSDAY => 'Thursday', + self::FRIDAY => 'Friday', + self::SATURDAY => 'Saturday', + ); + + /** + * Terms used to detect if a time passed is a relative date for testing purposes + * + * @var array + */ + protected static $relativeKeywords = array( + 'this', + 'next', + 'last', + 'tomorrow', + 'yesterday', + '+', + '-', + 'first', + 'last', + 'ago', + ); + + /** + * Number of X in Y + */ + const YEARS_PER_CENTURY = 100; + const YEARS_PER_DECADE = 10; + const MONTHS_PER_YEAR = 12; + const WEEKS_PER_YEAR = 52; + const DAYS_PER_WEEK = 7; + const HOURS_PER_DAY = 24; + const MINUTES_PER_HOUR = 60; + const SECONDS_PER_MINUTE = 60; + + /** + * Default format to use for __toString method when type juggling occurs. + * + * @var string + */ + const DEFAULT_TO_STRING_FORMAT = 'Y-m-d H:i:s'; + + /** + * Format to use for __toString method when type juggling occurs. + * + * @var string + */ + protected static $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; + + /** + * A test Carbon instance to be returned when now instances are created + * + * @var Carbon + */ + protected static $testNow; + + /** + * A translator to ... er ... translate stuff + * + * @var TranslatorInterface + */ + protected static $translator; + + /** + * Creates a DateTimeZone from a string or a DateTimeZone + * + * @param DateTimeZone|string|null $object + * + * @return DateTimeZone + * + * @throws InvalidArgumentException + */ + protected static function safeCreateDateTimeZone($object) + { + if ($object === null) { + // Don't return null... avoid Bug #52063 in PHP <5.3.6 + return new DateTimeZone(date_default_timezone_get()); + } + + if ($object instanceof DateTimeZone) { + return $object; + } + + $tz = @timezone_open((string) $object); + + if ($tz === false) { + throw new InvalidArgumentException('Unknown or bad timezone ('.$object.')'); + } + + return $tz; + } + + /////////////////////////////////////////////////////////////////// + //////////////////////////// CONSTRUCTORS ///////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Create a new Carbon instance. + * + * Please see the testing aids section (specifically static::setTestNow()) + * for more on the possibility of this constructor returning a test instance. + * + * @param string $time + * @param DateTimeZone|string $tz + */ + public function __construct($time = null, $tz = null) + { + // If the class has a test now set and we are trying to create a now() + // instance then override as required + if (static::hasTestNow() && (empty($time) || $time === 'now' || static::hasRelativeKeywords($time))) { + $testInstance = clone static::getTestNow(); + if (static::hasRelativeKeywords($time)) { + $testInstance->modify($time); + } + + //shift the time according to the given time zone + if ($tz !== NULL && $tz != static::getTestNow()->tz) { + $testInstance->setTimezone($tz); + } else { + $tz = $testInstance->tz; + } + + $time = $testInstance->toDateTimeString(); + } + + parent::__construct($time, static::safeCreateDateTimeZone($tz)); + } + + /** + * Create a Carbon instance from a DateTime one + * + * @param DateTime $dt + * + * @return static + */ + public static function instance(DateTime $dt) + { + return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimeZone()); + } + + /** + * Create a carbon instance from a string. This is an alias for the + * constructor that allows better fluent syntax as it allows you to do + * Carbon::parse('Monday next week')->fn() rather than + * (new Carbon('Monday next week'))->fn() + * + * @param string $time + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function parse($time = null, $tz = null) + { + return new static($time, $tz); + } + + /** + * Get a Carbon instance for the current date and time + * + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function now($tz = null) + { + return new static(null, $tz); + } + + /** + * Create a Carbon instance for today + * + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function today($tz = null) + { + return static::now($tz)->startOfDay(); + } + + /** + * Create a Carbon instance for tomorrow + * + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function tomorrow($tz = null) + { + return static::today($tz)->addDay(); + } + + /** + * Create a Carbon instance for yesterday + * + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function yesterday($tz = null) + { + return static::today($tz)->subDay(); + } + + /** + * Create a Carbon instance for the greatest supported date. + * + * @return Carbon + */ + public static function maxValue() + { + return static::createFromTimestamp(PHP_INT_MAX); + } + + /** + * Create a Carbon instance for the lowest supported date. + * + * @return Carbon + */ + public static function minValue() + { + return static::createFromTimestamp(~PHP_INT_MAX); + } + + /** + * Create a new Carbon instance from a specific date and time. + * + * If any of $year, $month or $day are set to null their now() values + * will be used. + * + * If $hour is null it will be set to its now() value and the default values + * for $minute and $second will be their now() values. + * If $hour is not null then the default values for $minute and $second + * will be 0. + * + * @param integer $year + * @param integer $month + * @param integer $day + * @param integer $hour + * @param integer $minute + * @param integer $second + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null) + { + $year = ($year === null) ? date('Y') : $year; + $month = ($month === null) ? date('n') : $month; + $day = ($day === null) ? date('j') : $day; + + if ($hour === null) { + $hour = date('G'); + $minute = ($minute === null) ? date('i') : $minute; + $second = ($second === null) ? date('s') : $second; + } else { + $minute = ($minute === null) ? 0 : $minute; + $second = ($second === null) ? 0 : $second; + } + + return static::createFromFormat('Y-n-j G:i:s', sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz); + } + + /** + * Create a Carbon instance from just a date. The time portion is set to now. + * + * @param integer $year + * @param integer $month + * @param integer $day + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function createFromDate($year = null, $month = null, $day = null, $tz = null) + { + return static::create($year, $month, $day, null, null, null, $tz); + } + + /** + * Create a Carbon instance from just a time. The date portion is set to today. + * + * @param integer $hour + * @param integer $minute + * @param integer $second + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function createFromTime($hour = null, $minute = null, $second = null, $tz = null) + { + return static::create(null, null, null, $hour, $minute, $second, $tz); + } + + /** + * Create a Carbon instance from a specific format + * + * @param string $format + * @param string $time + * @param DateTimeZone|string $tz + * + * @return static + * + * @throws InvalidArgumentException + */ + public static function createFromFormat($format, $time, $tz = null) + { + if ($tz !== null) { + $dt = parent::createFromFormat($format, $time, static::safeCreateDateTimeZone($tz)); + } else { + $dt = parent::createFromFormat($format, $time); + } + + if ($dt instanceof DateTime) { + return static::instance($dt); + } + + $errors = static::getLastErrors(); + throw new InvalidArgumentException(implode(PHP_EOL, $errors['errors'])); + } + + /** + * Create a Carbon instance from a timestamp + * + * @param integer $timestamp + * @param DateTimeZone|string $tz + * + * @return static + */ + public static function createFromTimestamp($timestamp, $tz = null) + { + return static::now($tz)->setTimestamp($timestamp); + } + + /** + * Create a Carbon instance from an UTC timestamp + * + * @param integer $timestamp + * + * @return static + */ + public static function createFromTimestampUTC($timestamp) + { + return new static('@'.$timestamp); + } + + /** + * Get a copy of the instance + * + * @return static + */ + public function copy() + { + return static::instance($this); + } + + /////////////////////////////////////////////////////////////////// + ///////////////////////// GETTERS AND SETTERS ///////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Get a part of the Carbon object + * + * @param string $name + * + * @throws InvalidArgumentException + * + * @return string|integer|DateTimeZone + */ + public function __get($name) + { + switch (true) { + case array_key_exists($name, $formats = array( + 'year' => 'Y', + 'yearIso' => 'o', + 'month' => 'n', + 'day' => 'j', + 'hour' => 'G', + 'minute' => 'i', + 'second' => 's', + 'micro' => 'u', + 'dayOfWeek' => 'w', + 'dayOfYear' => 'z', + 'weekOfYear' => 'W', + 'daysInMonth' => 't', + 'timestamp' => 'U', + )): + return (int) $this->format($formats[$name]); + + case $name === 'weekOfMonth': + return (int) ceil($this->day / static::DAYS_PER_WEEK); + + case $name === 'age': + return (int) $this->diffInYears(); + + case $name === 'quarter': + return (int) ceil($this->month / 3); + + case $name === 'offset': + return $this->getOffset(); + + case $name === 'offsetHours': + return $this->getOffset() / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR; + + case $name === 'dst': + return $this->format('I') == '1'; + + case $name === 'local': + return $this->offset == $this->copy()->setTimezone(date_default_timezone_get())->offset; + + case $name === 'utc': + return $this->offset == 0; + + case $name === 'timezone' || $name === 'tz': + return $this->getTimezone(); + + case $name === 'timezoneName' || $name === 'tzName': + return $this->getTimezone()->getName(); + + default: + throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name)); + } + } + + /** + * Check if an attribute exists on the object + * + * @param string $name + * + * @return boolean + */ + public function __isset($name) + { + try { + $this->__get($name); + } catch (InvalidArgumentException $e) { + return false; + } + + return true; + } + + /** + * Set a part of the Carbon object + * + * @param string $name + * @param string|integer|DateTimeZone $value + * + * @throws InvalidArgumentException + */ + public function __set($name, $value) + { + switch ($name) { + case 'year': + $this->setDate($value, $this->month, $this->day); + break; + + case 'month': + $this->setDate($this->year, $value, $this->day); + break; + + case 'day': + $this->setDate($this->year, $this->month, $value); + break; + + case 'hour': + $this->setTime($value, $this->minute, $this->second); + break; + + case 'minute': + $this->setTime($this->hour, $value, $this->second); + break; + + case 'second': + $this->setTime($this->hour, $this->minute, $value); + break; + + case 'timestamp': + parent::setTimestamp($value); + break; + + case 'timezone': + case 'tz': + $this->setTimezone($value); + break; + + default: + throw new InvalidArgumentException(sprintf("Unknown setter '%s'", $name)); + } + } + + /** + * Set the instance's year + * + * @param integer $value + * + * @return static + */ + public function year($value) + { + $this->year = $value; + + return $this; + } + + /** + * Set the instance's month + * + * @param integer $value + * + * @return static + */ + public function month($value) + { + $this->month = $value; + + return $this; + } + + /** + * Set the instance's day + * + * @param integer $value + * + * @return static + */ + public function day($value) + { + $this->day = $value; + + return $this; + } + + /** + * Set the instance's hour + * + * @param integer $value + * + * @return static + */ + public function hour($value) + { + $this->hour = $value; + + return $this; + } + + /** + * Set the instance's minute + * + * @param integer $value + * + * @return static + */ + public function minute($value) + { + $this->minute = $value; + + return $this; + } + + /** + * Set the instance's second + * + * @param integer $value + * + * @return static + */ + public function second($value) + { + $this->second = $value; + + return $this; + } + + /** + * Set the date and time all together + * + * @param integer $year + * @param integer $month + * @param integer $day + * @param integer $hour + * @param integer $minute + * @param integer $second + * + * @return static + */ + public function setDateTime($year, $month, $day, $hour, $minute, $second = 0) + { + return $this->setDate($year, $month, $day)->setTime($hour, $minute, $second); + } + + /** + * Set the instance's timestamp + * + * @param integer $value + * + * @return static + */ + public function timestamp($value) + { + $this->timestamp = $value; + + return $this; + } + + /** + * Alias for setTimezone() + * + * @param DateTimeZone|string $value + * + * @return static + */ + public function timezone($value) + { + return $this->setTimezone($value); + } + + /** + * Alias for setTimezone() + * + * @param DateTimeZone|string $value + * + * @return static + */ + public function tz($value) + { + return $this->setTimezone($value); + } + + /** + * Set the instance's timezone from a string or object + * + * @param DateTimeZone|string $value + * + * @return static + */ + public function setTimezone($value) + { + parent::setTimezone(static::safeCreateDateTimeZone($value)); + + return $this; + } + + /////////////////////////////////////////////////////////////////// + ///////////////////////// TESTING AIDS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Set a Carbon instance (real or mock) to be returned when a "now" + * instance is created. The provided instance will be returned + * specifically under the following conditions: + * - A call to the static now() method, ex. Carbon::now() + * - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) + * - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') + * + * Note the timezone parameter was left out of the examples above and + * has no affect as the mock value will be returned regardless of its value. + * + * To clear the test instance call this method using the default + * parameter of null. + * + * @param Carbon $testNow + */ + public static function setTestNow(Carbon $testNow = null) + { + static::$testNow = $testNow; + } + + /** + * Get the Carbon instance (real or mock) to be returned when a "now" + * instance is created. + * + * @return static the current instance used for testing + */ + public static function getTestNow() + { + return static::$testNow; + } + + /** + * Determine if there is a valid test instance set. A valid test instance + * is anything that is not null. + * + * @return boolean true if there is a test instance, otherwise false + */ + public static function hasTestNow() + { + return static::getTestNow() !== null; + } + + /** + * Determine if there is a relative keyword in the time string, this is to + * create dates relative to now for test instances. e.g.: next tuesday + * + * @param string $time + * + * @return boolean true if there is a keyword, otherwise false + */ + public static function hasRelativeKeywords($time) + { + // skip common format with a '-' in it + if (preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) { + foreach (static::$relativeKeywords as $keyword) { + if (stripos($time, $keyword) !== false) { + return true; + } + } + } + + return false; + } + + /////////////////////////////////////////////////////////////////// + /////////////////////// LOCALIZATION ////////////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Intialize the translator instance if necessary. + * + * @return TranslatorInterface + */ + protected static function translator() + { + if (static::$translator == null) { + static::$translator = new Translator('en'); + static::$translator->addLoader('array', new ArrayLoader()); + static::setLocale('en'); + } + + return static::$translator; + } + + /** + * Get the translator instance in use + * + * @return TranslatorInterface + */ + public static function getTranslator() + { + return static::translator(); + } + + /** + * Set the translator instance to use + * + * @param TranslatorInterface $translator + */ + public static function setTranslator(TranslatorInterface $translator) + { + static::$translator = $translator; + } + + /** + * Get the current translator locale + * + * @return string + */ + public static function getLocale() + { + return static::translator()->getLocale(); + } + + /** + * Set the current translator locale + * + * @param string $locale + */ + public static function setLocale($locale) + { + static::translator()->setLocale($locale); + + // Ensure the locale has been loaded. + static::translator()->addResource('array', require __DIR__.'/Lang/'.$locale.'.php', $locale); + } + + /////////////////////////////////////////////////////////////////// + /////////////////////// STRING FORMATTING ///////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Format the instance with the current locale. You can set the current + * locale using setlocale() http://php.net/setlocale. + * + * @param string $format + * + * @return string + */ + public function formatLocalized($format) + { + // Check for Windows to find and replace the %e + // modifier correctly + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { + $format = preg_replace('#(?format(static::$toStringFormat); + } + + /** + * Format the instance as date + * + * @return string + */ + public function toDateString() + { + return $this->format('Y-m-d'); + } + + /** + * Format the instance as a readable date + * + * @return string + */ + public function toFormattedDateString() + { + return $this->format('M j, Y'); + } + + /** + * Format the instance as time + * + * @return string + */ + public function toTimeString() + { + return $this->format('H:i:s'); + } + + /** + * Format the instance as date and time + * + * @return string + */ + public function toDateTimeString() + { + return $this->format('Y-m-d H:i:s'); + } + + /** + * Format the instance with day, date and time + * + * @return string + */ + public function toDayDateTimeString() + { + return $this->format('D, M j, Y g:i A'); + } + + /** + * Format the instance as ATOM + * + * @return string + */ + public function toAtomString() + { + return $this->format(static::ATOM); + } + + /** + * Format the instance as COOKIE + * + * @return string + */ + public function toCookieString() + { + return $this->format(static::COOKIE); + } + + /** + * Format the instance as ISO8601 + * + * @return string + */ + public function toIso8601String() + { + return $this->format(static::ISO8601); + } + + /** + * Format the instance as RFC822 + * + * @return string + */ + public function toRfc822String() + { + return $this->format(static::RFC822); + } + + /** + * Format the instance as RFC850 + * + * @return string + */ + public function toRfc850String() + { + return $this->format(static::RFC850); + } + + /** + * Format the instance as RFC1036 + * + * @return string + */ + public function toRfc1036String() + { + return $this->format(static::RFC1036); + } + + /** + * Format the instance as RFC1123 + * + * @return string + */ + public function toRfc1123String() + { + return $this->format(static::RFC1123); + } + + /** + * Format the instance as RFC2822 + * + * @return string + */ + public function toRfc2822String() + { + return $this->format(static::RFC2822); + } + + /** + * Format the instance as RFC3339 + * + * @return string + */ + public function toRfc3339String() + { + return $this->format(static::RFC3339); + } + + /** + * Format the instance as RSS + * + * @return string + */ + public function toRssString() + { + return $this->format(static::RSS); + } + + /** + * Format the instance as W3C + * + * @return string + */ + public function toW3cString() + { + return $this->format(static::W3C); + } + + /////////////////////////////////////////////////////////////////// + ////////////////////////// COMPARISONS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Determines if the instance is equal to another + * + * @param Carbon $dt + * + * @return boolean + */ + public function eq(Carbon $dt) + { + return $this == $dt; + } + + /** + * Determines if the instance is not equal to another + * + * @param Carbon $dt + * + * @return boolean + */ + public function ne(Carbon $dt) + { + return !$this->eq($dt); + } + + /** + * Determines if the instance is greater (after) than another + * + * @param Carbon $dt + * + * @return boolean + */ + public function gt(Carbon $dt) + { + return $this > $dt; + } + + /** + * Determines if the instance is greater (after) than or equal to another + * + * @param Carbon $dt + * + * @return boolean + */ + public function gte(Carbon $dt) + { + return $this >= $dt; + } + + /** + * Determines if the instance is less (before) than another + * + * @param Carbon $dt + * + * @return boolean + */ + public function lt(Carbon $dt) + { + return $this < $dt; + } + + /** + * Determines if the instance is less (before) or equal to another + * + * @param Carbon $dt + * + * @return boolean + */ + public function lte(Carbon $dt) + { + return $this <= $dt; + } + + /** + * Determines if the instance is between two others + * + * @param Carbon $dt1 + * @param Carbon $dt2 + * @param boolean $equal Indicates if a > and < comparison should be used or <= or >= + * + * @return boolean + */ + public function between(Carbon $dt1, Carbon $dt2, $equal = true) + { + if ($dt1->gt($dt2)) { + $temp = $dt1; + $dt1 = $dt2; + $dt2 = $temp; + } + + if ($equal) { + return $this->gte($dt1) && $this->lte($dt2); + } else { + return $this->gt($dt1) && $this->lt($dt2); + } + } + + /** + * Get the minimum instance between a given instance (default now) and the current instance. + * + * @param Carbon $dt + * + * @return static + */ + public function min(Carbon $dt = null) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + + return $this->lt($dt) ? $this : $dt; + } + + /** + * Get the maximum instance between a given instance (default now) and the current instance. + * + * @param Carbon $dt + * + * @return static + */ + public function max(Carbon $dt = null) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + + return $this->gt($dt) ? $this : $dt; + } + + /** + * Determines if the instance is a weekday + * + * @return boolean + */ + public function isWeekday() + { + return ($this->dayOfWeek != static::SUNDAY && $this->dayOfWeek != static::SATURDAY); + } + + /** + * Determines if the instance is a weekend day + * + * @return boolean + */ + public function isWeekend() + { + return !$this->isWeekDay(); + } + + /** + * Determines if the instance is yesterday + * + * @return boolean + */ + public function isYesterday() + { + return $this->toDateString() === static::yesterday($this->tz)->toDateString(); + } + + /** + * Determines if the instance is today + * + * @return boolean + */ + public function isToday() + { + return $this->toDateString() === static::now($this->tz)->toDateString(); + } + + /** + * Determines if the instance is tomorrow + * + * @return boolean + */ + public function isTomorrow() + { + return $this->toDateString() === static::tomorrow($this->tz)->toDateString(); + } + + /** + * Determines if the instance is in the future, ie. greater (after) than now + * + * @return boolean + */ + public function isFuture() + { + return $this->gt(static::now($this->tz)); + } + + /** + * Determines if the instance is in the past, ie. less (before) than now + * + * @return boolean + */ + public function isPast() + { + return $this->lt(static::now($this->tz)); + } + + /** + * Determines if the instance is a leap year + * + * @return boolean + */ + public function isLeapYear() + { + return $this->format('L') == '1'; + } + + /** + * Checks if the passed in date is the same day as the instance current day. + * + * @param Carbon $dt + * @return boolean + */ + public function isSameDay(Carbon $dt) + { + return $this->toDateString() === $dt->toDateString(); + } + + /////////////////////////////////////////////////////////////////// + /////////////////// ADDITIONS AND SUBTRACTIONS //////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Add years to the instance. Positive $value travel forward while + * negative $value travel into the past. + * + * @param integer $value + * + * @return static + */ + public function addYears($value) + { + return $this->modify((int) $value.' year'); + } + + /** + * Add a year to the instance + * + * @return static + */ + public function addYear($value = 1) + { + return $this->addYears($value); + } + + /** + * Remove a year from the instance + * + * @return static + */ + public function subYear($value = 1) + { + return $this->subYears($value); + } + + /** + * Remove years from the instance. + * + * @param integer $value + * + * @return static + */ + public function subYears($value) + { + return $this->addYears(-1 * $value); + } + + /** + * Add months to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addMonths($value) + { + return $this->modify((int) $value.' month'); + } + + /** + * Add a month to the instance + * + * @return static + */ + public function addMonth($value = 1) + { + return $this->addMonths($value); + } + + /** + * Remove a month from the instance + * + * @return static + */ + public function subMonth($value = 1) + { + return $this->subMonths($value); + } + + /** + * Remove months from the instance + * + * @param integer $value + * + * @return static + */ + public function subMonths($value) + { + return $this->addMonths(-1 * $value); + } + + /** + * Add months without overflowing to the instance. Positive $value + * travels forward while negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addMonthsNoOverflow($value) + { + $date = $this->copy()->addMonths($value); + + if ($date->day != $this->day) { + $date->day(1)->subMonth()->day($date->daysInMonth); + } + + return $date; + } + + /** + * Add a month with no overflow to the instance + * + * @return static + */ + public function addMonthNoOverflow($value = 1) + { + return $this->addMonthsNoOverflow($value); + } + + /** + * Remove a month with no overflow from the instance + * + * @return static + */ + public function subMonthNoOverflow($value = 1) + { + return $this->subMonthsNoOverflow($value); + } + + /** + * Remove months with no overflow from the instance + * + * @param integer $value + * + * @return static + */ + public function subMonthsNoOverflow($value) + { + return $this->addMonthsNoOverflow(-1 * $value); + } + + /** + * Add days to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addDays($value) + { + return $this->modify((int) $value.' day'); + } + + /** + * Add a day to the instance + * + * @return static + */ + public function addDay($value = 1) + { + return $this->addDays($value); + } + + /** + * Remove a day from the instance + * + * @return static + */ + public function subDay($value = 1) + { + return $this->subDays($value); + } + + /** + * Remove days from the instance + * + * @param integer $value + * + * @return static + */ + public function subDays($value) + { + return $this->addDays(-1 * $value); + } + + /** + * Add weekdays to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addWeekdays($value) + { + return $this->modify((int) $value.' weekday'); + } + + /** + * Add a weekday to the instance + * + * @return static + */ + public function addWeekday($value = 1) + { + return $this->addWeekdays($value); + } + + /** + * Remove a weekday from the instance + * + * @return static + */ + public function subWeekday($value = 1) + { + return $this->subWeekdays($value); + } + + /** + * Remove weekdays from the instance + * + * @param integer $value + * + * @return static + */ + public function subWeekdays($value) + { + return $this->addWeekdays(-1 * $value); + } + + /** + * Add weeks to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addWeeks($value) + { + return $this->modify((int) $value.' week'); + } + + /** + * Add a week to the instance + * + * @return static + */ + public function addWeek($value = 1) + { + return $this->addWeeks($value); + } + + /** + * Remove a week from the instance + * + * @return static + */ + public function subWeek($value = 1) + { + return $this->subWeeks($value); + } + + /** + * Remove weeks to the instance + * + * @param integer $value + * + * @return static + */ + public function subWeeks($value) + { + return $this->addWeeks(-1 * $value); + } + + /** + * Add hours to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addHours($value) + { + return $this->modify((int) $value.' hour'); + } + + /** + * Add an hour to the instance + * + * @return static + */ + public function addHour($value = 1) + { + return $this->addHours($value); + } + + /** + * Remove an hour from the instance + * + * @return static + */ + public function subHour($value = 1) + { + return $this->subHours($value); + } + + /** + * Remove hours from the instance + * + * @param integer $value + * + * @return static + */ + public function subHours($value) + { + return $this->addHours(-1 * $value); + } + + /** + * Add minutes to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addMinutes($value) + { + return $this->modify((int) $value.' minute'); + } + + /** + * Add a minute to the instance + * + * @return static + */ + public function addMinute($value = 1) + { + return $this->addMinutes($value); + } + + /** + * Remove a minute from the instance + * + * @return static + */ + public function subMinute($value = 1) + { + return $this->subMinutes($value); + } + + /** + * Remove minutes from the instance + * + * @param integer $value + * + * @return static + */ + public function subMinutes($value) + { + return $this->addMinutes(-1 * $value); + } + + /** + * Add seconds to the instance. Positive $value travels forward while + * negative $value travels into the past. + * + * @param integer $value + * + * @return static + */ + public function addSeconds($value) + { + return $this->modify((int) $value.' second'); + } + + /** + * Add a second to the instance + * + * @return static + */ + public function addSecond($value = 1) + { + return $this->addSeconds($value); + } + + /** + * Remove a second from the instance + * + * @return static + */ + public function subSecond($value = 1) + { + return $this->subSeconds($value); + } + + /** + * Remove seconds from the instance + * + * @param integer $value + * + * @return static + */ + public function subSeconds($value) + { + return $this->addSeconds(-1 * $value); + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// DIFFERENCES /////////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Get the difference in years + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInYears(Carbon $dt = null, $abs = true) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + + return (int) $this->diff($dt, $abs)->format('%r%y'); + } + + /** + * Get the difference in months + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInMonths(Carbon $dt = null, $abs = true) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + + return $this->diffInYears($dt, $abs) * static::MONTHS_PER_YEAR + (int) $this->diff($dt, $abs)->format('%r%m'); + } + + /** + * Get the difference in weeks + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInWeeks(Carbon $dt = null, $abs = true) + { + return (int) ($this->diffInDays($dt, $abs) / static::DAYS_PER_WEEK); + } + + /** + * Get the difference in days + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInDays(Carbon $dt = null, $abs = true) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + + return (int) $this->diff($dt, $abs)->format('%r%a'); + } + + /** + * Get the difference in days using a filter closure + * + * @param Closure $callback + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return int + */ + public function diffInDaysFiltered(Closure $callback, Carbon $dt = null, $abs = true) + { + return $this->diffFiltered(CarbonInterval::day(), $callback, $dt, $abs); + } + + /** + * Get the difference in hours using a filter closure + * + * @param Closure $callback + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return int + */ + public function diffInHoursFiltered(Closure $callback, Carbon $dt = null, $abs = true) + { + return $this->diffFiltered(CarbonInterval::hour(), $callback, $dt, $abs); + } + + /** + * Get the difference by the given interval using a filter closure + * + * @param CarbonInterval $ci An interval to traverse by + * @param Closure $callback + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return int + */ + public function diffFiltered(CarbonInterval $ci, Closure $callback, Carbon $dt = null, $abs = true) + { + $start = $this; + $end = ($dt === null) ? static::now($this->tz) : $dt; + $inverse = false; + + if ($end < $start) { + $start = $end; + $end = $this; + $inverse = true; + } + + $period = new DatePeriod($start, $ci, $end); + $vals = array_filter(iterator_to_array($period), function (DateTime $date) use ($callback) { + return call_user_func($callback, Carbon::instance($date)); + }); + + $diff = count($vals); + + return $inverse && !$abs ? -$diff : $diff; + } + + /** + * Get the difference in weekdays + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return int + */ + public function diffInWeekdays(Carbon $dt = null, $abs = true) + { + return $this->diffInDaysFiltered(function (Carbon $date) { + return $date->isWeekday(); + }, $dt, $abs); + } + + /** + * Get the difference in weekend days using a filter + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return int + */ + public function diffInWeekendDays(Carbon $dt = null, $abs = true) + { + return $this->diffInDaysFiltered(function (Carbon $date) { + return $date->isWeekend(); + }, $dt, $abs); + } + + /** + * Get the difference in hours + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInHours(Carbon $dt = null, $abs = true) + { + return (int) ($this->diffInSeconds($dt, $abs) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR); + } + + /** + * Get the difference in minutes + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInMinutes(Carbon $dt = null, $abs = true) + { + return (int) ($this->diffInSeconds($dt, $abs) / static::SECONDS_PER_MINUTE); + } + + /** + * Get the difference in seconds + * + * @param Carbon $dt + * @param boolean $abs Get the absolute of the difference + * + * @return integer + */ + public function diffInSeconds(Carbon $dt = null, $abs = true) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + $value = $dt->getTimestamp() - $this->getTimestamp(); + + return $abs ? abs($value) : $value; + } + + /** + * The number of seconds since midnight. + * + * @return integer + */ + public function secondsSinceMidnight() + { + return $this->diffInSeconds($this->copy()->startOfDay()); + } + + /** + * The number of seconds until 23:23:59. + * + * @return integer + */ + public function secondsUntilEndOfDay() + { + return $this->diffInSeconds($this->copy()->endOfDay()); + } + + /** + * Get the difference in a human readable format in the current locale. + * + * When comparing a value in the past to default now: + * 1 hour ago + * 5 months ago + * + * When comparing a value in the future to default now: + * 1 hour from now + * 5 months from now + * + * When comparing a value in the past to another value: + * 1 hour before + * 5 months before + * + * When comparing a value in the future to another value: + * 1 hour after + * 5 months after + * + * @param Carbon $other + * @param bool $absolute removes time difference modifiers ago, after, etc + * + * @return string + */ + public function diffForHumans(Carbon $other = null, $absolute = false) + { + $isNow = $other === null; + + if ($isNow) { + $other = static::now($this->tz); + } + + $diffInterval = $this->diff($other); + + switch (true) { + case ($diffInterval->y > 0): + $unit = 'year'; + $count = $diffInterval->y; + break; + + case ($diffInterval->m > 0): + $unit = 'month'; + $count = $diffInterval->m; + break; + + case ($diffInterval->d > 0): + $unit = 'day'; + $count = $diffInterval->d; + if ($count >= self::DAYS_PER_WEEK) { + $unit = 'week'; + $count = (int) ($count / self::DAYS_PER_WEEK); + } + break; + + case ($diffInterval->h > 0): + $unit = 'hour'; + $count = $diffInterval->h; + break; + + case ($diffInterval->i > 0): + $unit = 'minute'; + $count = $diffInterval->i; + break; + + default: + $count = $diffInterval->s; + $unit = 'second'; + break; + } + + if ($count == 0) { + $count = 1; + } + + $time = static::translator()->transChoice($unit, $count, array(':count' => $count)); + + if ($absolute) { + return $time; + } + + $isFuture = $diffInterval->invert === 1; + + $transId = $isNow ? ($isFuture ? 'from_now' : 'ago') : ($isFuture ? 'after' : 'before'); + + // Some langs have special pluralization for past and future tense. + $tryKeyExists = $unit.'_'.$transId; + if ($tryKeyExists !== static::translator()->transChoice($tryKeyExists, $count)) { + $time = static::translator()->transChoice($tryKeyExists, $count, array(':count' => $count)); + } + + return static::translator()->trans($transId, array(':time' => $time)); + } + + /////////////////////////////////////////////////////////////////// + //////////////////////////// MODIFIERS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Resets the time to 00:00:00 + * + * @return static + */ + public function startOfDay() + { + return $this->hour(0)->minute(0)->second(0); + } + + /** + * Resets the time to 23:59:59 + * + * @return static + */ + public function endOfDay() + { + return $this->hour(23)->minute(59)->second(59); + } + + /** + * Resets the date to the first day of the month and the time to 00:00:00 + * + * @return static + */ + public function startOfMonth() + { + return $this->startOfDay()->day(1); + } + + /** + * Resets the date to end of the month and time to 23:59:59 + * + * @return static + */ + public function endOfMonth() + { + return $this->day($this->daysInMonth)->endOfDay(); + } + + /** + * Resets the date to the first day of the year and the time to 00:00:00 + * + * @return static + */ + public function startOfYear() + { + return $this->month(1)->startOfMonth(); + } + + /** + * Resets the date to end of the year and time to 23:59:59 + * + * @return static + */ + public function endOfYear() + { + return $this->month(static::MONTHS_PER_YEAR)->endOfMonth(); + } + + /** + * Resets the date to the first day of the decade and the time to 00:00:00 + * + * @return static + */ + public function startOfDecade() + { + return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_DECADE); + } + + /** + * Resets the date to end of the decade and time to 23:59:59 + * + * @return static + */ + public function endOfDecade() + { + return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_DECADE + static::YEARS_PER_DECADE - 1); + } + + /** + * Resets the date to the first day of the century and the time to 00:00:00 + * + * @return static + */ + public function startOfCentury() + { + return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY); + } + + /** + * Resets the date to end of the century and time to 23:59:59 + * + * @return static + */ + public function endOfCentury() + { + return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY + static::YEARS_PER_CENTURY - 1); + } + + /** + * Resets the date to the first day of the ISO-8601 week (Monday) and the time to 00:00:00 + * + * @return static + */ + public function startOfWeek() + { + if ($this->dayOfWeek != static::MONDAY) { + $this->previous(static::MONDAY); + } + + return $this->startOfDay(); + } + + /** + * Resets the date to end of the ISO-8601 week (Sunday) and time to 23:59:59 + * + * @return static + */ + public function endOfWeek() + { + if ($this->dayOfWeek != static::SUNDAY) { + $this->next(static::SUNDAY); + } + + return $this->endOfDay(); + } + + /** + * Modify to the next occurence of a given day of the week. + * If no dayOfWeek is provided, modify to the next occurence + * of the current day of the week. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function next($dayOfWeek = null) + { + if ($dayOfWeek === null) { + $dayOfWeek = $this->dayOfWeek; + } + + return $this->startOfDay()->modify('next '.static::$days[$dayOfWeek]); + } + + /** + * Modify to the previous occurence of a given day of the week. + * If no dayOfWeek is provided, modify to the previous occurence + * of the current day of the week. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function previous($dayOfWeek = null) + { + if ($dayOfWeek === null) { + $dayOfWeek = $this->dayOfWeek; + } + + return $this->startOfDay()->modify('last '.static::$days[$dayOfWeek]); + } + + /** + * Modify to the first occurence of a given day of the week + * in the current month. If no dayOfWeek is provided, modify to the + * first day of the current month. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function firstOfMonth($dayOfWeek = null) + { + $this->startOfDay(); + + if ($dayOfWeek === null) { + return $this->day(1); + } + + return $this->modify('first '.static::$days[$dayOfWeek].' of '.$this->format('F').' '.$this->year); + } + + /** + * Modify to the last occurence of a given day of the week + * in the current month. If no dayOfWeek is provided, modify to the + * last day of the current month. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function lastOfMonth($dayOfWeek = null) + { + $this->startOfDay(); + + if ($dayOfWeek === null) { + return $this->day($this->daysInMonth); + } + + return $this->modify('last '.static::$days[$dayOfWeek].' of '.$this->format('F').' '.$this->year); + } + + /** + * Modify to the given occurence of a given day of the week + * in the current month. If the calculated occurence is outside the scope + * of the current month, then return false and no modifications are made. + * Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $nth + * @param int $dayOfWeek + * + * @return mixed + */ + public function nthOfMonth($nth, $dayOfWeek) + { + $dt = $this->copy()->firstOfMonth(); + $check = $dt->format('Y-m'); + $dt->modify('+'.$nth.' '.static::$days[$dayOfWeek]); + + return ($dt->format('Y-m') === $check) ? $this->modify($dt) : false; + } + + /** + * Modify to the first occurence of a given day of the week + * in the current quarter. If no dayOfWeek is provided, modify to the + * first day of the current quarter. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function firstOfQuarter($dayOfWeek = null) + { + return $this->day(1)->month($this->quarter * 3 - 2)->firstOfMonth($dayOfWeek); + } + + /** + * Modify to the last occurence of a given day of the week + * in the current quarter. If no dayOfWeek is provided, modify to the + * last day of the current quarter. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function lastOfQuarter($dayOfWeek = null) + { + return $this->day(1)->month($this->quarter * 3)->lastOfMonth($dayOfWeek); + } + + /** + * Modify to the given occurence of a given day of the week + * in the current quarter. If the calculated occurence is outside the scope + * of the current quarter, then return false and no modifications are made. + * Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $nth + * @param int $dayOfWeek + * + * @return mixed + */ + public function nthOfQuarter($nth, $dayOfWeek) + { + $dt = $this->copy()->day(1)->month($this->quarter * 3); + $last_month = $dt->month; + $year = $dt->year; + $dt->firstOfQuarter()->modify('+'.$nth.' '.static::$days[$dayOfWeek]); + + return ($last_month < $dt->month || $year !== $dt->year) ? false : $this->modify($dt); + } + + /** + * Modify to the first occurence of a given day of the week + * in the current year. If no dayOfWeek is provided, modify to the + * first day of the current year. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function firstOfYear($dayOfWeek = null) + { + return $this->month(1)->firstOfMonth($dayOfWeek); + } + + /** + * Modify to the last occurence of a given day of the week + * in the current year. If no dayOfWeek is provided, modify to the + * last day of the current year. Use the supplied consts + * to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $dayOfWeek + * + * @return mixed + */ + public function lastOfYear($dayOfWeek = null) + { + return $this->month(static::MONTHS_PER_YEAR)->lastOfMonth($dayOfWeek); + } + + /** + * Modify to the given occurence of a given day of the week + * in the current year. If the calculated occurence is outside the scope + * of the current year, then return false and no modifications are made. + * Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY. + * + * @param int $nth + * @param int $dayOfWeek + * + * @return mixed + */ + public function nthOfYear($nth, $dayOfWeek) + { + $dt = $this->copy()->firstOfYear()->modify('+'.$nth.' '.static::$days[$dayOfWeek]); + + return $this->year == $dt->year ? $this->modify($dt) : false; + } + + /** + * Modify the current instance to the average of a given instance (default now) and the current instance. + * + * @param Carbon $dt + * + * @return static + */ + public function average(Carbon $dt = null) + { + $dt = ($dt === null) ? static::now($this->tz) : $dt; + + return $this->addSeconds((int) ($this->diffInSeconds($dt, false) / 2)); + } + + /** + * Check if its the birthday. Compares the date/month values of the two dates. + * + * @param Carbon $dt + * + * @return boolean + */ + public function isBirthday(Carbon $dt) + { + return $this->format('md') === $dt->format('md'); + } +} diff --git a/vendor/nesbot/carbon/src/Carbon/CarbonInterval.php b/vendor/nesbot/carbon/src/Carbon/CarbonInterval.php new file mode 100755 index 0000000..cc13a9f --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/CarbonInterval.php @@ -0,0 +1,509 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Carbon; + +use DateInterval; +use InvalidArgumentException; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\Translation\Loader\ArrayLoader; + +/** + * A simple API extension for DateInterval. + * The implemenation provides helpers to handle weeks but only days are saved. + * Weeks are calculated based on the total days of the current instance. + * + * @property integer $years Total years of the current interval. + * @property integer $months Total months of the current interval. + * @property integer $weeks Total weeks of the current interval calculated from the days. + * @property integer $dayz Total days of the current interval (weeks * 7 + days). + * @property integer $hours Total hours of the current interval. + * @property integer $minutes Total minutes of the current interval. + * @property integer $seconds Total seconds of the current interval. + * + * @property-read integer $dayzExcludeWeeks Total days remaining in the final week of the current instance (days % 7). + * @property-read integer $daysExcludeWeeks alias of dayzExcludeWeeks + * + * @method static CarbonInterval years($years = 1) Create instance specifying a number of years. + * @method static CarbonInterval year($years = 1) Alias for years() + * @method static CarbonInterval months($months = 1) Create instance specifying a number of months. + * @method static CarbonInterval month($months = 1) Alias for months() + * @method static CarbonInterval weeks($weeks = 1) Create instance specifying a number of weeks. + * @method static CarbonInterval week($weeks = 1) Alias for weeks() + * @method static CarbonInterval days($days = 1) Create instance specifying a number of days. + * @method static CarbonInterval dayz($days = 1) Alias for days() + * @method static CarbonInterval day($days = 1) Alias for days() + * @method static CarbonInterval hours($hours = 1) Create instance specifying a number of hours. + * @method static CarbonInterval hour($hours = 1) Alias for hours() + * @method static CarbonInterval minutes($minutes = 1) Create instance specifying a number of minutes. + * @method static CarbonInterval minute($minutes = 1) Alias for minutes() + * @method static CarbonInterval seconds($seconds = 1) Create instance specifying a number of seconds. + * @method static CarbonInterval second($seconds = 1) Alias for seconds() + * + * @method CarbonInterval years() years($years = 1) Set the years portion of the current interval. + * @method CarbonInterval year() year($years = 1) Alias for years(). + * @method CarbonInterval months() months($months = 1) Set the months portion of the current interval. + * @method CarbonInterval month() month($months = 1) Alias for months(). + * @method CarbonInterval weeks() weeks($weeks = 1) Set the weeks portion of the current interval. Will overwrite dayz value. + * @method CarbonInterval week() week($weeks = 1) Alias for weeks(). + * @method CarbonInterval days() days($days = 1) Set the days portion of the current interval. + * @method CarbonInterval dayz() dayz($days = 1) Alias for days(). + * @method CarbonInterval day() day($days = 1) Alias for days(). + * @method CarbonInterval hours() hours($hours = 1) Set the hours portion of the current interval. + * @method CarbonInterval hour() hour($hours = 1) Alias for hours(). + * @method CarbonInterval minutes() minutes($minutes = 1) Set the minutes portion of the current interval. + * @method CarbonInterval minute() minute($minutes = 1) Alias for minutes(). + * @method CarbonInterval seconds() seconds($seconds = 1) Set the seconds portion of the current interval. + * @method CarbonInterval second() second($seconds = 1) Alias for seconds(). + */ +class CarbonInterval extends DateInterval +{ + /** + * Interval spec period designators + */ + const PERIOD_PREFIX = 'P'; + const PERIOD_YEARS = 'Y'; + const PERIOD_MONTHS = 'M'; + const PERIOD_DAYS = 'D'; + const PERIOD_TIME_PREFIX = 'T'; + const PERIOD_HOURS = 'H'; + const PERIOD_MINUTES = 'M'; + const PERIOD_SECONDS = 'S'; + + /** + * A translator to ... er ... translate stuff + * + * @var TranslatorInterface + */ + protected static $translator; + + /** + * Before PHP 5.4.20/5.5.4 instead of FALSE days will be set to -99999 when the interval instance + * was created by DateTime:diff(). + */ + const PHP_DAYS_FALSE = -99999; + + /** + * Determine if the interval was created via DateTime:diff() or not. + * + * @return boolean + */ + private static function wasCreatedFromDiff(DateInterval $interval) + { + return ($interval->days !== false && $interval->days !== static::PHP_DAYS_FALSE); + } + + /////////////////////////////////////////////////////////////////// + //////////////////////////// CONSTRUCTORS ///////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Create a new CarbonInterval instance. + * + * @param integer $years + * @param integer $months + * @param integer $weeks + * @param integer $days + * @param integer $hours + * @param integer $minutes + * @param integer $seconds + */ + public function __construct($years = 1, $months = null, $weeks = null, $days = null, $hours = null, $minutes = null, $seconds = null) + { + $spec = static::PERIOD_PREFIX; + + $spec .= $years > 0 ? $years.static::PERIOD_YEARS : ''; + $spec .= $months > 0 ? $months.static::PERIOD_MONTHS : ''; + + $specDays = 0; + $specDays += $weeks > 0 ? $weeks * Carbon::DAYS_PER_WEEK : 0; + $specDays += $days > 0 ? $days : 0; + + $spec .= ($specDays > 0) ? $specDays.static::PERIOD_DAYS : ''; + + if ($hours > 0 || $minutes > 0 || $seconds > 0) { + $spec .= static::PERIOD_TIME_PREFIX; + $spec .= $hours > 0 ? $hours.static::PERIOD_HOURS : ''; + $spec .= $minutes > 0 ? $minutes.static::PERIOD_MINUTES : ''; + $spec .= $seconds > 0 ? $seconds.static::PERIOD_SECONDS : ''; + } + + parent::__construct($spec); + } + + /** + * Create a new CarbonInterval instance from specific values. + * This is an alias for the constructor that allows better fluent + * syntax as it allows you to do CarbonInterval::create(1)->fn() rather than + * (new CarbonInterval(1))->fn(). + * + * @param integer $years + * @param integer $months + * @param integer $weeks + * @param integer $days + * @param integer $hours + * @param integer $minutes + * @param integer $seconds + * + * @return static + */ + public static function create($years = 1, $months = null, $weeks = null, $days = null, $hours = null, $minutes = null, $seconds = null) + { + return new static($years, $months, $weeks, $days, $hours, $minutes, $seconds); + } + + /** + * Provide static helpers to create instances. Allows CarbonInterval::years(3). + * + * Note: This is done using the magic method to allow static and instance methods to + * have the same names. + * + * @return static + */ + public static function __callStatic($name, $args) + { + $arg = count($args) == 0 ? 1 : $args[0]; + + switch ($name) { + case 'years': + case 'year': + return new static($arg); + + case 'months': + case 'month': + return new static(null, $arg); + + case 'weeks': + case 'week': + return new static(null, null, $arg); + + case 'days': + case 'dayz': + case 'day': + return new static(null, null, null, $arg); + + case 'hours': + case 'hour': + return new static(null, null, null, null, $arg); + + case 'minutes': + case 'minute': + return new static(null, null, null, null, null, $arg); + + case 'seconds': + case 'second': + return new static(null, null, null, null, null, null, $arg); + } + } + + /** + * Create a CarbonInterval instance from a DateInterval one. Can not instance + * DateInterval objects created from DateTime::diff() as you can't externally + * set the $days field. + * + * @param DateInterval $dt + * + * @throws InvalidArgumentException + * + * @return static + */ + public static function instance(DateInterval $di) + { + if (static::wasCreatedFromDiff($di)) { + throw new InvalidArgumentException("Can not instance a DateInterval object created from DateTime::diff()."); + } + + $instance = new static($di->y, $di->m, 0, $di->d, $di->h, $di->i, $di->s); + $instance->invert = $di->invert; + $instance->days = $di->days; + return $instance; + } + + /////////////////////////////////////////////////////////////////// + /////////////////////// LOCALIZATION ////////////////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Intialize the translator instance if necessary. + * + * @return TranslatorInterface + */ + protected static function translator() + { + if (static::$translator == null) { + static::$translator = new Translator('en'); + static::$translator->addLoader('array', new ArrayLoader()); + static::setLocale('en'); + } + + return static::$translator; + } + + /** + * Get the translator instance in use + * + * @return TranslatorInterface + */ + public static function getTranslator() + { + return static::translator(); + } + + /** + * Set the translator instance to use + * + * @param TranslatorInterface + */ + public static function setTranslator(TranslatorInterface $translator) + { + static::$translator = $translator; + } + + /** + * Get the current translator locale + * + * @return string + */ + public static function getLocale() + { + return static::translator()->getLocale(); + } + + /** + * Set the current translator locale + * + * @param string $locale + */ + public static function setLocale($locale) + { + static::translator()->setLocale($locale); + + // Ensure the locale has been loaded. + static::translator()->addResource('array', require __DIR__.'/Lang/'.$locale.'.php', $locale); + } + + /////////////////////////////////////////////////////////////////// + ///////////////////////// GETTERS AND SETTERS ///////////////////// + /////////////////////////////////////////////////////////////////// + + /** + * Get a part of the CarbonInterval object + * + * @param string $name + * + * @throws InvalidArgumentException + * + * @return integer + */ + public function __get($name) + { + switch ($name) { + case 'years': + return $this->y; + + case 'months': + return $this->m; + + case 'dayz': + return $this->d; + + case 'hours': + return $this->h; + + case 'minutes': + return $this->i; + + case 'seconds': + return $this->s; + + case 'weeks': + return (int)floor($this->d / Carbon::DAYS_PER_WEEK); + + case 'daysExcludeWeeks': + case 'dayzExcludeWeeks': + return $this->d % Carbon::DAYS_PER_WEEK; + + default: + throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name)); + } + } + + /** + * Set a part of the CarbonInterval object + * + * @param string $name + * @param integer $value + * + * @throws InvalidArgumentException + */ + public function __set($name, $val) + { + switch ($name) { + case 'years': + $this->y = $val; + break; + + case 'months': + $this->m = $val; + break; + + case 'weeks': + $this->d = $val * Carbon::DAYS_PER_WEEK; + break; + + case 'dayz': + $this->d = $val; + break; + + case 'hours': + $this->h = $val; + break; + + case 'minutes': + $this->i = $val; + break; + + case 'seconds': + $this->s = $val; + break; + } + } + + /** + * Allow setting of weeks and days to be cumulative. + * + * @param int $weeks Number of weeks to set + * @param int $days Number of days to set + * + * @return static + */ + public function weeksAndDays($weeks, $days) + { + $this->dayz = ($weeks * Carbon::DAYS_PER_WEEK) + $days; + return $this; + } + + /** + * Allow fluent calls on the setters... CarbonInterval::years(3)->months(5)->day(). + * + * Note: This is done using the magic method to allow static and instance methods to + * have the same names. + * + * @return static + */ + public function __call($name, $args) + { + $arg = count($args) == 0 ? 1 : $args[0]; + + switch ($name) { + case 'years': + case 'year': + $this->years = $arg; + break; + + case 'months': + case 'month': + $this->months = $arg; + break; + + case 'weeks': + case 'week': + $this->dayz = $arg * Carbon::DAYS_PER_WEEK; + break; + + case 'days': + case 'dayz': + case 'day': + $this->dayz = $arg; + break; + + case 'hours': + case 'hour': + $this->hours = $arg; + break; + + case 'minutes': + case 'minute': + $this->minutes = $arg; + break; + + case 'seconds': + case 'second': + $this->seconds = $arg; + break; + } + + return $this; + } + + /** + * Get the current interval in a human readable format in the current locale. + * + * @return string + */ + public function forHumans() + { + $periods = array( + 'year' => $this->years, + 'month' => $this->months, + 'week' => $this->weeks, + 'day' => $this->daysExcludeWeeks, + 'hour' => $this->hours, + 'minute' => $this->minutes, + 'second' => $this->seconds, + ); + + $parts = array(); + foreach ($periods as $unit => $count) { + if ($count > 0) { + array_push($parts, static::translator()->transChoice($unit, $count, array(':count' => $count))); + } + } + + return implode(' ', $parts); + } + + /** + * Format the instance as a string using the forHumans() function. + * + * @return string + */ + public function __toString() + { + return $this->forHumans(); + } + + /** + * Add the passed interval to the current instance + * + * @param DateInterval $interval + * + * @return static + */ + public function add(DateInterval $interval) + { + $sign = ($interval->invert === 1) ? -1 : 1; + + if (static::wasCreatedFromDiff($interval)) { + $this->dayz = $this->dayz + ($interval->days * $sign); + } else { + $this->years = $this->years + ($interval->y * $sign); + $this->months = $this->months + ($interval->m * $sign); + $this->dayz = $this->dayz + ($interval->d * $sign); + $this->hours = $this->hours + ($interval->h * $sign); + $this->minutes = $this->minutes + ($interval->i * $sign); + $this->seconds = $this->seconds + ($interval->s * $sign); + } + + return $this; + } +} diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/ar.php b/vendor/nesbot/carbon/src/Carbon/Lang/ar.php new file mode 100755 index 0000000..1ca9a5e --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/ar.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/ar/date.php + */ + +return array( + 'year' => '{0}سنة|{1}سنة|{2}سنتين|[3,Inf]:count سنوات / سنين', + 'month' => '{0}شهر|{1}شهر|{2}شهرين|[3,Inf]:count شهور / أشهر', + 'week' => '{0}أسبوع|{1}أسبوع|{2}أسبوعين|[3,Inf]:count أسابيع', + 'day' => '{0}يوم|{1}يوم|{2}يومين|[3,Inf]:count أيام', + 'hour' => '{0}ساعة|{1}ساعة|{2}ساعتين|[3,Inf]:count ساعات', + 'minute' => '{0}دقيقة|{1}دقيقة|{2}دقيقتين|[3,Inf]:count دقائق', + 'second' => '{0}ثانية|{1}ثانية|{2}ثانيتين|[3,Inf]:count ثوان', + 'ago' => 'منذ :time', + 'from_now' => 'من الآن :time', + 'after' => 'بعد :time', + 'before' => 'قبل :time', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/az.php b/vendor/nesbot/carbon/src/Carbon/Lang/az.php new file mode 100755 index 0000000..6202be9 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/az.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ + /** + * Extracted from https://github.com/The-Hasanov/laravel-date/blob/1006f37c431178b5c7219d02c93579c9690ae546/src/Lang/az.php + */ +return array( + 'year' => ':count il', + 'month' => ':count ay', + 'week' => ':count həftə', + 'day' => ':count gün', + 'hour' => ':count saat', + 'minute' => ':count dəqiqə', + 'second' => ':count saniyə', + 'ago' => ':time öncə', + 'from_now' => ':time sonra', + 'after' => ':time sonra', + 'before' => ':time öncə' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/bg.php b/vendor/nesbot/carbon/src/Carbon/Lang/bg.php new file mode 100755 index 0000000..7a262a7 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/bg.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/bg/date.php + */ + +return array( + 'year' => '1 година|:count години', + 'month' => '1 месец|:count месеца', + 'week' => '1 седмица|:count седмици', + 'day' => '1 ден|:count дни', + 'hour' => '1 час|:count часа', + 'minute' => '1 минута|:count минути', + 'second' => '1 секунда|:count секунди', + 'ago' => 'преди :time', + 'from_now' => ':time от сега', + 'after' => 'след :time', + 'before' => 'преди :time', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/ca.php b/vendor/nesbot/carbon/src/Carbon/Lang/ca.php new file mode 100755 index 0000000..95e04e4 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/ca.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/ca/date.php + */ +return array( + 'year' => '1 any|:count anys', + 'month' => '1 mes|:count mesos', + 'week' => '1 setmana|:count setmanes', + 'day' => '1 dia|:count díes', + 'hour' => '1 hora|:count hores', + 'minute' => '1 minut|:count minuts', + 'second' => '1 segon|:count segons', + 'ago' => 'Fa :time', + 'from_now' => 'Dins de :time', + 'after' => ':time després', + 'before' => ':time abans', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/cs.php b/vendor/nesbot/carbon/src/Carbon/Lang/cs.php new file mode 100755 index 0000000..da1a7e3 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/cs.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/cs/date.php + */ +return array( + 'year' => 'rok|:count roky|:count let', + 'month' => 'měsíc|:count měsíce|:count měsíců', + 'week' => 'týden|:count týdny|:count týdnů', + 'day' => 'den|:count dny|:count dní', + 'hour' => 'hodinu|:count hodiny|:count hodin', + 'minute' => 'minutu|:count minuty|:count minut', + 'second' => 'sekundu|:count sekundy|:count sekund', + 'ago' => 'před :time', + 'from_now' => 'za :time', + 'after' => ':time později', + 'before' => ':time předtím', + 'year_ago' => 'rokem|[2,Inf]:count lety', + 'month_ago' => 'měsícem|[2,Inf]:count měsíci', + 'week_ago' => 'týdnem|[2,Inf]:count týdny', + 'day_ago' => 'dnem|[2,Inf]:count dny', + 'hour_ago' => 'hodinou|[2,Inf]:count hodinami', + 'minute_ago' => 'minutou|[2,Inf]:count minutami', + 'second_ago' => 'sekundou|[2,Inf]:count sekundami', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/da.php b/vendor/nesbot/carbon/src/Carbon/Lang/da.php new file mode 100755 index 0000000..4586fad --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/da.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 år|:count år', + 'month' => '1 måned|:count måneder', + 'week' => '1 uge|:count uger', + 'day' => '1 dag|:count dage', + 'hour' => '1 time|:count timer', + 'minute' => '1 minut|:count minutter', + 'second' => '1 sekund|:count sekunder', + 'ago' => ':time siden', + 'from_now' => 'om :time', + 'after' => ':time efter', + 'before' => ':time før', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/de.php b/vendor/nesbot/carbon/src/Carbon/Lang/de.php new file mode 100755 index 0000000..7586b32 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/de.php @@ -0,0 +1,39 @@ + + * + * This file is released under the terms of CC0. + * CC0 is even more permissive than the MIT license, allowing you to use the code in + * any manner you want, without any copyright headers, notices, or other attribution. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 Jahr|:count Jahre', + 'month' => '1 Monat|:count Monate', + 'week' => '1 Woche|:count Wochen', + 'day' => '1 Tag|:count Tage', + 'hour' => '1 Stunde|:count Stunden', + 'minute' => '1 Minute|:count Minuten', + 'second' => '1 Sekunde|:count Sekunden', + 'ago' => 'vor :time', + 'from_now' => 'in :time', + 'after' => ':time später', + 'before' => ':time zuvor', + + 'year_from_now' => '1 Jahr|:count Jahren', + 'month_from_now' => '1 Monat|:count Monaten', + 'week_from_now' => '1 Woche|:count Wochen', + 'day_from_now' => '1 Tag|:count Tagen', + 'year_ago' => '1 Jahr|:count Jahren', + 'month_ago' => '1 Monat|:count Monaten', + 'week_ago' => '1 Woche|:count Wochen', + 'day_ago' => '1 Tag|:count Tagen', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/el.php b/vendor/nesbot/carbon/src/Carbon/Lang/el.php new file mode 100755 index 0000000..0cc34e6 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/el.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/el/date.php + */ +return array( + 'year' => '1 χρόνος|:count χρόνια', + 'month' => '1 μήνας|:count μήνες', + 'week' => '1 εβδομάδα|:count εβδομάδες', + 'day' => '1 μέρα|:count μέρες', + 'hour' => '1 ώρα|:count ώρες', + 'minute' => '1 λεπτό|:count λεπτά', + 'second' => '1 δευτερόλεπτο|:count δευτερόλεπτα', + 'ago' => 'πρίν απο :time', + 'from_now' => 'σε :time απο τώρα', + 'after' => ':time μετά', + 'before' => ':time πρίν' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/en.php b/vendor/nesbot/carbon/src/Carbon/Lang/en.php new file mode 100755 index 0000000..6b682b5 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/en.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 year|:count years', + 'month' => '1 month|:count months', + 'week' => '1 week|:count weeks', + 'day' => '1 day|:count days', + 'hour' => '1 hour|:count hours', + 'minute' => '1 minute|:count minutes', + 'second' => '1 second|:count seconds', + 'ago' => ':time ago', + 'from_now' => ':time from now', + 'after' => ':time after', + 'before' => ':time before', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/eo.php b/vendor/nesbot/carbon/src/Carbon/Lang/eo.php new file mode 100755 index 0000000..34cd0ee --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/eo.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/eo/date.php + */ +return array( + 'year' => '1 jaro|:count jaroj', + 'month' => '1 monato|:count monatoj', + 'week' => '1 semajno|:count semajnoj', + 'day' => '1 tago|:count tagoj', + 'hour' => '1 horo|:count horoj', + 'minute' => '1 minuto|:count minutoj', + 'second' => '1 sekundo|:count sekundoj', + 'ago' => 'antaŭ :time', + 'from_now' => 'je :time', + 'after' => ':time poste', + 'before' => ':time antaŭe' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/es.php b/vendor/nesbot/carbon/src/Carbon/Lang/es.php new file mode 100755 index 0000000..b4573ec --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/es.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 año|:count años', + 'month' => '1 mes|:count meses', + 'week' => '1 semana|:count semanas', + 'day' => '1 día|:count días', + 'hour' => '1 hora|:count horas', + 'minute' => '1 minuto|:count minutos', + 'second' => '1 segundo|:count segundos', + 'ago' => 'hace :time', + 'from_now' => 'dentro de :time', + 'after' => ':time antes', + 'before' => ':time después', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/eu b/vendor/nesbot/carbon/src/Carbon/Lang/eu new file mode 100755 index 0000000..91f1d2a --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/eu @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/eu/date.php + */ +return array( + 'year' => 'Urte 1|:count urte', + 'month' => 'Hile 1|:count hile', + 'week' => 'Aste 1|:count aste', + 'day' => 'Egun 1|:count egun', + 'hour' => 'Ordu 1|:count ordu', + 'minute' => 'Minutu 1|:count minutu', + 'second' => 'Segundu 1|:count segundu', + 'ago' => 'Orain dela :time', + 'from_now' => ':time barru', + 'after' => ':time geroago', + 'before' => ':time lehenago' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/fa.php b/vendor/nesbot/carbon/src/Carbon/Lang/fa.php new file mode 100755 index 0000000..581424e --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/fa.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ + +return array( + 'year' => ':count سال', + 'month' => ':count ماه', + 'week' => ':count هفته', + 'day' => ':count روز', + 'hour' => ':count ساعت', + 'minute' => ':count دقیقه', + 'second' => ':count ثانیه', + 'ago' => ':time پیش', + 'from_now' => ':time بعد', + 'after' => ':time پیش از', + 'before' => ':time پس از', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/fi.php b/vendor/nesbot/carbon/src/Carbon/Lang/fi.php new file mode 100755 index 0000000..7930c6b --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/fi.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/fi/date.php + */ +return array( + 'year' => '1 vuosi|:count vuotta', + 'month' => '1 kuukausi|:count kuukautta', + 'week' => '1 viikko|:count viikkoa', + 'day' => '1 päivä|:count päivää', + 'hour' => '1 tunti|:count tuntia', + 'minute' => '1 minuutti|:count minuuttia', + 'second' => '1 sekunti|:count sekuntia', + 'ago' => ':time sitten', + 'from_now' => ':time tästä hetkestä', + 'after' => ':time sen jälkeen', + 'before' => ':time ennen' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/fr.php b/vendor/nesbot/carbon/src/Carbon/Lang/fr.php new file mode 100755 index 0000000..b10ac40 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/fr.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 an|:count ans', + 'month' => ':count mois', + 'week' => '1 semaine|:count semaines', + 'day' => '1 jour|:count jours', + 'hour' => '1 heure|:count heures', + 'minute' => '1 minute|:count minutes', + 'second' => '1 seconde|:count secondes', + 'ago' => 'il y a :time', + 'from_now' => 'dans :time', + 'after' => ':time après', + 'before' => ':time avant', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/hr.php b/vendor/nesbot/carbon/src/Carbon/Lang/hr.php new file mode 100755 index 0000000..7ab1c26 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/hr.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/hr/date.php + */ +return array( + 'year' => ':count godinu|:count godine|:count godina', + 'month' => ':count mjesec|:count mjeseca|:count mjeseci', + 'week' => ':count tjedan|:count tjedna|:count tjedana', + 'day' => ':count dan|:count dana|:count dana', + 'hour' => ':count sat|:count sata|:count sati', + 'minute' => ':count minutu|:count minute |:count minuta', + 'second' => ':count sekundu|:count sekunde|:count sekundi', + 'ago' => 'prije :time', + 'from_now' => 'za :time', + 'after' => 'za :time', + 'before' => 'prije :time' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/hu.php b/vendor/nesbot/carbon/src/Carbon/Lang/hu.php new file mode 100755 index 0000000..a866039 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/hu.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/hu/date.php + */ +return array( + 'year' => '1 évvel|:count évvel', + 'month' => '1 hónappal|:count hónappal', + 'week' => '1 héttel|:count héttel', + 'day' => '1 nappal|:count nappal', + 'hour' => '1 órával|:count órával', + 'minute' => '1 perccel|:count perccel', + 'second' => '1 másodperccel|:count másodperccel', + 'ago' => ':time korábban', + 'from_now' => ':time később', + 'after' => ':time később', + 'before' => ':time korábban' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/id.php b/vendor/nesbot/carbon/src/Carbon/Lang/id.php new file mode 100755 index 0000000..4b168f6 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/id.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/id/date.php + */ +return array( + 'year' => ':count tahun', + 'month' => ':count bulan', + 'week' => ':count minggu', + 'day' => ':count hari', + 'hour' => ':count jam', + 'minute' => ':count menit', + 'second' => ':count detik', + 'ago' => ':time yang lalu', + 'from_now' => ':time dari sekarang', + 'after' => ':time setelah', + 'before' => ':time sebelum' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/it.php b/vendor/nesbot/carbon/src/Carbon/Lang/it.php new file mode 100755 index 0000000..ef1b55d --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/it.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 anno|:count anni', + 'month' => '1 mese|:count mesi', + 'week' => '1 settimana|:count settimane', + 'day' => '1 giorno|:count giorni', + 'hour' => '1 ora|:count ore', + 'minute' => '1 minuto|:count minuti', + 'second' => '1 secondo|:count secondi', + 'ago' => ':time fa', + 'from_now' => ':time da adesso', + 'after' => ':time dopo', + 'before' => ':time prima', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/ja.php b/vendor/nesbot/carbon/src/Carbon/Lang/ja.php new file mode 100755 index 0000000..4b5e77d --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/ja.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/ja/date.php + */ +return array( + 'year' => ':count 年', + 'month' => ':count ヶ月', + 'week' => ':count 週間', + 'day' => ':count 日', + 'hour' => ':count 時間', + 'minute' => ':count 分', + 'second' => ':count 秒', + 'ago' => ':time 前', + 'from_now' => '今から :time', + 'after' => ':time 後', + 'before' => ':time 前' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/ko.php b/vendor/nesbot/carbon/src/Carbon/Lang/ko.php new file mode 100755 index 0000000..f3ed1c4 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/ko.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/cs/date.php + */ +return array( + 'year' => ':count 년', + 'month' => ':count 개월', + 'week' => ':count 주일', + 'day' => ':count 일', + 'hour' => ':count 시간', + 'minute' => ':count 분', + 'second' => ':count 초', + 'ago' => ':time 전', + 'from_now' => ':time 후', + 'after' => ':time 뒤', + 'before' => ':time 앞', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/lt.php b/vendor/nesbot/carbon/src/Carbon/Lang/lt.php new file mode 100755 index 0000000..3d8b7f2 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/lt.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 metai|:count metai', + 'month' => '1 mėnuo|:count mėnesiai', + 'week' => '1 savaitė|:count savaitės', + 'day' => '1 diena|:count dienos', + 'hour' => '1 valanda|:count valandos', + 'minute' => '1 minutė|:count minutės', + 'second' => '1 sekundė|:count sekundės', + 'ago' => 'prieš :time', + 'from_now' => ':time nuo dabar', + 'after' => 'po :time', + 'before' => 'prieš :time', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/nl.php b/vendor/nesbot/carbon/src/Carbon/Lang/nl.php new file mode 100755 index 0000000..8104b71 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/nl.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 jaar|:count jaren', + 'month' => '1 maand|:count maanden', + 'week' => '1 week|:count weken', + 'day' => '1 dag|:count dagen', + 'hour' => ':count uur', + 'minute' => '1 minuut|:count minuten', + 'second' => '1 seconde|:count seconden', + 'ago' => ':time geleden', + 'from_now' => 'over :time', + 'after' => ':time later', + 'before' => ':time eerder', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/no.php b/vendor/nesbot/carbon/src/Carbon/Lang/no.php new file mode 100755 index 0000000..0cfd3d3 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/no.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/no/date.php + */ +return array( + 'year' => '1 år|:count år', + 'month' => '1 måned|:count måneder', + 'week' => '1 uke|:count uker', + 'day' => '1 dag|:count dager', + 'hour' => '1 time|:count timer', + 'minute' => '1 minutt|:count minutter', + 'second' => '1 sekund|:count sekunder', + 'ago' => ':time siden', + 'from_now' => 'om :time', + 'after' => ':time etter', + 'before' => ':time før' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/pl.php b/vendor/nesbot/carbon/src/Carbon/Lang/pl.php new file mode 100755 index 0000000..05fea60 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/pl.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/pl/date.php + */ +return array( + 'year' => '1 rok|:count lata|:count lat', + 'month' => '1 miesiąc|:count miesiące|:count miesięcy', + 'week' => '1 tydzień|:count tygodnie|:count tygodni', + 'day' => '1 dzień|:count dni|:count dni', + 'hour' => '1 godzina|:count godziny|:count godzin', + 'minute' => '1 minuta|:count minuty|:count minut', + 'second' => '1 sekunda|:count sekundy|:count sekund', + 'ago' => ':time temu', + 'from_now' => ':time od teraz', + 'after' => ':time przed', + 'before' => ':time po' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/pt.php b/vendor/nesbot/carbon/src/Carbon/Lang/pt.php new file mode 100755 index 0000000..28aab4d --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/pt.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/pt/date.php + */ +return array( + 'year' => '1 ano|:count anos', + 'month' => '1 mês|:count meses', + 'week' => '1 semana|:count semanas', + 'day' => '1 dia|:count dias', + 'hour' => '1 hora|:count horas', + 'minute' => '1 minuto|:count minutos', + 'second' => '1 segundo|:count segundos', + 'ago' => ':time atrás', + 'from_now' => 'em :time', + 'after' => ':time depois', + 'before' => ':time antes' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/pt_BR.php b/vendor/nesbot/carbon/src/Carbon/Lang/pt_BR.php new file mode 100755 index 0000000..70435ee --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/pt_BR.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => '1 ano|:count anos', + 'month' => '1 mês|:count meses', + 'week' => '1 semana|:count semanas', + 'day' => '1 dia|:count dias', + 'hour' => '1 hora|:count horas', + 'minute' => '1 minuto|:count minutos', + 'second' => '1 segundo|:count segundos', + 'ago' => 'há :time', + 'from_now' => 'dentro de :time', + 'after' => ':time depois', + 'before' => ':time antes', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/ro.php b/vendor/nesbot/carbon/src/Carbon/Lang/ro.php new file mode 100755 index 0000000..efc847d --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/ro.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/ro/date.php + */ +return array( + 'year' => 'un an|:count ani|:count ani', + 'month' => 'o lună|:count luni|:count luni', + 'week' => 'o săptămână|:count săptămâni|:count săptămâni', + 'day' => 'o zi|:count zile|:count zile', + 'hour' => 'o oră|:count ore|:count ore', + 'minute' => 'un minut|:count minute|:count minute', + 'second' => 'o secundă|:count secunde|:count secunde', + 'ago' => 'acum :time', + 'from_now' => ':time de acum', + 'after' => 'peste :time', + 'before' => 'acum :time' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/ru.php b/vendor/nesbot/carbon/src/Carbon/Lang/ru.php new file mode 100755 index 0000000..e4a1cb5 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/ru.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/ru/date.php + */ +return array( + 'year' => ':count год|:count года|:count лет', + 'month' => ':count месяц|:count месяца|:count месяцев', + 'week' => ':count неделю|:count недели|:count недель', + 'day' => ':count день|:count дня|:count дней', + 'hour' => ':count час|:count часа|:count часов', + 'minute' => ':count минуту|:count минуты|:count минут', + 'second' => ':count секунду|:count секунды|:count секунд', + 'ago' => ':time назад', + 'from_now' => 'через :time', + 'after' => ':time после', + 'before' => ':time до' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/sk.php b/vendor/nesbot/carbon/src/Carbon/Lang/sk.php new file mode 100755 index 0000000..8087afe --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/sk.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/sk/date.php + */ +return array( + 'year' => 'rok|:count roky|:count rokov', + 'month' => 'mesiac|:count mesiace|:count mesiacov', + 'week' => 'týždeň|:count týždne|:count týždňov', + 'day' => 'deň|:count dni|:count dní', + 'hour' => 'hodinu|:count hodiny|:count hodín', + 'minute' => 'minútu|:count minúty|:count minút', + 'second' => 'sekundu|:count sekundy|:count sekúnd', + 'ago' => 'pred :time', + 'from_now' => 'za :time', + 'after' => ':time neskôr', + 'before' => ':time predtým' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/sl.php b/vendor/nesbot/carbon/src/Carbon/Lang/sl.php new file mode 100755 index 0000000..bcfc001 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/sl.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/sl/date.php + */ +return array( + 'year' => '1 leto|:count leti|:count leta|:count let', + 'month' => '1 mesec|:count meseca|:count mesece|:count mesecev', + 'week' => '1 teden|:count tedna|:count tedne|:count tednov', + 'day' => '1 dan|:count dni|:count dni|:count dni', + 'hour' => '1 uro|:count uri|:count ure|:count ur', + 'minute' => '1 minuto|:count minuti|:count minute|:count minut', + 'second' => '1 sekundo|:count sekundi|:count sekunde|:count sekund', + 'year_ago' => '1 letom|:count leti|:count leti|:count leti', + 'month_ago' => '1 mesecem|:count meseci|:count meseci|:count meseci', + 'week_ago' => '1 tednom|:count tedni|:count tedni', + 'day_ago' => '1 dnem|:count dnevoma|:count dnevi|:count dnevi', + 'hour_ago' => '1 uro|:count urama|:count urami|:count urami', + 'minute_ago'=> '1 minuto|:count minutama|:count minutami', + 'second_ago'=> '1 sekundo|:count sekundama|:count sekundami|:count sekundami', + 'ago' => 'pred :time', + 'from_now' => 'čez :time', + 'after' => 'čez :time', + 'before' => 'pred :time' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/sr.php b/vendor/nesbot/carbon/src/Carbon/Lang/sr.php new file mode 100755 index 0000000..c19087f --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/sr.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/sr/date.php + */ +return array( + 'year' => ':count godina|:count godine|:count godina', + 'month' => ':count mesec|:count meseca|:count meseci', + 'week' => ':count nedelja|:count nedelje|:count nedelja', + 'day' => ':count dan|:count dana|:count dana', + 'hour' => ':count sat|:count sata|:count sati', + 'minute' => ':count minut|:count minuta |:count minuta', + 'second' => ':count sekund|:count sekunde|:count sekunde', + 'ago' => 'pre :time', + 'from_now' => ':time od sada', + 'after' => 'nakon :time', + 'before' => 'pre :time' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/sv.php b/vendor/nesbot/carbon/src/Carbon/Lang/sv.php new file mode 100755 index 0000000..2ed2349 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/sv.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/sv/date.php + */ +return array( + 'year' => '1 år|:count år', + 'month' => '1 månad|:count månader', + 'week' => '1 vecka|:count veckor', + 'day' => '1 dag|:count dagar', + 'hour' => '1 timme|:count timmar', + 'minute' => '1 minut|:count minuter', + 'second' => '1 sekund|:count sekunder', + 'ago' => ':time sedan', + 'from_now' => 'om :time', + 'after' => ':time efter', + 'before' => ':time före' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/th.php b/vendor/nesbot/carbon/src/Carbon/Lang/th.php new file mode 100755 index 0000000..aad56c2 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/th.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/th/date.php + */ +return array( + 'year' => '1 ปี|:count ปี', + 'month' => '1 เดือน|:count เดือน', + 'week' => '1 สัปดาห์|:count สัปดาห์', + 'day' => '1 วัน|:count วัน', + 'hour' => '1 ชั่วโมง|:count ชั่วโมง', + 'minute' => '1 นาที|:count นาที', + 'second' => '1 วินาที|:count วินาที', + 'ago' => ':time sitten', + 'ago' => ':time ที่แล้ว', + 'from_now' => ':time จากนี้', + 'after' => 'หลัง:time', + 'before' => 'ก่อน:time' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/tr.php b/vendor/nesbot/carbon/src/Carbon/Lang/tr.php new file mode 100755 index 0000000..52561db --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/tr.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +return array( + 'year' => ':count yıl', + 'month' => ':count ay', + 'week' => ':count hafta', + 'day' => ':count gün', + 'hour' => ':count saat', + 'minute' => ':count dakika', + 'second' => ':count saniye', + 'ago' => ':time önce', + 'from_now' => ':time andan itibaren', + 'after' => ':time sonra', + 'before' => ':time önce', +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/uk.php b/vendor/nesbot/carbon/src/Carbon/Lang/uk.php new file mode 100755 index 0000000..8e57386 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/uk.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/uk/date.php + */ +return array( + 'year' => ':count рік|:count роки|:count років', + 'month' => ':count місяць|:count місяці|:count місяців', + 'week' => ':count тиждень|:count тижні|:count тижнів', + 'day' => ':count день|:count дні|:count днів', + 'hour' => ':count година|:count години|:count годин', + 'minute' => ':count хвилину|:count хвилини|:count хвилин', + 'second' => ':count секунду|:count секунди|:count секунд', + 'ago' => ':time назад', + 'from_now' => 'через :time', + 'after' => ':time після', + 'before' => ':time до' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/vi.php b/vendor/nesbot/carbon/src/Carbon/Lang/vi.php new file mode 100755 index 0000000..7c70ff9 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/vi.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/vi/date.php + */ +return array( + 'year' => ':count năm', + 'month' => ':count tháng', + 'week' => ':count tuần', + 'day' => ':count ngày', + 'hour' => ':count giờ', + 'minute' => ':count phút', + 'second' => ':count giây', + 'ago' => ':time trước', + 'from_now' => ':time từ bây giờ', + 'after' => ':time sau', + 'before' => ':time trước' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/zh-TW.php b/vendor/nesbot/carbon/src/Carbon/Lang/zh-TW.php new file mode 100755 index 0000000..0ffdc7f --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/zh-TW.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/zh-TW/date.php + */ +return array( + 'year' => ':count 年', + 'month' => ':count 月', + 'week' => ':count 周', + 'day' => ':count 天', + 'hour' => ':count 小時', + 'minute' => ':count 分鐘', + 'second' => ':count 秒', + 'ago' => ':time前', + 'from_now' => '距現在 :time', + 'after' => ':time後', + 'before' => ':time前' +); diff --git a/vendor/nesbot/carbon/src/Carbon/Lang/zh.php b/vendor/nesbot/carbon/src/Carbon/Lang/zh.php new file mode 100755 index 0000000..9a74f39 --- /dev/null +++ b/vendor/nesbot/carbon/src/Carbon/Lang/zh.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +/** + * Translation messages. See http://symfony.com/doc/current/book/translation.html + * for possible formats. + * + */ +/** + * Extracted from https://github.com/jenssegers/laravel-date/blob/master/src/lang/zh/date.php + */ +return array( + 'year' => ':count年', + 'month' => ':count月', + 'week' => ':count周', + 'day' => ':count天', + 'hour' => ':count小时', + 'minute' => ':count分钟', + 'second' => ':count秒', + 'ago' => ':time前', + 'from_now' => ':time距现在', + 'after' => ':time后', + 'before' => ':time前' +); diff --git a/vendor/nesbot/carbon/tests/AddTest.php b/vendor/nesbot/carbon/tests/AddTest.php new file mode 100755 index 0000000..ba2db60 --- /dev/null +++ b/vendor/nesbot/carbon/tests/AddTest.php @@ -0,0 +1,241 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class AddTest extends TestFixture +{ + public function testAddYearsPositive() + { + $this->assertSame(1976, Carbon::createFromDate(1975)->addYears(1)->year); + } + + public function testAddYearsZero() + { + $this->assertSame(1975, Carbon::createFromDate(1975)->addYears(0)->year); + } + + public function testAddYearsNegative() + { + $this->assertSame(1974, Carbon::createFromDate(1975)->addYears(-1)->year); + } + + public function testAddYear() + { + $this->assertSame(1976, Carbon::createFromDate(1975)->addYear()->year); + } + + public function testAddMonthsPositive() + { + $this->assertSame(1, Carbon::createFromDate(1975, 12)->addMonths(1)->month); + } + + public function testAddMonthsZero() + { + $this->assertSame(12, Carbon::createFromDate(1975, 12)->addMonths(0)->month); + } + + public function testAddMonthsNegative() + { + $this->assertSame(11, Carbon::createFromDate(1975, 12, 1)->addMonths(-1)->month); + } + + public function testAddMonth() + { + $this->assertSame(1, Carbon::createFromDate(1975, 12)->addMonth()->month); + } + + public function testAddMonthWithOverflow() + { + $this->assertSame(3, Carbon::createFromDate(2012, 1, 31)->addMonth()->month); + } + + public function testAddMonthsNoOverflowPositive() + { + $this->assertSame('2012-02-29', Carbon::createFromDate(2012, 1, 31)->addMonthNoOverflow()->toDateString()); + $this->assertSame('2012-03-31', Carbon::createFromDate(2012, 1, 31)->addMonthsNoOverflow(2)->toDateString()); + $this->assertSame('2012-03-29', Carbon::createFromDate(2012, 2, 29)->addMonthNoOverflow()->toDateString()); + $this->assertSame('2012-02-29', Carbon::createFromDate(2011, 12, 31)->addMonthsNoOverflow(2)->toDateString()); + } + + public function testAddMonthsNoOverflowZero() + { + $this->assertSame(12, Carbon::createFromDate(1975, 12)->addMonths(0)->month); + } + + public function testAddMonthsNoOverflowNegative() + { + $this->assertSame('2012-01-29', Carbon::createFromDate(2012, 2, 29)->addMonthsNoOverflow(-1)->toDateString()); + $this->assertSame('2012-01-31', Carbon::createFromDate(2012, 3, 31)->addMonthsNoOverflow(-2)->toDateString()); + $this->assertSame('2012-02-29', Carbon::createFromDate(2012, 3, 31)->addMonthsNoOverflow(-1)->toDateString()); + $this->assertSame('2011-12-31', Carbon::createFromDate(2012, 1, 31)->addMonthsNoOverflow(-1)->toDateString()); + } + + public function testAddDaysPositive() + { + $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDays(1)->day); + } + + public function testAddDaysZero() + { + $this->assertSame(31, Carbon::createFromDate(1975, 5, 31)->addDays(0)->day); + } + + public function testAddDaysNegative() + { + $this->assertSame(30, Carbon::createFromDate(1975, 5, 31)->addDays(-1)->day); + } + + public function testAddDay() + { + $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDay()->day); + } + + public function testAddWeekdaysPositive() + { + $this->assertSame(17, Carbon::createFromDate(2012, 1, 4)->addWeekdays(9)->day); + } + + public function testAddWeekdaysZero() + { + $this->assertSame(4, Carbon::createFromDate(2012, 1, 4)->addWeekdays(0)->day); + } + + public function testAddWeekdaysNegative() + { + $this->assertSame(18, Carbon::createFromDate(2012, 1, 31)->addWeekdays(-9)->day); + } + + public function testAddWeekday() + { + $this->assertSame(9, Carbon::createFromDate(2012, 1, 6)->addWeekday()->day); + } + + public function testAddWeeksPositive() + { + $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeeks(1)->day); + } + + public function testAddWeeksZero() + { + $this->assertSame(21, Carbon::createFromDate(1975, 5, 21)->addWeeks(0)->day); + } + + public function testAddWeeksNegative() + { + $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->addWeeks(-1)->day); + } + + public function testAddWeek() + { + $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeek()->day); + } + + public function testAddHoursPositive() + { + $this->assertSame(1, Carbon::createFromTime(0)->addHours(1)->hour); + } + + public function testAddHoursZero() + { + $this->assertSame(0, Carbon::createFromTime(0)->addHours(0)->hour); + } + + public function testAddHoursNegative() + { + $this->assertSame(23, Carbon::createFromTime(0)->addHours(-1)->hour); + } + + public function testAddHour() + { + $this->assertSame(1, Carbon::createFromTime(0)->addHour()->hour); + } + + public function testAddMinutesPositive() + { + $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinutes(1)->minute); + } + + public function testAddMinutesZero() + { + $this->assertSame(0, Carbon::createFromTime(0, 0)->addMinutes(0)->minute); + } + + public function testAddMinutesNegative() + { + $this->assertSame(59, Carbon::createFromTime(0, 0)->addMinutes(-1)->minute); + } + + public function testAddMinute() + { + $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinute()->minute); + } + + public function testAddSecondsPositive() + { + $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSeconds(1)->second); + } + + public function testAddSecondsZero() + { + $this->assertSame(0, Carbon::createFromTime(0, 0, 0)->addSeconds(0)->second); + } + + public function testAddSecondsNegative() + { + $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->addSeconds(-1)->second); + } + + public function testAddSecond() + { + $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSecond()->second); + } + + /***** Test non plural methods with non default args *****/ + + public function testAddYearPassingArg() + { + $this->assertSame(1977, Carbon::createFromDate(1975)->addYear(2)->year); + } + + public function testAddMonthPassingArg() + { + $this->assertSame(7, Carbon::createFromDate(1975, 5, 1)->addMonth(2)->month); + } + + public function testAddMonthNoOverflowPassingArg() + { + $dt = Carbon::createFromDate(2010, 12, 31)->addMonthNoOverflow(2); + $this->assertSame(2011, $dt->year); + $this->assertSame(2, $dt->month); + $this->assertSame(28, $dt->day); + } + + public function testAddDayPassingArg() + { + $this->assertSame(12, Carbon::createFromDate(1975, 5, 10)->addDay(2)->day); + } + + public function testAddHourPassingArg() + { + $this->assertSame(2, Carbon::createFromTime(0)->addHour(2)->hour); + } + + public function testAddMinutePassingArg() + { + $this->assertSame(2, Carbon::createFromTime(0)->addMinute(2)->minute); + } + + public function testAddSecondPassingArg() + { + $this->assertSame(2, Carbon::createFromTime(0)->addSecond(2)->second); + } +} diff --git a/vendor/nesbot/carbon/tests/CarbonIntervalAddTest.php b/vendor/nesbot/carbon/tests/CarbonIntervalAddTest.php new file mode 100755 index 0000000..538c274 --- /dev/null +++ b/vendor/nesbot/carbon/tests/CarbonIntervalAddTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\CarbonInterval; +use Carbon\Carbon; + +class CarbonIntervalAddTest extends TestFixture +{ + public function testAdd() + { + $ci = CarbonInterval::create(4, 3, 6, 7, 8, 10, 11)->add(new DateInterval('P2Y1M5DT22H33M44S')); + $this->assertCarbonInterval($ci, 6, 4, 54, 30, 43, 55); + } + + public function testAddWithDiffDateInterval() + { + $diff = Carbon::now()->diff(Carbon::now()->addWeeks(3)); + $ci = CarbonInterval::create(4, 3, 6, 7, 8, 10, 11)->add($diff); + $this->assertCarbonInterval($ci, 4, 3, 70, 8, 10, 11); + } + + public function testAddWithNegativeDiffDateInterval() + { + $diff = Carbon::now()->diff(Carbon::now()->subWeeks(3)); + $ci = CarbonInterval::create(4, 3, 6, 7, 8, 10, 11)->add($diff); + $this->assertCarbonInterval($ci, 4, 3, 28, 8, 10, 11); + } +} diff --git a/vendor/nesbot/carbon/tests/CarbonIntervalConstructTest.php b/vendor/nesbot/carbon/tests/CarbonIntervalConstructTest.php new file mode 100755 index 0000000..ed9a885 --- /dev/null +++ b/vendor/nesbot/carbon/tests/CarbonIntervalConstructTest.php @@ -0,0 +1,224 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\CarbonInterval; +use Carbon\Carbon; + +class CarbonIntervalConstructTest extends TestFixture +{ + public function testDefaults() + { + $ci = new CarbonInterval(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 1, 0, 0, 0, 0, 0); + } + + /** + * @expectedException Exception + */ + public function testNulls() + { + $ci = new CarbonInterval(null, null, null, null, null, null); + } + + /** + * @expectedException Exception + */ + public function testZeroes() + { + $ci = new CarbonInterval(0, 0, 0, 0, 0, 0); + } + + public function testYears() + { + $ci = new CarbonInterval(1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 1, 0, 0, 0, 0, 0); + + $ci = CarbonInterval::years(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 2, 0, 0, 0, 0, 0); + + $ci = CarbonInterval::year(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 1, 0, 0, 0, 0, 0); + + $ci = CarbonInterval::year(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 3, 0, 0, 0, 0, 0); + } + + public function testMonths() + { + $ci = new CarbonInterval(0, 1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 1, 0, 0, 0, 0); + + $ci = CarbonInterval::months(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 2, 0, 0, 0, 0); + + $ci = CarbonInterval::month(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 1, 0, 0, 0, 0); + + $ci = CarbonInterval::month(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 3, 0, 0, 0, 0); + } + + public function testWeeks() + { + $ci = new CarbonInterval(0, 0, 1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 7, 0, 0, 0); + + $ci = CarbonInterval::weeks(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 14, 0, 0, 0); + + $ci = CarbonInterval::week(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 7, 0, 0, 0); + + $ci = CarbonInterval::week(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 21, 0, 0, 0); + } + + public function testDays() + { + $ci = new CarbonInterval(0, 0, 0, 1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 1, 0, 0, 0); + + $ci = CarbonInterval::days(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 2, 0, 0, 0); + + $ci = CarbonInterval::dayz(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 2, 0, 0, 0); + + $ci = CarbonInterval::day(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 1, 0, 0, 0); + + $ci = CarbonInterval::day(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 3, 0, 0, 0); + } + + public function testHours() + { + $ci = new CarbonInterval(0, 0, 0, 0, 1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 1, 0, 0); + + $ci = CarbonInterval::hours(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 2, 0, 0); + + $ci = CarbonInterval::hour(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 1, 0, 0); + + $ci = CarbonInterval::hour(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 3, 0, 0); + } + + public function testMinutes() + { + $ci = new CarbonInterval(0, 0, 0, 0, 0, 1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 1, 0); + + $ci = CarbonInterval::minutes(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 2, 0); + + $ci = CarbonInterval::minute(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 1, 0); + + $ci = CarbonInterval::minute(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 3, 0); + } + + public function testSeconds() + { + $ci = new CarbonInterval(0, 0, 0, 0, 0, 0, 1); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 0, 1); + + $ci = CarbonInterval::seconds(2); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 0, 2); + + $ci = CarbonInterval::second(); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 0, 1); + + $ci = CarbonInterval::second(3); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 0, 0, 0, 0, 0, 3); + } + + public function testYearsAndHours() + { + $ci = new CarbonInterval(5, 0, 0, 0, 3, 0, 0); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 5, 0, 0, 3, 0, 0); + } + + public function testAll() + { + $ci = new CarbonInterval(5, 6, 2, 5, 9, 10, 11); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 5, 6, 19, 9, 10, 11); + } + + public function testAllWithCreate() + { + $ci = CarbonInterval::create(5, 6, 2, 5, 9, 10, 11); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 5, 6, 19, 9, 10, 11); + } + + public function testInstance() + { + $ci = CarbonInterval::instance(new DateInterval('P2Y1M5DT22H33M44S')); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 2, 1, 5, 22, 33, 44); + $this->assertTrue($ci->days === false || $ci->days === CarbonInterval::PHP_DAYS_FALSE); + } + + public function testInstanceWithNegativeDateInterval() + { + $di = new DateInterval('P2Y1M5DT22H33M44S'); + $di->invert = 1; + $ci = CarbonInterval::instance($di); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 2, 1, 5, 22, 33, 44); + $this->assertTrue($ci->days === false || $ci->days === CarbonInterval::PHP_DAYS_FALSE); + $this->assertSame(1, $ci->invert); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testInstanceWithDaysThrowsException() + { + $ci = CarbonInterval::instance(Carbon::now()->diff(Carbon::now()->addWeeks(3))); + } +} diff --git a/vendor/nesbot/carbon/tests/CarbonIntervalForHumansTest.php b/vendor/nesbot/carbon/tests/CarbonIntervalForHumansTest.php new file mode 100755 index 0000000..1db5ecb --- /dev/null +++ b/vendor/nesbot/carbon/tests/CarbonIntervalForHumansTest.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\CarbonInterval; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\Loader\ArrayLoader; + +class CarbonIntervalForHumansTest extends TestFixture +{ + public function testGetTranslator() + { + $t = CarbonInterval::getTranslator(); + $this->assertNotNull($t); + $this->assertSame('en', $t->getLocale()); + } + + public function testSetTranslator() + { + $t = new Translator('fr'); + $t->addLoader('array', new ArrayLoader()); + CarbonInterval::setTranslator($t); + + $t = CarbonInterval::getTranslator(); + $this->assertNotNull($t); + $this->assertSame('fr', $t->getLocale()); + } + + public function testGetLocale() + { + CarbonInterval::setLocale('en'); + $this->assertSame('en', CarbonInterval::getLocale()); + } + + public function testSetLocale() + { + CarbonInterval::setLocale('en'); + $this->assertSame('en', CarbonInterval::getLocale()); + CarbonInterval::setLocale('fr'); + $this->assertSame('fr', CarbonInterval::getLocale()); + } + + public function testYear() + { + CarbonInterval::setLocale('en'); + $this->assertSame('1 year', CarbonInterval::year()->forHumans()); + } + + public function testYearToString() + { + CarbonInterval::setLocale('en'); + $this->assertSame('1 year:abc', CarbonInterval::year() . ':abc'); + } + + public function testYears() + { + CarbonInterval::setLocale('en'); + $this->assertSame('2 years', CarbonInterval::years(2)->forHumans()); + } + + public function testYearsAndMonth() + { + CarbonInterval::setLocale('en'); + $this->assertSame('2 years 1 month', CarbonInterval::create(2, 1)->forHumans()); + } + + public function testAll() + { + CarbonInterval::setLocale('en'); + $ci = CarbonInterval::create(11, 1, 2, 5, 22, 33, 55)->forHumans(); + $this->assertSame('11 years 1 month 2 weeks 5 days 22 hours 33 minutes 55 seconds', $ci); + } + + public function testYearsAndMonthInFrench() + { + CarbonInterval::setLocale('fr'); + $this->assertSame('2 ans 1 mois', CarbonInterval::create(2, 1)->forHumans()); + } + + public function testYearsAndMonthInGerman() + { + CarbonInterval::setLocale('de'); + $this->assertSame('1 Jahr 1 Monat', CarbonInterval::create(1, 1)->forHumans()); + $this->assertSame('2 Jahre 1 Monat', CarbonInterval::create(2, 1)->forHumans()); + } + + public function testYearsAndMonthInBulgarian() + { + CarbonInterval::setLocale('bg'); + $this->assertSame('1 година 1 месец', CarbonInterval::create(1, 1)->forHumans()); + $this->assertSame('2 години 1 месец', CarbonInterval::create(2, 1)->forHumans()); + } + + public function testYearsAndMonthInCatalan() + { + CarbonInterval::setLocale('ca'); + $this->assertSame('1 any 1 mes', CarbonInterval::create(1, 1)->forHumans()); + $this->assertSame('2 anys 1 mes', CarbonInterval::create(2, 1)->forHumans()); + } +} diff --git a/vendor/nesbot/carbon/tests/CarbonIntervalGettersTest.php b/vendor/nesbot/carbon/tests/CarbonIntervalGettersTest.php new file mode 100755 index 0000000..06c155e --- /dev/null +++ b/vendor/nesbot/carbon/tests/CarbonIntervalGettersTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\CarbonInterval; + +class CarbonIntervalGettersTest extends TestFixture +{ + public function testGettersThrowExceptionOnUnknownGetter() + { + $this->setExpectedException('InvalidArgumentException'); + CarbonInterval::year()->sdfsdfss; + } + + public function testYearsGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(4, $d->years); + } + + public function testMonthsGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(5, $d->months); + } + + public function testWeeksGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(6, $d->weeks); + } + + public function testDayzExcludingWeeksGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(5, $d->daysExcludeWeeks); + $this->assertSame(5, $d->dayzExcludeWeeks); + } + + public function testDayzGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(6 * 7 + 5, $d->dayz); + } + + public function testHoursGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(8, $d->hours); + } + + public function testMinutesGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(9, $d->minutes); + } + + public function testSecondsGetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $this->assertSame(10, $d->seconds); + } +} diff --git a/vendor/nesbot/carbon/tests/CarbonIntervalSettersTest.php b/vendor/nesbot/carbon/tests/CarbonIntervalSettersTest.php new file mode 100755 index 0000000..0921575 --- /dev/null +++ b/vendor/nesbot/carbon/tests/CarbonIntervalSettersTest.php @@ -0,0 +1,99 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\CarbonInterval; + +class CarbonIntervalSettersTest extends TestFixture +{ + public function testYearsSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->years = 2; + $this->assertSame(2, $d->years); + } + + public function testMonthsSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->months = 11; + $this->assertSame(11, $d->months); + } + + public function testWeeksSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->weeks = 11; + $this->assertSame(11, $d->weeks); + $this->assertSame(7 * 11, $d->dayz); + } + + public function testDayzSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->dayz = 11; + $this->assertSame(11, $d->dayz); + $this->assertSame(1, $d->weeks); + $this->assertSame(4, $d->dayzExcludeWeeks); + } + + public function testHoursSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->hours = 12; + $this->assertSame(12, $d->hours); + } + + public function testMinutesSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->minutes = 11; + $this->assertSame(11, $d->minutes); + } + + public function testSecondsSetter() + { + $d = CarbonInterval::create(4, 5, 6, 5, 8, 9, 10); + $d->seconds = 34; + $this->assertSame(34, $d->seconds); + } + + public function testFluentSetters() + { + $ci = CarbonInterval::years(4)->months(2)->dayz(5)->hours(3)->minute()->seconds(59); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 4, 2, 5, 3, 1, 59); + + $ci = CarbonInterval::years(4)->months(2)->weeks(2)->hours(3)->minute()->seconds(59); + $this->assertInstanceOfCarbonInterval($ci); + $this->assertCarbonInterval($ci, 4, 2, 14, 3, 1, 59); + } + + public function testFluentSettersDaysOverwritesWeeks() + { + $ci = CarbonInterval::weeks(3)->days(5); + $this->assertCarbonInterval($ci, 0, 0, 5, 0, 0, 0); + } + + public function testFluentSettersWeeksOverwritesDays() + { + $ci = CarbonInterval::days(5)->weeks(3); + $this->assertCarbonInterval($ci, 0, 0, 3 * 7, 0, 0, 0); + } + + public function testFluentSettersWeeksAndDaysIsCumulative() + { + $ci = CarbonInterval::year(5)->weeksAndDays(2, 6); + $this->assertCarbonInterval($ci, 5, 0, 20, 0, 0, 0); + $this->assertSame(20, $ci->dayz); + $this->assertSame(2, $ci->weeks); + $this->assertSame(6, $ci->dayzExcludeWeeks); + } +} diff --git a/vendor/nesbot/carbon/tests/ComparisonTest.php b/vendor/nesbot/carbon/tests/ComparisonTest.php new file mode 100755 index 0000000..c40bf8c --- /dev/null +++ b/vendor/nesbot/carbon/tests/ComparisonTest.php @@ -0,0 +1,200 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class ComparisonTest extends TestFixture +{ + public function testEqualToTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->eq(Carbon::createFromDate(2000, 1, 1))); + } + + public function testEqualToFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->eq(Carbon::createFromDate(2000, 1, 2))); + } + + public function testEqualWithTimezoneTrue() + { + $this->assertTrue(Carbon::create(2000, 1, 1, 12, 0, 0, 'America/Toronto')->eq(Carbon::create(2000, 1, 1, 9, 0, 0, 'America/Vancouver'))); + } + + public function testEqualWithTimezoneFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1, 'America/Toronto')->eq(Carbon::createFromDate(2000, 1, 1, 'America/Vancouver'))); + } + + public function testNotEqualToTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->ne(Carbon::createFromDate(2000, 1, 2))); + } + + public function testNotEqualToFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->ne(Carbon::createFromDate(2000, 1, 1))); + } + + public function testNotEqualWithTimezone() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1, 'America/Toronto')->ne(Carbon::createFromDate(2000, 1, 1, 'America/Vancouver'))); + } + + public function testGreaterThanTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->gt(Carbon::createFromDate(1999, 12, 31))); + } + + public function testGreaterThanFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->gt(Carbon::createFromDate(2000, 1, 2))); + } + + public function testGreaterThanWithTimezoneTrue() + { + $dt1 = Carbon::create(2000, 1, 1, 12, 0, 0, 'America/Toronto'); + $dt2 = Carbon::create(2000, 1, 1, 8, 59, 59, 'America/Vancouver'); + $this->assertTrue($dt1->gt($dt2)); + } + + public function testGreaterThanWithTimezoneFalse() + { + $dt1 = Carbon::create(2000, 1, 1, 12, 0, 0, 'America/Toronto'); + $dt2 = Carbon::create(2000, 1, 1, 9, 0, 1, 'America/Vancouver'); + $this->assertFalse($dt1->gt($dt2)); + } + + public function testGreaterThanOrEqualTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->gte(Carbon::createFromDate(1999, 12, 31))); + } + + public function testGreaterThanOrEqualTrueEqual() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->gte(Carbon::createFromDate(2000, 1, 1))); + } + + public function testGreaterThanOrEqualFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->gte(Carbon::createFromDate(2000, 1, 2))); + } + + public function testLessThanTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->lt(Carbon::createFromDate(2000, 1, 2))); + } + + public function testLessThanFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->lt(Carbon::createFromDate(1999, 12, 31))); + } + + public function testLessThanOrEqualTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->lte(Carbon::createFromDate(2000, 1, 2))); + } + + public function testLessThanOrEqualTrueEqual() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->lte(Carbon::createFromDate(2000, 1, 1))); + } + + public function testLessThanOrEqualFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->lte(Carbon::createFromDate(1999, 12, 31))); + } + + public function testBetweenEqualTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), true)); + } + + public function testBetweenNotEqualTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), false)); + } + + public function testBetweenEqualFalse() + { + $this->assertFalse(Carbon::createFromDate(1999, 12, 31)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), true)); + } + + public function testBetweenNotEqualFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), false)); + } + + public function testBetweenEqualSwitchTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), true)); + } + + public function testBetweenNotEqualSwitchTrue() + { + $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), false)); + } + + public function testBetweenEqualSwitchFalse() + { + $this->assertFalse(Carbon::createFromDate(1999, 12, 31)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), true)); + } + + public function testBetweenNotEqualSwitchFalse() + { + $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), false)); + } + + public function testMinIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->min() instanceof Carbon); + } + + public function testMinWithNow() + { + $dt = Carbon::create(2012, 1, 1, 0, 0, 0)->min(); + $this->assertCarbon($dt, 2012, 1, 1, 0, 0, 0); + } + + public function testMinWithInstance() + { + $dt1 = Carbon::create(2013, 12, 31, 23, 59, 59); + $dt2 = Carbon::create(2012, 1, 1, 0, 0, 0)->min($dt1); + $this->assertCarbon($dt2, 2012, 1, 1, 0, 0, 0); + } + + public function testMaxIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->max() instanceof Carbon); + } + + public function testMaxWithNow() + { + $dt = Carbon::create(2099, 12, 31, 23, 59, 59)->max(); + $this->assertCarbon($dt, 2099, 12, 31, 23, 59, 59); + } + + public function testMaxWithInstance() + { + $dt1 = Carbon::create(2012, 1, 1, 0, 0, 0); + $dt2 = Carbon::create(2099, 12, 31, 23, 59, 59)->max($dt1); + $this->assertCarbon($dt2, 2099, 12, 31, 23, 59, 59); + } + public function testIsBirthday() + { + $dt1 = Carbon::createFromDate(1987, 4, 23); + $dt2 = Carbon::createFromDate(2014, 9, 26); + $dt3 = Carbon::createFromDate(2014, 4, 23); + $this->assertFalse($dt2->isBirthday($dt1)); + $this->assertTrue($dt3->isBirthday($dt1)); + } +} diff --git a/vendor/nesbot/carbon/tests/ConstructTest.php b/vendor/nesbot/carbon/tests/ConstructTest.php new file mode 100755 index 0000000..7ef3af7 --- /dev/null +++ b/vendor/nesbot/carbon/tests/ConstructTest.php @@ -0,0 +1,105 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class ConstructTest extends TestFixture +{ + public function testCreatesAnInstanceDefaultToNow() + { + $c = new Carbon(); + $now = Carbon::now(); + $this->assertInstanceOfCarbon($c); + $this->assertSame($now->tzName, $c->tzName); + $this->assertCarbon($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second); + } + + public function testParseCreatesAnInstanceDefaultToNow() + { + $c = Carbon::parse(); + $now = Carbon::now(); + $this->assertInstanceOfCarbon($c); + $this->assertSame($now->tzName, $c->tzName); + $this->assertCarbon($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second); + } + + public function testWithFancyString() + { + $c = new Carbon('first day of January 2008'); + $this->assertCarbon($c, 2008, 1, 1, 0, 0, 0); + } + + public function testParseWithFancyString() + { + $c = Carbon::parse('first day of January 2008'); + $this->assertCarbon($c, 2008, 1, 1, 0, 0, 0); + } + + public function testDefaultTimezone() + { + $c = new Carbon('now'); + $this->assertSame('America/Toronto', $c->tzName); + } + + public function testParseWithDefaultTimezone() + { + $c = Carbon::parse('now'); + $this->assertSame('America/Toronto', $c->tzName); + } + + public function testSettingTimezone() + { + $timezone = 'Europe/London'; + $dtz = new \DateTimeZone($timezone); + $dt = new \DateTime('now', $dtz); + $dayLightSavingTimeOffset = $dt->format('I'); + + $c = new Carbon('now', $dtz); + $this->assertSame($timezone, $c->tzName); + $this->assertSame(0 + $dayLightSavingTimeOffset, $c->offsetHours); + } + + public function testParseSettingTimezone() + { + $timezone = 'Europe/London'; + $dtz = new \DateTimeZone($timezone); + $dt = new \DateTime('now', $dtz); + $dayLightSavingTimeOffset = $dt->format('I'); + + $c = Carbon::parse('now', $dtz); + $this->assertSame($timezone, $c->tzName); + $this->assertSame(0 + $dayLightSavingTimeOffset, $c->offsetHours); + } + + public function testSettingTimezoneWithString() + { + $timezone = 'Asia/Tokyo'; + $dtz = new \DateTimeZone($timezone); + $dt = new \DateTime('now', $dtz); + $dayLightSavingTimeOffset = $dt->format('I'); + + $c = new Carbon('now', $timezone); + $this->assertSame($timezone, $c->tzName); + $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours); + } + + public function testParseSettingTimezoneWithString() + { + $timezone = 'Asia/Tokyo'; + $dtz = new \DateTimeZone($timezone); + $dt = new \DateTime('now', $dtz); + $dayLightSavingTimeOffset = $dt->format('I'); + + $c = Carbon::parse('now', $timezone); + $this->assertSame($timezone, $c->tzName); + $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours); + } +} diff --git a/vendor/nesbot/carbon/tests/CopyTest.php b/vendor/nesbot/carbon/tests/CopyTest.php new file mode 100755 index 0000000..bd3fa92 --- /dev/null +++ b/vendor/nesbot/carbon/tests/CopyTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class CopyTest extends TestFixture +{ + public function testCopy() + { + $dating = Carbon::now(); + $dating2 = $dating->copy(); + $this->assertNotSame($dating, $dating2); + } + + public function testCopyEnsureTzIsCopied() + { + $dating = Carbon::createFromDate(2000, 1, 1, 'Europe/London'); + $dating2 = $dating->copy(); + $this->assertSame($dating->tzName, $dating2->tzName); + $this->assertSame($dating->offset, $dating2->offset); + } + + public function testCopyEnsureMicrosAreCopied() + { + $micro = 254687; + $dating = Carbon::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.'.$micro); + $dating2 = $dating->copy(); + $this->assertSame($micro, $dating2->micro); + } +} diff --git a/vendor/nesbot/carbon/tests/CreateFromDateTest.php b/vendor/nesbot/carbon/tests/CreateFromDateTest.php new file mode 100755 index 0000000..9706f7f --- /dev/null +++ b/vendor/nesbot/carbon/tests/CreateFromDateTest.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class CreateFromDateTest extends TestFixture +{ + public function testCreateFromDateWithDefaults() + { + $d = Carbon::createFromDate(); + $this->assertSame($d->timestamp, Carbon::create(null, null, null, null, null, null)->timestamp); + } + + public function testCreateFromDate() + { + $d = Carbon::createFromDate(1975, 5, 21); + $this->assertCarbon($d, 1975, 5, 21); + } + + public function testCreateFromDateWithYear() + { + $d = Carbon::createFromDate(1975); + $this->assertSame(1975, $d->year); + } + + public function testCreateFromDateWithMonth() + { + $d = Carbon::createFromDate(null, 5); + $this->assertSame(5, $d->month); + } + + public function testCreateFromDateWithDay() + { + $d = Carbon::createFromDate(null, null, 21); + $this->assertSame(21, $d->day); + } + + public function testCreateFromDateWithTimezone() + { + $d = Carbon::createFromDate(1975, 5, 21, 'Europe/London'); + $this->assertCarbon($d, 1975, 5, 21); + $this->assertSame('Europe/London', $d->tzName); + } + + public function testCreateFromDateWithDateTimeZone() + { + $d = Carbon::createFromDate(1975, 5, 21, new \DateTimeZone('Europe/London')); + $this->assertCarbon($d, 1975, 5, 21); + $this->assertSame('Europe/London', $d->tzName); + } +} diff --git a/vendor/nesbot/carbon/tests/CreateFromFormatTest.php b/vendor/nesbot/carbon/tests/CreateFromFormatTest.php new file mode 100755 index 0000000..5333041 --- /dev/null +++ b/vendor/nesbot/carbon/tests/CreateFromFormatTest.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class CreateFromFormatTest extends TestFixture +{ + public function testCreateFromFormatReturnsCarbon() + { + $d = Carbon::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11'); + $this->assertCarbon($d, 1975, 5, 21, 22, 32, 11); + $this->assertTrue($d instanceof Carbon); + } + + public function testCreateFromFormatWithTimezoneString() + { + $d = Carbon::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', 'Europe/London'); + $this->assertCarbon($d, 1975, 5, 21, 22, 32, 11); + $this->assertSame('Europe/London', $d->tzName); + } + + public function testCreateFromFormatWithTimezone() + { + $d = Carbon::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', new \DateTimeZone('Europe/London')); + $this->assertCarbon($d, 1975, 5, 21, 22, 32, 11); + $this->assertSame('Europe/London', $d->tzName); + } + + public function testCreateFromFormatWithMillis() + { + $d = Carbon::createFromFormat('Y-m-d H:i:s.u', '1975-05-21 22:32:11.254687'); + $this->assertSame(254687, $d->micro); + } +} diff --git a/vendor/nesbot/carbon/tests/CreateFromTimeTest.php b/vendor/nesbot/carbon/tests/CreateFromTimeTest.php new file mode 100755 index 0000000..73078f4 --- /dev/null +++ b/vendor/nesbot/carbon/tests/CreateFromTimeTest.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class CreateFromTimeTest extends TestFixture +{ + public function testCreateFromDateWithDefaults() + { + $d = Carbon::createFromTime(); + $this->assertSame($d->timestamp, Carbon::create(null, null, null, null, null, null)->timestamp); + } + + public function testCreateFromDate() + { + $d = Carbon::createFromTime(23, 5, 21); + $this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 23, 5, 21); + } + + public function testCreateFromTimeWithHour() + { + $d = Carbon::createFromTime(22); + $this->assertSame(22, $d->hour); + $this->assertSame(0, $d->minute); + $this->assertSame(0, $d->second); + } + + public function testCreateFromTimeWithMinute() + { + $d = Carbon::createFromTime(null, 5); + $this->assertSame(5, $d->minute); + } + + public function testCreateFromTimeWithSecond() + { + $d = Carbon::createFromTime(null, null, 21); + $this->assertSame(21, $d->second); + } + + public function testCreateFromTimeWithDateTimeZone() + { + $d = Carbon::createFromTime(12, 0, 0, new \DateTimeZone('Europe/London')); + $this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 12, 0, 0); + $this->assertSame('Europe/London', $d->tzName); + } + + public function testCreateFromTimeWithTimeZoneString() + { + $d = Carbon::createFromTime(12, 0, 0, 'Europe/London'); + $this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 12, 0, 0); + $this->assertSame('Europe/London', $d->tzName); + } +} diff --git a/vendor/nesbot/carbon/tests/CreateFromTimestampTest.php b/vendor/nesbot/carbon/tests/CreateFromTimestampTest.php new file mode 100755 index 0000000..108faac --- /dev/null +++ b/vendor/nesbot/carbon/tests/CreateFromTimestampTest.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class CreateFromTimestampTest extends TestFixture +{ + public function testCreateReturnsDatingInstance() + { + $d = Carbon::createFromTimestamp(Carbon::create(1975, 5, 21, 22, 32, 5)->timestamp); + $this->assertCarbon($d, 1975, 5, 21, 22, 32, 5); + } + + public function testCreateFromTimestampUsesDefaultTimezone() + { + $d = Carbon::createFromTimestamp(0); + + // We know Toronto is -5 since no DST in Jan + $this->assertSame(1969, $d->year); + $this->assertSame(-5 * 3600, $d->offset); + } + + public function testCreateFromTimestampWithDateTimeZone() + { + $d = Carbon::createFromTimestamp(0, new \DateTimeZone('UTC')); + $this->assertSame('UTC', $d->tzName); + $this->assertCarbon($d, 1970, 1, 1, 0, 0, 0); + } + + public function testCreateFromTimestampWithString() + { + $d = Carbon::createFromTimestamp(0, 'UTC'); + $this->assertCarbon($d, 1970, 1, 1, 0, 0, 0); + $this->assertSame(0, $d->offset); + $this->assertSame('UTC', $d->tzName); + } + + public function testCreateFromTimestampGMTDoesNotUseDefaultTimezone() + { + $d = Carbon::createFromTimestampUTC(0); + $this->assertCarbon($d, 1970, 1, 1, 0, 0, 0); + $this->assertSame(0, $d->offset); + } +} diff --git a/vendor/nesbot/carbon/tests/CreateTest.php b/vendor/nesbot/carbon/tests/CreateTest.php new file mode 100755 index 0000000..513d61d --- /dev/null +++ b/vendor/nesbot/carbon/tests/CreateTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class CreateTest extends TestFixture +{ + public function testCreateReturnsDatingInstance() + { + $d = Carbon::create(); + $this->assertTrue($d instanceof Carbon); + } + + public function testCreateWithDefaults() + { + $d = Carbon::create(); + $this->assertSame($d->timestamp, Carbon::now()->timestamp); + } + + public function testCreateWithYear() + { + $d = Carbon::create(2012); + $this->assertSame(2012, $d->year); + } + + public function testCreateWithInvalidYear() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::create(-3); + } + + public function testCreateWithMonth() + { + $d = Carbon::create(null, 3); + $this->assertSame(3, $d->month); + } + + public function testCreateWithInvalidMonth() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::create(null, -5); + } + + public function testCreateMonthWraps() + { + $d = Carbon::create(2011, 0, 1, 0, 0, 0); + $this->assertCarbon($d, 2010, 12, 1, 0, 0, 0); + } + + public function testCreateWithDay() + { + $d = Carbon::create(null, null, 21); + $this->assertSame(21, $d->day); + } + + public function testCreateWithInvalidDay() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::create(null, null, -4); + } + public function testCreateDayWraps() + { + $d = Carbon::create(2011, 1, 40, 0, 0, 0); + $this->assertCarbon($d, 2011, 2, 9, 0, 0, 0); + } + + public function testCreateWithHourAndDefaultMinSecToZero() + { + $d = Carbon::create(null, null, null, 14); + $this->assertSame(14, $d->hour); + $this->assertSame(0, $d->minute); + $this->assertSame(0, $d->second); + } + + public function testCreateWithInvalidHour() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::create(null, null, null, -1); + } + + public function testCreateHourWraps() + { + $d = Carbon::create(2011, 1, 1, 24, 0, 0); + $this->assertCarbon($d, 2011, 1, 2, 0, 0, 0); + } + + public function testCreateWithMinute() + { + $d = Carbon::create(null, null, null, null, 58); + $this->assertSame(58, $d->minute); + } + + public function testCreateWithInvalidMinute() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::create(2011, 1, 1, 0, -2, 0); + } + public function testCreateMinuteWraps() + { + $d = Carbon::create(2011, 1, 1, 0, 62, 0); + $this->assertCarbon($d, 2011, 1, 1, 1, 2, 0); + } + + public function testCreateWithSecond() + { + $d = Carbon::create(null, null, null, null, null, 59); + $this->assertSame(59, $d->second); + } + + public function testCreateWithInvalidSecond() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::create(null, null, null, null, null, -2); + } + public function testCreateSecondsWrap() + { + $d = Carbon::create(2012, 1, 1, 0, 0, 61); + $this->assertCarbon($d, 2012, 1, 1, 0, 1, 1); + } + + public function testCreateWithDateTimeZone() + { + $d = Carbon::create(2012, 1, 1, 0, 0, 0, new \DateTimeZone('Europe/London')); + $this->assertCarbon($d, 2012, 1, 1, 0, 0, 0); + $this->assertSame('Europe/London', $d->tzName); + } + + public function testCreateWithTimeZoneString() + { + $d = Carbon::create(2012, 1, 1, 0, 0, 0, 'Europe/London'); + $this->assertCarbon($d, 2012, 1, 1, 0, 0, 0); + $this->assertSame('Europe/London', $d->tzName); + } +} diff --git a/vendor/nesbot/carbon/tests/DayOfWeekModifiersTest.php b/vendor/nesbot/carbon/tests/DayOfWeekModifiersTest.php new file mode 100755 index 0000000..ead4928 --- /dev/null +++ b/vendor/nesbot/carbon/tests/DayOfWeekModifiersTest.php @@ -0,0 +1,288 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class DayOfWeekModifiersTest extends TestFixture +{ + public function testStartOfWeek() + { + $d = Carbon::create(1980, 8, 7, 12, 11, 9)->startOfWeek(); + $this->assertCarbon($d, 1980, 8, 4, 0, 0, 0); + } + + public function testStartOfWeekFromWeekStart() + { + $d = Carbon::createFromDate(1980, 8, 4)->startOfWeek(); + $this->assertCarbon($d, 1980, 8, 4, 0, 0, 0); + } + + public function testStartOfWeekCrossingYearBoundary() + { + $d = Carbon::createFromDate(2013, 12, 31, 'GMT'); + $d->startOfWeek(); + $this->assertCarbon($d, 2013, 12, 30, 0, 0, 0); + } + + public function testEndOfWeek() + { + $d = Carbon::create(1980, 8, 7, 11, 12, 13)->endOfWeek(); + $this->assertCarbon($d, 1980, 8, 10, 23, 59, 59); + } + + public function testEndOfWeekFromWeekEnd() + { + $d = Carbon::createFromDate(1980, 8, 9)->endOfWeek(); + $this->assertCarbon($d, 1980, 8, 10, 23, 59, 59); + } + + public function testEndOfWeekCrossingYearBoundary() + { + $d = Carbon::createFromDate(2013, 12, 31, 'GMT'); + $d->endOfWeek(); + $this->assertCarbon($d, 2014, 1, 5, 23, 59, 59); + } + + public function testNext() + { + $d = Carbon::createFromDate(1975, 5, 21)->next(); + $this->assertCarbon($d, 1975, 5, 28, 0, 0, 0); + } + + public function testNextMonday() + { + $d = Carbon::createFromDate(1975, 5, 21)->next(Carbon::MONDAY); + $this->assertCarbon($d, 1975, 5, 26, 0, 0, 0); + } + + public function testNextSaturday() + { + $d = Carbon::createFromDate(1975, 5, 21)->next(6); + $this->assertCarbon($d, 1975, 5, 24, 0, 0, 0); + } + + public function testNextTimestamp() + { + $d = Carbon::createFromDate(1975, 11, 14)->next(); + $this->assertCarbon($d, 1975, 11, 21, 0, 0, 0); + } + + public function testPrevious() + { + $d = Carbon::createFromDate(1975, 5, 21)->previous(); + $this->assertCarbon($d, 1975, 5, 14, 0, 0, 0); + } + + public function testPreviousMonday() + { + $d = Carbon::createFromDate(1975, 5, 21)->previous(Carbon::MONDAY); + $this->assertCarbon($d, 1975, 5, 19, 0, 0, 0); + } + + public function testPreviousSaturday() + { + $d = Carbon::createFromDate(1975, 5, 21)->previous(6); + $this->assertCarbon($d, 1975, 5, 17, 0, 0, 0); + } + + public function testPreviousTimestamp() + { + $d = Carbon::createFromDate(1975, 11, 28)->previous(); + $this->assertCarbon($d, 1975, 11, 21, 0, 0, 0); + } + + public function testFirstDayOfMonth() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfMonth(); + $this->assertCarbon($d, 1975, 11, 1, 0, 0, 0); + } + + public function testFirstWednesdayOfMonth() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfMonth(Carbon::WEDNESDAY); + $this->assertCarbon($d, 1975, 11, 5, 0, 0, 0); + } + + public function testFirstFridayOfMonth() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfMonth(5); + $this->assertCarbon($d, 1975, 11, 7, 0, 0, 0); + } + + public function testLastDayOfMonth() + { + $d = Carbon::createFromDate(1975, 12, 5)->lastOfMonth(); + $this->assertCarbon($d, 1975, 12, 31, 0, 0, 0); + } + + public function testLastTuesdayOfMonth() + { + $d = Carbon::createFromDate(1975, 12, 1)->lastOfMonth(Carbon::TUESDAY); + $this->assertCarbon($d, 1975, 12, 30, 0, 0, 0); + } + + public function testLastFridayOfMonth() + { + $d = Carbon::createFromDate(1975, 12, 5)->lastOfMonth(5); + $this->assertCarbon($d, 1975, 12, 26, 0, 0, 0); + } + + public function testNthOfMonthOutsideScope() + { + $this->assertFalse(Carbon::createFromDate(1975, 12, 5)->nthOfMonth(6, Carbon::MONDAY)); + } + + public function testNthOfMonthOutsideYear() + { + $this->assertFalse(Carbon::createFromDate(1975, 12, 5)->nthOfMonth(55, Carbon::MONDAY)); + } + + public function test2ndMondayOfMonth() + { + $d = Carbon::createFromDate(1975, 12, 5)->nthOfMonth(2, Carbon::MONDAY); + $this->assertCarbon($d, 1975, 12, 8, 0, 0, 0); + } + + public function test3rdWednesdayOfMonth() + { + $d = Carbon::createFromDate(1975, 12, 5)->nthOfMonth(3, 3); + $this->assertCarbon($d, 1975, 12, 17, 0, 0, 0); + } + + public function testFirstDayOfQuarter() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfQuarter(); + $this->assertCarbon($d, 1975, 10, 1, 0, 0, 0); + } + + public function testFirstWednesdayOfQuarter() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfQuarter(Carbon::WEDNESDAY); + $this->assertCarbon($d, 1975, 10, 1, 0, 0, 0); + } + + public function testFirstFridayOfQuarter() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfQuarter(5); + $this->assertCarbon($d, 1975, 10, 3, 0, 0, 0); + } + + public function testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth() + { + $d = Carbon::createFromDate(2014, 5, 31)->firstOfQuarter(); + $this->assertCarbon($d, 2014, 4, 1, 0, 0, 0); + } + + public function testLastDayOfQuarter() + { + $d = Carbon::createFromDate(1975, 8, 5)->lastOfQuarter(); + $this->assertCarbon($d, 1975, 9, 30, 0, 0, 0); + } + + public function testLastTuesdayOfQuarter() + { + $d = Carbon::createFromDate(1975, 8, 1)->lastOfQuarter(Carbon::TUESDAY); + $this->assertCarbon($d, 1975, 9, 30, 0, 0, 0); + } + + public function testLastFridayOfQuarter() + { + $d = Carbon::createFromDate(1975, 7, 5)->lastOfQuarter(5); + $this->assertCarbon($d, 1975, 9, 26, 0, 0, 0); + } + + public function testLastOfQuarterFromADayThatWillNotExistIntheLastMonth() + { + $d = Carbon::createFromDate(2014, 5, 31)->lastOfQuarter(); + $this->assertCarbon($d, 2014, 6, 30, 0, 0, 0); + } + + public function testNthOfQuarterOutsideScope() + { + $this->assertFalse(Carbon::createFromDate(1975, 1, 5)->nthOfQuarter(20, Carbon::MONDAY)); + } + + public function testNthOfQuarterOutsideYear() + { + $this->assertFalse(Carbon::createFromDate(1975, 1, 5)->nthOfQuarter(55, Carbon::MONDAY)); + } + + public function testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth() + { + $d = Carbon::createFromDate(2014, 5, 31)->nthOfQuarter(2, Carbon::MONDAY); + $this->assertCarbon($d, 2014, 4, 14, 0, 0, 0); + } + + public function test2ndMondayOfQuarter() + { + $d = Carbon::createFromDate(1975, 8, 5)->nthOfQuarter(2, Carbon::MONDAY); + $this->assertCarbon($d, 1975, 7, 14, 0, 0, 0); + } + + public function test3rdWednesdayOfQuarter() + { + $d = Carbon::createFromDate(1975, 8, 5)->nthOfQuarter(3, 3); + $this->assertCarbon($d, 1975, 7, 16, 0, 0, 0); + } + + public function testFirstDayOfYear() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfYear(); + $this->assertCarbon($d, 1975, 1, 1, 0, 0, 0); + } + + public function testFirstWednesdayOfYear() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfYear(Carbon::WEDNESDAY); + $this->assertCarbon($d, 1975, 1, 1, 0, 0, 0); + } + + public function testFirstFridayOfYear() + { + $d = Carbon::createFromDate(1975, 11, 21)->firstOfYear(5); + $this->assertCarbon($d, 1975, 1, 3, 0, 0, 0); + } + + public function testLastDayOfYear() + { + $d = Carbon::createFromDate(1975, 8, 5)->lastOfYear(); + $this->assertCarbon($d, 1975, 12, 31, 0, 0, 0); + } + + public function testLastTuesdayOfYear() + { + $d = Carbon::createFromDate(1975, 8, 1)->lastOfYear(Carbon::TUESDAY); + $this->assertCarbon($d, 1975, 12, 30, 0, 0, 0); + } + + public function testLastFridayOfYear() + { + $d = Carbon::createFromDate(1975, 7, 5)->lastOfYear(5); + $this->assertCarbon($d, 1975, 12, 26, 0, 0, 0); + } + + public function testNthOfYearOutsideScope() + { + $this->assertFalse(Carbon::createFromDate(1975, 1, 5)->nthOfYear(55, Carbon::MONDAY)); + } + + public function test2ndMondayOfYear() + { + $d = Carbon::createFromDate(1975, 8, 5)->nthOfYear(2, Carbon::MONDAY); + $this->assertCarbon($d, 1975, 1, 13, 0, 0, 0); + } + + public function test3rdWednesdayOfYear() + { + $d = Carbon::createFromDate(1975, 8, 5)->nthOfYear(3, 3); + $this->assertCarbon($d, 1975, 1, 15, 0, 0, 0); + } +} diff --git a/vendor/nesbot/carbon/tests/DiffTest.php b/vendor/nesbot/carbon/tests/DiffTest.php new file mode 100755 index 0000000..3901717 --- /dev/null +++ b/vendor/nesbot/carbon/tests/DiffTest.php @@ -0,0 +1,1042 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; +use Carbon\CarbonInterval; + +class DiffTest extends TestFixture +{ + public function testDiffInYearsPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInYears($dt->copy()->addYear())); + } + + public function testDiffInYearsNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-1, $dt->diffInYears($dt->copy()->subYear(), false)); + } + + public function testDiffInYearsNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInYears($dt->copy()->subYear())); + } + + public function testDiffInYearsVsDefaultNow() + { + $this->assertSame(1, Carbon::now()->subYear()->diffInYears()); + } + + public function testDiffInYearsEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInYears($dt->copy()->addYear()->addMonths(7))); + } + + public function testDiffInMonthsPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(13, $dt->diffInMonths($dt->copy()->addYear()->addMonth())); + } + + public function testDiffInMonthsNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-11, $dt->diffInMonths($dt->copy()->subYear()->addMonth(), false)); + } + + public function testDiffInMonthsNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(11, $dt->diffInMonths($dt->copy()->subYear()->addMonth())); + } + + public function testDiffInMonthsVsDefaultNow() + { + $this->assertSame(12, Carbon::now()->subYear()->diffInMonths()); + } + + public function testDiffInMonthsEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInMonths($dt->copy()->addMonth()->addDays(16))); + } + + public function testDiffInDaysPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(366, $dt->diffInDays($dt->copy()->addYear())); + } + + public function testDiffInDaysNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-365, $dt->diffInDays($dt->copy()->subYear(), false)); + } + + public function testDiffInDaysNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(365, $dt->diffInDays($dt->copy()->subYear())); + } + + public function testDiffInDaysVsDefaultNow() + { + $this->assertSame(7, Carbon::now()->subWeek()->diffInDays()); + } + + public function testDiffInDaysEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInDays($dt->copy()->addDay()->addHours(13))); + } + + public function testDiffInDaysFilteredPositiveWithMutated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(5, $dt->diffInDaysFiltered(function (Carbon $date) { + return $date->dayOfWeek === 1; + }, $dt->copy()->endOfMonth())); + } + + public function testDiffInDaysFilteredPositiveWithSecondObject() + { + $dt1 = Carbon::createFromDate(2000, 1, 1); + $dt2 = Carbon::createFromDate(2000, 1, 31); + + $this->assertSame(5, $dt1->diffInDaysFiltered(function (Carbon $date) { + return $date->dayOfWeek === Carbon::SUNDAY; + }, $dt2)); + } + + public function testDiffInDaysFilteredNegativeNoSignWithMutated() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(5, $dt->diffInDaysFiltered(function (Carbon $date) { + return $date->dayOfWeek === Carbon::SUNDAY; + }, $dt->copy()->startOfMonth())); + } + + public function testDiffInDaysFilteredNegativeNoSignWithSecondObject() + { + $dt1 = Carbon::createFromDate(2000, 1, 31); + $dt2 = Carbon::createFromDate(2000, 1, 1); + + $this->assertSame(5, $dt1->diffInDaysFiltered(function (Carbon $date) { + return $date->dayOfWeek === Carbon::SUNDAY; + }, $dt2)); + } + + public function testDiffInDaysFilteredNegativeWithSignWithMutated() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(-5, $dt->diffInDaysFiltered(function (Carbon $date) { + return $date->dayOfWeek === 1; + }, $dt->copy()->startOfMonth(), false)); + } + + public function testDiffInDaysFilteredNegativeWithSignWithSecondObject() + { + $dt1 = Carbon::createFromDate(2000, 1, 31); + $dt2 = Carbon::createFromDate(2000, 1, 1); + + $this->assertSame(-5, $dt1->diffInDaysFiltered(function (Carbon $date) { + return $date->dayOfWeek === Carbon::SUNDAY; + }, $dt2, false)); + } + + public function testDiffInHoursFiltered() + { + $dt1 = Carbon::createFromDate(2000, 1, 31)->endOfDay(); + $dt2 = Carbon::createFromDate(2000, 1, 1)->startOfDay(); + + $this->assertSame(31, $dt1->diffInHoursFiltered(function (Carbon $date) + { + return $date->hour === 9; + }, $dt2)); + } + + public function testDiffInHoursFilteredNegative() + { + $dt1 = Carbon::createFromDate(2000, 1, 31)->endOfDay(); + $dt2 = Carbon::createFromDate(2000, 1, 1)->startOfDay(); + + $this->assertSame(-31, $dt1->diffInHoursFiltered(function (Carbon $date) + { + return $date->hour === 9; + }, $dt2, false)); + } + + public function testDiffInHoursFilteredWorkHoursPerWeek() + { + $dt1 = Carbon::createFromDate(2000, 1, 5)->endOfDay(); + $dt2 = Carbon::createFromDate(2000, 1, 1)->startOfDay(); + + $this->assertSame(40, $dt1->diffInHoursFiltered(function (Carbon $date) + { + return ($date->hour > 8 && $date->hour < 17); + }, $dt2)); + } + + public function testDiffFilteredUsingMinutesPositiveWithMutated() + { + $dt = Carbon::createFromDate(2000, 1, 1)->startOfDay(); + $this->assertSame(60, $dt->diffFiltered(CarbonInterval::minute(), function (Carbon $date) { + return $date->hour === 12; + }, Carbon::createFromDate(2000, 1, 1)->endOfDay())); + } + + public function testDiffFilteredPositiveWithSecondObject() + { + $dt1 = Carbon::create(2000, 1, 1); + $dt2 = $dt1->copy()->addSeconds(80); + + $this->assertSame(40, $dt1->diffFiltered(CarbonInterval::second(), function (Carbon $date) { + return $date->second % 2 === 0; + }, $dt2)); + } + + public function testDiffFilteredNegativeNoSignWithMutated() + { + $dt = Carbon::createFromDate(2000, 1, 31); + + $this->assertSame(2, $dt->diffFiltered(CarbonInterval::days(2), function (Carbon $date) { + return $date->dayOfWeek === Carbon::SUNDAY; + }, $dt->copy()->startOfMonth())); + } + + public function testDiffFilteredNegativeNoSignWithSecondObject() + { + $dt1 = Carbon::createFromDate(2006, 1, 31); + $dt2 = Carbon::createFromDate(2000, 1, 1); + + $this->assertSame(7, $dt1->diffFiltered(CarbonInterval::year(), function (Carbon $date) { + return $date->month === 1; + }, $dt2)); + } + + public function testDiffFilteredNegativeWithSignWithMutated() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(-4, $dt->diffFiltered(CarbonInterval::week(), function (Carbon $date) { + return $date->month === 12; + }, $dt->copy()->subMonths(3), false)); + } + + public function testDiffFilteredNegativeWithSignWithSecondObject() + { + $dt1 = Carbon::createFromDate(2001, 1, 31); + $dt2 = Carbon::createFromDate(1999, 1, 1); + + $this->assertSame(-12, $dt1->diffFiltered(CarbonInterval::month(), function (Carbon $date) { + return $date->year === 2000; + }, $dt2, false)); + } + + public function testBug188DiffWithSameDates() + { + $start = Carbon::create(2014, 10, 8, 15, 20, 0); + $end = $start->copy(); + + $this->assertSame(0, $start->diffInDays($end)); + $this->assertSame(0, $start->diffInWeekdays($end)); + } + + public function testBug188DiffWithDatesOnlyHoursApart() + { + $start = Carbon::create(2014, 10, 8, 15, 20, 0); + $end = $start->copy(); + + $this->assertSame(0, $start->diffInDays($end)); + $this->assertSame(0, $start->diffInWeekdays($end)); + } + + public function testBug188DiffWithSameDates1DayApart() + { + $start = Carbon::create(2014, 10, 8, 15, 20, 0); + $end = $start->copy()->addDay(); + + $this->assertSame(1, $start->diffInDays($end)); + $this->assertSame(1, $start->diffInWeekdays($end)); + } + + public function testBug188DiffWithDatesOnTheWeekend() + { + $start = Carbon::create(2014, 1, 1, 0, 0, 0); + $start->next(Carbon::SATURDAY); + $end = $start->copy()->addDay(); + + $this->assertSame(1, $start->diffInDays($end)); + $this->assertSame(0, $start->diffInWeekdays($end)); + } + + public function testDiffInWeekdaysPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(21, $dt->diffInWeekdays($dt->copy()->endOfMonth())); + } + + public function testDiffInWeekdaysNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(21, $dt->diffInWeekdays($dt->copy()->startOfMonth())); + } + + public function testDiffInWeekdaysNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(-21, $dt->diffInWeekdays($dt->copy()->startOfMonth(), false)); + } + + public function testDiffInWeekendDaysPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(10, $dt->diffInWeekendDays($dt->copy()->endOfMonth())); + } + + public function testDiffInWeekendDaysNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(10, $dt->diffInWeekendDays($dt->copy()->startOfMonth())); + } + + public function testDiffInWeekendDaysNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 31); + $this->assertSame(-10, $dt->diffInWeekendDays($dt->copy()->startOfMonth(), false)); + } + + public function testDiffInWeeksPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(52, $dt->diffInWeeks($dt->copy()->addYear())); + } + + public function testDiffInWeeksNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-52, $dt->diffInWeeks($dt->copy()->subYear(), false)); + } + + public function testDiffInWeeksNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(52, $dt->diffInWeeks($dt->copy()->subYear())); + } + + public function testDiffInWeeksVsDefaultNow() + { + $this->assertSame(1, Carbon::now()->subWeek()->diffInWeeks()); + } + + public function testDiffInWeeksEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(0, $dt->diffInWeeks($dt->copy()->addWeek()->subDay())); + } + + public function testDiffInHoursPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(26, $dt->diffInHours($dt->copy()->addDay()->addHours(2))); + } + + public function testDiffInHoursNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-22, $dt->diffInHours($dt->copy()->subDay()->addHours(2), false)); + } + + public function testDiffInHoursNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(22, $dt->diffInHours($dt->copy()->subDay()->addHours(2))); + } + + public function testDiffInHoursVsDefaultNow() + { + Carbon::setTestNow(Carbon::create(2012, 1, 15)); + $this->assertSame(48, Carbon::now()->subDays(2)->diffInHours()); + Carbon::setTestNow(); + } + + public function testDiffInHoursEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInHours($dt->copy()->addHour()->addMinutes(31))); + } + + public function testDiffInMinutesPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(62, $dt->diffInMinutes($dt->copy()->addHour()->addMinutes(2))); + } + + public function testDiffInMinutesPositiveAlot() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1502, $dt->diffInMinutes($dt->copy()->addHours(25)->addMinutes(2))); + } + + public function testDiffInMinutesNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-58, $dt->diffInMinutes($dt->copy()->subHour()->addMinutes(2), false)); + } + + public function testDiffInMinutesNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(58, $dt->diffInMinutes($dt->copy()->subHour()->addMinutes(2))); + } + + public function testDiffInMinutesVsDefaultNow() + { + $this->assertSame(60, Carbon::now()->subHour()->diffInMinutes()); + } + + public function testDiffInMinutesEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInMinutes($dt->copy()->addMinute()->addSeconds(31))); + } + + public function testDiffInSecondsPositive() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(62, $dt->diffInSeconds($dt->copy()->addMinute()->addSeconds(2))); + } + + public function testDiffInSecondsPositiveAlot() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(7202, $dt->diffInSeconds($dt->copy()->addHours(2)->addSeconds(2))); + } + + public function testDiffInSecondsNegativeWithSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(-58, $dt->diffInSeconds($dt->copy()->subMinute()->addSeconds(2), false)); + } + + public function testDiffInSecondsNegativeNoSign() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(58, $dt->diffInSeconds($dt->copy()->subMinute()->addSeconds(2))); + } + + public function testDiffInSecondsVsDefaultNow() + { + $this->assertSame(3600, Carbon::now()->subHour()->diffInSeconds()); + } + + public function testDiffInSecondsEnsureIsTruncated() + { + $dt = Carbon::createFromDate(2000, 1, 1); + $this->assertSame(1, $dt->diffInSeconds($dt->copy()->addSeconds(1.9))); + } + + public function testDiffInSecondsWithTimezones() + { + $dtOttawa = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); + $dtVancouver = Carbon::createFromDate(2000, 1, 1, 'America/Vancouver'); + $this->assertSame(3 * 60 * 60, $dtOttawa->diffInSeconds($dtVancouver)); + } + + public function testDiffInSecondsWithTimezonesAndVsDefault() + { + $dt = Carbon::now('America/Vancouver'); + $this->assertSame(0, $dt->diffInSeconds()); + } + + public function testDiffForHumansNowAndSecond() + { + $d = Carbon::now(); + $this->assertSame('1 second ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndSecondWithTimezone() + { + $d = Carbon::now('America/Vancouver'); + $this->assertSame('1 second ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndSeconds() + { + $d = Carbon::now()->subSeconds(2); + $this->assertSame('2 seconds ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyMinute() + { + $d = Carbon::now()->subSeconds(59); + $this->assertSame('59 seconds ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndMinute() + { + $d = Carbon::now()->subMinute(); + $this->assertSame('1 minute ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndMinutes() + { + $d = Carbon::now()->subMinutes(2); + $this->assertSame('2 minutes ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyHour() + { + $d = Carbon::now()->subMinutes(59); + $this->assertSame('59 minutes ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndHour() + { + $d = Carbon::now()->subHour(); + $this->assertSame('1 hour ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndHours() + { + Carbon::setTestNow(Carbon::create(2012, 1, 15)); + $d = Carbon::now()->subHours(2); + $this->assertSame('2 hours ago', $d->diffForHumans()); + Carbon::setTestNow(); + } + + public function testDiffForHumansNowAndNearlyDay() + { + Carbon::setTestNow(Carbon::create(2012, 1, 15)); + $d = Carbon::now()->subHours(23); + $this->assertSame('23 hours ago', $d->diffForHumans()); + Carbon::setTestNow(); + } + + public function testDiffForHumansNowAndDay() + { + $d = Carbon::now()->subDay(); + $this->assertSame('1 day ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndDays() + { + $d = Carbon::now()->subDays(2); + $this->assertSame('2 days ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyWeek() + { + $d = Carbon::now()->subDays(6); + $this->assertSame('6 days ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndWeek() + { + $d = Carbon::now()->subWeek(); + $this->assertSame('1 week ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndWeeks() + { + $d = Carbon::now()->subWeeks(2); + $this->assertSame('2 weeks ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyMonth() + { + $d = Carbon::now()->subWeeks(3); + $this->assertSame('3 weeks ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndMonth() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->subWeeks(4); + $this->assertSame('4 weeks ago', $d->diffForHumans()); + $d = Carbon::now()->subMonth(); + $this->assertSame('1 month ago', $d->diffForHumans()); + Carbon::setTestNow(); + } + + public function testDiffForHumansNowAndMonths() + { + $d = Carbon::now()->subMonths(2); + $this->assertSame('2 months ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyYear() + { + $d = Carbon::now()->subMonths(11); + $this->assertSame('11 months ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndYear() + { + $d = Carbon::now()->subYear(); + $this->assertSame('1 year ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndYears() + { + $d = Carbon::now()->subYears(2); + $this->assertSame('2 years ago', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureSecond() + { + $d = Carbon::now()->addSecond(); + $this->assertSame('1 second from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureSeconds() + { + $d = Carbon::now()->addSeconds(2); + $this->assertSame('2 seconds from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyFutureMinute() + { + $d = Carbon::now()->addSeconds(59); + $this->assertSame('59 seconds from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureMinute() + { + $d = Carbon::now()->addMinute(); + $this->assertSame('1 minute from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureMinutes() + { + $d = Carbon::now()->addMinutes(2); + $this->assertSame('2 minutes from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyFutureHour() + { + $d = Carbon::now()->addMinutes(59); + $this->assertSame('59 minutes from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureHour() + { + $d = Carbon::now()->addHour(); + $this->assertSame('1 hour from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureHours() + { + $d = Carbon::now()->addHours(2); + $this->assertSame('2 hours from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyFutureDay() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->addHours(23); + $this->assertSame('23 hours from now', $d->diffForHumans()); + Carbon::setTestNow(); + } + + public function testDiffForHumansNowAndFutureDay() + { + $d = Carbon::now()->addDay(); + $this->assertSame('1 day from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureDays() + { + $d = Carbon::now()->addDays(2); + $this->assertSame('2 days from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyFutureWeek() + { + $d = Carbon::now()->addDays(6); + $this->assertSame('6 days from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureWeek() + { + $d = Carbon::now()->addWeek(); + $this->assertSame('1 week from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureWeeks() + { + $d = Carbon::now()->addWeeks(2); + $this->assertSame('2 weeks from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndNearlyFutureMonth() + { + $d = Carbon::now()->addWeeks(3); + $this->assertSame('3 weeks from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureMonth() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->addWeeks(4); + $this->assertSame('4 weeks from now', $d->diffForHumans()); + $d = Carbon::now()->addMonth(); + $this->assertSame('1 month from now', $d->diffForHumans()); + Carbon::setTestNow(); + } + + public function testDiffForHumansNowAndFutureMonths() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->addMonths(2); + $this->assertSame('2 months from now', $d->diffForHumans()); + Carbon::setTestNow(); + } + + public function testDiffForHumansNowAndNearlyFutureYear() + { + $d = Carbon::now()->addMonths(11); + $this->assertSame('11 months from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureYear() + { + $d = Carbon::now()->addYear(); + $this->assertSame('1 year from now', $d->diffForHumans()); + } + + public function testDiffForHumansNowAndFutureYears() + { + $d = Carbon::now()->addYears(2); + $this->assertSame('2 years from now', $d->diffForHumans()); + } + + public function testDiffForHumansOtherAndSecond() + { + $d = Carbon::now()->addSecond(); + $this->assertSame('1 second before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndSeconds() + { + $d = Carbon::now()->addSeconds(2); + $this->assertSame('2 seconds before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyMinute() + { + $d = Carbon::now()->addSeconds(59); + $this->assertSame('59 seconds before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndMinute() + { + $d = Carbon::now()->addMinute(); + $this->assertSame('1 minute before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndMinutes() + { + $d = Carbon::now()->addMinutes(2); + $this->assertSame('2 minutes before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyHour() + { + $d = Carbon::now()->addMinutes(59); + $this->assertSame('59 minutes before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndHour() + { + $d = Carbon::now()->addHour(); + $this->assertSame('1 hour before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndHours() + { + $d = Carbon::now()->addHours(2); + $this->assertSame('2 hours before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyDay() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->addHours(23); + $this->assertSame('23 hours before', Carbon::now()->diffForHumans($d)); + Carbon::setTestNow(); + } + + public function testDiffForHumansOtherAndDay() + { + $d = Carbon::now()->addDay(); + $this->assertSame('1 day before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndDays() + { + $d = Carbon::now()->addDays(2); + $this->assertSame('2 days before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyWeek() + { + $d = Carbon::now()->addDays(6); + $this->assertSame('6 days before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndWeek() + { + $d = Carbon::now()->addWeek(); + $this->assertSame('1 week before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndWeeks() + { + $d = Carbon::now()->addWeeks(2); + $this->assertSame('2 weeks before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyMonth() + { + $d = Carbon::now()->addWeeks(3); + $this->assertSame('3 weeks before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndMonth() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->addWeeks(4); + $this->assertSame('4 weeks before', Carbon::now()->diffForHumans($d)); + $d = Carbon::now()->addMonth(); + $this->assertSame('1 month before', Carbon::now()->diffForHumans($d)); + Carbon::setTestNow(); + } + + public function testDiffForHumansOtherAndMonths() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->addMonths(2); + $this->assertSame('2 months before', Carbon::now()->diffForHumans($d)); + Carbon::setTestNow(); + } + + public function testDiffForHumansOtherAndNearlyYear() + { + $d = Carbon::now()->addMonths(11); + $this->assertSame('11 months before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndYear() + { + $d = Carbon::now()->addYear(); + $this->assertSame('1 year before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndYears() + { + $d = Carbon::now()->addYears(2); + $this->assertSame('2 years before', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureSecond() + { + $d = Carbon::now()->subSecond(); + $this->assertSame('1 second after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureSeconds() + { + $d = Carbon::now()->subSeconds(2); + $this->assertSame('2 seconds after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyFutureMinute() + { + $d = Carbon::now()->subSeconds(59); + $this->assertSame('59 seconds after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureMinute() + { + $d = Carbon::now()->subMinute(); + $this->assertSame('1 minute after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureMinutes() + { + $d = Carbon::now()->subMinutes(2); + $this->assertSame('2 minutes after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyFutureHour() + { + $d = Carbon::now()->subMinutes(59); + $this->assertSame('59 minutes after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureHour() + { + $d = Carbon::now()->subHour(); + $this->assertSame('1 hour after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureHours() + { + $d = Carbon::now()->subHours(2); + $this->assertSame('2 hours after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyFutureDay() + { + Carbon::setTestNow(Carbon::create(2012, 1, 15)); + $d = Carbon::now()->subHours(23); + $this->assertSame('23 hours after', Carbon::now()->diffForHumans($d)); + Carbon::setTestNow(); + } + + public function testDiffForHumansOtherAndFutureDay() + { + $d = Carbon::now()->subDay(); + $this->assertSame('1 day after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureDays() + { + $d = Carbon::now()->subDays(2); + $this->assertSame('2 days after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyFutureWeek() + { + $d = Carbon::now()->subDays(6); + $this->assertSame('6 days after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureWeek() + { + $d = Carbon::now()->subWeek(); + $this->assertSame('1 week after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureWeeks() + { + $d = Carbon::now()->subWeeks(2); + $this->assertSame('2 weeks after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyFutureMonth() + { + $d = Carbon::now()->subWeeks(3); + $this->assertSame('3 weeks after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureMonth() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->subWeeks(4); + $this->assertSame('4 weeks after', Carbon::now()->diffForHumans($d)); + $d = Carbon::now()->subMonth(); + $this->assertSame('1 month after', Carbon::now()->diffForHumans($d)); + Carbon::setTestNow(); + } + + public function testDiffForHumansOtherAndFutureMonths() + { + $d = Carbon::now()->subMonths(2); + $this->assertSame('2 months after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndNearlyFutureYear() + { + $d = Carbon::now()->subMonths(11); + $this->assertSame('11 months after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureYear() + { + $d = Carbon::now()->subYear(); + $this->assertSame('1 year after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansOtherAndFutureYears() + { + $d = Carbon::now()->subYears(2); + $this->assertSame('2 years after', Carbon::now()->diffForHumans($d)); + } + + public function testDiffForHumansAbsoluteSeconds() + { + $d = Carbon::now()->subSeconds(59); + $this->assertSame('59 seconds', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addSeconds(59); + $this->assertSame('59 seconds', Carbon::now()->diffForHumans($d, true)); + } + + public function testDiffForHumansAbsoluteMinutes() + { + $d = Carbon::now()->subMinutes(30); + $this->assertSame('30 minutes', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addMinutes(30); + $this->assertSame('30 minutes', Carbon::now()->diffForHumans($d, true)); + } + + public function testDiffForHumansAbsoluteHours() + { + $d = Carbon::now()->subHours(3); + $this->assertSame('3 hours', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addHours(3); + $this->assertSame('3 hours', Carbon::now()->diffForHumans($d, true)); + } + + public function testDiffForHumansAbsoluteDays() + { + $d = Carbon::now()->subDays(2); + $this->assertSame('2 days', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addDays(2); + $this->assertSame('2 days', Carbon::now()->diffForHumans($d, true)); + } + + public function testDiffForHumansAbsoluteWeeks() + { + $d = Carbon::now()->subWeeks(2); + $this->assertSame('2 weeks', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addWeeks(2); + $this->assertSame('2 weeks', Carbon::now()->diffForHumans($d, true)); + } + + public function testDiffForHumansAbsoluteMonths() + { + Carbon::setTestNow(Carbon::create(2012, 1, 1)); + $d = Carbon::now()->subMonths(2); + $this->assertSame('2 months', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addMonths(2); + $this->assertSame('2 months', Carbon::now()->diffForHumans($d, true)); + Carbon::setTestNow(); + } + + public function testDiffForHumansAbsoluteYears() + { + $d = Carbon::now()->subYears(1); + $this->assertSame('1 year', Carbon::now()->diffForHumans($d, true)); + $d = Carbon::now()->addYears(1); + $this->assertSame('1 year', Carbon::now()->diffForHumans($d, true)); + } + + public function testDiffForHumansWithShorterMonthShouldStillBeAMonth() + { + $feb15 = Carbon::parse('2015-02-15'); + $mar15 = Carbon::parse('2015-03-15'); + $this->assertSame('1 month after', $mar15->diffForHumans($feb15)); + } +} diff --git a/vendor/nesbot/carbon/tests/FluidSettersTest.php b/vendor/nesbot/carbon/tests/FluidSettersTest.php new file mode 100755 index 0000000..3ec1264 --- /dev/null +++ b/vendor/nesbot/carbon/tests/FluidSettersTest.php @@ -0,0 +1,113 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class FluidSettersTest extends TestFixture +{ + public function testFluidYearSetter() + { + $d = Carbon::now(); + $this->assertTrue($d->year(1995) instanceof Carbon); + $this->assertSame(1995, $d->year); + } + + public function testFluidMonthSetter() + { + $d = Carbon::now(); + $this->assertTrue($d->month(3) instanceof Carbon); + $this->assertSame(3, $d->month); + } + + public function testFluidMonthSetterWithWrap() + { + $d = Carbon::createFromDate(2012, 8, 21); + $this->assertTrue($d->month(13) instanceof Carbon); + $this->assertSame(1, $d->month); + } + + public function testFluidDaySetter() + { + $d = Carbon::now(); + $this->assertTrue($d->day(2) instanceof Carbon); + $this->assertSame(2, $d->day); + } + + public function testFluidDaySetterWithWrap() + { + $d = Carbon::createFromDate(2000, 1, 1); + $this->assertTrue($d->day(32) instanceof Carbon); + $this->assertSame(1, $d->day); + } + + public function testFluidSetDate() + { + $d = Carbon::createFromDate(2000, 1, 1); + $this->assertTrue($d->setDate(1995, 13, 32) instanceof Carbon); + $this->assertCarbon($d, 1996, 2, 1); + } + + public function testFluidHourSetter() + { + $d = Carbon::now(); + $this->assertTrue($d->hour(2) instanceof Carbon); + $this->assertSame(2, $d->hour); + } + + public function testFluidHourSetterWithWrap() + { + $d = Carbon::now(); + $this->assertTrue($d->hour(25) instanceof Carbon); + $this->assertSame(1, $d->hour); + } + + public function testFluidMinuteSetter() + { + $d = Carbon::now(); + $this->assertTrue($d->minute(2) instanceof Carbon); + $this->assertSame(2, $d->minute); + } + + public function testFluidMinuteSetterWithWrap() + { + $d = Carbon::now(); + $this->assertTrue($d->minute(61) instanceof Carbon); + $this->assertSame(1, $d->minute); + } + + public function testFluidSecondSetter() + { + $d = Carbon::now(); + $this->assertTrue($d->second(2) instanceof Carbon); + $this->assertSame(2, $d->second); + } + + public function testFluidSecondSetterWithWrap() + { + $d = Carbon::now(); + $this->assertTrue($d->second(62) instanceof Carbon); + $this->assertSame(2, $d->second); + } + + public function testFluidSetTime() + { + $d = Carbon::createFromDate(2000, 1, 1); + $this->assertTrue($d->setTime(25, 61, 61) instanceof Carbon); + $this->assertCarbon($d, 2000, 1, 2, 2, 2, 1); + } + + public function testFluidTimestampSetter() + { + $d = Carbon::now(); + $this->assertTrue($d->timestamp(10) instanceof Carbon); + $this->assertSame(10, $d->timestamp); + } +} diff --git a/vendor/nesbot/carbon/tests/GettersTest.php b/vendor/nesbot/carbon/tests/GettersTest.php new file mode 100755 index 0000000..867dc55 --- /dev/null +++ b/vendor/nesbot/carbon/tests/GettersTest.php @@ -0,0 +1,285 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class GettersTest extends TestFixture +{ + public function testGettersThrowExceptionOnUnknownGetter() + { + $this->setExpectedException('InvalidArgumentException'); + Carbon::create(1234, 5, 6, 7, 8, 9)->sdfsdfss; + } + + public function testYearGetter() + { + $d = Carbon::create(1234, 5, 6, 7, 8, 9); + $this->assertSame(1234, $d->year); + } + + public function testYearIsoGetter() + { + $d = Carbon::createFromDate(2012, 12, 31); + $this->assertSame(2013, $d->yearIso); + } + + public function testMonthGetter() + { + $d = Carbon::create(1234, 5, 6, 7, 8, 9); + $this->assertSame(5, $d->month); + } + + public function testDayGetter() + { + $d = Carbon::create(1234, 5, 6, 7, 8, 9); + $this->assertSame(6, $d->day); + } + + public function testHourGetter() + { + $d = Carbon::create(1234, 5, 6, 7, 8, 9); + $this->assertSame(7, $d->hour); + } + + public function testMinuteGetter() + { + $d = Carbon::create(1234, 5, 6, 7, 8, 9); + $this->assertSame(8, $d->minute); + } + + public function testSecondGetter() + { + $d = Carbon::create(1234, 5, 6, 7, 8, 9); + $this->assertSame(9, $d->second); + } + + public function testMicroGetter() + { + $micro = 345678; + $d = Carbon::parse('2014-01-05 12:34:11.'.$micro); + $this->assertSame($micro, $d->micro); + } + + public function testMicroGetterWithDefaultNow() + { + $d = Carbon::now(); + $this->assertSame(0, $d->micro); + } + + public function testDayOfWeeGetter() + { + $d = Carbon::create(2012, 5, 7, 7, 8, 9); + $this->assertSame(Carbon::MONDAY, $d->dayOfWeek); + } + + public function testDayOfYearGetter() + { + $d = Carbon::createFromDate(2012, 5, 7); + $this->assertSame(127, $d->dayOfYear); + } + + public function testDaysInMonthGetter() + { + $d = Carbon::createFromDate(2012, 5, 7); + $this->assertSame(31, $d->daysInMonth); + } + + public function testTimestampGetter() + { + $d = Carbon::create(); + $d->setTimezone('GMT'); + $this->assertSame(0, $d->setDateTime(1970, 1, 1, 0, 0, 0)->timestamp); + } + + public function testGetAge() + { + $d = Carbon::now(); + $this->assertSame(0, $d->age); + } + + public function testGetAgeWithRealAge() + { + $d = Carbon::createFromDate(1975, 5, 21); + $age = intval(substr(date('Ymd') - date('Ymd', $d->timestamp), 0, -4)); + + $this->assertSame($age, $d->age); + } + + public function testGetQuarterFirst() + { + $d = Carbon::createFromDate(2012, 1, 1); + $this->assertSame(1, $d->quarter); + } + + public function testGetQuarterFirstEnd() + { + $d = Carbon::createFromDate(2012, 3, 31); + $this->assertSame(1, $d->quarter); + } + + public function testGetQuarterSecond() + { + $d = Carbon::createFromDate(2012, 4, 1); + $this->assertSame(2, $d->quarter); + } + + public function testGetQuarterThird() + { + $d = Carbon::createFromDate(2012, 7, 1); + $this->assertSame(3, $d->quarter); + } + + public function testGetQuarterFourth() + { + $d = Carbon::createFromDate(2012, 10, 1); + $this->assertSame(4, $d->quarter); + } + + public function testGetQuarterFirstLast() + { + $d = Carbon::createFromDate(2012, 12, 31); + $this->assertSame(4, $d->quarter); + } + + public function testGetLocalTrue() + { + // Default timezone has been set to America/Toronto in TestFixture.php + // @see : http://en.wikipedia.org/wiki/List_of_UTC_time_offsets + $this->assertTrue(Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->local); + $this->assertTrue(Carbon::createFromDate(2012, 1, 1, 'America/New_York')->local); + } + + public function testGetLocalFalse() + { + $this->assertFalse(Carbon::createFromDate(2012, 7, 1, 'UTC')->local); + $this->assertFalse(Carbon::createFromDate(2012, 7, 1, 'Europe/London')->local); + } + + public function testGetUtcFalse() + { + $this->assertFalse(Carbon::createFromDate(2013, 1, 1, 'America/Toronto')->utc); + $this->assertFalse(Carbon::createFromDate(2013, 1, 1, 'Europe/Paris')->utc); + } + + public function testGetUtcTrue() + { + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Atlantic/Reykjavik')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/Lisbon')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Africa/Casablanca')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Africa/Dakar')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/Dublin')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/London')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'UTC')->utc); + $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'GMT')->utc); + } + + public function testGetDstFalse() + { + $this->assertFalse(Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->dst); + } + + public function testGetDstTrue() + { + $this->assertTrue(Carbon::createFromDate(2012, 7, 1, 'America/Toronto')->dst); + } + + public function testOffsetForTorontoWithDST() + { + $this->assertSame(-18000, Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->offset); + } + + public function testOffsetForTorontoNoDST() + { + $this->assertSame(-14400, Carbon::createFromDate(2012, 6, 1, 'America/Toronto')->offset); + } + + public function testOffsetForGMT() + { + $this->assertSame(0, Carbon::createFromDate(2012, 6, 1, 'GMT')->offset); + } + + public function testOffsetHoursForTorontoWithDST() + { + $this->assertSame(-5, Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->offsetHours); + } + + public function testOffsetHoursForTorontoNoDST() + { + $this->assertSame(-4, Carbon::createFromDate(2012, 6, 1, 'America/Toronto')->offsetHours); + } + + public function testOffsetHoursForGMT() + { + $this->assertSame(0, Carbon::createFromDate(2012, 6, 1, 'GMT')->offsetHours); + } + + public function testIsLeapYearTrue() + { + $this->assertTrue(Carbon::createFromDate(2012, 1, 1)->isLeapYear()); + } + + public function testIsLeapYearFalse() + { + $this->assertFalse(Carbon::createFromDate(2011, 1, 1)->isLeapYear()); + } + + public function testWeekOfMonth() + { + $this->assertSame(5, Carbon::createFromDate(2012, 9, 30)->weekOfMonth); + $this->assertSame(4, Carbon::createFromDate(2012, 9, 28)->weekOfMonth); + $this->assertSame(3, Carbon::createFromDate(2012, 9, 20)->weekOfMonth); + $this->assertSame(2, Carbon::createFromDate(2012, 9, 8)->weekOfMonth); + $this->assertSame(1, Carbon::createFromDate(2012, 9, 1)->weekOfMonth); + } + + public function testWeekOfYearFirstWeek() + { + $this->assertSame(52, Carbon::createFromDate(2012, 1, 1)->weekOfYear); + $this->assertSame(1, Carbon::createFromDate(2012, 1, 2)->weekOfYear); + } + + public function testWeekOfYearLastWeek() + { + $this->assertSame(52, Carbon::createFromDate(2012, 12, 30)->weekOfYear); + $this->assertSame(1, Carbon::createFromDate(2012, 12, 31)->weekOfYear); + } + + public function testGetTimezone() + { + $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); + $this->assertSame('America/Toronto', $dt->timezone->getName()); + } + + public function testGetTz() + { + $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); + $this->assertSame('America/Toronto', $dt->tz->getName()); + } + + public function testGetTimezoneName() + { + $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); + $this->assertSame('America/Toronto', $dt->timezoneName); + } + + public function testGetTzName() + { + $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); + $this->assertSame('America/Toronto', $dt->tzName); + } + + public function testInvalidGetter() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::now(); + $bb = $d->doesNotExit; + } +} diff --git a/vendor/nesbot/carbon/tests/InstanceTest.php b/vendor/nesbot/carbon/tests/InstanceTest.php new file mode 100755 index 0000000..d2d1c35 --- /dev/null +++ b/vendor/nesbot/carbon/tests/InstanceTest.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class InstanceTest extends TestFixture +{ + public function testInstanceFromDateTime() + { + $dating = Carbon::instance(\DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11')); + $this->assertCarbon($dating, 1975, 5, 21, 22, 32, 11); + } + + public function testInstanceFromDateTimeKeepsTimezoneName() + { + $dating = Carbon::instance(\DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11')->setTimezone(new \DateTimeZone('America/Vancouver'))); + $this->assertSame('America/Vancouver', $dating->tzName); + } + + public function testInstanceFromDateTimeKeepsMicros() + { + $micro = 254687; + $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.'.$micro); + $carbon = Carbon::instance($datetime); + $this->assertSame($micro, $carbon->micro); + } +} diff --git a/vendor/nesbot/carbon/tests/IsTest.php b/vendor/nesbot/carbon/tests/IsTest.php new file mode 100755 index 0000000..bc098ad --- /dev/null +++ b/vendor/nesbot/carbon/tests/IsTest.php @@ -0,0 +1,133 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class IsTest extends TestFixture +{ + public function testIsWeekdayTrue() + { + $this->assertTrue(Carbon::createFromDate(2012, 1, 2)->isWeekday()); + } + + public function testIsWeekdayFalse() + { + $this->assertFalse(Carbon::createFromDate(2012, 1, 1)->isWeekday()); + } + + public function testIsWeekendTrue() + { + $this->assertTrue(Carbon::createFromDate(2012, 1, 1)->isWeekend()); + } + + public function testIsWeekendFalse() + { + $this->assertFalse(Carbon::createFromDate(2012, 1, 2)->isWeekend()); + } + + public function testIsYesterdayTrue() + { + $this->assertTrue(Carbon::now()->subDay()->isYesterday()); + } + + public function testIsYesterdayFalseWithToday() + { + $this->assertFalse(Carbon::now()->endOfDay()->isYesterday()); + } + + public function testIsYesterdayFalseWith2Days() + { + $this->assertFalse(Carbon::now()->subDays(2)->startOfDay()->isYesterday()); + } + + public function testIsTodayTrue() + { + $this->assertTrue(Carbon::now()->isToday()); + } + + public function testIsTodayFalseWithYesterday() + { + $this->assertFalse(Carbon::now()->subDay()->endOfDay()->isToday()); + } + + public function testIsTodayFalseWithTomorrow() + { + $this->assertFalse(Carbon::now()->addDay()->startOfDay()->isToday()); + } + + public function testIsTodayWithTimezone() + { + $this->assertTrue(Carbon::now('Asia/Tokyo')->isToday()); + } + + public function testIsTomorrowTrue() + { + $this->assertTrue(Carbon::now()->addDay()->isTomorrow()); + } + + public function testIsTomorrowFalseWithToday() + { + $this->assertFalse(Carbon::now()->endOfDay()->isTomorrow()); + } + + public function testIsTomorrowFalseWith2Days() + { + $this->assertFalse(Carbon::now()->addDays(2)->startOfDay()->isTomorrow()); + } + + public function testIsFutureTrue() + { + $this->assertTrue(Carbon::now()->addSecond()->isFuture()); + } + + public function testIsFutureFalse() + { + $this->assertFalse(Carbon::now()->isFuture()); + } + + public function testIsFutureFalseInThePast() + { + $this->assertFalse(Carbon::now()->subSecond()->isFuture()); + } + + public function testIsPastTrue() + { + $this->assertTrue(Carbon::now()->subSecond()->isPast()); + } + + public function testIsPastFalse() + { + $this->assertFalse(Carbon::now()->addSecond()->isPast()); + $this->assertFalse(Carbon::now()->isPast()); + } + + public function testIsLeapYearTrue() + { + $this->assertTrue(Carbon::createFromDate(2016, 1, 1)->isLeapYear()); + } + + public function testIsLeapYearFalse() + { + $this->assertFalse(Carbon::createFromDate(2014, 1, 1)->isLeapYear()); + } + + public function testIsSameDayTrue() + { + $current = Carbon::createFromDate(2012, 1, 2); + $this->assertTrue($current->isSameDay(Carbon::createFromDate(2012, 1, 2))); + } + + public function testIsSameDayFalse() + { + $current = Carbon::createFromDate(2012, 1, 2); + $this->assertFalse($current->isSameDay(Carbon::createFromDate(2012, 1, 3))); + } +} diff --git a/vendor/nesbot/carbon/tests/IssetTest.php b/vendor/nesbot/carbon/tests/IssetTest.php new file mode 100755 index 0000000..6f2c424 --- /dev/null +++ b/vendor/nesbot/carbon/tests/IssetTest.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class IssetTest extends TestFixture +{ + public function testIssetReturnFalseForUnknownProperty() + { + $this->assertFalse(isset(Carbon::create(1234, 5, 6, 7, 8, 9)->sdfsdfss)); + } + + public function testIssetReturnTrueForProperties() + { + $properties = array( + 'year', + 'month', + 'day', + 'hour', + 'minute', + 'second', + 'dayOfWeek', + 'dayOfYear', + 'daysInMonth', + 'timestamp', + 'age', + 'quarter', + 'dst', + 'offset', + 'offsetHours', + 'timezone', + 'timezoneName', + 'tz', + 'tzName', + ); + + foreach ($properties as $property) { + $this->assertTrue(isset(Carbon::create(1234, 5, 6, 7, 8, 9)->$property)); + } + } +} diff --git a/vendor/nesbot/carbon/tests/LocalizationTest.php b/vendor/nesbot/carbon/tests/LocalizationTest.php new file mode 100755 index 0000000..9e00c24 --- /dev/null +++ b/vendor/nesbot/carbon/tests/LocalizationTest.php @@ -0,0 +1,411 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\Loader\ArrayLoader; + +class LocalizationTest extends TestFixture +{ + public function testGetTranslator() + { + $t = Carbon::getTranslator(); + $this->assertNotNull($t); + $this->assertSame('en', $t->getLocale()); + } + + public function testSetTranslator() + { + $t = new Translator('fr'); + $t->addLoader('array', new ArrayLoader()); + Carbon::setTranslator($t); + + $t = Carbon::getTranslator(); + $this->assertNotNull($t); + $this->assertSame('fr', $t->getLocale()); + } + + public function testGetLocale() + { + Carbon::setLocale('en'); + $this->assertSame('en', Carbon::getLocale()); + } + + public function testSetLocale() + { + Carbon::setLocale('en'); + $this->assertSame('en', Carbon::getLocale()); + Carbon::setLocale('fr'); + $this->assertSame('fr', Carbon::getLocale()); + } + + /** + * The purpose of these tests aren't to test the validitity of the translation + * but more so to test that the language file exists. + */ + + public function testDiffForHumansLocalizedInFrench() + { + Carbon::setLocale('fr'); + + $d = Carbon::now()->subSecond(); + $this->assertSame('il y a 1 seconde', $d->diffForHumans()); + + $d = Carbon::now()->subSeconds(2); + $this->assertSame('il y a 2 secondes', $d->diffForHumans()); + + $d = Carbon::now()->subMinute(); + $this->assertSame('il y a 1 minute', $d->diffForHumans()); + + $d = Carbon::now()->subMinutes(2); + $this->assertSame('il y a 2 minutes', $d->diffForHumans()); + + $d = Carbon::now()->subHour(); + $this->assertSame('il y a 1 heure', $d->diffForHumans()); + + $d = Carbon::now()->subHours(2); + $this->assertSame('il y a 2 heures', $d->diffForHumans()); + + $d = Carbon::now()->subDay(); + $this->assertSame('il y a 1 jour', $d->diffForHumans()); + + $d = Carbon::now()->subDays(2); + $this->assertSame('il y a 2 jours', $d->diffForHumans()); + + $d = Carbon::now()->subWeek(); + $this->assertSame('il y a 1 semaine', $d->diffForHumans()); + + $d = Carbon::now()->subWeeks(2); + $this->assertSame('il y a 2 semaines', $d->diffForHumans()); + + $d = Carbon::now()->subMonth(); + $this->assertSame('il y a 1 mois', $d->diffForHumans()); + + $d = Carbon::now()->subMonths(2); + $this->assertSame('il y a 2 mois', $d->diffForHumans()); + + $d = Carbon::now()->subYear(); + $this->assertSame('il y a 1 an', $d->diffForHumans()); + + $d = Carbon::now()->subYears(2); + $this->assertSame('il y a 2 ans', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $this->assertSame('dans 1 seconde', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $d2 = Carbon::now(); + $this->assertSame('1 seconde après', $d->diffForHumans($d2)); + $this->assertSame('1 seconde avant', $d2->diffForHumans($d)); + + $this->assertSame('1 seconde', $d->diffForHumans($d2, true)); + $this->assertSame('2 secondes', $d2->diffForHumans($d->addSecond(), true)); + } + + public function testDiffForHumansLocalizedInSpanish() + { + Carbon::setLocale('es'); + + $d = Carbon::now()->subSecond(); + $this->assertSame('hace 1 segundo', $d->diffForHumans()); + + $d = Carbon::now()->subSeconds(3); + $this->assertSame('hace 3 segundos', $d->diffForHumans()); + + $d = Carbon::now()->subMinute(); + $this->assertSame('hace 1 minuto', $d->diffForHumans()); + + $d = Carbon::now()->subMinutes(2); + $this->assertSame('hace 2 minutos', $d->diffForHumans()); + + $d = Carbon::now()->subHour(); + $this->assertSame('hace 1 hora', $d->diffForHumans()); + + $d = Carbon::now()->subHours(2); + $this->assertSame('hace 2 horas', $d->diffForHumans()); + + $d = Carbon::now()->subDay(); + $this->assertSame('hace 1 día', $d->diffForHumans()); + + $d = Carbon::now()->subDays(2); + $this->assertSame('hace 2 días', $d->diffForHumans()); + + $d = Carbon::now()->subWeek(); + $this->assertSame('hace 1 semana', $d->diffForHumans()); + + $d = Carbon::now()->subWeeks(2); + $this->assertSame('hace 2 semanas', $d->diffForHumans()); + + $d = Carbon::now()->subMonth(); + $this->assertSame('hace 1 mes', $d->diffForHumans()); + + $d = Carbon::now()->subMonths(2); + $this->assertSame('hace 2 meses', $d->diffForHumans()); + + $d = Carbon::now()->subYear(); + $this->assertSame('hace 1 año', $d->diffForHumans()); + + $d = Carbon::now()->subYears(2); + $this->assertSame('hace 2 años', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $this->assertSame('dentro de 1 segundo', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $d2 = Carbon::now(); + $this->assertSame('1 segundo antes', $d->diffForHumans($d2)); + $this->assertSame('1 segundo después', $d2->diffForHumans($d)); + + $this->assertSame('1 segundo', $d->diffForHumans($d2, true)); + $this->assertSame('2 segundos', $d2->diffForHumans($d->addSecond(), true)); + } + + public function testDiffForHumansLocalizedInItalian() + { + Carbon::setLocale('it'); + + $d = Carbon::now()->addYear(); + $this->assertSame('1 anno da adesso', $d->diffForHumans()); + + $d = Carbon::now()->addYears(2); + $this->assertSame('2 anni da adesso', $d->diffForHumans()); + } + + public function testDiffForHumansLocalizedInGerman() + { + Carbon::setLocale('de'); + + $d = Carbon::now()->addYear(); + $this->assertSame('in 1 Jahr', $d->diffForHumans()); + + $d = Carbon::now()->addYears(2); + $this->assertSame('in 2 Jahren', $d->diffForHumans()); + + $d = Carbon::now()->subYear(); + $this->assertSame('1 Jahr später', Carbon::now()->diffForHumans($d)); + + $d = Carbon::now()->subYears(2); + $this->assertSame('2 Jahre später', Carbon::now()->diffForHumans($d)); + + $d = Carbon::now()->addYear(); + $this->assertSame('1 Jahr zuvor', Carbon::now()->diffForHumans($d)); + + $d = Carbon::now()->addYears(2); + $this->assertSame('2 Jahre zuvor', Carbon::now()->diffForHumans($d)); + + $d = Carbon::now()->subYear(); + $this->assertSame('vor 1 Jahr', $d->diffForHumans()); + + $d = Carbon::now()->subYears(2); + $this->assertSame('vor 2 Jahren', $d->diffForHumans()); + } + + public function testDiffForHumansLocalizedInTurkish() + { + Carbon::setLocale('tr'); + + $d = Carbon::now()->subSecond(); + $this->assertSame('1 saniye önce', $d->diffForHumans()); + + $d = Carbon::now()->subSeconds(2); + $this->assertSame('2 saniye önce', $d->diffForHumans()); + + $d = Carbon::now()->subMinute(); + $this->assertSame('1 dakika önce', $d->diffForHumans()); + + $d = Carbon::now()->subMinutes(2); + $this->assertSame('2 dakika önce', $d->diffForHumans()); + + $d = Carbon::now()->subHour(); + $this->assertSame('1 saat önce', $d->diffForHumans()); + + $d = Carbon::now()->subHours(2); + $this->assertSame('2 saat önce', $d->diffForHumans()); + + $d = Carbon::now()->subDay(); + $this->assertSame('1 gün önce', $d->diffForHumans()); + + $d = Carbon::now()->subDays(2); + $this->assertSame('2 gün önce', $d->diffForHumans()); + + $d = Carbon::now()->subWeek(); + $this->assertSame('1 hafta önce', $d->diffForHumans()); + + $d = Carbon::now()->subWeeks(2); + $this->assertSame('2 hafta önce', $d->diffForHumans()); + + $d = Carbon::now()->subMonth(); + $this->assertSame('1 ay önce', $d->diffForHumans()); + + $d = Carbon::now()->subMonths(2); + $this->assertSame('2 ay önce', $d->diffForHumans()); + + $d = Carbon::now()->subYear(); + $this->assertSame('1 yıl önce', $d->diffForHumans()); + + $d = Carbon::now()->subYears(2); + $this->assertSame('2 yıl önce', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $this->assertSame('1 saniye andan itibaren', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $d2 = Carbon::now(); + $this->assertSame('1 saniye sonra', $d->diffForHumans($d2)); + $this->assertSame('1 saniye önce', $d2->diffForHumans($d)); + + $this->assertSame('1 saniye', $d->diffForHumans($d2, true)); + $this->assertSame('2 saniye', $d2->diffForHumans($d->addSecond(), true)); + } + + public function testDiffForHumansLocalizedInDanish() + { + Carbon::setLocale('da'); + + $d = Carbon::now()->subSecond(); + $this->assertSame('1 sekund siden', $d->diffForHumans()); + + $d = Carbon::now()->subSeconds(2); + $this->assertSame('2 sekunder siden', $d->diffForHumans()); + + $d = Carbon::now()->subMinute(); + $this->assertSame('1 minut siden', $d->diffForHumans()); + + $d = Carbon::now()->subMinutes(2); + $this->assertSame('2 minutter siden', $d->diffForHumans()); + + $d = Carbon::now()->subHour(); + $this->assertSame('1 time siden', $d->diffForHumans()); + + $d = Carbon::now()->subHours(2); + $this->assertSame('2 timer siden', $d->diffForHumans()); + + $d = Carbon::now()->subDay(); + $this->assertSame('1 dag siden', $d->diffForHumans()); + + $d = Carbon::now()->subDays(2); + $this->assertSame('2 dage siden', $d->diffForHumans()); + + $d = Carbon::now()->subWeek(); + $this->assertSame('1 uge siden', $d->diffForHumans()); + + $d = Carbon::now()->subWeeks(2); + $this->assertSame('2 uger siden', $d->diffForHumans()); + + $d = Carbon::now()->subMonth(); + $this->assertSame('1 måned siden', $d->diffForHumans()); + + $d = Carbon::now()->subMonths(2); + $this->assertSame('2 måneder siden', $d->diffForHumans()); + + $d = Carbon::now()->subYear(); + $this->assertSame('1 år siden', $d->diffForHumans()); + + $d = Carbon::now()->subYears(2); + $this->assertSame('2 år siden', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $this->assertSame('om 1 sekund', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $d2 = Carbon::now(); + $this->assertSame('1 sekund efter', $d->diffForHumans($d2)); + $this->assertSame('1 sekund før', $d2->diffForHumans($d)); + + $this->assertSame('1 sekund', $d->diffForHumans($d2, true)); + $this->assertSame('2 sekunder', $d2->diffForHumans($d->addSecond(), true)); + } + + public function testDiffForHumansLocalizedInLithuanian() + { + Carbon::setLocale('lt'); + + $d = Carbon::now()->addYear(); + $this->assertSame('1 metai nuo dabar', $d->diffForHumans()); + + $d = Carbon::now()->addYears(2); + $this->assertSame('2 metai nuo dabar', $d->diffForHumans()); + } + + public function testDiffForHumansLocalizedInKorean() + { + Carbon::setLocale('ko'); + + $d = Carbon::now()->addYear(); + $this->assertSame('1 년 후', $d->diffForHumans()); + + $d = Carbon::now()->addYears(2); + $this->assertSame('2 년 후', $d->diffForHumans()); + } + + public function testDiffForHumansLocalizedInFarsi() + { + Carbon::setLocale('fa'); + + $d = Carbon::now()->subSecond(); + $this->assertSame('1 ثانیه پیش', $d->diffForHumans()); + + $d = Carbon::now()->subSeconds(2); + $this->assertSame('2 ثانیه پیش', $d->diffForHumans()); + + $d = Carbon::now()->subMinute(); + $this->assertSame('1 دقیقه پیش', $d->diffForHumans()); + + $d = Carbon::now()->subMinutes(2); + $this->assertSame('2 دقیقه پیش', $d->diffForHumans()); + + $d = Carbon::now()->subHour(); + $this->assertSame('1 ساعت پیش', $d->diffForHumans()); + + $d = Carbon::now()->subHours(2); + $this->assertSame('2 ساعت پیش', $d->diffForHumans()); + + $d = Carbon::now()->subDay(); + $this->assertSame('1 روز پیش', $d->diffForHumans()); + + $d = Carbon::now()->subDays(2); + $this->assertSame('2 روز پیش', $d->diffForHumans()); + + $d = Carbon::now()->subWeek(); + $this->assertSame('1 هفته پیش', $d->diffForHumans()); + + $d = Carbon::now()->subWeeks(2); + $this->assertSame('2 هفته پیش', $d->diffForHumans()); + + $d = Carbon::now()->subMonth(); + $this->assertSame('1 ماه پیش', $d->diffForHumans()); + + $d = Carbon::now()->subMonths(2); + $this->assertSame('2 ماه پیش', $d->diffForHumans()); + + $d = Carbon::now()->subYear(); + $this->assertSame('1 سال پیش', $d->diffForHumans()); + + $d = Carbon::now()->subYears(2); + $this->assertSame('2 سال پیش', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $this->assertSame('1 ثانیه بعد', $d->diffForHumans()); + + $d = Carbon::now()->addSecond(); + $d2 = Carbon::now(); + $this->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2)); + $this->assertSame('1 ثانیه پس از', $d2->diffForHumans($d)); + + $d = Carbon::now()->addSecond(); + $d2 = Carbon::now(); + $this->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2)); + $this->assertSame('1 ثانیه پس از', $d2->diffForHumans($d)); + + $this->assertSame('1 ثانیه', $d->diffForHumans($d2, true)); + $this->assertSame('2 ثانیه', $d2->diffForHumans($d->addSecond(), true)); + } +} diff --git a/vendor/nesbot/carbon/tests/NowAndOtherStaticHelpersTest.php b/vendor/nesbot/carbon/tests/NowAndOtherStaticHelpersTest.php new file mode 100755 index 0000000..7e7bdb9 --- /dev/null +++ b/vendor/nesbot/carbon/tests/NowAndOtherStaticHelpersTest.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class NowAndOtherStaticHelpersTest extends TestFixture +{ + public function testNow() + { + $dt = Carbon::now(); + $this->assertSame(time(), $dt->timestamp); + } + + public function testNowWithTimezone() + { + $dt = Carbon::now('Europe/London'); + $this->assertSame(time(), $dt->timestamp); + $this->assertSame('Europe/London', $dt->tzName); + } + + public function testToday() + { + $dt = Carbon::today(); + $this->assertSame(date('Y-m-d 00:00:00'), $dt->toDateTimeString()); + } + + public function testTodayWithTimezone() + { + $dt = Carbon::today('Europe/London'); + $dt2 = new \DateTime('now', new \DateTimeZone('Europe/London')); + $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); + } + + public function testTomorrow() + { + $dt = Carbon::tomorrow(); + $dt2 = new \DateTime('tomorrow'); + $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); + } + + public function testTomorrowWithTimezone() + { + $dt = Carbon::tomorrow('Europe/London'); + $dt2 = new \DateTime('tomorrow', new \DateTimeZone('Europe/London')); + $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); + } + + public function testYesterday() + { + $dt = Carbon::yesterday(); + $dt2 = new \DateTime('yesterday'); + $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); + } + + public function testYesterdayWithTimezone() + { + $dt = Carbon::yesterday('Europe/London'); + $dt2 = new \DateTime('yesterday', new \DateTimeZone('Europe/London')); + $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString()); + } + + public function testMinValue() + { + $this->assertLessThanOrEqual(- 2147483647, Carbon::minValue()->getTimestamp()); + } + + public function testMaxValue() + { + $this->assertGreaterThanOrEqual(2147483647, Carbon::maxValue()->getTimestamp()); + } +} diff --git a/vendor/nesbot/carbon/tests/RelativeTest.php b/vendor/nesbot/carbon/tests/RelativeTest.php new file mode 100755 index 0000000..1e0993c --- /dev/null +++ b/vendor/nesbot/carbon/tests/RelativeTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class RelativeTest extends TestFixture +{ + public function testSecondsSinceMidnight() + { + $d = Carbon::today()->addSeconds(30); + $this->assertSame(30, $d->secondsSinceMidnight()); + + $d = Carbon::today()->addDays(1); + $this->assertSame(0, $d->secondsSinceMidnight()); + + $d = Carbon::today()->addDays(1)->addSeconds(120); + $this->assertSame(120, $d->secondsSinceMidnight()); + + $d = Carbon::today()->addMonths(3)->addSeconds(42); + $this->assertSame(42, $d->secondsSinceMidnight()); + } + + public function testSecondsUntilEndOfDay() + { + $d = Carbon::today()->endOfDay(); + $this->assertSame(0, $d->secondsUntilEndOfDay()); + + $d = Carbon::today()->endOfDay()->subSeconds(60); + $this->assertSame(60, $d->secondsUntilEndOfDay()); + + $d = Carbon::create(2014, 10, 24, 12, 34, 56); + $this->assertSame(41103, $d->secondsUntilEndOfDay()); + + $d = Carbon::create(2014, 10, 24, 0, 0, 0); + $this->assertSame(86399, $d->secondsUntilEndOfDay()); + } +} diff --git a/vendor/nesbot/carbon/tests/SettersTest.php b/vendor/nesbot/carbon/tests/SettersTest.php new file mode 100755 index 0000000..54f5f5a --- /dev/null +++ b/vendor/nesbot/carbon/tests/SettersTest.php @@ -0,0 +1,253 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class SettersTest extends TestFixture +{ + public function testYearSetter() + { + $d = Carbon::now(); + $d->year = 1995; + $this->assertSame(1995, $d->year); + } + + public function testMonthSetter() + { + $d = Carbon::now(); + $d->month = 3; + $this->assertSame(3, $d->month); + } + + public function testMonthSetterWithWrap() + { + $d = Carbon::now(); + $d->month = 13; + $this->assertSame(1, $d->month); + } + + public function testDaySetter() + { + $d = Carbon::now(); + $d->day = 2; + $this->assertSame(2, $d->day); + } + + public function testDaySetterWithWrap() + { + $d = Carbon::createFromDate(2012, 8, 5); + $d->day = 32; + $this->assertSame(1, $d->day); + } + + public function testHourSetter() + { + $d = Carbon::now(); + $d->hour = 2; + $this->assertSame(2, $d->hour); + } + + public function testHourSetterWithWrap() + { + $d = Carbon::now(); + $d->hour = 25; + $this->assertSame(1, $d->hour); + } + + public function testMinuteSetter() + { + $d = Carbon::now(); + $d->minute = 2; + $this->assertSame(2, $d->minute); + } + + public function testMinuteSetterWithWrap() + { + $d = Carbon::now(); + $d->minute = 65; + $this->assertSame(5, $d->minute); + } + + public function testSecondSetter() + { + $d = Carbon::now(); + $d->second = 2; + $this->assertSame(2, $d->second); + } + + public function testTimeSetter() + { + $d = Carbon::now(); + $d->setTime(1, 1, 1); + $this->assertSame(1, $d->second); + $d->setTime(1, 1); + $this->assertSame(0, $d->second); + } + + public function testTimeSetterWithChaining() + { + $d = Carbon::now(); + $d->setTime(2, 2, 2)->setTime(1, 1, 1); + $this->assertInstanceOf('Carbon\Carbon', $d); + $this->assertSame(1, $d->second); + $d->setTime(2, 2, 2)->setTime(1, 1); + $this->assertInstanceOf('Carbon\Carbon', $d); + $this->assertSame(0, $d->second); + } + + public function testTimeSetterWithZero() + { + $d = Carbon::now(); + $d->setTime(1, 1); + $this->assertSame(0, $d->second); + } + + public function testDateTimeSetter() + { + $d = Carbon::now(); + $d->setDateTime($d->year, $d->month, $d->day, 1, 1, 1); + $this->assertSame(1, $d->second); + } + + public function testDateTimeSetterWithZero() + { + $d = Carbon::now(); + $d->setDateTime($d->year, $d->month, $d->day, 1, 1); + $this->assertSame(0, $d->second); + } + + public function testDateTimeSetterWithChaining() + { + $d = Carbon::now(); + $d->setDateTime(2013, 9, 24, 17, 4, 29); + $this->assertInstanceOf('Carbon\Carbon', $d); + $d->setDateTime(2014, 10, 25, 18, 5, 30); + $this->assertInstanceOf('Carbon\Carbon', $d); + $this->assertCarbon($d, 2014, 10, 25, 18, 5, 30); + } + + public function testSecondSetterWithWrap() + { + $d = Carbon::now(); + $d->second = 65; + $this->assertSame(5, $d->second); + } + + public function testTimestampSetter() + { + $d = Carbon::now(); + $d->timestamp = 10; + $this->assertSame(10, $d->timestamp); + + $d->setTimestamp(11); + $this->assertSame(11, $d->timestamp); + } + + public function testSetTimezoneWithInvalidTimezone() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::now(); + $d->setTimezone('sdf'); + } + + public function testTimezoneWithInvalidTimezone() + { + $d = Carbon::now(); + + try { + $d->timezone = 'sdf'; + $this->fail('InvalidArgumentException was not been raised.'); + } catch (InvalidArgumentException $expected) { + } + + try { + $d->timezone('sdf'); + $this->fail('InvalidArgumentException was not been raised.'); + } catch (InvalidArgumentException $expected) { + } + } + public function testTzWithInvalidTimezone() + { + $d = Carbon::now(); + + try { + $d->tz = 'sdf'; + $this->fail('InvalidArgumentException was not been raised.'); + } catch (InvalidArgumentException $expected) { + } + + try { + $d->tz('sdf'); + $this->fail('InvalidArgumentException was not been raised.'); + } catch (InvalidArgumentException $expected) { + } + } + public function testSetTimezoneUsingString() + { + $d = Carbon::now(); + $d->setTimezone('America/Toronto'); + $this->assertSame('America/Toronto', $d->tzName); + } + + public function testTimezoneUsingString() + { + $d = Carbon::now(); + $d->timezone = 'America/Toronto'; + $this->assertSame('America/Toronto', $d->tzName); + + $d->timezone('America/Vancouver'); + $this->assertSame('America/Vancouver', $d->tzName); + } + + public function testTzUsingString() + { + $d = Carbon::now(); + $d->tz = 'America/Toronto'; + $this->assertSame('America/Toronto', $d->tzName); + + $d->tz('America/Vancouver'); + $this->assertSame('America/Vancouver', $d->tzName); + } + + public function testSetTimezoneUsingDateTimeZone() + { + $d = Carbon::now(); + $d->setTimezone(new \DateTimeZone('America/Toronto')); + $this->assertSame('America/Toronto', $d->tzName); + } + + public function testTimezoneUsingDateTimeZone() + { + $d = Carbon::now(); + $d->timezone = new \DateTimeZone('America/Toronto'); + $this->assertSame('America/Toronto', $d->tzName); + + $d->timezone(new \DateTimeZone('America/Vancouver')); + $this->assertSame('America/Vancouver', $d->tzName); + } + + public function testTzUsingDateTimeZone() + { + $d = Carbon::now(); + $d->tz = new \DateTimeZone('America/Toronto'); + $this->assertSame('America/Toronto', $d->tzName); + + $d->tz(new \DateTimeZone('America/Vancouver')); + $this->assertSame('America/Vancouver', $d->tzName); + } + + public function testInvalidSetter() + { + $this->setExpectedException('InvalidArgumentException'); + $d = Carbon::now(); + $d->doesNotExit = 'bb'; + } +} diff --git a/vendor/nesbot/carbon/tests/StartEndOfTest.php b/vendor/nesbot/carbon/tests/StartEndOfTest.php new file mode 100755 index 0000000..e72ebed --- /dev/null +++ b/vendor/nesbot/carbon/tests/StartEndOfTest.php @@ -0,0 +1,236 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class StartEndOfTest extends TestFixture +{ + public function testStartOfDay() + { + $dt = Carbon::now(); + $this->assertTrue($dt->startOfDay() instanceof Carbon); + $this->assertCarbon($dt, $dt->year, $dt->month, $dt->day, 0, 0, 0); + } + + public function testEndOfDay() + { + $dt = Carbon::now(); + $this->assertTrue($dt->endOfDay() instanceof Carbon); + $this->assertCarbon($dt, $dt->year, $dt->month, $dt->day, 23, 59, 59); + } + + public function testStartOfMonthIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->startOfMonth() instanceof Carbon); + } + + public function testStartOfMonthFromNow() + { + $dt = Carbon::now()->startOfMonth(); + $this->assertCarbon($dt, $dt->year, $dt->month, 1, 0, 0, 0); + } + + public function testStartOfMonthFromLastDay() + { + $dt = Carbon::create(2000, 1, 31, 2, 3, 4)->startOfMonth(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testStartOfYearIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->startOfYear() instanceof Carbon); + } + + public function testStartOfYearFromNow() + { + $dt = Carbon::now()->startOfYear(); + $this->assertCarbon($dt, $dt->year, 1, 1, 0, 0, 0); + } + + public function testStartOfYearFromFirstDay() + { + $dt = Carbon::create(2000, 1, 1, 1, 1, 1)->startOfYear(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testStartOfYearFromLastDay() + { + $dt = Carbon::create(2000, 12, 31, 23, 59, 59)->startOfYear(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testEndOfMonthIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->endOfMonth() instanceof Carbon); + } + + public function testEndOfMonth() + { + $dt = Carbon::create(2000, 1, 1, 2, 3, 4)->endOfMonth(); + $this->assertCarbon($dt, 2000, 1, 31, 23, 59, 59); + } + + public function testEndOfMonthFromLastDay() + { + $dt = Carbon::create(2000, 1, 31, 2, 3, 4)->endOfMonth(); + $this->assertCarbon($dt, 2000, 1, 31, 23, 59, 59); + } + + public function testEndOfYearIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->endOfYear() instanceof Carbon); + } + + public function testEndOfYearFromNow() + { + $dt = Carbon::now()->endOfYear(); + $this->assertCarbon($dt, $dt->year, 12, 31, 23, 59, 59); + } + + public function testEndOfYearFromFirstDay() + { + $dt = Carbon::create(2000, 1, 1, 1, 1, 1)->endOfYear(); + $this->assertCarbon($dt, 2000, 12, 31, 23, 59, 59); + } + + public function testEndOfYearFromLastDay() + { + $dt = Carbon::create(2000, 12, 31, 23, 59, 59)->endOfYear(); + $this->assertCarbon($dt, 2000, 12, 31, 23, 59, 59); + } + + public function testStartOfDecadeIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->startOfDecade() instanceof Carbon); + } + + public function testStartOfDecadeFromNow() + { + $dt = Carbon::now()->startOfDecade(); + $this->assertCarbon($dt, $dt->year - $dt->year % 10, 1, 1, 0, 0, 0); + } + + public function testStartOfDecadeFromFirstDay() + { + $dt = Carbon::create(2000, 1, 1, 1, 1, 1)->startOfDecade(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testStartOfDecadeFromLastDay() + { + $dt = Carbon::create(2009, 12, 31, 23, 59, 59)->startOfDecade(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testEndOfDecadeIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->endOfDecade() instanceof Carbon); + } + + public function testEndOfDecadeFromNow() + { + $dt = Carbon::now()->endOfDecade(); + $this->assertCarbon($dt, $dt->year - $dt->year % 10 + 9, 12, 31, 23, 59, 59); + } + + public function testEndOfDecadeFromFirstDay() + { + $dt = Carbon::create(2000, 1, 1, 1, 1, 1)->endOfDecade(); + $this->assertCarbon($dt, 2009, 12, 31, 23, 59, 59); + } + + public function testEndOfDecadeFromLastDay() + { + $dt = Carbon::create(2009, 12, 31, 23, 59, 59)->endOfDecade(); + $this->assertCarbon($dt, 2009, 12, 31, 23, 59, 59); + } + + public function testStartOfCenturyIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->startOfCentury() instanceof Carbon); + } + + public function testStartOfCenturyFromNow() + { + $dt = Carbon::now()->startOfCentury(); + $this->assertCarbon($dt, $dt->year - $dt->year % 100, 1, 1, 0, 0, 0); + } + + public function testStartOfCenturyFromFirstDay() + { + $dt = Carbon::create(2000, 1, 1, 1, 1, 1)->startOfCentury(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testStartOfCenturyFromLastDay() + { + $dt = Carbon::create(2009, 12, 31, 23, 59, 59)->startOfCentury(); + $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0); + } + + public function testEndOfCenturyIsFluid() + { + $dt = Carbon::now(); + $this->assertTrue($dt->endOfCentury() instanceof Carbon); + } + + public function testEndOfCenturyFromNow() + { + $dt = Carbon::now()->endOfCentury(); + $this->assertCarbon($dt, $dt->year - $dt->year % 100 + 99, 12, 31, 23, 59, 59); + } + + public function testEndOfCenturyFromFirstDay() + { + $dt = Carbon::create(2000, 1, 1, 1, 1, 1)->endOfCentury(); + $this->assertCarbon($dt, 2099, 12, 31, 23, 59, 59); + } + + public function testEndOfCenturyFromLastDay() + { + $dt = Carbon::create(2099, 12, 31, 23, 59, 59)->endOfCentury(); + $this->assertCarbon($dt, 2099, 12, 31, 23, 59, 59); + } + + public function testAverageIsFluid() + { + $dt = Carbon::now()->average(); + $this->assertTrue($dt instanceof Carbon); + } + + public function testAverageFromSame() + { + $dt1 = Carbon::create(2000, 1, 31, 2, 3, 4); + $dt2 = Carbon::create(2000, 1, 31, 2, 3, 4)->average($dt1); + $this->assertCarbon($dt2, 2000, 1, 31, 2, 3, 4); + } + + public function testAverageFromGreater() + { + $dt1 = Carbon::create(2000, 1, 1, 1, 1, 1); + $dt2 = Carbon::create(2009, 12, 31, 23, 59, 59)->average($dt1); + $this->assertCarbon($dt2, 2004, 12, 31, 12, 30, 30); + } + + public function testAverageFromLower() + { + $dt1 = Carbon::create(2009, 12, 31, 23, 59, 59); + $dt2 = Carbon::create(2000, 1, 1, 1, 1, 1)->average($dt1); + $this->assertCarbon($dt2, 2004, 12, 31, 12, 30, 30); + } +} diff --git a/vendor/nesbot/carbon/tests/StringsTest.php b/vendor/nesbot/carbon/tests/StringsTest.php new file mode 100755 index 0000000..b3cc2fe --- /dev/null +++ b/vendor/nesbot/carbon/tests/StringsTest.php @@ -0,0 +1,157 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class MyCarbon extends Carbon +{ +} + +class StringsTest extends TestFixture +{ + public function testToString() + { + $d = Carbon::now(); + $this->assertSame(Carbon::now()->toDateTimeString(), ''.$d); + } + public function testSetToStringFormat() + { + Carbon::setToStringFormat('jS \o\f F, Y g:i:s a'); + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('25th of December, 1975 2:15:16 pm', ''.$d); + } + public function testResetToStringFormat() + { + $d = Carbon::now(); + Carbon::setToStringFormat('123'); + Carbon::resetToStringFormat(); + $this->assertSame($d->toDateTimeString(), ''.$d); + } + public function testExtendedClassToString() + { + $d = MyCarbon::now(); + $this->assertSame($d->toDateTimeString(), ''.$d); + } + + public function testToDateString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('1975-12-25', $d->toDateString()); + } + public function testToFormattedDateString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Dec 25, 1975', $d->toFormattedDateString()); + } + public function testToLocalizedFormattedDateString() + { + /**************** + + Working out a Travis issue on how to set a different locale + other than EN to test this. + + + $cache = setlocale(LC_TIME, 0); + setlocale(LC_TIME, 'German'); + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Donnerstag 25 Dezember 1975', $d->formatLocalized('%A %d %B %Y')); + setlocale(LC_TIME, $cache); + + *****************/ + } + public function testToLocalizedFormattedTimezonedDateString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16, 'Europe/London'); + $this->assertSame('Thursday 25 December 1975 14:15', $d->formatLocalized('%A %d %B %Y %H:%M')); + } + public function testToTimeString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('14:15:16', $d->toTimeString()); + } + public function testToDateTimeString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('1975-12-25 14:15:16', $d->toDateTimeString()); + } + public function testToDateTimeStringWithPaddedZeroes() + { + $d = Carbon::create(2000, 5, 2, 4, 3, 4); + $this->assertSame('2000-05-02 04:03:04', $d->toDateTimeString()); + } + public function testToDayDateTimeString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thu, Dec 25, 1975 2:15 PM', $d->toDayDateTimeString()); + } + + public function testToAtomString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('1975-12-25T14:15:16-05:00', $d->toAtomString()); + } + public function testToCOOKIEString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + if (\DateTime::COOKIE === 'l, d-M-y H:i:s T') { + $cookieString = 'Thursday, 25-Dec-75 14:15:16 EST'; + } else { + $cookieString = 'Thursday, 25-Dec-1975 14:15:16 EST'; + } + + $this->assertSame($cookieString, $d->toCOOKIEString()); + } + public function testToIso8601String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('1975-12-25T14:15:16-0500', $d->toIso8601String()); + } + public function testToRC822String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thu, 25 Dec 75 14:15:16 -0500', $d->toRfc822String()); + } + public function testToRfc850String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thursday, 25-Dec-75 14:15:16 EST', $d->toRfc850String()); + } + public function testToRfc1036String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thu, 25 Dec 75 14:15:16 -0500', $d->toRfc1036String()); + } + public function testToRfc1123String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRfc1123String()); + } + public function testToRfc2822String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRfc2822String()); + } + public function testToRfc3339String() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('1975-12-25T14:15:16-05:00', $d->toRfc3339String()); + } + public function testToRssString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRssString()); + } + public function testToW3cString() + { + $d = Carbon::create(1975, 12, 25, 14, 15, 16); + $this->assertSame('1975-12-25T14:15:16-05:00', $d->toW3cString()); + } +} diff --git a/vendor/nesbot/carbon/tests/SubTest.php b/vendor/nesbot/carbon/tests/SubTest.php new file mode 100755 index 0000000..ee6e74f --- /dev/null +++ b/vendor/nesbot/carbon/tests/SubTest.php @@ -0,0 +1,214 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class SubTest extends TestFixture +{ + public function testSubYearsPositive() + { + $this->assertSame(1974, Carbon::createFromDate(1975)->subYears(1)->year); + } + + public function testSubYearsZero() + { + $this->assertSame(1975, Carbon::createFromDate(1975)->subYears(0)->year); + } + + public function testSubYearsNegative() + { + $this->assertSame(1976, Carbon::createFromDate(1975)->subYears(-1)->year); + } + + public function testSubYear() + { + $this->assertSame(1974, Carbon::createFromDate(1975)->subYear()->year); + } + + public function testSubMonthsPositive() + { + $this->assertSame(12, Carbon::createFromDate(1975, 1, 1)->subMonths(1)->month); + } + + public function testSubMonthsZero() + { + $this->assertSame(1, Carbon::createFromDate(1975, 1, 1)->subMonths(0)->month); + } + + public function testSubMonthsNegative() + { + $this->assertSame(2, Carbon::createFromDate(1975, 1, 1)->subMonths(-1)->month); + } + + public function testSubMonth() + { + $this->assertSame(12, Carbon::createFromDate(1975, 1, 1)->subMonth()->month); + } + + public function testSubDaysPositive() + { + $this->assertSame(30, Carbon::createFromDate(1975, 5, 1)->subDays(1)->day); + } + + public function testSubDaysZero() + { + $this->assertSame(1, Carbon::createFromDate(1975, 5, 1)->subDays(0)->day); + } + + public function testSubDaysNegative() + { + $this->assertSame(2, Carbon::createFromDate(1975, 5, 1)->subDays(-1)->day); + } + + public function testSubDay() + { + $this->assertSame(30, Carbon::createFromDate(1975, 5, 1)->subDay()->day); + } + + public function testSubWeekdaysPositive() + { + $this->assertSame(22, Carbon::createFromDate(2012, 1, 4)->subWeekdays(9)->day); + } + + public function testSubWeekdaysZero() + { + $this->assertSame(4, Carbon::createFromDate(2012, 1, 4)->subWeekdays(0)->day); + } + + public function testSubWeekdaysNegative() + { + $this->assertSame(13, Carbon::createFromDate(2012, 1, 31)->subWeekdays(-9)->day); + } + + public function testSubWeekday() + { + $this->assertSame(6, Carbon::createFromDate(2012, 1, 9)->subWeekday()->day); + } + + public function testSubWeeksPositive() + { + $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->subWeeks(1)->day); + } + + public function testSubWeeksZero() + { + $this->assertSame(21, Carbon::createFromDate(1975, 5, 21)->subWeeks(0)->day); + } + + public function testSubWeeksNegative() + { + $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->subWeeks(-1)->day); + } + + public function testSubWeek() + { + $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->subWeek()->day); + } + + public function testSubHoursPositive() + { + $this->assertSame(23, Carbon::createFromTime(0)->subHours(1)->hour); + } + + public function testSubHoursZero() + { + $this->assertSame(0, Carbon::createFromTime(0)->subHours(0)->hour); + } + + public function testSubHoursNegative() + { + $this->assertSame(1, Carbon::createFromTime(0)->subHours(-1)->hour); + } + + public function testSubHour() + { + $this->assertSame(23, Carbon::createFromTime(0)->subHour()->hour); + } + + public function testSubMinutesPositive() + { + $this->assertSame(59, Carbon::createFromTime(0, 0)->subMinutes(1)->minute); + } + + public function testSubMinutesZero() + { + $this->assertSame(0, Carbon::createFromTime(0, 0)->subMinutes(0)->minute); + } + + public function testSubMinutesNegative() + { + $this->assertSame(1, Carbon::createFromTime(0, 0)->subMinutes(-1)->minute); + } + + public function testSubMinute() + { + $this->assertSame(59, Carbon::createFromTime(0, 0)->subMinute()->minute); + } + + public function testSubSecondsPositive() + { + $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->subSeconds(1)->second); + } + + public function testSubSecondsZero() + { + $this->assertSame(0, Carbon::createFromTime(0, 0, 0)->subSeconds(0)->second); + } + + public function testSubSecondsNegative() + { + $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->subSeconds(-1)->second); + } + + public function testSubSecond() + { + $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->subSecond()->second); + } + + /***** Test non plural methods with non default args *****/ + + public function testSubYearPassingArg() + { + $this->assertSame(1973, Carbon::createFromDate(1975)->subYear(2)->year); + } + + public function testSubMonthPassingArg() + { + $this->assertSame(3, Carbon::createFromDate(1975, 5, 1)->subMonth(2)->month); + } + + public function testSubMonthNoOverflowPassingArg() + { + $dt = Carbon::createFromDate(2011, 4, 30)->subMonthNoOverflow(2); + $this->assertSame(2, $dt->month); + $this->assertSame(28, $dt->day); + } + + public function testSubDayPassingArg() + { + $this->assertSame(8, Carbon::createFromDate(1975, 5, 10)->subDay(2)->day); + } + + public function testSubHourPassingArg() + { + $this->assertSame(22, Carbon::createFromTime(0)->subHour(2)->hour); + } + + public function testSubMinutePassingArg() + { + $this->assertSame(58, Carbon::createFromTime(0)->subMinute(2)->minute); + } + + public function testSubSecondPassingArg() + { + $this->assertSame(58, Carbon::createFromTime(0)->subSecond(2)->second); + } +} diff --git a/vendor/nesbot/carbon/tests/TestFixture.php b/vendor/nesbot/carbon/tests/TestFixture.php new file mode 100755 index 0000000..1196830 --- /dev/null +++ b/vendor/nesbot/carbon/tests/TestFixture.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require __DIR__.'/../vendor/autoload.php'; + +use Carbon\Carbon; +use Carbon\CarbonInterval; + +class TestFixture extends \PHPUnit_Framework_TestCase +{ + private $saveTz; + + protected function setUp() + { + //save current timezone + $this->saveTz = date_default_timezone_get(); + + date_default_timezone_set('America/Toronto'); + } + + protected function tearDown() + { + date_default_timezone_set($this->saveTz); + } + + protected function assertCarbon(Carbon $d, $year, $month, $day, $hour = null, $minute = null, $second = null) + { + $this->assertSame($year, $d->year, 'Carbon->year'); + $this->assertSame($month, $d->month, 'Carbon->month'); + $this->assertSame($day, $d->day, 'Carbon->day'); + + if ($hour !== null) { + $this->assertSame($hour, $d->hour, 'Carbon->hour'); + } + + if ($minute !== null) { + $this->assertSame($minute, $d->minute, 'Carbon->minute'); + } + + if ($second !== null) { + $this->assertSame($second, $d->second, 'Carbon->second'); + } + } + + protected function assertInstanceOfCarbon($d) + { + $this->assertInstanceOf('Carbon\Carbon', $d); + } + + protected function assertCarbonInterval(CarbonInterval $ci, $years, $months = null, $days = null, $hours = null, $minutes = null, $seconds = null) + { + $this->assertSame($years, $ci->years, 'CarbonInterval->years'); + + if ($months !== null) { + $this->assertSame($months, $ci->months, 'CarbonInterval->months'); + } + + if ($days !== null) { + $this->assertSame($days, $ci->dayz, 'CarbonInterval->dayz'); + } + + if ($hours !== null) { + $this->assertSame($hours, $ci->hours, 'CarbonInterval->hours'); + } + + if ($minutes !== null) { + $this->assertSame($minutes, $ci->minutes, 'CarbonInterval->minutes'); + } + + if ($seconds !== null) { + $this->assertSame($seconds, $ci->seconds, 'CarbonInterval->seconds'); + } + } + + protected function assertInstanceOfCarbonInterval($d) + { + $this->assertInstanceOf('Carbon\CarbonInterval', $d); + } +} diff --git a/vendor/nesbot/carbon/tests/TestingAidsTest.php b/vendor/nesbot/carbon/tests/TestingAidsTest.php new file mode 100755 index 0000000..458cdff --- /dev/null +++ b/vendor/nesbot/carbon/tests/TestingAidsTest.php @@ -0,0 +1,124 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Carbon\Carbon; + +class TestingAidsTest extends TestFixture +{ + public function testTestingAidsWithTestNowNotSet() + { + Carbon::setTestNow(); + + $this->assertFalse(Carbon::hasTestNow()); + $this->assertNull(Carbon::getTestNow()); + } + + public function testTestingAidsWithTestNowSet() + { + $notNow = Carbon::yesterday(); + Carbon::setTestNow($notNow); + + $this->assertTrue(Carbon::hasTestNow()); + $this->assertSame($notNow, Carbon::getTestNow()); + } + + public function testConstructorWithTestValueSet() + { + $notNow = Carbon::yesterday(); + Carbon::setTestNow($notNow); + + $this->assertEquals($notNow, new Carbon()); + $this->assertEquals($notNow, new Carbon(null)); + $this->assertEquals($notNow, new Carbon('')); + $this->assertEquals($notNow, new Carbon('now')); + } + + public function testNowWithTestValueSet() + { + $notNow = Carbon::yesterday(); + Carbon::setTestNow($notNow); + + $this->assertEquals($notNow, Carbon::now()); + } + + public function testParseWithTestValueSet() + { + $notNow = Carbon::yesterday(); + Carbon::setTestNow($notNow); + + $this->assertEquals($notNow, Carbon::parse()); + $this->assertEquals($notNow, Carbon::parse(null)); + $this->assertEquals($notNow, Carbon::parse('')); + $this->assertEquals($notNow, Carbon::parse('now')); + } + + public function testParseRelativeWithTestValueSet() + { + $notNow = Carbon::parse('2013-09-01 05:15:05'); + Carbon::setTestNow($notNow); + + $this->assertSame('2013-09-01 05:10:05', Carbon::parse('5 minutes ago')->toDateTimeString()); + + $this->assertSame('2013-08-25 05:15:05', Carbon::parse('1 week ago')->toDateTimeString()); + + $this->assertSame('2013-09-02 00:00:00', Carbon::parse('tomorrow')->toDateTimeString()); + $this->assertSame('2013-08-31 00:00:00', Carbon::parse('yesterday')->toDateTimeString()); + + $this->assertSame('2013-09-02 05:15:05', Carbon::parse('+1 day')->toDateTimeString()); + $this->assertSame('2013-08-31 05:15:05', Carbon::parse('-1 day')->toDateTimeString()); + + $this->assertSame('2013-09-02 00:00:00', Carbon::parse('next monday')->toDateTimeString()); + $this->assertSame('2013-09-03 00:00:00', Carbon::parse('next tuesday')->toDateTimeString()); + $this->assertSame('2013-09-04 00:00:00', Carbon::parse('next wednesday')->toDateTimeString()); + $this->assertSame('2013-09-05 00:00:00', Carbon::parse('next thursday')->toDateTimeString()); + $this->assertSame('2013-09-06 00:00:00', Carbon::parse('next friday')->toDateTimeString()); + $this->assertSame('2013-09-07 00:00:00', Carbon::parse('next saturday')->toDateTimeString()); + $this->assertSame('2013-09-08 00:00:00', Carbon::parse('next sunday')->toDateTimeString()); + + $this->assertSame('2013-08-26 00:00:00', Carbon::parse('last monday')->toDateTimeString()); + $this->assertSame('2013-08-27 00:00:00', Carbon::parse('last tuesday')->toDateTimeString()); + $this->assertSame('2013-08-28 00:00:00', Carbon::parse('last wednesday')->toDateTimeString()); + $this->assertSame('2013-08-29 00:00:00', Carbon::parse('last thursday')->toDateTimeString()); + $this->assertSame('2013-08-30 00:00:00', Carbon::parse('last friday')->toDateTimeString()); + $this->assertSame('2013-08-31 00:00:00', Carbon::parse('last saturday')->toDateTimeString()); + $this->assertSame('2013-08-25 00:00:00', Carbon::parse('last sunday')->toDateTimeString()); + + $this->assertSame('2013-09-02 00:00:00', Carbon::parse('this monday')->toDateTimeString()); + $this->assertSame('2013-09-03 00:00:00', Carbon::parse('this tuesday')->toDateTimeString()); + $this->assertSame('2013-09-04 00:00:00', Carbon::parse('this wednesday')->toDateTimeString()); + $this->assertSame('2013-09-05 00:00:00', Carbon::parse('this thursday')->toDateTimeString()); + $this->assertSame('2013-09-06 00:00:00', Carbon::parse('this friday')->toDateTimeString()); + $this->assertSame('2013-09-07 00:00:00', Carbon::parse('this saturday')->toDateTimeString()); + $this->assertSame('2013-09-01 00:00:00', Carbon::parse('this sunday')->toDateTimeString()); + + $this->assertSame('2013-10-01 05:15:05', Carbon::parse('first day of next month')->toDateTimeString()); + $this->assertSame('2013-09-30 05:15:05', Carbon::parse('last day of this month')->toDateTimeString()); + } + + public function testParseRelativeWithMinusSignsInDate() + { + $notNow = Carbon::parse('2013-09-01 05:15:05'); + Carbon::setTestNow($notNow); + + $this->assertSame('2000-01-03 00:00:00', Carbon::parse('2000-1-3')->toDateTimeString()); + $this->assertSame('2000-10-10 00:00:00', Carbon::parse('2000-10-10')->toDateTimeString()); + } + + public function testTimeZoneWithTestValueSet() + { + $notNow = Carbon::parse('2013-07-01 12:00:00', 'America/New_York'); + Carbon::setTestNow($notNow); + + $this->assertSame('2013-07-01T12:00:00-0400', Carbon::parse('now')->toIso8601String()); + $this->assertSame('2013-07-01T11:00:00-0500', Carbon::parse('now', 'America/Mexico_City')->toIso8601String()); + $this->assertSame('2013-07-01T09:00:00-0700', Carbon::parse('now', 'America/Vancouver')->toIso8601String()); + } +} diff --git a/vendor/slim/slim/CONTRIBUTING.md b/vendor/slim/slim/CONTRIBUTING.md new file mode 100755 index 0000000..9bbb6b1 --- /dev/null +++ b/vendor/slim/slim/CONTRIBUTING.md @@ -0,0 +1,20 @@ +# How to Contribute + +## Pull Requests + +1. Fork the Slim Framework repository +2. Create a new branch for each feature or improvement +3. Send a pull request from each feature branch to the **develop** branch + +It is very important to separate new features or improvements into separate feature branches, and to send a +pull request for each branch. This allows me to review and pull in new features or improvements individually. + +## Style Guide + +All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). + +## Unit Testing + +All pull requests must be accompanied by passing unit tests and complete code coverage. The Slim Framework uses phpunit for testing. + +[Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/) diff --git a/vendor/slim/slim/LICENSE b/vendor/slim/slim/LICENSE new file mode 100755 index 0000000..ec361cb --- /dev/null +++ b/vendor/slim/slim/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012 Josh Lockhart + +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/vendor/slim/slim/README.markdown b/vendor/slim/slim/README.markdown new file mode 100755 index 0000000..2bbe264 --- /dev/null +++ b/vendor/slim/slim/README.markdown @@ -0,0 +1,208 @@ +# Slim Framework + +[![Build Status](https://travis-ci.org/slimphp/Slim.svg?branch=master)](https://travis-ci.org/slimphp/Slim) + +Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs. +Slim is easy to use for both beginners and professionals. Slim favors cleanliness over terseness and common cases +over edge cases. Its interface is simple, intuitive, and extensively documented — both online and in the code itself. +Thank you for choosing the Slim Framework for your next project. I think you're going to love it. + +## Features + +* Powerful router + * Standard and custom HTTP methods + * Route parameters with wildcards and conditions + * Route redirect, halt, and pass + * Route middleware +* Resource Locator and DI container +* Template rendering with custom views +* Flash messages +* Encrypt cookie data +* HTTP caching +* Logging with custom log writers +* Error handling and debugging +* Middleware and hook architecture +* Simple configuration + +## Getting Started + +### Install + +You may install the Slim Framework with Composer (recommended) or manually. + +[Read how to install Slim](http://docs.slimframework.com/#Installation) + +### System Requirements + +You need **PHP >= 5.3.0**. If you use encrypted cookies, you'll also need the `mcrypt` extension. + +### Hello World Tutorial + +Instantiate a Slim application: + + $app = new \Slim\Slim(); + +Define a HTTP GET route: + + $app->get('/hello/:name', function ($name) { + echo "Hello, $name"; + }); + +Run the Slim application: + + $app->run(); + +### Setup your web server + +#### Apache + +Ensure the `.htaccess` and `index.php` files are in the same public-accessible directory. The `.htaccess` file +should contain this code: + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [QSA,L] + +Additionally, make sure your virtual host is configured with the AllowOverride option so that the .htaccess rewrite rules can be used: + + AllowOverride All + +#### Nginx + +The nginx configuration file should contain this code (along with other settings you may need) in your `location` block: + + try_files $uri $uri/ /index.php?$args; + +This assumes that Slim's `index.php` is in the root folder of your project (www root). + +#### HipHop Virtual Machine for PHP + +Your HipHop Virtual Machine configuration file should contain this code (along with other settings you may need). +Be sure you change the `ServerRoot` setting to point to your Slim app's document root directory. + + Server { + SourceRoot = /path/to/public/directory + } + + ServerVariables { + SCRIPT_NAME = /index.php + } + + VirtualHost { + * { + Pattern = .* + RewriteRules { + * { + pattern = ^(.*)$ + to = index.php/$1 + qsa = true + } + } + } + } + +#### lighttpd #### + +Your lighttpd configuration file should contain this code (along with other settings you may need). This code requires +lighttpd >= 1.4.24. + + url.rewrite-if-not-file = ("(.*)" => "/index.php/$0") + +This assumes that Slim's `index.php` is in the root folder of your project (www root). + +#### IIS + +Ensure the `Web.config` and `index.php` files are in the same public-accessible directory. The `Web.config` file should contain this code: + + + + + + + + + + + + + + + + + + + +#### Google App Engine + +Two steps are required to successfully run your Slim application on Google App Engine. First, ensure the `app.yaml` file includes a default handler to `index.php`: + + application: your-app-name + version: 1 + runtime: php + api_version: 1 + + handlers: + # ... + - url: /.* + script: public_html/index.php + +Next, edit your `index.php` file so Slim knows about the incoming URI: + + $app = new Slim(); + + // Google App Engine doesn't set $_SERVER['PATH_INFO'] + $app->environment['PATH_INFO'] = $_SERVER['REQUEST_URI']; + + // ... + $app->run(); + + +## Documentation + + + +## How to Contribute + +### Pull Requests + +1. Fork the Slim Framework repository +2. Create a new branch for each feature or improvement +3. Send a pull request from each feature branch to the **develop** branch + +It is very important to separate new features or improvements into separate feature branches, and to send a pull +request for each branch. This allows me to review and pull in new features or improvements individually. + +### Style Guide + +All pull requests must adhere to the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) standard. + +### Unit Testing + +All pull requests must be accompanied by passing unit tests and complete code coverage. The Slim Framework uses +`phpunit` for testing. + +[Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/) + +## Community + +### Forum and Knowledgebase + +Visit Slim's official forum and knowledge base at where you can find announcements, +chat with fellow Slim users, ask questions, help others, or show off your cool Slim Framework apps. + +### Twitter + +Follow [@slimphp](http://www.twitter.com/slimphp) on Twitter to receive news and updates about the framework. + +## Author + +The Slim Framework is created and maintained by [Josh Lockhart](http://www.joshlockhart.com). Josh is a senior +web developer at [New Media Campaigns](http://www.newmediacampaigns.com/). Josh also created and maintains +[PHP: The Right Way](http://www.phptherightway.com/), a popular movement in the PHP community to introduce new +PHP programmers to best practices and good information. + +## License + +The Slim Framework is released under the MIT public license. + + diff --git a/vendor/slim/slim/Slim/Environment.php b/vendor/slim/slim/Slim/Environment.php new file mode 100755 index 0000000..3459783 --- /dev/null +++ b/vendor/slim/slim/Slim/Environment.php @@ -0,0 +1,228 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * Environment + * + * This class creates and returns a key/value array of common + * environment variables for the current HTTP request. + * + * This is a singleton class; derived environment variables will + * be common across multiple Slim applications. + * + * This class matches the Rack (Ruby) specification as closely + * as possible. More information available below. + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class Environment implements \ArrayAccess, \IteratorAggregate +{ + /** + * @var array + */ + protected $properties; + + /** + * @var \Slim\Environment + */ + protected static $environment; + + /** + * Get environment instance (singleton) + * + * This creates and/or returns an environment instance (singleton) + * derived from $_SERVER variables. You may override the global server + * variables by using `\Slim\Environment::mock()` instead. + * + * @param bool $refresh Refresh properties using global server variables? + * @return \Slim\Environment + */ + public static function getInstance($refresh = false) + { + if (is_null(self::$environment) || $refresh) { + self::$environment = new self(); + } + + return self::$environment; + } + + /** + * Get mock environment instance + * + * @param array $userSettings + * @return \Slim\Environment + */ + public static function mock($userSettings = array()) + { + $defaults = array( + 'REQUEST_METHOD' => 'GET', + 'SCRIPT_NAME' => '', + 'PATH_INFO' => '', + 'QUERY_STRING' => '', + 'SERVER_NAME' => 'localhost', + 'SERVER_PORT' => 80, + 'ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'ACCEPT_LANGUAGE' => 'en-US,en;q=0.8', + 'ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', + 'USER_AGENT' => 'Slim Framework', + 'REMOTE_ADDR' => '127.0.0.1', + 'slim.url_scheme' => 'http', + 'slim.input' => '', + 'slim.errors' => @fopen('php://stderr', 'w') + ); + self::$environment = new self(array_merge($defaults, $userSettings)); + + return self::$environment; + } + + /** + * Constructor (private access) + * + * @param array|null $settings If present, these are used instead of global server variables + */ + private function __construct($settings = null) + { + if ($settings) { + $this->properties = $settings; + } else { + $env = array(); + + //The HTTP request method + $env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD']; + + //The IP + $env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; + + // Server params + $scriptName = $_SERVER['SCRIPT_NAME']; // <-- "/foo/index.php" + $requestUri = $_SERVER['REQUEST_URI']; // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc" + $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; // <-- "test=abc" or "" + + // Physical path + if (strpos($requestUri, $scriptName) !== false) { + $physicalPath = $scriptName; // <-- Without rewriting + } else { + $physicalPath = str_replace('\\', '', dirname($scriptName)); // <-- With rewriting + } + $env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes + + // Virtual path + $env['PATH_INFO'] = $requestUri; + if (substr($requestUri, 0, strlen($physicalPath)) == $physicalPath) { + $env['PATH_INFO'] = substr($requestUri, strlen($physicalPath)); // <-- Remove physical path + } + $env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string + $env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash + + // Query string (without leading "?") + $env['QUERY_STRING'] = $queryString; + + //Name of server host that is running the script + $env['SERVER_NAME'] = $_SERVER['SERVER_NAME']; + + //Number of server port that is running the script + //Fixes: https://github.com/slimphp/Slim/issues/962 + $env['SERVER_PORT'] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80; + + //HTTP request headers (retains HTTP_ prefix to match $_SERVER) + $headers = \Slim\Http\Headers::extract($_SERVER); + foreach ($headers as $key => $value) { + $env[$key] = $value; + } + + //Is the application running under HTTPS or HTTP protocol? + $env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https'; + + //Input stream (readable one time only; not available for multipart/form-data requests) + $rawInput = @file_get_contents('php://input'); + if (!$rawInput) { + $rawInput = ''; + } + $env['slim.input'] = $rawInput; + + //Error stream + $env['slim.errors'] = @fopen('php://stderr', 'w'); + + $this->properties = $env; + } + } + + /** + * Array Access: Offset Exists + */ + public function offsetExists($offset) + { + return isset($this->properties[$offset]); + } + + /** + * Array Access: Offset Get + */ + public function offsetGet($offset) + { + if (isset($this->properties[$offset])) { + return $this->properties[$offset]; + } + + return null; + } + + /** + * Array Access: Offset Set + */ + public function offsetSet($offset, $value) + { + $this->properties[$offset] = $value; + } + + /** + * Array Access: Offset Unset + */ + public function offsetUnset($offset) + { + unset($this->properties[$offset]); + } + + /** + * IteratorAggregate + * + * @return \ArrayIterator + */ + public function getIterator() + { + return new \ArrayIterator($this->properties); + } +} diff --git a/vendor/slim/slim/Slim/Exception/Pass.php b/vendor/slim/slim/Slim/Exception/Pass.php new file mode 100755 index 0000000..30a3a1d --- /dev/null +++ b/vendor/slim/slim/Slim/Exception/Pass.php @@ -0,0 +1,49 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Exception; + +/** + * Pass Exception + * + * This Exception will cause the Router::dispatch method + * to skip the current matching route and continue to the next + * matching route. If no subsequent routes are found, a + * HTTP 404 Not Found response will be sent to the client. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Pass extends \Exception +{ +} diff --git a/vendor/slim/slim/Slim/Exception/Stop.php b/vendor/slim/slim/Slim/Exception/Stop.php new file mode 100755 index 0000000..28aba78 --- /dev/null +++ b/vendor/slim/slim/Slim/Exception/Stop.php @@ -0,0 +1,47 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Exception; + +/** + * Stop Exception + * + * This Exception is thrown when the Slim application needs to abort + * processing and return control flow to the outer PHP script. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Stop extends \Exception +{ +} diff --git a/vendor/slim/slim/Slim/Helper/Set.php b/vendor/slim/slim/Slim/Helper/Set.php new file mode 100755 index 0000000..bf6e895 --- /dev/null +++ b/vendor/slim/slim/Slim/Helper/Set.php @@ -0,0 +1,246 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Helper; + +class Set implements \ArrayAccess, \Countable, \IteratorAggregate +{ + /** + * Key-value array of arbitrary data + * @var array + */ + protected $data = array(); + + /** + * Constructor + * @param array $items Pre-populate set with this key-value array + */ + public function __construct($items = array()) + { + $this->replace($items); + } + + /** + * Normalize data key + * + * Used to transform data key into the necessary + * key format for this set. Used in subclasses + * like \Slim\Http\Headers. + * + * @param string $key The data key + * @return mixed The transformed/normalized data key + */ + protected function normalizeKey($key) + { + return $key; + } + + /** + * Set data key to value + * @param string $key The data key + * @param mixed $value The data value + */ + public function set($key, $value) + { + $this->data[$this->normalizeKey($key)] = $value; + } + + /** + * Get data value with key + * @param string $key The data key + * @param mixed $default The value to return if data key does not exist + * @return mixed The data value, or the default value + */ + public function get($key, $default = null) + { + if ($this->has($key)) { + $isInvokable = is_object($this->data[$this->normalizeKey($key)]) && method_exists($this->data[$this->normalizeKey($key)], '__invoke'); + + return $isInvokable ? $this->data[$this->normalizeKey($key)]($this) : $this->data[$this->normalizeKey($key)]; + } + + return $default; + } + + /** + * Add data to set + * @param array $items Key-value array of data to append to this set + */ + public function replace($items) + { + foreach ($items as $key => $value) { + $this->set($key, $value); // Ensure keys are normalized + } + } + + /** + * Fetch set data + * @return array This set's key-value data array + */ + public function all() + { + return $this->data; + } + + /** + * Fetch set data keys + * @return array This set's key-value data array keys + */ + public function keys() + { + return array_keys($this->data); + } + + /** + * Does this set contain a key? + * @param string $key The data key + * @return boolean + */ + public function has($key) + { + return array_key_exists($this->normalizeKey($key), $this->data); + } + + /** + * Remove value with key from this set + * @param string $key The data key + */ + public function remove($key) + { + unset($this->data[$this->normalizeKey($key)]); + } + + /** + * Property Overloading + */ + + public function __get($key) + { + return $this->get($key); + } + + public function __set($key, $value) + { + $this->set($key, $value); + } + + public function __isset($key) + { + return $this->has($key); + } + + public function __unset($key) + { + $this->remove($key); + } + + /** + * Clear all values + */ + public function clear() + { + $this->data = array(); + } + + /** + * Array Access + */ + + public function offsetExists($offset) + { + return $this->has($offset); + } + + public function offsetGet($offset) + { + return $this->get($offset); + } + + public function offsetSet($offset, $value) + { + $this->set($offset, $value); + } + + public function offsetUnset($offset) + { + $this->remove($offset); + } + + /** + * Countable + */ + + public function count() + { + return count($this->data); + } + + /** + * IteratorAggregate + */ + + public function getIterator() + { + return new \ArrayIterator($this->data); + } + + /** + * Ensure a value or object will remain globally unique + * @param string $key The value or object name + * @param \Closure $value The closure that defines the object + * @return mixed + */ + public function singleton($key, $value) + { + $this->set($key, function ($c) use ($value) { + static $object; + + if (null === $object) { + $object = $value($c); + } + + return $object; + }); + } + + /** + * Protect closure from being directly invoked + * @param \Closure $callable A closure to keep from being invoked and evaluated + * @return \Closure + */ + public function protect(\Closure $callable) + { + return function () use ($callable) { + return $callable; + }; + } +} diff --git a/vendor/slim/slim/Slim/Http/Cookies.php b/vendor/slim/slim/Slim/Http/Cookies.php new file mode 100755 index 0000000..3b2e11e --- /dev/null +++ b/vendor/slim/slim/Slim/Http/Cookies.php @@ -0,0 +1,91 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Http; + +class Cookies extends \Slim\Helper\Set +{ + /** + * Default cookie settings + * @var array + */ + protected $defaults = array( + 'value' => '', + 'domain' => null, + 'path' => null, + 'expires' => null, + 'secure' => false, + 'httponly' => false + ); + + /** + * Set cookie + * + * The second argument may be a single scalar value, in which case + * it will be merged with the default settings and considered the `value` + * of the merged result. + * + * The second argument may also be an array containing any or all of + * the keys shown in the default settings above. This array will be + * merged with the defaults shown above. + * + * @param string $key Cookie name + * @param mixed $value Cookie settings + */ + public function set($key, $value) + { + if (is_array($value)) { + $cookieSettings = array_replace($this->defaults, $value); + } else { + $cookieSettings = array_replace($this->defaults, array('value' => $value)); + } + parent::set($key, $cookieSettings); + } + + /** + * Remove cookie + * + * Unlike \Slim\Helper\Set, this will actually *set* a cookie with + * an expiration date in the past. This expiration date will force + * the client-side cache to remove its cookie with the given name + * and settings. + * + * @param string $key Cookie name + * @param array $settings Optional cookie settings + */ + public function remove($key, $settings = array()) + { + $settings['value'] = ''; + $settings['expires'] = time() - 86400; + $this->set($key, array_replace($this->defaults, $settings)); + } +} diff --git a/vendor/slim/slim/Slim/Http/Headers.php b/vendor/slim/slim/Slim/Http/Headers.php new file mode 100755 index 0000000..c5e08f2 --- /dev/null +++ b/vendor/slim/slim/Slim/Http/Headers.php @@ -0,0 +1,104 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Http; + + /** + * HTTP Headers + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class Headers extends \Slim\Helper\Set +{ + /******************************************************************************** + * Static interface + *******************************************************************************/ + + /** + * Special-case HTTP headers that are otherwise unidentifiable as HTTP headers. + * Typically, HTTP headers in the $_SERVER array will be prefixed with + * `HTTP_` or `X_`. These are not so we list them here for later reference. + * + * @var array + */ + protected static $special = array( + 'CONTENT_TYPE', + 'CONTENT_LENGTH', + 'PHP_AUTH_USER', + 'PHP_AUTH_PW', + 'PHP_AUTH_DIGEST', + 'AUTH_TYPE' + ); + + /** + * Extract HTTP headers from an array of data (e.g. $_SERVER) + * @param array $data + * @return array + */ + public static function extract($data) + { + $results = array(); + foreach ($data as $key => $value) { + $key = strtoupper($key); + if (strpos($key, 'X_') === 0 || strpos($key, 'HTTP_') === 0 || in_array($key, static::$special)) { + if ($key === 'HTTP_CONTENT_LENGTH') { + continue; + } + $results[$key] = $value; + } + } + + return $results; + } + + /******************************************************************************** + * Instance interface + *******************************************************************************/ + + /** + * Transform header name into canonical form + * @param string $key + * @return string + */ + protected function normalizeKey($key) + { + $key = strtolower($key); + $key = str_replace(array('-', '_'), ' ', $key); + $key = preg_replace('#^http #', '', $key); + $key = ucwords($key); + $key = str_replace(' ', '-', $key); + + return $key; + } +} diff --git a/vendor/slim/slim/Slim/Http/Request.php b/vendor/slim/slim/Slim/Http/Request.php new file mode 100755 index 0000000..2cd88b4 --- /dev/null +++ b/vendor/slim/slim/Slim/Http/Request.php @@ -0,0 +1,617 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Http; + +/** + * Slim HTTP Request + * + * This class provides a human-friendly interface to the Slim environment variables; + * environment variables are passed by reference and will be modified directly. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Request +{ + const METHOD_HEAD = 'HEAD'; + const METHOD_GET = 'GET'; + const METHOD_POST = 'POST'; + const METHOD_PUT = 'PUT'; + const METHOD_PATCH = 'PATCH'; + const METHOD_DELETE = 'DELETE'; + const METHOD_OPTIONS = 'OPTIONS'; + const METHOD_OVERRIDE = '_METHOD'; + + /** + * @var array + */ + protected static $formDataMediaTypes = array('application/x-www-form-urlencoded'); + + /** + * Application Environment + * @var \Slim\Environment + */ + protected $env; + + /** + * HTTP Headers + * @var \Slim\Http\Headers + */ + public $headers; + + /** + * HTTP Cookies + * @var \Slim\Helper\Set + */ + public $cookies; + + /** + * Constructor + * @param \Slim\Environment $env + */ + public function __construct(\Slim\Environment $env) + { + $this->env = $env; + $this->headers = new \Slim\Http\Headers(\Slim\Http\Headers::extract($env)); + $this->cookies = new \Slim\Helper\Set(\Slim\Http\Util::parseCookieHeader($env['HTTP_COOKIE'])); + } + + /** + * Get HTTP method + * @return string + */ + public function getMethod() + { + return $this->env['REQUEST_METHOD']; + } + + /** + * Is this a GET request? + * @return bool + */ + public function isGet() + { + return $this->getMethod() === self::METHOD_GET; + } + + /** + * Is this a POST request? + * @return bool + */ + public function isPost() + { + return $this->getMethod() === self::METHOD_POST; + } + + /** + * Is this a PUT request? + * @return bool + */ + public function isPut() + { + return $this->getMethod() === self::METHOD_PUT; + } + + /** + * Is this a PATCH request? + * @return bool + */ + public function isPatch() + { + return $this->getMethod() === self::METHOD_PATCH; + } + + /** + * Is this a DELETE request? + * @return bool + */ + public function isDelete() + { + return $this->getMethod() === self::METHOD_DELETE; + } + + /** + * Is this a HEAD request? + * @return bool + */ + public function isHead() + { + return $this->getMethod() === self::METHOD_HEAD; + } + + /** + * Is this a OPTIONS request? + * @return bool + */ + public function isOptions() + { + return $this->getMethod() === self::METHOD_OPTIONS; + } + + /** + * Is this an AJAX request? + * @return bool + */ + public function isAjax() + { + if ($this->params('isajax')) { + return true; + } elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') { + return true; + } + + return false; + } + + /** + * Is this an XHR request? (alias of Slim_Http_Request::isAjax) + * @return bool + */ + public function isXhr() + { + return $this->isAjax(); + } + + /** + * Fetch GET and POST data + * + * This method returns a union of GET and POST data as a key-value array, or the value + * of the array key if requested; if the array key does not exist, NULL is returned, + * unless there is a default value specified. + * + * @param string $key + * @param mixed $default + * @return array|mixed|null + */ + public function params($key = null, $default = null) + { + $union = array_merge($this->get(), $this->post()); + if ($key) { + return isset($union[$key]) ? $union[$key] : $default; + } + + return $union; + } + + /** + * Fetch GET data + * + * This method returns a key-value array of data sent in the HTTP request query string, or + * the value of the array key if requested; if the array key does not exist, NULL is returned. + * + * @param string $key + * @param mixed $default Default return value when key does not exist + * @return array|mixed|null + */ + public function get($key = null, $default = null) + { + if (!isset($this->env['slim.request.query_hash'])) { + $output = array(); + if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) { + mb_parse_str($this->env['QUERY_STRING'], $output); + } else { + parse_str($this->env['QUERY_STRING'], $output); + } + $this->env['slim.request.query_hash'] = Util::stripSlashesIfMagicQuotes($output); + } + if ($key) { + if (isset($this->env['slim.request.query_hash'][$key])) { + return $this->env['slim.request.query_hash'][$key]; + } else { + return $default; + } + } else { + return $this->env['slim.request.query_hash']; + } + } + + /** + * Fetch POST data + * + * This method returns a key-value array of data sent in the HTTP request body, or + * the value of a hash key if requested; if the array key does not exist, NULL is returned. + * + * @param string $key + * @param mixed $default Default return value when key does not exist + * @return array|mixed|null + * @throws \RuntimeException If environment input is not available + */ + public function post($key = null, $default = null) + { + if (!isset($this->env['slim.input'])) { + throw new \RuntimeException('Missing slim.input in environment variables'); + } + if (!isset($this->env['slim.request.form_hash'])) { + $this->env['slim.request.form_hash'] = array(); + if ($this->isFormData() && is_string($this->env['slim.input'])) { + $output = array(); + if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) { + mb_parse_str($this->env['slim.input'], $output); + } else { + parse_str($this->env['slim.input'], $output); + } + $this->env['slim.request.form_hash'] = Util::stripSlashesIfMagicQuotes($output); + } else { + $this->env['slim.request.form_hash'] = Util::stripSlashesIfMagicQuotes($_POST); + } + } + if ($key) { + if (isset($this->env['slim.request.form_hash'][$key])) { + return $this->env['slim.request.form_hash'][$key]; + } else { + return $default; + } + } else { + return $this->env['slim.request.form_hash']; + } + } + + /** + * Fetch PUT data (alias for \Slim\Http\Request::post) + * @param string $key + * @param mixed $default Default return value when key does not exist + * @return array|mixed|null + */ + public function put($key = null, $default = null) + { + return $this->post($key, $default); + } + + /** + * Fetch PATCH data (alias for \Slim\Http\Request::post) + * @param string $key + * @param mixed $default Default return value when key does not exist + * @return array|mixed|null + */ + public function patch($key = null, $default = null) + { + return $this->post($key, $default); + } + + /** + * Fetch DELETE data (alias for \Slim\Http\Request::post) + * @param string $key + * @param mixed $default Default return value when key does not exist + * @return array|mixed|null + */ + public function delete($key = null, $default = null) + { + return $this->post($key, $default); + } + + /** + * Fetch COOKIE data + * + * This method returns a key-value array of Cookie data sent in the HTTP request, or + * the value of a array key if requested; if the array key does not exist, NULL is returned. + * + * @param string $key + * @return array|string|null + */ + public function cookies($key = null) + { + if ($key) { + return $this->cookies->get($key); + } + + return $this->cookies; + // if (!isset($this->env['slim.request.cookie_hash'])) { + // $cookieHeader = isset($this->env['COOKIE']) ? $this->env['COOKIE'] : ''; + // $this->env['slim.request.cookie_hash'] = Util::parseCookieHeader($cookieHeader); + // } + // if ($key) { + // if (isset($this->env['slim.request.cookie_hash'][$key])) { + // return $this->env['slim.request.cookie_hash'][$key]; + // } else { + // return null; + // } + // } else { + // return $this->env['slim.request.cookie_hash']; + // } + } + + /** + * Does the Request body contain parsed form data? + * @return bool + */ + public function isFormData() + { + $method = isset($this->env['slim.method_override.original_method']) ? $this->env['slim.method_override.original_method'] : $this->getMethod(); + + return ($method === self::METHOD_POST && is_null($this->getContentType())) || in_array($this->getMediaType(), self::$formDataMediaTypes); + } + + /** + * Get Headers + * + * This method returns a key-value array of headers sent in the HTTP request, or + * the value of a hash key if requested; if the array key does not exist, NULL is returned. + * + * @param string $key + * @param mixed $default The default value returned if the requested header is not available + * @return mixed + */ + public function headers($key = null, $default = null) + { + if ($key) { + return $this->headers->get($key, $default); + } + + return $this->headers; + // if ($key) { + // $key = strtoupper($key); + // $key = str_replace('-', '_', $key); + // $key = preg_replace('@^HTTP_@', '', $key); + // if (isset($this->env[$key])) { + // return $this->env[$key]; + // } else { + // return $default; + // } + // } else { + // $headers = array(); + // foreach ($this->env as $key => $value) { + // if (strpos($key, 'slim.') !== 0) { + // $headers[$key] = $value; + // } + // } + // + // return $headers; + // } + } + + /** + * Get Body + * @return string + */ + public function getBody() + { + return $this->env['slim.input']; + } + + /** + * Get Content Type + * @return string|null + */ + public function getContentType() + { + return $this->headers->get('CONTENT_TYPE'); + } + + /** + * Get Media Type (type/subtype within Content Type header) + * @return string|null + */ + public function getMediaType() + { + $contentType = $this->getContentType(); + if ($contentType) { + $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType); + + return strtolower($contentTypeParts[0]); + } + + return null; + } + + /** + * Get Media Type Params + * @return array + */ + public function getMediaTypeParams() + { + $contentType = $this->getContentType(); + $contentTypeParams = array(); + if ($contentType) { + $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType); + $contentTypePartsLength = count($contentTypeParts); + for ($i = 1; $i < $contentTypePartsLength; $i++) { + $paramParts = explode('=', $contentTypeParts[$i]); + $contentTypeParams[strtolower($paramParts[0])] = $paramParts[1]; + } + } + + return $contentTypeParams; + } + + /** + * Get Content Charset + * @return string|null + */ + public function getContentCharset() + { + $mediaTypeParams = $this->getMediaTypeParams(); + if (isset($mediaTypeParams['charset'])) { + return $mediaTypeParams['charset']; + } + + return null; + } + + /** + * Get Content-Length + * @return int + */ + public function getContentLength() + { + return $this->headers->get('CONTENT_LENGTH', 0); + } + + /** + * Get Host + * @return string + */ + public function getHost() + { + if (isset($this->env['HTTP_HOST'])) { + if (strpos($this->env['HTTP_HOST'], ':') !== false) { + $hostParts = explode(':', $this->env['HTTP_HOST']); + + return $hostParts[0]; + } + + return $this->env['HTTP_HOST']; + } + + return $this->env['SERVER_NAME']; + } + + /** + * Get Host with Port + * @return string + */ + public function getHostWithPort() + { + return sprintf('%s:%s', $this->getHost(), $this->getPort()); + } + + /** + * Get Port + * @return int + */ + public function getPort() + { + return (int)$this->env['SERVER_PORT']; + } + + /** + * Get Scheme (https or http) + * @return string + */ + public function getScheme() + { + return $this->env['slim.url_scheme']; + } + + /** + * Get Script Name (physical path) + * @return string + */ + public function getScriptName() + { + return $this->env['SCRIPT_NAME']; + } + + /** + * LEGACY: Get Root URI (alias for Slim_Http_Request::getScriptName) + * @return string + */ + public function getRootUri() + { + return $this->getScriptName(); + } + + /** + * Get Path (physical path + virtual path) + * @return string + */ + public function getPath() + { + return $this->getScriptName() . $this->getPathInfo(); + } + + /** + * Get Path Info (virtual path) + * @return string + */ + public function getPathInfo() + { + return $this->env['PATH_INFO']; + } + + /** + * LEGACY: Get Resource URI (alias for Slim_Http_Request::getPathInfo) + * @return string + */ + public function getResourceUri() + { + return $this->getPathInfo(); + } + + /** + * Get URL (scheme + host [ + port if non-standard ]) + * @return string + */ + public function getUrl() + { + $url = $this->getScheme() . '://' . $this->getHost(); + if (($this->getScheme() === 'https' && $this->getPort() !== 443) || ($this->getScheme() === 'http' && $this->getPort() !== 80)) { + $url .= sprintf(':%s', $this->getPort()); + } + + return $url; + } + + /** + * Get IP + * @return string + */ + public function getIp() + { + $keys = array('X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR', 'CLIENT_IP', 'REMOTE_ADDR'); + foreach ($keys as $key) { + if (isset($this->env[$key])) { + return $this->env[$key]; + } + } + + return $this->env['REMOTE_ADDR']; + } + + /** + * Get Referrer + * @return string|null + */ + public function getReferrer() + { + return $this->headers->get('HTTP_REFERER'); + } + + /** + * Get Referer (for those who can't spell) + * @return string|null + */ + public function getReferer() + { + return $this->getReferrer(); + } + + /** + * Get User Agent + * @return string|null + */ + public function getUserAgent() + { + return $this->headers->get('HTTP_USER_AGENT'); + } +} diff --git a/vendor/slim/slim/Slim/Http/Response.php b/vendor/slim/slim/Slim/Http/Response.php new file mode 100755 index 0000000..48c76d8 --- /dev/null +++ b/vendor/slim/slim/Slim/Http/Response.php @@ -0,0 +1,520 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Http; + +/** + * Response + * + * This is a simple abstraction over top an HTTP response. This + * provides methods to set the HTTP status, the HTTP headers, + * and the HTTP body. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Response implements \ArrayAccess, \Countable, \IteratorAggregate +{ + /** + * @var int HTTP status code + */ + protected $status; + + /** + * @var \Slim\Http\Headers + */ + public $headers; + + /** + * @var \Slim\Http\Cookies + */ + public $cookies; + + /** + * @var string HTTP response body + */ + protected $body; + + /** + * @var int Length of HTTP response body + */ + protected $length; + + /** + * @var array HTTP response codes and messages + */ + protected static $messages = array( + //Informational 1xx + 100 => '100 Continue', + 101 => '101 Switching Protocols', + //Successful 2xx + 200 => '200 OK', + 201 => '201 Created', + 202 => '202 Accepted', + 203 => '203 Non-Authoritative Information', + 204 => '204 No Content', + 205 => '205 Reset Content', + 206 => '206 Partial Content', + 226 => '226 IM Used', + //Redirection 3xx + 300 => '300 Multiple Choices', + 301 => '301 Moved Permanently', + 302 => '302 Found', + 303 => '303 See Other', + 304 => '304 Not Modified', + 305 => '305 Use Proxy', + 306 => '306 (Unused)', + 307 => '307 Temporary Redirect', + //Client Error 4xx + 400 => '400 Bad Request', + 401 => '401 Unauthorized', + 402 => '402 Payment Required', + 403 => '403 Forbidden', + 404 => '404 Not Found', + 405 => '405 Method Not Allowed', + 406 => '406 Not Acceptable', + 407 => '407 Proxy Authentication Required', + 408 => '408 Request Timeout', + 409 => '409 Conflict', + 410 => '410 Gone', + 411 => '411 Length Required', + 412 => '412 Precondition Failed', + 413 => '413 Request Entity Too Large', + 414 => '414 Request-URI Too Long', + 415 => '415 Unsupported Media Type', + 416 => '416 Requested Range Not Satisfiable', + 417 => '417 Expectation Failed', + 418 => '418 I\'m a teapot', + 422 => '422 Unprocessable Entity', + 423 => '423 Locked', + 426 => '426 Upgrade Required', + 428 => '428 Precondition Required', + 429 => '429 Too Many Requests', + 431 => '431 Request Header Fields Too Large', + //Server Error 5xx + 500 => '500 Internal Server Error', + 501 => '501 Not Implemented', + 502 => '502 Bad Gateway', + 503 => '503 Service Unavailable', + 504 => '504 Gateway Timeout', + 505 => '505 HTTP Version Not Supported', + 506 => '506 Variant Also Negotiates', + 510 => '510 Not Extended', + 511 => '511 Network Authentication Required' + ); + + /** + * Constructor + * @param string $body The HTTP response body + * @param int $status The HTTP response status + * @param \Slim\Http\Headers|array $headers The HTTP response headers + */ + public function __construct($body = '', $status = 200, $headers = array()) + { + $this->setStatus($status); + $this->headers = new \Slim\Http\Headers(array('Content-Type' => 'text/html')); + $this->headers->replace($headers); + $this->cookies = new \Slim\Http\Cookies(); + $this->write($body); + } + + public function getStatus() + { + return $this->status; + } + + public function setStatus($status) + { + $this->status = (int)$status; + } + + /** + * DEPRECATION WARNING! Use `getStatus` or `setStatus` instead. + * + * Get and set status + * @param int|null $status + * @return int + */ + public function status($status = null) + { + if (!is_null($status)) { + $this->status = (int) $status; + } + + return $this->status; + } + + /** + * DEPRECATION WARNING! Access `headers` property directly. + * + * Get and set header + * @param string $name Header name + * @param string|null $value Header value + * @return string Header value + */ + public function header($name, $value = null) + { + if (!is_null($value)) { + $this->headers->set($name, $value); + } + + return $this->headers->get($name); + } + + /** + * DEPRECATION WARNING! Access `headers` property directly. + * + * Get headers + * @return \Slim\Http\Headers + */ + public function headers() + { + return $this->headers; + } + + public function getBody() + { + return $this->body; + } + + public function setBody($content) + { + $this->write($content, true); + } + + /** + * DEPRECATION WARNING! use `getBody` or `setBody` instead. + * + * Get and set body + * @param string|null $body Content of HTTP response body + * @return string + */ + public function body($body = null) + { + if (!is_null($body)) { + $this->write($body, true); + } + + return $this->body; + } + + /** + * Append HTTP response body + * @param string $body Content to append to the current HTTP response body + * @param bool $replace Overwrite existing response body? + * @return string The updated HTTP response body + */ + public function write($body, $replace = false) + { + if ($replace) { + $this->body = $body; + } else { + $this->body .= (string)$body; + } + $this->length = strlen($this->body); + + return $this->body; + } + + public function getLength() + { + return $this->length; + } + + /** + * DEPRECATION WARNING! Use `getLength` or `write` or `body` instead. + * + * Get and set length + * @param int|null $length + * @return int + */ + public function length($length = null) + { + if (!is_null($length)) { + $this->length = (int) $length; + } + + return $this->length; + } + + /** + * Finalize + * + * This prepares this response and returns an array + * of [status, headers, body]. This array is passed to outer middleware + * if available or directly to the Slim run method. + * + * @return array[int status, array headers, string body] + */ + public function finalize() + { + // Prepare response + if (in_array($this->status, array(204, 304))) { + $this->headers->remove('Content-Type'); + $this->headers->remove('Content-Length'); + $this->setBody(''); + } + + return array($this->status, $this->headers, $this->body); + } + + /** + * DEPRECATION WARNING! Access `cookies` property directly. + * + * Set cookie + * + * Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie` + * header on its own and delegates this responsibility to the `Slim_Http_Util` class. This + * response's header is passed by reference to the utility class and is directly modified. By not + * relying on PHP's native implementation, Slim allows middleware the opportunity to massage or + * analyze the raw header before the response is ultimately delivered to the HTTP client. + * + * @param string $name The name of the cookie + * @param string|array $value If string, the value of cookie; if array, properties for + * cookie including: value, expire, path, domain, secure, httponly + */ + public function setCookie($name, $value) + { + // Util::setCookieHeader($this->header, $name, $value); + $this->cookies->set($name, $value); + } + + /** + * DEPRECATION WARNING! Access `cookies` property directly. + * + * Delete cookie + * + * Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie` + * header on its own and delegates this responsibility to the `Slim_Http_Util` class. This + * response's header is passed by reference to the utility class and is directly modified. By not + * relying on PHP's native implementation, Slim allows middleware the opportunity to massage or + * analyze the raw header before the response is ultimately delivered to the HTTP client. + * + * This method will set a cookie with the given name that has an expiration time in the past; this will + * prompt the HTTP client to invalidate and remove the client-side cookie. Optionally, you may + * also pass a key/value array as the second argument. If the "domain" key is present in this + * array, only the Cookie with the given name AND domain will be removed. The invalidating cookie + * sent with this response will adopt all properties of the second argument. + * + * @param string $name The name of the cookie + * @param array $settings Properties for cookie including: value, expire, path, domain, secure, httponly + */ + public function deleteCookie($name, $settings = array()) + { + $this->cookies->remove($name, $settings); + // Util::deleteCookieHeader($this->header, $name, $value); + } + + /** + * Redirect + * + * This method prepares this response to return an HTTP Redirect response + * to the HTTP client. + * + * @param string $url The redirect destination + * @param int $status The redirect HTTP status code + */ + public function redirect ($url, $status = 302) + { + $this->setStatus($status); + $this->headers->set('Location', $url); + } + + /** + * Helpers: Empty? + * @return bool + */ + public function isEmpty() + { + return in_array($this->status, array(201, 204, 304)); + } + + /** + * Helpers: Informational? + * @return bool + */ + public function isInformational() + { + return $this->status >= 100 && $this->status < 200; + } + + /** + * Helpers: OK? + * @return bool + */ + public function isOk() + { + return $this->status === 200; + } + + /** + * Helpers: Successful? + * @return bool + */ + public function isSuccessful() + { + return $this->status >= 200 && $this->status < 300; + } + + /** + * Helpers: Redirect? + * @return bool + */ + public function isRedirect() + { + return in_array($this->status, array(301, 302, 303, 307)); + } + + /** + * Helpers: Redirection? + * @return bool + */ + public function isRedirection() + { + return $this->status >= 300 && $this->status < 400; + } + + /** + * Helpers: Forbidden? + * @return bool + */ + public function isForbidden() + { + return $this->status === 403; + } + + /** + * Helpers: Not Found? + * @return bool + */ + public function isNotFound() + { + return $this->status === 404; + } + + /** + * Helpers: Client error? + * @return bool + */ + public function isClientError() + { + return $this->status >= 400 && $this->status < 500; + } + + /** + * Helpers: Server Error? + * @return bool + */ + public function isServerError() + { + return $this->status >= 500 && $this->status < 600; + } + + /** + * DEPRECATION WARNING! ArrayAccess interface will be removed from \Slim\Http\Response. + * Iterate `headers` or `cookies` properties directly. + */ + + /** + * Array Access: Offset Exists + */ + public function offsetExists($offset) + { + return isset($this->headers[$offset]); + } + + /** + * Array Access: Offset Get + */ + public function offsetGet($offset) + { + return $this->headers[$offset]; + } + + /** + * Array Access: Offset Set + */ + public function offsetSet($offset, $value) + { + $this->headers[$offset] = $value; + } + + /** + * Array Access: Offset Unset + */ + public function offsetUnset($offset) + { + unset($this->headers[$offset]); + } + + /** + * DEPRECATION WARNING! Countable interface will be removed from \Slim\Http\Response. + * Call `count` on `headers` or `cookies` properties directly. + * + * Countable: Count + */ + public function count() + { + return count($this->headers); + } + + /** + * DEPRECATION WARNING! IteratorAggregate interface will be removed from \Slim\Http\Response. + * Iterate `headers` or `cookies` properties directly. + * + * Get Iterator + * + * This returns the contained `\Slim\Http\Headers` instance which + * is itself iterable. + * + * @return \Slim\Http\Headers + */ + public function getIterator() + { + return $this->headers->getIterator(); + } + + /** + * Get message for HTTP status code + * @param int $status + * @return string|null + */ + public static function getMessageForCode($status) + { + if (isset(self::$messages[$status])) { + return self::$messages[$status]; + } else { + return null; + } + } +} diff --git a/vendor/slim/slim/Slim/Http/Util.php b/vendor/slim/slim/Slim/Http/Util.php new file mode 100755 index 0000000..00cac0e --- /dev/null +++ b/vendor/slim/slim/Slim/Http/Util.php @@ -0,0 +1,434 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Http; + +/** + * Slim HTTP Utilities + * + * This class provides useful methods for handling HTTP requests. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Util +{ + /** + * Strip slashes from string or array + * + * This method strips slashes from its input. By default, this method will only + * strip slashes from its input if magic quotes are enabled. Otherwise, you may + * override the magic quotes setting with either TRUE or FALSE as the send argument + * to force this method to strip or not strip slashes from its input. + * + * @param array|string $rawData + * @param bool $overrideStripSlashes + * @return array|string + */ + public static function stripSlashesIfMagicQuotes($rawData, $overrideStripSlashes = null) + { + $strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes; + if ($strip) { + return self::stripSlashes($rawData); + } + + return $rawData; + } + + /** + * Strip slashes from string or array + * @param array|string $rawData + * @return array|string + */ + protected static function stripSlashes($rawData) + { + return is_array($rawData) ? array_map(array('self', 'stripSlashes'), $rawData) : stripslashes($rawData); + } + + /** + * Encrypt data + * + * This method will encrypt data using a given key, vector, and cipher. + * By default, this will encrypt data using the RIJNDAEL/AES 256 bit cipher. You + * may override the default cipher and cipher mode by passing your own desired + * cipher and cipher mode as the final key-value array argument. + * + * @param string $data The unencrypted data + * @param string $key The encryption key + * @param string $iv The encryption initialization vector + * @param array $settings Optional key-value array with custom algorithm and mode + * @return string + */ + public static function encrypt($data, $key, $iv, $settings = array()) + { + if ($data === '' || !extension_loaded('mcrypt')) { + return $data; + } + + //Merge settings with defaults + $defaults = array( + 'algorithm' => MCRYPT_RIJNDAEL_256, + 'mode' => MCRYPT_MODE_CBC + ); + $settings = array_merge($defaults, $settings); + + //Get module + $module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], ''); + + //Validate IV + $ivSize = mcrypt_enc_get_iv_size($module); + if (strlen($iv) > $ivSize) { + $iv = substr($iv, 0, $ivSize); + } + + //Validate key + $keySize = mcrypt_enc_get_key_size($module); + if (strlen($key) > $keySize) { + $key = substr($key, 0, $keySize); + } + + //Encrypt value + mcrypt_generic_init($module, $key, $iv); + $res = @mcrypt_generic($module, $data); + mcrypt_generic_deinit($module); + + return $res; + } + + /** + * Decrypt data + * + * This method will decrypt data using a given key, vector, and cipher. + * By default, this will decrypt data using the RIJNDAEL/AES 256 bit cipher. You + * may override the default cipher and cipher mode by passing your own desired + * cipher and cipher mode as the final key-value array argument. + * + * @param string $data The encrypted data + * @param string $key The encryption key + * @param string $iv The encryption initialization vector + * @param array $settings Optional key-value array with custom algorithm and mode + * @return string + */ + public static function decrypt($data, $key, $iv, $settings = array()) + { + if ($data === '' || !extension_loaded('mcrypt')) { + return $data; + } + + //Merge settings with defaults + $defaults = array( + 'algorithm' => MCRYPT_RIJNDAEL_256, + 'mode' => MCRYPT_MODE_CBC + ); + $settings = array_merge($defaults, $settings); + + //Get module + $module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], ''); + + //Validate IV + $ivSize = mcrypt_enc_get_iv_size($module); + if (strlen($iv) > $ivSize) { + $iv = substr($iv, 0, $ivSize); + } + + //Validate key + $keySize = mcrypt_enc_get_key_size($module); + if (strlen($key) > $keySize) { + $key = substr($key, 0, $keySize); + } + + //Decrypt value + mcrypt_generic_init($module, $key, $iv); + $decryptedData = @mdecrypt_generic($module, $data); + $res = rtrim($decryptedData, "\0"); + mcrypt_generic_deinit($module); + + return $res; + } + + /** + * Serialize Response cookies into raw HTTP header + * @param \Slim\Http\Headers $headers The Response headers + * @param \Slim\Http\Cookies $cookies The Response cookies + * @param array $config The Slim app settings + */ + public static function serializeCookies(\Slim\Http\Headers &$headers, \Slim\Http\Cookies $cookies, array $config) + { + if ($config['cookies.encrypt']) { + foreach ($cookies as $name => $settings) { + if (is_string($settings['expires'])) { + $expires = strtotime($settings['expires']); + } else { + $expires = (int) $settings['expires']; + } + + $settings['value'] = static::encodeSecureCookie( + $settings['value'], + $expires, + $config['cookies.secret_key'], + $config['cookies.cipher'], + $config['cookies.cipher_mode'] + ); + static::setCookieHeader($headers, $name, $settings); + } + } else { + foreach ($cookies as $name => $settings) { + static::setCookieHeader($headers, $name, $settings); + } + } + } + + /** + * Encode secure cookie value + * + * This method will create the secure value of an HTTP cookie. The + * cookie value is encrypted and hashed so that its value is + * secure and checked for integrity when read in subsequent requests. + * + * @param string $value The insecure HTTP cookie value + * @param int $expires The UNIX timestamp at which this cookie will expire + * @param string $secret The secret key used to hash the cookie value + * @param int $algorithm The algorithm to use for encryption + * @param int $mode The algorithm mode to use for encryption + * @return string + */ + public static function encodeSecureCookie($value, $expires, $secret, $algorithm, $mode) + { + $key = hash_hmac('sha1', (string) $expires, $secret); + $iv = self::getIv($expires, $secret); + $secureString = base64_encode( + self::encrypt( + $value, + $key, + $iv, + array( + 'algorithm' => $algorithm, + 'mode' => $mode + ) + ) + ); + $verificationString = hash_hmac('sha1', $expires . $value, $key); + + return implode('|', array($expires, $secureString, $verificationString)); + } + + /** + * Decode secure cookie value + * + * This method will decode the secure value of an HTTP cookie. The + * cookie value is encrypted and hashed so that its value is + * secure and checked for integrity when read in subsequent requests. + * + * @param string $value The secure HTTP cookie value + * @param string $secret The secret key used to hash the cookie value + * @param int $algorithm The algorithm to use for encryption + * @param int $mode The algorithm mode to use for encryption + * @return bool|string + */ + public static function decodeSecureCookie($value, $secret, $algorithm, $mode) + { + if ($value) { + $value = explode('|', $value); + if (count($value) === 3 && ((int) $value[0] === 0 || (int) $value[0] > time())) { + $key = hash_hmac('sha1', $value[0], $secret); + $iv = self::getIv($value[0], $secret); + $data = self::decrypt( + base64_decode($value[1]), + $key, + $iv, + array( + 'algorithm' => $algorithm, + 'mode' => $mode + ) + ); + $verificationString = hash_hmac('sha1', $value[0] . $data, $key); + if ($verificationString === $value[2]) { + return $data; + } + } + } + + return false; + } + + /** + * Set HTTP cookie header + * + * This method will construct and set the HTTP `Set-Cookie` header. Slim + * uses this method instead of PHP's native `setcookie` method. This allows + * more control of the HTTP header irrespective of the native implementation's + * dependency on PHP versions. + * + * This method accepts the Slim_Http_Headers object by reference as its + * first argument; this method directly modifies this object instead of + * returning a value. + * + * @param array $header + * @param string $name + * @param string $value + */ + public static function setCookieHeader(&$header, $name, $value) + { + //Build cookie header + if (is_array($value)) { + $domain = ''; + $path = ''; + $expires = ''; + $secure = ''; + $httponly = ''; + if (isset($value['domain']) && $value['domain']) { + $domain = '; domain=' . $value['domain']; + } + if (isset($value['path']) && $value['path']) { + $path = '; path=' . $value['path']; + } + if (isset($value['expires'])) { + if (is_string($value['expires'])) { + $timestamp = strtotime($value['expires']); + } else { + $timestamp = (int) $value['expires']; + } + if ($timestamp !== 0) { + $expires = '; expires=' . gmdate('D, d-M-Y H:i:s e', $timestamp); + } + } + if (isset($value['secure']) && $value['secure']) { + $secure = '; secure'; + } + if (isset($value['httponly']) && $value['httponly']) { + $httponly = '; HttpOnly'; + } + $cookie = sprintf('%s=%s%s', urlencode($name), urlencode((string) $value['value']), $domain . $path . $expires . $secure . $httponly); + } else { + $cookie = sprintf('%s=%s', urlencode($name), urlencode((string) $value)); + } + + //Set cookie header + if (!isset($header['Set-Cookie']) || $header['Set-Cookie'] === '') { + $header['Set-Cookie'] = $cookie; + } else { + $header['Set-Cookie'] = implode("\n", array($header['Set-Cookie'], $cookie)); + } + } + + /** + * Delete HTTP cookie header + * + * This method will construct and set the HTTP `Set-Cookie` header to invalidate + * a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain) + * is already set in the HTTP response, it will also be removed. Slim uses this method + * instead of PHP's native `setcookie` method. This allows more control of the HTTP header + * irrespective of PHP's native implementation's dependency on PHP versions. + * + * This method accepts the Slim_Http_Headers object by reference as its + * first argument; this method directly modifies this object instead of + * returning a value. + * + * @param array $header + * @param string $name + * @param array $value + */ + public static function deleteCookieHeader(&$header, $name, $value = array()) + { + //Remove affected cookies from current response header + $cookiesOld = array(); + $cookiesNew = array(); + if (isset($header['Set-Cookie'])) { + $cookiesOld = explode("\n", $header['Set-Cookie']); + } + foreach ($cookiesOld as $c) { + if (isset($value['domain']) && $value['domain']) { + $regex = sprintf('@%s=.*domain=%s@', urlencode($name), preg_quote($value['domain'])); + } else { + $regex = sprintf('@%s=@', urlencode($name)); + } + if (preg_match($regex, $c) === 0) { + $cookiesNew[] = $c; + } + } + if ($cookiesNew) { + $header['Set-Cookie'] = implode("\n", $cookiesNew); + } else { + unset($header['Set-Cookie']); + } + + //Set invalidating cookie to clear client-side cookie + self::setCookieHeader($header, $name, array_merge(array('value' => '', 'path' => null, 'domain' => null, 'expires' => time() - 100), $value)); + } + + /** + * Parse cookie header + * + * This method will parse the HTTP request's `Cookie` header + * and extract cookies into an associative array. + * + * @param string + * @return array + */ + public static function parseCookieHeader($header) + { + $cookies = array(); + $header = rtrim($header, "\r\n"); + $headerPieces = preg_split('@\s*[;,]\s*@', $header); + foreach ($headerPieces as $c) { + $cParts = explode('=', $c, 2); + if (count($cParts) === 2) { + $key = urldecode($cParts[0]); + $value = urldecode($cParts[1]); + if (!isset($cookies[$key])) { + $cookies[$key] = $value; + } + } + } + + return $cookies; + } + + /** + * Generate a random IV + * + * This method will generate a non-predictable IV for use with + * the cookie encryption + * + * @param int $expires The UNIX timestamp at which this cookie will expire + * @param string $secret The secret key used to hash the cookie value + * @return string Hash + */ + private static function getIv($expires, $secret) + { + $data1 = hash_hmac('sha1', 'a'.$expires.'b', $secret); + $data2 = hash_hmac('sha1', 'z'.$expires.'y', $secret); + + return pack("h*", $data1.$data2); + } +} diff --git a/vendor/slim/slim/Slim/Log.php b/vendor/slim/slim/Slim/Log.php new file mode 100755 index 0000000..13cb825 --- /dev/null +++ b/vendor/slim/slim/Slim/Log.php @@ -0,0 +1,354 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * Log + * + * This is the primary logger for a Slim application. You may provide + * a Log Writer in conjunction with this Log to write to various output + * destinations (e.g. a file). This class provides this interface: + * + * debug( mixed $object, array $context ) + * info( mixed $object, array $context ) + * notice( mixed $object, array $context ) + * warning( mixed $object, array $context ) + * error( mixed $object, array $context ) + * critical( mixed $object, array $context ) + * alert( mixed $object, array $context ) + * emergency( mixed $object, array $context ) + * log( mixed $level, mixed $object, array $context ) + * + * This class assumes only that your Log Writer has a public `write()` method + * that accepts any object as its one and only argument. The Log Writer + * class may write or send its argument anywhere: a file, STDERR, + * a remote web API, etc. The possibilities are endless. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Log +{ + const EMERGENCY = 1; + const ALERT = 2; + const CRITICAL = 3; + const FATAL = 3; //DEPRECATED replace with CRITICAL + const ERROR = 4; + const WARN = 5; + const NOTICE = 6; + const INFO = 7; + const DEBUG = 8; + + /** + * @var array + */ + protected static $levels = array( + self::EMERGENCY => 'EMERGENCY', + self::ALERT => 'ALERT', + self::CRITICAL => 'CRITICAL', + self::ERROR => 'ERROR', + self::WARN => 'WARNING', + self::NOTICE => 'NOTICE', + self::INFO => 'INFO', + self::DEBUG => 'DEBUG' + ); + + /** + * @var mixed + */ + protected $writer; + + /** + * @var bool + */ + protected $enabled; + + /** + * @var int + */ + protected $level; + + /** + * Constructor + * @param mixed $writer + */ + public function __construct($writer) + { + $this->writer = $writer; + $this->enabled = true; + $this->level = self::DEBUG; + } + + /** + * Is logging enabled? + * @return bool + */ + public function getEnabled() + { + return $this->enabled; + } + + /** + * Enable or disable logging + * @param bool $enabled + */ + public function setEnabled($enabled) + { + if ($enabled) { + $this->enabled = true; + } else { + $this->enabled = false; + } + } + + /** + * Set level + * @param int $level + * @throws \InvalidArgumentException If invalid log level specified + */ + public function setLevel($level) + { + if (!isset(self::$levels[$level])) { + throw new \InvalidArgumentException('Invalid log level'); + } + $this->level = $level; + } + + /** + * Get level + * @return int + */ + public function getLevel() + { + return $this->level; + } + + /** + * Set writer + * @param mixed $writer + */ + public function setWriter($writer) + { + $this->writer = $writer; + } + + /** + * Get writer + * @return mixed + */ + public function getWriter() + { + return $this->writer; + } + + /** + * Is logging enabled? + * @return bool + */ + public function isEnabled() + { + return $this->enabled; + } + + /** + * Log debug message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function debug($object, $context = array()) + { + return $this->log(self::DEBUG, $object, $context); + } + + /** + * Log info message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function info($object, $context = array()) + { + return $this->log(self::INFO, $object, $context); + } + + /** + * Log notice message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function notice($object, $context = array()) + { + return $this->log(self::NOTICE, $object, $context); + } + + /** + * Log warning message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function warning($object, $context = array()) + { + return $this->log(self::WARN, $object, $context); + } + + /** + * DEPRECATED for function warning + * Log warning message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function warn($object, $context = array()) + { + return $this->log(self::WARN, $object, $context); + } + + /** + * Log error message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function error($object, $context = array()) + { + return $this->log(self::ERROR, $object, $context); + } + + /** + * Log critical message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function critical($object, $context = array()) + { + return $this->log(self::CRITICAL, $object, $context); + } + + /** + * DEPRECATED for function critical + * Log fatal message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function fatal($object, $context = array()) + { + return $this->log(self::CRITICAL, $object, $context); + } + + /** + * Log alert message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function alert($object, $context = array()) + { + return $this->log(self::ALERT, $object, $context); + } + + /** + * Log emergency message + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + */ + public function emergency($object, $context = array()) + { + return $this->log(self::EMERGENCY, $object, $context); + } + + /** + * Log message + * @param mixed $level + * @param mixed $object + * @param array $context + * @return mixed|bool What the Logger returns, or false if Logger not set or not enabled + * @throws \InvalidArgumentException If invalid log level + */ + public function log($level, $object, $context = array()) + { + if (!isset(self::$levels[$level])) { + throw new \InvalidArgumentException('Invalid log level supplied to function'); + } else if ($this->enabled && $this->writer && $level <= $this->level) { + if (is_array($object) || (is_object($object) && !method_exists($object, "__toString"))) { + $message = print_r($object, true); + } else { + $message = (string) $object; + } + + if (count($context) > 0) { + if (isset($context['exception']) && $context['exception'] instanceof \Exception) { + $message .= ' - ' . $context['exception']; + unset($context['exception']); + } + $message = $this->interpolate($message, $context); + } + return $this->writer->write($message, $level); + } else { + return false; + } + } + + /** + * DEPRECATED for function log + * Log message + * @param mixed $object The object to log + * @param int $level The message level + * @return int|bool + */ + protected function write($object, $level) + { + return $this->log($level, $object); + } + + /** + * Interpolate log message + * @param mixed $message The log message + * @param array $context An array of placeholder values + * @return string The processed string + */ + protected function interpolate($message, $context = array()) + { + $replace = array(); + foreach ($context as $key => $value) { + $replace['{' . $key . '}'] = $value; + } + return strtr($message, $replace); + } +} diff --git a/vendor/slim/slim/Slim/LogWriter.php b/vendor/slim/slim/Slim/LogWriter.php new file mode 100755 index 0000000..afa3ae9 --- /dev/null +++ b/vendor/slim/slim/Slim/LogWriter.php @@ -0,0 +1,75 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * Log Writer + * + * This class is used by Slim_Log to write log messages to a valid, writable + * resource handle (e.g. a file or STDERR). + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class LogWriter +{ + /** + * @var resource + */ + protected $resource; + + /** + * Constructor + * @param resource $resource + * @throws \InvalidArgumentException If invalid resource + */ + public function __construct($resource) + { + if (!is_resource($resource)) { + throw new \InvalidArgumentException('Cannot create LogWriter. Invalid resource handle.'); + } + $this->resource = $resource; + } + + /** + * Write message + * @param mixed $message + * @param int $level + * @return int|bool + */ + public function write($message, $level = null) + { + return fwrite($this->resource, (string) $message . PHP_EOL); + } +} diff --git a/vendor/slim/slim/Slim/Middleware.php b/vendor/slim/slim/Slim/Middleware.php new file mode 100755 index 0000000..79fbb1e --- /dev/null +++ b/vendor/slim/slim/Slim/Middleware.php @@ -0,0 +1,114 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * Middleware + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +abstract class Middleware +{ + /** + * @var \Slim\Slim Reference to the primary application instance + */ + protected $app; + + /** + * @var mixed Reference to the next downstream middleware + */ + protected $next; + + /** + * Set application + * + * This method injects the primary Slim application instance into + * this middleware. + * + * @param \Slim\Slim $application + */ + final public function setApplication($application) + { + $this->app = $application; + } + + /** + * Get application + * + * This method retrieves the application previously injected + * into this middleware. + * + * @return \Slim\Slim + */ + final public function getApplication() + { + return $this->app; + } + + /** + * Set next middleware + * + * This method injects the next downstream middleware into + * this middleware so that it may optionally be called + * when appropriate. + * + * @param \Slim|\Slim\Middleware + */ + final public function setNextMiddleware($nextMiddleware) + { + $this->next = $nextMiddleware; + } + + /** + * Get next middleware + * + * This method retrieves the next downstream middleware + * previously injected into this middleware. + * + * @return \Slim\Slim|\Slim\Middleware + */ + final public function getNextMiddleware() + { + return $this->next; + } + + /** + * Call + * + * Perform actions specific to this middleware and optionally + * call the next downstream middleware. + */ + abstract public function call(); +} diff --git a/vendor/slim/slim/Slim/Middleware/ContentTypes.php b/vendor/slim/slim/Slim/Middleware/ContentTypes.php new file mode 100755 index 0000000..fcc2242 --- /dev/null +++ b/vendor/slim/slim/Slim/Middleware/ContentTypes.php @@ -0,0 +1,174 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Middleware; + + /** + * Content Types + * + * This is middleware for a Slim application that intercepts + * the HTTP request body and parses it into the appropriate + * PHP data structure if possible; else it returns the HTTP + * request body unchanged. This is particularly useful + * for preparing the HTTP request body for an XML or JSON API. + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class ContentTypes extends \Slim\Middleware +{ + /** + * @var array + */ + protected $contentTypes; + + /** + * Constructor + * @param array $settings + */ + public function __construct($settings = array()) + { + $defaults = array( + 'application/json' => array($this, 'parseJson'), + 'application/xml' => array($this, 'parseXml'), + 'text/xml' => array($this, 'parseXml'), + 'text/csv' => array($this, 'parseCsv') + ); + $this->contentTypes = array_merge($defaults, $settings); + } + + /** + * Call + */ + public function call() + { + $mediaType = $this->app->request()->getMediaType(); + if ($mediaType) { + $env = $this->app->environment(); + $env['slim.input_original'] = $env['slim.input']; + $env['slim.input'] = $this->parse($env['slim.input'], $mediaType); + } + $this->next->call(); + } + + /** + * Parse input + * + * This method will attempt to parse the request body + * based on its content type if available. + * + * @param string $input + * @param string $contentType + * @return mixed + */ + protected function parse ($input, $contentType) + { + if (isset($this->contentTypes[$contentType]) && is_callable($this->contentTypes[$contentType])) { + $result = call_user_func($this->contentTypes[$contentType], $input); + if ($result) { + return $result; + } + } + + return $input; + } + + /** + * Parse JSON + * + * This method converts the raw JSON input + * into an associative array. + * + * @param string $input + * @return array|string + */ + protected function parseJson($input) + { + if (function_exists('json_decode')) { + $result = json_decode($input, true); + if(json_last_error() === JSON_ERROR_NONE) { + return $result; + } + } + } + + /** + * Parse XML + * + * This method creates a SimpleXMLElement + * based upon the XML input. If the SimpleXML + * extension is not available, the raw input + * will be returned unchanged. + * + * @param string $input + * @return \SimpleXMLElement|string + */ + protected function parseXml($input) + { + if (class_exists('SimpleXMLElement')) { + try { + $backup = libxml_disable_entity_loader(true); + $result = new \SimpleXMLElement($input); + libxml_disable_entity_loader($backup); + return $result; + } catch (\Exception $e) { + // Do nothing + } + } + + return $input; + } + + /** + * Parse CSV + * + * This method parses CSV content into a numeric array + * containing an array of data for each CSV line. + * + * @param string $input + * @return array + */ + protected function parseCsv($input) + { + $temp = fopen('php://memory', 'rw'); + fwrite($temp, $input); + fseek($temp, 0); + $res = array(); + while (($data = fgetcsv($temp)) !== false) { + $res[] = $data; + } + fclose($temp); + + return $res; + } +} diff --git a/vendor/slim/slim/Slim/Middleware/Flash.php b/vendor/slim/slim/Slim/Middleware/Flash.php new file mode 100755 index 0000000..593082f --- /dev/null +++ b/vendor/slim/slim/Slim/Middleware/Flash.php @@ -0,0 +1,212 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Middleware; + + /** + * Flash + * + * This is middleware for a Slim application that enables + * Flash messaging between HTTP requests. This allows you + * set Flash messages for the current request, for the next request, + * or to retain messages from the previous request through to + * the next request. + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class Flash extends \Slim\Middleware implements \ArrayAccess, \IteratorAggregate, \Countable +{ + /** + * @var array + */ + protected $settings; + + /** + * @var array + */ + protected $messages; + + /** + * Constructor + * @param array $settings + */ + public function __construct($settings = array()) + { + $this->settings = array_merge(array('key' => 'slim.flash'), $settings); + $this->messages = array( + 'prev' => array(), //flash messages from prev request (loaded when middleware called) + 'next' => array(), //flash messages for next request + 'now' => array() //flash messages for current request + ); + } + + /** + * Call + */ + public function call() + { + //Read flash messaging from previous request if available + $this->loadMessages(); + + //Prepare flash messaging for current request + $env = $this->app->environment(); + $env['slim.flash'] = $this; + $this->next->call(); + $this->save(); + } + + /** + * Now + * + * Specify a flash message for a given key to be shown for the current request + * + * @param string $key + * @param string $value + */ + public function now($key, $value) + { + $this->messages['now'][(string) $key] = $value; + } + + /** + * Set + * + * Specify a flash message for a given key to be shown for the next request + * + * @param string $key + * @param string $value + */ + public function set($key, $value) + { + $this->messages['next'][(string) $key] = $value; + } + + /** + * Keep + * + * Retain flash messages from the previous request for the next request + */ + public function keep() + { + foreach ($this->messages['prev'] as $key => $val) { + $this->messages['next'][$key] = $val; + } + } + + /** + * Save + */ + public function save() + { + $_SESSION[$this->settings['key']] = $this->messages['next']; + } + + /** + * Load messages from previous request if available + */ + public function loadMessages() + { + if (isset($_SESSION[$this->settings['key']])) { + $this->messages['prev'] = $_SESSION[$this->settings['key']]; + } + } + + /** + * Return array of flash messages to be shown for the current request + * + * @return array + */ + public function getMessages() + { + return array_merge($this->messages['prev'], $this->messages['now']); + } + + /** + * Array Access: Offset Exists + */ + public function offsetExists($offset) + { + $messages = $this->getMessages(); + + return isset($messages[$offset]); + } + + /** + * Array Access: Offset Get + */ + public function offsetGet($offset) + { + $messages = $this->getMessages(); + + return isset($messages[$offset]) ? $messages[$offset] : null; + } + + /** + * Array Access: Offset Set + */ + public function offsetSet($offset, $value) + { + $this->now($offset, $value); + } + + /** + * Array Access: Offset Unset + */ + public function offsetUnset($offset) + { + unset($this->messages['prev'][$offset], $this->messages['now'][$offset]); + } + + /** + * Iterator Aggregate: Get Iterator + * @return \ArrayIterator + */ + public function getIterator() + { + $messages = $this->getMessages(); + + return new \ArrayIterator($messages); + } + + /** + * Countable: Count + */ + public function count() + { + return count($this->getMessages()); + } + + + +} diff --git a/vendor/slim/slim/Slim/Middleware/MethodOverride.php b/vendor/slim/slim/Slim/Middleware/MethodOverride.php new file mode 100755 index 0000000..1298767 --- /dev/null +++ b/vendor/slim/slim/Slim/Middleware/MethodOverride.php @@ -0,0 +1,94 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Middleware; + + /** + * HTTP Method Override + * + * This is middleware for a Slim application that allows traditional + * desktop browsers to submit pseudo PUT and DELETE requests by relying + * on a pre-determined request parameter. Without this middleware, + * desktop browsers are only able to submit GET and POST requests. + * + * This middleware is included automatically! + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class MethodOverride extends \Slim\Middleware +{ + /** + * @var array + */ + protected $settings; + + /** + * Constructor + * @param array $settings + */ + public function __construct($settings = array()) + { + $this->settings = array_merge(array('key' => '_METHOD'), $settings); + } + + /** + * Call + * + * Implements Slim middleware interface. This method is invoked and passed + * an array of environment variables. This middleware inspects the environment + * variables for the HTTP method override parameter; if found, this middleware + * modifies the environment settings so downstream middleware and/or the Slim + * application will treat the request with the desired HTTP method. + * + * @return array[status, header, body] + */ + public function call() + { + $env = $this->app->environment(); + if (isset($env['HTTP_X_HTTP_METHOD_OVERRIDE'])) { + // Header commonly used by Backbone.js and others + $env['slim.method_override.original_method'] = $env['REQUEST_METHOD']; + $env['REQUEST_METHOD'] = strtoupper($env['HTTP_X_HTTP_METHOD_OVERRIDE']); + } elseif (isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'POST') { + // HTML Form Override + $req = new \Slim\Http\Request($env); + $method = $req->post($this->settings['key']); + if ($method) { + $env['slim.method_override.original_method'] = $env['REQUEST_METHOD']; + $env['REQUEST_METHOD'] = strtoupper($method); + } + } + $this->next->call(); + } +} diff --git a/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php b/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php new file mode 100755 index 0000000..aafda0f --- /dev/null +++ b/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php @@ -0,0 +1,116 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Middleware; + +/** + * Pretty Exceptions + * + * This middleware catches any Exception thrown by the surrounded + * application and displays a developer-friendly diagnostic screen. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class PrettyExceptions extends \Slim\Middleware +{ + /** + * @var array + */ + protected $settings; + + /** + * Constructor + * @param array $settings + */ + public function __construct($settings = array()) + { + $this->settings = $settings; + } + + /** + * Call + */ + public function call() + { + try { + $this->next->call(); + } catch (\Exception $e) { + $log = $this->app->getLog(); // Force Slim to append log to env if not already + $env = $this->app->environment(); + $env['slim.log'] = $log; + $env['slim.log']->error($e); + $this->app->contentType('text/html'); + $this->app->response()->status(500); + $this->app->response()->body($this->renderBody($env, $e)); + } + } + + /** + * Render response body + * @param array $env + * @param \Exception $exception + * @return string + */ + protected function renderBody(&$env, $exception) + { + $title = 'Slim Application Error'; + $code = $exception->getCode(); + $message = $exception->getMessage(); + $file = $exception->getFile(); + $line = $exception->getLine(); + $trace = str_replace(array('#', "\n"), array('
#', '
'), $exception->getTraceAsString()); + $html = sprintf('

%s

', $title); + $html .= '

The application could not run because of the following error:

'; + $html .= '

Details

'; + $html .= sprintf('
Type: %s
', get_class($exception)); + if ($code) { + $html .= sprintf('
Code: %s
', $code); + } + if ($message) { + $html .= sprintf('
Message: %s
', $message); + } + if ($file) { + $html .= sprintf('
File: %s
', $file); + } + if ($line) { + $html .= sprintf('
Line: %s
', $line); + } + if ($trace) { + $html .= '

Trace

'; + $html .= sprintf('
%s
', $trace); + } + + return sprintf("%s%s", $title, $html); + } +} diff --git a/vendor/slim/slim/Slim/Middleware/SessionCookie.php b/vendor/slim/slim/Slim/Middleware/SessionCookie.php new file mode 100755 index 0000000..939c977 --- /dev/null +++ b/vendor/slim/slim/Slim/Middleware/SessionCookie.php @@ -0,0 +1,205 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim\Middleware; + +/** + * Session Cookie + * + * This class provides an HTTP cookie storage mechanism + * for session data. This class avoids using a PHP session + * and instead serializes/unserializes the $_SESSION global + * variable to/from an HTTP cookie. + * + * You should NEVER store sensitive data in a client-side cookie + * in any format, encrypted (with cookies.encrypt) or not. If you + * need to store sensitive user information in a session, you should + * rely on PHP's native session implementation, or use other middleware + * to store session data in a database or alternative server-side cache. + * + * Because this class stores serialized session data in an HTTP cookie, + * you are inherently limited to 4 Kb. If you attempt to store + * more than this amount, serialization will fail. + * + * @package Slim + * @author Josh Lockhart + * @since 1.6.0 + */ +class SessionCookie extends \Slim\Middleware +{ + /** + * @var array + */ + protected $settings; + + /** + * Constructor + * + * @param array $settings + */ + public function __construct($settings = array()) + { + $defaults = array( + 'expires' => '20 minutes', + 'path' => '/', + 'domain' => null, + 'secure' => false, + 'httponly' => false, + 'name' => 'slim_session', + ); + $this->settings = array_merge($defaults, $settings); + if (is_string($this->settings['expires'])) { + $this->settings['expires'] = strtotime($this->settings['expires']); + } + + /** + * Session + * + * We must start a native PHP session to initialize the $_SESSION superglobal. + * However, we won't be using the native session store for persistence, so we + * disable the session cookie and cache limiter. We also set the session + * handler to this class instance to avoid PHP's native session file locking. + */ + ini_set('session.use_cookies', 0); + session_cache_limiter(false); + session_set_save_handler( + array($this, 'open'), + array($this, 'close'), + array($this, 'read'), + array($this, 'write'), + array($this, 'destroy'), + array($this, 'gc') + ); + } + + /** + * Call + */ + public function call() + { + $this->loadSession(); + $this->next->call(); + $this->saveSession(); + } + + /** + * Load session + */ + protected function loadSession() + { + if (session_id() === '') { + session_start(); + } + $value = $this->app->getCookie($this->settings['name']); + if ($value) { + $value = json_decode($value, true); + $_SESSION = is_array($value) ? $value : array(); + } else { + $_SESSION = array(); + } + } + + /** + * Save session + */ + protected function saveSession() + { + $value = json_encode($_SESSION); + + if (strlen($value) > 4096) { + $this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.'); + } else { + $this->app->setCookie( + $this->settings['name'], + $value, + $this->settings['expires'], + $this->settings['path'], + $this->settings['domain'], + $this->settings['secure'], + $this->settings['httponly'] + ); + } + // session_destroy(); + } + + /******************************************************************************** + * Session Handler + *******************************************************************************/ + + /** + * @codeCoverageIgnore + */ + public function open($savePath, $sessionName) + { + return true; + } + + /** + * @codeCoverageIgnore + */ + public function close() + { + return true; + } + + /** + * @codeCoverageIgnore + */ + public function read($id) + { + return ''; + } + + /** + * @codeCoverageIgnore + */ + public function write($id, $data) + { + return true; + } + + /** + * @codeCoverageIgnore + */ + public function destroy($id) + { + return true; + } + + /** + * @codeCoverageIgnore + */ + public function gc($maxlifetime) + { + return true; + } +} diff --git a/vendor/slim/slim/Slim/Route.php b/vendor/slim/slim/Slim/Route.php new file mode 100755 index 0000000..2127e62 --- /dev/null +++ b/vendor/slim/slim/Slim/Route.php @@ -0,0 +1,471 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * Route + * @package Slim + * @author Josh Lockhart, Thomas Bley + * @since 1.0.0 + */ +class Route +{ + /** + * @var string The route pattern (e.g. "/books/:id") + */ + protected $pattern; + + /** + * @var mixed The route callable + */ + protected $callable; + + /** + * @var array Conditions for this route's URL parameters + */ + protected $conditions = array(); + + /** + * @var array Default conditions applied to all route instances + */ + protected static $defaultConditions = array(); + + /** + * @var string The name of this route (optional) + */ + protected $name; + + /** + * @var array Key-value array of URL parameters + */ + protected $params = array(); + + /** + * @var array value array of URL parameter names + */ + protected $paramNames = array(); + + /** + * @var array key array of URL parameter names with + at the end + */ + protected $paramNamesPath = array(); + + /** + * @var array HTTP methods supported by this Route + */ + protected $methods = array(); + + /** + * @var array[Callable] Middleware to be run before only this route instance + */ + protected $middleware = array(); + + /** + * @var bool Whether or not this route should be matched in a case-sensitive manner + */ + protected $caseSensitive; + + /** + * Constructor + * @param string $pattern The URL pattern (e.g. "/books/:id") + * @param mixed $callable Anything that returns TRUE for is_callable() + * @param bool $caseSensitive Whether or not this route should be matched in a case-sensitive manner + */ + public function __construct($pattern, $callable, $caseSensitive = true) + { + $this->setPattern($pattern); + $this->setCallable($callable); + $this->setConditions(self::getDefaultConditions()); + $this->caseSensitive = $caseSensitive; + } + + /** + * Set default route conditions for all instances + * @param array $defaultConditions + */ + public static function setDefaultConditions(array $defaultConditions) + { + self::$defaultConditions = $defaultConditions; + } + + /** + * Get default route conditions for all instances + * @return array + */ + public static function getDefaultConditions() + { + return self::$defaultConditions; + } + + /** + * Get route pattern + * @return string + */ + public function getPattern() + { + return $this->pattern; + } + + /** + * Set route pattern + * @param string $pattern + */ + public function setPattern($pattern) + { + $this->pattern = $pattern; + } + + /** + * Get route callable + * @return mixed + */ + public function getCallable() + { + return $this->callable; + } + + /** + * Set route callable + * @param mixed $callable + * @throws \InvalidArgumentException If argument is not callable + */ + public function setCallable($callable) + { + $matches = array(); + if (is_string($callable) && preg_match('!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!', $callable, $matches)) { + $class = $matches[1]; + $method = $matches[2]; + $callable = function() use ($class, $method) { + static $obj = null; + if ($obj === null) { + $obj = new $class; + } + return call_user_func_array(array($obj, $method), func_get_args()); + }; + } + + if (!is_callable($callable)) { + throw new \InvalidArgumentException('Route callable must be callable'); + } + + $this->callable = $callable; + } + + /** + * Get route conditions + * @return array + */ + public function getConditions() + { + return $this->conditions; + } + + /** + * Set route conditions + * @param array $conditions + */ + public function setConditions(array $conditions) + { + $this->conditions = $conditions; + } + + /** + * Get route name + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * Set route name + * @param string $name + */ + public function setName($name) + { + $this->name = (string)$name; + } + + /** + * Get route parameters + * @return array + */ + public function getParams() + { + return $this->params; + } + + /** + * Set route parameters + * @param array $params + */ + public function setParams($params) + { + $this->params = $params; + } + + /** + * Get route parameter value + * @param string $index Name of URL parameter + * @return string + * @throws \InvalidArgumentException If route parameter does not exist at index + */ + public function getParam($index) + { + if (!isset($this->params[$index])) { + throw new \InvalidArgumentException('Route parameter does not exist at specified index'); + } + + return $this->params[$index]; + } + + /** + * Set route parameter value + * @param string $index Name of URL parameter + * @param mixed $value The new parameter value + * @throws \InvalidArgumentException If route parameter does not exist at index + */ + public function setParam($index, $value) + { + if (!isset($this->params[$index])) { + throw new \InvalidArgumentException('Route parameter does not exist at specified index'); + } + $this->params[$index] = $value; + } + + /** + * Add supported HTTP method(s) + */ + public function setHttpMethods() + { + $args = func_get_args(); + $this->methods = $args; + } + + /** + * Get supported HTTP methods + * @return array + */ + public function getHttpMethods() + { + return $this->methods; + } + + /** + * Append supported HTTP methods + */ + public function appendHttpMethods() + { + $args = func_get_args(); + if(count($args) && is_array($args[0])){ + $args = $args[0]; + } + $this->methods = array_merge($this->methods, $args); + } + + /** + * Append supported HTTP methods (alias for Route::appendHttpMethods) + * @return \Slim\Route + */ + public function via() + { + $args = func_get_args(); + if(count($args) && is_array($args[0])){ + $args = $args[0]; + } + $this->methods = array_merge($this->methods, $args); + + return $this; + } + + /** + * Detect support for an HTTP method + * @param string $method + * @return bool + */ + public function supportsHttpMethod($method) + { + return in_array($method, $this->methods); + } + + /** + * Get middleware + * @return array[Callable] + */ + public function getMiddleware() + { + return $this->middleware; + } + + /** + * Set middleware + * + * This method allows middleware to be assigned to a specific Route. + * If the method argument `is_callable` (including callable arrays!), + * we directly append the argument to `$this->middleware`. Else, we + * assume the argument is an array of callables and merge the array + * with `$this->middleware`. Each middleware is checked for is_callable() + * and an InvalidArgumentException is thrown immediately if it isn't. + * + * @param Callable|array[Callable] + * @return \Slim\Route + * @throws \InvalidArgumentException If argument is not callable or not an array of callables. + */ + public function setMiddleware($middleware) + { + if (is_callable($middleware)) { + $this->middleware[] = $middleware; + } elseif (is_array($middleware)) { + foreach ($middleware as $callable) { + if (!is_callable($callable)) { + throw new \InvalidArgumentException('All Route middleware must be callable'); + } + } + $this->middleware = array_merge($this->middleware, $middleware); + } else { + throw new \InvalidArgumentException('Route middleware must be callable or an array of callables'); + } + + return $this; + } + + /** + * Matches URI? + * + * Parse this route's pattern, and then compare it to an HTTP resource URI + * This method was modeled after the techniques demonstrated by Dan Sosedoff at: + * + * http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/ + * + * @param string $resourceUri A Request URI + * @return bool + */ + public function matches($resourceUri) + { + //Convert URL params into regex patterns, construct a regex for this route, init params + $patternAsRegex = preg_replace_callback( + '#:([\w]+)\+?#', + array($this, 'matchesCallback'), + str_replace(')', ')?', (string)$this->pattern) + ); + if (substr($this->pattern, -1) === '/') { + $patternAsRegex .= '?'; + } + + $regex = '#^' . $patternAsRegex . '$#'; + + if ($this->caseSensitive === false) { + $regex .= 'i'; + } + + //Cache URL params' names and values if this route matches the current HTTP request + if (!preg_match($regex, $resourceUri, $paramValues)) { + return false; + } + foreach ($this->paramNames as $name) { + if (isset($paramValues[$name])) { + if (isset($this->paramNamesPath[$name])) { + $this->params[$name] = explode('/', urldecode($paramValues[$name])); + } else { + $this->params[$name] = urldecode($paramValues[$name]); + } + } + } + + return true; + } + + /** + * Convert a URL parameter (e.g. ":id", ":id+") into a regular expression + * @param array $m URL parameters + * @return string Regular expression for URL parameter + */ + protected function matchesCallback($m) + { + $this->paramNames[] = $m[1]; + if (isset($this->conditions[$m[1]])) { + return '(?P<' . $m[1] . '>' . $this->conditions[$m[1]] . ')'; + } + if (substr($m[0], -1) === '+') { + $this->paramNamesPath[$m[1]] = 1; + + return '(?P<' . $m[1] . '>.+)'; + } + + return '(?P<' . $m[1] . '>[^/]+)'; + } + + /** + * Set route name + * @param string $name The name of the route + * @return \Slim\Route + */ + public function name($name) + { + $this->setName($name); + + return $this; + } + + /** + * Merge route conditions + * @param array $conditions Key-value array of URL parameter conditions + * @return \Slim\Route + */ + public function conditions(array $conditions) + { + $this->conditions = array_merge($this->conditions, $conditions); + + return $this; + } + + /** + * Dispatch route + * + * This method invokes the route object's callable. If middleware is + * registered for the route, each callable middleware is invoked in + * the order specified. + * + * @return bool + */ + public function dispatch() + { + foreach ($this->middleware as $mw) { + call_user_func_array($mw, array($this)); + } + + $return = call_user_func_array($this->getCallable(), array_values($this->getParams())); + return ($return === false) ? false : true; + } +} diff --git a/vendor/slim/slim/Slim/Router.php b/vendor/slim/slim/Slim/Router.php new file mode 100755 index 0000000..87e06ed --- /dev/null +++ b/vendor/slim/slim/Slim/Router.php @@ -0,0 +1,257 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * Router + * + * This class organizes, iterates, and dispatches \Slim\Route objects. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class Router +{ + /** + * @var Route The current route (most recently dispatched) + */ + protected $currentRoute; + + /** + * @var array Lookup hash of all route objects + */ + protected $routes; + + /** + * @var array Lookup hash of named route objects, keyed by route name (lazy-loaded) + */ + protected $namedRoutes; + + /** + * @var array Array of route objects that match the request URI (lazy-loaded) + */ + protected $matchedRoutes; + + /** + * @var array Array containing all route groups + */ + protected $routeGroups; + + /** + * Constructor + */ + public function __construct() + { + $this->routes = array(); + $this->routeGroups = array(); + } + + /** + * Get Current Route object or the first matched one if matching has been performed + * @return \Slim\Route|null + */ + public function getCurrentRoute() + { + if ($this->currentRoute !== null) { + return $this->currentRoute; + } + + if (is_array($this->matchedRoutes) && count($this->matchedRoutes) > 0) { + return $this->matchedRoutes[0]; + } + + return null; + } + + /** + * Return route objects that match the given HTTP method and URI + * @param string $httpMethod The HTTP method to match against + * @param string $resourceUri The resource URI to match against + * @param bool $reload Should matching routes be re-parsed? + * @return array[\Slim\Route] + */ + public function getMatchedRoutes($httpMethod, $resourceUri, $reload = false) + { + if ($reload || is_null($this->matchedRoutes)) { + $this->matchedRoutes = array(); + foreach ($this->routes as $route) { + if (!$route->supportsHttpMethod($httpMethod) && !$route->supportsHttpMethod("ANY")) { + continue; + } + + if ($route->matches($resourceUri)) { + $this->matchedRoutes[] = $route; + } + } + } + + return $this->matchedRoutes; + } + + /** + * Add a route object to the router + * @param \Slim\Route $route The Slim Route + */ + public function map(\Slim\Route $route) + { + list($groupPattern, $groupMiddleware) = $this->processGroups(); + + $route->setPattern($groupPattern . $route->getPattern()); + $this->routes[] = $route; + + + foreach ($groupMiddleware as $middleware) { + $route->setMiddleware($middleware); + } + } + + /** + * A helper function for processing the group's pattern and middleware + * @return array Returns an array with the elements: pattern, middlewareArr + */ + protected function processGroups() + { + $pattern = ""; + $middleware = array(); + foreach ($this->routeGroups as $group) { + $k = key($group); + $pattern .= $k; + if (is_array($group[$k])) { + $middleware = array_merge($middleware, $group[$k]); + } + } + return array($pattern, $middleware); + } + + /** + * Add a route group to the array + * @param string $group The group pattern (ie. "/books/:id") + * @param array|null $middleware Optional parameter array of middleware + * @return int The index of the new group + */ + public function pushGroup($group, $middleware = array()) + { + return array_push($this->routeGroups, array($group => $middleware)); + } + + /** + * Removes the last route group from the array + * @return bool True if successful, else False + */ + public function popGroup() + { + return (array_pop($this->routeGroups) !== null); + } + + /** + * Get URL for named route + * @param string $name The name of the route + * @param array $params Associative array of URL parameter names and replacement values + * @throws \RuntimeException If named route not found + * @return string The URL for the given route populated with provided replacement values + */ + public function urlFor($name, $params = array()) + { + if (!$this->hasNamedRoute($name)) { + throw new \RuntimeException('Named route not found for name: ' . $name); + } + $search = array(); + foreach ($params as $key => $value) { + $search[] = '#:' . preg_quote($key, '#') . '\+?(?!\w)#'; + } + $pattern = preg_replace($search, $params, $this->getNamedRoute($name)->getPattern()); + + //Remove remnants of unpopulated, trailing optional pattern segments, escaped special characters + return preg_replace('#\(/?:.+\)|\(|\)|\\\\#', '', $pattern); + } + + /** + * Add named route + * @param string $name The route name + * @param \Slim\Route $route The route object + * @throws \RuntimeException If a named route already exists with the same name + */ + public function addNamedRoute($name, \Slim\Route $route) + { + if ($this->hasNamedRoute($name)) { + throw new \RuntimeException('Named route already exists with name: ' . $name); + } + $this->namedRoutes[(string) $name] = $route; + } + + /** + * Has named route + * @param string $name The route name + * @return bool + */ + public function hasNamedRoute($name) + { + $this->getNamedRoutes(); + + return isset($this->namedRoutes[(string) $name]); + } + + /** + * Get named route + * @param string $name + * @return \Slim\Route|null + */ + public function getNamedRoute($name) + { + $this->getNamedRoutes(); + if ($this->hasNamedRoute($name)) { + return $this->namedRoutes[(string) $name]; + } + + return null; + } + + /** + * Get named routes + * @return \ArrayIterator + */ + public function getNamedRoutes() + { + if (is_null($this->namedRoutes)) { + $this->namedRoutes = array(); + foreach ($this->routes as $route) { + if ($route->getName() !== null) { + $this->addNamedRoute($route->getName(), $route); + } + } + } + + return new \ArrayIterator($this->namedRoutes); + } +} diff --git a/vendor/slim/slim/Slim/Slim.php b/vendor/slim/slim/Slim/Slim.php new file mode 100755 index 0000000..4a83595 --- /dev/null +++ b/vendor/slim/slim/Slim/Slim.php @@ -0,0 +1,1444 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +// Ensure mcrypt constants are defined even if mcrypt extension is not loaded +if (!extension_loaded('mcrypt')) { + define('MCRYPT_MODE_CBC', 0); + define('MCRYPT_RIJNDAEL_256', 0); +} + +/** + * Slim + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + * + * @property \Slim\Environment $environment + * @property \Slim\Http\Response $response + * @property \Slim\Http\Request $request + * @property \Slim\Router $router + */ +class Slim +{ + /** + * @const string + */ + const VERSION = '2.6.1'; + + /** + * @var \Slim\Helper\Set + */ + public $container; + + /** + * @var array[\Slim] + */ + protected static $apps = array(); + + /** + * @var string + */ + protected $name; + + /** + * @var array + */ + protected $middleware; + + /** + * @var mixed Callable to be invoked if application error + */ + protected $error; + + /** + * @var mixed Callable to be invoked if no matching routes are found + */ + protected $notFound; + + /** + * @var array + */ + protected $hooks = array( + 'slim.before' => array(array()), + 'slim.before.router' => array(array()), + 'slim.before.dispatch' => array(array()), + 'slim.after.dispatch' => array(array()), + 'slim.after.router' => array(array()), + 'slim.after' => array(array()) + ); + + /******************************************************************************** + * PSR-0 Autoloader + * + * Do not use if you are using Composer to autoload dependencies. + *******************************************************************************/ + + /** + * Slim PSR-0 autoloader + */ + public static function autoload($className) + { + $thisClass = str_replace(__NAMESPACE__.'\\', '', __CLASS__); + + $baseDir = __DIR__; + + if (substr($baseDir, -strlen($thisClass)) === $thisClass) { + $baseDir = substr($baseDir, 0, -strlen($thisClass)); + } + + $className = ltrim($className, '\\'); + $fileName = $baseDir; + $namespace = ''; + if ($lastNsPos = strripos($className, '\\')) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $fileName .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; + + if (file_exists($fileName)) { + require $fileName; + } + } + + /** + * Register Slim's PSR-0 autoloader + */ + public static function registerAutoloader() + { + spl_autoload_register(__NAMESPACE__ . "\\Slim::autoload"); + } + + /******************************************************************************** + * Instantiation and Configuration + *******************************************************************************/ + + /** + * Constructor + * @param array $userSettings Associative array of application settings + */ + public function __construct(array $userSettings = array()) + { + // Setup IoC container + $this->container = new \Slim\Helper\Set(); + $this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings); + + // Default environment + $this->container->singleton('environment', function ($c) { + return \Slim\Environment::getInstance(); + }); + + // Default request + $this->container->singleton('request', function ($c) { + return new \Slim\Http\Request($c['environment']); + }); + + // Default response + $this->container->singleton('response', function ($c) { + return new \Slim\Http\Response(); + }); + + // Default router + $this->container->singleton('router', function ($c) { + return new \Slim\Router(); + }); + + // Default view + $this->container->singleton('view', function ($c) { + $viewClass = $c['settings']['view']; + $templatesPath = $c['settings']['templates.path']; + + $view = ($viewClass instanceOf \Slim\View) ? $viewClass : new $viewClass; + $view->setTemplatesDirectory($templatesPath); + return $view; + }); + + // Default log writer + $this->container->singleton('logWriter', function ($c) { + $logWriter = $c['settings']['log.writer']; + + return is_object($logWriter) ? $logWriter : new \Slim\LogWriter($c['environment']['slim.errors']); + }); + + // Default log + $this->container->singleton('log', function ($c) { + $log = new \Slim\Log($c['logWriter']); + $log->setEnabled($c['settings']['log.enabled']); + $log->setLevel($c['settings']['log.level']); + $env = $c['environment']; + $env['slim.log'] = $log; + + return $log; + }); + + // Default mode + $this->container['mode'] = function ($c) { + $mode = $c['settings']['mode']; + + if (isset($_ENV['SLIM_MODE'])) { + $mode = $_ENV['SLIM_MODE']; + } else { + $envMode = getenv('SLIM_MODE'); + if ($envMode !== false) { + $mode = $envMode; + } + } + + return $mode; + }; + + // Define default middleware stack + $this->middleware = array($this); + $this->add(new \Slim\Middleware\Flash()); + $this->add(new \Slim\Middleware\MethodOverride()); + + // Make default if first instance + if (is_null(static::getInstance())) { + $this->setName('default'); + } + } + + public function __get($name) + { + return $this->container->get($name); + } + + public function __set($name, $value) + { + $this->container->set($name, $value); + } + + public function __isset($name) + { + return $this->container->has($name); + } + + public function __unset($name) + { + $this->container->remove($name); + } + + /** + * Get application instance by name + * @param string $name The name of the Slim application + * @return \Slim\Slim|null + */ + public static function getInstance($name = 'default') + { + return isset(static::$apps[$name]) ? static::$apps[$name] : null; + } + + /** + * Set Slim application name + * @param string $name The name of this Slim application + */ + public function setName($name) + { + $this->name = $name; + static::$apps[$name] = $this; + } + + /** + * Get Slim application name + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * Get default application settings + * @return array + */ + public static function getDefaultSettings() + { + return array( + // Application + 'mode' => 'development', + // Debugging + 'debug' => true, + // Logging + 'log.writer' => null, + 'log.level' => \Slim\Log::DEBUG, + 'log.enabled' => true, + // View + 'templates.path' => './templates', + 'view' => '\Slim\View', + // Cookies + 'cookies.encrypt' => false, + 'cookies.lifetime' => '20 minutes', + 'cookies.path' => '/', + 'cookies.domain' => null, + 'cookies.secure' => false, + 'cookies.httponly' => false, + // Encryption + 'cookies.secret_key' => 'CHANGE_ME', + 'cookies.cipher' => MCRYPT_RIJNDAEL_256, + 'cookies.cipher_mode' => MCRYPT_MODE_CBC, + // HTTP + 'http.version' => '1.1', + // Routing + 'routes.case_sensitive' => true + ); + } + + /** + * Configure Slim Settings + * + * This method defines application settings and acts as a setter and a getter. + * + * If only one argument is specified and that argument is a string, the value + * of the setting identified by the first argument will be returned, or NULL if + * that setting does not exist. + * + * If only one argument is specified and that argument is an associative array, + * the array will be merged into the existing application settings. + * + * If two arguments are provided, the first argument is the name of the setting + * to be created or updated, and the second argument is the setting value. + * + * @param string|array $name If a string, the name of the setting to set or retrieve. Else an associated array of setting names and values + * @param mixed $value If name is a string, the value of the setting identified by $name + * @return mixed The value of a setting if only one argument is a string + */ + public function config($name, $value = null) + { + $c = $this->container; + + if (is_array($name)) { + if (true === $value) { + $c['settings'] = array_merge_recursive($c['settings'], $name); + } else { + $c['settings'] = array_merge($c['settings'], $name); + } + } elseif (func_num_args() === 1) { + return isset($c['settings'][$name]) ? $c['settings'][$name] : null; + } else { + $settings = $c['settings']; + $settings[$name] = $value; + $c['settings'] = $settings; + } + } + + /******************************************************************************** + * Application Modes + *******************************************************************************/ + + /** + * Get application mode + * + * This method determines the application mode. It first inspects the $_ENV + * superglobal for key `SLIM_MODE`. If that is not found, it queries + * the `getenv` function. Else, it uses the application `mode` setting. + * + * @return string + */ + public function getMode() + { + return $this->mode; + } + + /** + * Configure Slim for a given mode + * + * This method will immediately invoke the callable if + * the specified mode matches the current application mode. + * Otherwise, the callable is ignored. This should be called + * only _after_ you initialize your Slim app. + * + * @param string $mode + * @param mixed $callable + * @return void + */ + public function configureMode($mode, $callable) + { + if ($mode === $this->getMode() && is_callable($callable)) { + call_user_func($callable); + } + } + + /******************************************************************************** + * Logging + *******************************************************************************/ + + /** + * Get application log + * @return \Slim\Log + */ + public function getLog() + { + return $this->log; + } + + /******************************************************************************** + * Routing + *******************************************************************************/ + + /** + * Add GET|POST|PUT|PATCH|DELETE route + * + * Adds a new route to the router with associated callable. This + * route will only be invoked when the HTTP request's method matches + * this route's method. + * + * ARGUMENTS: + * + * First: string The URL pattern (REQUIRED) + * In-Between: mixed Anything that returns TRUE for `is_callable` (OPTIONAL) + * Last: mixed Anything that returns TRUE for `is_callable` (REQUIRED) + * + * The first argument is required and must always be the + * route pattern (ie. '/books/:id'). + * + * The last argument is required and must always be the callable object + * to be invoked when the route matches an HTTP request. + * + * You may also provide an unlimited number of in-between arguments; + * each interior argument must be callable and will be invoked in the + * order specified before the route's callable is invoked. + * + * USAGE: + * + * Slim::get('/foo'[, middleware, middleware, ...], callable); + * + * @param array (See notes above) + * @return \Slim\Route + */ + protected function mapRoute($args) + { + $pattern = array_shift($args); + $callable = array_pop($args); + $route = new \Slim\Route($pattern, $callable, $this->settings['routes.case_sensitive']); + $this->router->map($route); + if (count($args) > 0) { + $route->setMiddleware($args); + } + + return $route; + } + + /** + * Add generic route without associated HTTP method + * @see mapRoute() + * @return \Slim\Route + */ + public function map() + { + $args = func_get_args(); + + return $this->mapRoute($args); + } + + /** + * Add GET route + * @see mapRoute() + * @return \Slim\Route + */ + public function get() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_GET, \Slim\Http\Request::METHOD_HEAD); + } + + /** + * Add POST route + * @see mapRoute() + * @return \Slim\Route + */ + public function post() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_POST); + } + + /** + * Add PUT route + * @see mapRoute() + * @return \Slim\Route + */ + public function put() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_PUT); + } + + /** + * Add PATCH route + * @see mapRoute() + * @return \Slim\Route + */ + public function patch() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_PATCH); + } + + /** + * Add DELETE route + * @see mapRoute() + * @return \Slim\Route + */ + public function delete() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_DELETE); + } + + /** + * Add OPTIONS route + * @see mapRoute() + * @return \Slim\Route + */ + public function options() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via(\Slim\Http\Request::METHOD_OPTIONS); + } + + /** + * Route Groups + * + * This method accepts a route pattern and a callback all Route + * declarations in the callback will be prepended by the group(s) + * that it is in + * + * Accepts the same parameters as a standard route so: + * (pattern, middleware1, middleware2, ..., $callback) + */ + public function group() + { + $args = func_get_args(); + $pattern = array_shift($args); + $callable = array_pop($args); + $this->router->pushGroup($pattern, $args); + if (is_callable($callable)) { + call_user_func($callable); + } + $this->router->popGroup(); + } + + /* + * Add route for any HTTP method + * @see mapRoute() + * @return \Slim\Route + */ + public function any() + { + $args = func_get_args(); + + return $this->mapRoute($args)->via("ANY"); + } + + /** + * Not Found Handler + * + * This method defines or invokes the application-wide Not Found handler. + * There are two contexts in which this method may be invoked: + * + * 1. When declaring the handler: + * + * If the $callable parameter is not null and is callable, this + * method will register the callable to be invoked when no + * routes match the current HTTP request. It WILL NOT invoke the callable. + * + * 2. When invoking the handler: + * + * If the $callable parameter is null, Slim assumes you want + * to invoke an already-registered handler. If the handler has been + * registered and is callable, it is invoked and sends a 404 HTTP Response + * whose body is the output of the Not Found handler. + * + * @param mixed $callable Anything that returns true for is_callable() + */ + public function notFound ($callable = null) + { + if (is_callable($callable)) { + $this->notFound = $callable; + } else { + ob_start(); + if (is_callable($this->notFound)) { + call_user_func($this->notFound); + } else { + call_user_func(array($this, 'defaultNotFound')); + } + $this->halt(404, ob_get_clean()); + } + } + + /** + * Error Handler + * + * This method defines or invokes the application-wide Error handler. + * There are two contexts in which this method may be invoked: + * + * 1. When declaring the handler: + * + * If the $argument parameter is callable, this + * method will register the callable to be invoked when an uncaught + * Exception is detected, or when otherwise explicitly invoked. + * The handler WILL NOT be invoked in this context. + * + * 2. When invoking the handler: + * + * If the $argument parameter is not callable, Slim assumes you want + * to invoke an already-registered handler. If the handler has been + * registered and is callable, it is invoked and passed the caught Exception + * as its one and only argument. The error handler's output is captured + * into an output buffer and sent as the body of a 500 HTTP Response. + * + * @param mixed $argument Callable|\Exception + */ + public function error($argument = null) + { + if (is_callable($argument)) { + //Register error handler + $this->error = $argument; + } else { + //Invoke error handler + $this->response->status(500); + $this->response->body(''); + $this->response->write($this->callErrorHandler($argument)); + $this->stop(); + } + } + + /** + * Call error handler + * + * This will invoke the custom or default error handler + * and RETURN its output. + * + * @param \Exception|null $argument + * @return string + */ + protected function callErrorHandler($argument = null) + { + ob_start(); + if (is_callable($this->error)) { + call_user_func_array($this->error, array($argument)); + } else { + call_user_func_array(array($this, 'defaultError'), array($argument)); + } + + return ob_get_clean(); + } + + /******************************************************************************** + * Application Accessors + *******************************************************************************/ + + /** + * Get a reference to the Environment object + * @return \Slim\Environment + */ + public function environment() + { + return $this->environment; + } + + /** + * Get the Request object + * @return \Slim\Http\Request + */ + public function request() + { + return $this->request; + } + + /** + * Get the Response object + * @return \Slim\Http\Response + */ + public function response() + { + return $this->response; + } + + /** + * Get the Router object + * @return \Slim\Router + */ + public function router() + { + return $this->router; + } + + /** + * Get and/or set the View + * + * This method declares the View to be used by the Slim application. + * If the argument is a string, Slim will instantiate a new object + * of the same class. If the argument is an instance of View or a subclass + * of View, Slim will use the argument as the View. + * + * If a View already exists and this method is called to create a + * new View, data already set in the existing View will be + * transferred to the new View. + * + * @param string|\Slim\View $viewClass The name or instance of a \Slim\View subclass + * @return \Slim\View + */ + public function view($viewClass = null) + { + if (!is_null($viewClass)) { + $existingData = is_null($this->view) ? array() : $this->view->getData(); + if ($viewClass instanceOf \Slim\View) { + $this->view = $viewClass; + } else { + $this->view = new $viewClass(); + } + $this->view->appendData($existingData); + $this->view->setTemplatesDirectory($this->config('templates.path')); + } + + return $this->view; + } + + /******************************************************************************** + * Rendering + *******************************************************************************/ + + /** + * Render a template + * + * Call this method within a GET, POST, PUT, PATCH, DELETE, NOT FOUND, or ERROR + * callable to render a template whose output is appended to the + * current HTTP response body. How the template is rendered is + * delegated to the current View. + * + * @param string $template The name of the template passed into the view's render() method + * @param array $data Associative array of data made available to the view + * @param int $status The HTTP response status code to use (optional) + */ + public function render($template, $data = array(), $status = null) + { + if (!is_null($status)) { + $this->response->status($status); + } + $this->view->appendData($data); + $this->view->display($template); + } + + /******************************************************************************** + * HTTP Caching + *******************************************************************************/ + + /** + * Set Last-Modified HTTP Response Header + * + * Set the HTTP 'Last-Modified' header and stop if a conditional + * GET request's `If-Modified-Since` header matches the last modified time + * of the resource. The `time` argument is a UNIX timestamp integer value. + * When the current request includes an 'If-Modified-Since' header that + * matches the specified last modified time, the application will stop + * and send a '304 Not Modified' response to the client. + * + * @param int $time The last modified UNIX timestamp + * @throws \InvalidArgumentException If provided timestamp is not an integer + */ + public function lastModified($time) + { + if (is_integer($time)) { + $this->response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s T', $time)); + if ($time === strtotime($this->request->headers->get('IF_MODIFIED_SINCE'))) { + $this->halt(304); + } + } else { + throw new \InvalidArgumentException('Slim::lastModified only accepts an integer UNIX timestamp value.'); + } + } + + /** + * Set ETag HTTP Response Header + * + * Set the etag header and stop if the conditional GET request matches. + * The `value` argument is a unique identifier for the current resource. + * The `type` argument indicates whether the etag should be used as a strong or + * weak cache validator. + * + * When the current request includes an 'If-None-Match' header with + * a matching etag, execution is immediately stopped. If the request + * method is GET or HEAD, a '304 Not Modified' response is sent. + * + * @param string $value The etag value + * @param string $type The type of etag to create; either "strong" or "weak" + * @throws \InvalidArgumentException If provided type is invalid + */ + public function etag($value, $type = 'strong') + { + //Ensure type is correct + if (!in_array($type, array('strong', 'weak'))) { + throw new \InvalidArgumentException('Invalid Slim::etag type. Expected "strong" or "weak".'); + } + + //Set etag value + $value = '"' . $value . '"'; + if ($type === 'weak') { + $value = 'W/'.$value; + } + $this->response['ETag'] = $value; + + //Check conditional GET + if ($etagsHeader = $this->request->headers->get('IF_NONE_MATCH')) { + $etags = preg_split('@\s*,\s*@', $etagsHeader); + if (in_array($value, $etags) || in_array('*', $etags)) { + $this->halt(304); + } + } + } + + /** + * Set Expires HTTP response header + * + * The `Expires` header tells the HTTP client the time at which + * the current resource should be considered stale. At that time the HTTP + * client will send a conditional GET request to the server; the server + * may return a 200 OK if the resource has changed, else a 304 Not Modified + * if the resource has not changed. The `Expires` header should be used in + * conjunction with the `etag()` or `lastModified()` methods above. + * + * @param string|int $time If string, a time to be parsed by `strtotime()`; + * If int, a UNIX timestamp; + */ + public function expires($time) + { + if (is_string($time)) { + $time = strtotime($time); + } + $this->response->headers->set('Expires', gmdate('D, d M Y H:i:s T', $time)); + } + + /******************************************************************************** + * HTTP Cookies + *******************************************************************************/ + + /** + * Set HTTP cookie to be sent with the HTTP response + * + * @param string $name The cookie name + * @param string $value The cookie value + * @param int|string $time The duration of the cookie; + * If integer, should be UNIX timestamp; + * If string, converted to UNIX timestamp with `strtotime`; + * @param string $path The path on the server in which the cookie will be available on + * @param string $domain The domain that the cookie is available to + * @param bool $secure Indicates that the cookie should only be transmitted over a secure + * HTTPS connection to/from the client + * @param bool $httponly When TRUE the cookie will be made accessible only through the HTTP protocol + */ + public function setCookie($name, $value, $time = null, $path = null, $domain = null, $secure = null, $httponly = null) + { + $settings = array( + 'value' => $value, + 'expires' => is_null($time) ? $this->config('cookies.lifetime') : $time, + 'path' => is_null($path) ? $this->config('cookies.path') : $path, + 'domain' => is_null($domain) ? $this->config('cookies.domain') : $domain, + 'secure' => is_null($secure) ? $this->config('cookies.secure') : $secure, + 'httponly' => is_null($httponly) ? $this->config('cookies.httponly') : $httponly + ); + $this->response->cookies->set($name, $settings); + } + + /** + * Get value of HTTP cookie from the current HTTP request + * + * Return the value of a cookie from the current HTTP request, + * or return NULL if cookie does not exist. Cookies created during + * the current request will not be available until the next request. + * + * @param string $name + * @param bool $deleteIfInvalid + * @return string|null + */ + public function getCookie($name, $deleteIfInvalid = true) + { + // Get cookie value + $value = $this->request->cookies->get($name); + + // Decode if encrypted + if ($this->config('cookies.encrypt')) { + $value = \Slim\Http\Util::decodeSecureCookie( + $value, + $this->config('cookies.secret_key'), + $this->config('cookies.cipher'), + $this->config('cookies.cipher_mode') + ); + if ($value === false && $deleteIfInvalid) { + $this->deleteCookie($name); + } + } + + /* + * transform $value to @return doc requirement. + * \Slim\Http\Util::decodeSecureCookie - is able + * to return false and we have to cast it to null. + */ + return $value === false ? null : $value; + } + + /** + * DEPRECATION WARNING! Use `setCookie` with the `cookies.encrypt` app setting set to `true`. + * + * Set encrypted HTTP cookie + * + * @param string $name The cookie name + * @param mixed $value The cookie value + * @param mixed $expires The duration of the cookie; + * If integer, should be UNIX timestamp; + * If string, converted to UNIX timestamp with `strtotime`; + * @param string $path The path on the server in which the cookie will be available on + * @param string $domain The domain that the cookie is available to + * @param bool $secure Indicates that the cookie should only be transmitted over a secure + * HTTPS connection from the client + * @param bool $httponly When TRUE the cookie will be made accessible only through the HTTP protocol + */ + public function setEncryptedCookie($name, $value, $expires = null, $path = null, $domain = null, $secure = false, $httponly = false) + { + $this->setCookie($name, $value, $expires, $path, $domain, $secure, $httponly); + } + + /** + * DEPRECATION WARNING! Use `getCookie` with the `cookies.encrypt` app setting set to `true`. + * + * Get value of encrypted HTTP cookie + * + * Return the value of an encrypted cookie from the current HTTP request, + * or return NULL if cookie does not exist. Encrypted cookies created during + * the current request will not be available until the next request. + * + * @param string $name + * @param bool $deleteIfInvalid + * @return string|bool + */ + public function getEncryptedCookie($name, $deleteIfInvalid = true) + { + return $this->getCookie($name, $deleteIfInvalid); + } + + /** + * Delete HTTP cookie (encrypted or unencrypted) + * + * Remove a Cookie from the client. This method will overwrite an existing Cookie + * with a new, empty, auto-expiring Cookie. This method's arguments must match + * the original Cookie's respective arguments for the original Cookie to be + * removed. If any of this method's arguments are omitted or set to NULL, the + * default Cookie setting values (set during Slim::init) will be used instead. + * + * @param string $name The cookie name + * @param string $path The path on the server in which the cookie will be available on + * @param string $domain The domain that the cookie is available to + * @param bool $secure Indicates that the cookie should only be transmitted over a secure + * HTTPS connection from the client + * @param bool $httponly When TRUE the cookie will be made accessible only through the HTTP protocol + */ + public function deleteCookie($name, $path = null, $domain = null, $secure = null, $httponly = null) + { + $settings = array( + 'domain' => is_null($domain) ? $this->config('cookies.domain') : $domain, + 'path' => is_null($path) ? $this->config('cookies.path') : $path, + 'secure' => is_null($secure) ? $this->config('cookies.secure') : $secure, + 'httponly' => is_null($httponly) ? $this->config('cookies.httponly') : $httponly + ); + $this->response->cookies->remove($name, $settings); + } + + /******************************************************************************** + * Helper Methods + *******************************************************************************/ + + /** + * Get the absolute path to this Slim application's root directory + * + * This method returns the absolute path to the Slim application's + * directory. If the Slim application is installed in a public-accessible + * sub-directory, the sub-directory path will be included. This method + * will always return an absolute path WITH a trailing slash. + * + * @return string + */ + public function root() + { + return rtrim($_SERVER['DOCUMENT_ROOT'], '/') . rtrim($this->request->getRootUri(), '/') . '/'; + } + + /** + * Clean current output buffer + */ + protected function cleanBuffer() + { + if (ob_get_level() !== 0) { + ob_clean(); + } + } + + /** + * Stop + * + * The thrown exception will be caught in application's `call()` method + * and the response will be sent as is to the HTTP client. + * + * @throws \Slim\Exception\Stop + */ + public function stop() + { + throw new \Slim\Exception\Stop(); + } + + /** + * Halt + * + * Stop the application and immediately send the response with a + * specific status and body to the HTTP client. This may send any + * type of response: info, success, redirect, client error, or server error. + * If you need to render a template AND customize the response status, + * use the application's `render()` method instead. + * + * @param int $status The HTTP response status + * @param string $message The HTTP response body + */ + public function halt($status, $message = '') + { + $this->cleanBuffer(); + $this->response->status($status); + $this->response->body($message); + $this->stop(); + } + + /** + * Pass + * + * The thrown exception is caught in the application's `call()` method causing + * the router's current iteration to stop and continue to the subsequent route if available. + * If no subsequent matching routes are found, a 404 response will be sent to the client. + * + * @throws \Slim\Exception\Pass + */ + public function pass() + { + $this->cleanBuffer(); + throw new \Slim\Exception\Pass(); + } + + /** + * Set the HTTP response Content-Type + * @param string $type The Content-Type for the Response (ie. text/html) + */ + public function contentType($type) + { + $this->response->headers->set('Content-Type', $type); + } + + /** + * Set the HTTP response status code + * @param int $code The HTTP response status code + */ + public function status($code) + { + $this->response->setStatus($code); + } + + /** + * Get the URL for a named route + * @param string $name The route name + * @param array $params Associative array of URL parameters and replacement values + * @throws \RuntimeException If named route does not exist + * @return string + */ + public function urlFor($name, $params = array()) + { + return $this->request->getRootUri() . $this->router->urlFor($name, $params); + } + + /** + * Redirect + * + * This method immediately redirects to a new URL. By default, + * this issues a 302 Found response; this is considered the default + * generic redirect response. You may also specify another valid + * 3xx status code if you want. This method will automatically set the + * HTTP Location header for you using the URL parameter. + * + * @param string $url The destination URL + * @param int $status The HTTP redirect status code (optional) + */ + public function redirect($url, $status = 302) + { + $this->response->redirect($url, $status); + $this->halt($status); + } + + /** + * RedirectTo + * + * Redirects to a specific named route + * + * @param string $route The route name + * @param array $params Associative array of URL parameters and replacement values + */ + public function redirectTo($route, $params = array(), $status = 302){ + $this->redirect($this->urlFor($route, $params), $status); + } + + /******************************************************************************** + * Flash Messages + *******************************************************************************/ + + /** + * Set flash message for subsequent request + * @param string $key + * @param mixed $value + */ + public function flash($key, $value) + { + if (isset($this->environment['slim.flash'])) { + $this->environment['slim.flash']->set($key, $value); + } + } + + /** + * Set flash message for current request + * @param string $key + * @param mixed $value + */ + public function flashNow($key, $value) + { + if (isset($this->environment['slim.flash'])) { + $this->environment['slim.flash']->now($key, $value); + } + } + + /** + * Keep flash messages from previous request for subsequent request + */ + public function flashKeep() + { + if (isset($this->environment['slim.flash'])) { + $this->environment['slim.flash']->keep(); + } + } + + /** + * Get all flash messages + */ + public function flashData() + { + if (isset($this->environment['slim.flash'])) { + return $this->environment['slim.flash']->getMessages(); + } + } + + /******************************************************************************** + * Hooks + *******************************************************************************/ + + /** + * Assign hook + * @param string $name The hook name + * @param mixed $callable A callable object + * @param int $priority The hook priority; 0 = high, 10 = low + */ + public function hook($name, $callable, $priority = 10) + { + if (!isset($this->hooks[$name])) { + $this->hooks[$name] = array(array()); + } + if (is_callable($callable)) { + $this->hooks[$name][(int) $priority][] = $callable; + } + } + + /** + * Invoke hook + * @param string $name The hook name + * @param mixed ... (Optional) Argument(s) for hooked functions, can specify multiple arguments + */ + public function applyHook($name) + { + if (!isset($this->hooks[$name])) { + $this->hooks[$name] = array(array()); + } + if (!empty($this->hooks[$name])) { + // Sort by priority, low to high, if there's more than one priority + if (count($this->hooks[$name]) > 1) { + ksort($this->hooks[$name]); + } + + $args = func_get_args(); + array_shift($args); + + foreach ($this->hooks[$name] as $priority) { + if (!empty($priority)) { + foreach ($priority as $callable) { + call_user_func_array($callable, $args); + } + } + } + } + } + + /** + * Get hook listeners + * + * Return an array of registered hooks. If `$name` is a valid + * hook name, only the listeners attached to that hook are returned. + * Else, all listeners are returned as an associative array whose + * keys are hook names and whose values are arrays of listeners. + * + * @param string $name A hook name (Optional) + * @return array|null + */ + public function getHooks($name = null) + { + if (!is_null($name)) { + return isset($this->hooks[(string) $name]) ? $this->hooks[(string) $name] : null; + } else { + return $this->hooks; + } + } + + /** + * Clear hook listeners + * + * Clear all listeners for all hooks. If `$name` is + * a valid hook name, only the listeners attached + * to that hook will be cleared. + * + * @param string $name A hook name (Optional) + */ + public function clearHooks($name = null) + { + if (!is_null($name) && isset($this->hooks[(string) $name])) { + $this->hooks[(string) $name] = array(array()); + } else { + foreach ($this->hooks as $key => $value) { + $this->hooks[$key] = array(array()); + } + } + } + + /******************************************************************************** + * Middleware + *******************************************************************************/ + + /** + * Add middleware + * + * This method prepends new middleware to the application middleware stack. + * The argument must be an instance that subclasses Slim_Middleware. + * + * @param \Slim\Middleware + */ + public function add(\Slim\Middleware $newMiddleware) + { + if(in_array($newMiddleware, $this->middleware)) { + $middleware_class = get_class($newMiddleware); + throw new \RuntimeException("Circular Middleware setup detected. Tried to queue the same Middleware instance ({$middleware_class}) twice."); + } + $newMiddleware->setApplication($this); + $newMiddleware->setNextMiddleware($this->middleware[0]); + array_unshift($this->middleware, $newMiddleware); + } + + /******************************************************************************** + * Runner + *******************************************************************************/ + + /** + * Run + * + * This method invokes the middleware stack, including the core Slim application; + * the result is an array of HTTP status, header, and body. These three items + * are returned to the HTTP client. + */ + public function run() + { + set_error_handler(array('\Slim\Slim', 'handleErrors')); + + //Apply final outer middleware layers + if ($this->config('debug')) { + //Apply pretty exceptions only in debug to avoid accidental information leakage in production + $this->add(new \Slim\Middleware\PrettyExceptions()); + } + + //Invoke middleware and application stack + $this->middleware[0]->call(); + + //Fetch status, header, and body + list($status, $headers, $body) = $this->response->finalize(); + + // Serialize cookies (with optional encryption) + \Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings); + + //Send headers + if (headers_sent() === false) { + //Send status + if (strpos(PHP_SAPI, 'cgi') === 0) { + header(sprintf('Status: %s', \Slim\Http\Response::getMessageForCode($status))); + } else { + header(sprintf('HTTP/%s %s', $this->config('http.version'), \Slim\Http\Response::getMessageForCode($status))); + } + + //Send headers + foreach ($headers as $name => $value) { + $hValues = explode("\n", $value); + foreach ($hValues as $hVal) { + header("$name: $hVal", false); + } + } + } + + //Send body, but only if it isn't a HEAD request + if (!$this->request->isHead()) { + echo $body; + } + + $this->applyHook('slim.after'); + + restore_error_handler(); + } + + /** + * Call + * + * This method finds and iterates all route objects that match the current request URI. + */ + public function call() + { + try { + if (isset($this->environment['slim.flash'])) { + $this->view()->setData('flash', $this->environment['slim.flash']); + } + $this->applyHook('slim.before'); + ob_start(); + $this->applyHook('slim.before.router'); + $dispatched = false; + $matchedRoutes = $this->router->getMatchedRoutes($this->request->getMethod(), $this->request->getResourceUri()); + foreach ($matchedRoutes as $route) { + try { + $this->applyHook('slim.before.dispatch'); + $dispatched = $route->dispatch(); + $this->applyHook('slim.after.dispatch'); + if ($dispatched) { + break; + } + } catch (\Slim\Exception\Pass $e) { + continue; + } + } + if (!$dispatched) { + $this->notFound(); + } + $this->applyHook('slim.after.router'); + $this->stop(); + } catch (\Slim\Exception\Stop $e) { + $this->response()->write(ob_get_clean()); + } catch (\Exception $e) { + if ($this->config('debug')) { + throw $e; + } else { + try { + $this->response()->write(ob_get_clean()); + $this->error($e); + } catch (\Slim\Exception\Stop $e) { + // Do nothing + } + } + } + } + + /******************************************************************************** + * Error Handling and Debugging + *******************************************************************************/ + + /** + * Convert errors into ErrorException objects + * + * This method catches PHP errors and converts them into \ErrorException objects; + * these \ErrorException objects are then thrown and caught by Slim's + * built-in or custom error handlers. + * + * @param int $errno The numeric type of the Error + * @param string $errstr The error message + * @param string $errfile The absolute path to the affected file + * @param int $errline The line number of the error in the affected file + * @return bool + * @throws \ErrorException + */ + public static function handleErrors($errno, $errstr = '', $errfile = '', $errline = '') + { + if (!($errno & error_reporting())) { + return; + } + + throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); + } + + /** + * Generate diagnostic template markup + * + * This method accepts a title and body content to generate an HTML document layout. + * + * @param string $title The title of the HTML template + * @param string $body The body content of the HTML template + * @return string + */ + protected static function generateTemplateMarkup($title, $body) + { + return sprintf("%s

%s

%s", $title, $title, $body); + } + + /** + * Default Not Found handler + */ + protected function defaultNotFound() + { + echo static::generateTemplateMarkup('404 Page Not Found', '

The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.

Visit the Home Page'); + } + + /** + * Default Error handler + */ + protected function defaultError($e) + { + $this->getLog()->error($e); + echo self::generateTemplateMarkup('Error', '

A website error has occurred. The website administrator has been notified of the issue. Sorry for the temporary inconvenience.

'); + } +} diff --git a/vendor/slim/slim/Slim/View.php b/vendor/slim/slim/Slim/View.php new file mode 100755 index 0000000..4059c80 --- /dev/null +++ b/vendor/slim/slim/Slim/View.php @@ -0,0 +1,282 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * @package Slim + * + * MIT LICENSE + * + * 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. + */ +namespace Slim; + +/** + * View + * + * The view is responsible for rendering a template. The view + * should subclass \Slim\View and implement this interface: + * + * public render(string $template); + * + * This method should render the specified template and return + * the resultant string. + * + * @package Slim + * @author Josh Lockhart + * @since 1.0.0 + */ +class View +{ + /** + * Data available to the view templates + * @var \Slim\Helper\Set + */ + protected $data; + + /** + * Path to templates base directory (without trailing slash) + * @var string + */ + protected $templatesDirectory; + + /** + * Constructor + */ + public function __construct() + { + $this->data = new \Slim\Helper\Set(); + } + + /******************************************************************************** + * Data methods + *******************************************************************************/ + + /** + * Does view data have value with key? + * @param string $key + * @return boolean + */ + public function has($key) + { + return $this->data->has($key); + } + + /** + * Return view data value with key + * @param string $key + * @return mixed + */ + public function get($key) + { + return $this->data->get($key); + } + + /** + * Set view data value with key + * @param string $key + * @param mixed $value + */ + public function set($key, $value) + { + $this->data->set($key, $value); + } + + /** + * Set view data value as Closure with key + * @param string $key + * @param mixed $value + */ + public function keep($key, \Closure $value) + { + $this->data->keep($key, $value); + } + + /** + * Return view data + * @return array + */ + public function all() + { + return $this->data->all(); + } + + /** + * Replace view data + * @param array $data + */ + public function replace(array $data) + { + $this->data->replace($data); + } + + /** + * Clear view data + */ + public function clear() + { + $this->data->clear(); + } + + /******************************************************************************** + * Legacy data methods + *******************************************************************************/ + + /** + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * Get data from view + */ + public function getData($key = null) + { + if (!is_null($key)) { + return isset($this->data[$key]) ? $this->data[$key] : null; + } + + return $this->data->all(); + } + + /** + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * Set data for view + */ + public function setData() + { + $args = func_get_args(); + if (count($args) === 1 && is_array($args[0])) { + $this->data->replace($args[0]); + } elseif (count($args) === 2) { + // Ensure original behavior is maintained. DO NOT invoke stored Closures. + if (is_object($args[1]) && method_exists($args[1], '__invoke')) { + $this->data->set($args[0], $this->data->protect($args[1])); + } else { + $this->data->set($args[0], $args[1]); + } + } else { + throw new \InvalidArgumentException('Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`'); + } + } + + /** + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * Append data to view + * @param array $data + */ + public function appendData($data) + { + if (!is_array($data)) { + throw new \InvalidArgumentException('Cannot append view data. Expected array argument.'); + } + $this->data->replace($data); + } + + /******************************************************************************** + * Resolve template paths + *******************************************************************************/ + + /** + * Set the base directory that contains view templates + * @param string $directory + * @throws \InvalidArgumentException If directory is not a directory + */ + public function setTemplatesDirectory($directory) + { + $this->templatesDirectory = rtrim($directory, DIRECTORY_SEPARATOR); + } + + /** + * Get templates base directory + * @return string + */ + public function getTemplatesDirectory() + { + return $this->templatesDirectory; + } + + /** + * Get fully qualified path to template file using templates base directory + * @param string $file The template file pathname relative to templates base directory + * @return string + */ + public function getTemplatePathname($file) + { + return $this->templatesDirectory . DIRECTORY_SEPARATOR . ltrim($file, DIRECTORY_SEPARATOR); + } + + /******************************************************************************** + * Rendering + *******************************************************************************/ + + /** + * Display template + * + * This method echoes the rendered template to the current output buffer + * + * @param string $template Pathname of template file relative to templates directory + * @param array $data Any additonal data to be passed to the template. + */ + public function display($template, $data = null) + { + echo $this->fetch($template, $data); + } + + /** + * Return the contents of a rendered template file + * + * @param string $template The template pathname, relative to the template base directory + * @param array $data Any additonal data to be passed to the template. + * @return string The rendered template + */ + public function fetch($template, $data = null) + { + return $this->render($template, $data); + } + + /** + * Render a template file + * + * NOTE: This method should be overridden by custom view subclasses + * + * @param string $template The template pathname, relative to the template base directory + * @param array $data Any additonal data to be passed to the template. + * @return string The rendered template + * @throws \RuntimeException If resolved template pathname is not a valid file + */ + protected function render($template, $data = null) + { + $templatePathname = $this->getTemplatePathname($template); + if (!is_file($templatePathname)) { + throw new \RuntimeException("View cannot render `$template` because the template does not exist"); + } + + $data = array_merge($this->data->all(), (array) $data); + extract($data); + ob_start(); + require $templatePathname; + + return ob_get_clean(); + } +} diff --git a/vendor/slim/slim/composer.json b/vendor/slim/slim/composer.json new file mode 100755 index 0000000..0becfe6 --- /dev/null +++ b/vendor/slim/slim/composer.json @@ -0,0 +1,24 @@ +{ + "name": "slim/slim", + "type": "library", + "description": "Slim Framework, a PHP micro framework", + "keywords": ["microframework","rest","router"], + "homepage": "http://github.com/codeguy/Slim", + "license": "MIT", + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "suggest": { + "ext-mcrypt": "Required for HTTP cookie encryption" + }, + "autoload": { + "psr-0": { "Slim": "." } + } +} diff --git a/vendor/slim/slim/index.php b/vendor/slim/slim/index.php new file mode 100755 index 0000000..355a8f5 --- /dev/null +++ b/vendor/slim/slim/index.php @@ -0,0 +1,169 @@ +get( + '/', + function () { + $template = << + + + + Slim Framework for PHP 5 + + + +
+ Slim +
+

Welcome to Slim!

+

+ Congratulations! Your Slim application is running. If this is + your first time using Slim, start with this "Hello World" Tutorial. +

+
+

Get Started

+
    +
  1. The application code is in index.php
  2. +
  3. Read the online documentation
  4. +
  5. Follow @slimphp on Twitter
  6. +
+
+
+

Slim Framework Community

+ +

Support Forum and Knowledge Base

+

+ Visit the Slim support forum and knowledge base + to read announcements, chat with fellow Slim users, ask questions, help others, or show off your cool + Slim Framework apps. +

+ +

Twitter

+

+ Follow @slimphp on Twitter to receive the very latest news + and updates about the framework. +

+
+
+

Slim Framework Extras

+

+ Custom View classes for Smarty, Twig, Mustache, and other template + frameworks are available online in a separate repository. +

+

Browse the Extras Repository

+
+ + +EOT; + echo $template; + } +); + +// POST route +$app->post( + '/post', + function () { + echo 'This is a POST route'; + } +); + +// PUT route +$app->put( + '/put', + function () { + echo 'This is a PUT route'; + } +); + +// PATCH route +$app->patch('/patch', function () { + echo 'This is a PATCH route'; +}); + +// DELETE route +$app->delete( + '/delete', + function () { + echo 'This is a DELETE route'; + } +); + +/** + * Step 4: Run the Slim application + * + * This method should be called last. This executes the Slim application + * and returns the HTTP response to the HTTP client. + */ +$app->run(); diff --git a/vendor/slim/slim/phpunit.xml.dist b/vendor/slim/slim/phpunit.xml.dist new file mode 100755 index 0000000..c4da172 --- /dev/null +++ b/vendor/slim/slim/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + + ./tests/ + + + + + + ./Slim/ + + + diff --git a/vendor/slim/slim/tests/EnvironmentTest.php b/vendor/slim/slim/tests/EnvironmentTest.php new file mode 100755 index 0000000..db54a51 --- /dev/null +++ b/vendor/slim/slim/tests/EnvironmentTest.php @@ -0,0 +1,376 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class EnvironmentTest extends PHPUnit_Framework_TestCase +{ + /** + * Default server settings assume the Slim app is installed + * in a subdirectory `foo/` directly beneath the public document + * root directory; URL rewrite is disabled; requested app + * resource is GET `/bar/xyz` with three query params. + * + * These only provide a common baseline for the following + * tests; tests are free to override these values. + */ + public function setUp() + { + $_SERVER['DOCUMENT_ROOT'] = '/var/www'; + $_SERVER['SCRIPT_FILENAME'] = '/var/www/foo/index.php'; + $_SERVER['SERVER_NAME'] = 'slim'; + $_SERVER['SERVER_PORT'] = '80'; + $_SERVER['SCRIPT_NAME'] = '/foo/index.php'; + $_SERVER['REQUEST_URI'] = '/foo/index.php/bar/xyz'; + $_SERVER['PATH_INFO'] = '/bar/xyz'; + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['QUERY_STRING'] = 'one=1&two=2&three=3'; + $_SERVER['HTTPS'] = ''; + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + unset($_SERVER['CONTENT_TYPE'], $_SERVER['CONTENT_LENGTH']); + } + + /** + * Test mock environment + * + * This should return the custom values where specified + * and the default values otherwise. + */ + public function testMockEnvironment() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PUT' + )); + $env2 = \Slim\Environment::getInstance(); + $this->assertSame($env, $env2); + $this->assertInstanceOf('\Slim\Environment', $env); + $this->assertEquals('PUT', $env['REQUEST_METHOD']); + $this->assertEquals(80, $env['SERVER_PORT']); + $this->assertNull($env['foo']); + } + + /** + * Test sets HTTP method + */ + public function testSetsHttpMethod() + { + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('GET', $env['REQUEST_METHOD']); + } + + /** + * Test parses script name and path info + * + * Pre-conditions: + * URL Rewrite is disabled; + * App installed in subdirectory; + */ + public function testParsesPathsWithoutUrlRewriteInSubdirectory() + { + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/bar/xyz', $env['PATH_INFO']); + $this->assertEquals('/foo/index.php', $env['SCRIPT_NAME']); + } + + /** + * Test parses script name and path info + * + * Pre-conditions: + * URL Rewrite is disabled; + * App installed in root directory; + */ + public function testParsesPathsWithoutUrlRewriteInRootDirectory() + { + $_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php'; + $_SERVER['REQUEST_URI'] = '/index.php/bar/xyz'; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/bar/xyz', $env['PATH_INFO']); + $this->assertEquals('/index.php', $env['SCRIPT_NAME']); + } + + /** + * Test parses script name and path info + * + * Pre-conditions: + * URL Rewrite disabled; + * App installed in root directory; + * Requested resource is "/"; + */ + public function testParsesPathsWithoutUrlRewriteInRootDirectoryForAppRootUri() + { + $_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php'; + $_SERVER['REQUEST_URI'] = '/index.php'; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + unset($_SERVER['PATH_INFO']); + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/', $env['PATH_INFO']); + $this->assertEquals('/index.php', $env['SCRIPT_NAME']); + } + + /** + * Test parses script name and path info + * + * Pre-conditions: + * URL Rewrite enabled; + * App installed in subdirectory; + */ + public function testParsesPathsWithUrlRewriteInSubdirectory() + { + $_SERVER['SCRIPT_NAME'] = '/foo/index.php'; + $_SERVER['REQUEST_URI'] = '/foo/bar/xyz'; + unset($_SERVER['PATH_INFO']); + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/bar/xyz', $env['PATH_INFO']); + $this->assertEquals('/foo', $env['SCRIPT_NAME']); + } + + /** + * Test parses script name and path info + * + * Pre-conditions: + * URL Rewrite enabled; + * App installed in root directory; + */ + public function testParsesPathsWithUrlRewriteInRootDirectory() + { + $_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php'; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['REQUEST_URI'] = '/bar/xyz'; + unset($_SERVER['PATH_INFO']); + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/bar/xyz', $env['PATH_INFO']); + $this->assertEquals('', $env['SCRIPT_NAME']); + } + + /** + * Test parses script name and path info + * + * Pre-conditions: + * URL Rewrite enabled; + * App installed in root directory; + * Requested resource is "/" + */ + public function testParsesPathsWithUrlRewriteInRootDirectoryForAppRootUri() + { + $_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php'; + $_SERVER['REQUEST_URI'] = '/'; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + unset($_SERVER['PATH_INFO']); + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/', $env['PATH_INFO']); + $this->assertEquals('', $env['SCRIPT_NAME']); + } + + /** + * Test parses query string + * + * Pre-conditions: + * $_SERVER['QUERY_STRING'] exists and is not empty; + */ + public function testParsesQueryString() + { + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('one=1&two=2&three=3', $env['QUERY_STRING']); + } + + /** + * Test removes query string from PATH_INFO when using URL Rewrite + * + * Pre-conditions: + * $_SERVER['QUERY_STRING'] exists and is not empty; + * URL Rewrite enabled; + */ + public function testRemovesQueryStringFromPathInfo() + { + $_SERVER['SCRIPT_NAME'] = '/foo/index.php'; + $_SERVER['REQUEST_URI'] = '/foo/bar/xyz?one=1&two=2&three=3'; + unset($_SERVER['PATH_INFO']); + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/bar/xyz', $env['PATH_INFO']); + } + + /** + * Test environment's PATH_INFO retains URL encoded characters (e.g. #) + * + * In earlier version, \Slim\Environment would use PATH_INFO instead + * of REQUEST_URI to determine the root URI and resource URI. + * Unfortunately, the server would URL decode the PATH_INFO string + * before it was handed to PHP. This prevented certain URL-encoded + * characters like the octothorpe from being delivered correctly to + * the Slim application environment. This test ensures the + * REQUEST_URI is used instead and parsed as expected. + */ + public function testPathInfoRetainsUrlEncodedCharacters() + { + $_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php'; + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['REQUEST_URI'] = '/foo/%23bar'; //<-- URL-encoded "#bar" + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('/foo/%23bar', $env['PATH_INFO']); + } + + /** + * Test parses query string + * + * Pre-conditions: + * $_SERVER['QUERY_STRING'] does not exist; + */ + public function testParsesQueryStringThatDoesNotExist() + { + unset($_SERVER['QUERY_STRING']); + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('', $env['QUERY_STRING']); + } + + /** + * Test SERVER_NAME is not empty + */ + public function testServerNameIsNotEmpty() + { + $env = \Slim\Environment::getInstance(true); + $this->assertFalse(empty($env['SERVER_NAME'])); + } + + /** + * Test SERVER_PORT is not empty + */ + public function testServerPortIsNotEmpty() + { + $env = \Slim\Environment::getInstance(true); + $this->assertFalse(empty($env['SERVER_PORT'])); + } + + /** + * Test unsets HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH + * + * Pre-conditions: + * HTTP_CONTENT_TYPE is sent with HTTP request; + * HTTP_CONTENT_LENGTH is sent with HTTP request; + */ + public function testUnsetsContentTypeAndContentLength() + { + $_SERVER['HTTP_CONTENT_LENGTH'] = 150; + $env = \Slim\Environment::getInstance(true); + $this->assertFalse(isset($env['HTTP_CONTENT_LENGTH'])); + } + + /** + * Test sets special request headers if not empty + * + * Pre-conditions: + * CONTENT_TYPE, CONTENT_LENGTH, X_REQUESTED_WITH are sent in client HTTP request; + * CONTENT_TYPE, CONTENT_LENGTH, X_REQUESTED_WITH are not empty; + */ + public function testSetsSpecialHeaders() + { + $_SERVER['CONTENT_TYPE'] = 'text/csv'; + $_SERVER['CONTENT_LENGTH'] = '100'; + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XmlHttpRequest'; + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('text/csv', $env['CONTENT_TYPE']); + $this->assertEquals('100', $env['CONTENT_LENGTH']); + $this->assertEquals('XmlHttpRequest', $env['HTTP_X_REQUESTED_WITH']); + } + + /** + * Tests X-HTTP-Method-Override is allowed through unmolested. + * + * Pre-conditions: + * X_HTTP_METHOD_OVERRIDE is sent in client HTTP request; + * X_HTTP_METHOD_OVERRIDE is not empty; + */ + public function testSetsHttpMethodOverrideHeader() { + $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'DELETE'; + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('DELETE', $env['HTTP_X_HTTP_METHOD_OVERRIDE']); + } + + /** + * Test detects HTTPS + * + * Pre-conditions: + * $_SERVER['HTTPS'] is set to a non-empty value; + */ + public function testHttps() + { + $_SERVER['HTTPS'] = 1; + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('https', $env['slim.url_scheme']); + } + + /** + * Test detects not HTTPS + * + * Pre-conditions: + * $_SERVER['HTTPS'] is set to an empty value; + */ + public function testNotHttps() + { + $_SERVER['HTTPS'] = ''; + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('http', $env['slim.url_scheme']); + } + + /** + * Test detects not HTTPS on IIS + * + * Pre-conditions: + * $_SERVER['HTTPS'] is set to "off"; + */ + public function testNotHttpsIIS() + { + $_SERVER['HTTPS'] = 'off'; + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('http', $env['slim.url_scheme']); + } + + /** + * Test input is an empty string (and not false) + * + * Pre-conditions: + * Input at php://input may only be read once; subsequent attempts + * will return `false`; in which case, use an empty string. + */ + public function testInputIsEmptyString() + { + $env = \Slim\Environment::getInstance(true); + $this->assertEquals('', $env['slim.input']); + } + + /** + * Test valid resource handle to php://stdErr + */ + public function testErrorResource() + { + $env = \Slim\Environment::getInstance(true); + $this->assertTrue(is_resource($env['slim.errors'])); + } +} diff --git a/vendor/slim/slim/tests/Foo.php b/vendor/slim/slim/tests/Foo.php new file mode 100755 index 0000000..d772d02 --- /dev/null +++ b/vendor/slim/slim/tests/Foo.php @@ -0,0 +1,7 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class SetTest extends PHPUnit_Framework_TestCase +{ + protected $bag; + protected $property; + + public function setUp() + { + $this->bag = new \Slim\Helper\Set(); + $this->property = new \ReflectionProperty($this->bag, 'data'); + $this->property->setAccessible(true); + } + + public function testSet() + { + $this->bag->set('foo', 'bar'); + $this->assertArrayHasKey('foo', $this->property->getValue($this->bag)); + $bag = $this->property->getValue($this->bag); + $this->assertEquals('bar', $bag['foo']); + } + + public function testGet() + { + $this->property->setValue($this->bag, array('foo' => 'bar')); + $this->assertEquals('bar', $this->bag->get('foo')); + } + + public function testGetNotExists() + { + $this->property->setValue($this->bag, array('foo' => 'bar')); + $this->assertEquals('default', $this->bag->get('abc', 'default')); + } + + public function testAdd() + { + $this->bag->replace(array( + 'abc' => '123', + 'foo' => 'bar' + )); + $this->assertArrayHasKey('abc', $this->property->getValue($this->bag)); + $this->assertArrayHasKey('foo', $this->property->getValue($this->bag)); + $bag = $this->property->getValue($this->bag); + $this->assertEquals('123', $bag['abc']); + $this->assertEquals('bar', $bag['foo']); + } + + public function testAll() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->assertEquals($data, $this->bag->all()); + } + + public function testKeys() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->assertEquals(array('abc', 'foo'), $this->bag->keys()); + } + + public function testRemove() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->bag->remove('foo'); + $this->assertEquals(array('abc' => '123'), $this->property->getValue($this->bag)); + } + + public function testClear() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->bag->clear(); + $this->assertEquals(array(), $this->property->getValue($this->bag)); + } + + public function testArrayAccessGet() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->assertEquals('bar', $this->bag['foo']); + } + + public function testArrayAccessSet() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->bag['foo'] = 'changed'; + $bag = $this->property->getValue($this->bag); + $this->assertEquals('changed', $bag['foo']); + } + + public function testArrayAccessExists() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->assertTrue(isset($this->bag['foo'])); + $this->assertFalse(isset($this->bag['bar'])); + } + + public function testArrayAccessUnset() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + unset($this->bag['foo']); + $this->assertEquals(array('abc' => '123'), $this->property->getValue($this->bag)); + } + + public function testCount() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->assertEquals(2, count($this->bag)); + } + + public function testGetIterator() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + $this->assertInstanceOf('\ArrayIterator', $this->bag->getIterator()); + } + + public function testPropertyOverloadGet() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + + $this->assertEquals('123', $this->bag->abc); + $this->assertEquals('bar', $this->bag->foo); + } + + public function testPropertyOverloadSet() + { + $this->bag->foo = 'bar'; + $this->assertArrayHasKey('foo', $this->property->getValue($this->bag)); + $this->assertEquals('bar', $this->bag->foo); + } + + public function testPropertyOverloadingIsset() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + + $this->assertTrue(isset($this->bag->abc)); + $this->assertTrue(isset($this->bag->foo)); + $this->assertFalse(isset($this->bag->foobar)); + } + + public function testPropertyOverloadingUnset() + { + $data = array( + 'abc' => '123', + 'foo' => 'bar' + ); + $this->property->setValue($this->bag, $data); + + $this->assertTrue(isset($this->bag->abc)); + unset($this->bag->abc); + $this->assertFalse(isset($this->bag->abc)); + $this->assertArrayNotHasKey('abc', $this->property->getValue($this->bag)); + $this->assertArrayHasKey('foo', $this->property->getValue($this->bag)); + } + + public function testProtect() + { + $callable = function () { + return 'foo'; + }; + $result = $this->bag->protect($callable); + + $this->assertInstanceOf('\Closure', $result); + $this->assertSame($callable, $result()); + } +} diff --git a/vendor/slim/slim/tests/Http/CookiesTest.php b/vendor/slim/slim/tests/Http/CookiesTest.php new file mode 100755 index 0000000..5ad1854 --- /dev/null +++ b/vendor/slim/slim/tests/Http/CookiesTest.php @@ -0,0 +1,92 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ +class CookiesTest extends PHPUnit_Framework_TestCase +{ + public function testSetWithStringValue() + { + $c = new \Slim\Http\Cookies(); + $c->set('foo', 'bar'); + $this->assertAttributeEquals( + array( + 'foo' => array( + 'value' => 'bar', + 'expires' => null, + 'domain' => null, + 'path' => null, + 'secure' => false, + 'httponly' => false + ) + ), + 'data', + $c + ); + } + + public function testSetWithArrayValue() + { + $now = time(); + $c = new \Slim\Http\Cookies(); + $c->set('foo', array( + 'value' => 'bar', + 'expires' => $now + 86400, + 'domain' => '.example.com', + 'path' => '/', + 'secure' => true, + 'httponly' => true + )); + $this->assertAttributeEquals( + array( + 'foo' => array( + 'value' => 'bar', + 'expires' => $now + 86400, + 'domain' => '.example.com', + 'path' => '/', + 'secure' => true, + 'httponly' => true + ) + ), + 'data', + $c + ); + } + + public function testRemove() + { + $c = new \Slim\Http\Cookies(); + $c->remove('foo'); + $prop = new \ReflectionProperty($c, 'data'); + $prop->setAccessible(true); + $cValue = $prop->getValue($c); + $this->assertEquals('', $cValue['foo']['value']); + $this->assertLessThan(time(), $cValue['foo']['expires']); + } +} diff --git a/vendor/slim/slim/tests/Http/HeadersTest.php b/vendor/slim/slim/tests/Http/HeadersTest.php new file mode 100755 index 0000000..c0466ef --- /dev/null +++ b/vendor/slim/slim/tests/Http/HeadersTest.php @@ -0,0 +1,59 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class HeadersTest extends PHPUnit_Framework_TestCase +{ + public function testNormalizesKey() + { + $h = new \Slim\Http\Headers(); + $h->set('Http_Content_Type', 'text/html'); + $prop = new \ReflectionProperty($h, 'data'); + $prop->setAccessible(true); + $this->assertArrayHasKey('Content-Type', $prop->getValue($h)); + } + + public function testExtractHeaders() + { + $test = array( + 'HTTP_HOST' => 'foo.com', + 'SERVER_NAME' => 'foo', + 'CONTENT_TYPE' => 'text/html', + 'X_FORWARDED_FOR' => '127.0.0.1' + ); + $results = \Slim\Http\Headers::extract($test); + $this->assertEquals(array( + 'HTTP_HOST' => 'foo.com', + 'CONTENT_TYPE' => 'text/html', + 'X_FORWARDED_FOR' => '127.0.0.1' + ), $results); + } +} diff --git a/vendor/slim/slim/tests/Http/RequestTest.php b/vendor/slim/slim/tests/Http/RequestTest.php new file mode 100755 index 0000000..117b72c --- /dev/null +++ b/vendor/slim/slim/tests/Http/RequestTest.php @@ -0,0 +1,949 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class RequestTest extends PHPUnit_Framework_TestCase +{ + /** + * Test sets HTTP method + */ + public function testGetMethod() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'GET' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('GET', $req->getMethod()); + } + + /** + * Test HTTP GET method detection + */ + public function testIsGet() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'GET' + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isGet()); + } + + /** + * Test HTTP POST method detection + */ + public function testIsPost() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isPost()); + } + + /** + * Test HTTP PUT method detection + */ + public function testIsPut() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PUT', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isPut()); + } + + /** + * Test HTTP DELETE method detection + */ + public function testIsDelete() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'DELETE', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isDelete()); + } + + /** + * Test HTTP OPTIONS method detection + */ + public function testIsOptions() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'OPTIONS', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isOptions()); + } + + /** + * Test HTTP HEAD method detection + */ + public function testIsHead() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'HEAD', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isHead()); + } + + /** + * Test HTTP PATCH method detection + */ + public function testIsPatch() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PATCH', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isPatch()); + } + + /** + * Test AJAX method detection w/ header + */ + public function testIsAjaxWithHeader() + { + $env = \Slim\Environment::mock(array( + 'X_REQUESTED_WITH' => 'XMLHttpRequest' + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isAjax()); + $this->assertTrue($req->isXhr()); + } + + /** + * Test AJAX method detection w/ query parameter + */ + public function testIsAjaxWithQueryParameter() + { + $env = \Slim\Environment::mock(array( + 'QUERY_STRING' => 'isajax=1', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isAjax()); + $this->assertTrue($req->isXhr()); + } + + /** + * Test AJAX method detection without header or query parameter + */ + public function testIsAjaxWithoutHeaderOrQueryParameter() + { + $env = \Slim\Environment::mock(); + $req = new \Slim\Http\Request($env); + $this->assertFalse($req->isAjax()); + $this->assertFalse($req->isXhr()); + } + + /** + * Test AJAX method detection with misspelled header + */ + public function testIsAjaxWithMisspelledHeader() + { + $env = \Slim\Environment::mock(array( + 'X_REQUESTED_WITH' => 'foo' + )); + $req = new \Slim\Http\Request($env); + $this->assertFalse($req->isAjax()); + $this->assertFalse($req->isXhr()); + } + + /** + * Test params from query string + */ + public function testParamsFromQueryString() + { + $env = \Slim\Environment::mock(array( + 'QUERY_STRING' => 'one=1&two=2&three=3' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(3, count($req->params())); + $this->assertEquals('1', $req->params('one')); + $this->assertNull($req->params('foo')); + $this->assertEquals(1, $req->params('foo', 1)); + } + + /** + * Test params from request body + */ + public function testParamsFromRequestBody() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => 'one=1&two=2&three=3', + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(5, count($req->params())); //Union of GET and POST + $this->assertEquals('bar', $req->params('foo')); + } + + /** + * Test fetch GET params + */ + public function testGet() + { + $env = \Slim\Environment::mock(array( + 'QUERY_STRING' => 'one=1&two=2&three=3' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(3, count($req->get())); + $this->assertEquals('1', $req->get('one')); + $this->assertNull($req->get('foo')); + $this->assertFalse($req->get('foo', false)); + } + + /** + * Test fetch GET params without multibyte + */ + public function testGetWithoutMultibyte() + { + $env = \Slim\Environment::mock(array( + 'QUERY_STRING' => 'one=1&two=2&three=3', + 'slim.tests.ignore_multibyte' => true + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(3, count($req->get())); + $this->assertEquals('1', $req->get('one')); + $this->assertNull($req->get('foo')); + $this->assertFalse($req->get('foo', false)); + } + + /** + * Test fetch POST params + */ + public function testPost() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(2, count($req->post())); + $this->assertEquals('bar', $req->post('foo')); + $this->assertNull($req->post('xyz')); + $this->assertFalse($req->post('xyz', false)); + } + + /** + * Test fetch POST params without multibyte + */ + public function testPostWithoutMultibyte() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15, + 'slim.tests.ignore_multibyte' => true + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(2, count($req->post())); + $this->assertEquals('bar', $req->post('foo')); + $this->assertNull($req->post('xyz')); + $this->assertFalse($req->post('xyz', false)); + } + + /** + * Test fetch POST without slim.input + */ + public function testPostWithoutInput() + { + $this->setExpectedException('RuntimeException'); + $env = \Slim\Environment::mock(); + unset($env['slim.input']); + $req = new \Slim\Http\Request($env); + $req->post('foo'); + } + + /** + * Test fetch POST params even if multipart/form-data request + */ + public function testPostWithMultipartRequest() + { + $_POST = array('foo' => 'bar'); //<-- Set by PHP + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'slim.input' => '', //<-- "php://input" is empty for multipart/form-data requests + 'CONTENT_TYPE' => 'multipart/form-data', + 'CONTENT_LENGTH' => 0 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(1, count($req->post())); + $this->assertEquals('bar', $req->post('foo')); + $this->assertNull($req->post('xyz')); + } + + /** + * Test fetch PUT params + */ + public function testPut() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PUT', + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(2, count($req->put())); + $this->assertEquals('bar', $req->put('foo')); + $this->assertEquals('bar', $req->params('foo')); + $this->assertNull($req->put('xyz')); + $this->assertFalse($req->put('xyz', false)); + } + + /** + * Test fetch PATCH params + */ + public function testPatch() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PATCH', + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(2, count($req->patch())); + $this->assertEquals('bar', $req->patch('foo')); + $this->assertEquals('bar', $req->params('foo')); + $this->assertNull($req->patch('xyz')); + $this->assertFalse($req->patch('xyz', false)); + } + + /** + * Test fetch DELETE params + */ + public function testDelete() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'DELETE', + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(2, count($req->delete())); + $this->assertEquals('bar', $req->delete('foo')); + $this->assertEquals('bar', $req->params('foo')); + $this->assertNull($req->delete('xyz')); + $this->assertFalse($req->delete('xyz', false)); + } + + /** + * Test fetch COOKIE params + */ + public function testCookies() + { + $env = \Slim\Environment::mock(array( + 'HTTP_COOKIE' => 'foo=bar; abc=123' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(2, count($req->cookies())); + $this->assertEquals('bar', $req->cookies('foo')); + $this->assertNull($req->cookies('xyz')); + } + + /** + * Test is form data + */ + public function testIsFormDataContentFormUrlencoded() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PUT', + 'slim.input' => '', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded' + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isFormData()); + } + + /** + * Test is form data + */ + public function testIsFormDataPostContentUnknown() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'slim.input' => '', + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isFormData()); + } + + /** + * Test is form data + */ + public function testIsFormDataPostContentUnknownWithMethodOverride() + { + $env = \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PUT', + )); + $env['slim.method_override.original_method'] = 'POST'; + $req = new \Slim\Http\Request($env); + $this->assertTrue($req->isPut()); + $this->assertTrue($req->isFormData()); + } + + /** + * Test is not form data + */ + public function testIsNotFormData() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'CONTENT_TYPE' => 'application/json' + )); + $req = new \Slim\Http\Request($env); + $this->assertFalse($req->isFormData()); + } + + /** + * Test headers + */ + public function testHeaders() + { + $env = \Slim\Environment::mock(array( + 'HTTP_ACCEPT_ENCODING' => 'gzip' + )); + $req = new \Slim\Http\Request($env); + $headers = $req->headers(); + $this->assertInstanceOf('\Slim\Http\Headers', $headers); + $this->assertEquals('gzip', $req->headers('HTTP_ACCEPT_ENCODING')); + $this->assertEquals('gzip', $req->headers('HTTP-ACCEPT-ENCODING')); + $this->assertEquals('gzip', $req->headers('http_accept_encoding')); + $this->assertEquals('gzip', $req->headers('http-accept-encoding')); + $this->assertEquals('gzip', $req->headers('ACCEPT_ENCODING')); + $this->assertEquals('gzip', $req->headers('ACCEPT-ENCODING')); + $this->assertEquals('gzip', $req->headers('accept_encoding')); + $this->assertEquals('gzip', $req->headers('accept-encoding')); + $this->assertNull($req->headers('foo')); + } + + /** + * Test accurately removes HTTP_ prefix from input header name + */ + public function testHeaderRemovesHttpPrefix() + { + $env = \Slim\Environment::mock(array( + 'X_HTTP_METHOD_OVERRIDE' => 'PUT', + 'CONTENT_TYPE' => 'application/json' + )); + //fwrite(fopen('php://stdout', 'w'), print_r($env, true)); + $req = new \Slim\Http\Request($env); + $this->assertEquals('PUT', $req->headers('X_HTTP_METHOD_OVERRIDE')); + $this->assertNull($req->headers('X_METHOD_OVERRIDE')); //<-- Ensures `HTTP_` is not removed if not prefix + $this->assertEquals('application/json', $req->headers('HTTP_CONTENT_TYPE')); //<-- Ensures `HTTP_` is removed if prefix + } + + /** + * Test get body + */ + public function testGetBodyWhenExists() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('foo=bar&abc=123', $req->getBody()); + } + + /** + * Test get body + */ + public function testGetBodyWhenNotExists() + { + $env = \Slim\Environment::mock(); + $req = new \Slim\Http\Request($env); + $this->assertEquals('', $req->getBody()); + } + + /** + * Test get content type + */ + public function testGetContentTypeWhenExists() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'CONTENT_TYPE' => 'application/json; charset=ISO-8859-4' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('application/json; charset=ISO-8859-4', $req->getContentType()); + } + + /** + * Test get content type for built-in PHP server + */ + public function testGetContentTypeForBuiltInServer() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'HTTP_CONTENT_TYPE' => 'application/json; charset=ISO-8859-4' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('application/json; charset=ISO-8859-4', $req->getContentType()); + } + + /** + * Test get content type + */ + public function testGetContentTypeWhenNotExists() + { + $env = \Slim\Environment::mock(); + $req = new \Slim\Http\Request($env); + $this->assertNull($req->getContentType()); + } + + /** + * Test get content type with built-in server + */ + public function testGetContentTypeWithBuiltInServer() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'HTTP_CONTENT_TYPE' => 'application/json; charset=ISO-8859-4' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('application/json; charset=ISO-8859-4', $req->getContentType()); + } + + /** + * Test get media type + */ + public function testGetMediaTypeWhenExists() + { + $env = \Slim\Environment::mock(array( + 'CONTENT_TYPE' => 'application/json;charset=utf-8' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('application/json', $req->getMediaType()); + } + + /** + * Test get media type + */ + public function testGetMediaTypeWhenNotExists() + { + $env = \Slim\Environment::mock(); + $req = new \Slim\Http\Request($env); + $this->assertNull($req->getMediaType()); + } + + /** + * Test get media type + */ + public function testGetMediaTypeWhenNoParamsExist() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'CONTENT_TYPE' => 'application/json' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('application/json', $req->getMediaType()); + } + + /** + * Test get media type params + */ + public function testGetMediaTypeParams() + { + $env = \Slim\Environment::mock(array( + 'CONTENT_TYPE' => 'application/json; charset=ISO-8859-4' + )); + $req = new \Slim\Http\Request($env); + $params = $req->getMediaTypeParams(); + $this->assertEquals(1, count($params)); + $this->assertArrayHasKey('charset', $params); + $this->assertEquals('ISO-8859-4', $params['charset']); + } + + /** + * Test get media type params + */ + public function testGetMediaTypeParamsWhenNotExists() + { + $env = \Slim\Environment::mock(); + $req = new \Slim\Http\Request($env); + $params = $req->getMediaTypeParams(); + $this->assertTrue(is_array($params)); + $this->assertEquals(0, count($params)); + } + + /** + * Test get content charset + */ + public function testGetContentCharset() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'CONTENT_TYPE' => 'application/json; charset=ISO-8859-4' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('ISO-8859-4', $req->getContentCharset()); + } + + /** + * Test get content charset + */ + public function testGetContentCharsetWhenNotExists() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + 'CONTENT_TYPE' => 'application/json' + )); + $req = new \Slim\Http\Request($env); + $this->assertNull($req->getContentCharset()); + } + + /** + * Test get content length + */ + public function testGetContentLength() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => 'foo=bar&abc=123', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 15 + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(15, $req->getContentLength()); + } + + /** + * Test get content length + */ + public function testGetContentLengthWhenNotExists() + { + $env = \Slim\Environment::mock(array( + 'slim.input' => '', + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals(0, $req->getContentLength()); + } + + /** + * Test get host + */ + public function testGetHost() + { + $env = \Slim\Environment::mock(array( + 'SERVER_NAME' => 'slim', + 'HTTP_HOST' => 'slimframework.com' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('slimframework.com', $req->getHost()); //Uses HTTP_HOST if available + } + + /** + * Test get host when it has a port number + */ + public function testGetHostAndStripPort() + { + $env = \Slim\Environment::mock(array( + 'SERVER_NAME' => 'slim', + 'HTTP_HOST' => 'slimframework.com:80' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('slimframework.com', $req->getHost()); //Uses HTTP_HOST if available + } + + /** + * Test get host + */ + public function testGetHostWhenNotExists() + { + $env = \Slim\Environment::mock(array( + 'SERVER_NAME' => 'slim', + 'HTTP_HOST' => 'slimframework.com' + )); + unset($env['HTTP_HOST']); + $req = new \Slim\Http\Request($env); + $this->assertEquals('slim', $req->getHost()); //Uses SERVER_NAME as backup + } + + /** + * Test get host with port + */ + public function testGetHostWithPort() + { + $env = \Slim\Environment::mock(array( + 'HTTP_HOST' => 'slimframework.com', + 'SERVER_NAME' => 'slim', + 'SERVER_PORT' => 80, + 'slim.url_scheme' => 'http' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('slimframework.com:80', $req->getHostWithPort()); + } + + /** + * Test get host with port doesn't duplicate port numbers + */ + public function testGetHostDoesntDuplicatePort() + { + $env = \Slim\Environment::mock(array( + 'HTTP_HOST' => 'slimframework.com:80', + 'SERVER_NAME' => 'slim', + 'SERVER_PORT' => 80, + 'slim.url_scheme' => 'http' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('slimframework.com:80', $req->getHostWithPort()); + } + + /** + * Test get port + */ + public function testGetPort() + { + $env = \Slim\Environment::mock(array( + 'SERVER_PORT' => 80 + )); + $req = new \Slim\Http\Request($env); + $this->assertTrue(is_integer($req->getPort())); + $this->assertEquals(80, $req->getPort()); + } + + /** + * Test get scheme + */ + public function testGetSchemeIfHttp() + { + $env = \Slim\Environment::mock(array( + 'slim.url_scheme' => 'http' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('http', $req->getScheme()); + } + + /** + * Test get scheme + */ + public function testGetSchemeIfHttps() + { + $env = \Slim\Environment::mock(array( + 'slim.url_scheme' => 'https', + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('https', $req->getScheme()); + } + + /** + * Test get [script name, root uri, path, path info, resource uri] in subdirectory without htaccess + */ + public function testAppPathsInSubdirectoryWithoutHtaccess() + { + $env = \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo/index.php', //<-- Physical + 'PATH_INFO' => '/bar/xyz', //<-- Virtual + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('/foo/index.php', $req->getScriptName()); + $this->assertEquals('/foo/index.php', $req->getRootUri()); + $this->assertEquals('/foo/index.php/bar/xyz', $req->getPath()); + $this->assertEquals('/bar/xyz', $req->getPathInfo()); + $this->assertEquals('/bar/xyz', $req->getResourceUri()); + } + + /** + * Test get [script name, root uri, path, path info, resource uri] in subdirectory with htaccess + */ + public function testAppPathsInSubdirectoryWithHtaccess() + { + $env = \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar/xyz', //<-- Virtual + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('/foo', $req->getScriptName()); + $this->assertEquals('/foo', $req->getRootUri()); + $this->assertEquals('/foo/bar/xyz', $req->getPath()); + $this->assertEquals('/bar/xyz', $req->getPathInfo()); + $this->assertEquals('/bar/xyz', $req->getResourceUri()); + } + + /** + * Test get [script name, root uri, path, path info, resource uri] in root directory without htaccess + */ + public function testAppPathsInRootDirectoryWithoutHtaccess() + { + $env = \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', //<-- Physical + 'PATH_INFO' => '/bar/xyz', //<-- Virtual + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('/index.php', $req->getScriptName()); + $this->assertEquals('/index.php', $req->getRootUri()); + $this->assertEquals('/index.php/bar/xyz', $req->getPath()); + $this->assertEquals('/bar/xyz', $req->getPathInfo()); + $this->assertEquals('/bar/xyz', $req->getResourceUri()); + } + + /** + * Test get [script name, root uri, path, path info, resource uri] in root directory with htaccess + */ + public function testAppPathsInRootDirectoryWithHtaccess() + { + $env = \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '', //<-- Physical + 'PATH_INFO' => '/bar/xyz', //<-- Virtual + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('', $req->getScriptName()); + $this->assertEquals('', $req->getRootUri()); + $this->assertEquals('/bar/xyz', $req->getPath()); + $this->assertEquals('/bar/xyz', $req->getPathInfo()); + $this->assertEquals('/bar/xyz', $req->getResourceUri()); + } + + /** + * Test get URL + */ + public function testGetUrl() + { + $env = \Slim\Environment::mock(array( + 'HTTP_HOST' => 'slimframework.com', + 'SERVER_NAME' => 'slim', + 'SERVER_PORT' => 80, + 'slim.url_scheme' => 'http' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('http://slimframework.com', $req->getUrl()); + } + + /** + * Test get URL + */ + public function testGetUrlWithCustomPort() + { + $env = \Slim\Environment::mock(array( + 'HTTP_HOST' => 'slimframework.com', + 'SERVER_NAME' => 'slim', + 'SERVER_PORT' => 8080, + 'slim.url_scheme' => 'http' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('http://slimframework.com:8080', $req->getUrl()); + } + + /** + * Test get URL + */ + public function testGetUrlWithHttps() + { + $env = \Slim\Environment::mock(array( + 'HTTP_HOST' => 'slimframework.com', + 'SERVER_NAME' => 'slim', + 'SERVER_PORT' => 443, + 'slim.url_scheme' => 'https' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('https://slimframework.com', $req->getUrl()); + } + + /** + * Test get IP + * @dataProvider dataTestIp + */ + public function testGetIp(array $server, $expected) + { + $env = \Slim\Environment::mock($server); + $req = new \Slim\Http\Request($env); + $this->assertEquals($expected, $req->getIp()); + } + + public function dataTestIp() + { + return array( + array(array('REMOTE_ADDR' => '127.0.0.1'), '127.0.0.1'), + array(array('REMOTE_ADDR' => '127.0.0.1', 'CLIENT_IP' => '127.0.0.2'), '127.0.0.2'), + array(array('REMOTE_ADDR' => '127.0.0.1', 'CLIENT_IP' => '127.0.0.2', 'X_FORWARDED_FOR' => '127.0.0.3'), '127.0.0.3'), + array(array('REMOTE_ADDR' => '127.0.0.1', 'CLIENT_IP' => '127.0.0.2', 'HTTP_X_FORWARDED_FOR' => '127.0.0.4'), '127.0.0.4'), + array(array('REMOTE_ADDR' => '127.0.0.1', 'CLIENT_IP' => '127.0.0.2', 'X_FORWARDED_FOR' => '127.0.0.3', 'HTTP_X_FORWARDED_FOR' => '127.0.0.4'), '127.0.0.3'), + ); + } + + /** + * Test get referer + */ + public function testGetReferrer() + { + $env = \Slim\Environment::mock(array( + 'HTTP_REFERER' => 'http://foo.com' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('http://foo.com', $req->getReferrer()); + $this->assertEquals('http://foo.com', $req->getReferer()); + } + + /** + * Test get referer + */ + public function testGetReferrerWhenNotExists() + { + $env = \Slim\Environment::mock(); + $req = new \Slim\Http\Request($env); + $this->assertNull($req->getReferrer()); + $this->assertNull($req->getReferer()); + } + + /** + * Test get user agent string + */ + public function testGetUserAgent() + { + $env = \Slim\Environment::mock(array( + 'HTTP_USER_AGENT' => 'user-agent-string' + )); + $req = new \Slim\Http\Request($env); + $this->assertEquals('user-agent-string', $req->getUserAgent()); + } + + /** + * Test get user agent string when not set + */ + public function testGetUserAgentWhenNotExists() + { + $env = \Slim\Environment::mock(); + unset($env['HTTP_USER_AGENT']); + $req = new \Slim\Http\Request($env); + $this->assertNull($req->getUserAgent()); + } +} diff --git a/vendor/slim/slim/tests/Http/ResponseTest.php b/vendor/slim/slim/tests/Http/ResponseTest.php new file mode 100755 index 0000000..c251fa1 --- /dev/null +++ b/vendor/slim/slim/tests/Http/ResponseTest.php @@ -0,0 +1,271 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class ResponseTest extends PHPUnit_Framework_TestCase +{ + public function testConstructWithoutArgs() + { + $res = new \Slim\Http\Response(); + + $this->assertAttributeEquals(200, 'status', $res); + $this->assertAttributeEquals('', 'body', $res); + } + + public function testConstructWithArgs() + { + $res = new \Slim\Http\Response('Foo', 201); + + $this->assertAttributeEquals(201, 'status', $res); + $this->assertAttributeEquals('Foo', 'body', $res); + } + + public function testGetStatus() + { + $res = new \Slim\Http\Response(); + + $this->assertEquals(200, $res->getStatus()); + } + + public function testSetStatus() + { + $res = new \Slim\Http\Response(); + $res->setStatus(301); + + $this->assertAttributeEquals(301, 'status', $res); + } + + /** + * DEPRECATION WARNING! + */ + public function testStatusGetOld() + { + $res = new \Slim\Http\Response('', 201); + $this->assertEquals(201, $res->status()); + } + + /** + * DEPRECATION WARNING! + */ + public function testStatusSetOld() + { + $res = new \Slim\Http\Response(); + $prop = new \ReflectionProperty($res, 'status'); + $prop->setAccessible(true); + $res->status(301); + + $this->assertEquals(301, $prop->getValue($res)); + } + + public function testGetBody() + { + $res = new \Slim\Http\Response(); + $property = new \ReflectionProperty($res, 'body'); + $property->setAccessible(true); + $property->setValue($res, 'foo'); + + $this->assertEquals('foo', $res->getBody()); + } + + public function testSetBody() + { + $res = new \Slim\Http\Response('bar'); + $res->setBody('foo'); // <-- Should replace body + + $this->assertAttributeEquals('foo', 'body', $res); + } + + public function testWrite() + { + $res = new \Slim\Http\Response(); + $property = new \ReflectionProperty($res, 'body'); + $property->setAccessible(true); + $property->setValue($res, 'foo'); + $res->write('bar'); // <-- Should append to body + + $this->assertAttributeEquals('foobar', 'body', $res); + } + + public function testLength() + { + $res = new \Slim\Http\Response('foo'); // <-- Sets body and length + + $this->assertEquals(3, $res->getLength()); + } + + public function testFinalize() + { + $res = new \Slim\Http\Response(); + $resFinal = $res->finalize(); + + $this->assertTrue(is_array($resFinal)); + $this->assertEquals(3, count($resFinal)); + $this->assertEquals(200, $resFinal[0]); + $this->assertInstanceOf('\Slim\Http\Headers', $resFinal[1]); + $this->assertEquals('', $resFinal[2]); + } + + public function testFinalizeWithEmptyBody() + { + $res = new \Slim\Http\Response('Foo', 304); + $resFinal = $res->finalize(); + + $this->assertEquals('', $resFinal[2]); + } + + public function testRedirect() + { + $res = new \Slim\Http\Response(); + $res->redirect('/foo'); + + $pStatus = new \ReflectionProperty($res, 'status'); + $pStatus->setAccessible(true); + + $this->assertEquals(302, $pStatus->getValue($res)); + $this->assertEquals('/foo', $res->headers['Location']); + } + + public function testIsEmpty() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(404); + $r2->setStatus(201); + $this->assertFalse($r1->isEmpty()); + $this->assertTrue($r2->isEmpty()); + } + + public function testIsClientError() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(404); + $r2->setStatus(500); + $this->assertTrue($r1->isClientError()); + $this->assertFalse($r2->isClientError()); + } + + public function testIsForbidden() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(403); + $r2->setStatus(500); + $this->assertTrue($r1->isForbidden()); + $this->assertFalse($r2->isForbidden()); + } + + public function testIsInformational() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(100); + $r2->setStatus(200); + $this->assertTrue($r1->isInformational()); + $this->assertFalse($r2->isInformational()); + } + + public function testIsNotFound() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(404); + $r2->setStatus(200); + $this->assertTrue($r1->isNotFound()); + $this->assertFalse($r2->isNotFound()); + } + + public function testIsOk() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(200); + $r2->setStatus(201); + $this->assertTrue($r1->isOk()); + $this->assertFalse($r2->isOk()); + } + + public function testIsSuccessful() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r3 = new \Slim\Http\Response(); + $r1->setStatus(200); + $r2->setStatus(201); + $r3->setStatus(302); + $this->assertTrue($r1->isSuccessful()); + $this->assertTrue($r2->isSuccessful()); + $this->assertFalse($r3->isSuccessful()); + } + + public function testIsRedirect() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(307); + $r2->setStatus(304); + $this->assertTrue($r1->isRedirect()); + $this->assertFalse($r2->isRedirect()); + } + + public function testIsRedirection() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r3 = new \Slim\Http\Response(); + $r1->setStatus(307); + $r2->setStatus(304); + $r3->setStatus(200); + $this->assertTrue($r1->isRedirection()); + $this->assertTrue($r2->isRedirection()); + $this->assertFalse($r3->isRedirection()); + } + + public function testIsServerError() + { + $r1 = new \Slim\Http\Response(); + $r2 = new \Slim\Http\Response(); + $r1->setStatus(500); + $r2->setStatus(400); + $this->assertTrue($r1->isServerError()); + $this->assertFalse($r2->isServerError()); + } + + public function testMessageForCode() + { + $this->assertEquals('200 OK', \Slim\Http\Response::getMessageForCode(200)); + } + + public function testMessageForCodeWithInvalidCode() + { + $this->assertNull(\Slim\Http\Response::getMessageForCode(600)); + } +} diff --git a/vendor/slim/slim/tests/Http/UtilTest.php b/vendor/slim/slim/tests/Http/UtilTest.php new file mode 100755 index 0000000..9abcfab --- /dev/null +++ b/vendor/slim/slim/tests/Http/UtilTest.php @@ -0,0 +1,445 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class SlimHttpUtilTest extends PHPUnit_Framework_TestCase +{ + /** + * Test strip slashes when magic quotes disabled + */ + public function testStripSlashesWithoutMagicQuotes() + { + $data = "This should have \"quotes\" in it"; + $stripped = \Slim\Http\Util::stripSlashesIfMagicQuotes($data, false); + $this->assertEquals($data, $stripped); + } + + /** + * Test strip slashes from array when magic quotes disabled + */ + public function testStripSlashesFromArrayWithoutMagicQuotes() + { + $data = array("This should have \"quotes\" in it", "And this \"too\" has quotes"); + $stripped = \Slim\Http\Util::stripSlashesIfMagicQuotes($data, false); + $this->assertEquals($data, $stripped); + } + + /** + * Test strip slashes when magic quotes enabled + */ + public function testStripSlashesWithMagicQuotes() + { + $data = "This should have \"quotes\" in it"; + $stripped = \Slim\Http\Util::stripSlashesIfMagicQuotes($data, true); + $this->assertEquals('This should have "quotes" in it', $stripped); + } + + /** + * Test strip slashes from array when magic quotes enabled + */ + public function testStripSlashesFromArrayWithMagicQuotes() + { + $data = array("This should have \"quotes\" in it", "And this \"too\" has quotes"); + $stripped = \Slim\Http\Util::stripSlashesIfMagicQuotes($data, true); + $this->assertEquals($data = array('This should have "quotes" in it', 'And this "too" has quotes'), $stripped); + } + + /** + * Test encrypt and decrypt with valid data + */ + public function testEncryptAndDecryptWithValidData() + { + $data = 'foo'; + $key = 'secret'; + $iv = md5('initializationVector'); + $encrypted = \Slim\Http\Util::encrypt($data, $key, $iv); + $decrypted = \Slim\Http\Util::decrypt($encrypted, $key, $iv); + $this->assertEquals($data, $decrypted); + $this->assertTrue($data !== $encrypted); + } + + /** + * Test encrypt when data is empty string + */ + public function testEncryptWhenDataIsEmptyString() + { + $data = ''; + $key = 'secret'; + $iv = md5('initializationVector'); + $encrypted = \Slim\Http\Util::encrypt($data, $key, $iv); + $this->assertEquals('', $encrypted); + } + + /** + * Test decrypt when data is empty string + */ + public function testDecryptWhenDataIsEmptyString() + { + $data = ''; + $key = 'secret'; + $iv = md5('initializationVector'); + $decrypted = \Slim\Http\Util::decrypt($data, $key, $iv); + $this->assertEquals('', $decrypted); + } + + /** + * Test encrypt when IV and key sizes are too long + */ + public function testEncryptAndDecryptWhenKeyAndIvAreTooLong() + { + $data = 'foo'; + $key = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; + $iv = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; + $encrypted = \Slim\Http\Util::encrypt($data, $key, $iv); + $decrypted = \Slim\Http\Util::decrypt($encrypted, $key, $iv); + $this->assertEquals($data, $decrypted); + $this->assertTrue($data !== $encrypted); + } + + public function testEncodeAndDecodeSecureCookieWithValidData() + { + //Prepare cookie value + $value = 'foo'; + $expires = time() + 86400; + $secret = 'password'; + $algorithm = MCRYPT_RIJNDAEL_256; + $mode = MCRYPT_MODE_CBC; + $encodedValue = \Slim\Http\Util::encodeSecureCookie($value, $expires, $secret, $algorithm, $mode); + $decodedValue = \Slim\Http\Util::decodeSecureCookie($encodedValue, $secret, $algorithm, $mode); + + //Test secure cookie value + $parts = explode('|', $encodedValue); + $this->assertEquals(3, count($parts)); + $this->assertEquals($expires, $parts[0]); + $this->assertEquals($value, $decodedValue); + } + + /** + * Test encode/decode secure cookie with old expiration + * + * In this test, the expiration date is purposefully set to a time before now. + * When decoding the encoded cookie value, FALSE is returned since the cookie + * will have expired before it is decoded. + */ + public function testEncodeAndDecodeSecureCookieWithOldExpiration() + { + $value = 'foo'; + $expires = time() - 100; + $secret = 'password'; + $algorithm = MCRYPT_RIJNDAEL_256; + $mode = MCRYPT_MODE_CBC; + $encodedValue = \Slim\Http\Util::encodeSecureCookie($value, $expires, $secret, $algorithm, $mode); + $decodedValue = \Slim\Http\Util::decodeSecureCookie($encodedValue, $secret, $algorithm, $mode); + $this->assertFalse($decodedValue); + } + + /** + * Test encode/decode secure cookie with tampered data + * + * In this test, the encoded data is purposefully changed to simulate someone + * tampering with the client-side cookie data. When decoding the encoded cookie value, + * FALSE is returned since the verification key will not match. + */ + public function testEncodeAndDecodeSecureCookieWithTamperedData() + { + $value = 'foo'; + $expires = time() + 86400; + $secret = 'password'; + $algorithm = MCRYPT_RIJNDAEL_256; + $mode = MCRYPT_MODE_CBC; + $encodedValue = \Slim\Http\Util::encodeSecureCookie($value, $expires, $secret, $algorithm, $mode); + $encodedValueParts = explode('|', $encodedValue); + $encodedValueParts[1] = $encodedValueParts[1] . 'changed'; + $encodedValue = implode('|', $encodedValueParts); + $decodedValue = \Slim\Http\Util::decodeSecureCookie($encodedValue, $secret, $algorithm, $mode); + $this->assertFalse($decodedValue); + } + + public function testSetCookieHeaderWithNameAndValue() + { + $name = 'foo'; + $value = 'bar'; + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, $value); + $this->assertEquals('foo=bar', $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueWhenCookieAlreadySet() + { + $name = 'foo'; + $value = 'bar'; + $header = array('Set-Cookie' => 'one=two'); + \Slim\Http\Util::setCookieHeader($header, $name, $value); + $this->assertEquals("one=two\nfoo=bar", $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomain() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain + )); + $this->assertEquals('foo=bar; domain=foo.com', $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomainAndPath() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $path = '/foo'; + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain, + 'path' => $path + )); + $this->assertEquals('foo=bar; domain=foo.com; path=/foo', $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomainAndPathAndExpiresAsString() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $path = '/foo'; + $expires = '2 days'; + $expiresFormat = gmdate('D, d-M-Y H:i:s e', strtotime($expires)); + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain, + 'path' => '/foo', + 'expires' => $expires + )); + $this->assertEquals('foo=bar; domain=foo.com; path=/foo; expires=' . $expiresFormat, $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomainAndPathAndExpiresAsInteger() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $path = '/foo'; + $expires = strtotime('2 days'); + $expiresFormat = gmdate('D, d-M-Y H:i:s e', $expires); + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain, + 'path' => '/foo', + 'expires' => $expires + )); + $this->assertEquals('foo=bar; domain=foo.com; path=/foo; expires=' . $expiresFormat, $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomainAndPathAndExpiresAsZero() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $path = '/foo'; + $expires = 0; + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain, + 'path' => '/foo', + 'expires' => $expires + )); + $this->assertEquals('foo=bar; domain=foo.com; path=/foo', $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomainAndPathAndExpiresAndSecure() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $path = '/foo'; + $expires = strtotime('2 days'); + $expiresFormat = gmdate('D, d-M-Y H:i:s e', $expires); + $secure = true; + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain, + 'path' => '/foo', + 'expires' => $expires, + 'secure' => $secure + )); + $this->assertEquals('foo=bar; domain=foo.com; path=/foo; expires=' . $expiresFormat . '; secure', $header['Set-Cookie']); + } + + public function testSetCookieHeaderWithNameAndValueAndDomainAndPathAndExpiresAndSecureAndHttpOnly() + { + $name = 'foo'; + $value = 'bar'; + $domain = 'foo.com'; + $path = '/foo'; + $expires = strtotime('2 days'); + $expiresFormat = gmdate('D, d-M-Y H:i:s e', $expires); + $secure = true; + $httpOnly = true; + $header = array(); + \Slim\Http\Util::setCookieHeader($header, $name, array( + 'value' => $value, + 'domain' => $domain, + 'path' => '/foo', + 'expires' => $expires, + 'secure' => $secure, + 'httponly' => $httpOnly + )); + $this->assertEquals('foo=bar; domain=foo.com; path=/foo; expires=' . $expiresFormat . '; secure; HttpOnly', $header['Set-Cookie']); + } + + /** + * Test serializeCookies and decrypt with string expires + * + * In this test a cookie with a string typed value for 'expires' is set, + * which should be parsed by `strtotime` to a timestamp when it's added to + * the headers; this timestamp should then be correctly parsed, and the + * value correctly decrypted, by `decodeSecureCookie`. + */ + public function testSerializeCookiesAndDecryptWithStringExpires() + { + $value = 'bar'; + + $headers = new \Slim\Http\Headers(); + + $settings = array( + 'cookies.encrypt' => true, + 'cookies.secret_key' => 'secret', + 'cookies.cipher' => MCRYPT_RIJNDAEL_256, + 'cookies.cipher_mode' => MCRYPT_MODE_CBC + ); + + $cookies = new \Slim\Http\Cookies(); + $cookies->set('foo', array( + 'value' => $value, + 'expires' => '1 hour' + )); + + \Slim\Http\Util::serializeCookies($headers, $cookies, $settings); + + $encrypted = $headers->get('Set-Cookie'); + $encrypted = strstr($encrypted, ';', true); + $encrypted = urldecode(substr(strstr($encrypted, '='), 1)); + + $decrypted = \Slim\Http\Util::decodeSecureCookie( + $encrypted, + $settings['cookies.secret_key'], + $settings['cookies.cipher'], + $settings['cookies.cipher_mode'] + ); + + $this->assertEquals($value, $decrypted); + $this->assertTrue($value !== $encrypted); + } + + public function testDeleteCookieHeaderWithSurvivingCookie() + { + $header = array('Set-Cookie' => "foo=bar\none=two"); + \Slim\Http\Util::deleteCookieHeader($header, 'foo'); + $this->assertEquals(1, preg_match("@^one=two\nfoo=; expires=@", $header['Set-Cookie'])); + } + + public function testDeleteCookieHeaderWithoutSurvivingCookie() + { + $header = array('Set-Cookie' => "foo=bar"); + \Slim\Http\Util::deleteCookieHeader($header, 'foo'); + $this->assertEquals(1, preg_match("@foo=; expires=@", $header['Set-Cookie'])); + } + + public function testDeleteCookieHeaderWithMatchingDomain() + { + $header = array('Set-Cookie' => "foo=bar; domain=foo.com"); + \Slim\Http\Util::deleteCookieHeader($header, 'foo', array( + 'domain' => 'foo.com' + )); + $this->assertEquals(1, preg_match("@foo=; domain=foo.com; expires=@", $header['Set-Cookie'])); + } + + public function testDeleteCookieHeaderWithoutMatchingDomain() + { + $header = array('Set-Cookie' => "foo=bar; domain=foo.com"); + \Slim\Http\Util::deleteCookieHeader($header, 'foo', array( + 'domain' => 'bar.com' + )); + $this->assertEquals(1, preg_match("@foo=bar; domain=foo\.com\nfoo=; domain=bar\.com@", $header['Set-Cookie'])); + } + + /** + * Test parses Cookie: HTTP header + */ + public function testParsesCookieHeader() + { + $header = 'foo=bar; one=two; colors=blue'; + $result = \Slim\Http\Util::parseCookieHeader($header); + $this->assertEquals(3, count($result)); + $this->assertEquals('bar', $result['foo']); + $this->assertEquals('two', $result['one']); + $this->assertEquals('blue', $result['colors']); + } + + /** + * Test parses Cookie: HTTP header with `=` in the cookie value + */ + public function testParsesCookieHeaderWithEqualSignInValue() + { + $header = 'foo=bar; one=two=; colors=blue'; + $result = \Slim\Http\Util::parseCookieHeader($header); + $this->assertEquals(3, count($result)); + $this->assertEquals('bar', $result['foo']); + $this->assertEquals('two=', $result['one']); + $this->assertEquals('blue', $result['colors']); + } + + public function testParsesCookieHeaderWithCommaSeparator() + { + $header = 'foo=bar, one=two, colors=blue'; + $result = \Slim\Http\Util::parseCookieHeader($header); + $this->assertEquals(3, count($result)); + $this->assertEquals('bar', $result['foo']); + $this->assertEquals('two', $result['one']); + $this->assertEquals('blue', $result['colors']); + } + + public function testPrefersLeftmostCookieWhenManyCookiesWithSameName() + { + $header = 'foo=bar; foo=beer'; + $result = \Slim\Http\Util::parseCookieHeader($header); + $this->assertEquals('bar', $result['foo']); + } +} diff --git a/vendor/slim/slim/tests/LogTest.php b/vendor/slim/slim/tests/LogTest.php new file mode 100755 index 0000000..28f99e8 --- /dev/null +++ b/vendor/slim/slim/tests/LogTest.php @@ -0,0 +1,208 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class MyWriter +{ + public function write( $object, $level ) + { + echo (string) $object; + + return true; + } +} + +class LogTest extends PHPUnit_Framework_TestCase +{ + public function testEnabled() + { + $log = new \Slim\Log(new MyWriter()); + $this->assertTrue($log->isEnabled()); //<-- Default case + $log->setEnabled(true); + $this->assertTrue($log->isEnabled()); + $log->setEnabled(false); + $this->assertFalse($log->isEnabled()); + } + + public function testGetLevel() + { + $log = new \Slim\Log(new MyWriter()); + $this->assertEquals(\Slim\Log::DEBUG, $log->getLevel()); + } + + public function testSetLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::WARN); + $this->assertEquals(\Slim\Log::WARN, $log->getLevel()); + } + + public function testSetInvalidLevel() + { + $this->setExpectedException('InvalidArgumentException'); + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::DEBUG + 1); + } + + public function testLogDebug() + { + $this->expectOutputString('Debug'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->debug('Debug'); + $this->assertTrue($result); + } + + public function testLogDebugExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::INFO); + $this->assertFalse($log->debug('Debug')); + } + + public function testLogInfo() + { + $this->expectOutputString('Info'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->info('Info'); + $this->assertTrue($result); + } + + public function testLogInfoExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::NOTICE); + $this->assertFalse($log->info('Info')); + } + + public function testLogNotice() + { + $this->expectOutputString('Notice'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->notice('Notice'); + $this->assertTrue($result); + } + + public function testLogNoticeExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::WARN); + $this->assertFalse($log->info('Info')); + } + + public function testLogWarn() + { + $this->expectOutputString('Warn'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->warning('Warn'); + $this->assertTrue($result); + } + + public function testLogWarnExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::ERROR); + $this->assertFalse($log->warning('Warn')); + } + + public function testLogError() + { + $this->expectOutputString('Error'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->error('Error'); + $this->assertTrue($result); + } + + public function testLogErrorExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::CRITICAL); + $this->assertFalse($log->error('Error')); + } + + public function testLogCritical() + { + $this->expectOutputString('Critical'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->critical('Critical'); + $this->assertTrue($result); + } + + public function testLogCriticalExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::ALERT); + $this->assertFalse($log->critical('Critical')); + } + + public function testLogAlert() + { + $this->expectOutputString('Alert'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->alert('Alert'); + $this->assertTrue($result); + } + + public function testLogAlertExcludedByLevel() + { + $log = new \Slim\Log(new MyWriter()); + $log->setLevel(\Slim\Log::EMERGENCY); + $this->assertFalse($log->alert('Alert')); + } + + public function testLogEmergency() + { + $this->expectOutputString('Emergency'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->emergency('Emergency'); + $this->assertTrue($result); + } + + public function testInterpolateMessage() + { + $this->expectOutputString('Hello Slim !'); + $log = new \Slim\Log(new MyWriter()); + $result = $log->debug( + 'Hello {framework} !', + array('framework' => "Slim") + ); + $this->assertTrue($result); + } + + public function testGetAndSetWriter() + { + $writer1 = new MyWriter(); + $writer2 = new MyWriter(); + $log = new \Slim\Log($writer1); + $this->assertSame($writer1, $log->getWriter()); + $log->setWriter($writer2); + $this->assertSame($writer2, $log->getWriter()); + } +} diff --git a/vendor/slim/slim/tests/LogWriterTest.php b/vendor/slim/slim/tests/LogWriterTest.php new file mode 100755 index 0000000..f36009d --- /dev/null +++ b/vendor/slim/slim/tests/LogWriterTest.php @@ -0,0 +1,48 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class LogWriterTest extends PHPUnit_Framework_TestCase +{ + public function testInstantiation() + { + $this->expectOutputString('Hello!' . PHP_EOL); + $handle = fopen('php://output', 'w'); + $fw = new \Slim\LogWriter($handle); + $this->assertTrue($fw->write('Hello!') > 0); //<-- Returns number of bytes written if successful + } + + public function testInstantiationWithNonResource() + { + $this->setExpectedException('InvalidArgumentException'); + $fw = new \Slim\LogWriter(@fopen('/foo/bar.txt', 'w')); + } +} diff --git a/vendor/slim/slim/tests/Middleware/ContentTypesTest.php b/vendor/slim/slim/tests/Middleware/ContentTypesTest.php new file mode 100755 index 0000000..4729a41 --- /dev/null +++ b/vendor/slim/slim/tests/Middleware/ContentTypesTest.php @@ -0,0 +1,162 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class ContentTypesTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + ob_start(); + } + + public function tearDown() + { + ob_end_clean(); + } + + /** + * Test parses JSON + */ + public function testParsesJson() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/json', + 'CONENT_LENGTH' => 13, + 'slim.input' => '{"foo":"bar"}' + )); + $s = new \Slim\Slim(); + $s->add(new \Slim\Middleware\ContentTypes()); + $s->run(); + $body = $s->request()->getBody(); + $this->assertTrue(is_array($body)); + $this->assertEquals('bar', $body['foo']); + } + + /** + * Test ignores JSON with errors + */ + public function testParsesJsonWithError() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/json', + 'CONENT_LENGTH' => 12, + 'slim.input' => '{"foo":"bar"' //<-- This should be incorrect! + )); + $s = new \Slim\Slim(); + $s->add(new \Slim\Middleware\ContentTypes()); + $s->run(); + $body = $s->request()->getBody(); + $this->assertTrue(is_string($body)); + $this->assertEquals('{"foo":"bar"', $body); + } + + /** + * Test parses XML + */ + public function testParsesXml() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/xml', + 'CONENT_LENGTH' => 68, + 'slim.input' => '1Clive Cussler' + )); + $s = new \Slim\Slim(); + $s->add(new \Slim\Middleware\ContentTypes()); + $s->run(); + $body = $s->request()->getBody(); + $this->assertInstanceOf('SimpleXMLElement', $body); + $this->assertEquals('Clive Cussler', (string) $body->book->author); + } + + /** + * Test ignores XML with errors + */ + public function testParsesXmlWithError() + { + libxml_use_internal_errors(true); + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/xml', + 'CONTENT_LENGTH' => 68, + 'slim.input' => '1Clive Cussler' //<-- This should be incorrect! + )); + $s = new \Slim\Slim(); + $s->add(new \Slim\Middleware\ContentTypes()); + $s->run(); + $body = $s->request()->getBody(); + $this->assertTrue(is_string($body)); + $this->assertEquals('1Clive Cussler', $body); + } + + /** + * Test parses CSV + */ + public function testParsesCsv() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'text/csv', + 'CONTENT_LENGTH' => 44, + 'slim.input' => "John,Doe,000-111-2222\nJane,Doe,111-222-3333" + )); + $s = new \Slim\Slim(); + $s->add(new \Slim\Middleware\ContentTypes()); + $s->run(); + $body = $s->request()->getBody(); + $this->assertTrue(is_array($body)); + $this->assertEquals(2, count($body)); + $this->assertEquals('000-111-2222', $body[0][2]); + $this->assertEquals('Doe', $body[1][1]); + } + + /** + * Test parses request body based on media-type only, disregarding + * any extra content-type header parameters + */ + public function testParsesRequestBodyWithMediaType() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/json; charset=ISO-8859-4', + 'CONTENT_LENGTH' => 13, + 'slim.input' => '{"foo":"bar"}' + )); + $s = new \Slim\Slim(); + $s->add(new \Slim\Middleware\ContentTypes()); + $s->run(); + $body = $s->request()->getBody(); + $this->assertTrue(is_array($body)); + $this->assertEquals('bar', $body['foo']); + } +} diff --git a/vendor/slim/slim/tests/Middleware/FlashTest.php b/vendor/slim/slim/tests/Middleware/FlashTest.php new file mode 100755 index 0000000..2faf2c1 --- /dev/null +++ b/vendor/slim/slim/tests/Middleware/FlashTest.php @@ -0,0 +1,141 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class SlimFlashTest extends PHPUnit_Framework_TestCase +{ + /** + * Setup + */ + public function setUp() + { + $_SESSION = array(); + } + + /** + * Test set flash message for next request + */ + public function testSetFlashForNextRequest() + { + $f = new \Slim\Middleware\Flash(); + $f->set('foo', 'bar'); + $f->save(); + $this->assertEquals('bar', $_SESSION['slim.flash']['foo']); + } + + /** + * Test set flash message for current request + */ + public function testSetFlashForCurrentRequest() + { + $f = new \Slim\Middleware\Flash(); + $f->now('foo', 'bar'); + $this->assertEquals('bar', $f['foo']); + } + + /** + * Test loads flash from previous request + */ + public function testLoadsFlashFromPreviousRequest() + { + $_SESSION['slim.flash'] = array('info' => 'foo'); + $f = new \Slim\Middleware\Flash(); + $f->loadMessages(); + $this->assertEquals('foo', $f['info']); + } + + /** + * Test keep flash message for next request + */ + public function testKeepFlashFromPreviousRequest() + { + $_SESSION['slim.flash'] = array('info' => 'foo'); + $f = new \Slim\Middleware\Flash(); + $f->loadMessages(); + $f->keep(); + $f->save(); + $this->assertEquals('foo', $_SESSION['slim.flash']['info']); + } + + /** + * Test flash messages from previous request do not persist to next request + */ + public function testFlashMessagesFromPreviousRequestDoNotPersist() + { + $_SESSION['slim.flash'] = array('info' => 'foo'); + $f = new \Slim\Middleware\Flash(); + $f->save(); + $this->assertEmpty($_SESSION['slim.flash']); + } + + /** + * Test set Flash using array access + */ + public function testFlashArrayAccess() + { + $_SESSION['slim.flash'] = array('info' => 'foo'); + $f = new \Slim\Middleware\Flash(); + $f['info'] = 'bar'; + $f->save(); + $this->assertTrue(isset($f['info'])); + $this->assertEquals('bar', $f['info']); + unset($f['info']); + $this->assertFalse(isset($f['info'])); + } + + /** + * Test iteration + */ + public function testIteration() + { + $_SESSION['slim.flash'] = array('info' => 'foo', 'error' => 'bar'); + $f = new \Slim\Middleware\Flash(); + $f->loadMessages(); + $output = ''; + foreach ($f as $key => $value) { + $output .= $key . $value; + } + $this->assertEquals('infofooerrorbar', $output); + } + + /** + * Test countable + */ + public function testCountable() + { + $_SESSION['slim.flash'] = array('info' => 'foo', 'error' => 'bar'); + $f = new \Slim\MiddleWare\Flash(); + $f->loadMessages(); + $this->assertEquals(2, count($f)); + } + + +} diff --git a/vendor/slim/slim/tests/Middleware/MethodOverrideTest.php b/vendor/slim/slim/tests/Middleware/MethodOverrideTest.php new file mode 100755 index 0000000..c07e397 --- /dev/null +++ b/vendor/slim/slim/tests/Middleware/MethodOverrideTest.php @@ -0,0 +1,149 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +/** + * We use a mock application, instead of a Slim application. + * so that we may easily test the Method Override middleware + * in isolation. + */ +class CustomAppMethod +{ + protected $environment; + + public function __construct() + { + $this->environment = \Slim\Environment::getInstance(); + } + + public function &environment() { + return $this->environment; + } + + public function call() + { + //Do nothing + } +} + +class MethodOverrideTest extends PHPUnit_Framework_TestCase +{ + /** + * Test overrides method as POST + */ + public function testOverrideMethodAsPost() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + 'CONTENT_LENGTH' => 11, + 'slim.input' => '_METHOD=PUT' + )); + $app = new CustomAppMethod(); + $mw = new \Slim\Middleware\MethodOverride(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $env =& $app->environment(); + $this->assertEquals('PUT', $env['REQUEST_METHOD']); + $this->assertTrue(isset($env['slim.method_override.original_method'])); + $this->assertEquals('POST', $env['slim.method_override.original_method']); + } + + /** + * Test does not override method if not POST + */ + public function testDoesNotOverrideMethodIfNotPost() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'GET', + 'slim.input' => '' + )); + $app = new CustomAppMethod(); + $mw = new \Slim\Middleware\MethodOverride(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $env =& $app->environment(); + $this->assertEquals('GET', $env['REQUEST_METHOD']); + $this->assertFalse(isset($env['slim.method_override.original_method'])); + } + + /** + * Test does not override method if no method override parameter + */ + public function testDoesNotOverrideMethodAsPostWithoutParameter() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'REMOTE_ADDR' => '127.0.0.1', + 'SCRIPT_NAME' => '/foo/index.php', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'QUERY_STRING' => 'foo=bar', + 'SERVER_NAME' => 'slim', + 'SERVER_PORT' => 80, + 'slim.url_scheme' => 'http', + 'slim.input' => '', + 'slim.errors' => fopen('php://stderr', 'w') + )); + $app = new CustomAppMethod(); + $mw = new \Slim\Middleware\MethodOverride(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $env =& $app->environment(); + $this->assertEquals('POST', $env['REQUEST_METHOD']); + $this->assertFalse(isset($env['slim.method_override.original_method'])); + } + + /** + * Test overrides method with X-Http-Method-Override header + */ + public function testOverrideMethodAsHeader() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/json', + 'CONTENT_LENGTH' => 0, + 'slim.input' => '', + 'HTTP_X_HTTP_METHOD_OVERRIDE' => 'DELETE' + )); + $app = new CustomAppMethod(); + $mw = new \Slim\Middleware\MethodOverride(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $env =& $app->environment(); + $this->assertEquals('DELETE', $env['REQUEST_METHOD']); + $this->assertTrue(isset($env['slim.method_override.original_method'])); + $this->assertEquals('POST', $env['slim.method_override.original_method']); + } +} diff --git a/vendor/slim/slim/tests/Middleware/PrettyExceptionsTest.php b/vendor/slim/slim/tests/Middleware/PrettyExceptionsTest.php new file mode 100755 index 0000000..0ba8883 --- /dev/null +++ b/vendor/slim/slim/tests/Middleware/PrettyExceptionsTest.php @@ -0,0 +1,153 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class PrettyExceptionsTest extends PHPUnit_Framework_TestCase +{ + /** + * Test middleware returns successful response unchanged + */ + public function testReturnsUnchangedSuccessResponse() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(); + $app->get('/foo', function () { + echo "Success"; + }); + $mw = new \Slim\Middleware\PrettyExceptions(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $this->assertEquals(200, $app->response()->status()); + $this->assertEquals('Success', $app->response()->body()); + } + + /** + * Test middleware returns diagnostic screen for error response + */ + public function testReturnsDiagnosticsForErrorResponse() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(array( + 'log.enabled' => false + )); + $app->get('/foo', function () { + throw new \Exception('Test Message', 100); + }); + $mw = new \Slim\Middleware\PrettyExceptions(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $this->assertEquals(1, preg_match('@Slim Application Error@', $app->response()->body())); + $this->assertEquals(500, $app->response()->status()); + } + + /** + * Test middleware overrides response content type to html + */ + public function testResponseContentTypeIsOverriddenToHtml() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(array( + 'log.enabled' => false + )); + $app->get('/foo', function () use ($app) { + $app->contentType('application/json;charset=utf-8'); //<-- set content type to something else + throw new \Exception('Test Message', 100); + }); + $mw = new \Slim\Middleware\PrettyExceptions(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $response = $app->response(); + $this->assertEquals('text/html', $response['Content-Type']); + } + + /** + * Test exception type is in response body + */ + public function testExceptionTypeIsInResponseBody() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(array( + 'log.enabled' => false + )); + $app->get('/foo', function () use ($app) { + throw new \LogicException('Test Message', 100); + }); + $mw = new \Slim\Middleware\PrettyExceptions(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + + $this->assertContains('LogicException', $app->response()->body()); + } + + /** + * Test with custom log + */ + public function testWithCustomLogWriter() + { + $this->setExpectedException('\LogicException'); + + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(array( + 'log.enabled' => false + )); + $app->container->singleton('log', function () use ($app) { + return new \Slim\Log(new \Slim\LogWriter('php://temp')); + }); + $app->get('/foo', function () use ($app) { + throw new \LogicException('Test Message', 100); + }); + $mw = new \Slim\Middleware\PrettyExceptions(); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + + $this->assertContains('LogicException', $app->response()->body()); + } +} diff --git a/vendor/slim/slim/tests/Middleware/SessionCookieTest.php b/vendor/slim/slim/tests/Middleware/SessionCookieTest.php new file mode 100755 index 0000000..39de500 --- /dev/null +++ b/vendor/slim/slim/tests/Middleware/SessionCookieTest.php @@ -0,0 +1,463 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class SessionCookieTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $_SESSION = array(); + } + + /** + * Test session cookie is set and constructed correctly + * + * We test for two things: + * + * 1) That the HTTP cookie exists with the correct name; + * 2) That the HTTP cookie's value is the expected value; + */ + public function testSessionCookieIsCreated() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(); + $app->get('/foo', function () { + $_SESSION['foo'] = 'bar'; + echo "Success"; + }); + $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + list($status, $header, $body) = $app->response()->finalize(); + $this->assertTrue($app->response->cookies->has('slim_session')); + $cookie = $app->response->cookies->get('slim_session'); + $this->assertEquals('{"foo":"bar"}', $cookie['value']); + } + + /** + * Test $_SESSION is populated from an encrypted HTTP cookie + * + * The encrypted cookie contains the serialized array ['foo' => 'bar']. The + * global secret, cipher, and cipher mode are assumed to be the default + * values. + */ + // public function testSessionIsPopulatedFromEncryptedCookie() + // { + // \Slim\Environment::mock(array( + // 'SCRIPT_NAME' => '/index.php', + // 'PATH_INFO' => '/foo', + // 'HTTP_COOKIE' => 'slim_session=1644004961%7CLKkYPwqKIMvBK7MWl6D%2BxeuhLuMaW4quN%2F512ZAaVIY%3D%7Ce0f007fa852c7101e8224bb529e26be4d0dfbd63', + // )); + // $app = new \Slim\Slim(); + // // The cookie value in the test is encrypted, so cookies.encrypt must + // // be set to true + // $app->config('cookies.encrypt', true); + // $app->get('/foo', function () { + // echo "Success"; + // }); + // $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); + // $mw->setApplication($app); + // $mw->setNextMiddleware($app); + // $mw->call(); + // $this->assertEquals(array('foo' => 'bar'), $_SESSION); + // } + + /** + * Test $_SESSION is populated from an unencrypted HTTP cookie + * + * The unencrypted cookie contains the serialized array ['foo' => 'bar']. + * The global cookies.encrypt setting is set to false + */ + public function testSessionIsPopulatedFromUnencryptedCookie() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo', + 'HTTP_COOKIE' => 'slim_session={"foo":"bar"}', + )); + $app = new \Slim\Slim(); + // The cookie value in the test is unencrypted, so cookies.encrypt must + // be set to false + $app->config('cookies.encrypt', false); + $app->get('/foo', function () { + echo "Success"; + }); + $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $this->assertEquals(array('foo' => 'bar'), $_SESSION); + } + + /** + * Test $_SESSION is populated from an unencrypted HTTP cookie + * + * The unencrypted cookie contains the serialized array ['foo' => 'bar']. + * The global cookies.encrypt setting is set to false + */ + public function testSessionIsPopulatedFromMalformedCookieData() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo', + 'HTTP_COOKIE' => 'slim_session={"foo":"bar"sdkhguy5y}', + )); + $app = new \Slim\Slim(); + // The cookie value in the test is unencrypted, so cookies.encrypt must + // be set to false + $app->config('cookies.encrypt', false); + $app->get('/foo', function () { + echo "Success"; + }); + $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $this->assertEquals(array(), $_SESSION); + } + + /** + * Test $_SESSION is populated as empty array if no HTTP cookie + */ + public function testSessionIsPopulatedAsEmptyIfNoCookie() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + $app = new \Slim\Slim(); + $app->get('/foo', function () { + echo "Success"; + }); + $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + $this->assertEquals(array(), $_SESSION); + } + + public function testSerializingTooLongValueWritesLogAndDoesntCreateCookie() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/index.php', + 'PATH_INFO' => '/foo' + )); + + $logWriter = $this->getMockBuilder('Slim\LogWriter') + ->disableOriginalConstructor() + ->getMock(); + + $logWriter->expects($this->once()) + ->method('write') + ->with('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.', \Slim\Log::ERROR); + + $app = new \Slim\Slim(array( + 'log.writer' => $logWriter + )); + + $tooLongValue = $this->getTooLongValue(); + + $app->get('/foo', function () use ($tooLongValue) { + $_SESSION['test'] = $tooLongValue; + echo "Success"; + }); + + $mw = new \Slim\Middleware\SessionCookie(array('expires' => '10 years')); + $mw->setApplication($app); + $mw->setNextMiddleware($app); + $mw->call(); + list($status, $header, $body) = $app->response()->finalize(); + $this->assertFalse($app->response->cookies->has('slim_session')); + } + + /** + * Generated by http://www.random.org/strings/ + */ + protected function getTooLongValue() + { + return << + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class MyMiddleware extends \Slim\Middleware +{ + public function call() {} +} + +class MiddlewareTest extends PHPUnit_Framework_TestCase +{ + public function testSetApplication() + { + $app = new stdClass(); + $mw = new MyMiddleware(); + $mw->setApplication($app); + + $this->assertAttributeSame($app, 'app', $mw); + } + + public function testGetApplication() + { + $app = new stdClass(); + $mw = new MyMiddleware(); + $property = new \ReflectionProperty($mw, 'app'); + $property->setAccessible(true); + $property->setValue($mw, $app); + + $this->assertSame($app, $mw->getApplication()); + } + + public function testSetNextMiddleware() + { + $mw1 = new MyMiddleware(); + $mw2 = new MyMiddleware(); + $mw1->setNextMiddleware($mw2); + + $this->assertAttributeSame($mw2, 'next', $mw1); + } + + public function testGetNextMiddleware() + { + $mw1 = new MyMiddleware(); + $mw2 = new MyMiddleware(); + $property = new \ReflectionProperty($mw1, 'next'); + $property->setAccessible(true); + $property->setValue($mw1, $mw2); + + $this->assertSame($mw2, $mw1->getNextMiddleware()); + } +} diff --git a/vendor/slim/slim/tests/README b/vendor/slim/slim/tests/README new file mode 100755 index 0000000..7bc611c --- /dev/null +++ b/vendor/slim/slim/tests/README @@ -0,0 +1,18 @@ +Slim Framework Unit Tests + +Follow the directions below to run the Slim Framework unit tests. You'll need the latest version of PHPUnit. To save development time, these unit tests require PHP >= 5.3. However, the Slim Framework itself requires only PHP >= 5.2. + +1. Install the latest version of PHPUnit +Visit http://www.phpunit.de/ for installation instructions. + +2. Run PHPUnit +From the filesystem directory that contains the `tests` directory, you may run all unit tests or specific unit tests. Here are several examples. The '$>' in the examples below is your command prompt. + +To run all tests: +$> phpunit tests + +To run all HTTP-related tests: +$> phpunit tests/Http + +To run only the HTTP Request tests: +$> phpunit tests/Http/RequestTest \ No newline at end of file diff --git a/vendor/slim/slim/tests/RouteTest.php b/vendor/slim/slim/tests/RouteTest.php new file mode 100755 index 0000000..6817641 --- /dev/null +++ b/vendor/slim/slim/tests/RouteTest.php @@ -0,0 +1,617 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class LazyInitializeTestClass { + public static $initialized = false; + + public function __construct() { + self::$initialized = true; + } + + public function foo() { + } +} + +class FooTestClass { + public static $foo_invoked = false; + public static $foo_invoked_args = array(); + + public function foo() { + self::$foo_invoked = true; + self::$foo_invoked_args = func_get_args(); + } +} + +class RouteTest extends PHPUnit_Framework_TestCase +{ + public function testGetPattern() + { + $route = new \Slim\Route('/foo', function () {}); + + $this->assertEquals('/foo', $route->getPattern()); + } + + public function testGetName() + { + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($route, 'name'); + $property->setAccessible(true); + $property->setValue($route, 'foo'); + + $this->assertEquals('foo', $route->getName()); + } + + public function testSetName() + { + $route = new \Slim\Route('/foo', function () {}); + $route->name('foo'); // <-- Alias for `setName()` + + $this->assertAttributeEquals('foo', 'name', $route); + } + + public function testGetCallable() + { + $callable = function () { + echo 'Foo'; + }; + $route = new \Slim\Route('/foo', $callable); + + $this->assertSame($callable, $route->getCallable()); + } + + public function testGetCallableAsClass() + { + FooTestClass::$foo_invoked = false; + FooTestClass::$foo_invoked_args = array(); + $route = new \Slim\Route('/foo', '\FooTestClass:foo'); + $route->setParams(array('bar' => '1234')); + + $this->assertFalse(FooTestClass::$foo_invoked); + $this->assertTrue($route->dispatch()); + $this->assertTrue(FooTestClass::$foo_invoked); + $this->assertEquals(array('1234'), FooTestClass::$foo_invoked_args); + } + + public function testGetCallableAsClassLazyInitialize() + { + LazyInitializeTestClass::$initialized = false; + + $route = new \Slim\Route('/foo', '\LazyInitializeTestClass:foo'); + $this->assertFalse(LazyInitializeTestClass::$initialized); + + $route->dispatch(); + $this->assertTrue(LazyInitializeTestClass::$initialized); + } + + public function testGetCallableAsStaticMethod() + { + $route = new \Slim\Route('/bar', '\Slim\Slim::getInstance'); + + $callable = $route->getCallable(); + $this->assertEquals('\Slim\Slim::getInstance', $callable); + } + + public function example_càllâble_wïth_wéird_chars() + { + return 'test'; + } + + public function testGetCallableWithOddCharsAsClass() + { + $route = new \Slim\Route('/foo', '\RouteTest:example_càllâble_wïth_wéird_chars'); + $callable = $route->getCallable(); + + $this->assertEquals('test', $callable()); + } + + public function testSetCallable() + { + $callable = function () { + echo 'Foo'; + }; + $route = new \Slim\Route('/foo', $callable); // <-- Called inside __construct() + + $this->assertAttributeSame($callable, 'callable', $route); + } + + public function testSetCallableWithInvalidArgument() + { + $this->setExpectedException('\InvalidArgumentException'); + $route = new \Slim\Route('/foo', 'doesNotExist'); // <-- Called inside __construct() + } + + public function testGetParams() + { + $route = new \Slim\Route('/hello/:first/:last', function () {}); + $route->matches('/hello/mr/anderson'); // <-- Parses params from argument + + $this->assertEquals(array( + 'first' => 'mr', + 'last' => 'anderson' + ), $route->getParams()); + } + + public function testSetParams() + { + $route = new \Slim\Route('/hello/:first/:last', function () {}); + $route->matches('/hello/mr/anderson'); // <-- Parses params from argument + $route->setParams(array( + 'first' => 'agent', + 'last' => 'smith' + )); + + $this->assertAttributeEquals(array( + 'first' => 'agent', + 'last' => 'smith' + ), 'params', $route); + } + + public function testGetParam() + { + $route = new \Slim\Route('/hello/:first/:last', function () {}); + + $property = new \ReflectionProperty($route, 'params'); + $property->setAccessible(true); + $property->setValue($route, array( + 'first' => 'foo', + 'last' => 'bar' + )); + + $this->assertEquals('foo', $route->getParam('first')); + } + + public function testGetParamThatDoesNotExist() + { + $this->setExpectedException('InvalidArgumentException'); + + $route = new \Slim\Route('/hello/:first/:last', function () {}); + + $property = new \ReflectionProperty($route, 'params'); + $property->setAccessible(true); + $property->setValue($route, array( + 'first' => 'foo', + 'last' => 'bar' + )); + + $route->getParam('middle'); + } + + public function testSetParam() + { + $route = new \Slim\Route('/hello/:first/:last', function () {}); + $route->matches('/hello/mr/anderson'); // <-- Parses params from argument + $route->setParam('last', 'smith'); + + $this->assertAttributeEquals(array( + 'first' => 'mr', + 'last' => 'smith' + ), 'params', $route); + } + + public function testSetParamThatDoesNotExist() + { + $this->setExpectedException('InvalidArgumentException'); + + $route = new \Slim\Route('/hello/:first/:last', function () {}); + $route->matches('/hello/mr/anderson'); // <-- Parses params from argument + $route->setParam('middle', 'smith'); // <-- Should trigger InvalidArgumentException + } + + public function testMatches() + { + $route = new \Slim\Route('/hello/:name', function () {}); + + $this->assertTrue($route->matches('/hello/josh')); + } + + public function testMatchesIsFalse() + { + $route = new \Slim\Route('/foo', function () {}); + + $this->assertFalse($route->matches('/bar')); + } + + public function testMatchesPatternWithTrailingSlash() + { + $route = new \Slim\Route('/foo/', function () {}); + + $this->assertTrue($route->matches('/foo/')); + $this->assertTrue($route->matches('/foo')); + } + + public function testMatchesPatternWithoutTrailingSlash() + { + $route = new \Slim\Route('/foo', function () {}); + + $this->assertFalse($route->matches('/foo/')); + $this->assertTrue($route->matches('/foo')); + } + + public function testMatchesWithConditions() + { + $route = new \Slim\Route('/hello/:first/and/:second', function () {}); + $route->conditions(array( + 'first' => '[a-zA-Z]{3,}' + )); + + $this->assertTrue($route->matches('/hello/Josh/and/John')); + } + + public function testMatchesWithConditionsIsFalse() + { + $route = new \Slim\Route('/hello/:first/and/:second', function () {}); + $route->conditions(array( + 'first' => '[a-z]{3,}' + )); + + $this->assertFalse($route->matches('/hello/Josh/and/John')); + } + + /* + * Route should match URI with valid path component according to rfc2396 + * + * "Uniform Resource Identifiers (URI): Generic Syntax" http://www.ietf.org/rfc/rfc2396.txt + * + * Excludes "+" which is valid but decodes into a space character + */ + public function testMatchesWithValidRfc2396PathComponent() + { + $symbols = ':@&=$,'; + $route = new \Slim\Route('/rfc2386/:symbols', function () {}); + + $this->assertTrue($route->matches('/rfc2386/' . $symbols)); + } + + /* + * Route should match URI including unreserved punctuation marks from rfc2396 + * + * "Uniform Resource Identifiers (URI): Generic Syntax" http://www.ietf.org/rfc/rfc2396.txt + */ + public function testMatchesWithUnreservedMarks() + { + $marks = "-_.!~*'()"; + $route = new \Slim\Route('/marks/:marks', function () {}); + + $this->assertTrue($route->matches('/marks/' . $marks)); + } + + public function testMatchesOptionalParameters() + { + $pattern = '/archive/:year(/:month(/:day))'; + + $route1 = new \Slim\Route($pattern, function () {}); + $this->assertTrue($route1->matches('/archive/2010')); + $this->assertEquals(array('year' => '2010'), $route1->getParams()); + + $route2 = new \Slim\Route($pattern, function () {}); + $this->assertTrue($route2->matches('/archive/2010/05')); + $this->assertEquals(array('year' => '2010', 'month' => '05'), $route2->getParams()); + + $route3 = new \Slim\Route($pattern, function () {}); + $this->assertTrue($route3->matches('/archive/2010/05/13')); + $this->assertEquals(array('year' => '2010', 'month' => '05', 'day' => '13'), $route3->getParams()); + } + + public function testMatchesIsCaseSensitiveByDefault() + { + $route = new \Slim\Route('/case/sensitive', function () {}); + $this->assertTrue($route->matches('/case/sensitive')); + $this->assertFalse($route->matches('/CaSe/SensItiVe')); + } + + public function testMatchesCanBeCaseInsensitive() + { + $route = new \Slim\Route('/Case/Insensitive', function () {}, false); + $this->assertTrue($route->matches('/Case/Insensitive')); + $this->assertTrue($route->matches('/CaSe/iNSensItiVe')); + } + + public function testGetConditions() + { + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($route, 'conditions'); + $property->setAccessible(true); + $property->setValue($route, array('foo' => '\d{3}')); + + $this->assertEquals(array('foo' => '\d{3}'), $route->getConditions()); + } + + public function testSetDefaultConditions() + { + \Slim\Route::setDefaultConditions(array( + 'id' => '\d+' + )); + + $property = new \ReflectionProperty('\Slim\Route', 'defaultConditions'); + $property->setAccessible(true); + + $this->assertEquals(array( + 'id' => '\d+' + ), $property->getValue()); + } + + public function testGetDefaultConditions() + { + $property = new \ReflectionProperty('\Slim\Route', 'defaultConditions'); + $property->setAccessible(true); + $property->setValue(array( + 'id' => '\d+' + )); + + $this->assertEquals(array( + 'id' => '\d+' + ), \Slim\Route::getDefaultConditions()); + } + + public function testDefaultConditionsAssignedToInstance() + { + $staticProperty = new \ReflectionProperty('\Slim\Route', 'defaultConditions'); + $staticProperty->setAccessible(true); + $staticProperty->setValue(array( + 'id' => '\d+' + )); + $route = new \Slim\Route('/foo', function () {}); + + $this->assertAttributeEquals(array( + 'id' => '\d+' + ), 'conditions', $route); + } + + public function testMatchesWildcard() + { + $route = new \Slim\Route('/hello/:path+/world', function () {}); + + $this->assertTrue($route->matches('/hello/foo/bar/world')); + $this->assertAttributeEquals(array( + 'path' => array('foo', 'bar') + ), 'params', $route); + } + + public function testMatchesMultipleWildcards() + { + $route = new \Slim\Route('/hello/:path+/world/:date+', function () {}); + + $this->assertTrue($route->matches('/hello/foo/bar/world/2012/03/10')); + $this->assertAttributeEquals(array( + 'path' => array('foo', 'bar'), + 'date' => array('2012', '03', '10') + ), 'params', $route); + } + + public function testMatchesParamsAndWildcards() + { + $route = new \Slim\Route('/hello/:path+/world/:year/:month/:day/:path2+', function () {}); + + $this->assertTrue($route->matches('/hello/foo/bar/world/2012/03/10/first/second')); + $this->assertAttributeEquals(array( + 'path' => array('foo', 'bar'), + 'year' => '2012', + 'month' => '03', + 'day' => '10', + 'path2' => array('first', 'second') + ), 'params', $route); + } + + public function testMatchesParamsWithOptionalWildcard() + { + $route = new \Slim\Route('/hello(/:foo(/:bar+))', function () {}); + + $this->assertTrue($route->matches('/hello')); + $this->assertTrue($route->matches('/hello/world')); + $this->assertTrue($route->matches('/hello/world/foo')); + $this->assertTrue($route->matches('/hello/world/foo/bar')); + } + + public function testSetMiddleware() + { + $route = new \Slim\Route('/foo', function () {}); + $mw = function () { + echo 'Foo'; + }; + $route->setMiddleware($mw); + + $this->assertAttributeContains($mw, 'middleware', $route); + } + + public function testSetMiddlewareMultipleTimes() + { + $route = new \Slim\Route('/foo', function () {}); + $mw1 = function () { + echo 'Foo'; + }; + $mw2 = function () { + echo 'Bar'; + }; + $route->setMiddleware($mw1); + $route->setMiddleware($mw2); + + $this->assertAttributeContains($mw1, 'middleware', $route); + $this->assertAttributeContains($mw2, 'middleware', $route); + } + + public function testSetMiddlewareWithArray() + { + $route = new \Slim\Route('/foo', function () {}); + $mw1 = function () { + echo 'Foo'; + }; + $mw2 = function () { + echo 'Bar'; + }; + $route->setMiddleware(array($mw1, $mw2)); + + $this->assertAttributeContains($mw1, 'middleware', $route); + $this->assertAttributeContains($mw2, 'middleware', $route); + } + + public function testSetMiddlewareWithInvalidArgument() + { + $this->setExpectedException('InvalidArgumentException'); + + $route = new \Slim\Route('/foo', function () {}); + $route->setMiddleware('doesNotExist'); // <-- Should throw InvalidArgumentException + } + + public function testSetMiddlewareWithArrayWithInvalidArgument() + { + $this->setExpectedException('InvalidArgumentException'); + + $route = new \Slim\Route('/foo', function () {}); + $route->setMiddleware(array('doesNotExist')); + } + + public function testGetMiddleware() + { + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($route, 'middleware'); + $property->setAccessible(true); + $property->setValue($route, array('foo' => 'bar')); + + $this->assertEquals(array('foo' => 'bar'), $route->getMiddleware()); + } + + public function testSetHttpMethods() + { + $route = new \Slim\Route('/foo', function () {}); + $route->setHttpMethods('GET', 'POST'); + + $this->assertAttributeEquals(array('GET', 'POST'), 'methods', $route); + } + + public function testGetHttpMethods() + { + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($route, 'methods'); + $property->setAccessible(true); + $property->setValue($route, array('GET', 'POST')); + + $this->assertEquals(array('GET', 'POST'), $route->getHttpMethods()); + } + + public function testAppendHttpMethods() + { + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($route, 'methods'); + $property->setAccessible(true); + $property->setValue($route, array('GET', 'POST')); + + $route->appendHttpMethods('PUT'); + + $this->assertAttributeEquals(array('GET', 'POST', 'PUT'), 'methods', $route); + } + + public function testAppendArrayOfHttpMethods() + { + $arrayOfMethods = array('GET','POST','PUT'); + $route = new \Slim\Route('/foo', function () {}); + $route->appendHttpMethods($arrayOfMethods); + + $this->assertAttributeEquals($arrayOfMethods,'methods',$route); + } + + public function testAppendHttpMethodsWithVia() + { + $route = new \Slim\Route('/foo', function () {}); + $route->via('PUT'); + + $this->assertAttributeContains('PUT', 'methods', $route); + } + + public function testAppendArrayOfHttpMethodsWithVia() + { + $arrayOfMethods = array('GET','POST','PUT'); + $route = new \Slim\Route('/foo', function () {}); + $route->via($arrayOfMethods); + + $this->assertAttributeEquals($arrayOfMethods,'methods',$route); + } + + public function testSupportsHttpMethod() + { + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($route, 'methods'); + $property->setAccessible(true); + $property->setValue($route, array('POST')); + + $this->assertTrue($route->supportsHttpMethod('POST')); + $this->assertFalse($route->supportsHttpMethod('PUT')); + } + + /** + * Test dispatch with params + */ + public function testDispatch() + { + $this->expectOutputString('Hello josh'); + $route = new \Slim\Route('/hello/:name', function ($name) { echo "Hello $name"; }); + $route->matches('/hello/josh'); //<-- Extracts params from resource URI + $route->dispatch(); + } + + /** + * Test dispatch with middleware + */ + public function testDispatchWithMiddleware() + { + $this->expectOutputString('First! Second! Hello josh'); + $route = new \Slim\Route('/hello/:name', function ($name) { echo "Hello $name"; }); + $route->setMiddleware(function () { + echo "First! "; + }); + $route->setMiddleware(function () { + echo "Second! "; + }); + $route->matches('/hello/josh'); //<-- Extracts params from resource URI + $route->dispatch(); + } + + /** + * Test middleware with arguments + */ + public function testRouteMiddlwareArguments() + { + $this->expectOutputString('foobar'); + $route = new \Slim\Route('/foo', function () { echo "bar"; }); + $route->setName('foo'); + $route->setMiddleware(function ($route) { + echo $route->getName(); + }); + $route->matches('/foo'); //<-- Extracts params from resource URI + $route->dispatch(); + } +} diff --git a/vendor/slim/slim/tests/RouterTest.php b/vendor/slim/slim/tests/RouterTest.php new file mode 100755 index 0000000..edbb6d4 --- /dev/null +++ b/vendor/slim/slim/tests/RouterTest.php @@ -0,0 +1,250 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class RouterTest extends PHPUnit_Framework_TestCase +{ + /** + * Constructor should initialize routes as empty array + */ + public function testConstruct() + { + $router = new \Slim\Router(); + + $this->assertAttributeEquals(array(), 'routes', $router); + } + + /** + * Map should set and return instance of \Slim\Route + */ + public function testMap() + { + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function() {}); + $router->map($route); + + $this->assertAttributeContains($route, 'routes', $router); + } + + /** + * Named route should be added and indexed by name + */ + public function testAddNamedRoute() + { + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function () {}); + $router->addNamedRoute('foo', $route); + + $property = new \ReflectionProperty($router, 'namedRoutes'); + $property->setAccessible(true); + + $rV = $property->getValue($router); + $this->assertSame($route, $rV['foo']); + } + + /** + * Named route should have unique name + */ + public function testAddNamedRouteWithDuplicateKey() + { + $this->setExpectedException('RuntimeException'); + + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function () {}); + $router->addNamedRoute('foo', $route); + $router->addNamedRoute('foo', $route); + } + + /** + * Router should return named route by name, or null if not found + */ + public function testGetNamedRoute() + { + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($router, 'namedRoutes'); + $property->setAccessible(true); + $property->setValue($router, array('foo' => $route)); + + $this->assertSame($route, $router->getNamedRoute('foo')); + $this->assertNull($router->getNamedRoute('bar')); + } + + /** + * Router should determine named routes and cache results + */ + public function testGetNamedRoutes() + { + $router = new \Slim\Router(); + $route1 = new \Slim\Route('/foo', function () {}); + $route2 = new \Slim\Route('/bar', function () {}); + + // Init router routes to array + $propertyRouterRoutes = new \ReflectionProperty($router, 'routes'); + $propertyRouterRoutes->setAccessible(true); + $propertyRouterRoutes->setValue($router, array($route1, $route2)); + + // Init router named routes to null + $propertyRouterNamedRoutes = new \ReflectionProperty($router, 'namedRoutes'); + $propertyRouterNamedRoutes->setAccessible(true); + $propertyRouterNamedRoutes->setValue($router, null); + + // Init route name + $propertyRouteName = new \ReflectionProperty($route2, 'name'); + $propertyRouteName->setAccessible(true); + $propertyRouteName->setValue($route2, 'bar'); + + $namedRoutes = $router->getNamedRoutes(); + $this->assertCount(1, $namedRoutes); + $this->assertSame($route2, $namedRoutes['bar']); + } + + /** + * Router should detect presence of a named route by name + */ + public function testHasNamedRoute() + { + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($router, 'namedRoutes'); + $property->setAccessible(true); + $property->setValue($router, array('foo' => $route)); + + $this->assertTrue($router->hasNamedRoute('foo')); + $this->assertFalse($router->hasNamedRoute('bar')); + } + + /** + * Router should return current route if set during iteration + */ + public function testGetCurrentRoute() + { + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function () {}); + + $property = new \ReflectionProperty($router, 'currentRoute'); + $property->setAccessible(true); + $property->setValue($router, $route); + + $this->assertSame($route, $router->getCurrentRoute()); + } + + /** + * Router should return first matching route if current route not set yet by iteration + */ + public function testGetCurrentRouteIfMatchedRoutes() + { + $router = new \Slim\Router(); + $route = new \Slim\Route('/foo', function () {}); + + $propertyMatchedRoutes = new \ReflectionProperty($router, 'matchedRoutes'); + $propertyMatchedRoutes->setAccessible(true); + $propertyMatchedRoutes->setValue($router, array($route)); + + $propertyCurrentRoute = new \ReflectionProperty($router, 'currentRoute'); + $propertyCurrentRoute->setAccessible(true); + $propertyCurrentRoute->setValue($router, null); + + $this->assertSame($route, $router->getCurrentRoute()); + } + + /** + * Router should return `null` if current route not set yet and there are no matching routes + */ + public function testGetCurrentRouteIfNoMatchedRoutes() + { + $router = new \Slim\Router(); + + $propertyMatchedRoutes = new \ReflectionProperty($router, 'matchedRoutes'); + $propertyMatchedRoutes->setAccessible(true); + $propertyMatchedRoutes->setValue($router, array()); + + $propertyCurrentRoute = new \ReflectionProperty($router, 'currentRoute'); + $propertyCurrentRoute->setAccessible(true); + $propertyCurrentRoute->setValue($router, null); + + $this->assertNull($router->getCurrentRoute()); + } + + public function testGetMatchedRoutes() + { + $router = new \Slim\Router(); + + $route1 = new \Slim\Route('/foo', function () {}); + $route1 = $route1->via('GET'); + + $route2 = new \Slim\Route('/foo', function () {}); + $route2 = $route2->via('POST'); + + $route3 = new \Slim\Route('/bar', function () {}); + $route3 = $route3->via('PUT'); + + $routes = new \ReflectionProperty($router, 'routes'); + $routes->setAccessible(true); + $routes->setValue($router, array($route1, $route2, $route3)); + + $matchedRoutes = $router->getMatchedRoutes('GET', '/foo'); + $this->assertSame($route1, $matchedRoutes[0]); + } + + // Test url for named route + + public function testUrlFor() + { + $router = new \Slim\Router(); + + $route1 = new \Slim\Route('/hello/:first/:last', function () {}); + $route1 = $route1->via('GET')->name('hello'); + + $route2 = new \Slim\Route('/path/(:foo\.:bar)', function () {}); + $route2 = $route2->via('GET')->name('regexRoute'); + + $routes = new \ReflectionProperty($router, 'namedRoutes'); + $routes->setAccessible(true); + $routes->setValue($router, array( + 'hello' => $route1, + 'regexRoute' => $route2 + )); + + $this->assertEquals('/hello/Josh/Lockhart', $router->urlFor('hello', array('first' => 'Josh', 'last' => 'Lockhart'))); + $this->assertEquals('/path/Hello.Josh', $router->urlFor('regexRoute', array('foo' => 'Hello', 'bar' => 'Josh'))); + } + + public function testUrlForIfNoSuchRoute() + { + $this->setExpectedException('RuntimeException'); + + $router = new \Slim\Router(); + $router->urlFor('foo', array('abc' => '123')); + } +} diff --git a/vendor/slim/slim/tests/SlimTest.php b/vendor/slim/slim/tests/SlimTest.php new file mode 100755 index 0000000..d661b4d --- /dev/null +++ b/vendor/slim/slim/tests/SlimTest.php @@ -0,0 +1,1657 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +//Mock custom view +class CustomView extends \Slim\View +{ + public function render($template, $data = null) { echo "Custom view"; } +} + +//Echo Logger +class EchoErrorLogger +{ + public function error($object) { echo get_class($object) .':'.$object->getMessage(); } +} + +//Mock extending class +class Derived extends \Slim\Slim +{ + public static function getDefaultSettings() + { + return array_merge( + array("late-static-binding" => true) + , parent::getDefaultSettings()); + } +} + +//Mock middleware +class CustomMiddleware extends \Slim\Middleware +{ + public function call() + { + $env = $this->app->environment(); + $res = $this->app->response(); + $env['slim.test'] = 'Hello'; + $this->next->call(); + $res->header('X-Slim-Test', 'Hello'); + $res->write('Hello'); + } +} + +class SlimTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + //Remove environment mode if set + unset($_ENV['SLIM_MODE']); + + //Reset session + $_SESSION = array(); + + //Prepare default environment variables + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'QUERY_STRING' => 'one=foo&two=bar', + 'SERVER_NAME' => 'slimframework.com', + )); + } + + /************************************************ + * INSTANTIATION + ************************************************/ + + /** + * Test version constant is string + */ + public function testHasVersionConstant() + { + $this->assertTrue(is_string(\Slim\Slim::VERSION)); + } + + /** + * Test default instance properties + */ + public function testDefaultInstanceProperties() + { + $s = new \Slim\Slim(); + $this->assertInstanceOf('\Slim\Http\Request', $s->request()); + $this->assertInstanceOf('\Slim\Http\Response', $s->response()); + $this->assertInstanceOf('\Slim\Router', $s->router()); + $this->assertInstanceOf('\Slim\View', $s->view()); + $this->assertInstanceOf('\Slim\Log', $s->getLog()); + $this->assertEquals(\Slim\Log::DEBUG, $s->getLog()->getLevel()); + $this->assertTrue($s->getLog()->getEnabled()); + $this->assertInstanceOf('\Slim\Environment', $s->environment()); + } + + /** + * Test get default instance + */ + public function testGetDefaultInstance() + { + $s = new \Slim\Slim(); + $s->setName('default'); //We must do this manually since a default app is already set in prev tests + $this->assertEquals('default', $s->getName()); + $this->assertInstanceOf('\Slim\Slim', \Slim\Slim::getInstance()); + $this->assertSame($s, \Slim\Slim::getInstance()); + } + + /** + * Test get named instance + */ + public function testGetNamedInstance() + { + $s = new \Slim\Slim(); + $s->setName('foo'); + $this->assertSame($s, \Slim\Slim::getInstance('foo')); + } + + /** + * Test Slim autoloader ignores non-Slim classes + * + * Pre-conditions: + * Instantiate a non-Slim class; + * + * Post-conditions: + * Slim autoloader returns without requiring a class file; + */ + public function testSlimAutoloaderIgnoresNonSlimClass() + { + $foo = new Foo(); + } + + /************************************************ + * SETTINGS + ************************************************/ + + /** + * Test get setting that exists + */ + public function testGetSettingThatExists() + { + $s = new \Slim\Slim(); + $this->assertEquals('./templates', $s->config('templates.path')); + } + + /** + * Test get setting that does not exist + */ + public function testGetSettingThatDoesNotExist() + { + $s = new \Slim\Slim(); + $this->assertNull($s->config('foo')); + } + + /** + * Test set setting + */ + public function testSetSetting() + { + $s = new \Slim\Slim(); + $this->assertEquals('./templates', $s->config('templates.path')); + $s->config('templates.path', './tmpl'); + $this->assertEquals('./tmpl', $s->config('templates.path')); + } + + /** + * Test batch set settings + */ + public function testBatchSetSettings() + { + $s = new \Slim\Slim(); + $this->assertEquals('./templates', $s->config('templates.path')); + $this->assertTrue($s->config('debug')); + $s->config(array( + 'templates.path' => './tmpl', + 'debug' => false + )); + $this->assertEquals('./tmpl', $s->config('templates.path')); + $this->assertFalse($s->config('debug')); + } + + /** + * Test set settings recursively + */ + public function testSetSettingsRecursively() + { + $config = array( + 'my_module' => array( + 'paths' => array( + './my_module/path/1', + ), + ) + ); + + $s = new \Slim\Slim($config); + + $override = array( + 'my_module' => array( + 'paths' => array( + './my_module/path/2', + './my_module/path/3', + ), + ) + ); + + // Test recursive batch behaviour + $s->config($override, true); + + $expected = array( + 'paths' => array( + './my_module/path/1', + './my_module/path/2', + './my_module/path/3', + ), + ); + + $this->assertEquals($expected, $s->config('my_module')); + + // Test default batch behaviour + $s = new \Slim\Slim($config); + $s->config($override); + + $this->assertNotEquals($expected, $s->config('my_module')); + } + + /************************************************ + * MODES + ************************************************/ + + /** + * Test default mode + */ + public function testGetDefaultMode() + { + $s = new \Slim\Slim(); + $this->assertEquals('development', $s->getMode()); + } + + /** + * Test custom mode from environment + */ + public function testGetModeFromEnvironment() + { + $_ENV['SLIM_MODE'] = 'production'; + $s = new \Slim\Slim(); + $this->assertEquals('production', $s->getMode()); + } + + /** + * Test custom mode from app settings + */ + public function testGetModeFromSettings() + { + $s = new \Slim\Slim(array( + 'mode' => 'test' + )); + $this->assertEquals('test', $s->getMode()); + } + + /** + * Test mode configuration + */ + public function testModeConfiguration() + { + $flag = 0; + $configureTest = function () use (&$flag) { + $flag = 'test'; + }; + $configureProduction = function () use (&$flag) { + $flag = 'production'; + }; + $s = new \Slim\Slim(array('mode' => 'test')); + $s->configureMode('test', $configureTest); + $s->configureMode('production', $configureProduction); + $this->assertEquals('test', $flag); + } + + /** + * Test mode configuration when mode does not match + */ + public function testModeConfigurationWhenModeDoesNotMatch() + { + $flag = 0; + $configureTest = function () use (&$flag) { + $flag = 'test'; + }; + $s = new \Slim\Slim(array('mode' => 'production')); + $s->configureMode('test', $configureTest); + $this->assertEquals(0, $flag); + } + + /** + * Test mode configuration when not callable + */ + public function testModeConfigurationWhenNotCallable() + { + $flag = 0; + $s = new \Slim\Slim(array('mode' => 'production')); + $s->configureMode('production', 'foo'); + $this->assertEquals(0, $flag); + } + + /** + * Test custom mode from getenv() + */ + public function testGetModeFromGetEnv() + { + putenv('SLIM_MODE=production'); + $s = new \Slim\Slim(); + $this->assertEquals('production', $s->getMode()); + } + + /************************************************ + * ROUTING + ************************************************/ + + /** + * Test GENERIC route + */ + public function testGenericRoute() + { + $s = new \Slim\Slim(); + $callable = function () { echo "foo"; }; + $route = $s->map('/bar', $callable); + $this->assertInstanceOf('\Slim\Route', $route); + $this->assertEmpty($route->getHttpMethods()); + } + + /** + * Test GET routes also get mapped as a HEAD route + */ + public function testGetRouteIsAlsoMappedAsHead() + { + $s = new \Slim\Slim(); + $route = $s->get('/foo', function () {}); + $this->assertTrue($route->supportsHttpMethod(\Slim\Http\Request::METHOD_GET)); + $this->assertTrue($route->supportsHttpMethod(\Slim\Http\Request::METHOD_HEAD)); + } + + /** + * Test GET route + */ + public function testGetRoute() + { + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $route = $s->get('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + + /** + * Test POST route + */ + public function testPostRoute() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'POST', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $route = $s->post('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + + /** + * Test PUT route + */ + public function testPutRoute() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PUT', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $route = $s->put('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + + /** + * Test PATCH route + */ + public function testPatchRoute() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'PATCH', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $route = $s->patch('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + + /** + * Test DELETE route + */ + public function testDeleteRoute() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'DELETE', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $route = $s->delete('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + + /** + * Test OPTIONS route + */ + public function testOptionsRoute() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'OPTIONS', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $route = $s->options('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + + /** + * Test route groups + */ + public function testRouteGroups() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'GET', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar/baz', //<-- Virtual' + )); + $s = new \Slim\Slim(); + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $s->group('/bar', $mw1, function () use ($s, $mw2, $callable) { + $s->get('/baz', $mw2, $callable); + }); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + } + + /* + * Test ANY route + */ + public function testAnyRoute() + { + $mw1 = function () { echo "foo"; }; + $mw2 = function () { echo "bar"; }; + $callable = function () { echo "xyz"; }; + $methods = array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'); + foreach ($methods as $i => $method) { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => $method, + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $route = $s->any('/bar', $mw1, $mw2, $callable); + $s->call(); + $this->assertEquals('foobarxyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + $this->assertSame($callable, $route->getCallable()); + } + } + + /** + * Test if route does NOT expect trailing slash and URL has one + */ + public function testRouteWithoutSlashAndUrlWithOne() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar/', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () { echo "xyz"; }); + $s->call(); + $this->assertEquals(404, $s->response()->status()); + } + + /** + * Tests if route will match in case-insensitive manner if configured to do so + */ + public function testRouteMatchesInCaseInsensitiveMannerIfConfigured() + { + \Slim\Environment::mock(array( + 'PATH_INFO' => '/BaR', // Does not match route case + )); + $s = new \Slim\Slim(array('routes.case_sensitive' => false)); + $route = $s->get('/bar', function () { echo "xyz"; }); + $s->call(); + $this->assertEquals(200, $s->response()->status()); + $this->assertEquals('xyz', $s->response()->body()); + $this->assertEquals('/bar', $route->getPattern()); + } + + /** + * Test if route contains URL encoded characters + */ + public function testRouteWithUrlEncodedCharacters() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar/jo%20hn/smi%20th', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/bar/:one/:two', function ($one, $two) { echo $one . $two; }); + $s->call(); + $this->assertEquals('jo hnsmi th', $s->response()->body()); + } + + /************************************************ + * VIEW + ************************************************/ + + /** + * Test set view with string class name + */ + public function testSetSlimViewFromString() + { + $s = new \Slim\Slim(); + $this->assertInstanceOf('\Slim\View', $s->view()); + $s->view('CustomView'); + $this->assertInstanceOf('CustomView', $s->view()); + } + + /** + * Test set view with object instance + */ + public function testSetSlimViewFromInstance() + { + $s = new \Slim\Slim(); + $this->assertInstanceOf('\Slim\View', $s->view()); + $s->view(new CustomView()); + $this->assertInstanceOf('CustomView', $s->view()); + } + + /** + * Test view data is transferred to newer view + */ + public function testViewDataTransfer() + { + $data = array('foo' => 'bar'); + $s = new \Slim\Slim(); + $s->view()->setData($data); + $s->view('CustomView'); + $this->assertSame($data, $s->view()->getData()); + } + + /************************************************ + * RENDERING + ************************************************/ + + /** + * Test template path is passed to view + */ + public function testViewGetsTemplatesPath() + { + $path = dirname(__FILE__) . '/templates'; + $s = new \Slim\Slim(array('templates.path' => $path)); + $this->assertEquals($s->view->getTemplatesDirectory(), $path); + } + + /** + * Test render with template and data + */ + public function testRenderTemplateWithData() + { + $s = new \Slim\Slim(array('templates.path' => dirname(__FILE__) . '/templates')); + $s->get('/bar', function () use ($s) { + $s->render('test.php', array('foo' => 'bar')); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(200, $status); + $this->assertEquals('test output bar', $body); + } + + /** + * Test render with template and data and status + */ + public function testRenderTemplateWithDataAndStatus() + { + $s = new \Slim\Slim(array('templates.path' => dirname(__FILE__) . '/templates')); + $s->get('/bar', function () use ($s) { + $s->render('test.php', array('foo' => 'bar'), 500); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(500, $status); + $this->assertEquals('test output bar', $body); + } + + /************************************************ + * LOG + ************************************************/ + + /** + * Test get log + * + * This asserts that a Slim app has a default Log + * upon instantiation. The Log itself is tested + * separately in another file. + */ + public function testGetLog() + { + $s = new \Slim\Slim(); + $this->assertInstanceOf('\Slim\Log', $s->getLog()); + } + + /************************************************ + * HTTP CACHING + ************************************************/ + + /** + * Test Last-Modified match + */ + public function testLastModifiedMatch() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'GET', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 03 Oct 2010 21:00:52 GMT', + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->lastModified(1286139652); + }); + $s->call(); + $this->assertEquals(304, $s->response()->status()); + } + + /** + * Test Last-Modified match + */ + public function testLastModifiedDoesNotMatch() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'IF_MODIFIED_SINCE' => 'Sun, 03 Oct 2010 21:00:52 GMT', + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->lastModified(1286139250); + }); + $s->call(); + $this->assertEquals(200, $s->response()->status()); + } + + public function testLastModifiedOnlyAcceptsIntegers() + { + $this->setExpectedException('\InvalidArgumentException'); + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->lastModified('Test'); + }); + $s->call(); + } + + /** + * Test Last Modified header format + */ + public function testLastModifiedHeaderFormat() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->lastModified(1286139652); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertTrue(isset($header['Last-Modified'])); + $this->assertEquals('Sun, 03 Oct 2010 21:00:52 GMT', $header['Last-Modified']); + } + + /** + * Test ETag matches + */ + public function testEtagMatches() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'HTTP_IF_NONE_MATCH' => '"abc123"', + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->etag('abc123'); + }); + $s->call(); + $this->assertEquals(304, $s->response()->status()); + } + + /** + * Test ETag does not match + */ + public function testEtagDoesNotMatch() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'IF_NONE_MATCH' => '"abc1234"', + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->etag('abc123'); + }); + $s->call(); + $this->assertEquals(200, $s->response()->status()); + } + + /** + * Test ETag with invalid type + */ + public function testETagWithInvalidType() + { + $this->setExpectedException('\InvalidArgumentException'); + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'IF_NONE_MATCH' => '"abc1234"', + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->etag('123','foo'); + }); + $s->call(); + } + + /** + * Test Expires + */ + public function testExpiresAsString() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->expires('5 days'); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertTrue(isset($header['Expires'])); + + $this->assertEquals( + strtotime('5 days'), + strtotime($header['Expires']), + 1 // delta + ); + } + + /** + * Test Expires + */ + public function testExpiresAsInteger() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $fiveDaysFromNow = time() + (60 * 60 * 24 * 5); + $expectedDate = gmdate('D, d M Y H:i:s T', $fiveDaysFromNow); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s, $fiveDaysFromNow) { + $s->expires($fiveDaysFromNow); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertTrue(isset($header['Expires'])); + $this->assertEquals($header['Expires'], $expectedDate); + } + + /************************************************ + * COOKIES + ************************************************/ + + /** + * Set cookie + * + * This tests that the Slim application instance sets + * a cookie in the HTTP response header. This does NOT + * test the implementation of setting the cookie; that is + * tested in a separate file. + */ + public function testSetCookie() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->setCookie('foo', 'bar', '2 days'); + $s->setCookie('foo1', 'bar1', '2 days'); + }); + $s->call(); + $cookie1 = $s->response->cookies->get('foo'); + $cookie2 = $s->response->cookies->get('foo1'); + $this->assertEquals(2, count($s->response->cookies)); + $this->assertEquals('bar', $cookie1['value']); + $this->assertEquals('bar1', $cookie2['value']); + } + + /** + * Test get cookie + * + * This method ensures that the `Cookie:` HTTP request + * header is parsed if present, and made accessible via the + * Request object. + */ + public function testGetCookie() + { + \Slim\Environment::mock(array( + 'REQUEST_METHOD' => 'GET', + 'REMOTE_ADDR' => '127.0.0.1', + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'QUERY_STRING' => 'one=foo&two=bar', + 'SERVER_NAME' => 'slimframework.com', + 'SERVER_PORT' => 80, + 'HTTP_COOKIE' => 'foo=bar; foo2=bar2', + 'slim.url_scheme' => 'http', + 'slim.input' => '', + 'slim.errors' => @fopen('php://stderr', 'w') + )); + $s = new \Slim\Slim(); + $this->assertEquals('bar', $s->getCookie('foo')); + $this->assertEquals('bar2', $s->getCookie('foo2')); + } + + /** + * Test get cookie when cookie does not exist + */ + public function testGetCookieThatDoesNotExist() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + )); + $s = new \Slim\Slim(); + $this->assertNull($s->getCookie('foo')); + } + + /** + * Test delete cookie + * + * This method ensures that the `Set-Cookie:` HTTP response + * header is set. The implementation of setting the response + * cookie is tested separately in another file. + */ + public function testDeleteCookie() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/bar', //<-- Virtual + 'COOKIE' => 'foo=bar; foo2=bar2', + )); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->setCookie('foo', 'bar'); + $s->deleteCookie('foo'); + }); + $s->call(); + $cookie = $s->response->cookies->get('foo'); + $this->assertEquals(1, count($s->response->cookies)); + $this->assertEquals('', $cookie['value']); + $this->assertLessThan(time(), $cookie['expires']); + } + + /************************************************ + * HELPERS + ************************************************/ + + /** + * Test get filesystem path to Slim app root directory + */ + public function testGetRoot() + { + $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__); //<-- No trailing slash + $s = new \Slim\Slim(); + $this->assertEquals($_SERVER['DOCUMENT_ROOT'] . '/foo/', $s->root()); //<-- Appends physical app path with trailing slash + } + + /** + * Test stop + */ + public function testStop() + { + $this->setExpectedException('\Slim\Exception\Stop'); + $s = new \Slim\Slim(); + $s->stop(); + } + + /** + * Test stop with subsequent output + */ + public function testStopWithSubsequentOutput() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + echo "Foo"; //<-- Should be in response body! + $s->stop(); + echo "Bar"; //<-- Should not be in response body! + }); + $s->call(); + $this->assertEquals('Foo', $s->response()->body()); + } + + /** + * Test stop with output buffer on and pre content + */ + public function testStopOutputWithOutputBufferingOnAndPreContent() + { + $this->expectOutputString('1.2.Foo.3'); //<-- PHP unit uses OB here + echo "1."; + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + echo "Foo"; + $s->stop(); + }); + echo "2."; + $s->run(); //<-- Needs to be run to actually echo body + echo ".3"; + } + + /** + * Test stop does not leave output buffers open + */ + public function testStopDoesNotLeaveOutputBuffersOpen() + { + $level_start = ob_get_level(); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->stop(); + }); + $s->run(); + $this->assertEquals($level_start, ob_get_level()); + } + + /** + * Test halt + */ + public function testHalt() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + echo "Foo!"; //<-- Should not be in response body! + $s->halt(500, 'Something broke'); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(500, $status); + $this->assertEquals('Something broke', $body); + } + + /** + * Test halt with output buffering and pre content + */ + public function testHaltOutputWithOutputBufferingOnAndPreContent() + { + $this->expectOutputString('1.2.Something broke.3'); //<-- PHP unit uses OB here + echo "1."; + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + echo "Foo!"; //<-- Should not be in response body! + $s->halt(500, 'Something broke'); + }); + echo "2."; + $s->run(); + echo ".3"; + } + + /** + * Test halt does not leave output buffers open + */ + public function testHaltDoesNotLeaveOutputBuffersOpen() + { + $level_start = ob_get_level(); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->halt(500, ''); + }); + $s->run(); + $this->assertEquals($level_start, ob_get_level()); + } + + /** + * Test pass cleans buffer and throws exception + */ + public function testPass() + { + ob_start(); + $s = new \Slim\Slim(); + echo "Foo"; + try { + $s->pass(); + $this->fail('Did not catch Slim_Exception_Pass'); + } catch ( \Slim\Exception\Pass $e ) {} + $output = ob_get_clean(); + $this->assertEquals('', $output); + } + + /** + * Test pass when there is a subsequent fallback route + */ + public function testPassWithSubsequentRoute() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/name/Frank', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/name/Frank', function () use ($s) { + echo "Fail"; //<-- Should not be in response body! + $s->pass(); + }); + $s->get('/name/:name', function ($name) { + echo $name; //<-- Should be in response body! + }); + $s->call(); + $this->assertEquals('Frank', $s->response()->body()); + } + + /** + * Test pass when there is not a subsequent fallback route + */ + public function testPassWithoutSubsequentRoute() + { + \Slim\Environment::mock(array( + 'SCRIPT_NAME' => '/foo', //<-- Physical + 'PATH_INFO' => '/name/Frank', //<-- Virtual + )); + $s = new \Slim\Slim(); + $s->get('/name/Frank', function () use ($s) { + echo "Fail"; //<-- Should not be in response body! + $s->pass(); + }); + $s->call(); + $this->assertEquals(404, $s->response()->status()); + } + + /** + * Test content type + */ + public function testContentType() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->contentType('application/json'); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals('application/json', $header['Content-Type']); + } + + /** + * Test status + */ + public function testStatus() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->status(403); + }); + $s->call(); + $this->assertEquals(403, $s->response()->status()); + } + + /** + * Test URL for + */ + public function testSlimUrlFor() + { + $s = new \Slim\Slim(); + $s->get('/hello/:name', function () {})->name('hello'); + $this->assertEquals('/foo/hello/Josh', $s->urlFor('hello', array('name' => 'Josh'))); //<-- Prepends physical path! + } + + /** + * Test redirect sets status and header + */ + public function testRedirect() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + echo "Foo"; //<-- Should not be in response body! + $s->redirect('/somewhere/else', 303); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(303, $status); + $this->assertEquals('/somewhere/else', $header['Location']); + $this->assertEquals('', $body); + } + + /************************************************ + * RUNNER + ************************************************/ + + /** + * Test that runner sends headers and body + */ + public function testRun() + { + $this->expectOutputString('Foo'); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + echo "Foo"; + }); + $s->run(); + } + + /** + * Test runner output with output buffering on and pre content + */ + public function testRunOutputWithOutputBufferingOnAndPreContent() + { + $this->expectOutputString('1.2.Foo.3'); //<-- PHP unit uses OB here + $s = new \Slim\Slim(); + echo "1."; + $s->get('/bar', function () use ($s) { + echo "Foo"; + }); + echo "2."; + $s->run(); + echo ".3"; + } + + /** + * Test that runner does not leave output buffers open + */ + public function testRunDoesNotLeaveAnyOutputBuffersOpen() + { + $level_start = ob_get_level(); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) {}); + $s->run(); + $this->assertEquals($level_start, ob_get_level()); + } + + /************************************************ + * MIDDLEWARE + ************************************************/ + + /** + * Test add middleware + * + * This asserts that middleware are queued and called + * in sequence. This also asserts that the environment + * variables are passed by reference. + */ + public function testAddMiddleware() + { + $this->expectOutputString('FooHello'); + $s = new \Slim\Slim(); + $s->add(new CustomMiddleware()); //<-- See top of this file for class definition + $s->get('/bar', function () { + echo 'Foo'; + }); + $s->run(); + $this->assertEquals('Hello', $s->response()->header('X-Slim-Test')); + } + + /** + * Test exception when adding circular middleware queues + * + * This asserts that the same middleware can NOT be queued twice (usually by accident). + * Circular middleware stack causes a troublesome to debug PHP Fatal error: + * + * > Fatal error: Maximum function nesting level of '100' reached. aborting! + */ + public function testFailureWhenAddingCircularMiddleware() + { + $this->setExpectedException('\RuntimeException'); + $middleware = new CustomMiddleware; + $s = new \Slim\Slim; + $s->add($middleware); + $s->add(new CustomMiddleware); + $s->add($middleware); + $s->run(); + } + + /************************************************ + * FLASH MESSAGING + ************************************************/ + + public function testSetFlashForNextRequest() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->flash('info', 'bar'); + }); + $this->assertFalse(isset($_SESSION['slim.flash'])); + $s->run(); + $this->assertEquals('bar', $_SESSION['slim.flash']['info']); + } + + public function testSetFlashForCurrentRequest() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->flashNow('info', 'bar'); + }); + $s->run(); + $env = $s->environment(); + $this->assertEquals('bar', $env['slim.flash']['info']); + } + + public function testKeepFlashForNextRequest() + { + $_SESSION['slim.flash'] = array('info' => 'Foo'); + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->flashKeep(); + }); + $s->run(); + $this->assertEquals('Foo', $_SESSION['slim.flash']['info']); + } + + public function testFlashData() + { + $s = new \Slim\Slim(); + $s->get('/bar', function () use ($s) { + $s->flashNow('info', 'bar'); + }); + $s->run(); + $this->assertEquals(array('info' => 'bar'), $s->flashData()); + } + + /************************************************ + * NOT FOUND HANDLING + ************************************************/ + + /** + * Test custom Not Found handler + */ + public function testNotFound() + { + $s = new \Slim\Slim(); + $s->notFound(function () { + echo "Not Found"; + }); + $s->get('/foo', function () {}); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(404, $status); + $this->assertEquals('Not Found', $body); + } + + /************************************************ + * ERROR HANDLING + ************************************************/ + + /** + * Test default and custom error handlers + * + * Pre-conditions: + * Invoked app route calls default error handler; + * + * Post-conditions: + * Response status code is 500; + */ + public function testSlimError() + { + $s = new \Slim\Slim(array( + "log.enabled" => false + )); + $s->get('/bar', function () use ($s) { + $s->error(); + }); + $s->call(); + $this->assertEquals(500, $s->response()->status()); + } + + /** + * Test default error handler logs the error when debug is false. + * + * Pre-conditions: + * Invoked app route calls default error handler; + * + * Post-conditions: + * Error log is called + */ + public function testDefaultHandlerLogsTheErrorWhenDebugIsFalse() + { + $s = new \Slim\Slim(array('debug' => false)); + $s->container->singleton('log', function ($c) { + return new EchoErrorLogger(); + }); + $s->get('/bar', function () use ($s) { + throw new \InvalidArgumentException('my specific error message'); + }); + + ob_start(); + $s->run(); + $output = ob_get_clean(); + $this->assertTrue(strpos($output, 'InvalidArgumentException:my specific error message') !== false); + } + + /** + * Test triggered errors are converted to ErrorExceptions + * + * Pre-conditions: + * Custom error handler defined; + * Invoked app route triggers error; + * + * Post-conditions: + * Response status is 500; + * Response body is equal to triggered error message; + * Error handler's argument is ErrorException instance; + */ + public function DISABLEDtestTriggeredErrorsAreConvertedToErrorExceptions() + { + $s = new \Slim\Slim(array( + 'debug' => false + )); + $s->error(function ( $e ) { + if ($e instanceof \ErrorException) { + echo $e->getMessage(); + } + }); + $s->get('/bar', function () { + trigger_error('Foo I say!'); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(500, $status); + $this->assertEquals('Foo I say!', $body); + } + + /** + * Test error triggered with multiple applications + * + * Pre-conditions: + * Multiple Slim apps are instantiated; + * Both apps are run; + * One app returns 200 OK; + * One app triggers an error; + * + * Post-conditions: + * One app returns 200 OK with no Exceptions; + * One app returns 500 Error; + * Error triggered does not affect other app; + */ + public function testErrorWithMultipleApps() + { + $s1 = new \Slim\Slim(array( + 'debug' => false, + 'log.enabled' => false + )); + $s2 = new \Slim\Slim(); + $s1->get('/bar', function () use ($s1) { + $s1->error(); + }); + $s2->get('/bar', function () { + echo 'success'; + }); + $s1->call(); + $s2->call(); + $this->assertEquals(500, $s1->response()->status()); + $this->assertEquals(200, $s2->response()->status()); + } + + /** + * Test custom error handler uses existing Response object + */ + public function testErrorHandlerUsesCurrentResponseObject() + { + $s = new \Slim\Slim(array( + 'debug' => false + )); + $s->error(function ( \Exception $e ) use ($s) { + $r = $s->response(); + $r->status(503); + $r->write('Foo'); + $r['X-Powered-By'] = 'Slim'; + echo 'Bar'; + }); + $s->get('/bar', function () { + throw new \Exception('Foo'); + }); + $s->call(); + list($status, $header, $body) = $s->response()->finalize(); + $this->assertEquals(503, $status); + $this->assertEquals('FooBar', $body); + $this->assertEquals('Slim', $header['X-Powered-By']); + } + + /** + * Test custom global error handler + */ + public function testHandleErrors() + { + $defaultErrorReporting = error_reporting(); + + // Test 1 + error_reporting(E_ALL ^ E_NOTICE); // <-- Report all errors EXCEPT notices + try { + \Slim\Slim::handleErrors(E_NOTICE, 'test error', 'Slim.php', 119); + } catch (\ErrorException $e) { + $this->fail('Slim::handleErrors reported a disabled error level.'); + } + + // Test 2 + error_reporting(E_ALL | E_STRICT); // <-- Report all errors, including E_STRICT + try { + \Slim\Slim::handleErrors(E_STRICT, 'test error', 'Slim.php', 119); + $this->fail('Slim::handleErrors didn\'t report a enabled error level'); + } catch (\ErrorException $e) {} + + error_reporting($defaultErrorReporting); + } + + /** + * Slim should keep reference to a callable error callback + */ + public function testErrorHandler() { + $s = new \Slim\Slim(); + $errCallback = function () { echo "404"; }; + $s->error($errCallback); + $this->assertSame($errCallback, PHPUnit_Framework_Assert::readAttribute($s, 'error')); + } + + /** + * Slim should throw a Slim_Exception_Stop if error callback is not callable + */ + public function testErrorHandlerIfNotCallable() { + $this->setExpectedException('\Slim\Exception\Stop'); + $s = new \Slim\Slim(array("log.enabled" => false)); + $errCallback = 'foo'; + $s->error($errCallback); + } + + /** + * Slim should keep reference to a callable NotFound callback + */ + public function testNotFoundHandler() { + $s = new \Slim\Slim(); + $notFoundCallback = function () { echo "404"; }; + $s->notFound($notFoundCallback); + $this->assertSame($notFoundCallback, PHPUnit_Framework_Assert::readAttribute($s, 'notFound')); + } + + /** + * Slim should throw a Slim_Exception_Stop if NotFound callback is not callable + */ + public function testNotFoundHandlerIfNotCallable() { + $this->setExpectedException('\Slim\Exception\Stop'); + $s = new \Slim\Slim(); + $notFoundCallback = 'foo'; + $s->notFound($notFoundCallback); + } + + /************************************************ + * HOOKS + ************************************************/ + + /** + * Test hook listener + * + * Pre-conditions: + * Slim app instantiated; + * Hook name does not exist; + * Listeners are callable objects; + * + * Post-conditions: + * Callables are invoked in expected order; + */ + public function testRegistersAndCallsHooksByPriority() + { + $this->expectOutputString('barfoo'); + $app = new \Slim\Slim(); + $callable1 = function () { echo "foo"; }; + $callable2 = function () { echo "bar"; }; + $app->hook('test.hook.one', $callable1); //default is 10 + $app->hook('test.hook.one', $callable2, 8); + $hooks = $app->getHooks(); + $this->assertEquals(7, count($hooks)); //6 default, 1 custom + $app->applyHook('test.hook.one'); + } + + /** + * Test hook listener if listener is not callable + * + * Pre-conditions: + * Slim app instantiated; + * Hook name does not exist; + * Listener is NOT a callable object; + * + * Post-conditions: + * Hook is created; + * Callable is NOT assigned to hook; + */ + public function testHookInvalidCallable() + { + $app = new \Slim\Slim(); + $callable = 'test'; //NOT callable + $app->hook('test.hook.one', $callable); + $this->assertEquals(array(array()), $app->getHooks('test.hook.one')); + } + + /** + * Test hook invocation if hook does not exist + * + * Pre-conditions: + * Slim app instantiated; + * Hook name does not exist; + * + * Post-conditions: + * Hook is created; + * Hook initialized with empty array; + */ + public function testHookInvocationIfNotExists() + { + $app = new \Slim\Slim(); + $app->applyHook('test.hook.one'); + $this->assertEquals(array(array()), $app->getHooks('test.hook.one')); + } + + /** + * Test clear hooks + * + * Pre-conditions: + * Slim app instantiated; + * Two hooks exist, each with one listener; + * + * Post-conditions: + * Case A: Listeners for 'test.hook.one' are cleared; + * Case B: Listeners for all hooks are cleared; + */ + public function testHookClear() + { + $app = new \Slim\Slim(); + $app->hook('test.hook.one', function () {}); + $app->hook('test.hook.two', function () {}); + $app->clearHooks('test.hook.two'); + $this->assertEquals(array(array()), $app->getHooks('test.hook.two')); + $hookOne = $app->getHooks('test.hook.one'); + $this->assertTrue(count($hookOne[10]) === 1); + $app->clearHooks(); + $this->assertEquals(array(array()), $app->getHooks('test.hook.one')); + } + + /** + * Test hooks accept multiple arguments + * + * Pre-conditions: + * Slim app instantiated; + * Hook name does not exist; + * Listener is a callable object; + * + * Post-conditions: + * Callable invoked with 2 arguments + */ + public function testHooksMultipleArguments() + { + $testArgA = 'argumentA'; + $testArgB = 'argumentB'; + + $this->expectOutputString($testArgA . $testArgB); + + $app = new \Slim\Slim(); + + $app->hook('test.hook.one', function ($argA, $argB) { + echo $argA . $argB; + }); + $app->applyHook('test.hook.one', $testArgA, $testArgB); + } + + /** + * Test late static binding + * + * Pre-conditions: + * Slim app is extended by Derived class and instantiated; + * Derived class overrides the 'getDefaultSettings' function and adds an extra default config value + * Test that the new config value exists + * + * Post-conditions: + * Config value exists and is equal to expected value + */ + public function testDerivedClassCanOverrideStaticFunction() + { + $app = new Derived(); + $this->assertEquals($app->config("late-static-binding"), true); + } +} diff --git a/vendor/slim/slim/tests/ViewTest.php b/vendor/slim/slim/tests/ViewTest.php new file mode 100755 index 0000000..5d84b8b --- /dev/null +++ b/vendor/slim/slim/tests/ViewTest.php @@ -0,0 +1,199 @@ + + * @copyright 2011 Josh Lockhart + * @link http://www.slimframework.com + * @license http://www.slimframework.com/license + * @version 2.6.1 + * + * MIT LICENSE + * + * 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. + */ + +class ViewTest extends PHPUnit_Framework_TestCase +{ + public function testGetDataAll() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $prop->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar'))); + + $this->assertSame(array('foo' => 'bar'), $view->getData()); + } + + public function testGetDataKeyExists() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $prop->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar'))); + + $this->assertEquals('bar', $view->getData('foo')); + } + + public function testGetDataKeyNotExists() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $prop->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar'))); + + $this->assertNull($view->getData('abc')); + } + + public function testSetDataKeyValue() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $view->setData('foo', 'bar'); + + $this->assertEquals(array('foo' => 'bar'), $prop->getValue($view)->all()); + } + + public function testSetDataKeyValueAsClosure() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + + $view->setData('fooClosure', function () { + return 'foo'; + }); + + $value = $prop->getValue($view)->get('fooClosure'); + $this->assertInstanceOf('Closure', $value); + $this->assertEquals('foo', $value()); + } + + public function testSetDataArray() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $view->setData(array('foo' => 'bar')); + + $this->assertEquals(array('foo' => 'bar'), $prop->getValue($view)->all()); + } + + public function testSetDataInvalidArgument() + { + $this->setExpectedException('InvalidArgumentException'); + + $view = new \Slim\View(); + $view->setData('foo'); + } + + public function testAppendData() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $view->appendData(array('foo' => 'bar')); + + $this->assertEquals(array('foo' => 'bar'), $prop->getValue($view)->all()); + } + + public function testLocalData() + { + $view = new \Slim\View(); + $prop1 = new \ReflectionProperty($view, 'data'); + $prop1->setAccessible(true); + $prop1->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar'))); + + $prop2 = new \ReflectionProperty($view, 'templatesDirectory'); + $prop2->setAccessible(true); + $prop2->setValue($view, dirname(__FILE__) . '/templates'); + + $output = $view->fetch('test.php', array('foo' => 'baz')); + $this->assertEquals('test output baz', $output); + } + + public function testAppendDataOverwrite() + { + $view = new \Slim\View(); + $prop = new \ReflectionProperty($view, 'data'); + $prop->setAccessible(true); + $prop->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar'))); + $view->appendData(array('foo' => '123')); + + $this->assertEquals(array('foo' => '123'), $prop->getValue($view)->all()); + } + + public function testAppendDataInvalidArgument() + { + $this->setExpectedException('InvalidArgumentException'); + + $view = new \Slim\View(); + $view->appendData('foo'); + } + + public function testGetTemplatesDirectory() + { + $view = new \Slim\View(); + $property = new \ReflectionProperty($view, 'templatesDirectory'); + $property->setAccessible(true); + $property->setValue($view, 'templates'); + + $this->assertEquals('templates', $view->getTemplatesDirectory()); + } + + public function testSetTemplatesDirectory() + { + $view = new \Slim\View(); + $directory = 'templates' . DIRECTORY_SEPARATOR; + $view->setTemplatesDirectory($directory); // <-- Should strip trailing slash + + $this->assertAttributeEquals('templates', 'templatesDirectory', $view); + } + + public function testDisplay() + { + $this->expectOutputString('test output bar'); + + $view = new \Slim\View(); + $prop1 = new \ReflectionProperty($view, 'data'); + $prop1->setAccessible(true); + $prop1->setValue($view, new \Slim\Helper\Set(array('foo' => 'bar'))); + + $prop2 = new \ReflectionProperty($view, 'templatesDirectory'); + $prop2->setAccessible(true); + $prop2->setValue($view, dirname(__FILE__) . '/templates'); + + $view->display('test.php'); + } + + public function testDisplayTemplateThatDoesNotExist() + { + $this->setExpectedException('\RuntimeException'); + + $view = new \Slim\View(); + + $prop2 = new \ReflectionProperty($view, 'templatesDirectory'); + $prop2->setAccessible(true); + $prop2->setValue($view, dirname(__FILE__) . '/templates'); + + $view->display('foo.php'); + } +} diff --git a/vendor/slim/slim/tests/bootstrap.php b/vendor/slim/slim/tests/bootstrap.php new file mode 100755 index 0000000..c253350 --- /dev/null +++ b/vendor/slim/slim/tests/bootstrap.php @@ -0,0 +1,22 @@ + diff --git a/vendor/slim/views/README.md b/vendor/slim/views/README.md new file mode 100755 index 0000000..99a1200 --- /dev/null +++ b/vendor/slim/views/README.md @@ -0,0 +1,181 @@ +# Slim Views + +This repository contains custom View classes for the template frameworks listed below. +You can use any of these custom View classes by either requiring the appropriate class in your +Slim Framework bootstrap file and initialize your Slim application using an instance of +the selected View class or using Composer (the recommended way). + +Slim Views only officially support the following views listed below. + +- Smarty +- Twig + +## How to Install + +#### using [Composer](http://getcomposer.org/) + +Install in your project by running the following composer command: + +```bash +$ php composer require slim/views +``` + +## Smarty + +### How to use + +```php + new \Slim\Views\Smarty() +)); +``` + +To use Smarty options do the following: + +```php +$view = $app->view(); +$view->parserDirectory = dirname(__FILE__) . 'smarty'; +$view->parserCompileDirectory = dirname(__FILE__) . '/compiled'; +$view->parserCacheDirectory = dirname(__FILE__) . '/cache'; +``` + +## Twig + +### How to use + +```php + new \Slim\Views\Twig() +)); +``` + +To use Twig options do the following: + +```php +$view = $app->view(); +$view->parserOptions = array( + 'debug' => true, + 'cache' => dirname(__FILE__) . '/cache' +); +``` + +In addition to all of this we also have a few helper functions which are included for both view parsers. +In order to start using these you can add them to their respective view parser as stated below: + +#### Twig + +```php +$view->parserExtensions = array( + new \Slim\Views\TwigExtension(), +); +``` + +#### Smarty + +```php +$view->parserExtensions = array( + dirname(__FILE__) . '/vendor/slim/views/Slim/Views/SmartyPlugins', +); +``` + +These helpers are listed below. + +- urlFor +- siteUrl +- baseUrl +- currentUrl + +#### urlFor + +__Twig__ + +Inside your Twig template you would write: + + {{ urlFor('hello', {"name": "Josh", "age": "19"}) }} + +You can easily pass variables that are objects or arrays by doing: + + Hello {{ name }} + +If you need to specify the appname for the getInstance method in the urlFor functions, set it as the third parameter of the function +in your template: + + Hello {{ name }} + +__Smarty__ + +Inside your Smarty template you would write: + + {urlFor name="hello" options="name.Josh|age.26"} + +or with the new array syntax: + + {urlFor name="hello" options=["name" => "Josh", "age" => "26"]} + +You can easily pass variables that are arrays as normal or using the (.): + + Hello {$name} + +If you need to specify the appname for the getInstance method in the urlFor functions, set the appname parameter in your function: + + Hello {$name} + +#### siteUrl + +__Twig__ + +Inside your Twig template you would write: + + {{ siteUrl('/about/me') }} + +__Smarty__ + +Inside your Smarty template you would write: + + {siteUrl url='/about/me'} + + +#### baseUrl + +__Twig__ + +Inside your Twig template you would write: + + {{ baseUrl() }} + +__Smarty__ + +Inside your Smarty template you would write: + + {baseUrl} + + +#### currentUrl + +__Twig__ + +Inside your Twig template you would write: + + {{ currentUrl() }} + +__Smarty__ + +Inside your Smarty template you would write: + + {currentUrl} + +## Authors + +[Josh Lockhart](https://github.com/codeguy) + +[Andrew Smith](https://github.com/silentworks) + +## License + +MIT Public License \ No newline at end of file diff --git a/vendor/slim/views/Smarty.php b/vendor/slim/views/Smarty.php new file mode 100755 index 0000000..1f5f9da --- /dev/null +++ b/vendor/slim/views/Smarty.php @@ -0,0 +1,124 @@ + + */ +class Smarty extends \Slim\View +{ + /** + * @var string The path to the Smarty code directory WITHOUT the trailing slash + */ + public $parserDirectory = null; + + /** + * @var string The path to the Smarty compiled templates folder WITHOUT the trailing slash + */ + public $parserCompileDirectory = null; + + /** + * @var string The path to the Smarty cache folder WITHOUT the trailing slash + */ + public $parserCacheDirectory = null; + + /** + * @var SmartyExtensions The Smarty extensions directory you want to load plugins from + */ + public $parserExtensions = array(); + + /** + * @var parserInstance persistent instance of the Parser object. + */ + private $parserInstance = null; + + /** + * Render Template + * + * This method will output the rendered template content + * + * @param string $template The path to the template, relative to the templates directory. + * @param null $data + * @return string + */ + public function render($template, $data = null) + { + $parser = $this->getInstance(); + $parser->assign($this->all()); + + return $parser->fetch($template, $data); + } + + /** + * Creates new Smarty object instance if it doesn't already exist, and returns it. + * + * @throws \RuntimeException If Smarty lib directory does not exist + * @return \Smarty Instance + */ + public function getInstance() + { + if (!($this->parserInstance instanceof \Smarty)) { + if (!class_exists('\Smarty')) { + if (!is_dir($this->parserDirectory)) { + throw new \RuntimeException('Cannot set the Smarty lib directory : ' . $this->parserDirectory . '. Directory does not exist.'); + } + require_once $this->parserDirectory . '/Smarty.class.php'; + } + + $this->parserInstance = new \Smarty(); + $this->parserInstance->template_dir = $this->getTemplatesDirectory(); + if ($this->parserExtensions) { + $this->parserInstance->addPluginsDir($this->parserExtensions); + } + if ($this->parserCompileDirectory) { + $this->parserInstance->compile_dir = $this->parserCompileDirectory; + } + if ($this->parserCacheDirectory) { + $this->parserInstance->cache_dir = $this->parserCacheDirectory; + } + } + + return $this->parserInstance; + } +} diff --git a/vendor/slim/views/SmartyPlugins/function.baseUrl.php b/vendor/slim/views/SmartyPlugins/function.baseUrl.php new file mode 100755 index 0000000..ce800b6 --- /dev/null +++ b/vendor/slim/views/SmartyPlugins/function.baseUrl.php @@ -0,0 +1,26 @@ +request(); + $uri = $req->getUrl(); + + if ($withUri) { + $uri .= $req->getRootUri(); + } + + return $uri; +} diff --git a/vendor/slim/views/SmartyPlugins/function.currentUrl.php b/vendor/slim/views/SmartyPlugins/function.currentUrl.php new file mode 100755 index 0000000..a35927b --- /dev/null +++ b/vendor/slim/views/SmartyPlugins/function.currentUrl.php @@ -0,0 +1,31 @@ +request(); + $uri = $req->getUrl() . $req->getPath(); + + if ($withQueryString) { + $env = $app->environment(); + + if ($env['QUERY_STRING']) { + $uri .= '?' . $env['QUERY_STRING']; + } + } + + return $uri; +} diff --git a/vendor/slim/views/SmartyPlugins/function.siteUrl.php b/vendor/slim/views/SmartyPlugins/function.siteUrl.php new file mode 100755 index 0000000..f08baa5 --- /dev/null +++ b/vendor/slim/views/SmartyPlugins/function.siteUrl.php @@ -0,0 +1,27 @@ +request(); + $uri = $req->getUrl(); + + if ($withUri) { + $uri .= $req->getRootUri(); + } + + return $uri . '/' . ltrim($url, '/'); +} diff --git a/vendor/slim/views/SmartyPlugins/function.urlFor.php b/vendor/slim/views/SmartyPlugins/function.urlFor.php new file mode 100755 index 0000000..0a4150f --- /dev/null +++ b/vendor/slim/views/SmartyPlugins/function.urlFor.php @@ -0,0 +1,42 @@ +urlFor($name); + + if (isset($params['options'])) { + switch (gettype($params['options'])) { + case 'array': + $opts = $params['options']; + break; + + case 'string': + $options = explode('|', $params['options']); + foreach ($options as $option) { + list($key, $value) = explode('.', $option); + $opts[$key] = $value; + } + break; + + default: + throw new \Exception('Options parameter is of unknown type, provide either string or array'); + } + + $url = \Slim\Slim::getInstance($appName)->urlFor($name, $opts); + } + + return $url; +} diff --git a/vendor/slim/views/Twig.php b/vendor/slim/views/Twig.php new file mode 100755 index 0000000..a76ddd2 --- /dev/null +++ b/vendor/slim/views/Twig.php @@ -0,0 +1,153 @@ +getInstance(); + $parser = $env->loadTemplate($template); + + $data = array_merge($this->all(), (array) $data); + + return $parser->render($data); + } + + /** + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * Use getInstance method instead + */ + public function getEnvironment() + { + return $this->getInstance(); + } + + /** + * Creates new TwigEnvironment if it doesn't already exist, and returns it. + * + * @return \Twig_Environment + */ + public function getInstance() + { + if (!$this->parserInstance) { + /** + * Check if Twig_Autoloader class exists + * otherwise include it. + */ + if (!class_exists('\Twig_Autoloader')) { + require_once $this->parserDirectory . '/Autoloader.php'; + } + + \Twig_Autoloader::register(); + $loader = new \Twig_Loader_Filesystem($this->getTemplateDirs()); + $this->parserInstance = new \Twig_Environment( + $loader, + $this->parserOptions + ); + + foreach ($this->parserExtensions as $ext) { + $extension = is_object($ext) ? $ext : new $ext; + $this->parserInstance->addExtension($extension); + } + } + + return $this->parserInstance; + } + + /** + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * Get a list of template directories + * + * Returns an array of templates defined by self::$twigTemplateDirs, falls + * back to Slim\View's built-in getTemplatesDirectory method. + * + * @return array + **/ + private function getTemplateDirs() + { + if (empty($this->twigTemplateDirs)) { + return array($this->getTemplatesDirectory()); + } + return $this->twigTemplateDirs; + } +} diff --git a/vendor/slim/views/TwigExtension.php b/vendor/slim/views/TwigExtension.php new file mode 100755 index 0000000..f5e7bb5 --- /dev/null +++ b/vendor/slim/views/TwigExtension.php @@ -0,0 +1,91 @@ +urlFor($name, $params); + } + + public function site($url, $withUri = true, $appName = 'default') + { + return $this->base($withUri, $appName) . '/' . ltrim($url, '/'); + } + + public function base($withUri = true, $appName = 'default') + { + $req = Slim::getInstance($appName)->request(); + $uri = $req->getUrl(); + + if ($withUri) { + $uri .= $req->getRootUri(); + } + return $uri; + } + + public function currentUrl($withQueryString = true, $appName = 'default') + { + $app = Slim::getInstance($appName); + $req = $app->request(); + $uri = $req->getUrl() . $req->getPath(); + + if ($withQueryString) { + $env = $app->environment(); + + if ($env['QUERY_STRING']) { + $uri .= '?' . $env['QUERY_STRING']; + } + } + + return $uri; + } +} diff --git a/vendor/slim/views/composer.json b/vendor/slim/views/composer.json new file mode 100755 index 0000000..2a1bf52 --- /dev/null +++ b/vendor/slim/views/composer.json @@ -0,0 +1,33 @@ +{ + "name": "slim/views", + "type": "library", + "description": "Smarty and Twig View Parser package for the Slim Framework", + "keywords": ["templating", "extensions", "slimphp"], + "homepage": "http://github.com/codeguy/Slim-Views", + "license": "MIT", + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://thoughts.silentworks.co.uk/" + } + ], + "require": { + "slim/slim": ">=2.4.0", + "php": ">=5.3.0" + }, + "suggest": { + "smarty/smarty": "Smarty templating system", + "twig/twig": "Twig templating system" + }, + "autoload": { + "psr-4": { + "Slim\\Views\\": "./" + } + } +} diff --git a/vendor/symfony/translation/CHANGELOG.md b/vendor/symfony/translation/CHANGELOG.md new file mode 100755 index 0000000..157752c --- /dev/null +++ b/vendor/symfony/translation/CHANGELOG.md @@ -0,0 +1,47 @@ +CHANGELOG +========= + +2.7.0 +----- + + * added DataCollectorTranslator for collecting the translated messages. + +2.6.0 +----- + + * added possibility to cache catalogues + * added TranslatorBagInterface + * added LoggingTranslator + * added Translator::getMessages() for retrieving the message catalogue as an array + +2.5.0 +----- + + * added relative file path template to the file dumpers + * added optional backup to the file dumpers + * changed IcuResFileDumper to extend FileDumper + +2.3.0 +----- + + * added classes to make operations on catalogues (like making a diff or a merge on 2 catalogues) + * added Translator::getFallbackLocales() + * deprecated Translator::setFallbackLocale() in favor of the new Translator::setFallbackLocales() method + +2.2.0 +----- + + * QtTranslationsLoader class renamed to QtFileLoader. QtTranslationsLoader is deprecated and will be removed in 2.3. + * [BC BREAK] uniformized the exception thrown by the load() method when an error occurs. The load() method now + throws Symfony\Component\Translation\Exception\NotFoundResourceException when a resource cannot be found + and Symfony\Component\Translation\Exception\InvalidResourceException when a resource is invalid. + * changed the exception class thrown by some load() methods from \RuntimeException to \InvalidArgumentException + (IcuDatFileLoader, IcuResFileLoader and QtFileLoader) + +2.1.0 +----- + + * added support for more than one fallback locale + * added support for extracting translation messages from templates (Twig and PHP) + * added dumpers for translation catalogs + * added support for QT, gettext, and ResourceBundles diff --git a/vendor/symfony/translation/Catalogue/AbstractOperation.php b/vendor/symfony/translation/Catalogue/AbstractOperation.php new file mode 100755 index 0000000..062056b --- /dev/null +++ b/vendor/symfony/translation/Catalogue/AbstractOperation.php @@ -0,0 +1,146 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Catalogue; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\MessageCatalogueInterface; + +/** + * Base catalogues binary operation class. + * + * @author Jean-François Simon + */ +abstract class AbstractOperation implements OperationInterface +{ + /** + * @var MessageCatalogueInterface + */ + protected $source; + + /** + * @var MessageCatalogueInterface + */ + protected $target; + + /** + * @var MessageCatalogue + */ + protected $result; + + /** + * @var null|array + */ + private $domains; + + /** + * @var array + */ + protected $messages; + + /** + * @param MessageCatalogueInterface $source + * @param MessageCatalogueInterface $target + * + * @throws \LogicException + */ + public function __construct(MessageCatalogueInterface $source, MessageCatalogueInterface $target) + { + if ($source->getLocale() !== $target->getLocale()) { + throw new \LogicException('Operated catalogues must belong to the same locale.'); + } + + $this->source = $source; + $this->target = $target; + $this->result = new MessageCatalogue($source->getLocale()); + $this->domains = null; + $this->messages = array(); + } + + /** + * {@inheritdoc} + */ + public function getDomains() + { + if (null === $this->domains) { + $this->domains = array_values(array_unique(array_merge($this->source->getDomains(), $this->target->getDomains()))); + } + + return $this->domains; + } + + /** + * {@inheritdoc} + */ + public function getMessages($domain) + { + if (!in_array($domain, $this->getDomains())) { + throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain)); + } + + if (!isset($this->messages[$domain]['all'])) { + $this->processDomain($domain); + } + + return $this->messages[$domain]['all']; + } + + /** + * {@inheritdoc} + */ + public function getNewMessages($domain) + { + if (!in_array($domain, $this->getDomains())) { + throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain)); + } + + if (!isset($this->messages[$domain]['new'])) { + $this->processDomain($domain); + } + + return $this->messages[$domain]['new']; + } + + /** + * {@inheritdoc} + */ + public function getObsoleteMessages($domain) + { + if (!in_array($domain, $this->getDomains())) { + throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain)); + } + + if (!isset($this->messages[$domain]['obsolete'])) { + $this->processDomain($domain); + } + + return $this->messages[$domain]['obsolete']; + } + + /** + * {@inheritdoc} + */ + public function getResult() + { + foreach ($this->getDomains() as $domain) { + if (!isset($this->messages[$domain])) { + $this->processDomain($domain); + } + } + + return $this->result; + } + + /** + * @param string $domain + */ + abstract protected function processDomain($domain); +} diff --git a/vendor/symfony/translation/Catalogue/DiffOperation.php b/vendor/symfony/translation/Catalogue/DiffOperation.php new file mode 100755 index 0000000..2d1994e --- /dev/null +++ b/vendor/symfony/translation/Catalogue/DiffOperation.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Catalogue; + +/** + * Diff operation between two catalogues. + * + * @author Jean-François Simon + */ +class DiffOperation extends AbstractOperation +{ + /** + * {@inheritdoc} + */ + protected function processDomain($domain) + { + $this->messages[$domain] = array( + 'all' => array(), + 'new' => array(), + 'obsolete' => array(), + ); + + foreach ($this->source->all($domain) as $id => $message) { + if ($this->target->has($id, $domain)) { + $this->messages[$domain]['all'][$id] = $message; + $this->result->add(array($id => $message), $domain); + if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) { + $this->result->setMetadata($id, $keyMetadata, $domain); + } + } else { + $this->messages[$domain]['obsolete'][$id] = $message; + } + } + + foreach ($this->target->all($domain) as $id => $message) { + if (!$this->source->has($id, $domain)) { + $this->messages[$domain]['all'][$id] = $message; + $this->messages[$domain]['new'][$id] = $message; + $this->result->add(array($id => $message), $domain); + if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) { + $this->result->setMetadata($id, $keyMetadata, $domain); + } + } + } + } +} diff --git a/vendor/symfony/translation/Catalogue/MergeOperation.php b/vendor/symfony/translation/Catalogue/MergeOperation.php new file mode 100755 index 0000000..562ca0e --- /dev/null +++ b/vendor/symfony/translation/Catalogue/MergeOperation.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Catalogue; + +/** + * Merge operation between two catalogues. + * + * @author Jean-François Simon + */ +class MergeOperation extends AbstractOperation +{ + /** + * {@inheritdoc} + */ + protected function processDomain($domain) + { + $this->messages[$domain] = array( + 'all' => array(), + 'new' => array(), + 'obsolete' => array(), + ); + + foreach ($this->source->all($domain) as $id => $message) { + $this->messages[$domain]['all'][$id] = $message; + $this->result->add(array($id => $message), $domain); + if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) { + $this->result->setMetadata($id, $keyMetadata, $domain); + } + } + + foreach ($this->target->all($domain) as $id => $message) { + if (!$this->source->has($id, $domain)) { + $this->messages[$domain]['all'][$id] = $message; + $this->messages[$domain]['new'][$id] = $message; + $this->result->add(array($id => $message), $domain); + if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) { + $this->result->setMetadata($id, $keyMetadata, $domain); + } + } + } + } +} diff --git a/vendor/symfony/translation/Catalogue/OperationInterface.php b/vendor/symfony/translation/Catalogue/OperationInterface.php new file mode 100755 index 0000000..d72378a --- /dev/null +++ b/vendor/symfony/translation/Catalogue/OperationInterface.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Catalogue; + +use Symfony\Component\Translation\MessageCatalogueInterface; + +/** + * Represents an operation on catalogue(s). + * + * @author Jean-François Simon + */ +interface OperationInterface +{ + /** + * Returns domains affected by operation. + * + * @return array + */ + public function getDomains(); + + /** + * Returns all valid messages after operation. + * + * @param string $domain + * + * @return array + */ + public function getMessages($domain); + + /** + * Returns new messages after operation. + * + * @param string $domain + * + * @return array + */ + public function getNewMessages($domain); + + /** + * Returns obsolete messages after operation. + * + * @param string $domain + * + * @return array + */ + public function getObsoleteMessages($domain); + + /** + * Returns resulting catalogue. + * + * @return MessageCatalogueInterface + */ + public function getResult(); +} diff --git a/vendor/symfony/translation/DataCollector/TranslationDataCollector.php b/vendor/symfony/translation/DataCollector/TranslationDataCollector.php new file mode 100755 index 0000000..eb9d1e7 --- /dev/null +++ b/vendor/symfony/translation/DataCollector/TranslationDataCollector.php @@ -0,0 +1,145 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\DataCollector; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\DataCollector\DataCollector; +use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; +use Symfony\Component\Translation\DataCollectorTranslator; + +/** + * @author Abdellatif Ait boudad + */ +class TranslationDataCollector extends DataCollector implements LateDataCollectorInterface +{ + /** + * @var DataCollectorTranslator + */ + private $translator; + + /** + * @param DataCollectorTranslator $translator + */ + public function __construct(DataCollectorTranslator $translator) + { + $this->translator = $translator; + } + + /** + * {@inheritdoc} + */ + public function lateCollect() + { + $messages = $this->sanitizeCollectedMessages($this->translator->getCollectedMessages()); + + $this->data = $this->computeCount($messages); + $this->data['messages'] = $messages; + } + + /** + * {@inheritdoc} + */ + public function collect(Request $request, Response $response, \Exception $exception = null) + { + } + + /** + * @return array + */ + public function getMessages() + { + return isset($this->data['messages']) ? $this->data['messages'] : array(); + } + + /** + * @return int + */ + public function getCountMissings() + { + return isset($this->data[DataCollectorTranslator::MESSAGE_MISSING]) ? $this->data[DataCollectorTranslator::MESSAGE_MISSING] : 0; + } + + /** + * @return int + */ + public function getCountFallbacks() + { + return isset($this->data[DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK]) ? $this->data[DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK] : 0; + } + + /** + * @return int + */ + public function getCountDefines() + { + return isset($this->data[DataCollectorTranslator::MESSAGE_DEFINED]) ? $this->data[DataCollectorTranslator::MESSAGE_DEFINED] : 0; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'translation'; + } + + private function sanitizeCollectedMessages($messages) + { + $result = array(); + foreach ($messages as $key => $message) { + $messageId = $message['locale'].$message['domain'].$message['id']; + + if (!isset($result[$messageId])) { + $message['count'] = 1; + $messages[$key]['translation'] = $this->sanitizeString($message['translation']); + $result[$messageId] = $message; + } else { + $result[$messageId]['count']++; + } + + unset($messages[$key]); + } + + return $result; + } + + private function computeCount($messages) + { + $count = array( + DataCollectorTranslator::MESSAGE_DEFINED => 0, + DataCollectorTranslator::MESSAGE_MISSING => 0, + DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK => 0, + ); + + foreach ($messages as $message) { + ++$count[$message['state']]; + } + + return $count; + } + + private function sanitizeString($string, $length = 80) + { + $string = trim(preg_replace('/\s+/', ' ', $string)); + + if (function_exists('mb_strlen') && false !== $encoding = mb_detect_encoding($string)) { + if (mb_strlen($string, $encoding) > $length) { + return mb_substr($string, 0, $length - 3, $encoding).'...'; + } + } elseif (strlen($string) > $length) { + return substr($string, 0, $length - 3).'...'; + } + + return $string; + } +} diff --git a/vendor/symfony/translation/DataCollectorTranslator.php b/vendor/symfony/translation/DataCollectorTranslator.php new file mode 100755 index 0000000..813a857 --- /dev/null +++ b/vendor/symfony/translation/DataCollectorTranslator.php @@ -0,0 +1,152 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * @author Abdellatif Ait boudad + */ +class DataCollectorTranslator implements TranslatorInterface, TranslatorBagInterface +{ + const MESSAGE_DEFINED = 0; + const MESSAGE_MISSING = 1; + const MESSAGE_EQUALS_FALLBACK = 2; + + /** + * @var TranslatorInterface|TranslatorBagInterface + */ + private $translator; + + /** + * @var array + */ + private $messages = array(); + + /** + * @param TranslatorInterface $translator The translator must implement TranslatorBagInterface + */ + public function __construct(TranslatorInterface $translator) + { + if (!$translator instanceof TranslatorBagInterface) { + throw new \InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', get_class($translator))); + } + + $this->translator = $translator; + } + + /** + * {@inheritdoc} + */ + public function trans($id, array $parameters = array(), $domain = null, $locale = null) + { + $trans = $this->translator->trans($id, $parameters, $domain, $locale); + $this->collectMessage($locale, $domain, $id, $trans); + + return $trans; + } + + /** + * {@inheritdoc} + */ + public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) + { + $trans = $this->translator->transChoice($id, $number, $parameters, $domain, $locale); + $this->collectMessage($locale, $domain, $id, $trans); + + return $trans; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function setLocale($locale) + { + $this->translator->setLocale($locale); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getLocale() + { + return $this->translator->getLocale(); + } + + /** + * {@inheritdoc} + */ + public function getCatalogue($locale = null) + { + return $this->translator->getCatalogue($locale); + } + + /** + * Passes through all unknown calls onto the translator object. + */ + public function __call($method, $args) + { + return call_user_func_array(array($this->translator, $method), $args); + } + + /** + * @return array + */ + public function getCollectedMessages() + { + return $this->messages; + } + + /** + * @param string|null $locale + * @param string|null $domain + * @param string $id + * @param string $trans + */ + private function collectMessage($locale, $domain, $id, $translation) + { + if (null === $domain) { + $domain = 'messages'; + } + + $id = (string) $id; + $catalogue = $this->translator->getCatalogue($locale); + $locale = $catalogue->getLocale(); + if ($catalogue->defines($id, $domain)) { + $state = self::MESSAGE_DEFINED; + } elseif ($catalogue->has($id, $domain)) { + $state = self::MESSAGE_EQUALS_FALLBACK; + + $fallbackCatalogue = $catalogue->getFallBackCatalogue(); + while ($fallbackCatalogue) { + if ($fallbackCatalogue->defines($id, $domain)) { + $locale = $fallbackCatalogue->getLocale(); + break; + } + + $fallbackCatalogue = $fallbackCatalogue->getFallBackCatalogue(); + } + } else { + $state = self::MESSAGE_MISSING; + } + + $this->messages[] = array( + 'locale' => $locale, + 'domain' => $domain, + 'id' => $id, + 'translation' => $translation, + 'state' => $state, + ); + } +} diff --git a/vendor/symfony/translation/Dumper/CsvFileDumper.php b/vendor/symfony/translation/Dumper/CsvFileDumper.php new file mode 100755 index 0000000..08005b0 --- /dev/null +++ b/vendor/symfony/translation/Dumper/CsvFileDumper.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * CsvFileDumper generates a csv formatted string representation of a message catalogue. + * + * @author Stealth35 + */ +class CsvFileDumper extends FileDumper +{ + private $delimiter = ';'; + private $enclosure = '"'; + + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain = 'messages') + { + $handle = fopen('php://memory', 'rb+'); + + foreach ($messages->all($domain) as $source => $target) { + fputcsv($handle, array($source, $target), $this->delimiter, $this->enclosure); + } + + rewind($handle); + $output = stream_get_contents($handle); + fclose($handle); + + return $output; + } + + /** + * Sets the delimiter and escape character for CSV. + * + * @param string $delimiter delimiter character + * @param string $enclosure enclosure character + */ + public function setCsvControl($delimiter = ';', $enclosure = '"') + { + $this->delimiter = $delimiter; + $this->enclosure = $enclosure; + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'csv'; + } +} diff --git a/vendor/symfony/translation/Dumper/DumperInterface.php b/vendor/symfony/translation/Dumper/DumperInterface.php new file mode 100755 index 0000000..cebc65e --- /dev/null +++ b/vendor/symfony/translation/Dumper/DumperInterface.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * DumperInterface is the interface implemented by all translation dumpers. + * There is no common option. + * + * @author Michel Salib + */ +interface DumperInterface +{ + /** + * Dumps the message catalogue. + * + * @param MessageCatalogue $messages The message catalogue + * @param array $options Options that are used by the dumper + */ + public function dump(MessageCatalogue $messages, $options = array()); +} diff --git a/vendor/symfony/translation/Dumper/FileDumper.php b/vendor/symfony/translation/Dumper/FileDumper.php new file mode 100755 index 0000000..f2f17d6 --- /dev/null +++ b/vendor/symfony/translation/Dumper/FileDumper.php @@ -0,0 +1,122 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s). + * Performs backup of already existing files. + * + * Options: + * - path (mandatory): the directory where the files should be saved + * + * @author Michel Salib + */ +abstract class FileDumper implements DumperInterface +{ + /** + * A template for the relative paths to files. + * + * @var string + */ + protected $relativePathTemplate = '%domain%.%locale%.%extension%'; + + /** + * Make file backup before the dump. + * + * @var bool + */ + private $backup = true; + + /** + * Sets the template for the relative paths to files. + * + * @param string $relativePathTemplate A template for the relative paths to files + */ + public function setRelativePathTemplate($relativePathTemplate) + { + $this->relativePathTemplate = $relativePathTemplate; + } + + /** + * Sets backup flag. + * + * @param bool + */ + public function setBackup($backup) + { + $this->backup = $backup; + } + + /** + * {@inheritdoc} + */ + public function dump(MessageCatalogue $messages, $options = array()) + { + if (!array_key_exists('path', $options)) { + throw new \InvalidArgumentException('The file dumper needs a path option.'); + } + + // save a file for each domain + foreach ($messages->getDomains() as $domain) { + // backup + $fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale()); + if (file_exists($fullpath)) { + if ($this->backup) { + copy($fullpath, $fullpath.'~'); + } + } else { + $directory = dirname($fullpath); + if (!file_exists($directory) && !@mkdir($directory, 0777, true)) { + throw new \RuntimeException(sprintf('Unable to create directory "%s".', $directory)); + } + } + // save file + file_put_contents($fullpath, $this->format($messages, $domain)); + } + } + + /** + * Transforms a domain of a message catalogue to its string representation. + * + * @param MessageCatalogue $messages + * @param string $domain + * + * @return string representation + */ + abstract protected function format(MessageCatalogue $messages, $domain); + + /** + * Gets the file extension of the dumper. + * + * @return string file extension + */ + abstract protected function getExtension(); + + /** + * Gets the relative file path using the template. + * + * @param string $domain The domain + * @param string $locale The locale + * + * @return string The relative file path + */ + private function getRelativePath($domain, $locale) + { + return strtr($this->relativePathTemplate, array( + '%domain%' => $domain, + '%locale%' => $locale, + '%extension%' => $this->getExtension(), + )); + } +} diff --git a/vendor/symfony/translation/Dumper/IcuResFileDumper.php b/vendor/symfony/translation/Dumper/IcuResFileDumper.php new file mode 100755 index 0000000..0a2ed9f --- /dev/null +++ b/vendor/symfony/translation/Dumper/IcuResFileDumper.php @@ -0,0 +1,112 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * IcuResDumper generates an ICU ResourceBundle formatted string representation of a message catalogue. + * + * @author Stealth35 + */ +class IcuResFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + protected $relativePathTemplate = '%domain%/%locale%.%extension%'; + + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain = 'messages') + { + $data = $indexes = $resources = ''; + + foreach ($messages->all($domain) as $source => $target) { + $indexes .= pack('v', strlen($data) + 28); + $data .= $source."\0"; + } + + $data .= $this->writePadding($data); + + $keyTop = $this->getPosition($data); + + foreach ($messages->all($domain) as $source => $target) { + $resources .= pack('V', $this->getPosition($data)); + + $data .= pack('V', strlen($target)) + .mb_convert_encoding($target."\0", 'UTF-16LE', 'UTF-8') + .$this->writePadding($data) + ; + } + + $resOffset = $this->getPosition($data); + + $data .= pack('v', count($messages)) + .$indexes + .$this->writePadding($data) + .$resources + ; + + $bundleTop = $this->getPosition($data); + + $root = pack('V7', + $resOffset + (2 << 28), // Resource Offset + Resource Type + 6, // Index length + $keyTop, // Index keys top + $bundleTop, // Index resources top + $bundleTop, // Index bundle top + count($messages), // Index max table length + 0 // Index attributes + ); + + $header = pack('vC2v4C12@32', + 32, // Header size + 0xDA, 0x27, // Magic number 1 and 2 + 20, 0, 0, 2, // Rest of the header, ..., Size of a char + 0x52, 0x65, 0x73, 0x42, // Data format identifier + 1, 2, 0, 0, // Data version + 1, 4, 0, 0 // Unicode version + ); + + $output = $header + .$root + .$data; + + return $output; + } + + private function writePadding($data) + { + $padding = strlen($data) % 4; + + if ($padding) { + return str_repeat("\xAA", 4 - $padding); + } + } + + private function getPosition($data) + { + $position = (strlen($data) + 28) / 4; + + return $position; + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'res'; + } +} diff --git a/vendor/symfony/translation/Dumper/IniFileDumper.php b/vendor/symfony/translation/Dumper/IniFileDumper.php new file mode 100755 index 0000000..45df389 --- /dev/null +++ b/vendor/symfony/translation/Dumper/IniFileDumper.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * IniFileDumper generates an ini formatted string representation of a message catalogue. + * + * @author Stealth35 + */ +class IniFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain = 'messages') + { + $output = ''; + + foreach ($messages->all($domain) as $source => $target) { + $escapeTarget = str_replace('"', '\"', $target); + $output .= $source.'="'.$escapeTarget."\"\n"; + } + + return $output; + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'ini'; + } +} diff --git a/vendor/symfony/translation/Dumper/JsonFileDumper.php b/vendor/symfony/translation/Dumper/JsonFileDumper.php new file mode 100755 index 0000000..7ad3518 --- /dev/null +++ b/vendor/symfony/translation/Dumper/JsonFileDumper.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * JsonFileDumper generates an json formatted string representation of a message catalogue. + * + * @author singles + */ +class JsonFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain = 'messages') + { + return json_encode($messages->all($domain), defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'json'; + } +} diff --git a/vendor/symfony/translation/Dumper/MoFileDumper.php b/vendor/symfony/translation/Dumper/MoFileDumper.php new file mode 100755 index 0000000..f8dc6ac --- /dev/null +++ b/vendor/symfony/translation/Dumper/MoFileDumper.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Loader\MoFileLoader; + +/** + * MoFileDumper generates a gettext formatted string representation of a message catalogue. + * + * @author Stealth35 + */ +class MoFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain = 'messages') + { + $output = $sources = $targets = $sourceOffsets = $targetOffsets = ''; + $offsets = array(); + $size = 0; + + foreach ($messages->all($domain) as $source => $target) { + $offsets[] = array_map('strlen', array($sources, $source, $targets, $target)); + $sources .= "\0".$source; + $targets .= "\0".$target; + ++$size; + } + + $header = array( + 'magicNumber' => MoFileLoader::MO_LITTLE_ENDIAN_MAGIC, + 'formatRevision' => 0, + 'count' => $size, + 'offsetId' => MoFileLoader::MO_HEADER_SIZE, + 'offsetTranslated' => MoFileLoader::MO_HEADER_SIZE + (8 * $size), + 'sizeHashes' => 0, + 'offsetHashes' => MoFileLoader::MO_HEADER_SIZE + (16 * $size), + ); + + $sourcesSize = strlen($sources); + $sourcesStart = $header['offsetHashes'] + 1; + + foreach ($offsets as $offset) { + $sourceOffsets .= $this->writeLong($offset[1]) + .$this->writeLong($offset[0] + $sourcesStart); + $targetOffsets .= $this->writeLong($offset[3]) + .$this->writeLong($offset[2] + $sourcesStart + $sourcesSize); + } + + $output = implode(array_map(array($this, 'writeLong'), $header)) + .$sourceOffsets + .$targetOffsets + .$sources + .$targets + ; + + return $output; + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'mo'; + } + + private function writeLong($str) + { + return pack('V*', $str); + } +} diff --git a/vendor/symfony/translation/Dumper/PhpFileDumper.php b/vendor/symfony/translation/Dumper/PhpFileDumper.php new file mode 100755 index 0000000..b354c12 --- /dev/null +++ b/vendor/symfony/translation/Dumper/PhpFileDumper.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * PhpFileDumper generates PHP files from a message catalogue. + * + * @author Michel Salib + */ +class PhpFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + protected function format(MessageCatalogue $messages, $domain) + { + $output = "all($domain), true).";\n"; + + return $output; + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'php'; + } +} diff --git a/vendor/symfony/translation/Dumper/PoFileDumper.php b/vendor/symfony/translation/Dumper/PoFileDumper.php new file mode 100755 index 0000000..983064b --- /dev/null +++ b/vendor/symfony/translation/Dumper/PoFileDumper.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * PoFileDumper generates a gettext formatted string representation of a message catalogue. + * + * @author Stealth35 + */ +class PoFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain = 'messages') + { + $output = 'msgid ""'."\n"; + $output .= 'msgstr ""'."\n"; + $output .= '"Content-Type: text/plain; charset=UTF-8\n"'."\n"; + $output .= '"Content-Transfer-Encoding: 8bit\n"'."\n"; + $output .= '"Language: '.$messages->getLocale().'\n"'."\n"; + $output .= "\n"; + + $newLine = false; + foreach ($messages->all($domain) as $source => $target) { + if ($newLine) { + $output .= "\n"; + } else { + $newLine = true; + } + $output .= sprintf('msgid "%s"'."\n", $this->escape($source)); + $output .= sprintf('msgstr "%s"', $this->escape($target)); + } + + return $output; + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'po'; + } + + private function escape($str) + { + return addcslashes($str, "\0..\37\42\134"); + } +} diff --git a/vendor/symfony/translation/Dumper/QtFileDumper.php b/vendor/symfony/translation/Dumper/QtFileDumper.php new file mode 100755 index 0000000..42aa093 --- /dev/null +++ b/vendor/symfony/translation/Dumper/QtFileDumper.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * QtFileDumper generates ts files from a message catalogue. + * + * @author Benjamin Eberlei + */ +class QtFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + public function format(MessageCatalogue $messages, $domain) + { + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->formatOutput = true; + $ts = $dom->appendChild($dom->createElement('TS')); + $context = $ts->appendChild($dom->createElement('context')); + $context->appendChild($dom->createElement('name', $domain)); + + foreach ($messages->all($domain) as $source => $target) { + $message = $context->appendChild($dom->createElement('message')); + $message->appendChild($dom->createElement('source', $source)); + $message->appendChild($dom->createElement('translation', $target)); + } + + return $dom->saveXML(); + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'ts'; + } +} diff --git a/vendor/symfony/translation/Dumper/XliffFileDumper.php b/vendor/symfony/translation/Dumper/XliffFileDumper.php new file mode 100755 index 0000000..58d1973 --- /dev/null +++ b/vendor/symfony/translation/Dumper/XliffFileDumper.php @@ -0,0 +1,109 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * XliffFileDumper generates xliff files from a message catalogue. + * + * @author Michel Salib + */ +class XliffFileDumper extends FileDumper +{ + /** + * @var string + */ + private $defaultLocale; + + /** + * {@inheritdoc} + */ + public function dump(MessageCatalogue $messages, $options = array()) + { + if (array_key_exists('default_locale', $options)) { + $this->defaultLocale = $options['default_locale']; + } else { + $this->defaultLocale = \Locale::getDefault(); + } + + parent::dump($messages, $options); + } + + /** + * {@inheritdoc} + */ + protected function format(MessageCatalogue $messages, $domain) + { + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->formatOutput = true; + + $xliff = $dom->appendChild($dom->createElement('xliff')); + $xliff->setAttribute('version', '1.2'); + $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2'); + + $xliffFile = $xliff->appendChild($dom->createElement('file')); + $xliffFile->setAttribute('source-language', str_replace('_', '-', $this->defaultLocale)); + $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale())); + $xliffFile->setAttribute('datatype', 'plaintext'); + $xliffFile->setAttribute('original', 'file.ext'); + + $xliffBody = $xliffFile->appendChild($dom->createElement('body')); + foreach ($messages->all($domain) as $source => $target) { + $translation = $dom->createElement('trans-unit'); + + $translation->setAttribute('id', md5($source)); + $translation->setAttribute('resname', $source); + + $s = $translation->appendChild($dom->createElement('source')); + $s->appendChild($dom->createTextNode($source)); + + // Does the target contain characters requiring a CDATA section? + $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target); + + $t = $translation->appendChild($dom->createElement('target')); + $t->appendChild($text); + + $metadata = $messages->getMetadata($source, $domain); + if (null !== $metadata && array_key_exists('notes', $metadata) && is_array($metadata['notes'])) { + foreach ($metadata['notes'] as $note) { + if (!isset($note['content'])) { + continue; + } + + $n = $translation->appendChild($dom->createElement('note')); + $n->appendChild($dom->createTextNode($note['content'])); + + if (isset($note['priority'])) { + $n->setAttribute('priority', $note['priority']); + } + + if (isset($note['from'])) { + $n->setAttribute('from', $note['from']); + } + } + } + + $xliffBody->appendChild($translation); + } + + return $dom->saveXML(); + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'xlf'; + } +} diff --git a/vendor/symfony/translation/Dumper/YamlFileDumper.php b/vendor/symfony/translation/Dumper/YamlFileDumper.php new file mode 100755 index 0000000..870fb98 --- /dev/null +++ b/vendor/symfony/translation/Dumper/YamlFileDumper.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Yaml\Yaml; + +/** + * YamlFileDumper generates yaml files from a message catalogue. + * + * @author Michel Salib + */ +class YamlFileDumper extends FileDumper +{ + /** + * {@inheritdoc} + */ + protected function format(MessageCatalogue $messages, $domain) + { + if (!class_exists('Symfony\Component\Yaml\Yaml')) { + throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.'); + } + + return Yaml::dump($messages->all($domain)); + } + + /** + * {@inheritdoc} + */ + protected function getExtension() + { + return 'yml'; + } +} diff --git a/vendor/symfony/translation/Exception/ExceptionInterface.php b/vendor/symfony/translation/Exception/ExceptionInterface.php new file mode 100755 index 0000000..7757e66 --- /dev/null +++ b/vendor/symfony/translation/Exception/ExceptionInterface.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Exception; + +/** + * Exception interface for all exceptions thrown by the component. + * + * @author Fabien Potencier + * + * @api + */ +interface ExceptionInterface +{ +} diff --git a/vendor/symfony/translation/Exception/InvalidResourceException.php b/vendor/symfony/translation/Exception/InvalidResourceException.php new file mode 100755 index 0000000..6413f1a --- /dev/null +++ b/vendor/symfony/translation/Exception/InvalidResourceException.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Exception; + +/** + * Thrown when a resource cannot be loaded. + * + * @author Fabien Potencier + * + * @api + */ +class InvalidResourceException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/symfony/translation/Exception/NotFoundResourceException.php b/vendor/symfony/translation/Exception/NotFoundResourceException.php new file mode 100755 index 0000000..7826e5c --- /dev/null +++ b/vendor/symfony/translation/Exception/NotFoundResourceException.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Exception; + +/** + * Thrown when a resource does not exist. + * + * @author Fabien Potencier + * + * @api + */ +class NotFoundResourceException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/symfony/translation/Extractor/AbstractFileExtractor.php b/vendor/symfony/translation/Extractor/AbstractFileExtractor.php new file mode 100755 index 0000000..196bc33 --- /dev/null +++ b/vendor/symfony/translation/Extractor/AbstractFileExtractor.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Extractor; + +/** + * Base class used by classes that extract translation messages from files. + * + * @author Marcos D. Sánchez + */ +abstract class AbstractFileExtractor +{ + /** + * @param string|array $resource files, a file or a directory + * + * @return array + */ + protected function extractFiles($resource) + { + if (is_array($resource) || $resource instanceof \Traversable) { + $files = array(); + foreach ($resource as $file) { + if ($this->canBeExtracted($file)) { + $files[] = $this->toSplFileInfo($file); + } + } + } elseif (is_file($resource)) { + $files = $this->canBeExtracted($resource) ? array($this->toSplFileInfo($resource)) : array(); + } else { + $files = $this->extractFromDirectory($resource); + } + + return $files; + } + + /** + * @param string $file + * + * @return \SplFileInfo + */ + private function toSplFileInfo($file) + { + return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file); + } + + /** + * @param string $file + * + * @throws \InvalidArgumentException + * + * @return bool + */ + protected function isFile($file) + { + if (!is_file($file)) { + throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $file)); + } + + return true; + } + + /** + * @param string $file + * + * @return bool + */ + abstract protected function canBeExtracted($file); + + /** + * @param string|array $resource files, a file or a directory + * + * @return array files to be extracted + */ + abstract protected function extractFromDirectory($resource); +} diff --git a/vendor/symfony/translation/Extractor/ChainExtractor.php b/vendor/symfony/translation/Extractor/ChainExtractor.php new file mode 100755 index 0000000..50e3c84 --- /dev/null +++ b/vendor/symfony/translation/Extractor/ChainExtractor.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Extractor; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * ChainExtractor extracts translation messages from template files. + * + * @author Michel Salib + */ +class ChainExtractor implements ExtractorInterface +{ + /** + * The extractors. + * + * @var ExtractorInterface[] + */ + private $extractors = array(); + + /** + * Adds a loader to the translation extractor. + * + * @param string $format The format of the loader + * @param ExtractorInterface $extractor The loader + */ + public function addExtractor($format, ExtractorInterface $extractor) + { + $this->extractors[$format] = $extractor; + } + + /** + * {@inheritdoc} + */ + public function setPrefix($prefix) + { + foreach ($this->extractors as $extractor) { + $extractor->setPrefix($prefix); + } + } + + /** + * {@inheritdoc} + */ + public function extract($directory, MessageCatalogue $catalogue) + { + foreach ($this->extractors as $extractor) { + $extractor->extract($directory, $catalogue); + } + } +} diff --git a/vendor/symfony/translation/Extractor/ExtractorInterface.php b/vendor/symfony/translation/Extractor/ExtractorInterface.php new file mode 100755 index 0000000..438f80b --- /dev/null +++ b/vendor/symfony/translation/Extractor/ExtractorInterface.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Extractor; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * Extracts translation messages from a directory or files to the catalogue. + * New found messages are injected to the catalogue using the prefix. + * + * @author Michel Salib + */ +interface ExtractorInterface +{ + /** + * Extracts translation messages from files, a file or a directory to the catalogue. + * + * @param string|array $resource files, a file or a directory + * @param MessageCatalogue $catalogue The catalogue + */ + public function extract($resource, MessageCatalogue $catalogue); + + /** + * Sets the prefix that should be used for new found messages. + * + * @param string $prefix The prefix + */ + public function setPrefix($prefix); +} diff --git a/vendor/symfony/translation/IdentityTranslator.php b/vendor/symfony/translation/IdentityTranslator.php new file mode 100755 index 0000000..9c9212e --- /dev/null +++ b/vendor/symfony/translation/IdentityTranslator.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * IdentityTranslator does not translate anything. + * + * @author Fabien Potencier + * + * @api + */ +class IdentityTranslator implements TranslatorInterface +{ + private $selector; + private $locale; + + /** + * Constructor. + * + * @param MessageSelector|null $selector The message selector for pluralization + * + * @api + */ + public function __construct(MessageSelector $selector = null) + { + $this->selector = $selector ?: new MessageSelector(); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function setLocale($locale) + { + $this->locale = $locale; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getLocale() + { + return $this->locale ?: \Locale::getDefault(); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function trans($id, array $parameters = array(), $domain = null, $locale = null) + { + return strtr((string) $id, $parameters); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) + { + return strtr($this->selector->choose((string) $id, (int) $number, $locale ?: $this->getLocale()), $parameters); + } +} diff --git a/vendor/symfony/translation/Interval.php b/vendor/symfony/translation/Interval.php new file mode 100755 index 0000000..2a51156 --- /dev/null +++ b/vendor/symfony/translation/Interval.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * Tests if a given number belongs to a given math interval. + * + * An interval can represent a finite set of numbers: + * + * {1,2,3,4} + * + * An interval can represent numbers between two numbers: + * + * [1, +Inf] + * ]-1,2[ + * + * The left delimiter can be [ (inclusive) or ] (exclusive). + * The right delimiter can be [ (exclusive) or ] (inclusive). + * Beside numbers, you can use -Inf and +Inf for the infinite. + * + * @author Fabien Potencier + * + * @see http://en.wikipedia.org/wiki/Interval_%28mathematics%29#The_ISO_notation + */ +class Interval +{ + /** + * Tests if the given number is in the math interval. + * + * @param int $number A number + * @param string $interval An interval + * + * @return bool + * + * @throws \InvalidArgumentException + */ + public static function test($number, $interval) + { + $interval = trim($interval); + + if (!preg_match('/^'.self::getIntervalRegexp().'$/x', $interval, $matches)) { + throw new \InvalidArgumentException(sprintf('"%s" is not a valid interval.', $interval)); + } + + if ($matches[1]) { + foreach (explode(',', $matches[2]) as $n) { + if ($number == $n) { + return true; + } + } + } else { + $leftNumber = self::convertNumber($matches['left']); + $rightNumber = self::convertNumber($matches['right']); + + return + ('[' === $matches['left_delimiter'] ? $number >= $leftNumber : $number > $leftNumber) + && (']' === $matches['right_delimiter'] ? $number <= $rightNumber : $number < $rightNumber) + ; + } + + return false; + } + + /** + * Returns a Regexp that matches valid intervals. + * + * @return string A Regexp (without the delimiters) + */ + public static function getIntervalRegexp() + { + return <<[\[\]]) + \s* + (?P-Inf|\-?\d+(\.\d+)?) + \s*,\s* + (?P\+?Inf|\-?\d+(\.\d+)?) + \s* + (?P[\[\]]) +EOF; + } + + private static function convertNumber($number) + { + if ('-Inf' === $number) { + return log(0); + } elseif ('+Inf' === $number || 'Inf' === $number) { + return -log(0); + } + + return (float) $number; + } +} diff --git a/vendor/symfony/translation/LICENSE b/vendor/symfony/translation/LICENSE new file mode 100755 index 0000000..43028bc --- /dev/null +++ b/vendor/symfony/translation/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2004-2015 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/vendor/symfony/translation/Loader/ArrayLoader.php b/vendor/symfony/translation/Loader/ArrayLoader.php new file mode 100755 index 0000000..68ba81d --- /dev/null +++ b/vendor/symfony/translation/Loader/ArrayLoader.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * ArrayLoader loads translations from a PHP array. + * + * @author Fabien Potencier + * + * @api + */ +class ArrayLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + $this->flatten($resource); + $catalogue = new MessageCatalogue($locale); + $catalogue->add($resource, $domain); + + return $catalogue; + } + + /** + * Flattens an nested array of translations. + * + * The scheme used is: + * 'key' => array('key2' => array('key3' => 'value')) + * Becomes: + * 'key.key2.key3' => 'value' + * + * This function takes an array by reference and will modify it + * + * @param array &$messages The array that will be flattened + * @param array $subnode Current subnode being parsed, used internally for recursive calls + * @param string $path Current path being parsed, used internally for recursive calls + */ + private function flatten(array &$messages, array $subnode = null, $path = null) + { + if (null === $subnode) { + $subnode = &$messages; + } + foreach ($subnode as $key => $value) { + if (is_array($value)) { + $nodePath = $path ? $path.'.'.$key : $key; + $this->flatten($messages, $value, $nodePath); + if (null === $path) { + unset($messages[$key]); + } + } elseif (null !== $path) { + $messages[$path.'.'.$key] = $value; + } + } + } +} diff --git a/vendor/symfony/translation/Loader/CsvFileLoader.php b/vendor/symfony/translation/Loader/CsvFileLoader.php new file mode 100755 index 0000000..fc92760 --- /dev/null +++ b/vendor/symfony/translation/Loader/CsvFileLoader.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * CsvFileLoader loads translations from CSV files. + * + * @author Saša Stamenković + * + * @api + */ +class CsvFileLoader extends ArrayLoader +{ + private $delimiter = ';'; + private $enclosure = '"'; + private $escape = '\\'; + + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + $messages = array(); + + try { + $file = new \SplFileObject($resource, 'rb'); + } catch (\RuntimeException $e) { + throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e); + } + + $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY); + $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape); + + foreach ($file as $data) { + if (substr($data[0], 0, 1) === '#') { + continue; + } + + if (!isset($data[1])) { + continue; + } + + if (count($data) == 2) { + $messages[$data[0]] = $data[1]; + } else { + continue; + } + } + + $catalogue = parent::load($messages, $locale, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } + + /** + * Sets the delimiter, enclosure, and escape character for CSV. + * + * @param string $delimiter delimiter character + * @param string $enclosure enclosure character + * @param string $escape escape character + */ + public function setCsvControl($delimiter = ';', $enclosure = '"', $escape = '\\') + { + $this->delimiter = $delimiter; + $this->enclosure = $enclosure; + $this->escape = $escape; + } +} diff --git a/vendor/symfony/translation/Loader/IcuDatFileLoader.php b/vendor/symfony/translation/Loader/IcuDatFileLoader.php new file mode 100755 index 0000000..71ba90a --- /dev/null +++ b/vendor/symfony/translation/Loader/IcuDatFileLoader.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * IcuResFileLoader loads translations from a resource bundle. + * + * @author stealth35 + */ +class IcuDatFileLoader extends IcuResFileLoader +{ + /** + * {@inheritdoc} + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource.'.dat')) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource.'.dat')) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + try { + $rb = new \ResourceBundle($locale, $resource); + } catch (\Exception $e) { + // HHVM compatibility: constructor throws on invalid resource + $rb = null; + } + + if (!$rb) { + throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource)); + } elseif (intl_is_failure($rb->getErrorCode())) { + throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode()); + } + + $messages = $this->flatten($rb); + $catalogue = new MessageCatalogue($locale); + $catalogue->add($messages, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource.'.dat')); + } + + return $catalogue; + } +} diff --git a/vendor/symfony/translation/Loader/IcuResFileLoader.php b/vendor/symfony/translation/Loader/IcuResFileLoader.php new file mode 100755 index 0000000..2f8037f --- /dev/null +++ b/vendor/symfony/translation/Loader/IcuResFileLoader.php @@ -0,0 +1,92 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\DirectoryResource; + +/** + * IcuResFileLoader loads translations from a resource bundle. + * + * @author stealth35 + */ +class IcuResFileLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!is_dir($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + try { + $rb = new \ResourceBundle($locale, $resource); + } catch (\Exception $e) { + // HHVM compatibility: constructor throws on invalid resource + $rb = null; + } + + if (!$rb) { + throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource)); + } elseif (intl_is_failure($rb->getErrorCode())) { + throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode()); + } + + $messages = $this->flatten($rb); + $catalogue = new MessageCatalogue($locale); + $catalogue->add($messages, $domain); + + if (class_exists('Symfony\Component\Config\Resource\DirectoryResource')) { + $catalogue->addResource(new DirectoryResource($resource)); + } + + return $catalogue; + } + + /** + * Flattens an ResourceBundle. + * + * The scheme used is: + * key { key2 { key3 { "value" } } } + * Becomes: + * 'key.key2.key3' => 'value' + * + * This function takes an array by reference and will modify it + * + * @param \ResourceBundle $rb the ResourceBundle that will be flattened + * @param array $messages used internally for recursive calls + * @param string $path current path being parsed, used internally for recursive calls + * + * @return array the flattened ResourceBundle + */ + protected function flatten(\ResourceBundle $rb, array &$messages = array(), $path = null) + { + foreach ($rb as $key => $value) { + $nodePath = $path ? $path.'.'.$key : $key; + if ($value instanceof \ResourceBundle) { + $this->flatten($value, $messages, $nodePath); + } else { + $messages[$nodePath] = $value; + } + } + + return $messages; + } +} diff --git a/vendor/symfony/translation/Loader/IniFileLoader.php b/vendor/symfony/translation/Loader/IniFileLoader.php new file mode 100755 index 0000000..1b3a7b1 --- /dev/null +++ b/vendor/symfony/translation/Loader/IniFileLoader.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * IniFileLoader loads translations from an ini file. + * + * @author stealth35 + */ +class IniFileLoader extends ArrayLoader +{ + /** + * {@inheritdoc} + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + $messages = parse_ini_file($resource, true); + + $catalogue = parent::load($messages, $locale, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } +} diff --git a/vendor/symfony/translation/Loader/JsonFileLoader.php b/vendor/symfony/translation/Loader/JsonFileLoader.php new file mode 100755 index 0000000..0913883 --- /dev/null +++ b/vendor/symfony/translation/Loader/JsonFileLoader.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * JsonFileLoader loads translations from an json file. + * + * @author singles + */ +class JsonFileLoader extends ArrayLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + $messages = array(); + if ($data = file_get_contents($resource)) { + $messages = json_decode($data, true); + + if (0 < $errorCode = json_last_error()) { + throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode))); + } + } + + if (null === $messages) { + $messages = array(); + } + + $catalogue = parent::load($messages, $locale, $domain); + $catalogue->addResource(new FileResource($resource)); + + return $catalogue; + } + + /** + * Translates JSON_ERROR_* constant into meaningful message. + * + * @param int $errorCode Error code returned by json_last_error() call + * + * @return string Message string + */ + private function getJSONErrorMessage($errorCode) + { + switch ($errorCode) { + case JSON_ERROR_DEPTH: + return 'Maximum stack depth exceeded'; + case JSON_ERROR_STATE_MISMATCH: + return 'Underflow or the modes mismatch'; + case JSON_ERROR_CTRL_CHAR: + return 'Unexpected control character found'; + case JSON_ERROR_SYNTAX: + return 'Syntax error, malformed JSON'; + case JSON_ERROR_UTF8: + return 'Malformed UTF-8 characters, possibly incorrectly encoded'; + default: + return 'Unknown error'; + } + } +} diff --git a/vendor/symfony/translation/Loader/LoaderInterface.php b/vendor/symfony/translation/Loader/LoaderInterface.php new file mode 100755 index 0000000..0b28e14 --- /dev/null +++ b/vendor/symfony/translation/Loader/LoaderInterface.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; + +/** + * LoaderInterface is the interface implemented by all translation loaders. + * + * @author Fabien Potencier + * + * @api + */ +interface LoaderInterface +{ + /** + * Loads a locale. + * + * @param mixed $resource A resource + * @param string $locale A locale + * @param string $domain The domain + * + * @return MessageCatalogue A MessageCatalogue instance + * + * @api + * + * @throws NotFoundResourceException when the resource cannot be found + * @throws InvalidResourceException when the resource cannot be loaded + */ + public function load($resource, $locale, $domain = 'messages'); +} diff --git a/vendor/symfony/translation/Loader/MoFileLoader.php b/vendor/symfony/translation/Loader/MoFileLoader.php new file mode 100755 index 0000000..746fd52 --- /dev/null +++ b/vendor/symfony/translation/Loader/MoFileLoader.php @@ -0,0 +1,191 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * @copyright Copyright (c) 2010, Union of RAD http://union-of-rad.org (http://lithify.me/) + */ +class MoFileLoader extends ArrayLoader +{ + /** + * Magic used for validating the format of a MO file as well as + * detecting if the machine used to create that file was little endian. + * + * @var float + */ + const MO_LITTLE_ENDIAN_MAGIC = 0x950412de; + + /** + * Magic used for validating the format of a MO file as well as + * detecting if the machine used to create that file was big endian. + * + * @var float + */ + const MO_BIG_ENDIAN_MAGIC = 0xde120495; + + /** + * The size of the header of a MO file in bytes. + * + * @var int Number of bytes. + */ + const MO_HEADER_SIZE = 28; + + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + $messages = $this->parse($resource); + + // empty file + if (null === $messages) { + $messages = array(); + } + + // not an array + if (!is_array($messages)) { + throw new InvalidResourceException(sprintf('The file "%s" must contain a valid mo file.', $resource)); + } + + $catalogue = parent::load($messages, $locale, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } + + /** + * Parses machine object (MO) format, independent of the machine's endian it + * was created on. Both 32bit and 64bit systems are supported. + * + * @param resource $resource + * + * @return array + * + * @throws InvalidResourceException If stream content has an invalid format. + */ + private function parse($resource) + { + $stream = fopen($resource, 'r'); + + $stat = fstat($stream); + + if ($stat['size'] < self::MO_HEADER_SIZE) { + throw new InvalidResourceException('MO stream content has an invalid format.'); + } + $magic = unpack('V1', fread($stream, 4)); + $magic = hexdec(substr(dechex(current($magic)), -8)); + + if ($magic == self::MO_LITTLE_ENDIAN_MAGIC) { + $isBigEndian = false; + } elseif ($magic == self::MO_BIG_ENDIAN_MAGIC) { + $isBigEndian = true; + } else { + throw new InvalidResourceException('MO stream content has an invalid format.'); + } + + // formatRevision + $this->readLong($stream, $isBigEndian); + $count = $this->readLong($stream, $isBigEndian); + $offsetId = $this->readLong($stream, $isBigEndian); + $offsetTranslated = $this->readLong($stream, $isBigEndian); + // sizeHashes + $this->readLong($stream, $isBigEndian); + // offsetHashes + $this->readLong($stream, $isBigEndian); + + $messages = array(); + + for ($i = 0; $i < $count; ++$i) { + $singularId = $pluralId = null; + $translated = null; + + fseek($stream, $offsetId + $i * 8); + + $length = $this->readLong($stream, $isBigEndian); + $offset = $this->readLong($stream, $isBigEndian); + + if ($length < 1) { + continue; + } + + fseek($stream, $offset); + $singularId = fread($stream, $length); + + if (strpos($singularId, "\000") !== false) { + list($singularId, $pluralId) = explode("\000", $singularId); + } + + fseek($stream, $offsetTranslated + $i * 8); + $length = $this->readLong($stream, $isBigEndian); + $offset = $this->readLong($stream, $isBigEndian); + + if ($length < 1) { + continue; + } + + fseek($stream, $offset); + $translated = fread($stream, $length); + + if (strpos($translated, "\000") !== false) { + $translated = explode("\000", $translated); + } + + $ids = array('singular' => $singularId, 'plural' => $pluralId); + $item = compact('ids', 'translated'); + + if (is_array($item['translated'])) { + $messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]); + if (isset($item['ids']['plural'])) { + $plurals = array(); + foreach ($item['translated'] as $plural => $translated) { + $plurals[] = sprintf('{%d} %s', $plural, $translated); + } + $messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals)); + } + } elseif (!empty($item['ids']['singular'])) { + $messages[$item['ids']['singular']] = stripcslashes($item['translated']); + } + } + + fclose($stream); + + return array_filter($messages); + } + + /** + * Reads an unsigned long from stream respecting endianess. + * + * @param resource $stream + * @param bool $isBigEndian + * + * @return int + */ + private function readLong($stream, $isBigEndian) + { + $result = unpack($isBigEndian ? 'N1' : 'V1', fread($stream, 4)); + $result = current($result); + + return (int) substr($result, -8); + } +} diff --git a/vendor/symfony/translation/Loader/PhpFileLoader.php b/vendor/symfony/translation/Loader/PhpFileLoader.php new file mode 100755 index 0000000..9ce2e7d --- /dev/null +++ b/vendor/symfony/translation/Loader/PhpFileLoader.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * PhpFileLoader loads translations from PHP files returning an array of translations. + * + * @author Fabien Potencier + * + * @api + */ +class PhpFileLoader extends ArrayLoader +{ + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + $messages = require $resource; + + $catalogue = parent::load($messages, $locale, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } +} diff --git a/vendor/symfony/translation/Loader/PoFileLoader.php b/vendor/symfony/translation/Loader/PoFileLoader.php new file mode 100755 index 0000000..b5d12e9 --- /dev/null +++ b/vendor/symfony/translation/Loader/PoFileLoader.php @@ -0,0 +1,180 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * @copyright Copyright (c) 2010, Union of RAD http://union-of-rad.org (http://lithify.me/) + * @copyright Copyright (c) 2012, Clemens Tolboom + */ +class PoFileLoader extends ArrayLoader +{ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + $messages = $this->parse($resource); + + // empty file + if (null === $messages) { + $messages = array(); + } + + // not an array + if (!is_array($messages)) { + throw new InvalidResourceException(sprintf('The file "%s" must contain a valid po file.', $resource)); + } + + $catalogue = parent::load($messages, $locale, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } + + /** + * Parses portable object (PO) format. + * + * From http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files + * we should be able to parse files having: + * + * white-space + * # translator-comments + * #. extracted-comments + * #: reference... + * #, flag... + * #| msgid previous-untranslated-string + * msgid untranslated-string + * msgstr translated-string + * + * extra or different lines are: + * + * #| msgctxt previous-context + * #| msgid previous-untranslated-string + * msgctxt context + * + * #| msgid previous-untranslated-string-singular + * #| msgid_plural previous-untranslated-string-plural + * msgid untranslated-string-singular + * msgid_plural untranslated-string-plural + * msgstr[0] translated-string-case-0 + * ... + * msgstr[N] translated-string-case-n + * + * The definition states: + * - white-space and comments are optional. + * - msgid "" that an empty singleline defines a header. + * + * This parser sacrifices some features of the reference implementation the + * differences to that implementation are as follows. + * - No support for comments spanning multiple lines. + * - Translator and extracted comments are treated as being the same type. + * - Message IDs are allowed to have other encodings as just US-ASCII. + * + * Items with an empty id are ignored. + * + * @param resource $resource + * + * @return array + */ + private function parse($resource) + { + $stream = fopen($resource, 'r'); + + $defaults = array( + 'ids' => array(), + 'translated' => null, + ); + + $messages = array(); + $item = $defaults; + + while ($line = fgets($stream)) { + $line = trim($line); + + if ($line === '') { + // Whitespace indicated current item is done + $this->addMessage($messages, $item); + $item = $defaults; + } elseif (substr($line, 0, 7) === 'msgid "') { + // We start a new msg so save previous + // TODO: this fails when comments or contexts are added + $this->addMessage($messages, $item); + $item = $defaults; + $item['ids']['singular'] = substr($line, 7, -1); + } elseif (substr($line, 0, 8) === 'msgstr "') { + $item['translated'] = substr($line, 8, -1); + } elseif ($line[0] === '"') { + $continues = isset($item['translated']) ? 'translated' : 'ids'; + + if (is_array($item[$continues])) { + end($item[$continues]); + $item[$continues][key($item[$continues])] .= substr($line, 1, -1); + } else { + $item[$continues] .= substr($line, 1, -1); + } + } elseif (substr($line, 0, 14) === 'msgid_plural "') { + $item['ids']['plural'] = substr($line, 14, -1); + } elseif (substr($line, 0, 7) === 'msgstr[') { + $size = strpos($line, ']'); + $item['translated'][(int) substr($line, 7, 1)] = substr($line, $size + 3, -1); + } + } + // save last item + $this->addMessage($messages, $item); + fclose($stream); + + return $messages; + } + + /** + * Save a translation item to the messages. + * + * A .po file could contain by error missing plural indexes. We need to + * fix these before saving them. + * + * @param array $messages + * @param array $item + */ + private function addMessage(array &$messages, array $item) + { + if (is_array($item['translated'])) { + $messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated'][0]); + if (isset($item['ids']['plural'])) { + $plurals = $item['translated']; + // PO are by definition indexed so sort by index. + ksort($plurals); + // Make sure every index is filled. + end($plurals); + $count = key($plurals); + // Fill missing spots with '-'. + $empties = array_fill(0, $count + 1, '-'); + $plurals += $empties; + ksort($plurals); + $messages[stripcslashes($item['ids']['plural'])] = stripcslashes(implode('|', $plurals)); + } + } elseif (!empty($item['ids']['singular'])) { + $messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated']); + } + } +} diff --git a/vendor/symfony/translation/Loader/QtFileLoader.php b/vendor/symfony/translation/Loader/QtFileLoader.php new file mode 100755 index 0000000..6dd0696 --- /dev/null +++ b/vendor/symfony/translation/Loader/QtFileLoader.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Config\Util\XmlUtils; +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * QtFileLoader loads translations from QT Translations XML files. + * + * @author Benjamin Eberlei + * + * @api + */ +class QtFileLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + try { + $dom = XmlUtils::loadFile($resource); + } catch (\InvalidArgumentException $e) { + throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource), $e->getCode(), $e); + } + + $internalErrors = libxml_use_internal_errors(true); + libxml_clear_errors(); + + $xpath = new \DOMXPath($dom); + $nodes = $xpath->evaluate('//TS/context/name[text()="'.$domain.'"]'); + + $catalogue = new MessageCatalogue($locale); + if ($nodes->length == 1) { + $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message'); + foreach ($translations as $translation) { + $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue; + + if (!empty($translationValue)) { + $catalogue->set( + (string) $translation->getElementsByTagName('source')->item(0)->nodeValue, + $translationValue, + $domain + ); + } + $translation = $translation->nextSibling; + } + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + } + + libxml_use_internal_errors($internalErrors); + + return $catalogue; + } +} diff --git a/vendor/symfony/translation/Loader/XliffFileLoader.php b/vendor/symfony/translation/Loader/XliffFileLoader.php new file mode 100755 index 0000000..d2b5407 --- /dev/null +++ b/vendor/symfony/translation/Loader/XliffFileLoader.php @@ -0,0 +1,188 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Config\Util\XmlUtils; +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; + +/** + * XliffFileLoader loads translations from XLIFF files. + * + * @author Fabien Potencier + * + * @api + */ +class XliffFileLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + list($xml, $encoding) = $this->parseFile($resource); + $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2'); + + $catalogue = new MessageCatalogue($locale); + foreach ($xml->xpath('//xliff:trans-unit') as $translation) { + $attributes = $translation->attributes(); + + if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) { + continue; + } + + $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source; + // If the xlf file has another encoding specified, try to convert it because + // simple_xml will always return utf-8 encoded values + $target = $this->utf8ToCharset((string) $translation->target, $encoding); + + $catalogue->set((string) $source, $target, $domain); + + if (isset($translation->note)) { + $notes = array(); + foreach ($translation->note as $xmlNote) { + $noteAttributes = $xmlNote->attributes(); + $note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding)); + if (isset($noteAttributes['priority'])) { + $note['priority'] = (int) $noteAttributes['priority']; + } + + if (isset($noteAttributes['from'])) { + $note['from'] = (string) $noteAttributes['from']; + } + + $notes[] = $note; + } + + $catalogue->setMetadata((string) $source, array('notes' => $notes), $domain); + } + } + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } + + /** + * Convert a UTF8 string to the specified encoding. + * + * @param string $content String to decode + * @param string $encoding Target encoding + * + * @return string + */ + private function utf8ToCharset($content, $encoding = null) + { + if ('UTF-8' !== $encoding && !empty($encoding)) { + if (function_exists('mb_convert_encoding')) { + return mb_convert_encoding($content, $encoding, 'UTF-8'); + } + + if (function_exists('iconv')) { + return iconv('UTF-8', $encoding, $content); + } + + throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + } + + return $content; + } + + /** + * Validates and parses the given file into a SimpleXMLElement. + * + * @param string $file + * + * @throws \RuntimeException + * + * @return \SimpleXMLElement + * + * @throws InvalidResourceException + */ + private function parseFile($file) + { + try { + $dom = XmlUtils::loadFile($file); + } catch (\InvalidArgumentException $e) { + throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $file, $e->getMessage()), $e->getCode(), $e); + } + + $internalErrors = libxml_use_internal_errors(true); + + $location = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd'; + $parts = explode('/', $location); + if (0 === stripos($location, 'phar://')) { + $tmpfile = tempnam(sys_get_temp_dir(), 'sf2'); + if ($tmpfile) { + copy($location, $tmpfile); + $parts = explode('/', str_replace('\\', '/', $tmpfile)); + } + } + $drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : ''; + $location = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts)); + + $source = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd'); + $source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source); + + if (!@$dom->schemaValidateSource($source)) { + throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors)))); + } + + $dom->normalizeDocument(); + + libxml_clear_errors(); + libxml_use_internal_errors($internalErrors); + + return array(simplexml_import_dom($dom), strtoupper($dom->encoding)); + } + + /** + * Returns the XML errors of the internal XML parser. + * + * @param bool $internalErrors + * + * @return array An array of errors + */ + private function getXmlErrors($internalErrors) + { + $errors = array(); + foreach (libxml_get_errors() as $error) { + $errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)', + LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR', + $error->code, + trim($error->message), + $error->file ?: 'n/a', + $error->line, + $error->column + ); + } + + libxml_clear_errors(); + libxml_use_internal_errors($internalErrors); + + return $errors; + } +} diff --git a/vendor/symfony/translation/Loader/YamlFileLoader.php b/vendor/symfony/translation/Loader/YamlFileLoader.php new file mode 100755 index 0000000..fb0946c --- /dev/null +++ b/vendor/symfony/translation/Loader/YamlFileLoader.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Loader; + +use Symfony\Component\Translation\Exception\InvalidResourceException; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Yaml\Parser as YamlParser; +use Symfony\Component\Yaml\Exception\ParseException; + +/** + * YamlFileLoader loads translations from Yaml files. + * + * @author Fabien Potencier + * + * @api + */ +class YamlFileLoader extends ArrayLoader +{ + private $yamlParser; + + /** + * {@inheritdoc} + * + * @api + */ + public function load($resource, $locale, $domain = 'messages') + { + if (!stream_is_local($resource)) { + throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); + } + + if (!file_exists($resource)) { + throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); + } + + if (!class_exists('Symfony\Component\Yaml\Parser')) { + throw new \LogicException('Loading translations from the YAML format requires the Symfony Yaml component.'); + } + + if (null === $this->yamlParser) { + $this->yamlParser = new YamlParser(); + } + + try { + $messages = $this->yamlParser->parse(file_get_contents($resource)); + } catch (ParseException $e) { + throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e); + } + + // empty file + if (null === $messages) { + $messages = array(); + } + + // not an array + if (!is_array($messages)) { + throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource)); + } + + $catalogue = parent::load($messages, $locale, $domain); + + if (class_exists('Symfony\Component\Config\Resource\FileResource')) { + $catalogue->addResource(new FileResource($resource)); + } + + return $catalogue; + } +} diff --git a/vendor/symfony/translation/Loader/schema/dic/xliff-core/xliff-core-1.2-strict.xsd b/vendor/symfony/translation/Loader/schema/dic/xliff-core/xliff-core-1.2-strict.xsd new file mode 100755 index 0000000..3ce2a8e --- /dev/null +++ b/vendor/symfony/translation/Loader/schema/dic/xliff-core/xliff-core-1.2-strict.xsd @@ -0,0 +1,2223 @@ + + + + + + + + + + + + + + + Values for the attribute 'context-type'. + + + + + Indicates a database content. + + + + + Indicates the content of an element within an XML document. + + + + + Indicates the name of an element within an XML document. + + + + + Indicates the line number from the sourcefile (see context-type="sourcefile") where the <source> is found. + + + + + Indicates a the number of parameters contained within the <source>. + + + + + Indicates notes pertaining to the parameters in the <source>. + + + + + Indicates the content of a record within a database. + + + + + Indicates the name of a record within a database. + + + + + Indicates the original source file in the case that multiple files are merged to form the original file from which the XLIFF file is created. This differs from the original <file> attribute in that this sourcefile is one of many that make up that file. + + + + + + + Values for the attribute 'count-type'. + + + + + Indicates the count units are items that are used X times in a certain context; example: this is a reusable text unit which is used 42 times in other texts. + + + + + Indicates the count units are translation units existing already in the same document. + + + + + Indicates a total count. + + + + + + + Values for the attribute 'ctype' when used other elements than <ph> or <x>. + + + + + Indicates a run of bolded text. + + + + + Indicates a run of text in italics. + + + + + Indicates a run of underlined text. + + + + + Indicates a run of hyper-text. + + + + + + + Values for the attribute 'ctype' when used with <ph> or <x>. + + + + + Indicates a inline image. + + + + + Indicates a page break. + + + + + Indicates a line break. + + + + + + + + + + + + Values for the attribute 'datatype'. + + + + + Indicates Active Server Page data. + + + + + Indicates C source file data. + + + + + Indicates Channel Definition Format (CDF) data. + + + + + Indicates ColdFusion data. + + + + + Indicates C++ source file data. + + + + + Indicates C-Sharp data. + + + + + Indicates strings from C, ASM, and driver files data. + + + + + Indicates comma-separated values data. + + + + + Indicates database data. + + + + + Indicates portions of document that follows data and contains metadata. + + + + + Indicates portions of document that precedes data and contains metadata. + + + + + Indicates data from standard UI file operations dialogs (e.g., Open, Save, Save As, Export, Import). + + + + + Indicates standard user input screen data. + + + + + Indicates HyperText Markup Language (HTML) data - document instance. + + + + + Indicates content within an HTML document’s <body> element. + + + + + Indicates Windows INI file data. + + + + + Indicates Interleaf data. + + + + + Indicates Java source file data (extension '.java'). + + + + + Indicates Java property resource bundle data. + + + + + Indicates Java list resource bundle data. + + + + + Indicates JavaScript source file data. + + + + + Indicates JScript source file data. + + + + + Indicates information relating to formatting. + + + + + Indicates LISP source file data. + + + + + Indicates information relating to margin formats. + + + + + Indicates a file containing menu. + + + + + Indicates numerically identified string table. + + + + + Indicates Maker Interchange Format (MIF) data. + + + + + Indicates that the datatype attribute value is a MIME Type value and is defined in the mime-type attribute. + + + + + Indicates GNU Machine Object data. + + + + + Indicates Message Librarian strings created by Novell's Message Librarian Tool. + + + + + Indicates information to be displayed at the bottom of each page of a document. + + + + + Indicates information to be displayed at the top of each page of a document. + + + + + Indicates a list of property values (e.g., settings within INI files or preferences dialog). + + + + + Indicates Pascal source file data. + + + + + Indicates Hypertext Preprocessor data. + + + + + Indicates plain text file (no formatting other than, possibly, wrapping). + + + + + Indicates GNU Portable Object file. + + + + + Indicates dynamically generated user defined document. e.g. Oracle Report, Crystal Report, etc. + + + + + Indicates Windows .NET binary resources. + + + + + Indicates Windows .NET Resources. + + + + + Indicates Rich Text Format (RTF) data. + + + + + Indicates Standard Generalized Markup Language (SGML) data - document instance. + + + + + Indicates Standard Generalized Markup Language (SGML) data - Document Type Definition (DTD). + + + + + Indicates Scalable Vector Graphic (SVG) data. + + + + + Indicates VisualBasic Script source file. + + + + + Indicates warning message. + + + + + Indicates Windows (Win32) resources (i.e. resources extracted from an RC script, a message file, or a compiled file). + + + + + Indicates Extensible HyperText Markup Language (XHTML) data - document instance. + + + + + Indicates Extensible Markup Language (XML) data - document instance. + + + + + Indicates Extensible Markup Language (XML) data - Document Type Definition (DTD). + + + + + Indicates Extensible Stylesheet Language (XSL) data. + + + + + Indicates XUL elements. + + + + + + + Values for the attribute 'mtype'. + + + + + Indicates the marked text is an abbreviation. + + + + + ISO-12620 2.1.8: A term resulting from the omission of any part of the full term while designating the same concept. + + + + + ISO-12620 2.1.8.1: An abbreviated form of a simple term resulting from the omission of some of its letters (e.g. 'adj.' for 'adjective'). + + + + + ISO-12620 2.1.8.4: An abbreviated form of a term made up of letters from the full form of a multiword term strung together into a sequence pronounced only syllabically (e.g. 'radar' for 'radio detecting and ranging'). + + + + + ISO-12620: A proper-name term, such as the name of an agency or other proper entity. + + + + + ISO-12620 2.1.18.1: A recurrent word combination characterized by cohesion in that the components of the collocation must co-occur within an utterance or series of utterances, even though they do not necessarily have to maintain immediate proximity to one another. + + + + + ISO-12620 2.1.5: A synonym for an international scientific term that is used in general discourse in a given language. + + + + + Indicates the marked text is a date and/or time. + + + + + ISO-12620 2.1.15: An expression used to represent a concept based on a statement that two mathematical expressions are, for instance, equal as identified by the equal sign (=), or assigned to one another by a similar sign. + + + + + ISO-12620 2.1.7: The complete representation of a term for which there is an abbreviated form. + + + + + ISO-12620 2.1.14: Figures, symbols or the like used to express a concept briefly, such as a mathematical or chemical formula. + + + + + ISO-12620 2.1.1: The concept designation that has been chosen to head a terminological record. + + + + + ISO-12620 2.1.8.3: An abbreviated form of a term consisting of some of the initial letters of the words making up a multiword term or the term elements making up a compound term when these letters are pronounced individually (e.g. 'BSE' for 'bovine spongiform encephalopathy'). + + + + + ISO-12620 2.1.4: A term that is part of an international scientific nomenclature as adopted by an appropriate scientific body. + + + + + ISO-12620 2.1.6: A term that has the same or nearly identical orthographic or phonemic form in many languages. + + + + + ISO-12620 2.1.16: An expression used to represent a concept based on mathematical or logical relations, such as statements of inequality, set relationships, Boolean operations, and the like. + + + + + ISO-12620 2.1.17: A unit to track object. + + + + + Indicates the marked text is a name. + + + + + ISO-12620 2.1.3: A term that represents the same or a very similar concept as another term in the same language, but for which interchangeability is limited to some contexts and inapplicable in others. + + + + + ISO-12620 2.1.17.2: A unique alphanumeric designation assigned to an object in a manufacturing system. + + + + + Indicates the marked text is a phrase. + + + + + ISO-12620 2.1.18: Any group of two or more words that form a unit, the meaning of which frequently cannot be deduced based on the combined sense of the words making up the phrase. + + + + + Indicates the marked text should not be translated. + + + + + ISO-12620 2.1.12: A form of a term resulting from an operation whereby non-Latin writing systems are converted to the Latin alphabet. + + + + + Indicates that the marked text represents a segment. + + + + + ISO-12620 2.1.18.2: A fixed, lexicalized phrase. + + + + + ISO-12620 2.1.8.2: A variant of a multiword term that includes fewer words than the full form of the term (e.g. 'Group of Twenty-four' for 'Intergovernmental Group of Twenty-four on International Monetary Affairs'). + + + + + ISO-12620 2.1.17.1: Stock keeping unit, an inventory item identified by a unique alphanumeric designation assigned to an object in an inventory control system. + + + + + ISO-12620 2.1.19: A fixed chunk of recurring text. + + + + + ISO-12620 2.1.13: A designation of a concept by letters, numerals, pictograms or any combination thereof. + + + + + ISO-12620 2.1.2: Any term that represents the same or a very similar concept as the main entry term in a term entry. + + + + + ISO-12620 2.1.18.3: Phraseological unit in a language that expresses the same semantic content as another phrase in that same language. + + + + + Indicates the marked text is a term. + + + + + ISO-12620 2.1.11: A form of a term resulting from an operation whereby the characters of one writing system are represented by characters from another writing system, taking into account the pronunciation of the characters converted. + + + + + ISO-12620 2.1.10: A form of a term resulting from an operation whereby the characters of an alphabetic writing system are represented by characters from another alphabetic writing system. + + + + + ISO-12620 2.1.8.5: An abbreviated form of a term resulting from the omission of one or more term elements or syllables (e.g. 'flu' for 'influenza'). + + + + + ISO-12620 2.1.9: One of the alternate forms of a term. + + + + + + + Values for the attribute 'restype'. + + + + + Indicates a Windows RC AUTO3STATE control. + + + + + Indicates a Windows RC AUTOCHECKBOX control. + + + + + Indicates a Windows RC AUTORADIOBUTTON control. + + + + + Indicates a Windows RC BEDIT control. + + + + + Indicates a bitmap, for example a BITMAP resource in Windows. + + + + + Indicates a button object, for example a BUTTON control Windows. + + + + + Indicates a caption, such as the caption of a dialog box. + + + + + Indicates the cell in a table, for example the content of the <td> element in HTML. + + + + + Indicates check box object, for example a CHECKBOX control in Windows. + + + + + Indicates a menu item with an associated checkbox. + + + + + Indicates a list box, but with a check-box for each item. + + + + + Indicates a color selection dialog. + + + + + Indicates a combination of edit box and listbox object, for example a COMBOBOX control in Windows. + + + + + Indicates an initialization entry of an extended combobox DLGINIT resource block. (code 0x1234). + + + + + Indicates an initialization entry of a combobox DLGINIT resource block (code 0x0403). + + + + + Indicates a UI base class element that cannot be represented by any other element. + + + + + Indicates a context menu. + + + + + Indicates a Windows RC CTEXT control. + + + + + Indicates a cursor, for example a CURSOR resource in Windows. + + + + + Indicates a date/time picker. + + + + + Indicates a Windows RC DEFPUSHBUTTON control. + + + + + Indicates a dialog box. + + + + + Indicates a Windows RC DLGINIT resource block. + + + + + Indicates an edit box object, for example an EDIT control in Windows. + + + + + Indicates a filename. + + + + + Indicates a file dialog. + + + + + Indicates a footnote. + + + + + Indicates a font name. + + + + + Indicates a footer. + + + + + Indicates a frame object. + + + + + Indicates a XUL grid element. + + + + + Indicates a groupbox object, for example a GROUPBOX control in Windows. + + + + + Indicates a header item. + + + + + Indicates a heading, such has the content of <h1>, <h2>, etc. in HTML. + + + + + Indicates a Windows RC HEDIT control. + + + + + Indicates a horizontal scrollbar. + + + + + Indicates an icon, for example an ICON resource in Windows. + + + + + Indicates a Windows RC IEDIT control. + + + + + Indicates keyword list, such as the content of the Keywords meta-data in HTML, or a K footnote in WinHelp RTF. + + + + + Indicates a label object. + + + + + Indicates a label that is also a HTML link (not necessarily a URL). + + + + + Indicates a list (a group of list-items, for example an <ol> or <ul> element in HTML). + + + + + Indicates a listbox object, for example an LISTBOX control in Windows. + + + + + Indicates an list item (an entry in a list). + + + + + Indicates a Windows RC LTEXT control. + + + + + Indicates a menu (a group of menu-items). + + + + + Indicates a toolbar containing one or more tope level menus. + + + + + Indicates a menu item (an entry in a menu). + + + + + Indicates a XUL menuseparator element. + + + + + Indicates a message, for example an entry in a MESSAGETABLE resource in Windows. + + + + + Indicates a calendar control. + + + + + Indicates an edit box beside a spin control. + + + + + Indicates a catch all for rectangular areas. + + + + + Indicates a standalone menu not necessarily associated with a menubar. + + + + + Indicates a pushbox object, for example a PUSHBOX control in Windows. + + + + + Indicates a Windows RC PUSHBUTTON control. + + + + + Indicates a radio button object. + + + + + Indicates a menuitem with associated radio button. + + + + + Indicates raw data resources for an application. + + + + + Indicates a row in a table. + + + + + Indicates a Windows RC RTEXT control. + + + + + Indicates a user navigable container used to show a portion of a document. + + + + + Indicates a generic divider object (e.g. menu group separator). + + + + + Windows accelerators, shortcuts in resource or property files. + + + + + Indicates a UI control to indicate process activity but not progress. + + + + + Indicates a splitter bar. + + + + + Indicates a Windows RC STATE3 control. + + + + + Indicates a window for providing feedback to the users, like 'read-only', etc. + + + + + Indicates a string, for example an entry in a STRINGTABLE resource in Windows. + + + + + Indicates a layers of controls with a tab to select layers. + + + + + Indicates a display and edits regular two-dimensional tables of cells. + + + + + Indicates a XUL textbox element. + + + + + Indicates a UI button that can be toggled to on or off state. + + + + + Indicates an array of controls, usually buttons. + + + + + Indicates a pop up tool tip text. + + + + + Indicates a bar with a pointer indicating a position within a certain range. + + + + + Indicates a control that displays a set of hierarchical data. + + + + + Indicates a URI (URN or URL). + + + + + Indicates a Windows RC USERBUTTON control. + + + + + Indicates a user-defined control like CONTROL control in Windows. + + + + + Indicates the text of a variable. + + + + + Indicates version information about a resource like VERSIONINFO in Windows. + + + + + Indicates a vertical scrollbar. + + + + + Indicates a graphical window. + + + + + + + Values for the attribute 'size-unit'. + + + + + Indicates a size in 8-bit bytes. + + + + + Indicates a size in Unicode characters. + + + + + Indicates a size in columns. Used for HTML text area. + + + + + Indicates a size in centimeters. + + + + + Indicates a size in dialog units, as defined in Windows resources. + + + + + Indicates a size in 'font-size' units (as defined in CSS). + + + + + Indicates a size in 'x-height' units (as defined in CSS). + + + + + Indicates a size in glyphs. A glyph is considered to be one or more combined Unicode characters that represent a single displayable text character. Sometimes referred to as a 'grapheme cluster' + + + + + Indicates a size in inches. + + + + + Indicates a size in millimeters. + + + + + Indicates a size in percentage. + + + + + Indicates a size in pixels. + + + + + Indicates a size in point. + + + + + Indicates a size in rows. Used for HTML text area. + + + + + + + Values for the attribute 'state'. + + + + + Indicates the terminating state. + + + + + Indicates only non-textual information needs adaptation. + + + + + Indicates both text and non-textual information needs adaptation. + + + + + Indicates only non-textual information needs review. + + + + + Indicates both text and non-textual information needs review. + + + + + Indicates that only the text of the item needs to be reviewed. + + + + + Indicates that the item needs to be translated. + + + + + Indicates that the item is new. For example, translation units that were not in a previous version of the document. + + + + + Indicates that changes are reviewed and approved. + + + + + Indicates that the item has been translated. + + + + + + + Values for the attribute 'state-qualifier'. + + + + + Indicates an exact match. An exact match occurs when a source text of a segment is exactly the same as the source text of a segment that was translated previously. + + + + + Indicates a fuzzy match. A fuzzy match occurs when a source text of a segment is very similar to the source text of a segment that was translated previously (e.g. when the difference is casing, a few changed words, white-space discripancy, etc.). + + + + + Indicates a match based on matching IDs (in addition to matching text). + + + + + Indicates a translation derived from a glossary. + + + + + Indicates a translation derived from existing translation. + + + + + Indicates a translation derived from machine translation. + + + + + Indicates a translation derived from a translation repository. + + + + + Indicates a translation derived from a translation memory. + + + + + Indicates the translation is suggested by machine translation. + + + + + Indicates that the item has been rejected because of incorrect grammar. + + + + + Indicates that the item has been rejected because it is incorrect. + + + + + Indicates that the item has been rejected because it is too long or too short. + + + + + Indicates that the item has been rejected because of incorrect spelling. + + + + + Indicates the translation is suggested by translation memory. + + + + + + + Values for the attribute 'unit'. + + + + + Refers to words. + + + + + Refers to pages. + + + + + Refers to <trans-unit> elements. + + + + + Refers to <bin-unit> elements. + + + + + Refers to glyphs. + + + + + Refers to <trans-unit> and/or <bin-unit> elements. + + + + + Refers to the occurrences of instances defined by the count-type value. + + + + + Refers to characters. + + + + + Refers to lines. + + + + + Refers to sentences. + + + + + Refers to paragraphs. + + + + + Refers to segments. + + + + + Refers to placeables (inline elements). + + + + + + + Values for the attribute 'priority'. + + + + + Highest priority. + + + + + High priority. + + + + + High priority, but not as important as 2. + + + + + High priority, but not as important as 3. + + + + + Medium priority, but more important than 6. + + + + + Medium priority, but less important than 5. + + + + + Low priority, but more important than 8. + + + + + Low priority, but more important than 9. + + + + + Low priority. + + + + + Lowest priority. + + + + + + + + + This value indicates that all properties can be reformatted. This value must be used alone. + + + + + This value indicates that no properties should be reformatted. This value must be used alone. + + + + + + + + + + + + + This value indicates that all information in the coord attribute can be modified. + + + + + This value indicates that the x information in the coord attribute can be modified. + + + + + This value indicates that the y information in the coord attribute can be modified. + + + + + This value indicates that the cx information in the coord attribute can be modified. + + + + + This value indicates that the cy information in the coord attribute can be modified. + + + + + This value indicates that all the information in the font attribute can be modified. + + + + + This value indicates that the name information in the font attribute can be modified. + + + + + This value indicates that the size information in the font attribute can be modified. + + + + + This value indicates that the weight information in the font attribute can be modified. + + + + + This value indicates that the information in the css-style attribute can be modified. + + + + + This value indicates that the information in the style attribute can be modified. + + + + + This value indicates that the information in the exstyle attribute can be modified. + + + + + + + + + + + + + Indicates that the context is informational in nature, specifying for example, how a term should be translated. Thus, should be displayed to anyone editing the XLIFF document. + + + + + Indicates that the context-group is used to specify where the term was found in the translatable source. Thus, it is not displayed. + + + + + Indicates that the context information should be used during translation memory lookups. Thus, it is not displayed. + + + + + + + + + Represents a translation proposal from a translation memory or other resource. + + + + + Represents a previous version of the target element. + + + + + Represents a rejected version of the target element. + + + + + Represents a translation to be used for reference purposes only, for example from a related product or a different language. + + + + + Represents a proposed translation that was used for the translation of the trans-unit, possibly modified. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Values for the attribute 'coord'. + + + + + + + + Version values: 1.0 and 1.1 are allowed for backward compatibility. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vendor/symfony/translation/Loader/schema/dic/xliff-core/xml.xsd b/vendor/symfony/translation/Loader/schema/dic/xliff-core/xml.xsd new file mode 100755 index 0000000..a46162a --- /dev/null +++ b/vendor/symfony/translation/Loader/schema/dic/xliff-core/xml.xsd @@ -0,0 +1,309 @@ + + + + + + +
+

About the XML namespace

+ +
+

+ + This schema document describes the XML namespace, in a form + suitable for import by other schema documents. +

+

+ See + http://www.w3.org/XML/1998/namespace.html and + + http://www.w3.org/TR/REC-xml for information + about this namespace. +

+ +

+ Note that local names in this namespace are intended to be + defined only by the World Wide Web Consortium or its subgroups. + The names currently defined in this namespace are listed below. + They should not be used with conflicting semantics by any Working + Group, specification, or document instance. +

+

+ See further below in this document for more information about how to refer to this schema document from your own + XSD schema documents and about the + namespace-versioning policy governing this schema document. +

+
+
+ +
+
+ + + + +
+ +

lang (as an attribute name)

+

+ + denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification.

+ +
+
+

Notes

+

+ Attempting to install the relevant ISO 2- and 3-letter + codes as the enumerated possible values is probably never + going to be a realistic possibility. +

+

+ + See BCP 47 at + http://www.rfc-editor.org/rfc/bcp/bcp47.txt + and the IANA language subtag registry at + + http://www.iana.org/assignments/language-subtag-registry + for further information. +

+

+ + The union allows for the 'un-declaration' of xml:lang with + the empty string. +

+
+
+
+ + + + + + + + + + +
+ + + + + +
+ +

space (as an attribute name)

+

+ denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification.

+ +
+
+
+ + + + + + + +
+ + + + +
+ +

base (as an attribute name)

+

+ denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification.

+ +

+ See http://www.w3.org/TR/xmlbase/ + for information about this attribute. +

+ +
+
+
+
+ + + + +
+ +

id (as an attribute name)

+

+ + denotes an attribute whose value + should be interpreted as if declared to be of type ID. + This name is reserved by virtue of its definition in the + xml:id specification.

+ +

+ See http://www.w3.org/TR/xml-id/ + for information about this attribute. +

+
+
+
+ +
+ + + + + + + + + + + +
+ +

Father (in any context at all)

+ +
+

+ denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: +

+
+

+ + In appreciation for his vision, leadership and + dedication the W3C XML Plenary on this 10th day of + February, 2000, reserves for Jon Bosak in perpetuity + the XML name "xml:Father". +

+
+
+
+
+
+ + + + +
+

About this schema document

+ +
+

+ This schema defines attributes and an attribute group suitable + for use by schemas wishing to allow xml:base, + xml:lang, xml:space or + xml:id attributes on elements they define. +

+ +

+ To enable this, such a schema must import this schema for + the XML namespace, e.g. as follows: +

+
+          <schema.. .>
+          .. .
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+     
+

+ or +

+
+
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+     
+

+ Subsequently, qualified reference to any of the attributes or the + group defined below will have the desired effect, e.g. +

+
+          <type.. .>
+          .. .
+           <attributeGroup ref="xml:specialAttrs"/>
+     
+

+ will define a type which will schema-validate an instance element + with any of those attributes. +

+ +
+
+
+
+ + + +
+

Versioning policy for this schema document

+ +
+

+ In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + + http://www.w3.org/2009/01/xml.xsd. +

+

+ At the date of issue it can also be found at + + http://www.w3.org/2001/xml.xsd. +

+ +

+ The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML + Schema itself, or with the XML namespace itself. In other words, + if the XML Schema or XML namespaces change, the version of this + document at + http://www.w3.org/2001/xml.xsd + + will change accordingly; the version at + + http://www.w3.org/2009/01/xml.xsd + + will not change. +

+

+ + Previous dated (and unchanging) versions of this schema + document are at: +

+ +
+
+
+
+ +
diff --git a/vendor/symfony/translation/LoggingTranslator.php b/vendor/symfony/translation/LoggingTranslator.php new file mode 100755 index 0000000..4ff3531 --- /dev/null +++ b/vendor/symfony/translation/LoggingTranslator.php @@ -0,0 +1,128 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +use Psr\Log\LoggerInterface; + +/** + * @author Abdellatif Ait boudad + */ +class LoggingTranslator implements TranslatorInterface, TranslatorBagInterface +{ + /** + * @var TranslatorInterface|TranslatorBagInterface + */ + private $translator; + + /** + * @var LoggerInterface + */ + private $logger; + + /** + * @param TranslatorInterface $translator The translator must implement TranslatorBagInterface + * @param LoggerInterface $logger + */ + public function __construct(TranslatorInterface $translator, LoggerInterface $logger) + { + if (!$translator instanceof TranslatorBagInterface) { + throw new \InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', get_class($translator))); + } + + $this->translator = $translator; + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function trans($id, array $parameters = array(), $domain = null, $locale = null) + { + $trans = $this->translator->trans($id, $parameters, $domain, $locale); + $this->log($id, $domain, $locale); + + return $trans; + } + + /** + * {@inheritdoc} + */ + public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) + { + $trans = $this->translator->transChoice($id, $number, $parameters, $domain, $locale); + $this->log($id, $domain, $locale); + + return $trans; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function setLocale($locale) + { + $this->translator->setLocale($locale); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getLocale() + { + return $this->translator->getLocale(); + } + + /** + * {@inheritdoc} + */ + public function getCatalogue($locale = null) + { + return $this->translator->getCatalogue($locale); + } + + /** + * Passes through all unknown calls onto the translator object. + */ + public function __call($method, $args) + { + return call_user_func_array(array($this->translator, $method), $args); + } + + /** + * Logs for missing translations. + * + * @param string $id + * @param string|null $domain + * @param string|null $locale + */ + private function log($id, $domain, $locale) + { + if (null === $domain) { + $domain = 'messages'; + } + + $id = (string) $id; + $catalogue = $this->translator->getCatalogue($locale); + if ($catalogue->defines($id, $domain)) { + return; + } + + if ($catalogue->has($id, $domain)) { + $this->logger->debug('Translation use fallback catalogue.', array('id' => $id, 'domain' => $domain, 'locale' => $catalogue->getLocale())); + } else { + $this->logger->warning('Translation not found.', array('id' => $id, 'domain' => $domain, 'locale' => $catalogue->getLocale())); + } + } +} diff --git a/vendor/symfony/translation/MessageCatalogue.php b/vendor/symfony/translation/MessageCatalogue.php new file mode 100755 index 0000000..aa92a58 --- /dev/null +++ b/vendor/symfony/translation/MessageCatalogue.php @@ -0,0 +1,293 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +use Symfony\Component\Config\Resource\ResourceInterface; + +/** + * MessageCatalogue. + * + * @author Fabien Potencier + * + * @api + */ +class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterface +{ + private $messages = array(); + private $metadata = array(); + private $resources = array(); + private $locale; + private $fallbackCatalogue; + private $parent; + + /** + * Constructor. + * + * @param string $locale The locale + * @param array $messages An array of messages classified by domain + * + * @api + */ + public function __construct($locale, array $messages = array()) + { + $this->locale = $locale; + $this->messages = $messages; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getLocale() + { + return $this->locale; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getDomains() + { + return array_keys($this->messages); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function all($domain = null) + { + if (null === $domain) { + return $this->messages; + } + + return isset($this->messages[$domain]) ? $this->messages[$domain] : array(); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function set($id, $translation, $domain = 'messages') + { + $this->add(array($id => $translation), $domain); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function has($id, $domain = 'messages') + { + if (isset($this->messages[$domain][$id])) { + return true; + } + + if (null !== $this->fallbackCatalogue) { + return $this->fallbackCatalogue->has($id, $domain); + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function defines($id, $domain = 'messages') + { + return isset($this->messages[$domain][$id]); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function get($id, $domain = 'messages') + { + if (isset($this->messages[$domain][$id])) { + return $this->messages[$domain][$id]; + } + + if (null !== $this->fallbackCatalogue) { + return $this->fallbackCatalogue->get($id, $domain); + } + + return $id; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function replace($messages, $domain = 'messages') + { + $this->messages[$domain] = array(); + + $this->add($messages, $domain); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function add($messages, $domain = 'messages') + { + if (!isset($this->messages[$domain])) { + $this->messages[$domain] = $messages; + } else { + $this->messages[$domain] = array_replace($this->messages[$domain], $messages); + } + } + + /** + * {@inheritdoc} + * + * @api + */ + public function addCatalogue(MessageCatalogueInterface $catalogue) + { + if ($catalogue->getLocale() !== $this->locale) { + throw new \LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale)); + } + + foreach ($catalogue->all() as $domain => $messages) { + $this->add($messages, $domain); + } + + foreach ($catalogue->getResources() as $resource) { + $this->addResource($resource); + } + + if ($catalogue instanceof MetadataAwareInterface) { + $metadata = $catalogue->getMetadata('', ''); + $this->addMetadata($metadata); + } + } + + /** + * {@inheritdoc} + * + * @api + */ + public function addFallbackCatalogue(MessageCatalogueInterface $catalogue) + { + // detect circular references + $c = $this; + do { + if ($c->getLocale() === $catalogue->getLocale()) { + throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale())); + } + } while ($c = $c->parent); + + $catalogue->parent = $this; + $this->fallbackCatalogue = $catalogue; + + foreach ($catalogue->getResources() as $resource) { + $this->addResource($resource); + } + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getFallbackCatalogue() + { + return $this->fallbackCatalogue; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getResources() + { + return array_values($this->resources); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function addResource(ResourceInterface $resource) + { + $this->resources[$resource->__toString()] = $resource; + } + + /** + * {@inheritdoc} + */ + public function getMetadata($key = '', $domain = 'messages') + { + if ('' == $domain) { + return $this->metadata; + } + + if (isset($this->metadata[$domain])) { + if ('' == $key) { + return $this->metadata[$domain]; + } + + if (isset($this->metadata[$domain][$key])) { + return $this->metadata[$domain][$key]; + } + } + } + + /** + * {@inheritdoc} + */ + public function setMetadata($key, $value, $domain = 'messages') + { + $this->metadata[$domain][$key] = $value; + } + + /** + * {@inheritdoc} + */ + public function deleteMetadata($key = '', $domain = 'messages') + { + if ('' == $domain) { + $this->metadata = array(); + } elseif ('' == $key) { + unset($this->metadata[$domain]); + } else { + unset($this->metadata[$domain][$key]); + } + } + + /** + * Adds current values with the new values. + * + * @param array $values Values to add + */ + private function addMetadata(array $values) + { + foreach ($values as $domain => $keys) { + foreach ($keys as $key => $value) { + $this->setMetadata($key, $value, $domain); + } + } + } +} diff --git a/vendor/symfony/translation/MessageCatalogueInterface.php b/vendor/symfony/translation/MessageCatalogueInterface.php new file mode 100755 index 0000000..647e337 --- /dev/null +++ b/vendor/symfony/translation/MessageCatalogueInterface.php @@ -0,0 +1,172 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +use Symfony\Component\Config\Resource\ResourceInterface; + +/** + * MessageCatalogueInterface. + * + * @author Fabien Potencier + * + * @api + */ +interface MessageCatalogueInterface +{ + /** + * Gets the catalogue locale. + * + * @return string The locale + * + * @api + */ + public function getLocale(); + + /** + * Gets the domains. + * + * @return array An array of domains + * + * @api + */ + public function getDomains(); + + /** + * Gets the messages within a given domain. + * + * If $domain is null, it returns all messages. + * + * @param string $domain The domain name + * + * @return array An array of messages + * + * @api + */ + public function all($domain = null); + + /** + * Sets a message translation. + * + * @param string $id The message id + * @param string $translation The messages translation + * @param string $domain The domain name + * + * @api + */ + public function set($id, $translation, $domain = 'messages'); + + /** + * Checks if a message has a translation. + * + * @param string $id The message id + * @param string $domain The domain name + * + * @return bool true if the message has a translation, false otherwise + * + * @api + */ + public function has($id, $domain = 'messages'); + + /** + * Checks if a message has a translation (it does not take into account the fallback mechanism). + * + * @param string $id The message id + * @param string $domain The domain name + * + * @return bool true if the message has a translation, false otherwise + * + * @api + */ + public function defines($id, $domain = 'messages'); + + /** + * Gets a message translation. + * + * @param string $id The message id + * @param string $domain The domain name + * + * @return string The message translation + * + * @api + */ + public function get($id, $domain = 'messages'); + + /** + * Sets translations for a given domain. + * + * @param array $messages An array of translations + * @param string $domain The domain name + * + * @api + */ + public function replace($messages, $domain = 'messages'); + + /** + * Adds translations for a given domain. + * + * @param array $messages An array of translations + * @param string $domain The domain name + * + * @api + */ + public function add($messages, $domain = 'messages'); + + /** + * Merges translations from the given Catalogue into the current one. + * + * The two catalogues must have the same locale. + * + * @param MessageCatalogueInterface $catalogue A MessageCatalogueInterface instance + * + * @api + */ + public function addCatalogue(MessageCatalogueInterface $catalogue); + + /** + * Merges translations from the given Catalogue into the current one + * only when the translation does not exist. + * + * This is used to provide default translations when they do not exist for the current locale. + * + * @param MessageCatalogueInterface $catalogue A MessageCatalogueInterface instance + * + * @api + */ + public function addFallbackCatalogue(MessageCatalogueInterface $catalogue); + + /** + * Gets the fallback catalogue. + * + * @return MessageCatalogueInterface|null A MessageCatalogueInterface instance or null when no fallback has been set + * + * @api + */ + public function getFallbackCatalogue(); + + /** + * Returns an array of resources loaded to build this collection. + * + * @return ResourceInterface[] An array of resources + * + * @api + */ + public function getResources(); + + /** + * Adds a resource for this collection. + * + * @param ResourceInterface $resource A resource instance + * + * @api + */ + public function addResource(ResourceInterface $resource); +} diff --git a/vendor/symfony/translation/MessageSelector.php b/vendor/symfony/translation/MessageSelector.php new file mode 100755 index 0000000..9f5430c --- /dev/null +++ b/vendor/symfony/translation/MessageSelector.php @@ -0,0 +1,90 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * MessageSelector. + * + * @author Fabien Potencier + * @author Bernhard Schussek + * + * @api + */ +class MessageSelector +{ + /** + * Given a message with different plural translations separated by a + * pipe (|), this method returns the correct portion of the message based + * on the given number, locale and the pluralization rules in the message + * itself. + * + * The message supports two different types of pluralization rules: + * + * interval: {0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples + * indexed: There is one apple|There are %count% apples + * + * The indexed solution can also contain labels (e.g. one: There is one apple). + * This is purely for making the translations more clear - it does not + * affect the functionality. + * + * The two methods can also be mixed: + * {0} There are no apples|one: There is one apple|more: There are %count% apples + * + * @param string $message The message being translated + * @param int $number The number of items represented for the message + * @param string $locale The locale to use for choosing + * + * @return string + * + * @throws \InvalidArgumentException + * + * @api + */ + public function choose($message, $number, $locale) + { + $parts = explode('|', $message); + $explicitRules = array(); + $standardRules = array(); + foreach ($parts as $part) { + $part = trim($part); + + if (preg_match('/^(?P'.Interval::getIntervalRegexp().')\s*(?P.*?)$/x', $part, $matches)) { + $explicitRules[$matches['interval']] = $matches['message']; + } elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) { + $standardRules[] = $matches[1]; + } else { + $standardRules[] = $part; + } + } + + // try to match an explicit rule, then fallback to the standard ones + foreach ($explicitRules as $interval => $m) { + if (Interval::test($number, $interval)) { + return $m; + } + } + + $position = PluralizationRules::get($number, $locale); + + if (!isset($standardRules[$position])) { + // when there's exactly one rule given, and that rule is a standard + // rule, use this rule + if (1 === count($parts) && isset($standardRules[0])) { + return $standardRules[0]; + } + + throw new \InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number)); + } + + return $standardRules[$position]; + } +} diff --git a/vendor/symfony/translation/MetadataAwareInterface.php b/vendor/symfony/translation/MetadataAwareInterface.php new file mode 100755 index 0000000..e93c6fb --- /dev/null +++ b/vendor/symfony/translation/MetadataAwareInterface.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * MetadataAwareInterface. + * + * @author Fabien Potencier + */ +interface MetadataAwareInterface +{ + /** + * Gets metadata for the given domain and key. + * + * Passing an empty domain will return an array with all metadata indexed by + * domain and then by key. Passing an empty key will return an array with all + * metadata for the given domain. + * + * @param string $key The key + * @param string $domain The domain name + * + * @return mixed The value that was set or an array with the domains/keys or null + */ + public function getMetadata($key = '', $domain = 'messages'); + + /** + * Adds metadata to a message domain. + * + * @param string $key The key + * @param mixed $value The value + * @param string $domain The domain name + */ + public function setMetadata($key, $value, $domain = 'messages'); + + /** + * Deletes metadata for the given key and domain. + * + * Passing an empty domain will delete all metadata. Passing an empty key will + * delete all metadata for the given domain. + * + * @param string $key The key + * @param string $domain The domain name + */ + public function deleteMetadata($key = '', $domain = 'messages'); +} diff --git a/vendor/symfony/translation/PluralizationRules.php b/vendor/symfony/translation/PluralizationRules.php new file mode 100755 index 0000000..e1eac82 --- /dev/null +++ b/vendor/symfony/translation/PluralizationRules.php @@ -0,0 +1,214 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * Returns the plural rules for a given locale. + * + * @author Fabien Potencier + */ +class PluralizationRules +{ + private static $rules = array(); + + /** + * Returns the plural position to use for the given locale and number. + * + * @param int $number The number + * @param string $locale The locale + * + * @return int The plural position + */ + public static function get($number, $locale) + { + if ('pt_BR' === $locale) { + // temporary set a locale for brazilian + $locale = 'xbr'; + } + + if (strlen($locale) > 3) { + $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); + } + + if (isset(self::$rules[$locale])) { + $return = call_user_func(self::$rules[$locale], $number); + + if (!is_int($return) || $return < 0) { + return 0; + } + + return $return; + } + + /* + * The plural rules are derived from code of the Zend Framework (2010-09-25), + * which is subject to the new BSD license (http://framework.zend.com/license/new-bsd). + * Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + */ + switch ($locale) { + case 'bo': + case 'dz': + case 'id': + case 'ja': + case 'jv': + case 'ka': + case 'km': + case 'kn': + case 'ko': + case 'ms': + case 'th': + case 'tr': + case 'vi': + case 'zh': + return 0; + break; + + case 'af': + case 'az': + case 'bn': + case 'bg': + case 'ca': + case 'da': + case 'de': + case 'el': + case 'en': + case 'eo': + case 'es': + case 'et': + case 'eu': + case 'fa': + case 'fi': + case 'fo': + case 'fur': + case 'fy': + case 'gl': + case 'gu': + case 'ha': + case 'he': + case 'hu': + case 'is': + case 'it': + case 'ku': + case 'lb': + case 'ml': + case 'mn': + case 'mr': + case 'nah': + case 'nb': + case 'ne': + case 'nl': + case 'nn': + case 'no': + case 'om': + case 'or': + case 'pa': + case 'pap': + case 'ps': + case 'pt': + case 'so': + case 'sq': + case 'sv': + case 'sw': + case 'ta': + case 'te': + case 'tk': + case 'ur': + case 'zu': + return ($number == 1) ? 0 : 1; + + case 'am': + case 'bh': + case 'fil': + case 'fr': + case 'gun': + case 'hi': + case 'ln': + case 'mg': + case 'nso': + case 'xbr': + case 'ti': + case 'wa': + return (($number == 0) || ($number == 1)) ? 0 : 1; + + case 'be': + case 'bs': + case 'hr': + case 'ru': + case 'sr': + case 'uk': + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); + + case 'cs': + case 'sk': + return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2); + + case 'ga': + return ($number == 1) ? 0 : (($number == 2) ? 1 : 2); + + case 'lt': + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); + + case 'sl': + return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3)); + + case 'mk': + return ($number % 10 == 1) ? 0 : 1; + + case 'mt': + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)); + + case 'lv': + return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2); + + case 'pl': + return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2); + + case 'cy': + return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3)); + + case 'ro': + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2); + + case 'ar': + return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))); + + default: + return 0; + } + } + + /** + * Overrides the default plural rule for a given locale. + * + * @param string $rule A PHP callable + * @param string $locale The locale + * + * @throws \LogicException + */ + public static function set($rule, $locale) + { + if ('pt_BR' === $locale) { + // temporary set a locale for brazilian + $locale = 'xbr'; + } + + if (strlen($locale) > 3) { + $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); + } + + if (!is_callable($rule)) { + throw new \LogicException('The given rule can not be called'); + } + + self::$rules[$locale] = $rule; + } +} diff --git a/vendor/symfony/translation/README.md b/vendor/symfony/translation/README.md new file mode 100755 index 0000000..2b00862 --- /dev/null +++ b/vendor/symfony/translation/README.md @@ -0,0 +1,37 @@ +Translation Component +===================== + +Translation provides tools for loading translation files and generating +translated strings from these including support for pluralization. + +```php +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\MessageSelector; +use Symfony\Component\Translation\Loader\ArrayLoader; + +$translator = new Translator('fr_FR', new MessageSelector()); +$translator->setFallbackLocales(array('fr')); +$translator->addLoader('array', new ArrayLoader()); +$translator->addResource('array', array( + 'Hello World!' => 'Bonjour', +), 'fr'); + +echo $translator->trans('Hello World!')."\n"; +``` + +Resources +--------- + +Silex integration: + +https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/TranslationServiceProvider.php + +Documentation: + +https://symfony.com/doc/2.7/book/translation.html + +You can run the unit tests with the following command: + + $ cd path/to/Symfony/Component/Translation/ + $ composer install + $ phpunit diff --git a/vendor/symfony/translation/Tests/Catalogue/AbstractOperationTest.php b/vendor/symfony/translation/Tests/Catalogue/AbstractOperationTest.php new file mode 100755 index 0000000..30c21af --- /dev/null +++ b/vendor/symfony/translation/Tests/Catalogue/AbstractOperationTest.php @@ -0,0 +1,73 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Catalogue; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\MessageCatalogueInterface; + +abstract class AbstractOperationTest extends \PHPUnit_Framework_TestCase +{ + public function testGetEmptyDomains() + { + $this->assertEquals( + array(), + $this->createOperation( + new MessageCatalogue('en'), + new MessageCatalogue('en') + )->getDomains() + ); + } + + public function testGetMergedDomains() + { + $this->assertEquals( + array('a', 'b', 'c'), + $this->createOperation( + new MessageCatalogue('en', array('a' => array(), 'b' => array())), + new MessageCatalogue('en', array('b' => array(), 'c' => array())) + )->getDomains() + ); + } + + public function testGetMessagesFromUnknownDomain() + { + $this->setExpectedException('InvalidArgumentException'); + $this->createOperation( + new MessageCatalogue('en'), + new MessageCatalogue('en') + )->getMessages('domain'); + } + + public function testGetEmptyMessages() + { + $this->assertEquals( + array(), + $this->createOperation( + new MessageCatalogue('en', array('a' => array())), + new MessageCatalogue('en') + )->getMessages('a') + ); + } + + public function testGetEmptyResult() + { + $this->assertEquals( + new MessageCatalogue('en'), + $this->createOperation( + new MessageCatalogue('en'), + new MessageCatalogue('en') + )->getResult() + ); + } + + abstract protected function createOperation(MessageCatalogueInterface $source, MessageCatalogueInterface $target); +} diff --git a/vendor/symfony/translation/Tests/Catalogue/DiffOperationTest.php b/vendor/symfony/translation/Tests/Catalogue/DiffOperationTest.php new file mode 100755 index 0000000..26bd582 --- /dev/null +++ b/vendor/symfony/translation/Tests/Catalogue/DiffOperationTest.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Catalogue; + +use Symfony\Component\Translation\Catalogue\DiffOperation; +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\MessageCatalogueInterface; + +class DiffOperationTest extends AbstractOperationTest +{ + public function testGetMessagesFromSingleDomain() + { + $operation = $this->createOperation( + new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))), + new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c'))) + ); + + $this->assertEquals( + array('a' => 'old_a', 'c' => 'new_c'), + $operation->getMessages('messages') + ); + + $this->assertEquals( + array('c' => 'new_c'), + $operation->getNewMessages('messages') + ); + + $this->assertEquals( + array('b' => 'old_b'), + $operation->getObsoleteMessages('messages') + ); + } + + public function testGetResultFromSingleDomain() + { + $this->assertEquals( + new MessageCatalogue('en', array( + 'messages' => array('a' => 'old_a', 'c' => 'new_c'), + )), + $this->createOperation( + new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))), + new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c'))) + )->getResult() + ); + } + + public function testGetResultWithMetadata() + { + $leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))); + $leftCatalogue->setMetadata('a', 'foo', 'messages'); + $leftCatalogue->setMetadata('b', 'bar', 'messages'); + $rightCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'new_b', 'c' => 'new_c'))); + $rightCatalogue->setMetadata('b', 'baz', 'messages'); + $rightCatalogue->setMetadata('c', 'qux', 'messages'); + + $diffCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'old_b', 'c' => 'new_c'))); + $diffCatalogue->setMetadata('b', 'bar', 'messages'); + $diffCatalogue->setMetadata('c', 'qux', 'messages'); + + $this->assertEquals( + $diffCatalogue, + $this->createOperation( + $leftCatalogue, + $rightCatalogue + )->getResult() + ); + } + + protected function createOperation(MessageCatalogueInterface $source, MessageCatalogueInterface $target) + { + return new DiffOperation($source, $target); + } +} diff --git a/vendor/symfony/translation/Tests/Catalogue/MergeOperationTest.php b/vendor/symfony/translation/Tests/Catalogue/MergeOperationTest.php new file mode 100755 index 0000000..8b51c15 --- /dev/null +++ b/vendor/symfony/translation/Tests/Catalogue/MergeOperationTest.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Catalogue; + +use Symfony\Component\Translation\Catalogue\MergeOperation; +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\MessageCatalogueInterface; + +class MergeOperationTest extends AbstractOperationTest +{ + public function testGetMessagesFromSingleDomain() + { + $operation = $this->createOperation( + new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))), + new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c'))) + ); + + $this->assertEquals( + array('a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'), + $operation->getMessages('messages') + ); + + $this->assertEquals( + array('c' => 'new_c'), + $operation->getNewMessages('messages') + ); + + $this->assertEquals( + array(), + $operation->getObsoleteMessages('messages') + ); + } + + public function testGetResultFromSingleDomain() + { + $this->assertEquals( + new MessageCatalogue('en', array( + 'messages' => array('a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'), + )), + $this->createOperation( + new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))), + new MessageCatalogue('en', array('messages' => array('a' => 'new_a', 'c' => 'new_c'))) + )->getResult() + ); + } + + public function testGetResultWithMetadata() + { + $leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b'))); + $leftCatalogue->setMetadata('a', 'foo', 'messages'); + $leftCatalogue->setMetadata('b', 'bar', 'messages'); + $rightCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'new_b', 'c' => 'new_c'))); + $rightCatalogue->setMetadata('b', 'baz', 'messages'); + $rightCatalogue->setMetadata('c', 'qux', 'messages'); + + $mergedCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b', 'c' => 'new_c'))); + $mergedCatalogue->setMetadata('a', 'foo', 'messages'); + $mergedCatalogue->setMetadata('b', 'bar', 'messages'); + $mergedCatalogue->setMetadata('c', 'qux', 'messages'); + + $this->assertEquals( + $mergedCatalogue, + $this->createOperation( + $leftCatalogue, + $rightCatalogue + )->getResult() + ); + } + + protected function createOperation(MessageCatalogueInterface $source, MessageCatalogueInterface $target) + { + return new MergeOperation($source, $target); + } +} diff --git a/vendor/symfony/translation/Tests/DataCollector/TranslationDataCollectorTest.php b/vendor/symfony/translation/Tests/DataCollector/TranslationDataCollectorTest.php new file mode 100755 index 0000000..085d312 --- /dev/null +++ b/vendor/symfony/translation/Tests/DataCollector/TranslationDataCollectorTest.php @@ -0,0 +1,121 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\DataCollector; + +use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\DataCollector\TranslationDataCollector; + +class TranslationDataCollectorTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Symfony\Component\HttpKernel\DataCollector\DataCollector')) { + $this->markTestSkipped('The "DataCollector" is not available'); + } + } + + public function testCollectEmptyMessages() + { + $translator = $this->getTranslator(); + $translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue(array())); + + $dataCollector = new TranslationDataCollector($translator); + $dataCollector->lateCollect(); + + $this->assertEquals(0, $dataCollector->getCountMissings()); + $this->assertEquals(0, $dataCollector->getCountFallbacks()); + $this->assertEquals(0, $dataCollector->getCountDefines()); + $this->assertEquals(array(), $dataCollector->getMessages()); + } + + public function testCollect() + { + $collectedMessages = array( + array( + 'id' => 'foo', + 'translation' => 'foo (en)', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_DEFINED, + ), + array( + 'id' => 'bar', + 'translation' => 'bar (fr)', + 'locale' => 'fr', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, + ), + array( + 'id' => 'choice', + 'translation' => 'choice', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_MISSING, + ), + array( + 'id' => 'choice', + 'translation' => 'choice', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_MISSING, + ), + ); + $expectedMessages = array( + array( + 'id' => 'foo', + 'translation' => 'foo (en)', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_DEFINED, + 'count' => 1, + ), + array( + 'id' => 'bar', + 'translation' => 'bar (fr)', + 'locale' => 'fr', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, + 'count' => 1, + ), + array( + 'id' => 'choice', + 'translation' => 'choice', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_MISSING, + 'count' => 2, + ), + ); + + $translator = $this->getTranslator(); + $translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue($collectedMessages)); + + $dataCollector = new TranslationDataCollector($translator); + $dataCollector->lateCollect(); + + $this->assertEquals(1, $dataCollector->getCountMissings()); + $this->assertEquals(1, $dataCollector->getCountFallbacks()); + $this->assertEquals(1, $dataCollector->getCountDefines()); + $this->assertEquals($expectedMessages, array_values($dataCollector->getMessages())); + } + + private function getTranslator() + { + $translator = $this + ->getMockBuilder('Symfony\Component\Translation\DataCollectorTranslator') + ->disableOriginalConstructor() + ->getMock() + ; + + return $translator; + } +} diff --git a/vendor/symfony/translation/Tests/DataCollectorTranslatorTest.php b/vendor/symfony/translation/Tests/DataCollectorTranslatorTest.php new file mode 100755 index 0000000..8e98ad3 --- /dev/null +++ b/vendor/symfony/translation/Tests/DataCollectorTranslatorTest.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\DataCollectorTranslator; +use Symfony\Component\Translation\Loader\ArrayLoader; + +class DataCollectorTranslatorTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Symfony\Component\HttpKernel\DataCollector\DataCollector')) { + $this->markTestSkipped('The "DataCollector" is not available'); + } + } + public function testCollectMessages() + { + $collector = $this->createCollector(); + $collector->setFallbackLocales(array('fr', 'ru')); + + $collector->trans('foo'); + $collector->trans('bar'); + $collector->transChoice('choice', 0); + $collector->trans('bar_ru'); + + $expectedMessages = array(); + $expectedMessages[] = array( + 'id' => 'foo', + 'translation' => 'foo (en)', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_DEFINED, + ); + $expectedMessages[] = array( + 'id' => 'bar', + 'translation' => 'bar (fr)', + 'locale' => 'fr', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, + ); + $expectedMessages[] = array( + 'id' => 'choice', + 'translation' => 'choice', + 'locale' => 'en', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_MISSING, + ); + $expectedMessages[] = array( + 'id' => 'bar_ru', + 'translation' => 'bar (ru)', + 'locale' => 'ru', + 'domain' => 'messages', + 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, + ); + + $this->assertEquals($expectedMessages, $collector->getCollectedMessages()); + } + + private function createCollector() + { + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (en)'), 'en'); + $translator->addResource('array', array('bar' => 'bar (fr)'), 'fr'); + $translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru'); + + $collector = new DataCollectorTranslator($translator); + + return $collector; + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/CsvFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/CsvFileDumperTest.php new file mode 100755 index 0000000..29177ff --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/CsvFileDumperTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\CsvFileDumper; + +class CsvFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar', 'bar' => 'foo +foo', 'foo;foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new CsvFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/valid.csv'), file_get_contents($tempDir.'/messages.en.csv')); + + unlink($tempDir.'/messages.en.csv'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/FileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/FileDumperTest.php new file mode 100755 index 0000000..9682089 --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/FileDumperTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\FileDumper; + +class FileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDumpBackupsFileIfExisting() + { + $tempDir = sys_get_temp_dir(); + $file = $tempDir.'/messages.en.concrete'; + $backupFile = $file.'~'; + + @touch($file); + + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $dumper = new ConcreteFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertTrue(file_exists($backupFile)); + + @unlink($file); + @unlink($backupFile); + } + + public function testDumpCreatesNestedDirectoriesAndFile() + { + $tempDir = sys_get_temp_dir(); + $translationsDir = $tempDir.'/test/translations'; + $file = $translationsDir.'/messages.en.concrete'; + + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $dumper = new ConcreteFileDumper(); + $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%'); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertTrue(file_exists($file)); + + @unlink($file); + @rmdir($translationsDir); + } +} + +class ConcreteFileDumper extends FileDumper +{ + protected function format(MessageCatalogue $messages, $domain) + { + return ''; + } + + protected function getExtension() + { + return 'concrete'; + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/IcuResFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/IcuResFileDumperTest.php new file mode 100755 index 0000000..7be7dfb --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/IcuResFileDumperTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\IcuResFileDumper; + +class IcuResFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + if (!function_exists('mb_convert_encoding')) { + $this->markTestSkipped('This test requires mbstring to work.'); + } + + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir().'/IcuResFileDumperTest'; + $dumper = new IcuResFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resourcebundle/res/en.res'), file_get_contents($tempDir.'/messages/en.res')); + + @unlink($tempDir.'/messages/en.res'); + @rmdir($tempDir.'/messages'); + @rmdir($tempDir); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/IniFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/IniFileDumperTest.php new file mode 100755 index 0000000..2a2cefd --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/IniFileDumperTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\IniFileDumper; + +class IniFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new IniFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ini'), file_get_contents($tempDir.'/messages.en.ini')); + + unlink($tempDir.'/messages.en.ini'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/JsonFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/JsonFileDumperTest.php new file mode 100755 index 0000000..697cd93 --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/JsonFileDumperTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\JsonFileDumper; + +class JsonFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + if (PHP_VERSION_ID < 50400) { + $this->markTestIncomplete('PHP below 5.4 doesn\'t support JSON pretty printing'); + } + + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new JsonFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($tempDir.'/messages.en.json')); + + unlink($tempDir.'/messages.en.json'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/MoFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/MoFileDumperTest.php new file mode 100755 index 0000000..439a25c --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/MoFileDumperTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\MoFileDumper; + +class MoFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new MoFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.mo'), file_get_contents($tempDir.'/messages.en.mo')); + + unlink($tempDir.'/messages.en.mo'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/PhpFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/PhpFileDumperTest.php new file mode 100755 index 0000000..18be5a0 --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/PhpFileDumperTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\PhpFileDumper; + +class PhpFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new PhpFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.php'), file_get_contents($tempDir.'/messages.en.php')); + + unlink($tempDir.'/messages.en.php'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/PoFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/PoFileDumperTest.php new file mode 100755 index 0000000..0296d6b --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/PoFileDumperTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\PoFileDumper; + +class PoFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new PoFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.po'), file_get_contents($tempDir.'/messages.en.po')); + + unlink($tempDir.'/messages.en.po'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/QtFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/QtFileDumperTest.php new file mode 100755 index 0000000..d7d8fb7 --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/QtFileDumperTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\QtFileDumper; + +class QtFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar'), 'resources'); + + $tempDir = sys_get_temp_dir(); + $dumper = new QtFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ts'), file_get_contents($tempDir.'/resources.en.ts')); + + unlink($tempDir.'/resources.en.ts'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/XliffFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/XliffFileDumperTest.php new file mode 100755 index 0000000..dff2cc4 --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/XliffFileDumperTest.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\XliffFileDumper; + +class XliffFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en_US'); + $catalogue->add(array( + 'foo' => 'bar', + 'key' => '', + 'key.with.cdata' => ' & ', + )); + $catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz')))); + $catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux')))); + + $tempDir = sys_get_temp_dir(); + $dumper = new XliffFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr_FR')); + + $this->assertEquals( + file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), + file_get_contents($tempDir.'/messages.en_US.xlf') + ); + + unlink($tempDir.'/messages.en_US.xlf'); + } +} diff --git a/vendor/symfony/translation/Tests/Dumper/YamlFileDumperTest.php b/vendor/symfony/translation/Tests/Dumper/YamlFileDumperTest.php new file mode 100755 index 0000000..3c68ade --- /dev/null +++ b/vendor/symfony/translation/Tests/Dumper/YamlFileDumperTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\YamlFileDumper; + +class YamlFileDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDump() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->add(array('foo' => 'bar')); + + $tempDir = sys_get_temp_dir(); + $dumper = new YamlFileDumper(); + $dumper->dump($catalogue, array('path' => $tempDir)); + + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.yml'), file_get_contents($tempDir.'/messages.en.yml')); + + unlink($tempDir.'/messages.en.yml'); + } +} diff --git a/vendor/symfony/translation/Tests/IdentityTranslatorTest.php b/vendor/symfony/translation/Tests/IdentityTranslatorTest.php new file mode 100755 index 0000000..352dd31 --- /dev/null +++ b/vendor/symfony/translation/Tests/IdentityTranslatorTest.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Intl\Util\IntlTestHelper; +use Symfony\Component\Translation\IdentityTranslator; + +class IdentityTranslatorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTransTests + */ + public function testTrans($expected, $id, $parameters) + { + $translator = new IdentityTranslator(); + + $this->assertEquals($expected, $translator->trans($id, $parameters)); + } + + /** + * @dataProvider getTransChoiceTests + */ + public function testTransChoiceWithExplicitLocale($expected, $id, $number, $parameters) + { + $translator = new IdentityTranslator(); + $translator->setLocale('en'); + + $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters)); + } + + /** + * @dataProvider getTransChoiceTests + */ + public function testTransChoiceWithDefaultLocale($expected, $id, $number, $parameters) + { + \Locale::setDefault('en'); + + $translator = new IdentityTranslator(); + + $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters)); + } + + public function testGetSetLocale() + { + $translator = new IdentityTranslator(); + $translator->setLocale('en'); + + $this->assertEquals('en', $translator->getLocale()); + } + + public function testGetLocaleReturnsDefaultLocaleIfNotSet() + { + // in order to test with "pt_BR" + IntlTestHelper::requireFullIntl($this); + + $translator = new IdentityTranslator(); + + \Locale::setDefault('en'); + $this->assertEquals('en', $translator->getLocale()); + + \Locale::setDefault('pt_BR'); + $this->assertEquals('pt_BR', $translator->getLocale()); + } + + public function getTransTests() + { + return array( + array('Symfony is great!', 'Symfony is great!', array()), + array('Symfony is awesome!', 'Symfony is %what%!', array('%what%' => 'awesome')), + ); + } + + public function getTransChoiceTests() + { + return array( + array('There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0, array('%count%' => 0)), + array('There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1, array('%count%' => 1)), + array('There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10, array('%count%' => 10)), + array('There are 0 apples', 'There is 1 apple|There are %count% apples', 0, array('%count%' => 0)), + array('There is 1 apple', 'There is 1 apple|There are %count% apples', 1, array('%count%' => 1)), + array('There are 10 apples', 'There is 1 apple|There are %count% apples', 10, array('%count%' => 10)), + // custom validation messages may be coded with a fixed value + array('There are 2 apples', 'There are 2 apples', 2, array('%count%' => 2)), + ); + } +} diff --git a/vendor/symfony/translation/Tests/IntervalTest.php b/vendor/symfony/translation/Tests/IntervalTest.php new file mode 100755 index 0000000..075c98b --- /dev/null +++ b/vendor/symfony/translation/Tests/IntervalTest.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\Interval; + +class IntervalTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getTests + */ + public function testTest($expected, $number, $interval) + { + $this->assertEquals($expected, Interval::test($number, $interval)); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testTestException() + { + Interval::test(1, 'foobar'); + } + + public function getTests() + { + return array( + array(true, 3, '{1,2, 3 ,4}'), + array(false, 10, '{1,2, 3 ,4}'), + array(false, 3, '[1,2]'), + array(true, 1, '[1,2]'), + array(true, 2, '[1,2]'), + array(false, 1, ']1,2['), + array(false, 2, ']1,2['), + array(true, log(0), '[-Inf,2['), + array(true, -log(0), '[-2,+Inf]'), + ); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/CsvFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/CsvFileLoaderTest.php new file mode 100755 index 0000000..463d3b5 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/CsvFileLoaderTest.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\CsvFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class CsvFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new CsvFileLoader(); + $resource = __DIR__.'/../fixtures/resources.csv'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadDoesNothingIfEmpty() + { + $loader = new CsvFileLoader(); + $resource = __DIR__.'/../fixtures/empty.csv'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array(), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new CsvFileLoader(); + $resource = __DIR__.'/../fixtures/not-exists.csv'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadNonLocalResource() + { + $loader = new CsvFileLoader(); + $resource = 'http://example.com/resources.csv'; + $loader->load($resource, 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/IcuDatFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/IcuDatFileLoaderTest.php new file mode 100755 index 0000000..ea9643d --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/IcuDatFileLoaderTest.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\IcuDatFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class IcuDatFileLoaderTest extends LocalizedTestCase +{ + protected function setUp() + { + if (!extension_loaded('intl')) { + $this->markTestSkipped('This test requires intl extension to work.'); + } + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadInvalidResource() + { + $loader = new IcuDatFileLoader(); + $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted/resources', 'es', 'domain2'); + } + + public function testDatEnglishLoad() + { + // bundled resource is build using pkgdata command which at least in ICU 4.2 comes in extremely! buggy form + // you must specify an temporary build directory which is not the same as current directory and + // MUST reside on the same partition. pkgdata -p resources -T /srv -d.packagelist.txt + $loader = new IcuDatFileLoader(); + $resource = __DIR__.'/../fixtures/resourcebundle/dat/resources'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('symfony' => 'Symfony 2 is great'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources()); + } + + public function testDatFrenchLoad() + { + $loader = new IcuDatFileLoader(); + $resource = __DIR__.'/../fixtures/resourcebundle/dat/resources'; + $catalogue = $loader->load($resource, 'fr', 'domain1'); + + $this->assertEquals(array('symfony' => 'Symfony 2 est génial'), $catalogue->all('domain1')); + $this->assertEquals('fr', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new IcuDatFileLoader(); + $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/IcuResFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/IcuResFileLoaderTest.php new file mode 100755 index 0000000..1a935c0 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/IcuResFileLoaderTest.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\IcuResFileLoader; +use Symfony\Component\Config\Resource\DirectoryResource; + +class IcuResFileLoaderTest extends LocalizedTestCase +{ + protected function setUp() + { + if (!extension_loaded('intl')) { + $this->markTestSkipped('This test requires intl extension to work.'); + } + } + + public function testLoad() + { + // resource is build using genrb command + $loader = new IcuResFileLoader(); + $resource = __DIR__.'/../fixtures/resourcebundle/res'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new DirectoryResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new IcuResFileLoader(); + $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadInvalidResource() + { + $loader = new IcuResFileLoader(); + $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted', 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/IniFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/IniFileLoaderTest.php new file mode 100755 index 0000000..1a5de0e --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/IniFileLoaderTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\IniFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class IniFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new IniFileLoader(); + $resource = __DIR__.'/../fixtures/resources.ini'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadDoesNothingIfEmpty() + { + $loader = new IniFileLoader(); + $resource = __DIR__.'/../fixtures/empty.ini'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array(), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new IniFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.ini'; + $loader->load($resource, 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/JsonFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/JsonFileLoaderTest.php new file mode 100755 index 0000000..6d4f353 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/JsonFileLoaderTest.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\JsonFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class JsonFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Symfony\Component\Config\Loader\Loader')) { + $this->markTestSkipped('The "Config" component is not available'); + } + } + + public function testLoad() + { + $loader = new JsonFileLoader(); + $resource = __DIR__.'/../fixtures/resources.json'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadDoesNothingIfEmpty() + { + $loader = new JsonFileLoader(); + $resource = __DIR__.'/../fixtures/empty.json'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array(), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new JsonFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.json'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + * @expectedExceptionMessage Error parsing JSON - Syntax error, malformed JSON + */ + public function testParseException() + { + $loader = new JsonFileLoader(); + $resource = __DIR__.'/../fixtures/malformed.json'; + $loader->load($resource, 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/LocalizedTestCase.php b/vendor/symfony/translation/Tests/Loader/LocalizedTestCase.php new file mode 100755 index 0000000..9d7c5d7 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/LocalizedTestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +abstract class LocalizedTestCase extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!extension_loaded('intl')) { + $this->markTestSkipped('The "intl" extension is not available'); + } + } +} diff --git a/vendor/symfony/translation/Tests/Loader/MoFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/MoFileLoaderTest.php new file mode 100755 index 0000000..34078d0 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/MoFileLoaderTest.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\MoFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class MoFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new MoFileLoader(); + $resource = __DIR__.'/../fixtures/resources.mo'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadPlurals() + { + $loader = new MoFileLoader(); + $resource = __DIR__.'/../fixtures/plurals.mo'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar', 'foos' => '{0} bar|{1} bars'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new MoFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.mo'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadInvalidResource() + { + $loader = new MoFileLoader(); + $resource = __DIR__.'/../fixtures/empty.mo'; + $loader->load($resource, 'en', 'domain1'); + } + + public function testLoadEmptyTranslation() + { + $loader = new MoFileLoader(); + $resource = __DIR__.'/../fixtures/empty-translation.mo'; + $catalogue = $loader->load($resource, 'en', 'message'); + + $this->assertEquals(array(), $catalogue->all('message')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/PhpFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/PhpFileLoaderTest.php new file mode 100755 index 0000000..0816b0f --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/PhpFileLoaderTest.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\PhpFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new PhpFileLoader(); + $resource = __DIR__.'/../fixtures/resources.php'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new PhpFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.php'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadThrowsAnExceptionIfFileNotLocal() + { + $loader = new PhpFileLoader(); + $resource = 'http://example.com/resources.php'; + $loader->load($resource, 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/PoFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/PoFileLoaderTest.php new file mode 100755 index 0000000..87090eb --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/PoFileLoaderTest.php @@ -0,0 +1,96 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\PoFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class PoFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/resources.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadPlurals() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/plurals.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar', 'foos' => 'bar|bars'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadDoesNothingIfEmpty() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/empty.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array(), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.po'; + $loader->load($resource, 'en', 'domain1'); + } + + public function testLoadEmptyTranslation() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/empty-translation.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => ''), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testEscapedId() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/escaped-id.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $messages = $catalogue->all('domain1'); + $this->assertArrayHasKey('escaped "foo"', $messages); + $this->assertEquals('escaped "bar"', $messages['escaped "foo"']); + } + + public function testEscapedIdPlurals() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/escaped-id-plurals.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $messages = $catalogue->all('domain1'); + $this->assertArrayHasKey('escaped "foo"', $messages); + $this->assertArrayHasKey('escaped "foos"', $messages); + $this->assertEquals('escaped "bar"', $messages['escaped "foo"']); + $this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/QtFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/QtFileLoaderTest.php new file mode 100755 index 0000000..3aca86a --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/QtFileLoaderTest.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\QtFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class QtFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new QtFileLoader(); + $resource = __DIR__.'/../fixtures/resources.ts'; + $catalogue = $loader->load($resource, 'en', 'resources'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('resources')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new QtFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.ts'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadNonLocalResource() + { + $loader = new QtFileLoader(); + $resource = 'http://domain1.com/resources.ts'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadInvalidResource() + { + $loader = new QtFileLoader(); + $resource = __DIR__.'/../fixtures/invalid-xml-resources.xlf'; + $loader->load($resource, 'en', 'domain1'); + } + + public function testLoadEmptyResource() + { + $loader = new QtFileLoader(); + $resource = __DIR__.'/../fixtures/empty.xlf'; + $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s".', $resource)); + $loader->load($resource, 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/XliffFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/XliffFileLoaderTest.php new file mode 100755 index 0000000..c3d65b4 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/XliffFileLoaderTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\XliffFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new XliffFileLoader(); + $resource = __DIR__.'/../fixtures/resources.xlf'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + $this->assertSame(array(), libxml_get_errors()); + } + + public function testLoadWithInternalErrorsEnabled() + { + libxml_use_internal_errors(true); + + $this->assertSame(array(), libxml_get_errors()); + + $loader = new XliffFileLoader(); + $resource = __DIR__.'/../fixtures/resources.xlf'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + $this->assertSame(array(), libxml_get_errors()); + } + + public function testLoadWithResname() + { + $loader = new XliffFileLoader(); + $catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'), $catalogue->all('domain1')); + } + + public function testIncompleteResource() + { + $loader = new XliffFileLoader(); + $catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar', 'key' => '', 'test' => 'with'), $catalogue->all('domain1')); + $this->assertFalse($catalogue->has('extra', 'domain1')); + } + + public function testEncoding() + { + if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + $this->markTestSkipped('The iconv and mbstring extensions are not available.'); + } + + $loader = new XliffFileLoader(); + $catalogue = $loader->load(__DIR__.'/../fixtures/encoding.xlf', 'en', 'domain1'); + + $this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1')); + $this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1')); + $this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz')))), $catalogue->getMetadata('foo', 'domain1')); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadInvalidResource() + { + $loader = new XliffFileLoader(); + $loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadResourceDoesNotValidate() + { + $loader = new XliffFileLoader(); + $loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new XliffFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.xlf'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadThrowsAnExceptionIfFileNotLocal() + { + $loader = new XliffFileLoader(); + $resource = 'http://example.com/resources.xlf'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + * @expectedExceptionMessage Document types are not allowed. + */ + public function testDocTypeIsNotAllowed() + { + $loader = new XliffFileLoader(); + $loader->load(__DIR__.'/../fixtures/withdoctype.xlf', 'en', 'domain1'); + } + + public function testParseEmptyFile() + { + $loader = new XliffFileLoader(); + $resource = __DIR__.'/../fixtures/empty.xlf'; + $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s":', $resource)); + $loader->load($resource, 'en', 'domain1'); + } + + public function testLoadNotes() + { + $loader = new XliffFileLoader(); + $catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1'); + + $this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo'))), $catalogue->getMetadata('foo', 'domain1')); + // message without target + $this->assertNull($catalogue->getMetadata('extra', 'domain1')); + $this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1')); + } +} diff --git a/vendor/symfony/translation/Tests/Loader/YamlFileLoaderTest.php b/vendor/symfony/translation/Tests/Loader/YamlFileLoaderTest.php new file mode 100755 index 0000000..00f7163 --- /dev/null +++ b/vendor/symfony/translation/Tests/Loader/YamlFileLoaderTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests\Loader; + +use Symfony\Component\Translation\Loader\YamlFileLoader; +use Symfony\Component\Config\Resource\FileResource; + +class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testLoad() + { + $loader = new YamlFileLoader(); + $resource = __DIR__.'/../fixtures/resources.yml'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + public function testLoadDoesNothingIfEmpty() + { + $loader = new YamlFileLoader(); + $resource = __DIR__.'/../fixtures/empty.yml'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals(array(), $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testLoadNonExistingResource() + { + $loader = new YamlFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.yml'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadThrowsAnExceptionIfFileNotLocal() + { + $loader = new YamlFileLoader(); + $resource = 'http://example.com/resources.yml'; + $loader->load($resource, 'en', 'domain1'); + } + + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException + */ + public function testLoadThrowsAnExceptionIfNotAnArray() + { + $loader = new YamlFileLoader(); + $resource = __DIR__.'/../fixtures/non-valid.yml'; + $loader->load($resource, 'en', 'domain1'); + } +} diff --git a/vendor/symfony/translation/Tests/LoggingTranslatorTest.php b/vendor/symfony/translation/Tests/LoggingTranslatorTest.php new file mode 100755 index 0000000..ab98d72 --- /dev/null +++ b/vendor/symfony/translation/Tests/LoggingTranslatorTest.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\LoggingTranslator; +use Symfony\Component\Translation\Loader\ArrayLoader; + +class LoggingTranslatorTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!interface_exists('Psr\Log\LoggerInterface')) { + $this->markTestSkipped('The "LoggerInterface" is not available'); + } + } + + public function testTransWithNoTranslationIsLogged() + { + $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger->expects($this->exactly(2)) + ->method('warning') + ->with('Translation not found.') + ; + + $translator = new Translator('ar'); + $loggableTranslator = new LoggingTranslator($translator, $logger); + $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10)); + $loggableTranslator->trans('bar'); + } + + public function testTransChoiceFallbackIsLogged() + { + $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger->expects($this->once()) + ->method('debug') + ->with('Translation use fallback catalogue.') + ; + + $translator = new Translator('ar'); + $translator->setFallbackLocales(array('en')); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en'); + $loggableTranslator = new LoggingTranslator($translator, $logger); + $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10)); + } +} diff --git a/vendor/symfony/translation/Tests/MessageCatalogueTest.php b/vendor/symfony/translation/Tests/MessageCatalogueTest.php new file mode 100755 index 0000000..7d95655 --- /dev/null +++ b/vendor/symfony/translation/Tests/MessageCatalogueTest.php @@ -0,0 +1,200 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\MessageCatalogue; + +class MessageCatalogueTest extends \PHPUnit_Framework_TestCase +{ + public function testGetLocale() + { + $catalogue = new MessageCatalogue('en'); + + $this->assertEquals('en', $catalogue->getLocale()); + } + + public function testGetDomains() + { + $catalogue = new MessageCatalogue('en', array('domain1' => array(), 'domain2' => array())); + + $this->assertEquals(array('domain1', 'domain2'), $catalogue->getDomains()); + } + + public function testAll() + { + $catalogue = new MessageCatalogue('en', $messages = array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + + $this->assertEquals(array('foo' => 'foo'), $catalogue->all('domain1')); + $this->assertEquals(array(), $catalogue->all('domain88')); + $this->assertEquals($messages, $catalogue->all()); + } + + public function testHas() + { + $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + + $this->assertTrue($catalogue->has('foo', 'domain1')); + $this->assertFalse($catalogue->has('bar', 'domain1')); + $this->assertFalse($catalogue->has('foo', 'domain88')); + } + + public function testGetSet() + { + $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + $catalogue->set('foo1', 'foo1', 'domain1'); + + $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); + $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); + } + + public function testAdd() + { + $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + $catalogue->add(array('foo1' => 'foo1'), 'domain1'); + + $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); + $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); + + $catalogue->add(array('foo' => 'bar'), 'domain1'); + $this->assertEquals('bar', $catalogue->get('foo', 'domain1')); + $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); + + $catalogue->add(array('foo' => 'bar'), 'domain88'); + $this->assertEquals('bar', $catalogue->get('foo', 'domain88')); + } + + public function testReplace() + { + $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + $catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1'); + + $this->assertEquals($messages, $catalogue->all('domain1')); + } + + public function testAddCatalogue() + { + $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); + + $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); + + $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + $catalogue->addResource($r); + + $catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo1' => 'foo1'))); + $catalogue1->addResource($r1); + + $catalogue->addCatalogue($catalogue1); + + $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); + $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); + + $this->assertEquals(array($r, $r1), $catalogue->getResources()); + } + + public function testAddFallbackCatalogue() + { + $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); + + $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); + + $catalogue = new MessageCatalogue('en_US', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); + $catalogue->addResource($r); + + $catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1'))); + $catalogue1->addResource($r1); + + $catalogue->addFallbackCatalogue($catalogue1); + + $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); + $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); + + $this->assertEquals(array($r, $r1), $catalogue->getResources()); + } + + /** + * @expectedException \LogicException + */ + public function testAddFallbackCatalogueWithCircularReference() + { + $main = new MessageCatalogue('en_US'); + $fallback = new MessageCatalogue('fr_FR'); + + $fallback->addFallbackCatalogue($main); + $main->addFallbackCatalogue($fallback); + } + + /** + * @expectedException \LogicException + */ + public function testAddCatalogueWhenLocaleIsNotTheSameAsTheCurrentOne() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->addCatalogue(new MessageCatalogue('fr', array())); + } + + public function testGetAddResource() + { + $catalogue = new MessageCatalogue('en'); + $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); + $catalogue->addResource($r); + $catalogue->addResource($r); + $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); + $catalogue->addResource($r1); + + $this->assertEquals(array($r, $r1), $catalogue->getResources()); + } + + public function testMetadataDelete() + { + $catalogue = new MessageCatalogue('en'); + $this->assertEquals(array(), $catalogue->getMetadata('', ''), 'Metadata is empty'); + $catalogue->deleteMetadata('key', 'messages'); + $catalogue->deleteMetadata('', 'messages'); + $catalogue->deleteMetadata(); + } + + public function testMetadataSetGetDelete() + { + $catalogue = new MessageCatalogue('en'); + $catalogue->setMetadata('key', 'value'); + $this->assertEquals('value', $catalogue->getMetadata('key', 'messages'), "Metadata 'key' = 'value'"); + + $catalogue->setMetadata('key2', array()); + $this->assertEquals(array(), $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 is array'); + + $catalogue->deleteMetadata('key2', 'messages'); + $this->assertEquals(null, $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 should is deleted.'); + + $catalogue->deleteMetadata('key2', 'domain'); + $this->assertEquals(null, $catalogue->getMetadata('key2', 'domain'), 'Metadata key2 should is deleted.'); + } + + public function testMetadataMerge() + { + $cat1 = new MessageCatalogue('en'); + $cat1->setMetadata('a', 'b'); + $this->assertEquals(array('messages' => array('a' => 'b')), $cat1->getMetadata('', ''), 'Cat1 contains messages metadata.'); + + $cat2 = new MessageCatalogue('en'); + $cat2->setMetadata('b', 'c', 'domain'); + $this->assertEquals(array('domain' => array('b' => 'c')), $cat2->getMetadata('', ''), 'Cat2 contains domain metadata.'); + + $cat1->addCatalogue($cat2); + $this->assertEquals(array('messages' => array('a' => 'b'), 'domain' => array('b' => 'c')), $cat1->getMetadata('', ''), 'Cat1 contains merged metadata.'); + } +} diff --git a/vendor/symfony/translation/Tests/MessageSelectorTest.php b/vendor/symfony/translation/Tests/MessageSelectorTest.php new file mode 100755 index 0000000..d5a4f3e --- /dev/null +++ b/vendor/symfony/translation/Tests/MessageSelectorTest.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\MessageSelector; + +class MessageSelectorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getChooseTests + */ + public function testChoose($expected, $id, $number) + { + $selector = new MessageSelector(); + + $this->assertEquals($expected, $selector->choose($id, $number, 'en')); + } + + public function testReturnMessageIfExactlyOneStandardRuleIsGiven() + { + $selector = new MessageSelector(); + + $this->assertEquals('There are two apples', $selector->choose('There are two apples', 2, 'en')); + } + + /** + * @dataProvider getNonMatchingMessages + * @expectedException \InvalidArgumentException + */ + public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number) + { + $selector = new MessageSelector(); + + $selector->choose($id, $number, 'en'); + } + + public function getNonMatchingMessages() + { + return array( + array('{0} There are no apples|{1} There is one apple', 2), + array('{1} There is one apple|]1,Inf] There are %count% apples', 0), + array('{1} There is one apple|]2,Inf] There are %count% apples', 2), + array('{0} There are no apples|There is one apple', 2), + ); + } + + public function getChooseTests() + { + return array( + array('There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0), + array('There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0), + array('There are no apples', '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0), + + array('There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1), + + array('There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10), + array('There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples', 10), + array('There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10), + + array('There are %count% apples', 'There is one apple|There are %count% apples', 0), + array('There is one apple', 'There is one apple|There are %count% apples', 1), + array('There are %count% apples', 'There is one apple|There are %count% apples', 10), + + array('There are %count% apples', 'one: There is one apple|more: There are %count% apples', 0), + array('There is one apple', 'one: There is one apple|more: There are %count% apples', 1), + array('There are %count% apples', 'one: There is one apple|more: There are %count% apples', 10), + + array('There are no apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 0), + array('There is one apple', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 1), + array('There are %count% apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 10), + + array('', '{0}|{1} There is one apple|]1,Inf] There are %count% apples', 0), + array('', '{0} There are no apples|{1}|]1,Inf] There are %count% apples', 1), + + // Indexed only tests which are Gettext PoFile* compatible strings. + array('There are %count% apples', 'There is one apple|There are %count% apples', 0), + array('There is one apple', 'There is one apple|There are %count% apples', 1), + array('There are %count% apples', 'There is one apple|There are %count% apples', 2), + + // Tests for float numbers + array('There is almost one apple', '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7), + array('There is one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1), + array('There is more than one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7), + array('There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0), + array('There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0), + array('There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0), + ); + } +} diff --git a/vendor/symfony/translation/Tests/PluralizationRulesTest.php b/vendor/symfony/translation/Tests/PluralizationRulesTest.php new file mode 100755 index 0000000..066e07f --- /dev/null +++ b/vendor/symfony/translation/Tests/PluralizationRulesTest.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\PluralizationRules; + +/** + * Test should cover all languages mentioned on http://translate.sourceforge.net/wiki/l10n/pluralforms + * and Plural forms mentioned on http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms. + * + * See also https://developer.mozilla.org/en/Localization_and_Plurals which mentions 15 rules having a maximum of 6 forms. + * The mozilla code is also interesting to check for. + * + * As mentioned by chx http://drupal.org/node/1273968 we can cover all by testing number from 0 to 199 + * + * The goal to cover all languages is to far fetched so this test case is smaller. + * + * @author Clemens Tolboom clemens@build2be.nl + */ +class PluralizationRulesTest extends \PHPUnit_Framework_TestCase +{ + /** + * We test failed langcode here. + * + * TODO: The languages mentioned in the data provide need to get fixed somehow within PluralizationRules. + * + * @dataProvider failingLangcodes + */ + public function testFailedLangcodes($nplural, $langCodes) + { + $matrix = $this->generateTestData($nplural, $langCodes); + $this->validateMatrix($nplural, $matrix, false); + } + + /** + * @dataProvider successLangcodes + */ + public function testLangcodes($nplural, $langCodes) + { + $matrix = $this->generateTestData($nplural, $langCodes); + $this->validateMatrix($nplural, $matrix); + } + + /** + * This array should contain all currently known langcodes. + * + * As it is impossible to have this ever complete we should try as hard as possible to have it almost complete. + * + * @return array + */ + public function successLangcodes() + { + return array( + array('1', array('ay','bo', 'cgg','dz','id', 'ja', 'jbo', 'ka','kk','km','ko','ky')), + array('2', array('nl', 'fr', 'en', 'de', 'de_GE')), + array('3', array('be','bs','cs','hr')), + array('4', array('cy','mt', 'sl')), + array('5', array()), + array('6', array('ar')), + ); + } + + /** + * This array should be at least empty within the near future. + * + * This both depends on a complete list trying to add above as understanding + * the plural rules of the current failing languages. + * + * @return array with nplural together with langcodes + */ + public function failingLangcodes() + { + return array( + array('1', array('fa')), + array('2', array('jbo')), + array('3', array('cbs')), + array('4', array('gd','kw')), + array('5', array('ga')), + array('6', array()), + ); + } + + /** + * We validate only on the plural coverage. Thus the real rules is not tested. + * + * @param string $nplural plural expected + * @param array $matrix containing langcodes and their plural index values. + * @param bool $expectSuccess + */ + protected function validateMatrix($nplural, $matrix, $expectSuccess = true) + { + foreach ($matrix as $langCode => $data) { + $indexes = array_flip($data); + if ($expectSuccess) { + $this->assertEquals($nplural, count($indexes), "Langcode '$langCode' has '$nplural' plural forms."); + } else { + $this->assertNotEquals((int) $nplural, count($indexes), "Langcode '$langCode' has '$nplural' plural forms."); + } + } + } + + protected function generateTestData($plural, $langCodes) + { + $matrix = array(); + foreach ($langCodes as $langCode) { + for ($count = 0; $count < 200; ++$count) { + $plural = PluralizationRules::get($count, $langCode); + $matrix[$langCode][$count] = $plural; + } + } + + return $matrix; + } +} diff --git a/vendor/symfony/translation/Tests/TranslatorCacheTest.php b/vendor/symfony/translation/Tests/TranslatorCacheTest.php new file mode 100755 index 0000000..d5d4639 --- /dev/null +++ b/vendor/symfony/translation/Tests/TranslatorCacheTest.php @@ -0,0 +1,360 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Config\Resource\ResourceInterface; +use Symfony\Component\Translation\Loader\ArrayLoader; +use Symfony\Component\Translation\Loader\LoaderInterface; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\MessageCatalogue; + +class TranslatorCacheTest extends \PHPUnit_Framework_TestCase +{ + protected $tmpDir; + + protected function setUp() + { + $this->tmpDir = sys_get_temp_dir().'/sf2_translation'; + $this->deleteTmpDir(); + } + + protected function tearDown() + { + $this->deleteTmpDir(); + } + + protected function deleteTmpDir() + { + if (!file_exists($dir = $this->tmpDir)) { + return; + } + + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->tmpDir), \RecursiveIteratorIterator::CHILD_FIRST); + foreach ($iterator as $path) { + if (preg_match('#[/\\\\]\.\.?$#', $path->__toString())) { + continue; + } + if ($path->isDir()) { + rmdir($path->__toString()); + } else { + unlink($path->__toString()); + } + } + rmdir($this->tmpDir); + } + + /** + * @dataProvider runForDebugAndProduction + */ + public function testThatACacheIsUsed($debug) + { + $locale = 'any_locale'; + $format = 'some_format'; + $msgid = 'test'; + + // Prime the cache + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, new ArrayLoader()); + $translator->addResource($format, array($msgid => 'OK'), $locale); + $translator->trans($msgid); + + // Try again and see we get a valid result whilst no loader can be used + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, $this->createFailingLoader()); + $translator->addResource($format, array($msgid => 'OK'), $locale); + $this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production')); + } + + public function testRefreshCacheWhenResourcesChange() + { + // prime the cache + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $loader + ->method('load') + ->will($this->returnValue($this->getCatalogue('fr', array( + 'foo' => 'foo A', + )))) + ; + + $translator = new Translator('fr', null, $this->tmpDir, true); + $translator->setLocale('fr'); + $translator->addLoader('loader', $loader); + $translator->addResource('loader', 'foo', 'fr'); + + $this->assertEquals('foo A', $translator->trans('foo')); + + // add a new resource to refresh the cache + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $loader + ->method('load') + ->will($this->returnValue($this->getCatalogue('fr', array( + 'foo' => 'foo B', + )))) + ; + + $translator = new Translator('fr', null, $this->tmpDir, true); + $translator->setLocale('fr'); + $translator->addLoader('loader', $loader); + $translator->addResource('loader', 'bar', 'fr'); + + $this->assertEquals('foo B', $translator->trans('foo')); + } + + public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh() + { + /* + * The testThatACacheIsUsed() test showed that we don't need the loader as long as the cache + * is fresh. + * + * Now we add a Resource that is never fresh and make sure that the + * cache is discarded (the loader is called twice). + * + * We need to run this for debug=true only because in production the cache + * will never be revalidated. + */ + + $locale = 'any_locale'; + $format = 'some_format'; + $msgid = 'test'; + + $catalogue = new MessageCatalogue($locale, array()); + $catalogue->addResource(new StaleResource()); // better use a helper class than a mock, because it gets serialized in the cache and re-loaded + + /** @var LoaderInterface|\PHPUnit_Framework_MockObject_MockObject $loader */ + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $loader + ->expects($this->exactly(2)) + ->method('load') + ->will($this->returnValue($catalogue)) + ; + + // 1st pass + $translator = new Translator($locale, null, $this->tmpDir, true); + $translator->addLoader($format, $loader); + $translator->addResource($format, null, $locale); + $translator->trans($msgid); + + // 2nd pass + $translator = new Translator($locale, null, $this->tmpDir, true); + $translator->addLoader($format, $loader); + $translator->addResource($format, null, $locale); + $translator->trans($msgid); + } + + /** + * @dataProvider runForDebugAndProduction + */ + public function testDifferentTranslatorsForSameLocaleDoNotInterfere($debug) + { + $locale = 'any_locale'; + $format = 'some_format'; + $msgid = 'test'; + + // Create a Translator and prime its cache + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, new ArrayLoader()); + $translator->addResource($format, array($msgid => 'FAIL'), $locale); + $translator->trans($msgid); + + /* + * Create another Translator with the same locale but a different resource. + * It should not use the first translator's cache but return the value from its own resource. + */ + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, new ArrayLoader()); + $translator->addResource($format, array($msgid => 'OK'), $locale); + + $this->assertEquals('OK', $translator->trans($msgid), '-> different translators for the same domain interfere in '.($debug ? 'debug' : 'production')); + } + + /** + * @dataProvider runForDebugAndProduction + */ + public function testDifferentTranslatorsForSameLocaleDoNotOverwriteEachOthersCache($debug) + { + /* + * Similar to the previous test. After we used the second translator, make + * sure there's still a useable cache for the first one. + */ + + $locale = 'any_locale'; + $format = 'some_format'; + $msgid = 'test'; + + // Create a Translator and prime its cache + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, new ArrayLoader()); + $translator->addResource($format, array($msgid => 'OK'), $locale); + $translator->trans($msgid); + + // Create another Translator with a different catalogue for the same locale + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, new ArrayLoader()); + $translator->addResource($format, array($msgid => 'FAIL'), $locale); + $translator->trans($msgid); + + // Now the first translator must still have a useable cache. + $translator = new Translator($locale, null, $this->tmpDir, $debug); + $translator->addLoader($format, $this->createFailingLoader()); + $translator->addResource($format, array($msgid => 'OK'), $locale); + $this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production')); + } + + public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales() + { + /* + * Because the cache file contains a catalogue including all of its fallback + * catalogues, we must take the set of fallback locales into consideration when + * loading a catalogue from the cache. + */ + $translator = new Translator('a', null, $this->tmpDir); + $translator->setFallbackLocales(array('b')); + + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (a)'), 'a'); + $translator->addResource('array', array('bar' => 'bar (b)'), 'b'); + + $this->assertEquals('bar (b)', $translator->trans('bar')); + + // Remove fallback locale + $translator->setFallbackLocales(array()); + $this->assertEquals('bar', $translator->trans('bar')); + + // Use a fresh translator with no fallback locales, result should be the same + $translator = new Translator('a', null, $this->tmpDir); + + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (a)'), 'a'); + $translator->addResource('array', array('bar' => 'bar (b)'), 'b'); + + $this->assertEquals('bar', $translator->trans('bar')); + } + + public function testPrimaryAndFallbackCataloguesContainTheSameMessagesRegardlessOfCaching() + { + /* + * As a safeguard against potential BC breaks, make sure that primary and fallback + * catalogues (reachable via getFallbackCatalogue()) always contain the full set of + * messages provided by the loader. This must also be the case when these catalogues + * are (internally) read from a cache. + * + * Optimizations inside the translator must not change this behaviour. + */ + + /* + * Create a translator that loads two catalogues for two different locales. + * The catalogues contain distinct sets of messages. + */ + $translator = new Translator('a', null, $this->tmpDir); + $translator->setFallbackLocales(array('b')); + + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (a)'), 'a'); + $translator->addResource('array', array('foo' => 'foo (b)'), 'b'); + $translator->addResource('array', array('bar' => 'bar (b)'), 'b'); + + $catalogue = $translator->getCatalogue('a'); + $this->assertFalse($catalogue->defines('bar')); // Sure, the "a" catalogue does not contain that message. + + $fallback = $catalogue->getFallbackCatalogue(); + $this->assertTrue($fallback->defines('foo')); // "foo" is present in "a" and "b" + + /* + * Now, repeat the same test. + * Behind the scenes, the cache is used. But that should not matter, right? + */ + $translator = new Translator('a', null, $this->tmpDir); + $translator->setFallbackLocales(array('b')); + + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (a)'), 'a'); + $translator->addResource('array', array('foo' => 'foo (b)'), 'b'); + $translator->addResource('array', array('bar' => 'bar (b)'), 'b'); + + $catalogue = $translator->getCatalogue('a'); + $this->assertFalse($catalogue->defines('bar')); + + $fallback = $catalogue->getFallbackCatalogue(); + $this->assertTrue($fallback->defines('foo')); + } + + public function testRefreshCacheWhenResourcesAreNoLongerFresh() + { + $resource = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $resource->method('isFresh')->will($this->returnValue(false)); + $loader + ->expects($this->exactly(2)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('fr', array(), array($resource)))); + + // prime the cache + $translator = new Translator('fr', null, $this->tmpDir, true); + $translator->addLoader('loader', $loader); + $translator->addResource('loader', 'foo', 'fr'); + $translator->trans('foo'); + + // prime the cache second time + $translator = new Translator('fr', null, $this->tmpDir, true); + $translator->addLoader('loader', $loader); + $translator->addResource('loader', 'foo', 'fr'); + $translator->trans('foo'); + } + + protected function getCatalogue($locale, $messages, $resources = array()) + { + $catalogue = new MessageCatalogue($locale); + foreach ($messages as $key => $translation) { + $catalogue->set($key, $translation); + } + foreach ($resources as $resource) { + $catalogue->addResource($resource); + } + + return $catalogue; + } + + public function runForDebugAndProduction() + { + return array(array(true), array(false)); + } + + /** + * @return LoaderInterface + */ + private function createFailingLoader() + { + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $loader + ->expects($this->never()) + ->method('load'); + + return $loader; + } +} + +class StaleResource implements ResourceInterface +{ + public function isFresh($timestamp) + { + return false; + } + + public function getResource() + { + } + + public function __toString() + { + return ''; + } +} diff --git a/vendor/symfony/translation/Tests/TranslatorTest.php b/vendor/symfony/translation/Tests/TranslatorTest.php new file mode 100755 index 0000000..3ee9be0 --- /dev/null +++ b/vendor/symfony/translation/Tests/TranslatorTest.php @@ -0,0 +1,627 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\MessageSelector; +use Symfony\Component\Translation\Loader\ArrayLoader; +use Symfony\Component\Translation\MessageCatalogue; + +class TranslatorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getInvalidLocalesTests + * @expectedException \InvalidArgumentException + */ + public function testConstructorInvalidLocale($locale) + { + $translator = new Translator($locale, new MessageSelector()); + } + + /** + * @dataProvider getValidLocalesTests + */ + public function testConstructorValidLocale($locale) + { + $translator = new Translator($locale, new MessageSelector()); + + $this->assertEquals($locale, $translator->getLocale()); + } + + public function testConstructorWithoutLocale() + { + $translator = new Translator(null, new MessageSelector()); + + $this->assertNull($translator->getLocale()); + } + + public function testSetGetLocale() + { + $translator = new Translator('en'); + + $this->assertEquals('en', $translator->getLocale()); + + $translator->setLocale('fr'); + $this->assertEquals('fr', $translator->getLocale()); + } + + /** + * @dataProvider getInvalidLocalesTests + * @expectedException \InvalidArgumentException + */ + public function testSetInvalidLocale($locale) + { + $translator = new Translator('fr', new MessageSelector()); + $translator->setLocale($locale); + } + + /** + * @dataProvider getValidLocalesTests + */ + public function testSetValidLocale($locale) + { + $translator = new Translator($locale, new MessageSelector()); + $translator->setLocale($locale); + + $this->assertEquals($locale, $translator->getLocale()); + } + + public function testGetCatalogue() + { + $translator = new Translator('en'); + + $this->assertEquals(new MessageCatalogue('en'), $translator->getCatalogue()); + + $translator->setLocale('fr'); + $this->assertEquals(new MessageCatalogue('fr'), $translator->getCatalogue('fr')); + } + + public function testGetCatalogueReturnsConsolidatedCatalogue() + { + /* + * This will be useful once we refactor so that different domains will be loaded lazily (on-demand). + * In that case, getCatalogue() will probably have to load all missing domains in order to return + * one complete catalogue. + */ + + $locale = 'whatever'; + $translator = new Translator($locale); + $translator->addLoader('loader-a', new ArrayLoader()); + $translator->addLoader('loader-b', new ArrayLoader()); + $translator->addResource('loader-a', array('foo' => 'foofoo'), $locale, 'domain-a'); + $translator->addResource('loader-b', array('bar' => 'foobar'), $locale, 'domain-b'); + + /* + * Test that we get a single catalogue comprising messages + * from different loaders and different domains + */ + $catalogue = $translator->getCatalogue($locale); + $this->assertTrue($catalogue->defines('foo', 'domain-a')); + $this->assertTrue($catalogue->defines('bar', 'domain-b')); + } + + public function testSetFallbackLocales() + { + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foofoo'), 'en'); + $translator->addResource('array', array('bar' => 'foobar'), 'fr'); + + // force catalogue loading + $translator->trans('bar'); + + $translator->setFallbackLocales(array('fr')); + $this->assertEquals('foobar', $translator->trans('bar')); + } + + public function testSetFallbackLocalesMultiple() + { + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (en)'), 'en'); + $translator->addResource('array', array('bar' => 'bar (fr)'), 'fr'); + + // force catalogue loading + $translator->trans('bar'); + + $translator->setFallbackLocales(array('fr_FR', 'fr')); + $this->assertEquals('bar (fr)', $translator->trans('bar')); + } + + /** + * @dataProvider getInvalidLocalesTests + * @expectedException \InvalidArgumentException + */ + public function testSetFallbackInvalidLocales($locale) + { + $translator = new Translator('fr', new MessageSelector()); + $translator->setFallbackLocales(array('fr', $locale)); + } + + /** + * @dataProvider getValidLocalesTests + */ + public function testSetFallbackValidLocales($locale) + { + $translator = new Translator($locale, new MessageSelector()); + $translator->setFallbackLocales(array('fr', $locale)); + // no assertion. this method just asserts that no exception is thrown + } + + public function testTransWithFallbackLocale() + { + $translator = new Translator('fr_FR'); + $translator->setFallbackLocales(array('en')); + + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('bar' => 'foobar'), 'en'); + + $this->assertEquals('foobar', $translator->trans('bar')); + } + + /** + * @dataProvider getInvalidLocalesTests + * @expectedException \InvalidArgumentException + */ + public function testAddResourceInvalidLocales($locale) + { + $translator = new Translator('fr', new MessageSelector()); + $translator->addResource('array', array('foo' => 'foofoo'), $locale); + } + + /** + * @dataProvider getValidLocalesTests + */ + public function testAddResourceValidLocales($locale) + { + $translator = new Translator('fr', new MessageSelector()); + $translator->addResource('array', array('foo' => 'foofoo'), $locale); + // no assertion. this method just asserts that no exception is thrown + } + + public function testAddResourceAfterTrans() + { + $translator = new Translator('fr'); + $translator->addLoader('array', new ArrayLoader()); + + $translator->setFallbackLocales(array('en')); + + $translator->addResource('array', array('foo' => 'foofoo'), 'en'); + $this->assertEquals('foofoo', $translator->trans('foo')); + + $translator->addResource('array', array('bar' => 'foobar'), 'en'); + $this->assertEquals('foobar', $translator->trans('bar')); + } + + /** + * @dataProvider getTransFileTests + * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException + */ + public function testTransWithoutFallbackLocaleFile($format, $loader) + { + $loaderClass = 'Symfony\\Component\\Translation\\Loader\\'.$loader; + $translator = new Translator('en'); + $translator->addLoader($format, new $loaderClass()); + $translator->addResource($format, __DIR__.'/fixtures/non-existing', 'en'); + $translator->addResource($format, __DIR__.'/fixtures/resources.'.$format, 'en'); + + // force catalogue loading + $translator->trans('foo'); + } + + /** + * @dataProvider getTransFileTests + */ + public function testTransWithFallbackLocaleFile($format, $loader) + { + $loaderClass = 'Symfony\\Component\\Translation\\Loader\\'.$loader; + $translator = new Translator('en_GB'); + $translator->addLoader($format, new $loaderClass()); + $translator->addResource($format, __DIR__.'/fixtures/non-existing', 'en_GB'); + $translator->addResource($format, __DIR__.'/fixtures/resources.'.$format, 'en', 'resources'); + + $this->assertEquals('bar', $translator->trans('foo', array(), 'resources')); + } + + public function testTransWithFallbackLocaleBis() + { + $translator = new Translator('en_US'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foofoo'), 'en_US'); + $translator->addResource('array', array('bar' => 'foobar'), 'en'); + $this->assertEquals('foobar', $translator->trans('bar')); + } + + public function testTransWithFallbackLocaleTer() + { + $translator = new Translator('fr_FR'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foo (en_US)'), 'en_US'); + $translator->addResource('array', array('bar' => 'bar (en)'), 'en'); + + $translator->setFallbackLocales(array('en_US', 'en')); + + $this->assertEquals('foo (en_US)', $translator->trans('foo')); + $this->assertEquals('bar (en)', $translator->trans('bar')); + } + + public function testTransNonExistentWithFallback() + { + $translator = new Translator('fr'); + $translator->setFallbackLocales(array('en')); + $translator->addLoader('array', new ArrayLoader()); + $this->assertEquals('non-existent', $translator->trans('non-existent')); + } + + /** + * @expectedException \RuntimeException + */ + public function testWhenAResourceHasNoRegisteredLoader() + { + $translator = new Translator('en'); + $translator->addResource('array', array('foo' => 'foofoo'), 'en'); + + $translator->trans('foo'); + } + + /** + * @dataProvider getTransTests + */ + public function testTrans($expected, $id, $translation, $parameters, $locale, $domain) + { + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array((string) $id => $translation), $locale, $domain); + + $this->assertEquals($expected, $translator->trans($id, $parameters, $domain, $locale)); + } + + /** + * @dataProvider getInvalidLocalesTests + * @expectedException \InvalidArgumentException + */ + public function testTransInvalidLocale($locale) + { + $translator = new Translator('en', new MessageSelector()); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foofoo'), 'en'); + + $translator->trans('foo', array(), '', $locale); + } + + /** + * @dataProvider getValidLocalesTests + */ + public function testTransValidLocale($locale) + { + $translator = new Translator($locale, new MessageSelector()); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('test' => 'OK'), $locale); + + $this->assertEquals('OK', $translator->trans('test')); + $this->assertEquals('OK', $translator->trans('test', array(), null, $locale)); + } + + /** + * @dataProvider getFlattenedTransTests + */ + public function testFlattenedTrans($expected, $messages, $id) + { + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', $messages, 'fr', ''); + + $this->assertEquals($expected, $translator->trans($id, array(), '', 'fr')); + } + + /** + * @dataProvider getTransChoiceTests + */ + public function testTransChoice($expected, $id, $translation, $number, $parameters, $locale, $domain) + { + $translator = new Translator('en'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array((string) $id => $translation), $locale, $domain); + + $this->assertEquals($expected, $translator->transChoice($id, $number, $parameters, $domain, $locale)); + } + + /** + * @dataProvider getInvalidLocalesTests + * @expectedException \InvalidArgumentException + */ + public function testTransChoiceInvalidLocale($locale) + { + $translator = new Translator('en', new MessageSelector()); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foofoo'), 'en'); + + $translator->transChoice('foo', 1, array(), '', $locale); + } + + /** + * @dataProvider getValidLocalesTests + */ + public function testTransChoiceValidLocale($locale) + { + $translator = new Translator('en', new MessageSelector()); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('foo' => 'foofoo'), 'en'); + + $translator->transChoice('foo', 1, array(), '', $locale); + // no assertion. this method just asserts that no exception is thrown + } + + public function getTransFileTests() + { + return array( + array('csv', 'CsvFileLoader'), + array('ini', 'IniFileLoader'), + array('mo', 'MoFileLoader'), + array('po', 'PoFileLoader'), + array('php', 'PhpFileLoader'), + array('ts', 'QtFileLoader'), + array('xlf', 'XliffFileLoader'), + array('yml', 'YamlFileLoader'), + array('json', 'JsonFileLoader'), + ); + } + + public function getTransTests() + { + return array( + array('Symfony est super !', 'Symfony is great!', 'Symfony est super !', array(), 'fr', ''), + array('Symfony est awesome !', 'Symfony is %what%!', 'Symfony est %what% !', array('%what%' => 'awesome'), 'fr', ''), + array('Symfony est super !', new StringClass('Symfony is great!'), 'Symfony est super !', array(), 'fr', ''), + ); + } + + public function getFlattenedTransTests() + { + $messages = array( + 'symfony' => array( + 'is' => array( + 'great' => 'Symfony est super!', + ), + ), + 'foo' => array( + 'bar' => array( + 'baz' => 'Foo Bar Baz', + ), + 'baz' => 'Foo Baz', + ), + ); + + return array( + array('Symfony est super!', $messages, 'symfony.is.great'), + array('Foo Bar Baz', $messages, 'foo.bar.baz'), + array('Foo Baz', $messages, 'foo.baz'), + ); + } + + public function getTransChoiceTests() + { + return array( + array('Il y a 0 pomme', '{0} There are no appless|{1} There is one apple|]1,Inf] There is %count% apples', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array('%count%' => 0), 'fr', ''), + array('Il y a 1 pomme', '{0} There are no appless|{1} There is one apple|]1,Inf] There is %count% apples', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 1, array('%count%' => 1), 'fr', ''), + array('Il y a 10 pommes', '{0} There are no appless|{1} There is one apple|]1,Inf] There is %count% apples', '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 10, array('%count%' => 10), 'fr', ''), + + array('Il y a 0 pomme', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 0, array('%count%' => 0), 'fr', ''), + array('Il y a 1 pomme', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 1, array('%count%' => 1), 'fr', ''), + array('Il y a 10 pommes', 'There is one apple|There is %count% apples', 'Il y a %count% pomme|Il y a %count% pommes', 10, array('%count%' => 10), 'fr', ''), + + array('Il y a 0 pomme', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array('%count%' => 0), 'fr', ''), + array('Il y a 1 pomme', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array('%count%' => 1), 'fr', ''), + array('Il y a 10 pommes', 'one: There is one apple|more: There is %count% apples', 'one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array('%count%' => 10), 'fr', ''), + + array('Il n\'y a aucune pomme', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 0, array('%count%' => 0), 'fr', ''), + array('Il y a 1 pomme', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 1, array('%count%' => 1), 'fr', ''), + array('Il y a 10 pommes', '{0} There are no apples|one: There is one apple|more: There is %count% apples', '{0} Il n\'y a aucune pomme|one: Il y a %count% pomme|more: Il y a %count% pommes', 10, array('%count%' => 10), 'fr', ''), + + array('Il y a 0 pomme', new StringClass('{0} There are no appless|{1} There is one apple|]1,Inf] There is %count% apples'), '[0,1] Il y a %count% pomme|]1,Inf] Il y a %count% pommes', 0, array('%count%' => 0), 'fr', ''), + ); + } + + public function getInvalidLocalesTests() + { + return array( + array('fr FR'), + array('français'), + array('fr+en'), + array('utf#8'), + array('fr&en'), + array('fr~FR'), + array(' fr'), + array('fr '), + array('fr*'), + array('fr/FR'), + array('fr\\FR'), + ); + } + + public function getValidLocalesTests() + { + return array( + array(''), + array(null), + array('fr'), + array('francais'), + array('FR'), + array('frFR'), + array('fr-FR'), + array('fr_FR'), + array('fr.FR'), + array('fr-FR.UTF8'), + array('sr@latin'), + ); + } + + public function testTransChoiceFallback() + { + $translator = new Translator('ru'); + $translator->setFallbackLocales(array('en')); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en'); + + $this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10))); + } + + public function testTransChoiceFallbackBis() + { + $translator = new Translator('ru'); + $translator->setFallbackLocales(array('en_US', 'en')); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en_US'); + + $this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10))); + } + + public function testTransChoiceFallbackWithNoTranslation() + { + $translator = new Translator('ru'); + $translator->setFallbackLocales(array('en')); + $translator->addLoader('array', new ArrayLoader()); + + // consistent behavior with Translator::trans(), which returns the string + // unchanged if it can't be found + $this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, array('%count%' => 10))); + } + + /** + * @dataProvider dataProviderGetMessages + */ + public function testGetMessages($resources, $locale, $expected) + { + $locales = array_keys($resources); + $_locale = !is_null($locale) ? $locale : reset($locales); + $locales = array_slice($locales, 0, array_search($_locale, $locales)); + + $translator = new Translator($_locale, new MessageSelector()); + $translator->setFallbackLocales(array_reverse($locales)); + $translator->addLoader('array', new ArrayLoader()); + foreach ($resources as $_locale => $domainMessages) { + foreach ($domainMessages as $domain => $messages) { + $translator->addResource('array', $messages, $_locale, $domain); + } + } + $result = $translator->getMessages($locale); + + $this->assertEquals($expected, $result); + } + + public function dataProviderGetMessages() + { + $resources = array( + 'en' => array( + 'jsmessages' => array( + 'foo' => 'foo (EN)', + 'bar' => 'bar (EN)', + ), + 'messages' => array( + 'foo' => 'foo messages (EN)', + ), + 'validators' => array( + 'int' => 'integer (EN)', + ), + ), + 'pt-PT' => array( + 'messages' => array( + 'foo' => 'foo messages (PT)', + ), + 'validators' => array( + 'str' => 'integer (PT)', + ), + ), + 'pt_BR' => array( + 'validators' => array( + 'int' => 'integer (BR)', + ), + ), + ); + + return array( + array($resources, null, + array( + 'jsmessages' => array( + 'foo' => 'foo (EN)', + 'bar' => 'bar (EN)', + ), + 'messages' => array( + 'foo' => 'foo messages (EN)', + ), + 'validators' => array( + 'int' => 'integer (EN)', + ), + ), + ), + array($resources, 'en', + array( + 'jsmessages' => array( + 'foo' => 'foo (EN)', + 'bar' => 'bar (EN)', + ), + 'messages' => array( + 'foo' => 'foo messages (EN)', + ), + 'validators' => array( + 'int' => 'integer (EN)', + ), + ), + ), + array($resources, 'pt-PT', + array( + 'jsmessages' => array( + 'foo' => 'foo (EN)', + 'bar' => 'bar (EN)', + ), + 'messages' => array( + 'foo' => 'foo messages (PT)', + ), + 'validators' => array( + 'int' => 'integer (EN)', + 'str' => 'integer (PT)', + ), + ), + ), + array($resources, 'pt_BR', + array( + 'jsmessages' => array( + 'foo' => 'foo (EN)', + 'bar' => 'bar (EN)', + ), + 'messages' => array( + 'foo' => 'foo messages (PT)', + ), + 'validators' => array( + 'int' => 'integer (BR)', + 'str' => 'integer (PT)', + ), + ), + ), + ); + } +} + +class StringClass +{ + protected $str; + + public function __construct($str) + { + $this->str = $str; + } + + public function __toString() + { + return $this->str; + } +} diff --git a/vendor/symfony/translation/Tests/fixtures/empty-translation.mo b/vendor/symfony/translation/Tests/fixtures/empty-translation.mo new file mode 100755 index 0000000000000000000000000000000000000000..ed01000c9b1b3fdf40fc2369a7799e72e41a1edf GIT binary patch literal 49 ncmca7#4?ou2pEA_28dNa93apEVrC%L1#y7D5JaTq=Q98RUv2}O literal 0 HcmV?d00001 diff --git a/vendor/symfony/translation/Tests/fixtures/empty-translation.po b/vendor/symfony/translation/Tests/fixtures/empty-translation.po new file mode 100755 index 0000000..ff6f22a --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/empty-translation.po @@ -0,0 +1,3 @@ +msgid "foo" +msgstr "" + diff --git a/vendor/symfony/translation/Tests/fixtures/empty.csv b/vendor/symfony/translation/Tests/fixtures/empty.csv new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/empty.ini b/vendor/symfony/translation/Tests/fixtures/empty.ini new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/empty.json b/vendor/symfony/translation/Tests/fixtures/empty.json new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/empty.mo b/vendor/symfony/translation/Tests/fixtures/empty.mo new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/empty.po b/vendor/symfony/translation/Tests/fixtures/empty.po new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/empty.xlf b/vendor/symfony/translation/Tests/fixtures/empty.xlf new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/empty.yml b/vendor/symfony/translation/Tests/fixtures/empty.yml new file mode 100755 index 0000000..e69de29 diff --git a/vendor/symfony/translation/Tests/fixtures/encoding.xlf b/vendor/symfony/translation/Tests/fixtures/encoding.xlf new file mode 100755 index 0000000..0a88f92 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/encoding.xlf @@ -0,0 +1,16 @@ + + + + + + foo + br + bz + + + bar + f + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/escaped-id-plurals.po b/vendor/symfony/translation/Tests/fixtures/escaped-id-plurals.po new file mode 100755 index 0000000..c412aa2 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/escaped-id-plurals.po @@ -0,0 +1,10 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: en\n" + +msgid "escaped \"foo\"" +msgid_plural "escaped \"foos\"" +msgstr[0] "escaped \"bar\"" +msgstr[1] "escaped \"bars\"" diff --git a/vendor/symfony/translation/Tests/fixtures/escaped-id.po b/vendor/symfony/translation/Tests/fixtures/escaped-id.po new file mode 100755 index 0000000..308eadd --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/escaped-id.po @@ -0,0 +1,8 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: en\n" + +msgid "escaped \"foo\"" +msgstr "escaped \"bar\"" diff --git a/vendor/symfony/translation/Tests/fixtures/invalid-xml-resources.xlf b/vendor/symfony/translation/Tests/fixtures/invalid-xml-resources.xlf new file mode 100755 index 0000000..7bf6c98 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/invalid-xml-resources.xlf @@ -0,0 +1,23 @@ + + + + + + foo + bar + + + extra + + + key + + + + test + with + note + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/malformed.json b/vendor/symfony/translation/Tests/fixtures/malformed.json new file mode 100755 index 0000000..4563ec6 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/malformed.json @@ -0,0 +1,3 @@ +{ + "foo" "bar" +} \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/non-valid.xlf b/vendor/symfony/translation/Tests/fixtures/non-valid.xlf new file mode 100755 index 0000000..734fc97 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/non-valid.xlf @@ -0,0 +1,11 @@ + + + + + + foo + bar + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/non-valid.yml b/vendor/symfony/translation/Tests/fixtures/non-valid.yml new file mode 100755 index 0000000..257cc56 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/non-valid.yml @@ -0,0 +1 @@ +foo diff --git a/vendor/symfony/translation/Tests/fixtures/plurals.mo b/vendor/symfony/translation/Tests/fixtures/plurals.mo new file mode 100755 index 0000000000000000000000000000000000000000..6445e77beab595289cd154ea253c4e49dfd6af47 GIT binary patch literal 74 zcmca7#4?ou2pEA_28dOFm>Gz5fS3b_Eugd`kOrxNfwcU51|TkGNJ=aM;bH~=*B}U7 literal 0 HcmV?d00001 diff --git a/vendor/symfony/translation/Tests/fixtures/plurals.po b/vendor/symfony/translation/Tests/fixtures/plurals.po new file mode 100755 index 0000000..439c41a --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/plurals.po @@ -0,0 +1,5 @@ +msgid "foo" +msgid_plural "foos" +msgstr[0] "bar" +msgstr[1] "bars" + diff --git a/vendor/symfony/translation/Tests/fixtures/resname.xlf b/vendor/symfony/translation/Tests/fixtures/resname.xlf new file mode 100755 index 0000000..2df16af --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resname.xlf @@ -0,0 +1,19 @@ + + + + + + + bar + + + bar source + baz + + + baz + foo + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/corrupted/resources.dat b/vendor/symfony/translation/Tests/fixtures/resourcebundle/corrupted/resources.dat new file mode 100755 index 0000000..391250c --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resourcebundle/corrupted/resources.dat @@ -0,0 +1 @@ +XXX \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.res b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.res new file mode 100755 index 0000000000000000000000000000000000000000..1fc1436d6641b7290ad5d9f4d331111e4a0419dd GIT binary patch literal 120 zcmY#jxTP+_00K-5L8-+~j7$s+j4WUQFaeZPU<0x^fmjTR8No6P48@hXY594T3_?JD sFheCnE<+kaK0_XmrNCeW#F-4mKr)@7h#{3Bk)Z^rYSk)61{ttf0N1AuGXMYp literal 0 HcmV?d00001 diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.txt b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.txt new file mode 100755 index 0000000..3d9e9ea --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/en.txt @@ -0,0 +1,3 @@ +en{ + symfony{"Symfony is great"} +} \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.res b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.res new file mode 100755 index 0000000000000000000000000000000000000000..f58416094be89f5fb64f78f6c3b873c6458696d0 GIT binary patch literal 124 zcmY#jxTP+_00K-5L8-+~j7$s+j4WUQFd@popuh%XaRRY86f=Tl7#NBxbJOzkDj7if wgBdCrav9PX@)`1gECmK5AWmf{W+(yD=?pJ{qL~bd3^_oRt5z{G$biiQ03-qri2wiq literal 0 HcmV?d00001 diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.txt b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.txt new file mode 100755 index 0000000..182d0a0 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/fr.txt @@ -0,0 +1,3 @@ +fr{ + symfony{"Symfony est génial"} +} \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/packagelist.txt b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/packagelist.txt new file mode 100755 index 0000000..c5783ed --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/packagelist.txt @@ -0,0 +1,2 @@ +en.res +fr.res diff --git a/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/resources.dat b/vendor/symfony/translation/Tests/fixtures/resourcebundle/dat/resources.dat new file mode 100755 index 0000000000000000000000000000000000000000..563b0eaef2e5a0a6e9623bf7b93b44beb0a7dc27 GIT binary patch literal 352 zcmY#jxTP+_00K-5&bfImj6fDMm=7VCfD}mH0f<$B_y7!;@F0Xawl zX+>axRdAqyWPVU;u@fWEKt>jzAy5D`TY(M8<^*CfC^BI_d>?DRn Nh9V%%$RGn&2LK231)%@{ literal 0 HcmV?d00001 diff --git a/vendor/symfony/translation/Tests/fixtures/resources-clean.xlf b/vendor/symfony/translation/Tests/fixtures/resources-clean.xlf new file mode 100755 index 0000000..4ce15af --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources-clean.xlf @@ -0,0 +1,22 @@ + + + + + + foo + bar + baz + + + key + + baz + qux + + + key.with.cdata + & ]]> + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/resources.csv b/vendor/symfony/translation/Tests/fixtures/resources.csv new file mode 100755 index 0000000..374b9eb --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.csv @@ -0,0 +1,4 @@ +"foo"; "bar" +#"bar"; "foo" +"incorrect"; "number"; "columns"; "will"; "be"; "ignored" +"incorrect" \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/resources.ini b/vendor/symfony/translation/Tests/fixtures/resources.ini new file mode 100755 index 0000000..4953062 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.ini @@ -0,0 +1 @@ +foo="bar" diff --git a/vendor/symfony/translation/Tests/fixtures/resources.json b/vendor/symfony/translation/Tests/fixtures/resources.json new file mode 100755 index 0000000..8a79687 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.json @@ -0,0 +1,3 @@ +{ + "foo": "bar" +} \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/resources.mo b/vendor/symfony/translation/Tests/fixtures/resources.mo new file mode 100755 index 0000000000000000000000000000000000000000..0a9660257c07afef243a011d9806d6217e4f1379 GIT binary patch literal 52 pcmca7#4?ou2pEA_28dNa93apEVrC%Lh0=yVnjtMepCKu+2mox%1k?Zk literal 0 HcmV?d00001 diff --git a/vendor/symfony/translation/Tests/fixtures/resources.php b/vendor/symfony/translation/Tests/fixtures/resources.php new file mode 100755 index 0000000..c291398 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.php @@ -0,0 +1,5 @@ + 'bar', +); diff --git a/vendor/symfony/translation/Tests/fixtures/resources.po b/vendor/symfony/translation/Tests/fixtures/resources.po new file mode 100755 index 0000000..ccfce6b --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.po @@ -0,0 +1,8 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: en\n" + +msgid "foo" +msgstr "bar" \ No newline at end of file diff --git a/vendor/symfony/translation/Tests/fixtures/resources.ts b/vendor/symfony/translation/Tests/fixtures/resources.ts new file mode 100755 index 0000000..40e1852 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.ts @@ -0,0 +1,10 @@ + + + + resources + + foo + bar + + + diff --git a/vendor/symfony/translation/Tests/fixtures/resources.xlf b/vendor/symfony/translation/Tests/fixtures/resources.xlf new file mode 100755 index 0000000..b0e5988 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.xlf @@ -0,0 +1,23 @@ + + + + + + foo + bar + + + extra + + + key + + + + test + with + note + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/resources.yml b/vendor/symfony/translation/Tests/fixtures/resources.yml new file mode 100755 index 0000000..20e9ff3 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/resources.yml @@ -0,0 +1 @@ +foo: bar diff --git a/vendor/symfony/translation/Tests/fixtures/valid.csv b/vendor/symfony/translation/Tests/fixtures/valid.csv new file mode 100755 index 0000000..59882e5 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/valid.csv @@ -0,0 +1,4 @@ +foo;bar +bar;"foo +foo" +"foo;foo";bar diff --git a/vendor/symfony/translation/Tests/fixtures/withdoctype.xlf b/vendor/symfony/translation/Tests/fixtures/withdoctype.xlf new file mode 100755 index 0000000..f83e834 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/withdoctype.xlf @@ -0,0 +1,12 @@ + + + + + + + foo + bar + + + + diff --git a/vendor/symfony/translation/Tests/fixtures/withnote.xlf b/vendor/symfony/translation/Tests/fixtures/withnote.xlf new file mode 100755 index 0000000..b1d3f83 --- /dev/null +++ b/vendor/symfony/translation/Tests/fixtures/withnote.xlf @@ -0,0 +1,22 @@ + + + + + + foo + bar + foo + + + extra + bar + + + key + + baz + qux + + + + diff --git a/vendor/symfony/translation/Translator.php b/vendor/symfony/translation/Translator.php new file mode 100755 index 0000000..ec31506 --- /dev/null +++ b/vendor/symfony/translation/Translator.php @@ -0,0 +1,504 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +use Symfony\Component\Translation\Loader\LoaderInterface; +use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\ConfigCacheInterface; +use Symfony\Component\Config\ConfigCacheFactoryInterface; +use Symfony\Component\Config\ConfigCacheFactory; + +/** + * Translator. + * + * @author Fabien Potencier + * + * @api + */ +class Translator implements TranslatorInterface, TranslatorBagInterface +{ + /** + * @var MessageCatalogueInterface[] + */ + protected $catalogues = array(); + + /** + * @var string + */ + protected $locale; + + /** + * @var array + */ + private $fallbackLocales = array(); + + /** + * @var LoaderInterface[] + */ + private $loaders = array(); + + /** + * @var array + */ + private $resources = array(); + + /** + * @var MessageSelector + */ + private $selector; + + /** + * @var string + */ + private $cacheDir; + + /** + * @var bool + */ + private $debug; + + /** + * @var ConfigCacheFactoryInterface|null + */ + private $configCacheFactory; + + /** + * Constructor. + * + * @param string $locale The locale + * @param MessageSelector|null $selector The message selector for pluralization + * @param string|null $cacheDir The directory to use for the cache + * @param bool $debug Use cache in debug mode ? + * + * @throws \InvalidArgumentException If a locale contains invalid characters + * + * @api + */ + public function __construct($locale, MessageSelector $selector = null, $cacheDir = null, $debug = false) + { + $this->setLocale($locale); + $this->selector = $selector ?: new MessageSelector(); + $this->cacheDir = $cacheDir; + $this->debug = $debug; + } + + /** + * Sets the ConfigCache factory to use. + * + * @param ConfigCacheFactoryInterface $configCacheFactory + */ + public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory) + { + $this->configCacheFactory = $configCacheFactory; + } + + /** + * Adds a Loader. + * + * @param string $format The name of the loader (@see addResource()) + * @param LoaderInterface $loader A LoaderInterface instance + * + * @api + */ + public function addLoader($format, LoaderInterface $loader) + { + $this->loaders[$format] = $loader; + } + + /** + * Adds a Resource. + * + * @param string $format The name of the loader (@see addLoader()) + * @param mixed $resource The resource name + * @param string $locale The locale + * @param string $domain The domain + * + * @throws \InvalidArgumentException If the locale contains invalid characters + * + * @api + */ + public function addResource($format, $resource, $locale, $domain = null) + { + if (null === $domain) { + $domain = 'messages'; + } + + $this->assertValidLocale($locale); + + $this->resources[$locale][] = array($format, $resource, $domain); + + if (in_array($locale, $this->fallbackLocales)) { + $this->catalogues = array(); + } else { + unset($this->catalogues[$locale]); + } + } + + /** + * {@inheritdoc} + * + * @api + */ + public function setLocale($locale) + { + $this->assertValidLocale($locale); + $this->locale = $locale; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function getLocale() + { + return $this->locale; + } + + /** + * Sets the fallback locale(s). + * + * @param string|array $locales The fallback locale(s) + * + * @throws \InvalidArgumentException If a locale contains invalid characters + * + * @deprecated since version 2.3, to be removed in 3.0. Use setFallbackLocales() instead. + * + * @api + */ + public function setFallbackLocale($locales) + { + trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the setFallbackLocales() method instead.', E_USER_DEPRECATED); + + $this->setFallbackLocales(is_array($locales) ? $locales : array($locales)); + } + + /** + * Sets the fallback locales. + * + * @param array $locales The fallback locales + * + * @throws \InvalidArgumentException If a locale contains invalid characters + * + * @api + */ + public function setFallbackLocales(array $locales) + { + // needed as the fallback locales are linked to the already loaded catalogues + $this->catalogues = array(); + + foreach ($locales as $locale) { + $this->assertValidLocale($locale); + } + + $this->fallbackLocales = $locales; + } + + /** + * Gets the fallback locales. + * + * @return array $locales The fallback locales + * + * @api + */ + public function getFallbackLocales() + { + return $this->fallbackLocales; + } + + /** + * {@inheritdoc} + * + * @api + */ + public function trans($id, array $parameters = array(), $domain = null, $locale = null) + { + if (null === $domain) { + $domain = 'messages'; + } + + return strtr($this->getCatalogue($locale)->get((string) $id, $domain), $parameters); + } + + /** + * {@inheritdoc} + * + * @api + */ + public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) + { + if (null === $domain) { + $domain = 'messages'; + } + + $id = (string) $id; + $catalogue = $this->getCatalogue($locale); + $locale = $catalogue->getLocale(); + while (!$catalogue->defines($id, $domain)) { + if ($cat = $catalogue->getFallbackCatalogue()) { + $catalogue = $cat; + $locale = $catalogue->getLocale(); + } else { + break; + } + } + + return strtr($this->selector->choose($catalogue->get($id, $domain), (int) $number, $locale), $parameters); + } + + /** + * {@inheritdoc} + */ + public function getCatalogue($locale = null) + { + if (null === $locale) { + $locale = $this->getLocale(); + } else { + $this->assertValidLocale($locale); + } + + if (!isset($this->catalogues[$locale])) { + $this->loadCatalogue($locale); + } + + return $this->catalogues[$locale]; + } + + /** + * Gets the loaders. + * + * @return array LoaderInterface[] + */ + protected function getLoaders() + { + return $this->loaders; + } + + /** + * Collects all messages for the given locale. + * + * @param string|null $locale Locale of translations, by default is current locale + * + * @return array[array] indexed by catalog + */ + public function getMessages($locale = null) + { + $catalogue = $this->getCatalogue($locale); + $messages = $catalogue->all(); + while ($catalogue = $catalogue->getFallbackCatalogue()) { + $messages = array_replace_recursive($catalogue->all(), $messages); + } + + return $messages; + } + + /** + * @param string $locale + */ + protected function loadCatalogue($locale) + { + if (null === $this->cacheDir) { + $this->initializeCatalogue($locale); + } else { + $this->initializeCacheCatalogue($locale); + } + } + + /** + * @param string $locale + */ + protected function initializeCatalogue($locale) + { + $this->assertValidLocale($locale); + + try { + $this->doLoadCatalogue($locale); + } catch (NotFoundResourceException $e) { + if (!$this->computeFallbackLocales($locale)) { + throw $e; + } + } + $this->loadFallbackCatalogues($locale); + } + + /** + * @param string $locale + */ + private function initializeCacheCatalogue($locale) + { + if (isset($this->catalogues[$locale])) { + /* Catalogue already initialized. */ + return; + } + + $this->assertValidLocale($locale); + $self = $this; // required for PHP 5.3 where "$this" cannot be use()d in anonymous functions. Change in Symfony 3.0. + $cache = $this->getConfigCacheFactory()->cache($this->getCatalogueCachePath($locale), + function (ConfigCacheInterface $cache) use ($self, $locale) { + $self->dumpCatalogue($locale, $cache); + } + ); + + if (isset($this->catalogues[$locale])) { + /* Catalogue has been initialized as it was written out to cache. */ + return; + } + + /* Read catalogue from cache. */ + $this->catalogues[$locale] = include $cache->getPath(); + } + + /** + * This method is public because it needs to be callable from a closure in PHP 5.3. It should be made protected (or even private, if possible) in 3.0. + * + * @internal + */ + public function dumpCatalogue($locale, ConfigCacheInterface $cache) + { + $this->initializeCatalogue($locale); + $fallbackContent = $this->getFallbackContent($this->catalogues[$locale]); + + $content = sprintf(<<catalogues[$locale]->all(), true), + $fallbackContent + ); + + $cache->write($content, $this->catalogues[$locale]->getResources()); + } + + private function getFallbackContent(MessageCatalogue $catalogue) + { + $fallbackContent = ''; + $current = ''; + $replacementPattern = '/[^a-z0-9_]/i'; + $fallbackCatalogue = $catalogue->getFallbackCatalogue(); + while ($fallbackCatalogue) { + $fallback = $fallbackCatalogue->getLocale(); + $fallbackSuffix = ucfirst(preg_replace($replacementPattern, '_', $fallback)); + $currentSuffix = ucfirst(preg_replace($replacementPattern, '_', $current)); + + $fallbackContent .= sprintf(<<addFallbackCatalogue(\$catalogue%s); + +EOF + , + $fallbackSuffix, + $fallback, + var_export($fallbackCatalogue->all(), true), + $currentSuffix, + $fallbackSuffix + ); + $current = $fallbackCatalogue->getLocale(); + $fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue(); + } + + return $fallbackContent; + } + + private function getCatalogueCachePath($locale) + { + $catalogueHash = sha1(serialize(array( + 'resources' => isset($this->resources[$locale]) ? $this->resources[$locale] : array(), + 'fallback_locales' => $this->fallbackLocales, + ))); + + return $this->cacheDir.'/catalogue.'.$locale.'.'.$catalogueHash.'.php'; + } + + private function doLoadCatalogue($locale) + { + $this->catalogues[$locale] = new MessageCatalogue($locale); + + if (isset($this->resources[$locale])) { + foreach ($this->resources[$locale] as $resource) { + if (!isset($this->loaders[$resource[0]])) { + throw new \RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0])); + } + $this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2])); + } + } + } + + private function loadFallbackCatalogues($locale) + { + $current = $this->catalogues[$locale]; + + foreach ($this->computeFallbackLocales($locale) as $fallback) { + if (!isset($this->catalogues[$fallback])) { + $this->doLoadCatalogue($fallback); + } + + $current->addFallbackCatalogue($this->catalogues[$fallback]); + $current = $this->catalogues[$fallback]; + } + } + + protected function computeFallbackLocales($locale) + { + $locales = array(); + foreach ($this->fallbackLocales as $fallback) { + if ($fallback === $locale) { + continue; + } + + $locales[] = $fallback; + } + + if (strrchr($locale, '_') !== false) { + array_unshift($locales, substr($locale, 0, -strlen(strrchr($locale, '_')))); + } + + return array_unique($locales); + } + + /** + * Asserts that the locale is valid, throws an Exception if not. + * + * @param string $locale Locale to tests + * + * @throws \InvalidArgumentException If the locale contains invalid characters + */ + protected function assertValidLocale($locale) + { + if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) { + throw new \InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale)); + } + } + + /** + * Provides the ConfigCache factory implementation, falling back to a + * default implementation if necessary. + * + * @return ConfigCacheFactoryInterface $configCacheFactory + */ + private function getConfigCacheFactory() + { + if (!$this->configCacheFactory) { + $this->configCacheFactory = new ConfigCacheFactory($this->debug); + } + + return $this->configCacheFactory; + } +} diff --git a/vendor/symfony/translation/TranslatorBagInterface.php b/vendor/symfony/translation/TranslatorBagInterface.php new file mode 100755 index 0000000..6f650b5 --- /dev/null +++ b/vendor/symfony/translation/TranslatorBagInterface.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * TranslatorBagInterface. + * + * @author Abdellatif Ait boudad + */ +interface TranslatorBagInterface +{ + /** + * Gets the catalogue by locale. + * + * @param string|null $locale The locale or null to use the default + * + * @throws \InvalidArgumentException If the locale contains invalid characters + * + * @return MessageCatalogueInterface + */ + public function getCatalogue($locale = null); +} diff --git a/vendor/symfony/translation/TranslatorInterface.php b/vendor/symfony/translation/TranslatorInterface.php new file mode 100755 index 0000000..fe1a865 --- /dev/null +++ b/vendor/symfony/translation/TranslatorInterface.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation; + +/** + * TranslatorInterface. + * + * @author Fabien Potencier + * + * @api + */ +interface TranslatorInterface +{ + /** + * Translates the given message. + * + * @param string $id The message id (may also be an object that can be cast to string) + * @param array $parameters An array of parameters for the message + * @param string|null $domain The domain for the message or null to use the default + * @param string|null $locale The locale or null to use the default + * + * @throws \InvalidArgumentException If the locale contains invalid characters + * + * @return string The translated string + * + * @api + */ + public function trans($id, array $parameters = array(), $domain = null, $locale = null); + + /** + * Translates the given choice message by choosing a translation according to a number. + * + * @param string $id The message id (may also be an object that can be cast to string) + * @param int $number The number to use to find the indice of the message + * @param array $parameters An array of parameters for the message + * @param string|null $domain The domain for the message or null to use the default + * @param string|null $locale The locale or null to use the default + * + * @throws \InvalidArgumentException If the locale contains invalid characters + * + * @return string The translated string + * + * @api + */ + public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null); + + /** + * Sets the current locale. + * + * @param string $locale The locale + * + * @throws \InvalidArgumentException If the locale contains invalid characters + * + * @api + */ + public function setLocale($locale); + + /** + * Returns the current locale. + * + * @return string The locale + * + * @api + */ + public function getLocale(); +} diff --git a/vendor/symfony/translation/Writer/TranslationWriter.php b/vendor/symfony/translation/Writer/TranslationWriter.php new file mode 100755 index 0000000..44ac182 --- /dev/null +++ b/vendor/symfony/translation/Writer/TranslationWriter.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Writer; + +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Dumper\DumperInterface; + +/** + * TranslationWriter writes translation messages. + * + * @author Michel Salib + */ +class TranslationWriter +{ + /** + * Dumpers used for export. + * + * @var array + */ + private $dumpers = array(); + + /** + * Adds a dumper to the writer. + * + * @param string $format The format of the dumper + * @param DumperInterface $dumper The dumper + */ + public function addDumper($format, DumperInterface $dumper) + { + $this->dumpers[$format] = $dumper; + } + + /** + * Disables dumper backup. + */ + public function disableBackup() + { + foreach ($this->dumpers as $dumper) { + $dumper->setBackup(false); + } + } + + /** + * Obtains the list of supported formats. + * + * @return array + */ + public function getFormats() + { + return array_keys($this->dumpers); + } + + /** + * Writes translation from the catalogue according to the selected format. + * + * @param MessageCatalogue $catalogue The message catalogue to dump + * @param string $format The format to use to dump the messages + * @param array $options Options that are passed to the dumper + * + * @throws \InvalidArgumentException + */ + public function writeTranslations(MessageCatalogue $catalogue, $format, $options = array()) + { + if (!isset($this->dumpers[$format])) { + throw new \InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format)); + } + + // get the right dumper + $dumper = $this->dumpers[$format]; + + if (isset($options['path']) && !is_dir($options['path'])) { + mkdir($options['path'], 0777, true); + } + + // save + $dumper->dump($catalogue, $options); + } +} diff --git a/vendor/symfony/translation/composer.json b/vendor/symfony/translation/composer.json new file mode 100755 index 0000000..6f1053e --- /dev/null +++ b/vendor/symfony/translation/composer.json @@ -0,0 +1,45 @@ +{ + "name": "symfony/translation", + "type": "library", + "description": "Symfony Translation Component", + "keywords": [], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7", + "symfony/config": "~2.7", + "symfony/intl": "~2.3", + "symfony/yaml": "~2.2", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/config": "<2.7" + }, + "suggest": { + "symfony/config": "", + "symfony/yaml": "", + "psr/log": "To use logging capability in translator" + }, + "autoload": { + "psr-4": { "Symfony\\Component\\Translation\\": "" } + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + } +} diff --git a/vendor/symfony/translation/phpunit.xml.dist b/vendor/symfony/translation/phpunit.xml.dist new file mode 100755 index 0000000..16cca4a --- /dev/null +++ b/vendor/symfony/translation/phpunit.xml.dist @@ -0,0 +1,28 @@ + + + + + + + + + + ./Tests/ + + + + + + ./ + + ./vendor + ./Tests + + + + diff --git a/vendor/twig/twig/CHANGELOG b/vendor/twig/twig/CHANGELOG new file mode 100755 index 0000000..9493d5d --- /dev/null +++ b/vendor/twig/twig/CHANGELOG @@ -0,0 +1,736 @@ +* 1.18.2 (2015-06-06) + + * fixed template/line guessing in exceptions for nested templates + * optimized the number of inodes and the size of realpath cache when using the cache + +* 1.18.1 (2015-04-19) + + * fixed memory leaks in the C extension + * deprecated Twig_Loader_String + * fixed the slice filter when used with a SimpleXMLElement object + * fixed filesystem loader when trying to load non-files (like directories) + +* 1.18.0 (2015-01-25) + + * fixed some error messages where the line was wrong (unknown variables or argument names) + * added a new way to customize the main Module node (via empty nodes) + * added Twig_Environment::createTemplate() to create a template from a string + * added a profiler + * fixed filesystem loader cache when different file paths are used for the same template + +* 1.17.0 (2015-01-14) + + * added a 'filename' autoescaping strategy, which dynamically chooses the + autoescaping strategy for a template based on template file extension. + +* 1.16.3 (2014-12-25) + + * fixed regression for dynamic parent templates + * fixed cache management with statcache + * fixed a regression in the slice filter + +* 1.16.2 (2014-10-17) + + * fixed timezone on dates as strings + * fixed 2-words test names when a custom node class is not used + * fixed macros when using an argument named like a PHP super global (like GET or POST) + * fixed date_modify when working with DateTimeImmutable + * optimized for loops + * fixed multi-byte characters handling in the split filter + * fixed a regression in the in operator + * fixed a regression in the slice filter + +* 1.16.1 (2014-10-10) + + * improved error reporting in a sandboxed template + * fixed missing error file/line information under certain circumstances + * fixed wrong error line number in some error messages + * fixed the in operator to use strict comparisons + * sped up the slice filter + * fixed for mb function overload mb_substr acting different + * fixed the attribute() function when passing a variable for the arguments + +* 1.16.0 (2014-07-05) + + * changed url_encode to always encode according to RFC 3986 + * fixed inheritance in a 'use'-hierarchy + * removed the __toString policy check when the sandbox is disabled + * fixed recursively calling blocks in templates with inheritance + +* 1.15.1 (2014-02-13) + + * fixed the conversion of the special '0000-00-00 00:00' date + * added an error message when trying to import an undefined block from a trait + * fixed a C extension crash when accessing defined but uninitialized property. + +* 1.15.0 (2013-12-06) + + * made ignoreStrictCheck in Template::getAttribute() works with __call() methods throwing BadMethodCallException + * added min and max functions + * added the round filter + * fixed a bug that prevented the optimizers to be enabled/disabled selectively + * fixed first and last filters for UTF-8 strings + * added a source function to include the content of a template without rendering it + * fixed the C extension sandbox behavior when get or set is prepend to method name + +* 1.14.2 (2013-10-30) + + * fixed error filename/line when an error occurs in an included file + * allowed operators that contain whitespaces to have more than one whitespace + * allowed tests to be made of 1 or 2 words (like "same as" or "divisible by") + +* 1.14.1 (2013-10-15) + + * made it possible to use named operators as variables + * fixed the possibility to have a variable named 'matches' + * added support for PHP 5.5 DateTimeInterface + +* 1.14.0 (2013-10-03) + + * fixed usage of the html_attr escaping strategy to avoid double-escaping with the html strategy + * added new operators: ends with, starts with, and matches + * fixed some compatibility issues with HHVM + * added a way to add custom escaping strategies + * fixed the C extension compilation on Windows + * fixed the batch filter when using a fill argument with an exact match of elements to batch + * fixed the filesystem loader cache when a template name exists in several namespaces + * fixed template_from_string when the template includes or extends other ones + * fixed a crash of the C extension on an edge case + +* 1.13.2 (2013-08-03) + + * fixed the error line number for an error occurs in and embedded template + * fixed crashes of the C extension on some edge cases + +* 1.13.1 (2013-06-06) + + * added the possibility to ignore the filesystem constructor argument in Twig_Loader_Filesystem + * fixed Twig_Loader_Chain::exists() for a loader which implements Twig_ExistsLoaderInterface + * adjusted backtrace call to reduce memory usage when an error occurs + * added support for object instances as the second argument of the constant test + * fixed the include function when used in an assignment + +* 1.13.0 (2013-05-10) + + * fixed getting a numeric-like item on a variable ('09' for instance) + * fixed getting a boolean or float key on an array, so it is consistent with PHP's array access: + `{{ array[false] }}` behaves the same as `echo $array[false];` (equals `$array[0]`) + * made the escape filter 20% faster for happy path (escaping string for html with UTF-8) + * changed ☃ to § in tests + * enforced usage of named arguments after positional ones + +* 1.12.3 (2013-04-08) + + * fixed a security issue in the filesystem loader where it was possible to include a template one + level above the configured path + * fixed fatal error that should be an exception when adding a filter/function/test too late + * added a batch filter + * added support for encoding an array as query string in the url_encode filter + +* 1.12.2 (2013-02-09) + + * fixed the timezone used by the date filter and function when the given date contains a timezone (like 2010-01-28T15:00:00+02:00) + * fixed globals when getGlobals is called early on + * added the first and last filter + +* 1.12.1 (2013-01-15) + + * added support for object instances as the second argument of the constant function + * relaxed globals management to avoid a BC break + * added support for {{ some_string[:2] }} + +* 1.12.0 (2013-01-08) + + * added verbatim as an alias for the raw tag to avoid confusion with the raw filter + * fixed registration of tests and functions as anonymous functions + * fixed globals management + +* 1.12.0-RC1 (2012-12-29) + + * added an include function (does the same as the include tag but in a more flexible way) + * added the ability to use any PHP callable to define filters, functions, and tests + * added a syntax error when using a loop variable that is not defined + * added the ability to set default values for macro arguments + * added support for named arguments for filters, tests, and functions + * moved filters/functions/tests syntax errors to the parser + * added support for extended ternary operator syntaxes + +* 1.11.1 (2012-11-11) + + * fixed debug info line numbering (was off by 2) + * fixed escaping when calling a macro inside another one (regression introduced in 1.9.1) + * optimized variable access on PHP 5.4 + * fixed a crash of the C extension when an exception was thrown from a macro called without being imported (using _self.XXX) + +* 1.11.0 (2012-11-07) + + * fixed macro compilation when a variable name is a PHP reserved keyword + * changed the date filter behavior to always apply the default timezone, except if false is passed as the timezone + * fixed bitwise operator precedences + * added the template_from_string function + * fixed default timezone usage for the date function + * optimized the way Twig exceptions are managed (to make them faster) + * added Twig_ExistsLoaderInterface (implementing this interface in your loader make the chain loader much faster) + +* 1.10.3 (2012-10-19) + + * fixed wrong template location in some error messages + * reverted a BC break introduced in 1.10.2 + * added a split filter + +* 1.10.2 (2012-10-15) + + * fixed macro calls on PHP 5.4 + +* 1.10.1 (2012-10-15) + + * made a speed optimization to macro calls when imported via the "import" tag + * fixed C extension compilation on Windows + * fixed a segfault in the C extension when using DateTime objects + +* 1.10.0 (2012-09-28) + + * extracted functional tests framework to make it reusable for third-party extensions + * added namespaced templates support in Twig_Loader_Filesystem + * added Twig_Loader_Filesystem::prependPath() + * fixed an error when a token parser pass a closure as a test to the subparse() method + +* 1.9.2 (2012-08-25) + + * fixed the in operator for objects that contain circular references + * fixed the C extension when accessing a public property of an object implementing the \ArrayAccess interface + +* 1.9.1 (2012-07-22) + + * optimized macro calls when auto-escaping is on + * fixed wrong parent class for Twig_Function_Node + * made Twig_Loader_Chain more explicit about problems + +* 1.9.0 (2012-07-13) + + * made the parsing independent of the template loaders + * fixed exception trace when an error occurs when rendering a child template + * added escaping strategies for CSS, URL, and HTML attributes + * fixed nested embed tag calls + * added the date_modify filter + +* 1.8.3 (2012-06-17) + + * fixed paths in the filesystem loader when passing a path that ends with a slash or a backslash + * fixed escaping when a project defines a function named html or js + * fixed chmod mode to apply the umask correctly + +* 1.8.2 (2012-05-30) + + * added the abs filter + * fixed a regression when using a number in template attributes + * fixed compiler when mbstring.func_overload is set to 2 + * fixed DateTimeZone support in date filter + +* 1.8.1 (2012-05-17) + + * fixed a regression when dealing with SimpleXMLElement instances in templates + * fixed "is_safe" value for the "dump" function when "html_errors" is not defined in php.ini + * switched to use mbstring whenever possible instead of iconv (you might need to update your encoding as mbstring and iconv encoding names sometimes differ) + +* 1.8.0 (2012-05-08) + + * enforced interface when adding tests, filters, functions, and node visitors from extensions + * fixed a side-effect of the date filter where the timezone might be changed + * simplified usage of the autoescape tag; the only (optional) argument is now the escaping strategy or false (with a BC layer) + * added a way to dynamically change the auto-escaping strategy according to the template "filename" + * changed the autoescape option to also accept a supported escaping strategy (for BC, true is equivalent to html) + * added an embed tag + +* 1.7.0 (2012-04-24) + + * fixed a PHP warning when using CIFS + * fixed template line number in some exceptions + * added an iterable test + * added an error when defining two blocks with the same name in a template + * added the preserves_safety option for filters + * fixed a PHP notice when trying to access a key on a non-object/array variable + * enhanced error reporting when the template file is an instance of SplFileInfo + * added Twig_Environment::mergeGlobals() + * added compilation checks to avoid misuses of the sandbox tag + * fixed filesystem loader freshness logic for high traffic websites + * fixed random function when charset is null + +* 1.6.5 (2012-04-11) + + * fixed a regression when a template only extends another one without defining any blocks + +* 1.6.4 (2012-04-02) + + * fixed PHP notice in Twig_Error::guessTemplateLine() introduced in 1.6.3 + * fixed performance when compiling large files + * optimized parent template creation when the template does not use dynamic inheritance + +* 1.6.3 (2012-03-22) + + * fixed usage of Z_ADDREF_P for PHP 5.2 in the C extension + * fixed compilation of numeric values used in templates when using a locale where the decimal separator is not a dot + * made the strategy used to guess the real template file name and line number in exception messages much faster and more accurate + +* 1.6.2 (2012-03-18) + + * fixed sandbox mode when used with inheritance + * added preserveKeys support for the slice filter + * fixed the date filter when a DateTime instance is passed with a specific timezone + * added a trim filter + +* 1.6.1 (2012-02-29) + + * fixed Twig C extension + * removed the creation of Twig_Markup instances when not needed + * added a way to set the default global timezone for dates + * fixed the slice filter on strings when the length is not specified + * fixed the creation of the cache directory in case of a race condition + +* 1.6.0 (2012-02-04) + + * fixed raw blocks when used with the whitespace trim option + * made a speed optimization to macro calls when imported via the "from" tag + * fixed globals, parsers, visitors, filters, tests, and functions management in Twig_Environment when a new one or new extension is added + * fixed the attribute function when passing arguments + * added slice notation support for the [] operator (syntactic sugar for the slice operator) + * added a slice filter + * added string support for the reverse filter + * fixed the empty test and the length filter for Twig_Markup instances + * added a date function to ease date comparison + * fixed unary operators precedence + * added recursive parsing support in the parser + * added string and integer handling for the random function + +* 1.5.1 (2012-01-05) + + * fixed a regression when parsing strings + +* 1.5.0 (2012-01-04) + + * added Traversable objects support for the join filter + +* 1.5.0-RC2 (2011-12-30) + + * added a way to set the default global date interval format + * fixed the date filter for DateInterval instances (setTimezone() does not exist for them) + * refactored Twig_Template::display() to ease its extension + * added a number_format filter + +* 1.5.0-RC1 (2011-12-26) + + * removed the need to quote hash keys + * allowed hash keys to be any expression + * added a do tag + * added a flush tag + * added support for dynamically named filters and functions + * added a dump function to help debugging templates + * added a nl2br filter + * added a random function + * added a way to change the default format for the date filter + * fixed the lexer when an operator ending with a letter ends a line + * added string interpolation support + * enhanced exceptions for unknown filters, functions, tests, and tags + +* 1.4.0 (2011-12-07) + + * fixed lexer when using big numbers (> PHP_INT_MAX) + * added missing preserveKeys argument to the reverse filter + * fixed macros containing filter tag calls + +* 1.4.0-RC2 (2011-11-27) + + * removed usage of Reflection in Twig_Template::getAttribute() + * added a C extension that can optionally replace Twig_Template::getAttribute() + * added negative timestamp support to the date filter + +* 1.4.0-RC1 (2011-11-20) + + * optimized variable access when using PHP 5.4 + * changed the precedence of the .. operator to be more consistent with languages that implements such a feature like Ruby + * added an Exception to Twig_Loader_Array::isFresh() method when the template does not exist to be consistent with other loaders + * added Twig_Function_Node to allow more complex functions to have their own Node class + * added Twig_Filter_Node to allow more complex filters to have their own Node class + * added Twig_Test_Node to allow more complex tests to have their own Node class + * added a better error message when a template is empty but contain a BOM + * fixed "in" operator for empty strings + * fixed the "defined" test and the "default" filter (now works with more than one call (foo.bar.foo) and for both values of the strict_variables option) + * changed the way extensions are loaded (addFilter/addFunction/addGlobal/addTest/addNodeVisitor/addTokenParser/addExtension can now be called in any order) + * added Twig_Environment::display() + * made the escape filter smarter when the encoding is not supported by PHP + * added a convert_encoding filter + * moved all node manipulations outside the compile() Node method + * made several speed optimizations + +* 1.3.0 (2011-10-08) + +no changes + +* 1.3.0-RC1 (2011-10-04) + + * added an optimization for the parent() function + * added cache reloading when auto_reload is true and an extension has been modified + * added the possibility to force the escaping of a string already marked as safe (instance of Twig_Markup) + * allowed empty templates to be used as traits + * added traits support for the "parent" function + +* 1.2.0 (2011-09-13) + +no changes + +* 1.2.0-RC1 (2011-09-10) + + * enhanced the exception when a tag remains unclosed + * added support for empty Countable objects for the "empty" test + * fixed algorithm that determines if a template using inheritance is valid (no output between block definitions) + * added better support for encoding problems when escaping a string (available as of PHP 5.4) + * added a way to ignore a missing template when using the "include" tag ({% include "foo" ignore missing %}) + * added support for an array of templates to the "include" and "extends" tags ({% include ['foo', 'bar'] %}) + * added support for bitwise operators in expressions + * added the "attribute" function to allow getting dynamic attributes on variables + * added Twig_Loader_Chain + * added Twig_Loader_Array::setTemplate() + * added an optimization for the set tag when used to capture a large chunk of static text + * changed name regex to match PHP one "[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*" (works for blocks, tags, functions, filters, and macros) + * removed the possibility to use the "extends" tag from a block + * added "if" modifier support to "for" loops + +* 1.1.2 (2011-07-30) + + * fixed json_encode filter on PHP 5.2 + * fixed regression introduced in 1.1.1 ({{ block(foo|lower) }}) + * fixed inheritance when using conditional parents + * fixed compilation of templates when the body of a child template is not empty + * fixed output when a macro throws an exception + * fixed a parsing problem when a large chunk of text is enclosed in a comment tag + * added PHPDoc for all Token parsers and Core extension functions + +* 1.1.1 (2011-07-17) + + * added a performance optimization in the Optimizer (also helps to lower the number of nested level calls) + * made some performance improvement for some edge cases + +* 1.1.0 (2011-06-28) + + * fixed json_encode filter + +* 1.1.0-RC3 (2011-06-24) + + * fixed method case-sensitivity when using the sandbox mode + * added timezone support for the date filter + * fixed possible security problems with NUL bytes + +* 1.1.0-RC2 (2011-06-16) + + * added an exception when the template passed to "use" is not a string + * made 'a.b is defined' not throw an exception if a is not defined (in strict mode) + * added {% line \d+ %} directive + +* 1.1.0-RC1 (2011-05-28) + +Flush your cache after upgrading. + + * fixed date filter when using a timestamp + * fixed the defined test for some cases + * fixed a parsing problem when a large chunk of text is enclosed in a raw tag + * added support for horizontal reuse of template blocks (see docs for more information) + * added whitespace control modifier to all tags (see docs for more information) + * added null as an alias for none (the null test is also an alias for the none test now) + * made TRUE, FALSE, NONE equivalent to their lowercase counterparts + * wrapped all compilation and runtime exceptions with Twig_Error_Runtime and added logic to guess the template name and line + * moved display() method to Twig_Template (generated templates should now use doDisplay() instead) + +* 1.0.0 (2011-03-27) + + * fixed output when using mbstring + * fixed duplicate call of methods when using the sandbox + * made the charset configurable for the escape filter + +* 1.0.0-RC2 (2011-02-21) + + * changed the way {% set %} works when capturing (the content is now marked as safe) + * added support for macro name in the endmacro tag + * make Twig_Error compatible with PHP 5.3.0 > + * fixed an infinite loop on some Windows configurations + * fixed the "length" filter for numbers + * fixed Template::getAttribute() as properties in PHP are case sensitive + * removed coupling between Twig_Node and Twig_Template + * fixed the ternary operator precedence rule + +* 1.0.0-RC1 (2011-01-09) + +Backward incompatibilities: + + * the "items" filter, which has been deprecated for quite a long time now, has been removed + * the "range" filter has been converted to a function: 0|range(10) -> range(0, 10) + * the "constant" filter has been converted to a function: {{ some_date|date('DATE_W3C'|constant) }} -> {{ some_date|date(constant('DATE_W3C')) }} + * the "cycle" filter has been converted to a function: {{ ['odd', 'even']|cycle(i) }} -> {{ cycle(['odd', 'even'], i) }} + * the "for" tag does not support "joined by" anymore + * the "autoescape" first argument is now "true"/"false" (instead of "on"/"off") + * the "parent" tag has been replaced by a "parent" function ({{ parent() }} instead of {% parent %}) + * the "display" tag has been replaced by a "block" function ({{ block('title') }} instead of {% display title %}) + * removed the grammar and simple token parser (moved to the Twig Extensions repository) + +Changes: + + * added "needs_context" option for filters and functions (the context is then passed as a first argument) + * added global variables support + * made macros return their value instead of echoing directly (fixes calling a macro in sandbox mode) + * added the "from" tag to import macros as functions + * added support for functions (a function is just syntactic sugar for a getAttribute() call) + * made macros callable when sandbox mode is enabled + * added an exception when a macro uses a reserved name + * the "default" filter now uses the "empty" test instead of just checking for null + * added the "empty" test + +* 0.9.10 (2010-12-16) + +Backward incompatibilities: + + * The Escaper extension is enabled by default, which means that all displayed + variables are now automatically escaped. You can revert to the previous + behavior by removing the extension via $env->removeExtension('escaper') + or just set the 'autoescape' option to 'false'. + * removed the "without loop" attribute for the "for" tag (not needed anymore + as the Optimizer take care of that for most cases) + * arrays and hashes have now a different syntax + * arrays keep the same syntax with square brackets: [1, 2] + * hashes now use curly braces (["a": "b"] should now be written as {"a": "b"}) + * support for "arrays with keys" and "hashes without keys" is not supported anymore ([1, "foo": "bar"] or {"foo": "bar", 1}) + * the i18n extension is now part of the Twig Extensions repository + +Changes: + + * added the merge filter + * removed 'is_escaper' option for filters (a left over from the previous version) -- you must use 'is_safe' now instead + * fixed usage of operators as method names (like is, in, and not) + * changed the order of execution for node visitors + * fixed default() filter behavior when used with strict_variables set to on + * fixed filesystem loader compatibility with PHAR files + * enhanced error messages when an unexpected token is parsed in an expression + * fixed filename not being added to syntax error messages + * added the autoescape option to enable/disable autoescaping + * removed the newline after a comment (mimics PHP behavior) + * added a syntax error exception when parent block is used on a template that does not extend another one + * made the Escaper extension enabled by default + * fixed sandbox extension when used with auto output escaping + * fixed escaper when wrapping a Twig_Node_Print (the original class must be preserved) + * added an Optimizer extension (enabled by default; optimizes "for" loops and "raw" filters) + * added priority to node visitors + +* 0.9.9 (2010-11-28) + +Backward incompatibilities: + * the self special variable has been renamed to _self + * the odd and even filters are now tests: + {{ foo|odd }} must now be written {{ foo is odd }} + * the "safe" filter has been renamed to "raw" + * in Node classes, + sub-nodes are now accessed via getNode() (instead of property access) + attributes via getAttribute() (instead of array access) + * the urlencode filter had been renamed to url_encode + * the include tag now merges the passed variables with the current context by default + (the old behavior is still possible by adding the "only" keyword) + * moved Exceptions to Twig_Error_* (Twig_SyntaxError/Twig_RuntimeError are now Twig_Error_Syntax/Twig_Error_Runtime) + * removed support for {{ 1 < i < 3 }} (use {{ i > 1 and i < 3 }} instead) + * the "in" filter has been removed ({{ a|in(b) }} should now be written {{ a in b }}) + +Changes: + * added file and line to Twig_Error_Runtime exceptions thrown from Twig_Template + * changed trans tag to accept any variable for the plural count + * fixed sandbox mode (__toString() method check was not enforced if called implicitly from complex statements) + * added the ** (power) operator + * changed the algorithm used for parsing expressions + * added the spaceless tag + * removed trim_blocks option + * added support for is*() methods for attributes (foo.bar now looks for foo->getBar() or foo->isBar()) + * changed all exceptions to extend Twig_Error + * fixed unary expressions ({{ not(1 or 0) }}) + * fixed child templates (with an extend tag) that uses one or more imports + * added support for {{ 1 not in [2, 3] }} (more readable than the current {{ not (1 in [2, 3]) }}) + * escaping has been rewritten + * the implementation of template inheritance has been rewritten + (blocks can now be called individually and still work with inheritance) + * fixed error handling for if tag when a syntax error occurs within a subparse process + * added a way to implement custom logic for resolving token parsers given a tag name + * fixed js escaper to be stricter (now uses a whilelist-based js escaper) + * added the following filers: "constant", "trans", "replace", "json_encode" + * added a "constant" test + * fixed objects with __toString() not being autoescaped + * fixed subscript expressions when calling __call() (methods now keep the case) + * added "test" feature (accessible via the "is" operator) + * removed the debug tag (should be done in an extension) + * fixed trans tag when no vars are used in plural form + * fixed race condition when writing template cache + * added the special _charset variable to reference the current charset + * added the special _context variable to reference the current context + * renamed self to _self (to avoid conflict) + * fixed Twig_Template::getAttribute() for protected properties + +* 0.9.8 (2010-06-28) + +Backward incompatibilities: + * the trans tag plural count is now attached to the plural tag: + old: `{% trans count %}...{% plural %}...{% endtrans %}` + new: `{% trans %}...{% plural count %}...{% endtrans %}` + + * added a way to translate strings coming from a variable ({% trans var %}) + * fixed trans tag when used with the Escaper extension + * fixed default cache umask + * removed Twig_Template instances from the debug tag output + * fixed objects with __isset() defined + * fixed set tag when used with a capture + * fixed type hinting for Twig_Environment::addFilter() method + +* 0.9.7 (2010-06-12) + +Backward incompatibilities: + * changed 'as' to '=' for the set tag ({% set title as "Title" %} must now be {% set title = "Title" %}) + * removed the sandboxed attribute of the include tag (use the new sandbox tag instead) + * refactored the Node system (if you have custom nodes, you will have to update them to use the new API) + + * added self as a special variable that refers to the current template (useful for importing macros from the current template) + * added Twig_Template instance support to the include tag + * added support for dynamic and conditional inheritance ({% extends some_var %} and {% extends standalone ? "minimum" : "base" %}) + * added a grammar sub-framework to ease the creation of custom tags + * fixed the for tag for large arrays (some loop variables are now only available for arrays and objects that implement the Countable interface) + * removed the Twig_Resource::resolveMissingFilter() method + * fixed the filter tag which did not apply filtering to included files + * added a bunch of unit tests + * added a bunch of phpdoc + * added a sandbox tag in the sandbox extension + * changed the date filter to support any date format supported by DateTime + * added strict_variable setting to throw an exception when an invalid variable is used in a template (disabled by default) + * added the lexer, parser, and compiler as arguments to the Twig_Environment constructor + * changed the cache option to only accepts an explicit path to a cache directory or false + * added a way to add token parsers, filters, and visitors without creating an extension + * added three interfaces: Twig_NodeInterface, Twig_TokenParserInterface, and Twig_FilterInterface + * changed the generated code to match the new coding standards + * fixed sandbox mode (__toString() method check was not enforced if called implicitly from a simple statement like {{ article }}) + * added an exception when a child template has a non-empty body (as it is always ignored when rendering) + +* 0.9.6 (2010-05-12) + + * fixed variables defined outside a loop and for which the value changes in a for loop + * fixed the test suite for PHP 5.2 and older versions of PHPUnit + * added support for __call() in expression resolution + * fixed node visiting for macros (macros are now visited by visitors as any other node) + * fixed nested block definitions with a parent call (rarely useful but nonetheless supported now) + * added the cycle filter + * fixed the Lexer when mbstring.func_overload is used with an mbstring.internal_encoding different from ASCII + * added a long-syntax for the set tag ({% set foo %}...{% endset %}) + * unit tests are now powered by PHPUnit + * added support for gettext via the `i18n` extension + * fixed twig_capitalize_string_filter() and fixed twig_length_filter() when used with UTF-8 values + * added a more useful exception if an if tag is not closed properly + * added support for escaping strategy in the autoescape tag + * fixed lexer when a template has a big chunk of text between/in a block + +* 0.9.5 (2010-01-20) + +As for any new release, don't forget to remove all cached templates after +upgrading. + +If you have defined custom filters, you MUST upgrade them for this release. To +upgrade, replace "array" with "new Twig_Filter_Function", and replace the +environment constant by the "needs_environment" option: + + // before + 'even' => array('twig_is_even_filter', false), + 'escape' => array('twig_escape_filter', true), + + // after + 'even' => new Twig_Filter_Function('twig_is_even_filter'), + 'escape' => new Twig_Filter_Function('twig_escape_filter', array('needs_environment' => true)), + +If you have created NodeTransformer classes, you will need to upgrade them to +the new interface (please note that the interface is not yet considered +stable). + + * fixed list nodes that did not extend the Twig_NodeListInterface + * added the "without loop" option to the for tag (it disables the generation of the loop variable) + * refactored node transformers to node visitors + * fixed automatic-escaping for blocks + * added a way to specify variables to pass to an included template + * changed the automatic-escaping rules to be more sensible and more configurable in custom filters (the documentation lists all the rules) + * improved the filter system to allow object methods to be used as filters + * changed the Array and String loaders to actually make use of the cache mechanism + * included the default filter function definitions in the extension class files directly (Core, Escaper) + * added the // operator (like the floor() PHP function) + * added the .. operator (as a syntactic sugar for the range filter when the step is 1) + * added the in operator (as a syntactic sugar for the in filter) + * added the following filters in the Core extension: in, range + * added support for arrays (same behavior as in PHP, a mix between lists and dictionaries, arrays and hashes) + * enhanced some error messages to provide better feedback in case of parsing errors + +* 0.9.4 (2009-12-02) + +If you have custom loaders, you MUST upgrade them for this release: The +Twig_Loader base class has been removed, and the Twig_LoaderInterface has also +been changed (see the source code for more information or the documentation). + + * added support for DateTime instances for the date filter + * fixed loop.last when the array only has one item + * made it possible to insert newlines in tag and variable blocks + * fixed a bug when a literal '\n' were present in a template text + * fixed bug when the filename of a template contains */ + * refactored loaders + +* 0.9.3 (2009-11-11) + +This release is NOT backward compatible with the previous releases. + + The loaders do not take the cache and autoReload arguments anymore. Instead, + the Twig_Environment class has two new options: cache and auto_reload. + Upgrading your code means changing this kind of code: + + $loader = new Twig_Loader_Filesystem('/path/to/templates', '/path/to/compilation_cache', true); + $twig = new Twig_Environment($loader); + + to something like this: + + $loader = new Twig_Loader_Filesystem('/path/to/templates'); + $twig = new Twig_Environment($loader, array( + 'cache' => '/path/to/compilation_cache', + 'auto_reload' => true, + )); + + * deprecated the "items" filter as it is not needed anymore + * made cache and auto_reload options of Twig_Environment instead of arguments of Twig_Loader + * optimized template loading speed + * removed output when an error occurs in a template and render() is used + * made major speed improvements for loops (up to 300% on even the smallest loops) + * added properties as part of the sandbox mode + * added public properties support (obj.item can now be the item property on the obj object) + * extended set tag to support expression as value ({% set foo as 'foo' ~ 'bar' %} ) + * fixed bug when \ was used in HTML + +* 0.9.2 (2009-10-29) + + * made some speed optimizations + * changed the cache extension to .php + * added a js escaping strategy + * added support for short block tag + * changed the filter tag to allow chained filters + * made lexer more flexible as you can now change the default delimiters + * added set tag + * changed default directory permission when cache dir does not exist (more secure) + * added macro support + * changed filters first optional argument to be a Twig_Environment instance instead of a Twig_Template instance + * made Twig_Autoloader::autoload() a static method + * avoid writing template file if an error occurs + * added $ escaping when outputting raw strings + * enhanced some error messages to ease debugging + * fixed empty cache files when the template contains an error + +* 0.9.1 (2009-10-14) + + * fixed a bug in PHP 5.2.6 + * fixed numbers with one than one decimal + * added support for method calls with arguments ({{ foo.bar('a', 43) }}) + * made small speed optimizations + * made minor tweaks to allow better extensibility and flexibility + +* 0.9.0 (2009-10-12) + + * Initial release diff --git a/vendor/twig/twig/LICENSE b/vendor/twig/twig/LICENSE new file mode 100755 index 0000000..a470002 --- /dev/null +++ b/vendor/twig/twig/LICENSE @@ -0,0 +1,31 @@ +Copyright (c) 2009-2014 by the Twig Team. + +Some rights reserved. + +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/vendor/twig/twig/README.rst b/vendor/twig/twig/README.rst new file mode 100755 index 0000000..81737b0 --- /dev/null +++ b/vendor/twig/twig/README.rst @@ -0,0 +1,15 @@ +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. + +More Information +---------------- + +Read the `documentation`_ for more information. + +.. _documentation: http://twig.sensiolabs.org/documentation diff --git a/vendor/twig/twig/composer.json b/vendor/twig/twig/composer.json new file mode 100755 index 0000000..20d8ca7 --- /dev/null +++ b/vendor/twig/twig/composer.json @@ -0,0 +1,42 @@ +{ + "name": "twig/twig", + "type": "library", + "description": "Twig, the flexible, fast, and secure template language for PHP", + "keywords": ["templating"], + "homepage": "http://twig.sensiolabs.org", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "homepage": "http://twig.sensiolabs.org/contributors", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "support": { + "forum": "https://groups.google.com/forum/#!forum/twig-users" + }, + "require": { + "php": ">=5.2.7" + }, + "autoload": { + "psr-0" : { + "Twig_" : "lib/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + } + } +} diff --git a/vendor/twig/twig/doc/advanced.rst b/vendor/twig/twig/doc/advanced.rst new file mode 100755 index 0000000..0e3be90 --- /dev/null +++ b/vendor/twig/twig/doc/advanced.rst @@ -0,0 +1,834 @@ +Extending Twig +============== + +.. caution:: + + This section describes how to extend Twig as of **Twig 1.12**. If you are + using an older version, read the :doc:`legacy` chapter + instead. + +Twig can be extended in many ways; you can add extra tags, filters, tests, +operators, global variables, and functions. You can even extend the parser +itself with node visitors. + +.. note:: + + The first section of this chapter describes how to extend Twig easily. If + you want to reuse your changes in different projects or if you want to + share them with others, you should then create an extension as described + in the following section. + +.. caution:: + + When extending Twig without creating an extension, Twig won't be able to + recompile your templates when the PHP code is updated. To see your changes + in real-time, either disable template caching or package your code into an + extension (see the next section of this chapter). + +Before extending Twig, you must understand the differences between all the +different possible extension points and when to use them. + +First, remember that Twig has two main language constructs: + +* ``{{ }}``: used to print the result of an expression evaluation; + +* ``{% %}``: used to execute statements. + +To understand why Twig exposes so many extension points, let's see how to +implement a *Lorem ipsum* generator (it needs to know the number of words to +generate). + +You can use a ``lipsum`` *tag*: + +.. code-block:: jinja + + {% lipsum 40 %} + +That works, but using a tag for ``lipsum`` is not a good idea for at least +three main reasons: + +* ``lipsum`` is not a language construct; +* The tag outputs something; +* The tag is not flexible as you cannot use it in an expression: + + .. code-block:: jinja + + {{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }} + +In fact, you rarely need to create tags; and that's good news because tags are +the most complex extension point of Twig. + +Now, let's use a ``lipsum`` *filter*: + +.. code-block:: jinja + + {{ 40|lipsum }} + +Again, it works, but it looks weird. A filter transforms the passed value to +something else but here we use the value to indicate the number of words to +generate (so, ``40`` is an argument of the filter, not the value we want to +transform). + +Next, let's use a ``lipsum`` *function*: + +.. code-block:: jinja + + {{ lipsum(40) }} + +Here we go. For this specific example, the creation of a function is the +extension point to use. And you can use it anywhere an expression is accepted: + +.. code-block:: jinja + + {{ 'some text' ~ lipsum(40) ~ 'some more text' }} + + {% set lipsum = lipsum(40) %} + +Last but not the least, you can also use a *global* object with a method able +to generate lorem ipsum text: + +.. code-block:: jinja + + {{ text.lipsum(40) }} + +As a rule of thumb, use functions for frequently used features and global +objects for everything else. + +Keep in mind the following when you want to extend Twig: + +========== ========================== ========== ========================= +What? Implementation difficulty? How often? When? +========== ========================== ========== ========================= +*macro* trivial frequent Content generation +*global* trivial frequent Helper object +*function* trivial frequent Content generation +*filter* trivial frequent Value transformation +*tag* complex rare DSL language construct +*test* trivial rare Boolean decision +*operator* trivial rare Values transformation +========== ========================== ========== ========================= + +Globals +------- + +A global variable is like any other template variable, except that it's +available in all templates and macros:: + + $twig = new Twig_Environment($loader); + $twig->addGlobal('text', new Text()); + +You can then use the ``text`` variable anywhere in a template: + +.. code-block:: jinja + + {{ text.lipsum(40) }} + +Filters +------- + +Creating a filter is as simple as associating a name with a PHP callable:: + + // an anonymous function + $filter = new Twig_SimpleFilter('rot13', function ($string) { + return str_rot13($string); + }); + + // or a simple PHP function + $filter = new Twig_SimpleFilter('rot13', 'str_rot13'); + + // or a class method + $filter = new Twig_SimpleFilter('rot13', array('SomeClass', 'rot13Filter')); + +The first argument passed to the ``Twig_SimpleFilter`` constructor is the name +of the filter you will use in templates and the second one is the PHP callable +to associate with it. + +Then, add the filter to your Twig environment:: + + $twig = new Twig_Environment($loader); + $twig->addFilter($filter); + +And here is how to use it in a template: + +.. code-block:: jinja + + {{ 'Twig'|rot13 }} + + {# will output Gjvt #} + +When called by Twig, the PHP callable receives the left side of the filter +(before the pipe ``|``) as the first argument and the extra arguments passed +to the filter (within parentheses ``()``) as extra arguments. + +For instance, the following code: + +.. code-block:: jinja + + {{ 'TWIG'|lower }} + {{ now|date('d/m/Y') }} + +is compiled to something like the following:: + + + + +The ``Twig_SimpleFilter`` class takes an array of options as its last +argument:: + + $filter = new Twig_SimpleFilter('rot13', 'str_rot13', $options); + +Environment-aware Filters +~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you want to access the current environment instance in your filter, set the +``needs_environment`` option to ``true``; Twig will pass the current +environment as the first argument to the filter call:: + + $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $string) { + // get the current charset for instance + $charset = $env->getCharset(); + + return str_rot13($string); + }, array('needs_environment' => true)); + +Context-aware Filters +~~~~~~~~~~~~~~~~~~~~~ + +If you want to access the current context in your filter, set the +``needs_context`` option to ``true``; Twig will pass the current context as +the first argument to the filter call (or the second one if +``needs_environment`` is also set to ``true``):: + + $filter = new Twig_SimpleFilter('rot13', function ($context, $string) { + // ... + }, array('needs_context' => true)); + + $filter = new Twig_SimpleFilter('rot13', function (Twig_Environment $env, $context, $string) { + // ... + }, array('needs_context' => true, 'needs_environment' => true)); + +Automatic Escaping +~~~~~~~~~~~~~~~~~~ + +If automatic escaping is enabled, the output of the filter may be escaped +before printing. If your filter acts as an escaper (or explicitly outputs HTML +or JavaScript code), you will want the raw output to be printed. In such a +case, set the ``is_safe`` option:: + + $filter = new Twig_SimpleFilter('nl2br', 'nl2br', array('is_safe' => array('html'))); + +Some filters may need to work on input that is already escaped or safe, for +example when adding (safe) HTML tags to originally unsafe output. In such a +case, set the ``pre_escape`` option to escape the input data before it is run +through your filter:: + + $filter = new Twig_SimpleFilter('somefilter', 'somefilter', array('pre_escape' => 'html', 'is_safe' => array('html'))); + +Dynamic Filters +~~~~~~~~~~~~~~~ + +A filter name containing the special ``*`` character is a dynamic filter as +the ``*`` can be any string:: + + $filter = new Twig_SimpleFilter('*_path', function ($name, $arguments) { + // ... + }); + +The following filters will be matched by the above defined dynamic filter: + +* ``product_path`` +* ``category_path`` + +A dynamic filter can define more than one dynamic parts:: + + $filter = new Twig_SimpleFilter('*_path_*', function ($name, $suffix, $arguments) { + // ... + }); + +The filter will receive all dynamic part values before the normal filter +arguments, but after the environment and the context. For instance, a call to +``'foo'|a_path_b()`` will result in the following arguments to be passed to +the filter: ``('a', 'b', 'foo')``. + +Functions +--------- + +Functions are defined in the exact same way as filters, but you need to create +an instance of ``Twig_SimpleFunction``:: + + $twig = new Twig_Environment($loader); + $function = new Twig_SimpleFunction('function_name', function () { + // ... + }); + $twig->addFunction($function); + +Functions support the same features as filters, except for the ``pre_escape`` +and ``preserves_safety`` options. + +Tests +----- + +Tests are defined in the exact same way as filters and functions, but you need +to create an instance of ``Twig_SimpleTest``:: + + $twig = new Twig_Environment($loader); + $test = new Twig_SimpleTest('test_name', function () { + // ... + }); + $twig->addTest($test); + +Tests allow you to create custom application specific logic for evaluating +boolean conditions. As a simple example, let's create a Twig test that checks if +objects are 'red':: + + $twig = new Twig_Environment($loader); + $test = new Twig_SimpleTest('red', function ($value) { + if (isset($value->color) && $value->color == 'red') { + return true; + } + if (isset($value->paint) && $value->paint == 'red') { + return true; + } + return false; + }); + $twig->addTest($test); + +Test functions should always return true/false. + +When creating tests you can use the ``node_class`` option to provide custom test +compilation. This is useful if your test can be compiled into PHP primitives. +This is used by many of the tests built into Twig:: + + $twig = new Twig_Environment($loader); + $test = new Twig_SimpleTest( + 'odd', + null, + array('node_class' => 'Twig_Node_Expression_Test_Odd')); + $twig->addTest($test); + + 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(')') + ; + } + } + +The above example shows how you can create tests that use a node class. The +node class has access to one sub-node called 'node'. This sub-node contains the +value that is being tested. When the ``odd`` filter is used in code such as: + +.. code-block:: jinja + + {% if my_value is odd %} + +The ``node`` sub-node will contain an expression of ``my_value``. Node-based +tests also have access to the ``arguments`` node. This node will contain the +various other arguments that have been provided to your test. + +Tags +---- + +One of the most exciting features of a template engine like Twig is the +possibility to define new language constructs. This is also the most complex +feature as you need to understand how Twig's internals work. + +Let's create a simple ``set`` tag that allows the definition of simple +variables from within a template. The tag can be used like follows: + +.. code-block:: jinja + + {% set name = "value" %} + + {{ name }} + + {# should output value #} + +.. note:: + + The ``set`` tag is part of the Core extension and as such is always + available. The built-in version is slightly more powerful and supports + multiple assignments by default (cf. the template designers chapter for + more information). + +Three steps are needed to define a new tag: + +* Defining a Token Parser class (responsible for parsing the template code); + +* Defining a Node class (responsible for converting the parsed code to PHP); + +* Registering the tag. + +Registering a new tag +~~~~~~~~~~~~~~~~~~~~~ + +Adding a tag is as simple as calling the ``addTokenParser`` method on the +``Twig_Environment`` instance:: + + $twig = new Twig_Environment($loader); + $twig->addTokenParser(new Project_Set_TokenParser()); + +Defining a Token Parser +~~~~~~~~~~~~~~~~~~~~~~~ + +Now, let's see the actual code of this class:: + + class Project_Set_TokenParser extends Twig_TokenParser + { + public function parse(Twig_Token $token) + { + $parser = $this->parser; + $stream = $parser->getStream(); + + $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $stream->expect(Twig_Token::OPERATOR_TYPE, '='); + $value = $parser->getExpressionParser()->parseExpression(); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new Project_Set_Node($name, $value, $token->getLine(), $this->getTag()); + } + + public function getTag() + { + return 'set'; + } + } + +The ``getTag()`` method must return the tag we want to parse, here ``set``. + +The ``parse()`` method is invoked whenever the parser encounters a ``set`` +tag. It should return a ``Twig_Node`` instance that represents the node (the +``Project_Set_Node`` calls creating is explained in the next section). + +The parsing process is simplified thanks to a bunch of methods you can call +from the token stream (``$this->parser->getStream()``): + +* ``getCurrent()``: Gets the current token in the stream. + +* ``next()``: Moves to the next token in the stream, *but returns the old one*. + +* ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether + the current token is of a particular type or value (or both). The value may be an + array of several possible values. + +* ``expect($type[, $value[, $message]])``: If the current token isn't of the given + type/value a syntax error is thrown. Otherwise, if the type and value are correct, + the token is returned and the stream moves to the next token. + +* ``look()``: Looks a the next token without consuming it. + +Parsing expressions is done by calling the ``parseExpression()`` like we did for +the ``set`` tag. + +.. tip:: + + Reading the existing ``TokenParser`` classes is the best way to learn all + the nitty-gritty details of the parsing process. + +Defining a Node +~~~~~~~~~~~~~~~ + +The ``Project_Set_Node`` class itself is rather simple:: + + class Project_Set_Node extends Twig_Node + { + public function __construct($name, Twig_Node_Expression $value, $line, $tag = null) + { + parent::__construct(array('value' => $value), array('name' => $name), $line, $tag); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('$context[\''.$this->getAttribute('name').'\'] = ') + ->subcompile($this->getNode('value')) + ->raw(";\n") + ; + } + } + +The compiler implements a fluid interface and provides methods that helps the +developer generate beautiful and readable PHP code: + +* ``subcompile()``: Compiles a node. + +* ``raw()``: Writes the given string as is. + +* ``write()``: Writes the given string by adding indentation at the beginning + of each line. + +* ``string()``: Writes a quoted string. + +* ``repr()``: Writes a PHP representation of a given value (see + ``Twig_Node_For`` for a usage example). + +* ``addDebugInfo()``: Adds the line of the original template file related to + the current node as a comment. + +* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a + usage example). + +* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a + usage example). + +.. _creating_extensions: + +Creating an Extension +--------------------- + +The main motivation for writing an extension is to move often used code into a +reusable class like adding support for internationalization. An extension can +define tags, filters, tests, operators, global variables, functions, and node +visitors. + +Creating an extension also makes for a better separation of code that is +executed at compilation time and code needed at runtime. As such, it makes +your code faster. + +Most of the time, it is useful to create a single extension for your project, +to host all the specific tags and filters you want to add to Twig. + +.. tip:: + + When packaging your code into an extension, Twig is smart enough to + recompile your templates whenever you make a change to it (when + ``auto_reload`` is enabled). + +.. note:: + + Before writing your own extensions, have a look at the Twig official + extension repository: http://github.com/twigphp/Twig-extensions. + +An extension is a class that implements the following interface:: + + interface Twig_ExtensionInterface + { + /** + * 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 + */ + function initRuntime(Twig_Environment $environment); + + /** + * Returns the token parser instances to add to the existing list. + * + * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + */ + function getTokenParsers(); + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return array An array of Twig_NodeVisitorInterface instances + */ + function getNodeVisitors(); + + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + function getFilters(); + + /** + * Returns a list of tests to add to the existing list. + * + * @return array An array of tests + */ + function getTests(); + + /** + * Returns a list of functions to add to the existing list. + * + * @return array An array of functions + */ + function getFunctions(); + + /** + * Returns a list of operators to add to the existing list. + * + * @return array An array of operators + */ + function getOperators(); + + /** + * Returns a list of global variables to add to the existing list. + * + * @return array An array of global variables + */ + function getGlobals(); + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + function getName(); + } + +To keep your extension class clean and lean, it can inherit from the built-in +``Twig_Extension`` class instead of implementing the whole interface. That +way, you just need to implement the ``getName()`` method as the +``Twig_Extension`` provides empty implementations for all other methods. + +The ``getName()`` method must return a unique identifier for your extension. + +Now, with this information in mind, let's create the most basic extension +possible:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getName() + { + return 'project'; + } + } + +.. note:: + + Of course, this extension does nothing for now. We will customize it in + the next sections. + +Twig does not care where you save your extension on the filesystem, as all +extensions must be registered explicitly to be available in your templates. + +You can register an extension by using the ``addExtension()`` method on your +main ``Environment`` object:: + + $twig = new Twig_Environment($loader); + $twig->addExtension(new Project_Twig_Extension()); + +Of course, you need to first load the extension file by either using +``require_once()`` or by using an autoloader (see `spl_autoload_register()`_). + +.. tip:: + + The bundled extensions are great examples of how extensions work. + +Globals +~~~~~~~ + +Global variables can be registered in an extension via the ``getGlobals()`` +method:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getGlobals() + { + return array( + 'text' => new Text(), + ); + } + + // ... + } + +Functions +~~~~~~~~~ + +Functions can be registered in an extension via the ``getFunctions()`` +method:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getFunctions() + { + return array( + new Twig_SimpleFunction('lipsum', 'generate_lipsum'), + ); + } + + // ... + } + +Filters +~~~~~~~ + +To add a filter to an extension, you need to override the ``getFilters()`` +method. This method must return an array of filters to add to the Twig +environment:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getFilters() + { + return array( + new Twig_SimpleFilter('rot13', 'str_rot13'), + ); + } + + // ... + } + +Tags +~~~~ + +Adding a tag in an extension can be done by overriding the +``getTokenParsers()`` method. This method must return an array of tags to add +to the Twig environment:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getTokenParsers() + { + return array(new Project_Set_TokenParser()); + } + + // ... + } + +In the above code, we have added a single new tag, defined by the +``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is +responsible for parsing the tag and compiling it to PHP. + +Operators +~~~~~~~~~ + +The ``getOperators()`` methods lets you add new operators. Here is how to add +``!``, ``||``, and ``&&`` operators:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getOperators() + { + return array( + array( + '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), + ), + array( + '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + ), + ); + } + + // ... + } + +Tests +~~~~~ + +The ``getTests()`` method lets you add new test functions:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getTests() + { + return array( + new Twig_SimpleTest('even', 'twig_test_even'), + ); + } + + // ... + } + +Overloading +----------- + +To overload an already defined filter, test, operator, global variable, or +function, re-define it in an extension and register it **as late as +possible** (order matters):: + + class MyCoreExtension extends Twig_Extension + { + public function getFilters() + { + return array( + new Twig_SimpleFilter('date', array($this, 'dateFilter')), + ); + } + + public function dateFilter($timestamp, $format = 'F j, Y H:i') + { + // do something different from the built-in date filter + } + + public function getName() + { + return 'project'; + } + } + + $twig = new Twig_Environment($loader); + $twig->addExtension(new MyCoreExtension()); + +Here, we have overloaded the built-in ``date`` filter with a custom one. + +If you do the same on the Twig_Environment itself, beware that it takes +precedence over any other registered extensions:: + + $twig = new Twig_Environment($loader); + $twig->addFilter(new Twig_SimpleFilter('date', function ($timestamp, $format = 'F j, Y H:i') { + // do something different from the built-in date filter + })); + // the date filter will come from the above registration, not + // from the registered extension below + $twig->addExtension(new MyCoreExtension()); + +.. caution:: + + Note that overloading the built-in Twig elements is not recommended as it + might be confusing. + +Testing an Extension +-------------------- + +Functional Tests +~~~~~~~~~~~~~~~~ + +You can create functional tests for extensions simply by creating the +following file structure in your test directory:: + + Fixtures/ + filters/ + foo.test + bar.test + functions/ + foo.test + bar.test + tags/ + foo.test + bar.test + IntegrationTest.php + +The ``IntegrationTest.php`` file should look like this:: + + class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase + { + public function getExtensions() + { + return array( + new Project_Twig_Extension1(), + new Project_Twig_Extension2(), + ); + } + + public function getFixturesDir() + { + return dirname(__FILE__).'/Fixtures/'; + } + } + +Fixtures examples can be found within the Twig repository +`tests/Twig/Fixtures`_ directory. + +Node Tests +~~~~~~~~~~ + +Testing the node visitors can be complex, so extend your test cases from +``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository +`tests/Twig/Node`_ directory. + +.. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register +.. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php +.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures +.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node diff --git a/vendor/twig/twig/doc/advanced_legacy.rst b/vendor/twig/twig/doc/advanced_legacy.rst new file mode 100755 index 0000000..2ef6bfd --- /dev/null +++ b/vendor/twig/twig/doc/advanced_legacy.rst @@ -0,0 +1,887 @@ +Extending Twig +============== + +.. caution:: + + This section describes how to extends Twig for versions **older than + 1.12**. If you are using a newer version, read the :doc:`newer` + chapter instead. + +Twig can be extended in many ways; you can add extra tags, filters, tests, +operators, global variables, and functions. You can even extend the parser +itself with node visitors. + +.. note:: + + The first section of this chapter describes how to extend Twig easily. If + you want to reuse your changes in different projects or if you want to + share them with others, you should then create an extension as described + in the following section. + +.. caution:: + + When extending Twig by calling methods on the Twig environment instance, + Twig won't be able to recompile your templates when the PHP code is + updated. To see your changes in real-time, either disable template caching + or package your code into an extension (see the next section of this + chapter). + +Before extending Twig, you must understand the differences between all the +different possible extension points and when to use them. + +First, remember that Twig has two main language constructs: + +* ``{{ }}``: used to print the result of an expression evaluation; + +* ``{% %}``: used to execute statements. + +To understand why Twig exposes so many extension points, let's see how to +implement a *Lorem ipsum* generator (it needs to know the number of words to +generate). + +You can use a ``lipsum`` *tag*: + +.. code-block:: jinja + + {% lipsum 40 %} + +That works, but using a tag for ``lipsum`` is not a good idea for at least +three main reasons: + +* ``lipsum`` is not a language construct; +* The tag outputs something; +* The tag is not flexible as you cannot use it in an expression: + + .. code-block:: jinja + + {{ 'some text' ~ {% lipsum 40 %} ~ 'some more text' }} + +In fact, you rarely need to create tags; and that's good news because tags are +the most complex extension point of Twig. + +Now, let's use a ``lipsum`` *filter*: + +.. code-block:: jinja + + {{ 40|lipsum }} + +Again, it works, but it looks weird. A filter transforms the passed value to +something else but here we use the value to indicate the number of words to +generate (so, ``40`` is an argument of the filter, not the value we want to +transform). + +Next, let's use a ``lipsum`` *function*: + +.. code-block:: jinja + + {{ lipsum(40) }} + +Here we go. For this specific example, the creation of a function is the +extension point to use. And you can use it anywhere an expression is accepted: + +.. code-block:: jinja + + {{ 'some text' ~ ipsum(40) ~ 'some more text' }} + + {% set ipsum = ipsum(40) %} + +Last but not the least, you can also use a *global* object with a method able +to generate lorem ipsum text: + +.. code-block:: jinja + + {{ text.lipsum(40) }} + +As a rule of thumb, use functions for frequently used features and global +objects for everything else. + +Keep in mind the following when you want to extend Twig: + +========== ========================== ========== ========================= +What? Implementation difficulty? How often? When? +========== ========================== ========== ========================= +*macro* trivial frequent Content generation +*global* trivial frequent Helper object +*function* trivial frequent Content generation +*filter* trivial frequent Value transformation +*tag* complex rare DSL language construct +*test* trivial rare Boolean decision +*operator* trivial rare Values transformation +========== ========================== ========== ========================= + +Globals +------- + +A global variable is like any other template variable, except that it's +available in all templates and macros:: + + $twig = new Twig_Environment($loader); + $twig->addGlobal('text', new Text()); + +You can then use the ``text`` variable anywhere in a template: + +.. code-block:: jinja + + {{ text.lipsum(40) }} + +Filters +------- + +A filter is a regular PHP function or an object method that takes the left +side of the filter (before the pipe ``|``) as first argument and the extra +arguments passed to the filter (within parentheses ``()``) as extra arguments. + +Defining a filter is as easy as associating the filter name with a PHP +callable. For instance, let's say you have the following code in a template: + +.. code-block:: jinja + + {{ 'TWIG'|lower }} + +When compiling this template to PHP, Twig looks for the PHP callable +associated with the ``lower`` filter. The ``lower`` filter is a built-in Twig +filter, and it is simply mapped to the PHP ``strtolower()`` function. After +compilation, the generated PHP code is roughly equivalent to: + +.. code-block:: html+php + + + +As you can see, the ``'TWIG'`` string is passed as a first argument to the PHP +function. + +A filter can also take extra arguments like in the following example: + +.. code-block:: jinja + + {{ now|date('d/m/Y') }} + +In this case, the extra arguments are passed to the function after the main +argument, and the compiled code is equivalent to: + +.. code-block:: html+php + + + +Let's see how to create a new filter. + +In this section, we will create a ``rot13`` filter, which should return the +`rot13`_ transformation of a string. Here is an example of its usage and the +expected output: + +.. code-block:: jinja + + {{ "Twig"|rot13 }} + + {# should displays Gjvt #} + +Adding a filter is as simple as calling the ``addFilter()`` method on the +``Twig_Environment`` instance:: + + $twig = new Twig_Environment($loader); + $twig->addFilter('rot13', new Twig_Filter_Function('str_rot13')); + +The second argument of ``addFilter()`` is an instance of ``Twig_Filter``. +Here, we use ``Twig_Filter_Function`` as the filter is a PHP function. The +first argument passed to the ``Twig_Filter_Function`` constructor is the name +of the PHP function to call, here ``str_rot13``, a native PHP function. + +Let's say I now want to be able to add a prefix before the converted string: + +.. code-block:: jinja + + {{ "Twig"|rot13('prefix_') }} + + {# should displays prefix_Gjvt #} + +As the PHP ``str_rot13()`` function does not support this requirement, let's +create a new PHP function:: + + function project_compute_rot13($string, $prefix = '') + { + return $prefix.str_rot13($string); + } + +As you can see, the ``prefix`` argument of the filter is passed as an extra +argument to the ``project_compute_rot13()`` function. + +Adding this filter is as easy as before:: + + $twig->addFilter('rot13', new Twig_Filter_Function('project_compute_rot13')); + +For better encapsulation, a filter can also be defined as a static method of a +class. The ``Twig_Filter_Function`` class can also be used to register such +static methods as filters:: + + $twig->addFilter('rot13', new Twig_Filter_Function('SomeClass::rot13Filter')); + +.. tip:: + + In an extension, you can also define a filter as a static method of the + extension class. + +Environment aware Filters +~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``Twig_Filter`` classes take options as their last argument. For instance, +if you want access to the current environment instance in your filter, set the +``needs_environment`` option to ``true``:: + + $filter = new Twig_Filter_Function('str_rot13', array('needs_environment' => true)); + +Twig will then pass the current environment as the first argument to the +filter call:: + + function twig_compute_rot13(Twig_Environment $env, $string) + { + // get the current charset for instance + $charset = $env->getCharset(); + + return str_rot13($string); + } + +Automatic Escaping +~~~~~~~~~~~~~~~~~~ + +If automatic escaping is enabled, the output of the filter may be escaped +before printing. If your filter acts as an escaper (or explicitly outputs HTML +or JavaScript code), you will want the raw output to be printed. In such a +case, set the ``is_safe`` option:: + + $filter = new Twig_Filter_Function('nl2br', array('is_safe' => array('html'))); + +Some filters may need to work on input that is already escaped or safe, for +example when adding (safe) HTML tags to originally unsafe output. In such a +case, set the ``pre_escape`` option to escape the input data before it is run +through your filter:: + + $filter = new Twig_Filter_Function('somefilter', array('pre_escape' => 'html', 'is_safe' => array('html'))); + +Dynamic Filters +~~~~~~~~~~~~~~~ + +.. versionadded:: 1.5 + Dynamic filters support was added in Twig 1.5. + +A filter name containing the special ``*`` character is a dynamic filter as +the ``*`` can be any string:: + + $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); + + function twig_path($name, $arguments) + { + // ... + } + +The following filters will be matched by the above defined dynamic filter: + +* ``product_path`` +* ``category_path`` + +A dynamic filter can define more than one dynamic parts:: + + $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); + + function twig_path($name, $suffix, $arguments) + { + // ... + } + +The filter will receive all dynamic part values before the normal filters +arguments. For instance, a call to ``'foo'|a_path_b()`` will result in the +following PHP call: ``twig_path('a', 'b', 'foo')``. + +Functions +--------- + +A function is a regular PHP function or an object method that can be called from +templates. + +.. code-block:: jinja + + {{ constant("DATE_W3C") }} + +When compiling this template to PHP, Twig looks for the PHP callable +associated with the ``constant`` function. The ``constant`` function is a built-in Twig +function, and it is simply mapped to the PHP ``constant()`` function. After +compilation, the generated PHP code is roughly equivalent to: + +.. code-block:: html+php + + + +Adding a function is similar to adding a filter. This can be done by calling the +``addFunction()`` method on the ``Twig_Environment`` instance:: + + $twig = new Twig_Environment($loader); + $twig->addFunction('functionName', new Twig_Function_Function('someFunction')); + +You can also expose extension methods as functions in your templates:: + + // $this is an object that implements Twig_ExtensionInterface. + $twig = new Twig_Environment($loader); + $twig->addFunction('otherFunction', new Twig_Function_Method($this, 'someMethod')); + +Functions also support ``needs_environment`` and ``is_safe`` parameters. + +Dynamic Functions +~~~~~~~~~~~~~~~~~ + +.. versionadded:: 1.5 + Dynamic functions support was added in Twig 1.5. + +A function name containing the special ``*`` character is a dynamic function +as the ``*`` can be any string:: + + $twig->addFunction('*_path', new Twig_Function_Function('twig_path')); + + function twig_path($name, $arguments) + { + // ... + } + +The following functions will be matched by the above defined dynamic function: + +* ``product_path`` +* ``category_path`` + +A dynamic function can define more than one dynamic parts:: + + $twig->addFilter('*_path_*', new Twig_Filter_Function('twig_path')); + + function twig_path($name, $suffix, $arguments) + { + // ... + } + +The function will receive all dynamic part values before the normal functions +arguments. For instance, a call to ``a_path_b('foo')`` will result in the +following PHP call: ``twig_path('a', 'b', 'foo')``. + +Tags +---- + +One of the most exciting feature of a template engine like Twig is the +possibility to define new language constructs. This is also the most complex +feature as you need to understand how Twig's internals work. + +Let's create a simple ``set`` tag that allows the definition of simple +variables from within a template. The tag can be used like follows: + +.. code-block:: jinja + + {% set name = "value" %} + + {{ name }} + + {# should output value #} + +.. note:: + + The ``set`` tag is part of the Core extension and as such is always + available. The built-in version is slightly more powerful and supports + multiple assignments by default (cf. the template designers chapter for + more information). + +Three steps are needed to define a new tag: + +* Defining a Token Parser class (responsible for parsing the template code); + +* Defining a Node class (responsible for converting the parsed code to PHP); + +* Registering the tag. + +Registering a new tag +~~~~~~~~~~~~~~~~~~~~~ + +Adding a tag is as simple as calling the ``addTokenParser`` method on the +``Twig_Environment`` instance:: + + $twig = new Twig_Environment($loader); + $twig->addTokenParser(new Project_Set_TokenParser()); + +Defining a Token Parser +~~~~~~~~~~~~~~~~~~~~~~~ + +Now, let's see the actual code of this class:: + + class Project_Set_TokenParser extends Twig_TokenParser + { + public function parse(Twig_Token $token) + { + $lineno = $token->getLine(); + $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); + $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, '='); + $value = $this->parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + + return new Project_Set_Node($name, $value, $lineno, $this->getTag()); + } + + public function getTag() + { + return 'set'; + } + } + +The ``getTag()`` method must return the tag we want to parse, here ``set``. + +The ``parse()`` method is invoked whenever the parser encounters a ``set`` +tag. It should return a ``Twig_Node`` instance that represents the node (the +``Project_Set_Node`` calls creating is explained in the next section). + +The parsing process is simplified thanks to a bunch of methods you can call +from the token stream (``$this->parser->getStream()``): + +* ``getCurrent()``: Gets the current token in the stream. + +* ``next()``: Moves to the next token in the stream, *but returns the old one*. + +* ``test($type)``, ``test($value)`` or ``test($type, $value)``: Determines whether + the current token is of a particular type or value (or both). The value may be an + array of several possible values. + +* ``expect($type[, $value[, $message]])``: If the current token isn't of the given + type/value a syntax error is thrown. Otherwise, if the type and value are correct, + the token is returned and the stream moves to the next token. + +* ``look()``: Looks a the next token without consuming it. + +Parsing expressions is done by calling the ``parseExpression()`` like we did for +the ``set`` tag. + +.. tip:: + + Reading the existing ``TokenParser`` classes is the best way to learn all + the nitty-gritty details of the parsing process. + +Defining a Node +~~~~~~~~~~~~~~~ + +The ``Project_Set_Node`` class itself is rather simple:: + + class Project_Set_Node extends Twig_Node + { + public function __construct($name, Twig_Node_Expression $value, $lineno, $tag = null) + { + parent::__construct(array('value' => $value), array('name' => $name), $lineno, $tag); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('$context[\''.$this->getAttribute('name').'\'] = ') + ->subcompile($this->getNode('value')) + ->raw(";\n") + ; + } + } + +The compiler implements a fluid interface and provides methods that helps the +developer generate beautiful and readable PHP code: + +* ``subcompile()``: Compiles a node. + +* ``raw()``: Writes the given string as is. + +* ``write()``: Writes the given string by adding indentation at the beginning + of each line. + +* ``string()``: Writes a quoted string. + +* ``repr()``: Writes a PHP representation of a given value (see + ``Twig_Node_For`` for a usage example). + +* ``addDebugInfo()``: Adds the line of the original template file related to + the current node as a comment. + +* ``indent()``: Indents the generated code (see ``Twig_Node_Block`` for a + usage example). + +* ``outdent()``: Outdents the generated code (see ``Twig_Node_Block`` for a + usage example). + +.. _creating_extensions: + +Creating an Extension +--------------------- + +The main motivation for writing an extension is to move often used code into a +reusable class like adding support for internationalization. An extension can +define tags, filters, tests, operators, global variables, functions, and node +visitors. + +Creating an extension also makes for a better separation of code that is +executed at compilation time and code needed at runtime. As such, it makes +your code faster. + +Most of the time, it is useful to create a single extension for your project, +to host all the specific tags and filters you want to add to Twig. + +.. tip:: + + When packaging your code into an extension, Twig is smart enough to + recompile your templates whenever you make a change to it (when the + ``auto_reload`` is enabled). + +.. note:: + + Before writing your own extensions, have a look at the Twig official + extension repository: http://github.com/twigphp/Twig-extensions. + +An extension is a class that implements the following interface:: + + interface Twig_ExtensionInterface + { + /** + * 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 + */ + function initRuntime(Twig_Environment $environment); + + /** + * Returns the token parser instances to add to the existing list. + * + * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + */ + function getTokenParsers(); + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return array An array of Twig_NodeVisitorInterface instances + */ + function getNodeVisitors(); + + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + function getFilters(); + + /** + * Returns a list of tests to add to the existing list. + * + * @return array An array of tests + */ + function getTests(); + + /** + * Returns a list of functions to add to the existing list. + * + * @return array An array of functions + */ + function getFunctions(); + + /** + * Returns a list of operators to add to the existing list. + * + * @return array An array of operators + */ + function getOperators(); + + /** + * Returns a list of global variables to add to the existing list. + * + * @return array An array of global variables + */ + function getGlobals(); + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + function getName(); + } + +To keep your extension class clean and lean, it can inherit from the built-in +``Twig_Extension`` class instead of implementing the whole interface. That +way, you just need to implement the ``getName()`` method as the +``Twig_Extension`` provides empty implementations for all other methods. + +The ``getName()`` method must return a unique identifier for your extension. + +Now, with this information in mind, let's create the most basic extension +possible:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getName() + { + return 'project'; + } + } + +.. note:: + + Of course, this extension does nothing for now. We will customize it in + the next sections. + +Twig does not care where you save your extension on the filesystem, as all +extensions must be registered explicitly to be available in your templates. + +You can register an extension by using the ``addExtension()`` method on your +main ``Environment`` object:: + + $twig = new Twig_Environment($loader); + $twig->addExtension(new Project_Twig_Extension()); + +Of course, you need to first load the extension file by either using +``require_once()`` or by using an autoloader (see `spl_autoload_register()`_). + +.. tip:: + + The bundled extensions are great examples of how extensions work. + +Globals +~~~~~~~ + +Global variables can be registered in an extension via the ``getGlobals()`` +method:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getGlobals() + { + return array( + 'text' => new Text(), + ); + } + + // ... + } + +Functions +~~~~~~~~~ + +Functions can be registered in an extension via the ``getFunctions()`` +method:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getFunctions() + { + return array( + 'lipsum' => new Twig_Function_Function('generate_lipsum'), + ); + } + + // ... + } + +Filters +~~~~~~~ + +To add a filter to an extension, you need to override the ``getFilters()`` +method. This method must return an array of filters to add to the Twig +environment:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getFilters() + { + return array( + 'rot13' => new Twig_Filter_Function('str_rot13'), + ); + } + + // ... + } + +As you can see in the above code, the ``getFilters()`` method returns an array +where keys are the name of the filters (``rot13``) and the values the +definition of the filter (``new Twig_Filter_Function('str_rot13')``). + +As seen in the previous chapter, you can also define filters as static methods +on the extension class:: + +$twig->addFilter('rot13', new Twig_Filter_Function('Project_Twig_Extension::rot13Filter')); + +You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function`` +when defining a filter to use a method:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getFilters() + { + return array( + 'rot13' => new Twig_Filter_Method($this, 'rot13Filter'), + ); + } + + public function rot13Filter($string) + { + return str_rot13($string); + } + + // ... + } + +The first argument of the ``Twig_Filter_Method`` constructor is always +``$this``, the current extension object. The second one is the name of the +method to call. + +Using methods for filters is a great way to package your filter without +polluting the global namespace. This also gives the developer more flexibility +at the cost of a small overhead. + +Overriding default Filters +.......................... + +If some default core filters do not suit your needs, you can easily override +them by creating your own extension. Just use the same names as the one you +want to override:: + + class MyCoreExtension extends Twig_Extension + { + public function getFilters() + { + return array( + 'date' => new Twig_Filter_Method($this, 'dateFilter'), + // ... + ); + } + + public function dateFilter($timestamp, $format = 'F j, Y H:i') + { + return '...'.twig_date_format_filter($timestamp, $format); + } + + public function getName() + { + return 'project'; + } + } + +Here, we override the ``date`` filter with a custom one. Using this extension +is as simple as registering the ``MyCoreExtension`` extension by calling the +``addExtension()`` method on the environment instance:: + + $twig = new Twig_Environment($loader); + $twig->addExtension(new MyCoreExtension()); + +Tags +~~~~ + +Adding a tag in an extension can be done by overriding the +``getTokenParsers()`` method. This method must return an array of tags to add +to the Twig environment:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getTokenParsers() + { + return array(new Project_Set_TokenParser()); + } + + // ... + } + +In the above code, we have added a single new tag, defined by the +``Project_Set_TokenParser`` class. The ``Project_Set_TokenParser`` class is +responsible for parsing the tag and compiling it to PHP. + +Operators +~~~~~~~~~ + +The ``getOperators()`` methods allows to add new operators. Here is how to add +``!``, ``||``, and ``&&`` operators:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getOperators() + { + return array( + array( + '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), + ), + array( + '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + ), + ); + } + + // ... + } + +Tests +~~~~~ + +The ``getTests()`` methods allows to add new test functions:: + + class Project_Twig_Extension extends Twig_Extension + { + public function getTests() + { + return array( + 'even' => new Twig_Test_Function('twig_test_even'), + ); + } + + // ... + } + +Testing an Extension +-------------------- + +.. versionadded:: 1.10 + Support for functional tests was added in Twig 1.10. + +Functional Tests +~~~~~~~~~~~~~~~~ + +You can create functional tests for extensions simply by creating the +following file structure in your test directory:: + + Fixtures/ + filters/ + foo.test + bar.test + functions/ + foo.test + bar.test + tags/ + foo.test + bar.test + IntegrationTest.php + +The ``IntegrationTest.php`` file should look like this:: + + class Project_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase + { + public function getExtensions() + { + return array( + new Project_Twig_Extension1(), + new Project_Twig_Extension2(), + ); + } + + public function getFixturesDir() + { + return dirname(__FILE__).'/Fixtures/'; + } + } + +Fixtures examples can be found within the Twig repository +`tests/Twig/Fixtures`_ directory. + +Node Tests +~~~~~~~~~~ + +Testing the node visitors can be complex, so extend your test cases from +``Twig_Test_NodeTestCase``. Examples can be found in the Twig repository +`tests/Twig/Node`_ directory. + +.. _`spl_autoload_register()`: http://www.php.net/spl_autoload_register +.. _`rot13`: http://www.php.net/manual/en/function.str-rot13.php +.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Fixtures +.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/master/test/Twig/Tests/Node diff --git a/vendor/twig/twig/doc/api.rst b/vendor/twig/twig/doc/api.rst new file mode 100755 index 0000000..f367db0 --- /dev/null +++ b/vendor/twig/twig/doc/api.rst @@ -0,0 +1,552 @@ +Twig for Developers +=================== + +This chapter describes the API to Twig and not the template language. It will +be most useful as reference to those implementing the template interface to +the application and not those who are creating Twig templates. + +Basics +------ + +Twig uses a central object called the **environment** (of class +``Twig_Environment``). Instances of this class are used to store the +configuration and extensions, and are used to load templates from the file +system or other locations. + +Most applications will create one ``Twig_Environment`` object on application +initialization and use that to load templates. In some cases it's however +useful to have multiple environments side by side, if different configurations +are in use. + +The simplest way to configure Twig to load templates for your application +looks roughly like this:: + + require_once '/path/to/lib/Twig/Autoloader.php'; + Twig_Autoloader::register(); + + $loader = new Twig_Loader_Filesystem('/path/to/templates'); + $twig = new Twig_Environment($loader, array( + 'cache' => '/path/to/compilation_cache', + )); + +This will create a template environment with the default settings and a loader +that looks up the templates in the ``/path/to/templates/`` folder. Different +loaders are available and you can also write your own if you want to load +templates from a database or other resources. + +.. note:: + + Notice that the second argument of the environment is an array of options. + The ``cache`` option is a compilation cache directory, where Twig caches + the compiled templates to avoid the parsing phase for sub-sequent + requests. It is very different from the cache you might want to add for + the evaluated templates. For such a need, you can use any available PHP + cache library. + +To load a template from this environment you just have to call the +``loadTemplate()`` method which then returns a ``Twig_Template`` instance:: + + $template = $twig->loadTemplate('index.html'); + +To render the template with some variables, call the ``render()`` method:: + + echo $template->render(array('the' => 'variables', 'go' => 'here')); + +.. note:: + + The ``display()`` method is a shortcut to output the template directly. + +You can also load and render the template in one fell swoop:: + + echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here')); + +.. _environment_options: + +Environment Options +------------------- + +When creating a new ``Twig_Environment`` instance, you can pass an array of +options as the constructor second argument:: + + $twig = new Twig_Environment($loader, array('debug' => true)); + +The following options are available: + +* ``debug`` *boolean* + + When set to ``true``, the generated templates have a + ``__toString()`` method that you can use to display the generated nodes + (default to ``false``). + +* ``charset`` *string (default to ``utf-8``)* + + The charset used by the templates. + +* ``base_template_class`` *string (default to ``Twig_Template``)* + + The base template class to use for generated + templates. + +* ``cache`` *string|false* + + An absolute path where to store the compiled templates, or + ``false`` to disable caching (which is the default). + +* ``auto_reload`` *boolean* + + When developing with Twig, it's useful to recompile the + template whenever the source code changes. If you don't provide a value for + the ``auto_reload`` option, it will be determined automatically based on the + ``debug`` value. + +* ``strict_variables`` *boolean* + + If set to ``false``, Twig will silently ignore invalid + variables (variables and or attributes/methods that do not exist) and + replace them with a ``null`` value. When set to ``true``, Twig throws an + exception instead (default to ``false``). + +* ``autoescape`` *string|boolean* + + If set to ``true``, HTML auto-escaping will be enabled by + default for all templates (default to ``true``). + + As of Twig 1.8, you can set the escaping strategy to use (``html``, ``js``, + ``false`` to disable). + + As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``, + ``html_attr``, or a PHP callback that takes the template "filename" and must + return the escaping strategy to use -- the callback cannot be a function name + to avoid collision with built-in escaping strategies). + + As of Twig 1.17, the ``filename`` escaping strategy determines the escaping + strategy to use for a template based on the template filename extension (this + strategy does not incur any overhead at runtime as auto-escaping is done at + compilation time.) + +* ``optimizations`` *integer* + + A flag that indicates which optimizations to apply + (default to ``-1`` -- all optimizations are enabled; set it to ``0`` to + disable). + +Loaders +------- + +Loaders are responsible for loading templates from a resource such as the file +system. + +Compilation Cache +~~~~~~~~~~~~~~~~~ + +All template loaders can cache the compiled templates on the filesystem for +future reuse. It speeds up Twig a lot as templates are only compiled once; and +the performance boost is even larger if you use a PHP accelerator such as APC. +See the ``cache`` and ``auto_reload`` options of ``Twig_Environment`` above +for more information. + +Built-in Loaders +~~~~~~~~~~~~~~~~ + +Here is a list of the built-in loaders Twig provides: + +``Twig_Loader_Filesystem`` +.......................... + +.. versionadded:: 1.10 + The ``prependPath()`` and support for namespaces were added in Twig 1.10. + +``Twig_Loader_Filesystem`` loads templates from the file system. This loader +can find templates in folders on the file system and is the preferred way to +load them:: + + $loader = new Twig_Loader_Filesystem($templateDir); + +It can also look for templates in an array of directories:: + + $loader = new Twig_Loader_Filesystem(array($templateDir1, $templateDir2)); + +With such a configuration, Twig will first look for templates in +``$templateDir1`` and if they do not exist, it will fallback to look for them +in the ``$templateDir2``. + +You can add or prepend paths via the ``addPath()`` and ``prependPath()`` +methods:: + + $loader->addPath($templateDir3); + $loader->prependPath($templateDir4); + +The filesystem loader also supports namespaced templates. This allows to group +your templates under different namespaces which have their own template paths. + +When using the ``setPaths()``, ``addPath()``, and ``prependPath()`` methods, +specify the namespace as the second argument (when not specified, these +methods act on the "main" namespace):: + + $loader->addPath($templateDir, 'admin'); + +Namespaced templates can be accessed via the special +``@namespace_name/template_path`` notation:: + + $twig->render('@admin/index.html', array()); + +``Twig_Loader_Array`` +..................... + +``Twig_Loader_Array`` loads a template from a PHP array. It's passed an array +of strings bound to template names:: + + $loader = new Twig_Loader_Array(array( + 'index.html' => 'Hello {{ name }}!', + )); + $twig = new Twig_Environment($loader); + + echo $twig->render('index.html', array('name' => 'Fabien')); + +This loader is very useful for unit testing. It can also be used for small +projects where storing all templates in a single PHP file might make sense. + +.. tip:: + + When using the ``Array`` or ``String`` loaders with a cache mechanism, you + should know that a new cache key is generated each time a template content + "changes" (the cache key being the source code of the template). If you + don't want to see your cache grows out of control, you need to take care + of clearing the old cache file by yourself. + +``Twig_Loader_Chain`` +..................... + +``Twig_Loader_Chain`` delegates the loading of templates to other loaders:: + + $loader1 = new Twig_Loader_Array(array( + 'base.html' => '{% block content %}{% endblock %}', + )); + $loader2 = new Twig_Loader_Array(array( + 'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}', + 'base.html' => 'Will never be loaded', + )); + + $loader = new Twig_Loader_Chain(array($loader1, $loader2)); + + $twig = new Twig_Environment($loader); + +When looking for a template, Twig will try each loader in turn and it will +return as soon as the template is found. When rendering the ``index.html`` +template from the above example, Twig will load it with ``$loader2`` but the +``base.html`` template will be loaded from ``$loader1``. + +``Twig_Loader_Chain`` accepts any loader that implements +``Twig_LoaderInterface``. + +.. note:: + + You can also add loaders via the ``addLoader()`` method. + +Create your own Loader +~~~~~~~~~~~~~~~~~~~~~~ + +All loaders implement the ``Twig_LoaderInterface``:: + + interface Twig_LoaderInterface + { + /** + * Gets the source code of a template, given its name. + * + * @param string $name string The name of the template to load + * + * @return string The template source code + */ + function getSource($name); + + /** + * Gets the cache key to use for the cache for a given template name. + * + * @param string $name string The name of the template to load + * + * @return string The cache key + */ + function getCacheKey($name); + + /** + * Returns true if the template is still fresh. + * + * @param string $name The template name + * @param timestamp $time The last modification time of the cached template + */ + function isFresh($name, $time); + } + +The ``isFresh()`` method must return ``true`` if the current cached template +is still fresh, given the last modification time, or ``false`` otherwise. + +.. tip:: + + As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface`` + to make your loader faster when used with the chain loader. + +Using Extensions +---------------- + +Twig extensions are packages that add new features to Twig. Using an +extension is as simple as using the ``addExtension()`` method:: + + $twig->addExtension(new Twig_Extension_Sandbox()); + +Twig comes bundled with the following extensions: + +* *Twig_Extension_Core*: Defines all the core features of Twig. + +* *Twig_Extension_Escaper*: Adds automatic output-escaping and the possibility + to escape/unescape blocks of code. + +* *Twig_Extension_Sandbox*: Adds a sandbox mode to the default Twig + environment, making it safe to evaluate untrusted code. + +* *Twig_Extension_Profiler*: Enabled the built-in Twig profiler (as of Twig + 1.18). + +* *Twig_Extension_Optimizer*: Optimizes the node tree before compilation. + +The core, escaper, and optimizer extensions do not need to be added to the +Twig environment, as they are registered by default. + +Built-in Extensions +------------------- + +This section describes the features added by the built-in extensions. + +.. tip:: + + Read the chapter about extending Twig to learn how to create your own + extensions. + +Core Extension +~~~~~~~~~~~~~~ + +The ``core`` extension defines all the core features of Twig: + +* :doc:`Tags `; +* :doc:`Filters `; +* :doc:`Functions `; +* :doc:`Tests `. + +Escaper Extension +~~~~~~~~~~~~~~~~~ + +The ``escaper`` extension adds automatic output escaping to Twig. It defines a +tag, ``autoescape``, and a filter, ``raw``. + +When creating the escaper extension, you can switch on or off the global +output escaping strategy:: + + $escaper = new Twig_Extension_Escaper('html'); + $twig->addExtension($escaper); + +If set to ``html``, all variables in templates are escaped (using the ``html`` +escaping strategy), except those using the ``raw`` filter: + +.. code-block:: jinja + + {{ article.to_html|raw }} + +You can also change the escaping mode locally by using the ``autoescape`` tag +(see the :doc:`autoescape` doc for the syntax used before +Twig 1.8): + +.. code-block:: jinja + + {% autoescape 'html' %} + {{ var }} + {{ var|raw }} {# var won't be escaped #} + {{ var|escape }} {# var won't be double-escaped #} + {% endautoescape %} + +.. warning:: + + The ``autoescape`` tag has no effect on included files. + +The escaping rules are implemented as follows: + +* Literals (integers, booleans, arrays, ...) used in the template directly as + variables or filter arguments are never automatically escaped: + + .. code-block:: jinja + + {{ "Twig
" }} {# won't be escaped #} + + {% set text = "Twig
" %} + {{ text }} {# will be escaped #} + +* Expressions which the result is always a literal or a variable marked safe + are never automatically escaped: + + .. code-block:: jinja + + {{ foo ? "Twig
" : "
Twig" }} {# won't be escaped #} + + {% set text = "Twig
" %} + {{ foo ? text : "
Twig" }} {# will be escaped #} + + {% set text = "Twig
" %} + {{ foo ? text|raw : "
Twig" }} {# won't be escaped #} + + {% set text = "Twig
" %} + {{ foo ? text|escape : "
Twig" }} {# the result of the expression won't be escaped #} + +* Escaping is applied before printing, after any other filter is applied: + + .. code-block:: jinja + + {{ var|upper }} {# is equivalent to {{ var|upper|escape }} #} + +* The `raw` filter should only be used at the end of the filter chain: + + .. code-block:: jinja + + {{ var|raw|upper }} {# will be escaped #} + + {{ var|upper|raw }} {# won't be escaped #} + +* Automatic escaping is not applied if the last filter in the chain is marked + safe for the current context (e.g. ``html`` or ``js``). ``escape`` and + ``escape('html')`` are marked safe for HTML, ``escape('js')`` is marked + safe for JavaScript, ``raw`` is marked safe for everything. + + .. code-block:: jinja + + {% autoescape 'js' %} + {{ var|escape('html') }} {# will be escaped for HTML and JavaScript #} + {{ var }} {# will be escaped for JavaScript #} + {{ var|escape('js') }} {# won't be double-escaped #} + {% endautoescape %} + +.. note:: + + Note that autoescaping has some limitations as escaping is applied on + expressions after evaluation. For instance, when working with + concatenation, ``{{ foo|raw ~ bar }}`` won't give the expected result as + escaping is applied on the result of the concatenation, not on the + individual variables (so, the ``raw`` filter won't have any effect here). + +Sandbox Extension +~~~~~~~~~~~~~~~~~ + +The ``sandbox`` extension can be used to evaluate untrusted code. Access to +unsafe attributes and methods is prohibited. The sandbox security is managed +by a policy instance. By default, Twig comes with one policy class: +``Twig_Sandbox_SecurityPolicy``. This class allows you to white-list some +tags, filters, properties, and methods:: + + $tags = array('if'); + $filters = array('upper'); + $methods = array( + 'Article' => array('getTitle', 'getBody'), + ); + $properties = array( + 'Article' => array('title', 'body'), + ); + $functions = array('range'); + $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions); + +With the previous configuration, the security policy will only allow usage of +the ``if`` tag, and the ``upper`` filter. Moreover, the templates will only be +able to call the ``getTitle()`` and ``getBody()`` methods on ``Article`` +objects, and the ``title`` and ``body`` public properties. Everything else +won't be allowed and will generate a ``Twig_Sandbox_SecurityError`` exception. + +The policy object is the first argument of the sandbox constructor:: + + $sandbox = new Twig_Extension_Sandbox($policy); + $twig->addExtension($sandbox); + +By default, the sandbox mode is disabled and should be enabled when including +untrusted template code by using the ``sandbox`` tag: + +.. code-block:: jinja + + {% sandbox %} + {% include 'user.html' %} + {% endsandbox %} + +You can sandbox all templates by passing ``true`` as the second argument of +the extension constructor:: + + $sandbox = new Twig_Extension_Sandbox($policy, true); + +Profiler Extension +~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 1.18 + The Profile extension was added in Twig 1.18. + +The ``profiler`` extension enables a profiler for Twig templates; it should +only be used on your development machines as it adds some overhead:: + + $profile = new Twig_Profiler_Profile(); + $twig->addExtension(new Twig_Extension_Profiler($profile)); + + $dumper = new Twig_Profiler_Dumper_Text(); + echo $dumper->dump($profile); + +A profile contains information about time and memory consumption for template, +block, and macro executions. + +You can also dump the data in a `Blackfire.io `_ +compatible format:: + + $dumper = new Twig_Profiler_Dumper_Blackfire(); + file_put_contents('/path/to/profile.prof', $dumper->dump($profile)); + +Upload the profile to visualize it (create a `free account +`_ first): + +.. code-block:: sh + + blackfire --slot=7 upload /path/to/profile.prof + +Optimizer Extension +~~~~~~~~~~~~~~~~~~~ + +The ``optimizer`` extension optimizes the node tree before compilation:: + + $twig->addExtension(new Twig_Extension_Optimizer()); + +By default, all optimizations are turned on. You can select the ones you want +to enable by passing them to the constructor:: + + $optimizer = new Twig_Extension_Optimizer(Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR); + + $twig->addExtension($optimizer); + +Twig supports the following optimizations: + +* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_ALL``, enables all optimizations + (this is the default value). +* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_NONE``, disables all optimizations. + This reduces the compilation time, but it can increase the execution time + and the consumed memory. +* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_FOR``, optimizes the ``for`` tag by + removing the ``loop`` variable creation whenever possible. +* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_RAW_FILTER``, removes the ``raw`` + filter whenever possible. +* ``Twig_NodeVisitor_Optimizer::OPTIMIZE_VAR_ACCESS``, simplifies the creation + and access of variables in the compiled templates whenever possible. + +Exceptions +---------- + +Twig can throw exceptions: + +* ``Twig_Error``: The base exception for all errors. + +* ``Twig_Error_Syntax``: Thrown to tell the user that there is a problem with + the template syntax. + +* ``Twig_Error_Runtime``: Thrown when an error occurs at runtime (when a filter + does not exist for instance). + +* ``Twig_Error_Loader``: Thrown when an error occurs during template loading. + +* ``Twig_Sandbox_SecurityError``: Thrown when an unallowed tag, filter, or + method is called in a sandboxed template. diff --git a/vendor/twig/twig/doc/coding_standards.rst b/vendor/twig/twig/doc/coding_standards.rst new file mode 100755 index 0000000..f435df4 --- /dev/null +++ b/vendor/twig/twig/doc/coding_standards.rst @@ -0,0 +1,101 @@ +Coding Standards +================ + +When writing Twig templates, we recommend you to follow these official coding +standards: + +* Put one (and only one) space after the start of a delimiter (``{{``, ``{%``, + and ``{#``) and before the end of a delimiter (``}}``, ``%}``, and ``#}``): + + .. code-block:: jinja + + {{ foo }} + {# comment #} + {% if foo %}{% endif %} + + When using the whitespace control character, do not put any spaces between + it and the delimiter: + + .. code-block:: jinja + + {{- foo -}} + {#- comment -#} + {%- if foo -%}{%- endif -%} + +* Put one (and only one) space before and after the following operators: + comparison operators (``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``), math + operators (``+``, ``-``, ``/``, ``*``, ``%``, ``//``, ``**``), logic + operators (``not``, ``and``, ``or``), ``~``, ``is``, ``in``, and the ternary + operator (``?:``): + + .. code-block:: jinja + + {{ 1 + 2 }} + {{ foo ~ bar }} + {{ true ? true : false }} + +* Put one (and only one) space after the ``:`` sign in hashes and ``,`` in + arrays and hashes: + + .. code-block:: jinja + + {{ [1, 2, 3] }} + {{ {'foo': 'bar'} }} + +* Do not put any spaces after an opening parenthesis and before a closing + parenthesis in expressions: + + .. code-block:: jinja + + {{ 1 + (2 * 3) }} + +* Do not put any spaces before and after string delimiters: + + .. code-block:: jinja + + {{ 'foo' }} + {{ "foo" }} + +* Do not put any spaces before and after the following operators: ``|``, + ``.``, ``..``, ``[]``: + + .. code-block:: jinja + + {{ foo|upper|lower }} + {{ user.name }} + {{ user[name] }} + {% for i in 1..12 %}{% endfor %} + +* Do not put any spaces before and after the parenthesis used for filter and + function calls: + + .. code-block:: jinja + + {{ foo|default('foo') }} + {{ range(1..10) }} + +* Do not put any spaces before and after the opening and the closing of arrays + and hashes: + + .. code-block:: jinja + + {{ [1, 2, 3] }} + {{ {'foo': 'bar'} }} + +* Use lower cased and underscored variable names: + + .. code-block:: jinja + + {% set foo = 'foo' %} + {% set foo_bar = 'foo' %} + +* Indent your code inside tags (use the same indentation as the one used for + the target language of the rendered template): + + .. code-block:: jinja + + {% block foo %} + {% if true %} + true + {% endif %} + {% endblock %} diff --git a/vendor/twig/twig/doc/deprecated.rst b/vendor/twig/twig/doc/deprecated.rst new file mode 100755 index 0000000..bde62ba --- /dev/null +++ b/vendor/twig/twig/doc/deprecated.rst @@ -0,0 +1,115 @@ +Deprecated Features +=================== + +This document lists all deprecated features in Twig. Deprecated features are +kept for backward compatibility and removed in the next major release (a +feature that was deprecated in Twig 1.x is removed in Twig 2.0). + +Token Parsers +------------- + +* As of Twig 1.x, the token parser broker sub-system is deprecated. The + following class and interface will be removed in 2.0: + + * ``Twig_TokenParserBrokerInterface`` + * ``Twig_TokenParserBroker`` + +Extensions +---------- + +* As of Twig 1.x, the ability to remove an extension is deprecated and the + ``Twig_Environment::removeExtension()`` method will be removed in 2.0. + +PEAR +---- + +PEAR support has been discontinued in Twig 1.15.1, and no PEAR packages are +provided anymore. Use Composer instead. + +Filters +------- + +* As of Twig 1.x, use ``Twig_SimpleFilter`` to add a filter. The following + classes and interfaces will be removed in 2.0: + + * ``Twig_FilterInterface`` + * ``Twig_FilterCallableInterface`` + * ``Twig_Filter`` + * ``Twig_Filter_Function`` + * ``Twig_Filter_Method`` + * ``Twig_Filter_Node`` + +* As of Twig 2.x, the ``Twig_SimpleFilter`` class is deprecated and will be + removed in Twig 3.x (use ``Twig_Filter`` instead). In Twig 2.x, + ``Twig_SimpleFilter`` is just an alias for ``Twig_Filter``. + +Functions +--------- + +* As of Twig 1.x, use ``Twig_SimpleFunction`` to add a function. The following + classes and interfaces will be removed in 2.0: + + * ``Twig_FunctionInterface`` + * ``Twig_FunctionCallableInterface`` + * ``Twig_Function`` + * ``Twig_Function_Function`` + * ``Twig_Function_Method`` + * ``Twig_Function_Node`` + +* As of Twig 2.x, the ``Twig_SimpleFunction`` class is deprecated and will be + removed in Twig 3.x (use ``Twig_Function`` instead). In Twig 2.x, + ``Twig_SimpleFunction`` is just an alias for ``Twig_Function``. + +Tests +----- + +* As of Twig 1.x, use ``Twig_SimpleTest`` to add a test. The following classes + and interfaces will be removed in 2.0: + + * ``Twig_TestInterface`` + * ``Twig_TestCallableInterface`` + * ``Twig_Test`` + * ``Twig_Test_Function`` + * ``Twig_Test_Method`` + * ``Twig_Test_Node`` + +* As of Twig 2.x, the ``Twig_SimpleTest`` class is deprecated and will be + removed in Twig 3.x (use ``Twig_Test`` instead). In Twig 2.x, + ``Twig_SimpleTest`` is just an alias for ``Twig_Test``. + +* The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same + as`` and ``divisible by`` respectively. + +Nodes +----- + +* As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig + 2.0. + +Interfaces +---------- + +* As of Twig 2.x, the following interfaces are deprecated and empty (they will + be removed in Twig 3.0): + +* ``Twig_CompilerInterface`` (use ``Twig_Compiler`` instead) +* ``Twig_LexerInterface`` (use ``Twig_Lexer`` instead) +* ``Twig_NodeInterface`` (use ``Twig_Node`` instead) +* ``Twig_ParserInterface`` (use ``Twig_Parser`` instead) +* ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``) +* ``Twig_TemplateInterface`` (use ``Twig_Template`` instead, and use + those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL, + Twig_Template::METHOD_CALL) + +Loaders +------- + +* As of Twig 1.x, ``Twig_Loader_String`` is deprecated and will be removed in + 2.0. + +Globals +------- + +* As of Twig 2.x, the ability to register a global variable after the runtime + or the extensions have been initialized is not possible anymore (but + changing the value of an already registered global is possible). diff --git a/vendor/twig/twig/doc/filters/abs.rst b/vendor/twig/twig/doc/filters/abs.rst new file mode 100755 index 0000000..22fa59d --- /dev/null +++ b/vendor/twig/twig/doc/filters/abs.rst @@ -0,0 +1,18 @@ +``abs`` +======= + +The ``abs`` filter returns the absolute value. + +.. code-block:: jinja + + {# number = -5 #} + + {{ number|abs }} + + {# outputs 5 #} + +.. note:: + + Internally, Twig uses the PHP `abs`_ function. + +.. _`abs`: http://php.net/abs diff --git a/vendor/twig/twig/doc/filters/batch.rst b/vendor/twig/twig/doc/filters/batch.rst new file mode 100755 index 0000000..da47eb6 --- /dev/null +++ b/vendor/twig/twig/doc/filters/batch.rst @@ -0,0 +1,45 @@ +``batch`` +========= + +.. versionadded:: 1.12.3 + The ``batch`` filter was added in Twig 1.12.3. + +The ``batch`` filter "batches" items by returning a list of lists with the +given number of items. A second parameter can be provided and used to fill in +missing items: + +.. code-block:: jinja + + {% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %} + + + {% for row in items|batch(3, 'No item') %} + + {% for column in row %} + + {% endfor %} + + {% endfor %} +
{{ column }}
+ +The above example will be rendered as: + +.. code-block:: jinja + + + + + + + + + + + + + + + + + +
abc
def
gNo itemNo item
diff --git a/vendor/twig/twig/doc/filters/capitalize.rst b/vendor/twig/twig/doc/filters/capitalize.rst new file mode 100755 index 0000000..10546a1 --- /dev/null +++ b/vendor/twig/twig/doc/filters/capitalize.rst @@ -0,0 +1,11 @@ +``capitalize`` +============== + +The ``capitalize`` filter capitalizes a value. The first character will be +uppercase, all others lowercase: + +.. code-block:: jinja + + {{ 'my first car'|capitalize }} + + {# outputs 'My first car' #} diff --git a/vendor/twig/twig/doc/filters/convert_encoding.rst b/vendor/twig/twig/doc/filters/convert_encoding.rst new file mode 100755 index 0000000..f4ebe58 --- /dev/null +++ b/vendor/twig/twig/doc/filters/convert_encoding.rst @@ -0,0 +1,28 @@ +``convert_encoding`` +==================== + +.. versionadded:: 1.4 + The ``convert_encoding`` filter was added in Twig 1.4. + +The ``convert_encoding`` filter converts a string from one encoding to +another. The first argument is the expected output charset and the second one +is the input charset: + +.. code-block:: jinja + + {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }} + +.. note:: + + This filter relies on the `iconv`_ or `mbstring`_ extension, so one of + them must be installed. In case both are installed, `mbstring`_ is used by + default (Twig before 1.8.1 uses `iconv`_ by default). + +Arguments +--------- + +* ``to``: The output charset +* ``from``: The input charset + +.. _`iconv`: http://php.net/iconv +.. _`mbstring`: http://php.net/mbstring diff --git a/vendor/twig/twig/doc/filters/date.rst b/vendor/twig/twig/doc/filters/date.rst new file mode 100755 index 0000000..c86d42b --- /dev/null +++ b/vendor/twig/twig/doc/filters/date.rst @@ -0,0 +1,94 @@ +``date`` +======== + +.. versionadded:: 1.1 + The timezone support has been added in Twig 1.1. + +.. versionadded:: 1.5 + The default date format support has been added in Twig 1.5. + +.. versionadded:: 1.6.1 + The default timezone support has been added in Twig 1.6.1. + +.. versionadded:: 1.11.0 + The introduction of the false value for the timezone was introduced in Twig 1.11.0 + +The ``date`` filter formats a date to a given format: + +.. code-block:: jinja + + {{ post.published_at|date("m/d/Y") }} + +The format specifier is the same as supported by `date`_, +except when the filtered data is of type `DateInterval`_, when the format must conform to +`DateInterval::format`_ instead. + +The ``date`` filter accepts strings (it must be in a format supported by the +`strtotime`_ function), `DateTime`_ instances, or `DateInterval`_ instances. For +instance, to display the current date, filter the word "now": + +.. code-block:: jinja + + {{ "now"|date("m/d/Y") }} + +To escape words and characters in the date format use ``\\`` in front of each +character: + +.. code-block:: jinja + + {{ post.published_at|date("F jS \\a\\t g:ia") }} + +If the value passed to the ``date`` filter is ``null``, it will return the +current date by default. If an empty string is desired instead of the current +date, use a ternary operator: + +.. code-block:: jinja + + {{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }} + +If no format is provided, Twig will use the default one: ``F j, Y H:i``. This +default can be easily changed by calling the ``setDateFormat()`` method on the +``core`` extension instance. The first argument is the default format for +dates and the second one is the default format for date intervals: + +.. code-block:: php + + $twig = new Twig_Environment($loader); + $twig->getExtension('core')->setDateFormat('d/m/Y', '%d days'); + +Timezone +-------- + +By default, the date is displayed by applying the default timezone (the one +specified in php.ini or declared in Twig -- see below), but you can override +it by explicitly specifying a timezone: + +.. code-block:: jinja + + {{ post.published_at|date("m/d/Y", "Europe/Paris") }} + +If the date is already a DateTime object, and if you want to keep its current +timezone, pass ``false`` as the timezone value: + +.. code-block:: jinja + + {{ post.published_at|date("m/d/Y", false) }} + +The default timezone can also be set globally by calling ``setTimezone()``: + +.. code-block:: php + + $twig = new Twig_Environment($loader); + $twig->getExtension('core')->setTimezone('Europe/Paris'); + +Arguments +--------- + +* ``format``: The date format +* ``timezone``: The date timezone + +.. _`strtotime`: http://www.php.net/strtotime +.. _`DateTime`: http://www.php.net/DateTime +.. _`DateInterval`: http://www.php.net/DateInterval +.. _`date`: http://www.php.net/date +.. _`DateInterval::format`: http://www.php.net/DateInterval.format diff --git a/vendor/twig/twig/doc/filters/date_modify.rst b/vendor/twig/twig/doc/filters/date_modify.rst new file mode 100755 index 0000000..add40b5 --- /dev/null +++ b/vendor/twig/twig/doc/filters/date_modify.rst @@ -0,0 +1,23 @@ +``date_modify`` +=============== + +.. versionadded:: 1.9.0 + The date_modify filter has been added in Twig 1.9.0. + +The ``date_modify`` filter modifies a date with a given modifier string: + +.. code-block:: jinja + + {{ post.published_at|date_modify("+1 day")|date("m/d/Y") }} + +The ``date_modify`` filter accepts strings (it must be in a format supported +by the `strtotime`_ function) or `DateTime`_ instances. You can easily combine +it with the :doc:`date` filter for formatting. + +Arguments +--------- + +* ``modifier``: The modifier + +.. _`strtotime`: http://www.php.net/strtotime +.. _`DateTime`: http://www.php.net/DateTime diff --git a/vendor/twig/twig/doc/filters/default.rst b/vendor/twig/twig/doc/filters/default.rst new file mode 100755 index 0000000..641ac6e --- /dev/null +++ b/vendor/twig/twig/doc/filters/default.rst @@ -0,0 +1,33 @@ +``default`` +=========== + +The ``default`` filter returns the passed default value if the value is +undefined or empty, otherwise the value of the variable: + +.. code-block:: jinja + + {{ var|default('var is not defined') }} + + {{ var.foo|default('foo item on var is not defined') }} + + {{ var['foo']|default('foo item on var is not defined') }} + + {{ ''|default('passed var is empty') }} + +When using the ``default`` filter on an expression that uses variables in some +method calls, be sure to use the ``default`` filter whenever a variable can be +undefined: + +.. code-block:: jinja + + {{ var.method(foo|default('foo'))|default('foo') }} + +.. note:: + + Read the documentation for the :doc:`defined<../tests/defined>` and + :doc:`empty<../tests/empty>` tests to learn more about their semantics. + +Arguments +--------- + +* ``default``: The default value diff --git a/vendor/twig/twig/doc/filters/escape.rst b/vendor/twig/twig/doc/filters/escape.rst new file mode 100755 index 0000000..fc9771a --- /dev/null +++ b/vendor/twig/twig/doc/filters/escape.rst @@ -0,0 +1,116 @@ +``escape`` +========== + +.. versionadded:: 1.9.0 + The ``css``, ``url``, and ``html_attr`` strategies were added in Twig + 1.9.0. + +.. versionadded:: 1.14.0 + The ability to define custom escapers was added in Twig 1.14.0. + +The ``escape`` filter escapes a string for safe insertion into the final +output. It supports different escaping strategies depending on the template +context. + +By default, it uses the HTML escaping strategy: + +.. code-block:: jinja + + {{ user.username|escape }} + +For convenience, the ``e`` filter is defined as an alias: + +.. code-block:: jinja + + {{ user.username|e }} + +The ``escape`` filter can also be used in other contexts than HTML thanks to +an optional argument which defines the escaping strategy to use: + +.. code-block:: jinja + + {{ user.username|e }} + {# is equivalent to #} + {{ user.username|e('html') }} + +And here is how to escape variables included in JavaScript code: + +.. code-block:: jinja + + {{ user.username|escape('js') }} + {{ user.username|e('js') }} + +The ``escape`` filter supports the following escaping strategies: + +* ``html``: escapes a string for the **HTML body** context. + +* ``js``: escapes a string for the **JavaScript context**. + +* ``css``: escapes a string for the **CSS context**. CSS escaping can be + applied to any string being inserted into CSS and escapes everything except + alphanumerics. + +* ``url``: escapes a string for the **URI or parameter contexts**. This should + not be used to escape an entire URI; only a subcomponent being inserted. + +* ``html_attr``: escapes a string for the **HTML attribute** context. + +.. note:: + + Internally, ``escape`` uses the PHP native `htmlspecialchars`_ function + for the HTML escaping strategy. + +.. caution:: + + When using automatic escaping, Twig tries to not double-escape a variable + when the automatic escaping strategy is the same as the one applied by the + escape filter; but that does not work when using a variable as the + escaping strategy: + + .. code-block:: jinja + + {% set strategy = 'html' %} + + {% autoescape 'html' %} + {{ var|escape('html') }} {# won't be double-escaped #} + {{ var|escape(strategy) }} {# will be double-escaped #} + {% endautoescape %} + + When using a variable as the escaping strategy, you should disable + automatic escaping: + + .. code-block:: jinja + + {% set strategy = 'html' %} + + {% autoescape 'html' %} + {{ var|escape(strategy)|raw }} {# won't be double-escaped #} + {% endautoescape %} + +Custom Escapers +--------------- + +You can define custom escapers by calling the ``setEscaper()`` method on the +``core`` extension instance. The first argument is the escaper name (to be +used in the ``escape`` call) and the second one must be a valid PHP callable: + +.. code-block:: php + + $twig = new Twig_Environment($loader); + $twig->getExtension('core')->setEscaper('csv', 'csv_escaper')); + +When called by Twig, the callable receives the Twig environment instance, the +string to escape, and the charset. + +.. note:: + + Built-in escapers cannot be overridden mainly they should be considered as + the final implementation and also for better performance. + +Arguments +--------- + +* ``strategy``: The escaping strategy +* ``charset``: The string charset + +.. _`htmlspecialchars`: http://php.net/htmlspecialchars diff --git a/vendor/twig/twig/doc/filters/first.rst b/vendor/twig/twig/doc/filters/first.rst new file mode 100755 index 0000000..674c1f9 --- /dev/null +++ b/vendor/twig/twig/doc/filters/first.rst @@ -0,0 +1,25 @@ +``first`` +========= + +.. versionadded:: 1.12.2 + The ``first`` filter was added in Twig 1.12.2. + +The ``first`` filter returns the first "element" of a sequence, a mapping, or +a string: + +.. code-block:: jinja + + {{ [1, 2, 3, 4]|first }} + {# outputs 1 #} + + {{ { a: 1, b: 2, c: 3, d: 4 }|first }} + {# outputs 1 #} + + {{ '1234'|first }} + {# outputs 1 #} + +.. note:: + + It also works with objects implementing the `Traversable`_ interface. + +.. _`Traversable`: http://php.net/manual/en/class.traversable.php diff --git a/vendor/twig/twig/doc/filters/format.rst b/vendor/twig/twig/doc/filters/format.rst new file mode 100755 index 0000000..f8effd9 --- /dev/null +++ b/vendor/twig/twig/doc/filters/format.rst @@ -0,0 +1,16 @@ +``format`` +========== + +The ``format`` filter formats a given string by replacing the placeholders +(placeholders follows the `sprintf`_ notation): + +.. code-block:: jinja + + {{ "I like %s and %s."|format(foo, "bar") }} + + {# outputs I like foo and bar + if the foo parameter equals to the foo string. #} + +.. _`sprintf`: http://www.php.net/sprintf + +.. seealso:: :doc:`replace` diff --git a/vendor/twig/twig/doc/filters/index.rst b/vendor/twig/twig/doc/filters/index.rst new file mode 100755 index 0000000..8daa961 --- /dev/null +++ b/vendor/twig/twig/doc/filters/index.rst @@ -0,0 +1,37 @@ +Filters +======= + +.. toctree:: + :maxdepth: 1 + + abs + batch + capitalize + convert_encoding + date + date_modify + default + escape + first + format + join + json_encode + keys + last + length + lower + merge + nl2br + number_format + raw + replace + reverse + round + slice + sort + split + striptags + title + trim + upper + url_encode diff --git a/vendor/twig/twig/doc/filters/join.rst b/vendor/twig/twig/doc/filters/join.rst new file mode 100755 index 0000000..2fab945 --- /dev/null +++ b/vendor/twig/twig/doc/filters/join.rst @@ -0,0 +1,23 @@ +``join`` +======== + +The ``join`` filter returns a string which is the concatenation of the items +of a sequence: + +.. code-block:: jinja + + {{ [1, 2, 3]|join }} + {# returns 123 #} + +The separator between elements is an empty string per default, but you can +define it with the optional first parameter: + +.. code-block:: jinja + + {{ [1, 2, 3]|join('|') }} + {# outputs 1|2|3 #} + +Arguments +--------- + +* ``glue``: The separator diff --git a/vendor/twig/twig/doc/filters/json_encode.rst b/vendor/twig/twig/doc/filters/json_encode.rst new file mode 100755 index 0000000..a39bb47 --- /dev/null +++ b/vendor/twig/twig/doc/filters/json_encode.rst @@ -0,0 +1,21 @@ +``json_encode`` +=============== + +The ``json_encode`` filter returns the JSON representation of a value: + +.. code-block:: jinja + + {{ data|json_encode() }} + +.. note:: + + Internally, Twig uses the PHP `json_encode`_ function. + +Arguments +--------- + +* ``options``: A bitmask of `json_encode options`_ (``{{ + data|json_encode(constant('JSON_PRETTY_PRINT')) }}``) + +.. _`json_encode`: http://php.net/json_encode +.. _`json_encode options`: http://www.php.net/manual/en/json.constants.php diff --git a/vendor/twig/twig/doc/filters/keys.rst b/vendor/twig/twig/doc/filters/keys.rst new file mode 100755 index 0000000..e4f090c --- /dev/null +++ b/vendor/twig/twig/doc/filters/keys.rst @@ -0,0 +1,11 @@ +``keys`` +======== + +The ``keys`` filter returns the keys of an array. It is useful when you want to +iterate over the keys of an array: + +.. code-block:: jinja + + {% for key in array|keys %} + ... + {% endfor %} diff --git a/vendor/twig/twig/doc/filters/last.rst b/vendor/twig/twig/doc/filters/last.rst new file mode 100755 index 0000000..345b657 --- /dev/null +++ b/vendor/twig/twig/doc/filters/last.rst @@ -0,0 +1,25 @@ +``last`` +======== + +.. versionadded:: 1.12.2 + The ``last`` filter was added in Twig 1.12.2. + +The ``last`` filter returns the last "element" of a sequence, a mapping, or +a string: + +.. code-block:: jinja + + {{ [1, 2, 3, 4]|last }} + {# outputs 4 #} + + {{ { a: 1, b: 2, c: 3, d: 4 }|last }} + {# outputs 4 #} + + {{ '1234'|last }} + {# outputs 4 #} + +.. note:: + + It also works with objects implementing the `Traversable`_ interface. + +.. _`Traversable`: http://php.net/manual/en/class.traversable.php diff --git a/vendor/twig/twig/doc/filters/length.rst b/vendor/twig/twig/doc/filters/length.rst new file mode 100755 index 0000000..1f783b3 --- /dev/null +++ b/vendor/twig/twig/doc/filters/length.rst @@ -0,0 +1,11 @@ +``length`` +========== + +The ``length`` filter returns the number of items of a sequence or mapping, or +the length of a string: + +.. code-block:: jinja + + {% if users|length > 10 %} + ... + {% endif %} diff --git a/vendor/twig/twig/doc/filters/lower.rst b/vendor/twig/twig/doc/filters/lower.rst new file mode 100755 index 0000000..ef9faa9 --- /dev/null +++ b/vendor/twig/twig/doc/filters/lower.rst @@ -0,0 +1,10 @@ +``lower`` +========= + +The ``lower`` filter converts a value to lowercase: + +.. code-block:: jinja + + {{ 'WELCOME'|lower }} + + {# outputs 'welcome' #} diff --git a/vendor/twig/twig/doc/filters/merge.rst b/vendor/twig/twig/doc/filters/merge.rst new file mode 100755 index 0000000..cb8b1b2 --- /dev/null +++ b/vendor/twig/twig/doc/filters/merge.rst @@ -0,0 +1,47 @@ +``merge`` +========= + +The ``merge`` filter merges an array with another array: + +.. code-block:: jinja + + {% set values = [1, 2] %} + + {% set values = values|merge(['apple', 'orange']) %} + + {# values now contains [1, 2, 'apple', 'orange'] #} + +New values are added at the end of the existing ones. + +The ``merge`` filter also works on hashes: + +.. code-block:: jinja + + {% set items = { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'unknown' } %} + + {% set items = items|merge({ 'peugeot': 'car', 'renault': 'car' }) %} + + {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car', 'renault': 'car' } #} + +For hashes, the merging process occurs on the keys: if the key does not +already exist, it is added but if the key already exists, its value is +overridden. + +.. tip:: + + If you want to ensure that some values are defined in an array (by given + default values), reverse the two elements in the call: + + .. code-block:: jinja + + {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %} + + {% set items = { 'apple': 'unknown' }|merge(items) %} + + {# items now contains { 'apple': 'fruit', 'orange': 'fruit' } #} + +.. note:: + + Internally, Twig uses the PHP `array_merge`_ function. + +.. _`array_merge`: http://php.net/array_merge diff --git a/vendor/twig/twig/doc/filters/nl2br.rst b/vendor/twig/twig/doc/filters/nl2br.rst new file mode 100755 index 0000000..5c923e1 --- /dev/null +++ b/vendor/twig/twig/doc/filters/nl2br.rst @@ -0,0 +1,22 @@ +``nl2br`` +========= + +.. versionadded:: 1.5 + The ``nl2br`` filter was added in Twig 1.5. + +The ``nl2br`` filter inserts HTML line breaks before all newlines in a string: + +.. code-block:: jinja + + {{ "I like Twig.\nYou will like it too."|nl2br }} + {# outputs + + I like Twig.
+ You will like it too. + + #} + +.. note:: + + The ``nl2br`` filter pre-escapes the input before applying the + transformation. diff --git a/vendor/twig/twig/doc/filters/number_format.rst b/vendor/twig/twig/doc/filters/number_format.rst new file mode 100755 index 0000000..3114e84 --- /dev/null +++ b/vendor/twig/twig/doc/filters/number_format.rst @@ -0,0 +1,45 @@ +``number_format`` +================= + +.. versionadded:: 1.5 + The ``number_format`` filter was added in Twig 1.5 + +The ``number_format`` filter formats numbers. It is a wrapper around PHP's +`number_format`_ function: + +.. code-block:: jinja + + {{ 200.35|number_format }} + +You can control the number of decimal places, decimal point, and thousands +separator using the additional arguments: + +.. code-block:: jinja + + {{ 9800.333|number_format(2, '.', ',') }} + +If no formatting options are provided then Twig will use the default formatting +options of: + +* 0 decimal places. +* ``.`` as the decimal point. +* ``,`` as the thousands separator. + +These defaults can be easily changed through the core extension: + +.. code-block:: php + + $twig = new Twig_Environment($loader); + $twig->getExtension('core')->setNumberFormat(3, '.', ','); + +The defaults set for ``number_format`` can be over-ridden upon each call using the +additional parameters. + +Arguments +--------- + +* ``decimal``: The number of decimal points to display +* ``decimal_point``: The character(s) to use for the decimal point +* ``thousand_sep``: The character(s) to use for the thousands separator + +.. _`number_format`: http://php.net/number_format diff --git a/vendor/twig/twig/doc/filters/raw.rst b/vendor/twig/twig/doc/filters/raw.rst new file mode 100755 index 0000000..e5e5b12 --- /dev/null +++ b/vendor/twig/twig/doc/filters/raw.rst @@ -0,0 +1,36 @@ +``raw`` +======= + +The ``raw`` filter marks the value as being "safe", which means that in an +environment with automatic escaping enabled this variable will not be escaped +if ``raw`` is the last filter applied to it: + +.. code-block:: jinja + + {% autoescape %} + {{ var|raw }} {# var won't be escaped #} + {% endautoescape %} + +.. note:: + + Be careful when using the ``raw`` filter inside expressions: + + .. code-block:: jinja + + {% autoescape %} + {% set hello = 'Hello' %} + {% set hola = 'Hola' %} + + {{ false ? 'Hola' : hello|raw }} + does not render the same as + {{ false ? hola : hello|raw }} + but renders the same as + {{ (false ? hola : hello)|raw }} + {% endautoescape %} + + The first ternary statement is not escaped: ``hello`` is marked as being + safe and Twig does not escape static values (see + :doc:`escape<../tags/autoescape>`). In the second ternary statement, even + if ``hello`` is marked as safe, ``hola`` remains unsafe and so is the whole + expression. The third ternary statement is marked as safe and the result is + not escaped. diff --git a/vendor/twig/twig/doc/filters/replace.rst b/vendor/twig/twig/doc/filters/replace.rst new file mode 100755 index 0000000..1227957 --- /dev/null +++ b/vendor/twig/twig/doc/filters/replace.rst @@ -0,0 +1,19 @@ +``replace`` +=========== + +The ``replace`` filter formats a given string by replacing the placeholders +(placeholders are free-form): + +.. code-block:: jinja + + {{ "I like %this% and %that%."|replace({'%this%': foo, '%that%': "bar"}) }} + + {# outputs I like foo and bar + if the foo parameter equals to the foo string. #} + +Arguments +--------- + +* ``replace_pairs``: The placeholder values + +.. seealso:: :doc:`format` diff --git a/vendor/twig/twig/doc/filters/reverse.rst b/vendor/twig/twig/doc/filters/reverse.rst new file mode 100755 index 0000000..76fd2c1 --- /dev/null +++ b/vendor/twig/twig/doc/filters/reverse.rst @@ -0,0 +1,47 @@ +``reverse`` +=========== + +.. versionadded:: 1.6 + Support for strings has been added in Twig 1.6. + +The ``reverse`` filter reverses a sequence, a mapping, or a string: + +.. code-block:: jinja + + {% for user in users|reverse %} + ... + {% endfor %} + + {{ '1234'|reverse }} + + {# outputs 4321 #} + +.. tip:: + + For sequences and mappings, numeric keys are not preserved. To reverse + them as well, pass ``true`` as an argument to the ``reverse`` filter: + + .. code-block:: jinja + + {% for key, value in {1: "a", 2: "b", 3: "c"}|reverse %} + {{ key }}: {{ value }} + {%- endfor %} + + {# output: 0: c 1: b 2: a #} + + {% for key, value in {1: "a", 2: "b", 3: "c"}|reverse(true) %} + {{ key }}: {{ value }} + {%- endfor %} + + {# output: 3: c 2: b 1: a #} + +.. note:: + + It also works with objects implementing the `Traversable`_ interface. + +Arguments +--------- + +* ``preserve_keys``: Preserve keys when reversing a mapping or a sequence. + +.. _`Traversable`: http://php.net/Traversable diff --git a/vendor/twig/twig/doc/filters/round.rst b/vendor/twig/twig/doc/filters/round.rst new file mode 100755 index 0000000..2521cf1 --- /dev/null +++ b/vendor/twig/twig/doc/filters/round.rst @@ -0,0 +1,37 @@ +``round`` +========= + +.. versionadded:: 1.15.0 + The ``round`` filter was added in Twig 1.15.0. + +The ``round`` filter rounds a number to a given precision: + +.. code-block:: jinja + + {{ 42.55|round }} + {# outputs 43 #} + + {{ 42.55|round(1, 'floor') }} + {# outputs 42.5 #} + +The ``round`` filter takes two optional arguments; the first one specifies the +precision (default is ``0``) and the second the rounding method (default is +``common``): + +* ``common`` rounds either up or down (rounds the value up to precision decimal + places away from zero, when it is half way there -- making 1.5 into 2 and + -1.5 into -2); + +* ``ceil`` always rounds up; + +* ``floor`` always rounds down. + +.. note:: + + The ``//`` operator is equivalent to ``|round(0, 'floor')``. + +Arguments +--------- + +* ``precision``: The rounding precision +* ``method``: The rounding method diff --git a/vendor/twig/twig/doc/filters/slice.rst b/vendor/twig/twig/doc/filters/slice.rst new file mode 100755 index 0000000..70bf139 --- /dev/null +++ b/vendor/twig/twig/doc/filters/slice.rst @@ -0,0 +1,71 @@ +``slice`` +=========== + +.. versionadded:: 1.6 + The ``slice`` filter was added in Twig 1.6. + +The ``slice`` filter extracts a slice of a sequence, a mapping, or a string: + +.. code-block:: jinja + + {% for i in [1, 2, 3, 4, 5]|slice(1, 2) %} + {# will iterate over 2 and 3 #} + {% endfor %} + + {{ '12345'|slice(1, 2) }} + + {# outputs 23 #} + +You can use any valid expression for both the start and the length: + +.. code-block:: jinja + + {% for i in [1, 2, 3, 4, 5]|slice(start, length) %} + {# ... #} + {% endfor %} + +As syntactic sugar, you can also use the ``[]`` notation: + +.. code-block:: jinja + + {% for i in [1, 2, 3, 4, 5][start:length] %} + {# ... #} + {% endfor %} + + {{ '12345'[1:2] }} {# will display "23" #} + + {# you can omit the first argument -- which is the same as 0 #} + {{ '12345'[:2] }} {# will display "12" #} + + {# you can omit the last argument -- which will select everything till the end #} + {{ '12345'[2:] }} {# will display "345" #} + +The ``slice`` filter works as the `array_slice`_ PHP function for arrays and +`mb_substr`_ for strings with a fallback to `substr`_. + +If the start is non-negative, the sequence will start at that start in the +variable. If start is negative, the sequence will start that far from the end +of the variable. + +If length is given and is positive, then the sequence will have up to that +many elements in it. If the variable is shorter than the length, then only the +available variable elements will be present. If length is given and is +negative then the sequence will stop that many elements from the end of the +variable. If it is omitted, then the sequence will have everything from offset +up until the end of the variable. + +.. note:: + + It also works with objects implementing the `Traversable`_ interface. + +Arguments +--------- + +* ``start``: The start of the slice +* ``length``: The size of the slice +* ``preserve_keys``: Whether to preserve key or not (when the input is an array) + +.. _`Traversable`: http://php.net/manual/en/class.traversable.php +.. _`array_slice`: http://php.net/array_slice +.. _`mb_substr` : http://php.net/mb-substr +.. _`substr`: http://php.net/substr diff --git a/vendor/twig/twig/doc/filters/sort.rst b/vendor/twig/twig/doc/filters/sort.rst new file mode 100755 index 0000000..3331152 --- /dev/null +++ b/vendor/twig/twig/doc/filters/sort.rst @@ -0,0 +1,17 @@ +``sort`` +======== + +The ``sort`` filter sorts an array: + +.. code-block:: jinja + + {% for user in users|sort %} + ... + {% endfor %} + +.. note:: + + Internally, Twig uses the PHP `asort`_ function to maintain index + association. + +.. _`asort`: http://php.net/asort diff --git a/vendor/twig/twig/doc/filters/split.rst b/vendor/twig/twig/doc/filters/split.rst new file mode 100755 index 0000000..bbc6d79 --- /dev/null +++ b/vendor/twig/twig/doc/filters/split.rst @@ -0,0 +1,53 @@ +``split`` +========= + +.. versionadded:: 1.10.3 + The ``split`` filter was added in Twig 1.10.3. + +The ``split`` filter splits a string by the given delimiter and returns a list +of strings: + +.. code-block:: jinja + + {% set foo = "one,two,three"|split(',') %} + {# foo contains ['one', 'two', 'three'] #} + +You can also pass a ``limit`` argument: + + * If ``limit`` is positive, the returned array will contain a maximum of + limit elements with the last element containing the rest of string; + + * If ``limit`` is negative, all components except the last -limit are + returned; + + * If ``limit`` is zero, then this is treated as 1. + +.. code-block:: jinja + + {% set foo = "one,two,three,four,five"|split(',', 3) %} + {# foo contains ['one', 'two', 'three,four,five'] #} + +If the ``delimiter`` is an empty string, then value will be split by equal +chunks. Length is set by the ``limit`` argument (one character by default). + +.. code-block:: jinja + + {% set foo = "123"|split('') %} + {# foo contains ['1', '2', '3'] #} + + {% set bar = "aabbcc"|split('', 2) %} + {# bar contains ['aa', 'bb', 'cc'] #} + +.. note:: + + Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is + empty) functions for string splitting. + +Arguments +--------- + +* ``delimiter``: The delimiter +* ``limit``: The limit argument + +.. _`explode`: http://php.net/explode +.. _`str_split`: http://php.net/str_split diff --git a/vendor/twig/twig/doc/filters/striptags.rst b/vendor/twig/twig/doc/filters/striptags.rst new file mode 100755 index 0000000..72c6f25 --- /dev/null +++ b/vendor/twig/twig/doc/filters/striptags.rst @@ -0,0 +1,15 @@ +``striptags`` +============= + +The ``striptags`` filter strips SGML/XML tags and replace adjacent whitespace +by one space: + +.. code-block:: jinja + + {{ some_html|striptags }} + +.. note:: + + Internally, Twig uses the PHP `strip_tags`_ function. + +.. _`strip_tags`: http://php.net/strip_tags diff --git a/vendor/twig/twig/doc/filters/title.rst b/vendor/twig/twig/doc/filters/title.rst new file mode 100755 index 0000000..c5a318e --- /dev/null +++ b/vendor/twig/twig/doc/filters/title.rst @@ -0,0 +1,11 @@ +``title`` +========= + +The ``title`` filter returns a titlecased version of the value. Words will +start with uppercase letters, all remaining characters are lowercase: + +.. code-block:: jinja + + {{ 'my first car'|title }} + + {# outputs 'My First Car' #} diff --git a/vendor/twig/twig/doc/filters/trim.rst b/vendor/twig/twig/doc/filters/trim.rst new file mode 100755 index 0000000..4ddb208 --- /dev/null +++ b/vendor/twig/twig/doc/filters/trim.rst @@ -0,0 +1,29 @@ +``trim`` +======== + +.. versionadded:: 1.6.2 + The ``trim`` filter was added in Twig 1.6.2. + +The ``trim`` filter strips whitespace (or other characters) from the beginning +and end of a string: + +.. code-block:: jinja + + {{ ' I like Twig. '|trim }} + + {# outputs 'I like Twig.' #} + + {{ ' I like Twig.'|trim('.') }} + + {# outputs ' I like Twig' #} + +.. note:: + + Internally, Twig uses the PHP `trim`_ function. + +Arguments +--------- + +* ``character_mask``: The characters to strip + +.. _`trim`: http://php.net/trim diff --git a/vendor/twig/twig/doc/filters/upper.rst b/vendor/twig/twig/doc/filters/upper.rst new file mode 100755 index 0000000..561cebe --- /dev/null +++ b/vendor/twig/twig/doc/filters/upper.rst @@ -0,0 +1,10 @@ +``upper`` +========= + +The ``upper`` filter converts a value to uppercase: + +.. code-block:: jinja + + {{ 'welcome'|upper }} + + {# outputs 'WELCOME' #} diff --git a/vendor/twig/twig/doc/filters/url_encode.rst b/vendor/twig/twig/doc/filters/url_encode.rst new file mode 100755 index 0000000..5944e59 --- /dev/null +++ b/vendor/twig/twig/doc/filters/url_encode.rst @@ -0,0 +1,34 @@ +``url_encode`` +============== + +.. versionadded:: 1.12.3 + Support for encoding an array as query string was added in Twig 1.12.3. + +.. versionadded:: 1.16.0 + The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes + according to RFC 3986. + +The ``url_encode`` filter percent encodes a given string as URL segment +or an array as query string: + +.. code-block:: jinja + + {{ "path-seg*ment"|url_encode }} + {# outputs "path-seg%2Ament" #} + + {{ "string with spaces"|url_encode }} + {# outputs "string%20with%20spaces" #} + + {{ {'param': 'value', 'foo': 'bar'}|url_encode }} + {# outputs "param=value&foo=bar" #} + +.. note:: + + Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass + ``true`` as the first parameter) or the `http_build_query`_ function. Note + that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the + ``raw`` argument was removed.) + +.. _`urlencode`: http://php.net/urlencode +.. _`rawurlencode`: http://php.net/rawurlencode +.. _`http_build_query`: http://php.net/http_build_query diff --git a/vendor/twig/twig/doc/functions/attribute.rst b/vendor/twig/twig/doc/functions/attribute.rst new file mode 100755 index 0000000..ceba96b --- /dev/null +++ b/vendor/twig/twig/doc/functions/attribute.rst @@ -0,0 +1,26 @@ +``attribute`` +============= + +.. versionadded:: 1.2 + The ``attribute`` function was added in Twig 1.2. + +The ``attribute`` function can be used to access a "dynamic" attribute of a +variable: + +.. code-block:: jinja + + {{ attribute(object, method) }} + {{ attribute(object, method, arguments) }} + {{ attribute(array, item) }} + +In addition, the ``defined`` test can check for the existence of a dynamic +attribute: + +.. code-block:: jinja + + {{ attribute(object, method) is defined ? 'Method exists' : 'Method does not exist' }} + +.. note:: + + The resolution algorithm is the same as the one used for the ``.`` + notation, except that the item can be any valid expression. diff --git a/vendor/twig/twig/doc/functions/block.rst b/vendor/twig/twig/doc/functions/block.rst new file mode 100755 index 0000000..fd571ef --- /dev/null +++ b/vendor/twig/twig/doc/functions/block.rst @@ -0,0 +1,15 @@ +``block`` +========= + +When a template uses inheritance and if you want to print a block multiple +times, use the ``block`` function: + +.. code-block:: jinja + + {% block title %}{% endblock %} + +

{{ block('title') }}

+ + {% block body %}{% endblock %} + +.. seealso:: :doc:`extends<../tags/extends>`, :doc:`parent<../functions/parent>` diff --git a/vendor/twig/twig/doc/functions/constant.rst b/vendor/twig/twig/doc/functions/constant.rst new file mode 100755 index 0000000..bea0e9f --- /dev/null +++ b/vendor/twig/twig/doc/functions/constant.rst @@ -0,0 +1,18 @@ +``constant`` +============ + +.. versionadded: 1.12.1 + constant now accepts object instances as the second argument. + +``constant`` returns the constant value for a given string: + +.. code-block:: jinja + + {{ some_date|date(constant('DATE_W3C')) }} + {{ constant('Namespace\\Classname::CONSTANT_NAME') }} + +As of 1.12.1 you can read constants from object instances as well: + +.. code-block:: jinja + + {{ constant('RSS', date) }} diff --git a/vendor/twig/twig/doc/functions/cycle.rst b/vendor/twig/twig/doc/functions/cycle.rst new file mode 100755 index 0000000..e343493 --- /dev/null +++ b/vendor/twig/twig/doc/functions/cycle.rst @@ -0,0 +1,28 @@ +``cycle`` +========= + +The ``cycle`` function cycles on an array of values: + +.. code-block:: jinja + + {% set start_year = date() | date('Y') %} + {% set end_year = start_year + 5 %} + + {% for year in start_year..end_year %} + {{ cycle(['odd', 'even'], loop.index0) }} + {% endfor %} + +The array can contain any number of values: + +.. code-block:: jinja + + {% set fruits = ['apple', 'orange', 'citrus'] %} + + {% for i in 0..10 %} + {{ cycle(fruits, i) }} + {% endfor %} + +Arguments +--------- + +* ``position``: The cycle position diff --git a/vendor/twig/twig/doc/functions/date.rst b/vendor/twig/twig/doc/functions/date.rst new file mode 100755 index 0000000..714e08c --- /dev/null +++ b/vendor/twig/twig/doc/functions/date.rst @@ -0,0 +1,52 @@ +``date`` +======== + +.. versionadded:: 1.6 + The date function has been added in Twig 1.6. + +.. versionadded:: 1.6.1 + The default timezone support has been added in Twig 1.6.1. + +Converts an argument to a date to allow date comparison: + +.. code-block:: jinja + + {% if date(user.created_at) < date('-2days') %} + {# do something #} + {% endif %} + +The argument must be in one of PHP’s supported `date and time formats`_. + +You can pass a timezone as the second argument: + +.. code-block:: jinja + + {% if date(user.created_at) < date('-2days', 'Europe/Paris') %} + {# do something #} + {% endif %} + +If no argument is passed, the function returns the current date: + +.. code-block:: jinja + + {% if date(user.created_at) < date() %} + {# always! #} + {% endif %} + +.. note:: + + You can set the default timezone globally by calling ``setTimezone()`` on + the ``core`` extension instance: + + .. code-block:: php + + $twig = new Twig_Environment($loader); + $twig->getExtension('core')->setTimezone('Europe/Paris'); + +Arguments +--------- + +* ``date``: The date +* ``timezone``: The timezone + +.. _`date and time formats`: http://php.net/manual/en/datetime.formats.php diff --git a/vendor/twig/twig/doc/functions/dump.rst b/vendor/twig/twig/doc/functions/dump.rst new file mode 100755 index 0000000..a231f08 --- /dev/null +++ b/vendor/twig/twig/doc/functions/dump.rst @@ -0,0 +1,69 @@ +``dump`` +======== + +.. versionadded:: 1.5 + The ``dump`` function was added in Twig 1.5. + +The ``dump`` function dumps information about a template variable. This is +mostly useful to debug a template that does not behave as expected by +introspecting its variables: + +.. code-block:: jinja + + {{ dump(user) }} + +.. note:: + + The ``dump`` function is not available by default. You must add the + ``Twig_Extension_Debug`` extension explicitly when creating your Twig + environment:: + + $twig = new Twig_Environment($loader, array( + 'debug' => true, + // ... + )); + $twig->addExtension(new Twig_Extension_Debug()); + + Even when enabled, the ``dump`` function won't display anything if the + ``debug`` option on the environment is not enabled (to avoid leaking debug + information on a production server). + +In an HTML context, wrap the output with a ``pre`` tag to make it easier to +read: + +.. code-block:: jinja + +
+        {{ dump(user) }}
+    
+ +.. tip:: + + Using a ``pre`` tag is not needed when `XDebug`_ is enabled and + ``html_errors`` is ``on``; as a bonus, the output is also nicer with + XDebug enabled. + +You can debug several variables by passing them as additional arguments: + +.. code-block:: jinja + + {{ dump(user, categories) }} + +If you don't pass any value, all variables from the current context are +dumped: + +.. code-block:: jinja + + {{ dump() }} + +.. note:: + + Internally, Twig uses the PHP `var_dump`_ function. + +Arguments +--------- + +* ``context``: The context to dump + +.. _`XDebug`: http://xdebug.org/docs/display +.. _`var_dump`: http://php.net/var_dump diff --git a/vendor/twig/twig/doc/functions/include.rst b/vendor/twig/twig/doc/functions/include.rst new file mode 100755 index 0000000..33bd56d --- /dev/null +++ b/vendor/twig/twig/doc/functions/include.rst @@ -0,0 +1,80 @@ +``include`` +=========== + +.. versionadded:: 1.12 + The ``include`` function was added in Twig 1.12. + +The ``include`` function returns the rendered content of a template: + +.. code-block:: jinja + + {{ include('template.html') }} + {{ include(some_var) }} + +Included templates have access to the variables of the active context. + +If you are using the filesystem loader, the templates are looked for in the +paths defined by it. + +The context is passed by default to the template but you can also pass +additional variables: + +.. code-block:: jinja + + {# template.html will have access to the variables from the current context and the additional ones provided #} + {{ include('template.html', {foo: 'bar'}) }} + +You can disable access to the context by setting ``with_context`` to +``false``: + +.. code-block:: jinja + + {# only the foo variable will be accessible #} + {{ include('template.html', {foo: 'bar'}, with_context = false) }} + +.. code-block:: jinja + + {# no variables will be accessible #} + {{ include('template.html', with_context = false) }} + +And if the expression evaluates to a ``Twig_Template`` object, Twig will use it +directly:: + + // {{ include(template) }} + + $template = $twig->loadTemplate('some_template.twig'); + + $twig->loadTemplate('template.twig')->display(array('template' => $template)); + +When you set the ``ignore_missing`` flag, Twig will return an empty string if +the template does not exist: + +.. code-block:: jinja + + {{ include('sidebar.html', ignore_missing = true) }} + +You can also provide a list of templates that are checked for existence before +inclusion. The first template that exists will be rendered: + +.. code-block:: jinja + + {{ include(['page_detailed.html', 'page.html']) }} + +If ``ignore_missing`` is set, it will fall back to rendering nothing if none +of the templates exist, otherwise it will throw an exception. + +When including a template created by an end user, you should consider +sandboxing it: + +.. code-block:: jinja + + {{ include('page.html', sandboxed = true) }} + +Arguments +--------- + +* ``template``: The template to render +* ``variables``: The variables to pass to the template +* ``with_context``: Whether to pass the current context variables or not +* ``ignore_missing``: Whether to ignore missing templates or not +* ``sandboxed``: Whether to sandbox the template or not diff --git a/vendor/twig/twig/doc/functions/index.rst b/vendor/twig/twig/doc/functions/index.rst new file mode 100755 index 0000000..07214a7 --- /dev/null +++ b/vendor/twig/twig/doc/functions/index.rst @@ -0,0 +1,20 @@ +Functions +========= + +.. toctree:: + :maxdepth: 1 + + attribute + block + constant + cycle + date + dump + include + max + min + parent + random + range + source + template_from_string diff --git a/vendor/twig/twig/doc/functions/max.rst b/vendor/twig/twig/doc/functions/max.rst new file mode 100755 index 0000000..6f3cfc5 --- /dev/null +++ b/vendor/twig/twig/doc/functions/max.rst @@ -0,0 +1,20 @@ +``max`` +======= + +.. versionadded:: 1.15 + The ``max`` function was added in Twig 1.15. + +``max`` returns the biggest value of a sequence or a set of values: + +.. code-block:: jinja + + {{ max(1, 3, 2) }} + {{ max([1, 3, 2]) }} + +When called with a mapping, max ignores keys and only compares values: + +.. code-block:: jinja + + {{ max({2: "e", 1: "a", 3: "b", 5: "d", 4: "c"}) }} + {# returns "e" #} + diff --git a/vendor/twig/twig/doc/functions/min.rst b/vendor/twig/twig/doc/functions/min.rst new file mode 100755 index 0000000..7b6a65e --- /dev/null +++ b/vendor/twig/twig/doc/functions/min.rst @@ -0,0 +1,20 @@ +``min`` +======= + +.. versionadded:: 1.15 + The ``min`` function was added in Twig 1.15. + +``min`` returns the lowest value of a sequence or a set of values: + +.. code-block:: jinja + + {{ min(1, 3, 2) }} + {{ min([1, 3, 2]) }} + +When called with a mapping, min ignores keys and only compares values: + +.. code-block:: jinja + + {{ min({2: "e", 3: "a", 1: "b", 5: "d", 4: "c"}) }} + {# returns "a" #} + diff --git a/vendor/twig/twig/doc/functions/parent.rst b/vendor/twig/twig/doc/functions/parent.rst new file mode 100755 index 0000000..f5bd200 --- /dev/null +++ b/vendor/twig/twig/doc/functions/parent.rst @@ -0,0 +1,20 @@ +``parent`` +========== + +When a template uses inheritance, it's possible to render the contents of the +parent block when overriding a block by using the ``parent`` function: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% block sidebar %} +

Table Of Contents

+ ... + {{ parent() }} + {% endblock %} + +The ``parent()`` call will return the content of the ``sidebar`` block as +defined in the ``base.html`` template. + +.. seealso:: :doc:`extends<../tags/extends>`, :doc:`block<../functions/block>`, :doc:`block<../tags/block>` diff --git a/vendor/twig/twig/doc/functions/random.rst b/vendor/twig/twig/doc/functions/random.rst new file mode 100755 index 0000000..168e74f --- /dev/null +++ b/vendor/twig/twig/doc/functions/random.rst @@ -0,0 +1,29 @@ +``random`` +========== + +.. versionadded:: 1.5 + The ``random`` function was added in Twig 1.5. + +.. versionadded:: 1.6 + String and integer handling was added in Twig 1.6. + +The ``random`` function returns a random value depending on the supplied +parameter type: + +* a random item from a sequence; +* a random character from a string; +* a random integer between 0 and the integer parameter (inclusive). + +.. code-block:: jinja + + {{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #} + {{ random('ABC') }} {# example output: C #} + {{ random() }} {# example output: 15386094 (works as the native PHP mt_rand function) #} + {{ random(5) }} {# example output: 3 #} + +Arguments +--------- + +* ``values``: The values + +.. _`mt_rand`: http://php.net/mt_rand diff --git a/vendor/twig/twig/doc/functions/range.rst b/vendor/twig/twig/doc/functions/range.rst new file mode 100755 index 0000000..b7cd011 --- /dev/null +++ b/vendor/twig/twig/doc/functions/range.rst @@ -0,0 +1,45 @@ +``range`` +========= + +Returns a list containing an arithmetic progression of integers: + +.. code-block:: jinja + + {% for i in range(0, 3) %} + {{ i }}, + {% endfor %} + + {# outputs 0, 1, 2, 3, #} + +When step is given (as the third parameter), it specifies the increment (or +decrement): + +.. code-block:: jinja + + {% for i in range(0, 6, 2) %} + {{ i }}, + {% endfor %} + + {# outputs 0, 2, 4, 6, #} + +The Twig built-in ``..`` operator is just syntactic sugar for the ``range`` +function (with a step of 1): + +.. code-block:: jinja + + {% for i in 0..3 %} + {{ i }}, + {% endfor %} + +.. tip:: + + The ``range`` function works as the native PHP `range`_ function. + +Arguments +--------- + +* ``low``: The first value of the sequence. +* ``high``: The highest possible value of the sequence. +* ``step``: The increment between elements of the sequence. + +.. _`range`: http://php.net/range diff --git a/vendor/twig/twig/doc/functions/source.rst b/vendor/twig/twig/doc/functions/source.rst new file mode 100755 index 0000000..8ff39c2 --- /dev/null +++ b/vendor/twig/twig/doc/functions/source.rst @@ -0,0 +1,21 @@ +``source`` +========== + +.. versionadded:: 1.15 + The ``source`` function was added in Twig 1.15. + +The ``source`` function returns the content of a template without rendering it: + +.. code-block:: jinja + + {{ source('template.html') }} + {{ source(some_var) }} + +The function uses the same template loaders as the ones used to include +templates. So, if you are using the filesystem loader, the templates are looked +for in the paths defined by it. + +Arguments +--------- + +* ``name``: The name of the template to read diff --git a/vendor/twig/twig/doc/functions/template_from_string.rst b/vendor/twig/twig/doc/functions/template_from_string.rst new file mode 100755 index 0000000..ce6a60d --- /dev/null +++ b/vendor/twig/twig/doc/functions/template_from_string.rst @@ -0,0 +1,32 @@ +``template_from_string`` +======================== + +.. versionadded:: 1.11 + The ``template_from_string`` function was added in Twig 1.11. + +The ``template_from_string`` function loads a template from a string: + +.. code-block:: jinja + + {{ include(template_from_string("Hello {{ name }}")) }} + {{ include(template_from_string(page.template)) }} + +.. note:: + + The ``template_from_string`` function is not available by default. You + must add the ``Twig_Extension_StringLoader`` extension explicitly when + creating your Twig environment:: + + $twig = new Twig_Environment(...); + $twig->addExtension(new Twig_Extension_StringLoader()); + +.. note:: + + Even if you will probably always use the ``template_from_string`` function + with the ``include`` function, you can use it with any tag or function that + takes a template as an argument (like the ``embed`` or ``extends`` tags). + +Arguments +--------- + +* ``template``: The template diff --git a/vendor/twig/twig/doc/index.rst b/vendor/twig/twig/doc/index.rst new file mode 100755 index 0000000..358bd73 --- /dev/null +++ b/vendor/twig/twig/doc/index.rst @@ -0,0 +1,19 @@ +Twig +==== + +.. toctree:: + :maxdepth: 2 + + intro + installation + templates + api + advanced + internals + deprecated + recipes + coding_standards + tags/index + filters/index + functions/index + tests/index diff --git a/vendor/twig/twig/doc/installation.rst b/vendor/twig/twig/doc/installation.rst new file mode 100755 index 0000000..afdcf16 --- /dev/null +++ b/vendor/twig/twig/doc/installation.rst @@ -0,0 +1,116 @@ +Installation +============ + +You have multiple ways to install Twig. + +Installing the Twig PHP package +------------------------------- + +Installing via Composer (recommended) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Install `Composer`_ and run the following command to get the latest version: + +.. code-block:: bash + + composer require twig/twig:~1.0 + +Installing from the tarball release +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +1. Download the most recent tarball from the `download page`_ +2. Verify the integrity of the tarball http://fabien.potencier.org/article/73/signing-project-releases +3. Unpack the tarball +4. Move the files somewhere in your project + +Installing the development version +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: bash + + git clone git://github.com/twigphp/Twig.git + +Installing the PEAR package +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. note:: + + Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the last + version published on the PEAR channel; use Composer instead. + +.. code-block:: bash + + pear channel-discover pear.twig-project.org + pear install twig/Twig + +Installing the C extension +-------------------------- + +.. versionadded:: 1.4 + The C extension was added in Twig 1.4. + +.. note:: + + The C extension is **optional** but it brings some nice performance + improvements. Note that the extension is not a replacement for the PHP + code; it only implements a small part of the PHP code to improve the + performance at runtime; you must still install the regular PHP code. + +Twig comes with a C extension that enhances the performance of the Twig +runtime engine; install it like any other PHP extensions: + +.. code-block:: bash + + cd ext/twig + phpize + ./configure + make + make install + +.. note:: + + You can also install the C extension via PEAR (note that this method is + deprecated and newer versions of Twig are not available on the PEAR + channel): + + .. code-block:: bash + + pear channel-discover pear.twig-project.org + pear install twig/CTwig + +For Windows: + +1. Setup the build environment following the `PHP documentation`_ +2. Put Twig's C extension source code into ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig`` +3. Use the ``configure --disable-all --enable-cli --enable-twig=shared`` command instead of step 14 +4. ``nmake`` +5. Copy the ``C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll`` file to your PHP setup. + +.. tip:: + + For Windows ZendServer, ZTS is not enabled as mentioned in `Zend Server + FAQ`_. + + You have to use ``configure --disable-all --disable-zts --enable-cli + --enable-twig=shared`` to be able to build the twig C extension for + ZendServer. + + The built DLL will be available in + ``C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release`` + +Finally, enable the extension in your ``php.ini`` configuration file: + +.. code-block:: ini + + extension=twig.so #For Unix systems + extension=php_twig.dll #For Windows systems + +And from now on, Twig will automatically compile your templates to take +advantage of the C extension. Note that this extension does not replace the +PHP code but only provides an optimized version of the +``Twig_Template::getAttribute()`` method. + +.. _`download page`: https://github.com/twigphp/Twig/tags +.. _`Composer`: https://getcomposer.org/download/ +.. _`PHP documentation`: https://wiki.php.net/internals/windows/stepbystepbuild +.. _`Zend Server FAQ`: http://www.zend.com/en/products/server/faq#faqD6 diff --git a/vendor/twig/twig/doc/internals.rst b/vendor/twig/twig/doc/internals.rst new file mode 100755 index 0000000..a68796b --- /dev/null +++ b/vendor/twig/twig/doc/internals.rst @@ -0,0 +1,138 @@ +Twig Internals +============== + +Twig is very extensible and you can easily hack it. Keep in mind that you +should probably try to create an extension before hacking the core, as most +features and enhancements can be handled with extensions. This chapter is also +useful for people who want to understand how Twig works under the hood. + +How does Twig work? +------------------- + +The rendering of a Twig template can be summarized into four key steps: + +* **Load** the template: If the template is already compiled, load it and go + to the *evaluation* step, otherwise: + + * First, the **lexer** tokenizes the template source code into small pieces + for easier processing; + * Then, the **parser** converts the token stream into a meaningful tree + of nodes (the Abstract Syntax Tree); + * Eventually, the *compiler* transforms the AST into PHP code. + +* **Evaluate** the template: It basically means calling the ``display()`` + method of the compiled template and passing it the context. + +The Lexer +--------- + +The lexer tokenizes a template source code into a token stream (each token is +an instance of ``Twig_Token``, and the stream is an instance of +``Twig_TokenStream``). The default lexer recognizes 13 different token types: + +* ``Twig_Token::BLOCK_START_TYPE``, ``Twig_Token::BLOCK_END_TYPE``: Delimiters for blocks (``{% %}``) +* ``Twig_Token::VAR_START_TYPE``, ``Twig_Token::VAR_END_TYPE``: Delimiters for variables (``{{ }}``) +* ``Twig_Token::TEXT_TYPE``: A text outside an expression; +* ``Twig_Token::NAME_TYPE``: A name in an expression; +* ``Twig_Token::NUMBER_TYPE``: A number in an expression; +* ``Twig_Token::STRING_TYPE``: A string in an expression; +* ``Twig_Token::OPERATOR_TYPE``: An operator; +* ``Twig_Token::PUNCTUATION_TYPE``: A punctuation sign; +* ``Twig_Token::INTERPOLATION_START_TYPE``, ``Twig_Token::INTERPOLATION_END_TYPE`` (as of Twig 1.5): Delimiters for string interpolation; +* ``Twig_Token::EOF_TYPE``: Ends of template. + +You can manually convert a source code into a token stream by calling the +``tokenize()`` method of an environment:: + + $stream = $twig->tokenize($source, $identifier); + +As the stream has a ``__toString()`` method, you can have a textual +representation of it by echoing the object:: + + echo $stream."\n"; + +Here is the output for the ``Hello {{ name }}`` template: + +.. code-block:: text + + TEXT_TYPE(Hello ) + VAR_START_TYPE() + NAME_TYPE(name) + VAR_END_TYPE() + EOF_TYPE() + +.. note:: + + The default lexer (``Twig_Lexer``) can be changed by calling + the ``setLexer()`` method:: + + $twig->setLexer($lexer); + +The Parser +---------- + +The parser converts the token stream into an AST (Abstract Syntax Tree), or a +node tree (an instance of ``Twig_Node_Module``). The core extension defines +the basic nodes like: ``for``, ``if``, ... and the expression nodes. + +You can manually convert a token stream into a node tree by calling the +``parse()`` method of an environment:: + + $nodes = $twig->parse($stream); + +Echoing the node object gives you a nice representation of the tree:: + + echo $nodes."\n"; + +Here is the output for the ``Hello {{ name }}`` template: + +.. code-block:: text + + Twig_Node_Module( + Twig_Node_Text(Hello ) + Twig_Node_Print( + Twig_Node_Expression_Name(name) + ) + ) + +.. note:: + + The default parser (``Twig_TokenParser``) can be changed by calling the + ``setParser()`` method:: + + $twig->setParser($parser); + +The Compiler +------------ + +The last step is done by the compiler. It takes a node tree as an input and +generates PHP code usable for runtime execution of the template. + +You can manually compile a node tree to PHP code with the ``compile()`` method +of an environment:: + + $php = $twig->compile($nodes); + +The generated template for a ``Hello {{ name }}`` template reads as follows +(the actual output can differ depending on the version of Twig you are +using):: + + /* Hello {{ name }} */ + class __TwigTemplate_1121b6f109fe93ebe8c6e22e3712bceb extends Twig_Template + { + protected function doDisplay(array $context, array $blocks = array()) + { + // line 1 + echo "Hello "; + echo twig_escape_filter($this->env, $this->getContext($context, "name"), "html", null, true); + } + + // some more code + } + +.. note:: + + The default compiler (``Twig_Compiler``) can be changed by calling the + ``setCompiler()`` method:: + + $twig->setCompiler($compiler); diff --git a/vendor/twig/twig/doc/intro.rst b/vendor/twig/twig/doc/intro.rst new file mode 100755 index 0000000..773c476 --- /dev/null +++ b/vendor/twig/twig/doc/intro.rst @@ -0,0 +1,81 @@ +Introduction +============ + +This is the documentation for Twig, the flexible, fast, and secure template +engine for PHP. + +If you have any exposure to other text-based template languages, such as +Smarty, Django, or Jinja, you should feel right at home with Twig. It's both +designer and developer friendly by sticking to PHP's principles and adding +functionality useful for templating environments. + +The key-features are... + +* *Fast*: Twig compiles templates down to plain optimized PHP code. The + overhead compared to regular PHP code was reduced to the very minimum. + +* *Secure*: Twig has a sandbox mode to evaluate untrusted template code. This + allows Twig to be used as a template language for applications where users + may modify the template design. + +* *Flexible*: Twig is powered by a flexible lexer and parser. This allows the + developer to define its own custom tags and filters, and create its own DSL. + +Prerequisites +------------- + +Twig needs at least **PHP 5.2.4** to run. + +Installation +------------ + +The recommended way to install Twig is via Composer: + +.. code-block:: bash + + composer require "twig/twig:~1.0" + +.. note:: + + To learn more about the other installation methods, read the + :doc:`installation` chapter; it also explains how to install + the Twig C extension. + +Basic API Usage +--------------- + +This section gives you a brief introduction to the PHP API for Twig. + +.. code-block:: php + + require_once '/path/to/vendor/autoload.php'; + + $loader = new Twig_Loader_Array(array( + 'index' => 'Hello {{ name }}!', + )); + $twig = new Twig_Environment($loader); + + echo $twig->render('index', array('name' => 'Fabien')); + +Twig uses a loader (``Twig_Loader_Array``) to locate templates, and an +environment (``Twig_Environment``) to store the configuration. + +The ``render()`` method loads the template passed as a first argument and +renders it with the variables passed as a second argument. + +As templates are generally stored on the filesystem, Twig also comes with a +filesystem loader:: + + $loader = new Twig_Loader_Filesystem('/path/to/templates'); + $twig = new Twig_Environment($loader, array( + 'cache' => '/path/to/compilation_cache', + )); + + echo $twig->render('index.html', array('name' => 'Fabien')); + +.. tip:: + + If you are not using Composer, use the Twig built-in autoloader:: + + require_once '/path/to/lib/Twig/Autoloader.php'; + Twig_Autoloader::register(); diff --git a/vendor/twig/twig/doc/recipes.rst b/vendor/twig/twig/doc/recipes.rst new file mode 100755 index 0000000..86cede6 --- /dev/null +++ b/vendor/twig/twig/doc/recipes.rst @@ -0,0 +1,425 @@ +Recipes +======= + +Making a Layout conditional +--------------------------- + +Working with Ajax means that the same content is sometimes displayed as is, +and sometimes decorated with a layout. As Twig layout template names can be +any valid expression, you can pass a variable that evaluates to ``true`` when +the request is made via Ajax and choose the layout accordingly: + +.. code-block:: jinja + + {% extends request.ajax ? "base_ajax.html" : "base.html" %} + + {% block content %} + This is the content to be displayed. + {% endblock %} + +Making an Include dynamic +------------------------- + +When including a template, its name does not need to be a string. For +instance, the name can depend on the value of a variable: + +.. code-block:: jinja + + {% include var ~ '_foo.html' %} + +If ``var`` evaluates to ``index``, the ``index_foo.html`` template will be +rendered. + +As a matter of fact, the template name can be any valid expression, such as +the following: + +.. code-block:: jinja + + {% include var|default('index') ~ '_foo.html' %} + +Overriding a Template that also extends itself +---------------------------------------------- + +A template can be customized in two different ways: + +* *Inheritance*: A template *extends* a parent template and overrides some + blocks; + +* *Replacement*: If you use the filesystem loader, Twig loads the first + template it finds in a list of configured directories; a template found in a + directory *replaces* another one from a directory further in the list. + +But how do you combine both: *replace* a template that also extends itself +(aka a template in a directory further in the list)? + +Let's say that your templates are loaded from both ``.../templates/mysite`` +and ``.../templates/default`` in this order. The ``page.twig`` template, +stored in ``.../templates/default`` reads as follows: + +.. code-block:: jinja + + {# page.twig #} + {% extends "layout.twig" %} + + {% block content %} + {% endblock %} + +You can replace this template by putting a file with the same name in +``.../templates/mysite``. And if you want to extend the original template, you +might be tempted to write the following: + +.. code-block:: jinja + + {# page.twig in .../templates/mysite #} + {% extends "page.twig" %} {# from .../templates/default #} + +Of course, this will not work as Twig will always load the template from +``.../templates/mysite``. + +It turns out it is possible to get this to work, by adding a directory right +at the end of your template directories, which is the parent of all of the +other directories: ``.../templates`` in our case. This has the effect of +making every template file within our system uniquely addressable. Most of the +time you will use the "normal" paths, but in the special case of wanting to +extend a template with an overriding version of itself we can reference its +parent's full, unambiguous template path in the extends tag: + +.. code-block:: jinja + + {# page.twig in .../templates/mysite #} + {% extends "default/page.twig" %} {# from .../templates #} + +.. note:: + + This recipe was inspired by the following Django wiki page: + http://code.djangoproject.com/wiki/ExtendingTemplates + +Customizing the Syntax +---------------------- + +Twig allows some syntax customization for the block delimiters. It's not +recommended to use this feature as templates will be tied with your custom +syntax. But for specific projects, it can make sense to change the defaults. + +To change the block delimiters, you need to create your own lexer object:: + + $twig = new Twig_Environment(); + + $lexer = new Twig_Lexer($twig, array( + 'tag_comment' => array('{#', '#}'), + 'tag_block' => array('{%', '%}'), + 'tag_variable' => array('{{', '}}'), + 'interpolation' => array('#{', '}'), + )); + $twig->setLexer($lexer); + +Here are some configuration example that simulates some other template engines +syntax:: + + // Ruby erb syntax + $lexer = new Twig_Lexer($twig, array( + 'tag_comment' => array('<%#', '%>'), + 'tag_block' => array('<%', '%>'), + 'tag_variable' => array('<%=', '%>'), + )); + + // SGML Comment Syntax + $lexer = new Twig_Lexer($twig, array( + 'tag_comment' => array(''), + 'tag_block' => array(''), + 'tag_variable' => array('${', '}'), + )); + + // Smarty like + $lexer = new Twig_Lexer($twig, array( + 'tag_comment' => array('{*', '*}'), + 'tag_block' => array('{', '}'), + 'tag_variable' => array('{$', '}'), + )); + +Using dynamic Object Properties +------------------------------- + +When Twig encounters a variable like ``article.title``, it tries to find a +``title`` public property in the ``article`` object. + +It also works if the property does not exist but is rather defined dynamically +thanks to the magic ``__get()`` method; you just need to also implement the +``__isset()`` magic method like shown in the following snippet of code:: + + class Article + { + public function __get($name) + { + if ('title' == $name) { + return 'The title'; + } + + // throw some kind of error + } + + public function __isset($name) + { + if ('title' == $name) { + return true; + } + + return false; + } + } + +Accessing the parent Context in Nested Loops +-------------------------------------------- + +Sometimes, when using nested loops, you need to access the parent context. The +parent context is always accessible via the ``loop.parent`` variable. For +instance, if you have the following template data:: + + $data = array( + 'topics' => array( + 'topic1' => array('Message 1 of topic 1', 'Message 2 of topic 1'), + 'topic2' => array('Message 1 of topic 2', 'Message 2 of topic 2'), + ), + ); + +And the following template to display all messages in all topics: + +.. code-block:: jinja + + {% for topic, messages in topics %} + * {{ loop.index }}: {{ topic }} + {% for message in messages %} + - {{ loop.parent.loop.index }}.{{ loop.index }}: {{ message }} + {% endfor %} + {% endfor %} + +The output will be similar to: + +.. code-block:: text + + * 1: topic1 + - 1.1: The message 1 of topic 1 + - 1.2: The message 2 of topic 1 + * 2: topic2 + - 2.1: The message 1 of topic 2 + - 2.2: The message 2 of topic 2 + +In the inner loop, the ``loop.parent`` variable is used to access the outer +context. So, the index of the current ``topic`` defined in the outer for loop +is accessible via the ``loop.parent.loop.index`` variable. + +Defining undefined Functions and Filters on the Fly +--------------------------------------------------- + +When a function (or a filter) is not defined, Twig defaults to throw a +``Twig_Error_Syntax`` exception. However, it can also call a `callback`_ (any +valid PHP callable) which should return a function (or a filter). + +For filters, register callbacks with ``registerUndefinedFilterCallback()``. +For functions, use ``registerUndefinedFunctionCallback()``:: + + // auto-register all native PHP functions as Twig functions + // don't try this at home as it's not secure at all! + $twig->registerUndefinedFunctionCallback(function ($name) { + if (function_exists($name)) { + return new Twig_Function_Function($name); + } + + return false; + }); + +If the callable is not able to return a valid function (or filter), it must +return ``false``. + +If you register more than one callback, Twig will call them in turn until one +does not return ``false``. + +.. tip:: + + As the resolution of functions and filters is done during compilation, + there is no overhead when registering these callbacks. + +Validating the Template Syntax +------------------------------ + +When template code is provided by a third-party (through a web interface for +instance), it might be interesting to validate the template syntax before +saving it. If the template code is stored in a `$template` variable, here is +how you can do it:: + + try { + $twig->parse($twig->tokenize($template)); + + // the $template is valid + } catch (Twig_Error_Syntax $e) { + // $template contains one or more syntax errors + } + +If you iterate over a set of files, you can pass the filename to the +``tokenize()`` method to get the filename in the exception message:: + + foreach ($files as $file) { + try { + $twig->parse($twig->tokenize($template, $file)); + + // the $template is valid + } catch (Twig_Error_Syntax $e) { + // $template contains one or more syntax errors + } + } + +.. note:: + + This method won't catch any sandbox policy violations because the policy + is enforced during template rendering (as Twig needs the context for some + checks like allowed methods on objects). + +Refreshing modified Templates when APC is enabled and apc.stat = 0 +------------------------------------------------------------------ + +When using APC with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing +the template cache won't update the APC cache. To get around this, one can +extend ``Twig_Environment`` and force the update of the APC cache when Twig +rewrites the cache:: + + class Twig_Environment_APC extends Twig_Environment + { + protected function writeCacheFile($file, $content) + { + parent::writeCacheFile($file, $content); + + // Compile cached file into bytecode cache + apc_compile_file($file); + } + } + +Reusing a stateful Node Visitor +------------------------------- + +When attaching a visitor to a ``Twig_Environment`` instance, Twig uses it to +visit *all* templates it compiles. If you need to keep some state information +around, you probably want to reset it when visiting a new template. + +This can be easily achieved with the following code:: + + protected $someTemplateState = array(); + + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Module) { + // reset the state as we are entering a new template + $this->someTemplateState = array(); + } + + // ... + + return $node; + } + +Using a Database to store Templates +----------------------------------- + +If you are developing a CMS, templates are usually stored in a database. This +recipe gives you a simple PDO template loader you can use as a starting point +for your own. + +First, let's create a temporary in-memory SQLite3 database to work with:: + + $dbh = new PDO('sqlite::memory:'); + $dbh->exec('CREATE TABLE templates (name STRING, source STRING, last_modified INTEGER)'); + $base = '{% block content %}{% endblock %}'; + $index = ' + {% extends "base.twig" %} + {% block content %}Hello {{ name }}{% endblock %} + '; + $now = time(); + $dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('base.twig', '$base', $now)"); + $dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('index.twig', '$index', $now)"); + +We have created a simple ``templates`` table that hosts two templates: +``base.twig`` and ``index.twig``. + +Now, let's define a loader able to use this database:: + + class DatabaseTwigLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface + { + protected $dbh; + + public function __construct(PDO $dbh) + { + $this->dbh = $dbh; + } + + public function getSource($name) + { + if (false === $source = $this->getValue('source', $name)) { + throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name)); + } + + return $source; + } + + // Twig_ExistsLoaderInterface as of Twig 1.11 + public function exists($name) + { + return $name === $this->getValue('name', $name); + } + + public function getCacheKey($name) + { + return $name; + } + + public function isFresh($name, $time) + { + if (false === $lastModified = $this->getValue('last_modified', $name)) { + return false; + } + + return $lastModified <= $time; + } + + protected function getValue($column, $name) + { + $sth = $this->dbh->prepare('SELECT '.$column.' FROM templates WHERE name = :name'); + $sth->execute(array(':name' => (string) $name)); + + return $sth->fetchColumn(); + } + } + +Finally, here is an example on how you can use it:: + + $loader = new DatabaseTwigLoader($dbh); + $twig = new Twig_Environment($loader); + + echo $twig->render('index.twig', array('name' => 'Fabien')); + +Using different Template Sources +-------------------------------- + +This recipe is the continuation of the previous one. Even if you store the +contributed templates in a database, you might want to keep the original/base +templates on the filesystem. When templates can be loaded from different +sources, you need to use the ``Twig_Loader_Chain`` loader. + +As you can see in the previous recipe, we reference the template in the exact +same way as we would have done it with a regular filesystem loader. This is +the key to be able to mix and match templates coming from the database, the +filesystem, or any other loader for that matter: the template name should be a +logical name, and not the path from the filesystem:: + + $loader1 = new DatabaseTwigLoader($dbh); + $loader2 = new Twig_Loader_Array(array( + 'base.twig' => '{% block content %}{% endblock %}', + )); + $loader = new Twig_Loader_Chain(array($loader1, $loader2)); + + $twig = new Twig_Environment($loader); + + echo $twig->render('index.twig', array('name' => 'Fabien')); + +Now that the ``base.twig`` templates is defined in an array loader, you can +remove it from the database, and everything else will still work as before. + +.. _callback: http://www.php.net/manual/en/function.is-callable.php diff --git a/vendor/twig/twig/doc/tags/autoescape.rst b/vendor/twig/twig/doc/tags/autoescape.rst new file mode 100755 index 0000000..4208d1a --- /dev/null +++ b/vendor/twig/twig/doc/tags/autoescape.rst @@ -0,0 +1,83 @@ +``autoescape`` +============== + +Whether automatic escaping is enabled or not, you can mark a section of a +template to be escaped or not by using the ``autoescape`` tag: + +.. code-block:: jinja + + {# The following syntax works as of Twig 1.8 -- see the note below for previous versions #} + + {% autoescape %} + Everything will be automatically escaped in this block + using the HTML strategy + {% endautoescape %} + + {% autoescape 'html' %} + Everything will be automatically escaped in this block + using the HTML strategy + {% endautoescape %} + + {% autoescape 'js' %} + Everything will be automatically escaped in this block + using the js escaping strategy + {% endautoescape %} + + {% autoescape false %} + Everything will be outputted as is in this block + {% endautoescape %} + +.. note:: + + Before Twig 1.8, the syntax was different: + + .. code-block:: jinja + + {% autoescape true %} + Everything will be automatically escaped in this block + using the HTML strategy + {% endautoescape %} + + {% autoescape false %} + Everything will be outputted as is in this block + {% endautoescape %} + + {% autoescape true js %} + Everything will be automatically escaped in this block + using the js escaping strategy + {% endautoescape %} + +When automatic escaping is enabled everything is escaped by default except for +values explicitly marked as safe. Those can be marked in the template by using +the :doc:`raw<../filters/raw>` filter: + +.. code-block:: jinja + + {% autoescape %} + {{ safe_value|raw }} + {% endautoescape %} + +Functions returning template data (like :doc:`macros` and +:doc:`parent<../functions/parent>`) always return safe markup. + +.. note:: + + Twig is smart enough to not escape an already escaped value by the + :doc:`escape<../filters/escape>` filter. + +.. note:: + + Twig does not escape static expressions: + + .. code-block:: jinja + + {% set hello = "Hello" %} + {{ hello }} + {{ "world" }} + + Will be rendered "Hello **world**". + +.. note:: + + The chapter :doc:`Twig for Developers<../api>` gives more information + about when and how automatic escaping is applied. diff --git a/vendor/twig/twig/doc/tags/block.rst b/vendor/twig/twig/doc/tags/block.rst new file mode 100755 index 0000000..e380482 --- /dev/null +++ b/vendor/twig/twig/doc/tags/block.rst @@ -0,0 +1,11 @@ +``block`` +========= + +Blocks are used for inheritance and act as placeholders and replacements at +the same time. They are documented in detail in the documentation for the +:doc:`extends<../tags/extends>` tag. + +Block names should consist of alphanumeric characters, and underscores. Dashes +are not permitted. + +.. seealso:: :doc:`block<../functions/block>`, :doc:`parent<../functions/parent>`, :doc:`use<../tags/use>`, :doc:`extends<../tags/extends>` diff --git a/vendor/twig/twig/doc/tags/do.rst b/vendor/twig/twig/doc/tags/do.rst new file mode 100755 index 0000000..1c344e3 --- /dev/null +++ b/vendor/twig/twig/doc/tags/do.rst @@ -0,0 +1,12 @@ +``do`` +====== + +.. versionadded:: 1.5 + The ``do`` tag was added in Twig 1.5. + +The ``do`` tag works exactly like the regular variable expression (``{{ ... +}}``) just that it doesn't print anything: + +.. code-block:: jinja + + {% do 1 + 2 %} diff --git a/vendor/twig/twig/doc/tags/embed.rst b/vendor/twig/twig/doc/tags/embed.rst new file mode 100755 index 0000000..5a6a029 --- /dev/null +++ b/vendor/twig/twig/doc/tags/embed.rst @@ -0,0 +1,178 @@ +``embed`` +========= + +.. versionadded:: 1.8 + The ``embed`` tag was added in Twig 1.8. + +The ``embed`` tag combines the behaviour of :doc:`include` and +:doc:`extends`. +It allows you to include another template's contents, just like ``include`` +does. But it also allows you to override any block defined inside the +included template, like when extending a template. + +Think of an embedded template as a "micro layout skeleton". + +.. code-block:: jinja + + {% embed "teasers_skeleton.twig" %} + {# These blocks are defined in "teasers_skeleton.twig" #} + {# and we override them right here: #} + {% block left_teaser %} + Some content for the left teaser box + {% endblock %} + {% block right_teaser %} + Some content for the right teaser box + {% endblock %} + {% endembed %} + +The ``embed`` tag takes the idea of template inheritance to the level of +content fragments. While template inheritance allows for "document skeletons", +which are filled with life by child templates, the ``embed`` tag allows you to +create "skeletons" for smaller units of content and re-use and fill them +anywhere you like. + +Since the use case may not be obvious, let's look at a simplified example. +Imagine a base template shared by multiple HTML pages, defining a single block +named "content": + +.. code-block:: text + + ┌─── page layout ─────────────────────┐ + │ │ + │ ┌── block "content" ──┐ │ + │ │ │ │ + │ │ │ │ + │ │ (child template to │ │ + │ │ put content here) │ │ + │ │ │ │ + │ │ │ │ + │ └─────────────────────┘ │ + │ │ + └─────────────────────────────────────┘ + +Some pages ("foo" and "bar") share the same content structure - +two vertically stacked boxes: + +.. code-block:: text + + ┌─── page layout ─────────────────────┐ + │ │ + │ ┌── block "content" ──┐ │ + │ │ ┌─ block "top" ───┐ │ │ + │ │ │ │ │ │ + │ │ └─────────────────┘ │ │ + │ │ ┌─ block "bottom" ┐ │ │ + │ │ │ │ │ │ + │ │ └─────────────────┘ │ │ + │ └─────────────────────┘ │ + │ │ + └─────────────────────────────────────┘ + +While other pages ("boom" and "baz") share a different content structure - +two boxes side by side: + +.. code-block:: text + + ┌─── page layout ─────────────────────┐ + │ │ + │ ┌── block "content" ──┐ │ + │ │ │ │ + │ │ ┌ block ┐ ┌ block ┐ │ │ + │ │ │"left" │ │"right"│ │ │ + │ │ │ │ │ │ │ │ + │ │ │ │ │ │ │ │ + │ │ └───────┘ └───────┘ │ │ + │ └─────────────────────┘ │ + │ │ + └─────────────────────────────────────┘ + +Without the ``embed`` tag, you have two ways to design your templates: + + * Create two "intermediate" base templates that extend the master layout + template: one with vertically stacked boxes to be used by the "foo" and + "bar" pages and another one with side-by-side boxes for the "boom" and + "baz" pages. + + * Embed the markup for the top/bottom and left/right boxes into each page + template directly. + +These two solutions do not scale well because they each have a major drawback: + + * The first solution may indeed work for this simplified example. But imagine + we add a sidebar, which may again contain different, recurring structures + of content. Now we would need to create intermediate base templates for + all occurring combinations of content structure and sidebar structure... + and so on. + + * The second solution involves duplication of common code with all its negative + consequences: any change involves finding and editing all affected copies + of the structure, correctness has to be verified for each copy, copies may + go out of sync by careless modifications etc. + +In such a situation, the ``embed`` tag comes in handy. The common layout +code can live in a single base template, and the two different content structures, +let's call them "micro layouts" go into separate templates which are embedded +as necessary: + +Page template ``foo.twig``: + +.. code-block:: jinja + + {% extends "layout_skeleton.twig" %} + + {% block content %} + {% embed "vertical_boxes_skeleton.twig" %} + {% block top %} + Some content for the top box + {% endblock %} + + {% block bottom %} + Some content for the bottom box + {% endblock %} + {% endembed %} + {% endblock %} + +And here is the code for ``vertical_boxes_skeleton.twig``: + +.. code-block:: html+jinja + +
+ {% block top %} + Top box default content + {% endblock %} +
+ +
+ {% block bottom %} + Bottom box default content + {% endblock %} +
+ +The goal of the ``vertical_boxes_skeleton.twig`` template being to factor +out the HTML markup for the boxes. + +The ``embed`` tag takes the exact same arguments as the ``include`` tag: + +.. code-block:: jinja + + {% embed "base" with {'foo': 'bar'} %} + ... + {% endembed %} + + {% embed "base" with {'foo': 'bar'} only %} + ... + {% endembed %} + + {% embed "base" ignore missing %} + ... + {% endembed %} + +.. warning:: + + As embedded templates do not have "names", auto-escaping strategies based + on the template "filename" won't work as expected if you change the + context (for instance, if you embed a CSS/JavaScript template into an HTML + one). In that case, explicitly set the default auto-escaping strategy with + the ``autoescape`` tag. + +.. seealso:: :doc:`include<../tags/include>` diff --git a/vendor/twig/twig/doc/tags/extends.rst b/vendor/twig/twig/doc/tags/extends.rst new file mode 100755 index 0000000..1ad2b12 --- /dev/null +++ b/vendor/twig/twig/doc/tags/extends.rst @@ -0,0 +1,268 @@ +``extends`` +=========== + +The ``extends`` tag can be used to extend a template from another one. + +.. note:: + + Like PHP, Twig does not support multiple inheritance. So you can only have + one extends tag called per rendering. However, Twig supports horizontal + :doc:`reuse`. + +Let's define a base template, ``base.html``, which defines a simple HTML +skeleton document: + +.. code-block:: html+jinja + + + + + {% block head %} + + {% block title %}{% endblock %} - My Webpage + {% endblock %} + + +
{% block content %}{% endblock %}
+ + + + +In this example, the :doc:`block` tags define four blocks that child +templates can fill in. + +All the ``block`` tag does is to tell the template engine that a child +template may override those portions of the template. + +Child Template +-------------- + +A child template might look like this: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% block title %}Index{% endblock %} + {% block head %} + {{ parent() }} + + {% endblock %} + {% block content %} +

Index

+

+ Welcome on my awesome homepage. +

+ {% endblock %} + +The ``extends`` tag is the key here. It tells the template engine that this +template "extends" another template. When the template system evaluates this +template, first it locates the parent. The extends tag should be the first tag +in the template. + +Note that since the child template doesn't define the ``footer`` block, the +value from the parent template is used instead. + +You can't define multiple ``block`` tags with the same name in the same +template. This limitation exists because a block tag works in "both" +directions. That is, a block tag doesn't just provide a hole to fill - it also +defines the content that fills the hole in the *parent*. If there were two +similarly-named ``block`` tags in a template, that template's parent wouldn't +know which one of the blocks' content to use. + +If you want to print a block multiple times you can however use the +``block`` function: + +.. code-block:: jinja + + {% block title %}{% endblock %} +

{{ block('title') }}

+ {% block body %}{% endblock %} + +Parent Blocks +------------- + +It's possible to render the contents of the parent block by using the +:doc:`parent<../functions/parent>` function. This gives back the results of +the parent block: + +.. code-block:: jinja + + {% block sidebar %} +

Table Of Contents

+ ... + {{ parent() }} + {% endblock %} + +Named Block End-Tags +-------------------- + +Twig allows you to put the name of the block after the end tag for better +readability: + +.. code-block:: jinja + + {% block sidebar %} + {% block inner_sidebar %} + ... + {% endblock inner_sidebar %} + {% endblock sidebar %} + +Of course, the name after the ``endblock`` word must match the block name. + +Block Nesting and Scope +----------------------- + +Blocks can be nested for more complex layouts. Per default, blocks have access +to variables from outer scopes: + +.. code-block:: jinja + + {% for item in seq %} +
  • {% block loop_item %}{{ item }}{% endblock %}
  • + {% endfor %} + +Block Shortcuts +--------------- + +For blocks with few content, it's possible to use a shortcut syntax. The +following constructs do the same: + +.. code-block:: jinja + + {% block title %} + {{ page_title|title }} + {% endblock %} + +.. code-block:: jinja + + {% block title page_title|title %} + +Dynamic Inheritance +------------------- + +Twig supports dynamic inheritance by using a variable as the base template: + +.. code-block:: jinja + + {% extends some_var %} + +If the variable evaluates to a ``Twig_Template`` object, Twig will use it as +the parent template:: + + // {% extends layout %} + + $layout = $twig->loadTemplate('some_layout_template.twig'); + + $twig->display('template.twig', array('layout' => $layout)); + +.. versionadded:: 1.2 + The possibility to pass an array of templates has been added in Twig 1.2. + +You can also provide a list of templates that are checked for existence. The +first template that exists will be used as a parent: + +.. code-block:: jinja + + {% extends ['layout.html', 'base_layout.html'] %} + +Conditional Inheritance +----------------------- + +As the template name for the parent can be any valid Twig expression, it's +possible to make the inheritance mechanism conditional: + +.. code-block:: jinja + + {% extends standalone ? "minimum.html" : "base.html" %} + +In this example, the template will extend the "minimum.html" layout template +if the ``standalone`` variable evaluates to ``true``, and "base.html" +otherwise. + +How do blocks work? +------------------- + +A block provides a way to change how a certain part of a template is rendered +but it does not interfere in any way with the logic around it. + +Let's take the following example to illustrate how a block works and more +importantly, how it does not work: + +.. code-block:: jinja + + {# base.twig #} + + {% for post in posts %} + {% block post %} +

    {{ post.title }}

    +

    {{ post.body }}

    + {% endblock %} + {% endfor %} + +If you render this template, the result would be exactly the same with or +without the ``block`` tag. The ``block`` inside the ``for`` loop is just a way +to make it overridable by a child template: + +.. code-block:: jinja + + {# child.twig #} + + {% extends "base.twig" %} + + {% block post %} +
    +
    {{ post.title }}
    +
    {{ post.text }}
    +
    + {% endblock %} + +Now, when rendering the child template, the loop is going to use the block +defined in the child template instead of the one defined in the base one; the +executed template is then equivalent to the following one: + +.. code-block:: jinja + + {% for post in posts %} +
    +
    {{ post.title }}
    +
    {{ post.text }}
    +
    + {% endfor %} + +Let's take another example: a block included within an ``if`` statement: + +.. code-block:: jinja + + {% if posts is empty %} + {% block head %} + {{ parent() }} + + + {% endblock head %} + {% endif %} + +Contrary to what you might think, this template does not define a block +conditionally; it just makes overridable by a child template the output of +what will be rendered when the condition is ``true``. + +If you want the output to be displayed conditionally, use the following +instead: + +.. code-block:: jinja + + {% block head %} + {{ parent() }} + + {% if posts is empty %} + + {% endif %} + {% endblock head %} + +.. seealso:: :doc:`block<../functions/block>`, :doc:`block<../tags/block>`, :doc:`parent<../functions/parent>`, :doc:`use<../tags/use>` diff --git a/vendor/twig/twig/doc/tags/filter.rst b/vendor/twig/twig/doc/tags/filter.rst new file mode 100755 index 0000000..82ca5c6 --- /dev/null +++ b/vendor/twig/twig/doc/tags/filter.rst @@ -0,0 +1,21 @@ +``filter`` +========== + +Filter sections allow you to apply regular Twig filters on a block of template +data. Just wrap the code in the special ``filter`` section: + +.. code-block:: jinja + + {% filter upper %} + This text becomes uppercase + {% endfilter %} + +You can also chain filters: + +.. code-block:: jinja + + {% filter lower|escape %} + SOME TEXT + {% endfilter %} + + {# outputs "<strong>some text</strong>" #} diff --git a/vendor/twig/twig/doc/tags/flush.rst b/vendor/twig/twig/doc/tags/flush.rst new file mode 100755 index 0000000..55ef593 --- /dev/null +++ b/vendor/twig/twig/doc/tags/flush.rst @@ -0,0 +1,17 @@ +``flush`` +========= + +.. versionadded:: 1.5 + The flush tag was added in Twig 1.5. + +The ``flush`` tag tells Twig to flush the output buffer: + +.. code-block:: jinja + + {% flush %} + +.. note:: + + Internally, Twig uses the PHP `flush`_ function. + +.. _`flush`: http://php.net/flush diff --git a/vendor/twig/twig/doc/tags/for.rst b/vendor/twig/twig/doc/tags/for.rst new file mode 100755 index 0000000..0673b55 --- /dev/null +++ b/vendor/twig/twig/doc/tags/for.rst @@ -0,0 +1,172 @@ +``for`` +======= + +Loop over each item in a sequence. For example, to display a list of users +provided in a variable called ``users``: + +.. code-block:: jinja + +

    Members

    +
      + {% for user in users %} +
    • {{ user.username|e }}
    • + {% endfor %} +
    + +.. note:: + + A sequence can be either an array or an object implementing the + ``Traversable`` interface. + +If you do need to iterate over a sequence of numbers, you can use the ``..`` +operator: + +.. code-block:: jinja + + {% for i in 0..10 %} + * {{ i }} + {% endfor %} + +The above snippet of code would print all numbers from 0 to 10. + +It can be also useful with letters: + +.. code-block:: jinja + + {% for letter in 'a'..'z' %} + * {{ letter }} + {% endfor %} + +The ``..`` operator can take any expression at both sides: + +.. code-block:: jinja + + {% for letter in 'a'|upper..'z'|upper %} + * {{ letter }} + {% endfor %} + +.. tip: + + If you need a step different from 1, you can use the ``range`` function + instead. + +The `loop` variable +------------------- + +Inside of a ``for`` loop block you can access some special variables: + +===================== ============================================================= +Variable Description +===================== ============================================================= +``loop.index`` The current iteration of the loop. (1 indexed) +``loop.index0`` The current iteration of the loop. (0 indexed) +``loop.revindex`` The number of iterations from the end of the loop (1 indexed) +``loop.revindex0`` The number of iterations from the end of the loop (0 indexed) +``loop.first`` True if first iteration +``loop.last`` True if last iteration +``loop.length`` The number of items in the sequence +``loop.parent`` The parent context +===================== ============================================================= + +.. code-block:: jinja + + {% for user in users %} + {{ loop.index }} - {{ user.username }} + {% endfor %} + +.. note:: + + The ``loop.length``, ``loop.revindex``, ``loop.revindex0``, and + ``loop.last`` variables are only available for PHP arrays, or objects that + implement the ``Countable`` interface. They are also not available when + looping with a condition. + +.. versionadded:: 1.2 + The ``if`` modifier support has been added in Twig 1.2. + +Adding a condition +------------------ + +Unlike in PHP, it's not possible to ``break`` or ``continue`` in a loop. You +can however filter the sequence during iteration which allows you to skip +items. The following example skips all the users which are not active: + +.. code-block:: jinja + +
      + {% for user in users if user.active %} +
    • {{ user.username|e }}
    • + {% endfor %} +
    + +The advantage is that the special loop variable will count correctly thus not +counting the users not iterated over. Keep in mind that properties like +``loop.last`` will not be defined when using loop conditions. + +.. note:: + + Using the ``loop`` variable within the condition is not recommended as it + will probably not be doing what you expect it to. For instance, adding a + condition like ``loop.index > 4`` won't work as the index is only + incremented when the condition is true (so the condition will never + match). + +The `else` Clause +----------------- + +If no iteration took place because the sequence was empty, you can render a +replacement block by using ``else``: + +.. code-block:: jinja + +
      + {% for user in users %} +
    • {{ user.username|e }}
    • + {% else %} +
    • no user found
    • + {% endfor %} +
    + +Iterating over Keys +------------------- + +By default, a loop iterates over the values of the sequence. You can iterate +on keys by using the ``keys`` filter: + +.. code-block:: jinja + +

    Members

    +
      + {% for key in users|keys %} +
    • {{ key }}
    • + {% endfor %} +
    + +Iterating over Keys and Values +------------------------------ + +You can also access both keys and values: + +.. code-block:: jinja + +

    Members

    +
      + {% for key, user in users %} +
    • {{ key }}: {{ user.username|e }}
    • + {% endfor %} +
    + +Iterating over a Subset +----------------------- + +You might want to iterate over a subset of values. This can be achieved using +the :doc:`slice <../filters/slice>` filter: + +.. code-block:: jinja + +

    Top Ten Members

    +
      + {% for user in users|slice(0, 10) %} +
    • {{ user.username|e }}
    • + {% endfor %} +
    diff --git a/vendor/twig/twig/doc/tags/from.rst b/vendor/twig/twig/doc/tags/from.rst new file mode 100755 index 0000000..39334fd --- /dev/null +++ b/vendor/twig/twig/doc/tags/from.rst @@ -0,0 +1,8 @@ +``from`` +======== + +The ``from`` tag imports :doc:`macro<../tags/macro>` names into the current +namespace. The tag is documented in detail in the documentation for the +:doc:`import<../tags/import>` tag. + +.. seealso:: :doc:`macro<../tags/macro>`, :doc:`import<../tags/import>` diff --git a/vendor/twig/twig/doc/tags/if.rst b/vendor/twig/twig/doc/tags/if.rst new file mode 100755 index 0000000..12edf98 --- /dev/null +++ b/vendor/twig/twig/doc/tags/if.rst @@ -0,0 +1,76 @@ +``if`` +====== + +The ``if`` statement in Twig is comparable with the if statements of PHP. + +In the simplest form you can use it to test if an expression evaluates to +``true``: + +.. code-block:: jinja + + {% if online == false %} +

    Our website is in maintenance mode. Please, come back later.

    + {% endif %} + +You can also test if an array is not empty: + +.. code-block:: jinja + + {% if users %} +
      + {% for user in users %} +
    • {{ user.username|e }}
    • + {% endfor %} +
    + {% endif %} + +.. note:: + + If you want to test if the variable is defined, use ``if users is + defined`` instead. + +You can also use ``not`` to check for values that evaluate to ``false``: + +.. code-block:: jinja + + {% if not user.subscribed %} +

    You are not subscribed to our mailing list.

    + {% endif %} + +For multiple conditions, ``and`` and ``or`` can be used: + +.. code-block:: jinja + + {% if temperature > 18 and temperature < 27 %} +

    It's a nice day for a walk in the park.

    + {% endif %} + +For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can +use more complex ``expressions`` there too: + +.. code-block:: jinja + + {% if kenny.sick %} + Kenny is sick. + {% elseif kenny.dead %} + You killed Kenny! You bastard!!! + {% else %} + Kenny looks okay --- so far + {% endif %} + +.. note:: + + The rules to determine if an expression is ``true`` or ``false`` are the + same as in PHP; here are the edge cases rules: + + ====================== ==================== + Value Boolean evaluation + ====================== ==================== + empty string false + numeric zero false + whitespace-only string true + empty array false + null false + non-empty array true + object true + ====================== ==================== diff --git a/vendor/twig/twig/doc/tags/import.rst b/vendor/twig/twig/doc/tags/import.rst new file mode 100755 index 0000000..21a1e19 --- /dev/null +++ b/vendor/twig/twig/doc/tags/import.rst @@ -0,0 +1,57 @@ +``import`` +========== + +Twig supports putting often used code into :doc:`macros<../tags/macro>`. These +macros can go into different templates and get imported from there. + +There are two ways to import templates. You can import the complete template +into a variable or request specific macros from it. + +Imagine we have a helper module that renders forms (called ``forms.html``): + +.. code-block:: jinja + + {% macro input(name, value, type, size) %} + + {% endmacro %} + + {% macro textarea(name, value, rows, cols) %} + + {% endmacro %} + +The easiest and most flexible is importing the whole module into a variable. +That way you can access the attributes: + +.. code-block:: jinja + + {% import 'forms.html' as forms %} + +
    +
    Username
    +
    {{ forms.input('username') }}
    +
    Password
    +
    {{ forms.input('password', null, 'password') }}
    +
    +

    {{ forms.textarea('comment') }}

    + +Alternatively you can import names from the template into the current +namespace: + +.. code-block:: jinja + + {% from 'forms.html' import input as input_field, textarea %} + +
    +
    Username
    +
    {{ input_field('username') }}
    +
    Password
    +
    {{ input_field('password', '', 'password') }}
    +
    +

    {{ textarea('comment') }}

    + +.. tip:: + + To import macros from the current file, use the special ``_self`` variable + for the source. + +.. seealso:: :doc:`macro<../tags/macro>`, :doc:`from<../tags/from>` diff --git a/vendor/twig/twig/doc/tags/include.rst b/vendor/twig/twig/doc/tags/include.rst new file mode 100755 index 0000000..da18dc6 --- /dev/null +++ b/vendor/twig/twig/doc/tags/include.rst @@ -0,0 +1,86 @@ +``include`` +=========== + +The ``include`` statement includes a template and returns the rendered content +of that file into the current namespace: + +.. code-block:: jinja + + {% include 'header.html' %} + Body + {% include 'footer.html' %} + +Included templates have access to the variables of the active context. + +If you are using the filesystem loader, the templates are looked for in the +paths defined by it. + +You can add additional variables by passing them after the ``with`` keyword: + +.. code-block:: jinja + + {# template.html will have access to the variables from the current context and the additional ones provided #} + {% include 'template.html' with {'foo': 'bar'} %} + + {% set vars = {'foo': 'bar'} %} + {% include 'template.html' with vars %} + +You can disable access to the context by appending the ``only`` keyword: + +.. code-block:: jinja + + {# only the foo variable will be accessible #} + {% include 'template.html' with {'foo': 'bar'} only %} + +.. code-block:: jinja + + {# no variables will be accessible #} + {% include 'template.html' only %} + +.. tip:: + + When including a template created by an end user, you should consider + sandboxing it. More information in the :doc:`Twig for Developers<../api>` + chapter and in the :doc:`sandbox<../tags/sandbox>` tag documentation. + +The template name can be any valid Twig expression: + +.. code-block:: jinja + + {% include some_var %} + {% include ajax ? 'ajax.html' : 'not_ajax.html' %} + +And if the expression evaluates to a ``Twig_Template`` object, Twig will use it +directly:: + + // {% include template %} + + $template = $twig->loadTemplate('some_template.twig'); + + $twig->loadTemplate('template.twig')->display(array('template' => $template)); + +.. versionadded:: 1.2 + The ``ignore missing`` feature has been added in Twig 1.2. + +You can mark an include with ``ignore missing`` in which case Twig will ignore +the statement if the template to be included does not exist. It has to be +placed just after the template name. Here some valid examples: + +.. code-block:: jinja + + {% include 'sidebar.html' ignore missing %} + {% include 'sidebar.html' ignore missing with {'foo': 'bar'} %} + {% include 'sidebar.html' ignore missing only %} + +.. versionadded:: 1.2 + The possibility to pass an array of templates has been added in Twig 1.2. + +You can also provide a list of templates that are checked for existence before +inclusion. The first template that exists will be included: + +.. code-block:: jinja + + {% include ['page_detailed.html', 'page.html'] %} + +If ``ignore missing`` is given, it will fall back to rendering nothing if none +of the templates exist, otherwise it will throw an exception. diff --git a/vendor/twig/twig/doc/tags/index.rst b/vendor/twig/twig/doc/tags/index.rst new file mode 100755 index 0000000..e6a632b --- /dev/null +++ b/vendor/twig/twig/doc/tags/index.rst @@ -0,0 +1,24 @@ +Tags +==== + +.. toctree:: + :maxdepth: 1 + + autoescape + block + do + embed + extends + filter + flush + for + from + if + import + include + macro + sandbox + set + spaceless + use + verbatim diff --git a/vendor/twig/twig/doc/tags/macro.rst b/vendor/twig/twig/doc/tags/macro.rst new file mode 100755 index 0000000..11c115a --- /dev/null +++ b/vendor/twig/twig/doc/tags/macro.rst @@ -0,0 +1,83 @@ +``macro`` +========= + +Macros are comparable with functions in regular programming languages. They +are useful to put often used HTML idioms into reusable elements to not repeat +yourself. + +Here is a small example of a macro that renders a form element: + +.. code-block:: jinja + + {% macro input(name, value, type, size) %} + + {% endmacro %} + +Macros differs from native PHP functions in a few ways: + +* Default argument values are defined by using the ``default`` filter in the + macro body; + +* Arguments of a macro are always optional. + +But as with PHP functions, macros don't have access to the current template +variables. + +.. tip:: + + You can pass the whole context as an argument by using the special + ``_context`` variable. + +Macros can be defined in any template, and need to be "imported" before being +used (see the documentation for the :doc:`import<../tags/import>` tag for more +information): + +.. code-block:: jinja + + {% import "forms.html" as forms %} + +The above ``import`` call imports the "forms.html" file (which can contain only +macros, or a template and some macros), and import the functions as items of +the ``forms`` variable. + +The macro can then be called at will: + +.. code-block:: jinja + +

    {{ forms.input('username') }}

    +

    {{ forms.input('password', null, 'password') }}

    + +If macros are defined and used in the same template, you can use the +special ``_self`` variable to import them: + +.. code-block:: jinja + + {% import _self as forms %} + +

    {{ forms.input('username') }}

    + +.. warning:: + + When you define a macro in the template where you are going to use it, you + might be tempted to call the macro directly via ``_self.input()`` instead + of importing it; even if seems to work, this is just a side-effect of the + current implementation and it won't work anymore in Twig 2.x. + +When you want to use a macro in another macro from the same file, you need to +import it locally: + +.. code-block:: jinja + + {% macro input(name, value, type, size) %} + + {% endmacro %} + + {% macro wrapped_input(name, value, type, size) %} + {% import _self as forms %} + +
    + {{ forms.input(name, value, type, size) }} +
    + {% endmacro %} + +.. seealso:: :doc:`from<../tags/from>`, :doc:`import<../tags/import>` diff --git a/vendor/twig/twig/doc/tags/sandbox.rst b/vendor/twig/twig/doc/tags/sandbox.rst new file mode 100755 index 0000000..e186726 --- /dev/null +++ b/vendor/twig/twig/doc/tags/sandbox.rst @@ -0,0 +1,30 @@ +``sandbox`` +=========== + +The ``sandbox`` tag can be used to enable the sandboxing mode for an included +template, when sandboxing is not enabled globally for the Twig environment: + +.. code-block:: jinja + + {% sandbox %} + {% include 'user.html' %} + {% endsandbox %} + +.. warning:: + + The ``sandbox`` tag is only available when the sandbox extension is + enabled (see the :doc:`Twig for Developers<../api>` chapter). + +.. note:: + + The ``sandbox`` tag can only be used to sandbox an include tag and it + cannot be used to sandbox a section of a template. The following example + won't work: + + .. code-block:: jinja + + {% sandbox %} + {% for i in 1..2 %} + {{ i }} + {% endfor %} + {% endsandbox %} diff --git a/vendor/twig/twig/doc/tags/set.rst b/vendor/twig/twig/doc/tags/set.rst new file mode 100755 index 0000000..3eba239 --- /dev/null +++ b/vendor/twig/twig/doc/tags/set.rst @@ -0,0 +1,78 @@ +``set`` +======= + +Inside code blocks you can also assign values to variables. Assignments use +the ``set`` tag and can have multiple targets. + +Here is how you can assign the ``bar`` value to the ``foo`` variable: + +.. code-block:: jinja + + {% set foo = 'bar' %} + +After the ``set`` call, the ``foo`` variable is available in the template like +any other ones: + +.. code-block:: jinja + + {# displays bar #} + {{ foo }} + +The assigned value can be any valid :ref:`Twig expressions +`: + +.. code-block:: jinja + + {% set foo = [1, 2] %} + {% set foo = {'foo': 'bar'} %} + {% set foo = 'foo' ~ 'bar' %} + +Several variables can be assigned in one block: + +.. code-block:: jinja + + {% set foo, bar = 'foo', 'bar' %} + + {# is equivalent to #} + + {% set foo = 'foo' %} + {% set bar = 'bar' %} + +The ``set`` tag can also be used to 'capture' chunks of text: + +.. code-block:: jinja + + {% set foo %} + + {% endset %} + +.. caution:: + + If you enable automatic output escaping, Twig will only consider the + content to be safe when capturing chunks of text. + +.. note:: + + Note that loops are scoped in Twig; therefore a variable declared inside a + ``for`` loop is not accessible outside the loop itself: + + .. code-block:: jinja + + {% for item in list %} + {% set foo = item %} + {% endfor %} + + {# foo is NOT available #} + + If you want to access the variable, just declare it before the loop: + + .. code-block:: jinja + + {% set foo = "" %} + {% for item in list %} + {% set foo = item %} + {% endfor %} + + {# foo is available #} diff --git a/vendor/twig/twig/doc/tags/spaceless.rst b/vendor/twig/twig/doc/tags/spaceless.rst new file mode 100755 index 0000000..b39cb27 --- /dev/null +++ b/vendor/twig/twig/doc/tags/spaceless.rst @@ -0,0 +1,37 @@ +``spaceless`` +============= + +Use the ``spaceless`` tag to remove whitespace *between HTML tags*, not +whitespace within HTML tags or whitespace in plain text: + +.. code-block:: jinja + + {% spaceless %} +
    + foo +
    + {% endspaceless %} + + {# output will be
    foo
    #} + +This tag is not meant to "optimize" the size of the generated HTML content but +merely to avoid extra whitespace between HTML tags to avoid browser rendering +quirks under some circumstances. + +.. tip:: + + If you want to optimize the size of the generated HTML content, gzip + compress the output instead. + +.. tip:: + + If you want to create a tag that actually removes all extra whitespace in + an HTML string, be warned that this is not as easy as it seems to be + (think of ``textarea`` or ``pre`` tags for instance). Using a third-party + library like Tidy is probably a better idea. + +.. tip:: + + For more information on whitespace control, read the + :ref:`dedicated section ` of the documentation and learn how + you can also use the whitespace control modifier on your tags. diff --git a/vendor/twig/twig/doc/tags/use.rst b/vendor/twig/twig/doc/tags/use.rst new file mode 100755 index 0000000..a2f3af0 --- /dev/null +++ b/vendor/twig/twig/doc/tags/use.rst @@ -0,0 +1,124 @@ +``use`` +======= + +.. versionadded:: 1.1 + Horizontal reuse was added in Twig 1.1. + +.. note:: + + Horizontal reuse is an advanced Twig feature that is hardly ever needed in + regular templates. It is mainly used by projects that need to make + template blocks reusable without using inheritance. + +Template inheritance is one of the most powerful Twig's feature but it is +limited to single inheritance; a template can only extend one other template. +This limitation makes template inheritance simple to understand and easy to +debug: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% block title %}{% endblock %} + {% block content %}{% endblock %} + +Horizontal reuse is a way to achieve the same goal as multiple inheritance, +but without the associated complexity: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% use "blocks.html" %} + + {% block title %}{% endblock %} + {% block content %}{% endblock %} + +The ``use`` statement tells Twig to import the blocks defined in +``blocks.html`` into the current template (it's like macros, but for blocks): + +.. code-block:: jinja + + {# blocks.html #} + + {% block sidebar %}{% endblock %} + +In this example, the ``use`` statement imports the ``sidebar`` block into the +main template. The code is mostly equivalent to the following one (the +imported blocks are not outputted automatically): + +.. code-block:: jinja + + {% extends "base.html" %} + + {% block sidebar %}{% endblock %} + {% block title %}{% endblock %} + {% block content %}{% endblock %} + +.. note:: + + The ``use`` tag only imports a template if it does not extend another + template, if it does not define macros, and if the body is empty. But it + can *use* other templates. + +.. note:: + + Because ``use`` statements are resolved independently of the context + passed to the template, the template reference cannot be an expression. + +The main template can also override any imported block. If the template +already defines the ``sidebar`` block, then the one defined in ``blocks.html`` +is ignored. To avoid name conflicts, you can rename imported blocks: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% use "blocks.html" with sidebar as base_sidebar %} + + {% block sidebar %}{% endblock %} + {% block title %}{% endblock %} + {% block content %}{% endblock %} + +.. versionadded:: 1.3 + The ``parent()`` support was added in Twig 1.3. + +The ``parent()`` function automatically determines the correct inheritance +tree, so it can be used when overriding a block defined in an imported +template: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% use "blocks.html" %} + + {% block sidebar %} + {{ parent() }} + {% endblock %} + + {% block title %}{% endblock %} + {% block content %}{% endblock %} + +In this example, ``parent()`` will correctly call the ``sidebar`` block from +the ``blocks.html`` template. + +.. tip:: + + In Twig 1.2, renaming allows you to simulate inheritance by calling the + "parent" block: + + .. code-block:: jinja + + {% extends "base.html" %} + + {% use "blocks.html" with sidebar as parent_sidebar %} + + {% block sidebar %} + {{ block('parent_sidebar') }} + {% endblock %} + +.. note:: + + You can use as many ``use`` statements as you want in any given template. + If two imported templates define the same block, the latest one wins. diff --git a/vendor/twig/twig/doc/tags/verbatim.rst b/vendor/twig/twig/doc/tags/verbatim.rst new file mode 100755 index 0000000..fe61ca1 --- /dev/null +++ b/vendor/twig/twig/doc/tags/verbatim.rst @@ -0,0 +1,24 @@ +``verbatim`` +============ + +.. versionadded:: 1.12 + The ``verbatim`` tag was added in Twig 1.12 (it was named ``raw`` before). + +The ``verbatim`` tag marks sections as being raw text that should not be +parsed. For example to put Twig syntax as example into a template you can use +this snippet: + +.. code-block:: jinja + + {% verbatim %} +
      + {% for item in seq %} +
    • {{ item }}
    • + {% endfor %} +
    + {% endverbatim %} + +.. note:: + + The ``verbatim`` tag works in the exact same way as the old ``raw`` tag, + but was renamed to avoid confusion with the ``raw`` filter. \ No newline at end of file diff --git a/vendor/twig/twig/doc/templates.rst b/vendor/twig/twig/doc/templates.rst new file mode 100755 index 0000000..a60c196 --- /dev/null +++ b/vendor/twig/twig/doc/templates.rst @@ -0,0 +1,881 @@ +Twig for Template Designers +=========================== + +This document describes the syntax and semantics of the template engine and +will be most useful as reference to those creating Twig templates. + +Synopsis +-------- + +A template is simply a text file. It can generate any text-based format (HTML, +XML, CSV, LaTeX, etc.). It doesn't have a specific extension, ``.html`` or +``.xml`` are just fine. + +A template contains **variables** or **expressions**, which get replaced with +values when the template is evaluated, and **tags**, which control the logic +of the template. + +Below is a minimal template that illustrates a few basics. We will cover further +details later on: + +.. code-block:: html+jinja + + + + + My Webpage + + + + +

    My Webpage

    + {{ a_variable }} + + + +There are two kinds of delimiters: ``{% ... %}`` and ``{{ ... }}``. The first +one is used to execute statements such as for-loops, the latter prints the +result of an expression to the template. + +IDEs Integration +---------------- + +Many IDEs support syntax highlighting and auto-completion for Twig: + +* *Textmate* via the `Twig bundle`_ +* *Vim* via the `Jinja syntax plugin`_ or the `vim-twig plugin`_ +* *Netbeans* via the `Twig syntax plugin`_ (until 7.1, native as of 7.2) +* *PhpStorm* (native as of 2.1) +* *Eclipse* via the `Twig plugin`_ +* *Sublime Text* via the `Twig bundle`_ +* *GtkSourceView* via the `Twig language definition`_ (used by gedit and other projects) +* *Coda* and *SubEthaEdit* via the `Twig syntax mode`_ +* *Coda 2* via the `other Twig syntax mode`_ +* *Komodo* and *Komodo Edit* via the Twig highlight/syntax check mode +* *Notepad++* via the `Notepad++ Twig Highlighter`_ +* *Emacs* via `web-mode.el`_ +* *Atom* via the `PHP-twig for atom`_ + +Variables +--------- + +The application passes variables to the templates for manipulation in the +template. Variables may have attributes or elements you can access, +too. The visual representation of a variable depends heavily on the application providing +it. + +You can use a dot (``.``) to access attributes of a variable (methods or +properties of a PHP object, or items of a PHP array), or the so-called +"subscript" syntax (``[]``): + +.. code-block:: jinja + + {{ foo.bar }} + {{ foo['bar'] }} + +When the attribute contains special characters (like ``-`` that would be +interpreted as the minus operator), use the ``attribute`` function instead to +access the variable attribute: + +.. code-block:: jinja + + {# equivalent to the non-working foo.data-foo #} + {{ attribute(foo, 'data-foo') }} + +.. note:: + + It's important to know that the curly braces are *not* part of the + variable but the print statement. When accessing variables inside tags, + don't put the braces around them. + +If a variable or attribute does not exist, you will receive a ``null`` value +when the ``strict_variables`` option is set to ``false``; alternatively, if ``strict_variables`` +is set, Twig will throw an error (see :ref:`environment options`). + +.. sidebar:: Implementation + + For convenience's sake ``foo.bar`` does the following things on the PHP + layer: + + * check if ``foo`` is an array and ``bar`` a valid element; + * if not, and if ``foo`` is an object, check that ``bar`` is a valid property; + * if not, and if ``foo`` is an object, check that ``bar`` is a valid method + (even if ``bar`` is the constructor - use ``__construct()`` instead); + * if not, and if ``foo`` is an object, check that ``getBar`` is a valid method; + * if not, and if ``foo`` is an object, check that ``isBar`` is a valid method; + * if not, return a ``null`` value. + + ``foo['bar']`` on the other hand only works with PHP arrays: + + * check if ``foo`` is an array and ``bar`` a valid element; + * if not, return a ``null`` value. + +.. note:: + + If you want to access a dynamic attribute of a variable, use the + :doc:`attribute` function instead. + +Global Variables +~~~~~~~~~~~~~~~~ + +The following variables are always available in templates: + +* ``_self``: references the current template; +* ``_context``: references the current context; +* ``_charset``: references the current charset. + +Setting Variables +~~~~~~~~~~~~~~~~~ + +You can assign values to variables inside code blocks. Assignments use the +:doc:`set` tag: + +.. code-block:: jinja + + {% set foo = 'foo' %} + {% set foo = [1, 2] %} + {% set foo = {'foo': 'bar'} %} + +Filters +------- + +Variables can be modified by **filters**. Filters are separated from the +variable by a pipe symbol (``|``) and may have optional arguments in +parentheses. Multiple filters can be chained. The output of one filter is +applied to the next. + +The following example removes all HTML tags from the ``name`` and title-cases +it: + +.. code-block:: jinja + + {{ name|striptags|title }} + +Filters that accept arguments have parentheses around the arguments. This +example will join a list by commas: + +.. code-block:: jinja + + {{ list|join(', ') }} + +To apply a filter on a section of code, wrap it in the +:doc:`filter` tag: + +.. code-block:: jinja + + {% filter upper %} + This text becomes uppercase + {% endfilter %} + +Go to the :doc:`filters` page to learn more about built-in +filters. + +Functions +--------- + +Functions can be called to generate content. Functions are called by their +name followed by parentheses (``()``) and may have arguments. + +For instance, the ``range`` function returns a list containing an arithmetic +progression of integers: + +.. code-block:: jinja + + {% for i in range(0, 3) %} + {{ i }}, + {% endfor %} + +Go to the :doc:`functions` page to learn more about the +built-in functions. + +Named Arguments +--------------- + +.. versionadded:: 1.12 + Support for named arguments was added in Twig 1.12. + +.. code-block:: jinja + + {% for i in range(low=1, high=10, step=2) %} + {{ i }}, + {% endfor %} + +Using named arguments makes your templates more explicit about the meaning of +the values you pass as arguments: + +.. code-block:: jinja + + {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }} + + {# versus #} + + {{ data|convert_encoding(from='iso-2022-jp', to='UTF-8') }} + +Named arguments also allow you to skip some arguments for which you don't want +to change the default value: + +.. code-block:: jinja + + {# the first argument is the date format, which defaults to the global date format if null is passed #} + {{ "now"|date(null, "Europe/Paris") }} + + {# or skip the format value by using a named argument for the time zone #} + {{ "now"|date(timezone="Europe/Paris") }} + +You can also use both positional and named arguments in one call, in which +case positional arguments must always come before named arguments: + +.. code-block:: jinja + + {{ "now"|date('d/m/Y H:i', timezone="Europe/Paris") }} + +.. tip:: + + Each function and filter documentation page has a section where the names + of all arguments are listed when supported. + +Control Structure +----------------- + +A control structure refers to all those things that control the flow of a +program - conditionals (i.e. ``if``/``elseif``/``else``), ``for``-loops, as +well as things like blocks. Control structures appear inside ``{% ... %}`` +blocks. + +For example, to display a list of users provided in a variable called +``users``, use the :doc:`for` tag: + +.. code-block:: jinja + +

    Members

    +
      + {% for user in users %} +
    • {{ user.username|e }}
    • + {% endfor %} +
    + +The :doc:`if` tag can be used to test an expression: + +.. code-block:: jinja + + {% if users|length > 0 %} +
      + {% for user in users %} +
    • {{ user.username|e }}
    • + {% endfor %} +
    + {% endif %} + +Go to the :doc:`tags` page to learn more about the built-in tags. + +Comments +-------- + +To comment-out part of a line in a template, use the comment syntax ``{# ... +#}``. This is useful for debugging or to add information for other template +designers or yourself: + +.. code-block:: jinja + + {# note: disabled template because we no longer use this + {% for user in users %} + ... + {% endfor %} + #} + +Including other Templates +------------------------- + +The :doc:`include` tag is useful to include a template and +return the rendered content of that template into the current one: + +.. code-block:: jinja + + {% include 'sidebar.html' %} + +Per default included templates are passed the current context. + +The context that is passed to the included template includes variables defined +in the template: + +.. code-block:: jinja + + {% for box in boxes %} + {% include "render_box.html" %} + {% endfor %} + +The included template ``render_box.html`` is able to access ``box``. + +The filename of the template depends on the template loader. For instance, the +``Twig_Loader_Filesystem`` allows you to access other templates by giving the +filename. You can access templates in subdirectories with a slash: + +.. code-block:: jinja + + {% include "sections/articles/sidebar.html" %} + +This behavior depends on the application embedding Twig. + +Template Inheritance +-------------------- + +The most powerful part of Twig is template inheritance. Template inheritance +allows you to build a base "skeleton" template that contains all the common +elements of your site and defines **blocks** that child templates can +override. + +Sounds complicated but it is very basic. It's easier to understand it by +starting with an example. + +Let's define a base template, ``base.html``, which defines a simple HTML +skeleton document that you might use for a simple two-column page: + +.. code-block:: html+jinja + + + + + {% block head %} + + {% block title %}{% endblock %} - My Webpage + {% endblock %} + + +
    {% block content %}{% endblock %}
    + + + + +In this example, the :doc:`block` tags define four blocks that +child templates can fill in. All the ``block`` tag does is to tell the +template engine that a child template may override those portions of the +template. + +A child template might look like this: + +.. code-block:: jinja + + {% extends "base.html" %} + + {% block title %}Index{% endblock %} + {% block head %} + {{ parent() }} + + {% endblock %} + {% block content %} +

    Index

    +

    + Welcome to my awesome homepage. +

    + {% endblock %} + +The :doc:`extends` tag is the key here. It tells the template +engine that this template "extends" another template. When the template system +evaluates this template, first it locates the parent. The extends tag should +be the first tag in the template. + +Note that since the child template doesn't define the ``footer`` block, the +value from the parent template is used instead. + +It's possible to render the contents of the parent block by using the +:doc:`parent` function. This gives back the results of the +parent block: + +.. code-block:: jinja + + {% block sidebar %} +

    Table Of Contents

    + ... + {{ parent() }} + {% endblock %} + +.. tip:: + + The documentation page for the :doc:`extends` tag describes + more advanced features like block nesting, scope, dynamic inheritance, and + conditional inheritance. + +.. note:: + + Twig also supports multiple inheritance with the so called horizontal reuse + with the help of the :doc:`use` tag. This is an advanced feature + hardly ever needed in regular templates. + +HTML Escaping +------------- + +When generating HTML from templates, there's always a risk that a variable +will include characters that affect the resulting HTML. There are two +approaches: manually escaping each variable or automatically escaping +everything by default. + +Twig supports both, automatic escaping is enabled by default. + +.. note:: + + Automatic escaping is only supported if the *escaper* extension has been + enabled (which is the default). + +Working with Manual Escaping +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If manual escaping is enabled, it is **your** responsibility to escape +variables if needed. What to escape? Any variable you don't trust. + +Escaping works by piping the variable through the +:doc:`escape` or ``e`` filter: + +.. code-block:: jinja + + {{ user.username|e }} + +By default, the ``escape`` filter uses the ``html`` strategy, but depending on +the escaping context, you might want to explicitly use any other available +strategies: + +.. code-block:: jinja + + {{ user.username|e('js') }} + {{ user.username|e('css') }} + {{ user.username|e('url') }} + {{ user.username|e('html_attr') }} + +Working with Automatic Escaping +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Whether automatic escaping is enabled or not, you can mark a section of a +template to be escaped or not by using the :doc:`autoescape` +tag: + +.. code-block:: jinja + + {% autoescape %} + Everything will be automatically escaped in this block (using the HTML strategy) + {% endautoescape %} + +By default, auto-escaping uses the ``html`` escaping strategy. If you output +variables in other contexts, you need to explicitly escape them with the +appropriate escaping strategy: + +.. code-block:: jinja + + {% autoescape 'js' %} + Everything will be automatically escaped in this block (using the JS strategy) + {% endautoescape %} + +Escaping +-------- + +It is sometimes desirable or even necessary to have Twig ignore parts it would +otherwise handle as variables or blocks. For example if the default syntax is +used and you want to use ``{{`` as raw string in the template and not start a +variable you have to use a trick. + +The easiest way is to output the variable delimiter (``{{``) by using a variable +expression: + +.. code-block:: jinja + + {{ '{{' }} + +For bigger sections it makes sense to mark a block +:doc:`verbatim`. + +Macros +------ + +.. versionadded:: 1.12 + Support for default argument values was added in Twig 1.12. + +Macros are comparable with functions in regular programming languages. They +are useful to reuse often used HTML fragments to not repeat yourself. + +A macro is defined via the :doc:`macro` tag. Here is a small example +(subsequently called ``forms.html``) of a macro that renders a form element: + +.. code-block:: jinja + + {% macro input(name, value, type, size) %} + + {% endmacro %} + +Macros can be defined in any template, and need to be "imported" via the +:doc:`import` tag before being used: + +.. code-block:: jinja + + {% import "forms.html" as forms %} + +

    {{ forms.input('username') }}

    + +Alternatively, you can import individual macro names from a template into the +current namespace via the :doc:`from` tag and optionally alias them: + +.. code-block:: jinja + + {% from 'forms.html' import input as input_field %} + +
    +
    Username
    +
    {{ input_field('username') }}
    +
    Password
    +
    {{ input_field('password', '', 'password') }}
    +
    + +A default value can also be defined for macro arguments when not provided in a +macro call: + +.. code-block:: jinja + + {% macro input(name, value = "", type = "text", size = 20) %} + + {% endmacro %} + +.. _twig-expressions: + +Expressions +----------- + +Twig allows expressions everywhere. These work very similar to regular PHP and +even if you're not working with PHP you should feel comfortable with it. + +.. note:: + + The operator precedence is as follows, with the lowest-precedence + operators listed first: ``b-and``, ``b-xor``, ``b-or``, ``or``, ``and``, + ``==``, ``!=``, ``<``, ``>``, ``>=``, ``<=``, ``in``, ``matches``, + ``starts with``, ``ends with``, ``..``, ``+``, ``-``, ``~``, ``*``, ``/``, + ``//``, ``%``, ``is``, ``**``, ``|``, ``[]``, and ``.``: + + .. code-block:: jinja + + {% set greeting = 'Hello ' %} + {% set name = 'Fabien' %} + + {{ greeting ~ name|lower }} {# Hello fabien #} + + {# use parenthesis to change precedence #} + {{ (greeting ~ name)|lower }} {# hello fabien #} + +Literals +~~~~~~~~ + +.. versionadded:: 1.5 + Support for hash keys as names and expressions was added in Twig 1.5. + +The simplest form of expressions are literals. Literals are representations +for PHP types such as strings, numbers, and arrays. The following literals +exist: + +* ``"Hello World"``: Everything between two double or single quotes is a + string. They are useful whenever you need a string in the template (for + example as arguments to function calls, filters or just to extend or include + a template). A string can contain a delimiter if it is preceded by a + backslash (``\``) -- like in ``'It\'s good'``. + +* ``42`` / ``42.23``: Integers and floating point numbers are created by just + writing the number down. If a dot is present the number is a float, + otherwise an integer. + +* ``["foo", "bar"]``: Arrays are defined by a sequence of expressions + separated by a comma (``,``) and wrapped with squared brackets (``[]``). + +* ``{"foo": "bar"}``: Hashes are defined by a list of keys and values + separated by a comma (``,``) and wrapped with curly braces (``{}``): + + .. code-block:: jinja + + {# keys as string #} + { 'foo': 'foo', 'bar': 'bar' } + + {# keys as names (equivalent to the previous hash) -- as of Twig 1.5 #} + { foo: 'foo', bar: 'bar' } + + {# keys as integer #} + { 2: 'foo', 4: 'bar' } + + {# keys as expressions (the expression must be enclosed into parentheses) -- as of Twig 1.5 #} + { (1 + 1): 'foo', (a ~ 'b'): 'bar' } + +* ``true`` / ``false``: ``true`` represents the true value, ``false`` + represents the false value. + +* ``null``: ``null`` represents no specific value. This is the value returned + when a variable does not exist. ``none`` is an alias for ``null``. + +Arrays and hashes can be nested: + +.. code-block:: jinja + + {% set foo = [1, {"foo": "bar"}] %} + +.. tip:: + + Using double-quoted or single-quoted strings has no impact on performance + but string interpolation is only supported in double-quoted strings. + +Math +~~~~ + +Twig allows you to calculate with values. This is rarely useful in templates +but exists for completeness' sake. The following operators are supported: + +* ``+``: Adds two objects together (the operands are casted to numbers). ``{{ + 1 + 1 }}`` is ``2``. + +* ``-``: Subtracts the second number from the first one. ``{{ 3 - 2 }}`` is + ``1``. + +* ``/``: Divides two numbers. The returned value will be a floating point + number. ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``. + +* ``%``: Calculates the remainder of an integer division. ``{{ 11 % 7 }}`` is + ``4``. + +* ``//``: Divides two numbers and returns the floored integer result. ``{{ 20 + // 7 }}`` is ``2``, ``{{ -20 // 7 }}`` is ``-3`` (this is just syntactic + sugar for the :doc:`round` filter). + +* ``*``: Multiplies the left operand with the right one. ``{{ 2 * 2 }}`` would + return ``4``. + +* ``**``: Raises the left operand to the power of the right operand. ``{{ 2 ** + 3 }}`` would return ``8``. + +Logic +~~~~~ + +You can combine multiple expressions with the following operators: + +* ``and``: Returns true if the left and the right operands are both true. + +* ``or``: Returns true if the left or the right operand is true. + +* ``not``: Negates a statement. + +* ``(expr)``: Groups an expression. + +.. note:: + + Twig also support bitwise operators (``b-and``, ``b-xor``, and ``b-or``). + +.. note:: + + Operators are case sensitive. + +Comparisons +~~~~~~~~~~~ + +The following comparison operators are supported in any expression: ``==``, +``!=``, ``<``, ``>``, ``>=``, and ``<=``. + +You can also check if a string ``starts with`` or ``ends with`` another +string: + +.. code-block:: jinja + + {% if 'Fabien' starts with 'F' %} + {% endif %} + + {% if 'Fabien' ends with 'n' %} + {% endif %} + +.. note:: + + For complex string comparisons, the ``matches`` operator allows you to use + `regular expressions`_: + + .. code-block:: jinja + + {% if phone matches '/^[\\d\\.]+$/' %} + {% endif %} + +Containment Operator +~~~~~~~~~~~~~~~~~~~~ + +The ``in`` operator performs containment test. + +It returns ``true`` if the left operand is contained in the right: + +.. code-block:: jinja + + {# returns true #} + + {{ 1 in [1, 2, 3] }} + + {{ 'cd' in 'abcde' }} + +.. tip:: + + You can use this filter to perform a containment test on strings, arrays, + or objects implementing the ``Traversable`` interface. + +To perform a negative test, use the ``not in`` operator: + +.. code-block:: jinja + + {% if 1 not in [1, 2, 3] %} + + {# is equivalent to #} + {% if not (1 in [1, 2, 3]) %} + +Test Operator +~~~~~~~~~~~~~ + +The ``is`` operator performs tests. Tests can be used to test a variable against +a common expression. The right operand is name of the test: + +.. code-block:: jinja + + {# find out if a variable is odd #} + + {{ name is odd }} + +Tests can accept arguments too: + +.. code-block:: jinja + + {% if post.status is constant('Post::PUBLISHED') %} + +Tests can be negated by using the ``is not`` operator: + +.. code-block:: jinja + + {% if post.status is not constant('Post::PUBLISHED') %} + + {# is equivalent to #} + {% if not (post.status is constant('Post::PUBLISHED')) %} + +Go to the :doc:`tests` page to learn more about the built-in +tests. + +Other Operators +~~~~~~~~~~~~~~~ + +.. versionadded:: 1.12.0 + Support for the extended ternary operator was added in Twig 1.12.0. + +The following operators are very useful but don't fit into any of the other +categories: + +* ``..``: Creates a sequence based on the operand before and after the + operator (this is just syntactic sugar for the :doc:`range` + function). + +* ``|``: Applies a filter. + +* ``~``: Converts all operands into strings and concatenates them. ``{{ "Hello + " ~ name ~ "!" }}`` would return (assuming ``name`` is ``'John'``) ``Hello + John!``. + +* ``.``, ``[]``: Gets an attribute of an object. + +* ``?:``: The ternary operator: + + .. code-block:: jinja + + {{ foo ? 'yes' : 'no' }} + + {# as of Twig 1.12.0 #} + {{ foo ?: 'no' }} is the same as {{ foo ? foo : 'no' }} + {{ foo ? 'yes' }} is the same as {{ foo ? 'yes' : '' }} + +String Interpolation +~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 1.5 + String interpolation was added in Twig 1.5. + +String interpolation (`#{expression}`) allows any valid expression to appear +within a *double-quoted string*. The result of evaluating that expression is +inserted into the string: + +.. code-block:: jinja + + {{ "foo #{bar} baz" }} + {{ "foo #{1 + 2} baz" }} + +.. _templates-whitespace-control: + +Whitespace Control +------------------ + +.. versionadded:: 1.1 + Tag level whitespace control was added in Twig 1.1. + +The first newline after a template tag is removed automatically (like in PHP.) +Whitespace is not further modified by the template engine, so each whitespace +(spaces, tabs, newlines etc.) is returned unchanged. + +Use the ``spaceless`` tag to remove whitespace *between HTML tags*: + +.. code-block:: jinja + + {% spaceless %} +
    + foo bar +
    + {% endspaceless %} + + {# output will be
    foo bar
    #} + +In addition to the spaceless tag you can also control whitespace on a per tag +level. By using the whitespace control modifier on your tags, you can trim +leading and or trailing whitespace: + +.. code-block:: jinja + + {% set value = 'no spaces' %} + {#- No leading/trailing whitespace -#} + {%- if true -%} + {{- value -}} + {%- endif -%} + + {# output 'no spaces' #} + +The above sample shows the default whitespace control modifier, and how you can +use it to remove whitespace around tags. Trimming space will consume all whitespace +for that side of the tag. It is possible to use whitespace trimming on one side +of a tag: + +.. code-block:: jinja + + {% set value = 'no spaces' %} +
  • {{- value }}
  • + + {# outputs '
  • no spaces
  • ' #} + +Extensions +---------- + +Twig can be easily extended. + +If you are looking for new tags, filters, or functions, have a look at the Twig official +`extension repository`_. + +If you want to create your own, read the :ref:`Creating an +Extension` chapter. + +.. _`Twig bundle`: https://github.com/Anomareh/PHP-Twig.tmbundle +.. _`Jinja syntax plugin`: http://jinja.pocoo.org/docs/integration/#vim +.. _`vim-twig plugin`: https://github.com/evidens/vim-twig +.. _`Twig syntax plugin`: http://plugins.netbeans.org/plugin/37069/php-twig +.. _`Twig plugin`: https://github.com/pulse00/Twig-Eclipse-Plugin +.. _`Twig language definition`: https://github.com/gabrielcorpse/gedit-twig-template-language +.. _`extension repository`: http://github.com/twigphp/Twig-extensions +.. _`Twig syntax mode`: https://github.com/bobthecow/Twig-HTML.mode +.. _`other Twig syntax mode`: https://github.com/muxx/Twig-HTML.mode +.. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig +.. _`web-mode.el`: http://web-mode.org/ +.. _`regular expressions`: http://php.net/manual/en/pcre.pattern.php +.. _`PHP-twig for atom`: https://github.com/reesef/php-twig diff --git a/vendor/twig/twig/doc/tests/constant.rst b/vendor/twig/twig/doc/tests/constant.rst new file mode 100755 index 0000000..8d0724a --- /dev/null +++ b/vendor/twig/twig/doc/tests/constant.rst @@ -0,0 +1,22 @@ +``constant`` +============ + +.. versionadded: 1.13.1 + constant now accepts object instances as the second argument. + +``constant`` checks if a variable has the exact same value as a constant. You +can use either global constants or class constants: + +.. code-block:: jinja + + {% if post.status is constant('Post::PUBLISHED') %} + the status attribute is exactly the same as Post::PUBLISHED + {% endif %} + +You can test constants from object instances as well: + +.. code-block:: jinja + + {% if post.status is constant('PUBLISHED', post) %} + the status attribute is exactly the same as Post::PUBLISHED + {% endif %} diff --git a/vendor/twig/twig/doc/tests/defined.rst b/vendor/twig/twig/doc/tests/defined.rst new file mode 100755 index 0000000..702ce72 --- /dev/null +++ b/vendor/twig/twig/doc/tests/defined.rst @@ -0,0 +1,30 @@ +``defined`` +=========== + +``defined`` checks if a variable is defined in the current context. This is very +useful if you use the ``strict_variables`` option: + +.. code-block:: jinja + + {# defined works with variable names #} + {% if foo is defined %} + ... + {% endif %} + + {# and attributes on variables names #} + {% if foo.bar is defined %} + ... + {% endif %} + + {% if foo['bar'] is defined %} + ... + {% endif %} + +When using the ``defined`` test on an expression that uses variables in some +method calls, be sure that they are all defined first: + +.. code-block:: jinja + + {% if var is defined and foo.method(var) is defined %} + ... + {% endif %} diff --git a/vendor/twig/twig/doc/tests/divisibleby.rst b/vendor/twig/twig/doc/tests/divisibleby.rst new file mode 100755 index 0000000..6c693b2 --- /dev/null +++ b/vendor/twig/twig/doc/tests/divisibleby.rst @@ -0,0 +1,14 @@ +``divisible by`` +================ + +.. versionadded:: 1.14.2 + The ``divisible by`` test was added in Twig 1.14.2 as an alias for + ``divisibleby``. + +``divisible by`` checks if a variable is divisible by a number: + +.. code-block:: jinja + + {% if loop.index is divisible by(3) %} + ... + {% endif %} diff --git a/vendor/twig/twig/doc/tests/empty.rst b/vendor/twig/twig/doc/tests/empty.rst new file mode 100755 index 0000000..e5b5599 --- /dev/null +++ b/vendor/twig/twig/doc/tests/empty.rst @@ -0,0 +1,11 @@ +``empty`` +========= + +``empty`` checks if a variable is empty: + +.. code-block:: jinja + + {# evaluates to true if the foo variable is null, false, an empty array, or the empty string #} + {% if foo is empty %} + ... + {% endif %} diff --git a/vendor/twig/twig/doc/tests/even.rst b/vendor/twig/twig/doc/tests/even.rst new file mode 100755 index 0000000..6ab5cc3 --- /dev/null +++ b/vendor/twig/twig/doc/tests/even.rst @@ -0,0 +1,10 @@ +``even`` +======== + +``even`` returns ``true`` if the given number is even: + +.. code-block:: jinja + + {{ var is even }} + +.. seealso:: :doc:`odd<../tests/odd>` diff --git a/vendor/twig/twig/doc/tests/index.rst b/vendor/twig/twig/doc/tests/index.rst new file mode 100755 index 0000000..c63208e --- /dev/null +++ b/vendor/twig/twig/doc/tests/index.rst @@ -0,0 +1,15 @@ +Tests +===== + +.. toctree:: + :maxdepth: 1 + + constant + defined + divisibleby + empty + even + iterable + null + odd + sameas diff --git a/vendor/twig/twig/doc/tests/iterable.rst b/vendor/twig/twig/doc/tests/iterable.rst new file mode 100755 index 0000000..89a172f --- /dev/null +++ b/vendor/twig/twig/doc/tests/iterable.rst @@ -0,0 +1,19 @@ +``iterable`` +============ + +.. versionadded:: 1.7 + The iterable test was added in Twig 1.7. + +``iterable`` checks if a variable is an array or a traversable object: + +.. code-block:: jinja + + {# evaluates to true if the foo variable is iterable #} + {% if users is iterable %} + {% for user in users %} + Hello {{ user }}! + {% endfor %} + {% else %} + {# users is probably a string #} + Hello {{ users }}! + {% endif %} diff --git a/vendor/twig/twig/doc/tests/null.rst b/vendor/twig/twig/doc/tests/null.rst new file mode 100755 index 0000000..44eec62 --- /dev/null +++ b/vendor/twig/twig/doc/tests/null.rst @@ -0,0 +1,12 @@ +``null`` +======== + +``null`` returns ``true`` if the variable is ``null``: + +.. code-block:: jinja + + {{ var is null }} + +.. note:: + + ``none`` is an alias for ``null``. diff --git a/vendor/twig/twig/doc/tests/odd.rst b/vendor/twig/twig/doc/tests/odd.rst new file mode 100755 index 0000000..9eece77 --- /dev/null +++ b/vendor/twig/twig/doc/tests/odd.rst @@ -0,0 +1,10 @@ +``odd`` +======= + +``odd`` returns ``true`` if the given number is odd: + +.. code-block:: jinja + + {{ var is odd }} + +.. seealso:: :doc:`even<../tests/even>` diff --git a/vendor/twig/twig/doc/tests/sameas.rst b/vendor/twig/twig/doc/tests/sameas.rst new file mode 100755 index 0000000..16f904d --- /dev/null +++ b/vendor/twig/twig/doc/tests/sameas.rst @@ -0,0 +1,14 @@ +``same as`` +=========== + +.. versionadded:: 1.14.2 + The ``same as`` test was added in Twig 1.14.2 as an alias for ``sameas``. + +``same as`` checks if a variable is the same as another variable. +This is the equivalent to ``===`` in PHP: + +.. code-block:: jinja + + {% if foo.attribute is same as(false) %} + the foo attribute really is the 'false' PHP value + {% endif %} diff --git a/vendor/twig/twig/ext/twig/config.m4 b/vendor/twig/twig/ext/twig/config.m4 new file mode 100755 index 0000000..83486be --- /dev/null +++ b/vendor/twig/twig/ext/twig/config.m4 @@ -0,0 +1,8 @@ +dnl config.m4 for extension twig + +PHP_ARG_ENABLE(twig, whether to enable twig support, +[ --enable-twig Enable twig support]) + +if test "$PHP_TWIG" != "no"; then + PHP_NEW_EXTENSION(twig, twig.c, $ext_shared) +fi diff --git a/vendor/twig/twig/ext/twig/config.w32 b/vendor/twig/twig/ext/twig/config.w32 new file mode 100755 index 0000000..cb287b9 --- /dev/null +++ b/vendor/twig/twig/ext/twig/config.w32 @@ -0,0 +1,8 @@ +// vim:ft=javascript + +ARG_ENABLE("twig", "Twig support", "no"); + +if (PHP_TWIG != "no") { + AC_DEFINE('HAVE_TWIG', 1); + EXTENSION('twig', 'twig.c'); +} diff --git a/vendor/twig/twig/ext/twig/php_twig.h b/vendor/twig/twig/ext/twig/php_twig.h new file mode 100755 index 0000000..168f966 --- /dev/null +++ b/vendor/twig/twig/ext/twig/php_twig.h @@ -0,0 +1,35 @@ +/* + +----------------------------------------------------------------------+ + | Twig Extension | + +----------------------------------------------------------------------+ + | Copyright (c) 2011 Derick Rethans | + +----------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met (BSD-3-Clause). | + +----------------------------------------------------------------------+ + | Author: Derick Rethans | + +----------------------------------------------------------------------+ + */ + +#ifndef PHP_TWIG_H +#define PHP_TWIG_H + +#define PHP_TWIG_VERSION "1.18.2" + +#include "php.h" + +extern zend_module_entry twig_module_entry; +#define phpext_twig_ptr &twig_module_entry +#ifndef PHP_WIN32 +zend_module_entry *get_module(void); +#endif + +#ifdef ZTS +#include "TSRM.h" +#endif + +PHP_FUNCTION(twig_template_get_attributes); +PHP_RSHUTDOWN_FUNCTION(twig); + +#endif diff --git a/vendor/twig/twig/ext/twig/twig.c b/vendor/twig/twig/ext/twig/twig.c new file mode 100755 index 0000000..40c03fd --- /dev/null +++ b/vendor/twig/twig/ext/twig/twig.c @@ -0,0 +1,1099 @@ +/* + +----------------------------------------------------------------------+ + | Twig Extension | + +----------------------------------------------------------------------+ + | Copyright (c) 2011 Derick Rethans | + +----------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met (BSD-3-Clause). | + +----------------------------------------------------------------------+ + | Author: Derick Rethans | + +----------------------------------------------------------------------+ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_twig.h" +#include "ext/standard/php_var.h" +#include "ext/standard/php_string.h" +#include "ext/standard/php_smart_str.h" +#include "ext/spl/spl_exceptions.h" + +#include "Zend/zend_object_handlers.h" +#include "Zend/zend_interfaces.h" +#include "Zend/zend_exceptions.h" + +#ifndef Z_ADDREF_P +#define Z_ADDREF_P(pz) (pz)->refcount++ +#endif + +#define FREE_DTOR(z) \ + zval_dtor(z); \ + efree(z); + +#if PHP_VERSION_ID >= 50300 + #define APPLY_TSRMLS_DC TSRMLS_DC + #define APPLY_TSRMLS_CC TSRMLS_CC + #define APPLY_TSRMLS_FETCH() +#else + #define APPLY_TSRMLS_DC + #define APPLY_TSRMLS_CC + #define APPLY_TSRMLS_FETCH() TSRMLS_FETCH() +#endif + +ZEND_BEGIN_ARG_INFO_EX(twig_template_get_attribute_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 6) + ZEND_ARG_INFO(0, template) + ZEND_ARG_INFO(0, object) + ZEND_ARG_INFO(0, item) + ZEND_ARG_INFO(0, arguments) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, isDefinedTest) +ZEND_END_ARG_INFO() + +#ifndef PHP_FE_END +#define PHP_FE_END { NULL, NULL, NULL, 0, 0 } +#endif + +static const zend_function_entry twig_functions[] = { + PHP_FE(twig_template_get_attributes, twig_template_get_attribute_args) + PHP_FE_END +}; + +PHP_RSHUTDOWN_FUNCTION(twig) +{ +#if ZEND_DEBUG + CG(unclean_shutdown) = 0; /* get rid of PHPUnit's exit() and report memleaks */ +#endif + return SUCCESS; +} + +zend_module_entry twig_module_entry = { + STANDARD_MODULE_HEADER, + "twig", + twig_functions, + NULL, + NULL, + NULL, + PHP_RSHUTDOWN(twig), + NULL, + PHP_TWIG_VERSION, + STANDARD_MODULE_PROPERTIES +}; + + +#ifdef COMPILE_DL_TWIG +ZEND_GET_MODULE(twig) +#endif + +static int TWIG_ARRAY_KEY_EXISTS(zval *array, zval *key) +{ + if (Z_TYPE_P(array) != IS_ARRAY) { + return 0; + } + + switch (Z_TYPE_P(key)) { + case IS_NULL: + return zend_hash_exists(Z_ARRVAL_P(array), "", 1); + + case IS_BOOL: + case IS_DOUBLE: + convert_to_long(key); + case IS_LONG: + return zend_hash_index_exists(Z_ARRVAL_P(array), Z_LVAL_P(key)); + + default: + convert_to_string(key); + return zend_symtable_exists(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1); + } +} + +static int TWIG_INSTANCE_OF(zval *object, zend_class_entry *interface TSRMLS_DC) +{ + if (Z_TYPE_P(object) != IS_OBJECT) { + return 0; + } + return instanceof_function(Z_OBJCE_P(object), interface TSRMLS_CC); +} + +static int TWIG_INSTANCE_OF_USERLAND(zval *object, char *interface TSRMLS_DC) +{ + zend_class_entry **pce; + if (Z_TYPE_P(object) != IS_OBJECT) { + return 0; + } + if (zend_lookup_class(interface, strlen(interface), &pce TSRMLS_CC) == FAILURE) { + return 0; + } + return instanceof_function(Z_OBJCE_P(object), *pce TSRMLS_CC); +} + +static zval *TWIG_GET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC) +{ + zend_class_entry *ce = Z_OBJCE_P(object); + zval *retval; + + if (Z_TYPE_P(object) == IS_OBJECT) { + SEPARATE_ARG_IF_REF(offset); + zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset); + + zval_ptr_dtor(&offset); + + if (!retval) { + if (!EG(exception)) { + zend_error(E_ERROR, "Undefined offset for object of type %s used as array", ce->name); + } + return NULL; + } + + return retval; + } + return NULL; +} + +static int TWIG_ISSET_ARRAYOBJECT_ELEMENT(zval *object, zval *offset TSRMLS_DC) +{ + zend_class_entry *ce = Z_OBJCE_P(object); + zval *retval; + + if (Z_TYPE_P(object) == IS_OBJECT) { + SEPARATE_ARG_IF_REF(offset); + zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset); + + zval_ptr_dtor(&offset); + + if (!retval) { + if (!EG(exception)) { + zend_error(E_ERROR, "Undefined offset for object of type %s used as array", ce->name); + } + return 0; + } + + return (retval && Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval)); + } + return 0; +} + +static char *TWIG_STRTOLOWER(const char *str, int str_len) +{ + char *item_dup; + + item_dup = estrndup(str, str_len); + php_strtolower(item_dup, str_len); + return item_dup; +} + +static zval *TWIG_CALL_USER_FUNC_ARRAY(zval *object, char *function, zval *arguments TSRMLS_DC) +{ + zend_fcall_info fci; + zval ***args = NULL; + int arg_count = 0; + HashTable *table; + HashPosition pos; + int i = 0; + zval *retval_ptr; + zval *zfunction; + + if (arguments) { + table = HASH_OF(arguments); + args = safe_emalloc(sizeof(zval **), table->nNumOfElements, 0); + + zend_hash_internal_pointer_reset_ex(table, &pos); + + while (zend_hash_get_current_data_ex(table, (void **)&args[i], &pos) == SUCCESS) { + i++; + zend_hash_move_forward_ex(table, &pos); + } + arg_count = table->nNumOfElements; + } + + MAKE_STD_ZVAL(zfunction); + ZVAL_STRING(zfunction, function, 1); + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = zfunction; + fci.symbol_table = NULL; +#if PHP_VERSION_ID >= 50300 + fci.object_ptr = object; +#else + fci.object_pp = &object; +#endif + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = arg_count; + fci.params = args; + fci.no_separation = 0; + + if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) { + ALLOC_INIT_ZVAL(retval_ptr); + ZVAL_BOOL(retval_ptr, 0); + } + + if (args) { + efree(fci.params); + } + FREE_DTOR(zfunction); + return retval_ptr; +} + +static int TWIG_CALL_BOOLEAN(zval *object, char *functionName TSRMLS_DC) +{ + zval *ret; + int res; + + ret = TWIG_CALL_USER_FUNC_ARRAY(object, functionName, NULL TSRMLS_CC); + res = Z_LVAL_P(ret); + zval_ptr_dtor(&ret); + return res; +} + +static zval *TWIG_GET_STATIC_PROPERTY(zval *class, char *prop_name TSRMLS_DC) +{ + zval **tmp_zval; + zend_class_entry *ce; + + if (class == NULL || Z_TYPE_P(class) != IS_OBJECT) { + return NULL; + } + + ce = zend_get_class_entry(class TSRMLS_CC); +#if PHP_VERSION_ID >= 50400 + tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0, NULL TSRMLS_CC); +#else + tmp_zval = zend_std_get_static_property(ce, prop_name, strlen(prop_name), 0 TSRMLS_CC); +#endif + return *tmp_zval; +} + +static zval *TWIG_GET_ARRAY_ELEMENT_ZVAL(zval *class, zval *prop_name TSRMLS_DC) +{ + zval **tmp_zval; + + if (class == NULL || Z_TYPE_P(class) != IS_ARRAY) { + if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) { + // array access object + return TWIG_GET_ARRAYOBJECT_ELEMENT(class, prop_name TSRMLS_CC); + } + return NULL; + } + + switch(Z_TYPE_P(prop_name)) { + case IS_NULL: + zend_hash_find(HASH_OF(class), "", 1, (void**) &tmp_zval); + return *tmp_zval; + + case IS_BOOL: + case IS_DOUBLE: + convert_to_long(prop_name); + case IS_LONG: + zend_hash_index_find(HASH_OF(class), Z_LVAL_P(prop_name), (void **) &tmp_zval); + return *tmp_zval; + + case IS_STRING: + zend_symtable_find(HASH_OF(class), Z_STRVAL_P(prop_name), Z_STRLEN_P(prop_name) + 1, (void**) &tmp_zval); + return *tmp_zval; + } + + return NULL; +} + +static zval *TWIG_GET_ARRAY_ELEMENT(zval *class, char *prop_name, int prop_name_length TSRMLS_DC) +{ + zval **tmp_zval; + + if (class == NULL/* || Z_TYPE_P(class) != IS_ARRAY*/) { + return NULL; + } + + if (class != NULL && Z_TYPE_P(class) == IS_OBJECT && TWIG_INSTANCE_OF(class, zend_ce_arrayaccess TSRMLS_CC)) { + // array access object + zval *tmp_name_zval; + zval *tmp_ret_zval; + + ALLOC_INIT_ZVAL(tmp_name_zval); + ZVAL_STRING(tmp_name_zval, prop_name, 1); + tmp_ret_zval = TWIG_GET_ARRAYOBJECT_ELEMENT(class, tmp_name_zval TSRMLS_CC); + FREE_DTOR(tmp_name_zval); + return tmp_ret_zval; + } + + if (zend_symtable_find(HASH_OF(class), prop_name, prop_name_length+1, (void**)&tmp_zval) == SUCCESS) { + return *tmp_zval; + } + return NULL; +} + +static zval *TWIG_PROPERTY(zval *object, zval *propname TSRMLS_DC) +{ + zval *tmp = NULL; + + if (Z_OBJ_HT_P(object)->read_property) { +#if PHP_VERSION_ID >= 50400 + tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS, NULL TSRMLS_CC); +#else + tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS TSRMLS_CC); +#endif + if (tmp == EG(uninitialized_zval_ptr)) { + ZVAL_NULL(tmp); + } + } + return tmp; +} + +static int TWIG_HAS_PROPERTY(zval *object, zval *propname TSRMLS_DC) +{ + if (Z_OBJ_HT_P(object)->has_property) { +#if PHP_VERSION_ID >= 50400 + return Z_OBJ_HT_P(object)->has_property(object, propname, 0, NULL TSRMLS_CC); +#else + return Z_OBJ_HT_P(object)->has_property(object, propname, 0 TSRMLS_CC); +#endif + } + return 0; +} + +static int TWIG_HAS_DYNAMIC_PROPERTY(zval *object, char *prop, int prop_len TSRMLS_DC) +{ + if (Z_OBJ_HT_P(object)->get_properties) { + return zend_hash_quick_exists( + Z_OBJ_HT_P(object)->get_properties(object TSRMLS_CC), // the properties hash + prop, // property name + prop_len + 1, // property length + zend_get_hash_value(prop, prop_len + 1) // hash value + ); + } + return 0; +} + +static zval *TWIG_PROPERTY_CHAR(zval *object, char *propname TSRMLS_DC) +{ + zval *tmp_name_zval, *tmp; + + ALLOC_INIT_ZVAL(tmp_name_zval); + ZVAL_STRING(tmp_name_zval, propname, 1); + tmp = TWIG_PROPERTY(object, tmp_name_zval TSRMLS_CC); + FREE_DTOR(tmp_name_zval); + return tmp; +} + +static zval *TWIG_CALL_S(zval *object, char *method, char *arg0 TSRMLS_DC) +{ + zend_fcall_info fci; + zval **args[1]; + zval *argument; + zval *zfunction; + zval *retval_ptr; + + MAKE_STD_ZVAL(argument); + ZVAL_STRING(argument, arg0, 1); + args[0] = &argument; + + MAKE_STD_ZVAL(zfunction); + ZVAL_STRING(zfunction, method, 1); + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = zfunction; + fci.symbol_table = NULL; +#if PHP_VERSION_ID >= 50300 + fci.object_ptr = object; +#else + fci.object_pp = &object; +#endif + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 1; + fci.params = args; + fci.no_separation = 0; + + if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) { + FREE_DTOR(zfunction); + zval_ptr_dtor(&argument); + return 0; + } + FREE_DTOR(zfunction); + zval_ptr_dtor(&argument); + return retval_ptr; +} + +static int TWIG_CALL_SB(zval *object, char *method, char *arg0 TSRMLS_DC) +{ + zval *retval_ptr; + int success; + + retval_ptr = TWIG_CALL_S(object, method, arg0 TSRMLS_CC); + success = (retval_ptr && (Z_TYPE_P(retval_ptr) == IS_BOOL) && Z_LVAL_P(retval_ptr)); + + if (retval_ptr) { + zval_ptr_dtor(&retval_ptr); + } + + return success; +} + +static int TWIG_CALL_ZZ(zval *object, char *method, zval *arg1, zval *arg2 TSRMLS_DC) +{ + zend_fcall_info fci; + zval **args[2]; + zval *zfunction; + zval *retval_ptr; + int success; + + args[0] = &arg1; + args[1] = &arg2; + + MAKE_STD_ZVAL(zfunction); + ZVAL_STRING(zfunction, method, 1); + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = zfunction; + fci.symbol_table = NULL; +#if PHP_VERSION_ID >= 50300 + fci.object_ptr = object; +#else + fci.object_pp = &object; +#endif + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 2; + fci.params = args; + fci.no_separation = 0; + + if (zend_call_function(&fci, NULL TSRMLS_CC) == FAILURE) { + FREE_DTOR(zfunction); + return 0; + } + + FREE_DTOR(zfunction); + + success = (retval_ptr && (Z_TYPE_P(retval_ptr) == IS_BOOL) && Z_LVAL_P(retval_ptr)); + if (retval_ptr) { + zval_ptr_dtor(&retval_ptr); + } + + return success; +} + +#ifndef Z_SET_REFCOUNT_P +# define Z_SET_REFCOUNT_P(pz, rc) pz->refcount = rc +# define Z_UNSET_ISREF_P(pz) pz->is_ref = 0 +#endif + +static void TWIG_NEW(zval *object, char *class, zval *arg0, zval *arg1 TSRMLS_DC) +{ + zend_class_entry **pce; + + if (zend_lookup_class(class, strlen(class), &pce TSRMLS_CC) == FAILURE) { + return; + } + + Z_TYPE_P(object) = IS_OBJECT; + object_init_ex(object, *pce); + Z_SET_REFCOUNT_P(object, 1); + Z_UNSET_ISREF_P(object); + + TWIG_CALL_ZZ(object, "__construct", arg0, arg1 TSRMLS_CC); +} + +static int twig_add_array_key_to_string(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +{ + smart_str *buf; + char *joiner; + APPLY_TSRMLS_FETCH(); + + buf = va_arg(args, smart_str*); + joiner = va_arg(args, char*); + + if (buf->len != 0) { + smart_str_appends(buf, joiner); + } + + if (hash_key->nKeyLength == 0) { + smart_str_append_long(buf, (long) hash_key->h); + } else { + char *key, *tmp_str; + int key_len, tmp_len; + key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC); + tmp_str = php_str_to_str_ex(key, key_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL); + + smart_str_appendl(buf, tmp_str, tmp_len); + efree(key); + efree(tmp_str); + } + + return 0; +} + +static char *TWIG_IMPLODE_ARRAY_KEYS(char *joiner, zval *array TSRMLS_DC) +{ + smart_str collector = { 0, 0, 0 }; + + smart_str_appendl(&collector, "", 0); + zend_hash_apply_with_arguments(HASH_OF(array) APPLY_TSRMLS_CC, twig_add_array_key_to_string, 2, &collector, joiner); + smart_str_0(&collector); + + return collector.c; +} + +static void TWIG_RUNTIME_ERROR(zval *template TSRMLS_DC, char *message, ...) +{ + char *buffer; + va_list args; + zend_class_entry **pce; + zval *ex; + zval *constructor; + zval *zmessage; + zval *lineno; + zval *filename_func; + zval *filename; + zval *constructor_args[3]; + zval *constructor_retval; + + if (zend_lookup_class("Twig_Error_Runtime", strlen("Twig_Error_Runtime"), &pce TSRMLS_CC) == FAILURE) { + return; + } + + va_start(args, message); + vspprintf(&buffer, 0, message, args); + va_end(args); + + MAKE_STD_ZVAL(ex); + object_init_ex(ex, *pce); + + // Call Twig_Error constructor + MAKE_STD_ZVAL(constructor); + MAKE_STD_ZVAL(zmessage); + MAKE_STD_ZVAL(lineno); + MAKE_STD_ZVAL(filename); + MAKE_STD_ZVAL(filename_func); + MAKE_STD_ZVAL(constructor_retval); + + ZVAL_STRINGL(constructor, "__construct", sizeof("__construct")-1, 1); + ZVAL_STRING(zmessage, buffer, 1); + ZVAL_LONG(lineno, -1); + + // Get template filename + ZVAL_STRINGL(filename_func, "getTemplateName", sizeof("getTemplateName")-1, 1); + call_user_function(EG(function_table), &template, filename_func, filename, 0, 0 TSRMLS_CC); + + constructor_args[0] = zmessage; + constructor_args[1] = lineno; + constructor_args[2] = filename; + call_user_function(EG(function_table), &ex, constructor, constructor_retval, 3, constructor_args TSRMLS_CC); + + zval_ptr_dtor(&constructor_retval); + zval_ptr_dtor(&zmessage); + zval_ptr_dtor(&lineno); + zval_ptr_dtor(&filename); + FREE_DTOR(constructor); + FREE_DTOR(filename_func); + efree(buffer); + + zend_throw_exception_object(ex TSRMLS_CC); +} + +static char *TWIG_GET_CLASS_NAME(zval *object TSRMLS_DC) +{ + char *class_name; + zend_uint class_name_len; + + if (Z_TYPE_P(object) != IS_OBJECT) { + return ""; + } +#if PHP_API_VERSION >= 20100412 + zend_get_object_classname(object, (const char **) &class_name, &class_name_len TSRMLS_CC); +#else + zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC); +#endif + return class_name; +} + +static int twig_add_method_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +{ + zval *retval; + char *item; + size_t item_len; + zend_function *mptr = (zend_function *) pDest; + APPLY_TSRMLS_FETCH(); + + if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)) { + return 0; + } + + retval = va_arg(args, zval*); + + item_len = strlen(mptr->common.function_name); + item = estrndup(mptr->common.function_name, item_len); + php_strtolower(item, item_len); + + add_assoc_stringl_ex(retval, item, item_len+1, item, item_len, 0); + + return 0; +} + +static int twig_add_property_to_class(void *pDest APPLY_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +{ + zend_class_entry *ce; + zval *retval; + char *class_name, *prop_name; + zend_property_info *pptr = (zend_property_info *) pDest; + APPLY_TSRMLS_FETCH(); + + if (!(pptr->flags & ZEND_ACC_PUBLIC) || (pptr->flags & ZEND_ACC_STATIC)) { + return 0; + } + + ce = *va_arg(args, zend_class_entry**); + retval = va_arg(args, zval*); + +#if PHP_API_VERSION >= 20100412 + zend_unmangle_property_name(pptr->name, pptr->name_length, (const char **) &class_name, (const char **) &prop_name); +#else + zend_unmangle_property_name(pptr->name, pptr->name_length, &class_name, &prop_name); +#endif + + add_assoc_string(retval, prop_name, prop_name, 1); + + return 0; +} + +static void twig_add_class_to_cache(zval *cache, zval *object, char *class_name TSRMLS_DC) +{ + zval *class_info, *class_methods, *class_properties; + zend_class_entry *class_ce; + + class_ce = zend_get_class_entry(object TSRMLS_CC); + + ALLOC_INIT_ZVAL(class_info); + ALLOC_INIT_ZVAL(class_methods); + ALLOC_INIT_ZVAL(class_properties); + array_init(class_info); + array_init(class_methods); + array_init(class_properties); + // add all methods to self::cache[$class]['methods'] + zend_hash_apply_with_arguments(&class_ce->function_table APPLY_TSRMLS_CC, twig_add_method_to_class, 1, class_methods); + zend_hash_apply_with_arguments(&class_ce->properties_info APPLY_TSRMLS_CC, twig_add_property_to_class, 2, &class_ce, class_properties); + + add_assoc_zval(class_info, "methods", class_methods); + add_assoc_zval(class_info, "properties", class_properties); + add_assoc_zval(cache, class_name, class_info); +} + +/* {{{ proto mixed twig_template_get_attributes(TwigTemplate template, mixed object, mixed item, array arguments, string type, boolean isDefinedTest, boolean ignoreStrictCheck) + A C implementation of TwigTemplate::getAttribute() */ +PHP_FUNCTION(twig_template_get_attributes) +{ + zval *template; + zval *object; + char *item; + int item_len; + zval *zitem, ztmpitem; + zval *arguments = NULL; + zval *ret = NULL; + char *type = NULL; + int type_len = 0; + zend_bool isDefinedTest = 0; + zend_bool ignoreStrictCheck = 0; + int free_ret = 0; + zval *tmp_self_cache; + char *class_name = NULL; + zval *tmp_class; + char *type_name; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ozz|asbb", &template, &object, &zitem, &arguments, &type, &type_len, &isDefinedTest, &ignoreStrictCheck) == FAILURE) { + return; + } + + // convert the item to a string + ztmpitem = *zitem; + zval_copy_ctor(&ztmpitem); + convert_to_string(&ztmpitem); + item_len = Z_STRLEN(ztmpitem); + item = estrndup(Z_STRVAL(ztmpitem), item_len); + zval_dtor(&ztmpitem); + + if (!type) { + type = "any"; + } + +/* + // array + if (Twig_Template::METHOD_CALL !== $type) { + $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; + + if ((is_array($object) && array_key_exists($arrayItem, $object)) + || ($object instanceof ArrayAccess && isset($object[$arrayItem])) + ) { + if ($isDefinedTest) { + return true; + } + + return $object[$arrayItem]; + } +*/ + + + if (strcmp("method", type) != 0) { + if ((TWIG_ARRAY_KEY_EXISTS(object, zitem)) + || (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC) && TWIG_ISSET_ARRAYOBJECT_ELEMENT(object, zitem TSRMLS_CC)) + ) { + + if (isDefinedTest) { + efree(item); + RETURN_TRUE; + } + + ret = TWIG_GET_ARRAY_ELEMENT_ZVAL(object, zitem TSRMLS_CC); + + if (!ret) { + ret = &EG(uninitialized_zval); + } + RETVAL_ZVAL(ret, 1, 0); + if (free_ret) { + zval_ptr_dtor(&ret); + } + efree(item); + return; + } +/* + if (Twig_Template::ARRAY_CALL === $type) { + if ($isDefinedTest) { + return false; + } + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return null; + } +*/ + if (strcmp("array", type) == 0 || Z_TYPE_P(object) != IS_OBJECT) { + if (isDefinedTest) { + efree(item); + RETURN_FALSE; + } + if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { + efree(item); + 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 === $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->getTemplateName()); + } + } +*/ + if (TWIG_INSTANCE_OF(object, zend_ce_arrayaccess TSRMLS_CC)) { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" in object with ArrayAccess of class \"%s\" does not exist", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); + } else if (Z_TYPE_P(object) == IS_OBJECT) { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); + } else if (Z_TYPE_P(object) == IS_ARRAY) { + if (0 == zend_hash_num_elements(Z_ARRVAL_P(object))) { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty", item); + } else { + char *array_keys = TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist", item, array_keys); + efree(array_keys); + } + } else { + char *type_name = zend_zval_type_name(object); + Z_ADDREF_P(object); + if (Z_TYPE_P(object) == IS_NULL) { + convert_to_string(object); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, + (strcmp("array", type) == 0) + ? "Impossible to access a key (\"%s\") on a %s variable" + : "Impossible to access an attribute (\"%s\") on a %s variable", + item, type_name); + } else { + convert_to_string(object); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, + (strcmp("array", type) == 0) + ? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")" + : "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\")", + item, type_name, Z_STRVAL_P(object)); + } + zval_ptr_dtor(&object); + } + efree(item); + return; + } + } + +/* + if (!is_object($object)) { + if ($isDefinedTest) { + return false; + } +*/ + + if (Z_TYPE_P(object) != IS_OBJECT) { + if (isDefinedTest) { + efree(item); + RETURN_FALSE; + } +/* + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return null; + } + + if (null === $object) { + $message = sprintf('Impossible to invoke a method ("%s") on a null variable', $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->getTemplateName()); + } +*/ + if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { + efree(item); + return; + } + + type_name = zend_zval_type_name(object); + Z_ADDREF_P(object); + if (Z_TYPE_P(object) == IS_NULL) { + convert_to_string_ex(&object); + + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable", item, type_name); + } else { + convert_to_string_ex(&object); + + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\")", item, type_name, Z_STRVAL_P(object)); + } + + zval_ptr_dtor(&object); + efree(item); + return; + } +/* + $class = get_class($object); +*/ + + class_name = TWIG_GET_CLASS_NAME(object TSRMLS_CC); + tmp_self_cache = TWIG_GET_STATIC_PROPERTY(template, "cache" TSRMLS_CC); + tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name, strlen(class_name) TSRMLS_CC); + + if (!tmp_class) { + twig_add_class_to_cache(tmp_self_cache, object, class_name TSRMLS_CC); + tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name, strlen(class_name) TSRMLS_CC); + } + efree(class_name); + +/* + // object property + if (Twig_Template::METHOD_CALL !== $type) { + if (isset($object->$item) || array_key_exists((string) $item, $object)) { + if ($isDefinedTest) { + return true; + } + + if ($this->env->hasExtension('sandbox')) { + $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item); + } + + return $object->$item; + } + } +*/ + if (strcmp("method", type) != 0) { + zval *tmp_properties, *tmp_item; + + tmp_properties = TWIG_GET_ARRAY_ELEMENT(tmp_class, "properties", strlen("properties") TSRMLS_CC); + tmp_item = TWIG_GET_ARRAY_ELEMENT(tmp_properties, item, item_len TSRMLS_CC); + + if (tmp_item || TWIG_HAS_PROPERTY(object, zitem TSRMLS_CC) || TWIG_HAS_DYNAMIC_PROPERTY(object, item, item_len TSRMLS_CC)) { + if (isDefinedTest) { + efree(item); + RETURN_TRUE; + } + if (TWIG_CALL_SB(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "hasExtension", "sandbox" TSRMLS_CC)) { + TWIG_CALL_ZZ(TWIG_CALL_S(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getExtension", "sandbox" TSRMLS_CC), "checkPropertyAllowed", object, zitem TSRMLS_CC); + } + if (EG(exception)) { + efree(item); + return; + } + + ret = TWIG_PROPERTY(object, zitem TSRMLS_CC); + efree(item); + RETURN_ZVAL(ret, 1, 0); + } + } +/* + // object method + if (!isset(self::$cache[$class]['methods'])) { + self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object))); + } + + $call = false; + $lcItem = strtolower($item); + if (isset(self::$cache[$class]['methods'][$lcItem])) { + $method = (string) $item; + } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) { + $method = 'get'.$item; + } elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) { + $method = 'is'.$item; + } elseif (isset(self::$cache[$class]['methods']['__call'])) { + $method = (string) $item; + $call = true; +*/ + { + int call = 0; + char *lcItem = TWIG_STRTOLOWER(item, item_len); + int lcItem_length; + char *method = NULL; + char *tmp_method_name_get; + char *tmp_method_name_is; + zval *zmethod; + zval *tmp_methods; + + lcItem_length = strlen(lcItem); + tmp_method_name_get = emalloc(4 + lcItem_length); + tmp_method_name_is = emalloc(3 + lcItem_length); + + sprintf(tmp_method_name_get, "get%s", lcItem); + sprintf(tmp_method_name_is, "is%s", lcItem); + + tmp_methods = TWIG_GET_ARRAY_ELEMENT(tmp_class, "methods", strlen("methods") TSRMLS_CC); + + if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, lcItem, lcItem_length TSRMLS_CC)) { + method = item; + } else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, tmp_method_name_get, lcItem_length + 3 TSRMLS_CC)) { + method = tmp_method_name_get; + } else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, tmp_method_name_is, lcItem_length + 2 TSRMLS_CC)) { + method = tmp_method_name_is; + } else if (TWIG_GET_ARRAY_ELEMENT(tmp_methods, "__call", 6 TSRMLS_CC)) { + method = item; + call = 1; +/* + } else { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return null; + } + + throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName()); + } + + if ($isDefinedTest) { + return true; + } +*/ + } else { + efree(tmp_method_name_get); + efree(tmp_method_name_is); + efree(lcItem); + + if (isDefinedTest) { + efree(item); + RETURN_FALSE; + } + if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { + efree(item); + return; + } + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Method \"%s\" for object \"%s\" does not exist", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); + efree(item); + return; + } + + if (isDefinedTest) { + efree(tmp_method_name_get); + efree(tmp_method_name_is); + efree(lcItem);efree(item); + RETURN_TRUE; + } +/* + if ($this->env->hasExtension('sandbox')) { + $this->env->getExtension('sandbox')->checkMethodAllowed($object, $method); + } +*/ + MAKE_STD_ZVAL(zmethod); + ZVAL_STRING(zmethod, method, 1); + if (TWIG_CALL_SB(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "hasExtension", "sandbox" TSRMLS_CC)) { + TWIG_CALL_ZZ(TWIG_CALL_S(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getExtension", "sandbox" TSRMLS_CC), "checkMethodAllowed", object, zmethod TSRMLS_CC); + } + zval_ptr_dtor(&zmethod); + if (EG(exception)) { + efree(tmp_method_name_get); + efree(tmp_method_name_is); + efree(lcItem);efree(item); + return; + } +/* + // 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 = call_user_func_array(array($object, $method), $arguments); + } catch (BadMethodCallException $e) { + if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { + return null; + } + throw $e; + } +*/ + ret = TWIG_CALL_USER_FUNC_ARRAY(object, method, arguments TSRMLS_CC); + if (EG(exception) && TWIG_INSTANCE_OF(EG(exception), spl_ce_BadMethodCallException TSRMLS_CC)) { + if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { + efree(tmp_method_name_get); + efree(tmp_method_name_is); + efree(lcItem);efree(item); + zend_clear_exception(TSRMLS_C); + return; + } + } + free_ret = 1; + efree(tmp_method_name_get); + efree(tmp_method_name_is); + efree(lcItem); + } +/* + // useful when calling a template method from a template + // this is not supported but unfortunately heavily used in the Symfony profiler + if ($object instanceof Twig_TemplateInterface) { + return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); + } + + return $ret; +*/ + efree(item); + // ret can be null, if e.g. the called method throws an exception + if (ret) { + if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_TemplateInterface" TSRMLS_CC)) { + if (Z_STRLEN_P(ret) != 0) { + zval *charset = TWIG_CALL_USER_FUNC_ARRAY(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getCharset", NULL TSRMLS_CC); + TWIG_NEW(return_value, "Twig_Markup", ret, charset TSRMLS_CC); + zval_ptr_dtor(&charset); + if (ret) { + zval_ptr_dtor(&ret); + } + return; + } + } + + RETVAL_ZVAL(ret, 1, 0); + if (free_ret) { + zval_ptr_dtor(&ret); + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Autoloader.php b/vendor/twig/twig/lib/Twig/Autoloader.php new file mode 100755 index 0000000..87f7415 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Autoloader.php @@ -0,0 +1,48 @@ + + */ +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) + { + if (PHP_VERSION_ID < 50300) { + spl_autoload_register(array(__CLASS__, 'autoload')); + } else { + spl_autoload_register(array(__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(array('_', "\0"), array('/', ''), $class).'.php')) { + require $file; + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Compiler.php b/vendor/twig/twig/lib/Twig/Compiler.php new file mode 100755 index 0000000..2514c31 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Compiler.php @@ -0,0 +1,278 @@ + + */ +class Twig_Compiler implements Twig_CompilerInterface +{ + protected $lastLine; + protected $source; + protected $indentation; + protected $env; + protected $debugInfo; + protected $sourceOffset; + protected $sourceLine; + protected $filename; + + /** + * Constructor. + * + * @param Twig_Environment $env The twig environment instance + */ + public function __construct(Twig_Environment $env) + { + $this->env = $env; + $this->debugInfo = array(); + } + + public function getFilename() + { + return $this->filename; + } + + /** + * Returns the environment instance related to this compiler. + * + * @return Twig_Environment The environment instance + */ + 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 Twig_Compiler The current compiler instance + */ + public function compile(Twig_NodeInterface $node, $indentation = 0) + { + $this->lastLine = null; + $this->source = ''; + $this->debugInfo = array(); + $this->sourceOffset = 0; + // source code starts at 1 (as we then increment it when we encounter new lines) + $this->sourceLine = 1; + $this->indentation = $indentation; + + if ($node instanceof Twig_Node_Module) { + $this->filename = $node->getAttribute('filename'); + } + + $node->compile($this); + + return $this; + } + + public function subcompile(Twig_NodeInterface $node, $raw = true) + { + if (false === $raw) { + $this->addIndentation(); + } + + $node->compile($this); + + return $this; + } + + /** + * Adds a raw string to the compiled code. + * + * @param string $string The string + * + * @return Twig_Compiler The current compiler instance + */ + public function raw($string) + { + $this->source .= $string; + + return $this; + } + + /** + * Writes a string to the compiled code by adding indentation. + * + * @return Twig_Compiler The current compiler instance + */ + public function write() + { + $strings = func_get_args(); + foreach ($strings as $string) { + $this->addIndentation(); + $this->source .= $string; + } + + return $this; + } + + /** + * Appends an indentation to the current PHP code after compilation. + * + * @return Twig_Compiler The current compiler instance + */ + public function addIndentation() + { + $this->source .= str_repeat(' ', $this->indentation * 4); + + return $this; + } + + /** + * Adds a quoted string to the compiled code. + * + * @param string $value The string + * + * @return Twig_Compiler The current compiler instance + */ + 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 Twig_Compiler The current compiler instance + */ + public function repr($value) + { + if (is_int($value) || is_float($value)) { + if (false !== $locale = setlocale(LC_NUMERIC, 0)) { + setlocale(LC_NUMERIC, 'C'); + } + + $this->raw($value); + + 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. + * + * @param Twig_NodeInterface $node The related twig node + * + * @return Twig_Compiler The current compiler instance + */ + public function addDebugInfo(Twig_NodeInterface $node) + { + if ($node->getLine() != $this->lastLine) { + $this->write(sprintf("// line %d\n", $node->getLine())); + + // 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) { + // 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->getLine(); + + $this->lastLine = $node->getLine(); + } + + 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 Twig_Compiler The current compiler instance + */ + public function indent($step = 1) + { + $this->indentation += $step; + + return $this; + } + + /** + * Outdents the generated code. + * + * @param int $step The number of indentation to remove + * + * @return Twig_Compiler The current compiler instance + * + * @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', uniqid(mt_rand(), true), false)); + } +} diff --git a/vendor/twig/twig/lib/Twig/CompilerInterface.php b/vendor/twig/twig/lib/Twig/CompilerInterface.php new file mode 100755 index 0000000..272c767 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/CompilerInterface.php @@ -0,0 +1,36 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_CompilerInterface +{ + /** + * Compiles a node. + * + * @param Twig_NodeInterface $node The node to compile + * + * @return Twig_CompilerInterface The current compiler instance + */ + public function compile(Twig_NodeInterface $node); + + /** + * Gets the current PHP code after compilation. + * + * @return string The PHP code + */ + public function getSource(); +} diff --git a/vendor/twig/twig/lib/Twig/Environment.php b/vendor/twig/twig/lib/Twig/Environment.php new file mode 100755 index 0000000..f14e5d8 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Environment.php @@ -0,0 +1,1292 @@ + + */ +class Twig_Environment +{ + const VERSION = '1.18.2'; + + 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; + protected $extensionInitialized; + protected $loadedTemplates; + protected $strictVariables; + protected $unaryOperators; + protected $binaryOperators; + protected $templateClassPrefix = '__TwigTemplate_'; + protected $functionCallbacks; + protected $filterCallbacks; + protected $staging; + + /** + * 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, 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 + * * filename: set the autoescaping strategy based on the template filename extension + * * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename" + * + * * 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 A Twig_LoaderInterface instance + * @param array $options An array of options + */ + public function __construct(Twig_LoaderInterface $loader = null, $options = array()) + { + if (null !== $loader) { + $this->setLoader($loader); + } + + $options = array_merge(array( + '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->runtimeInitialized = false; + $this->setCache($options['cache']); + $this->functionCallbacks = array(); + $this->filterCallbacks = array(); + + $this->addExtension(new Twig_Extension_Core()); + $this->addExtension(new Twig_Extension_Escaper($options['autoescape'])); + $this->addExtension(new Twig_Extension_Optimizer($options['optimizations'])); + $this->extensionInitialized = false; + $this->staging = new Twig_Extension_Staging(); + } + + /** + * 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; + } + + /** + * Enables debugging mode. + */ + public function enableDebug() + { + $this->debug = true; + } + + /** + * Disables debugging mode. + */ + public function disableDebug() + { + $this->debug = false; + } + + /** + * 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; + } + + /** + * Disables the strict_variables option. + */ + public function disableStrictVariables() + { + $this->strictVariables = false; + } + + /** + * 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 cache directory or false if cache is disabled. + * + * @return string|false + */ + public function getCache() + { + return $this->cache; + } + + /** + * Sets the cache directory or false if cache is disabled. + * + * @param string|false $cache The absolute path to the compiled templates, + * or false to disable cache + */ + public function setCache($cache) + { + $this->cache = $cache ? $cache : false; + } + + /** + * 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 + */ + public function getCacheFilename($name) + { + if (false === $this->cache) { + return false; + } + + $class = substr($this->getTemplateClass($name), strlen($this->templateClassPrefix)); + + return $this->getCache().'/'.$class[0].'/'.$class[1].'/'.$class.'.php'; + } + + /** + * Gets the template class associated with the given string. + * + * @param string $name The name for which to calculate the template class name + * @param int $index The index if it is an embedded template + * + * @return string The template class name + */ + public function getTemplateClass($name, $index = null) + { + return $this->templateClassPrefix.hash('sha256', $this->getLoader()->getCacheKey($name)).(null === $index ? '' : '_'.$index); + } + + /** + * Gets the template class prefix. + * + * @return string The template class prefix + */ + public function getTemplateClassPrefix() + { + 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 = array()) + { + 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 = array()) + { + $this->loadTemplate($name)->display($context); + } + + /** + * Loads a template by name. + * + * @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_Syntax When an error occurred during compilation + */ + public function loadTemplate($name, $index = null) + { + $cls = $this->getTemplateClass($name, $index); + + if (isset($this->loadedTemplates[$cls])) { + return $this->loadedTemplates[$cls]; + } + + if (!class_exists($cls, false)) { + if (false === $cache = $this->getCacheFilename($name)) { + eval('?>'.$this->compileSource($this->getLoader()->getSource($name), $name)); + } else { + if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) { + $this->writeCacheFile($cache, $this->compileSource($this->getLoader()->getSource($name), $name)); + } + + require_once $cache; + } + } + + 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 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', uniqid(mt_rand(), true), false)); + + $loader = new Twig_Loader_Chain(array( + new Twig_Loader_Array(array($name => $template)), + $current = $this->getLoader(), + )); + + $this->setLoader($loader); + try { + $template = $this->loadTemplate($name); + } catch (Exception $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) + { + foreach ($this->extensions as $extension) { + $r = new ReflectionObject($extension); + if (filemtime($r->getFileName()) > $time) { + return false; + } + } + + return $this->getLoader()->isFresh($name, $time); + } + + /** + * Tries to load a template consecutively from an array. + * + * Similar to loadTemplate() but it also accepts Twig_TemplateInterface instances and an array + * of templates where each is tried to be loaded. + * + * @param string|Twig_Template|array $names A template or an array of templates to try consecutively + * + * @return Twig_Template + * + * @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 = array($names); + } + + foreach ($names as $name) { + if ($name instanceof Twig_Template) { + 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. + */ + public function clearTemplateCache() + { + $this->loadedTemplates = array(); + } + + /** + * Clears the template cache files on the filesystem. + */ + public function clearCacheFiles() + { + if (false === $this->cache) { + return; + } + + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->cache), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if ($file->isFile()) { + @unlink($file->getPathname()); + } + } + } + + /** + * Gets the Lexer instance. + * + * @return Twig_LexerInterface A Twig_LexerInterface instance + */ + public function getLexer() + { + if (null === $this->lexer) { + $this->lexer = new Twig_Lexer($this); + } + + return $this->lexer; + } + + /** + * Sets the Lexer instance. + * + * @param Twig_LexerInterface $lexer A Twig_LexerInterface instance + */ + public function setLexer(Twig_LexerInterface $lexer) + { + $this->lexer = $lexer; + } + + /** + * Tokenizes a source code. + * + * @param string $source The template source code + * @param string $name The template name + * + * @return Twig_TokenStream A Twig_TokenStream instance + * + * @throws Twig_Error_Syntax When the code is syntactically wrong + */ + public function tokenize($source, $name = null) + { + return $this->getLexer()->tokenize($source, $name); + } + + /** + * Gets the Parser instance. + * + * @return Twig_ParserInterface A Twig_ParserInterface instance + */ + public function getParser() + { + if (null === $this->parser) { + $this->parser = new Twig_Parser($this); + } + + return $this->parser; + } + + /** + * Sets the Parser instance. + * + * @param Twig_ParserInterface $parser A Twig_ParserInterface instance + */ + public function setParser(Twig_ParserInterface $parser) + { + $this->parser = $parser; + } + + /** + * Converts a token stream to a node tree. + * + * @param Twig_TokenStream $stream A token stream instance + * + * @return Twig_Node_Module A node tree + * + * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong + */ + public function parse(Twig_TokenStream $stream) + { + return $this->getParser()->parse($stream); + } + + /** + * Gets the Compiler instance. + * + * @return Twig_CompilerInterface A Twig_CompilerInterface instance + */ + public function getCompiler() + { + if (null === $this->compiler) { + $this->compiler = new Twig_Compiler($this); + } + + return $this->compiler; + } + + /** + * Sets the Compiler instance. + * + * @param Twig_CompilerInterface $compiler A Twig_CompilerInterface instance + */ + public function setCompiler(Twig_CompilerInterface $compiler) + { + $this->compiler = $compiler; + } + + /** + * Compiles a node and returns the PHP code. + * + * @param Twig_NodeInterface $node A Twig_NodeInterface instance + * + * @return string The compiled PHP source code + */ + public function compile(Twig_NodeInterface $node) + { + return $this->getCompiler()->compile($node)->getSource(); + } + + /** + * Compiles a template source code. + * + * @param string $source The template source code + * @param string $name The template name + * + * @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) + { + try { + return $this->compile($this->parse($this->tokenize($source, $name))); + } catch (Twig_Error $e) { + $e->setTemplateFile($name); + 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, $name, $e); + } + } + + /** + * Sets the Loader instance. + * + * @param Twig_LoaderInterface $loader A Twig_LoaderInterface instance + */ + public function setLoader(Twig_LoaderInterface $loader) + { + $this->loader = $loader; + } + + /** + * Gets the Loader instance. + * + * @return Twig_LoaderInterface A Twig_LoaderInterface instance + */ + 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. + */ + public function initRuntime() + { + $this->runtimeInitialized = true; + + foreach ($this->getExtensions() as $extension) { + $extension->initRuntime($this); + } + } + + /** + * Returns true if the given extension is registered. + * + * @param string $name The extension name + * + * @return bool Whether the extension is registered or not + */ + public function hasExtension($name) + { + return isset($this->extensions[$name]); + } + + /** + * Gets an extension by name. + * + * @param string $name The extension name + * + * @return Twig_ExtensionInterface A Twig_ExtensionInterface instance + */ + public function getExtension($name) + { + if (!isset($this->extensions[$name])) { + throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $name)); + } + + return $this->extensions[$name]; + } + + /** + * Registers an extension. + * + * @param Twig_ExtensionInterface $extension A Twig_ExtensionInterface instance + */ + 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())); + } + + $this->extensions[$extension->getName()] = $extension; + } + + /** + * 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) + { + if ($this->extensionInitialized) { + throw new LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); + } + + unset($this->extensions[$name]); + } + + /** + * 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; + } + + /** + * Registers a Token Parser. + * + * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance + */ + 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 A broker containing token parsers + */ + 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[] An array of Twig_TokenParserInterface instances + */ + public function getTags() + { + $tags = array(); + foreach ($this->getTokenParsers()->getParsers() as $parser) { + if ($parser instanceof Twig_TokenParserInterface) { + $tags[$parser->getTag()] = $parser; + } + } + + return $tags; + } + + /** + * Registers a Node Visitor. + * + * @param Twig_NodeVisitorInterface $visitor A Twig_NodeVisitorInterface instance + */ + 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[] An array of Twig_NodeVisitorInterface instances + */ + 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 A Twig_FilterInterface instance or a Twig_SimpleFilter instance + */ + 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(); + } + + 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 + */ + 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 registerUndefinedFunctionCallback. + * + * @return Twig_FilterInterface[] An array of Twig_FilterInterface instances + * + * @see registerUndefinedFilterCallback + */ + 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(); + } + + 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[] An array of Twig_TestInterface instances + */ + 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 + */ + public function getTest($name) + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + if (isset($this->tests[$name])) { + return $this->tests[$name]; + } + + return false; + } + + /** + * Registers a Function. + * + * @param string|Twig_SimpleFunction $name The function name or a Twig_SimpleFunction instance + * @param Twig_FunctionInterface|Twig_SimpleFunction $function A Twig_FunctionInterface instance or a Twig_SimpleFunction instance + */ + 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(); + } + + 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 + */ + 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[] An array of Twig_FunctionInterface instances + * + * @see registerUndefinedFunctionCallback + */ + 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(); + } + + /* This condition must be uncommented in Twig 2.0 + if (!array_key_exists($name, $this->globals)) { + 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 + */ + 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 + */ + public function getUnaryOperators() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->unaryOperators; + } + + /** + * Gets the registered binary Operators. + * + * @return array An array of binary operators + */ + public function getBinaryOperators() + { + if (!$this->extensionInitialized) { + $this->initExtensions(); + } + + return $this->binaryOperators; + } + + public function computeAlternatives($name, $items) + { + $alternatives = array(); + 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); + } + + protected function initGlobals() + { + $globals = array(); + foreach ($this->extensions as $extension) { + $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); + } + + protected function initExtensions() + { + if ($this->extensionInitialized) { + return; + } + + $this->extensionInitialized = true; + $this->parsers = new Twig_TokenParserBroker(); + $this->filters = array(); + $this->functions = array(); + $this->tests = array(); + $this->visitors = array(); + $this->unaryOperators = array(); + $this->binaryOperators = array(); + + foreach ($this->extensions as $extension) { + $this->initExtension($extension); + } + $this->initExtension($this->staging); + } + + protected function initExtension(Twig_ExtensionInterface $extension) + { + // filters + foreach ($extension->getFilters() as $name => $filter) { + if ($name instanceof Twig_SimpleFilter) { + $filter = $name; + $name = $filter->getName(); + } elseif ($filter instanceof Twig_SimpleFilter) { + $name = $filter->getName(); + } + + $this->filters[$name] = $filter; + } + + // functions + foreach ($extension->getFunctions() as $name => $function) { + if ($name instanceof Twig_SimpleFunction) { + $function = $name; + $name = $function->getName(); + } elseif ($function instanceof Twig_SimpleFunction) { + $name = $function->getName(); + } + + $this->functions[$name] = $function; + } + + // tests + foreach ($extension->getTests() as $name => $test) { + if ($name instanceof Twig_SimpleTest) { + $test = $name; + $name = $test->getName(); + } elseif ($test instanceof Twig_SimpleTest) { + $name = $test->getName(); + } + + $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) { + $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 (2 !== count($operators)) { + throw new InvalidArgumentException(sprintf('"%s::getOperators()" does not return a valid operators array.', get_class($extension))); + } + + $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); + $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]); + } + } + + protected function writeCacheFile($file, $content) + { + $dir = dirname($file); + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true)) { + clearstatcache(false, $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($file)); + if (false !== @file_put_contents($tmpFile, $content)) { + // rename does not work on Win32 before 5.2.6 + if (@rename($tmpFile, $file) || (@copy($tmpFile, $file) && unlink($tmpFile))) { + @chmod($file, 0666 & ~umask()); + + return; + } + } + + throw new RuntimeException(sprintf('Failed to write cache file "%s".', $file)); + } +} diff --git a/vendor/twig/twig/lib/Twig/Error.php b/vendor/twig/twig/lib/Twig/Error.php new file mode 100755 index 0000000..90650c5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Error.php @@ -0,0 +1,250 @@ + + */ +class Twig_Error extends Exception +{ + protected $lineno; + protected $filename; + protected $rawMessage; + protected $previous; + + /** + * Constructor. + * + * Set both the line number and the filename 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 filename 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 string $filename The template file name where the error occurred + * @param Exception $previous The previous exception + */ + public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null) + { + if (PHP_VERSION_ID < 50300) { + $this->previous = $previous; + parent::__construct(''); + } else { + parent::__construct('', 0, $previous); + } + + $this->lineno = $lineno; + $this->filename = $filename; + + if (-1 === $this->lineno || null === $this->filename) { + $this->guessTemplateInfo(); + } + + $this->rawMessage = $message; + + $this->updateRepr(); + } + + /** + * Gets the raw message. + * + * @return string The raw message + */ + public function getRawMessage() + { + return $this->rawMessage; + } + + /** + * Gets the filename where the error occurred. + * + * @return string The filename + */ + public function getTemplateFile() + { + return $this->filename; + } + + /** + * Sets the filename where the error occurred. + * + * @param string $filename The filename + */ + public function setTemplateFile($filename) + { + $this->filename = $filename; + + $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(); + } + + public function guess() + { + $this->guessTemplateInfo(); + $this->updateRepr(); + } + + /** + * For PHP < 5.3.0, provides access to the getPrevious() method. + * + * @param string $method The method name + * @param array $arguments The parameters to be passed to the method + * + * @return Exception The previous exception or null + * + * @throws BadMethodCallException + */ + public function __call($method, $arguments) + { + if ('getprevious' == strtolower($method)) { + return $this->previous; + } + + throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method)); + } + + protected function updateRepr() + { + $this->message = $this->rawMessage; + + $dot = false; + if ('.' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $dot = true; + } + + if ($this->filename) { + if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) { + $filename = sprintf('"%s"', $this->filename); + } else { + $filename = json_encode($this->filename); + } + $this->message .= sprintf(' in %s', $filename); + } + + if ($this->lineno && $this->lineno >= 0) { + $this->message .= sprintf(' at line %d', $this->lineno); + } + + if ($dot) { + $this->message .= '.'; + } + } + + protected function guessTemplateInfo() + { + $template = null; + $templateClass = null; + + if (PHP_VERSION_ID >= 50306) { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + } else { + $backtrace = debug_backtrace(); + } + + 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 filename + if (null !== $template && null === $this->filename) { + $this->filename = $template->getTemplateName(); + } + + if (null === $template || $this->lineno > -1) { + return; + } + + $r = new ReflectionObject($template); + $file = $r->getFileName(); + + // hhvm has a bug where eval'ed files comes out as the current directory + if (is_dir($file)) { + $file = ''; + } + + $exceptions = array($e = $this); + while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) { + $exceptions[] = $e; + } + + while ($e = array_pop($exceptions)) { + $traces = $e->getTrace(); + array_unshift($traces, array('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/vendor/twig/twig/lib/Twig/Error/Loader.php b/vendor/twig/twig/lib/Twig/Error/Loader.php new file mode 100755 index 0000000..68efb57 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Error/Loader.php @@ -0,0 +1,31 @@ + + */ +class Twig_Error_Loader extends Twig_Error +{ + public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null) + { + parent::__construct($message, false, false, $previous); + } +} diff --git a/vendor/twig/twig/lib/Twig/Error/Runtime.php b/vendor/twig/twig/lib/Twig/Error/Runtime.php new file mode 100755 index 0000000..8b6cedd --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Error/Runtime.php @@ -0,0 +1,20 @@ + + */ +class Twig_Error_Runtime extends Twig_Error +{ +} diff --git a/vendor/twig/twig/lib/Twig/Error/Syntax.php b/vendor/twig/twig/lib/Twig/Error/Syntax.php new file mode 100755 index 0000000..0f5c579 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Error/Syntax.php @@ -0,0 +1,20 @@ + + */ +class Twig_Error_Syntax extends Twig_Error +{ +} diff --git a/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php b/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php new file mode 100755 index 0000000..b168c3c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php @@ -0,0 +1,29 @@ + + * + * @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); +} diff --git a/vendor/twig/twig/lib/Twig/ExpressionParser.php b/vendor/twig/twig/lib/Twig/ExpressionParser.php new file mode 100755 index 0000000..8fc8346 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/ExpressionParser.php @@ -0,0 +1,619 @@ + + */ +class Twig_ExpressionParser +{ + const OPERATOR_LEFT = 1; + const OPERATOR_RIGHT = 2; + + protected $parser; + protected $unaryOperators; + protected $binaryOperators; + + public function __construct(Twig_Parser $parser, array $unaryOperators, array $binaryOperators) + { + $this->parser = $parser; + $this->unaryOperators = $unaryOperators; + $this->binaryOperators = $binaryOperators; + } + + 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 (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(), array($negClass, $posClass)) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { + throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s"', $token->getValue()), $token->getLine(), $this->parser->getFilename()); + } + + $this->parser->getStream()->next(); + $expr = $this->parsePrimaryExpression(); + + $node = new $class($expr, $token->getLine()); + break; + } + + default: + if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) { + $node = $this->parseArrayExpression(); + } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) { + $node = $this->parseHashExpression(); + } else { + throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getFilename()); + } + } + + return $this->parsePostfixExpression($node); + } + + public function parseStringExpression() + { + $stream = $this->parser->getStream(); + + $nodes = array(); + // 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->getLine()); + } + + 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(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(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(), $this->parser->getFilename()); + } + + $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 ($token->getType() == Twig_Token::PUNCTUATION_TYPE) { + 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->getFilename()); + } + + 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->getFilename()); + } + + return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); + case 'block': + return new Twig_Node_Expression_BlockReference($this->parseArguments()->getNode(0), false, $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->getFilename()); + } + + 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(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(array(), $lineno); + $type = Twig_Template::ANY_CALL; + if ($token->getValue() == '.') { + $token = $stream->next(); + if ( + $token->getType() == Twig_Token::NAME_TYPE + || + $token->getType() == Twig_Token::NUMBER_TYPE + || + ($token->getType() == Twig_Token::OPERATOR_TYPE && 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_TemplateInterface::METHOD_CALL; + foreach ($this->parseArguments() as $n) { + $arguments->addElement($n); + } + } + } else { + throw new Twig_Error_Syntax('Expected name or number', $lineno, $this->parser->getFilename()); + } + + 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(), $this->parser->getFilename()); + } + + $node = new Twig_Node_Expression_MethodCall($node, 'get'.$arg->getAttribute('value'), $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(array($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 = array(); + $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(), $this->parser->getFilename()); + } + $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(), $this->parser->getFilename()); + } + } 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() + { + $targets = array(); + while (true) { + $token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to'); + if (in_array($token->getValue(), array('true', 'false', 'none'))) { + throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s"', $token->getValue()), $token->getLine(), $this->parser->getFilename()); + } + $targets[] = new Twig_Node_Expression_AssignName($token->getValue(), $token->getLine()); + + if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { + break; + } + } + + return new Twig_Node($targets); + } + + public function parseMultitargetExpression() + { + $targets = array(); + while (true) { + $targets[] = $this->parseExpression(); + if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) { + break; + } + } + + return new Twig_Node($targets); + } + + protected function getFunctionNodeClass($name, $line) + { + $env = $this->parser->getEnvironment(); + + if (false === $function = $env->getFunction($name)) { + $message = sprintf('The function "%s" does not exist', $name); + if ($alternatives = $env->computeAlternatives($name, array_keys($env->getFunctions()))) { + $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); + } + + throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename()); + } + + 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) + { + $env = $this->parser->getEnvironment(); + + if (false === $filter = $env->getFilter($name)) { + $message = sprintf('The filter "%s" does not exist', $name); + if ($alternatives = $env->computeAlternatives($name, array_keys($env->getFilters()))) { + $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); + } + + throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename()); + } + + 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; + } +} diff --git a/vendor/twig/twig/lib/Twig/Extension.php b/vendor/twig/twig/lib/Twig/Extension.php new file mode 100755 index 0000000..5c8ad5c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension.php @@ -0,0 +1,93 @@ +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 = array($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; + } + + /** + * Returns the token parser instance to add to the existing list. + * + * @return Twig_TokenParser[] An array of Twig_TokenParser instances + */ + public function getTokenParsers() + { + return array( + 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(), + ); + } + + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + public function getFilters() + { + $filters = array( + // formatting filters + new Twig_SimpleFilter('date', 'twig_date_format_filter', array('needs_environment' => true)), + new Twig_SimpleFilter('date_modify', 'twig_date_modify_filter', array('needs_environment' => true)), + new Twig_SimpleFilter('format', 'sprintf'), + new Twig_SimpleFilter('replace', 'strtr'), + new Twig_SimpleFilter('number_format', 'twig_number_format_filter', array('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', array('needs_environment' => true)), + new Twig_SimpleFilter('capitalize', 'twig_capitalize_string_filter', array('needs_environment' => true)), + new Twig_SimpleFilter('upper', 'strtoupper'), + new Twig_SimpleFilter('lower', 'strtolower'), + new Twig_SimpleFilter('striptags', 'strip_tags'), + new Twig_SimpleFilter('trim', 'trim'), + new Twig_SimpleFilter('nl2br', 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))), + + // array helpers + new Twig_SimpleFilter('join', 'twig_join_filter'), + new Twig_SimpleFilter('split', 'twig_split_filter', array('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', array('needs_environment' => true)), + new Twig_SimpleFilter('length', 'twig_length_filter', array('needs_environment' => true)), + new Twig_SimpleFilter('slice', 'twig_slice', array('needs_environment' => true)), + new Twig_SimpleFilter('first', 'twig_first', array('needs_environment' => true)), + new Twig_SimpleFilter('last', 'twig_last', array('needs_environment' => true)), + + // iteration and runtime + new Twig_SimpleFilter('default', '_twig_default_filter', array('node_class' => 'Twig_Node_Expression_Filter_Default')), + new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'), + + // escaping + new Twig_SimpleFilter('escape', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')), + new Twig_SimpleFilter('e', 'twig_escape_filter', array('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', array('needs_environment' => true)); + $filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', array('needs_environment' => true)); + } + + return $filters; + } + + /** + * Returns a list of global functions to add to the existing list. + * + * @return array An array of global functions + */ + public function getFunctions() + { + return array( + 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', array('needs_environment' => true)), + new Twig_SimpleFunction('date', 'twig_date_converter', array('needs_environment' => true)), + new Twig_SimpleFunction('include', 'twig_include', array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('all'))), + new Twig_SimpleFunction('source', 'twig_source', array('needs_environment' => true, 'is_safe' => array('all'))), + ); + } + + /** + * Returns a list of tests to add to the existing list. + * + * @return array An array of tests + */ + public function getTests() + { + return array( + new Twig_SimpleTest('even', null, array('node_class' => 'Twig_Node_Expression_Test_Even')), + new Twig_SimpleTest('odd', null, array('node_class' => 'Twig_Node_Expression_Test_Odd')), + new Twig_SimpleTest('defined', null, array('node_class' => 'Twig_Node_Expression_Test_Defined')), + new Twig_SimpleTest('sameas', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas')), + new Twig_SimpleTest('same as', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas')), + new Twig_SimpleTest('none', null, array('node_class' => 'Twig_Node_Expression_Test_Null')), + new Twig_SimpleTest('null', null, array('node_class' => 'Twig_Node_Expression_Test_Null')), + new Twig_SimpleTest('divisibleby', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby')), + new Twig_SimpleTest('divisible by', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby')), + new Twig_SimpleTest('constant', null, array('node_class' => 'Twig_Node_Expression_Test_Constant')), + new Twig_SimpleTest('empty', 'twig_test_empty'), + new Twig_SimpleTest('iterable', 'twig_test_iterable'), + ); + } + + /** + * Returns a list of operators to add to the existing list. + * + * @return array An array of operators + */ + public function getOperators() + { + return array( + array( + 'not' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), + '-' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'), + '+' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'), + ), + array( + 'or' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'and' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'b-or' => array('precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'b-xor' => array('precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'b-and' => array('precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '!=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '<' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '>=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '<=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'not in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'matches' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Matches', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'starts with' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_StartsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'ends with' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_EndsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '..' => array('precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '+' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '-' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '~' => array('precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '*' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mul', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '/' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Div', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '//' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_FloorDiv', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '%' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'is' => array('precedence' => 100, 'callable' => array($this, 'parseTestExpression'), 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'is not' => array('precedence' => 100, 'callable' => array($this, 'parseNotTestExpression'), 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '**' => array('precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT), + ), + ); + } + + public function parseNotTestExpression(Twig_Parser $parser, Twig_NodeInterface $node) + { + return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($parser, $node), $parser->getCurrentToken()->getLine()); + } + + public function parseTestExpression(Twig_Parser $parser, Twig_NodeInterface $node) + { + $stream = $parser->getStream(); + $name = $this->getTestName($parser, $node->getLine()); + $class = $this->getTestNodeClass($parser, $name); + $arguments = null; + if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { + $arguments = $parser->getExpressionParser()->parseArguments(true); + } + + return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine()); + } + + protected function getTestName(Twig_Parser $parser, $line) + { + $stream = $parser->getStream(); + $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); + $env = $parser->getEnvironment(); + $testMap = $env->getTests(); + + if (isset($testMap[$name])) { + return $name; + } + + if ($stream->test(Twig_Token::NAME_TYPE)) { + // try 2-words tests + $name = $name.' '.$parser->getCurrentToken()->getValue(); + + if (isset($testMap[$name])) { + $parser->getStream()->next(); + + return $name; + } + } + + $message = sprintf('The test "%s" does not exist', $name); + if ($alternatives = $env->computeAlternatives($name, array_keys($testMap))) { + $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); + } + + throw new Twig_Error_Syntax($message, $line, $parser->getFilename()); + } + + protected function getTestNodeClass(Twig_Parser $parser, $name) + { + $env = $parser->getEnvironment(); + $testMap = $env->getTests(); + + if ($testMap[$name] instanceof Twig_SimpleTest) { + return $testMap[$name]->getNodeClass(); + } + + return $testMap[$name] instanceof Twig_Test_Node ? $testMap[$name]->getClass() : 'Twig_Node_Expression_Test'; + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'core'; + } +} + +/** + * Cycles over a value. + * + * @param ArrayAccess|array $values An array or an ArrayAccess instance + * @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 A Twig_Environment instance + * @param Traversable|array|int|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 A Twig_Environment instance + * @param DateTime|DateTimeInterface|DateInterval|string $date A date + * @param string|null $format The target format, null to use the default + * @param DateTimeZone|string|null|false $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('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 A Twig_Environment instance + * @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 A Twig_Environment instance + * @param DateTime|DateTimeInterface|string|null $date A date + * @param DateTimeZone|string|null|false $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('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; + } + + $asString = (string) $date; + if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { + $date = '@'.$date; + } + + $date = new DateTime($date, $env->getExtension('core')->getTimezone()); + if (false !== $timezone) { + $date->setTimezone($timezone); + } + + return $date; +} + +/** + * 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 A Twig_Environment instance + * @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('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); +} + +if (PHP_VERSION_ID < 50300) { + /** + * JSON encodes a variable. + * + * @param mixed $value The value to encode. + * @param int $options Not used on PHP 5.2.x + * + * @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); + } +} else { + /** + * 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 $arr1 An array + * @param array $arr2 An array + * + * @return array The merged array + */ +function twig_array_merge($arr1, $arr2) +{ + if (!is_array($arr1) || !is_array($arr2)) { + throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or hashes; %s and %s given.', gettype($arr1), gettype($arr2))); + } + + return array_merge($arr1, $arr2); +} + +/** + * Slices a variable. + * + * @param Twig_Environment $env A Twig_Environment instance + * @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) { + if ($item instanceof IteratorAggregate) { + $item = $item->getIterator(); + } + + if ($start >= 0 && $length >= 0 && $item instanceof Iterator) { + try { + return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys); + } catch (OutOfBoundsException $exception) { + return array(); + } + } + + $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 A Twig_Environment instance + * @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 A Twig_Environment instance + * @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 separator between elements is an empty string per default, you can define it with the optional parameter. + * + *
    + *  {{ [1, 2, 3]|join('|') }}
    + *  {# returns 1|2|3 #}
    + *
    + *  {{ [1, 2, 3]|join }}
    + *  {# returns 123 #}
    + * 
    + * + * @param array $value An array + * @param string $glue The separator + * + * @return string The concatenated string + */ +function twig_join_filter($value, $glue = '') +{ + if ($value instanceof Traversable) { + $value = iterator_to_array($value, false); + } + + return implode($glue, (array) $value); +} + +/** + * 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(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 (is_object($array) && $array instanceof Traversable) { + return array_keys(iterator_to_array($array)); + } + + if (!is_array($array)) { + return array(); + } + + return array_keys($array); +} + +/** + * Reverses a variable. + * + * @param Twig_Environment $env A Twig_Environment instance + * @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 (is_object($item) && $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 $array + * + * @return array + */ +function twig_sort_filter($array) +{ + asort($array); + + return $array; +} + +/* used internally */ +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) { + return in_array($value, iterator_to_array($compare, false), is_object($value) || is_resource($value)); + } + + return false; +} + +/** + * Escapes a string. + * + * @param Twig_Environment $env A Twig_Environment instance + * @param string $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; + } else { + return $string; + } + } + + if (null === $charset) { + $charset = $env->getCharset(); + } + + switch ($strategy) { + case 'html': + // see http://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; + + if (null === $htmlspecialcharsCharsets) { + if (defined('HHVM_VERSION')) { + $htmlspecialcharsCharsets = array('utf-8' => true, 'UTF-8' => true); + } else { + $htmlspecialcharsCharsets = array( + '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 \xHH or \uHHHH representations + if ('UTF-8' != $charset) { + $string = twig_convert_encoding($string, 'UTF-8', $charset); + } + + if (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) { + 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 (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) { + 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 (0 == strlen($string) ? false : (1 == preg_match('/^./su', $string) ? false : true)) { + 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': + if (PHP_VERSION_ID < 50300) { + return str_replace('%7E', '~', rawurlencode($string)); + } + + return rawurlencode($string); + + default: + static $escapers; + + if (null === $escapers) { + $escapers = $env->getExtension('core')->getEscapers(); + } + + if (isset($escapers[$strategy])) { + return call_user_func($escapers[$strategy], $env, $string, $charset); + } + + $validStrategies = implode(', ', array_merge(array('html', 'js', 'url', 'css', 'html_attr'), array_keys($escapers))); + + throw new Twig_Error_Runtime(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); + } +} + +/* used internally */ +function twig_escape_filter_is_safe(Twig_Node $filterArgs) +{ + foreach ($filterArgs as $arg) { + if ($arg instanceof Twig_Node_Expression_Constant) { + return array($arg->getAttribute('value')); + } + + return array(); + } + + return array('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).'); + } +} + +function _twig_escape_js_callback($matches) +{ + $char = $matches[0]; + + // \xHH + if (!isset($char[1])) { + return '\\x'.strtoupper(substr('00'.bin2hex($char), -2)); + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + + return '\\u'.strtoupper(substr('0000'.bin2hex($char), -4)); +} + +function _twig_escape_css_callback($matches) +{ + $char = $matches[0]; + + // \xHH + if (!isset($char[1])) { + $hex = ltrim(strtoupper(bin2hex($char)), '0'); + if (0 === strlen($hex)) { + $hex = '0'; + } + + return '\\'.$hex.' '; + } + + // \uHHHH + $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); + + return '\\'.ltrim(strtoupper(bin2hex($char)), '0').' '; +} + +/** + * This function is adapted from code coming from Zend Framework. + * + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +function _twig_escape_html_attr_callback($matches) +{ + /* + * 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 = array( + 34 => 'quot', /* quotation mark */ + 38 => 'amp', /* ampersand */ + 60 => 'lt', /* less-than sign */ + 62 => 'gt', /* greater-than sign */ + ); + + $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 && $chr != "\t" && $chr != "\n" && $chr != "\r") || ($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 (strlen($chr) == 1) { + $hex = strtoupper(substr('00'.bin2hex($chr), -2)); + } else { + $chr = twig_convert_encoding($chr, 'UTF-16BE', 'UTF-8'); + $hex = strtoupper(substr('0000'.bin2hex($chr), -4)); + } + + $int = hexdec($hex); + if (array_key_exists($int, $entityMap)) { + return sprintf('&%s;', $entityMap[$int]); + } + + /** + * Per OWASP recommendations, we'll use hex entities for any other + * characters where a named entity does not exist. + */ + return sprintf('&#x%s;', $hex); +} + +// add multibyte extensions if possible +if (function_exists('mb_get_info')) { + /** + * 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) + { + return is_scalar($thing) ? mb_strlen($thing, $env->getCharset()) : count($thing); + } + + /** + * Converts a string to uppercase. + * + * @param Twig_Environment $env A Twig_Environment instance + * @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 A Twig_Environment instance + * @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 A Twig_Environment instance + * @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 A Twig_Environment instance + * @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 A Twig_Environment instance + * @param mixed $thing A variable + * + * @return int The length of the value + */ + function twig_length_filter(Twig_Environment $env, $thing) + { + return is_scalar($thing) ? strlen($thing) : count($thing); + } + + /** + * Returns a titlecased string. + * + * @param Twig_Environment $env A Twig_Environment instance + * @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 A Twig_Environment instance + * @param string $string A string + * + * @return string The capitalized string + */ + function twig_capitalize_string_filter(Twig_Environment $env, $string) + { + return ucfirst(strtolower($string)); + } +} + +/* used internally */ +function twig_ensure_traversable($seq) +{ + if ($seq instanceof Traversable || is_array($seq)) { + return $seq; + } + + return array(); +} + +/** + * 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); + } + + return '' === $value || false === $value || null === $value || array() === $value; +} + +/** + * Checks if a variable is traversable. + * + *
    + * {# evaluates to true if the foo variable is an array or a traversable object #}
    + * {% if foo is traversable %}
    + *     {# ... #}
    + * {% 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 = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false) +{ + $alreadySandboxed = false; + $sandbox = null; + if ($withContext) { + $variables = array_merge($context, $variables); + } + + if ($isSandboxed = $sandboxed && $env->hasExtension('sandbox')) { + $sandbox = $env->getExtension('sandbox'); + if (!$alreadySandboxed = $sandbox->isSandboxed()) { + $sandbox->enableSandbox(); + } + } + + try { + return $env->resolveTemplate($template)->render($variables); + } catch (Twig_Error_Loader $e) { + if (!$ignoreMissing) { + throw $e; + } + } + + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } +} + +/** + * Returns a template content without rendering it. + * + * @param string $name The template name + * + * @return string The template source + */ +function twig_source(Twig_Environment $env, $name) +{ + return $env->getLoader()->getSource($name); +} + +/** + * Provides the ability to get constants from instances as well as class/global constants. + * + * @param string $constant The name of the constant + * @param null|object $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); +} + +/** + * 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) { + $last = count($result) - 1; + if ($fillCount = $size - count($result[$last])) { + $result[$last] = array_merge( + $result[$last], + array_fill(0, $fillCount, $fill) + ); + } + } + + return $result; +} diff --git a/vendor/twig/twig/lib/Twig/Extension/Debug.php b/vendor/twig/twig/lib/Twig/Extension/Debug.php new file mode 100755 index 0000000..e3a85bf --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/Debug.php @@ -0,0 +1,71 @@ + $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)), + ); + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + 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 = array(); + 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(); +} diff --git a/vendor/twig/twig/lib/Twig/Extension/Escaper.php b/vendor/twig/twig/lib/Twig/Extension/Escaper.php new file mode 100755 index 0000000..cf2020e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/Escaper.php @@ -0,0 +1,113 @@ +setDefaultStrategy($defaultStrategy); + } + + /** + * Returns the token parser instances to add to the existing list. + * + * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + */ + public function getTokenParsers() + { + return array(new Twig_TokenParser_AutoEscape()); + } + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances + */ + public function getNodeVisitors() + { + return array(new Twig_NodeVisitor_Escaper()); + } + + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + public function getFilters() + { + return array( + new Twig_SimpleFilter('raw', 'twig_raw_filter', array('is_safe' => array('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 + * "filename" as an argument and returns the strategy to use. + * + * @param mixed $defaultStrategy An escaping strategy + */ + public function setDefaultStrategy($defaultStrategy) + { + // for BC + if (true === $defaultStrategy) { + $defaultStrategy = 'html'; + } + + if ('filename' === $defaultStrategy) { + $defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess'); + } + + $this->defaultStrategy = $defaultStrategy; + } + + /** + * Gets the default strategy to use when not defined by the user. + * + * @param string $filename The template "filename" + * + * @return string The default strategy to use for the template + */ + public function getDefaultStrategy($filename) + { + // disable string callables to avoid calling a function named html or js, + // or any other upcoming escaping strategy + if (!is_string($this->defaultStrategy) && is_callable($this->defaultStrategy)) { + return call_user_func($this->defaultStrategy, $filename); + } + + return $this->defaultStrategy; + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + 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; +} diff --git a/vendor/twig/twig/lib/Twig/Extension/Optimizer.php b/vendor/twig/twig/lib/Twig/Extension/Optimizer.php new file mode 100755 index 0000000..013fcb6 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/Optimizer.php @@ -0,0 +1,35 @@ +optimizers = $optimizers; + } + + /** + * {@inheritdoc} + */ + public function getNodeVisitors() + { + return array(new Twig_NodeVisitor_Optimizer($this->optimizers)); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'optimizer'; + } +} diff --git a/vendor/twig/twig/lib/Twig/Extension/Profiler.php b/vendor/twig/twig/lib/Twig/Extension/Profiler.php new file mode 100755 index 0000000..35e04a0 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/Profiler.php @@ -0,0 +1,52 @@ +actives = array($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(); + } + } + + /** + * {@inheritdoc} + */ + public function getNodeVisitors() + { + return array(new Twig_Profiler_NodeVisitor_Profiler($this->getName())); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'profiler'; + } +} diff --git a/vendor/twig/twig/lib/Twig/Extension/Sandbox.php b/vendor/twig/twig/lib/Twig/Extension/Sandbox.php new file mode 100755 index 0000000..c58259c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/Sandbox.php @@ -0,0 +1,112 @@ +policy = $policy; + $this->sandboxedGlobally = $sandboxed; + } + + /** + * Returns the token parser instances to add to the existing list. + * + * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + */ + public function getTokenParsers() + { + return array(new Twig_TokenParser_Sandbox()); + } + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances + */ + public function getNodeVisitors() + { + return array(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; + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'sandbox'; + } +} diff --git a/vendor/twig/twig/lib/Twig/Extension/Staging.php b/vendor/twig/twig/lib/Twig/Extension/Staging.php new file mode 100755 index 0000000..8ab0f45 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/Staging.php @@ -0,0 +1,113 @@ + + */ +class Twig_Extension_Staging extends Twig_Extension +{ + protected $functions = array(); + protected $filters = array(); + protected $visitors = array(); + protected $tokenParsers = array(); + protected $globals = array(); + protected $tests = array(); + + public function addFunction($name, $function) + { + $this->functions[$name] = $function; + } + + /** + * {@inheritdoc} + */ + public function getFunctions() + { + return $this->functions; + } + + public function addFilter($name, $filter) + { + $this->filters[$name] = $filter; + } + + /** + * {@inheritdoc} + */ + public function getFilters() + { + return $this->filters; + } + + public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) + { + $this->visitors[] = $visitor; + } + + /** + * {@inheritdoc} + */ + public function getNodeVisitors() + { + return $this->visitors; + } + + public function addTokenParser(Twig_TokenParserInterface $parser) + { + $this->tokenParsers[] = $parser; + } + + /** + * {@inheritdoc} + */ + public function getTokenParsers() + { + return $this->tokenParsers; + } + + public function addGlobal($name, $value) + { + $this->globals[$name] = $value; + } + + /** + * {@inheritdoc} + */ + public function getGlobals() + { + return $this->globals; + } + + public function addTest($name, $test) + { + $this->tests[$name] = $test; + } + + /** + * {@inheritdoc} + */ + public function getTests() + { + return $this->tests; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'staging'; + } +} diff --git a/vendor/twig/twig/lib/Twig/Extension/StringLoader.php b/vendor/twig/twig/lib/Twig/Extension/StringLoader.php new file mode 100755 index 0000000..4e1a546 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Extension/StringLoader.php @@ -0,0 +1,47 @@ + true)), + ); + } + + /** + * {@inheritdoc} + */ + 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 + * + * @return Twig_Template A Twig_Template instance + */ +function twig_template_from_string(Twig_Environment $env, $template) +{ + return $env->createTemplate($template); +} diff --git a/vendor/twig/twig/lib/Twig/ExtensionInterface.php b/vendor/twig/twig/lib/Twig/ExtensionInterface.php new file mode 100755 index 0000000..49541b0 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/ExtensionInterface.php @@ -0,0 +1,83 @@ + + */ +interface Twig_ExtensionInterface +{ + /** + * 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); + + /** + * Returns the token parser instances to add to the existing list. + * + * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances + */ + public function getTokenParsers(); + + /** + * Returns the node visitor instances to add to the existing list. + * + * @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances + */ + public function getNodeVisitors(); + + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + public function getFilters(); + + /** + * Returns a list of tests to add to the existing list. + * + * @return array An array of tests + */ + public function getTests(); + + /** + * Returns a list of functions to add to the existing list. + * + * @return array An array of functions + */ + public function getFunctions(); + + /** + * Returns a list of operators to add to the existing list. + * + * @return array An array of operators + */ + public function getOperators(); + + /** + * Returns a list of global variables to add to the existing list. + * + * @return array An array of global variables + */ + public function getGlobals(); + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName(); +} diff --git a/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php b/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php new file mode 100755 index 0000000..b1ace7d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php @@ -0,0 +1,49 @@ + + */ +class Twig_FileExtensionEscapingStrategy +{ + /** + * Guesses the best autoescaping strategy based on the file name. + * + * @param string $filename The template file name + * + * @return string The escaping strategy name to use + */ + public static function guess($filename) + { + if (!preg_match('{\.(js|css|txt)(?:\.[^/\\\\]+)?$}', $filename, $match)) { + return 'html'; + } + + switch ($match[1]) { + case 'js': + return 'js'; + + case 'css': + return 'css'; + + case 'txt': + return false; + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Filter.php b/vendor/twig/twig/lib/Twig/Filter.php new file mode 100755 index 0000000..5cfbb66 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Filter.php @@ -0,0 +1,81 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface +{ + protected $options; + protected $arguments = array(); + + public function __construct(array $options = array()) + { + $this->options = array_merge(array( + '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/vendor/twig/twig/lib/Twig/Filter/Function.php b/vendor/twig/twig/lib/Twig/Filter/Function.php new file mode 100755 index 0000000..ad374a5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Filter/Function.php @@ -0,0 +1,37 @@ + + * @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 = array()) + { + $options['callable'] = $function; + + parent::__construct($options); + + $this->function = $function; + } + + public function compile() + { + return $this->function; + } +} diff --git a/vendor/twig/twig/lib/Twig/Filter/Method.php b/vendor/twig/twig/lib/Twig/Filter/Method.php new file mode 100755 index 0000000..63c8c3b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Filter/Method.php @@ -0,0 +1,39 @@ + + * @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 = array()) + { + $options['callable'] = array($extension, $method); + + parent::__construct($options); + + $this->extension = $extension; + $this->method = $method; + } + + public function compile() + { + return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); + } +} diff --git a/vendor/twig/twig/lib/Twig/Filter/Node.php b/vendor/twig/twig/lib/Twig/Filter/Node.php new file mode 100755 index 0000000..8744c5e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Filter/Node.php @@ -0,0 +1,39 @@ + + * @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 = array()) + { + parent::__construct($options); + + $this->class = $class; + } + + public function getClass() + { + return $this->class; + } + + public function compile() + { + } +} diff --git a/vendor/twig/twig/lib/Twig/FilterCallableInterface.php b/vendor/twig/twig/lib/Twig/FilterCallableInterface.php new file mode 100755 index 0000000..145534d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/FilterCallableInterface.php @@ -0,0 +1,23 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_FilterCallableInterface +{ + public function getCallable(); +} diff --git a/vendor/twig/twig/lib/Twig/FilterInterface.php b/vendor/twig/twig/lib/Twig/FilterInterface.php new file mode 100755 index 0000000..5319ecc --- /dev/null +++ b/vendor/twig/twig/lib/Twig/FilterInterface.php @@ -0,0 +1,42 @@ + + * @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/vendor/twig/twig/lib/Twig/Function.php b/vendor/twig/twig/lib/Twig/Function.php new file mode 100755 index 0000000..b5ffb2b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Function.php @@ -0,0 +1,71 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface +{ + protected $options; + protected $arguments = array(); + + public function __construct(array $options = array()) + { + $this->options = array_merge(array( + '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 array(); + } + + public function getCallable() + { + return $this->options['callable']; + } +} diff --git a/vendor/twig/twig/lib/Twig/Function/Function.php b/vendor/twig/twig/lib/Twig/Function/Function.php new file mode 100755 index 0000000..d1e1b96 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Function/Function.php @@ -0,0 +1,38 @@ + + * @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 = array()) + { + $options['callable'] = $function; + + parent::__construct($options); + + $this->function = $function; + } + + public function compile() + { + return $this->function; + } +} diff --git a/vendor/twig/twig/lib/Twig/Function/Method.php b/vendor/twig/twig/lib/Twig/Function/Method.php new file mode 100755 index 0000000..67039a9 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Function/Method.php @@ -0,0 +1,40 @@ + + * @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 = array()) + { + $options['callable'] = array($extension, $method); + + parent::__construct($options); + + $this->extension = $extension; + $this->method = $method; + } + + public function compile() + { + return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); + } +} diff --git a/vendor/twig/twig/lib/Twig/Function/Node.php b/vendor/twig/twig/lib/Twig/Function/Node.php new file mode 100755 index 0000000..06a0d0d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Function/Node.php @@ -0,0 +1,39 @@ + + * @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 = array()) + { + parent::__construct($options); + + $this->class = $class; + } + + public function getClass() + { + return $this->class; + } + + public function compile() + { + } +} diff --git a/vendor/twig/twig/lib/Twig/FunctionCallableInterface.php b/vendor/twig/twig/lib/Twig/FunctionCallableInterface.php new file mode 100755 index 0000000..0aab4f5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/FunctionCallableInterface.php @@ -0,0 +1,23 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_FunctionCallableInterface +{ + public function getCallable(); +} diff --git a/vendor/twig/twig/lib/Twig/FunctionInterface.php b/vendor/twig/twig/lib/Twig/FunctionInterface.php new file mode 100755 index 0000000..67f4f89 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/FunctionInterface.php @@ -0,0 +1,39 @@ + + * @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/vendor/twig/twig/lib/Twig/Lexer.php b/vendor/twig/twig/lib/Twig/Lexer.php new file mode 100755 index 0000000..19380b5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Lexer.php @@ -0,0 +1,407 @@ + + */ +class Twig_Lexer implements Twig_LexerInterface +{ + protected $tokens; + protected $code; + protected $cursor; + protected $lineno; + protected $end; + protected $state; + protected $states; + protected $brackets; + protected $env; + protected $filename; + protected $options; + protected $regexes; + protected $position; + protected $positions; + protected $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 = array()) + { + $this->env = $env; + + $this->options = array_merge(array( + 'tag_comment' => array('{#', '#}'), + 'tag_block' => array('{%', '%}'), + 'tag_variable' => array('{{', '}}'), + 'whitespace_trim' => '-', + 'interpolation' => array('#{', '}'), + ), $options); + + $this->regexes = array( + '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', + ); + } + + /** + * {@inheritdoc} + */ + public function tokenize($code, $filename = null) + { + 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(array("\r\n", "\r"), "\n", $code); + $this->filename = $filename; + $this->cursor = 0; + $this->lineno = 1; + $this->end = strlen($this->code); + $this->tokens = array(); + $this->state = self::STATE_DATA; + $this->states = array(); + $this->brackets = array(); + $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->filename); + } + + if ($mbEncoding) { + mb_internal_encoding($mbEncoding); + } + + return new Twig_TokenStream($this->tokens, $this->filename); + } + + 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"', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->filename); + } + } + + // 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[] = array($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->filename); + } + + 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->filename); + } + } + + $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[] = array('"', $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->filename); + } + } + + protected function lexRawData($tag) + { + 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->filename); + } + + $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->filename); + } + + $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[] = array($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->filename); + } + + $this->popState(); + ++$this->cursor; + } + } + + 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('='), + array_keys($this->env->getUnaryOperators()), + array_keys($this->env->getBinaryOperators()) + ); + + $operators = array_combine($operators, array_map('strlen', $operators)); + arsort($operators); + + $regex = array(); + 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); + } +} diff --git a/vendor/twig/twig/lib/Twig/LexerInterface.php b/vendor/twig/twig/lib/Twig/LexerInterface.php new file mode 100755 index 0000000..24a9478 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/LexerInterface.php @@ -0,0 +1,32 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_LexerInterface +{ + /** + * Tokenizes a source code. + * + * @param string $code The source code + * @param string $filename A unique identifier for the source code + * + * @return Twig_TokenStream A token stream instance + * + * @throws Twig_Error_Syntax When the code is syntactically wrong + */ + public function tokenize($code, $filename = null); +} diff --git a/vendor/twig/twig/lib/Twig/Loader/Array.php b/vendor/twig/twig/lib/Twig/Loader/Array.php new file mode 100755 index 0000000..436edd8 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Loader/Array.php @@ -0,0 +1,97 @@ + + */ +class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface +{ + protected $templates = array(); + + /** + * Constructor. + * + * @param array $templates An array of templates (keys are the names, and values are the source code) + * + * @see Twig_Loader + */ + 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; + } + + /** + * {@inheritdoc} + */ + public function getSource($name) + { + $name = (string) $name; + if (!isset($this->templates[$name])) { + throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); + } + + return $this->templates[$name]; + } + + /** + * {@inheritdoc} + */ + public function exists($name) + { + return isset($this->templates[(string) $name]); + } + + /** + * {@inheritdoc} + */ + 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 $this->templates[$name]; + } + + /** + * {@inheritdoc} + */ + 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; + } +} diff --git a/vendor/twig/twig/lib/Twig/Loader/Chain.php b/vendor/twig/twig/lib/Twig/Loader/Chain.php new file mode 100755 index 0000000..7919eda --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Loader/Chain.php @@ -0,0 +1,138 @@ + + */ +class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface +{ + private $hasSourceCache = array(); + protected $loaders = array(); + + /** + * Constructor. + * + * @param Twig_LoaderInterface[] $loaders An array of loader instances + */ + public function __construct(array $loaders = array()) + { + foreach ($loaders as $loader) { + $this->addLoader($loader); + } + } + + /** + * Adds a loader instance. + * + * @param Twig_LoaderInterface $loader A Loader instance + */ + public function addLoader(Twig_LoaderInterface $loader) + { + $this->loaders[] = $loader; + $this->hasSourceCache = array(); + } + + /** + * {@inheritdoc} + */ + public function getSource($name) + { + $exceptions = array(); + 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, implode(', ', $exceptions))); + } + + /** + * {@inheritdoc} + */ + 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 { + $loader->getSource($name); + + return $this->hasSourceCache[$name] = true; + } catch (Twig_Error_Loader $e) { + } + } + + return $this->hasSourceCache[$name] = false; + } + + /** + * {@inheritdoc} + */ + public function getCacheKey($name) + { + $exceptions = array(); + 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, implode(' ', $exceptions))); + } + + /** + * {@inheritdoc} + */ + public function isFresh($name, $time) + { + $exceptions = array(); + 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, implode(' ', $exceptions))); + } +} diff --git a/vendor/twig/twig/lib/Twig/Loader/Filesystem.php b/vendor/twig/twig/lib/Twig/Loader/Filesystem.php new file mode 100755 index 0000000..818a461 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Loader/Filesystem.php @@ -0,0 +1,240 @@ + + */ +class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface +{ + /** Identifier of the main namespace. */ + const MAIN_NAMESPACE = '__main__'; + + protected $paths = array(); + protected $cache = array(); + + /** + * Constructor. + * + * @param string|array $paths A path or an array of paths where to look for templates + */ + public function __construct($paths = array()) + { + 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] : array(); + } + + /** + * 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 = array($paths); + } + + $this->paths[$namespace] = array(); + 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 name + * + * @throws Twig_Error_Loader + */ + public function addPath($path, $namespace = self::MAIN_NAMESPACE) + { + // invalidate the cache + $this->cache = array(); + + if (!is_dir($path)) { + throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); + } + + $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 name + * + * @throws Twig_Error_Loader + */ + public function prependPath($path, $namespace = self::MAIN_NAMESPACE) + { + // invalidate the cache + $this->cache = array(); + + if (!is_dir($path)) { + throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path)); + } + + $path = rtrim($path, '/\\'); + + if (!isset($this->paths[$namespace])) { + $this->paths[$namespace][] = $path; + } else { + array_unshift($this->paths[$namespace], $path); + } + } + + /** + * {@inheritdoc} + */ + public function getSource($name) + { + return file_get_contents($this->findTemplate($name)); + } + + /** + * {@inheritdoc} + */ + public function getCacheKey($name) + { + return $this->findTemplate($name); + } + + /** + * {@inheritdoc} + */ + public function exists($name) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return true; + } + + try { + $this->findTemplate($name); + + return true; + } catch (Twig_Error_Loader $exception) { + return false; + } + } + + /** + * {@inheritdoc} + */ + public function isFresh($name, $time) + { + return filemtime($this->findTemplate($name)) <= $time; + } + + protected function findTemplate($name) + { + $name = $this->normalizeName($name); + + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } + + $this->validateName($name); + + list($namespace, $shortname) = $this->parseName($name); + + if (!isset($this->paths[$namespace])) { + throw new Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); + } + + foreach ($this->paths[$namespace] as $path) { + if (is_file($path.'/'.$shortname)) { + if (false !== $realpath = realpath($path.'/'.$shortname)) { + return $this->cache[$name] = $realpath; + } + + return $this->cache[$name] = $path.'/'.$shortname; + } + } + + throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]))); + } + + 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 array($namespace, $shortname); + } + + return array($default, $name); + } + + protected function normalizeName($name) + { + return preg_replace('#/{2,}#', '/', strtr((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)); + } + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Loader/String.php b/vendor/twig/twig/lib/Twig/Loader/String.php new file mode 100755 index 0000000..63d6890 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Loader/String.php @@ -0,0 +1,59 @@ + + */ +class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface +{ + /** + * {@inheritdoc} + */ + public function getSource($name) + { + return $name; + } + + /** + * {@inheritdoc} + */ + public function exists($name) + { + return true; + } + + /** + * {@inheritdoc} + */ + public function getCacheKey($name) + { + return $name; + } + + /** + * {@inheritdoc} + */ + public function isFresh($name, $time) + { + return true; + } +} diff --git a/vendor/twig/twig/lib/Twig/LoaderInterface.php b/vendor/twig/twig/lib/Twig/LoaderInterface.php new file mode 100755 index 0000000..9cd45e2 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/LoaderInterface.php @@ -0,0 +1,53 @@ + + */ +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 + */ + 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); +} diff --git a/vendor/twig/twig/lib/Twig/Markup.php b/vendor/twig/twig/lib/Twig/Markup.php new file mode 100755 index 0000000..69871fc --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Markup.php @@ -0,0 +1,37 @@ + + */ +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); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node.php b/vendor/twig/twig/lib/Twig/Node.php new file mode 100755 index 0000000..1c78e7b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node.php @@ -0,0 +1,229 @@ + + */ +class Twig_Node implements Twig_NodeInterface +{ + protected $nodes; + protected $attributes; + protected $lineno; + protected $tag; + + /** + * 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(), array $attributes = array(), $lineno = 0, $tag = null) + { + $this->nodes = $nodes; + $this->attributes = $attributes; + $this->lineno = $lineno; + $this->tag = $tag; + } + + public function __toString() + { + $attributes = array(); + foreach ($this->attributes as $name => $value) { + $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); + } + + $repr = array(get_class($this).'('.implode(', ', $attributes)); + + if (count($this->nodes)) { + foreach ($this->nodes as $name => $node) { + $len = strlen($name) + 4; + $noderepr = array(); + 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) + { + $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 getLine() + { + return $this->lineno; + } + + public function getNodeTag() + { + return $this->tag; + } + + /** + * Returns true if the attribute is defined. + * + * @param string $name The attribute name + * + * @return bool true if the attribute is defined, false otherwise + */ + public function hasAttribute($name) + { + return array_key_exists($name, $this->attributes); + } + + /** + * Gets an attribute value by name. + * + * @param string $name + * + * @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]; + } + + /** + * Sets an attribute by name to a value. + * + * @param string $name + * @param mixed $value + */ + public function setAttribute($name, $value) + { + $this->attributes[$name] = $value; + } + + /** + * Removes an attribute by name. + * + * @param string $name + */ + public function removeAttribute($name) + { + unset($this->attributes[$name]); + } + + /** + * Returns true if the node with the given name exists. + * + * @param string $name + * + * @return bool + */ + public function hasNode($name) + { + return array_key_exists($name, $this->nodes); + } + + /** + * Gets a node by name. + * + * @param string $name + * + * @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]; + } + + /** + * Sets a node. + * + * @param string $name + * @param Twig_Node $node + */ + public function setNode($name, $node = null) + { + $this->nodes[$name] = $node; + } + + /** + * Removes a node by name. + * + * @param string $name + */ + public function removeNode($name) + { + unset($this->nodes[$name]); + } + + public function count() + { + return count($this->nodes); + } + + public function getIterator() + { + return new ArrayIterator($this->nodes); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/AutoEscape.php b/vendor/twig/twig/lib/Twig/Node/AutoEscape.php new file mode 100755 index 0000000..fcabf90 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/AutoEscape.php @@ -0,0 +1,39 @@ + + */ +class Twig_Node_AutoEscape extends Twig_Node +{ + public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape') + { + parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->subcompile($this->getNode('body')); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Block.php b/vendor/twig/twig/lib/Twig/Node/Block.php new file mode 100755 index 0000000..989e4a0 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Block.php @@ -0,0 +1,44 @@ + + */ +class Twig_Node_Block extends Twig_Node +{ + public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null) + { + parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n") + ->indent() + ; + + $compiler + ->subcompile($this->getNode('body')) + ->outdent() + ->write("}\n\n") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/BlockReference.php b/vendor/twig/twig/lib/Twig/Node/BlockReference.php new file mode 100755 index 0000000..a05ea04 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/BlockReference.php @@ -0,0 +1,37 @@ + + */ +class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface +{ + public function __construct($name, $lineno, $tag = null) + { + parent::__construct(array(), array('name' => $name), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Body.php b/vendor/twig/twig/lib/Twig/Node/Body.php new file mode 100755 index 0000000..3ffb134 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Body.php @@ -0,0 +1,19 @@ + + */ +class Twig_Node_Body extends Twig_Node +{ +} diff --git a/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php b/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php new file mode 100755 index 0000000..3040b76 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/CheckSecurity.php @@ -0,0 +1,78 @@ + + */ +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 = array(); + foreach (array('tags', 'filters', 'functions') as $type) { + foreach ($this->{'used'.ucfirst($type)} as $name => $node) { + if ($node instanceof Twig_Node) { + ${$type}[$name] = $node->getLine(); + } 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('sandbox')->checkSecurity(\n") + ->indent() + ->write(!$tags ? "array(),\n" : "array('".implode("', '", array_keys($tags))."'),\n") + ->write(!$filters ? "array(),\n" : "array('".implode("', '", array_keys($filters))."'),\n") + ->write(!$functions ? "array()\n" : "array('".implode("', '", array_keys($functions))."')\n") + ->outdent() + ->write(");\n") + ->outdent() + ->write("} catch (Twig_Sandbox_SecurityError \$e) {\n") + ->indent() + ->write("\$e->setTemplateFile(\$this->getTemplateName());\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") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Do.php b/vendor/twig/twig/lib/Twig/Node/Do.php new file mode 100755 index 0000000..9981bc1 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Do.php @@ -0,0 +1,38 @@ + + */ +class Twig_Node_Do extends Twig_Node +{ + public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + { + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Embed.php b/vendor/twig/twig/lib/Twig/Node/Embed.php new file mode 100755 index 0000000..c54d2cc --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Embed.php @@ -0,0 +1,42 @@ + + */ +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($filename, $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('filename', $filename); + $this->setAttribute('index', $index); + } + + protected function addGetTemplate(Twig_Compiler $compiler) + { + $compiler + ->write("\$this->loadTemplate(") + ->string($this->getAttribute('filename')) + ->raw(', ') + ->repr($compiler->getFilename()) + ->raw(', ') + ->repr($this->getLine()) + ->raw(', ') + ->string($this->getAttribute('index')) + ->raw(")") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression.php b/vendor/twig/twig/lib/Twig/Node/Expression.php new file mode 100755 index 0000000..a7382e7 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression.php @@ -0,0 +1,20 @@ + + */ +abstract class Twig_Node_Expression extends Twig_Node +{ +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Array.php b/vendor/twig/twig/lib/Twig/Node/Expression/Array.php new file mode 100755 index 0000000..6cf7ca1 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Array.php @@ -0,0 +1,86 @@ +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 = array(); + + foreach (array_chunk($this->nodes, 2) as $pair) { + $pairs[] = array( + '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->getLine()); + } + + array_push($this->nodes, $key, $value); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->raw('array('); + $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/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php b/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php new file mode 100755 index 0000000..4d5dbdb --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php @@ -0,0 +1,28 @@ +raw('$context[') + ->string($this->getAttribute('name')) + ->raw(']') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php new file mode 100755 index 0000000..5c383d1 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php @@ -0,0 +1,40 @@ + $left, 'right' => $right), array(), $lineno); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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); +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Add.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Add.php new file mode 100755 index 0000000..0ef8e11 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Add.php @@ -0,0 +1,18 @@ +raw('+'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/And.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/And.php new file mode 100755 index 0000000..d5752eb --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/And.php @@ -0,0 +1,18 @@ +raw('&&'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php new file mode 100755 index 0000000..9a46d84 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseAnd.php @@ -0,0 +1,18 @@ +raw('&'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php new file mode 100755 index 0000000..058a20b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseOr.php @@ -0,0 +1,18 @@ +raw('|'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php new file mode 100755 index 0000000..f4da73d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/BitwiseXor.php @@ -0,0 +1,18 @@ +raw('^'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Concat.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Concat.php new file mode 100755 index 0000000..f9a6462 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Concat.php @@ -0,0 +1,18 @@ +raw('.'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Div.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Div.php new file mode 100755 index 0000000..e0797a6 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Div.php @@ -0,0 +1,18 @@ +raw('/'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php new file mode 100755 index 0000000..93b3b96 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php @@ -0,0 +1,30 @@ +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(''); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Equal.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Equal.php new file mode 100755 index 0000000..7b1236d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Equal.php @@ -0,0 +1,17 @@ +raw('=='); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php new file mode 100755 index 0000000..d3518b5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php @@ -0,0 +1,29 @@ +raw('intval(floor('); + parent::compile($compiler); + $compiler->raw('))'); + } + + public function operator(Twig_Compiler $compiler) + { + return $compiler->raw('/'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Greater.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Greater.php new file mode 100755 index 0000000..a110bd9 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Greater.php @@ -0,0 +1,17 @@ +raw('>'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php new file mode 100755 index 0000000..3754fed --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/GreaterEqual.php @@ -0,0 +1,17 @@ +raw('>='); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php new file mode 100755 index 0000000..1d485b6 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php @@ -0,0 +1,33 @@ +raw('twig_in_filter(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Twig_Compiler $compiler) + { + return $compiler->raw('in'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Less.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Less.php new file mode 100755 index 0000000..45fd300 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Less.php @@ -0,0 +1,17 @@ +raw('<'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/LessEqual.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/LessEqual.php new file mode 100755 index 0000000..e38e257 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/LessEqual.php @@ -0,0 +1,17 @@ +raw('<='); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Matches.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Matches.php new file mode 100755 index 0000000..93bb292 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Matches.php @@ -0,0 +1,28 @@ +raw('preg_match(') + ->subcompile($this->getNode('right')) + ->raw(', ') + ->subcompile($this->getNode('left')) + ->raw(')') + ; + } + + public function operator(Twig_Compiler $compiler) + { + return $compiler->raw(''); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mod.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mod.php new file mode 100755 index 0000000..9924114 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mod.php @@ -0,0 +1,18 @@ +raw('%'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mul.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mul.php new file mode 100755 index 0000000..c91529c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Mul.php @@ -0,0 +1,18 @@ +raw('*'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotEqual.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotEqual.php new file mode 100755 index 0000000..26867ba --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotEqual.php @@ -0,0 +1,17 @@ +raw('!='); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php new file mode 100755 index 0000000..8f215f1 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php @@ -0,0 +1,33 @@ +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'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Or.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Or.php new file mode 100755 index 0000000..adba49c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Or.php @@ -0,0 +1,18 @@ +raw('||'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php new file mode 100755 index 0000000..6cd3a21 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php @@ -0,0 +1,33 @@ +raw('pow(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Twig_Compiler $compiler) + { + return $compiler->raw('**'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php new file mode 100755 index 0000000..fc102fe --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php @@ -0,0 +1,33 @@ +raw('range(') + ->subcompile($this->getNode('left')) + ->raw(', ') + ->subcompile($this->getNode('right')) + ->raw(')') + ; + } + + public function operator(Twig_Compiler $compiler) + { + return $compiler->raw('..'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php new file mode 100755 index 0000000..d2e30d6 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php @@ -0,0 +1,30 @@ +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(''); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Sub.php b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Sub.php new file mode 100755 index 0000000..d446399 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Sub.php @@ -0,0 +1,18 @@ +raw('-'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php b/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php new file mode 100755 index 0000000..4ddb2cf --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php @@ -0,0 +1,51 @@ + + */ +class Twig_Node_Expression_BlockReference extends Twig_Node_Expression +{ + public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null) + { + parent::__construct(array('name' => $name), array('as_string' => $asString, 'output' => false), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + if ($this->getAttribute('as_string')) { + $compiler->raw('(string) '); + } + + if ($this->getAttribute('output')) { + $compiler + ->addDebugInfo($this) + ->write("\$this->displayBlock(") + ->subcompile($this->getNode('name')) + ->raw(", \$context, \$blocks);\n") + ; + } else { + $compiler + ->raw("\$this->renderBlock(") + ->subcompile($this->getNode('name')) + ->raw(", \$context, \$blocks)") + ; + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Call.php b/vendor/twig/twig/lib/Twig/Node/Expression/Call.php new file mode 100755 index 0000000..998160b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Call.php @@ -0,0 +1,210 @@ +hasAttribute('callable') && $callable = $this->getAttribute('callable')) { + if (is_string($callable)) { + $compiler->raw($callable); + } elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) { + $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', $callable[0]->getName(), $callable[1])); + } else { + $type = ucfirst($this->getAttribute('type')); + $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name'))); + $closingParenthesis = true; + } + } else { + $compiler->raw($this->getAttribute('thing')->compile()); + } + + $this->compileArguments($compiler); + + if ($closingParenthesis) { + $compiler->raw(')'); + } + } + + protected function compileArguments(Twig_Compiler $compiler) + { + $compiler->raw('('); + + $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') && null !== $this->getNode('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(')'); + } + + protected function getArguments($callable, $arguments) + { + $callType = $this->getAttribute('type'); + $callName = $this->getAttribute('name'); + + $parameters = array(); + $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)); + } + + $parameters[$name] = $node; + } + + if (!$named) { + return $parameters; + } + + if (!$callable) { + throw new LogicException(sprintf('Named arguments are not supported for %s "%s".', $callType, $callName)); + } + + // manage named arguments + if (is_array($callable)) { + $r = new ReflectionMethod($callable[0], $callable[1]); + } elseif (is_object($callable) && !$callable instanceof Closure) { + $r = new ReflectionObject($callable); + $r = $r->getMethod('__invoke'); + } elseif (is_string($callable) && false !== strpos($callable, '::')) { + $r = new ReflectionMethod($callable); + } else { + $r = new ReflectionFunction($callable); + } + + $definition = $r->getParameters(); + if ($this->hasNode('node')) { + array_shift($definition); + } + if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { + array_shift($definition); + } + if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { + array_shift($definition); + } + if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { + foreach ($this->getAttribute('arguments') as $argument) { + array_shift($definition); + } + } + + $arguments = array(); + $names = array(); + $missingArguments = array(); + $optionalArguments = array(); + $pos = 0; + foreach ($definition as $param) { + $names[] = $name = $this->normalizeName($param->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)); + } + + if (!empty($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)) + ); + } + + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$name]; + unset($parameters[$name]); + $optionalArguments = array(); + } elseif (array_key_exists($pos, $parameters)) { + $arguments = array_merge($arguments, $optionalArguments); + $arguments[] = $parameters[$pos]; + unset($parameters[$pos]); + $optionalArguments = array(); + ++$pos; + } elseif ($param->isDefaultValueAvailable()) { + $optionalArguments[] = new Twig_Node_Expression_Constant($param->getDefaultValue(), -1); + } elseif ($param->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)); + } + } + + 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->getLine() : -1); + } + + return $arguments; + } + + protected function normalizeName($name) + { + return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), $name)); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Conditional.php b/vendor/twig/twig/lib/Twig/Node/Expression/Conditional.php new file mode 100755 index 0000000..edcb1e2 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Conditional.php @@ -0,0 +1,31 @@ + $expr1, 'expr2' => $expr2, 'expr3' => $expr3), array(), $lineno); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('((') + ->subcompile($this->getNode('expr1')) + ->raw(') ? (') + ->subcompile($this->getNode('expr2')) + ->raw(') : (') + ->subcompile($this->getNode('expr3')) + ->raw('))') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Constant.php b/vendor/twig/twig/lib/Twig/Node/Expression/Constant.php new file mode 100755 index 0000000..a91dc69 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Constant.php @@ -0,0 +1,23 @@ + $value), $lineno); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler->repr($this->getAttribute('value')); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php b/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php new file mode 100755 index 0000000..db06abb --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php @@ -0,0 +1,33 @@ + + */ +class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression +{ + public function __construct($name, $lineno, $tag = null) + { + parent::__construct(array(), array('name' => $name), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php b/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php new file mode 100755 index 0000000..207b062 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Filter.php @@ -0,0 +1,36 @@ + $node, 'filter' => $filterName, 'arguments' => $arguments), array(), $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()); + } + + $this->compileCallable($compiler); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php b/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php new file mode 100755 index 0000000..1827c88 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Filter/Default.php @@ -0,0 +1,43 @@ + + * {{ 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->getLine()), $arguments, $node->getLine()); + + 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->getLine()); + $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getLine()); + + $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getLine()); + } else { + $node = $default; + } + + parent::__construct($node, $filterName, $arguments, $lineno, $tag); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler->subcompile($this->getNode('node')); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Function.php b/vendor/twig/twig/lib/Twig/Node/Expression/Function.php new file mode 100755 index 0000000..3e1f6b5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Function.php @@ -0,0 +1,35 @@ + $arguments), array('name' => $name), $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) { + $this->setAttribute('callable', $function->getCallable()); + } + + $this->compileCallable($compiler); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php b/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php new file mode 100755 index 0000000..6ce6111 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php @@ -0,0 +1,63 @@ + $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno); + } + + public function compile(Twig_Compiler $compiler) + { + 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 || null !== $this->getNode('arguments'); + + if ($needFirst) { + if (null !== $this->getNode('arguments')) { + $compiler->raw(', ')->subcompile($this->getNode('arguments')); + } else { + $compiler->raw(', array()'); + } + } + + 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(')'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/MethodCall.php b/vendor/twig/twig/lib/Twig/Node/Expression/MethodCall.php new file mode 100755 index 0000000..620b02b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/MethodCall.php @@ -0,0 +1,41 @@ + $node, 'arguments' => $arguments), array('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(')'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Name.php b/vendor/twig/twig/lib/Twig/Node/Expression/Name.php new file mode 100755 index 0000000..0bfcdbc --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Name.php @@ -0,0 +1,90 @@ + '$this', + '_context' => '$context', + '_charset' => '$this->env->getCharset()', + ); + + public function __construct($name, $lineno) + { + parent::__construct(array(), array('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('array_key_exists(')->repr($name)->raw(', $context)'); + } + } elseif ($this->isSpecial()) { + $compiler->raw($this->specialVars[$name]); + } elseif ($this->getAttribute('always_defined')) { + $compiler + ->raw('$context[') + ->string($name) + ->raw(']') + ; + } else { + // remove the non-PHP 5.4 version when PHP 5.3 support is dropped + // as the non-optimized version is just a workaround for slow ternary operator + // when the context has a lot of variables + if (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'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php b/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php new file mode 100755 index 0000000..a22ce03 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php @@ -0,0 +1,47 @@ + + */ +class Twig_Node_Expression_Parent extends Twig_Node_Expression +{ + public function __construct($name, $lineno, $tag = null) + { + parent::__construct(array(), array('output' => false, 'name' => $name), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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)") + ; + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/TempName.php b/vendor/twig/twig/lib/Twig/Node/Expression/TempName.php new file mode 100755 index 0000000..e6b058e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/TempName.php @@ -0,0 +1,26 @@ + $name), $lineno); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('$_') + ->raw($this->getAttribute('name')) + ->raw('_') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test.php new file mode 100755 index 0000000..639f501 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test.php @@ -0,0 +1,32 @@ + $node, 'arguments' => $arguments), array('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_TestCallableInterface || $test instanceof Twig_SimpleTest) { + $this->setAttribute('callable', $test->getCallable()); + } + + $this->compileCallable($compiler); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Constant.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Constant.php new file mode 100755 index 0000000..de55f5f --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Constant.php @@ -0,0 +1,46 @@ + + * {% 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('))') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php new file mode 100755 index 0000000..247b2e2 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php @@ -0,0 +1,54 @@ + + * {# 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) + { + parent::__construct($node, $name, $arguments, $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); + } else { + throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine()); + } + } + + 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')); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php new file mode 100755 index 0000000..d5bed23 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php @@ -0,0 +1,33 @@ + + * {% 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(')') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Even.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Even.php new file mode 100755 index 0000000..d7853e8 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Even.php @@ -0,0 +1,32 @@ + + * {{ 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(')') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Null.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Null.php new file mode 100755 index 0000000..1c83825 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Null.php @@ -0,0 +1,31 @@ + + * {{ 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(')') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Odd.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Odd.php new file mode 100755 index 0000000..421c19e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Odd.php @@ -0,0 +1,32 @@ + + * {{ 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(')') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Test/Sameas.php b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Sameas.php new file mode 100755 index 0000000..b48905e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Test/Sameas.php @@ -0,0 +1,29 @@ + + */ +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(')') + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php b/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php new file mode 100755 index 0000000..1cf54c3 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Unary.php @@ -0,0 +1,27 @@ + $node), array(), $lineno); + } + + public function compile(Twig_Compiler $compiler) + { + $compiler->raw(' '); + $this->operator($compiler); + $compiler->subcompile($this->getNode('node')); + } + + abstract public function operator(Twig_Compiler $compiler); +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Neg.php b/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Neg.php new file mode 100755 index 0000000..2a3937e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Neg.php @@ -0,0 +1,18 @@ +raw('-'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Not.php b/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Not.php new file mode 100755 index 0000000..f94073c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Not.php @@ -0,0 +1,18 @@ +raw('!'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Pos.php b/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Pos.php new file mode 100755 index 0000000..04edb52 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Expression/Unary/Pos.php @@ -0,0 +1,18 @@ +raw('+'); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Flush.php b/vendor/twig/twig/lib/Twig/Node/Flush.php new file mode 100755 index 0000000..20d6aab --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Flush.php @@ -0,0 +1,36 @@ + + */ +class Twig_Node_Flush extends Twig_Node +{ + public function __construct($lineno, $tag) + { + parent::__construct(array(), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("flush();\n") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/For.php b/vendor/twig/twig/lib/Twig/Node/For.php new file mode 100755 index 0000000..c54a23c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/For.php @@ -0,0 +1,112 @@ + + */ +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(array($body, $this->loop = new Twig_Node_ForLoop($lineno, $tag))); + + if (null !== $ifexpr) { + $body = new Twig_Node_If(new Twig_Node(array($ifexpr, $body)), null, $lineno, $tag); + } + + parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + // the (array) cast bypasses a PHP 5.2.6 bug + ->write("\$context['_parent'] = (array) \$context;\n") + ->write("\$context['_seq'] = twig_ensure_traversable(") + ->subcompile($this->getNode('seq')) + ->raw(");\n") + ; + + if (null !== $this->getNode('else')) { + $compiler->write("\$context['_iterated'] = false;\n"); + } + + if ($this->getAttribute('with_loop')) { + $compiler + ->write("\$context['loop'] = array(\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', null !== $this->getNode('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 (null !== $this->getNode('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/vendor/twig/twig/lib/Twig/Node/ForLoop.php b/vendor/twig/twig/lib/Twig/Node/ForLoop.php new file mode 100755 index 0000000..d330283 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/ForLoop.php @@ -0,0 +1,55 @@ + + */ +class Twig_Node_ForLoop extends Twig_Node +{ + public function __construct($lineno, $tag = null) + { + parent::__construct(array(), array('with_loop' => false, 'ifexpr' => false, 'else' => false), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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") + ; + } + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/If.php b/vendor/twig/twig/lib/Twig/Node/If.php new file mode 100755 index 0000000..980274e --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/If.php @@ -0,0 +1,66 @@ + + */ +class Twig_Node_If extends Twig_Node +{ + public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null) + { + parent::__construct(array('tests' => $tests, 'else' => $else), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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') && null !== $this->getNode('else')) { + $compiler + ->outdent() + ->write("} else {\n") + ->indent() + ->subcompile($this->getNode('else')) + ; + } + + $compiler + ->outdent() + ->write("}\n"); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Import.php b/vendor/twig/twig/lib/Twig/Node/Import.php new file mode 100755 index 0000000..5e4aa11 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Import.php @@ -0,0 +1,54 @@ + + */ +class Twig_Node_Import extends Twig_Node +{ + public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $var, $lineno, $tag = null) + { + parent::__construct(array('expr' => $expr, 'var' => $var), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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($compiler->getFilename()) + ->raw(', ') + ->repr($this->getLine()) + ->raw(")") + ; + } + + $compiler->raw(";\n"); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Include.php b/vendor/twig/twig/lib/Twig/Node/Include.php new file mode 100755 index 0000000..46b0685 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Include.php @@ -0,0 +1,88 @@ + + */ +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) + { + parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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($compiler->getFilename()) + ->raw(', ') + ->repr($this->getLine()) + ->raw(")") + ; + } + + protected function addTemplateArguments(Twig_Compiler $compiler) + { + if (null === $this->getNode('variables')) { + $compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()'); + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('array_merge($context, ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; + } else { + $compiler->subcompile($this->getNode('variables')); + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Macro.php b/vendor/twig/twig/lib/Twig/Node/Macro.php new file mode 100755 index 0000000..ab7e8d2 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Macro.php @@ -0,0 +1,96 @@ + + */ +class Twig_Node_Macro extends Twig_Node +{ + public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null) + { + parent::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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(', '); + } + } + + $compiler + ->raw(")\n") + ->write("{\n") + ->indent() + ; + + if (!count($this->getNode('arguments'))) { + $compiler->write("\$context = \$this->env->getGlobals();\n\n"); + } else { + $compiler + ->write("\$context = \$this->env->mergeGlobals(array(\n") + ->indent() + ; + + foreach ($this->getNode('arguments') as $name => $default) { + $compiler + ->write('') + ->string($name) + ->raw(' => $__'.$name.'__') + ->raw(",\n") + ; + } + + $compiler + ->outdent() + ->write("));\n\n") + ; + } + + $compiler + ->write("\$blocks = array();\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("}\n\n") + ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") + ->outdent() + ->write("}\n\n") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Module.php b/vendor/twig/twig/lib/Twig/Node/Module.php new file mode 100755 index 0000000..7802263 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Module.php @@ -0,0 +1,423 @@ + + */ +class Twig_Node_Module extends Twig_Node +{ + public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $filename) + { + // embedded templates are set as attributes so that they are only visited once by the visitors + parent::__construct(array( + 'parent' => $parent, + '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(), + ), array( + 'filename' => $filename, + 'index' => null, + 'embedded_templates' => $embeddedTemplates, + ), 1); + } + + public function setIndex($index) + { + $this->setAttribute('index', $index); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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')) + || null === $this->getNode('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->compileClassFooter($compiler); + } + + protected function compileGetParent(Twig_Compiler $compiler) + { + if (null === $parent = $this->getNode('parent')) { + return; + } + + $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($compiler->getFilename()) + ->raw(', ') + ->repr($this->getNode('parent')->getLine()) + ->raw(")") + ; + } + + $compiler + ->raw(";\n") + ->outdent() + ->write("}\n\n") + ; + } + + protected function compileClassHeader(Twig_Compiler $compiler) + { + $compiler + ->write("\n\n") + // if the filename contains */, add a blank to avoid a PHP parse error + ->write("/* ".str_replace('*/', '* /', $this->getAttribute('filename'))." */\n") + ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getAttribute('filename'), $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 (null === $parent = $this->getNode('parent')) { + $compiler->write("\$this->parent = false;\n\n"); + } elseif ($parent instanceof Twig_Node_Expression_Constant) { + $compiler + ->addDebugInfo($parent) + ->write("\$this->parent = \$this->loadTemplate(") + ->subcompile($parent) + ->raw(', ') + ->repr($compiler->getFilename()) + ->raw(', ') + ->repr($this->getNode('parent')->getLine()) + ->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("array(\n") + ; + } else { + $compiler + ->write("\$this->blocks = array(\n") + ; + } + + // blocks + $compiler + ->indent() + ; + + foreach ($this->getNode('blocks') as $name => $node) { + $compiler + ->write(sprintf("'%s' => array(\$this, 'block_%s'),\n", $name, $name)) + ; + } + + if ($countTraits) { + $compiler + ->outdent() + ->write(")\n") + ; + } + + $compiler + ->outdent() + ->write(");\n") + ->outdent() + ->subcompile($this->getNode('constructor_end')) + ->write("}\n\n") + ; + } + + protected function compileDisplay(Twig_Compiler $compiler) + { + $compiler + ->write("protected function doDisplay(array \$context, array \$blocks = array())\n", "{\n") + ->indent() + ->subcompile($this->getNode('display_start')) + ->subcompile($this->getNode('body')) + ; + + if (null !== $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->getAttribute('filename')) + ->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 = null === $this->getNode('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(array($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") + ; + } + + 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($compiler->getFilename()) + ->raw(', ') + ->repr($node->getLine()) + ->raw(");\n") + ; + } else { + $compiler + ->write(sprintf("%s = ", $var)) + ->subcompile($node) + ->raw(";\n") + ->write(sprintf("if (!%s", $var)) + ->raw(" instanceof Twig_Template) {\n") + ->indent() + ->write(sprintf("%s = \$this->loadTemplate(%s") + ->raw(', ') + ->repr($compiler->getFilename()) + ->raw(', ') + ->repr($node->getLine()) + ->raw(");\n", $var, $var)) + ->outdent() + ->write("}\n") + ; + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Print.php b/vendor/twig/twig/lib/Twig/Node/Print.php new file mode 100755 index 0000000..4263536 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Print.php @@ -0,0 +1,39 @@ + + */ +class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface +{ + public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + { + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Sandbox.php b/vendor/twig/twig/lib/Twig/Node/Sandbox.php new file mode 100755 index 0000000..8ca772b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Sandbox.php @@ -0,0 +1,47 @@ + + */ +class Twig_Node_Sandbox extends Twig_Node +{ + public function __construct(Twig_NodeInterface $body, $lineno, $tag = null) + { + parent::__construct(array('body' => $body), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("\$sandbox = \$this->env->getExtension('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") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php b/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php new file mode 100755 index 0000000..823e7ac --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php @@ -0,0 +1,61 @@ + + */ +class Twig_Node_SandboxedPrint extends Twig_Node_Print +{ + public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + { + parent::__construct($expr, $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo $this->env->getExtension(\'sandbox\')->ensureToStringAllowed(') + ->subcompile($this->getNode('expr')) + ->raw(");\n") + ; + } + + /** + * Removes node filters. + * + * This is mostly needed when another visitor adds filters (like the escaper one). + * + * @param Twig_Node $node A Node + * + * @return Twig_Node + */ + protected function removeNodeFilter($node) + { + if ($node instanceof Twig_Node_Expression_Filter) { + return $this->removeNodeFilter($node->getNode('node')); + } + + return $node; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Set.php b/vendor/twig/twig/lib/Twig/Node/Set.php new file mode 100755 index 0000000..407d147 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Set.php @@ -0,0 +1,101 @@ + + */ +class Twig_Node_Set extends Twig_Node +{ + public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) + { + parent::__construct(array('names' => $names, 'values' => $values), array('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->getLine())); + $this->setAttribute('capture', false); + } + } + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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('array('); + 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"); + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/SetTemp.php b/vendor/twig/twig/lib/Twig/Node/SetTemp.php new file mode 100755 index 0000000..3bdd1cb --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/SetTemp.php @@ -0,0 +1,35 @@ + $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") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Spaceless.php b/vendor/twig/twig/lib/Twig/Node/Spaceless.php new file mode 100755 index 0000000..1478c59 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Spaceless.php @@ -0,0 +1,40 @@ + + */ +class Twig_Node_Spaceless extends Twig_Node +{ + public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless') + { + parent::__construct(array('body' => $body), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + 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") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Node/Text.php b/vendor/twig/twig/lib/Twig/Node/Text.php new file mode 100755 index 0000000..6863604 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Node/Text.php @@ -0,0 +1,39 @@ + + */ +class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface +{ + public function __construct($data, $lineno) + { + parent::__construct(array(), array('data' => $data), $lineno); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write('echo ') + ->string($this->getAttribute('data')) + ->raw(";\n") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/NodeInterface.php b/vendor/twig/twig/lib/Twig/NodeInterface.php new file mode 100755 index 0000000..8077349 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeInterface.php @@ -0,0 +1,31 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_NodeInterface extends Countable, IteratorAggregate +{ + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler $compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler); + + public function getLine(); + + public function getNodeTag(); +} diff --git a/vendor/twig/twig/lib/Twig/NodeOutputInterface.php b/vendor/twig/twig/lib/Twig/NodeOutputInterface.php new file mode 100755 index 0000000..22172c0 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeOutputInterface.php @@ -0,0 +1,19 @@ + + */ +interface Twig_NodeOutputInterface +{ +} diff --git a/vendor/twig/twig/lib/Twig/NodeTraverser.php b/vendor/twig/twig/lib/Twig/NodeTraverser.php new file mode 100755 index 0000000..6024e65 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeTraverser.php @@ -0,0 +1,90 @@ + + */ +class Twig_NodeTraverser +{ + protected $env; + protected $visitors; + + /** + * Constructor. + * + * @param Twig_Environment $env A Twig_Environment instance + * @param Twig_NodeVisitorInterface[] $visitors An array of Twig_NodeVisitorInterface instances + */ + public function __construct(Twig_Environment $env, array $visitors = array()) + { + $this->env = $env; + $this->visitors = array(); + foreach ($visitors as $visitor) { + $this->addVisitor($visitor); + } + } + + /** + * Adds a visitor. + * + * @param Twig_NodeVisitorInterface $visitor A Twig_NodeVisitorInterface instance + */ + public function addVisitor(Twig_NodeVisitorInterface $visitor) + { + if (!isset($this->visitors[$visitor->getPriority()])) { + $this->visitors[$visitor->getPriority()] = array(); + } + + $this->visitors[$visitor->getPriority()][] = $visitor; + } + + /** + * Traverses a node and calls the registered visitors. + * + * @param Twig_NodeInterface $node A Twig_NodeInterface instance + * + * @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 !== $n = $this->traverseForVisitor($visitor, $n)) { + $node->setNode($k, $n); + } else { + $node->removeNode($k); + } + } + + return $visitor->leaveNode($node, $this->env); + } +} diff --git a/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php b/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php new file mode 100755 index 0000000..cc4b3d7 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeVisitor/Escaper.php @@ -0,0 +1,167 @@ + + */ +class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface +{ + protected $statusStack = array(); + protected $blocks = array(); + protected $safeAnalysis; + protected $traverser; + protected $defaultStrategy = false; + protected $safeVars = array(); + + public function __construct() + { + $this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis(); + } + + /** + * Called before child nodes are visited. + * + * @param Twig_NodeInterface $node The node to visit + * @param Twig_Environment $env The Twig environment instance + * + * @return Twig_NodeInterface The modified node + */ + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Module) { + if ($env->hasExtension('escaper') && $defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename'))) { + $this->defaultStrategy = $defaultStrategy; + } + $this->safeVars = array(); + } 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; + } + + /** + * Called after child nodes are visited. + * + * @param Twig_NodeInterface $node The node to visit + * @param Twig_Environment $env The Twig environment instance + * + * @return Twig_NodeInterface The modified node + */ + public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Module) { + $this->defaultStrategy = false; + $this->safeVars = array(); + } 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->getLine() + ); + } + + 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, array($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->getLine(); + $name = new Twig_Node_Expression_Constant('escape', $line); + $args = new Twig_Node(array(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); + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 0; + } +} diff --git a/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php b/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php new file mode 100755 index 0000000..b206e9a --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php @@ -0,0 +1,271 @@ + + */ +class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface +{ + const OPTIMIZE_ALL = -1; + const OPTIMIZE_NONE = 0; + const OPTIMIZE_FOR = 2; + const OPTIMIZE_RAW_FILTER = 4; + const OPTIMIZE_VAR_ACCESS = 8; + + protected $loops = array(); + protected $loopsTargets = array(); + protected $optimizers; + protected $prependedNodes = array(); + protected $inABody = false; + + /** + * Constructor. + * + * @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; + } + + /** + * {@inheritdoc} + */ + public function enterNode(Twig_NodeInterface $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('sandbox')) { + if ($this->inABody) { + if (!$node instanceof Twig_Node_Expression) { + if (get_class($node) !== 'Twig_Node') { + array_unshift($this->prependedNodes, array()); + } + } else { + $node = $this->optimizeVariables($node, $env); + } + } elseif ($node instanceof Twig_Node_Body) { + $this->inABody = true; + } + } + + return $node; + } + + /** + * {@inheritdoc} + */ + public function leaveNode(Twig_NodeInterface $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('sandbox')) { + if ($node instanceof Twig_Node_Body) { + $this->inABody = false; + } elseif ($this->inABody) { + if (!$expression && get_class($node) !== 'Twig_Node' && $prependedNodes = array_shift($this->prependedNodes)) { + $nodes = array(); + foreach (array_unique($prependedNodes) as $name) { + $nodes[] = new Twig_Node_SetTemp($name, $node->getLine()); + } + + $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->getLine()); + } + + return $node; + } + + /** + * Optimizes print nodes. + * + * It replaces: + * + * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" + * + * @param Twig_NodeInterface $node A Node + * @param Twig_Environment $env The current Twig environment + * + * @return Twig_NodeInterface + */ + protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if (!$node instanceof Twig_Node_Print) { + return $node; + } + + if ( + $node->getNode('expr') instanceof Twig_Node_Expression_BlockReference || + $node->getNode('expr') instanceof Twig_Node_Expression_Parent + ) { + $node->getNode('expr')->setAttribute('output', true); + + return $node->getNode('expr'); + } + + return $node; + } + + /** + * Removes "raw" filters. + * + * @param Twig_NodeInterface $node A Node + * @param Twig_Environment $env The current Twig environment + * + * @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. + * + * @param Twig_NodeInterface $node A Node + * @param Twig_Environment $env The current Twig environment + */ + 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. + * + * @param Twig_NodeInterface $node A Node + * @param Twig_Environment $env The current Twig environment + */ + 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); + } + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 255; + } +} diff --git a/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php b/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php new file mode 100755 index 0000000..a5d06de --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -0,0 +1,139 @@ +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][] = array( + 'key' => $node, + 'value' => $safe, + ); + } + + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + return $node; + } + + public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Expression_Constant) { + // constants are marked safe for all + $this->setSafe($node, array('all')); + } elseif ($node instanceof Twig_Node_Expression_BlockReference) { + // blocks are safe by definition + $this->setSafe($node, array('all')); + } elseif ($node instanceof Twig_Node_Expression_Parent) { + // parent block is safe by definition + $this->setSafe($node, array('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, array()); + } + } 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, array()); + } + } elseif ($node instanceof Twig_Node_Expression_MethodCall) { + if ($node->getAttribute('safe')) { + $this->setSafe($node, array('all')); + } else { + $this->setSafe($node, array()); + } + } 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, array('all')); + } else { + $this->setSafe($node, array()); + } + } else { + $this->setSafe($node, array()); + } + + return $node; + } + + protected function intersectSafe(array $a = null, array $b = null) + { + if (null === $a || null === $b) { + return array(); + } + + if (in_array('all', $a)) { + return $b; + } + + if (in_array('all', $b)) { + return $a; + } + + return array_intersect($a, $b); + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 0; + } +} diff --git a/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php b/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php new file mode 100755 index 0000000..5467f81 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php @@ -0,0 +1,92 @@ + + */ +class Twig_NodeVisitor_Sandbox implements Twig_NodeVisitorInterface +{ + protected $inAModule = false; + protected $tags; + protected $filters; + protected $functions; + + /** + * Called before child nodes are visited. + * + * @param Twig_NodeInterface $node The node to visit + * @param Twig_Environment $env The Twig environment instance + * + * @return Twig_NodeInterface The modified node + */ + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Module) { + $this->inAModule = true; + $this->tags = array(); + $this->filters = array(); + $this->functions = array(); + + 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; + } + + // wrap print to check __toString() calls + if ($node instanceof Twig_Node_Print) { + return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag()); + } + } + + return $node; + } + + /** + * Called after child nodes are visited. + * + * @param Twig_NodeInterface $node The node to visit + * @param Twig_Environment $env The Twig environment instance + * + * @return Twig_NodeInterface The modified node + */ + public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Module) { + $this->inAModule = false; + + $node->setNode('display_start', new Twig_Node(array(new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start')))); + } + + return $node; + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 0; + } +} diff --git a/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php b/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php new file mode 100755 index 0000000..f276163 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php @@ -0,0 +1,47 @@ + + */ +interface Twig_NodeVisitorInterface +{ + /** + * Called before child nodes are visited. + * + * @param Twig_NodeInterface $node The node to visit + * @param Twig_Environment $env The Twig environment instance + * + * @return Twig_NodeInterface The modified node + */ + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env); + + /** + * Called after child nodes are visited. + * + * @param Twig_NodeInterface $node The node to visit + * @param Twig_Environment $env The Twig environment instance + * + * @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(); +} diff --git a/vendor/twig/twig/lib/Twig/Parser.php b/vendor/twig/twig/lib/Twig/Parser.php new file mode 100755 index 0000000..549ce2b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Parser.php @@ -0,0 +1,390 @@ + + */ +class Twig_Parser implements Twig_ParserInterface +{ + protected $stack = array(); + 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 = array(); + + /** + * Constructor. + * + * @param Twig_Environment $env A Twig_Environment instance + */ + public function __construct(Twig_Environment $env) + { + $this->env = $env; + } + + public function getEnvironment() + { + return $this->env; + } + + public function getVarName() + { + return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false)); + } + + public function getFilename() + { + return $this->stream->getFilename(); + } + + /** + * {@inheritdoc} + */ + public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) + { + // push all variables into the stack to keep the current state of the parser + $vars = get_object_vars($this); + unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser']); + $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->getUnaryOperators(), $this->env->getBinaryOperators()); + } + + $this->stream = $stream; + $this->parent = null; + $this->blocks = array(); + $this->macros = array(); + $this->traits = array(); + $this->blockStack = array(); + $this->importedSymbols = array(array()); + $this->embeddedTemplates = array(); + + try { + $body = $this->subparse($test, $dropNeedle); + + if (null !== $this->parent) { + if (null === $body = $this->filterBodyNodes($body)) { + $body = new Twig_Node(); + } + } + } catch (Twig_Error_Syntax $e) { + if (!$e->getTemplateFile()) { + $e->setTemplateFile($this->getFilename()); + } + + if (!$e->getTemplateLine()) { + $e->setTemplateLine($this->stream->getCurrent()->getLine()); + } + + throw $e; + } + + $node = new Twig_Node_Module(new Twig_Node_Body(array($body)), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $this->getFilename()); + + $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 = array(); + 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 ($token->getType() !== Twig_Token::NAME_TYPE) { + throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename()); + } + + 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, array(), $lineno); + } + + $subparser = $this->handlers->getTokenParser($token->getValue()); + if (null === $subparser) { + if (null !== $test) { + $error = sprintf('Unexpected tag name "%s"', $token->getValue()); + if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { + $error .= sprintf(' (expecting closing tag for the "%s" tag defined near line %s)', $test[0]->getTag(), $lineno); + } + + throw new Twig_Error_Syntax($error, $token->getLine(), $this->getFilename()); + } + + $message = sprintf('Unknown tag name "%s"', $token->getValue()); + if ($alternatives = $this->env->computeAlternatives($token->getValue(), array_keys($this->env->getTags()))) { + $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); + } + + throw new Twig_Error_Syntax($message, $token->getLine(), $this->getFilename()); + } + + $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.', 0, $this->getFilename()); + } + } + + if (1 === count($rv)) { + return $rv[0]; + } + + return new Twig_Node($rv, array(), $lineno); + } + + public function addHandler($name, $class) + { + $this->handlers[$name] = $class; + } + + public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) + { + $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(array($value), array(), $value->getLine()); + } + + public function hasMacro($name) + { + return isset($this->macros[$name]); + } + + public function setMacro($name, Twig_Node_Macro $node) + { + if (null === $this->reservedMacroNames) { + $this->reservedMacroNames = array(); + $r = new ReflectionClass($this->env->getBaseTemplateClass()); + foreach ($r->getMethods() as $method) { + $this->reservedMacroNames[] = $method->getName(); + } + } + + if (in_array($name, $this->reservedMacroNames)) { + throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword', $name), $node->getLine(), $this->getFilename()); + } + + $this->macros[$name] = $node; + } + + 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] = array('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, array()); + } + + public function popLocalScope() + { + array_shift($this->importedSymbols); + } + + /** + * Gets the expression parser. + * + * @return Twig_ExpressionParser The expression parser + */ + public function getExpressionParser() + { + return $this->expressionParser; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + } + + /** + * Gets the token stream. + * + * @return Twig_TokenStream The token stream + */ + public function getStream() + { + return $this->stream; + } + + /** + * Gets the current token. + * + * @return Twig_Token The current 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))) { + throw new Twig_Error_Syntax('A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.', $node->getLine(), $this->getFilename()); + } + + throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->getFilename()); + } + + // bypass "set" nodes as they "capture" the output + if ($node instanceof Twig_Node_Set) { + 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; + } +} diff --git a/vendor/twig/twig/lib/Twig/ParserInterface.php b/vendor/twig/twig/lib/Twig/ParserInterface.php new file mode 100755 index 0000000..8e7cc0a --- /dev/null +++ b/vendor/twig/twig/lib/Twig/ParserInterface.php @@ -0,0 +1,31 @@ + + * + * @deprecated since 1.12 (to be removed in 3.0) + */ +interface Twig_ParserInterface +{ + /** + * Converts a token stream to a node tree. + * + * @param Twig_TokenStream $stream A token stream instance + * + * @return Twig_Node_Module A node tree + * + * @throws Twig_Error_Syntax When the token stream is syntactically or semantically wrong + */ + public function parse(Twig_TokenStream $stream); +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/Dumper/Blackfire.php b/vendor/twig/twig/lib/Twig/Profiler/Dumper/Blackfire.php new file mode 100755 index 0000000..b82747a --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/Dumper/Blackfire.php @@ -0,0 +1,68 @@ + + */ +class Twig_Profiler_Dumper_Blackfire +{ + public function dump(Twig_Profiler_Profile $profile) + { + $data = array(); + $this->dumpProfile('main()', $profile, $data); + $this->dumpChildren('main()', $profile, $data); + + $start = 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'] += 1; + $data[$edge]['wt'] += floor($profile->getDuration() * 1000000); + $data[$edge]['mu'] += $profile->getMemoryUsage(); + $data[$edge]['pmu'] += $profile->getPeakMemoryUsage(); + } else { + $data[$edge] = array( + 'ct' => 1, + 'wt' => floor($profile->getDuration() * 1000000), + 'mu' => $profile->getMemoryUsage(), + 'pmu' => $profile->getPeakMemoryUsage(), + ); + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/Dumper/Html.php b/vendor/twig/twig/lib/Twig/Profiler/Dumper/Html.php new file mode 100755 index 0000000..c898520 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/Dumper/Html.php @@ -0,0 +1,43 @@ + + */ +class Twig_Profiler_Dumper_Html extends Twig_Profiler_Dumper_Text +{ + static private $colors = array( + '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); + } +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/Dumper/Text.php b/vendor/twig/twig/lib/Twig/Profiler/Dumper/Text.php new file mode 100755 index 0000000..998e210 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/Dumper/Text.php @@ -0,0 +1,68 @@ + + */ +class Twig_Profiler_Dumper_Text +{ + private $root; + + public function dump(Twig_Profiler_Profile $profile) + { + return $this->dumpProfile($profile); + } + + 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); + } + + 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; + } +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/Node/EnterProfile.php b/vendor/twig/twig/lib/Twig/Profiler/Node/EnterProfile.php new file mode 100755 index 0000000..11c1114 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/Node/EnterProfile.php @@ -0,0 +1,40 @@ + + */ +class Twig_Profiler_Node_EnterProfile extends Twig_Node +{ + public function __construct($extensionName, $type, $name, $varName) + { + parent::__construct(array(), array('extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName)); + } + + /** + * {@inheritdoc} + */ + 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") + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/Node/LeaveProfile.php b/vendor/twig/twig/lib/Twig/Profiler/Node/LeaveProfile.php new file mode 100755 index 0000000..88074c2 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/Node/LeaveProfile.php @@ -0,0 +1,34 @@ + + */ +class Twig_Profiler_Node_LeaveProfile extends Twig_Node +{ + public function __construct($varName) + { + parent::__construct(array(), array('var_name' => $varName)); + } + + /** + * {@inheritdoc} + */ + 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')) + ; + } +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php b/vendor/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php new file mode 100755 index 0000000..58beb0a --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/NodeVisitor/Profiler.php @@ -0,0 +1,72 @@ + + */ +class Twig_Profiler_NodeVisitor_Profiler implements Twig_NodeVisitorInterface +{ + private $extensionName; + + public function __construct($extensionName) + { + $this->extensionName = $extensionName; + } + + /** + * {@inheritdoc} + */ + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + return $node; + } + + /** + * {@inheritdoc} + */ + public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Module) { + $varName = $this->getVarName(); + $node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start')))); + $node->setNode('display_end', new Twig_Node(array(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(array( + 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(array( + 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', uniqid(mt_rand(), true), false)); + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 0; + } +} diff --git a/vendor/twig/twig/lib/Twig/Profiler/Profile.php b/vendor/twig/twig/lib/Twig/Profiler/Profile.php new file mode 100755 index 0000000..fe48a4d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Profiler/Profile.php @@ -0,0 +1,150 @@ + + */ +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 = array(); + private $ends = array(); + private $profiles = array(); + + public function __construct($template = 'main', $type = Twig_Profiler_Profile::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(Twig_Profiler_Profile $profile) + { + $this->profiles[] = $profile; + } + + /** + * Returns the duration in microseconds. + * + * @return int + */ + public function getDuration() + { + 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 = array( + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ); + } + + /** + * Stops the profiling. + */ + public function leave() + { + $this->ends = array( + 'wt' => microtime(true), + 'mu' => memory_get_usage(), + 'pmu' => memory_get_peak_usage(), + ); + } + + public function getIterator() + { + return new ArrayIterator($this->profiles); + } + + public function serialize() + { + return serialize(array($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); + } +} diff --git a/vendor/twig/twig/lib/Twig/Sandbox/SecurityError.php b/vendor/twig/twig/lib/Twig/Sandbox/SecurityError.php new file mode 100755 index 0000000..015bfae --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Sandbox/SecurityError.php @@ -0,0 +1,19 @@ + + */ +class Twig_Sandbox_SecurityError extends Twig_Error +{ +} diff --git a/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php b/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php new file mode 100755 index 0000000..99faba9 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php @@ -0,0 +1,31 @@ + + */ +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; + } +} diff --git a/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php b/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php new file mode 100755 index 0000000..05cf488 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php @@ -0,0 +1,31 @@ + + */ +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; + } +} diff --git a/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php b/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php new file mode 100755 index 0000000..b3bb5e8 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php @@ -0,0 +1,31 @@ + + */ +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; + } +} diff --git a/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php b/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php new file mode 100755 index 0000000..c4dd03d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php @@ -0,0 +1,119 @@ + + */ +class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface +{ + protected $allowedTags; + protected $allowedFilters; + protected $allowedMethods; + protected $allowedProperties; + protected $allowedFunctions; + + public function __construct(array $allowedTags = array(), array $allowedFilters = array(), array $allowedMethods = array(), array $allowedProperties = array(), array $allowedFunctions = array()) + { + $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 = array(); + foreach ($methods as $class => $m) { + $this->allowedMethods[$class] = array_map('strtolower', is_array($m) ? $m : array($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) { + throw new Twig_Sandbox_SecurityError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, get_class($obj))); + } + } + + 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 : array($properties)); + + break; + } + } + + if (!$allowed) { + throw new Twig_Sandbox_SecurityError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, get_class($obj))); + } + } +} diff --git a/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicyInterface.php b/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicyInterface.php new file mode 100755 index 0000000..6ab48e3 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicyInterface.php @@ -0,0 +1,24 @@ + + */ +interface Twig_Sandbox_SecurityPolicyInterface +{ + public function checkSecurity($tags, $filters, $functions); + + public function checkMethodAllowed($obj, $method); + + public function checkPropertyAllowed($obj, $method); +} diff --git a/vendor/twig/twig/lib/Twig/SimpleFilter.php b/vendor/twig/twig/lib/Twig/SimpleFilter.php new file mode 100755 index 0000000..d35c563 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/SimpleFilter.php @@ -0,0 +1,94 @@ + + */ +class Twig_SimpleFilter +{ + protected $name; + protected $callable; + protected $options; + protected $arguments = array(); + + public function __construct($name, $callable, array $options = array()) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge(array( + 'needs_environment' => false, + 'needs_context' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'pre_escape' => null, + 'preserves_safety' => null, + 'node_class' => 'Twig_Node_Expression_Filter', + ), $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']; + } +} diff --git a/vendor/twig/twig/lib/Twig/SimpleFunction.php b/vendor/twig/twig/lib/Twig/SimpleFunction.php new file mode 100755 index 0000000..8ef6aca --- /dev/null +++ b/vendor/twig/twig/lib/Twig/SimpleFunction.php @@ -0,0 +1,84 @@ + + */ +class Twig_SimpleFunction +{ + protected $name; + protected $callable; + protected $options; + protected $arguments = array(); + + public function __construct($name, $callable, array $options = array()) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge(array( + 'needs_environment' => false, + 'needs_context' => false, + 'is_safe' => null, + 'is_safe_callback' => null, + 'node_class' => 'Twig_Node_Expression_Function', + ), $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 array(); + } +} diff --git a/vendor/twig/twig/lib/Twig/SimpleTest.php b/vendor/twig/twig/lib/Twig/SimpleTest.php new file mode 100755 index 0000000..225459c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/SimpleTest.php @@ -0,0 +1,46 @@ + + */ +class Twig_SimpleTest +{ + protected $name; + protected $callable; + protected $options; + + public function __construct($name, $callable, array $options = array()) + { + $this->name = $name; + $this->callable = $callable; + $this->options = array_merge(array( + 'node_class' => 'Twig_Node_Expression_Test', + ), $options); + } + + public function getName() + { + return $this->name; + } + + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } +} diff --git a/vendor/twig/twig/lib/Twig/Template.php b/vendor/twig/twig/lib/Twig/Template.php new file mode 100755 index 0000000..0878d16 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Template.php @@ -0,0 +1,536 @@ + + */ +abstract class Twig_Template implements Twig_TemplateInterface +{ + protected static $cache = array(); + + protected $parent; + protected $parents = array(); + protected $env; + protected $blocks; + protected $traits; + + /** + * Constructor. + * + * @param Twig_Environment $env A Twig_Environment instance + */ + public function __construct(Twig_Environment $env) + { + $this->env = $env; + $this->blocks = array(); + $this->traits = array(); + } + + /** + * Returns the template name. + * + * @return string The template name + */ + abstract public function getTemplateName(); + + /** + * {@inheritdoc} + */ + public function getEnvironment() + { + 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|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) { + return $this->parents[$parent->getTemplateName()] = $parent; + } + + if (!isset($this->parents[$parent])) { + $this->parents[$parent] = $this->loadTemplate($parent); + } + } catch (Twig_Error_Loader $e) { + $e->setTemplateFile(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 = array()) + { + $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->getTemplateName()); + } + } + + /** + * 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 = array(), $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; + } + + if (null !== $template) { + try { + $template->$block($context, $blocks); + } catch (Twig_Error $e) { + 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->getTemplateName(), $e); + } + } elseif (false !== $parent = $this->getParent($context)) { + $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); + } + } + + /** + * 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 = array()) + { + 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 + */ + public function renderBlock($name, array $context, array $blocks = array(), $useBlocks = true) + { + ob_start(); + $this->displayBlock($name, $context, $blocks, $useBlocks); + + return ob_get_clean(); + } + + /** + * Returns whether a block exists or not. + * + * This method is for internal use only and should never be called + * directly. + * + * This method does only return blocks defined in the current template + * or defined in "used" traits. + * + * It does not return blocks from parent templates as the parent + * template name can be dynamic, which is only known based on the + * current context. + * + * @param string $name The block name + * + * @return bool true if the block exists, false otherwise + */ + public function hasBlock($name) + { + return isset($this->blocks[(string) $name]); + } + + /** + * Returns all block names. + * + * This method is for internal use only and should never be called + * directly. + * + * @return array An array of block names + * + * @see hasBlock + */ + public function getBlockNames() + { + return array_keys($this->blocks); + } + + protected function loadTemplate($template, $templateName = null, $line = null, $index = null) + { + try { + if (is_array($template)) { + return $this->env->resolveTemplate($template); + } + + if ($template instanceof self) { + return $template; + } + + return $this->env->loadTemplate($template, $index); + } catch (Twig_Error $e) { + if (!$e->getTemplateFile()) { + $e->setTemplateFile($templateName ? $templateName : $this->getTemplateName()); + } + + 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 + * + * @see hasBlock + */ + public function getBlocks() + { + return $this->blocks; + } + + /** + * {@inheritdoc} + */ + public function display(array $context, array $blocks = array()) + { + $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); + } + + /** + * {@inheritdoc} + */ + 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; + } + + return ob_get_clean(); + } + + protected function displayWithErrorHandling(array $context, array $blocks = array()) + { + try { + $this->doDisplay($context, $blocks); + } catch (Twig_Error $e) { + if (!$e->getTemplateFile()) { + $e->setTemplateFile($this->getTemplateName()); + } + + // 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->getTemplateName(), $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 = array()); + + /** + * 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 + */ + 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->getTemplateName()); + } + + 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 + */ + protected function getAttribute($object, $item, array $arguments = array(), $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) && 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->getTemplateName()); + } + } + + 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); + } 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->getTemplateName()); + } + + // object property + if (self::METHOD_CALL !== $type) { + if (isset($object->$item) || array_key_exists((string) $item, $object)) { + if ($isDefinedTest) { + return true; + } + + if ($this->env->hasExtension('sandbox')) { + $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item); + } + + return $object->$item; + } + } + + $class = get_class($object); + + // object method + if (!isset(self::$cache[$class]['methods'])) { + self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object))); + } + + $call = false; + $lcItem = strtolower($item); + if (isset(self::$cache[$class]['methods'][$lcItem])) { + $method = (string) $item; + } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) { + $method = 'get'.$item; + } elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) { + $method = 'is'.$item; + } elseif (isset(self::$cache[$class]['methods']['__call'])) { + $method = (string) $item; + $call = true; + } else { + if ($isDefinedTest) { + return false; + } + + if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { + return; + } + + throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName()); + } + + if ($isDefinedTest) { + return true; + } + + if ($this->env->hasExtension('sandbox')) { + $this->env->getExtension('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 = call_user_func_array(array($object, $method), $arguments); + } catch (BadMethodCallException $e) { + if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { + return; + } + throw $e; + } + + // useful when calling a template method from a template + // this is not supported but unfortunately heavily used in the Symfony profiler + if ($object instanceof Twig_TemplateInterface) { + return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); + } + + return $ret; + } +} diff --git a/vendor/twig/twig/lib/Twig/TemplateInterface.php b/vendor/twig/twig/lib/Twig/TemplateInterface.php new file mode 100755 index 0000000..d178832 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TemplateInterface.php @@ -0,0 +1,48 @@ + + * + * @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 = array()); + + /** + * Returns the bound environment for this template. + * + * @return Twig_Environment The current environment + */ + public function getEnvironment(); +} diff --git a/vendor/twig/twig/lib/Twig/Test.php b/vendor/twig/twig/lib/Twig/Test.php new file mode 100755 index 0000000..3baff88 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Test.php @@ -0,0 +1,34 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +abstract class Twig_Test implements Twig_TestInterface, Twig_TestCallableInterface +{ + protected $options; + protected $arguments = array(); + + public function __construct(array $options = array()) + { + $this->options = array_merge(array( + 'callable' => null, + ), $options); + } + + public function getCallable() + { + return $this->options['callable']; + } +} diff --git a/vendor/twig/twig/lib/Twig/Test/Function.php b/vendor/twig/twig/lib/Twig/Test/Function.php new file mode 100755 index 0000000..4be6b9b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Test/Function.php @@ -0,0 +1,35 @@ + + * @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 = array()) + { + $options['callable'] = $function; + + parent::__construct($options); + + $this->function = $function; + } + + public function compile() + { + return $this->function; + } +} diff --git a/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php b/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php new file mode 100755 index 0000000..b8bceb8 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Test/IntegrationTestCase.php @@ -0,0 +1,154 @@ + + * @author Karma Dordrak + */ +abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase +{ + abstract protected function getExtensions(); + abstract protected function getFixturesDir(); + + /** + * @dataProvider getTests + */ + public function testIntegration($file, $message, $condition, $templates, $exception, $outputs) + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); + } + + public function getTests() + { + $fixturesDir = realpath($this->getFixturesDir()); + $tests = array(); + + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { + if (!preg_match('/\.test$/', $file)) { + 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 = $this->parseTemplates($match[3]); + $exception = $match[5]; + $outputs = array(array(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 = $this->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[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs); + } + + return $tests; + } + + protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) + { + if ($condition) { + eval('$ret = '.$condition.';'); + if (!$ret) { + $this->markTestSkipped($condition); + } + } + + $loader = new Twig_Loader_Array($templates); + + foreach ($outputs as $match) { + $config = array_merge(array( + 'cache' => false, + 'strict_variables' => true, + ), $match[2] ? eval($match[2].';') : array()); + $twig = new Twig_Environment($loader, $config); + $twig->addGlobal('global', 'global'); + foreach ($this->getExtensions() as $extension) { + $twig->addExtension($extension); + } + + try { + $template = $twig->loadTemplate('index.twig'); + } catch (Exception $e) { + if (false !== $exception) { + $this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); + + return; + } + + if ($e instanceof Twig_Error_Syntax) { + $e->setTemplateFile($file); + + throw $e; + } + + 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->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); + + return; + } + + if ($e instanceof Twig_Error_Syntax) { + $e->setTemplateFile($file); + } else { + $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); + $this->assertThat(null, new PHPUnit_Framework_Constraint_Exception($class)); + } + + $expected = trim($match[3], "\n "); + + if ($expected != $output) { + echo 'Compiled template that failed:'; + + foreach (array_keys($templates) as $name) { + echo "Template: $name\n"; + $source = $loader->getSource($name); + echo $twig->compile($twig->parse($twig->tokenize($source, $name))); + } + } + $this->assertEquals($expected, $output, $message.' (in '.$file.')'); + } + } + + protected static function parseTemplates($test) + { + $templates = array(); + 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/vendor/twig/twig/lib/Twig/Test/Method.php b/vendor/twig/twig/lib/Twig/Test/Method.php new file mode 100755 index 0000000..17c6c04 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Test/Method.php @@ -0,0 +1,37 @@ + + * @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 = array()) + { + $options['callable'] = array($extension, $method); + + parent::__construct($options); + + $this->extension = $extension; + $this->method = $method; + } + + public function compile() + { + return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); + } +} diff --git a/vendor/twig/twig/lib/Twig/Test/Node.php b/vendor/twig/twig/lib/Twig/Test/Node.php new file mode 100755 index 0000000..c832a57 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Test/Node.php @@ -0,0 +1,37 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_Test_Node extends Twig_Test +{ + protected $class; + + public function __construct($class, array $options = array()) + { + parent::__construct($options); + + $this->class = $class; + } + + public function getClass() + { + return $this->class; + } + + public function compile() + { + } +} diff --git a/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php b/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php new file mode 100755 index 0000000..bf86521 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Test/NodeTestCase.php @@ -0,0 +1,60 @@ +assertNodeCompilation($source, $node, $environment); + } + + public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null) + { + $compiler = $this->getCompiler($environment); + $compiler->compile($node); + + $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(); + } + + protected function getVariableGetter($name, $line = false) + { + $line = $line > 0 ? "// line {$line}\n" : ''; + + 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('; + } +} diff --git a/vendor/twig/twig/lib/Twig/TestCallableInterface.php b/vendor/twig/twig/lib/Twig/TestCallableInterface.php new file mode 100755 index 0000000..0db4368 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TestCallableInterface.php @@ -0,0 +1,21 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_TestCallableInterface +{ + public function getCallable(); +} diff --git a/vendor/twig/twig/lib/Twig/TestInterface.php b/vendor/twig/twig/lib/Twig/TestInterface.php new file mode 100755 index 0000000..30d8a2c --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TestInterface.php @@ -0,0 +1,26 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +interface Twig_TestInterface +{ + /** + * Compiles a test. + * + * @return string The PHP code for the test + */ + public function compile(); +} diff --git a/vendor/twig/twig/lib/Twig/Token.php b/vendor/twig/twig/lib/Twig/Token.php new file mode 100755 index 0000000..15dd4eb --- /dev/null +++ b/vendor/twig/twig/lib/Twig/Token.php @@ -0,0 +1,216 @@ + + */ +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; + + /** + * Constructor. + * + * @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; + } + + /** + * Returns a string representation of the token. + * + * @return string A string representation of the token + */ + 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|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 + ); + } + + /** + * Gets the line. + * + * @return int The source line + */ + public function getLine() + { + return $this->lineno; + } + + /** + * Gets the token type. + * + * @return int The token type + */ + public function getType() + { + return $this->type; + } + + /** + * Gets the token value. + * + * @return string The token value + */ + 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)); + } + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser.php b/vendor/twig/twig/lib/Twig/TokenParser.php new file mode 100755 index 0000000..57b1825 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser.php @@ -0,0 +1,33 @@ + + */ +abstract class Twig_TokenParser implements Twig_TokenParserInterface +{ + /** + * @var Twig_Parser + */ + protected $parser; + + /** + * Sets the parser associated with this token parser + * + * @param Twig_Parser $parser A Twig_Parser instance + */ + public function setParser(Twig_Parser $parser) + { + $this->parser = $parser; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php b/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php new file mode 100755 index 0000000..2756028 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php @@ -0,0 +1,89 @@ + + * {% 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 %} + * + */ +class Twig_TokenParser_AutoEscape extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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 Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename()); + } + $value = $expr->getAttribute('value'); + + $compat = true === $value || false === $value; + + if (true === $value) { + $value = 'html'; + } + + if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { + if (false === $value) { + throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename()); + } + + $value = $stream->next()->getValue(); + } + } + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($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'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'autoescape'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Block.php b/vendor/twig/twig/lib/Twig/TokenParser/Block.php new file mode 100755 index 0000000..0a46200 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Block.php @@ -0,0 +1,81 @@ + + * {% block head %} + * + * {% block title %}{% endblock %} - My Webpage + * {% endblock %} + * + */ +class Twig_TokenParser_Block extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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 '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename()); + } + $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno)); + $this->parser->pushLocalScope(); + $this->parser->pushBlockStack($name); + + if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) { + $body = $this->parser->subparse(array($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->getFilename()); + } + } + } else { + $body = new Twig_Node(array( + 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'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'block'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Do.php b/vendor/twig/twig/lib/Twig/TokenParser/Do.php new file mode 100755 index 0000000..f50939d --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Do.php @@ -0,0 +1,42 @@ +parser->getExpressionParser()->parseExpression(); + + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + + return new Twig_Node_Do($expr, $token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'do'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Embed.php b/vendor/twig/twig/lib/Twig/TokenParser/Embed.php new file mode 100755 index 0000000..69cb5f3 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Embed.php @@ -0,0 +1,66 @@ +parser->getStream(); + + $parent = $this->parser->getExpressionParser()->parseExpression(); + + list($variables, $only, $ignoreMissing) = $this->parseArguments(); + + // inject a fake parent to make the parent() function work + $stream->injectTokens(array( + new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()), + new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()), + new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine()), + new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()), + )); + + $module = $this->parser->parse($stream, array($this, 'decideBlockEnd'), true); + + // override the parent with the correct one + $module->setNode('parent', $parent); + + $this->parser->embedTemplate($module); + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new Twig_Node_Embed($module->getAttribute('filename'), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Twig_Token $token) + { + return $token->test('endembed'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'embed'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Extends.php b/vendor/twig/twig/lib/Twig/TokenParser/Extends.php new file mode 100755 index 0000000..f5ecee2 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Extends.php @@ -0,0 +1,52 @@ + + * {% extends "base.html" %} + * + */ +class Twig_TokenParser_Extends extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + public function parse(Twig_Token $token) + { + if (!$this->parser->isMainScope()) { + throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine(), $this->parser->getFilename()); + } + + if (null !== $this->parser->getParent()) { + throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine(), $this->parser->getFilename()); + } + $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); + + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'extends'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Filter.php b/vendor/twig/twig/lib/Twig/TokenParser/Filter.php new file mode 100755 index 0000000..2b97475 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Filter.php @@ -0,0 +1,61 @@ + + * {% filter upper %} + * This text becomes uppercase + * {% endfilter %} + * + */ +class Twig_TokenParser_Filter extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + public function parse(Twig_Token $token) + { + $name = $this->parser->getVarName(); + $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), true, $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(array($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'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'filter'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Flush.php b/vendor/twig/twig/lib/Twig/TokenParser/Flush.php new file mode 100755 index 0000000..4e15e78 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Flush.php @@ -0,0 +1,42 @@ +parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + + return new Twig_Node_Flush($token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'flush'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/For.php b/vendor/twig/twig/lib/Twig/TokenParser/For.php new file mode 100755 index 0000000..5c07d63 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/For.php @@ -0,0 +1,135 @@ + + *
      + * {% for user in users %} + *
    • {{ user.username|e }}
    • + * {% endfor %} + *
    + * + */ +class Twig_TokenParser_For extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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(array($this, 'decideForFork')); + if ($stream->next()->getValue() == 'else') { + $stream->expect(Twig_Token::BLOCK_END_TYPE); + $else = $this->parser->subparse(array($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->getLine()); + $valueTarget = $targets->getNode(1); + $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine()); + } else { + $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno); + $valueTarget = $targets->getNode(0); + $valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine()); + } + + 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(array('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->getLine(), $stream->getFilename()); + } + + 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'), array('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->getLine(), $stream->getFilename()); + } + } + + // 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); + } + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'for'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/From.php b/vendor/twig/twig/lib/Twig/TokenParser/From.php new file mode 100755 index 0000000..dd73f99 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/From.php @@ -0,0 +1,70 @@ + + * {% from 'forms.html' import forms %} + * + */ +class Twig_TokenParser_From extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + public function parse(Twig_Token $token) + { + $macro = $this->parser->getExpressionParser()->parseExpression(); + $stream = $this->parser->getStream(); + $stream->expect('import'); + + $targets = array(); + 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) { + $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var')); + } + + return $node; + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'from'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/If.php b/vendor/twig/twig/lib/Twig/TokenParser/If.php new file mode 100755 index 0000000..3d7d1f5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/If.php @@ -0,0 +1,94 @@ + + * {% if users %} + *
      + * {% for user in users %} + *
    • {{ user.username|e }}
    • + * {% endfor %} + *
    + * {% endif %} + * + */ +class Twig_TokenParser_If extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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(array($this, 'decideIfFork')); + $tests = array($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(array($this, 'decideIfEnd')); + break; + + case 'elseif': + $expr = $this->parser->getExpressionParser()->parseExpression(); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($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->getFilename()); + } + } + + $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(array('elseif', 'else', 'endif')); + } + + public function decideIfEnd(Twig_Token $token) + { + return $token->test(array('endif')); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'if'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Import.php b/vendor/twig/twig/lib/Twig/TokenParser/Import.php new file mode 100755 index 0000000..e7050c7 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Import.php @@ -0,0 +1,49 @@ + + * {% import 'forms.html' as forms %} + * + */ +class Twig_TokenParser_Import extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'import'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Include.php b/vendor/twig/twig/lib/Twig/TokenParser/Include.php new file mode 100755 index 0000000..9c3099a --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Include.php @@ -0,0 +1,75 @@ + + * {% include 'header.html' %} + * Body + * {% include 'footer.html' %} + * + */ +class Twig_TokenParser_Include extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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 array($variables, $only, $ignoreMissing); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'include'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Macro.php b/vendor/twig/twig/lib/Twig/TokenParser/Macro.php new file mode 100755 index 0000000..ad910b5 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Macro.php @@ -0,0 +1,68 @@ + + * {% macro input(name, value, type, size) %} + * + * {% endmacro %} + * + */ +class Twig_TokenParser_Macro extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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(array($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->getFilename()); + } + } + $this->parser->popLocalScope(); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag())); + } + + public function decideBlockEnd(Twig_Token $token) + { + return $token->test('endmacro'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'macro'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php b/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php new file mode 100755 index 0000000..9457325 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php @@ -0,0 +1,68 @@ + + * {% sandbox %} + * {% include 'user.html' %} + * {% endsandbox %} + * + * + * @see http://www.twig-project.org/doc/api.html#sandbox-extension for details + */ +class Twig_TokenParser_Sandbox extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + public function parse(Twig_Token $token) + { + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); + $this->parser->getStream()->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->getLine(), $this->parser->getFilename()); + } + } + } + + return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); + } + + public function decideBlockEnd(Twig_Token $token) + { + return $token->test('endsandbox'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'sandbox'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Set.php b/vendor/twig/twig/lib/Twig/TokenParser/Set.php new file mode 100755 index 0000000..0b41909 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Set.php @@ -0,0 +1,83 @@ + + * {% 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 %} + * + */ +class Twig_TokenParser_Set extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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->getFilename()); + } + } 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->getFilename()); + } + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + $values = $this->parser->subparse(array($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'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'set'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php b/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php new file mode 100755 index 0000000..1e3fa8f --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Spaceless.php @@ -0,0 +1,59 @@ + + * {% spaceless %} + *
    + * foo + *
    + * {% endspaceless %} + * + * {# output will be
    foo
    #} + * + */ +class Twig_TokenParser_Spaceless extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + public function parse(Twig_Token $token) + { + $lineno = $token->getLine(); + + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($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'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'spaceless'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParser/Use.php b/vendor/twig/twig/lib/Twig/TokenParser/Use.php new file mode 100755 index 0000000..3ea68b1 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParser/Use.php @@ -0,0 +1,76 @@ + + * {% extends "base.html" %} + * + * {% use "blocks.html" %} + * + * {% block title %}{% endblock %} + * {% block content %}{% endblock %} + * + * + * @see http://www.twig-project.org/doc/templates.html#horizontal-reuse for details. + */ +class Twig_TokenParser_Use extends Twig_TokenParser +{ + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface instance + */ + 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->getFilename()); + } + + $targets = array(); + 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(array('template' => $template, 'targets' => new Twig_Node($targets)))); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'use'; + } +} diff --git a/vendor/twig/twig/lib/Twig/TokenParserBroker.php b/vendor/twig/twig/lib/Twig/TokenParserBroker.php new file mode 100755 index 0000000..ec3fba6 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParserBroker.php @@ -0,0 +1,136 @@ + + * @deprecated since 1.12 (to be removed in 2.0) + */ +class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface +{ + protected $parser; + protected $parsers = array(); + protected $brokers = array(); + + /** + * Constructor. + * + * @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances + * @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances + */ + public function __construct($parsers = array(), $brokers = array()) + { + 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; + } + } + + /** + * Adds a TokenParser. + * + * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance + */ + public function addTokenParser(Twig_TokenParserInterface $parser) + { + $this->parsers[$parser->getTag()] = $parser; + } + + /** + * Removes a TokenParser. + * + * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance + */ + public function removeTokenParser(Twig_TokenParserInterface $parser) + { + $name = $parser->getTag(); + if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { + unset($this->parsers[$name]); + } + } + + /** + * Adds a TokenParserBroker. + * + * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance + */ + public function addTokenParserBroker(Twig_TokenParserBroker $broker) + { + $this->brokers[] = $broker; + } + + /** + * Removes a TokenParserBroker. + * + * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance + */ + public function removeTokenParserBroker(Twig_TokenParserBroker $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 null|Twig_TokenParserInterface 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/vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php b/vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php new file mode 100755 index 0000000..3f006e3 --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParserBrokerInterface.php @@ -0,0 +1,45 @@ + + * @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 null|Twig_TokenParserInterface 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. + * + * @param Twig_ParserInterface $parser A Twig_ParserInterface interface + */ + public function setParser(Twig_ParserInterface $parser); + + /** + * Gets the Twig_ParserInterface. + * + * @return null|Twig_ParserInterface A Twig_ParserInterface instance or null + */ + public function getParser(); +} diff --git a/vendor/twig/twig/lib/Twig/TokenParserInterface.php b/vendor/twig/twig/lib/Twig/TokenParserInterface.php new file mode 100755 index 0000000..17e394b --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenParserInterface.php @@ -0,0 +1,43 @@ + + */ +interface Twig_TokenParserInterface +{ + /** + * Sets the parser associated with this token parser + * + * @param Twig_Parser $parser A Twig_Parser instance + */ + public function setParser(Twig_Parser $parser); + + /** + * Parses a token and returns a node. + * + * @param Twig_Token $token A Twig_Token instance + * + * @return Twig_NodeInterface A Twig_NodeInterface 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(); +} diff --git a/vendor/twig/twig/lib/Twig/TokenStream.php b/vendor/twig/twig/lib/Twig/TokenStream.php new file mode 100755 index 0000000..7e95a4f --- /dev/null +++ b/vendor/twig/twig/lib/Twig/TokenStream.php @@ -0,0 +1,156 @@ + + */ +class Twig_TokenStream +{ + protected $tokens; + protected $current; + protected $filename; + + /** + * Constructor. + * + * @param array $tokens An array of tokens + * @param string $filename The name of the filename which tokens are associated with + */ + public function __construct(array $tokens, $filename = null) + { + $this->tokens = $tokens; + $this->current = 0; + $this->filename = $filename; + } + + /** + * Returns a string representation of the token stream. + * + * @return string + */ + 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->filename); + } + + 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->filename + ); + } + $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->filename); + } + + 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 $this->tokens[$this->current]->getType() === Twig_Token::EOF_TYPE; + } + + /** + * Gets the current token + * + * @return Twig_Token + */ + public function getCurrent() + { + return $this->tokens[$this->current]; + } + + /** + * Gets the filename associated with this stream + * + * @return string + */ + public function getFilename() + { + return $this->filename; + } +} diff --git a/vendor/twig/twig/phpunit.xml.dist b/vendor/twig/twig/phpunit.xml.dist new file mode 100755 index 0000000..6c5046f --- /dev/null +++ b/vendor/twig/twig/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + + ./test/Twig/ + + + + + + ./lib/Twig/ + + + diff --git a/vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php b/vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php new file mode 100755 index 0000000..c8b7999 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/AutoloaderTest.php @@ -0,0 +1,21 @@ +assertFalse(class_exists('FooBarFoo'), '->autoload() does not try to load classes that does not begin with Twig'); + + $autoloader = new Twig_Autoloader(); + $this->assertNull($autoloader->autoload('Foo'), '->autoload() returns false if it is not able to load a class'); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/CompilerTest.php b/vendor/twig/twig/test/Twig/Tests/CompilerTest.php new file mode 100755 index 0000000..e24b0b5 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/CompilerTest.php @@ -0,0 +1,33 @@ +markTestSkipped('Your platform does not support locales.'); + } + + $required_locales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'); + if (false === setlocale(LC_NUMERIC, $required_locales)) { + $this->markTestSkipped('Could not set any of required locales: '.implode(", ", $required_locales)); + } + + $this->assertEquals('1.2', $compiler->repr(1.2)->getSource()); + $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0))); + + setlocale(LC_NUMERIC, $locale); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php b/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php new file mode 100755 index 0000000..d0ada96 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php @@ -0,0 +1,288 @@ +render('test'); + } + + public function testAutoescapeOption() + { + $loader = new Twig_Loader_Array(array( + 'html' => '{{ foo }} {{ foo }}', + 'js' => '{{ bar }} {{ bar }}', + )); + + $twig = new Twig_Environment($loader, array( + 'debug' => true, + 'cache' => false, + 'autoescape' => array($this, 'escapingStrategyCallback'), + )); + + $this->assertEquals('foo<br/ > foo<br/ >', $twig->render('html', array('foo' => 'foo
    '))); + $this->assertEquals('foo\x3Cbr\x2F\x20\x3E foo\x3Cbr\x2F\x20\x3E', $twig->render('js', array('bar' => 'foo
    '))); + } + + public function escapingStrategyCallback($filename) + { + return $filename; + } + + public function testGlobals() + { + // globals can be added after calling getGlobals + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->addGlobal('foo', 'bar'); + $globals = $twig->getGlobals(); + $this->assertEquals('bar', $globals['foo']); + + // globals can be modified after runtime init + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->initRuntime(); + $twig->addGlobal('foo', 'bar'); + $globals = $twig->getGlobals(); + $this->assertEquals('bar', $globals['foo']); + + // globals can be modified after extensions init + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->getFunctions(); + $twig->addGlobal('foo', 'bar'); + $globals = $twig->getGlobals(); + $this->assertEquals('bar', $globals['foo']); + + // globals can be modified after extensions and runtime init + $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{foo}}'))); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->getFunctions(); + $twig->initRuntime(); + $twig->addGlobal('foo', 'bar'); + $globals = $twig->getGlobals(); + $this->assertEquals('bar', $globals['foo']); + + $twig = new Twig_Environment($loader); + $twig->getGlobals(); + $twig->addGlobal('foo', 'bar'); + $template = $twig->loadTemplate('index'); + $this->assertEquals('bar', $template->render(array())); + + /* to be uncomment in Twig 2.0 + // globals cannot be added after runtime init + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->initRuntime(); + try { + $twig->addGlobal('bar', 'bar'); + $this->fail(); + } catch (LogicException $e) { + $this->assertFalse(array_key_exists('bar', $twig->getGlobals())); + } + + // globals cannot be added after extensions init + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->getFunctions(); + try { + $twig->addGlobal('bar', 'bar'); + $this->fail(); + } catch (LogicException $e) { + $this->assertFalse(array_key_exists('bar', $twig->getGlobals())); + } + + // globals cannot be added after extensions and runtime init + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addGlobal('foo', 'foo'); + $twig->getGlobals(); + $twig->getFunctions(); + $twig->initRuntime(); + try { + $twig->addGlobal('bar', 'bar'); + $this->fail(); + } catch (LogicException $e) { + $this->assertFalse(array_key_exists('bar', $twig->getGlobals())); + } + + // test adding globals after initRuntime without call to getGlobals + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->initRuntime(); + try { + $twig->addGlobal('bar', 'bar'); + $this->fail(); + } catch (LogicException $e) { + $this->assertFalse(array_key_exists('bar', $twig->getGlobals())); + } + */ + } + + public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() + { + $options = array('cache' => sys_get_temp_dir().'/twig', 'auto_reload' => false, 'debug' => false); + + // force compilation + $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{ foo }}')), $options); + $cache = $twig->getCacheFilename('index'); + if (!is_dir(dirname($cache))) { + mkdir(dirname($cache), 0777, true); + } + file_put_contents($cache, $twig->compileSource('{{ foo }}', 'index')); + + // check that extensions won't be initialized when rendering a template that is already in the cache + $twig = $this + ->getMockBuilder('Twig_Environment') + ->setConstructorArgs(array($loader, $options)) + ->setMethods(array('initExtensions')) + ->getMock() + ; + + $twig->expects($this->never())->method('initExtensions'); + + // render template + $output = $twig->render('index', array('foo' => 'bar')); + $this->assertEquals('bar', $output); + + unlink($cache); + } + + public function testAddExtension() + { + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension()); + + $this->assertArrayHasKey('test', $twig->getTags()); + $this->assertArrayHasKey('foo_filter', $twig->getFilters()); + $this->assertArrayHasKey('foo_function', $twig->getFunctions()); + $this->assertArrayHasKey('foo_test', $twig->getTests()); + $this->assertArrayHasKey('foo_unary', $twig->getUnaryOperators()); + $this->assertArrayHasKey('foo_binary', $twig->getBinaryOperators()); + $this->assertArrayHasKey('foo_global', $twig->getGlobals()); + $visitors = $twig->getNodeVisitors(); + $this->assertEquals('Twig_Tests_EnvironmentTest_NodeVisitor', get_class($visitors[2])); + } + + public function testRemoveExtension() + { + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension()); + $twig->removeExtension('environment_test'); + + $this->assertFalse(array_key_exists('test', $twig->getTags())); + $this->assertFalse(array_key_exists('foo_filter', $twig->getFilters())); + $this->assertFalse(array_key_exists('foo_function', $twig->getFunctions())); + $this->assertFalse(array_key_exists('foo_test', $twig->getTests())); + $this->assertFalse(array_key_exists('foo_unary', $twig->getUnaryOperators())); + $this->assertFalse(array_key_exists('foo_binary', $twig->getBinaryOperators())); + $this->assertFalse(array_key_exists('foo_global', $twig->getGlobals())); + $this->assertCount(2, $twig->getNodeVisitors()); + } +} + +class Twig_Tests_EnvironmentTest_Extension extends Twig_Extension +{ + public function getTokenParsers() + { + return array( + new Twig_Tests_EnvironmentTest_TokenParser(), + ); + } + + public function getNodeVisitors() + { + return array( + new Twig_Tests_EnvironmentTest_NodeVisitor(), + ); + } + + public function getFilters() + { + return array( + new Twig_SimpleFilter('foo_filter', 'foo_filter'), + ); + } + + public function getTests() + { + return array( + new Twig_SimpleTest('foo_test', 'foo_test'), + ); + } + + public function getFunctions() + { + return array( + new Twig_SimpleFunction('foo_function', 'foo_function'), + ); + } + + public function getOperators() + { + return array( + array('foo_unary' => array()), + array('foo_binary' => array()), + ); + } + + public function getGlobals() + { + return array( + 'foo_global' => 'foo_global', + ); + } + + public function getName() + { + return 'environment_test'; + } +} + +class Twig_Tests_EnvironmentTest_TokenParser extends Twig_TokenParser +{ + public function parse(Twig_Token $token) + { + } + + public function getTag() + { + return 'test'; + } +} + +class Twig_Tests_EnvironmentTest_NodeVisitor implements Twig_NodeVisitorInterface +{ + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + return $node; + } + + public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + { + return $node; + } + + public function getPriority() + { + return 0; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/ErrorTest.php b/vendor/twig/twig/test/Twig/Tests/ErrorTest.php new file mode 100755 index 0000000..6a78d2b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/ErrorTest.php @@ -0,0 +1,144 @@ +setTemplateFile(new SplFileInfo(__FILE__)); + + $this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage()); + } + + public function testErrorWithArrayFilename() + { + $error = new Twig_Error('foo'); + $error->setTemplateFile(array('foo' => 'bar')); + + $this->assertEquals('foo in {"foo":"bar"}', $error->getMessage()); + } + + public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk() + { + $loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors'); + $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false)); + + $template = $twig->loadTemplate('index.html'); + try { + $template->render(array()); + + $this->fail(); + } catch (Twig_Error_Runtime $e) { + $this->assertEquals('Variable "foo" does not exist in "index.html" at line 3', $e->getMessage()); + $this->assertEquals(3, $e->getTemplateLine()); + $this->assertEquals('index.html', $e->getTemplateFile()); + } + + try { + $template->render(array('foo' => new Twig_Tests_ErrorTest_Foo())); + + $this->fail(); + } catch (Twig_Error_Runtime $e) { + $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage()); + $this->assertEquals(3, $e->getTemplateLine()); + $this->assertEquals('index.html', $e->getTemplateFile()); + } + } + + /** + * @dataProvider getErroredTemplates + */ + public function testTwigExceptionAddsFileAndLine($templates, $name, $line) + { + $loader = new Twig_Loader_Array($templates); + $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false)); + + $template = $twig->loadTemplate('index'); + + try { + $template->render(array()); + + $this->fail(); + } catch (Twig_Error_Runtime $e) { + $this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d', $name, $line), $e->getMessage()); + $this->assertEquals($line, $e->getTemplateLine()); + $this->assertEquals($name, $e->getTemplateFile()); + } + + try { + $template->render(array('foo' => new Twig_Tests_ErrorTest_Foo())); + + $this->fail(); + } catch (Twig_Error_Runtime $e) { + $this->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e->getMessage()); + $this->assertEquals($line, $e->getTemplateLine()); + $this->assertEquals($name, $e->getTemplateFile()); + } + } + + public function getErroredTemplates() + { + return array( + // error occurs in a template + array( + array( + 'index' => "\n\n{{ foo.bar }}\n\n\n{{ 'foo' }}", + ), + 'index', 3, + ), + + // error occurs in an included template + array( + array( + 'index' => "{% include 'partial' %}", + 'partial' => '{{ foo.bar }}', + ), + 'partial', 1, + ), + + // error occurs in a parent block when called via parent() + array( + array( + 'index' => "{% extends 'base' %} + {% block content %} + {{ parent() }} + {% endblock %}", + 'base' => '{% block content %}{{ foo.bar }}{% endblock %}', + ), + 'base', 1, + ), + + // error occurs in a block from the child + array( + array( + 'index' => "{% extends 'base' %} + {% block content %} + {{ foo.bar }} + {% endblock %} + {% block foo %} + {{ foo.bar }} + {% endblock %}", + 'base' => '{% block content %}{% endblock %}', + ), + 'index', 3, + ), + ); + } +} + +class Twig_Tests_ErrorTest_Foo +{ + public function bar() + { + throw new Exception('Runtime error...'); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/ExpressionParserTest.php b/vendor/twig/twig/test/Twig/Tests/ExpressionParserTest.php new file mode 100755 index 0000000..ff263cf --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/ExpressionParserTest.php @@ -0,0 +1,332 @@ +getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize($template, 'index')); + } + + public function getFailingTestsForAssignment() + { + return array( + array('{% set false = "foo" %}'), + array('{% set true = "foo" %}'), + array('{% set none = "foo" %}'), + array('{% set 3 = "foo" %}'), + array('{% set 1 + 2 = "foo" %}'), + array('{% set "bar" = "foo" %}'), + array('{% set %}{% endset %}'), + ); + } + + /** + * @dataProvider getTestsForArray + */ + public function testArrayExpression($template, $expected) + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $stream = $env->tokenize($template, 'index'); + $parser = new Twig_Parser($env); + + $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); + } + + /** + * @expectedException Twig_Error_Syntax + * @dataProvider getFailingTestsForArray + */ + public function testArraySyntaxError($template) + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize($template, 'index')); + } + + public function getFailingTestsForArray() + { + return array( + array('{{ [1, "a": "b"] }}'), + array('{{ {"a": "b", 2} }}'), + ); + } + + public function getTestsForArray() + { + return array( + // simple array + array('{{ [1, 2] }}', new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant(0, 1), + new Twig_Node_Expression_Constant(1, 1), + + new Twig_Node_Expression_Constant(1, 1), + new Twig_Node_Expression_Constant(2, 1), + ), 1), + ), + + // array with trailing , + array('{{ [1, 2, ] }}', new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant(0, 1), + new Twig_Node_Expression_Constant(1, 1), + + new Twig_Node_Expression_Constant(1, 1), + new Twig_Node_Expression_Constant(2, 1), + ), 1), + ), + + // simple hash + array('{{ {"a": "b", "b": "c"} }}', new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant('a', 1), + new Twig_Node_Expression_Constant('b', 1), + + new Twig_Node_Expression_Constant('b', 1), + new Twig_Node_Expression_Constant('c', 1), + ), 1), + ), + + // hash with trailing , + array('{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant('a', 1), + new Twig_Node_Expression_Constant('b', 1), + + new Twig_Node_Expression_Constant('b', 1), + new Twig_Node_Expression_Constant('c', 1), + ), 1), + ), + + // hash in an array + array('{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant(0, 1), + new Twig_Node_Expression_Constant(1, 1), + + new Twig_Node_Expression_Constant(1, 1), + new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant('a', 1), + new Twig_Node_Expression_Constant('b', 1), + + new Twig_Node_Expression_Constant('b', 1), + new Twig_Node_Expression_Constant('c', 1), + ), 1), + ), 1), + ), + + // array in a hash + array('{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant('a', 1), + new Twig_Node_Expression_Array(array( + new Twig_Node_Expression_Constant(0, 1), + new Twig_Node_Expression_Constant(1, 1), + + new Twig_Node_Expression_Constant(1, 1), + new Twig_Node_Expression_Constant(2, 1), + ), 1), + new Twig_Node_Expression_Constant('b', 1), + new Twig_Node_Expression_Constant('c', 1), + ), 1), + ), + ); + } + + /** + * @expectedException Twig_Error_Syntax + */ + public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $stream = $env->tokenize('{{ "a" "b" }}', 'index'); + $parser = new Twig_Parser($env); + + $parser->parse($stream); + } + + /** + * @dataProvider getTestsForString + */ + public function testStringExpression($template, $expected) + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); + $stream = $env->tokenize($template, 'index'); + $parser = new Twig_Parser($env); + + $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); + } + + public function getTestsForString() + { + return array( + array( + '{{ "foo" }}', new Twig_Node_Expression_Constant('foo', 1), + ), + array( + '{{ "foo #{bar}" }}', new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), + new Twig_Node_Expression_Name('bar', 1), + 1 + ), + ), + array( + '{{ "foo #{bar} baz" }}', new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), + new Twig_Node_Expression_Name('bar', 1), + 1 + ), + new Twig_Node_Expression_Constant(' baz', 1), + 1 + ), + ), + + array( + '{{ "foo #{"foo #{bar} baz"} baz" }}', new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), + new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), + new Twig_Node_Expression_Name('bar', 1), + 1 + ), + new Twig_Node_Expression_Constant(' baz', 1), + 1 + ), + 1 + ), + new Twig_Node_Expression_Constant(' baz', 1), + 1 + ), + ), + ); + } + + /** + * @expectedException Twig_Error_Syntax + */ + public function testAttributeCallDoesNotSupportNamedArguments() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize('{{ foo.bar(name="Foo") }}', 'index')); + } + + /** + * @expectedException Twig_Error_Syntax + */ + public function testMacroCallDoesNotSupportNamedArguments() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1 + */ + public function testMacroDefinitionDoesNotSupportNonNameVariableName() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize('{% macro foo("a") %}{% endmacro %}', 'index')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1 + * @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues + */ + public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template) + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize($template, 'index')); + } + + public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues() + { + return array( + array('{% macro foo(name = "a #{foo} a") %}{% endmacro %}'), + array('{% macro foo(name = [["b", "a #{foo} a"]]) %}{% endmacro %}'), + ); + } + + /** + * @dataProvider getMacroDefinitionSupportsConstantDefaultValues + */ + public function testMacroDefinitionSupportsConstantDefaultValues($template) + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize($template, 'index')); + } + + public function getMacroDefinitionSupportsConstantDefaultValues() + { + return array( + array('{% macro foo(name = "aa") %}{% endmacro %}'), + array('{% macro foo(name = 12) %}{% endmacro %}'), + array('{% macro foo(name = true) %}{% endmacro %}'), + array('{% macro foo(name = ["a"]) %}{% endmacro %}'), + array('{% macro foo(name = [["a"]]) %}{% endmacro %}'), + array('{% macro foo(name = {a: "a"}) %}{% endmacro %}'), + array('{% macro foo(name = {a: {b: "a"}}) %}{% endmacro %}'), + ); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage The function "cycl" does not exist. Did you mean "cycle" in "index" at line 1 + */ + public function testUnknownFunction() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize('{{ cycl() }}', 'index')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage The filter "lowe" does not exist. Did you mean "lower" in "index" at line 1 + */ + public function testUnknownFilter() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize('{{ 1|lowe }}', 'index')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage The test "nul" does not exist. Did you mean "null" in "index" at line 1 + */ + public function testUnknownTest() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $parser = new Twig_Parser($env); + + $parser->parse($env->tokenize('{{ 1 is nul }}', 'index')); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php b/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php new file mode 100755 index 0000000..b3b1cb0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php @@ -0,0 +1,156 @@ +assertTrue(in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type + } + } + + public function getRandomFunctionTestData() + { + return array( + array( // array + array('apple', 'orange', 'citrus'), + array('apple', 'orange', 'citrus'), + ), + array( // Traversable + new ArrayObject(array('apple', 'orange', 'citrus')), + array('apple', 'orange', 'citrus'), + ), + array( // unicode string + 'Ä€é', + array('Ä', '€', 'é'), + ), + array( // numeric but string + '123', + array('1', '2', '3'), + ), + array( // integer + 5, + range(0, 5, 1), + ), + array( // float + 5.9, + range(0, 5, 1), + ), + array( // negative + -2, + array(0, -1, -2), + ), + ); + } + + public function testRandomFunctionWithoutParameter() + { + $max = mt_getrandmax(); + + for ($i = 0; $i < 100; $i++) { + $val = twig_random(new Twig_Environment()); + $this->assertTrue(is_int($val) && $val >= 0 && $val <= $max); + } + } + + public function testRandomFunctionReturnsAsIs() + { + $this->assertSame('', twig_random(new Twig_Environment(), '')); + $this->assertSame('', twig_random(new Twig_Environment(null, array('charset' => null)), '')); + + $instance = new stdClass(); + $this->assertSame($instance, twig_random(new Twig_Environment(), $instance)); + } + + /** + * @expectedException Twig_Error_Runtime + */ + public function testRandomFunctionOfEmptyArrayThrowsException() + { + twig_random(new Twig_Environment(), array()); + } + + public function testRandomFunctionOnNonUTF8String() + { + if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + $this->markTestSkipped('needs iconv or mbstring'); + } + + $twig = new Twig_Environment(); + $twig->setCharset('ISO-8859-1'); + + $text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); + for ($i = 0; $i < 30; $i++) { + $rand = twig_random($twig, $text); + $this->assertTrue(in_array(twig_convert_encoding($rand, 'UTF-8', 'ISO-8859-1'), array('Ä', 'é'), true)); + } + } + + public function testReverseFilterOnNonUTF8String() + { + if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + $this->markTestSkipped('needs iconv or mbstring'); + } + + $twig = new Twig_Environment(); + $twig->setCharset('ISO-8859-1'); + + $input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); + $output = twig_convert_encoding(twig_reverse_filter($twig, $input), 'UTF-8', 'ISO-8859-1'); + + $this->assertEquals($output, 'éÄ'); + } + + public function testCustomEscaper() + { + $twig = new Twig_Environment(); + $twig->getExtension('core')->setEscaper('foo', 'foo_escaper_for_test'); + + $this->assertEquals('fooUTF-8', twig_escape_filter($twig, 'foo', 'foo')); + } + + /** + * @expectedException Twig_Error_Runtime + */ + public function testUnknownCustomEscaper() + { + twig_escape_filter(new Twig_Environment(), 'foo', 'bar'); + } + + public function testTwigFirst() + { + $twig = new Twig_Environment(); + $this->assertEquals('a', twig_first($twig, 'abc')); + $this->assertEquals(1, twig_first($twig, array(1, 2, 3))); + $this->assertSame('', twig_first($twig, null)); + $this->assertSame('', twig_first($twig, '')); + } + + public function testTwigLast() + { + $twig = new Twig_Environment(); + $this->assertEquals('c', twig_last($twig, 'abc')); + $this->assertEquals(3, twig_last($twig, array(1, 2, 3))); + $this->assertSame('', twig_last($twig, null)); + $this->assertSame('', twig_last($twig, '')); + } +} + +function foo_escaper_for_test(Twig_Environment $env, $string, $charset) +{ + return $string.$charset; +} diff --git a/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php b/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php new file mode 100755 index 0000000..fee35a0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php @@ -0,0 +1,220 @@ + 'Fabien', + 'obj' => new FooObject(), + 'arr' => array('obj' => new FooObject()), + ); + + self::$templates = array( + '1_basic1' => '{{ obj.foo }}', + '1_basic2' => '{{ name|upper }}', + '1_basic3' => '{% if name %}foo{% endif %}', + '1_basic4' => '{{ obj.bar }}', + '1_basic5' => '{{ obj }}', + '1_basic6' => '{{ arr.obj }}', + '1_basic7' => '{{ cycle(["foo","bar"], 1) }}', + '1_basic8' => '{{ obj.getfoobar }}{{ obj.getFooBar }}', + '1_basic9' => '{{ obj.foobar }}{{ obj.fooBar }}', + '1_basic' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}', + '1_layout' => '{% block content %}{% endblock %}', + '1_child' => "{% extends \"1_layout\" %}\n{% block content %}\n{{ \"a\"|json_encode }}\n{% endblock %}", + ); + } + + /** + * @expectedException Twig_Sandbox_SecurityError + * @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child" at line 3. + */ + public function testSandboxWithInheritance() + { + $twig = $this->getEnvironment(true, array(), self::$templates, array('block')); + $twig->loadTemplate('1_child')->render(array()); + } + + public function testSandboxGloballySet() + { + $twig = $this->getEnvironment(false, array(), self::$templates); + $this->assertEquals('FOO', $twig->loadTemplate('1_basic')->render(self::$params), 'Sandbox does nothing if it is disabled globally'); + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic1')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed method is called'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic2')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic3')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic4')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic5')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic6')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_basic7')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template'); + } catch (Twig_Sandbox_SecurityError $e) { + } + + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => 'foo')); + FooObject::reset(); + $this->assertEquals('foo', $twig->loadTemplate('1_basic1')->render(self::$params), 'Sandbox allow some methods'); + $this->assertEquals(1, FooObject::$called['foo'], 'Sandbox only calls method once'); + + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => '__toString')); + FooObject::reset(); + $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allow some methods'); + $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); + + $twig = $this->getEnvironment(false, array(), self::$templates); + FooObject::reset(); + $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled'); + $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); + + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array('upper')); + $this->assertEquals('FABIEN', $twig->loadTemplate('1_basic2')->render(self::$params), 'Sandbox allow some filters'); + + $twig = $this->getEnvironment(true, array(), self::$templates, array('if')); + $this->assertEquals('foo', $twig->loadTemplate('1_basic3')->render(self::$params), 'Sandbox allow some tags'); + + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array(), array('FooObject' => 'bar')); + $this->assertEquals('bar', $twig->loadTemplate('1_basic4')->render(self::$params), 'Sandbox allow some properties'); + + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array(), array(), array('cycle')); + $this->assertEquals('bar', $twig->loadTemplate('1_basic7')->render(self::$params), 'Sandbox allow some functions'); + + foreach (array('getfoobar', 'getFoobar', 'getFooBar') as $name) { + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => $name)); + FooObject::reset(); + $this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic8')->render(self::$params), 'Sandbox allow methods in a case-insensitive way'); + $this->assertEquals(2, FooObject::$called['getFooBar'], 'Sandbox only calls method once'); + + $this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic9')->render(self::$params), 'Sandbox allow methods via shortcut names (ie. without get/set)'); + } + } + + public function testSandboxLocallySetForAnInclude() + { + self::$templates = array( + '2_basic' => '{{ obj.foo }}{% include "2_included" %}{{ obj.foo }}', + '2_included' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}', + ); + + $twig = $this->getEnvironment(false, array(), self::$templates); + $this->assertEquals('fooFOOfoo', $twig->loadTemplate('2_basic')->render(self::$params), 'Sandbox does nothing if disabled globally and sandboxed not used for the include'); + + self::$templates = array( + '3_basic' => '{{ obj.foo }}{% sandbox %}{% include "3_included" %}{% endsandbox %}{{ obj.foo }}', + '3_included' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}', + ); + + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('3_basic')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed'); + } catch (Twig_Sandbox_SecurityError $e) { + } + } + + public function testMacrosInASandbox() + { + $twig = $this->getEnvironment(true, array('autoescape' => true), array('index' => <<{{ text }}

    {% endmacro %} + +{{- macros.test('username') }} +EOF + ), array('macro', 'import'), array('escape')); + + $this->assertEquals('

    username

    ', $twig->loadTemplate('index')->render(array())); + } + + protected function getEnvironment($sandboxed, $options, $templates, $tags = array(), $filters = array(), $methods = array(), $properties = array(), $functions = array()) + { + $loader = new Twig_Loader_Array($templates); + $twig = new Twig_Environment($loader, array_merge(array('debug' => true, 'cache' => false, 'autoescape' => false), $options)); + $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods, $properties, $functions); + $twig->addExtension(new Twig_Extension_Sandbox($policy, $sandboxed)); + + return $twig; + } +} + +class FooObject +{ + public static $called = array('__toString' => 0, 'foo' => 0, 'getFooBar' => 0); + + public $bar = 'bar'; + + public static function reset() + { + self::$called = array('__toString' => 0, 'foo' => 0, 'getFooBar' => 0); + } + + public function __toString() + { + ++self::$called['__toString']; + + return 'foo'; + } + + public function foo() + { + ++self::$called['foo']; + + return 'foo'; + } + + public function getFooBar() + { + ++self::$called['getFooBar']; + + return 'foobar'; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php b/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php new file mode 100755 index 0000000..6f5bfee --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php @@ -0,0 +1,79 @@ +tmpDir = sys_get_temp_dir().'/TwigTests'; + if (!file_exists($this->tmpDir)) { + @mkdir($this->tmpDir, 0777, true); + } + + if (!is_writable($this->tmpDir)) { + $this->markTestSkipped(sprintf('Unable to run the tests as "%s" is not writable.', $this->tmpDir)); + } + + $this->env = new Twig_Environment(new Twig_Loader_Array(array('index' => 'index', 'index2' => 'index2')), array('cache' => $this->tmpDir)); + } + + public function tearDown() + { + if ($this->fileName) { + unlink($this->fileName); + } + + $this->removeDir($this->tmpDir); + } + + public function testWritingCacheFiles() + { + $name = 'index'; + $this->env->loadTemplate($name); + $cacheFileName = $this->env->getCacheFilename($name); + + $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.'); + $this->fileName = $cacheFileName; + } + + public function testClearingCacheFiles() + { + $name = 'index2'; + $this->env->loadTemplate($name); + $cacheFileName = $this->env->getCacheFilename($name); + + $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.'); + $this->env->clearCacheFiles(); + $this->assertFalse(file_exists($cacheFileName), 'Cache file was not cleared.'); + } + + private function removeDir($target) + { + $fp = opendir($target); + while (false !== $file = readdir($fp)) { + if (in_array($file, array('.', '..'))) { + continue; + } + + if (is_dir($target.'/'.$file)) { + self::removeDir($target.'/'.$file); + } else { + unlink($target.'/'.$file); + } + } + closedir($fp); + rmdir($target); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php b/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php new file mode 100755 index 0000000..d2f55eb --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/FileExtensionEscapingStrategyTest.php @@ -0,0 +1,49 @@ +assertEquals($strategy, Twig_FileExtensionEscapingStrategy::guess($filename)); + } + + public function getGuessData() + { + return array( + // default + array('html', 'foo.html'), + array('html', 'foo.html.twig'), + array('html', 'foo'), + array('html', 'foo.bar.twig'), + array('html', 'foo.txt/foo'), + array('html', 'foo.txt/foo.js/'), + + // css + array('css', 'foo.css'), + array('css', 'foo.css.twig'), + array('css', 'foo.twig.css'), + + // js + array('js', 'foo.js'), + array('js', 'foo.js.twig'), + array('js', 'foo.txt/foo.js'), + array('js', 'foo.txt.twig/foo.js'), + + // txt + array(false, 'foo.txt'), + array(false, 'foo.txt.twig'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/autoescape/filename.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/autoescape/filename.test new file mode 100755 index 0000000..b091ad3 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/autoescape/filename.test @@ -0,0 +1,18 @@ +--TEST-- +"filename" autoescape strategy +--TEMPLATE-- +{{ br -}} +{{ include('index.html.twig') -}} +{{ include('index.txt.twig') -}} +--TEMPLATE(index.html.twig)-- +{{ br -}} +--TEMPLATE(index.txt.twig)-- +{{ br -}} +--DATA-- +return array('br' => '
    ') +--CONFIG-- +return array('autoescape' => 'filename') +--EXPECT-- +<br /> +<br /> +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/errors/base.html b/vendor/twig/twig/test/Twig/Tests/Fixtures/errors/base.html new file mode 100755 index 0000000..cb0dbe4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/errors/base.html @@ -0,0 +1 @@ +{% block content %}{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/errors/index.html b/vendor/twig/twig/test/Twig/Tests/Fixtures/errors/index.html new file mode 100755 index 0000000..df57c82 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/errors/index.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +{% block content %} + {{ foo.bar }} +{% endblock %} +{% block foo %} + {{ foo.bar }} +{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test new file mode 100755 index 0000000..ce49165 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable.test @@ -0,0 +1,18 @@ +--TEST-- +Exception for multiline array with undefined variable +--TEMPLATE-- +{% set foo = { + foo: 'foo', + bar: 'bar', + + + foobar: foobar, + + + + foo2: foo2, +} %} +--DATA-- +return array('foobar' => 'foobar') +--EXCEPTION-- +Twig_Error_Runtime: Variable "foo2" does not exist in "index.twig" at line 11 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test new file mode 100755 index 0000000..e3c040f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_array_with_undefined_variable_again.test @@ -0,0 +1,18 @@ +--TEST-- +Exception for multiline array with undefined variable +--TEMPLATE-- +{% set foo = { + foo: 'foo', + bar: 'bar', + + + foobar: foobar, + + + + foo2: foo2, +} %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Runtime: Variable "foobar" does not exist in "index.twig" at line 7 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test new file mode 100755 index 0000000..d799a39 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_undefined_variable.test @@ -0,0 +1,12 @@ +--TEST-- +Exception for multile function with undefined variable +--TEMPLATE-- +{{ include('foo', + with_context=with_context +) }} +--TEMPLATE(foo)-- +Foo +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Runtime: Variable "with_context" does not exist in "index.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_unknown_argument.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_unknown_argument.test new file mode 100755 index 0000000..64761fc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_function_with_unknown_argument.test @@ -0,0 +1,9 @@ +--TEST-- +Exception for multiline function with unknown argument +--TEMPLATE-- +{{ include('foo', + with_context=True, + invalid=False +) }} +--EXCEPTION-- +Twig_Error_Syntax: Unknown argument "invalid" for function "include(template, variables, with_context, ignore_missing, sandboxed)" in "index.twig" at line 4. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test new file mode 100755 index 0000000..096a5db --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/multiline_tag_with_undefined_variable.test @@ -0,0 +1,12 @@ +--TEST-- +Exception for multiline tag with undefined variable +--TEMPLATE-- +{% include 'foo' + with vars +%} +--TEMPLATE(foo)-- +Foo +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Runtime: Variable "vars" does not exist in "index.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test new file mode 100755 index 0000000..5dd9f38 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test @@ -0,0 +1,10 @@ +--TEST-- +Exception for syntax error in reused template +--TEMPLATE-- +{% use 'foo.twig' %} +--TEMPLATE(foo.twig)-- +{% block bar %} + {% do node.data = 5 %} +{% endblock %} +--EXCEPTION-- +Twig_Error_Syntax: Unexpected token "operator" of value "=" ("end of statement block" expected) in "foo.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test new file mode 100755 index 0000000..02245e9 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test @@ -0,0 +1,20 @@ +--TEST-- +Exception for an unclosed tag +--TEMPLATE-- +{% block foo %} + {% if foo %} + + + + + {% for i in fo %} + + + + {% endfor %} + + + +{% endblock %} +--EXCEPTION-- +Twig_Error_Syntax: Unexpected tag name "endblock" (expecting closing tag for the "if" tag defined near line 4) in "index.twig" at line 16 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_parent.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_parent.test new file mode 100755 index 0000000..c8e7a09 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_parent.test @@ -0,0 +1,8 @@ +--TEST-- +Exception for an undefined parent +--TEMPLATE-- +{% extends 'foo.html' %} + +{% set foo = "foo" %} +--EXCEPTION-- +Twig_Error_Loader: Template "foo.html" is not defined in "index.twig" at line 2. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test new file mode 100755 index 0000000..6679fbe --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test @@ -0,0 +1,9 @@ +--TEST-- +Exception for an undefined trait +--TEMPLATE-- +{% use 'foo' with foobar as bar %} +--TEMPLATE(foo)-- +{% block bar %} +{% endblock %} +--EXCEPTION-- +Twig_Error_Runtime: Block "foobar" is not defined in trait "foo" in "index.twig" at line 2. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array.test new file mode 100755 index 0000000..c69b119 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array.test @@ -0,0 +1,61 @@ +--TEST-- +Twig supports array notation +--TEMPLATE-- +{# empty array #} +{{ []|join(',') }} + +{{ [1, 2]|join(',') }} +{{ ['foo', "bar"]|join(',') }} +{{ {0: 1, 'foo': 'bar'}|join(',') }} +{{ {0: 1, 'foo': 'bar'}|keys|join(',') }} + +{{ {0: 1, foo: 'bar'}|join(',') }} +{{ {0: 1, foo: 'bar'}|keys|join(',') }} + +{# nested arrays #} +{% set a = [1, 2, [1, 2], {'foo': {'foo': 'bar'}}] %} +{{ a[2]|join(',') }} +{{ a[3]["foo"]|join(',') }} + +{# works even if [] is used inside the array #} +{{ [foo[bar]]|join(',') }} + +{# elements can be any expression #} +{{ ['foo'|upper, bar|upper, bar == foo]|join(',') }} + +{# arrays can have a trailing , like in PHP #} +{{ + [ + 1, + 2, + ]|join(',') +}} + +{# keys can be any expression #} +{% set a = 1 %} +{% set b = "foo" %} +{% set ary = { (a): 'a', (b): 'b', 'c': 'c', (a ~ b): 'd' } %} +{{ ary|keys|join(',') }} +{{ ary|join(',') }} +--DATA-- +return array('bar' => 'bar', 'foo' => array('bar' => 'bar')) +--EXPECT-- +1,2 +foo,bar +1,bar +0,foo + +1,bar +0,foo + +1,2 +bar + +bar + +FOO,BAR, + +1,2 + +1,foo,c,1foo +a,b,c,d diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array_call.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array_call.test new file mode 100755 index 0000000..f3df328 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/array_call.test @@ -0,0 +1,14 @@ +--TEST-- +Twig supports method calls +--TEMPLATE-- +{{ items.foo }} +{{ items['foo'] }} +{{ items[foo] }} +{{ items[items[foo]] }} +--DATA-- +return array('foo' => 'bar', 'items' => array('foo' => 'bar', 'bar' => 'foo')) +--EXPECT-- +bar +bar +foo +bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/binary.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/binary.test new file mode 100755 index 0000000..f5e6845 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/binary.test @@ -0,0 +1,46 @@ +--TEST-- +Twig supports binary operations (+, -, *, /, ~, %, and, or) +--TEMPLATE-- +{{ 1 + 1 }} +{{ 2 - 1 }} +{{ 2 * 2 }} +{{ 2 / 2 }} +{{ 3 % 2 }} +{{ 1 and 1 }} +{{ 1 and 0 }} +{{ 0 and 1 }} +{{ 0 and 0 }} +{{ 1 or 1 }} +{{ 1 or 0 }} +{{ 0 or 1 }} +{{ 0 or 0 }} +{{ 0 or 1 and 0 }} +{{ 1 or 0 and 1 }} +{{ "foo" ~ "bar" }} +{{ foo ~ "bar" }} +{{ "foo" ~ bar }} +{{ foo ~ bar }} +{{ 20 // 7 }} +--DATA-- +return array('foo' => 'bar', 'bar' => 'foo') +--EXPECT-- +2 +1 +4 +1 +1 +1 + + + +1 +1 +1 + + +1 +foobar +barbar +foofoo +barfoo +2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test new file mode 100755 index 0000000..74fe6ca --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test @@ -0,0 +1,14 @@ +--TEST-- +Twig supports bitwise operations +--TEMPLATE-- +{{ 1 b-and 5 }} +{{ 1 b-or 5 }} +{{ 1 b-xor 5 }} +{{ (1 and 0 b-or 0) is same as(1 and (0 b-or 0)) ? 'ok' : 'ko' }} +--DATA-- +return array() +--EXPECT-- +1 +5 +4 +ok diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/comparison.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/comparison.test new file mode 100755 index 0000000..726b850 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/comparison.test @@ -0,0 +1,14 @@ +--TEST-- +Twig supports comparison operators (==, !=, <, >, >=, <=) +--TEMPLATE-- +{{ 1 > 2 }}/{{ 1 > 1 }}/{{ 1 >= 2 }}/{{ 1 >= 1 }} +{{ 1 < 2 }}/{{ 1 < 1 }}/{{ 1 <= 2 }}/{{ 1 <= 1 }} +{{ 1 == 1 }}/{{ 1 == 2 }} +{{ 1 != 1 }}/{{ 1 != 2 }} +--DATA-- +return array() +--EXPECT-- +///1 +1//1/1 +1/ +/1 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test new file mode 100755 index 0000000..238dd27 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test @@ -0,0 +1,17 @@ +--TEST-- +Twig supports the "divisible by" operator +--TEMPLATE-- +{{ 8 is divisible by(2) ? 'OK' }} +{{ 8 is not divisible by(3) ? 'OK' }} +{{ 8 is divisible by (2) ? 'OK' }} +{{ 8 is not + divisible + by + (3) ? 'OK' }} +--DATA-- +return array() +--EXPECT-- +OK +OK +OK +OK diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/dotdot.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/dotdot.test new file mode 100755 index 0000000..9cd0676 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/dotdot.test @@ -0,0 +1,20 @@ +--TEST-- +Twig supports the .. operator +--TEMPLATE-- +{% for i in 0..10 %}{{ i }} {% endfor %} + +{% for letter in 'a'..'z' %}{{ letter }} {% endfor %} + +{% for letter in 'a'|upper..'z'|upper %}{{ letter }} {% endfor %} + +{% for i in foo[0]..foo[1] %}{{ i }} {% endfor %} + +{% for i in 0 + 1 .. 10 - 1 %}{{ i }} {% endfor %} +--DATA-- +return array('foo' => array(1, 10)) +--EXPECT-- +0 1 2 3 4 5 6 7 8 9 10 +a b c d e f g h i j k l m n o p q r s t u v w x y z +A B C D E F G H I J K L M N O P Q R S T U V W X Y Z +1 2 3 4 5 6 7 8 9 10 +1 2 3 4 5 6 7 8 9 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test new file mode 100755 index 0000000..9ad5e5e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test @@ -0,0 +1,26 @@ +--TEST-- +Twig supports the "ends with" operator +--TEMPLATE-- +{{ 'foo' ends with 'o' ? 'OK' : 'KO' }} +{{ not ('foo' ends with 'f') ? 'OK' : 'KO' }} +{{ not ('foo' ends with 'foowaytoolong') ? 'OK' : 'KO' }} +{{ 'foo' ends with '' ? 'OK' : 'KO' }} +{{ '1' ends with true ? 'OK' : 'KO' }} +{{ 1 ends with true ? 'OK' : 'KO' }} +{{ 0 ends with false ? 'OK' : 'KO' }} +{{ '' ends with false ? 'OK' : 'KO' }} +{{ false ends with false ? 'OK' : 'KO' }} +{{ false ends with '' ? 'OK' : 'KO' }} +--DATA-- +return array() +--EXPECT-- +OK +OK +OK +OK +KO +KO +KO +KO +KO +KO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/grouping.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/grouping.test new file mode 100755 index 0000000..79f8e0b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/grouping.test @@ -0,0 +1,8 @@ +--TEST-- +Twig supports grouping of expressions +--TEMPLATE-- +{{ (2 + 2) / 2 }} +--DATA-- +return array() +--EXPECT-- +2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/literals.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/literals.test new file mode 100755 index 0000000..7ae3bae --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/literals.test @@ -0,0 +1,22 @@ +--TEST-- +Twig supports literals +--TEMPLATE-- +1 {{ true }} +2 {{ TRUE }} +3 {{ false }} +4 {{ FALSE }} +5 {{ none }} +6 {{ NONE }} +7 {{ null }} +8 {{ NULL }} +--DATA-- +return array() +--EXPECT-- +1 1 +2 1 +3 +4 +5 +6 +7 +8 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/magic_call.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/magic_call.test new file mode 100755 index 0000000..159db96 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/magic_call.test @@ -0,0 +1,27 @@ +--TEST-- +Twig supports __call() for attributes +--TEMPLATE-- +{{ foo.foo }} +{{ foo.bar }} +--DATA-- +class TestClassForMagicCallAttributes +{ + public function getBar() + { + return 'bar_from_getbar'; + } + + public function __call($method, $arguments) + { + if ('foo' === $method) + { + return 'foo_from_call'; + } + + return false; + } +} +return array('foo' => new TestClassForMagicCallAttributes()) +--EXPECT-- +foo_from_call +bar_from_getbar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/matches.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/matches.test new file mode 100755 index 0000000..b6c7716 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/matches.test @@ -0,0 +1,12 @@ +--TEST-- +Twig supports the "matches" operator +--TEMPLATE-- +{{ 'foo' matches '/o/' ? 'OK' : 'KO' }} +{{ 'foo' matches '/^fo/' ? 'OK' : 'KO' }} +{{ 'foo' matches '/O/i' ? 'OK' : 'KO' }} +--DATA-- +return array() +--EXPECT-- +OK +OK +OK diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/method_call.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/method_call.test new file mode 100755 index 0000000..5f801e6 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/method_call.test @@ -0,0 +1,28 @@ +--TEST-- +Twig supports method calls +--TEMPLATE-- +{{ items.foo.foo }} +{{ items.foo.getFoo() }} +{{ items.foo.bar }} +{{ items.foo['bar'] }} +{{ items.foo.bar('a', 43) }} +{{ items.foo.bar(foo) }} +{{ items.foo.self.foo() }} +{{ items.foo.is }} +{{ items.foo.in }} +{{ items.foo.not }} +--DATA-- +return array('foo' => 'bar', 'items' => array('foo' => new TwigTestFoo(), 'bar' => 'foo')) +--CONFIG-- +return array('strict_variables' => false) +--EXPECT-- +foo +foo +bar + +bar_a-43 +bar_bar +foo +is +in +not diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/negative_numbers.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/negative_numbers.test new file mode 100755 index 0000000..1853b1b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/negative_numbers.test @@ -0,0 +1,18 @@ +--TEST-- +Twig manages negative numbers correctly +--TEMPLATE-- +{{ -1 }} +{{ - 1 }} +{{ 5 - 1 }} +{{ 5-1 }} +{{ 5 + -1 }} +{{ 5 + - 1 }} +--DATA-- +return array() +--EXPECT-- +-1 +-1 +4 +4 +4 +4 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/operators_as_variables.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/operators_as_variables.test new file mode 100755 index 0000000..fe29d08 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/operators_as_variables.test @@ -0,0 +1,16 @@ +--TEST-- +Twig allows to use named operators as variable names +--TEMPLATE-- +{% for match in matches %} + {{- match }} +{% endfor %} +{{ in }} +{{ is }} +--DATA-- +return array('matches' => array(1, 2, 3), 'in' => 'in', 'is' => 'is') +--EXPECT-- +1 +2 +3 +in +is diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/postfix.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/postfix.test new file mode 100755 index 0000000..542c350 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/postfix.test @@ -0,0 +1,22 @@ +--TEST-- +Twig parses postfix expressions +--TEMPLATE-- +{% import _self as macros %} + +{% macro foo() %}foo{% endmacro %} + +{{ 'a' }} +{{ 'a'|upper }} +{{ ('a')|upper }} +{{ -1|upper }} +{{ macros.foo() }} +{{ (macros).foo() }} +--DATA-- +return array(); +--EXPECT-- +a +A +A +-1 +foo +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test new file mode 100755 index 0000000..601201d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test @@ -0,0 +1,21 @@ +--TEST-- +Twig supports the "same as" operator +--TEMPLATE-- +{{ 1 is same as(1) ? 'OK' }} +{{ 1 is not same as(true) ? 'OK' }} +{{ 1 is same as(1) ? 'OK' }} +{{ 1 is not same as(true) ? 'OK' }} +{{ 1 is same as (1) ? 'OK' }} +{{ 1 is not + same + as + (true) ? 'OK' }} +--DATA-- +return array() +--EXPECT-- +OK +OK +OK +OK +OK +OK diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test new file mode 100755 index 0000000..75d331e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test @@ -0,0 +1,27 @@ +--TEST-- +Twig supports the "starts with" operator +--TEMPLATE-- +{{ 'foo' starts with 'f' ? 'OK' : 'KO' }} +{{ not ('foo' starts with 'oo') ? 'OK' : 'KO' }} +{{ not ('foo' starts with 'foowaytoolong') ? 'OK' : 'KO' }} +{{ 'foo' starts with 'f' ? 'OK' : 'KO' }} +{{ 'foo' starts +with 'f' ? 'OK' : 'KO' }} +{{ 'foo' starts with '' ? 'OK' : 'KO' }} +{{ '1' starts with true ? 'OK' : 'KO' }} +{{ '' starts with false ? 'OK' : 'KO' }} +{{ 'a' starts with false ? 'OK' : 'KO' }} +{{ false starts with '' ? 'OK' : 'KO' }} +--DATA-- +return array() +--EXPECT-- +OK +OK +OK +OK +OK +OK +KO +KO +KO +KO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/strings.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/strings.test new file mode 100755 index 0000000..a911661 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/strings.test @@ -0,0 +1,10 @@ +--TEST-- +Twig supports string interpolation +--TEMPLATE-- +{{ "foo #{"foo #{bar} baz"} baz" }} +{{ "foo #{bar}#{bar} baz" }} +--DATA-- +return array('bar' => 'BAR'); +--EXPECT-- +foo foo BAR baz baz +foo BARBAR baz diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator.test new file mode 100755 index 0000000..0e6fa96 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator.test @@ -0,0 +1,18 @@ +--TEST-- +Twig supports the ternary operator +--TEMPLATE-- +{{ 1 ? 'YES' : 'NO' }} +{{ 0 ? 'YES' : 'NO' }} +{{ 0 ? 'YES' : (1 ? 'YES1' : 'NO1') }} +{{ 0 ? 'YES' : (0 ? 'YES1' : 'NO1') }} +{{ 1 == 1 ? 'foo
    ':'' }} +{{ foo ~ (bar ? ('-' ~ bar) : '') }} +--DATA-- +return array('foo' => 'foo', 'bar' => 'bar') +--EXPECT-- +YES +NO +YES1 +NO1 +foo
    +foo-bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_noelse.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_noelse.test new file mode 100755 index 0000000..fdc660f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_noelse.test @@ -0,0 +1,10 @@ +--TEST-- +Twig supports the ternary operator +--TEMPLATE-- +{{ 1 ? 'YES' }} +{{ 0 ? 'YES' }} +--DATA-- +return array() +--EXPECT-- +YES + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_nothen.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_nothen.test new file mode 100755 index 0000000..9057e83 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ternary_operator_nothen.test @@ -0,0 +1,10 @@ +--TEST-- +Twig supports the ternary operator +--TEMPLATE-- +{{ 'YES' ?: 'NO' }} +{{ 0 ?: 'NO' }} +--DATA-- +return array() +--EXPECT-- +YES +NO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/two_word_operators_as_variables.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/two_word_operators_as_variables.test new file mode 100755 index 0000000..47f37e4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/two_word_operators_as_variables.test @@ -0,0 +1,8 @@ +--TEST-- +Twig does not allow to use two-word named operators as variable names +--TEMPLATE-- +{{ starts with }} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Syntax: Unexpected token "operator" of value "starts with" in "index.twig" at line 2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary.test new file mode 100755 index 0000000..b79219a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary.test @@ -0,0 +1,12 @@ +--TEST-- +Twig supports unary operators (not, -, +) +--TEMPLATE-- +{{ not 1 }}/{{ not 0 }} +{{ +1 + 1 }}/{{ -1 - 1 }} +{{ not (false or true) }} +--DATA-- +return array() +--EXPECT-- +/1 +2/-2 + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_macro_arguments.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_macro_arguments.test new file mode 100755 index 0000000..ad84a9c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_macro_arguments.test @@ -0,0 +1,22 @@ +--TEST-- +Twig manages negative numbers as default parameters +--TEMPLATE-- +{% import _self as macros %} +{{ macros.negative_number1() }} +{{ macros.negative_number2() }} +{{ macros.negative_number3() }} +{{ macros.positive_number1() }} +{{ macros.positive_number2() }} +{% macro negative_number1(nb=-1) %}{{ nb }}{% endmacro %} +{% macro negative_number2(nb = --1) %}{{ nb }}{% endmacro %} +{% macro negative_number3(nb = - 1) %}{{ nb }}{% endmacro %} +{% macro positive_number1(nb = +1) %}{{ nb }}{% endmacro %} +{% macro positive_number2(nb = ++1) %}{{ nb }}{% endmacro %} +--DATA-- +return array() +--EXPECT-- +-1 +1 +-1 +1 +1 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_precedence.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_precedence.test new file mode 100755 index 0000000..cc6eef8 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/unary_precedence.test @@ -0,0 +1,14 @@ +--TEST-- +Twig unary operators precedence +--TEMPLATE-- +{{ -1 - 1 }} +{{ -1 - -1 }} +{{ -1 * -1 }} +{{ 4 / -1 * 5 }} +--DATA-- +return array() +--EXPECT-- +-2 +0 +1 +-20 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/abs.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/abs.test new file mode 100755 index 0000000..27e93fd --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/abs.test @@ -0,0 +1,30 @@ +--TEST-- +"abs" filter +--TEMPLATE-- +{{ (-5.5)|abs }} +{{ (-5)|abs }} +{{ (-0)|abs }} +{{ 0|abs }} +{{ 5|abs }} +{{ 5.5|abs }} +{{ number1|abs }} +{{ number2|abs }} +{{ number3|abs }} +{{ number4|abs }} +{{ number5|abs }} +{{ number6|abs }} +--DATA-- +return array('number1' => -5.5, 'number2' => -5, 'number3' => -0, 'number4' => 0, 'number5' => 5, 'number6' => 5.5) +--EXPECT-- +5.5 +5 +0 +0 +5 +5.5 +5.5 +5 +0 +0 +5 +5.5 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch.test new file mode 100755 index 0000000..cb6de7f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch.test @@ -0,0 +1,31 @@ +--TEST-- +"batch" filter +--TEMPLATE-- +{% for row in items|batch(3) %} +
    + {% for column in row %} +
    {{ column }}
    + {% endfor %} +
    +{% endfor %} +--DATA-- +return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')) +--EXPECT-- +
    +
    a
    +
    b
    +
    c
    +
    +
    +
    d
    +
    e
    +
    f
    +
    +
    +
    g
    +
    h
    +
    i
    +
    +
    +
    j
    +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test new file mode 100755 index 0000000..e2ec4be --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test @@ -0,0 +1,29 @@ +--TEST-- +"batch" filter +--TEMPLATE-- +{% for row in items|batch(3.1) %} +
    + {% for column in row %} +
    {{ column }}
    + {% endfor %} +
    +{% endfor %} +--DATA-- +return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')) +--EXPECT-- +
    +
    a
    +
    b
    +
    c
    +
    d
    +
    +
    +
    e
    +
    f
    +
    g
    +
    h
    +
    +
    +
    i
    +
    j
    +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_empty_fill.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_empty_fill.test new file mode 100755 index 0000000..af996f2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_empty_fill.test @@ -0,0 +1,37 @@ +--TEST-- +"batch" filter +--TEMPLATE-- + +{% for row in items|batch(3, '') %} + + {% for column in row %} + + {% endfor %} + +{% endfor %} +
    {{ column }}
    +--DATA-- +return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')) +--EXPECT-- + + + + + + + + + + + + + + + + + + + + + +
    abc
    def
    ghi
    j
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_exact_elements.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_exact_elements.test new file mode 100755 index 0000000..72483f4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_exact_elements.test @@ -0,0 +1,33 @@ +--TEST-- +"batch" filter +--TEMPLATE-- +{% for row in items|batch(3, 'fill') %} +
    + {% for column in row %} +
    {{ column }}
    + {% endfor %} +
    +{% endfor %} +--DATA-- +return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l')) +--EXPECT-- +
    +
    a
    +
    b
    +
    c
    +
    +
    +
    d
    +
    e
    +
    f
    +
    +
    +
    g
    +
    h
    +
    i
    +
    +
    +
    j
    +
    k
    +
    l
    +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_fill.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_fill.test new file mode 100755 index 0000000..746295f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_with_fill.test @@ -0,0 +1,37 @@ +--TEST-- +"batch" filter +--TEMPLATE-- + +{% for row in items|batch(3, 'fill') %} + + {% for column in row %} + + {% endfor %} + +{% endfor %} +
    {{ column }}
    +--DATA-- +return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')) +--EXPECT-- + + + + + + + + + + + + + + + + + + + + + +
    abc
    def
    ghi
    jfillfill
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/convert_encoding.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/convert_encoding.test new file mode 100755 index 0000000..380b04b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/convert_encoding.test @@ -0,0 +1,10 @@ +--TEST-- +"convert_encoding" filter +--CONDITION-- +function_exists('iconv') || function_exists('mb_convert_encoding') +--TEMPLATE-- +{{ "愛していますか?"|convert_encoding('ISO-2022-JP', 'UTF-8')|convert_encoding('UTF-8', 'ISO-2022-JP') }} +--DATA-- +return array() +--EXPECT-- +愛していますか? diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test new file mode 100755 index 0000000..d17e5e2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test @@ -0,0 +1,90 @@ +--TEST-- +"date" filter +--TEMPLATE-- +{{ date1|date }} +{{ date1|date('d/m/Y') }} +{{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }} +{{ date1|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }} +{{ date1|date('d/m/Y H:i:s P', 'America/Chicago') }} +{{ date1|date('e') }} +{{ date1|date('d/m/Y H:i:s') }} + +{{ date2|date }} +{{ date2|date('d/m/Y') }} +{{ date2|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }} +{{ date2|date('d/m/Y H:i:s', timezone1) }} +{{ date2|date('d/m/Y H:i:s') }} + +{{ date3|date }} +{{ date3|date('d/m/Y') }} + +{{ date4|date }} +{{ date4|date('d/m/Y') }} + +{{ date5|date }} +{{ date5|date('d/m/Y') }} + +{{ date6|date('d/m/Y H:i:s P', 'Europe/Paris') }} +{{ date6|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }} +{{ date6|date('d/m/Y H:i:s P', false) }} +{{ date6|date('e', 'Europe/Paris') }} +{{ date6|date('e', false) }} + +{{ date7|date }} +{{ date7|date(timezone='Europe/Paris') }} +{{ date7|date(timezone='Asia/Hong_Kong') }} +{{ date7|date(timezone=false) }} +{{ date7|date(timezone='Indian/Mauritius') }} + +{{ '2010-01-28 15:00:00'|date(timezone="Europe/Paris") }} +{{ '2010-01-28 15:00:00'|date(timezone="Asia/Hong_Kong") }} +--DATA-- +date_default_timezone_set('Europe/Paris'); +return array( + 'date1' => mktime(13, 45, 0, 10, 4, 2010), + 'date2' => new DateTime('2010-10-04 13:45'), + 'date3' => '2010-10-04 13:45', + 'date4' => 1286199900, // DateTime::createFromFormat('Y-m-d H:i', '2010-10-04 13:45', new DateTimeZone('UTC'))->getTimestamp() -- A unixtimestamp is always GMT + 'date5' => -189291360, // DateTime::createFromFormat('Y-m-d H:i', '1964-01-02 03:04', new DateTimeZone('UTC'))->getTimestamp(), + 'date6' => new DateTime('2010-10-04 13:45', new DateTimeZone('America/New_York')), + 'date7' => '2010-01-28T15:00:00+04:00', + 'timezone1' => new DateTimeZone('America/New_York'), +) +--EXPECT-- +October 4, 2010 13:45 +04/10/2010 +04/10/2010 19:45:00 +04/10/2010 19:45:00 +08:00 +04/10/2010 06:45:00 -05:00 +Europe/Paris +04/10/2010 13:45:00 + +October 4, 2010 13:45 +04/10/2010 +04/10/2010 19:45:00 +04/10/2010 07:45:00 +04/10/2010 13:45:00 + +October 4, 2010 13:45 +04/10/2010 + +October 4, 2010 15:45 +04/10/2010 + +January 2, 1964 04:04 +02/01/1964 + +04/10/2010 19:45:00 +02:00 +05/10/2010 01:45:00 +08:00 +04/10/2010 13:45:00 -04:00 +Europe/Paris +America/New_York + +January 28, 2010 12:00 +January 28, 2010 12:00 +January 28, 2010 19:00 +January 28, 2010 15:00 +January 28, 2010 15:00 + +January 28, 2010 15:00 +January 28, 2010 22:00 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format.test new file mode 100755 index 0000000..11a1ef4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format.test @@ -0,0 +1,14 @@ +--TEST-- +"date" filter +--TEMPLATE-- +{{ date1|date }} +{{ date1|date('d/m/Y') }} +--DATA-- +date_default_timezone_set('UTC'); +$twig->getExtension('core')->setDateFormat('Y-m-d', '%d days %h hours'); +return array( + 'date1' => mktime(13, 45, 0, 10, 4, 2010), +) +--EXPECT-- +2010-10-04 +04/10/2010 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test new file mode 100755 index 0000000..e6d3707 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test @@ -0,0 +1,16 @@ +--TEST-- +"date" filter (interval support as of PHP 5.3) +--CONDITION-- +version_compare(phpversion(), '5.3.0', '>=') +--TEMPLATE-- +{{ date2|date }} +{{ date2|date('%d days') }} +--DATA-- +date_default_timezone_set('UTC'); +$twig->getExtension('core')->setDateFormat('Y-m-d', '%d days %h hours'); +return array( + 'date2' => new DateInterval('P2D'), +) +--EXPECT-- +2 days 0 hours +2 days diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test new file mode 100755 index 0000000..4e18325 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test @@ -0,0 +1,37 @@ +--TEST-- +"date" filter +--CONDITION-- +version_compare(phpversion(), '5.5.0', '>=') +--TEMPLATE-- +{{ date1|date }} +{{ date1|date('d/m/Y') }} +{{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }} +{{ date1|date('d/m/Y H:i:s', timezone1) }} +{{ date1|date('d/m/Y H:i:s') }} +{{ date1|date_modify('+1 hour')|date('d/m/Y H:i:s') }} + +{{ date2|date('d/m/Y H:i:s P', 'Europe/Paris') }} +{{ date2|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }} +{{ date2|date('d/m/Y H:i:s P', false) }} +{{ date2|date('e', 'Europe/Paris') }} +{{ date2|date('e', false) }} +--DATA-- +date_default_timezone_set('Europe/Paris'); +return array( + 'date1' => new DateTimeImmutable('2010-10-04 13:45'), + 'date2' => new DateTimeImmutable('2010-10-04 13:45', new DateTimeZone('America/New_York')), + 'timezone1' => new DateTimeZone('America/New_York'), +) +--EXPECT-- +October 4, 2010 13:45 +04/10/2010 +04/10/2010 19:45:00 +04/10/2010 07:45:00 +04/10/2010 13:45:00 +04/10/2010 14:45:00 + +04/10/2010 19:45:00 +02:00 +05/10/2010 01:45:00 +08:00 +04/10/2010 13:45:00 -04:00 +Europe/Paris +America/New_York diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test new file mode 100755 index 0000000..0c8c6f1 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_interval.test @@ -0,0 +1,19 @@ +--TEST-- +"date" filter (interval support as of PHP 5.3) +--CONDITION-- +version_compare(phpversion(), '5.3.0', '>=') +--TEMPLATE-- +{{ date1|date }} +{{ date1|date('%d days %h hours') }} +{{ date1|date('%d days %h hours', timezone1) }} +--DATA-- +date_default_timezone_set('UTC'); +return array( + 'date1' => new DateInterval('P2D'), + // This should have no effect on DateInterval formatting + 'timezone1' => new DateTimeZone('America/New_York'), +) +--EXPECT-- +2 days +2 days 0 hours +2 days 0 hours diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_modify.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_modify.test new file mode 100755 index 0000000..53d3a69 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_modify.test @@ -0,0 +1,14 @@ +--TEST-- +"date_modify" filter +--TEMPLATE-- +{{ date1|date_modify('-1day')|date('Y-m-d H:i:s') }} +{{ date2|date_modify('-1day')|date('Y-m-d H:i:s') }} +--DATA-- +date_default_timezone_set('UTC'); +return array( + 'date1' => '2010-10-04 13:45', + 'date2' => new DateTime('2010-10-04 13:45'), +) +--EXPECT-- +2010-10-03 13:45:00 +2010-10-03 13:45:00 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_namedargs.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_namedargs.test new file mode 100755 index 0000000..4ecde8a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_namedargs.test @@ -0,0 +1,13 @@ +--TEST-- +"date" filter +--TEMPLATE-- +{{ date|date(format='d/m/Y H:i:s P', timezone='America/Chicago') }} +{{ date|date(timezone='America/Chicago', format='d/m/Y H:i:s P') }} +{{ date|date('d/m/Y H:i:s P', timezone='America/Chicago') }} +--DATA-- +date_default_timezone_set('UTC'); +return array('date' => mktime(13, 45, 0, 10, 4, 2010)) +--EXPECT-- +04/10/2010 08:45:00 -05:00 +04/10/2010 08:45:00 -05:00 +04/10/2010 08:45:00 -05:00 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test new file mode 100755 index 0000000..b8d1d66 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test @@ -0,0 +1,150 @@ +--TEST-- +"default" filter +--TEMPLATE-- +Variable: +{{ definedVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ zeroVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ emptyVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ nullVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ undefinedVar |default('default') is same as('default') ? 'ok' : 'ko' }} +Array access: +{{ nested.definedVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested['definedVar'] |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested.zeroVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested.emptyVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ nested.nullVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ nested.undefinedVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ nested['undefinedVar'] |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ undefinedVar.foo |default('default') is same as('default') ? 'ok' : 'ko' }} +Plain values: +{{ 'defined' |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ 0 |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ '' |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ null |default('default') is same as('default') ? 'ok' : 'ko' }} +Precedence: +{{ 'o' ~ nullVar |default('k') }} +{{ 'o' ~ nested.nullVar |default('k') }} +Object methods: +{{ object.foo |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.undefinedMethod |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ object.getFoo() |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.getFoo('a') |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.undefinedMethod() |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ object.undefinedMethod('a') |default('default') is same as('default') ? 'ok' : 'ko' }} +Deep nested: +{{ nested.undefinedVar.foo.bar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ nested.definedArray.0 |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested['definedArray'][0] |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.self.foo |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.self.undefinedMethod |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ object.undefinedMethod.self |default('default') is same as('default') ? 'ok' : 'ko' }} +--DATA-- +return array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'nested' => array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'definedArray' => array(0), + ), + 'object' => new TwigTestFoo(), +) +--CONFIG-- +return array('strict_variables' => false) +--EXPECT-- +Variable: +ok +ok +ok +ok +ok +Array access: +ok +ok +ok +ok +ok +ok +ok +ok +Plain values: +ok +ok +ok +ok +Precedence: +ok +ok +Object methods: +ok +ok +ok +ok +ok +ok +Deep nested: +ok +ok +ok +ok +ok +ok +--DATA-- +return array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'nested' => array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'emptyVar' => '', + 'nullVar' => null, + 'definedArray' => array(0), + ), + 'object' => new TwigTestFoo(), +) +--CONFIG-- +return array('strict_variables' => true) +--EXPECT-- +Variable: +ok +ok +ok +ok +ok +Array access: +ok +ok +ok +ok +ok +ok +ok +ok +Plain values: +ok +ok +ok +ok +Precedence: +ok +ok +Object methods: +ok +ok +ok +ok +ok +ok +Deep nested: +ok +ok +ok +ok +ok +ok diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/dynamic_filter.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/dynamic_filter.test new file mode 100755 index 0000000..93c5913 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/dynamic_filter.test @@ -0,0 +1,10 @@ +--TEST-- +dynamic filter +--TEMPLATE-- +{{ 'bar'|foo_path }} +{{ 'bar'|a_foo_b_bar }} +--DATA-- +return array() +--EXPECT-- +foo/bar +a/b/bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape.test new file mode 100755 index 0000000..a606c10 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape.test @@ -0,0 +1,8 @@ +--TEST-- +"escape" filter +--TEMPLATE-- +{{ "foo
    "|e }} +--DATA-- +return array() +--EXPECT-- +foo <br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_html_attr.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_html_attr.test new file mode 100755 index 0000000..009a245 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_html_attr.test @@ -0,0 +1,8 @@ +--TEST-- +"escape" filter does not escape with the html strategy when using the html_attr strategy +--TEMPLATE-- +{{ '
    '|escape('html_attr') }} +--DATA-- +return array() +--EXPECT-- +<br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_non_supported_charset.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_non_supported_charset.test new file mode 100755 index 0000000..bba26a0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/escape_non_supported_charset.test @@ -0,0 +1,8 @@ +--TEST-- +"escape" filter +--TEMPLATE-- +{{ "愛していますか?
    "|e }} +--DATA-- +return array() +--EXPECT-- +愛していますか? <br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test new file mode 100755 index 0000000..aa54645 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test @@ -0,0 +1,17 @@ +--TEST-- +"first" filter +--TEMPLATE-- +{{ [1, 2, 3, 4]|first }} +{{ {a: 1, b: 2, c: 3, d: 4}|first }} +{{ '1234'|first }} +{{ arr|first }} +{{ 'Ä€é'|first }} +{{ ''|first }} +--DATA-- +return array('arr' => new ArrayObject(array(1, 2, 3, 4))) +--EXPECT-- +1 +1 +1 +1 +Ä diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/force_escape.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/force_escape.test new file mode 100755 index 0000000..85a9b71 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/force_escape.test @@ -0,0 +1,18 @@ +--TEST-- +"escape" filter +--TEMPLATE-- +{% set foo %} + foo
    +{% endset %} + +{{ foo|e('html') -}} +{{ foo|e('js') }} +{% autoescape true %} + {{ foo }} +{% endautoescape %} +--DATA-- +return array() +--EXPECT-- + foo<br /> +\x20\x20\x20\x20foo\x3Cbr\x20\x2F\x3E\x0A + foo
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/format.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/format.test new file mode 100755 index 0000000..97221ff --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/format.test @@ -0,0 +1,8 @@ +--TEST-- +"format" filter +--TEMPLATE-- +{{ string|format(foo, 3) }} +--DATA-- +return array('string' => '%s/%d', 'foo' => 'bar') +--EXPECT-- +bar/3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/join.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/join.test new file mode 100755 index 0000000..b342c17 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/join.test @@ -0,0 +1,12 @@ +--TEST-- +"join" filter +--TEMPLATE-- +{{ ["foo", "bar"]|join(', ') }} +{{ foo|join(', ') }} +{{ bar|join(', ') }} +--DATA-- +return array('foo' => new TwigTestFoo(), 'bar' => new ArrayObject(array(3, 4))) +--EXPECT-- +foo, bar +1, 2 +3, 4 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/json_encode.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/json_encode.test new file mode 100755 index 0000000..1738d40 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/json_encode.test @@ -0,0 +1,12 @@ +--TEST-- +"json_encode" filter +--TEMPLATE-- +{{ "foo"|json_encode|raw }} +{{ foo|json_encode|raw }} +{{ [foo, "foo"]|json_encode|raw }} +--DATA-- +return array('foo' => new Twig_Markup('foo', 'UTF-8')) +--EXPECT-- +"foo" +"foo" +["foo","foo"] diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test new file mode 100755 index 0000000..1b8031e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test @@ -0,0 +1,17 @@ +--TEST-- +"last" filter +--TEMPLATE-- +{{ [1, 2, 3, 4]|last }} +{{ {a: 1, b: 2, c: 3, d: 4}|last }} +{{ '1234'|last }} +{{ arr|last }} +{{ 'Ä€é'|last }} +{{ ''|last }} +--DATA-- +return array('arr' => new ArrayObject(array(1, 2, 3, 4))) +--EXPECT-- +4 +4 +4 +4 +é diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length.test new file mode 100755 index 0000000..3347474 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length.test @@ -0,0 +1,14 @@ +--TEST-- +"length" filter +--TEMPLATE-- +{{ array|length }} +{{ string|length }} +{{ number|length }} +{{ markup|length }} +--DATA-- +return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000, 'markup' => new Twig_Markup('foo', 'UTF-8')) +--EXPECT-- +2 +3 +4 +3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length_utf8.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length_utf8.test new file mode 100755 index 0000000..5d5e243 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/length_utf8.test @@ -0,0 +1,12 @@ +--TEST-- +"length" filter +--CONDITION-- +function_exists('mb_get_info') +--TEMPLATE-- +{{ string|length }} +{{ markup|length }} +--DATA-- +return array('string' => 'été', 'markup' => new Twig_Markup('foo', 'UTF-8')) +--EXPECT-- +3 +3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test new file mode 100755 index 0000000..2bd3d4c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/merge.test @@ -0,0 +1,16 @@ +--TEST-- +"merge" filter +--TEMPLATE-- +{{ items|merge({'bar': 'foo'})|join }} +{{ items|merge({'bar': 'foo'})|keys|join }} +{{ {'bar': 'foo'}|merge(items)|join }} +{{ {'bar': 'foo'}|merge(items)|keys|join }} +{{ numerics|merge([4, 5, 6])|join }} +--DATA-- +return array('items' => array('foo' => 'bar'), 'numerics' => array(1, 2, 3)) +--EXPECT-- +barfoo +foobar +foobar +barfoo +123456 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/nl2br.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/nl2br.test new file mode 100755 index 0000000..6545a9b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/nl2br.test @@ -0,0 +1,14 @@ +--TEST-- +"nl2br" filter +--TEMPLATE-- +{{ "I like Twig.\nYou will like it too.\n\nEverybody like it!"|nl2br }} +{{ text|nl2br }} +--DATA-- +return array('text' => "If you have some HTML\nit will be escaped.") +--EXPECT-- +I like Twig.
    +You will like it too.
    +
    +Everybody like it! +If you have some <strong>HTML</strong>
    +it will be escaped. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format.test new file mode 100755 index 0000000..639a865 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format.test @@ -0,0 +1,18 @@ +--TEST-- +"number_format" filter +--TEMPLATE-- +{{ 20|number_format }} +{{ 20.25|number_format }} +{{ 20.25|number_format(2) }} +{{ 20.25|number_format(2, ',') }} +{{ 1020.25|number_format(2, ',') }} +{{ 1020.25|number_format(2, ',', '.') }} +--DATA-- +return array(); +--EXPECT-- +20 +20 +20.25 +20,25 +1,020,25 +1.020,25 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format_default.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format_default.test new file mode 100755 index 0000000..c6903cc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/number_format_default.test @@ -0,0 +1,21 @@ +--TEST-- +"number_format" filter with defaults. +--TEMPLATE-- +{{ 20|number_format }} +{{ 20.25|number_format }} +{{ 20.25|number_format(1) }} +{{ 20.25|number_format(2, ',') }} +{{ 1020.25|number_format }} +{{ 1020.25|number_format(2, ',') }} +{{ 1020.25|number_format(2, ',', '.') }} +--DATA-- +$twig->getExtension('core')->setNumberFormat(2, '!', '='); +return array(); +--EXPECT-- +20!00 +20!25 +20!3 +20,25 +1=020!25 +1=020,25 +1.020,25 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test new file mode 100755 index 0000000..4021660 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/replace.test @@ -0,0 +1,8 @@ +--TEST-- +"replace" filter +--TEMPLATE-- +{{ "I like %this% and %that%."|replace({'%this%': "foo", '%that%': "bar"}) }} +--DATA-- +return array() +--EXPECT-- +I like foo and bar. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reverse.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reverse.test new file mode 100755 index 0000000..7948ac4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/reverse.test @@ -0,0 +1,18 @@ +--TEST-- +"reverse" filter +--TEMPLATE-- +{{ [1, 2, 3, 4]|reverse|join('') }} +{{ '1234évènement'|reverse }} +{{ arr|reverse|join('') }} +{{ {'a': 'c', 'b': 'a'}|reverse()|join(',') }} +{{ {'a': 'c', 'b': 'a'}|reverse(preserveKeys=true)|join(glue=',') }} +{{ {'a': 'c', 'b': 'a'}|reverse(preserve_keys=true)|join(glue=',') }} +--DATA-- +return array('arr' => new ArrayObject(array(1, 2, 3, 4))) +--EXPECT-- +4321 +tnemenèvé4321 +4321 +a,c +a,c +a,c diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/round.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/round.test new file mode 100755 index 0000000..57806b6 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/round.test @@ -0,0 +1,22 @@ +--TEST-- +"round" filter +--TEMPLATE-- +{{ 2.7|round }} +{{ 2.1|round }} +{{ 2.1234|round(3, 'floor') }} +{{ 2.1|round(0, 'ceil') }} + +{{ 21.3|round(-1)}} +{{ 21.3|round(-1, 'ceil')}} +{{ 21.3|round(-1, 'floor')}} +--DATA-- +return array() +--EXPECT-- +3 +2 +2.123 +3 + +20 +30 +20 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test new file mode 100755 index 0000000..b49b89f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test @@ -0,0 +1,54 @@ +--TEST-- +"slice" filter +--TEMPLATE-- +{{ [1, 2, 3, 4][1:2]|join('') }} +{{ {a: 1, b: 2, c: 3, d: 4}[1:2]|join('') }} +{{ [1, 2, 3, 4][start:length]|join('') }} +{{ [1, 2, 3, 4]|slice(1, 2)|join('') }} +{{ [1, 2, 3, 4]|slice(1, 2)|keys|join('') }} +{{ [1, 2, 3, 4]|slice(1, 2, true)|keys|join('') }} +{{ {a: 1, b: 2, c: 3, d: 4}|slice(1, 2)|join('') }} +{{ {a: 1, b: 2, c: 3, d: 4}|slice(1, 2)|keys|join('') }} +{{ '1234'|slice(1, 2) }} +{{ '1234'[1:2] }} +{{ arr|slice(1, 2)|join('') }} +{{ arr[1:2]|join('') }} +{{ arr[4:1]|join('') }} +{{ arr[3:2]|join('') }} + +{{ [1, 2, 3, 4]|slice(1)|join('') }} +{{ [1, 2, 3, 4][1:]|join('') }} +{{ '1234'|slice(1) }} +{{ '1234'[1:] }} +{{ '1234'[:1] }} + +{{ arr|slice(3)|join('') }} +{{ arr[2:]|join('') }} +{{ xml|slice(1)|join('')}} +--DATA-- +return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4)), 'xml' => new SimpleXMLElement('12')) +--EXPECT-- +23 +23 +23 +23 +01 +12 +23 +bc +23 +23 +23 +23 + +4 + +234 +234 +234 +234 +1 + +4 +34 +2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test new file mode 100755 index 0000000..21d575f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/sort.test @@ -0,0 +1,10 @@ +--TEST-- +"sort" filter +--TEMPLATE-- +{{ array1|sort|join }} +{{ array2|sort|join }} +--DATA-- +return array('array1' => array(4, 1), 'array2' => array('foo', 'bar')) +--EXPECT-- +14 +barfoo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/special_chars.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/special_chars.test new file mode 100755 index 0000000..dbaf7dc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/special_chars.test @@ -0,0 +1,8 @@ +--TEST-- +"§" custom filter +--TEMPLATE-- +{{ 'foo'|§ }} +--DATA-- +return array() +--EXPECT-- +§foo§ diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test new file mode 100755 index 0000000..a093ed7 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test @@ -0,0 +1,20 @@ +--TEST-- +"split" filter +--TEMPLATE-- +{{ "one,two,three,four,five"|split(',')|join('-') }} +{{ foo|split(',')|join('-') }} +{{ foo|split(',', 3)|join('-') }} +{{ baz|split('')|join('-') }} +{{ baz|split('', 1)|join('-') }} +{{ baz|split('', 2)|join('-') }} +{{ foo|split(',', -2)|join('-') }} +--DATA-- +return array('foo' => "one,two,three,four,five", 'baz' => '12345',) +--EXPECT-- +one-two-three-four-five +one-two-three-four-five +one-two-three,four,five +1-2-3-4-5 +1-2-3-4-5 +12-34-5 +one-two-three \ No newline at end of file diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test new file mode 100755 index 0000000..305e162 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test @@ -0,0 +1,24 @@ +--TEST-- +"split" filter +--CONDITION-- +function_exists('mb_get_info') +--TEMPLATE-- +{{ "é"|split('', 10)|join('-') }} +{{ foo|split(',')|join('-') }} +{{ foo|split(',', 1)|join('-') }} +{{ foo|split(',', 2)|join('-') }} +{{ foo|split(',', 3)|join('-') }} +{{ baz|split('')|join('-') }} +{{ baz|split('', 1)|join('-') }} +{{ baz|split('', 2)|join('-') }} +--DATA-- +return array('foo' => 'Ä,é,Äほ', 'baz' => 'éÄßごa',) +--EXPECT-- +é +Ä-é-Äほ +Ä,é,Äほ +Ä-é,Äほ +Ä-é-Äほ +é-Ä-ß-ご-a +é-Ä-ß-ご-a +éÄ-ßご-a \ No newline at end of file diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/trim.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/trim.test new file mode 100755 index 0000000..3192062 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/trim.test @@ -0,0 +1,12 @@ +--TEST-- +"trim" filter +--TEMPLATE-- +{{ " I like Twig. "|trim }} +{{ text|trim }} +{{ " foo/"|trim("/") }} +--DATA-- +return array('text' => " If you have some HTML it will be escaped. ") +--EXPECT-- +I like Twig. +If you have some <strong>HTML</strong> it will be escaped. + foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test new file mode 100755 index 0000000..8726159 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test @@ -0,0 +1,16 @@ +--TEST-- +"url_encode" filter +--CONDITION-- +defined('PHP_QUERY_RFC3986') +--TEMPLATE-- +{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }} +{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }} +{{ {}|url_encode|default("default") }} +{{ 'spéßi%le%c0d@dspa ce'|url_encode }} +--DATA-- +return array() +--EXPECT-- +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +default +sp%C3%A9%C3%9Fi%25le%25c0d%40dspa%20ce diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test new file mode 100755 index 0000000..11800e9 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test @@ -0,0 +1,16 @@ +--TEST-- +"url_encode" filter for PHP < 5.4 and HHVM +--CONDITION-- +defined('PHP_QUERY_RFC3986') +--TEMPLATE-- +{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }} +{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }} +{{ {}|url_encode|default("default") }} +{{ 'spéßi%le%c0d@dspa ce'|url_encode }} +--DATA-- +return array() +--EXPECT-- +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +default +sp%C3%A9%C3%9Fi%25le%25c0d%40dspa%20ce diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test new file mode 100755 index 0000000..71b2038 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test @@ -0,0 +1,18 @@ +--TEST-- +"attribute" function +--TEMPLATE-- +{{ attribute(obj, method) }} +{{ attribute(array, item) }} +{{ attribute(obj, "bar", ["a", "b"]) }} +{{ attribute(obj, "bar", arguments) }} +{{ attribute(obj, method) is defined ? 'ok' : 'ko' }} +{{ attribute(obj, nonmethod) is defined ? 'ok' : 'ko' }} +--DATA-- +return array('obj' => new TwigTestFoo(), 'method' => 'foo', 'array' => array('foo' => 'bar'), 'item' => 'foo', 'nonmethod' => 'xxx', 'arguments' => array('a', 'b')) +--EXPECT-- +foo +bar +bar_a-b +bar_a-b +ok +ko diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/block.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/block.test new file mode 100755 index 0000000..8e54059 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/block.test @@ -0,0 +1,12 @@ +--TEST-- +"block" function +--TEMPLATE-- +{% extends 'base.twig' %} +{% block bar %}BAR{% endblock %} +--TEMPLATE(base.twig)-- +{% block foo %}{{ block('bar') }}{% endblock %} +{% block bar %}BAR_BASE{% endblock %} +--DATA-- +return array() +--EXPECT-- +BARBAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/constant.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/constant.test new file mode 100755 index 0000000..6312879 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/constant.test @@ -0,0 +1,10 @@ +--TEST-- +"constant" function +--TEMPLATE-- +{{ constant('DATE_W3C') == expect ? 'true' : 'false' }} +{{ constant('ARRAY_AS_PROPS', object) }} +--DATA-- +return array('expect' => DATE_W3C, 'object' => new ArrayObject(array('hi'))); +--EXPECT-- +true +2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/cycle.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/cycle.test new file mode 100755 index 0000000..522a63b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/cycle.test @@ -0,0 +1,16 @@ +--TEST-- +"cycle" function +--TEMPLATE-- +{% for i in 0..6 %} +{{ cycle(array1, i) }}-{{ cycle(array2, i) }} +{% endfor %} +--DATA-- +return array('array1' => array('odd', 'even'), 'array2' => array('apple', 'orange', 'citrus')) +--EXPECT-- +odd-apple +even-orange +odd-citrus +even-apple +odd-orange +even-citrus +odd-apple diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date.test new file mode 100755 index 0000000..8be9c0c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date.test @@ -0,0 +1,25 @@ +--TEST-- +"date" function +--TEMPLATE-- +{{ date() == date('now') ? 'OK' : 'KO' }} +{{ date(date1) == date('2010-10-04 13:45') ? 'OK' : 'KO' }} +{{ date(date2) == date('2010-10-04 13:45') ? 'OK' : 'KO' }} +{{ date(date3) == date('2010-10-04 13:45') ? 'OK' : 'KO' }} +{{ date(date4) == date('2010-10-04 13:45') ? 'OK' : 'KO' }} +{{ date(date5) == date('1964-01-02 03:04') ? 'OK' : 'KO' }} +--DATA-- +date_default_timezone_set('UTC'); +return array( + 'date1' => mktime(13, 45, 0, 10, 4, 2010), + 'date2' => new DateTime('2010-10-04 13:45'), + 'date3' => '2010-10-04 13:45', + 'date4' => 1286199900, // DateTime::createFromFormat('Y-m-d H:i', '2010-10-04 13:45', new DateTimeZone('UTC'))->getTimestamp() -- A unixtimestamp is always GMT + 'date5' => -189291360, // DateTime::createFromFormat('Y-m-d H:i', '1964-01-02 03:04', new DateTimeZone('UTC'))->getTimestamp(), +) +--EXPECT-- +OK +OK +OK +OK +OK +OK diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date_namedargs.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date_namedargs.test new file mode 100755 index 0000000..b9dd9e3 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/date_namedargs.test @@ -0,0 +1,11 @@ +--TEST-- +"date" function +--TEMPLATE-- +{{ date(date, "America/New_York")|date('d/m/Y H:i:s P', false) }} +{{ date(timezone="America/New_York", date=date)|date('d/m/Y H:i:s P', false) }} +--DATA-- +date_default_timezone_set('UTC'); +return array('date' => mktime(13, 45, 0, 10, 4, 2010)) +--EXPECT-- +04/10/2010 09:45:00 -04:00 +04/10/2010 09:45:00 -04:00 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump.test new file mode 100755 index 0000000..f407237 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump.test @@ -0,0 +1,16 @@ +--TEST-- +"dump" function +--CONDITION-- +!extension_loaded('xdebug') +--TEMPLATE-- +{{ dump('foo') }} +{{ dump('foo', 'bar') }} +--DATA-- +return array('foo' => 'foo', 'bar' => 'bar') +--CONFIG-- +return array('debug' => true, 'autoescape' => false); +--EXPECT-- +string(3) "foo" + +string(3) "foo" +string(3) "bar" diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump_array.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump_array.test new file mode 100755 index 0000000..889b7a9 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dump_array.test @@ -0,0 +1,19 @@ +--TEST-- +"dump" function, xdebug is not loaded or xdebug <2.2-dev is loaded +--CONDITION-- +!extension_loaded('xdebug') || (($r = new ReflectionExtension('xdebug')) && version_compare($r->getVersion(), '2.2-dev', '<')) +--TEMPLATE-- +{{ dump() }} +--DATA-- +return array('foo' => 'foo', 'bar' => 'bar') +--CONFIG-- +return array('debug' => true, 'autoescape' => false); +--EXPECT-- +array(3) { + ["foo"]=> + string(3) "foo" + ["bar"]=> + string(3) "bar" + ["global"]=> + string(6) "global" +} diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dynamic_function.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dynamic_function.test new file mode 100755 index 0000000..913fbc9 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/dynamic_function.test @@ -0,0 +1,10 @@ +--TEST-- +dynamic function +--TEMPLATE-- +{{ foo_path('bar') }} +{{ a_foo_b_bar('bar') }} +--DATA-- +return array() +--EXPECT-- +foo/bar +a/b/bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/assignment.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/assignment.test new file mode 100755 index 0000000..b7653b4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/assignment.test @@ -0,0 +1,13 @@ +--TEST-- +"include" function +--TEMPLATE-- +{% set tmp = include("foo.twig") %} + +FOO{{ tmp }}BAR +--TEMPLATE(foo.twig)-- +FOOBAR +--DATA-- +return array() +--EXPECT-- +FOO +FOOBARBAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/autoescaping.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/autoescaping.test new file mode 100755 index 0000000..56f8f3b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/autoescaping.test @@ -0,0 +1,10 @@ +--TEST-- +"include" function is safe for auto-escaping +--TEMPLATE-- +{{ include("foo.twig") }} +--TEMPLATE(foo.twig)-- +

    Test

    +--DATA-- +return array() +--EXPECT-- +

    Test

    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/basic.test new file mode 100755 index 0000000..a434182 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/basic.test @@ -0,0 +1,17 @@ +--TEST-- +"include" function +--TEMPLATE-- +FOO +{{ include("foo.twig") }} + +BAR +--TEMPLATE(foo.twig)-- +FOOBAR +--DATA-- +return array() +--EXPECT-- +FOO + +FOOBAR + +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/expression.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/expression.test new file mode 100755 index 0000000..aba30ce --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/expression.test @@ -0,0 +1,17 @@ +--TEST-- +"include" function allows expressions for the template to include +--TEMPLATE-- +FOO +{{ include(foo) }} + +BAR +--TEMPLATE(foo.twig)-- +FOOBAR +--DATA-- +return array('foo' => 'foo.twig') +--EXPECT-- +FOO + +FOOBAR + +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing.test new file mode 100755 index 0000000..43a2ccc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/ignore_missing.test @@ -0,0 +1,10 @@ +--TEST-- +"include" function +--TEMPLATE-- +{{ include(["foo.twig", "bar.twig"], ignore_missing = true) }} +{{ include("foo.twig", ignore_missing = true) }} +{{ include("foo.twig", ignore_missing = true, variables = {}) }} +{{ include("foo.twig", ignore_missing = true, variables = {}, with_context = true) }} +--DATA-- +return array() +--EXPECT-- diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing.test new file mode 100755 index 0000000..4d2f6cf --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing.test @@ -0,0 +1,8 @@ +--TEST-- +"include" function +--TEMPLATE-- +{{ include("foo.twig") }} +--DATA-- +return array(); +--EXCEPTION-- +Twig_Error_Loader: Template "foo.twig" is not defined in "index.twig" at line 2. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing_nested.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing_nested.test new file mode 100755 index 0000000..78fddc7 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/missing_nested.test @@ -0,0 +1,16 @@ +--TEST-- +"include" function +--TEMPLATE-- +{% extends "base.twig" %} + +{% block content %} + {{ parent() }} +{% endblock %} +--TEMPLATE(base.twig)-- +{% block content %} + {{ include("foo.twig") }} +{% endblock %} +--DATA-- +return array(); +--EXCEPTION-- +Twig_Error_Loader: Template "foo.twig" is not defined in "base.twig" at line 3. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test new file mode 100755 index 0000000..7b9ccac --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test @@ -0,0 +1,13 @@ +--TEST-- +"include" tag sandboxed +--TEMPLATE-- +{{ include("foo.twig", sandboxed = true) }} +--TEMPLATE(foo.twig)-- + + +{{ foo|e }} +{{ foo|e }} +--DATA-- +return array() +--EXCEPTION-- +Twig_Sandbox_SecurityNotAllowedFilterError: Filter "e" is not allowed in "foo.twig" at line 4. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/template_instance.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/template_instance.test new file mode 100755 index 0000000..18d405a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/template_instance.test @@ -0,0 +1,10 @@ +--TEST-- +"include" function accepts Twig_Template instance +--TEMPLATE-- +{{ include(foo) }} FOO +--TEMPLATE(foo.twig)-- +BAR +--DATA-- +return array('foo' => $twig->loadTemplate('foo.twig')) +--EXPECT-- +BAR FOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/templates_as_array.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/templates_as_array.test new file mode 100755 index 0000000..1a81006 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/templates_as_array.test @@ -0,0 +1,12 @@ +--TEST-- +"include" function +--TEMPLATE-- +{{ include(["foo.twig", "bar.twig"]) }} +{{- include(["bar.twig", "foo.twig"]) }} +--TEMPLATE(foo.twig)-- +foo +--DATA-- +return array() +--EXPECT-- +foo +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_context.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_context.test new file mode 100755 index 0000000..35611fb --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_context.test @@ -0,0 +1,16 @@ +--TEST-- +"include" function accept variables and with_context +--TEMPLATE-- +{{ include("foo.twig") }} +{{- include("foo.twig", with_context = false) }} +{{- include("foo.twig", {'foo1': 'bar'}) }} +{{- include("foo.twig", {'foo1': 'bar'}, with_context = false) }} +--TEMPLATE(foo.twig)-- +{% for k, v in _context %}{{ k }},{% endfor %} +--DATA-- +return array('foo' => 'bar') +--EXPECT-- +foo,global,_parent, +global,_parent, +foo,global,foo1,_parent, +foo1,global,_parent, diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_variables.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_variables.test new file mode 100755 index 0000000..b2ace94 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/with_variables.test @@ -0,0 +1,12 @@ +--TEST-- +"include" function accept variables +--TEMPLATE-- +{{ include("foo.twig", {'foo': 'bar'}) }} +{{- include("foo.twig", vars) }} +--TEMPLATE(foo.twig)-- +{{ foo }} +--DATA-- +return array('vars' => array('foo' => 'bar')) +--EXPECT-- +bar +bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/max.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/max.test new file mode 100755 index 0000000..e6c94af --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/max.test @@ -0,0 +1,12 @@ +--TEST-- +"max" function +--TEMPLATE-- +{{ max([2, 1, 3, 5, 4]) }} +{{ max(2, 1, 3, 5, 4) }} +{{ max({2:"two", 1:"one", 3:"three", 5:"five", 4:"for"}) }} +--DATA-- +return array() +--EXPECT-- +5 +5 +two diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/min.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/min.test new file mode 100755 index 0000000..660471c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/min.test @@ -0,0 +1,12 @@ +--TEST-- +"min" function +--TEMPLATE-- +{{ min(2, 1, 3, 5, 4) }} +{{ min([2, 1, 3, 5, 4]) }} +{{ min({2:"two", 1:"one", 3:"three", 5:"five", 4:"for"}) }} +--DATA-- +return array() +--EXPECT-- +1 +1 +five diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/range.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/range.test new file mode 100755 index 0000000..e0377c8 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/range.test @@ -0,0 +1,8 @@ +--TEST-- +"range" function +--TEMPLATE-- +{{ range(low=0+1, high=10+0, step=2)|join(',') }} +--DATA-- +return array() +--EXPECT-- +1,3,5,7,9 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test new file mode 100755 index 0000000..f39712d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test @@ -0,0 +1,21 @@ +--TEST-- +"block" function recursively called in a parent template +--TEMPLATE-- +{% extends "ordered_menu.twig" %} +{% block label %}"{{ parent() }}"{% endblock %} +{% block list %}{% set class = 'b' %}{{ parent() }}{% endblock %} +--TEMPLATE(ordered_menu.twig)-- +{% extends "menu.twig" %} +{% block list %}{% set class = class|default('a') %}
      {{ block('children') }}
    {% endblock %} +--TEMPLATE(menu.twig)-- +{% extends "base.twig" %} +{% block list %}
      {{ block('children') }}
    {% endblock %} +{% block children %}{% set currentItem = item %}{% for item in currentItem %}{{ block('item') }}{% endfor %}{% set item = currentItem %}{% endblock %} +{% block item %}
  • {% if item is not iterable %}{{ block('label') }}{% else %}{{ block('list') }}{% endif %}
  • {% endblock %} +{% block label %}{{ item }}{{ block('unknown') }}{% endblock %} +--TEMPLATE(base.twig)-- +{{ block('list') }} +--DATA-- +return array('item' => array('1', '2', array('3.1', array('3.2.1', '3.2.2'), '3.4'))) +--EXPECT-- +
    1. "1"
    2. "2"
      1. "3.1"
        1. "3.2.1"
        2. "3.2.2"
      2. "3.4"
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/source.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/source.test new file mode 100755 index 0000000..0e094c3 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/source.test @@ -0,0 +1,17 @@ +--TEST-- +"source" function +--TEMPLATE-- +FOO +{{ source("foo.twig") }} + +BAR +--TEMPLATE(foo.twig)-- +{{ foo }}
    +--DATA-- +return array() +--EXPECT-- +FOO + +{{ foo }}
    + +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/special_chars.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/special_chars.test new file mode 100755 index 0000000..30c3df5 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/special_chars.test @@ -0,0 +1,8 @@ +--TEST-- +"§" custom function +--TEMPLATE-- +{{ §('foo') }} +--DATA-- +return array() +--EXPECT-- +§foo§ diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string.test new file mode 100755 index 0000000..3d3b958 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/template_from_string.test @@ -0,0 +1,15 @@ +--TEST-- +"template_from_string" function +--TEMPLATE-- +{% include template_from_string(template) %} + +{% include template_from_string("Hello {{ name }}") %} +{% include template_from_string('{% extends "parent.twig" %}{% block content %}Hello {{ name }}{% endblock %}') %} +--TEMPLATE(parent.twig)-- +{% block content %}{% endblock %} +--DATA-- +return array('name' => 'Fabien', 'template' => "Hello {{ name }}") +--EXPECT-- +Hello Fabien +Hello Fabien +Hello Fabien diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/default_values.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/default_values.test new file mode 100755 index 0000000..4ccff7b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/default_values.test @@ -0,0 +1,16 @@ +--TEST-- +macro +--TEMPLATE-- +{% from _self import test %} + +{% macro test(a, b = 'bar') -%} +{{ a }}{{ b }} +{%- endmacro %} + +{{ test('foo') }} +{{ test('bar', 'foo') }} +--DATA-- +return array(); +--EXPECT-- +foobar +barfoo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/nested_calls.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/nested_calls.test new file mode 100755 index 0000000..cd25428 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/nested_calls.test @@ -0,0 +1,18 @@ +--TEST-- +macro +--TEMPLATE-- +{% import _self as macros %} + +{% macro foo(data) %} + {{ data }} +{% endmacro %} + +{% macro bar() %} +
    +{% endmacro %} + +{{ macros.foo(macros.bar()) }} +--DATA-- +return array(); +--EXPECT-- +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/reserved_variables.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/reserved_variables.test new file mode 100755 index 0000000..cbfb921 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/reserved_variables.test @@ -0,0 +1,14 @@ +--TEST-- +macro +--TEMPLATE-- +{% from _self import test %} + +{% macro test(this) -%} + {{ this }} +{%- endmacro %} + +{{ test(this) }} +--DATA-- +return array('this' => 'foo'); +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/simple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/simple.test new file mode 100755 index 0000000..6a366cd --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/simple.test @@ -0,0 +1,22 @@ +--TEST-- +macro +--TEMPLATE-- +{% import _self as test %} +{% from _self import test %} + +{% macro test(a, b) -%} + {{ a|default('a') }}
    + {{- b|default('b') }}
    +{%- endmacro %} + +{{ test.test() }} +{{ test() }} +{{ test.test(1, "c") }} +{{ test(1, "c") }} +--DATA-- +return array(); +--EXPECT-- +a
    b
    +a
    b
    +1
    c
    +1
    c
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/with_filters.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/with_filters.test new file mode 100755 index 0000000..685626f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/macros/with_filters.test @@ -0,0 +1,14 @@ +--TEST-- +macro with a filter +--TEMPLATE-- +{% import _self as test %} + +{% macro test() %} + {% filter escape %}foo
    {% endfilter %} +{% endmacro %} + +{{ test.test() }} +--DATA-- +return array(); +--EXPECT-- +foo<br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test new file mode 100755 index 0000000..df48578 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test @@ -0,0 +1,15 @@ +--TEST-- +Exception with bad line number +--TEMPLATE-- +{% block content %} + {{ foo }} + {{ include("foo") }} +{% endblock %} +index +--TEMPLATE(foo)-- +foo +{{ foo.bar }} +--DATA-- +return array('foo' => 'foo'); +--EXCEPTION-- +Twig_Error_Runtime: Impossible to access an attribute ("bar") on a string variable ("foo") in "foo" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/empty_token.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/empty_token.test new file mode 100755 index 0000000..65f6cd2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/empty_token.test @@ -0,0 +1,8 @@ +--TEST-- +Twig outputs 0 nodes correctly +--TEMPLATE-- +{{ foo }}0{{ foo }} +--DATA-- +return array('foo' => 'foo') +--EXPECT-- +foo0foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/issue_1143.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/issue_1143.test new file mode 100755 index 0000000..ff7c8bb --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/issue_1143.test @@ -0,0 +1,23 @@ +--TEST-- +error in twig extension +--TEMPLATE-- +{{ object.region is not null ? object.regionChoices[object.region] }} +--DATA-- +class House +{ + const REGION_S = 1; + const REGION_P = 2; + + public static $regionChoices = array(self::REGION_S => 'house.region.s', self::REGION_P => 'house.region.p'); + + public function getRegionChoices() + { + return self::$regionChoices; + } +} + +$object = new House(); +$object->region = 1; +return array('object' => $object) +--EXPECT-- +house.region.s diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test new file mode 100755 index 0000000..269a305 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test @@ -0,0 +1,10 @@ +--TEST-- +Twig allows multi-word tests without a custom node class +--TEMPLATE-- +{{ 'foo' is multi word ? 'yes' : 'no' }} +{{ 'foo bar' is multi word ? 'yes' : 'no' }} +--DATA-- +return array() +--EXPECT-- +no +yes diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test new file mode 100755 index 0000000..60c3c51 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/simple_xml_element.test @@ -0,0 +1,19 @@ +--TEST-- +Twig is able to deal with SimpleXMLElement instances as variables +--CONDITION-- +version_compare(phpversion(), '5.3.0', '>=') +--TEMPLATE-- +Hello '{{ images.image.0.group }}'! +{{ images.image.0.group.attributes.myattr }} +{{ images.children().image.count() }} +{% for image in images %} + - {{ image.group }} +{% endfor %} +--DATA-- +return array('images' => new SimpleXMLElement('foobar')) +--EXPECT-- +Hello 'foo'! +example +2 + - foo + - bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test new file mode 100755 index 0000000..e18e110 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test @@ -0,0 +1,8 @@ +--TEST-- +Twig does not confuse strings with integers in getAttribute() +--TEMPLATE-- +{{ hash['2e2'] }} +--DATA-- +return array('hash' => array('2e2' => 'works')) +--EXPECT-- +works diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test new file mode 100755 index 0000000..2f6a3e1 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/basic.test @@ -0,0 +1,26 @@ +--TEST-- +"autoescape" tag applies escaping on its children +--TEMPLATE-- +{% autoescape %} +{{ var }}
    +{% endautoescape %} +{% autoescape 'html' %} +{{ var }}
    +{% endautoescape %} +{% autoescape false %} +{{ var }}
    +{% endautoescape %} +{% autoescape true %} +{{ var }}
    +{% endautoescape %} +{% autoescape false %} +{{ var }}
    +{% endautoescape %} +--DATA-- +return array('var' => '
    ') +--EXPECT-- +<br />
    +<br />
    +

    +<br />
    +

    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test new file mode 100755 index 0000000..05ab83c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test @@ -0,0 +1,12 @@ +--TEST-- +"autoescape" tag applies escaping on embedded blocks +--TEMPLATE-- +{% autoescape 'html' %} + {% block foo %} + {{ var }} + {% endblock %} +{% endautoescape %} +--DATA-- +return array('var' => '
    ') +--EXPECT-- +<br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test new file mode 100755 index 0000000..9c09724 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test @@ -0,0 +1,10 @@ +--TEST-- +"autoescape" tag does not double-escape +--TEMPLATE-- +{% autoescape 'html' %} +{{ var|escape }} +{% endautoescape %} +--DATA-- +return array('var' => '
    ') +--EXPECT-- +<br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/functions.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/functions.test new file mode 100755 index 0000000..ce7ea78 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/functions.test @@ -0,0 +1,83 @@ +--TEST-- +"autoescape" tag applies escaping after calling functions +--TEMPLATE-- + +autoescape false +{% autoescape false %} + +safe_br +{{ safe_br() }} + +unsafe_br +{{ unsafe_br() }} + +{% endautoescape %} + +autoescape 'html' +{% autoescape 'html' %} + +safe_br +{{ safe_br() }} + +unsafe_br +{{ unsafe_br() }} + +unsafe_br()|raw +{{ (unsafe_br())|raw }} + +safe_br()|escape +{{ (safe_br())|escape }} + +safe_br()|raw +{{ (safe_br())|raw }} + +unsafe_br()|escape +{{ (unsafe_br())|escape }} + +{% endautoescape %} + +autoescape js +{% autoescape 'js' %} + +safe_br +{{ safe_br() }} + +{% endautoescape %} +--DATA-- +return array() +--EXPECT-- + +autoescape false + +safe_br +
    + +unsafe_br +
    + + +autoescape 'html' + +safe_br +
    + +unsafe_br +<br /> + +unsafe_br()|raw +
    + +safe_br()|escape +<br /> + +safe_br()|raw +
    + +unsafe_br()|escape +<br /> + + +autoescape js + +safe_br +\x3Cbr\x20\x2F\x3E diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/literal.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/literal.test new file mode 100755 index 0000000..e389d4d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/literal.test @@ -0,0 +1,45 @@ +--TEST-- +"autoescape" tag does not apply escaping on literals +--TEMPLATE-- +{% autoescape 'html' %} + +1. Simple literal +{{ "
    " }} + +2. Conditional expression with only literals +{{ true ? "
    " : "
    " }} + +3. Conditional expression with a variable +{{ true ? "
    " : someVar }} + +4. Nested conditionals with only literals +{{ true ? (true ? "
    " : "
    ") : "\n" }} + +5. Nested conditionals with a variable +{{ true ? (true ? "
    " : someVar) : "\n" }} + +6. Nested conditionals with a variable marked safe +{{ true ? (true ? "
    " : someVar|raw) : "\n" }} + +{% endautoescape %} +--DATA-- +return array() +--EXPECT-- + +1. Simple literal +
    + +2. Conditional expression with only literals +
    + +3. Conditional expression with a variable +<br /> + +4. Nested conditionals with only literals +
    + +5. Nested conditionals with a variable +<br /> + +6. Nested conditionals with a variable marked safe +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/nested.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/nested.test new file mode 100755 index 0000000..798e6fe --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/nested.test @@ -0,0 +1,26 @@ +--TEST-- +"autoescape" tags can be nested at will +--TEMPLATE-- +{{ var }} +{% autoescape 'html' %} + {{ var }} + {% autoescape false %} + {{ var }} + {% autoescape 'html' %} + {{ var }} + {% endautoescape %} + {{ var }} + {% endautoescape %} + {{ var }} +{% endautoescape %} +{{ var }} +--DATA-- +return array('var' => '
    ') +--EXPECT-- +<br /> + <br /> +
    + <br /> +
    + <br /> +<br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/objects.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/objects.test new file mode 100755 index 0000000..e896aa4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/objects.test @@ -0,0 +1,26 @@ +--TEST-- +"autoescape" tag applies escaping to object method calls +--TEMPLATE-- +{% autoescape 'html' %} +{{ user.name }} +{{ user.name|lower }} +{{ user }} +{% endautoescape %} +--DATA-- +class UserForAutoEscapeTest +{ + public function getName() + { + return 'Fabien
    '; + } + + public function __toString() + { + return 'Fabien
    '; + } +} +return array('user' => new UserForAutoEscapeTest()) +--EXPECT-- +Fabien<br /> +fabien<br /> +Fabien<br /> diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/raw.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/raw.test new file mode 100755 index 0000000..9f1cedd --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/raw.test @@ -0,0 +1,10 @@ +--TEST-- +"autoescape" tag does not escape when raw is used as a filter +--TEMPLATE-- +{% autoescape 'html' %} +{{ var|raw }} +{% endautoescape %} +--DATA-- +return array('var' => '
    ') +--EXPECT-- +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test new file mode 100755 index 0000000..cf8ccee --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test @@ -0,0 +1,17 @@ +--TEST-- +"autoescape" tag accepts an escaping strategy +--TEMPLATE-- +{% autoescape true js %}{{ var }}{% endautoescape %} + +{% autoescape true html %}{{ var }}{% endautoescape %} + +{% autoescape 'js' %}{{ var }}{% endautoescape %} + +{% autoescape 'html' %}{{ var }}{% endautoescape %} +--DATA-- +return array('var' => '
    "') +--EXPECT-- +\x3Cbr\x20\x2F\x3E\x22 +<br />" +\x3Cbr\x20\x2F\x3E\x22 +<br />" diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/type.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/type.test new file mode 100755 index 0000000..4f41520 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/type.test @@ -0,0 +1,69 @@ +--TEST-- +escape types +--TEMPLATE-- + +1. autoescape 'html' |escape('js') + +{% autoescape 'html' %} + +{% endautoescape %} + +2. autoescape 'html' |escape('js') + +{% autoescape 'html' %} + +{% endautoescape %} + +3. autoescape 'js' |escape('js') + +{% autoescape 'js' %} + +{% endautoescape %} + +4. no escape + +{% autoescape false %} + +{% endautoescape %} + +5. |escape('js')|escape('html') + +{% autoescape false %} + +{% endautoescape %} + +6. autoescape 'html' |escape('js')|escape('html') + +{% autoescape 'html' %} + +{% endautoescape %} + +--DATA-- +return array('msg' => "<>\n'\"") +--EXPECT-- + +1. autoescape 'html' |escape('js') + + + +2. autoescape 'html' |escape('js') + + + +3. autoescape 'js' |escape('js') + + + +4. no escape + + + +5. |escape('js')|escape('html') + + + +6. autoescape 'html' |escape('js')|escape('html') + + + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test new file mode 100755 index 0000000..7821a9a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test @@ -0,0 +1,131 @@ +--TEST-- +"autoescape" tag applies escaping after calling filters +--TEMPLATE-- +{% autoescape 'html' %} + +(escape_and_nl2br is an escaper filter) + +1. Don't escape escaper filter output +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is not escaped ) +{{ var|escape_and_nl2br }} + +2. Don't escape escaper filter output +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is not escaped, |raw is redundant ) +{{ var|escape_and_nl2br|raw }} + +3. Explicit escape +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is explicitly escaped by |escape ) +{{ var|escape_and_nl2br|escape }} + +4. Escape non-escaper filter output +( var is upper-cased by |upper, + the output is auto-escaped ) +{{ var|upper }} + +5. Escape if last filter is not an escaper +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is upper-cased by |upper, + the output is auto-escaped as |upper is not an escaper ) +{{ var|escape_and_nl2br|upper }} + +6. Don't escape escaper filter output +( var is upper cased by upper, + the output is escaped by |escape_and_nl2br, line-breaks are added, + the output is not escaped as |escape_and_nl2br is an escaper ) +{{ var|upper|escape_and_nl2br }} + +7. Escape if last filter is not an escaper +( the output of |format is "" ~ var ~ "", + the output is auto-escaped ) +{{ "%s"|format(var) }} + +8. Escape if last filter is not an escaper +( the output of |format is "" ~ var ~ "", + |raw is redundant, + the output is auto-escaped ) +{{ "%s"|raw|format(var) }} + +9. Don't escape escaper filter output +( the output of |format is "" ~ var ~ "", + the output is not escaped due to |raw filter at the end ) +{{ "%s"|format(var)|raw }} + +10. Don't escape escaper filter output +( the output of |format is "" ~ var ~ "", + the output is not escaped due to |raw filter at the end, + the |raw filter on var is redundant ) +{{ "%s"|format(var|raw)|raw }} + +{% endautoescape %} +--DATA-- +return array('var' => "\nTwig") +--EXPECT-- + +(escape_and_nl2br is an escaper filter) + +1. Don't escape escaper filter output +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is not escaped ) +<Fabien>
    +Twig + +2. Don't escape escaper filter output +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is not escaped, |raw is redundant ) +<Fabien>
    +Twig + +3. Explicit escape +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is explicitly escaped by |escape ) +&lt;Fabien&gt;<br /> +Twig + +4. Escape non-escaper filter output +( var is upper-cased by |upper, + the output is auto-escaped ) +<FABIEN> +TWIG + +5. Escape if last filter is not an escaper +( var is escaped by |escape_and_nl2br, line-breaks are added, + the output is upper-cased by |upper, + the output is auto-escaped as |upper is not an escaper ) +&LT;FABIEN&GT;<BR /> +TWIG + +6. Don't escape escaper filter output +( var is upper cased by upper, + the output is escaped by |escape_and_nl2br, line-breaks are added, + the output is not escaped as |escape_and_nl2br is an escaper ) +<FABIEN>
    +TWIG + +7. Escape if last filter is not an escaper +( the output of |format is "" ~ var ~ "", + the output is auto-escaped ) +<b><Fabien> +Twig</b> + +8. Escape if last filter is not an escaper +( the output of |format is "" ~ var ~ "", + |raw is redundant, + the output is auto-escaped ) +<b><Fabien> +Twig</b> + +9. Don't escape escaper filter output +( the output of |format is "" ~ var ~ "", + the output is not escaped due to |raw filter at the end ) + +Twig + +10. Don't escape escaper filter output +( the output of |format is "" ~ var ~ "", + the output is not escaped due to |raw filter at the end, + the |raw filter on var is redundant ) + +Twig diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test new file mode 100755 index 0000000..f58a1e0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test @@ -0,0 +1,23 @@ +--TEST-- +"autoescape" tag do not applies escaping on filter arguments +--TEMPLATE-- +{% autoescape 'html' %} +{{ var|nl2br("
    ") }} +{{ var|nl2br("
    "|escape) }} +{{ var|nl2br(sep) }} +{{ var|nl2br(sep|raw) }} +{{ var|nl2br(sep|escape) }} +{% endautoescape %} +--DATA-- +return array('var' => "\nTwig", 'sep' => '
    ') +--EXPECT-- +<Fabien>
    +Twig +<Fabien><br /> +Twig +<Fabien>
    +Twig +<Fabien>
    +Twig +<Fabien><br /> +Twig diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test new file mode 100755 index 0000000..134c77e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test @@ -0,0 +1,68 @@ +--TEST-- +"autoescape" tag applies escaping after calling filters, and before calling pre_escape filters +--TEMPLATE-- +{% autoescape 'html' %} + +(nl2br is pre_escaped for "html" and declared safe for "html") + +1. Pre-escape and don't post-escape +( var|escape|nl2br ) +{{ var|nl2br }} + +2. Don't double-pre-escape +( var|escape|nl2br ) +{{ var|escape|nl2br }} + +3. Don't escape safe values +( var|raw|nl2br ) +{{ var|raw|nl2br }} + +4. Don't escape safe values +( var|escape|nl2br|nl2br ) +{{ var|nl2br|nl2br }} + +5. Re-escape values that are escaped for an other contexts +( var|escape_something|escape|nl2br ) +{{ var|escape_something|nl2br }} + +6. Still escape when using filters not declared safe +( var|escape|nl2br|upper|escape ) +{{ var|nl2br|upper }} + +{% endautoescape %} +--DATA-- +return array('var' => "\nTwig") +--EXPECT-- + +(nl2br is pre_escaped for "html" and declared safe for "html") + +1. Pre-escape and don't post-escape +( var|escape|nl2br ) +<Fabien>
    +Twig + +2. Don't double-pre-escape +( var|escape|nl2br ) +<Fabien>
    +Twig + +3. Don't escape safe values +( var|raw|nl2br ) +
    +Twig + +4. Don't escape safe values +( var|escape|nl2br|nl2br ) +<Fabien>

    +Twig + +5. Re-escape values that are escaped for an other contexts +( var|escape_something|escape|nl2br ) +<FABIEN>
    +TWIG + +6. Still escape when using filters not declared safe +( var|escape|nl2br|upper|escape ) +&LT;FABIEN&GT;<BR /> +TWIG + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test new file mode 100755 index 0000000..32d3943 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test @@ -0,0 +1,50 @@ +--TEST-- +"autoescape" tag handles filters preserving the safety +--TEMPLATE-- +{% autoescape 'html' %} + +(preserves_safety is preserving safety for "html") + +1. Unsafe values are still unsafe +( var|preserves_safety|escape ) +{{ var|preserves_safety }} + +2. Safe values are still safe +( var|escape|preserves_safety ) +{{ var|escape|preserves_safety }} + +3. Re-escape values that are escaped for an other contexts +( var|escape_something|preserves_safety|escape ) +{{ var|escape_something|preserves_safety }} + +4. Still escape when using filters not declared safe +( var|escape|preserves_safety|replace({'FABIEN': 'FABPOT'})|escape ) +{{ var|escape|preserves_safety|replace({'FABIEN': 'FABPOT'}) }} + +{% endautoescape %} +--DATA-- +return array('var' => "\nTwig") +--EXPECT-- + +(preserves_safety is preserving safety for "html") + +1. Unsafe values are still unsafe +( var|preserves_safety|escape ) +<FABIEN> +TWIG + +2. Safe values are still safe +( var|escape|preserves_safety ) +<FABIEN> +TWIG + +3. Re-escape values that are escaped for an other contexts +( var|escape_something|preserves_safety|escape ) +<FABIEN> +TWIG + +4. Still escape when using filters not declared safe +( var|escape|preserves_safety|replace({'FABIEN': 'FABPOT'})|escape ) +&LT;FABPOT&GT; +TWIG + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/basic.test new file mode 100755 index 0000000..360dcf0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/basic.test @@ -0,0 +1,11 @@ +--TEST-- +"block" tag +--TEMPLATE-- +{% block title1 %}FOO{% endblock %} +{% block title2 foo|lower %} +--TEMPLATE(foo.twig)-- +{% block content %}{% endblock %} +--DATA-- +return array('foo' => 'bar') +--EXPECT-- +FOObar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/block_unique_name.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/block_unique_name.test new file mode 100755 index 0000000..5c205c0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/block_unique_name.test @@ -0,0 +1,11 @@ +--TEST-- +"block" tag +--TEMPLATE-- +{% block content %} + {% block content %} + {% endblock %} +{% endblock %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Syntax: The block 'content' has already been defined line 2 in "index.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/special_chars.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/special_chars.test new file mode 100755 index 0000000..be17fed --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/block/special_chars.test @@ -0,0 +1,10 @@ +--TEST-- +"§" special chars in a block name +--TEMPLATE-- +{% block § %} +§ +{% endblock § %} +--DATA-- +return array() +--EXPECT-- +§ diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/basic.test new file mode 100755 index 0000000..f44296e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/basic.test @@ -0,0 +1,35 @@ +--TEST-- +"embed" tag +--TEMPLATE-- +FOO +{% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + block1extended + {% endblock %} +{% endembed %} + +BAR +--TEMPLATE(foo.twig)-- +A +{% block c1 %} + block1 +{% endblock %} +B +{% block c2 %} + block2 +{% endblock %} +C +--DATA-- +return array() +--EXPECT-- +FOO + +A + block1 + + block1extended + B + block2 +C +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/error_line.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/error_line.test new file mode 100755 index 0000000..71ab2e0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/error_line.test @@ -0,0 +1,16 @@ +--TEST-- +"embed" tag +--TEMPLATE(index.twig)-- +FOO +{% embed "foo.twig" %} + {% block c1 %} + {{ nothing }} + {% endblock %} +{% endembed %} +BAR +--TEMPLATE(foo.twig)-- +{% block c1 %}{% endblock %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Runtime: Variable "nothing" does not exist in "index.twig" at line 5 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/multiple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/multiple.test new file mode 100755 index 0000000..da161e6 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/multiple.test @@ -0,0 +1,50 @@ +--TEST-- +"embed" tag +--TEMPLATE-- +FOO +{% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + block1extended + {% endblock %} +{% endembed %} + +{% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + block1extended + {% endblock %} +{% endembed %} + +BAR +--TEMPLATE(foo.twig)-- +A +{% block c1 %} + block1 +{% endblock %} +B +{% block c2 %} + block2 +{% endblock %} +C +--DATA-- +return array() +--EXPECT-- +FOO + +A + block1 + + block1extended + B + block2 +C + +A + block1 + + block1extended + B + block2 +C +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/nested.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/nested.test new file mode 100755 index 0000000..81563dc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/nested.test @@ -0,0 +1,42 @@ +--TEST-- +"embed" tag +--TEMPLATE-- +{% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + {% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + block1extended + {% endblock %} + {% endembed %} + + {% endblock %} +{% endembed %} +--TEMPLATE(foo.twig)-- +A +{% block c1 %} + block1 +{% endblock %} +B +{% block c2 %} + block2 +{% endblock %} +C +--DATA-- +return array() +--EXPECT-- +A + block1 + + +A + block1 + + block1extended + B + block2 +C + B + block2 +C diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/with_extends.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/with_extends.test new file mode 100755 index 0000000..cf7953d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/embed/with_extends.test @@ -0,0 +1,57 @@ +--TEST-- +"embed" tag +--TEMPLATE-- +{% extends "base.twig" %} + +{% block c1 %} + {{ parent() }} + blockc1baseextended +{% endblock %} + +{% block c2 %} + {{ parent() }} + + {% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + block1extended + {% endblock %} + {% endembed %} +{% endblock %} +--TEMPLATE(base.twig)-- +A +{% block c1 %} + blockc1base +{% endblock %} +{% block c2 %} + blockc2base +{% endblock %} +B +--TEMPLATE(foo.twig)-- +A +{% block c1 %} + block1 +{% endblock %} +B +{% block c2 %} + block2 +{% endblock %} +C +--DATA-- +return array() +--EXPECT-- +A + blockc1base + + blockc1baseextended + blockc2base + + + +A + block1 + + block1extended + B + block2 +CB \ No newline at end of file diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/basic.test new file mode 100755 index 0000000..82094f2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/basic.test @@ -0,0 +1,10 @@ +--TEST-- +"filter" tag applies a filter on its children +--TEMPLATE-- +{% filter upper %} +Some text with a {{ var }} +{% endfilter %} +--DATA-- +return array('var' => 'var') +--EXPECT-- +SOME TEXT WITH A VAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/json_encode.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/json_encode.test new file mode 100755 index 0000000..3e7148b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/json_encode.test @@ -0,0 +1,8 @@ +--TEST-- +"filter" tag applies a filter on its children +--TEMPLATE-- +{% filter json_encode|raw %}test{% endfilter %} +--DATA-- +return array() +--EXPECT-- +"test" diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/multiple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/multiple.test new file mode 100755 index 0000000..75512ef --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/multiple.test @@ -0,0 +1,10 @@ +--TEST-- +"filter" tags accept multiple chained filters +--TEMPLATE-- +{% filter lower|title %} + {{ var }} +{% endfilter %} +--DATA-- +return array('var' => 'VAR') +--EXPECT-- + Var diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/nested.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/nested.test new file mode 100755 index 0000000..7e4e4eb --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/nested.test @@ -0,0 +1,16 @@ +--TEST-- +"filter" tags can be nested at will +--TEMPLATE-- +{% filter lower|title %} + {{ var }} + {% filter upper %} + {{ var }} + {% endfilter %} + {{ var }} +{% endfilter %} +--DATA-- +return array('var' => 'var') +--EXPECT-- + Var + Var + Var diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_for_tag.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_for_tag.test new file mode 100755 index 0000000..22745ea --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_for_tag.test @@ -0,0 +1,13 @@ +--TEST-- +"filter" tag applies the filter on "for" tags +--TEMPLATE-- +{% filter upper %} +{% for item in items %} +{{ item }} +{% endfor %} +{% endfilter %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- +A +B diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_if_tag.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_if_tag.test new file mode 100755 index 0000000..afd95b2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/filter/with_if_tag.test @@ -0,0 +1,29 @@ +--TEST-- +"filter" tag applies the filter on "if" tags +--TEMPLATE-- +{% filter upper %} +{% if items %} +{{ items|join(', ') }} +{% endif %} + +{% if items.3 is defined %} +FOO +{% else %} +{{ items.1 }} +{% endif %} + +{% if items.3 is defined %} +FOO +{% elseif items.1 %} +{{ items.0 }} +{% endif %} + +{% endfilter %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- +A, B + +B + +A diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/condition.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/condition.test new file mode 100755 index 0000000..380531f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/condition.test @@ -0,0 +1,14 @@ +--TEST-- +"for" tag takes a condition +--TEMPLATE-- +{% for i in 1..5 if i is odd -%} + {{ loop.index }}.{{ i }}{{ foo.bar }} +{% endfor %} +--DATA-- +return array('foo' => array('bar' => 'X')) +--CONFIG-- +return array('strict_variables' => false) +--EXPECT-- +1.1X +2.3X +3.5X diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/context.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/context.test new file mode 100755 index 0000000..ddc6930 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/context.test @@ -0,0 +1,18 @@ +--TEST-- +"for" tag keeps the context safe +--TEMPLATE-- +{% for item in items %} + {% for item in items %} + * {{ item }} + {% endfor %} + * {{ item }} +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- + * a + * b + * a + * a + * b + * b diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/else.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/else.test new file mode 100755 index 0000000..20ccc88 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/else.test @@ -0,0 +1,23 @@ +--TEST-- +"for" tag can use an "else" clause +--TEMPLATE-- +{% for item in items %} + * {{ item }} +{% else %} + no item +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- + * a + * b +--DATA-- +return array('items' => array()) +--EXPECT-- + no item +--DATA-- +return array() +--CONFIG-- +return array('strict_variables' => false) +--EXPECT-- + no item diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/inner_variables.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/inner_variables.test new file mode 100755 index 0000000..49fb9ca --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/inner_variables.test @@ -0,0 +1,17 @@ +--TEST-- +"for" tag does not reset inner variables +--TEMPLATE-- +{% for i in 1..2 %} + {% for j in 0..2 %} + {{k}}{% set k = k+1 %} {{ loop.parent.loop.index }} + {% endfor %} +{% endfor %} +--DATA-- +return array('k' => 0) +--EXPECT-- + 0 1 + 1 1 + 2 1 + 3 2 + 4 2 + 5 2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys.test new file mode 100755 index 0000000..4e22cb4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys.test @@ -0,0 +1,11 @@ +--TEST-- +"for" tag can iterate over keys +--TEMPLATE-- +{% for key in items|keys %} + * {{ key }} +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- + * 0 + * 1 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys_and_values.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys_and_values.test new file mode 100755 index 0000000..4c21168 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/keys_and_values.test @@ -0,0 +1,11 @@ +--TEST-- +"for" tag can iterate over keys and values +--TEMPLATE-- +{% for key, item in items %} + * {{ key }}/{{ item }} +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- + * 0/a + * 1/b diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context.test new file mode 100755 index 0000000..93bc76a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context.test @@ -0,0 +1,19 @@ +--TEST-- +"for" tag adds a loop variable to the context +--TEMPLATE-- +{% for item in items %} + * {{ loop.index }}/{{ loop.index0 }} + * {{ loop.revindex }}/{{ loop.revindex0 }} + * {{ loop.first }}/{{ loop.last }}/{{ loop.length }} + +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- + * 1/0 + * 2/1 + * 1//2 + + * 2/1 + * 1/0 + * /1/2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context_local.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context_local.test new file mode 100755 index 0000000..58af2c3 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_context_local.test @@ -0,0 +1,10 @@ +--TEST-- +"for" tag adds a loop variable to the context locally +--TEMPLATE-- +{% for item in items %} +{% endfor %} +{% if loop is not defined %}WORKS{% endif %} +--DATA-- +return array('items' => array()) +--EXPECT-- +WORKS diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined.test new file mode 100755 index 0000000..4301ef2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined.test @@ -0,0 +1,10 @@ +--TEST-- +"for" tag +--TEMPLATE-- +{% for i, item in items if i > 0 %} + {{ loop.last }} +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXCEPTION-- +Twig_Error_Syntax: The "loop.last" variable is not defined when looping with a condition in "index.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined_cond.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined_cond.test new file mode 100755 index 0000000..c7e723a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/loop_not_defined_cond.test @@ -0,0 +1,9 @@ +--TEST-- +"for" tag +--TEMPLATE-- +{% for i, item in items if loop.last > 0 %} +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXCEPTION-- +Twig_Error_Syntax: The "loop" variable cannot be used in a looping condition in "index.twig" at line 2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/nested_else.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/nested_else.test new file mode 100755 index 0000000..f8b9f6b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/nested_else.test @@ -0,0 +1,17 @@ +--TEST-- +"for" tag can use an "else" clause +--TEMPLATE-- +{% for item in items %} + {% for item in items1 %} + * {{ item }} + {% else %} + no {{ item }} + {% endfor %} +{% else %} + no item1 +{% endfor %} +--DATA-- +return array('items' => array('a', 'b'), 'items1' => array()) +--EXPECT-- +no a + no b diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects.test new file mode 100755 index 0000000..5034437 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects.test @@ -0,0 +1,43 @@ +--TEST-- +"for" tag iterates over iterable objects +--TEMPLATE-- +{% for item in items %} + * {{ item }} + * {{ loop.index }}/{{ loop.index0 }} + * {{ loop.first }} + +{% endfor %} + +{% for key, value in items %} + * {{ key }}/{{ value }} +{% endfor %} + +{% for key in items|keys %} + * {{ key }} +{% endfor %} +--DATA-- +class ItemsIterator implements Iterator +{ + protected $values = array('foo' => 'bar', 'bar' => 'foo'); + public function current() { return current($this->values); } + public function key() { return key($this->values); } + public function next() { return next($this->values); } + public function rewind() { return reset($this->values); } + public function valid() { return false !== current($this->values); } +} +return array('items' => new ItemsIterator()) +--EXPECT-- + * bar + * 1/0 + * 1 + + * foo + * 2/1 + * + + + * foo/bar + * bar/foo + + * foo + * bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test new file mode 100755 index 0000000..4a1ff61 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test @@ -0,0 +1,47 @@ +--TEST-- +"for" tag iterates over iterable and countable objects +--TEMPLATE-- +{% for item in items %} + * {{ item }} + * {{ loop.index }}/{{ loop.index0 }} + * {{ loop.revindex }}/{{ loop.revindex0 }} + * {{ loop.first }}/{{ loop.last }}/{{ loop.length }} + +{% endfor %} + +{% for key, value in items %} + * {{ key }}/{{ value }} +{% endfor %} + +{% for key in items|keys %} + * {{ key }} +{% endfor %} +--DATA-- +class ItemsIteratorCountable implements Iterator, Countable +{ + protected $values = array('foo' => 'bar', 'bar' => 'foo'); + public function current() { return current($this->values); } + public function key() { return key($this->values); } + public function next() { return next($this->values); } + public function rewind() { return reset($this->values); } + public function valid() { return false !== current($this->values); } + public function count() { return count($this->values); } +} +return array('items' => new ItemsIteratorCountable()) +--EXPECT-- + * bar + * 1/0 + * 2/1 + * 1//2 + + * foo + * 2/1 + * 1/0 + * /1/2 + + + * foo/bar + * bar/foo + + * foo + * bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/recursive.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/recursive.test new file mode 100755 index 0000000..17b2e22 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/recursive.test @@ -0,0 +1,18 @@ +--TEST-- +"for" tags can be nested +--TEMPLATE-- +{% for key, item in items %} +* {{ key }} ({{ loop.length }}): +{% for value in item %} + * {{ value }} ({{ loop.length }}) +{% endfor %} +{% endfor %} +--DATA-- +return array('items' => array('a' => array('a1', 'a2', 'a3'), 'b' => array('b1'))) +--EXPECT-- +* a (2): + * a1 (3) + * a2 (3) + * a3 (3) +* b (2): + * b1 (1) diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/values.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/values.test new file mode 100755 index 0000000..82f2ae8 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/values.test @@ -0,0 +1,11 @@ +--TEST-- +"for" tag iterates over item values +--TEMPLATE-- +{% for item in items %} + * {{ item }} +{% endfor %} +--DATA-- +return array('items' => array('a', 'b')) +--EXPECT-- + * a + * b diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/from.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/from.test new file mode 100755 index 0000000..5f5da0e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/from.test @@ -0,0 +1,14 @@ +--TEST-- +global variables +--TEMPLATE-- +{% include "included.twig" %} +{% from "included.twig" import foobar %} +{{ foobar() }} +--TEMPLATE(included.twig)-- +{% macro foobar() %} +called foobar +{% endmacro %} +--DATA-- +return array(); +--EXPECT-- +called foobar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/basic.test new file mode 100755 index 0000000..c1c3d27 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/basic.test @@ -0,0 +1,22 @@ +--TEST-- +"if" creates a condition +--TEMPLATE-- +{% if a is defined %} + {{ a }} +{% elseif b is defined %} + {{ b }} +{% else %} + NOTHING +{% endif %} +--DATA-- +return array('a' => 'a') +--EXPECT-- + a +--DATA-- +return array('b' => 'b') +--EXPECT-- + b +--DATA-- +return array() +--EXPECT-- + NOTHING diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/expression.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/expression.test new file mode 100755 index 0000000..edfb73d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/if/expression.test @@ -0,0 +1,22 @@ +--TEST-- +"if" takes an expression as a test +--TEMPLATE-- +{% if a < 2 %} + A1 +{% elseif a > 10 %} + A2 +{% else %} + A3 +{% endif %} +--DATA-- +return array('a' => 1) +--EXPECT-- + A1 +--DATA-- +return array('a' => 12) +--EXPECT-- + A2 +--DATA-- +return array('a' => 7) +--EXPECT-- + A3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/basic.test new file mode 100755 index 0000000..8fe1a6c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/basic.test @@ -0,0 +1,16 @@ +--TEST-- +"include" tag +--TEMPLATE-- +FOO +{% include "foo.twig" %} + +BAR +--TEMPLATE(foo.twig)-- +FOOBAR +--DATA-- +return array() +--EXPECT-- +FOO + +FOOBAR +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/expression.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/expression.test new file mode 100755 index 0000000..eaeeb11 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/expression.test @@ -0,0 +1,16 @@ +--TEST-- +"include" tag allows expressions for the template to include +--TEMPLATE-- +FOO +{% include foo %} + +BAR +--TEMPLATE(foo.twig)-- +FOOBAR +--DATA-- +return array('foo' => 'foo.twig') +--EXPECT-- +FOO + +FOOBAR +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing.test new file mode 100755 index 0000000..24aed06 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/ignore_missing.test @@ -0,0 +1,10 @@ +--TEST-- +"include" tag +--TEMPLATE-- +{% include ["foo.twig", "bar.twig"] ignore missing %} +{% include "foo.twig" ignore missing %} +{% include "foo.twig" ignore missing with {} %} +{% include "foo.twig" ignore missing with {} only %} +--DATA-- +return array() +--EXPECT-- diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing.test new file mode 100755 index 0000000..f25e871 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing.test @@ -0,0 +1,8 @@ +--TEST-- +"include" tag +--TEMPLATE-- +{% include "foo.twig" %} +--DATA-- +return array(); +--EXCEPTION-- +Twig_Error_Loader: Template "foo.twig" is not defined in "index.twig" at line 2. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing_nested.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing_nested.test new file mode 100755 index 0000000..86c1864 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/missing_nested.test @@ -0,0 +1,16 @@ +--TEST-- +"include" tag +--TEMPLATE-- +{% extends "base.twig" %} + +{% block content %} + {{ parent() }} +{% endblock %} +--TEMPLATE(base.twig)-- +{% block content %} + {% include "foo.twig" %} +{% endblock %} +--DATA-- +return array(); +--EXCEPTION-- +Twig_Error_Loader: Template "foo.twig" is not defined in "base.twig" at line 3. diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/only.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/only.test new file mode 100755 index 0000000..77760a0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/only.test @@ -0,0 +1,16 @@ +--TEST-- +"include" tag accept variables and only +--TEMPLATE-- +{% include "foo.twig" %} +{% include "foo.twig" only %} +{% include "foo.twig" with {'foo1': 'bar'} %} +{% include "foo.twig" with {'foo1': 'bar'} only %} +--TEMPLATE(foo.twig)-- +{% for k, v in _context %}{{ k }},{% endfor %} +--DATA-- +return array('foo' => 'bar') +--EXPECT-- +foo,global,_parent, +global,_parent, +foo,global,foo1,_parent, +foo1,global,_parent, diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/template_instance.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/template_instance.test new file mode 100755 index 0000000..6ba064a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/template_instance.test @@ -0,0 +1,10 @@ +--TEST-- +"include" tag accepts Twig_Template instance +--TEMPLATE-- +{% include foo %} FOO +--TEMPLATE(foo.twig)-- +BAR +--DATA-- +return array('foo' => $twig->loadTemplate('foo.twig')) +--EXPECT-- +BAR FOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/templates_as_array.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/templates_as_array.test new file mode 100755 index 0000000..ab670ee --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/templates_as_array.test @@ -0,0 +1,12 @@ +--TEST-- +"include" tag +--TEMPLATE-- +{% include ["foo.twig", "bar.twig"] %} +{% include ["bar.twig", "foo.twig"] %} +--TEMPLATE(foo.twig)-- +foo +--DATA-- +return array() +--EXPECT-- +foo +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/with_variables.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/with_variables.test new file mode 100755 index 0000000..41384ac --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/include/with_variables.test @@ -0,0 +1,12 @@ +--TEST-- +"include" tag accept variables +--TEMPLATE-- +{% include "foo.twig" with {'foo': 'bar'} %} +{% include "foo.twig" with vars %} +--TEMPLATE(foo.twig)-- +{{ foo }} +--DATA-- +return array('vars' => array('foo' => 'bar')) +--EXPECT-- +bar +bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/basic.test new file mode 100755 index 0000000..0778a4b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/basic.test @@ -0,0 +1,14 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "foo.twig" %} + +{% block content %} +FOO +{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %}{% endblock %} +--DATA-- +return array() +--EXPECT-- +FOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test new file mode 100755 index 0000000..9a81499 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test @@ -0,0 +1,32 @@ +--TEST-- +block_expr +--TEMPLATE-- +{% extends "base.twig" %} + +{% block element -%} + Element: + {{- parent() -}} +{% endblock %} +--TEMPLATE(base.twig)-- +{% spaceless %} +{% block element -%} +
    + {%- if item.children is defined %} + {%- for item in item.children %} + {{- block('element') -}} + {% endfor %} + {%- endif -%} +
    +{%- endblock %} +{% endspaceless %} +--DATA-- +return array( + 'item' => array( + 'children' => array( + null, + null, + ) + ) +) +--EXPECT-- +Element:
    Element:
    Element:
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test new file mode 100755 index 0000000..3e868c0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test @@ -0,0 +1,34 @@ +--TEST-- +block_expr2 +--TEMPLATE-- +{% extends "base2.twig" %} + +{% block element -%} + Element: + {{- parent() -}} +{% endblock %} +--TEMPLATE(base2.twig)-- +{% extends "base.twig" %} +--TEMPLATE(base.twig)-- +{% spaceless %} +{% block element -%} +
    + {%- if item.children is defined %} + {%- for item in item.children %} + {{- block('element') -}} + {% endfor %} + {%- endif -%} +
    +{%- endblock %} +{% endspaceless %} +--DATA-- +return array( + 'item' => array( + 'children' => array( + null, + null, + ) + ) +) +--EXPECT-- +Element:
    Element:
    Element:
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/conditional.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/conditional.test new file mode 100755 index 0000000..8576e77 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/conditional.test @@ -0,0 +1,14 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends standalone ? foo : 'bar.twig' %} + +{% block content %}{{ parent() }}FOO{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %}FOO{% endblock %} +--TEMPLATE(bar.twig)-- +{% block content %}BAR{% endblock %} +--DATA-- +return array('foo' => 'foo.twig', 'standalone' => true) +--EXPECT-- +FOOFOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/dynamic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/dynamic.test new file mode 100755 index 0000000..ee06ddc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/dynamic.test @@ -0,0 +1,14 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends foo %} + +{% block content %} +FOO +{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %}{% endblock %} +--DATA-- +return array('foo' => 'foo.twig') +--EXPECT-- +FOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/empty.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/empty.test new file mode 100755 index 0000000..784f357 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/empty.test @@ -0,0 +1,10 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "foo.twig" %} +--TEMPLATE(foo.twig)-- +{% block content %}FOO{% endblock %} +--DATA-- +return array() +--EXPECT-- +FOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array.test new file mode 100755 index 0000000..a1cb1ce --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array.test @@ -0,0 +1,12 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends ["foo.twig", "bar.twig"] %} +--TEMPLATE(bar.twig)-- +{% block content %} +foo +{% endblock %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_empty_name.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_empty_name.test new file mode 100755 index 0000000..acc74f6 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_empty_name.test @@ -0,0 +1,12 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends ["", "bar.twig"] %} +--TEMPLATE(bar.twig)-- +{% block content %} +foo +{% endblock %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_null_name.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_null_name.test new file mode 100755 index 0000000..cfa648d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/extends_as_array_with_null_name.test @@ -0,0 +1,12 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends [null, "bar.twig"] %} +--TEMPLATE(bar.twig)-- +{% block content %} +foo +{% endblock %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple.test new file mode 100755 index 0000000..dfc2b6c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple.test @@ -0,0 +1,12 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "layout.twig" %}{% block content %}{{ parent() }}index {% endblock %} +--TEMPLATE(layout.twig)-- +{% extends "base.twig" %}{% block content %}{{ parent() }}layout {% endblock %} +--TEMPLATE(base.twig)-- +{% block content %}base {% endblock %} +--DATA-- +return array() +--EXPECT-- +base layout index diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple_dynamic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple_dynamic.test new file mode 100755 index 0000000..1d3e639 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/multiple_dynamic.test @@ -0,0 +1,22 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% set foo = 1 %} +{{ include('parent.twig') }} +{{ include('parent.twig') }} +{% set foo = 2 %} +{{ include('parent.twig') }} +--TEMPLATE(parent.twig)-- +{% extends foo~'_parent.twig' %}{% block content %}{{ parent() }} parent{% endblock %} +--TEMPLATE(1_parent.twig)-- +{% block content %}1{% endblock %} +--TEMPLATE(2_parent.twig)-- +{% block content %}2{% endblock %} +--DATA-- +return array() +--EXPECT-- +1 parent + +1 parent + +2 parent diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks.test new file mode 100755 index 0000000..faca925 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks.test @@ -0,0 +1,22 @@ +--TEST-- +"block" tag +--TEMPLATE-- +{% extends "foo.twig" %} + +{% block content %} + {% block subcontent %} + {% block subsubcontent %} + SUBSUBCONTENT + {% endblock %} + {% endblock %} +{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %} + {% block subcontent %} + SUBCONTENT + {% endblock %} +{% endblock %} +--DATA-- +return array() +--EXPECT-- +SUBSUBCONTENT diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks_parent_only.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks_parent_only.test new file mode 100755 index 0000000..0ad11d0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_blocks_parent_only.test @@ -0,0 +1,15 @@ +--TEST-- +"block" tag +--TEMPLATE-- +{% block content %} + CONTENT + {%- block subcontent -%} + SUBCONTENT + {%- endblock -%} + ENDCONTENT +{% endblock %} +--TEMPLATE(foo.twig)-- +--DATA-- +return array() +--EXPECT-- +CONTENTSUBCONTENTENDCONTENT diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_inheritance.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_inheritance.test new file mode 100755 index 0000000..71e3cdf --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/nested_inheritance.test @@ -0,0 +1,16 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "layout.twig" %} +{% block inside %}INSIDE{% endblock inside %} +--TEMPLATE(layout.twig)-- +{% extends "base.twig" %} +{% block body %} + {% block inside '' %} +{% endblock body %} +--TEMPLATE(base.twig)-- +{% block body '' %} +--DATA-- +return array() +--EXPECT-- +INSIDE diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent.test new file mode 100755 index 0000000..4f975db --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent.test @@ -0,0 +1,12 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "foo.twig" %} + +{% block content %}{{ parent() }}FOO{{ parent() }}{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %}BAR{% endblock %} +--DATA-- +return array() +--EXPECT-- +BARFOOBAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_change.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_change.test new file mode 100755 index 0000000..a8bc90c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_change.test @@ -0,0 +1,16 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends foo ? 'foo.twig' : 'bar.twig' %} +--TEMPLATE(foo.twig)-- +FOO +--TEMPLATE(bar.twig)-- +BAR +--DATA-- +return array('foo' => true) +--EXPECT-- +FOO +--DATA-- +return array('foo' => false) +--EXPECT-- +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_in_a_block.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_in_a_block.test new file mode 100755 index 0000000..c9e86b1 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_in_a_block.test @@ -0,0 +1,8 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% block content %} + {% extends "foo.twig" %} +{% endblock %} +--EXCEPTION-- +Twig_Error_Syntax: Cannot extend from a block in "index.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test new file mode 100755 index 0000000..6281671 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test @@ -0,0 +1,20 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "base.twig" %} +{% block content %}{% include "included.twig" %}{% endblock %} + +{% block footer %}Footer{% endblock %} +--TEMPLATE(included.twig)-- +{% extends "base.twig" %} +{% block content %}Included Content{% endblock %} +--TEMPLATE(base.twig)-- +{% block content %}Default Content{% endblock %} + +{% block footer %}Default Footer{% endblock %} +--DATA-- +return array() +--EXPECT-- +Included Content +Default Footer +Footer diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_nested.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_nested.test new file mode 100755 index 0000000..71e7c20 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_nested.test @@ -0,0 +1,28 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "foo.twig" %} + +{% block content %} + {% block inside %} + INSIDE OVERRIDDEN + {% endblock %} + + BEFORE + {{ parent() }} + AFTER +{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %} + BAR +{% endblock %} +--DATA-- +return array() +--EXPECT-- + +INSIDE OVERRIDDEN + + BEFORE + BAR + + AFTER diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends.test new file mode 100755 index 0000000..a9eaa4c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends.test @@ -0,0 +1,8 @@ +--TEST-- +"parent" tag +--TEMPLATE-- +{% block content %} + {{ parent() }} +{% endblock %} +--EXCEPTION-- +Twig_Error_Syntax: Calling "parent" on a template that does not extend nor "use" another template is forbidden in "index.twig" at line 3 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends_but_traits.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends_but_traits.test new file mode 100755 index 0000000..63c7305 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/parent_without_extends_but_traits.test @@ -0,0 +1,14 @@ +--TEST-- +"parent" tag +--TEMPLATE-- +{% use 'foo.twig' %} + +{% block content %} + {{ parent() }} +{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %}BAR{% endblock %} +--DATA-- +return array() +--EXPECT-- +BAR diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test new file mode 100755 index 0000000..d1876a5 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test @@ -0,0 +1,14 @@ +--TEST-- +"extends" tag accepts Twig_Template instance +--TEMPLATE-- +{% extends foo %} + +{% block content %} +{{ parent() }}FOO +{% endblock %} +--TEMPLATE(foo.twig)-- +{% block content %}BAR{% endblock %} +--DATA-- +return array('foo' => $twig->loadTemplate('foo.twig')) +--EXPECT-- +BARFOO diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/use.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/use.test new file mode 100755 index 0000000..8f9ece7 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/use.test @@ -0,0 +1,44 @@ +--TEST-- +"parent" function +--TEMPLATE-- +{% extends "parent.twig" %} + +{% use "use1.twig" %} +{% use "use2.twig" %} + +{% block content_parent %} + {{ parent() }} +{% endblock %} + +{% block content_use1 %} + {{ parent() }} +{% endblock %} + +{% block content_use2 %} + {{ parent() }} +{% endblock %} + +{% block content %} + {{ block('content_use1_only') }} + {{ block('content_use2_only') }} +{% endblock %} +--TEMPLATE(parent.twig)-- +{% block content_parent 'content_parent' %} +{% block content_use1 'content_parent' %} +{% block content_use2 'content_parent' %} +{% block content '' %} +--TEMPLATE(use1.twig)-- +{% block content_use1 'content_use1' %} +{% block content_use2 'content_use1' %} +{% block content_use1_only 'content_use1_only' %} +--TEMPLATE(use2.twig)-- +{% block content_use2 'content_use2' %} +{% block content_use2_only 'content_use2_only' %} +--DATA-- +return array() +--EXPECT-- + content_parent + content_use1 + content_use2 + content_use1_only + content_use2_only diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/basic.test new file mode 100755 index 0000000..eef0c10 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/basic.test @@ -0,0 +1,17 @@ +--TEST-- +"macro" tag +--TEMPLATE-- +{% import _self as macros %} + +{{ macros.input('username') }} +{{ macros.input('password', null, 'password', 1) }} + +{% macro input(name, value, type, size) %} + +{% endmacro %} +--DATA-- +return array() +--EXPECT-- + + + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test new file mode 100755 index 0000000..ae6203b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/endmacro_name.test @@ -0,0 +1,16 @@ +--TEST-- +"macro" tag supports name for endmacro +--TEMPLATE-- +{% import _self as macros %} + +{{ macros.foo() }} +{{ macros.bar() }} + +{% macro foo() %}foo{% endmacro %} +{% macro bar() %}bar{% endmacro bar %} +--DATA-- +return array() +--EXPECT-- +foo +bar + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/external.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/external.test new file mode 100755 index 0000000..5cd3dae --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/external.test @@ -0,0 +1,17 @@ +--TEST-- +"macro" tag +--TEMPLATE-- +{% import 'forms.twig' as forms %} + +{{ forms.input('username') }} +{{ forms.input('password', null, 'password', 1) }} +--TEMPLATE(forms.twig)-- +{% macro input(name, value, type, size) %} + +{% endmacro %} +--DATA-- +return array() +--EXPECT-- + + + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from.test new file mode 100755 index 0000000..205f591 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/from.test @@ -0,0 +1,18 @@ +--TEST-- +"macro" tag +--TEMPLATE-- +{% from 'forms.twig' import foo %} +{% from 'forms.twig' import foo as foobar, bar %} + +{{ foo('foo') }} +{{ foobar('foo') }} +{{ bar('foo') }} +--TEMPLATE(forms.twig)-- +{% macro foo(name) %}foo{{ name }}{% endmacro %} +{% macro bar(name) %}bar{{ name }}{% endmacro %} +--DATA-- +return array() +--EXPECT-- +foofoo +foofoo +barfoo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/global.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/global.test new file mode 100755 index 0000000..6b37176 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/global.test @@ -0,0 +1,14 @@ +--TEST-- +"macro" tag +--TEMPLATE-- +{% from 'forms.twig' import foo %} + +{{ foo('foo') }} +{{ foo() }} +--TEMPLATE(forms.twig)-- +{% macro foo(name) %}{{ name|default('foo') }}{{ global }}{% endmacro %} +--DATA-- +return array() +--EXPECT-- +fooglobal +fooglobal diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/self_import.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/self_import.test new file mode 100755 index 0000000..17756cb --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/self_import.test @@ -0,0 +1,17 @@ +--TEST-- +"macro" tag +--TEMPLATE-- +{% import _self as forms %} + +{{ forms.input('username') }} +{{ forms.input('password', null, 'password', 1) }} + +{% macro input(name, value, type, size) %} + +{% endmacro %} +--DATA-- +return array() +--EXPECT-- + + + diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/special_chars.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/special_chars.test new file mode 100755 index 0000000..3721770 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/special_chars.test @@ -0,0 +1,14 @@ +--TEST-- +"§" as a macro name +--TEMPLATE-- +{% import _self as macros %} + +{{ macros.§('foo') }} + +{% macro §(foo) %} + §{{ foo }}§ +{% endmacro %} +--DATA-- +return array() +--EXPECT-- +§foo§ diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test new file mode 100755 index 0000000..5679462 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test @@ -0,0 +1,14 @@ +--TEST-- +Super globals as macro arguments +--TEMPLATE-- +{% import _self as macros %} + +{{ macros.foo('foo') }} + +{% macro foo(GET) %} + {{ GET }} +{% endmacro %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.test new file mode 100755 index 0000000..0445e85 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/basic.test @@ -0,0 +1,10 @@ +--TEST-- +"raw" tag +--TEMPLATE-- +{% raw %} +{{ foo }} +{% endraw %} +--DATA-- +return array() +--EXPECT-- +{{ foo }} diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.test new file mode 100755 index 0000000..2fd9fb2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.test @@ -0,0 +1,10 @@ +--TEST-- +"raw" tag +--TEMPLATE-- +{% raw %} +{{ foo }} +{% endverbatim %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Syntax: Unexpected end of file: Unclosed "raw" block in "index.twig" at line 2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.test new file mode 100755 index 0000000..352bb18 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.test @@ -0,0 +1,56 @@ +--TEST-- +"raw" tag +--TEMPLATE-- +1*** + +{%- raw %} + {{ 'bla' }} +{% endraw %} + +1*** +2*** + +{%- raw -%} + {{ 'bla' }} +{% endraw %} + +2*** +3*** + +{%- raw -%} + {{ 'bla' }} +{% endraw -%} + +3*** +4*** + +{%- raw -%} + {{ 'bla' }} +{%- endraw %} + +4*** +5*** + +{%- raw -%} + {{ 'bla' }} +{%- endraw -%} + +5*** +--DATA-- +return array() +--EXPECT-- +1*** + {{ 'bla' }} + + +1*** +2***{{ 'bla' }} + + +2*** +3***{{ 'bla' }} +3*** +4***{{ 'bla' }} + +4*** +5***{{ 'bla' }}5*** diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid1.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid1.test new file mode 100755 index 0000000..683c59a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid1.test @@ -0,0 +1,11 @@ +--TEST-- +sandbox tag +--TEMPLATE-- +{%- sandbox %} + {%- include "foo.twig" %} + a +{%- endsandbox %} +--TEMPLATE(foo.twig)-- +foo +--EXCEPTION-- +Twig_Error_Syntax: Only "include" tags are allowed within a "sandbox" section in "index.twig" at line 4 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid2.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid2.test new file mode 100755 index 0000000..3dcfa88 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/not_valid2.test @@ -0,0 +1,14 @@ +--TEST-- +sandbox tag +--TEMPLATE-- +{%- sandbox %} + {%- include "foo.twig" %} + + {% if 1 %} + {%- include "foo.twig" %} + {% endif %} +{%- endsandbox %} +--TEMPLATE(foo.twig)-- +foo +--EXCEPTION-- +Twig_Error_Syntax: Only "include" tags are allowed within a "sandbox" section in "index.twig" at line 5 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/simple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/simple.test new file mode 100755 index 0000000..de20f3d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/sandbox/simple.test @@ -0,0 +1,22 @@ +--TEST-- +sandbox tag +--TEMPLATE-- +{%- sandbox %} + {%- include "foo.twig" %} +{%- endsandbox %} + +{%- sandbox %} + {%- include "foo.twig" %} + {%- include "foo.twig" %} +{%- endsandbox %} + +{%- sandbox %}{% include "foo.twig" %}{% endsandbox %} +--TEMPLATE(foo.twig)-- +foo +--DATA-- +return array() +--EXPECT-- +foo +foo +foo +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/basic.test new file mode 100755 index 0000000..a5a9f83 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/basic.test @@ -0,0 +1,20 @@ +--TEST-- +"set" tag +--TEMPLATE-- +{% set foo = 'foo' %} +{% set bar = 'foo
    ' %} + +{{ foo }} +{{ bar }} + +{% set foo, bar = 'foo', 'bar' %} + +{{ foo }}{{ bar }} +--DATA-- +return array() +--EXPECT-- +foo +foo<br /> + + +foobar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture-empty.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture-empty.test new file mode 100755 index 0000000..ec657f0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture-empty.test @@ -0,0 +1,9 @@ +--TEST-- +"set" tag block empty capture +--TEMPLATE-- +{% set foo %}{% endset %} + +{% if foo %}FAIL{% endif %} +--DATA-- +return array() +--EXPECT-- diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture.test new file mode 100755 index 0000000..f156a1a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/capture.test @@ -0,0 +1,10 @@ +--TEST-- +"set" tag block capture +--TEMPLATE-- +{% set foo %}f
    o
    o{% endset %} + +{{ foo }} +--DATA-- +return array() +--EXPECT-- +f
    o
    o diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/expression.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/expression.test new file mode 100755 index 0000000..8ff434a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/set/expression.test @@ -0,0 +1,12 @@ +--TEST-- +"set" tag +--TEMPLATE-- +{% set foo, bar = 'foo' ~ 'bar', 'bar' ~ 'foo' %} + +{{ foo }} +{{ bar }} +--DATA-- +return array() +--EXPECT-- +foobar +barfoo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/spaceless/simple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/spaceless/simple.test new file mode 100755 index 0000000..dd06dec --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/spaceless/simple.test @@ -0,0 +1,12 @@ +--TEST-- +"spaceless" tag removes whites between HTML tags +--TEMPLATE-- +{% spaceless %} + +
    foo
    + +{% endspaceless %} +--DATA-- +return array() +--EXPECT-- +
    foo
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/special_chars.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/special_chars.test new file mode 100755 index 0000000..789b4ba --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/special_chars.test @@ -0,0 +1,8 @@ +--TEST-- +"§" custom tag +--TEMPLATE-- +{% § %} +--DATA-- +return array() +--EXPECT-- +§ diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/trim_block.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/trim_block.test new file mode 100755 index 0000000..1d2273f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/trim_block.test @@ -0,0 +1,74 @@ +--TEST-- +Whitespace trimming on tags. +--TEMPLATE-- +{{ 5 * '{#-'|length }} +{{ '{{-'|length * 5 + '{%-'|length }} + +Trim on control tag: +{% for i in range(1, 9) -%} + {{ i }} +{%- endfor %} + + +Trim on output tag: +{% for i in range(1, 9) %} + {{- i -}} +{% endfor %} + + +Trim comments: + +{#- Invisible -#} + +After the comment. + +Trim leading space: +{% if leading %} + + {{- leading }} +{% endif %} + +{%- if leading %} + {{- leading }} + +{%- endif %} + + +Trim trailing space: +{% if trailing -%} + {{ trailing -}} + +{% endif -%} + +Combined: + +{%- if both -%} +
      +
    • {{- both -}}
    • +
    + +{%- endif -%} + +end +--DATA-- +return array('leading' => 'leading space', 'trailing' => 'trailing space', 'both' => 'both') +--EXPECT-- +15 +18 + +Trim on control tag: +123456789 + +Trim on output tag: +123456789 + +Trim comments:After the comment. + +Trim leading space: +leading space +leading space + +Trim trailing space: +trailing spaceCombined:
      +
    • both
    • +
    end diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/aliases.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/aliases.test new file mode 100755 index 0000000..f887006 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/aliases.test @@ -0,0 +1,12 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "blocks.twig" with content as foo %} + +{{ block('foo') }} +--TEMPLATE(blocks.twig)-- +{% block content 'foo' %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/basic.test new file mode 100755 index 0000000..7364d76 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/basic.test @@ -0,0 +1,12 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "blocks.twig" %} + +{{ block('content') }} +--TEMPLATE(blocks.twig)-- +{% block content 'foo' %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep.test new file mode 100755 index 0000000..b551a1e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep.test @@ -0,0 +1,22 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "foo.twig" %} + +{{ block('content') }} +{{ block('foo') }} +{{ block('bar') }} +--TEMPLATE(foo.twig)-- +{% use "bar.twig" %} + +{% block content 'foo' %} +{% block foo 'foo' %} +--TEMPLATE(bar.twig)-- +{% block content 'bar' %} +{% block bar 'bar' %} +--DATA-- +return array() +--EXPECT-- +foo +foo +bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep_empty.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep_empty.test new file mode 100755 index 0000000..05cca68 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/deep_empty.test @@ -0,0 +1,10 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "foo.twig" %} +--TEMPLATE(foo.twig)-- +{% use "bar.twig" %} +--TEMPLATE(bar.twig)-- +--DATA-- +return array() +--EXPECT-- diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test new file mode 100755 index 0000000..6368b08 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test @@ -0,0 +1,25 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "parent.twig" %} + +{{ block('container') }} +--TEMPLATE(parent.twig)-- +{% use "ancestor.twig" %} + +{% block sub_container %} +
    overriden sub_container
    +{% endblock %} +--TEMPLATE(ancestor.twig)-- +{% block container %} +
    {{ block('sub_container') }}
    +{% endblock %} + +{% block sub_container %} +
    sub_container
    +{% endblock %} +--DATA-- +return array() +--EXPECT-- +
    overriden sub_container
    +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test new file mode 100755 index 0000000..114e301 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "ancestor.twig" %} +{% use "parent.twig" %} + +{{ block('container') }} +--TEMPLATE(parent.twig)-- +{% block sub_container %} +
    overriden sub_container
    +{% endblock %} +--TEMPLATE(ancestor.twig)-- +{% block container %} +
    {{ block('sub_container') }}
    +{% endblock %} + +{% block sub_container %} +
    sub_container
    +{% endblock %} +--DATA-- +return array() +--EXPECT-- +
    overriden sub_container
    +
    diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple.test new file mode 100755 index 0000000..198be0c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple.test @@ -0,0 +1,21 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "foo.twig" %} +{% use "bar.twig" %} + +{{ block('content') }} +{{ block('foo') }} +{{ block('bar') }} +--TEMPLATE(foo.twig)-- +{% block content 'foo' %} +{% block foo 'foo' %} +--TEMPLATE(bar.twig)-- +{% block content 'bar' %} +{% block bar 'bar' %} +--DATA-- +return array() +--EXPECT-- +bar +foo +bar diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple_aliases.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple_aliases.test new file mode 100755 index 0000000..8de871a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/multiple_aliases.test @@ -0,0 +1,23 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "foo.twig" with content as foo_content %} +{% use "bar.twig" %} + +{{ block('content') }} +{{ block('foo') }} +{{ block('bar') }} +{{ block('foo_content') }} +--TEMPLATE(foo.twig)-- +{% block content 'foo' %} +{% block foo 'foo' %} +--TEMPLATE(bar.twig)-- +{% block content 'bar' %} +{% block bar 'bar' %} +--DATA-- +return array() +--EXPECT-- +bar +foo +bar +foo diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test new file mode 100755 index 0000000..59db23d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig' with foobar as base_base_foobar %} +{% block foobar %} + {{- block('base_base_foobar') -}} + Content of block (second override) +{% endblock foobar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' with foobar as base_foobar %} +{% block foobar %} + {{- block('base_foobar') -}} + Content of block (first override) +{% endblock foobar %} +--TEMPLATE(file1.html.twig)-- +{% block foobar -%} + Content of block +{% endblock foobar %} +--DATA-- +return array() +--EXPECT-- +Content of block +Content of block (first override) +Content of block (second override) diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test new file mode 100755 index 0000000..d3f302d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig'%} +{% block foobar %} + {{- parent() -}} + Content of block (second override) +{% endblock foobar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' %} +{% block foobar %} + {{- parent() -}} + Content of block (first override) +{% endblock foobar %} +--TEMPLATE(file1.html.twig)-- +{% block foobar -%} + Content of block +{% endblock foobar %} +--DATA-- +return array() +--EXPECT-- +Content of block +Content of block (first override) +Content of block (second override) diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test new file mode 100755 index 0000000..95b55a4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test @@ -0,0 +1,38 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig' %} +{% use 'file1.html.twig' with foo %} +{% block foo %} + {{- parent() -}} + Content of foo (second override) +{% endblock foo %} +{% block bar %} + {{- parent() -}} + Content of bar (second override) +{% endblock bar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' %} +{% block foo %} + {{- parent() -}} + Content of foo (first override) +{% endblock foo %} +{% block bar %} + {{- parent() -}} + Content of bar (first override) +{% endblock bar %} +--TEMPLATE(file1.html.twig)-- +{% block foo -%} + Content of foo +{% endblock foo %} +{% block bar -%} + Content of bar +{% endblock bar %} +--DATA-- +return array() +--EXPECT-- +Content of foo +Content of foo (first override) +Content of foo (second override) +Content of bar +Content of bar (second override) diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/basic.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/basic.test new file mode 100755 index 0000000..a95be55 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/basic.test @@ -0,0 +1,10 @@ +--TEST-- +"verbatim" tag +--TEMPLATE-- +{% verbatim %} +{{ foo }} +{% endverbatim %} +--DATA-- +return array() +--EXPECT-- +{{ foo }} diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test new file mode 100755 index 0000000..941dddc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/mixed_usage_with_raw.test @@ -0,0 +1,10 @@ +--TEST-- +"verbatim" tag +--TEMPLATE-- +{% verbatim %} +{{ foo }} +{% endraw %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Syntax: Unexpected end of file: Unclosed "verbatim" block in "index.twig" at line 2 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test new file mode 100755 index 0000000..eb61044 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/verbatim/whitespace_control.test @@ -0,0 +1,56 @@ +--TEST-- +"verbatim" tag +--TEMPLATE-- +1*** + +{%- verbatim %} + {{ 'bla' }} +{% endverbatim %} + +1*** +2*** + +{%- verbatim -%} + {{ 'bla' }} +{% endverbatim %} + +2*** +3*** + +{%- verbatim -%} + {{ 'bla' }} +{% endverbatim -%} + +3*** +4*** + +{%- verbatim -%} + {{ 'bla' }} +{%- endverbatim %} + +4*** +5*** + +{%- verbatim -%} + {{ 'bla' }} +{%- endverbatim -%} + +5*** +--DATA-- +return array() +--EXPECT-- +1*** + {{ 'bla' }} + + +1*** +2***{{ 'bla' }} + + +2*** +3***{{ 'bla' }} +3*** +4***{{ 'bla' }} + +4*** +5***{{ 'bla' }}5*** diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/array.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/array.test new file mode 100755 index 0000000..1429d37 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/array.test @@ -0,0 +1,24 @@ +--TEST-- +array index test +--TEMPLATE-- +{% for key, value in days %} +{{ key }} +{% endfor %} +--DATA-- +return array('days' => array( + 1 => array('money' => 9), + 2 => array('money' => 21), + 3 => array('money' => 38), + 4 => array('money' => 6), + 18 => array('money' => 6), + 19 => array('money' => 3), + 31 => array('money' => 11), +)); +--EXPECT-- +1 +2 +3 +4 +18 +19 +31 diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/constant.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/constant.test new file mode 100755 index 0000000..60218ac --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/constant.test @@ -0,0 +1,14 @@ +--TEST-- +"const" test +--TEMPLATE-- +{{ 8 is constant('E_NOTICE') ? 'ok' : 'no' }} +{{ 'bar' is constant('TwigTestFoo::BAR_NAME') ? 'ok' : 'no' }} +{{ value is constant('TwigTestFoo::BAR_NAME') ? 'ok' : 'no' }} +{{ 2 is constant('ARRAY_AS_PROPS', object) ? 'ok' : 'no' }} +--DATA-- +return array('value' => 'bar', 'object' => new ArrayObject(array('hi'))); +--EXPECT-- +ok +ok +ok +ok \ No newline at end of file diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined.test new file mode 100755 index 0000000..cbfe03d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/defined.test @@ -0,0 +1,108 @@ +--TEST-- +"defined" test +--TEMPLATE-- +{{ definedVar is defined ? 'ok' : 'ko' }} +{{ definedVar is not defined ? 'ko' : 'ok' }} +{{ undefinedVar is defined ? 'ko' : 'ok' }} +{{ undefinedVar is not defined ? 'ok' : 'ko' }} +{{ zeroVar is defined ? 'ok' : 'ko' }} +{{ nullVar is defined ? 'ok' : 'ko' }} +{{ nested.definedVar is defined ? 'ok' : 'ko' }} +{{ nested['definedVar'] is defined ? 'ok' : 'ko' }} +{{ nested.definedVar is not defined ? 'ko' : 'ok' }} +{{ nested.undefinedVar is defined ? 'ko' : 'ok' }} +{{ nested['undefinedVar'] is defined ? 'ko' : 'ok' }} +{{ nested.undefinedVar is not defined ? 'ok' : 'ko' }} +{{ nested.zeroVar is defined ? 'ok' : 'ko' }} +{{ nested.nullVar is defined ? 'ok' : 'ko' }} +{{ nested.definedArray.0 is defined ? 'ok' : 'ko' }} +{{ nested['definedArray'][0] is defined ? 'ok' : 'ko' }} +{{ object.foo is defined ? 'ok' : 'ko' }} +{{ object.undefinedMethod is defined ? 'ko' : 'ok' }} +{{ object.getFoo() is defined ? 'ok' : 'ko' }} +{{ object.getFoo('a') is defined ? 'ok' : 'ko' }} +{{ object.undefinedMethod() is defined ? 'ko' : 'ok' }} +{{ object.undefinedMethod('a') is defined ? 'ko' : 'ok' }} +{{ object.self.foo is defined ? 'ok' : 'ko' }} +{{ object.self.undefinedMethod is defined ? 'ko' : 'ok' }} +{{ object.undefinedMethod.self is defined ? 'ko' : 'ok' }} +--DATA-- +return array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'nested' => array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'definedArray' => array(0), + ), + 'object' => new TwigTestFoo(), +); +--EXPECT-- +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +--DATA-- +return array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'nested' => array( + 'definedVar' => 'defined', + 'zeroVar' => 0, + 'nullVar' => null, + 'definedArray' => array(0), + ), + 'object' => new TwigTestFoo(), +); +--CONFIG-- +return array('strict_variables' => false) +--EXPECT-- +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok +ok diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/empty.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/empty.test new file mode 100755 index 0000000..a776d03 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/empty.test @@ -0,0 +1,45 @@ +--TEST-- +"empty" test +--TEMPLATE-- +{{ foo is empty ? 'ok' : 'ko' }} +{{ bar is empty ? 'ok' : 'ko' }} +{{ foobar is empty ? 'ok' : 'ko' }} +{{ array is empty ? 'ok' : 'ko' }} +{{ zero is empty ? 'ok' : 'ko' }} +{{ string is empty ? 'ok' : 'ko' }} +{{ countable_empty is empty ? 'ok' : 'ko' }} +{{ countable_not_empty is empty ? 'ok' : 'ko' }} +{{ markup_empty is empty ? 'ok' : 'ko' }} +{{ markup_not_empty is empty ? 'ok' : 'ko' }} +--DATA-- + +class CountableStub implements Countable +{ + private $items; + + public function __construct(array $items) + { + $this->items = $items; + } + + public function count() + { + return count($this->items); + } +} +return array( + 'foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0', + 'countable_empty' => new CountableStub(array()), 'countable_not_empty' => new CountableStub(array(1, 2)), + 'markup_empty' => new Twig_Markup('', 'UTF-8'), 'markup_not_empty' => new Twig_Markup('test', 'UTF-8'), +); +--EXPECT-- +ok +ok +ok +ok +ko +ko +ok +ko +ok +ko diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/even.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/even.test new file mode 100755 index 0000000..695b4c2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/even.test @@ -0,0 +1,14 @@ +--TEST-- +"even" test +--TEMPLATE-- +{{ 1 is even ? 'ko' : 'ok' }} +{{ 2 is even ? 'ok' : 'ko' }} +{{ 1 is not even ? 'ok' : 'ko' }} +{{ 2 is not even ? 'ko' : 'ok' }} +--DATA-- +return array() +--EXPECT-- +ok +ok +ok +ok diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in.test new file mode 100755 index 0000000..545f51f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in.test @@ -0,0 +1,128 @@ +--TEST-- +Twig supports the in operator +--TEMPLATE-- +{% if bar in foo %} +TRUE +{% endif %} +{% if not (bar in foo) %} +{% else %} +TRUE +{% endif %} +{% if bar not in foo %} +{% else %} +TRUE +{% endif %} +{% if 'a' in bar %} +TRUE +{% endif %} +{% if 'c' not in bar %} +TRUE +{% endif %} +{% if '' in bar %} +TRUE +{% endif %} +{% if '' in '' %} +TRUE +{% endif %} +{% if '0' not in '' %} +TRUE +{% endif %} +{% if 'a' not in '0' %} +TRUE +{% endif %} +{% if '0' in '0' %} +TRUE +{% endif %} + +{{ false in [0, 1] ? 'TRUE' : 'FALSE' }} +{{ true in [0, 1] ? 'TRUE' : 'FALSE' }} +{{ '0' in [0, 1] ? 'TRUE' : 'FALSE' }} +{{ '' in [0, 1] ? 'TRUE' : 'FALSE' }} +{{ 0 in ['', 1] ? 'TRUE' : 'FALSE' }} + +{{ '' in 'foo' ? 'TRUE' : 'FALSE' }} +{{ 0 in 'foo' ? 'TRUE' : 'FALSE' }} +{{ false in 'foo' ? 'TRUE' : 'FALSE' }} +{{ false in '100' ? 'TRUE' : 'FALSE' }} +{{ true in '100' ? 'TRUE' : 'FALSE' }} + +{{ [] in [true, false] ? 'TRUE' : 'FALSE' }} +{{ [] in [true, ''] ? 'TRUE' : 'FALSE' }} +{{ [] in [true, []] ? 'TRUE' : 'FALSE' }} + +{{ resource ? 'TRUE' : 'FALSE' }} +{{ resource in 'foo'~resource ? 'TRUE' : 'FALSE' }} +{{ object in 'stdClass' ? 'TRUE' : 'FALSE' }} +{{ [] in 'Array' ? 'TRUE' : 'FALSE' }} +{{ dir_object in 'foo'~dir_object ? 'TRUE' : 'FALSE' }} + +{{ ''~resource in resource ? 'TRUE' : 'FALSE' }} +{{ 'stdClass' in object ? 'TRUE' : 'FALSE' }} +{{ 'Array' in [] ? 'TRUE' : 'FALSE' }} +{{ ''~dir_object in dir_object ? 'TRUE' : 'FALSE' }} + +{{ resource in [''~resource] ? 'TRUE' : 'FALSE' }} +{{ resource in [resource + 1 - 1] ? 'TRUE' : 'FALSE' }} +{{ dir_object in [''~dir_object] ? 'TRUE' : 'FALSE' }} + +{{ 5 in 125 ? 'TRUE' : 'FALSE' }} +{{ 5 in '125' ? 'TRUE' : 'FALSE' }} +{{ '5' in 125 ? 'TRUE' : 'FALSE' }} +{{ '5' in '125' ? 'TRUE' : 'FALSE' }} + +{{ 5.5 in 125.5 ? 'TRUE' : 'FALSE' }} +{{ 5.5 in '125.5' ? 'TRUE' : 'FALSE' }} +{{ '5.5' in 125.5 ? 'TRUE' : 'FALSE' }} +--DATA-- +return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'dir_object' => new SplFileInfo(dirname(__FILE__)), 'object' => new stdClass(), 'resource' => opendir(dirname(__FILE__))) +--EXPECT-- +TRUE +TRUE +TRUE +TRUE +TRUE +TRUE +TRUE +TRUE +TRUE +TRUE + +TRUE +TRUE +TRUE +TRUE +TRUE + +TRUE +FALSE +FALSE +FALSE +FALSE + +TRUE +FALSE +TRUE + +TRUE +FALSE +FALSE +FALSE +FALSE + +FALSE +FALSE +FALSE +FALSE + +FALSE +FALSE +FALSE + +FALSE +TRUE +FALSE +TRUE + +FALSE +TRUE +FALSE diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in_with_objects.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in_with_objects.test new file mode 100755 index 0000000..8e08061 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/in_with_objects.test @@ -0,0 +1,19 @@ +--TEST-- +Twig supports the in operator when using objects +--TEMPLATE-- +{% if object in object_list %} +TRUE +{% endif %} +--DATA-- +$foo = new TwigTestFoo(); +$foo1 = new TwigTestFoo(); + +$foo->position = $foo1; +$foo1->position = $foo; + +return array( + 'object' => $foo, + 'object_list' => array($foo1, $foo), +); +--EXPECT-- +TRUE diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/iterable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/iterable.test new file mode 100755 index 0000000..ec52550 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/iterable.test @@ -0,0 +1,19 @@ +--TEST-- +"iterable" test +--TEMPLATE-- +{{ foo is iterable ? 'ok' : 'ko' }} +{{ traversable is iterable ? 'ok' : 'ko' }} +{{ obj is iterable ? 'ok' : 'ko' }} +{{ val is iterable ? 'ok' : 'ko' }} +--DATA-- +return array( + 'foo' => array(), + 'traversable' => new ArrayIterator(array()), + 'obj' => new stdClass(), + 'val' => 'test', +); +--EXPECT-- +ok +ok +ko +ko \ No newline at end of file diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/odd.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/odd.test new file mode 100755 index 0000000..1b8311e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tests/odd.test @@ -0,0 +1,10 @@ +--TEST-- +"odd" test +--TEMPLATE-- +{{ 1 is odd ? 'ok' : 'ko' }} +{{ 2 is odd ? 'ko' : 'ok' }} +--DATA-- +return array() +--EXPECT-- +ok +ok \ No newline at end of file diff --git a/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php b/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php new file mode 100755 index 0000000..70f9b80 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php @@ -0,0 +1,229 @@ +position = 0; + } + + public function current() + { + return $this->array[$this->position]; + } + + public function key() + { + return 'a'; + } + + public function next() + { + ++$this->position; + } + + public function valid() + { + return isset($this->array[$this->position]); + } +} + +class TwigTestTokenParser_§ extends Twig_TokenParser +{ + public function parse(Twig_Token $token) + { + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + + return new Twig_Node_Print(new Twig_Node_Expression_Constant('§', -1), -1); + } + + public function getTag() + { + return '§'; + } +} + +class TwigTestExtension extends Twig_Extension +{ + public function getTokenParsers() + { + return array( + new TwigTestTokenParser_§(), + ); + } + + public function getFilters() + { + return array( + new Twig_SimpleFilter('§', array($this, '§Filter')), + new Twig_SimpleFilter('escape_and_nl2br', array($this, 'escape_and_nl2br'), array('needs_environment' => true, 'is_safe' => array('html'))), + new Twig_SimpleFilter('nl2br', array($this, 'nl2br'), array('pre_escape' => 'html', 'is_safe' => array('html'))), + new Twig_SimpleFilter('escape_something', array($this, 'escape_something'), array('is_safe' => array('something'))), + new Twig_SimpleFilter('preserves_safety', array($this, 'preserves_safety'), array('preserves_safety' => array('html'))), + new Twig_SimpleFilter('*_path', array($this, 'dynamic_path')), + new Twig_SimpleFilter('*_foo_*_bar', array($this, 'dynamic_foo')), + ); + } + + public function getFunctions() + { + return array( + new Twig_SimpleFunction('§', array($this, '§Function')), + new Twig_SimpleFunction('safe_br', array($this, 'br'), array('is_safe' => array('html'))), + new Twig_SimpleFunction('unsafe_br', array($this, 'br')), + new Twig_SimpleFunction('*_path', array($this, 'dynamic_path')), + new Twig_SimpleFunction('*_foo_*_bar', array($this, 'dynamic_foo')), + ); + } + + public function getTests() + { + return array( + new Twig_SimpleTest('multi word', array($this, 'is_multi_word')), + ); + } + + public function §Filter($value) + { + return "§{$value}§"; + } + + public function §Function($value) + { + return "§{$value}§"; + } + + /** + * nl2br which also escapes, for testing escaper filters + */ + public function escape_and_nl2br($env, $value, $sep = '
    ') + { + return $this->nl2br(twig_escape_filter($env, $value, 'html'), $sep); + } + + /** + * nl2br only, for testing filters with pre_escape + */ + public function nl2br($value, $sep = '
    ') + { + // not secure if $value contains html tags (not only entities) + // don't use + return str_replace("\n", "$sep\n", $value); + } + + public function dynamic_path($element, $item) + { + return $element.'/'.$item; + } + + public function dynamic_foo($foo, $bar, $item) + { + return $foo.'/'.$bar.'/'.$item; + } + + public function escape_something($value) + { + return strtoupper($value); + } + + public function preserves_safety($value) + { + return strtoupper($value); + } + + public function br() + { + return '
    '; + } + + public function is_multi_word($value) + { + return false !== strpos($value, ' '); + } + + public function getName() + { + return 'integration_test'; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/LexerTest.php b/vendor/twig/twig/test/Twig/Tests/LexerTest.php new file mode 100755 index 0000000..4ef58e5 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/LexerTest.php @@ -0,0 +1,300 @@ +tokenize($template); + + $stream->expect(Twig_Token::BLOCK_START_TYPE); + $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue()); + } + + public function testNameLabelForFunction() + { + $template = '{{ §() }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + + $stream->expect(Twig_Token::VAR_START_TYPE); + $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue()); + } + + public function testBracketsNesting() + { + $template = '{{ {"a":{"b":"c"}} }}'; + + $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '{')); + $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '}')); + } + + protected function countToken($template, $type, $value = null) + { + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + + $count = 0; + while (!$stream->isEOF()) { + $token = $stream->next(); + if ($type === $token->getType()) { + if (null === $value || $value === $token->getValue()) { + ++$count; + } + } + } + + return $count; + } + + public function testLineDirective() + { + $template = "foo\n" + ."bar\n" + ."{% line 10 %}\n" + ."{{\n" + ."baz\n" + ."}}\n"; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + + // foo\nbar\n + $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); + // \n (after {% line %}) + $this->assertSame(10, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); + // {{ + $this->assertSame(11, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine()); + // baz + $this->assertSame(12, $stream->expect(Twig_Token::NAME_TYPE)->getLine()); + } + + public function testLineDirectiveInline() + { + $template = "foo\n" + ."bar{% line 10 %}{{\n" + ."baz\n" + ."}}\n"; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + + // foo\nbar + $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); + // {{ + $this->assertSame(10, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine()); + // baz + $this->assertSame(11, $stream->expect(Twig_Token::NAME_TYPE)->getLine()); + } + + public function testLongComments() + { + $template = '{# '.str_repeat('*', 100000).' #}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + + // should not throw an exception + } + + public function testLongRaw() + { + $template = '{% raw %}'.str_repeat('*', 100000).'{% endraw %}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + + // should not throw an exception + } + + public function testLongVar() + { + $template = '{{ '.str_repeat('x', 100000).' }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + + // should not throw an exception + } + + public function testLongBlock() + { + $template = '{% '.str_repeat('x', 100000).' %}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + + // should not throw an exception + } + + public function testBigNumbers() + { + $template = '{{ 922337203685477580700 }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->next(); + $node = $stream->next(); + $this->assertEquals("922337203685477580700", $node->getValue()); + } + + public function testStringWithEscapedDelimiter() + { + $tests = array( + "{{ 'foo \' bar' }}" => 'foo \' bar', + '{{ "foo \" bar" }}' => "foo \" bar", + ); + $lexer = new Twig_Lexer(new Twig_Environment()); + foreach ($tests as $template => $expected) { + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, $expected); + } + } + + public function testStringWithInterpolation() + { + $template = 'foo {{ "bar #{ baz + 1 }" }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::TEXT_TYPE, 'foo '); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, 'bar '); + $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); + $stream->expect(Twig_Token::NAME_TYPE, 'baz'); + $stream->expect(Twig_Token::OPERATOR_TYPE, '+'); + $stream->expect(Twig_Token::NUMBER_TYPE, '1'); + $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); + $stream->expect(Twig_Token::VAR_END_TYPE); + } + + public function testStringWithEscapedInterpolation() + { + $template = '{{ "bar \#{baz+1}" }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, 'bar #{baz+1}'); + $stream->expect(Twig_Token::VAR_END_TYPE); + } + + public function testStringWithHash() + { + $template = '{{ "bar # baz" }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, 'bar # baz'); + $stream->expect(Twig_Token::VAR_END_TYPE); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unclosed """ + */ + public function testStringWithUnterminatedInterpolation() + { + $template = '{{ "bar #{x" }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + } + + public function testStringWithNestedInterpolations() + { + $template = '{{ "bar #{ "foo#{bar}" }" }}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, 'bar '); + $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, 'foo'); + $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); + $stream->expect(Twig_Token::NAME_TYPE, 'bar'); + $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); + $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); + $stream->expect(Twig_Token::VAR_END_TYPE); + } + + public function testStringWithNestedInterpolationsInBlock() + { + $template = '{% foo "bar #{ "foo#{bar}" }" %}'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::BLOCK_START_TYPE); + $stream->expect(Twig_Token::NAME_TYPE, 'foo'); + $stream->expect(Twig_Token::STRING_TYPE, 'bar '); + $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, 'foo'); + $stream->expect(Twig_Token::INTERPOLATION_START_TYPE); + $stream->expect(Twig_Token::NAME_TYPE, 'bar'); + $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); + $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); + $stream->expect(Twig_Token::BLOCK_END_TYPE); + } + + public function testOperatorEndingWithALetterAtTheEndOfALine() + { + $template = "{{ 1 and\n0}}"; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::NUMBER_TYPE, 1); + $stream->expect(Twig_Token::OPERATOR_TYPE, 'and'); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unclosed "variable" at line 3 + */ + public function testUnterminatedVariable() + { + $template = ' + +{{ + +bar + + +'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unclosed "block" at line 3 + */ + public function testUnterminatedBlock() + { + $template = ' + +{% + +bar + + +'; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $lexer->tokenize($template); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php b/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php new file mode 100755 index 0000000..1369a6b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/ArrayTest.php @@ -0,0 +1,97 @@ + 'bar')); + + $this->assertEquals('bar', $loader->getSource('foo')); + } + + /** + * @expectedException Twig_Error_Loader + */ + public function testGetSourceWhenTemplateDoesNotExist() + { + $loader = new Twig_Loader_Array(array()); + + $loader->getSource('foo'); + } + + public function testGetCacheKey() + { + $loader = new Twig_Loader_Array(array('foo' => 'bar')); + + $this->assertEquals('bar', $loader->getCacheKey('foo')); + } + + /** + * @expectedException Twig_Error_Loader + */ + public function testGetCacheKeyWhenTemplateDoesNotExist() + { + $loader = new Twig_Loader_Array(array()); + + $loader->getCacheKey('foo'); + } + + public function testSetTemplate() + { + $loader = new Twig_Loader_Array(array()); + $loader->setTemplate('foo', 'bar'); + + $this->assertEquals('bar', $loader->getSource('foo')); + } + + public function testIsFresh() + { + $loader = new Twig_Loader_Array(array('foo' => 'bar')); + $this->assertTrue($loader->isFresh('foo', time())); + } + + /** + * @expectedException Twig_Error_Loader + */ + public function testIsFreshWhenTemplateDoesNotExist() + { + $loader = new Twig_Loader_Array(array()); + + $loader->isFresh('foo', time()); + } + + public function testTemplateReference() + { + $name = new Twig_Test_Loader_TemplateReference('foo'); + $loader = new Twig_Loader_Array(array('foo' => 'bar')); + + $loader->getCacheKey($name); + $loader->getSource($name); + $loader->isFresh($name, time()); + $loader->setTemplate($name, 'foobar'); + } +} + +class Twig_Test_Loader_TemplateReference +{ + private $name; + + public function __construct($name) + { + $this->name = $name; + } + + public function __toString() + { + return $this->name; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php b/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php new file mode 100755 index 0000000..4fe0db9 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php @@ -0,0 +1,79 @@ + 'bar')), + new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')), + )); + + $this->assertEquals('bar', $loader->getSource('foo')); + $this->assertEquals('foo', $loader->getSource('bar')); + } + + /** + * @expectedException Twig_Error_Loader + */ + public function testGetSourceWhenTemplateDoesNotExist() + { + $loader = new Twig_Loader_Chain(array()); + + $loader->getSource('foo'); + } + + public function testGetCacheKey() + { + $loader = new Twig_Loader_Chain(array( + new Twig_Loader_Array(array('foo' => 'bar')), + new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')), + )); + + $this->assertEquals('bar', $loader->getCacheKey('foo')); + $this->assertEquals('foo', $loader->getCacheKey('bar')); + } + + /** + * @expectedException Twig_Error_Loader + */ + public function testGetCacheKeyWhenTemplateDoesNotExist() + { + $loader = new Twig_Loader_Chain(array()); + + $loader->getCacheKey('foo'); + } + + public function testAddLoader() + { + $loader = new Twig_Loader_Chain(); + $loader->addLoader(new Twig_Loader_Array(array('foo' => 'bar'))); + + $this->assertEquals('bar', $loader->getSource('foo')); + } + + public function testExists() + { + $loader1 = $this->getMock('Twig_Loader_Array', array('exists', 'getSource'), array(), '', false); + $loader1->expects($this->once())->method('exists')->will($this->returnValue(false)); + $loader1->expects($this->never())->method('getSource'); + + $loader2 = $this->getMock('Twig_LoaderInterface'); + $loader2->expects($this->once())->method('getSource')->will($this->returnValue('content')); + + $loader = new Twig_Loader_Chain(); + $loader->addLoader($loader1); + $loader->addLoader($loader2); + + $this->assertTrue($loader->exists('foo')); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php b/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php new file mode 100755 index 0000000..e07f374 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/FilesystemTest.php @@ -0,0 +1,175 @@ +getCacheKey($template); + $this->fail(); + } catch (Twig_Error_Loader $e) { + $this->assertNotContains('Unable to find template', $e->getMessage()); + } + } + + public function getSecurityTests() + { + return array( + array("AutoloaderTest\0.php"), + array('..\\AutoloaderTest.php'), + array('..\\\\\\AutoloaderTest.php'), + array('../AutoloaderTest.php'), + array('..////AutoloaderTest.php'), + array('./../AutoloaderTest.php'), + array('.\\..\\AutoloaderTest.php'), + array('././././././../AutoloaderTest.php'), + array('.\\./.\\./.\\./../AutoloaderTest.php'), + array('foo/../../AutoloaderTest.php'), + array('foo\\..\\..\\AutoloaderTest.php'), + array('foo/../bar/../../AutoloaderTest.php'), + array('foo/bar/../../../AutoloaderTest.php'), + array('filters/../../AutoloaderTest.php'), + array('filters//..//..//AutoloaderTest.php'), + array('filters\\..\\..\\AutoloaderTest.php'), + array('filters\\\\..\\\\..\\\\AutoloaderTest.php'), + array('filters\\//../\\/\\..\\AutoloaderTest.php'), + array('/../AutoloaderTest.php'), + ); + } + + public function testPaths() + { + $basePath = dirname(__FILE__).'/Fixtures'; + + $loader = new Twig_Loader_Filesystem(array($basePath.'/normal', $basePath.'/normal_bis')); + $loader->setPaths(array($basePath.'/named', $basePath.'/named_bis'), 'named'); + $loader->addPath($basePath.'/named_ter', 'named'); + $loader->addPath($basePath.'/normal_ter'); + $loader->prependPath($basePath.'/normal_final'); + $loader->prependPath($basePath.'/named/../named_quater', 'named'); + $loader->prependPath($basePath.'/named_final', 'named'); + + $this->assertEquals(array( + $basePath.'/normal_final', + $basePath.'/normal', + $basePath.'/normal_bis', + $basePath.'/normal_ter', + ), $loader->getPaths()); + $this->assertEquals(array( + $basePath.'/named_final', + $basePath.'/named/../named_quater', + $basePath.'/named', + $basePath.'/named_bis', + $basePath.'/named_ter', + ), $loader->getPaths('named')); + + $this->assertEquals( + realpath($basePath.'/named_quater/named_absolute.html'), + realpath($loader->getCacheKey('@named/named_absolute.html')) + ); + $this->assertEquals("path (final)\n", $loader->getSource('index.html')); + $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html')); + $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); + } + + public function testEmptyConstructor() + { + $loader = new Twig_Loader_Filesystem(); + $this->assertEquals(array(), $loader->getPaths()); + } + + public function testGetNamespaces() + { + $loader = new Twig_Loader_Filesystem(sys_get_temp_dir()); + $this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE), $loader->getNamespaces()); + + $loader->addPath(sys_get_temp_dir(), 'named'); + $this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'), $loader->getNamespaces()); + } + + public function testFindTemplateExceptionNamespace() + { + $basePath = dirname(__FILE__).'/Fixtures'; + + $loader = new Twig_Loader_Filesystem(array($basePath.'/normal')); + $loader->addPath($basePath.'/named', 'named'); + + try { + $loader->getSource('@named/nowhere.html'); + } catch (Exception $e) { + $this->assertInstanceof('Twig_Error_Loader', $e); + $this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage()); + } + } + + public function testFindTemplateWithCache() + { + $basePath = dirname(__FILE__).'/Fixtures'; + + $loader = new Twig_Loader_Filesystem(array($basePath.'/normal')); + $loader->addPath($basePath.'/named', 'named'); + + // prime the cache for index.html in the named namespace + $namedSource = $loader->getSource('@named/index.html'); + $this->assertEquals("named path\n", $namedSource); + + // get index.html from the main namespace + $this->assertEquals("path\n", $loader->getSource('index.html')); + } + + public function testLoadTemplateAndRenderBlockWithCache() + { + $loader = new Twig_Loader_Filesystem(array()); + $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme2'); + $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1'); + $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1', 'default_theme'); + + $twig = new Twig_Environment($loader); + + $template = $twig->loadTemplate('blocks.html.twig'); + $this->assertSame('block from theme 1', $template->renderBlock('b1', array())); + + $template = $twig->loadTemplate('blocks.html.twig'); + $this->assertSame('block from theme 2', $template->renderBlock('b2', array())); + } + + public function getArrayInheritanceTests() + { + return array( + 'valid array inheritance' => array('array_inheritance_valid_parent.html.twig'), + 'array inheritance with null first template' => array('array_inheritance_null_parent.html.twig'), + 'array inheritance with empty first template' => array('array_inheritance_empty_parent.html.twig'), + 'array inheritance with non-existent first template' => array('array_inheritance_nonexistent_parent.html.twig'), + ); + } + + /** + * @dataProvider getArrayInheritanceTests + * + * @param $templateName string Template name with array inheritance + */ + public function testArrayInheritance($templateName) + { + $loader = new Twig_Loader_Filesystem(array()); + $loader->addPath(dirname(__FILE__).'/Fixtures/inheritance'); + + $twig = new Twig_Environment($loader); + + $template = $twig->loadTemplate($templateName); + $this->assertSame('VALID Child', $template->renderBlock('body', array())); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_empty_parent.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_empty_parent.html.twig new file mode 100755 index 0000000..6977ebf --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_empty_parent.html.twig @@ -0,0 +1,3 @@ +{% extends ['','parent.html.twig'] %} + +{% block body %}{{ parent() }} Child{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_nonexistent_parent.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_nonexistent_parent.html.twig new file mode 100755 index 0000000..5b50a8b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_nonexistent_parent.html.twig @@ -0,0 +1,3 @@ +{% extends ['nonexistent.html.twig','parent.html.twig'] %} + +{% block body %}{{ parent() }} Child{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_null_parent.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_null_parent.html.twig new file mode 100755 index 0000000..a16b3ad --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_null_parent.html.twig @@ -0,0 +1,3 @@ +{% extends [null,'parent.html.twig'] %} + +{% block body %}{{ parent() }} Child{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_valid_parent.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_valid_parent.html.twig new file mode 100755 index 0000000..4940dad --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/array_inheritance_valid_parent.html.twig @@ -0,0 +1,3 @@ +{% extends ['parent.html.twig','spare_parent.html.twig'] %} + +{% block body %}{{ parent() }} Child{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/parent.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/parent.html.twig new file mode 100755 index 0000000..d594c0e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/parent.html.twig @@ -0,0 +1 @@ +{% block body %}VALID{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/spare_parent.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/spare_parent.html.twig new file mode 100755 index 0000000..70b7360 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/inheritance/spare_parent.html.twig @@ -0,0 +1 @@ +{% block body %}SPARE PARENT{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named/index.html new file mode 100755 index 0000000..9e5449c --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named/index.html @@ -0,0 +1 @@ +named path diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_bis/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_bis/index.html new file mode 100755 index 0000000..d3a272b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_bis/index.html @@ -0,0 +1 @@ +named path (bis) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_final/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_final/index.html new file mode 100755 index 0000000..9f05d15 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_final/index.html @@ -0,0 +1 @@ +named path (final) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html new file mode 100755 index 0000000..b1fb5f5 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html @@ -0,0 +1 @@ +named path (quater) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_ter/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_ter/index.html new file mode 100755 index 0000000..24fb68a --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/named_ter/index.html @@ -0,0 +1 @@ +named path (ter) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal/index.html new file mode 100755 index 0000000..e7a8fd4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal/index.html @@ -0,0 +1 @@ +path diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_bis/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_bis/index.html new file mode 100755 index 0000000..bfa9160 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_bis/index.html @@ -0,0 +1 @@ +path (bis) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_final/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_final/index.html new file mode 100755 index 0000000..73a089b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_final/index.html @@ -0,0 +1 @@ +path (final) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_ter/index.html b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_ter/index.html new file mode 100755 index 0000000..b7ad97d --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/normal_ter/index.html @@ -0,0 +1 @@ +path (ter) diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig new file mode 100755 index 0000000..dd0cbc2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme1/blocks.html.twig @@ -0,0 +1,3 @@ +{% block b1 %}block from theme 1{% endblock %} + +{% block b2 %}block from theme 1{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig new file mode 100755 index 0000000..07cf9db --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Loader/Fixtures/themes/theme2/blocks.html.twig @@ -0,0 +1,3 @@ +{% use '@default_theme/blocks.html.twig' %} + +{% block b2 %}block from theme 2{% endblock %} diff --git a/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php b/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php new file mode 100755 index 0000000..36b6329 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php @@ -0,0 +1,33 @@ +markTestSkipped('Skip under HHVM as the behavior is not the same as plain PHP (which is an edge case anyway)'); + } + + $twig = new Twig_Environment(new Twig_Loader_Array(array('index' => '{{ d1.date }}{{ d2.date }}')), array( + 'debug' => true, + 'cache' => false, + 'autoescape' => false, + )); + + $d1 = new DateTime(); + $d2 = new DateTime(); + $output = $twig->render('index', compact('d1', 'd2')); + + // If it fails, PHP will crash. + $this->assertEquals($output, $d1->date.$d2->date); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/AutoEscapeTest.php b/vendor/twig/twig/test/Twig/Tests/Node/AutoEscapeTest.php new file mode 100755 index 0000000..25d1602 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/AutoEscapeTest.php @@ -0,0 +1,32 @@ +assertEquals($body, $node->getNode('body')); + $this->assertTrue($node->getAttribute('value')); + } + + public function getTests() + { + $body = new Twig_Node(array(new Twig_Node_Text('foo', 1))); + $node = new Twig_Node_AutoEscape(true, $body, 1); + + return array( + array($node, "// line 1\necho \"foo\";"), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/BlockReferenceTest.php b/vendor/twig/twig/test/Twig/Tests/Node/BlockReferenceTest.php new file mode 100755 index 0000000..84dac9b --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/BlockReferenceTest.php @@ -0,0 +1,31 @@ +assertEquals('foo', $node->getAttribute('name')); + } + + public function getTests() + { + return array( + array(new Twig_Node_BlockReference('foo', 1), <<displayBlock('foo', \$context, \$blocks); +EOF + ), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/BlockTest.php b/vendor/twig/twig/test/Twig/Tests/Node/BlockTest.php new file mode 100755 index 0000000..e7246dc --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/BlockTest.php @@ -0,0 +1,39 @@ +assertEquals($body, $node->getNode('body')); + $this->assertEquals('foo', $node->getAttribute('name')); + } + + public function getTests() + { + $body = new Twig_Node_Text('foo', 1); + $node = new Twig_Node_Block('foo', $body, 1); + + return array( + array($node, <<assertEquals($expr, $node->getNode('expr')); + } + + public function getTests() + { + $tests = array(); + + $expr = new Twig_Node_Expression_Constant('foo', 1); + $node = new Twig_Node_Do($expr, 1); + $tests[] = array($node, "// line 1\n\"foo\";"); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/ArrayTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ArrayTest.php new file mode 100755 index 0000000..4f83ab1 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ArrayTest.php @@ -0,0 +1,37 @@ +assertEquals($foo, $node->getNode(1)); + } + + public function getTests() + { + $elements = array( + new Twig_Node_Expression_Constant('foo', 1), + new Twig_Node_Expression_Constant('bar', 1), + + new Twig_Node_Expression_Constant('bar', 1), + new Twig_Node_Expression_Constant('foo', 1), + ); + $node = new Twig_Node_Expression_Array($elements, 1); + + return array( + array($node, 'array("foo" => "bar", "bar" => "foo")'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/AssignNameTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/AssignNameTest.php new file mode 100755 index 0000000..bf365de --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/AssignNameTest.php @@ -0,0 +1,29 @@ +assertEquals('foo', $node->getAttribute('name')); + } + + public function getTests() + { + $node = new Twig_Node_Expression_AssignName('foo', 1); + + return array( + array($node, '$context["foo"]'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AddTest.php new file mode 100755 index 0000000..02310a1 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AddTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Add($left, $right, 1); + + return array( + array($node, '(1 + 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AndTest.php new file mode 100755 index 0000000..2df3c8e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/AndTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_And($left, $right, 1); + + return array( + array($node, '(1 && 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php new file mode 100755 index 0000000..759e482 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Concat($left, $right, 1); + + return array( + array($node, '(1 . 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/DivTest.php new file mode 100755 index 0000000..0e54b10 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/DivTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Div($left, $right, 1); + + return array( + array($node, '(1 / 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php new file mode 100755 index 0000000..602888f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 1); + + return array( + array($node, 'intval(floor((1 / 2)))'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ModTest.php new file mode 100755 index 0000000..4c663c7 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/ModTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Mod($left, $right, 1); + + return array( + array($node, '(1 % 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/MulTest.php new file mode 100755 index 0000000..e92c95e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/MulTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Mul($left, $right, 1); + + return array( + array($node, '(1 * 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/OrTest.php new file mode 100755 index 0000000..ec37c83 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/OrTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Or($left, $right, 1); + + return array( + array($node, '(1 || 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/SubTest.php new file mode 100755 index 0000000..061cb27 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Binary/SubTest.php @@ -0,0 +1,34 @@ +assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); + } + + public function getTests() + { + $left = new Twig_Node_Expression_Constant(1, 1); + $right = new Twig_Node_Expression_Constant(2, 1); + $node = new Twig_Node_Expression_Binary_Sub($left, $right, 1); + + return array( + array($node, '(1 - 2)'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php new file mode 100755 index 0000000..af4e351 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/CallTest.php @@ -0,0 +1,102 @@ + 'function', 'name' => 'date')); + $this->assertEquals(array('U', null), $node->getArguments('date', array('format' => 'U', 'timestamp' => null))); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Positional arguments cannot be used after named arguments for function "date". + */ + public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); + $node->getArguments('date', array('timestamp' => 123456, 'Y-m-d')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Argument "format" is defined twice for function "date". + */ + public function testGetArgumentsWhenArgumentIsDefinedTwice() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); + $node->getArguments('date', array('Y-m-d', 'format' => 'U')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unknown argument "unknown" for function "date(format, timestamp)". + */ + public function testGetArgumentsWithWrongNamedArgumentName() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); + $node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown' => '')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)". + */ + public function testGetArgumentsWithWrongNamedArgumentNames() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); + $node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => '')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length". + */ + public function testResolveArgumentsWithMissingValueForOptionalArgument() + { + if (defined('HHVM_VERSION')) { + $this->markTestSkipped('Skip under HHVM as the behavior is not the same as plain PHP (which is an edge case anyway)'); + } + + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'substr_compare')); + $node->getArguments('substr_compare', array('abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true)); + } + + public function testResolveArgumentsOnlyNecessaryArgumentsForCustomFunction() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_function')); + + $this->assertEquals(array('arg1'), $node->getArguments(array($this, 'customFunction'), array('arg1' => 'arg1'))); + } + + public function testGetArgumentsForStaticMethod() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_static_function')); + $this->assertEquals(array('arg1'), $node->getArguments(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1'))); + } + + public static function customStaticFunction($arg1, $arg2 = 'default', $arg3 = array()) + { + } + + public function customFunction($arg1, $arg2 = 'default', $arg3 = array()) + { + } +} + +class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call +{ + public function getArguments($callable, $arguments) + { + return parent::getArguments($callable, $arguments); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/ConditionalTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ConditionalTest.php new file mode 100755 index 0000000..a3e8bad --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ConditionalTest.php @@ -0,0 +1,38 @@ +assertEquals($expr1, $node->getNode('expr1')); + $this->assertEquals($expr2, $node->getNode('expr2')); + $this->assertEquals($expr3, $node->getNode('expr3')); + } + + public function getTests() + { + $tests = array(); + + $expr1 = new Twig_Node_Expression_Constant(1, 1); + $expr2 = new Twig_Node_Expression_Constant(2, 1); + $expr3 = new Twig_Node_Expression_Constant(3, 1); + $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 1); + $tests[] = array($node, '((1) ? (2) : (3))'); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/ConstantTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ConstantTest.php new file mode 100755 index 0000000..2ff9318 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ConstantTest.php @@ -0,0 +1,30 @@ +assertEquals('foo', $node->getAttribute('value')); + } + + public function getTests() + { + $tests = array(); + + $node = new Twig_Node_Expression_Constant('foo', 1); + $tests[] = array($node, '"foo"'); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php new file mode 100755 index 0000000..4aefa7e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/FilterTest.php @@ -0,0 +1,121 @@ +assertEquals($expr, $node->getNode('node')); + $this->assertEquals($name, $node->getNode('filter')); + $this->assertEquals($args, $node->getNode('arguments')); + } + + public function getTests() + { + $tests = array(); + + $expr = new Twig_Node_Expression_Constant('foo', 1); + $node = $this->createFilter($expr, 'upper'); + $node = $this->createFilter($node, 'number_format', array(new Twig_Node_Expression_Constant(2, 1), new Twig_Node_Expression_Constant('.', 1), new Twig_Node_Expression_Constant(',', 1))); + + if (function_exists('mb_get_info')) { + $tests[] = array($node, 'twig_number_format_filter($this->env, twig_upper_filter($this->env, "foo"), 2, ".", ",")'); + } else { + $tests[] = array($node, 'twig_number_format_filter($this->env, strtoupper("foo"), 2, ".", ",")'); + } + + // named arguments + $date = new Twig_Node_Expression_Constant(0, 1); + $node = $this->createFilter($date, 'date', array( + 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), + 'format' => new Twig_Node_Expression_Constant('d/m/Y H:i:s P', 1), + )); + $tests[] = array($node, 'twig_date_format_filter($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")'); + + // skip an optional argument + $date = new Twig_Node_Expression_Constant(0, 1); + $node = $this->createFilter($date, 'date', array( + 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), + )); + $tests[] = array($node, 'twig_date_format_filter($this->env, 0, null, "America/Chicago")'); + + // underscores vs camelCase for named arguments + $string = new Twig_Node_Expression_Constant('abc', 1); + $node = $this->createFilter($string, 'reverse', array( + 'preserve_keys' => new Twig_Node_Expression_Constant(true, 1), + )); + $tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)'); + $node = $this->createFilter($string, 'reverse', array( + 'preserveKeys' => new Twig_Node_Expression_Constant(true, 1), + )); + $tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)'); + + // filter as an anonymous function + if (PHP_VERSION_ID >= 50300) { + $node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous'); + $tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))'); + } + + return $tests; + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unknown argument "foobar" for filter "date(format, timezone)" at line 1. + */ + public function testCompileWithWrongNamedArgumentName() + { + $date = new Twig_Node_Expression_Constant(0, 1); + $node = $this->createFilter($date, 'date', array( + 'foobar' => new Twig_Node_Expression_Constant('America/Chicago', 1), + )); + + $compiler = $this->getCompiler(); + $compiler->compile($node); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Value for argument "from" is required for filter "replace". + */ + public function testCompileWithMissingNamedArgument() + { + $value = new Twig_Node_Expression_Constant(0, 1); + $node = $this->createFilter($value, 'replace', array( + 'to' => new Twig_Node_Expression_Constant('foo', 1), + )); + + $compiler = $this->getCompiler(); + $compiler->compile($node); + } + + protected function createFilter($node, $name, array $arguments = array()) + { + $name = new Twig_Node_Expression_Constant($name, 1); + $arguments = new Twig_Node($arguments); + + return new Twig_Node_Expression_Filter($node, $name, $arguments, 1); + } + + protected function getEnvironment() + { + if (PHP_VERSION_ID >= 50300) { + return include 'PHP53/FilterInclude.php'; + } + + return parent::getEnvironment(); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php new file mode 100755 index 0000000..209b8cf --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/FunctionTest.php @@ -0,0 +1,87 @@ +assertEquals($name, $node->getAttribute('name')); + $this->assertEquals($args, $node->getNode('arguments')); + } + + public function getTests() + { + $environment = new Twig_Environment(); + $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', array())); + $environment->addFunction(new Twig_SimpleFunction('bar', 'bar', array('needs_environment' => true))); + $environment->addFunction(new Twig_SimpleFunction('foofoo', 'foofoo', array('needs_context' => true))); + $environment->addFunction(new Twig_SimpleFunction('foobar', 'foobar', array('needs_environment' => true, 'needs_context' => true))); + + $tests = array(); + + $node = $this->createFunction('foo'); + $tests[] = array($node, 'foo()', $environment); + + $node = $this->createFunction('foo', array(new Twig_Node_Expression_Constant('bar', 1), new Twig_Node_Expression_Constant('foobar', 1))); + $tests[] = array($node, 'foo("bar", "foobar")', $environment); + + $node = $this->createFunction('bar'); + $tests[] = array($node, 'bar($this->env)', $environment); + + $node = $this->createFunction('bar', array(new Twig_Node_Expression_Constant('bar', 1))); + $tests[] = array($node, 'bar($this->env, "bar")', $environment); + + $node = $this->createFunction('foofoo'); + $tests[] = array($node, 'foofoo($context)', $environment); + + $node = $this->createFunction('foofoo', array(new Twig_Node_Expression_Constant('bar', 1))); + $tests[] = array($node, 'foofoo($context, "bar")', $environment); + + $node = $this->createFunction('foobar'); + $tests[] = array($node, 'foobar($this->env, $context)', $environment); + + $node = $this->createFunction('foobar', array(new Twig_Node_Expression_Constant('bar', 1))); + $tests[] = array($node, 'foobar($this->env, $context, "bar")', $environment); + + // named arguments + $node = $this->createFunction('date', array( + 'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), + 'date' => new Twig_Node_Expression_Constant(0, 1), + )); + $tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")'); + + // function as an anonymous function + if (PHP_VERSION_ID >= 50300) { + $node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); + $tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))'); + } + + return $tests; + } + + protected function createFunction($name, array $arguments = array()) + { + return new Twig_Node_Expression_Function($name, new Twig_Node($arguments), 1); + } + + protected function getEnvironment() + { + if (PHP_VERSION_ID >= 50300) { + return include 'PHP53/FunctionInclude.php'; + } + + return parent::getEnvironment(); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php new file mode 100755 index 0000000..2764478 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -0,0 +1,50 @@ +addElement(new Twig_Node_Expression_Name('foo', 1)); + $args->addElement(new Twig_Node_Expression_Constant('bar', 1)); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); + + $this->assertEquals($expr, $node->getNode('node')); + $this->assertEquals($attr, $node->getNode('attribute')); + $this->assertEquals($args, $node->getNode('arguments')); + $this->assertEquals(Twig_Template::ARRAY_CALL, $node->getAttribute('type')); + } + + public function getTests() + { + $tests = array(); + + $expr = new Twig_Node_Expression_Name('foo', 1); + $attr = new Twig_Node_Expression_Constant('bar', 1); + $args = new Twig_Node_Expression_Array(array(), 1); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1); + $tests[] = array($node, sprintf('%s%s, "bar", array())', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))); + + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); + $tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))); + + $args = new Twig_Node_Expression_Array(array(), 1); + $args->addElement(new Twig_Node_Expression_Name('foo', 1)); + $args->addElement(new Twig_Node_Expression_Constant('bar', 1)); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1); + $tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php new file mode 100755 index 0000000..905d8ee --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/NameTest.php @@ -0,0 +1,37 @@ +assertEquals('foo', $node->getAttribute('name')); + } + + public function getTests() + { + $node = new Twig_Node_Expression_Name('foo', 1); + $self = new Twig_Node_Expression_Name('_self', 1); + $context = new Twig_Node_Expression_Name('_context', 1); + + $env = new Twig_Environment(null, array('strict_variables' => true)); + $env1 = new Twig_Environment(null, array('strict_variables' => false)); + + return array( + array($node, "// line 1\n".(PHP_VERSION_ID >= 50400 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env), + array($node, $this->getVariableGetter('foo', 1), $env1), + array($self, "// line 1\n\$this"), + array($context, "// line 1\n\$context"), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php new file mode 100755 index 0000000..15e3aa9 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FilterInclude.php @@ -0,0 +1,6 @@ +addFilter(new Twig_SimpleFilter('anonymous', function () {})); + +return $env; diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php new file mode 100755 index 0000000..d2170ed --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/FunctionInclude.php @@ -0,0 +1,6 @@ +addFunction(new Twig_SimpleFunction('anonymous', function () {})); + +return $env; diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php new file mode 100755 index 0000000..6366286 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/PHP53/TestInclude.php @@ -0,0 +1,6 @@ +addTest(new Twig_SimpleTest('anonymous', function () {})); + +return $env; diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/ParentTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ParentTest.php new file mode 100755 index 0000000..ab2bbe0 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/ParentTest.php @@ -0,0 +1,28 @@ +assertEquals('foo', $node->getAttribute('name')); + } + + public function getTests() + { + $tests = array(); + $tests[] = array(new Twig_Node_Expression_Parent('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)'); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php new file mode 100755 index 0000000..e62a8af --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/TestTest.php @@ -0,0 +1,56 @@ +assertEquals($expr, $node->getNode('node')); + $this->assertEquals($args, $node->getNode('arguments')); + $this->assertEquals($name, $node->getAttribute('name')); + } + + public function getTests() + { + $tests = array(); + + $expr = new Twig_Node_Expression_Constant('foo', 1); + $node = new Twig_Node_Expression_Test_Null($expr, 'null', new Twig_Node(array()), 1); + $tests[] = array($node, '(null === "foo")'); + + // test as an anonymous function + if (PHP_VERSION_ID >= 50300) { + $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); + $tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))'); + } + + return $tests; + } + + protected function createTest($node, $name, array $arguments = array()) + { + return new Twig_Node_Expression_Test($node, $name, new Twig_Node($arguments), 1); + } + + protected function getEnvironment() + { + if (PHP_VERSION_ID >= 50300) { + return include 'PHP53/TestInclude.php'; + } + + return parent::getEnvironment(); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NegTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NegTest.php new file mode 100755 index 0000000..b633371 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NegTest.php @@ -0,0 +1,32 @@ +assertEquals($expr, $node->getNode('node')); + } + + public function getTests() + { + $node = new Twig_Node_Expression_Constant(1, 1); + $node = new Twig_Node_Expression_Unary_Neg($node, 1); + + return array( + array($node, '-1'), + array(new Twig_Node_Expression_Unary_Neg($node, 1), '- -1'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NotTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NotTest.php new file mode 100755 index 0000000..d7c6f85 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/NotTest.php @@ -0,0 +1,31 @@ +assertEquals($expr, $node->getNode('node')); + } + + public function getTests() + { + $node = new Twig_Node_Expression_Constant(1, 1); + $node = new Twig_Node_Expression_Unary_Not($node, 1); + + return array( + array($node, '!1'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/PosTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/PosTest.php new file mode 100755 index 0000000..057250f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/Unary/PosTest.php @@ -0,0 +1,31 @@ +assertEquals($expr, $node->getNode('node')); + } + + public function getTests() + { + $node = new Twig_Node_Expression_Constant(1, 1); + $node = new Twig_Node_Expression_Unary_Pos($node, 1); + + return array( + array($node, '+1'), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php b/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php new file mode 100755 index 0000000..b289592 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/ForTest.php @@ -0,0 +1,191 @@ +setAttribute('with_loop', false); + + $this->assertEquals($keyTarget, $node->getNode('key_target')); + $this->assertEquals($valueTarget, $node->getNode('value_target')); + $this->assertEquals($seq, $node->getNode('seq')); + $this->assertTrue($node->getAttribute('ifexpr')); + $this->assertEquals('Twig_Node_If', get_class($node->getNode('body'))); + $this->assertEquals($body, $node->getNode('body')->getNode('tests')->getNode(1)->getNode(0)); + $this->assertNull($node->getNode('else')); + + $else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1); + $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node->setAttribute('with_loop', false); + $this->assertEquals($else, $node->getNode('else')); + } + + public function getTests() + { + $tests = array(); + + $keyTarget = new Twig_Node_Expression_AssignName('key', 1); + $valueTarget = new Twig_Node_Expression_AssignName('item', 1); + $seq = new Twig_Node_Expression_Name('items', 1); + $ifexpr = null; + $body = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)), array(), 1); + $else = null; + $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node->setAttribute('with_loop', false); + + $tests[] = array($node, <<getVariableGetter('items')}); +foreach (\$context['_seq'] as \$context["key"] => \$context["item"]) { + echo {$this->getVariableGetter('foo')}; +} +\$_parent = \$context['_parent']; +unset(\$context['_seq'], \$context['_iterated'], \$context['key'], \$context['item'], \$context['_parent'], \$context['loop']); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; +EOF + ); + + $keyTarget = new Twig_Node_Expression_AssignName('k', 1); + $valueTarget = new Twig_Node_Expression_AssignName('v', 1); + $seq = new Twig_Node_Expression_Name('values', 1); + $ifexpr = null; + $body = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)), array(), 1); + $else = null; + $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node->setAttribute('with_loop', true); + + $tests[] = array($node, <<getVariableGetter('values')}); +\$context['loop'] = array( + 'parent' => \$context['_parent'], + 'index0' => 0, + 'index' => 1, + 'first' => true, +); +if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) { + \$length = count(\$context['_seq']); + \$context['loop']['revindex0'] = \$length - 1; + \$context['loop']['revindex'] = \$length; + \$context['loop']['length'] = \$length; + \$context['loop']['last'] = 1 === \$length; +} +foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) { + echo {$this->getVariableGetter('foo')}; + ++\$context['loop']['index0']; + ++\$context['loop']['index']; + \$context['loop']['first'] = false; + if (isset(\$context['loop']['length'])) { + --\$context['loop']['revindex0']; + --\$context['loop']['revindex']; + \$context['loop']['last'] = 0 === \$context['loop']['revindex0']; + } +} +\$_parent = \$context['_parent']; +unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; +EOF + ); + + $keyTarget = new Twig_Node_Expression_AssignName('k', 1); + $valueTarget = new Twig_Node_Expression_AssignName('v', 1); + $seq = new Twig_Node_Expression_Name('values', 1); + $ifexpr = new Twig_Node_Expression_Constant(true, 1); + $body = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)), array(), 1); + $else = null; + $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node->setAttribute('with_loop', true); + + $tests[] = array($node, <<getVariableGetter('values')}); +\$context['loop'] = array( + 'parent' => \$context['_parent'], + 'index0' => 0, + 'index' => 1, + 'first' => true, +); +foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) { + if (true) { + echo {$this->getVariableGetter('foo')}; + ++\$context['loop']['index0']; + ++\$context['loop']['index']; + \$context['loop']['first'] = false; + } +} +\$_parent = \$context['_parent']; +unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; +EOF + ); + + $keyTarget = new Twig_Node_Expression_AssignName('k', 1); + $valueTarget = new Twig_Node_Expression_AssignName('v', 1); + $seq = new Twig_Node_Expression_Name('values', 1); + $ifexpr = null; + $body = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1)), array(), 1); + $else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1); + $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node->setAttribute('with_loop', true); + + $tests[] = array($node, <<getVariableGetter('values')}); +\$context['_iterated'] = false; +\$context['loop'] = array( + 'parent' => \$context['_parent'], + 'index0' => 0, + 'index' => 1, + 'first' => true, +); +if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) { + \$length = count(\$context['_seq']); + \$context['loop']['revindex0'] = \$length - 1; + \$context['loop']['revindex'] = \$length; + \$context['loop']['length'] = \$length; + \$context['loop']['last'] = 1 === \$length; +} +foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) { + echo {$this->getVariableGetter('foo')}; + \$context['_iterated'] = true; + ++\$context['loop']['index0']; + ++\$context['loop']['index']; + \$context['loop']['first'] = false; + if (isset(\$context['loop']['length'])) { + --\$context['loop']['revindex0']; + --\$context['loop']['revindex']; + \$context['loop']['last'] = 0 === \$context['loop']['revindex0']; + } +} +if (!\$context['_iterated']) { + echo {$this->getVariableGetter('foo')}; +} +\$_parent = \$context['_parent']; +unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php b/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php new file mode 100755 index 0000000..e47dd65 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php @@ -0,0 +1,88 @@ +assertEquals($t, $node->getNode('tests')); + $this->assertNull($node->getNode('else')); + + $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1); + $node = new Twig_Node_If($t, $else, 1); + $this->assertEquals($else, $node->getNode('else')); + } + + public function getTests() + { + $tests = array(); + + $t = new Twig_Node(array( + new Twig_Node_Expression_Constant(true, 1), + new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1), + ), array(), 1); + $else = null; + $node = new Twig_Node_If($t, $else, 1); + + $tests[] = array($node, <<getVariableGetter('foo')}; +} +EOF + ); + + $t = new Twig_Node(array( + new Twig_Node_Expression_Constant(true, 1), + new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1), + new Twig_Node_Expression_Constant(false, 1), + new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1), + ), array(), 1); + $else = null; + $node = new Twig_Node_If($t, $else, 1); + + $tests[] = array($node, <<getVariableGetter('foo')}; +} elseif (false) { + echo {$this->getVariableGetter('bar')}; +} +EOF + ); + + $t = new Twig_Node(array( + new Twig_Node_Expression_Constant(true, 1), + new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1), + ), array(), 1); + $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1); + $node = new Twig_Node_If($t, $else, 1); + + $tests[] = array($node, <<getVariableGetter('foo')}; +} else { + echo {$this->getVariableGetter('bar')}; +} +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/ImportTest.php b/vendor/twig/twig/test/Twig/Tests/Node/ImportTest.php new file mode 100755 index 0000000..36525b2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/ImportTest.php @@ -0,0 +1,40 @@ +assertEquals($macro, $node->getNode('expr')); + $this->assertEquals($var, $node->getNode('var')); + } + + public function getTests() + { + $tests = array(); + + $macro = new Twig_Node_Expression_Constant('foo.twig', 1); + $var = new Twig_Node_Expression_AssignName('macro', 1); + $node = new Twig_Node_Import($macro, $var, 1); + + $tests[] = array($node, <<loadTemplate("foo.twig", null, 1); +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php b/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php new file mode 100755 index 0000000..6fe5c17 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php @@ -0,0 +1,83 @@ +assertNull($node->getNode('variables')); + $this->assertEquals($expr, $node->getNode('expr')); + $this->assertFalse($node->getAttribute('only')); + + $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1); + $node = new Twig_Node_Include($expr, $vars, true, false, 1); + $this->assertEquals($vars, $node->getNode('variables')); + $this->assertTrue($node->getAttribute('only')); + } + + public function getTests() + { + $tests = array(); + + $expr = new Twig_Node_Expression_Constant('foo.twig', 1); + $node = new Twig_Node_Include($expr, null, false, false, 1); + $tests[] = array($node, <<loadTemplate("foo.twig", null, 1)->display(\$context); +EOF + ); + + $expr = new Twig_Node_Expression_Conditional( + new Twig_Node_Expression_Constant(true, 1), + new Twig_Node_Expression_Constant('foo', 1), + new Twig_Node_Expression_Constant('foo', 1), + 0 + ); + $node = new Twig_Node_Include($expr, null, false, false, 1); + $tests[] = array($node, <<loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context); +EOF + ); + + $expr = new Twig_Node_Expression_Constant('foo.twig', 1); + $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1); + $node = new Twig_Node_Include($expr, $vars, false, false, 1); + $tests[] = array($node, <<loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, array("foo" => true))); +EOF + ); + + $node = new Twig_Node_Include($expr, $vars, true, false, 1); + $tests[] = array($node, <<loadTemplate("foo.twig", null, 1)->display(array("foo" => true)); +EOF + ); + + $node = new Twig_Node_Include($expr, $vars, true, true, 1); + $tests[] = array($node, <<loadTemplate("foo.twig", null, 1)->display(array("foo" => true)); +} catch (Twig_Error_Loader \$e) { + // ignore missing template +} +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php b/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php new file mode 100755 index 0000000..52ee8b7 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php @@ -0,0 +1,61 @@ +assertEquals($body, $node->getNode('body')); + $this->assertEquals($arguments, $node->getNode('arguments')); + $this->assertEquals('foo', $node->getAttribute('name')); + } + + public function getTests() + { + $body = new Twig_Node_Text('foo', 1); + $arguments = new Twig_Node(array( + 'foo' => new Twig_Node_Expression_Constant(null, 1), + 'bar' => new Twig_Node_Expression_Constant('Foo', 1), + ), array(), 1); + $node = new Twig_Node_Macro('foo', $body, $arguments, 1); + + return array( + array($node, <<env->mergeGlobals(array( + "foo" => \$__foo__, + "bar" => \$__bar__, + )); + + \$blocks = array(); + + ob_start(); + try { + echo "foo"; + } catch (Exception \$e) { + ob_end_clean(); + + throw \$e; + } + + return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset()); +} +EOF + ), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php b/vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php new file mode 100755 index 0000000..5688af8 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php @@ -0,0 +1,183 @@ +assertEquals($body, $node->getNode('body')); + $this->assertEquals($blocks, $node->getNode('blocks')); + $this->assertEquals($macros, $node->getNode('macros')); + $this->assertEquals($parent, $node->getNode('parent')); + $this->assertEquals($filename, $node->getAttribute('filename')); + } + + public function getTests() + { + $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); + + $tests = array(); + + $body = new Twig_Node_Text('foo', 1); + $extends = null; + $blocks = new Twig_Node(); + $macros = new Twig_Node(); + $traits = new Twig_Node(); + $filename = 'foo.twig'; + + $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename); + $tests[] = array($node, <<parent = false; + + \$this->blocks = array( + ); + } + + protected function doDisplay(array \$context, array \$blocks = array()) + { + // line 1 + echo "foo"; + } + + public function getTemplateName() + { + return "foo.twig"; + } + + public function getDebugInfo() + { + return array ( 19 => 1,); + } +} +EOF + , $twig); + + $import = new Twig_Node_Import(new Twig_Node_Expression_Constant('foo.twig', 1), new Twig_Node_Expression_AssignName('macro', 1), 2); + + $body = new Twig_Node(array($import)); + $extends = new Twig_Node_Expression_Constant('layout.twig', 1); + + $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename); + $tests[] = array($node, <<parent = \$this->loadTemplate("layout.twig", "foo.twig", 1); + \$this->blocks = array( + ); + } + + protected function doGetParent(array \$context) + { + return "layout.twig"; + } + + protected function doDisplay(array \$context, array \$blocks = array()) + { + // line 2 + \$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2); + // line 1 + \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks)); + } + + public function getTemplateName() + { + return "foo.twig"; + } + + public function isTraitable() + { + return false; + } + + public function getDebugInfo() + { + return array ( 26 => 1, 24 => 2, 11 => 1,); + } +} +EOF + , $twig); + + $set = new Twig_Node_Set(false, new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 4))), new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 4))), 4); + $body = new Twig_Node(array($set)); + $extends = new Twig_Node_Expression_Conditional( + new Twig_Node_Expression_Constant(true, 2), + new Twig_Node_Expression_Constant('foo', 2), + new Twig_Node_Expression_Constant('foo', 2), + 2 + ); + + $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename); + $tests[] = array($node, <<loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2); + } + + protected function doDisplay(array \$context, array \$blocks = array()) + { + // line 4 + \$context["foo"] = "foo"; + // line 2 + \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks)); + } + + public function getTemplateName() + { + return "foo.twig"; + } + + public function isTraitable() + { + return false; + } + + public function getDebugInfo() + { + return array ( 17 => 2, 15 => 4, 9 => 2,); + } +} +EOF + , $twig); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/PrintTest.php b/vendor/twig/twig/test/Twig/Tests/Node/PrintTest.php new file mode 100755 index 0000000..4e0990f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/PrintTest.php @@ -0,0 +1,29 @@ +assertEquals($expr, $node->getNode('expr')); + } + + public function getTests() + { + $tests = array(); + $tests[] = array(new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 1), 1), "// line 1\necho \"foo\";"); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/SandboxTest.php b/vendor/twig/twig/test/Twig/Tests/Node/SandboxTest.php new file mode 100755 index 0000000..46ecf97 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/SandboxTest.php @@ -0,0 +1,44 @@ +assertEquals($body, $node->getNode('body')); + } + + public function getTests() + { + $tests = array(); + + $body = new Twig_Node_Text('foo', 1); + $node = new Twig_Node_Sandbox($body, 1); + + $tests[] = array($node, <<env->getExtension('sandbox'); +if (!\$alreadySandboxed = \$sandbox->isSandboxed()) { + \$sandbox->enableSandbox(); +} +echo "foo"; +if (!\$alreadySandboxed) { + \$sandbox->disableSandbox(); +} +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/SandboxedPrintTest.php b/vendor/twig/twig/test/Twig/Tests/Node/SandboxedPrintTest.php new file mode 100755 index 0000000..05e1854 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/SandboxedPrintTest.php @@ -0,0 +1,33 @@ +assertEquals($expr, $node->getNode('expr')); + } + + public function getTests() + { + $tests = array(); + + $tests[] = array(new Twig_Node_SandboxedPrint(new Twig_Node_Expression_Constant('foo', 1), 1), <<env->getExtension('sandbox')->ensureToStringAllowed("foo"); +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/SetTest.php b/vendor/twig/twig/test/Twig/Tests/Node/SetTest.php new file mode 100755 index 0000000..62ad280 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/SetTest.php @@ -0,0 +1,69 @@ +assertEquals($names, $node->getNode('names')); + $this->assertEquals($values, $node->getNode('values')); + $this->assertFalse($node->getAttribute('capture')); + } + + public function getTests() + { + $tests = array(); + + $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1); + $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1)), array(), 1); + $node = new Twig_Node_Set(false, $names, $values, 1); + $tests[] = array($node, <<env->getCharset()); +EOF + ); + + $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1)), array(), 1); + $values = new Twig_Node_Text('foo', 1); + $node = new Twig_Node_Set(true, $names, $values, 1); + $tests[] = array($node, <<env->getCharset()); +EOF + ); + + $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 1), new Twig_Node_Expression_AssignName('bar', 1)), array(), 1); + $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Name('bar', 1)), array(), 1); + $node = new Twig_Node_Set(false, $names, $values, 1); + $tests[] = array($node, <<getVariableGetter('bar')}); +EOF + ); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/SpacelessTest.php b/vendor/twig/twig/test/Twig/Tests/Node/SpacelessTest.php new file mode 100755 index 0000000..222ca09 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/SpacelessTest.php @@ -0,0 +1,37 @@ +
    foo
    ', 1))); + $node = new Twig_Node_Spaceless($body, 1); + + $this->assertEquals($body, $node->getNode('body')); + } + + public function getTests() + { + $body = new Twig_Node(array(new Twig_Node_Text('
    foo
    ', 1))); + $node = new Twig_Node_Spaceless($body, 1); + + return array( + array($node, <<
    foo
    "; +echo trim(preg_replace('/>\s+<', ob_get_clean())); +EOF + ), + ); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Node/TextTest.php b/vendor/twig/twig/test/Twig/Tests/Node/TextTest.php new file mode 100755 index 0000000..ceaf67f --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/TextTest.php @@ -0,0 +1,28 @@ +assertEquals('foo', $node->getAttribute('data')); + } + + public function getTests() + { + $tests = array(); + $tests[] = array(new Twig_Node_Text('foo', 1), "// line 1\necho \"foo\";"); + + return $tests; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php new file mode 100755 index 0000000..b5ea7aa --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -0,0 +1,124 @@ +getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + + $stream = $env->parse($env->tokenize('{{ block("foo") }}', 'index')); + + $node = $stream->getNode('body')->getNode(0); + + $this->assertEquals('Twig_Node_Expression_BlockReference', get_class($node)); + $this->assertTrue($node->getAttribute('output')); + } + + public function testRenderParentBlockOptimizer() + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + + $stream = $env->parse($env->tokenize('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index')); + + $node = $stream->getNode('blocks')->getNode('content')->getNode(0)->getNode('body'); + + $this->assertEquals('Twig_Node_Expression_Parent', get_class($node)); + $this->assertTrue($node->getAttribute('output')); + } + + public function testRenderVariableBlockOptimizer() + { + if (PHP_VERSION_ID >= 50400) { + return; + } + + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); + $stream = $env->parse($env->tokenize('{{ block(name|lower) }}', 'index')); + + $node = $stream->getNode('body')->getNode(0)->getNode(1); + + $this->assertEquals('Twig_Node_Expression_BlockReference', get_class($node)); + $this->assertTrue($node->getAttribute('output')); + } + + /** + * @dataProvider getTestsForForOptimizer + */ + public function testForOptimizer($template, $expected) + { + $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false)); + + $stream = $env->parse($env->tokenize($template, 'index')); + + foreach ($expected as $target => $withLoop) { + $this->assertTrue($this->checkForConfiguration($stream, $target, $withLoop), sprintf('variable %s is %soptimized', $target, $withLoop ? 'not ' : '')); + } + } + + public function getTestsForForOptimizer() + { + return array( + array('{% for i in foo %}{% endfor %}', array('i' => false)), + + array('{% for i in foo %}{{ loop.index }}{% endfor %}', array('i' => true)), + + array('{% for i in foo %}{% for j in foo %}{% endfor %}{% endfor %}', array('i' => false, 'j' => false)), + + array('{% for i in foo %}{% include "foo" %}{% endfor %}', array('i' => true)), + + array('{% for i in foo %}{% include "foo" only %}{% endfor %}', array('i' => false)), + + array('{% for i in foo %}{% include "foo" with { "foo": "bar" } only %}{% endfor %}', array('i' => false)), + + array('{% for i in foo %}{% include "foo" with { "foo": loop.index } only %}{% endfor %}', array('i' => true)), + + array('{% for i in foo %}{% for j in foo %}{{ loop.index }}{% endfor %}{% endfor %}', array('i' => false, 'j' => true)), + + array('{% for i in foo %}{% for j in foo %}{{ loop.parent.loop.index }}{% endfor %}{% endfor %}', array('i' => true, 'j' => true)), + + array('{% for i in foo %}{% set l = loop %}{% for j in foo %}{{ l.index }}{% endfor %}{% endfor %}', array('i' => true, 'j' => false)), + + array('{% for i in foo %}{% for j in foo %}{{ foo.parent.loop.index }}{% endfor %}{% endfor %}', array('i' => false, 'j' => false)), + + array('{% for i in foo %}{% for j in foo %}{{ loop["parent"].loop.index }}{% endfor %}{% endfor %}', array('i' => true, 'j' => true)), + + array('{% for i in foo %}{{ include("foo") }}{% endfor %}', array('i' => true)), + + array('{% for i in foo %}{{ include("foo", with_context = false) }}{% endfor %}', array('i' => false)), + + array('{% for i in foo %}{{ include("foo", with_context = true) }}{% endfor %}', array('i' => true)), + + array('{% for i in foo %}{{ include("foo", { "foo": "bar" }, with_context = false) }}{% endfor %}', array('i' => false)), + + array('{% for i in foo %}{{ include("foo", { "foo": loop.index }, with_context = false) }}{% endfor %}', array('i' => true)), + ); + } + + public function checkForConfiguration(Twig_NodeInterface $node = null, $target, $withLoop) + { + if (null === $node) { + return; + } + + foreach ($node as $n) { + if ($n instanceof Twig_Node_For) { + if ($target === $n->getNode('value_target')->getAttribute('name')) { + return $withLoop == $n->getAttribute('with_loop'); + } + } + + $ret = $this->checkForConfiguration($n, $target, $withLoop); + if (null !== $ret) { + return $ret; + } + } + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/ParserTest.php b/vendor/twig/twig/test/Twig/Tests/ParserTest.php new file mode 100755 index 0000000..b4a3abb --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/ParserTest.php @@ -0,0 +1,180 @@ +getParser(); + $parser->setMacro('display', $this->getMock('Twig_Node_Macro', array(), array(), '', null)); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unknown tag name "foo". Did you mean "for" at line 1 + */ + public function testUnknownTag() + { + $stream = new Twig_TokenStream(array( + new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), + new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1), + new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), + new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + )); + $parser = new Twig_Parser(new Twig_Environment()); + $parser->parse($stream); + } + + /** + * @dataProvider getFilterBodyNodesData + */ + public function testFilterBodyNodes($input, $expected) + { + $parser = $this->getParser(); + + $this->assertEquals($expected, $parser->filterBodyNodes($input)); + } + + public function getFilterBodyNodesData() + { + return array( + array( + new Twig_Node(array(new Twig_Node_Text(' ', 1))), + new Twig_Node(array()), + ), + array( + $input = new Twig_Node(array(new Twig_Node_Set(false, new Twig_Node(), new Twig_Node(), 1))), + $input, + ), + array( + $input = new Twig_Node(array(new Twig_Node_Set(true, new Twig_Node(), new Twig_Node(array(new Twig_Node(array(new Twig_Node_Text('foo', 1))))), 1))), + $input, + ), + ); + } + + /** + * @dataProvider getFilterBodyNodesDataThrowsException + * @expectedException Twig_Error_Syntax + */ + public function testFilterBodyNodesThrowsException($input) + { + $parser = $this->getParser(); + + $parser->filterBodyNodes($input); + } + + public function getFilterBodyNodesDataThrowsException() + { + return array( + array(new Twig_Node_Text('foo', 1)), + array(new Twig_Node(array(new Twig_Node(array(new Twig_Node_Text('foo', 1)))))), + ); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed at line 1. + */ + public function testFilterBodyNodesWithBOM() + { + $parser = $this->getParser(); + $parser->filterBodyNodes(new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF), 1)); + } + + public function testParseIsReentrant() + { + $twig = new Twig_Environment(null, array( + 'autoescape' => false, + 'optimizations' => 0, + )); + $twig->addTokenParser(new TestTokenParser()); + + $parser = new Twig_Parser($twig); + + $parser->parse(new Twig_TokenStream(array( + new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), + new Twig_Token(Twig_Token::NAME_TYPE, 'test', 1), + new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), + new Twig_Token(Twig_Token::VAR_START_TYPE, '', 1), + new Twig_Token(Twig_Token::NAME_TYPE, 'foo', 1), + new Twig_Token(Twig_Token::VAR_END_TYPE, '', 1), + new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + ))); + + $this->assertNull($parser->getParent()); + } + + // The getVarName() must not depend on the template loaders, + // If this test does not throw any exception, that's good. + // see https://github.com/symfony/symfony/issues/4218 + public function testGetVarName() + { + $twig = new Twig_Environment(null, array( + 'autoescape' => false, + 'optimizations' => 0, + )); + + $twig->parse($twig->tokenize(<<setParent(new Twig_Node()); + $parser->stream = $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock(); + + return $parser; + } +} + +class TestParser extends Twig_Parser +{ + public $stream; + + public function filterBodyNodes(Twig_NodeInterface $node) + { + return parent::filterBodyNodes($node); + } +} + +class TestTokenParser extends Twig_TokenParser +{ + public function parse(Twig_Token $token) + { + // simulate the parsing of another template right in the middle of the parsing of the current template + $this->parser->parse(new Twig_TokenStream(array( + new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', 1), + new Twig_Token(Twig_Token::NAME_TYPE, 'extends', 1), + new Twig_Token(Twig_Token::STRING_TYPE, 'base', 1), + new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', 1), + new Twig_Token(Twig_Token::EOF_TYPE, '', 1), + ))); + + $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + + return new Twig_Node(array()); + } + + public function getTag() + { + return 'test'; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/AbstractTest.php b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/AbstractTest.php new file mode 100755 index 0000000..d855664 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/AbstractTest.php @@ -0,0 +1,101 @@ +getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock(); + + $profile->expects($this->any())->method('isRoot')->will($this->returnValue(true)); + $profile->expects($this->any())->method('getName')->will($this->returnValue('main')); + $profile->expects($this->any())->method('getDuration')->will($this->returnValue(1)); + $profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0)); + $profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0)); + + $subProfiles = array( + $this->getIndexProfile( + array( + $this->getEmbeddedBlockProfile(), + $this->getEmbeddedTemplateProfile( + array( + $this->getIncludedTemplateProfile(), + ) + ), + $this->getMacroProfile(), + $this->getEmbeddedTemplateProfile( + array( + $this->getIncludedTemplateProfile(), + ) + ), + ) + ), + ); + + $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles)); + $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles))); + + return $profile; + } + + private function getIndexProfile(array $subProfiles = array()) + { + return $this->generateProfile('main', 1, true, 'template', 'index.twig', $subProfiles); + } + + private function getEmbeddedBlockProfile(array $subProfiles = array()) + { + return $this->generateProfile('body', 0.0001, false, 'block', 'embedded.twig', $subProfiles); + } + + private function getEmbeddedTemplateProfile(array $subProfiles = array()) + { + return $this->generateProfile('main', 0.0001, true, 'template', 'embedded.twig', $subProfiles); + } + + private function getIncludedTemplateProfile(array $subProfiles = array()) + { + return $this->generateProfile('main', 0.0001, true, 'template', 'included.twig', $subProfiles); + } + + private function getMacroProfile(array $subProfiles = array()) + { + return $this->generateProfile('foo', 0.0001, false, 'macro', 'index.twig', $subProfiles); + } + + /** + * @param string $name + * @param float $duration + * @param bool $isTemplate + * @param string $type + * @param string $templateName + * @param array $subProfiles + * + * @return Twig_Profiler_Profile + */ + private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = array()) + { + $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock(); + + $profile->expects($this->any())->method('isRoot')->will($this->returnValue(false)); + $profile->expects($this->any())->method('getName')->will($this->returnValue($name)); + $profile->expects($this->any())->method('getDuration')->will($this->returnValue($duration)); + $profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0)); + $profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0)); + $profile->expects($this->any())->method('isTemplate')->will($this->returnValue($isTemplate)); + $profile->expects($this->any())->method('getType')->will($this->returnValue($type)); + $profile->expects($this->any())->method('getTemplate')->will($this->returnValue($templateName)); + $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles)); + $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles))); + + return $profile; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php new file mode 100755 index 0000000..1a1b9d2 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php @@ -0,0 +1,32 @@ +assertStringMatchesFormat(<<index.twig//1 %d %d %d +index.twig==>embedded.twig::block(body)//1 %d %d 0 +index.twig==>embedded.twig//2 %d %d %d +embedded.twig==>included.twig//2 %d %d %d +index.twig==>index.twig::macro(foo)//1 %d %d %d +EOF + , $dumper->dump($this->getProfile())); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/HtmlTest.php b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/HtmlTest.php new file mode 100755 index 0000000..66a68c4 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/HtmlTest.php @@ -0,0 +1,30 @@ +assertStringMatchesFormat(<<main %d.%dms/%d% +└ index.twig %d.%dms/%d% + └ embedded.twig::block(body) + └ embedded.twig + │ └ included.twig + └ index.twig::macro(foo) + └ embedded.twig + └ included.twig + +EOF + , $dumper->dump($this->getProfile())); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/TextTest.php b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/TextTest.php new file mode 100755 index 0000000..e2ea165 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Profiler/Dumper/TextTest.php @@ -0,0 +1,30 @@ +assertStringMatchesFormat(<<dump($this->getProfile())); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/Profiler/ProfileTest.php b/vendor/twig/twig/test/Twig/Tests/Profiler/ProfileTest.php new file mode 100755 index 0000000..f786f06 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Profiler/ProfileTest.php @@ -0,0 +1,100 @@ +assertEquals('template', $profile->getTemplate()); + $this->assertEquals('type', $profile->getType()); + $this->assertEquals('name', $profile->getName()); + } + + public function testIsRoot() + { + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $this->assertTrue($profile->isRoot()); + + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE); + $this->assertFalse($profile->isRoot()); + } + + public function testIsTemplate() + { + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::TEMPLATE); + $this->assertTrue($profile->isTemplate()); + + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $this->assertFalse($profile->isTemplate()); + } + + public function testIsBlock() + { + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::BLOCK); + $this->assertTrue($profile->isBlock()); + + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $this->assertFalse($profile->isBlock()); + } + + public function testIsMacro() + { + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::MACRO); + $this->assertTrue($profile->isMacro()); + + $profile = new Twig_Profiler_Profile('template', Twig_Profiler_Profile::ROOT); + $this->assertFalse($profile->isMacro()); + } + + public function testGetAddProfile() + { + $profile = new Twig_Profiler_Profile(); + $profile->addProfile($a = new Twig_Profiler_Profile()); + $profile->addProfile($b = new Twig_Profiler_Profile()); + + $this->assertSame(array($a, $b), $profile->getProfiles()); + $this->assertSame(array($a, $b), iterator_to_array($profile)); + } + + public function testGetDuration() + { + $profile = new Twig_Profiler_Profile(); + usleep(1); + $profile->leave(); + + $this->assertTrue($profile->getDuration() > 0, sprintf('Expected duration > 0, got: %f', $profile->getDuration())); + } + + public function testSerialize() + { + $profile = new Twig_Profiler_Profile('template', 'type', 'name'); + $profile1 = new Twig_Profiler_Profile('template1', 'type1', 'name1'); + $profile->addProfile($profile1); + $profile->leave(); + $profile1->leave(); + + $profile2 = unserialize(serialize($profile)); + $profiles = $profile->getProfiles(); + $this->assertCount(1, $profiles); + $profile3 = $profiles[0]; + + $this->assertEquals($profile->getTemplate(), $profile2->getTemplate()); + $this->assertEquals($profile->getType(), $profile2->getType()); + $this->assertEquals($profile->getName(), $profile2->getName()); + $this->assertEquals($profile->getDuration(), $profile2->getDuration()); + + $this->assertEquals($profile1->getTemplate(), $profile3->getTemplate()); + $this->assertEquals($profile1->getType(), $profile3->getType()); + $this->assertEquals($profile1->getName(), $profile3->getName()); + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/TemplateTest.php b/vendor/twig/twig/test/Twig/Tests/TemplateTest.php new file mode 100755 index 0000000..cac7926 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/TemplateTest.php @@ -0,0 +1,670 @@ + $template.$useExt, // appending $useExt makes the template content unique + ); + + $env = new Twig_Environment(new Twig_Loader_Array($templates), array('strict_variables' => true)); + if (!$useExt) { + $env->addNodeVisitor(new CExtDisablingNodeVisitor()); + } + $template = $env->loadTemplate($name); + + $context = array( + 'string' => 'foo', + 'null' => null, + 'empty_array' => array(), + 'array' => array('foo' => 'foo'), + 'array_access' => new Twig_TemplateArrayAccessObject(), + 'magic_exception' => new Twig_TemplateMagicPropertyObjectWithException(), + 'object' => new stdClass(), + ); + + try { + $template->render($context); + $this->fail('Accessing an invalid attribute should throw an exception.'); + } catch (Twig_Error_Runtime $e) { + $this->assertSame(sprintf($message, $name), $e->getMessage()); + } + } + + public function getAttributeExceptions() + { + $tests = array( + array('{{ string["a"] }}', 'Impossible to access a key ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ null["a"] }}', 'Impossible to access a key ("a") on a null variable in "%s" at line 1', false), + array('{{ empty_array["a"] }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), + array('{{ array["a"] }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), + array('{{ array_access["a"] }}', 'Key "a" in object with ArrayAccess of class "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), + array('{{ string.a }}', 'Impossible to access an attribute ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ string.a() }}', 'Impossible to invoke a method ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ null.a }}', 'Impossible to access an attribute ("a") on a null variable in "%s" at line 1', false), + array('{{ null.a() }}', 'Impossible to invoke a method ("a") on a null variable in "%s" at line 1', false), + array('{{ empty_array.a }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), + array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), + array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1', false), + array('{{ array_access.a }}', 'Method "a" for object "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), + array('{% macro foo(obj) %}{{ obj.missing_method() }}{% endmacro %}{{ _self.foo(array_access) }}', 'Method "missing_method" for object "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), + array('{{ magic_exception.test }}', 'An exception has been thrown during the rendering of a template ("Hey! Don\'t try to isset me!") in "%s" at line 1.', false), + array('{{ object["a"] }}', 'Impossible to access a key "a" on an object of class "stdClass" that does not implement ArrayAccess interface in "%s" at line 1', false), + ); + + if (function_exists('twig_template_get_attributes')) { + foreach (array_slice($tests, 0) as $test) { + $test[2] = true; + $tests[] = $test; + } + } + + return $tests; + } + + /** + * @dataProvider getGetAttributeWithSandbox + */ + public function testGetAttributeWithSandbox($object, $item, $allowed, $useExt) + { + $twig = new Twig_Environment(); + $policy = new Twig_Sandbox_SecurityPolicy(array(), array(), array(/*method*/), array(/*prop*/), array()); + $twig->addExtension(new Twig_Extension_Sandbox($policy, !$allowed)); + $template = new Twig_TemplateTest($twig, $useExt); + + try { + $template->getAttribute($object, $item, array(), 'any'); + + if (!$allowed) { + $this->fail(); + } + } catch (Twig_Sandbox_SecurityError $e) { + if ($allowed) { + $this->fail(); + } + + $this->assertContains('is not allowed', $e->getMessage()); + } + } + + public function getGetAttributeWithSandbox() + { + $tests = array( + array(new Twig_TemplatePropertyObject(), 'defined', false, false), + array(new Twig_TemplatePropertyObject(), 'defined', true, false), + array(new Twig_TemplateMethodObject(), 'defined', false, false), + array(new Twig_TemplateMethodObject(), 'defined', true, false), + ); + + if (function_exists('twig_template_get_attributes')) { + foreach (array_slice($tests, 0) as $test) { + $test[3] = true; + $tests[] = $test; + } + } + + return $tests; + } + + /** + * @dataProvider getGetAttributeWithTemplateAsObject + */ + public function testGetAttributeWithTemplateAsObject($useExt) + { + $template = new Twig_TemplateTest(new Twig_Environment(), $useExt); + $template1 = new Twig_TemplateTest(new Twig_Environment(), false); + + $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string')); + $this->assertEquals('some_string', $template->getAttribute($template1, 'string')); + + $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'true')); + $this->assertEquals('1', $template->getAttribute($template1, 'true')); + + $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'zero')); + $this->assertEquals('0', $template->getAttribute($template1, 'zero')); + + $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty')); + $this->assertSame('', $template->getAttribute($template1, 'empty')); + } + + public function getGetAttributeWithTemplateAsObject() + { + $bools = array( + array(false), + ); + + if (function_exists('twig_template_get_attributes')) { + $bools[] = array(true); + } + + return $bools; + } + + /** + * @dataProvider getTestsDependingOnExtensionAvailability + */ + public function testGetAttributeOnArrayWithConfusableKey($useExt = false) + { + $template = new Twig_TemplateTest( + new Twig_Environment(), + $useExt + ); + + $array = array('Zero', 'One', -1 => 'MinusOne', '' => 'EmptyString', '1.5' => 'FloatButString', '01' => 'IntegerButStringWithLeadingZeros'); + + $this->assertSame('Zero', $array[false]); + $this->assertSame('One', $array[true]); + $this->assertSame('One', $array[1.5]); + $this->assertSame('One', $array['1']); + $this->assertSame('MinusOne', $array[-1.5]); + $this->assertSame('FloatButString', $array['1.5']); + $this->assertSame('IntegerButStringWithLeadingZeros', $array['01']); + $this->assertSame('EmptyString', $array[null]); + + $this->assertSame('Zero', $template->getAttribute($array, false), 'false is treated as 0 when accessing an array (equals PHP behavior)'); + $this->assertSame('One', $template->getAttribute($array, true), 'true is treated as 1 when accessing an array (equals PHP behavior)'); + $this->assertSame('One', $template->getAttribute($array, 1.5), 'float is casted to int when accessing an array (equals PHP behavior)'); + $this->assertSame('One', $template->getAttribute($array, '1'), '"1" is treated as integer 1 when accessing an array (equals PHP behavior)'); + $this->assertSame('MinusOne', $template->getAttribute($array, -1.5), 'negative float is casted to int when accessing an array (equals PHP behavior)'); + $this->assertSame('FloatButString', $template->getAttribute($array, '1.5'), '"1.5" is treated as-is when accessing an array (equals PHP behavior)'); + $this->assertSame('IntegerButStringWithLeadingZeros', $template->getAttribute($array, '01'), '"01" is treated as-is when accessing an array (equals PHP behavior)'); + $this->assertSame('EmptyString', $template->getAttribute($array, null), 'null is treated as "" when accessing an array (equals PHP behavior)'); + } + + public function getTestsDependingOnExtensionAvailability() + { + if (function_exists('twig_template_get_attributes')) { + return array(array(false), array(true)); + } + + return array(array(false)); + } + + /** + * @dataProvider getGetAttributeTests + */ + public function testGetAttribute($defined, $value, $object, $item, $arguments, $type, $useExt = false) + { + $template = new Twig_TemplateTest(new Twig_Environment(), $useExt); + + $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); + } + + /** + * @dataProvider getGetAttributeTests + */ + public function testGetAttributeStrict($defined, $value, $object, $item, $arguments, $type, $useExt = false, $exceptionMessage = null) + { + $template = new Twig_TemplateTest(new Twig_Environment(null, array('strict_variables' => true)), $useExt); + + if ($defined) { + $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); + } else { + try { + $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); + + throw new Exception('Expected Twig_Error_Runtime exception.'); + } catch (Twig_Error_Runtime $e) { + if (null !== $exceptionMessage) { + $this->assertSame($exceptionMessage, $e->getMessage()); + } + } + } + } + + /** + * @dataProvider getGetAttributeTests + */ + public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type, $useExt = false) + { + $template = new Twig_TemplateTest(new Twig_Environment(), $useExt); + + $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true)); + } + + /** + * @dataProvider getGetAttributeTests + */ + public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type, $useExt = false) + { + $template = new Twig_TemplateTest(new Twig_Environment(null, array('strict_variables' => true)), $useExt); + + $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true)); + } + + /** + * @dataProvider getTestsDependingOnExtensionAvailability + */ + public function testGetAttributeCallExceptions($useExt = false) + { + $template = new Twig_TemplateTest(new Twig_Environment(), $useExt); + + $object = new Twig_TemplateMagicMethodExceptionObject(); + + $this->assertNull($template->getAttribute($object, 'foo')); + } + + public function getGetAttributeTests() + { + $array = array( + 'defined' => 'defined', + 'zero' => 0, + 'null' => null, + '1' => 1, + 'bar' => true, + '09' => '09', + '+4' => '+4', + ); + + $objectArray = new Twig_TemplateArrayAccessObject(); + $stdObject = (object) $array; + $magicPropertyObject = new Twig_TemplateMagicPropertyObject(); + $propertyObject = new Twig_TemplatePropertyObject(); + $propertyObject1 = new Twig_TemplatePropertyObjectAndIterator(); + $propertyObject2 = new Twig_TemplatePropertyObjectAndArrayAccess(); + $propertyObject3 = new Twig_TemplatePropertyObjectDefinedWithUndefinedValue(); + $methodObject = new Twig_TemplateMethodObject(); + $magicMethodObject = new Twig_TemplateMagicMethodObject(); + + $anyType = Twig_Template::ANY_CALL; + $methodType = Twig_Template::METHOD_CALL; + $arrayType = Twig_Template::ARRAY_CALL; + + $basicTests = array( + // array(defined, value, property to fetch) + array(true, 'defined', 'defined'), + array(false, null, 'undefined'), + array(false, null, 'protected'), + array(true, 0, 'zero'), + array(true, 1, 1), + array(true, 1, 1.0), + array(true, null, 'null'), + array(true, true, 'bar'), + array(true, '09', '09'), + array(true, '+4', '+4'), + ); + $testObjects = array( + // array(object, type of fetch) + array($array, $arrayType), + array($objectArray, $arrayType), + array($stdObject, $anyType), + array($magicPropertyObject, $anyType), + array($methodObject, $methodType), + array($methodObject, $anyType), + array($propertyObject, $anyType), + array($propertyObject1, $anyType), + array($propertyObject2, $anyType), + ); + + $tests = array(); + foreach ($testObjects as $testObject) { + foreach ($basicTests as $test) { + // properties cannot be numbers + if (($testObject[0] instanceof stdClass || $testObject[0] instanceof Twig_TemplatePropertyObject) && is_numeric($test[2])) { + continue; + } + + if ('+4' === $test[2] && $methodObject === $testObject[0]) { + continue; + } + + $tests[] = array($test[0], $test[1], $testObject[0], $test[2], array(), $testObject[1]); + } + } + + // additional properties tests + $tests = array_merge($tests, array( + array(true, null, $propertyObject3, 'foo', array(), $anyType), + )); + + // additional method tests + $tests = array_merge($tests, array( + array(true, 'defined', $methodObject, 'defined', array(), $methodType), + array(true, 'defined', $methodObject, 'DEFINED', array(), $methodType), + array(true, 'defined', $methodObject, 'getDefined', array(), $methodType), + array(true, 'defined', $methodObject, 'GETDEFINED', array(), $methodType), + array(true, 'static', $methodObject, 'static', array(), $methodType), + array(true, 'static', $methodObject, 'getStatic', array(), $methodType), + + array(true, '__call_undefined', $magicMethodObject, 'undefined', array(), $methodType), + array(true, '__call_UNDEFINED', $magicMethodObject, 'UNDEFINED', array(), $methodType), + )); + + // add the same tests for the any type + foreach ($tests as $test) { + if ($anyType !== $test[5]) { + $test[5] = $anyType; + $tests[] = $test; + } + } + + $methodAndPropObject = new Twig_TemplateMethodAndPropObject(); + + // additional method tests + $tests = array_merge($tests, array( + array(true, 'a', $methodAndPropObject, 'a', array(), $anyType), + array(true, 'a', $methodAndPropObject, 'a', array(), $methodType), + array(false, null, $methodAndPropObject, 'a', array(), $arrayType), + + array(true, 'b_prop', $methodAndPropObject, 'b', array(), $anyType), + array(true, 'b', $methodAndPropObject, 'B', array(), $anyType), + array(true, 'b', $methodAndPropObject, 'b', array(), $methodType), + array(true, 'b', $methodAndPropObject, 'B', array(), $methodType), + array(false, null, $methodAndPropObject, 'b', array(), $arrayType), + + array(false, null, $methodAndPropObject, 'c', array(), $anyType), + array(false, null, $methodAndPropObject, 'c', array(), $methodType), + array(false, null, $methodAndPropObject, 'c', array(), $arrayType), + + )); + + // tests when input is not an array or object + $tests = array_merge($tests, array( + array(false, null, 42, 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a integer variable ("42")'), + array(false, null, "string", 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a string variable ("string")'), + array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" does not exist as the array is empty'), + )); + + // add twig_template_get_attributes tests + + if (function_exists('twig_template_get_attributes')) { + foreach (array_slice($tests, 0) as $test) { + $test = array_pad($test, 7, null); + $test[6] = true; + $tests[] = $test; + } + } + + return $tests; + } +} + +class Twig_TemplateTest extends Twig_Template +{ + protected $useExtGetAttribute = false; + + public function __construct(Twig_Environment $env, $useExtGetAttribute = false) + { + parent::__construct($env); + $this->useExtGetAttribute = $useExtGetAttribute; + self::$cache = array(); + } + + public function getZero() + { + return 0; + } + + public function getEmpty() + { + return ''; + } + + public function getString() + { + return 'some_string'; + } + + public function getTrue() + { + return true; + } + + public function getTemplateName() + { + } + + public function getDebugInfo() + { + return array(); + } + + protected function doGetParent(array $context) + { + } + + protected function doDisplay(array $context, array $blocks = array()) + { + } + + public function getAttribute($object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + { + if ($this->useExtGetAttribute) { + return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); + } else { + return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); + } + } +} + +class Twig_TemplateArrayAccessObject implements ArrayAccess +{ + protected $protected = 'protected'; + + public $attributes = array( + 'defined' => 'defined', + 'zero' => 0, + 'null' => null, + '1' => 1, + 'bar' => true, + '09' => '09', + '+4' => '+4', + ); + + public function offsetExists($name) + { + return array_key_exists($name, $this->attributes); + } + + public function offsetGet($name) + { + return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; + } + + public function offsetSet($name, $value) + { + } + + public function offsetUnset($name) + { + } +} + +class Twig_TemplateMagicPropertyObject +{ + public $defined = 'defined'; + + public $attributes = array( + 'zero' => 0, + 'null' => null, + '1' => 1, + 'bar' => true, + '09' => '09', + '+4' => '+4', + ); + + protected $protected = 'protected'; + + public function __isset($name) + { + return array_key_exists($name, $this->attributes); + } + + public function __get($name) + { + return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; + } +} + +class Twig_TemplateMagicPropertyObjectWithException +{ + public function __isset($key) + { + throw new Exception('Hey! Don\'t try to isset me!'); + } +} + +class Twig_TemplatePropertyObject +{ + public $defined = 'defined'; + public $zero = 0; + public $null = null; + public $bar = true; + + protected $protected = 'protected'; +} + +class Twig_TemplatePropertyObjectAndIterator extends Twig_TemplatePropertyObject implements IteratorAggregate +{ + public function getIterator() + { + return new ArrayIterator(array('foo', 'bar')); + } +} + +class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObject implements ArrayAccess +{ + private $data = array(); + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->data[$offset] : 'n/a'; + } + + public function offsetSet($offset, $value) + { + } + + public function offsetUnset($offset) + { + } +} + +class Twig_TemplatePropertyObjectDefinedWithUndefinedValue +{ + public $foo; + + public function __construct() + { + $this->foo = @$notExist; + } +} + +class Twig_TemplateMethodObject +{ + public function getDefined() + { + return 'defined'; + } + + public function get1() + { + return 1; + } + + public function get09() + { + return '09'; + } + + public function getZero() + { + return 0; + } + + public function getNull() + { + } + + public function isBar() + { + return true; + } + + protected function getProtected() + { + return 'protected'; + } + + public static function getStatic() + { + return 'static'; + } +} + +class Twig_TemplateMethodAndPropObject +{ + private $a = 'a_prop'; + public function getA() + { + return 'a'; + } + + public $b = 'b_prop'; + public function getB() + { + return 'b'; + } + + private $c = 'c_prop'; + private function getC() + { + return 'c'; + } +} + +class Twig_TemplateMagicMethodObject +{ + public function __call($method, $arguments) + { + return '__call_'.$method; + } +} + +class Twig_TemplateMagicMethodExceptionObject +{ + public function __call($method, $arguments) + { + throw new BadMethodCallException(sprintf('Unkown method %s', $method)); + } +} + +class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface +{ + public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) + { + if ($node instanceof Twig_Node_Expression_GetAttr) { + $node->setAttribute('disable_c_ext', true); + } + + return $node; + } + + public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) + { + return $node; + } + + public function getPriority() + { + return 0; + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/TokenStreamTest.php b/vendor/twig/twig/test/Twig/Tests/TokenStreamTest.php new file mode 100755 index 0000000..fd4ec63 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/TokenStreamTest.php @@ -0,0 +1,70 @@ +isEOF()) { + $token = $stream->next(); + + $repr[] = $token->getValue(); + } + $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token'); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedMessage Unexpected end of template + */ + public function testEndOfTemplateNext() + { + $stream = new Twig_TokenStream(array( + new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1), + )); + while (!$stream->isEOF()) { + $stream->next(); + } + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedMessage Unexpected end of template + */ + public function testEndOfTemplateLook() + { + $stream = new Twig_TokenStream(array( + new Twig_Token(Twig_Token::BLOCK_START_TYPE, 1, 1), + )); + while (!$stream->isEOF()) { + $stream->look(); + $stream->next(); + } + } +} diff --git a/vendor/twig/twig/test/Twig/Tests/escapingTest.php b/vendor/twig/twig/test/Twig/Tests/escapingTest.php new file mode 100755 index 0000000..dfa9d43 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/escapingTest.php @@ -0,0 +1,320 @@ + ''', + '"' => '"', + '<' => '<', + '>' => '>', + '&' => '&', + ); + + protected $htmlAttrSpecialChars = array( + '\'' => ''', + /* Characters beyond ASCII value 255 to unicode escape */ + 'Ā' => 'Ā', + /* Immune chars excluded */ + ',' => ',', + '.' => '.', + '-' => '-', + '_' => '_', + /* Basic alnums excluded */ + 'a' => 'a', + 'A' => 'A', + 'z' => 'z', + 'Z' => 'Z', + '0' => '0', + '9' => '9', + /* Basic control characters and null */ + "\r" => ' ', + "\n" => ' ', + "\t" => ' ', + "\0" => '�', // should use Unicode replacement char + /* Encode chars as named entities where possible */ + '<' => '<', + '>' => '>', + '&' => '&', + '"' => '"', + /* Encode spaces for quoteless attribute protection */ + ' ' => ' ', + ); + + protected $jsSpecialChars = array( + /* HTML special chars - escape without exception to hex */ + '<' => '\\x3C', + '>' => '\\x3E', + '\'' => '\\x27', + '"' => '\\x22', + '&' => '\\x26', + /* Characters beyond ASCII value 255 to unicode escape */ + 'Ā' => '\\u0100', + /* Immune chars excluded */ + ',' => ',', + '.' => '.', + '_' => '_', + /* Basic alnums excluded */ + 'a' => 'a', + 'A' => 'A', + 'z' => 'z', + 'Z' => 'Z', + '0' => '0', + '9' => '9', + /* Basic control characters and null */ + "\r" => '\\x0D', + "\n" => '\\x0A', + "\t" => '\\x09', + "\0" => '\\x00', + /* Encode spaces for quoteless attribute protection */ + ' ' => '\\x20', + ); + + protected $urlSpecialChars = array( + /* HTML special chars - escape without exception to percent encoding */ + '<' => '%3C', + '>' => '%3E', + '\'' => '%27', + '"' => '%22', + '&' => '%26', + /* Characters beyond ASCII value 255 to hex sequence */ + 'Ā' => '%C4%80', + /* Punctuation and unreserved check */ + ',' => '%2C', + '.' => '.', + '_' => '_', + '-' => '-', + ':' => '%3A', + ';' => '%3B', + '!' => '%21', + /* Basic alnums excluded */ + 'a' => 'a', + 'A' => 'A', + 'z' => 'z', + 'Z' => 'Z', + '0' => '0', + '9' => '9', + /* Basic control characters and null */ + "\r" => '%0D', + "\n" => '%0A', + "\t" => '%09', + "\0" => '%00', + /* PHP quirks from the past */ + ' ' => '%20', + '~' => '~', + '+' => '%2B', + ); + + protected $cssSpecialChars = array( + /* HTML special chars - escape without exception to hex */ + '<' => '\\3C ', + '>' => '\\3E ', + '\'' => '\\27 ', + '"' => '\\22 ', + '&' => '\\26 ', + /* Characters beyond ASCII value 255 to unicode escape */ + 'Ā' => '\\100 ', + /* Immune chars excluded */ + ',' => '\\2C ', + '.' => '\\2E ', + '_' => '\\5F ', + /* Basic alnums excluded */ + 'a' => 'a', + 'A' => 'A', + 'z' => 'z', + 'Z' => 'Z', + '0' => '0', + '9' => '9', + /* Basic control characters and null */ + "\r" => '\\D ', + "\n" => '\\A ', + "\t" => '\\9 ', + "\0" => '\\0 ', + /* Encode spaces for quoteless attribute protection */ + ' ' => '\\20 ', + ); + + protected $env; + + public function setUp() + { + $this->env = new Twig_Environment(); + } + + public function testHtmlEscapingConvertsSpecialChars() + { + foreach ($this->htmlSpecialChars as $key => $value) { + $this->assertEquals($value, twig_escape_filter($this->env, $key, 'html'), 'Failed to escape: '.$key); + } + } + + public function testHtmlAttributeEscapingConvertsSpecialChars() + { + foreach ($this->htmlAttrSpecialChars as $key => $value) { + $this->assertEquals($value, twig_escape_filter($this->env, $key, 'html_attr'), 'Failed to escape: '.$key); + } + } + + public function testJavascriptEscapingConvertsSpecialChars() + { + foreach ($this->jsSpecialChars as $key => $value) { + $this->assertEquals($value, twig_escape_filter($this->env, $key, 'js'), 'Failed to escape: '.$key); + } + } + + public function testJavascriptEscapingReturnsStringIfZeroLength() + { + $this->assertEquals('', twig_escape_filter($this->env, '', 'js')); + } + + public function testJavascriptEscapingReturnsStringIfContainsOnlyDigits() + { + $this->assertEquals('123', twig_escape_filter($this->env, '123', 'js')); + } + + public function testCssEscapingConvertsSpecialChars() + { + foreach ($this->cssSpecialChars as $key => $value) { + $this->assertEquals($value, twig_escape_filter($this->env, $key, 'css'), 'Failed to escape: '.$key); + } + } + + public function testCssEscapingReturnsStringIfZeroLength() + { + $this->assertEquals('', twig_escape_filter($this->env, '', 'css')); + } + + public function testCssEscapingReturnsStringIfContainsOnlyDigits() + { + $this->assertEquals('123', twig_escape_filter($this->env, '123', 'css')); + } + + public function testUrlEscapingConvertsSpecialChars() + { + foreach ($this->urlSpecialChars as $key => $value) { + $this->assertEquals($value, twig_escape_filter($this->env, $key, 'url'), 'Failed to escape: '.$key); + } + } + + /** + * Range tests to confirm escaped range of characters is within OWASP recommendation + */ + + /** + * Only testing the first few 2 ranges on this prot. function as that's all these + * other range tests require + */ + public function testUnicodeCodepointConversionToUtf8() + { + $expected = " ~ޙ"; + $codepoints = array(0x20, 0x7e, 0x799); + $result = ''; + foreach ($codepoints as $value) { + $result .= $this->codepointToUtf8($value); + } + $this->assertEquals($expected, $result); + } + + /** + * Convert a Unicode Codepoint to a literal UTF-8 character. + * + * @param int $codepoint Unicode codepoint in hex notation + * + * @return string UTF-8 literal string + */ + protected function codepointToUtf8($codepoint) + { + if ($codepoint < 0x80) { + return chr($codepoint); + } + if ($codepoint < 0x800) { + return chr($codepoint >> 6 & 0x3f | 0xc0) + .chr($codepoint & 0x3f | 0x80); + } + if ($codepoint < 0x10000) { + return chr($codepoint >> 12 & 0x0f | 0xe0) + .chr($codepoint >> 6 & 0x3f | 0x80) + .chr($codepoint & 0x3f | 0x80); + } + if ($codepoint < 0x110000) { + return chr($codepoint >> 18 & 0x07 | 0xf0) + .chr($codepoint >> 12 & 0x3f | 0x80) + .chr($codepoint >> 6 & 0x3f | 0x80) + .chr($codepoint & 0x3f | 0x80); + } + throw new Exception('Codepoint requested outside of Unicode range'); + } + + public function testJavascriptEscapingEscapesOwaspRecommendedRanges() + { + $immune = array(',', '.', '_'); // Exceptions to escaping ranges + for ($chr = 0; $chr < 0xFF; $chr++) { + if ($chr >= 0x30 && $chr <= 0x39 + || $chr >= 0x41 && $chr <= 0x5A + || $chr >= 0x61 && $chr <= 0x7A) { + $literal = $this->codepointToUtf8($chr); + $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'js')); + } else { + $literal = $this->codepointToUtf8($chr); + if (in_array($literal, $immune)) { + $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'js')); + } else { + $this->assertNotEquals( + $literal, + twig_escape_filter($this->env, $literal, 'js'), + "$literal should be escaped!"); + } + } + } + } + + public function testHtmlAttributeEscapingEscapesOwaspRecommendedRanges() + { + $immune = array(',', '.', '-', '_'); // Exceptions to escaping ranges + for ($chr = 0; $chr < 0xFF; $chr++) { + if ($chr >= 0x30 && $chr <= 0x39 + || $chr >= 0x41 && $chr <= 0x5A + || $chr >= 0x61 && $chr <= 0x7A) { + $literal = $this->codepointToUtf8($chr); + $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'html_attr')); + } else { + $literal = $this->codepointToUtf8($chr); + if (in_array($literal, $immune)) { + $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'html_attr')); + } else { + $this->assertNotEquals( + $literal, + twig_escape_filter($this->env, $literal, 'html_attr'), + "$literal should be escaped!"); + } + } + } + } + + public function testCssEscapingEscapesOwaspRecommendedRanges() + { + // CSS has no exceptions to escaping ranges + for ($chr = 0; $chr < 0xFF; $chr++) { + if ($chr >= 0x30 && $chr <= 0x39 + || $chr >= 0x41 && $chr <= 0x5A + || $chr >= 0x61 && $chr <= 0x7A) { + $literal = $this->codepointToUtf8($chr); + $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'css')); + } else { + $literal = $this->codepointToUtf8($chr); + $this->assertNotEquals( + $literal, + twig_escape_filter($this->env, $literal, 'css'), + "$literal should be escaped!"); + } + } + } +} diff --git a/vendor/twig/twig/test/bootstrap.php b/vendor/twig/twig/test/bootstrap.php new file mode 100755 index 0000000..aecb976 --- /dev/null +++ b/vendor/twig/twig/test/bootstrap.php @@ -0,0 +1,13 @@ +