You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rack'em likes [Composer](http://getcomposer.org/), go ahead and install it if it isn't already.
22
+
## Features
25
23
26
-
I like to install Rack'em globally so that I can use it in any project. Unfortunately, Composer does not have a way of doing this by default, so here is an easy way to allow global package installation:
24
+
* Tiny
25
+
* Provides a common interface for applications
26
+
* Environment values are consistent regardless of web server
27
+
* Run applications locally without other dependencies
27
28
28
-
### Setting up Composer for global installtion
29
+
##Getting Started
29
30
30
-
```bash
31
-
$ curl https://raw.github.com/gist/4242494/5d6344d2976e07d051ace18d41fa035113353e90/global_composer.sh | sh
32
-
```
31
+
Rack'em likes [Composer](http://getcomposer.org/), go ahead and install it if it isn't already.
33
32
34
33
### Installing Rack'em
35
34
36
-
If you are using the global installtion method from above, you can easily do:
Otherwise, you need to add `rackem/rackem` to your project's composer.json:
43
-
44
-
```json
45
-
{
46
-
"require": {
47
-
"rackem/rackem": "*"
48
-
}
49
-
}
38
+
$ composer require rackem/rackem:@stable
50
39
```
51
40
52
-
There's also a shortcut to do this with Composer:
41
+
Installing globally is awesome:
53
42
54
43
```bash
55
-
$ composer require rackem/rackem:*
44
+
$ composer global require rackem/rackem:@stable
56
45
```
57
46
58
-
Optionally, there is a PSR autoloader you can use:
47
+
Optionally, download Rack'em and require rackem.php:
59
48
60
49
```php
61
50
<?php
@@ -64,7 +53,7 @@ require 'rackem/rackem.php';
64
53
65
54
## rackem
66
55
67
-
rackem is a tool for running Rack'em applications without the need for a web server. This makes developing Rack applications with PHP a breeze.
56
+
rackem is a HTTP server for running Rack'em applications. This makes developing PHP applications a breeze.
68
57
69
58
Provide rackem your main application script, and you are good to go:
70
59
@@ -77,9 +66,9 @@ $ rackem config.php
77
66
78
67
## Usage
79
68
80
-
Any object that has a callable method `call()` can be considered a Rack application. Rack expects call to return an HTTP response array containing: status code, headers, and body.
69
+
Anything that `is_callable()` or has an instance method `call()` can be considered an application. The application must return an HTTP response array containing: status code, headers, and body.
81
70
82
-
Here is an example of a basic Rackem application:
71
+
Here is an example of a basic Rack'em application:
83
72
84
73
```php
85
74
<?php
@@ -95,7 +84,7 @@ class App
95
84
return \Rackem::run("App");
96
85
```
97
86
98
-
`Rack::run()` accepts 1 of 3 things:
87
+
`Rackem::run()` accepts 1 of 3 things:
99
88
100
89
- String referencing a Class
101
90
- Class instance
@@ -113,18 +102,23 @@ return \Rackem::run($app);
113
102
114
103
## Middleware
115
104
116
-
Just like Rack, Rack'em supports the use of Middleware. Middleware is basically a Rack application that must be passed `$app` in its constructor, with an optional `$options` parameter. `$app` is an instance of the previous application in the Rack stack.
105
+
Fill your rack with middleware for ultimate awesomeness.
106
+
107
+
Middleware is basically an application that is passed the previous application in the stack and optionally an array of options in its constructor.
117
108
118
-
Here is an example of a Middleware class that just passes the response on:
109
+
The most basic middleware (hint: it doesn't do anything):
119
110
120
111
```php
121
112
<?php
122
113
123
114
class MyMiddleware
124
115
{
125
-
public function __construct($app)
116
+
public $app, $options;
117
+
118
+
public function __construct($app, $options = array())
126
119
{
127
120
$this->app = $app;
121
+
$this->options = $options;
128
122
}
129
123
130
124
public function call($env)
@@ -137,7 +131,7 @@ class MyMiddleware
137
131
return \Rackem::run( new App() );
138
132
```
139
133
140
-
There is also a Middleware helper class to make things a bit easier:
134
+
There is also of course a helper class to make things a bit easier:
141
135
142
136
```php
143
137
<?php
@@ -146,7 +140,8 @@ class MyMiddleware extends \Rackem\Middleware
146
140
{
147
141
public function call($env)
148
142
{
149
-
return $this->app->call($env);
143
+
// do stuff
144
+
return parent::call($env);
150
145
}
151
146
}
152
147
```
@@ -180,7 +175,7 @@ class JsonFormatter extends \Rackem\Middleware
180
175
$res = new \Rackem\Response($this->app->call($env));
0 commit comments