Skip to content

Commit 19b6384

Browse files
committed
Arrow functions
1 parent 60f8821 commit 19b6384

File tree

6 files changed

+12
-33
lines changed

6 files changed

+12
-33
lines changed

getting-started/events.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
$config = include __DIR__ . '/../config/config.php';
66

77
$config['events']['web'] = [
8-
function($model, $msg) {
9-
return $model . ' ' . $msg;
10-
},
11-
function($response, $model) {
12-
return $response->with('body', $model);
13-
},
8+
fn($model, $msg) => $model . ' ' . $msg,
9+
fn($response, $model) => $response->with('body', $model),
1410
function($response) {
1511
echo $response->body();
1612
}

getting-started/functional-programming.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ function web($request, $response) {
5252
<p>Its <a href="https://github.com/mvc5/mvc5/blob/master/config/service.php#L79">configuration</a> can also be an <a href="http://php.net/manual/en/functions.anonymous.php">anonymous function</a> that returns another <a href="http://php.net/manual/en/functions.anonymous.php">anonymous function</a> as the one to invoke.</p>
5353

5454
```php
55-
'web' => function() {
56-
return function($request, $response) {
55+
'web' => fn() => function($request, $response) {
5756
var_dump($request->path());
58-
};
59-
},
57+
}
6058
```
6159

6260
<p>However, a function can become large and separating it into a list of functions enables it to be extended with each function having their own individual dependencies. Consequently, the outcome of the function does not have to depend on the list of functions and by using an <a href="https://github.com/mvc5/mvc5/blob/master/src/Event/Event.php">event</a> class, the outcome of each function and the function itself can be controlled.</p>

getting-started/middleware.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ An alternative to using an [event](https://github.com/mvc5/mvc5/blob/master/src/
66
$config = include __DIR__ . '/../config/config.php';
77

88
$config['middleware']['web'] = [
9-
function($request, $response, $next) {
10-
return $next($request->with('controller', function() { return 'Hello!'; }), $response);
11-
},
12-
function($request, $response, $next) {
13-
return $next($request, $response->with('body', $request['controller']()));
14-
},
9+
fn($request, $response, $next) => $next($request->with('controller', fn() => 'Hello!'), $response),
10+
fn($request, $response, $next) => $next($request, $response->with('body', $request['controller']())),
1511
function($request, $response, $next) {
1612
echo $response->body();
1713
}

overview/events.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ function __invoke(callable $callable, array $args = [], callable $callback = nul
1414
For example, the <code>dashboard:remove</code> event uses three functions to create a model and to return a [layout](https://github.com/mvc5/mvc5/blob/master/src/ViewLayout.php) object. It does not have its own [event](https://github.com/mvc5/mvc5/blob/master/src/Event/Event.php) class, so an instance of the [default event model](https://github.com/mvc5/mvc5/blob/master/src/Event.php) is used.
1515
```php
1616
'dashboard:remove' => [
17-
function() {
18-
return $model = '<h1>Validate</h1>';
19-
},
20-
function($model) {
21-
return $model . '<h1>Remove</h1>';
22-
},
17+
fn() => $model = '<h1>Validate</h1>',
18+
fn($model) => $model . '<h1>Remove</h1>',
2319
function(TemplateLayout $layout, $model = null) {
2420
$model .= '<h1>Respond</h1>';
2521

overview/rest-api-methods.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Routes can be configured with [actions](https://github.com/mvc5/mvc5/blob/master
77
'controller' => 'Resource\Controller',
88
'csrf_token' => false,
99
'action' => [
10-
'POST' => function(Url $url) {
11-
return new Response\RedirectResponse($url(), 201);
12-
}
10+
'POST' => fn(Url $url) => new Response\RedirectResponse($url(), 201)
1311
]
1412
]
1513
```

overview/service-container.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@ $app = new App([
99
'services' => [
1010
'dashboard' => new Plugins(
1111
[
12-
'home' => function($template) {
13-
return function($view, $form) use($template) {
14-
return $this->call($view, [$template, $form + ['message' => 'Demo Page']]);
15-
};
16-
},
12+
'home' => fn($template) => fn($view, $form) =>
13+
$this->call($view, [$template, $form + ['message' => 'Demo Page']]),
1714
'template' => new Value('dashboard/index')
1815
],
1916
new Link, //reference to parent container
2017
true //use current container as the scope for anonymous functions
2118
),
22-
'view' => function() {
23-
return function($template, $var) {
19+
'view' => fn() => function($template, $var) {
2420
include $template;
25-
};
2621
},
2722
]
2823
]);

0 commit comments

Comments
 (0)