From e8e63a2d2540e1ca37b253b02e07768b5fd42e61 Mon Sep 17 00:00:00 2001 From: Jesal Gadhia Date: Fri, 4 May 2012 21:51:01 -0700 Subject: [PATCH] Fixing dir structure --- .../.htaccess => .htaccess | 0 .../Slim/Environment.php | 0 .../Slim/Exception/Pass.php | 0 .../Slim/Exception/RequestSlash.php | 0 .../Slim/Exception/Stop.php | 0 .../Slim/Http/Headers.php | 0 .../Slim/Http/Request.php | 0 .../Slim/Http/Response.php | 0 .../Slim/Http/Util.php | 0 Slim/{codeguy-Slim-aa7e919 => }/Slim/Log.php | 0 .../Slim/LogFileWriter.php | 0 .../Slim/Middleware.php | 0 .../Slim/Middleware/ContentTypes.php | 0 .../Slim/Middleware/Flash.php | 0 .../Slim/Middleware/MethodOverride.php | 0 .../Slim/Middleware/PrettyExceptions.php | 0 .../Slim/Middleware/SessionCookie.php | 0 .../{codeguy-Slim-aa7e919 => }/Slim/Route.php | 0 .../Slim/Router.php | 0 Slim/{codeguy-Slim-aa7e919 => }/Slim/Slim.php | 0 Slim/{codeguy-Slim-aa7e919 => }/Slim/View.php | 0 Slim/codeguy-Slim-aa7e919/LICENSE | 19 - Slim/codeguy-Slim-aa7e919/README.markdown | 163 --- Slim/codeguy-Slim-aa7e919/composer.json | 21 - .../docs/caching-etag.markdown | 12 - .../docs/caching-expires.markdown | 11 - .../docs/caching-last-modified.markdown | 10 - .../docs/caching.markdown | 9 - .../docs/environment.markdown | 56 - .../docs/errors-debug.markdown | 19 - .../docs/errors-error-handler.markdown | 29 - .../docs/errors-notfound-handler.markdown | 35 - .../docs/errors-output.markdown | 18 - .../docs/errors-reporting.markdown | 3 - .../codeguy-Slim-aa7e919/docs/errors.markdown | 7 - Slim/codeguy-Slim-aa7e919/docs/flash.markdown | 25 - .../docs/hooks-custom.markdown | 10 - .../docs/hooks-default.markdown | 21 - .../docs/hooks-usage.markdown | 33 - Slim/codeguy-Slim-aa7e919/docs/hooks.markdown | 7 - Slim/codeguy-Slim-aa7e919/docs/index.txt | 144 -- .../docs/instantiation.markdown | 11 - .../docs/logging.markdown | 104 -- .../docs/middleware-add.markdown | 28 - .../docs/middleware-architecture.markdown | 36 - .../docs/middleware-implementation.markdown | 11 - .../docs/middleware.markdown | 3 - Slim/codeguy-Slim-aa7e919/docs/modes.markdown | 54 - .../docs/names-and-scopes.markdown | 58 - .../docs/request-cookies.markdown | 24 - .../docs/request-headers.markdown | 15 - .../docs/request-helpers.markdown | 46 - .../docs/request-method.markdown | 27 - .../docs/request-parameters.markdown | 24 - .../docs/request-paths.markdown | 19 - .../docs/request-xhr.markdown | 8 - .../docs/request.markdown | 7 - .../docs/response-body.markdown | 16 - .../docs/response-cookies.markdown | 47 - .../docs/response-header.markdown | 15 - .../docs/response-helpers.markdown | 52 - .../docs/response-status.markdown | 9 - .../docs/response.markdown | 9 - .../docs/routing-conditions.markdown | 30 - .../docs/routing-custom.markdown | 29 - .../docs/routing-delete.markdown | 32 - .../docs/routing-generic.markdown | 11 - .../docs/routing-get.markdown | 20 - .../docs/routing-helpers-halt.markdown | 22 - .../docs/routing-helpers-pass.markdown | 13 - .../docs/routing-helpers-redirect.markdown | 19 - .../docs/routing-helpers-stop.markdown | 11 - .../docs/routing-helpers-urlfor.markdown | 15 - .../docs/routing-helpers.markdown | 3 - .../docs/routing-indepth-slashes.markdown | 17 - .../routing-indepth-with-rewrite.markdown | 30 - .../routing-indepth-without-rewrite.markdown | 11 - .../docs/routing-indepth.markdown | 13 - .../docs/routing-middleware.markdown | 49 - .../docs/routing-names.markdown | 15 - .../docs/routing-options.markdown | 30 - .../docs/routing-parameters.markdown | 40 - .../docs/routing-post.markdown | 20 - .../docs/routing-put.markdown | 32 - .../docs/routing.markdown | 7 - .../docs/sessions.markdown | 38 - .../docs/settings.markdown | 192 --- .../docs/system-requirements.markdown | 7 - .../docs/views-custom.markdown | 47 - .../docs/views-data.markdown | 31 - .../docs/views-rendering.markdown | 32 - .../docs/views-settings.markdown | 15 - Slim/codeguy-Slim-aa7e919/docs/views.markdown | 43 - .../docs/welcome.markdown | 6 - Slim/codeguy-Slim-aa7e919/index.php | 163 --- .../tests/EnvironmentTest.php | 340 ----- Slim/codeguy-Slim-aa7e919/tests/Foo.php | 7 - .../tests/Http/HeadersTest.php | 137 -- .../tests/Http/RequestTest.php | 875 ------------ .../tests/Http/ResponseTest.php | 534 ------- .../tests/Http/UtilTest.php | 352 ----- .../tests/LogFileWriterTest.php | 49 - Slim/codeguy-Slim-aa7e919/tests/LogTest.php | 138 -- .../tests/Middleware/ContentTypesTest.php | 157 --- .../tests/Middleware/FlashTest.php | 110 -- .../tests/Middleware/MethodOverrideTest.php | 145 -- .../tests/Middleware/PrettyExceptionsTest.php | 79 -- .../tests/Middleware/SessionCookieTest.php | 110 -- .../tests/MiddlewareTest.php | 82 -- Slim/codeguy-Slim-aa7e919/tests/README | 18 - Slim/codeguy-Slim-aa7e919/tests/RouteTest.php | 444 ------ .../codeguy-Slim-aa7e919/tests/RouterTest.php | 329 ----- Slim/codeguy-Slim-aa7e919/tests/SlimTest.php | 1229 ----------------- Slim/codeguy-Slim-aa7e919/tests/ViewTest.php | 180 --- .../tests/templates/test.php | 1 - index.php | 4 +- 116 files changed, 2 insertions(+), 7636 deletions(-) rename Slim/codeguy-Slim-aa7e919/.htaccess => .htaccess (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Environment.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Exception/Pass.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Exception/RequestSlash.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Exception/Stop.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Http/Headers.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Http/Request.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Http/Response.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Http/Util.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Log.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/LogFileWriter.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Middleware.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Middleware/ContentTypes.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Middleware/Flash.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Middleware/MethodOverride.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Middleware/PrettyExceptions.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Middleware/SessionCookie.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Route.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Router.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/Slim.php (100%) rename Slim/{codeguy-Slim-aa7e919 => }/Slim/View.php (100%) delete mode 100644 Slim/codeguy-Slim-aa7e919/LICENSE delete mode 100644 Slim/codeguy-Slim-aa7e919/README.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/composer.json delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/caching-etag.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/caching-expires.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/caching-last-modified.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/caching.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/environment.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/errors-debug.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/errors-error-handler.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/errors-notfound-handler.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/errors-output.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/errors-reporting.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/errors.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/flash.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/hooks-custom.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/hooks-default.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/hooks-usage.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/hooks.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/index.txt delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/instantiation.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/logging.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/middleware-add.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/middleware-architecture.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/middleware-implementation.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/middleware.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/modes.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/names-and-scopes.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-cookies.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-headers.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-helpers.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-method.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-parameters.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-paths.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request-xhr.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/request.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/response-body.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/response-cookies.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/response-header.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/response-helpers.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/response-status.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/response.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-conditions.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-custom.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-delete.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-generic.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-get.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-helpers-halt.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-helpers-pass.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-helpers-redirect.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-helpers-stop.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-helpers-urlfor.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-helpers.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-indepth-slashes.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-indepth-with-rewrite.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-indepth-without-rewrite.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-indepth.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-middleware.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-names.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-options.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-parameters.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-post.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing-put.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/routing.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/sessions.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/settings.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/system-requirements.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/views-custom.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/views-data.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/views-rendering.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/views-settings.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/views.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/docs/welcome.markdown delete mode 100644 Slim/codeguy-Slim-aa7e919/index.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/EnvironmentTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Foo.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Http/HeadersTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Http/RequestTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Http/ResponseTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Http/UtilTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/LogFileWriterTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/LogTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Middleware/ContentTypesTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Middleware/FlashTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Middleware/MethodOverrideTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Middleware/PrettyExceptionsTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/Middleware/SessionCookieTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/MiddlewareTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/README delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/RouteTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/RouterTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/SlimTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/ViewTest.php delete mode 100644 Slim/codeguy-Slim-aa7e919/tests/templates/test.php diff --git a/Slim/codeguy-Slim-aa7e919/.htaccess b/.htaccess similarity index 100% rename from Slim/codeguy-Slim-aa7e919/.htaccess rename to .htaccess diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Environment.php b/Slim/Slim/Environment.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Environment.php rename to Slim/Slim/Environment.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Exception/Pass.php b/Slim/Slim/Exception/Pass.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Exception/Pass.php rename to Slim/Slim/Exception/Pass.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Exception/RequestSlash.php b/Slim/Slim/Exception/RequestSlash.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Exception/RequestSlash.php rename to Slim/Slim/Exception/RequestSlash.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Exception/Stop.php b/Slim/Slim/Exception/Stop.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Exception/Stop.php rename to Slim/Slim/Exception/Stop.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Http/Headers.php b/Slim/Slim/Http/Headers.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Http/Headers.php rename to Slim/Slim/Http/Headers.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Http/Request.php b/Slim/Slim/Http/Request.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Http/Request.php rename to Slim/Slim/Http/Request.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Http/Response.php b/Slim/Slim/Http/Response.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Http/Response.php rename to Slim/Slim/Http/Response.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Http/Util.php b/Slim/Slim/Http/Util.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Http/Util.php rename to Slim/Slim/Http/Util.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Log.php b/Slim/Slim/Log.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Log.php rename to Slim/Slim/Log.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/LogFileWriter.php b/Slim/Slim/LogFileWriter.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/LogFileWriter.php rename to Slim/Slim/LogFileWriter.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Middleware.php b/Slim/Slim/Middleware.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Middleware.php rename to Slim/Slim/Middleware.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Middleware/ContentTypes.php b/Slim/Slim/Middleware/ContentTypes.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Middleware/ContentTypes.php rename to Slim/Slim/Middleware/ContentTypes.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Middleware/Flash.php b/Slim/Slim/Middleware/Flash.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Middleware/Flash.php rename to Slim/Slim/Middleware/Flash.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Middleware/MethodOverride.php b/Slim/Slim/Middleware/MethodOverride.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Middleware/MethodOverride.php rename to Slim/Slim/Middleware/MethodOverride.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Middleware/PrettyExceptions.php b/Slim/Slim/Middleware/PrettyExceptions.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Middleware/PrettyExceptions.php rename to Slim/Slim/Middleware/PrettyExceptions.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Middleware/SessionCookie.php b/Slim/Slim/Middleware/SessionCookie.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Middleware/SessionCookie.php rename to Slim/Slim/Middleware/SessionCookie.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Route.php b/Slim/Slim/Route.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Route.php rename to Slim/Slim/Route.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Router.php b/Slim/Slim/Router.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Router.php rename to Slim/Slim/Router.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/Slim.php b/Slim/Slim/Slim.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/Slim.php rename to Slim/Slim/Slim.php diff --git a/Slim/codeguy-Slim-aa7e919/Slim/View.php b/Slim/Slim/View.php similarity index 100% rename from Slim/codeguy-Slim-aa7e919/Slim/View.php rename to Slim/Slim/View.php diff --git a/Slim/codeguy-Slim-aa7e919/LICENSE b/Slim/codeguy-Slim-aa7e919/LICENSE deleted file mode 100644 index eec67e7..0000000 --- a/Slim/codeguy-Slim-aa7e919/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2011 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. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/README.markdown b/Slim/codeguy-Slim-aa7e919/README.markdown deleted file mode 100644 index f1e2101..0000000 --- a/Slim/codeguy-Slim-aa7e919/README.markdown +++ /dev/null @@ -1,163 +0,0 @@ -# Slim Framework for PHP 5 - -Slim is a micro framework for PHP 5 that helps you quickly write simple yet powerful RESTful 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 Slim for your next project. I think you're going to love it. - -## Features - -* Clean and simple [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for writing powerful web applications -* HTTP routing - * Supports all standard and custom HTTP request methods - * Route parameters and conditions - * Route redirects - * Route passing - * Route halting - * Route middleware - * Named routes and `urlFor()` helper -* Easy configuration -* Easy templating with custom Views (e.g. Twig, Mustache, Smarty) -* Flash messaging -* Signed cookies with AES-256 encryption -* HTTP caching (ETag and Last-Modified) -* Logging -* Error handling - * Custom Not Found handler - * Custom Error handler - * Debugging -* Built upon the Rack protocol -* Extensible middleware and hook architecture -* Supports PHP >= 5.2.0 - -## "Hello World" application (PHP >= 5.3) - -The Slim Framework for PHP 5 supports anonymous functions. This is the preferred method to define Slim application routes. This example assumes you have setup URL rewriting with your web server (see below). - -```php -get('/hello/:name', function ($name) { - echo "Hello, $name!"; -}); -$app->run(); -``` - -## "Hello World" application (PHP < 5.3) - -If you are running PHP < 5.3, the second argument to the application's `get()` instance method is the name of a callable function instead of an anonymous function. This example assumes you have setup URL rewriting with your web server (see below). - -```php -get('/hello/:name', 'hello'); -function hello($name) { - echo "Hello, $name!"; -} -$app->run(); -``` - -## Get Started - -### Install Slim - -Download the Slim Framework for PHP 5 and unzip the downloaded file into your virtual host's public directory. Slim will work in a sub-directory, too. - -### Setup your webserver - -#### 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] - -#### Nginx - -Your nginx configuration file should contain this code (along with other settings you may need) in your `location` block: - - if (!-f $request_filename) { - rewrite ^ /index.php last; - } - -This assumes that Slim's `index.php` is in the root folder of your project (www root). - -#### 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") - -This assumes that Slim's `index.php` is in the root folder of your project (www root). - -### Build Your Application - -Your Slim application will be defined in `index.php`. First, `require` the Slim Framework: - -```php -require 'Slim/Slim.php'; -``` - -Next, initialize the Slim application: - -```php -$app = new Slim(); -``` - -Next, define your application's routes: - -```php -$app->get('/hello/:name', function ($name) { - echo "Hello $name"; -}); -``` - -Finally, run your Slim application: - -```php - $app->run(); -``` - -For more information about building an application with the Slim Framework, refer to the [official documentation](http://github.com/codeguy/Slim/wiki/Slim-Framework-Documentation). - -## Documentation - -* [Stable Branch Documentation](http://www.slimframework.com/documentation/stable) -* [Development Branch Documentation](http://www.slimframework.com/documentation/develop) - -## 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 the very latest news and updates about the framework. - -### IRC - -You can find me, Josh Lockhart, hanging out in the ##slim chat room during the day. Feel free to say hi, ask questions, or just hang out. If you're on a Mac, check out Colloquy; if you're on a PC, check out mIRC; if you're on Linux, I'm sure you already know what you're doing. - -## Resources - -Additional resources (ie. custom Views and plugins) are available online in a separate repository. - - - -Here are more links that may also be useful. - -* Road Map: -* Source Code: - -## About the Author - -Slim is created and maintained by Josh Lockhart, a web developer by day at [New Media Campaigns](http://www.newmediacampaigns.com), and a [hacker by night](http://github.com/codeguy). - -Slim is in active development, and test coverage is continually improving. - -## Open Source License - -Slim is released under the MIT public license. - - diff --git a/Slim/codeguy-Slim-aa7e919/composer.json b/Slim/codeguy-Slim-aa7e919/composer.json deleted file mode 100644 index 8c8bcbe..0000000 --- a/Slim/codeguy-Slim-aa7e919/composer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "slim/slim", - "type": "library", - "description": "Slim Framework, a micro framework for PHP 5", - "keywords": ["templating","extensions"], - "homepage": "http://github.com/codeguy/Slim", - "license": "MIT", - "authors": [ - { - "name": "Josh Lockhart", - "email": "info@joshlockhart.com", - "homepage": "http://www.joshlockhart.com/" - } - ], - "require": { - "php": ">=5.2.0" - }, - "autoload": { - "psr-0": { "Slim": "Slim/" } - } -} diff --git a/Slim/codeguy-Slim-aa7e919/docs/caching-etag.markdown b/Slim/codeguy-Slim-aa7e919/docs/caching-etag.markdown deleted file mode 100644 index f62f7cd..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/caching-etag.markdown +++ /dev/null @@ -1,12 +0,0 @@ -# Etag [caching-etag] # - -A Slim application provides built-in support for HTTP caching using ETags. An ETag is a unique identifier for a resource URI. When an ETag header is set with the `etag()` method, the HTTP client will send an **If-None-Match** header with each subsequent HTTP request of the same resource URI. If the ETag value for the resource URI matches the **If-None-Match** HTTP request header, the Slim application will return a **304 Not Modified** HTTP response that will prompt the HTTP client to continue using its cache; this also prevents the Slim application from serving the entire markup for the resource URI, saving bandwidth and response time. - -Setting an ETag with Slim is very simple. Invoke the `etag()` application method in your route callback, passing it a unique ID as the first and only argument. - - $app->get('/foo', function () use ($app) { - $app->etag('unique-id'); - echo "This will be cached after the initial request!"; - }); - -That’s it. Make sure the unique ETag ID *is unique for the given resource*. Also make sure the ETag unique ID changes as your resource changes; otherwise, the HTTP client will continue serving its outdated cache. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/caching-expires.markdown b/Slim/codeguy-Slim-aa7e919/docs/caching-expires.markdown deleted file mode 100644 index 4dabf86..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/caching-expires.markdown +++ /dev/null @@ -1,11 +0,0 @@ -# Expires [caching-expires] # - -Used in conjunction with the Slim application's `etag()` or `lastModified()` methods, the `expires()` method sets an `Expires:` header on the HTTP response informing the HTTP client when its client-side cache for the current resource should be considered stale. The HTTP client will continue serving from its client-side cache until the expiration date is reached, at which time the HTTP client will send a conditional GET request to the Slim application. - -The `expires()` method accepts one argument: an integer UNIX timestamp, or a string to be parsed with `strtotime()`. - - $app->get('/foo', function () use ($app) { - $app->etag('unique-resource-id'); - $app->expires('+1 week'); - echo "This will be cached client-side for one week"; - }); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/caching-last-modified.markdown b/Slim/codeguy-Slim-aa7e919/docs/caching-last-modified.markdown deleted file mode 100644 index df0f39e..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/caching-last-modified.markdown +++ /dev/null @@ -1,10 +0,0 @@ -# Last-Modified [caching-last-modified] # - -A Slim application provides built-in support for HTTP caching using the resource’s last modified date. When you specify a last modified date, Slim tells the HTTP client the date and time the current resource was last modified. The HTTP client will then send a **If-Modified-Since** header with each subsequent HTTP request for the given resource URI. If the last modification date you specify matches the **If-Modified-Since** HTTP request header, the Slim application will return a **304 Not Modified** HTTP response that will prompt the HTTP client to use its cache; this also prevents the Slim application from serving the entire markup for the resource URI saving bandwidth and response time. - -Setting a last modified date with Slim is very simple. You only need to invoke the `lastModified()` application instance method in your route callback passing in a UNIX timestamp that represents the last modification date for the given resource. Be sure the `lastModified()` application instance method's timestamp updates along with the resource’s last modification date; otherwise, the browser client will continue serving its outdated cache. - - $app->get('/foo', function () use ($app) { - $app->lastModified(1286139652); - echo "This will be cached after the initial request!"; - }); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/caching.markdown b/Slim/codeguy-Slim-aa7e919/docs/caching.markdown deleted file mode 100644 index 2c46d3b..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/caching.markdown +++ /dev/null @@ -1,9 +0,0 @@ -# HTTP Caching [caching] # - -A Slim application provides built-in support for HTTP caching with its `etag()`, `lastModified()`, and `expires()` instance methods. It is best to use _one_ of `etag()` or `lastModified()` — in conjunction with `expires()` — per route; never use _both_ `etag()` and `lastModified()` together in the same route callback. - -The `etag()` and `lastModified()` methods should be invoked in a route callback *before* other code; this allows Slim to check conditional GET requests _before_ processing the route callback's remaining code. - -Both `etag()` and `lastModified()` instruct the HTTP client to store the resource response in a client-side cache. The `expires()` method indicates to the HTTP client when the client-side cache should be considered stale. - -More details for each method are below. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/environment.markdown b/Slim/codeguy-Slim-aa7e919/docs/environment.markdown deleted file mode 100644 index fc485dc..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/environment.markdown +++ /dev/null @@ -1,56 +0,0 @@ -# The Environment [environment] # - -The Slim Framework implements a derivation of the [Rack protocol](http://rack.rubyforge.org/doc/files/SPEC.html). When you instantiate a Slim application, it immediately inspects the `$_SERVER` superglobal and derives a set of environment variables that dictate application behavior. - -## What is the Environment? ## - -A Slim application's "environment" is an associative array of settings that are parsed once and made accessible to the Slim application and its middleware. You are free to modify the environment variables during runtime; changes will propagate immediately throughout the application. - -When you instantiate a Slim application, the environment variables are derived from the `$_SERVER` superglobal; you do not need to set these yourself. However, you are free to modify or supplement these variables in [Slim middleware](#middleware). - -These variables are fundamental to determining how your Slim application runs: the resource URI, the HTTP method, the HTTP request body, the URL query parameters, error output, and more. Middleware, described later, gives you the power to — among other things — manipulate environment variables before and/or after the Slim application is run. - -## Environment Variables ## - -The following text respectfully borrows the same information originally available at . The environment array **must** include these variables: - -REQUEST_METHOD -: The HTTP request method. This is required and may never be an empty string. - -SCRIPT_NAME -: The initial portion of the request URI's "path" that corresponds to the physical directory in which the Slim application is installed --- so that the application knows its virtual "location". This may be an empty string if the application is installed in the top-level of the public document root directory. This will never have a trailing slash. - -PATH_INFO -: The remaining portion of the request URI's "path" that determines the "virtual" location of the HTTP request's target resource within the Slim application context. This will always have a leading slash; it may or may not have a trailing slash. - -QUERY_STRING -: The part of the HTTP request's URI after, but not including, the "?". This is required but may be an empty string. - -SERVER_NAME -: When combined with **SCRIPT\_NAME** and **PATH\_INFO**, this can be used to create a fully qualified URL to an application resource. However, if **HTTP_HOST** is present, that should be used instead of this. This is required and may never be an empty string. - -SERVER_PORT -: When combined with **SCRIPT\_NAME** and **PATH\_INFO**, this can be used to create a fully qualified URL to any application resource. This is required and may never be an empty string. - -HTTP_* -: Variables matching the HTTP request headers sent by the client. The existence of these variables correspond with those sent in the current HTTP request. - -slim.url_scheme -: Will be "http" or "https" depending on the HTTP request URL. - -slim.input -: Will be a string representing the raw HTTP request body. If the HTTP request body is empty (e.g. with a GET request), this will be an empty string. - -slim.errors -: Must always be a writable resource; by default, this is a write-only resource handle to **php://stderr**. - -The Slim application can store its own data in the environment, too. The environment array's keys must contain at least one dot, and should be prefixed uniquely (e.g. "prefix.foo"). The prefix **slim.** is reserved for use by Slim itself and must not be used otherwise. The environment must not contain the keys **HTTP\_CONTENT\_TYPE** or **HTTP\_CONTENT\_LENGTH** (use the versions without **HTTP\_**). The CGI keys (named without a period) must have String values. There are the following restrictions: - -* slim.url_scheme must either be "http" or "https". -* slim.input must be a string. -* There must be a valid, writable resource in "slim.errors". -* The **REQUEST\_METHOD** must be a valid token. -* The **SCRIPT\_NAME**, if non-empty, must start with / -* The **PATH\_INFO**, if non-empty, must start with / -* The **CONTENT_LENGTH**, if given, must consist of digits only. -* One of **SCRIPT\_NAME** or **PATH\_INFO** must be set. **PATH\_INFO** should be / if **SCRIPT\_NAME** is empty. **SCRIPT\_NAME** never should be /, but instead be an empty string. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/errors-debug.markdown b/Slim/codeguy-Slim-aa7e919/docs/errors-debug.markdown deleted file mode 100644 index 63a98d3..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/errors-debug.markdown +++ /dev/null @@ -1,19 +0,0 @@ -# Debugging [errors-debug] # - -You can enable debugging during application instantiation with this setting: - - $app = new Slim(array( - 'debug' => true - )); - -You may also enable debugging during runtime with the Slim application's `config()` instance method. - - $app = new Slim(); - - //Enable debugging (on by default) - $app->config('debug', true); - - //Disable debugging - $app->config('debug', false); - -If debugging is enabled and an exception or error occurs, a detailed error message will appear with the error description, the affected file, the file line number, and a stack trace. If debugging is disabled, your [custom Error handler](#error-handler) will be invoked instead. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/errors-error-handler.markdown b/Slim/codeguy-Slim-aa7e919/docs/errors-error-handler.markdown deleted file mode 100644 index 55e4b14..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/errors-error-handler.markdown +++ /dev/null @@ -1,29 +0,0 @@ -# Error Handler [error-handler] # - -You may use the Slim application's `error()` instance method to specify a custom error handler to be invoked when an error or exception occurs. Custom error handlers are only invoked if application debugging is disabled. - -A custom error handler should render a user-friendly message that mitigates user confusion. Similar to the Slim application's `notFound()` instance method, the `error()` instance method acts as both a getter and a setter. - -## Set a Custom Error Handler ## - -You may set a custom error handler by passing a callable into the `error()` instance method as the first and only argument. - - $app = new Slim(); - - //PHP >= 5.3 - $app->error(function ( Exception $e ) use ($app) { - $app->render('error.php'); - }); - - //PHP < 5.3 - $app->error('custom_error_handler'); - function custom_error_handler( Exception $e ){ - $app = Slim::getInstance(); - $app->render('error.php'); - } - -In this example, notice how the custom error handler accepts the caught Exception as its argument. This allows you to respond appropriately to different exceptions. - -## Invoke a Custom Error Handler ## - -Usually, the Slim application will automatically invoke the error handler when an exception or error occurs. However, you may also manually invoke the error handler with the Slim application's `error()` method (without an argument). \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/errors-notfound-handler.markdown b/Slim/codeguy-Slim-aa7e919/docs/errors-notfound-handler.markdown deleted file mode 100644 index 153a395..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/errors-notfound-handler.markdown +++ /dev/null @@ -1,35 +0,0 @@ -# Not Found Handler [not-found-handler] # - -It is an inevitability that someone will request a page that does not exist. The Slim application lets you easily define a custom **Not Found** handler with the Slim application's `notFound()` instance method. The Not Found handler will be invoked when a matching route is not found for the current HTTP request. This method may be invoked in two different contexts. - -## When defining the handler ## - -If you invoke the Slim application's `notFound()` instance method and specify a callable object as its first and only argument, this method will register the callable object as the Not Found handler. However, the registered handler will not be invoked. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->notFound(function () use ($app) { - $app->render('404.html'); - }); - - //For PHP < 5.3 - $app->notFound('custom_not_found_callback'); - function custom_not_found_callback() { - $app = Slim::getInstance(); - $app->render('404.html'); - } - -## When invoking the Not Found handler ## - -If you invoke the Slim application's `notFound()` instance method without any arguments, this method will invoke the previously registered Not Found handler. - - $app = new Slim(); - - $app->get('/hello/:name', function ($name) use ($app) { - if ( $name === 'Waldo' ) { - $app->notFound(); - } else { - echo "Hello, $name"; - } - }); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/errors-output.markdown b/Slim/codeguy-Slim-aa7e919/docs/errors-output.markdown deleted file mode 100644 index d6dbd30..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/errors-output.markdown +++ /dev/null @@ -1,18 +0,0 @@ -# Error Output [errors-output] # - -The Slim environment will always contain a key **slim.errors** with a value that is a writable resource to which log and error messages may be written. The Slim application's [Slim_Log](#logging) object will write log messages to **slim.errors** whenever an Exception is caught or the `Slim_Log` object is manually invoked. - -If you want to redirect error output to a different location, you can define your own writable resource by modifying the Slim application's environment settings. I recommend you use [middleware](#middleware) to update the environment like this: - - class CustomErrorMiddleware extends Slim_Middleware { - public function call() { - // Set new error output - $env = $this->app->environment(); - $env['slim.errors'] = fopen('/path/to/custom/output', 'w'); - - // Call next middleware - $this->next->call(); - } - } - -Remember, **slim.errors** does not have to point to a file; it can point to any valid writable resource. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/errors-reporting.markdown b/Slim/codeguy-Slim-aa7e919/docs/errors-reporting.markdown deleted file mode 100644 index e2095c5..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/errors-reporting.markdown +++ /dev/null @@ -1,3 +0,0 @@ -# Error Reporting [errors-reporting] # - -By default, Slim will report **E\_ALL** and **E\_STRICT** errors. You can change the error reporting by editing **Slim/Slim.php**; the error reporting definition is at the top of that file. Only reported errors will be handled by Slim. Unreported errors will be ignored or handled elsewhere. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/errors.markdown b/Slim/codeguy-Slim-aa7e919/docs/errors.markdown deleted file mode 100644 index ca25534..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/errors.markdown +++ /dev/null @@ -1,7 +0,0 @@ -# Error Handling [errors] # - -Let’s face it: sometimes things go wrong. It is important to intercept errors and respond to them appropriately. A Slim application provides helper methods to respond to errors and exceptions. - -Each Slim application handles its own errors and exceptions. If there are multiple Slim applications in the same PHP script, each application will catch and handle its own errors and exceptions. Errors or exceptions generated outside of a Slim application must be caught and handled elsewhere. - -To prevent recoverable errors from stopping the entire PHP script, Slim converts errors into `ErrorException` instances that are caught and handled by a default or custom Slim application error handler. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/flash.markdown b/Slim/codeguy-Slim-aa7e919/docs/flash.markdown deleted file mode 100644 index e8ec612..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/flash.markdown +++ /dev/null @@ -1,25 +0,0 @@ -# Flash Messaging [flash] # - -Slim supports flash messaging much like Rails and other larger web frameworks. Flash messaging allows you to define messages that will persist until the next HTTP request but no further. This is helpful to display messages to the user after a given event or error occurs. - -As shown below, the Slim application's `flash()` and `flashNow()` instance methods accept two arguments: a key and a message. The key may be whatever you want and defines how the message will be accessed in the View templates. For example, if I invoke the Slim application's `flash('foo', 'The foo message')` instance method with those arguments, I can access that message in the next request’s templates with `flash['foo']`. - -Flash messages are persisted with sessions; sessions are required for flash messages to work. Flash messages are stored in `$\_SESSION['flash']`. - -## Flash - -The Slim application's `flash()` instance method sets a message that will be available in the next request’s view templates. The message in this example will be available in the variable `flash['error']` in the next request’s view templates. - - $app->flash('error', 'User email is required'); - -## Flash Now - -The Slim application's `flashNow()` instance method sets a message that will be available in the current request’s view templates. Messages set with the `flashNow()` application instance method will not be available in the next request. The message in the example below will be available in the variable `flash['info']` in the current request’s view templates. - - $app->flashNow('info', 'Your credit card is expired'); - -## Flash Keep - -This method tells the Slim application to keep existing flash messages set in the previous request so they will be available to the next request. This method is helpful for persisting flash messages across HTTP redirects. - - $app->flashKeep(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/hooks-custom.markdown b/Slim/codeguy-Slim-aa7e919/docs/hooks-custom.markdown deleted file mode 100644 index 39a4d8d..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/hooks-custom.markdown +++ /dev/null @@ -1,10 +0,0 @@ -# Custom Hooks [hooks-custom] # - -Custom hooks may also be created and invoked in a Slim application. When a custom hook is invoked with `applyHook()`, it will invoke all callables assigned to that hook. This is exactly how the Slim application's [default hooks](#hooks-default) work. In this example, I apply a custom hook called "my.hook.name". All callables previously registered for this hook will be invoked. - - $app = new Slim(); - $app->applyHook('my.hook.name'); - -When you run the above code, any callables previously assigned to the hook **my.hook.name** will be invoked in order of priority (ascending). - -You should register callables to a hook before the hook is applied. Think of it this way: when you invoke the Slim application's `applyHook()` instance method, you are asking Slim to invoke all callables already registered for that hook name. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/hooks-default.markdown b/Slim/codeguy-Slim-aa7e919/docs/hooks-default.markdown deleted file mode 100644 index 1419f39..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/hooks-default.markdown +++ /dev/null @@ -1,21 +0,0 @@ -# Default Hooks [hooks-default] # - -These are the default hooks always invoked in a Slim application. - -slim.before -: This hook is invoked before the Slim application is run and before output buffering is turned on. This hook is invoked once during the Slim application lifecycle. - -slim.before.router -: This hook is invoked after output buffering is turned on and before the router is dispatched. This hook is invoked once during the Slim application lifecycle. - -slim.before.dispatch -: This hook is invoked before the current matching route is dispatched. Usually this hook is invoked only once during the Slim application lifecycle; however, this hook may be invoked multiple times if a matching route chooses to pass to a subsequent matching route. - -slim.after.dispatch -: This hook is invoked after the current matching route is dispatched. Usually this hook is invoked only once during the Slim application lifecycle; however, this hook may be invoked multiple times if a matching route chooses to pass to a subsequent matching route. - -slim.after.router -: This hook is invoked after the router is dispatched, before the Response is sent to the client, and after output buffering is turned off. This hook is invoked once during the Slim application lifecycle. - -slim.after -: This hook is invoked after output buffering is turned off and after the Response is sent to the client. This hook is invoked once during the Slim application lifecycle. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/hooks-usage.markdown b/Slim/codeguy-Slim-aa7e919/docs/hooks-usage.markdown deleted file mode 100644 index cd4108a..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/hooks-usage.markdown +++ /dev/null @@ -1,33 +0,0 @@ -# How to use a hook # - -A callable is assigned to a hook using the Slim application's `hook()` instance method: - - $app = new Slim(); - $app->hook('the.hook.name', function () { - //Do something - }); - -The first argument is the hook name, and the second argument is the callable. Each hook maintains a priority list of registered callables. By default, each callable assigned to a hook is given a priority of 10. You can give your callable a different priority by passing an integer as the third parameter of the `hook()` method like this: - - $app = new Slim(); - $app->hook('the.hook.name', function () { - //Do something - }, 5); - -The example above assigns a priority of 5 to the callable. When the hook is called, it will sort all callables assigned to it by priority (ascending). A callable with priority 1 will be invoked before a callable with priority 10. - -Hooks do not pass arguments to their callables. If a callable needs to access the Slim application, you can inject the application into the callback with the `use` keyword or with the static `getInstance()` method: - - $app = new Slim(); - - //If using PHP >= 5.3 - $app->hook('the.hook.name', function () use ($app) { - // Do something - }); - - //If using PHP < 5.3 - $app->hook('the.hook.name', 'nameOfMyHookFunction'); - function nameOfMyHookFunction() { - $app = Slim::getInstance(); - //Do something - } \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/hooks.markdown b/Slim/codeguy-Slim-aa7e919/docs/hooks.markdown deleted file mode 100644 index 0aa6b9f..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/hooks.markdown +++ /dev/null @@ -1,7 +0,0 @@ -# Hooks [hooks] # - -A Slim application provides a set of hooks to which you can register your own callbacks. - -A “hook” is a moment in the Slim application lifecycle at which a priority list of callables assigned to the hook will be invoked. A hook is identified by a string name. - -A “callable” is anything that returns `true` for `is_callable()`. A callable is assigned to a hook and is invoked when the hook is called. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/index.txt b/Slim/codeguy-Slim-aa7e919/docs/index.txt deleted file mode 100644 index 570e202..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/index.txt +++ /dev/null @@ -1,144 +0,0 @@ -# Documentation -# -# This documentation is written in MultiMarkdown format and may be consolidated into HTML, PDF, -# ODF, Latex, or other formats using the `mmd_merge` command line utility. -# -# Learn more about MultiMarkdown at - -welcome.markdown - -system-requirements.markdown - -instantiation.markdown - - settings.markdown - - names-and-scopes.markdown - - modes.markdown - -routing.markdown - - routing-get.markdown - - routing-post.markdown - - routing-put.markdown - - routing-delete.markdown - - routing-options.markdown - - routing-generic.markdown - - routing-custom.markdown - - routing-parameters.markdown - - routing-names.markdown - - routing-conditions.markdown - - routing-middleware.markdown - - routing-helpers.markdown - - routing-helpers-halt.markdown - - routing-helpers-pass.markdown - - routing-helpers-redirect.markdown - - routing-helpers-stop.markdown - - routing-helpers-urlfor.markdown - - routing-indepth.markdown - - routing-indepth-slashes.markdown - - routing-indepth-with-rewrite.markdown - - routing-indepth-without-rewrite.markdown - -environment.markdown - -request.markdown - - request-method.markdown - - request-parameters.markdown - - request-headers.markdown - - request-cookies.markdown - - request-xhr.markdown - - request-paths.markdown - - request-helpers.markdown - -response.markdown - - response-status.markdown - - response-header.markdown - - response-body.markdown - - response-cookies.markdown - - response-helpers.markdown - -views.markdown - - views-rendering.markdown - - views-custom.markdown - - views-data.markdown - - views-settings.markdown - -caching.markdown - - caching-etag.markdown - - caching-last-modified.markdown - - caching-expires.markdown - -middleware.markdown - - middleware-architecture.markdown - - middleware-implementation.markdown - - middleware-add.markdown - -hooks.markdown - - hooks-usage.markdown - - hooks-custom.markdown - - hooks-default.markdown - -flash.markdown - -sessions.markdown - -logging.markdown - -errors.markdown - - errors-error-handler.markdown - - errors-notfound-handler.markdown - - errors-debug.markdown - - errors-reporting.markdown - - errors-output.markdown \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/instantiation.markdown b/Slim/codeguy-Slim-aa7e919/docs/instantiation.markdown deleted file mode 100644 index 42bea26..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/instantiation.markdown +++ /dev/null @@ -1,11 +0,0 @@ -# Instantiation - -First `require()` Slim into your application file. If you move the **Slim/** directory elsewhere on your filesystem, it is important that you keep Slim's dependencies in the same directory as Slim.php. Keeping the files together enables you to only require **Slim.php** and have the other files loaded automatically. Assuming the **Slim/** directory is on your include path, you only need to call: - - require 'Slim/Slim.php'; - -After you require Slim, instantiate your Slim application like this: - - $app = new Slim(); - -The Slim constructor accepts an optional associative array of settings to customize the Slim application during instantiation (see [settings]). \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/logging.markdown b/Slim/codeguy-Slim-aa7e919/docs/logging.markdown deleted file mode 100644 index 23669cd..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/logging.markdown +++ /dev/null @@ -1,104 +0,0 @@ -# Logging [logging] # - -A Slim application provides a `Slim_Log` object that logs data to a specific output via a log writer. - -## How to Log Messages ## - -To log messages from a Slim application, get a reference to the `Slim_Log` object like this: - - $log = $app->getLog(); - -The `Slim_Log` object provides the following public interface: - - $log->debug( mixed $object ); - $log->info( mixed $object ); - $log->warn( mixed $object ); - $log->error( mixed $object ); - $log->fatal( mixed $object ); - -Each `Slim_Log` method accepts one mixed argument. The argument is usually a string, but the argument can be anything. The argument will be passed to the log writer. It is the log writer's responsibility to log arbitrary input appropriately. - -## Log Writers ## - -The Slim application's `Slim_Log` instance has a log writer. The log writer is responsible for sending a logged message to the appropriate output (e.g. STDERR, a log file, a remote web service, Twitter, or a database). Out of the box, the Slim application's `Slim_Log` object has a log writer instance of class `Slim_LogFileWriter`; this log writer directs output to the resource handle referenced by the application environment's **slim.errors** key (by default, this is "php://stderr"). You may also define and use a custom log writer. - -### How to Use a Custom Log Writer ### - -A custom log writer must implement the following public interface: - - public function write( mixed $message ); - -You must tell the Slim application's `Slim_Log` instance to use your writer. You can do so in your application's settings during instantiation like this: - - $app = new Slim(array( - 'log.writer' => new MyLogWriter() - )); - -You may also set a custom log writer with middleware like this: - - class CustomLogWriterMiddleware extends Slim_Middleware { - public function call() { - //Set the new log writer - $log = $this->app->getLog()->setWriter( new MyLogWriter() ); - - //Call next middleware - $this->next->call(); - } - } - -You can set the log writer similarly in an application [hook](#hooks) or [route](#routing-get) callback like this: - - $app->hook('slim.before', function () use ($app) { - $app->getLog()->setWriter( new MyLogWriter() ); - }); - -If you only need to redirect error output to a different resource, I recommend you [update the Environment's **slim.errors** element](#errors-output) instead of writing and entirely new LogWriter. - -## How to Enable or Disable Logging ## - -The Slim application's `Slim_Log` object provides the following public methods to enable or disable logging during runtime. - - //Enable logging - $app->getLog()->setEnabled(true); - - //Disable logging - $app->getLog()->setEnabled(false); - -You may enable or disable the `Slim_Log` object during application instantiation like this: - - $app = new Slim(array( - 'log.enabled' => true - )); - -If logging is disabled, the `Slim_Log` object will ignore all logged messages until it is enabled. - -## Log Levels ## - -The Slim application's `Slim_Log` object provides the following public methods to define the _level_ of messages it will log. When you invoke the `Slim_Log` objects's `debug()`, `info()`, `warn()`, `error()`, or `fatal()` methods, you are inherently assigning a level to the logged message: - -Debug -: Level 4 - -Info -: Level 3 - -Warn -: Level 2 - -Error -: Level 1 - -Fatal -: Level 0 - -Only messages that have a level _less than_ the current `Slim_Log` object's level will be logged. For example, if the `Slim_Log` object's level is "2", the `Slim_Log` object will ignore debug and info messages but will accept warn, error, and fatal messages. - -You can set the `Slim_Log` object's level like this: - - $app->getLog()->setLevel(2); - -You can set the `Slim_Log` object's level during application instantiation like this: - - $app = new Slim(array( - 'log.level' => 2 - )); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/middleware-add.markdown b/Slim/codeguy-Slim-aa7e919/docs/middleware-add.markdown deleted file mode 100644 index 753faf8..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/middleware-add.markdown +++ /dev/null @@ -1,28 +0,0 @@ -# Add Middleware [middleware-add] # - -Use the Slim application's `add()` instance method to add new middleware to a Slim application. New middleware will surround previously added middleware, or the Slim application itself if no middleware has yet been added. - -## Example Middleware ## - - class Secret_Middleware extends Slim_Middleware { - public function call() { - $app = $this->app; - $req = $app->request(); - $res = $app->response(); - if ( $req->headers('X-Secret-Request') === 'The sun is shining' ) { - $res->header('X-Secret-Response', 'But the ice is slippery'); - } - $this->next->call(); - } - } - -## Add Middleware ## - - $app = new Slim(); - $app->add(new Secret_Middleware()); - $app->get('/foo', function () use ($app) { - //Do something - }); - $app->run(); - -The Slim application's `add()` method accepts one argument: a middleware instance. If the middleware instance requires special configuration, it may implement its own constructor so that it may be configured before it is added to the Slim application. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/middleware-architecture.markdown b/Slim/codeguy-Slim-aa7e919/docs/middleware-architecture.markdown deleted file mode 100644 index faaa1cd..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/middleware-architecture.markdown +++ /dev/null @@ -1,36 +0,0 @@ -# Middleware Architecture [middleware-architecture] # - -Think of a Slim application as the core of an onion. Each layer of the onion is middleware. When you invoke the Slim application's `run()` method, the outer-most middleware layer is invoked first. When ready, that middleware layer is responsible for optionally invoking the next middleware layer that it surrounds. This process steps deeper into the onion — through each middleware layer — until the core Slim application is invoked. This stepped process is possible because each middleware layer, and the Slim application itself, all implement a public `call()` instance method. When you add new middleware to a Slim application, the added middleware will become a new outer layer and surround the previous outer middleware layer (if available) or the Slim application itself. - -## Application Reference ## - -The purpose of middleware is to inspect, analyze, or modify the application environment, the application request, and the application response before and/or after the Slim application is invoked. It is easy for each middleware to obtain references to the primary Slim application, the Slim application's environment, the Slim application's request, and the Slim application's response: - - class My_Middleware extends Slim_Middleware { - public function call() { - //The Slim application - $app = $this->app; - - //The Environment object - $env = $app->environment(); - - //The Request object - $req = $app->request(); - - //The Response object - $res = $app->response(); - } - } - -Changes made to the environment, request, and response objects will propagate immediately throughout the application and its other middleware layers. This is possible because every middleware layer is given a reference to the same Slim application object. - -## Next Middleware Reference ## - -Each middleware layer also has a reference to the _next_ inner middleware layer with `$this->next`. It is each middleware's responsibility to optionally call the next middleware. Doing so will allow the Slim application to complete its full lifecycle. If a middleware layer chooses _not_ to call the next inner middleware layer, further inner middleware and the Slim application itself will not be run, and the application response will be returned to the HTTP client as is. - - class My_Middleware extends Slim_Middleware { - public function call() { - //Optionally call the next middleware - $this->next->call(); - } - } \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/middleware-implementation.markdown b/Slim/codeguy-Slim-aa7e919/docs/middleware-implementation.markdown deleted file mode 100644 index c1225ae..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/middleware-implementation.markdown +++ /dev/null @@ -1,11 +0,0 @@ -# Middleware Implementation [middleware-implementation] # - -Middleware **must** extend the `Slim_Middleware` class and implement a public `call()` instance method. The `call()` method does not accept arguments. Otherwise, each middleware may implement its own constructor, properties, and methods. I encourage you to look at Slim's built-in middleware for working examples (e.g. `Slim/Middleware/ContentTypes.php` or `Slim/Middleware/SessionCookie.php`). - -This example is the most simple implementation of Slim application middleware. It extends `Slim_Middleware`, implements a public `call()` method, and calls the next inner middleware. - - class My_Middleware extends Slim_Middleware { - public function call() { - $this->next->call(); - } - } \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/middleware.markdown b/Slim/codeguy-Slim-aa7e919/docs/middleware.markdown deleted file mode 100644 index faed9a9..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/middleware.markdown +++ /dev/null @@ -1,3 +0,0 @@ -# Middleware [middleware] # - -The Slim Framework implements a derivation of the Rack protocol. As a result, a Slim application can have middleware that may inspect, analyze, or modify the application environment variables, the application Request object, and the application Response object before and/or after the Slim application is invoked. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/modes.markdown b/Slim/codeguy-Slim-aa7e919/docs/modes.markdown deleted file mode 100644 index f6ae132..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/modes.markdown +++ /dev/null @@ -1,54 +0,0 @@ -# Application Modes [application-modes] - -It is common practice to run web applications in a specific mode depending on the current state of the project. If you are developing the application, you will run the application in "development" mode; if you are testing the application, you will run the application in "test" mode; if you launch the application, you will run the application in "production" mode. - -Slim supports the concept of modes in that you may define your own modes and prompt Slim to prepare itself appropriately in the current mode. For example, you may want to enable debugging in "development" mode but not in "production" mode. The examples below demonstrate how to configure Slim differently for a given mode. - -## What is a mode? [what-is-a-mode] - -Technically, an application mode is merely a string of text — like "development" or "production" — that has an associated callback function used to prepare the Slim application appropriately. The application mode may be anything you like: “testing”, “production”, “development”, or even “foo”. - -## How do I set the Slim application mode? [how-to-set-mode] - -### Use an environment variable - -If Slim sees an environment variable named **SLIM_MODE**, it will set the current application mode to that variable’s value. This lets you define the Slim application mode programmatically if calling the application from the command line. - - $_ENV['SLIM_MODE'] = 'production'; - -### Use an application setting - -If an environment variable is not found, Slim will next look for the mode in the application settings. - - $app = new Slim(array( - 'mode' => 'production' - )); - -### Default mode - -If the environment variable and application setting are not found, Slim will set the application mode to “development”. - -## Configure Slim for a specific mode [configure-for-mode] - -After you instantiate a Slim application, you may configure the Slim application for a specific mode with the `configureMode()` application instance method. This method accepts two arguments: the first is the name of the target mode, and the second is anything that returns `true` for `is_callable()` that will be immediately invoked if the first argument matches the current application mode. - -In this example, assume the current application mode is “production”. Only the callable associated with the “production” mode will be invoked. The callable associated with the “development” mode will be ignored until the application mode is changed to "development". - - $app = new Slim(array( - 'mode' => 'production' - )); - - $app->configureMode('production', function () use ($app) { - $app->config(array( - 'log.enable' => true, - 'log.path' => '../logs', - 'debug' => false - )); - }); - - $app->configureMode('development', function () use ($app) { - $app->config(array( - 'log.enable' => false, - 'debug' => true - )); - }); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/names-and-scopes.markdown b/Slim/codeguy-Slim-aa7e919/docs/names-and-scopes.markdown deleted file mode 100644 index 83e9c32..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/names-and-scopes.markdown +++ /dev/null @@ -1,58 +0,0 @@ -# Application Names and Scopes [names-and-scopes] - -When you build a Slim application you will enter various scopes in your code (e.g. global scope and function scope). You will likely need a reference to your Slim application in each scope. You can use application names, or `use` with PHP >= 5.3, to obtain a reference to your Slim application. - -## Application Names [application-names] - -Every Slim application may be given a name. **This is optional**. Names help you get a reference to a Slim application instance in any scope throughout your code. Here is how you set and get an application's name: - - $app = new Slim(); - $app->setName('foo'); - $theName = $app->getName(); //returns "foo" - -## Scope Resolution [scope-resolution] - -So how do you get a reference to your Slim application? The example below demonstrates how to obtain a reference to a Slim application within a route callback function. The Slim `$app` variable is accessed in the global scope to define the GET route. We also need to access the Slim `$app` variable within the route’s callback scope to render a template. - - $app = new Slim(); - $app->get('/foo', function () { - $app->render('foo.php'); //<--ERROR - }); - -This fails because we cannot access the Slim `$app` variable inside of the route callback function. In PHP >= 5.3 we can inject the Slim `$app` variable into the anonymous function scope with the `use` keyword: - - $app = new Slim(); - $app->get('/foo', function () use ($app) { - $app->render('foo.php'); //<--SUCCESS - }); - -Now it works correctly. In PHP < 5.3, you can use `Slim::getInstance()` instead. - - $app = new Slim(); - $app->get('/foo', 'foo'); - function foo() { - $app = Slim::getInstance(); - $app->render('foo.php'); - } - -The first instantiated Slim application is automatically assigned the name "default". If you invoke `Slim::getInstance()` without an argument, it will return the Slim application that is named "default". - -If you instantiate multiple Slim applications with PHP < 5.3, it is important that you assign each Slim application a name. - - $app1 = new Slim(); - $app1->setName('myApp1'); - - $app2 = new Slim(); - $app2->setName('myApp2'); - - $app1->get('/foo', 'appOneCallback'); - function appOneCallback() { - $app = Slim::getInstance('myApp1'); - } - - $app2->get('/foo', 'appTwoCallback'); - function appTwoCallback() { - $app = Slim::getInstance('myApp2'); - } - -Invoking `Slim::getInstance()` without an argument will return a reference to `$app1` because that is the first Slim application instantiated. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-cookies.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-cookies.markdown deleted file mode 100644 index 778fd92..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-cookies.markdown +++ /dev/null @@ -1,24 +0,0 @@ -# Request Cookies [request-cookies] # - -## Get Cookies [request-cookies-basic] ## - -A Slim application will automatically parse cookies sent with the current HTTP request. You can fetch cookie values with the Slim application's `getCookie()` instance method like this: - - $foo = $app->getCookie('foo'); - -Only Cookies **sent** with the current HTTP request are accessible with this method. If you set a cookie during the current request, it will not be accessible with this method until the subsequent request. If you want to fetch an array of all cookies sent with the current request, you must use the Request object's `cookies()` instance method like this: - - //Get all cookies as associative array - $cookies = $app->request()->cookies(); - -## Get Encrypted Cookies [request-cookies-encrypted] ## - -If you previously set an encrypted cookie, you can fetch its decrypted value with the Slim application's `getEncryptedCookie()` instance method like this: - - $cookieValue = $app->getEncryptedCookie('foo'); - -If the cookie was modified while with the HTTP client, Slim will automatically destroy the cookie's value and invalidate the cookie in the next HTTP response. You can disable this behavior by passing `false` as the second argument: - - $cookieValue = $app->getEncryptedCookie('foo', false); - -Whether you destroy invalid cookies or not, `NULL` is returned if the cookie does not exist or is invalid. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-headers.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-headers.markdown deleted file mode 100644 index 39f1d41..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-headers.markdown +++ /dev/null @@ -1,15 +0,0 @@ -# Request Headers [request-headers] # - -A Slim application will automatically parse all HTTP request headers. You can access the Request headers using the Request `headers()` instance method. - - $app = new Slim(); - - //Fetch all request headers as associative array - $headers = $app->request()->headers(); - - //Fetch only the ACCEPT_CHARSET header - $charset = $app->request()->headers('ACCEPT_CHARSET'); //returns string or NULL - -In the second example, the `headers()` method will either return a string value or `NULL` if the header with the given name does not exist. - -The HTTP specification states that HTTP header names may be uppercase, lowercase, or mixed-case. Slim is smart enough to parse and return header values whether you request a header value using upper, lower, or mixed case header name, with either underscores or dashes. So use the naming convention with which you are most comfortable. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-helpers.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-helpers.markdown deleted file mode 100644 index 18b847e..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-helpers.markdown +++ /dev/null @@ -1,46 +0,0 @@ -# Request Helpers [request-helpers] # - -Slim provides several helper methods that help you fetch common HTTP request information. - - //Fetch HTTP request content type (e.g. "application/json;charset=utf-8" - $contentType = $app->request()->getContentType(); - - //Fetch HTTP request media type (e.g "application/json") - $mediaType = $app->request()->getMediaType(); - - //Fetch HTTP request media type params (e.g [charset => "utf-8"]) - $mediaTypeParams = $app->request()->getMediaTypeParams(); - - //Fetch HTTP request content type charset (e.g. "utf-8") - $charset = $app->request()->getContentCharset(); - - //Fetch HTTP request content length - $contentLength = $app->request()->getContentLength(); - - //Fetch HTTP request host (e.g. "slimframework.com") - $host = $app->request()->getHost(); - - //Fetch HTTP request host with port (e.g. "slimframework.com:80") - $hostAndPort = $app->request()->getHostWithPort(); - - //Fetch HTTP request port (e.g. 80) - $port = $app->request()->getPort(); - - //Fetch HTTP request scheme (e.g. "http" or "https") - $scheme = $app->request()->getScheme(); - - //Fetch HTTP request URI path (root URI + resource URI) - $path = $app->request()->getPath(); - - //Fetch HTTP request URL (scheme + host [ + port if non-standard ]) - $url = $app->request()->getUrl(); - - //Fetch HTTP request IP address - $ip = $app->request()->getIp(); - - //Fetch HTTP request referer - $ref = $app->request()->getReferer(); - $ref = $app->request()->getReferrer(); - - //Fetch HTTP request user agent string - $ua = $app->request()->getUserAgent(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-method.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-method.markdown deleted file mode 100644 index ed62ea8..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-method.markdown +++ /dev/null @@ -1,27 +0,0 @@ -# Request Method [request-method] # - -Every HTTP request has a method (e.g. GET or POST). You can obtain the current HTTP request method via the Slim application's Request object: - - //What is the request method? - $method = $app->request()->getMethod(); //returns "GET", "POST", etc. - - //Is this a GET request? - $app->request()->isGet(); //true or false - - //Is this a POST request? - $app->request()->isPost(); //true or false - - //Is this a PUT request? - $app->request()->isPut(); //true or false - - //Is this a DELETE request? - $app->request()->isDelete(); //true or false - - //Is this a HEAD request? - $app->request()->isHead(); //true or false - - //Is this a OPTIONS request? - $app->request()->isOptions(); //true or false - - //Is this a request made with Ajax/XHR? - $app->request()->isAjax(); //true or false \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-parameters.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-parameters.markdown deleted file mode 100644 index 3717eba..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-parameters.markdown +++ /dev/null @@ -1,24 +0,0 @@ -# Request Parameters [request-parameters] # - -An HTTP request may have associated parameters (not to be confused with [Route parameters](#routing-paramters)). The GET, POST, or PUT parameters sent with the current HTTP request are exposed via the Slim application's Request object. - -If you want to quickly fetch a request parameter value without considering its type, use the `params()` Request method: - - $paramValue = $app->request()->params('paramName'); - -The `params()` Request instance method will first search **PUT** parameters, then **POST** parameters, then **GET** parameters. If no parameter is found, `NULL` is returned. If you only want to search for a specific type of parameter, you can use these Request instance methods instead: - - //GET parameter - $paramValue = $app->request()->get('paramName'); - - //POST parameter - $paramValue = $app->request()->post('paramName'); - - //PUT parameter - $paramValue = $app->request()->put('paramName'); - -If a parameter does not exist, each method above will return `NULL`. You can also invoke any of these functions without an argument to obtain an array of all parameters of the given type: - - $allGetParams = $app->request()->get(); - $allPostParams = $app->request()->post(); - $allPutParams = $app->request()->put(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-paths.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-paths.markdown deleted file mode 100644 index 2f5ec1d..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-paths.markdown +++ /dev/null @@ -1,19 +0,0 @@ -# Request Paths [request-paths] # - -Every HTTP request received by a Slim application will have a root URI and a resource URI. - -The **root URI** is the physical URL path of the directory in which the Slim application is instantiated and run. If a Slim application is instantiated in **index.php** within the top-most directory of the virtual host's document root, the root URI will be an empty string. If a Slim application is instantiated and run in **index.php** within a physical subdirectory of the virtual host's document root, the root URI will be the path to that subdirectory *with* a leading slash and *without* a trailing slash. - -The **resource URI** is the virtual URI path of an application resource. The resource URI will be matched to the Slim application's routes. - -Here's an example. Assume the Slim application is installed in a physical subdirectory **/foo** beneath your virtual host's document root. Also assume the full HTTP request URL (what you'd see in the browser location bar) is **/foo/books/1**. The root URI is **/foo** (the path to the physical directory in which the Slim application is instantiated) and the resource URI is **/books/1** (the path to the application resource). - -You can get the Request’s root URI and resource URI like this: - - $app = new Slim(); - - //Get the Request root URI - $rootUri = $app->request()->getRootUri(); - - //Get the Request resource URI - $resourceUri = $app->request()->getResourceUri(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request-xhr.markdown b/Slim/codeguy-Slim-aa7e919/docs/request-xhr.markdown deleted file mode 100644 index 3fac963..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request-xhr.markdown +++ /dev/null @@ -1,8 +0,0 @@ -# XMLHttpRequest [request-xhr] # - -When using a Javascript framework like MooTools or jQuery to execute an XMLHttpRequest, the XMLHttpRequest will usually be sent with a 'X-Requested-With' HTTP header. The Slim application will detect the HTTP request's ‘X-Requested-With’ header and flag the request as such. If for some reason an XMLHttpRequest cannot be sent with the 'X-Requested-With' HTTP header, you can force the Slim application to assume an HTTP request is an XMLHttpRequest by setting a GET, POST, or PUT parameter in the HTTP request named “isajax” with a truthy value. - -Here's how you tell if the current request is an XHR/Ajax request: - - $isXHR = $app->request()->isAjax(); //true or false - $isXHR = $app->request()->isXhr(); //true or false; alias of `isAjax()` \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/request.markdown b/Slim/codeguy-Slim-aa7e919/docs/request.markdown deleted file mode 100644 index 06ca31c..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/request.markdown +++ /dev/null @@ -1,7 +0,0 @@ -# The Request Object [request] # - -Each Slim application instance has one Request object. The Request object is an abstraction of the current HTTP request and allows you to easily interact with the [Environment](#environment) variables. Although each Slim application includes a default Request object, the `Slim_Http_Request` class is idempotent; you may instantiate the class at will (in [Middleware](#middleware) or elsewhere in your Slim application) without affecting the application as a whole. - -You can obtain a reference to the Slim application's Request object like this: - - $app->request(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/response-body.markdown b/Slim/codeguy-Slim-aa7e919/docs/response-body.markdown deleted file mode 100644 index 739535f..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/response-body.markdown +++ /dev/null @@ -1,16 +0,0 @@ -# Response Body [response-body] # - -The HTTP response returned to the client will have a body. The HTTP body is the actual content of the HTTP response delivered to the client. You can use the Slim application's Response object to set the HTTP response's body like this: - - $response = $app->response(); - $response->body('Foo'); //The body is now "Foo" (overwrites) - $response->write('Bar'); //The body is now "FooBar" (appends) - -When you overwrite or append the Response's body, the Response object will automatically set the `Content-Length` header based on the byte size of the new response body. - -You can fetch the Response object's body using the same Response `body()` instance method without an argument like this: - - $response = $app->response(); - $body = $response->body(); - -Usually, you will never need to manually set the Response body with the Response `body()` or `write()` methods; instead, the Slim application will do this for you. Whenever you `echo()` content from within a route callback, the `echo()`'d content is captured in an output buffer and later appended to the Response body before the HTTP response is returned to the client. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/response-cookies.markdown b/Slim/codeguy-Slim-aa7e919/docs/response-cookies.markdown deleted file mode 100644 index d08220a..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/response-cookies.markdown +++ /dev/null @@ -1,47 +0,0 @@ -# Response Cookies [response-cookies] # - -The Slim application instance provides several helper methods to send cookies with the HTTP response. - -## Set Cookie ## - -This example demonstrates how to use the Slim application's `setCookie()` instance method to create a Cookie that will be sent with the HTTP response: - - $app->setCookie('foo', 'bar', '2 days'); - -This creates a cookie with name **foo** and value **bar** that expires two days from now. You may also provide additional cookie properties, including path, domain, secure, and httponly. The Slim application's `setCookie()` method uses the same signature as PHP's native `setCookie()` function. - - $app->setCookie($name, $value, $expiresAt, $path, $domain, $secure, $httponly); - -The last argument, `$httpOnly`, was added in PHP 5.2. However, because Slim's underlying cookie implementation does not rely on PHP's native `setCookie()` function, you may use the `$httpOnly` cookie property even with PHP 5.1. - -## Set Encrypted Cookie [response-cookies-encrypted] ## - -You may also create encrypted cookies using the Slim application's `setEncryptedCookie()` instance method. This method acts the same as the Slim application's `setCookie()` instance method demonstrated above, but it will encrypt the cookie value using the AES-256 cipher and your own secret key. To use encryption, you **must** define your encryption key when you instantiate your Slim application like this: - - $app = new Slim(array( - 'cookies.secret_key' => 'my_secret_key' - )); - -If you prefer, you may also change the default cipher and cipher mode, too: - - $app = new Slim(array( - 'cookies.secret_key' => 'my_secret_key', - 'cookies.cipher' => MCRYPT_RIJNDAEL_256, - 'cookies.cipher_mode' => MCRYPT_MODE_CBC - )); - -The encrypted cookie value is hashed and later verified to ensure data integrity so that its value is not changed while on the HTTP client. - -## Delete Cookie [response-cookies-delete] ## - -You can delete a cookie using the Slim application's `deleteCookie()` instance method. This will remove the cookie from the HTTP client before the next HTTP request. This method accepts the same signature as the Slim application's `setCookie()` instance method, just without the `$expires` argument. Only the first argument is required. - - $app->deleteCookie('foo'); - -Or if you need to also specify the **path** and **domain**: - - $app->deleteCookie('foo', '/', 'foo.com'); - -You may also further specify the **secure** and **httponly** properties, too: - - $app->deleteCookie('foo', '/', 'foo.com', true, true); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/response-header.markdown b/Slim/codeguy-Slim-aa7e919/docs/response-header.markdown deleted file mode 100644 index 12b8c06..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/response-header.markdown +++ /dev/null @@ -1,15 +0,0 @@ -# Response Header [response-header] # - -The HTTP response returned to the HTTP client will have a header. The HTTP header is a list of keys and values that provide metadata about the HTTP response. You can use the Slim application's Response object to set the HTTP response's header. The Response object is special because it acts like an array. Here's an example. - - $response = $app->response(); - $response['Content-Type'] = 'application/json'; - $response['X-Powered-By'] = 'Slim'; - -Just the same, you can also fetch headers from the Response object like this: - - $response = $app->response(); - $contentType = $response['Content-Type']; - $poweredBy = $response['X-Powered-By']; - -If a header with the given name does not exist, `NULL` is returned instead. You may specify header names with upper, lower, or mixed case with dashes or underscores. Use the naming convention with which you are most comfortable. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/response-helpers.markdown b/Slim/codeguy-Slim-aa7e919/docs/response-helpers.markdown deleted file mode 100644 index be4b248..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/response-helpers.markdown +++ /dev/null @@ -1,52 +0,0 @@ -# Response Helpers [response-helpers] # - -The Response object provides several instance methods to help you inspect and interact with the underlying HTTP response. - -## Finalize [response-helpers-finalize] ## - -The Response object's `finalize()` method returns a numeric array of status, header, and body. The status is an integer; the header is an iterable data structure; and the body is a string. Were you to create a new Response object in the Slim application or in middleware, you would call this method to produce the status, header, and body for the underlying response. - - $res = new Slim_Http_Response(); - $res->status(400); - $res->write('You made a bad request'); - $res['Content-Type'] = 'text/plain'; - $array = $res->finalize(); //returns [200, ['Content-type' => 'text/plain'], 'You made a bad request'] - -## Redirect [response-helpers-redirect] ## - -The Response object's `redirect()` method will help you quickly set the status and **Location:** header needed to return a **3xx Redirect** response. - - $app->response()->redirect('/foo', 303); - -In this example, the Response will now have a **Location:** header with value "/foo" and a 303 status code. - -## Status Inspection [response-helpers-inspection] ## - -The Response object provides several methods to help you quickly inspect the type of Response based on its status. All return a boolean value. They are: - - //Is this an informational response? - $app->response()->isInformational(); - - //Is this a 200 OK response? - $app->response()->isOk(); - - //Is this a 2xx successful response? - $app->response()->isSuccessful(); - - //Is this a 3xx redirection response? - $app->response()->isRedirection(); - - //Is this a specific redirect response? (301, 302, 303, 307) - $app->response()->isRedirect(); - - //Is this a forbidden response? - $app->response()->isForbidden(); - - //Is this a not found response? - $app->response()->isNotFound(); - - //Is this a client error response? - $app->response()->isClientError(); - - //Is this a server error response? - $app->response()->isServerError(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/response-status.markdown b/Slim/codeguy-Slim-aa7e919/docs/response-status.markdown deleted file mode 100644 index 9eec58a..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/response-status.markdown +++ /dev/null @@ -1,9 +0,0 @@ -# Response Status [response-status] # - -The HTTP response returned to the client will have a status code indicating the response's type (e.g. 200 OK, 400 Bad Request, or 500 Server Error). You can use the Slim application's Response object to set the HTTP response's status like this: - - $app->response()->status(400); - -You only need to set the Response object's status if you intend to return an HTTP response that does not have a **200 OK** status. You can just as easily fetch the Response object's current HTTP status by invoking the same method without an argument, like this: - - $status = $app->response()->status(); //returns int \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/response.markdown b/Slim/codeguy-Slim-aa7e919/docs/response.markdown deleted file mode 100644 index 8d3fb43..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/response.markdown +++ /dev/null @@ -1,9 +0,0 @@ -# The Response Object [response] # - -Each Slim application instance has one Response object. The Response object is a high-level interface that allows you to easily interact with the HTTP response that is returned to the HTTP client. Although each Slim application includes a default Response object, the `Slim_Http_Response` class is idempotent; you may instantiate the class at will (in [Middleware](#middleware) or elsewhere in your Slim application) without affecting the application as a whole. - -You can obtain a reference to the Slim application's Response object like this: - - $app->response(); - -An HTTP response has three primary properties: the status code, the header, and the body. The Response object provides several helper methods, described next, that help you interact with these HTTP response properties in your Slim application. The default Response object in each Slim application will return a **200 OK** HTTP response with the **text/html** content type. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-conditions.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-conditions.markdown deleted file mode 100644 index 4b76f5e..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-conditions.markdown +++ /dev/null @@ -1,30 +0,0 @@ -# Route Conditions [routing-conditions] # - -Slim lets you assign conditions to route parameters. If the specified conditions are not met, the route is not run. For example, if you need a route with a second segment that must be a valid 4-digit year, you could enforce this condition like this: - - $app = new Slim(); - $app->get('/archive/:year', function ($year) { - echo "You are viewing archives from $year"; - })->conditions(array('year' => '(19|20)\d\d')); - -Invoke the `conditions()` Route method. The first and only argument is an associative array with keys that match any of the route’s parameters and values that are regular expressions. - -## Application-wide Route Conditions - -If many of your Slim application Routes accept the same parameters and use the same conditions, you can define default application-wide Route conditions like this: - - Slim_Route::setDefaultConditions(array( - 'firstName' => '[a-zA-Z]{3,}' - )); - -Define application-wide route conditions before you define application routes. When you define a route, the route will automatically be assigned any application-wide Route conditions defined with `Slim\_Route::setDefaultConditions()`. If for whatever reason you need to get the application-wide default route conditions, you can fetch them with `Slim_Route::getDefaultConditions()`; this static method returns an array exactly as the default route conditions were defined. - -You may override a default route condition by redefining the route’s condition when you define the route, like this: - - $app = new Slim(); - $app->get('/hello/:firstName', $callable)->conditions(array('firstName' => '[a-z]{10,}')); - -You may append new conditions to a given route like this: - - $app = new Slim(); - $app->get('/hello/:firstName/:lastName', $callable)->conditions(array('lastName' => '[a-z]{10,}')); diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-custom.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-custom.markdown deleted file mode 100644 index b008b85..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-custom.markdown +++ /dev/null @@ -1,29 +0,0 @@ -# Custom Routes [routing-custom] # - -## One Route, Multiple HTTP Methods ## - -Sometimes you may need a route to respond to multiple HTTP methods; sometimes you may need a route to respond to a custom HTTP method. You can accomplish both with the `via()` Route method. This example demonstrates how to map a resource URI to a callback that responds to multiple HTTP methods. - - $app = new Slim(); - $app->map('/foo/bar', function() { - echo "I respond to multiple HTTP methods!"; - })->via('GET', 'POST'); - $app->run(); - -The route defined in this example will respond to both GET and POST requests for the resource identified by "/foo/bar". Specify each appropriate HTTP method as a separate string argument to the `via()` Route method. Like other Route methods (e.g. `name()` and `conditions()`), the `via()` Route method is chainable: - - $app = new Slim(); - $app->map('/foo/bar', function() { - echo "Fancy, huh?"; - })->via('GET', 'POST')->name('foo'); - $app->run(); - -## One Route, Custom HTTP Methods ## - -The `via()` Route method is not limited to just GET, POST, PUT, DELETE, and OPTIONS methods. You may also specify your own custom HTTP methods (e.g. if you were responding to WebDAV HTTP requests). You can define a route that responds to a custom "FOO" HTTP method like this: - - $app = new Slim(); - $app->map('/hello', function() { - echo "Hello"; - })->via('FOO'); - $app->run(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-delete.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-delete.markdown deleted file mode 100644 index a231399..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-delete.markdown +++ /dev/null @@ -1,32 +0,0 @@ -# DELETE Routes [routing-delete] # - -Use the `delete()` application instance method to map a callback function to a resource URI that is requested with the HTTP DELETE method. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->delete('/books/:id', function ($id) { - //Delete book identified by $id - }); - - //For PHP < 5.3 - $app->delete('/books/:id', 'delete_book'); - function delete_book($id) { - //Delete book identified by $id - } - -In this example, an HTTP DELETE request for “/books/1” will invoke the associated callback function. - -The first argument of the `delete()` application instance method is the resource URI. The last argument is anything that returns `true` for `is_callable()`. I encourage you to use PHP >= 5.3 so you may take advantage of anonymous functions. - -## Method Override ## - -Unfortunately, modern browsers do not provide native support for HTTP DELETE requests. To work around this limitation, ensure your HTML form’s **method** attribute is “post”, then add a method override parameter to your HTML form like this: - -
- ... other form fields here... - - -
- -If you are using [Backbone.js](http://documentcloud.github.com/backbone/) or a command-line HTTP client, you may also override the HTTP method by using the `X-HTTP-Method-Override` header. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-generic.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-generic.markdown deleted file mode 100644 index 6232417..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-generic.markdown +++ /dev/null @@ -1,11 +0,0 @@ -# Generic Routes [routing-generic] # - -Slim provides the `map()` application instance method to define generic routes that are not immediately associated with an HTTP method. - - $app = new Slim(); - $app->map('/generic/route', function () { - echo "I'm a generic route!"; - }); - $app->run(); - -This example always returns a **404 Not Found** response because the "/generic/route" route does not respond to any HTTP methods. Use the [via()](#routing-custom) method (available on Route objects), to assign one or many HTTP methods to a generic route. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-get.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-get.markdown deleted file mode 100644 index b6f0b29..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-get.markdown +++ /dev/null @@ -1,20 +0,0 @@ -# GET Routes [routing-get] # - -Use the `get()` application instance method to map a callback function to a resource URI that is requested with the HTTP GET method. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->get('/books/:id', function ($id) { - //Show book identified by $id - }); - - //For PHP < 5.3 - $app->get('/books/:id', 'show_book'); - function show_book($id) { - //Show book identified by $id - } - -In this example, an HTTP GET request for “/books/1” will invoke the associated callback function, passing “1” as the callback function argument. - -The first argument of the `get()` application instance method is the resource URI. The last argument is anything that returns `true` for `is_callable()`. I encourage you to use PHP >= 5.3 so you may take advantage of anonymous functions. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-halt.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-halt.markdown deleted file mode 100644 index f3e556e..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-halt.markdown +++ /dev/null @@ -1,22 +0,0 @@ -# Halt [routing-helpers-halt] # - -The `halt()` application instance method will immediately return an HTTP response with a given status code and body. This method accepts two arguments: the HTTP status code and an optional message. Slim will immediately halt the current application and send an HTTP response to the client with the specified status and optional message (as the response body). This will override the existing Response object. - - $app = new Slim(); - - //Send a default 500 error response - $app->halt(500); - - //Or if you encounter a Balrog... - $app->halt(403, 'You shall not pass!'); - -If you would like to render a template with a list of error messages, you should use the `render()` application instance method instead. - - $app = new Slim(); - $app->get('/foo', function () use ($app) { - $errorData = array('error' => 'Permission Denied'); - $app->render('errorTemplate.php', $errorData, 403); - }); - $app->run(); - -The `halt()` application instance method may send any type of HTTP response to the client: informational, success, redirect, not found, client error, or server error. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-pass.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-pass.markdown deleted file mode 100644 index 5603e8f..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-pass.markdown +++ /dev/null @@ -1,13 +0,0 @@ -# Pass [routing-helpers-pass] # - -A route can tell the Slim application to continue to the next matching route with the `pass()` application instance method. When this method is invoked, the Slim application will immediately stop processing the current matching route and invoke the next matching route. If no subsequent matching route is found, a **404 Not Found** response is sent to the client. Here is an example. Assume an HTTP request for "GET /hello/Frank". - - $app = new Slim(); - $app->get('/hello/Frank', function () use ($app) { - echo "You won't see this..."; - $app->pass(); - }); - $app->get('/hello/:name', function ($name) use ($app) { - echo "But you will see this!"; - }); - $app->run(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-redirect.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-redirect.markdown deleted file mode 100644 index 7bcfa6e..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-redirect.markdown +++ /dev/null @@ -1,19 +0,0 @@ -# Redirect [routing-helpers-redirect] # - -It is easy to redirect the client to another URL with the `redirect()` application instance method. This method accepts two arguments: the first argument is the URL to which the client will redirect; the second optional argument is the HTTP status code. By default the `redirect()` application instance method will send an **HTTP 302 Temporary Redirect** response. - - $app = new Slim(); - $app->get('/foo', function () use ($app) { - $app->redirect('/bar'); - }); - $app->run(); - -Or if you wish to use a permanent redirect, you must specify the destination URL as the first parameter and the HTTP status code as the second parameter. - - $app = new Slim(); - $app->get('/old', function () use ($app) { - $app->redirect('/new', 301); - }); - $app->run(); - -This method will automatically set the **Location:** header. The HTTP redirect response will be sent to the HTTP client immediately. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-stop.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-stop.markdown deleted file mode 100644 index 08846a8..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-stop.markdown +++ /dev/null @@ -1,11 +0,0 @@ -# Stop [routing-helpers-stop] # - -The `stop()` application instance method will stop the Slim application and send the current HTTP response to the client as is. No *ifs*, *ands*, or *buts*. - - $app = new Slim(); - $app->get('/foo', function () use ($app) { - echo "You will see this..."; - $app->stop(); - echo "But not this"; - }); - $app->run(); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-urlfor.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-urlfor.markdown deleted file mode 100644 index 6c90e99..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers-urlfor.markdown +++ /dev/null @@ -1,15 +0,0 @@ -# URL For [routing-helpers-urlfor] # - -The `urlFor()` application instance method lets you dynamically create URLs *for a named route* so that, were a route pattern to change, your URLs would update automatically without breaking your application. This example demonstrates how to generate URLs for a named route. - - $app = new Slim(); - - //Create a named route - $app->get('/hello/:name', function ($name) use ($app) { - echo "Hello $name"; - })->name('hello'); - - //Generate a URL for the named route - $url = $app->urlFor('hello', array('name' => 'Josh')); - -In this example, `$url` is "/hello/Josh". To use the `urlFor()` application instance method, you must first assign a name to a route. Next, invoke the `urlFor()` application instance method. The first argument is the name of the route, and the second argument is an associative array used to replace the route’s URL parameters with actual values; the array's keys must match parameters in the route's URI and the values will be used as substitutions. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-helpers.markdown deleted file mode 100644 index 93d7b06..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-helpers.markdown +++ /dev/null @@ -1,3 +0,0 @@ -# Route Helpers [routing-helpers] # - -Slim provides several helper methods (exposed via the `Slim` application instance) that will help you control the flow of your application. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-slashes.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-slashes.markdown deleted file mode 100644 index e89029f..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-slashes.markdown +++ /dev/null @@ -1,17 +0,0 @@ -# Trailing Slashes [routing-indepth-slashes] # - -Slim routes automatically provide pretty URLs and intelligent redirection — behavior very similar to the Apache web server. Here are two example routes: - - $app = new Slim(); - - //This has a trailing slash - $app->get('/services/', function () {}); - - //This does not have a trailing slash - $app->get('/contact', function () {}); - -At first glance, both routes appear similar. However, in the first route example, the canonical URL for the services route has a trailing slash. It acts the same as a folder; accessing it without a trailing slash will prompt Slim to redirect to the canonical URL with the trailing slash. - -In the second example, the URL is defined without a trailing slash. Therefore, it behaves similar to a file. Accessing it with a trailing slash will result with a **404 Not Found** response. - -This behavior allows URLs to continue working if users access the page and forget the trailing slash. This is consistent with the Apache web server’s behavior. Because Slim automatically redirects URLs, search engines will always index the canonical URLs rather than index both the correct and incorrect URLs. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-with-rewrite.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-with-rewrite.markdown deleted file mode 100644 index 525bc75..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-with-rewrite.markdown +++ /dev/null @@ -1,30 +0,0 @@ -# URL Rewriting [routing-indepth-with-rewrite] # - -I strongly encourage you to use a web server that supports URL rewriting; this will let you enjoy clean, human-friendly URLs with your Slim application. To enable URL rewriting, you should use the appropriate tools provided by your web server to forward all HTTP requests to the PHP file in which you instantiate and run your Slim application. - -I am most familiar with the Apache web server, so my examples below demonstrate how to setup a Slim application with Apache and mod_rewrite. - -Here is an example directory structure: - - www.mysite.com/ - public_html/ <-- Document root! - .htaccess - index.php <-- I instantiate Slim here! - lib/ - Slim/ <-- I store Slim lib files here! - -The **.htaccess** file in the directory structure above contains: - - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php [QSA,L] - -As a result, Apache will send all requests for non-existent files to my **index.php** script in which I instantiate and run my Slim application. With URL rewriting enabled and assuming the following Slim application is defined in **index.php**, you can access the application route below at "/foo" rather than "/index.php/foo". - - $app = new Slim(); - $app->get('/foo', function () { - echo "Foo!"; - }); - $app->run(); - -This process will act very much the same for nginx, except that you will define the URL rewriting in your nginx configuration file rather than in a **.htaccess** file. I will defer to those more intelligent than me to demonstrate nginx configuration. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-without-rewrite.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-without-rewrite.markdown deleted file mode 100644 index c6515bb..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth-without-rewrite.markdown +++ /dev/null @@ -1,11 +0,0 @@ -# Without URL Rewriting [routing-indepth-without-rewrite] # - -Slim will work without URL rewriting. In this scenario, you must include the name of the PHP file in which you instantiate and run the Slim application in the resource URI. For example, assume the following Slim application is defined in **index.php** at the top level of your virtual host's document root: - - $app = new Slim(); - $app->get('/foo', function () { - echo "Foo!"; - }); - $app->run(); - -You can access the defined route at "/index.php/foo". If the same application is instead defined in **index.php** inside of the physical subdirectory **blog/**, you can access the defined route at **/blog/index.php/foo**. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-indepth.markdown deleted file mode 100644 index 91d29af..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-indepth.markdown +++ /dev/null @@ -1,13 +0,0 @@ -# Routing In-Depth [routing-indepth] # - -Slim's routing methods, described earlier, help you map a resource URI to a callback function for a given HTTP method (or for multiple HTTP methods). This is the simplest explanation of Slim's router. However, there is more than meets the eye. - -When you invoke a routing method (e.g `get()`, `post()`, `put()`, etc.) to define a route, you are actually telling Slim to create a Route object that responds to the respective HTTP request method. The Route object will know its resource URI, its callback, and the HTTP methods to which it responds. You may further assign [names](#routing-names) and [conditions](#routing-conditions) to a Route object. - -When you invoke your app's `run()` method, Slim will determine the current HTTP request's method and URI. Slim next iterates over each route in your application in the order they were defined. If a route's URI matches the HTTP request's URI, Slim asks the matching route if it answers to the current HTTP request's method. If yes, the route's callback is invoked; if no, the Route is ignored but Slim remembers the HTTP methods to which that Route *does* respond (more on this in a bit). - -If a route matches both the current HTTP request's URI and method, Slim will invoke that Route's callback and send the eventual HTTP response to the client. Subsequent route objects will not be iterated. - -If Slim finds routes that match the HTTP request URI but not the HTTP request method, Slim will return a **405 Method Not Allowed** response with an **Allow:** header that lists the HTTP methods to which the found routes do respond (as I alluded to above). - -If Slim does not find routes that match the HTTP request URI, Slim will return a **404 Not Found** response. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-middleware.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-middleware.markdown deleted file mode 100644 index 4cce224..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-middleware.markdown +++ /dev/null @@ -1,49 +0,0 @@ -# Route Middleware [routing-middleware] # - -Slim enables you to associate middleware with a specific application route. When the given route matches the current HTTP request and is invoked, Slim will first invoke the associated middleware in the order they are defined. - -## What is Route Middleware? - -Route middleware is anything that returns true for is_callable. - -## How do I Add Route Middleware? - -When you define a new application route with the Slim application's `get()`, `post()`, `put()`, or `delete()` methods you must define a route pattern and a callable to be invoked when the route matches an HTTP request. - - $app = new Slim(); - $app->get('/foo', function () { - //Do something - }); - -In the example above, the first argument is the route pattern. The last argument is the callable to be invoked when the route matches the current HTTP request. The route pattern must always be the first argument. The route callable must always be the last argument. - -You can assign middleware to this route by passing each middleware as a separate interior or... (ahem) middle... argument like this: - - function myMiddleware1() { - echo "This is middleware!"; - } - function myMiddleware2() { - echo "This is middleware!"; - } - $app = new Slim(); - $app->get('/foo', 'myMiddleware', 'myMiddleware2', function () { - //Do something - }); - -When the **/foo** route matches the current HTTP request, the `myMiddleware1` and `myMiddleware2` functions will be invoked in sequence before the route’s callable. - -If you are running PHP >= 5.3, you can get a bit more creative. Suppose you wanted to authenticate the current user against a given role for a specific route. You could use some closure magic like this: - - $authenticateForRole = function ( $role = 'member' ) { - return function () use ( $role ) { - $user = User::fetchFromDatabaseSomehow(); - if ( $user->belongsToRole($role) === false ) { - Slim::flash('error', 'Login required'); - Slim::redirect('/login'); - } - } - } - $app = new Slim(); - $app->get('/foo', $authenticateForRole('admin'), function () { - //Display admin control panel - }); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-names.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-names.markdown deleted file mode 100644 index f0a7aa6..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-names.markdown +++ /dev/null @@ -1,15 +0,0 @@ -# Named Routes [routing-names] # - -Slim lets you assign a name to a route. Naming a route enables you to dynamically generate URLs using the [urlFor](#routing-helpers-urlfor) helper method. When you use the `urlFor()` application instance method to create application URLs, you can freely change route patterns without breaking your application. Here is an example of a named route: - - $app = new Slim(); - $app->get('/hello/:name', function ($name) { - echo "Hello, $name!"; - })->name('hello'); - -You may now generate URLs for this route using the `urlFor()` application instance method, described later in this documentation. The route `name()` method is also chainable: - - $app = new Slim(); - $app->get('/hello/:name', function ($name) { - echo "Hello, $name!"; - })->name('hello')->conditions(array('name' => '\w+')); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-options.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-options.markdown deleted file mode 100644 index b7bccfb..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-options.markdown +++ /dev/null @@ -1,30 +0,0 @@ -# OPTIONS Routes [routing-options] # - -Use the `options()` application instance method to map a callback function to a resource URI that is requested with the HTTP OPTIONS method. - - $app = new Slim(); - - //For PHP 5 >= 5.3 - $app->options('/books/:id', function ($id) { - //Provide options for this resource to the client - }); - - //For PHP 5 < 5.3 - $app->options('/books/:id', 'options_book'); - function options_book($id) { - //Provide options for this resource to the client - } - -In this example, an HTTP OPTIONS request for “/books/1” will invoke the associated callback function. - -The first argument of the `options()` application instance method is the resource URI. The last argument is anything that returns `true` for `is_callable()`. I encourage you to use PHP >= 5.3 so you may take advantage of anonymous functions. - -## Method Override ## - -Unfortunately, modern browsers do not provide native support for HTTP OPTIONS requests. To work around this limitation, ensure your HTML form’s **method** attribute is “post”, then add a method override parameter to your HTML form like this: - -
- ... other form fields here... - - -
\ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-parameters.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-parameters.markdown deleted file mode 100644 index 2e2e052..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-parameters.markdown +++ /dev/null @@ -1,40 +0,0 @@ -# Route Parameters [routing-parameters] # - -You can embed parameters into route resource URIs. In this example, I have two parameters in my route URI, “:one” and “:two”. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->get('/books/:one/:two', function ($one, $two) { - echo "The first paramter is " . $one; - echo "The second parameter is " . $two; - }); - - //For PHP < 5.3 - $app->get('/books/:one/:two', 'callback_name'); - function callback_name($one, $two) { - echo "The first paramter is " . $one; - echo "The second parameter is " . $two; - } - -To create a URL parameter, prepend “:” to the parameter name in the route URI pattern. When the route matches the current HTTP request, the values for each route parameter are extracted from the HTTP request URI and are passed into the associated callback function in order of appearance. - -## Optional Route Parameters - -You may also have optional route parameters. These are ideal for using one route for a blog archive. To declare optional route parameters, specify your route pattern like this: - - $app = new Slim(); - $app->get('/archive(/:year(/:month(/:day)))', function ($year = 2010, $month = 12, $day = 05) { - echo sprintf('%s-%s-%s', $year, $month, $day); - }); - -Each subsequent route segment is optional. This route will accept HTTP requests for: - - /archive - /archive/2010 - /archive/2010/12 - /archive/2010/12/05 - -If an optional route segment is omitted from the HTTP request, the default values in the callback signature are used instead. - -Currently, you can only use optional route segments in situations like the example above where each route segment is subsequently optional. You may find this feature unstable when used in scenarios different from the example above. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-post.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-post.markdown deleted file mode 100644 index a472009..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-post.markdown +++ /dev/null @@ -1,20 +0,0 @@ -# POST Routes [routing-post] # - -Use the `post()` application instance method to map a callback function to a resource URI that is requested with the HTTP POST method. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->post('/books', function () { - //Create book - }); - - //For PHP < 5.3 - $app->post('/books', 'post_book'); - function post_book() { - //Create book - } - -In this example, an HTTP POST request for “/books” will invoke the associated callback function. - -The first argument of the `post()` application instance method is the resource URI. The last argument is anything that returns `true` for `is_callable()`. I encourage you to use PHP >= 5.3 so you may take advantage of anonymous functions. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing-put.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing-put.markdown deleted file mode 100644 index 12b1df9..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing-put.markdown +++ /dev/null @@ -1,32 +0,0 @@ -# PUT Routes [routing-put] # - -Use the `put()` application instance method to map a callback function to a resource URI that is requested with the HTTP PUT method. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->put('/books/:id', function ($id) { - //Update book identified by $id - }); - - //For PHP < 5.3 - $app->put('/books/:id', 'put_book'); - function put_book($id) { - //Update book identified by $id - } - -In this example, an HTTP PUT request for “/books/1” will invoke the associated callback function. - -The first argument of the `put()` application instance method is the resource URI. The last argument is anything that returns `true` for `is_callable()`. I encourage you to use PHP >= 5.3 so you may take advantage of anonymous functions. - -## Method Override ## - -Unfortunately, modern browsers do not provide native support for HTTP PUT requests. To work around this limitation, ensure your HTML form’s **method** attribute is “post”, then add a method override parameter to your HTML form like this: - -
- ... other form fields here... - - -
- -If you are using [Backbone.js](http://documentcloud.github.com/backbone/) or a command-line HTTP client, you may also override the HTTP method by using the `X-HTTP-Method-Override` header. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/routing.markdown b/Slim/codeguy-Slim-aa7e919/docs/routing.markdown deleted file mode 100644 index 72223ae..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/routing.markdown +++ /dev/null @@ -1,7 +0,0 @@ -# Routing [routing] - -Slim helps you map resource URIs to callback functions for specific HTTP request methods (e.g. GET, POST, PUT, DELETE, OPTIONS or HEAD). Slim will invoke the first route that matches the current HTTP request's URI and method. - -If Slim does not find routes with URIs that match the HTTP request URI, Slim will automatically return a **404 Not Found** response. - -If Slim finds routes with URIs that match the HTTP request URI *but not* the HTTP request method, Slim will automatically return a **405 Method Not Allowed** response with an **Allow:** header whose value lists HTTP methods that are acceptable for the requested resource. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/sessions.markdown b/Slim/codeguy-Slim-aa7e919/docs/sessions.markdown deleted file mode 100644 index d94933d..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/sessions.markdown +++ /dev/null @@ -1,38 +0,0 @@ -# Sessions [sessions] # - -## Native PHP Sessions ## - -A Slim application does not presume anything about sessions. If you prefer to use a PHP session, you must configure and start a native PHP session with `session_start()` before you instantiate the Slim application. - -You should also disable PHP's session cache limiter so that PHP does not send conflicting cache expiration headers with the HTTP response. You can disable PHP's session cache limiter with: - - session_cache_limiter(false); - session_start(); - -## Secure Sessions ## - -You may also use the `Slim_Middleware_SessionCookie` middleware to persist session data in encrypted, hashed HTTP cookies. To enable the session cookie middleware, add the `Slim_Middleware_SessionCookie` middleware to your Slim application like this: - - $app = new Slim(); - - $app->add('Slim_Middleware_SessionCookie', array( - 'expires' => '20 minutes', - 'path' => '/', - 'domain' => null, - 'secure' => false, - 'httponly' => false, - 'name' => 'slim_session', - 'secret' => 'CHANGE_ME', - 'cipher' => MCRYPT_RIJNDAEL_256, - 'cipher_mode' => MCRYPT_MODE_CBC - )); - - // Define routes here - - $app->run(); - -The second argument is optional; it is shown here so you can see the default middleware settings. The session cookie middleware will work seamlessly with the `$_SESSION` superglobal so you can easily migrate to this session storage middleware with zero changes to your application code. - -If you use the session cookie middleware, you **DO NOT need to start a native PHP session**. The `$_SESSION` superglobal will still be available, and it will be persisted into an HTTP cookie via the middleware layer rather than with PHP's native session management. - -Remember, HTTP cookies are inherently limited to only 4 kilobytes of data. If your encrypted session data will exceed this length, you should instead rely on PHP's native sessions or an alternate session store. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/settings.markdown b/Slim/codeguy-Slim-aa7e919/docs/settings.markdown deleted file mode 100644 index 97488df..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/settings.markdown +++ /dev/null @@ -1,192 +0,0 @@ -# Settings [settings] - -Slim's constructor accepts an associative array of settings to customize the Slim application during instantiation. These settings may be retrieved or changed during runtime as demonstrated below. Before I list the available settings, I want to quickly explain how you may define and inspect settings with your Slim application. - -To define settings upon instantiation, pass an associative array into the Slim constructor: - - $app = new Slim(array( - 'debug' => true, - 'templates.path' => '../templates' - )); - -To define settings after instantiation, use the `config` application instance method; the first argument is the setting name and the second argument is the setting value. - - $app->config('debug', false); - -You may also define multiple settings at once using an associative array: - - $app->config(array( - 'debug' => true, - 'templates.path' => '../templates' - )); - -To retrieve the value of a setting, you also use the `config` application instance method; however, you only pass one argument — the name of the setting you wish to inspect. If the setting you request does not exist, `NULL` is returned. - - $settingValue = $app->config('templates.path'); //returns "../templates" - -You are not limited to the settings shown below; you may also define your own. - -## mode [settings-mode] ## - -Declare the Slim application mode (e.g. "test", "development", "production"). However, this may be anything you want. - -Data Type -: string - -Default -: development - -## debug [settings-debug] - -Enable or disable application debugging. If true, Slim will display debugging information for errors and exceptions. If false, Slim will instead invoke the default or custom error handler, passing the exception into the handler as the first and only argument. - -Data Type -: boolean - -Default -: true - -## log.writer [settings-log-writer] ## - -This sets the application log writer upon instantiation. This is optional. By default the application log will write logged messages to STDERR. If you do specify a custom log writer here, it must be an object that implements a `write()` public instance method that accepts a mixed argument; the `write()` method is responsible for sending the logged object to the appropriate output. - -Data Type -: mixed - -Default -: Slim_LogFileWriter - -## log.level [settings-log-level] ## - -This sets the application log level upon instantiation to determine which messages are logged. - -Data Type -: int - -Default -: 4 - -## log.enabled [settings-log-enabled] ## - -This enables or disables the application log upon instantiation. - -Data Type -: boolean - -Default -: true - -## templates.path [settings-templates-path] - -The relative or absolute filesystem path to template files directory. This is referenced by the application View to fetch and render templates. - -Data Type -: string - -Default -: ./templates - -## view [settings-view] - -Determines the View class used by the Slim application. - -Data Type -: If string, the name of the custom View class; - If object, a subclass of `Slim_View`; - -Default -: Slim_View - -## cookies.lifetime [settings-cookies-lifetime] - -Determines the lifetime of HTTP cookies created by the Slim application. - -Data Type -: If integer, a valid UNIX timestamp at which the cookie expires; - If string, a description parsed by `strtotime` to extrapolate a valid UNIX timestamp. - -Default -: 20 minutes - -## cookies.path [settings-cookies-path] - -Determines the default HTTP cookie path if none specified when invoking the Slim::setCookie or Slim::setEncryptedCookie application instance methods. - -Data Type -: string - -Default -: / - -## cookies.domain [settings-cookies-domain] - -Determines the default HTTP cookie domain if none specified when invoking the Slim::setCookie or Slim::setEncryptedCookie application instance methods. - -Data Type -: string - -Default -: null - -## cookies.secure [settings-cookies-secure] - -Should the Slim application transfer HTTP cookies over SSL/HTTPS only? - -Data Type -: boolean - -Default -: false - -## cookies.httponly [settings-cookies-httponly] - -Should the Slim application transfer HTTP cookies using the HTTP protocol only? - -Data Type -: boolean - -Default -: false - -## cookies.secret_key [settings-cookies-secret-key] - -The secret key used for HTTP cookie encryption. This field is required if you use encrypted HTTP cookies in your Slim application. - -Data Type -: string - -Default -: CHANGE_ME - -## cookies.cipher [settings-cookies-cipher] - -The mcrypt cipher used for HTTP cookie encryption. You can see a list of available ciphers at http://php.net/manual/en/mcrypt.ciphers.php. - -Data Type -: PHP constant (see URL above) - -Default -: MCRYPT_RIJNDAEL_256 - -## cookies.cipher_mode [settings-cookies-cipher-mode] - -The mcrypt cipher mode used for HTTP cookie encryption. You can see a list of available cipher modes at http://php.net/manual/en/mcrypt.ciphers.php. - -Data Type -: PHP constant (see URL above) - -Default -: MCRYPT_MODE_CBC - -## http.version [settings-http-version] - -By default, Slim returns an HTTP/1.1 response to the client. Use this setting if you need to return an HTTP/1.0 response. This is useful if you use PHPFog or an nginx server configuration where you communicate with backend proxies rather than directly with the HTTP client. - -Data Type -: string - -Default -: 1.1 - -Possible Values -: "1.1" or "1.0" \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/system-requirements.markdown b/Slim/codeguy-Slim-aa7e919/docs/system-requirements.markdown deleted file mode 100644 index d25bf4b..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/system-requirements.markdown +++ /dev/null @@ -1,7 +0,0 @@ -# System Requirements [system-requirements] - -* Web server -* PHP >= 5.2.0 -* libmcrypt > 2.4.x - -I encourage you to choose a web server with a URL rewrite function so you may enjoy clean URLs with your Slim application. \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/views-custom.markdown b/Slim/codeguy-Slim-aa7e919/docs/views-custom.markdown deleted file mode 100644 index 3f4cd76..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/views-custom.markdown +++ /dev/null @@ -1,47 +0,0 @@ -# Custom Views [views-custom] # - -A custom view is a subclass of `Slim_View` that implements a public `render()` method. When the custom view’s render method is invoked, it is passed the desired template pathname (relative to the app's "templates.path" setting) as its one and only argument. - - class CustomView extends Slim_View { - public function render( $template ) { - return 'The final rendered template'; - } - } - -The custom view can do whatever it wants, so long as it returns the template’s rendered output as a string. A custom view makes it easy to integrate popular PHP template systems like Twig or Smarty. - -You can browse ready-to-use custom views that work with popular PHP template engines in the [Slim-Extras](https://github.com/codeguy/Slim-Extras) repository on GitHub. - -The custom view may access data passed to it by the Slim application's `render()` instance method. The custom view can access this array of data with `$this->data`. Here is an example. - -## The Route - - $app = new Slim(); - $app->get('/books/:id', function ($id) use ($app) { - $app->render('show.php', array('title' => 'Sahara')); - }); - -## The View - - class CustomView extends Slim_View { - public function render( $template ) { - //$template === 'show.php' - //$this->data['title'] === 'Sahara' - } - } - -If the custom view is not discoverable by a registered autoloader, it must be required before the Slim application is instantiated. - - require 'Slim/Slim.php'; - require 'CustomView.php'; - $app = new Slim(array( - 'view' => 'CustomView' - )); - -It is also possible to pass a custom view instance into the Slim application’s constructor instead of the custom view class name. This may be helpful if your custom view requires special preparation before application instantiation. - - require 'Slim/Slim.php'; - require 'CustomView.php'; - $app = new Slim(array( - 'view' => new CustomView() - )); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/views-data.markdown b/Slim/codeguy-Slim-aa7e919/docs/views-data.markdown deleted file mode 100644 index c4f1085..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/views-data.markdown +++ /dev/null @@ -1,31 +0,0 @@ -# View Data [views-data] # - -The view's `setData()` and `appendData()` instance methods inject data into the view object; the injected data is available to view templates. View data is stored internally as a key-value array. - -## Set Data ## - -The view's `setData()` instance method will _overwrite_ existing view data. - -You may use this method to set a single variable to a given value like this: - - $view = $app->view(); - $view->setData('color', 'red'); - -The view's data will now contain a key "color" with value "red". You may also use the view's `setData()` instance method to batch assign an entire array of data like this: - - $view = $app->view(); - $view->setData(array( - 'color' => 'red', - 'size' => 'medium' - )); - -Remember, the view's `setData()` instance will _replace_ all previous data. - -## Append Data ## - -The view also has the `appendData()` instance method. This method _appends_ data to the view's existing data. This method accepts an array as its one and only argument like this: - - $app = new Slim(); - $app->view()->appendData(array( - 'foo' => 'bar' - )); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/views-rendering.markdown b/Slim/codeguy-Slim-aa7e919/docs/views-rendering.markdown deleted file mode 100644 index 6e6422f..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/views-rendering.markdown +++ /dev/null @@ -1,32 +0,0 @@ -# Rendering [views-rendering] # - -You can use the Slim application's `render()` instance method to ask the current View to render a template with a given set of variables. The `render()` method will `echo()` the output returned from the View so that the output is appended automatically to the Response object's body. This assumes nothing about how the template is rendered; that is delegated to the View. - - $app = new Slim(); - - //For PHP >= 5.3 - $app->get('/books/:id', function ($id) use ($app) { - $app->render('myTemplate.php', array('id' => $id)); - }); - - //For PHP < 5.3 - $app->get('/books/:id', 'show_book'); - function show_book($id) { - $app = Slim::getInstance(); - $app->render('myTemplate.php', array('id' => $id)); - } - -If you need to pass data from the route callback into the View, you must explicitly do so by passing an array as the second argument of the Slim application's `render()` instance method like this: - - $app->render( - 'myTemplate.php', - array( 'name' => 'Josh' ) - ); - -You can also set the HTTP response status when you render a template: - - $app->render( - 'myTemplate.php', - array( 'name' => 'Josh' ), - 404 - ); \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/views-settings.markdown b/Slim/codeguy-Slim-aa7e919/docs/views-settings.markdown deleted file mode 100644 index 0745acd..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/views-settings.markdown +++ /dev/null @@ -1,15 +0,0 @@ -# View Settings [views-settings] # - -The Slim application's view is configurable with application settings. These settings are described in the [Application Settings](#settings) section of this documentation. Briefly, these settings are: - -## view ## - -The class name or instance of a custom view. The view class must subclass `Slim_View`. - -[More Information](#settings-view) - -## templates.path ## - -The relative or absolute file system path to the directory that contains view templates. - -[More Information](#settings-templates-path) \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/views.markdown b/Slim/codeguy-Slim-aa7e919/docs/views.markdown deleted file mode 100644 index 3d1c37c..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/views.markdown +++ /dev/null @@ -1,43 +0,0 @@ -# Views [views] # - -A View is a PHP class that **returns** a rendered template as a string. - -## Set the View ## - -The Slim application View may be set during instantiation like this: - - //During instantiation as instance - $app = new Slim(array( - 'view' => new TwigView() - )); - - //During instantiation as class name - $app = new Slim(array( - 'view' => 'TwigView' - )); - -During instantiation, you may pass either an instance of the View or the class name; if you use the class name, the class must be discoverable (either already included or available to a registered autoloader). - -The View may be set during runtime, too, like this: - - $app = new Slim(); - $app->get('/foo', function () use ($app) { - //Using an instance of View - $app->view(new TwigView()); - - //Using a class name - $app->view('TwigView'); - }); - $app->run(); - -If you set the View after instantiation, data already set on the previous View will be transferred to the new View. - -## Get the View ## - -You can just as easily fetch a reference to the current View with the same method but without an argument: - - $theView = $app->view(); - -## The Default View ## - -The Slim application will use a default View unless you specify your own. The default view uses `require()` and `extract()` to pull a template into memory and render its content against a set of variables. The rendered content is captured in an output buffer and returned. It's a fairly naive implementation, but it is easily overridden with [custom Views](#views-custom). \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/docs/welcome.markdown b/Slim/codeguy-Slim-aa7e919/docs/welcome.markdown deleted file mode 100644 index 41cc5a7..0000000 --- a/Slim/codeguy-Slim-aa7e919/docs/welcome.markdown +++ /dev/null @@ -1,6 +0,0 @@ -# Slim Framework for PHP 5 Documentation [welcome] - -Slim is a micro framework for PHP 5 that helps you quickly write simple yet powerful RESTful 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 here and within the code itself. If you need further explanation about a certain class or method, don't hesitate to open up the source code. Thank you for choosing Slim for your next project. I think you're going to love it. - -Best regards, -Josh Lockhart \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/index.php b/Slim/codeguy-Slim-aa7e919/index.php deleted file mode 100644 index 600f416..0000000 --- a/Slim/codeguy-Slim-aa7e919/index.php +++ /dev/null @@ -1,163 +0,0 @@ -get('/hello/:name', 'myFunction'); - * function myFunction($name) { echo "Hello, $name"; } - * - * The routes below work with PHP >= 5.3. - */ - -//GET route -$app->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. -

- -

IRC

-

- Find Josh Lockhart in the irc.freenode.net "##slim" IRC channel during the day. Say hi, ask questions, - or just hang out with fellow Slim users. -

-
-
-

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'; -}); - -//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 is responsible for executing - * the Slim application using the settings and routes defined above. - */ -$app->run(); diff --git a/Slim/codeguy-Slim-aa7e919/tests/EnvironmentTest.php b/Slim/codeguy-Slim-aa7e919/tests/EnvironmentTest.php deleted file mode 100644 index 798c9da..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/EnvironmentTest.php +++ /dev/null @@ -1,340 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Environment.php'; - -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['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['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['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_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['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_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_TYPE'] = 'text/csv'; - $_SERVER['HTTP_CONTENT_LENGTH'] = 150; - $env = Slim_Environment::getInstance(true); - $this->assertFalse(isset($env['HTTP_CONTENT_TYPE'])); - $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['X_REQUESTED_WITH']); - } - - /** - * 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'])); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Foo.php b/Slim/codeguy-Slim-aa7e919/tests/Foo.php deleted file mode 100644 index 5ff331e..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Foo.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Http/HeadersTest.php b/Slim/codeguy-Slim-aa7e919/tests/Http/HeadersTest.php deleted file mode 100644 index a1c32e9..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Http/HeadersTest.php +++ /dev/null @@ -1,137 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Http/Headers.php'; - -class HeadersTest extends PHPUnit_Framework_TestCase { - /** - * Test constructor without args - */ - public function testConstructorWithoutArgs() { - $h = new Slim_Http_Headers(); - $this->assertEquals(0, count($h)); - } - - /** - * Test constructor with args - */ - public function testConstructorWithArgs() { - $h = new Slim_Http_Headers(array('Content-Type' => 'text/html')); - $this->assertEquals(1, count($h)); - } - - /** - * Test get and set header - */ - public function testSetAndGetHeader() { - $h = new Slim_Http_Headers(); - $h['Content-Type'] = 'text/html'; - $this->assertEquals('text/html', $h['Content-Type']); - $this->assertEquals('text/html', $h['Content-type']); - $this->assertEquals('text/html', $h['content-type']); - } - - /** - * Test get non-existent header - */ - public function testGetNonExistentHeader() { - $h = new Slim_Http_Headers(); - $this->assertNull($h['foo']); - } - - /** - * Test isset header - */ - public function testHeaderIsSet() { - $h = new Slim_Http_Headers(); - $h['Content-Type'] = 'text/html'; - $this->assertTrue(isset($h['Content-Type'])); - $this->assertTrue(isset($h['Content-type'])); - $this->assertTrue(isset($h['content-type'])); - $this->assertFalse(isset($h['foo'])); - } - - /** - * Test unset header - */ - public function testUnsetHeader() { - $h = new Slim_Http_Headers(); - $h['Content-Type'] = 'text/html'; - $this->assertEquals(1, count($h)); - unset($h['Content-Type']); - $this->assertEquals(0, count($h)); - } - - /** - * Test merge headers - */ - public function testMergeHeaders() { - $h = new Slim_Http_Headers(); - $h['Content-Type'] = 'text/html'; - $this->assertEquals(1, count($h)); - $h->merge(array('Content-type' => 'text/csv', 'content-length' => 10)); - $this->assertEquals(2, count($h)); - $this->assertEquals('text/csv', $h['content-type']); - $this->assertEquals(10, $h['Content-length']); - } - - /** - * Test iteration - */ - public function testIteration() { - $h = new Slim_Http_Headers(); - $h['One'] = 'Foo'; - $h['Two'] = 'Bar'; - $output = ''; - foreach ( $h as $key => $value ) { - $output .= $key . $value; - } - $this->assertEquals('OneFooTwoBar', $output); - } - - /** - * Test outputs header name in original form, not canonical form - */ - public function testOutputsOriginalNotCanonicalName() { - $h = new Slim_Http_Headers(); - $h['X-Powered-By'] = 'Slim'; - $h['Content-Type'] = 'text/csv'; - $keys = array(); - foreach ( $h as $name => $value ) { - $keys[] = $name; - } - $this->assertContains('X-Powered-By', $keys); - $this->assertContains('Content-Type', $keys); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Http/RequestTest.php b/Slim/codeguy-Slim-aa7e919/tests/Http/RequestTest.php deleted file mode 100644 index b27a545..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Http/RequestTest.php +++ /dev/null @@ -1,875 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Environment.php'; -require_once 'Slim/Http/Util.php'; -require_once 'Slim/Http/Request.php'; - -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()); - $this->assertFalse($req->isPost()); - $this->assertFalse($req->isPut()); - $this->assertFalse($req->isDelete()); - $this->assertFalse($req->isOptions()); - $this->assertFalse($req->isHead()); - } - - /** - * Test HTTP POST method detection - */ - public function testIsPost() { - $env = Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'POST', - )); - $req = new Slim_Http_Request($env); - $this->assertFalse($req->isGet()); - $this->assertTrue($req->isPost()); - $this->assertFalse($req->isPut()); - $this->assertFalse($req->isDelete()); - $this->assertFalse($req->isOptions()); - $this->assertFalse($req->isHead()); - } - - /** - * Test HTTP PUT method detection - */ - public function testIsPut() { - $env = Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'PUT', - )); - $req = new Slim_Http_Request($env); - $this->assertFalse($req->isGet()); - $this->assertFalse($req->isPost()); - $this->assertTrue($req->isPut()); - $this->assertFalse($req->isDelete()); - $this->assertFalse($req->isOptions()); - $this->assertFalse($req->isHead()); - } - - /** - * Test HTTP DELETE method detection - */ - public function testIsDelete() { - $env = Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'DELETE', - )); - $req = new Slim_Http_Request($env); - $this->assertFalse($req->isGet()); - $this->assertFalse($req->isPost()); - $this->assertFalse($req->isPut()); - $this->assertTrue($req->isDelete()); - $this->assertFalse($req->isOptions()); - $this->assertFalse($req->isHead()); - } - - /** - * Test HTTP OPTIONS method detection - */ - public function testIsOptions() { - $env = Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'OPTIONS', - )); - $req = new Slim_Http_Request($env); - $this->assertFalse($req->isGet()); - $this->assertFalse($req->isPost()); - $this->assertFalse($req->isPut()); - $this->assertFalse($req->isDelete()); - $this->assertTrue($req->isOptions()); - $this->assertFalse($req->isHead()); - } - - /** - * Test HTTP HEAD method detection - */ - public function testIsHead() { - $env = Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'HEAD', - )); - $req = new Slim_Http_Request($env); - $this->assertFalse($req->isGet()); - $this->assertFalse($req->isPost()); - $this->assertFalse($req->isPut()); - $this->assertFalse($req->isDelete()); - $this->assertFalse($req->isOptions()); - $this->assertTrue($req->isHead()); - } - - /** - * 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' => 'one=1&two=2&three=3&isajax=1', - )); - $req = new Slim_Http_Request($env); - $this->assertTrue($req->isAjax()); - $this->assertTrue($req->isXhr()); - } - - /** - * Test AJAX method detection wihtout header or query paramter - */ - 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')); - } - - /** - * 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')); - } - - /** - * 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')); - } - - /** - * 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')); - } - - /** - * 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')); - } - - /** - * 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')); - } - - /** - * 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')); - } - - /** - * Test fetch COOKIE params - */ - public function testCookies() { - $env = Slim_Environment::mock(array( - '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( - 'ACCEPT_ENCODING' => 'gzip' - )); - $req = new Slim_Http_Request($env); - $headers = $req->headers(); - $this->assertTrue(is_array($headers)); - $this->assertArrayHasKey('ACCEPT_ENCODING', $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 - */ - public function testGetContentTypeWhenNotExists() { - $env = Slim_Environment::mock(); - $req = new Slim_Http_Request($env); - $this->assertNull($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', - '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', - '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', - 'HOST' => 'slimframework.com' - )); - unset($env['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( - '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 dulplicate port numbers - */ - public function testGetHostDoesntDulplicatePort() { - $env = Slim_Environment::mock(array( - '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( - '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( - '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( - '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 - */ - public function testGetIp() { - $env = Slim_Environment::mock(array( - 'REMOTE_ADDR' => '127.0.0.1' - )); - $req = new Slim_Http_Request($env); - $this->assertEquals('127.0.0.1', $req->getIp()); - } - - /** - * Test get IP with proxy server and Client-Ip header - */ - public function testGetIpWithClientIp() { - $env = Slim_Environment::mock(array( - 'REMOTE_ADDR' => '127.0.0.1', - 'CLIENT_IP' => '127.0.0.2' - )); - $req = new Slim_Http_Request($env); - $this->assertEquals('127.0.0.2', $req->getIp()); - } - - /** - * Test get IP with proxy server and X-Forwarded-For header - */ - public function testGetIpWithForwardedFor() { - $env = Slim_Environment::mock(array( - 'REMOTE_ADDR' => '127.0.0.1', - 'CLIENT_IP' => '127.0.0.2', - 'X_FORWARDED_FOR' => '127.0.0.3' - )); - $req = new Slim_Http_Request($env); - $this->assertEquals('127.0.0.3', $req->getIp()); - } - - /** - * Test get refererer - */ - public function testGetReferrer() { - $env = Slim_Environment::mock(array( - '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 refererer - */ - 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( - '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['USER_AGENT']); - $req = new Slim_Http_Request($env); - $this->assertNull($req->getUserAgent()); - } -} diff --git a/Slim/codeguy-Slim-aa7e919/tests/Http/ResponseTest.php b/Slim/codeguy-Slim-aa7e919/tests/Http/ResponseTest.php deleted file mode 100644 index 2bfa076..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Http/ResponseTest.php +++ /dev/null @@ -1,534 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Http/Headers.php'; -require_once 'Slim/Http/Util.php'; -require_once 'Slim/Http/Response.php'; - -class ResponseTest extends PHPUnit_Framework_TestCase { - /** - * Test constructor without args - */ - public function testConstructorWithoutArgs() { - $r = new Slim_Http_Response(); - $this->assertEquals('', $r->body()); - $this->assertEquals(200, $r->status()); - $this->assertEquals(0, $r->length()); - $this->assertEquals('text/html', $r['Content-Type']); - } - - /** - * Test constructor with args - */ - public function testConstructorWithArgs() { - $r = new Slim_Http_Response('Page Not Found', 404, array('Content-Type' => 'application/json', 'X-Created-By' => 'Slim')); - $this->assertEquals('Page Not Found', $r->body()); - $this->assertEquals(404, $r->status()); - $this->assertEquals(14, $r->length()); - $this->assertEquals('application/json', $r['Content-Type']); - $this->assertEquals('Slim', $r['X-Created-By']); - } - - /** - * Test get status - */ - public function testGetStatus() { - $r = new Slim_Http_Response(); - $this->assertEquals(200, $r->status()); - } - - /** - * Test set status - */ - public function testSetStatus() { - $r = new Slim_Http_Response(); - $r->status(500); - $this->assertEquals(500, $r->status()); - } - - /** - * Test get headers - */ - public function testGetHeaders() { - $r = new Slim_Http_Response(); - $headers = $r->headers(); - $this->assertEquals(1, count($headers)); - $this->assertEquals('text/html', $headers['Content-Type']); - } - - /** - * Test get and set header (without Array Access) - */ - public function testGetAndSetHeader() { - $r = new Slim_Http_Response(); - $r->header('X-Foo', 'Bar'); - $this->assertEquals('Bar', $r->header('X-Foo')); - } - - /** - * Test get body - */ - public function testGetBody() { - $r = new Slim_Http_Response('Foo'); - $this->assertEquals('Foo', $r->body()); - } - - /** - * Test set body - */ - public function testSetBody() { - $r = new Slim_Http_Response(); - $r->body('Foo'); - $this->assertEquals('Foo', $r->body()); - } - - /** - * Test get length - */ - public function testGetLength() { - $r = new Slim_Http_Response('Foo'); - $this->assertEquals(3, $r->length()); - } - - /** - * Test set length - */ - public function testSetLength() { - $r = new Slim_Http_Response(); - $r->length(3); - $this->assertEquals(3, $r->length()); - } - - /** - * Test write for appending - */ - public function testWriteAppend() { - $r = new Slim_Http_Response('Foo'); - $r->write('Bar'); - $this->assertEquals('FooBar', $r->body()); - } - - /** - * Test write for replacing - */ - public function testWriteReplace() { - $r = new Slim_Http_Response('Foo'); - $r->write('Bar', true); - $this->assertEquals('Bar', $r->body()); - } - - /** - * Test finalize - */ - public function testFinalize() { - $r = new Slim_Http_Response(); - $r->status(404); - $r['Content-Type'] = 'application/json'; - $r->write('Foo'); - $result = $r->finalize(); - $this->assertEquals(3, count($result)); - $this->assertEquals(404, $result[0]); - $this->assertFalse(is_null($result[1]['Content-Type'])); - } - - /** - * Test finalize - */ - public function testFinalizeWithoutBody() { - $r = new Slim_Http_Response(); - $r->status(204); - $r['Content-Type'] = 'application/json'; - $r->write('Foo'); - $result = $r->finalize(); - $this->assertEquals(3, count($result)); - $this->assertEquals('', $result[2]); - } - - /** - * Test set cookie with only name and value - */ - public function testSetCookieWithNameAndValue() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', 'bar'); - $this->assertEquals('foo=bar', $r['Set-Cookie']); - } - - /** - * Test set multiple cookies with only name and value - */ - public function testSetMultipleCookiesWithNameAndValue() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', 'bar'); - $r->setCookie('abc', '123'); - $this->assertEquals("foo=bar\nabc=123", $r['Set-Cookie']); - } - - /** - * Test set cookie only name and value and expires (as int) - */ - public function testSetMultipleCookiesWithNameAndValueAndExpiresAsInt() { - $now = time(); - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'expires' => $now - )); - $this->assertEquals("foo=bar; expires=" . gmdate('D, d-M-Y H:i:s e', $now), $r['Set-Cookie']); - } - - /** - * Test set cookie with only name and value and expires (as string) - */ - public function testSetMultipleCookiesWithNameAndValueAndExpiresAsString() { - $expires = 'next Tuesday'; - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'expires' => $expires - )); - $this->assertEquals("foo=bar; expires=" . gmdate('D, d-M-Y H:i:s e', strtotime($expires)), $r['Set-Cookie']); - } - - /** - * Test set cookie with name, value, domain - */ - public function testSetCookieWithNameAndValueAndDomain() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'domain' => '.slimframework.com' - )); - $this->assertEquals('foo=bar; domain=.slimframework.com', $r['Set-Cookie']); - } - - /** - * Test set cookie with name, value, domain, path - */ - public function testSetCookieWithNameAndValueAndDomainAndPath() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'domain' => '.slimframework.com', - 'path' => '/foo' - )); - $this->assertEquals($r['Set-Cookie'], 'foo=bar; domain=.slimframework.com; path=/foo'); - } - - /** - * Test set cookie with only name and value and secure flag - */ - public function testSetCookieWithNameAndValueAndSecureFlag() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'secure' => true - )); - $this->assertEquals('foo=bar; secure', $r['Set-Cookie']); - } - - /** - * Test set cookie with only name and value and secure flag (as non-truthy) - */ - public function testSetCookieWithNameAndValueAndSecureFlagAsNonTruthy() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'secure' => 0 - )); - $this->assertEquals('foo=bar', $r['Set-Cookie']); - } - - /** - * Test set cookie with only name and value and httponly flag - */ - public function testSetCookieWithNameAndValueAndHttpOnlyFlag() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'httponly' => true - )); - $this->assertEquals('foo=bar; HttpOnly', $r['Set-Cookie']); - } - - /** - * Test set cookie with only name and value and httponly flag (as non-truthy) - */ - public function testSetCookieWithNameAndValueAndHttpOnlyFlagAsNonTruthy() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'httponly' => 0 - )); - $this->assertEquals('foo=bar', $r['Set-Cookie']); - } - - /* - * Test delete cookie by name - */ - public function testDeleteCookieByName() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', 'bar'); - $r->setCookie('abc', '123'); - $r->deleteCookie('foo'); - $this->assertEquals(1, preg_match("@abc=123\nfoo=; expires=@", $r['Set-Cookie'])); - } - - /* - * Test delete cookie by name and domain - */ - public function testDeleteCookieByNameAndDomain1() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', 'bar'); //Note: This does not have domain associated with it - $r->setCookie('abc', '123'); - $r->deleteCookie('foo', array('domain' => '.slimframework.com')); //This SHOULD NOT remove the `foo` cookie - $this->assertEquals(1, preg_match("@foo=bar\nabc=123\nfoo=; domain=.slimframework.com; expires=@", $r['Set-Cookie'])); - } - - /* - * Test delete cookie by name and domain - */ - public function testDeleteCookieByNameAndDomain2() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', array( - 'value' => 'bar', - 'domain' => '.slimframework.com' //Note: This does have domain associated with it - )); - $r->setCookie('abc', '123'); - $r->deleteCookie('foo', array('domain' => '.slimframework.com')); //This SHOULD remove the `foo` cookie - $this->assertEquals(1, preg_match("@abc=123\nfoo=; domain=.slimframework.com; expires=@", $r['Set-Cookie'])); - } - - /** - * Test delete cookie by name and custom props - */ - public function testDeleteCookieByNameAndCustomProps() { - $r = new Slim_Http_Response(); - $r->setCookie('foo', 'bar'); - $r->setCookie('abc', '123'); - $r->deleteCookie('foo', array( - 'secure' => true, - 'httponly' => true - )); - $this->assertEquals(1, preg_match("@abc=123\nfoo=; expires=.*; secure; HttpOnly@", $r['Set-Cookie'])); - } - - /** - * Test redirect - */ - public function testRedirect() { - $r = new Slim_Http_Response(); - $r->redirect('/foo'); - $this->assertEquals(302, $r->status()); - $this->assertEquals('/foo', $r['Location']); - } - - /** - * Test redirect with custom status - */ - public function testRedirectWithCustomStatus() { - $r = new Slim_Http_Response(); - $r->redirect('/foo', 307); - $this->assertEquals(307, $r->status()); - $this->assertEquals('/foo', $r['Location']); - } - - /** - * Test isEmpty - */ - public function testIsEmpty() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(404); - $r2->status(201); - $this->assertFalse($r1->isEmpty()); - $this->assertTrue($r2->isEmpty()); - } - - /** - * Test isClientError - */ - public function testIsClientError() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(404); - $r2->status(500); - $this->assertTrue($r1->isClientError()); - $this->assertFalse($r2->isClientError()); - } - - /** - * Test isForbidden - */ - public function testIsForbidden() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(403); - $r2->status(500); - $this->assertTrue($r1->isForbidden()); - $this->assertFalse($r2->isForbidden()); - } - - /** - * Test isInformational - */ - public function testIsInformational() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(100); - $r2->status(200); - $this->assertTrue($r1->isInformational()); - $this->assertFalse($r2->isInformational()); - } - - /** - * Test isInformational - */ - public function testIsNotFound() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(404); - $r2->status(200); - $this->assertTrue($r1->isNotFound()); - $this->assertFalse($r2->isNotFound()); - } - - /** - * Test isOk - */ - public function testIsOk() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(200); - $r2->status(201); - $this->assertTrue($r1->isOk()); - $this->assertFalse($r2->isOk()); - } - - /** - * Test isSuccessful - */ - public function testIsSuccessful() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r3 = new Slim_Http_Response(); - $r1->status(200); - $r2->status(201); - $r3->status(302); - $this->assertTrue($r1->isSuccessful()); - $this->assertTrue($r2->isSuccessful()); - $this->assertFalse($r3->isSuccessful()); - } - - /** - * Test isRedirect - */ - public function testIsRedirect() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(307); - $r2->status(304); - $this->assertTrue($r1->isRedirect()); - $this->assertFalse($r2->isRedirect()); - } - - /** - * Test isRedirection - */ - public function testIsRedirection() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r3 = new Slim_Http_Response(); - $r1->status(307); - $r2->status(304); - $r3->status(200); - $this->assertTrue($r1->isRedirection()); - $this->assertTrue($r2->isRedirection()); - $this->assertFalse($r3->isRedirection()); - } - - /** - * Test isServerError - */ - public function testIsServerError() { - $r1 = new Slim_Http_Response(); - $r2 = new Slim_Http_Response(); - $r1->status(500); - $r2->status(400); - $this->assertTrue($r1->isServerError()); - $this->assertFalse($r2->isServerError()); - } - - /** - * Test offset exists and offset get - */ - public function testOffsetExistsAndGet() { - $r = new Slim_Http_Response(); - $this->assertFalse(empty($r['Content-Type'])); - $this->assertNull($r['foo']); - } - - /** - * Test iteration - */ - public function testIteration() { - $h = new Slim_Http_Response(); - $output = ''; - foreach ( $h as $key => $value ) { - $output .= $key . $value; - } - $this->assertEquals('Content-Typetext/html', $output); - } - - /** - * Test countable - */ - public function testCountable() { - $r1 = new Slim_Http_Response(); - $this->assertEquals(1, count($r1)); //Content-Type - } - - /** - * Test message for code when message exists - */ - public function testMessageForCode() { - $this->assertEquals('200 OK', Slim_Http_Response::getMessageForCode(200)); - } - - /** - * Test message for code when message exists - */ - public function testMessageForCodeWithInvalidCode() { - $this->assertNull(Slim_Http_Response::getMessageForCode(600)); - } -} diff --git a/Slim/codeguy-Slim-aa7e919/tests/Http/UtilTest.php b/Slim/codeguy-Slim-aa7e919/tests/Http/UtilTest.php deleted file mode 100644 index 5c77e0a..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Http/UtilTest.php +++ /dev/null @@ -1,352 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Http/Util.php'; - -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']); - } - - 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; colors=red; colors=green'; - $result = Slim_Http_Util::parseCookieHeader($header); - $this->assertEquals(3, count($result)); - $this->assertEquals('bar', $result['foo']); - $this->assertEquals('two', $result['one']); - $this->assertEquals(3, count($result['colors'])); - $this->assertEquals('blue', $result['colors'][0]); - $this->assertEquals('red', $result['colors'][1]); - $this->assertEquals('green', $result['colors'][2]); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/LogFileWriterTest.php b/Slim/codeguy-Slim-aa7e919/tests/LogFileWriterTest.php deleted file mode 100644 index bbd6149..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/LogFileWriterTest.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/LogFileWriter.php'; - -class LogFileWriterTest extends PHPUnit_Framework_TestCase { - public function testInstantiation() { - $this->expectOutputString('Hello!' . PHP_EOL); - $handle = fopen('php://output', 'w'); - $fw = new Slim_LogFileWriter($handle); - $this->assertTrue($fw->write('Hello!') > 0); //<-- Returns number of bytes written if successful - } - - public function testInstantiationWithNonResource() { - $this->setExpectedException('InvalidArgumentException'); - $fw = new Slim_LogFileWriter(@fopen('/foo/bar.txt', 'w')); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/LogTest.php b/Slim/codeguy-Slim-aa7e919/tests/LogTest.php deleted file mode 100644 index 10cd1b1..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/LogTest.php +++ /dev/null @@ -1,138 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require 'Slim/Log.php'; - -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(4, $log->getLevel()); - } - - public function testSetLevel() { - $log = new Slim_Log(new MyWriter()); - $log->setLevel(2); - $this->assertEquals(2, $log->getLevel()); - } - - public function testSetInvalidLevel() { - $this->setExpectedException('InvalidArgumentException'); - $log = new Slim_Log(new MyWriter()); - $log->setLevel(5); - } - - 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(3); - $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(2); - $this->assertFalse($log->info('Info')); - } - - public function testLogWarn() { - $this->expectOutputString('Warn'); - $log = new Slim_Log(new MyWriter()); - $result = $log->warn('Warn'); - $this->assertTrue($result); - } - - public function testLogWarnExcludedByLevel() { - $log = new Slim_Log(new MyWriter()); - $log->setLevel(1); - $this->assertFalse($log->warn('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(0); - $this->assertFalse($log->error('Error')); - } - - public function testLogFatal() { - $this->expectOutputString('Fatal'); - $log = new Slim_Log(new MyWriter()); - $result = $log->fatal('Fatal'); - $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()); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Middleware/ContentTypesTest.php b/Slim/codeguy-Slim-aa7e919/tests/Middleware/ContentTypesTest.php deleted file mode 100644 index 558ddc8..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Middleware/ContentTypesTest.php +++ /dev/null @@ -1,157 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Slim.php'; -require_once 'Slim/Middleware/ContentTypes.php'; - -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(); - $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(); - $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(); - $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() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'POST', - 'CONTENT_TYPE' => 'application/xml', - 'CONENT_LENGTH' => 68, - 'slim.input' => '1Clive Cussler' //<-- This should be incorrect! - )); - $s = new 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', - 'CONENT_LENGTH' => 44, - 'slim.input' => "John,Doe,000-111-2222\nJane,Doe,111-222-3333" - )); - $s = new 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', - 'CONENT_LENGTH' => 13, - 'slim.input' => '{"foo":"bar"}' - )); - $s = new Slim(); - $s->add(new Slim_Middleware_ContentTypes()); - $s->run(); - $body = $s->request()->getBody(); - $this->assertTrue(is_array($body)); - $this->assertEquals('bar', $body['foo']); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Middleware/FlashTest.php b/Slim/codeguy-Slim-aa7e919/tests/Middleware/FlashTest.php deleted file mode 100644 index 48cc599..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Middleware/FlashTest.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Middleware.php'; -require_once 'Slim/Middleware/Flash.php'; - -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 preivous 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'])); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Middleware/MethodOverrideTest.php b/Slim/codeguy-Slim-aa7e919/tests/Middleware/MethodOverrideTest.php deleted file mode 100644 index 262cd8a..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Middleware/MethodOverrideTest.php +++ /dev/null @@ -1,145 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Slim.php'; - -/** - * 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; - } - - 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', - 'CONENT_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 ovveride 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', - 'CONENT_LENGTH' => 0, - 'slim.input' => '', - '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']); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Middleware/PrettyExceptionsTest.php b/Slim/codeguy-Slim-aa7e919/tests/Middleware/PrettyExceptionsTest.php deleted file mode 100644 index 30bfd8d..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Middleware/PrettyExceptionsTest.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Slim.php'; - -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(); - $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(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()); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/Middleware/SessionCookieTest.php b/Slim/codeguy-Slim-aa7e919/tests/Middleware/SessionCookieTest.php deleted file mode 100644 index 54aebe6..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/Middleware/SessionCookieTest.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Slim.php'; - -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 is added to the `Set-Cookie:` response header; - * 2) That the HTTP cookie is constructed in the expected format; - */ - public function testSessionCookieIsCreatedAndEncrypted() { - Slim_Environment::mock(array( - 'SCRIPT_NAME' => '/index.php', - 'PATH_INFO' => '/foo' - )); - $app = new Slim(); - $app->get('/foo', function () { - 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(); - $matches = array(); - preg_match_all('@^slim_session=.+|.+|.+; expires=@', $header['Set-Cookie'], $matches, PREG_SET_ORDER); - $this->assertEquals(1, count($matches)); - } - - /** - * Test $_SESSION is populated from HTTP cookie - * - * The HTTP cookie in this test was created using the previous test; the encrypted cookie contains - * the serialized array ['foo' => 'bar']. The middleware secret, cipher, and cipher mode are assumed - * to be the default values. - */ - public function testSessionIsPopulatedFromCookie() { - Slim_Environment::mock(array( - 'SCRIPT_NAME' => '/index.php', - 'PATH_INFO' => '/foo', - 'COOKIE' => 'slim_session=1644004961%7CLKkYPwqKIMvBK7MWl6D%2BxeuhLuMaW4quN%2F512ZAaVIY%3D%7Ce0f007fa852c7101e8224bb529e26be4d0dfbd63', - )); - $app = new 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('foo' => 'bar'), $_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(); - $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); - } -} diff --git a/Slim/codeguy-Slim-aa7e919/tests/MiddlewareTest.php b/Slim/codeguy-Slim-aa7e919/tests/MiddlewareTest.php deleted file mode 100644 index 5d82fcb..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/MiddlewareTest.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Middleware.php'; - -class My_Middleware extends Slim_Middleware { - public function call() { - echo "Before"; - $this->next->call(); - echo "After"; - } -} - -class My_Application { - public function call() { - echo "Application"; - } -} - -class MiddlewareTest extends PHPUnit_Framework_TestCase { - /** - * Get and set application - */ - public function testGetAndSetApplication() { - $app = new My_Application(); - $mw = new My_Middleware(); - $mw->setApplication($app); - $this->assertSame($app, $mw->getApplication()); - } - - /** - * Get and set next middleware - */ - public function testGetAndSetNextMiddleware() { - $mw1 = new My_Middleware(); - $mw2 = new My_Middleware(); - $mw1->setNextMiddleware($mw2); - $this->assertSame($mw2, $mw1->getNextMiddleware()); - } - - /** - * Test call - */ - public function testCall() { - $this->expectOutputString('BeforeApplicationAfter'); - $app = new My_Application(); - $mw = new My_Middleware(); - $mw->setNextMiddleware($app); - $mw->call(); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/README b/Slim/codeguy-Slim-aa7e919/tests/README deleted file mode 100644 index 7bc611c..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/README +++ /dev/null @@ -1,18 +0,0 @@ -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/Slim/codeguy-Slim-aa7e919/tests/RouteTest.php b/Slim/codeguy-Slim-aa7e919/tests/RouteTest.php deleted file mode 100644 index 50de3b8..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/RouteTest.php +++ /dev/null @@ -1,444 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Route.php'; -require_once 'Slim/Router.php'; -require_once 'Slim/Environment.php'; -require_once 'Slim/Http/Headers.php'; -require_once 'Slim/Http/Request.php'; -require_once 'Slim/Http/Response.php'; -require_once 'Slim/Exception/RequestSlash.php'; - -/** - * Router Mock - * - * This is a mock for the Router class so that it, - * A) provides the necessary features for this test and - * B) removes dependencies on the Request class. - */ -class RouterMock extends Slim_Router { - - public $cache = array(); - - public function __construct() {} - - public function addNamedRoute($name, Slim_Route $route) { - $this->cache[$name] = $route; - } - -} - -class RouteTest extends PHPUnit_Framework_TestCase { - - /** - * Route should set name and be cached by Router - */ - public function testRouteSetsNameAndIsCached() { - $router = new RouterMock(); - $route = new Slim_Route('/foo/bar', function () {}); - $route->setRouter($router); - $route->name('foo'); - $cacheKeys = array_keys($router->cache); - $cacheValues = array_values($router->cache); - $this->assertEquals('foo', $route->getName()); - $this->assertSame($router, $route->getRouter()); - $this->assertEquals($cacheKeys[0], 'foo'); - $this->assertSame($cacheValues[0], $route); - } - - /** - * Route should set pattern - */ - public function testRouteSetsPattern() { - $route1 = new Slim_Route('/foo/bar', function () {}); - $this->assertEquals('/foo/bar', $route1->getPattern()); - } - - /** - * Route should store a reference to the callable - * anonymous function. - */ - public function testRouteSetsCallableAsFunction() { - $callable = function () { echo "Foo!"; }; - $route = new Slim_Route('/foo/bar', $callable); - $this->assertSame($callable, $route->getCallable()); - } - - /** - * Route should store a reference to the callable - * regular function (for PHP 5 < 5.3) - */ - public function testRouteSetsCallableAsString() { - $route = new Slim_Route('/foo/bar', 'testCallable'); - $this->assertEquals('testCallable', $route->getCallable()); - } - - /** - * If route matches a resource URI, param should be extracted. - */ - public function testRouteMatchesAndParamExtracted() { - $resource = '/hello/Josh'; - $route = new Slim_Route('/hello/:name', function () {}); - $result = $route->matches($resource); - $this->assertTrue($result); - $this->assertEquals(array('name' => 'Josh'), $route->getParams()); - } - - /** - * If route matches a resource URI, multiple params should be extracted. - */ - public function testRouteMatchesAndMultipleParamsExtracted() { - $resource = '/hello/Josh/and/John'; - $route = new Slim_Route('/hello/:first/and/:second', function () {}); - $result = $route->matches($resource); - $this->assertTrue($result); - $this->assertEquals(array('first' => 'Josh', 'second' => 'John'), $route->getParams()); - } - - /** - * If route does not match a resource URI, params remain an empty array - */ - public function testRouteDoesNotMatchAndParamsNotExtracted() { - $resource = '/foo/bar'; - $route = new Slim_Route('/hello/:name', function () {}); - $result = $route->matches($resource); - $this->assertFalse($result); - $this->assertEquals(array(), $route->getParams()); - } - - /** - * Route matches URI with trailing slash - * - */ - public function testRouteMatchesWithTrailingSlash() { - $resource1 = '/foo/bar/'; - $resource2 = '/foo/bar'; - $route = new Slim_Route('/foo/:one/', function () {}); - $this->assertTrue($route->matches($resource1)); - $this->assertTrue($route->matches($resource2)); - } - - /** - * Route matches URI with conditions - */ - public function testRouteMatchesResourceWithConditions() { - $resource = '/hello/Josh/and/John'; - $route = new Slim_Route('/hello/:first/and/:second', function () {}); - $route->conditions(array('first' => '[a-zA-Z]{3,}')); - $result = $route->matches($resource); - $this->assertTrue($result); - $this->assertEquals(array('first' => 'Josh', 'second' => 'John'), $route->getParams()); - } - - /** - * Route does not match URI with conditions - */ - public function testRouteDoesNotMatchResourceWithConditions() { - $resource = '/hello/Josh/and/John'; - $route = new Slim_Route('/hello/:first/and/:second', function () {}); - $route->conditions(array('first' => '[a-z]{3,}')); - $result = $route->matches($resource); - $this->assertFalse($result); - $this->assertEquals(array(), $route->getParams()); - } - - /* - * 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 testRouteMatchesResourceWithValidRfc2396PathComponent() { - $symbols = ':@&=$,'; - $resource = '/rfc2386/' . $symbols; - $route = new Slim_Route('/rfc2386/:symbols', function () {}); - $result = $route->matches($resource); - $this->assertTrue($result); - $this->assertEquals(array('symbols' => $symbols), $route->getParams()); - } - - /* - * 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 testRouteMatchesResourceWithUnreservedMarks() { - $marks = "-_.!~*'()"; - $resource = '/marks/' . $marks; - $route = new Slim_Route('/marks/:marks', function () {}); - $result = $route->matches($resource); - $this->assertTrue($result); - $this->assertEquals(array('marks' => $marks), $route->getParams()); - } - - /** - * Route optional parameters - * - * Pre-conditions: - * Route pattern requires :year, optionally accepts :month and :day - * - * Post-conditions: - * All: Year is 2010 - * Case A: Month and day default values are used - * Case B: Month is "05" and day default value is used - * Case C: Month is "05" and day is "13" - */ - public function testRouteOptionalParameters() { - $pattern = '/archive/:year(/:month(/:day))'; - - //Case A - $routeA = new Slim_Route($pattern, function () {}); - $resourceA = '/archive/2010'; - $resultA = $routeA->matches($resourceA); - $this->assertTrue($resultA); - $this->assertEquals(array('year' => '2010'), $routeA->getParams()); - - //Case B - $routeB = new Slim_Route($pattern, function () {}); - $resourceB = '/archive/2010/05'; - $resultB = $routeB->matches($resourceB); - $this->assertTrue($resultB); - $this->assertEquals(array('year' => '2010', 'month' => '05'), $routeB->getParams()); - - //Case C - $routeC = new Slim_Route($pattern, function () {}); - $resourceC = '/archive/2010/05/13'; - $resultC = $routeC->matches($resourceC); - $this->assertTrue($resultC); - $this->assertEquals(array('year' => '2010', 'month' => '05', 'day' => '13'), $routeC->getParams()); - } - - /** - * Test route default conditions - * - * Pre-conditions: - * Route class has default conditions; - * - * Post-conditions: - * Case A: Route instance has default conditions; - * Case B: Route instance has newly merged conditions; - */ - public function testRouteDefaultConditions() { - Slim_Route::setDefaultConditions(array('id' => '\d+')); - $r = new Slim_Route('/foo', function () {}); - //Case A - $this->assertEquals(Slim_Route::getDefaultConditions(), $r->getConditions()); - //Case B - $r->conditions(array('name' => '[a-z]{2,5}')); - $c = $r->getConditions(); - $this->assertArrayHasKey('id', $c); - $this->assertArrayHasKey('name', $c); - } - - /** - * Test route sets and gets middleware - * - * Pre-conditions: - * Route instantiated - * - * Post-conditions: - * Case A: Middleware set as callable, not array - * Case B: Middleware set after other middleware already set - * Case C: Middleware set as array of callables - * Case D: Middleware set as a callable array - * Case E: Middleware is invalid; throws InvalidArgumentException - */ - public function testRouteMiddleware() { - $callable1 = function () {}; - $callable2 = function () {}; - //Case A - $r1 = new Slim_Route('/foo', function () {}); - $r1->setMiddleware($callable1); - $mw = $r1->getMiddleware(); - $this->assertInternalType('array', $mw); - $this->assertEquals(1, count($mw)); - //Case B - $r1->setMiddleware($callable2); - $mw = $r1->getMiddleware(); - $this->assertEquals(2, count($mw)); - //Case C - $r2 = new Slim_Route('/foo', function () {}); - $r2->setMiddleware(array($callable1, $callable2)); - $mw = $r2->getMiddleware(); - $this->assertInternalType('array', $mw); - $this->assertEquals(2, count($mw)); - //Case D - $r3 = new Slim_Route('/foo', function () {}); - $r3->setMiddleware(array($this, 'callableTestFunction')); - $mw = $r3->getMiddleware(); - $this->assertInternalType('array', $mw); - $this->assertEquals(1, count($mw)); - //Case E - try { - $r3->setMiddleware('sdjfsoi788'); - $this->fail('Did not catch InvalidArgumentException when setting invalid route middleware'); - } catch ( InvalidArgumentException $e ) {} - } - - public function callableTestFunction() {} - - /** - * Test that a Route manages the HTTP methods that it supports - * - * Case A: Route initially supports no HTTP methods - * Case B: Route can set its supported HTTP methods - * Case C: Route can append supported HTTP methods - * Case D: Route can test if it supports an HTTP method - * Case E: Route can lazily declare supported HTTP methods with `via` - */ - public function testHttpMethods() { - //Case A - $r = new Slim_Route('/foo', function () {}); - $this->assertEmpty($r->getHttpMethods()); - //Case B - $r->setHttpMethods('GET'); - $this->assertEquals(array('GET'), $r->getHttpMethods()); - //Case C - $r->appendHttpMethods('POST', 'PUT'); - $this->assertEquals(array('GET', 'POST', 'PUT'), $r->getHttpMethods()); - //Case D - $this->assertTrue($r->supportsHttpMethod('GET')); - $this->assertFalse($r->supportsHttpMethod('DELETE')); - //Case E - $viaResult = $r->via('DELETE'); - $this->assertTrue($viaResult instanceof Slim_Route); - $this->assertTrue($r->supportsHttpMethod('DELETE')); - } - - public function testDispatch() { - $this->expectOutputString('Hello josh'); - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'GET', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/hello/josh', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $env = Slim_Environment::getInstance(); - $req = new Slim_Http_Request($env); - $res = new Slim_Http_Response(); - $router = new Slim_Router($req, $res); - $route = new Slim_Route('/hello/:name', function ($name) { echo "Hello $name"; }); - $route->setRouter($router); - $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI - $route->dispatch(); - } - - public function testDispatchWithMiddlware() { - $this->expectOutputString('First! Second! Hello josh'); - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'GET', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/hello/josh', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $env = Slim_Environment::getInstance(); - $req = new Slim_Http_Request($env); - $res = new Slim_Http_Response(); - $router = new Slim_Router($req, $res); - $route = new Slim_Route('/hello/:name', function ($name) { echo "Hello $name"; }); - $route->setMiddleware(function () { - echo "First! "; - }); - $route->setMiddleware(function () { - echo "Second! "; - }); - $route->setRouter($router); - $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI - $route->dispatch(); - } - - public function testDispatchWithRequestSlash() { - $this->setExpectedException('Slim_Exception_RequestSlash'); - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'GET', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/hello/josh', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $env = Slim_Environment::getInstance(); - $req = new Slim_Http_Request($env); - $res = new Slim_Http_Response(); - $router = new Slim_Router($req, $res); - $route = new Slim_Route('/hello/:name/', function ($name) { echo "Hello $name"; }); - $route->setRouter($router); - $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI - $route->dispatch(); - } - - public function testDispatchWithoutCallable() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'GET', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/hello/josh', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $env = Slim_Environment::getInstance(); - $req = new Slim_Http_Request($env); - $res = new Slim_Http_Response(); - $router = new Slim_Router($req, $res); - $route = new Slim_Route('/hello/:name', 'foo'); - $route->setRouter($router); - $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI - $this->assertFalse($route->dispatch()); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/RouterTest.php b/Slim/codeguy-Slim-aa7e919/tests/RouterTest.php deleted file mode 100644 index 8ffaa3f..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/RouterTest.php +++ /dev/null @@ -1,329 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Environment.php'; -require_once 'Slim/Http/Headers.php'; -require_once 'Slim/Http/Request.php'; -require_once 'Slim/Http/Response.php'; -require_once 'Slim/Router.php'; -require_once 'Slim/Route.php'; - -class RouterTest extends PHPUnit_Framework_TestCase { - - protected $env; - protected $req; - protected $res; - - public function setUp() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'GET', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $this->env = Slim_Environment::getInstance(); - $this->req = new Slim_Http_Request($this->env); - $this->res = new Slim_Http_Response(); - } - - /** - * Test sets and gets Request and Response - */ - public function testRouterRequestAndResponse() { - $router = new Slim_Router($this->req, $this->res); - $this->assertSame($this->req, $router->getRequest()); - $this->assertSame($this->res, $router->getResponse()); - } - - /** - * Router::urlFor should return a full route pattern - * even if no params data is provided. - */ - public function testUrlForNamedRouteWithoutParams() { - $router = new Slim_Router($this->req, $this->res); - $route = $router->map('/foo/bar', function () {})->via('GET'); - $router->addNamedRoute('foo', $route); - $this->assertEquals('/foo/bar', $router->urlFor('foo')); - } - - /** - * Router::urlFor should return a full route pattern if - * param data is provided. - */ - public function testUrlForNamedRouteWithParams() { - $router = new Slim_Router($this->req, $this->res); - $route = $router->map('/foo/:one/and/:two', function ($one, $two) {})->via('GET'); - $router->addNamedRoute('foo', $route); - $this->assertEquals('/foo/Josh/and/John', $router->urlFor('foo', array('one' => 'Josh', 'two' => 'John'))); - } - - /** - * Router::urlFor should throw an exception if Route with name - * does not exist. - */ - public function testUrlForNamedRouteThatDoesNotExist() { - $this->setExpectedException('RuntimeException'); - $router = new Slim_Router($this->req, $this->res); - $route = $router->map('/foo/bar', function () {})->via('GET'); - $router->addNamedRoute('bar', $route); - $router->urlFor('foo'); - } - - /** - * Router::addNamedRoute should throw an exception if named Route - * with same name already exists. - */ - public function testNamedRouteWithExistingName() { - $this->setExpectedException('RuntimeException'); - $router = new Slim_Router($this->req, $this->res); - $route1 = $router->map('/foo/bar', function () {})->via('GET'); - $route2 = $router->map('/foo/bar/2', function () {})->via('GET'); - $router->addNamedRoute('bar', $route1); - $router->addNamedRoute('bar', $route2); - } - - /** - * Test if named route exists - * - * Pre-conditions: - * Slim app instantiated; - * Named route created; - * - * Post-conditions: - * Named route found to exist; - * Non-existant route found not to exist; - */ - public function testHasNamedRoute() { - $router = new Slim_Router($this->req, $this->res); - $route = $router->map('/foo', function () {})->via('GET'); - $router->addNamedRoute('foo', $route); - $this->assertTrue($router->hasNamedRoute('foo')); - $this->assertFalse($router->hasNamedRoute('bar')); - } - - /** - * Test Router gets named route - * - * Pre-conditions; - * Slim app instantiated; - * Named route created; - * - * Post-conditions: - * Named route fetched by named; - * NULL is returned if named route does not exist; - */ - public function testGetNamedRoute() { - $router = new Slim_Router($this->req, $this->res); - $route1 = $router->map('/foo', function () {})->via('GET'); - $router->addNamedRoute('foo', $route1); - $this->assertSame($route1, $router->getNamedRoute('foo')); - $this->assertNull($router->getNamedRoute('bar')); - } - - /** - * Test external iterator for Router's named routes - * - * Pre-conditions: - * Slim app instantiated; - * Named routes created; - * - * Post-conditions: - * Array iterator returned for named routes; - */ - public function testGetNamedRoutes() { - $router = new Slim_Router($this->req, $this->res); - $route1 = $router->map('/foo', function () {})->via('GET'); - $route2 = $router->map('/bar', function () {})->via('POST'); - $router->addNamedRoute('foo', $route1); - $router->addNamedRoute('bar', $route2); - $namedRoutesIterator = $router->getNamedRoutes(); - $this->assertInstanceOf('ArrayIterator', $namedRoutesIterator); - $this->assertEquals(2, $namedRoutesIterator->count()); - } - - /** - * Router should keep reference to a callable NotFound callback - */ - public function testNotFoundHandler() { - $router = new Slim_Router($this->req, $this->res); - $notFoundCallback = function () { echo "404"; }; - $callback = $router->notFound($notFoundCallback); - $this->assertSame($notFoundCallback, $callback); - } - - /** - * Router should NOT keep reference to a callback that is not callable - */ - public function testNotFoundHandlerIfNotCallable() { - $router = new Slim_Router($this->req, $this->res); - $notFoundCallback = 'foo'; - $callback = $router->notFound($notFoundCallback); - $this->assertNull($callback); - } - - /** - * Router should keep reference to a callable NotFound callback - */ - public function testErrorHandler() { - $router = new Slim_Router($this->req, $this->res); - $errCallback = function () { echo "404"; }; - $callback = $router->error($errCallback); - $this->assertSame($errCallback, $callback); - } - - /** - * Router should NOT keep reference to a callback that is not callable - */ - public function testErrorHandlerIfNotCallable() { - $router = new Slim_Router($this->req, $this->res); - $errCallback = 'foo'; - $callback = $router->error($errCallback); - $this->assertNull($callback); - } - - /** - * Router considers HEAD requests as GET requests - */ - public function testRouterConsidersHeadAsGet() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'HEAD', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $this->env = Slim_Environment::getInstance(); - $this->req = new Slim_Http_Request($this->env); - $this->res = new Slim_Http_Response(); - $router = new Slim_Router($this->req, $this->res); - $route = $router->map('/bar', function () {})->via('GET', 'HEAD'); - $numberOfMatchingRoutes = count($router->getMatchedRoutes()); - $this->assertEquals(1, $numberOfMatchingRoutes); - } - - /** - * Router::urlFor - */ - public function testRouterUrlFor() { - $router = new Slim_Router($this->req, $this->res); - $route1 = $router->map('/foo/bar', function () {})->via('GET'); - $route2 = $router->map('/foo/:one/:two', function () {})->via('GET'); - $route3 = $router->map('/foo/:one(/:two)', function () {})->via('GET'); - $route4 = $router->map('/foo/:one/(:two/)', function () {})->via('GET'); - $route5 = $router->map('/foo/:one/(:two/(:three/))', function () {})->via('GET'); - $route1->setName('route1'); - $route2->setName('route2'); - $route3->setName('route3'); - $route4->setName('route4'); - $route5->setName('route5'); - //Route - $this->assertEquals('/foo/bar', $router->urlFor('route1')); - //Route with params - $this->assertEquals('/foo/foo/bar', $router->urlFor('route2', array('one' => 'foo', 'two' => 'bar'))); - $this->assertEquals('/foo/foo/:two', $router->urlFor('route2', array('one' => 'foo'))); - $this->assertEquals('/foo/:one/bar', $router->urlFor('route2', array('two' => 'bar'))); - //Route with params and optional segments - $this->assertEquals('/foo/foo/bar', $router->urlFor('route3', array('one' => 'foo', 'two' => 'bar'))); - $this->assertEquals('/foo/foo', $router->urlFor('route3', array('one' => 'foo'))); - $this->assertEquals('/foo/:one/bar', $router->urlFor('route3', array('two' => 'bar'))); - $this->assertEquals('/foo/:one', $router->urlFor('route3')); - //Route with params and optional segments - $this->assertEquals('/foo/foo/bar/', $router->urlFor('route4', array('one' => 'foo', 'two' => 'bar'))); - $this->assertEquals('/foo/foo/', $router->urlFor('route4', array('one' => 'foo'))); - $this->assertEquals('/foo/:one/bar/', $router->urlFor('route4', array('two' => 'bar'))); - $this->assertEquals('/foo/:one/', $router->urlFor('route4')); - //Route with params and optional segments - $this->assertEquals('/foo/foo/bar/what/', $router->urlFor('route5', array('one' => 'foo', 'two' => 'bar', 'three' => 'what'))); - $this->assertEquals('/foo/foo/', $router->urlFor('route5', array('one' => 'foo'))); - $this->assertEquals('/foo/:one/bar/', $router->urlFor('route5', array('two' => 'bar'))); - $this->assertEquals('/foo/:one/bar/what/', $router->urlFor('route5', array('two' => 'bar', 'three' => 'what'))); - $this->assertEquals('/foo/:one/', $router->urlFor('route5')); - } - - /** - * Test that router returns matched routes based on URI only, not - * based on the HTTP method. - */ - public function testRouterMatchesRoutesByUriOnly() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'GET', - 'REMOTE_ADDR' => '127.0.0.1', - 'SCRIPT_NAME' => '', //<-- Physical - 'PATH_INFO' => '/foo', //<-- Virtual - 'QUERY_STRING' => 'one=1&two=2&three=3', - 'SERVER_NAME' => 'slim', - 'SERVER_PORT' => 80, - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => fopen('php://stderr', 'w'), - 'HTTP_HOST' => 'slim' - )); - $this->env = Slim_Environment::getInstance(); - $this->req = new Slim_Http_Request($this->env); - $this->res = new Slim_Http_Response(); - $router = new Slim_Router($this->req, $this->res); - $router->map('/foo', function () {})->via('GET'); - $router->map('/foo', function () {})->via('POST'); - $router->map('/foo', function () {})->via('PUT'); - $router->map('/foo/bar/xyz', function () {})->via('DELETE'); - $this->assertEquals(3, count($router->getMatchedRoutes())); - } - - /** - * Test that Router implements IteratorAggregate interface - */ - public function testRouterImplementsIteratorAggregate() { - $router = new Slim_Router($this->req, $this->res); - $router->map('/bar', function () {})->via('GET'); - $router->map('/foo1', function () {})->via('POST'); - $router->map('/bar', function () {})->via('PUT'); - $router->map('/foo/bar/xyz', function () {})->via('DELETE'); - $iterator = $router->getIterator(); - $this->assertInstanceOf('ArrayIterator', $iterator); - $this->assertEquals(2, $iterator->count()); - } -} \ No newline at end of file diff --git a/Slim/codeguy-Slim-aa7e919/tests/SlimTest.php b/Slim/codeguy-Slim-aa7e919/tests/SlimTest.php deleted file mode 100644 index 9ab9de7..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/SlimTest.php +++ /dev/null @@ -1,1229 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/Slim.php'; - -//Register non-Slim autoloader -function customAutoLoader( $class ) { - $file = rtrim(dirname(__FILE__), '/') . '/' . $class . '.php'; - if ( file_exists($file) ) { - require $file; - } else { - return; - } -} -spl_autoload_register('customAutoLoader'); - -//Mock custom view -class CustomView extends Slim_View { - function render($template) { echo "Custom view"; } -} - -//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 default instance properties - */ - public function testDefaultInstanceProperties() { - $s = new 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(4, $s->getLog()->getLevel()); - $this->assertTrue($s->getLog()->getEnabled()); - $this->assertInstanceOf('Slim_Environment', $s->environment()); - } - - /** - * Test get default instance - */ - public function testGetDefaultInstance() { - $s = new 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::getInstance()); - $this->assertSame($s, Slim::getInstance()); - } - - /** - * Test get named instance - */ - public function testGetNamedInstance() { - $s = new Slim(); - $s->setName('foo'); - $this->assertSame($s, 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(); - $this->assertEquals('./templates', $s->config('templates.path')); - } - - /** - * Test get setting that does not exist - */ - public function testGetSettingThatDoesNotExist() { - $s = new Slim(); - $this->assertNull($s->config('foo')); - } - - /** - * Test set setting - */ - public function testSetSetting() { - $s = new 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(); - $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')); - } - - /************************************************ - * MODES - ************************************************/ - - /** - * Test default mode - */ - public function testGetDefaultMode() { - $s = new Slim(); - $this->assertEquals('development', $s->getMode()); - } - - /** - * Test custom mode from environment - */ - public function testGetModeFromEnvironment() { - $_ENV['SLIM_MODE'] = 'production'; - $s = new Slim(); - $this->assertEquals('production', $s->getMode()); - } - - /** - * Test custom mode from app settings - */ - public function testGetModeFromSettings() { - $s = new 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(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(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(array('mode' => 'production')); - $s->configureMode('production', 'foo'); - $this->assertEquals(0, $flag); - } - - /************************************************ - * ROUTING - ************************************************/ - - /** - * Test GENERIC route - */ - public function testGenericRoute() { - $s = new Slim(); - $callable = function () { echo "foo"; }; - $route = $s->map('/bar', $callable); - $this->assertInstanceOf('Slim_Route', $route); - $this->assertEmpty($route->getHttpMethods()); - } - - /** - * Test GET route - */ - public function testGetRoute() { - $s = new 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(); - $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(); - $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 DELETE route - */ - public function testDeleteRoute() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'DELETE', - 'SCRIPT_NAME' => '/foo', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - )); - $s = new 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(); - $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 if route expects trailing slash and URL does not have one - */ - public function testRouteWithSlashAndUrlWithout() { - Slim_Environment::mock(array( - 'SCRIPT_NAME' => '/foo', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - )); - $s = new Slim(); - $s->get('/bar/', function () { echo "xyz"; }); - $s->call(); - $this->assertEquals(301, $s->response()->status()); - } - - /** - * Test 405 Method Not Allowed - */ - public function testMethodNotAllowed() { - Slim_Environment::mock(array( - 'REQUEST_METHOD' => 'POST', - 'SCRIPT_NAME' => '/foo', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - )); - $s = new Slim(); - $s->get('/bar', function () { echo "xyz"; }); - $s->call(); - $this->assertEquals(405, $s->response()->status()); - } - - /** - * 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(); - $s->get('/bar', function () { echo "xyz"; }); - $s->call(); - $this->assertEquals(404, $s->response()->status()); - } - - /** - * 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(); - $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(); - $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(); - $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(); - $s->view()->setData($data); - $s->view('CustomView'); - $this->assertSame($data, $s->view()->getData()); - } - - /************************************************ - * RENDERING - ************************************************/ - - /** - * Test render with template and data - */ - public function testRenderTemplateWithData() { - $s = new 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(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(); - $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 - 'IF_MODIFIED_SINCE' => 'Sun, 03 Oct 2010 17:00:52 -0400', - )); - $s = new 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 17:00:52 -0400', - )); - $s = new 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(); - $s->get('/bar', function () use ($s) { - $s->lastModified('Test'); - }); - $s->call(); - } - - /** - * Test ETag matches - */ - public function testEtagMatches() { - Slim_Environment::mock(array( - 'SCRIPT_NAME' => '/foo', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - 'IF_NONE_MATCH' => '"abc123"', - )); - $s = new 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(); - $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(); - $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 - )); - $expectedDate = gmdate('D, d M Y', strtotime('5 days')); //Just the day, month, and year - $s = new 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(0, strpos($header['Expires'], $expectedDate)); - } - - /** - * 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', $fiveDaysFromNow); //Just the day, month, and year - $s = new 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(0, strpos($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(); - $s->get('/bar', function () use ($s) { - $s->setCookie('foo', 'bar', '2 days'); - $s->setCookie('foo1', 'bar1', '2 days'); - }); - $s->call(); - list($status, $header, $body) = $s->response()->finalize(); - $cookies = explode("\n", $header['Set-Cookie']); - $this->assertEquals(2, count($cookies)); - $this->assertEquals(1, preg_match('@foo=bar@', $cookies[0])); - $this->assertEquals(1, preg_match('@foo1=bar1@', $cookies[1])); - } - - /** - * 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, - 'COOKIE' => 'foo=bar; foo2=bar2', - 'slim.url_scheme' => 'http', - 'slim.input' => '', - 'slim.errors' => @fopen('php://stderr', 'w') - )); - $s = new 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(); - $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(); - $s->get('/bar', function () use ($s) { - $s->setCookie('foo', 'bar'); - $s->deleteCookie('foo'); - }); - $s->call(); - list($status, $header, $body) = $s->response()->finalize(); - $cookies = explode("\n", $header['Set-Cookie']); - $this->assertEquals(1, count($cookies)); - $this->assertEquals(1, preg_match('@^foo=;@', $cookies[0])); - } - - /** - * Test set encrypted cookie - * - * This method ensures that the `Set-Cookie:` HTTP request - * header is set. The implementation is tested in a separate file. - */ - public function testSetEncryptedCookie() { - $s = new Slim(); - $s->setEncryptedCookie('foo', 'bar'); - $r = $s->response(); - $this->assertEquals(1, preg_match("@^foo=.+%7C.+%7C.+@", $r['Set-Cookie'])); //<-- %7C is a url-encoded pipe - } - - /** - * Test get encrypted cookie - * - * This only tests that this method runs without error. The implementation of - * fetching the encrypted cookie is tested separately. - */ - public function testGetEncryptedCookieAndDeletingIt() { - Slim_Environment::mock(array( - 'SCRIPT_NAME' => '/foo', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - )); - $s = new Slim(); - $r = $s->response(); - $this->assertFalse($s->getEncryptedCookie('foo')); - $this->assertEquals(1, preg_match("@foo=;.*@", $r['Set-Cookie'])); - } - - /** - * Test get encrypted cookie WITHOUT deleting it - * - * This only tests that this method runs without error. The implementation of - * fetching the encrypted cookie is tested separately. - */ - public function testGetEncryptedCookieWithoutDeletingIt() { - Slim_Environment::mock(array( - 'SCRIPT_NAME' => '/foo', //<-- Physical - 'PATH_INFO' => '/bar', //<-- Virtual - )); - $s = new Slim(); - $r = $s->response(); - $this->assertFalse($s->getEncryptedCookie('foo', false)); - $this->assertEquals(0, preg_match("@foo=;.*@", $r['Set-Cookie'])); - } - - /************************************************ - * HELPERS - ************************************************/ - - /** - * Test get filesystem path to Slim app root directory - */ - public function testGetRoot() { - $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__); //<-- No trailing slash - $s = new 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(); - $s->stop(); - } - - /** - * Test stop with subsequent output - */ - public function testStopWithSubsequentOutput() { - $this->expectOutputString('Foo'); - $s = new 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 halt - */ - public function testHalt() { - $s = new 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 pass cleans buffer and throws exception - */ - public function testPass() { - ob_start(); - $s = new 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(); - $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(); - $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(); - $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(); - $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(); - $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(); - $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('/somewhere/else', $body); - } - - /************************************************ - * RUNNER - ************************************************/ - - /** - * Test that runner sends headers and body - */ - public function testRun() { - $this->expectOutputString('Foo'); - $s = new Slim(); - $s->get('/bar', function () use ($s) { - echo "Foo"; - }); - $s->run(); - } - - /************************************************ - * 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(); - $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')); - } - - /************************************************ - * FLASH MESSAGING - ************************************************/ - - public function testSetFlashForNextRequest() { - $s = new 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(); - $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(); - $s->get('/bar', function () use ($s) { - $s->flashKeep(); - }); - $s->run(); - $this->assertEquals('Foo', $_SESSION['slim.flash']['info']); - } - - /************************************************ - * NOT FOUND HANDLING - ************************************************/ - - /** - * Test custom Not Found handler - */ - public function testNotFound() { - $s = new 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(); - $s->get('/bar', function () use ($s) { - $s->error(); - }); - $s->call(); - $this->assertEquals(500, $s->response()->status()); - } - - /** - * 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 testTriggeredErrorsAreConvertedToErrorExceptions() { - $s = new 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(array( - 'debug' => false - )); - $s2 = new Slim(); - $s1->get('/bar', function () { - trigger_error('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(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']); - } - - /************************************************ - * 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(); - $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(); - $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(); - $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(); - $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 hook filter behavior - */ - public function testHookFilterBehavior() { - $app = new Slim(); - $app->hook('test.hook', function ($arg) { return $arg . 'foo'; }); - $this->assertEquals('barfoo', $app->applyHook('test.hook', 'bar')); - } -} diff --git a/Slim/codeguy-Slim-aa7e919/tests/ViewTest.php b/Slim/codeguy-Slim-aa7e919/tests/ViewTest.php deleted file mode 100644 index c80c886..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/ViewTest.php +++ /dev/null @@ -1,180 +0,0 @@ - - * @copyright 2011 Josh Lockhart - * @link http://www.slimframework.com - * @license http://www.slimframework.com/license - * @version 1.5.2 - * - * 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. - */ - -set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path()); - -require_once 'Slim/View.php'; - -class ViewTest extends PHPUnit_Framework_TestCase { - - public function setUp() { - $this->view = new Slim_View(); - } - - public function generateTestData() { - return array('a' => 1, 'b' => 2, 'c' => 3); - } - - /** - * Test initial View data is an empty array - * - * Pre-conditions: - * None - * - * Post-conditions: - * The View object's data attribute is an empty array - */ - public function testViewIsConstructedWithDataArray() { - $this->assertEquals(array(), $this->view->getData()); - } - - /** - * Test View sets and gets data - * - * Pre-conditions: - * Case A: Set view data key/value - * Case B: Set view data as array - * Case C: Set view data with one argument that is not an array - * - * Post-conditions: - * Case A: Data key/value are set - * Case B: Data is set to array - * Case C: An InvalidArgumentException is thrown - */ - public function testViewSetAndGetData() { - //Case A - $this->view->setData('one', 1); - $this->assertEquals(1, $this->view->getData('one')); - - //Case B - $data = array('foo' => 'bar', 'a' => 'A'); - $this->view->setData($data); - $this->assertSame($data, $this->view->getData()); - - //Case C - try { - $this->view->setData('foo'); - $this->fail('Setting View data with non-array single argument did not throw exception'); - } catch ( InvalidArgumentException $e ) {} - } - - /** - * Test View appends data - * - * Pre-conditions: - * Append data to View several times - * - * Post-conditions: - * The View data contains all appended data - */ - public function testViewAppendsData(){ - $this->view->appendData(array('a' => 'A')); - $this->view->appendData(array('b' => 'B')); - $this->assertEquals(array('a' => 'A', 'b' => 'B'), $this->view->getData()); - } - - /** - * Test View templates directory - * - * Pre-conditions: - * View templates directory is set to an existing directory - * - * Post-conditions: - * The templates directory is set correctly. - */ - public function testSetsTemplatesDirectory() { - $templatesDirectory = dirname(__FILE__) . '/templates'; - $this->view->setTemplatesDirectory($templatesDirectory); - $this->assertEquals($templatesDirectory, $this->view->getTemplatesDirectory()); - } - - /** - * Test View templates directory may have a trailing slash when set - * - * Pre-conditions: - * View templates directory is set to an existing directory with a trailing slash - * - * Post-conditions: - * The View templates directory is set correctly without a trailing slash - */ - public function testTemplatesDirectoryWithTrailingSlash() { - $this->view->setTemplatesDirectory(dirname(__FILE__) . '/templates/'); - $this->assertEquals(dirname(__FILE__) . '/templates', $this->view->getTemplatesDirectory()); - } - - /** - * Test View renders template - * - * Pre-conditions: - * View templates directory is set to an existing directory. - * View data is set without errors - * Case A: View renders an existing template - * Case B: View renders a non-existing template - * - * Post-conditions: - * Case A: The rendered template is returned as a string - * Case B: A RuntimeException is thrown - */ - public function testRendersTemplateWithData() { - $this->view->setTemplatesDirectory(dirname(__FILE__) . '/templates'); - $this->view->setData(array('foo' => 'bar')); - - //Case A - $output = $this->view->render('test.php'); - $this->assertEquals('test output bar', $output); - - //Case B - try { - $output = $this->view->render('foo.php'); - $this->fail('Rendering non-existent template did not throw exception'); - } catch ( RuntimeException $e ) {} - } - - /** - * Test View displays template - * - * Pre-conditions: - * View templates directory is set to an existing directory. - * View data is set without errors - * View is displayed - * - * Post-conditions: - * The output buffer contains the rendered template - */ - public function testDisplaysTemplateWithData() { - $this->expectOutputString('test output bar'); - $this->view->setTemplatesDirectory(dirname(__FILE__) . '/templates'); - $this->view->setData(array('foo' => 'bar')); - $this->view->display('test.php'); - } - -} diff --git a/Slim/codeguy-Slim-aa7e919/tests/templates/test.php b/Slim/codeguy-Slim-aa7e919/tests/templates/test.php deleted file mode 100644 index 2bdcdf8..0000000 --- a/Slim/codeguy-Slim-aa7e919/tests/templates/test.php +++ /dev/null @@ -1 +0,0 @@ -test output \ No newline at end of file diff --git a/index.php b/index.php index 3cd5432..db57fcf 100644 --- a/index.php +++ b/index.php @@ -13,12 +13,12 @@ )); //GET route -$app->get('/index', function ($name) { +$app->get('/index', function () { echo "Hello you've reached SlimJim!"; }); //POST route -$app->post('/deploy/:payload', function () { +$app->post('/deploy/:payload', function ($payload) { echo $payload //$app->response()->status(400); });