Skip to content

Instantly share code, notes, and snippets.

@vasildakov-zz
Created July 14, 2015 12:49
Show Gist options
  • Save vasildakov-zz/d425f8b77ac8adda2d9f to your computer and use it in GitHub Desktop.
Save vasildakov-zz/d425f8b77ac8adda2d9f to your computer and use it in GitHub Desktop.
Specification Pattern
<?php
namespace App\Entity;
abstract class Entity
{
public function getId() {
return $this->id;
}
}
<?php
namespace App\Specification;
use App\Entity\Entity as AbstractEntity;
interface EntitySpecification extends Specification {
public function isSatisfiedBy(AbstractEntity $entity);
}
<?php
namespace App\Specification;
interface Specification {
public function isSatisfiedBy($criteria);
}
<?php
namespace App\Entity;
class User extends Entity {
}
<?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