PHPackages                             markstory/cakephp-spekkoek - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. markstory/cakephp-spekkoek

Abandoned → No replacement as this code was built into cakephpArchivedCakephp-plugin[API Development](/categories/api)

markstory/cakephp-spekkoek
==========================

Prototype implementation of PSR7 middleware for CakePHP.

0.3.0(10y ago)141831MITPHPPHP &gt;=5.5.9

Since Mar 9Pushed 8y ago6 watchersCompare

[ Source](https://github.com/markstory/cakephp-spekkoek)[ Packagist](https://packagist.org/packages/markstory/cakephp-spekkoek)[ RSS](/packages/markstory-cakephp-spekkoek/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Spekkoek plugin for CakePHP
===========================

[](#spekkoek-plugin-for-cakephp)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![Build Status](https://camo.githubusercontent.com/0f3b911bf6d4a0d7a07f1eb2d131eabbc74263118dfd756b50af16e1e561d6fe/68747470733a2f2f7472617669732d63692e6f72672f6d61726b73746f72792f63616b657068702d7370656b6b6f656b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/markstory/cakephp-spekkoek)[![codecov.io](https://camo.githubusercontent.com/ba866259f0e0cc26ee6bbb428e8fbd93d5f9708135308fff2e8e556da650432c/68747470733a2f2f636f6465636f762e696f2f6769746875622f6d61726b73746f72792f63616b657068702d7370656b6b6f656b2f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/markstory/cakephp-spekkoek?branch=master)

This plugin is a prototype for adding PSR7 middleware &amp; request/response object support to CakePHP. It should be considered experimental.

Concepts
--------

[](#concepts)

Spekkoek aims to provide PSR7 middleware for a CakePHP 3.x application. It adds a few new concepts to a CakePHP application that extend and enhance the existing abstractions.

- `Spekkoek\Application` The Application object provides an object oriented approach to bootstrapping. This class is used to load bootstrapping and application configuration. It also provides hook methods for configuring middleware.
- `Spekkoek\MiddlewareStack` A MiddlewareStack provides an interface for building and manipulating the stack of middleware. The `Application` is also a middleware object that helps encapsulate the existing CakePHP dispatch process.
- `Spekkoek\Server` Is the entry point for a request/response. It consumes an application, and returns a response. The server's emit() method can be used to emit a response to the webserver SAPI.

There are PSR7 middleware versions of all the CakePHP core DispatchFilters. These are intended to be long term replacements for the CakePHP dispatch filters.

Middleware
----------

[](#middleware)

Middleware is a closure or callable object that accepts a request/response and returns a response. Each middleware is also provided the next callable in the chain. This callable should be invoked if/when you want to delegate the response creation to the next middleware object. Middleware objects need to implement the following protocol:

```
public function __invoke($request, $response, $next)
```

Middleware objects *must* return a Response object. They can either augment the existing response object or create a new one, or delegate to the next middleware object by calling `$next`. A trivial example of middleware would be:

```
use Cake\Log\Log;
class TimingMiddleware
{
    public function __invoke($request, $response, $next)
    {
        $start = microtime(true);
        $response = $next($request, $response);
        $end = microtime(true);
        Log::info(sprintf(
            'Request to %s took %f seconds',
            $request->getUri()->getPath(),
            ($end - $start)
        ));
        return $response;
    }
}
```

Here we can see the `$next` object in action and also how to put some simple logic before and after the lower layers.

Usage
-----

[](#usage)

This plugin fundamentally reworks your application's bootstrap process. It requires replacing your `webroot/index.php` and implementing an `Application` class.

Installation &amp; Getting Started
----------------------------------

[](#installation--getting-started)

Unlike many other plugins, Spekkoek requires a more setup. Because it needs to augment how bootstrapping, requests and responses are handled you'll need to modify your `webroot/index.php`

Install the plugin with `composer`:

```
composer require "markstory/cakephp-spekkoek:dev-master"

```

Next update your `webroot/index.php` to update

### Build the Application class

[](#build-the-application-class)

In your application's `src` directory create `src/Application.php` and put the following in it:

```
