Created
May 17, 2017 17:38
-
-
Save geekish/3a1cf866aec0a6ee1935007cbf915d78 to your computer and use it in GitHub Desktop.
Slim invokable class as group callable example (PR #2229)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Example\MyGroup; | |
use Slim\App; | |
$app = new App; | |
// I'd use DI for this | |
$dependency = new SomeDependency; | |
$group = new MyGroup($dependency); | |
// Ideally the callable resolver could be used to resolve group callables too, and I'd just give the class name | |
$app->group("/example", $group); | |
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Example; | |
use Slim\App; | |
use SomeDependency; | |
class MyGroup | |
{ | |
public function __construct(SomeDependency $dependency) | |
{ | |
$this->dependency = $dependency; | |
} | |
public function __invoke(App $app) | |
{ | |
// register your routes here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment