Skip to content

Commit

Permalink
Merge pull request #4 from krakphp/3-utilize-krak-invoke
Browse files Browse the repository at this point in the history
Utilize Krak Invoke #3

Closes #3
  • Loading branch information
ragboyjr committed Apr 30, 2017
2 parents fabf316 + 18bcc8d commit bd58ce6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
36 changes: 22 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Change Log

All notable changes to this project will be documented in this file.
## Unreleased

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

## [Unreleased]
- Invoke Library #3

## [0.5.1] - 2017-03-31
## 0.5.1 - 2017-03-31

### Added

Expand All @@ -19,7 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Bug in Stack where unshifting would mess up the stored index values for named entries.
- Bug where removed named entries wouldn't fully be deleted.

## [0.5.0] - 2017-03-11
## 0.5.0 - 2017-03-11

### Added

- `composer` func which creates composer functions that accept an array of middleware
Expand All @@ -33,18 +33,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Moved `MwStack` to simply `Stack` and simplified the API
- Removed Pimple integration in favor for the PSR container.

## [0.4.2] - 2017-01-19
## 0.4.2 - 2017-01-19

### Added

- Added `withName` func to MwStack
- Made the `$name` parameter optional in the MwStack

## [0.4.1] - 2017-01-19
## 0.4.1 - 2017-01-19

### Added

- Added `withContext` and `withLinkClass` options to MwStack.

## [0.4.0] - 2017-01-04
## 0.4.0 - 2017-01-04

### Changed

- Made `splitArgs` a public function
Expand All @@ -60,13 +63,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
to middleware
- Added Context\\PimpleContext to provide better pimple integration

## [0.3.3] - 2017-01-03
## 0.3.3 - 2017-01-03

### Changed

- Update license year
- Reverted changes from 0.3.1 and 0.3.2 due to bc breaks

## [0.3.2] - 2016-12-26
## 0.3.2 - 2016-12-26

### Added

- Added the CHANGELOG.md
Expand All @@ -79,7 +84,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Several documentation pages to be more explicit
- Moved docs to doc

## [0.3.1] - 2016-12-19
## 0.3.1 - 2016-12-19

### Added

- Added Custom Invocation into the mw system
Expand All @@ -91,7 +97,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Updated the typehinting to be more forgiving to allow for Custom Invocation

## [0.3.0] - 2016-11-27
## 0.3.0 - 2016-11-27

### Changed

- Better Error Handling
Expand All @@ -100,7 +107,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Improvements to before/after
- More verbose function arguments

## [0.2.0] - 2016-11-23
## 0.2.0 - 2016-11-23

### Changed

- Removed all http related information
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=5.6",
"krak/invoke": "^0.1.0"
},
"require-dev": {
"krak/cargo": "^0.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/Context/ContainerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Krak\Mw\Context;

use Psr\Container\ContainerInterface,
Krak\Mw;
use Psr\Container\ContainerInterface;
use Krak\Mw;
use Krak\Invoke;

class ContainerContext implements Mw\Context
{
Expand All @@ -12,7 +13,7 @@ class ContainerContext implements Mw\Context

public function __construct(ContainerInterface $container, $invoke = null) {
$this->container = $container;
$this->invoke = $invoke ?: Mw\containerAwareInvoke($container);
$this->invoke = $invoke ?: Invoke\ContainerInvoke::create($container);
}

public function getInvoke() {
Expand Down
5 changes: 3 additions & 2 deletions src/Context/StdContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Krak\Mw\Context;

use Krak\Mw\Context;
use Krak\Invoke;

class StdContext implements Context
{
private $invoke;

public function __construct($invoke = 'call_user_func') {
$this->invoke = $invoke;
public function __construct($invoke = null) {
$this->invoke = $invoke ?: new Invoke\CallableInvoke();
}

public function getInvoke() {
Expand Down
6 changes: 5 additions & 1 deletion src/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Krak\Mw;

use Krak\Invoke;

/** Represents a link in the middleware chain. A link instance is passed to every middleware
as the last parameter which allows the next middleware to be called */
class Link
Expand All @@ -23,7 +25,9 @@ public function __invoke(...$params) {
$mw = $this->mw;
$invoke = $this->ctx->getInvoke();
$params[] = $this->next;
return $invoke($mw, ...$params);
return $invoke instanceof Invoke\Invoke
? $invoke->invoke($mw, ...$params)
: $invoke($mw, ...$params);
}

/** Chains a middleware to the current link */
Expand Down
4 changes: 3 additions & 1 deletion src/mw.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ function guard($msg) {
};
}

/** invokes a middleware checking if the mw is a service defined in a PSR Container */
/** @deprecated Use Krak\Invoke instead
invokes a middleware checking if the mw is a service defined in a PSR Container */
function containerAwareInvoke(ContainerInterface $c, $invoke = 'call_user_func') {
return function($func, ...$params) use ($c, $invoke) {
if (is_string($func) && $c->has($func)) {
Expand All @@ -179,6 +180,7 @@ function containerAwareInvoke(ContainerInterface $c, $invoke = 'call_user_func')
};
}

/** @deprecated Use Krak\Invoke instead */
function methodInvoke($method, $allow_callable = true, $invoke = 'call_user_func') {
return function($func, ...$params) use ($method, $invoke, $allow_callable) {
if (is_object($func) && method_exists($func, $method)) {
Expand Down

0 comments on commit bd58ce6

Please sign in to comment.