Last active
March 24, 2021 18:17
-
-
Save alexsoyes/3c5de108ca10d51cbb62eaecb656f2e1 to your computer and use it in GitHub Desktop.
Single Responsibility Principle in PHP
This file contains hidden or 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 | |
/** | |
* 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