У нас вы можете посмотреть бесплатно Chain Of Responsibility 🔐(Middleware Design Pattern) или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Design Patterns in Php ~ Lesson 1: Chain of Responsibility (Aka how "middleware" is implemented) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The chain of responsibility design pattern is one of my absolute favorite software architecture concepts. One of my largest pet peeves is nested indents....I avoid them with my life! The chain of responsibility can take a whole bunch of nested if statements and flatten them out by abstracting the conditional logic to classes. On top of getting us out of indented if hell (Actual hell if you as me), the chain of responsibility design pattern is PHENOMENAL for validating http requests being sent into our application. It allows us easily extend, replace, remove, and re-order the validation that we intend to implement on an incoming request before it ever reaches our applications actual core behavior. The best part is that we don't have to modify existing if else code, we simply create another class. Brilliant and assists us in following the O from SOLID (Open closed principle) extraordinarily well. When we use the Chain of responsibility design pattern on Http Requests, especially within frameworks like Laravel, Php slim framework, Lumen, etc... we usually reference this pattern as "Middleware". Using the chain of responsibility pattern we are able to put a middle layer between the http request coming in and the actual ability for that request to reach parts of our application they're not supposed to. The Chain Of Responsibility Breakdown ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. What "Thing" are we validating? Define it. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Thing public $id; public $name; public $email; 2. Create an abstract class each "Link" in our "Chain of Responsibility" will extend from ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ abstract class CheckThing protected $nextCheck; public abstract function check(Thing $thing); public function then(CheckThing $nextCheck); // setter for $nextCheck public function next(Thing $thing); // Trigger the nextCheck($thing) in the chain 3. Create Chain Links (Specific Thing Checks), Each one validates something about thing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class CheckId extends CheckThing public check(Thing $thing) 1. check or validate id A. if check fails throw exception B. if check passes run next check by calling CheckId's next($thing) class CheckName extends CheckThing public check(Thing $thing) 1. check or validate name A. if check fails throw exception B. if check passes run next check by calling CheckName's next($thing) class CheckEmail extends CheckThing public check(Thing $thing) 1. check or validate email A. if check fails throw exception B. if check passes run next check by calling CheckName's next($thing) 4. Implement the chain of responsibility design pattern ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // A. initialize thing $thing = new Thing; // B. Initialize thing checks $checkId = new CheckId; $checkName = new CheckName; $checkEmail = new CheckEmail; // C. Define the order of responsibility. // $checkId~then($checkName); // $checkName~then($checkEmail); // D. Trigger Initial check in our Chain Of Responsibility $checkId ~ check($thing); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Clean Code Studio ~ Simplify Clean Code Clean Life ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://cleancode.studio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #ChainOfResponsibility #MiddlewareDesignPattern #SoftwareDesignPatterns