Skip to content

Instantly share code, notes, and snippets.

@geekish
Created May 17, 2017 17:38
Show Gist options
  • Save geekish/3a1cf866aec0a6ee1935007cbf915d78 to your computer and use it in GitHub Desktop.
Save geekish/3a1cf866aec0a6ee1935007cbf915d78 to your computer and use it in GitHub Desktop.
Slim invokable class as group callable example (PR #2229)
<?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();
<?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