Created
July 14, 2015 12:49
-
-
Save vasildakov-zz/d425f8b77ac8adda2d9f to your computer and use it in GitHub Desktop.
Specification Pattern
This file contains 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 | |
namespace App\Entity; | |
abstract class Entity | |
{ | |
public function getId() { | |
return $this->id; | |
} | |
} |
This file contains 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 | |
namespace App\Specification; | |
use App\Entity\Entity as AbstractEntity; | |
interface EntitySpecification extends Specification { | |
public function isSatisfiedBy(AbstractEntity $entity); | |
} |
This file contains 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 | |
namespace App\Specification; | |
interface Specification { | |
public function isSatisfiedBy($criteria); | |
} |
This file contains 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 | |
namespace App\Entity; | |
class User extends Entity { | |
} |
This file contains 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 | |
use App\Entity\User; | |
class UserIsAllowedToDoSomething implements EntitySpecification { | |
public function isSatisfiedBy(User $user) { | |
return $user->isAdmin(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment