Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.x'
Browse files Browse the repository at this point in the history
* upstream/2.x: (33 commits)
  Updated version number references for upcoming Slim 2.6.3
  Clean up the output buffon on error in debug mode
  Updated version number references for Slim 2
  Updated the other code snippets as well
  Added color to the Readme
  Update How to Contribute section of README
  fixed broken license link
  Update SessionCookie unit tests for new JSON decoding
  Fix the build indicator.
  escape html code in exception page
  update version number in tests folder
  update version numbers
  Fix slimphp#1034 (CVE-2015-2171)
  Correct terminology in README
  travis: PHP 7.0 nightly added
  Fixes slimphp#962, Missing SERVER_PORT on GAE.
  Add HTTP status codes from new RFCs.
  Update index.php to fix broken "Hello World" link
  Fix: Method doesn't return anything
  Fix: Undefined classes
  ...
  • Loading branch information
Jacob Christiansen committed Sep 7, 2015
2 parents e1c5570 + faf8306 commit 5a47657
Show file tree
Hide file tree
Showing 44 changed files with 280 additions and 211 deletions.
3 changes: 2 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ RewriteEngine On
#
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule ^ index.php [QSA,L]
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

script: phpunit --coverage-text
174 changes: 89 additions & 85 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Slim Framework

[![Build Status](https://secure.travis-ci.org/codeguy/Slim.png?branch=master)](http://travis-ci.org/codeguy/Slim)
[![Build Status](https://travis-ci.org/slimphp/Slim.svg?branch=master)](https://travis-ci.org/slimphp/Slim)

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
Slim is easy to use for both beginners and professionals. Slim favors cleanliness over terseness and common cases
Expand All @@ -17,7 +17,7 @@ Thank you for choosing the Slim Framework for your next project. I think you're
* Resource Locator and DI container
* Template rendering with custom views
* Flash messages
* Secure cookies with AES-256 encryption
* Encrypt cookie data
* HTTP caching
* Logging with custom log writers
* Error handling and debugging
Expand All @@ -39,130 +39,134 @@ You need **PHP >= 5.3.0**. If you use encrypted cookies, you'll also need the `m
### Hello World Tutorial

Instantiate a Slim application:

$app = new \Slim\Slim();

```php
$app = new \Slim\Slim();
```
Define a HTTP GET route:

$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});

```php
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
```
Run the Slim application:

$app->run();

```php
$app->run();
```
### Setup your web server

#### Apache

Ensure the `.htaccess` and `index.php` files are in the same public-accessible directory. The `.htaccess` file
should contain this code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
```
Additionally, make sure your virtual host is configured with the AllowOverride option so that the .htaccess rewrite rules can be used:

AllowOverride All

```
AllowOverride All
```
#### Nginx

The nginx configuration file should contain this code (along with other settings you may need) in your `location` block:

try_files $uri $uri/ /index.php?$args;

```
try_files $uri $uri/ /index.php?$args;
```
This assumes that Slim's `index.php` is in the root folder of your project (www root).

#### HipHop Virtual Machine for PHP

Your HipHop Virtual Machine configuration file should contain this code (along with other settings you may need).
Be sure you change the `ServerRoot` setting to point to your Slim app's document root directory.

Server {
SourceRoot = /path/to/public/directory
}

ServerVariables {
SCRIPT_NAME = /index.php
}

VirtualHost {
* {
Pattern = .*
RewriteRules {
* {
pattern = ^(.*)$
to = index.php/$1
qsa = true
}
}
```
Server {
SourceRoot = /path/to/public/directory
}
ServerVariables {
SCRIPT_NAME = /index.php
}
VirtualHost {
* {
Pattern = .*
RewriteRules {
* {
pattern = ^(.*)$
to = index.php/$1
qsa = true
}
}
}

}
```
#### lighttpd ####

Your lighttpd configuration file should contain this code (along with other settings you may need). This code requires
lighttpd >= 1.4.24.

url.rewrite-if-not-file = ("(.*)" => "/index.php/$0")

```
url.rewrite-if-not-file = ("(.*)" => "/index.php/$0")
```
This assumes that Slim's `index.php` is in the root folder of your project (www root).

#### IIS

Ensure the `Web.config` and `index.php` files are in the same public-accessible directory. The `Web.config` file should contain this code:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
```
#### Google App Engine

Two steps are required to successfully run your Slim application on Google App Engine. First, ensure the `app.yaml` file includes a default handler to `index.php`:

application: your-app-name
version: 1
runtime: php
api_version: 1
handlers:
# ...
- url: /.*
script: public_html/index.php

```
application: your-app-name
version: 1
runtime: php
api_version: 1
handlers:
# ...
- url: /.*
script: public_html/index.php
```
Next, edit your `index.php` file so Slim knows about the incoming URI:
```php
$app = new Slim();

$app = new Slim();

// Google App Engine doesn't set $_SERVER['PATH_INFO']
$app->environment['PATH_INFO'] = $_SERVER['REQUEST_URI'];

// ...
$app->run();
// Google App Engine doesn't set $_SERVER['PATH_INFO']
$app->environment['PATH_INFO'] = $_SERVER['REQUEST_URI'];

// ...
$app->run();
```

## Documentation

<http://docs.slimframework.com/>

## How to Contribute


*NOTE: We are only accepting security fixes for Slim 2 (master branch). All development is concentrated on Slim 3 which is on the develop branch.*


### Pull Requests

1. Fork the Slim Framework repository
Expand Down Expand Up @@ -205,4 +209,4 @@ PHP programmers to best practices and good information.

The Slim Framework is released under the MIT public license.

<http://www.slimframework.com/license>
<https://github.com/slimphp/Slim/blob/master/LICENSE>
14 changes: 9 additions & 5 deletions Slim/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -140,7 +140,10 @@ private function __construct($settings = null)
$env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes

// Virtual path
$env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path
$env['PATH_INFO'] = $requestUri;
if (substr($requestUri, 0, strlen($physicalPath)) == $physicalPath) {
$env['PATH_INFO'] = substr($requestUri, strlen($physicalPath)); // <-- Remove physical path
}
$env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash

Expand All @@ -151,7 +154,8 @@ private function __construct($settings = null)
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];

//Number of server port that is running the script
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
//Fixes: https://github.com/slimphp/Slim/issues/962
$env['SERVER_PORT'] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;

//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
$headers = \Slim\Http\Headers::extract($_SERVER);
Expand Down Expand Up @@ -191,9 +195,9 @@ public function offsetGet($offset)
{
if (isset($this->properties[$offset])) {
return $this->properties[$offset];
} else {
return null;
}

return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Slim/Exception/Pass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Exception/Stop.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down
12 changes: 6 additions & 6 deletions Slim/Helper/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -160,7 +160,7 @@ public function __isset($key)

public function __unset($key)
{
return $this->remove($key);
$this->remove($key);
}

/**
Expand Down Expand Up @@ -215,8 +215,8 @@ public function getIterator()

/**
* Ensure a value or object will remain globally unique
* @param string $key The value or object name
* @param Closure The closure that defines the object
* @param string $key The value or object name
* @param \Closure $value The closure that defines the object
* @return mixed
*/
public function singleton($key, $value)
Expand All @@ -234,8 +234,8 @@ public function singleton($key, $value)

/**
* Protect closure from being directly invoked
* @param Closure $callable A closure to keep from being invoked and evaluated
* @return Closure
* @param \Closure $callable A closure to keep from being invoked and evaluated
* @return \Closure
*/
public function protect(\Closure $callable)
{
Expand Down
2 changes: 1 addition & 1 deletion Slim/Http/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Http/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down
6 changes: 3 additions & 3 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.4.2
* @version 2.6.3
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -169,9 +169,9 @@ public function isAjax()
return true;
} elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') {
return true;
} else {
return false;
}

return false;
}

/**
Expand Down
Loading

0 comments on commit 5a47657

Please sign in to comment.