Have you ever worked with pipelines in Laravel?!

Probably you have heard it while having an interview?

It has lots of use cases and one of its usage is middleware implementation in its kernel.

I'm going to write about pipelines and its design pattern.

thread 🧵

1/8

First of all Pipelines in Laravel are implemented based on chain of responsibility design pattern.

In chain of responsibility which is a behavioral design pattern we pass data to receivers and this receivers implement a specific interface that has a handler method.
2/8

Handler methods may deal with the passed argument and pass it to the next handler.

read more about the design pattern here :

https://t.co/XrJKXecyTv

Let's go for the main part :
3/8

Imagine we want to implement a twitter bot that gets some tweets around the trends and filter the words that we don't wanna show finally send as a new tweet from our bot.

About the filtering part, if it was me, I would implement it with pipelines.

Why?!
4/8

Currently I know exactly what words should be filtered but what about the future?! What if I want to add more filters, I will have to modify the source code and add more switch, if else statements, etc.

I want my code to be robust and maintainable keeping SOLID principles.
5/8

So I'm gonna use pipeline like this (picture) :

First I will have my initial filters and also give the ability to myself or other developers to add more filters without even seeing the code.

See the picture and lets go deeper and check the main interface and pipelines 😎
6/8

I have defined a contract for all of my filters, every new filter and existing filters must implement this interface and implement the filter method

As you can see in the previous picture we gave our method name "filter" passed to via()

Nothing more let's go for filters
7/8

This is one of the filters we have implemented as you can see everything is clear filter method gets an argument called $content which is the text we wanna filter and when we modify the content and remove bad words it calls the next receiver from pipelines filters we defined
8/8

That's it all.
This is the pipeline design pattern we have in Laravel.

As you can see there are a lot of advantages using this design pattern having SOLID standards.

But sometimes it's better to keep things simple when our program is not that big and you are alone...

More from For later read

Today's Twitter threads (a Twitter thread).

Inside: Planet Money on HP's myriad ripoffs; Strength in numbers; and more!

Archived at: https://t.co/esjoT3u5Gr

#Pluralistic

1/


On Feb 22, I'm delivering a keynote address for the NISO Plus conference, "The day of the comet: what trustbusting means for digital manipulation."

https://t.co/Z84xicXhGg

2/


Planet Money on HP's myriad ripoffs: Ink-stained wretches of the world, unite!

https://t.co/k5ASdVUrC2

3/


Strength in numbers: The crisis in accounting.

https://t.co/DjfAfHWpNN

4/


#15yrsago Bad Samaritan family won’t return found expensive camera https://t.co/Rn9E5R1gtV

#10yrsago What does Libyan revolution mean for https://t.co/Jz28qHVhrV? https://t.co/dN1e4MxU4r

5/

You May Also Like

Tip from the Monkey
Pangolins, September 2019 and PLA are the key to this mystery
Stay Tuned!


1. Yang


2. A jacobin capuchin dangling a flagellin pangolin on a javelin while playing a mandolin and strangling a mannequin on a paladin's palanquin, said Saladin
More to come tomorrow!


3. Yigang Tong
https://t.co/CYtqYorhzH
Archived: https://t.co/ncz5ruwE2W


4. YT Interview
Some bats & pangolins carry viruses related with SARS-CoV-2, found in SE Asia and in Yunnan, & the pangolins carrying SARS-CoV-2 related viruses were smuggled from SE Asia, so there is a possibility that SARS-CoV-2 were coming from
"I lied about my basic beliefs in order to keep a prestigious job. Now that it will be zero-cost to me, I have a few things to say."


We know that elite institutions like the one Flier was in (partial) charge of rely on irrelevant status markers like private school education, whiteness, legacy, and ability to charm an old white guy at an interview.

Harvard's discriminatory policies are becoming increasingly well known, across the political spectrum (see, e.g., the recent lawsuit on discrimination against East Asian applications.)

It's refreshing to hear a senior administrator admits to personally opposing policies that attempt to remedy these basic flaws. These are flaws that harm his institution's ability to do cutting-edge research and to serve the public.

Harvard is being eclipsed by institutions that have different ideas about how to run a 21st Century institution. Stanford, for one; the UC system; the "public Ivys".