Mw
latest
  • Usage
  • Avanced Usage
  • Cookbook
  • API
  • Troubleshooting
Mw
  • Docs »
  • Custom Link Class
  • Edit on GitHub

Custom Link ClassΒΆ

You can optionally provide your own Link to allow easier access to the Context or other methods. It’s best to extend the Mw\Link and just add methods and not data because the Link class logic is very critical to the design of the mw system.

<?php

use Krak\Mw;

class LoggingLink extends Mw\Link
{
    public function echoLog($info) {
        echo $info . PHP_EOL;
    }
    public function log() {
        return $this->getContext()->logger;
    }
}

$handler = mw\compose([
    function($i, $next) {
        $next->echoLog('hi');
        return 1;
    }
], null, null, LoggingLink::class);

assert($handler(0) == 1);

© Copyright 2016, RJ Garcia. Revision 5b61836f.

Built with Sphinx using a theme provided by Read the Docs.