Skip to content

Instantly share code, notes, and snippets.

@thiagocordeiro
Last active August 25, 2020 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagocordeiro/e754ea346431435936dbd480d5a4cd90 to your computer and use it in GitHub Desktop.
Save thiagocordeiro/e754ea346431435936dbd480d5a4cd90 to your computer and use it in GitHub Desktop.
<?php
class BaseController
{
public function __contruct(Foo $foo)
{
$this->foo = $foo;
}
}
class UserController extends BaseController
{
public function __contruct(Foo $foo, Bar $bar)
{
$this->bar = $bar;
$this->user = $this->loadFromSession();
parent::__construct($foo);
}
protected function loadFromSession(): User { ... }
protected function hasPermissionTo(string $action): bool { ... }
}
class ScheduleAppointmentController extends UserController
{
public function __contruct(AppointmentService $service, Foo $foo, Bar $bar)
{
$this->service = $service;
parent::__construct($foo, $bar);
}
public function __invoke(): Response
{
if (false === $this->hasPermissionTo(self::class)) {
throw new HttpException(Response::HTTP_FORBIDDEN);
}
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment