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 | |
| interface MemberInterface | |
| { | |
| public function getID(); | |
| public function getLoginName(); | |
| public function getDisplayName(); | |
| public function getPostCount(); | |
| public function incrementPostCount(); | |
| public function decrementPostCount(); |
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 | |
| class Member extends Model implements MemberInterface | |
| { | |
| const ATTR_DISPLAY_NAME = ‘display_name’; | |
| const ATTR_LOGIN_NAME = ‘login_name’; | |
| const ATTR_POST_COUNT = ‘posts’; | |
| protected $fillable = [ | |
| self::ATTR_LOGIN_NAME, |
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 | |
| interface MemberRepositoryInterface | |
| { | |
| public function find($id); | |
| public function findTopPosters($count = 10); | |
| public function save(MemberInterface $member); | |
| } |
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 | |
| class EloquentMemberRepository implements MemberRepositoryInterface | |
| { | |
| /** | |
| * @var Member | |
| */ | |
| protected $model; | |
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 | |
| DemonstrationController | |
| { | |
| public function createPost(MemberRepositoryInterface $repository) | |
| { | |
| // validate request, create the post, and... | |
| $member = Auth::user()->member(); | |
| $member->incrementPostCount(); |
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 | |
| DemonstrationController | |
| { | |
| public function createPost() | |
| { | |
| // validate request, create the post, and... | |
| $member = Auth::user()->getMember(); | |
| $member->posts++; |
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 | |
| DemonstrationController | |
| { | |
| public function createPost() | |
| { | |
| // validate request, create the post, and... | |
| $member = Auth::user()->member(); | |
| $member->incrementPostCount(); |
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
| class Person { | |
| constructor(age) { | |
| this.age = age; | |
| } | |
| } | |
| let person = new Person(15); | |
| person.age = -33; | |
| // This lack of encapsulation and privacy is bad since it makes |
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 | |
| // in service provider | |
| public function boot() | |
| { | |
| // When the saving event fires on any model... | |
| Event::listen(['eloquent.saving: *'], function() { | |
| // Start listening for database queries... | |
| DB::listen(function($query) { | |
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 | |
| function makeSlug(Entity $entity) | |
| { | |
| return sprintf("%d-%s", $entity->getID(), str_slug($entity->getName())); | |
| } | |
| /* | |
| Entity with ID 3343 and name of "This Is An Article About Code" | |
| becomes 3343-this-is-an-article-about-code |