Skip to content

Commit

Permalink
Merge branch 'release-2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jul 14, 2013
2 parents b8181de + b7f45df commit 926865b
Show file tree
Hide file tree
Showing 43 changed files with 2,488 additions and 2,311 deletions.
24 changes: 23 additions & 1 deletion README.markdown
Expand Up @@ -66,7 +66,7 @@ should contain this code:

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

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

This assumes that Slim's `index.php` is in the root folder of your project (www root).

Expand All @@ -79,6 +79,28 @@ lighttpd >= 1.4.24.

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>

## Documentation

<http://docs.slimframework.com/>
Expand Down
36 changes: 21 additions & 15 deletions Slim/Environment.php
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.2.0
* @version 2.3.0
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -87,7 +87,7 @@ public static function getInstance($refresh = false)
*/
public static function mock($userSettings = array())
{
self::$environment = new self(array_merge(array(
$defaults = array(
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => '',
'PATH_INFO' => '',
Expand All @@ -102,7 +102,8 @@ public static function mock($userSettings = array())
'slim.url_scheme' => 'http',
'slim.input' => '',
'slim.errors' => @fopen('php://stderr', 'w')
), $userSettings));
);
self::$environment = new self(array_merge($defaults, $userSettings));

return self::$environment;
}
Expand Down Expand Up @@ -143,7 +144,7 @@ private function __construct($settings = null)
if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) {
$env['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME']; //Without URL rewrite
} else {
$env['SCRIPT_NAME'] = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']) ); //With URL rewrite
$env['SCRIPT_NAME'] = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])); //With URL rewrite
}
$env['PATH_INFO'] = substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($env['SCRIPT_NAME']));
if (strpos($env['PATH_INFO'], '?') !== false) {
Expand All @@ -161,29 +162,34 @@ private function __construct($settings = null)
//Number of server port that is running the script
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];

//HTTP request headers
$specialHeaders = array('CONTENT_TYPE', 'CONTENT_LENGTH', 'PHP_AUTH_USER', 'PHP_AUTH_PW', 'PHP_AUTH_DIGEST', 'AUTH_TYPE');
foreach ($_SERVER as $key => $value) {
$value = is_string($value) ? trim($value) : $value;
if (strpos($key, 'HTTP_') === 0) {
$env[substr($key, 5)] = $value;
} elseif (strpos($key, 'X_') === 0 || in_array($key, $specialHeaders)) {
$env[$key] = $value;
}
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
$headers = \Slim\Http\Headers::extract($_SERVER);
foreach ($headers as $key => $value) {
$env[$key] = $value;
}

// $specialHeaders = array('CONTENT_TYPE', 'CONTENT_LENGTH', 'PHP_AUTH_USER', 'PHP_AUTH_PW', 'PHP_AUTH_DIGEST', 'AUTH_TYPE');
// foreach ($_SERVER as $key => $value) {
// $value = is_string($value) ? trim($value) : $value;
// if (strpos($key, 'HTTP_') === 0) {
// $env[substr($key, 5)] = $value;
// } elseif (strpos($key, 'X_') === 0 || in_array($key, $specialHeaders)) {
// $env[$key] = $value;
// }
// }

//Is the application running under HTTPS or HTTP protocol?
$env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';

//Input stream (readable one time only; not available for mutipart/form-data requests)
//Input stream (readable one time only; not available for multipart/form-data requests)
$rawInput = @file_get_contents('php://input');
if (!$rawInput) {
$rawInput = '';
}
$env['slim.input'] = $rawInput;

//Error stream
$env['slim.errors'] = fopen('php://stderr', 'w');
$env['slim.errors'] = @fopen('php://stderr', 'w');

$this->properties = $env;
}
Expand Down
3 changes: 1 addition & 2 deletions Slim/Exception/Pass.php
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.2.0
* @version 2.3.0
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -46,5 +46,4 @@
*/
class Pass extends \Exception
{

}
3 changes: 1 addition & 2 deletions Slim/Exception/Stop.php
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.2.0
* @version 2.3.0
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -44,5 +44,4 @@
*/
class Stop extends \Exception
{

}
210 changes: 210 additions & 0 deletions Slim/Helper/Set.php
@@ -0,0 +1,210 @@
<?php
/**
* Slim - a micro PHP 5 framework
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.3.0
* @package Slim
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Slim\Helper;

class Set implements \ArrayAccess, \Countable, \IteratorAggregate
{
/**
* Key-value array of arbitrary data
* @var array
*/
protected $data = array();

/**
* Constructor
* @param array $items Pre-populate set with this key-value array
*/
public function __construct($items = array())
{
$this->replace($items);
}

/**
* Normalize data key
*
* Used to transform data key into the necessary
* key format for this set. Used in subclasses
* like \Slim\Http\Headers.
*
* @param string $key The data key
* @return mixed The transformed/normalized data key
*/
protected function normalizeKey($key)
{
return $key;
}

/**
* Set data key to value
* @param string $key The data key
* @param mixed $value The data value
*/
public function set($key, $value)
{
$this->data[$this->normalizeKey($key)] = $value;
}

/**
* Get data value with key
* @param string $key The data key
* @param mixed $default The value to return if data key does not exist
* @return mixed The data value, or the default value
*/
public function get($key, $default = null)
{
if ($this->has($key)) {
$isInvokable = is_object($this->data[$this->normalizeKey($key)]) && method_exists($this->data[$this->normalizeKey($key)], '__invoke');

return $isInvokable ? $this->data[$this->normalizeKey($key)]($this) : $this->data[$this->normalizeKey($key)];
}

return $default;
}

/**
* Add data to set
* @param array $items Key-value array of data to append to this set
*/
public function replace($items)
{
foreach ($items as $key => $value) {
$this->set($key, $value); // Ensure keys are normalized
}
}

/**
* Fetch set data
* @return array This set's key-value data array
*/
public function all()
{
return $this->data;
}

/**
* Fetch set data keys
* @return array This set's key-value data array keys
*/
public function keys()
{
return array_keys($this->data);
}

/**
* Does this set contain a key?
* @param string $key The data key
* @return boolean
*/
public function has($key)
{
return array_key_exists($this->normalizeKey($key), $this->data);
}

/**
* Remove value with key from this set
* @param string $key The data key
*/
public function remove($key)
{
unset($this->data[$this->normalizeKey($key)]);
}

/**
* Clear all values
*/
public function clear()
{
$this->data = array();
}

/**
* Array Access
*/

public function offsetExists($offset)
{
return $this->has($offset);
}

public function offsetGet($offset)
{
return $this->get($offset);
}

public function offsetSet($offset, $value)
{
$this->set($offset, $value);
}

public function offsetUnset($offset)
{
$this->remove($offset);
}

/**
* Countable
*/

public function count()
{
return count($this->data);
}

/**
* IteratorAggregate
*/

public function getIterator()
{
return new \ArrayIterator($this->data);
}

/**
* Ensure a value or object will remain globally unique
* @param string $key The value or object name
* @param Closure The closure that defines the object
* @return mixed
*/
public function singleton($key, $value)
{
$this->set($key, function ($c) use ($value) {
static $object;

if (null === $object) {
$object = $value($c);
}

return $object;
});
}
}

0 comments on commit 926865b

Please sign in to comment.