David Flores
#Linux #Drupal #Symfony #WebDeveloper #Silex #OpenSource
The Right Way
David Flores
Co-Mantainer at @DrupalConsole, Linux, Drupal, Symfony, Silex, BackEnd, Seguridad, Python, Open Source, Future Father ...sometimes #Nerd Speaker
david@indava.com
@dmouse
http://bit.ly/php-single-responsability-principle
https://www.destroyallsoftware.com/talks/wat
Robert C. Martin
So a responsibility is a family of functions that serves one particular actor. (Robert C. Martin)
<?php
namespace Catedral;
class Plomero implements PloneroInterface {
public function __construct();
public function reparaCalentador();
public function instalaCalentador();
}
An actor for a responsibility is the single source of change for that responsibility. (Robert C. Martin)
<?php
namespace Catedral;
class Plomero implements PloneroInterface {
public function __construct();
public function reparaCalentador();
public function instalaCalentador();
public function instalaLavabo();
}
<?php
namespace Blog;
class Image
{
public function upload(Request $request) {
foreach($request->files as $uploadedFile) {
$name = $uploadedFile->getName();
$file = $uploadedFile->move($directory, $name);
}
}
}
Feature 1
<?php
namespace Blog;
class Image
{
public function upload(Request $request) {
foreach($request->files as $uploadedFile) {
$name = $uploadedFile->getName();
$file = $uploadedFile->move($directory, $name);
}
}
$this->sendEmail($file);
}
Feature 2
<?php
namespace Blog;
class Image
{
public function upload(Request $request) {
foreach($request->files as $uploadedFile) {
$name = $uploadedFile->getName();
$file = $uploadedFile->move($directory, $name);
}
}
$this->sendEmail($file);
$this->sendTweet($file);
}
Feature 3
<?php
namespace Blog;
class Image
{
public function upload(Request $request) {
foreach($request->files as $uploadedFile) {
$name = $uploadedFile->getName();
$file = $uploadedFile->move($directory, $name);
}
}
$this->sendEmail($file);
$this->sendTweet($file);
$this->sendFacebook($file);
}
Feature 4
<?php
namespace Blog;
class Image
{
public function upload(Request $request) {
foreach($request->files as $uploadedFile) {
$name = $uploadedFile->getName();
$file = $uploadedFile->move($directory, $name);
}
}
$this->dispatch->dispatch(
ImageEvents::AFTER_UPLOAD,
new ImageEvent($file);
);
}
Events
By David Flores