Skip to content

Instantly share code, notes, and snippets.

@tgalopin
Last active August 15, 2017 21:21
Show Gist options
  • Save tgalopin/46e2be955762d6d68360dd455afeab70 to your computer and use it in GitHub Desktop.
Save tgalopin/46e2be955762d6d68360dd455afeab70 to your computer and use it in GitHub Desktop.
<?php
class Foo implements ServiceSubscriberInterface
{
use ServiceSubscriberTrait;
public function do()
{
$this->getRouter();
}
private function getRouter(): RouterInterface
{
return $this->container->get(__FUNCTION__);
}
}
trait ServiceSubscriberTrait
{
private $container;
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}
public static function getSubscribedServices()
{
$r = new \ReflectionClass(static::class);
// detect methods, autowire and define services with functions names in the current service locator
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment