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
FROM php:7.4-fpm | |
# Install dependencies | |
RUN apt-get update && apt-get install -y \ | |
zlib1g-dev \ | |
libxml2-dev \ | |
libzip-dev \ | |
libonig-dev \ | |
unzip |
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
// Now the data you'll be working with will ALWAYS be an array, so you can plan for that. | |
// You still needed the conditional (a ternary in this case), but you've pushed it to the top of your code | |
// allowing all subsequent code to work with it in a more uniform way. | |
const normalizedData = Array.isArray(data) ? data : [data]; | |
const transformedData = normalizedData.map(myTransformerFunction); |
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 | |
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 |
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 | |
// 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 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 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 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 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 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 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); | |
} |
NewerOlder