Skip to content

Instantly share code, notes, and snippets.

@alexsoyes
Last active March 24, 2021 18:17
Show Gist options
  • Save alexsoyes/3c5de108ca10d51cbb62eaecb656f2e1 to your computer and use it in GitHub Desktop.
Save alexsoyes/3c5de108ca10d51cbb62eaecb656f2e1 to your computer and use it in GitHub Desktop.
Single Responsibility Principle in PHP
<?php
/**
* Single Responsibility Principle in PHP
*
* Each class should be stored in a folder called Services/User/*.
*/
// Located in Services/User/UserAuthenticatorService.php
class UserAuthenticatorService
{
public function isAllowedToAccessAdmin( User $user ): bool
{
// ...
}
}
// Located in Services/User/UserFormatterService.php
class UserFormatterService
{
public function serialize( User $user ): string
{
// ...
}
}
// Located in Services/User/UserSessionService.php
class UserSessionService
{
public function invalidate( User $user ): void
{
// ...
}
}
// Located in Services/User/UserUpdatorService.php
class UserUpdatorService
{
public function updateFromAPI( User $user): User
{
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment