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

Hi @EdinburghUni @EHRC @EHRCChair @KishwerFalkner @RJHilsenrath @trussliz @GEOgovuk

The DIVERSITY INFORMATION section in yr job application mentions 'legal equality duties'. You then ask "What is your gender identity?" with options

Female
Male
Non-binary
Not-listed
Other

1/13


'Gender identity' is not a protected characteristic under the Equality Act 2010 and is not defined in the Act.

https://t.co/qisFhCiV1u

2/13


Sex is the protected characteristic and the only two possible options for sex are 'Female' and 'Male' as defined in the Act and consistent with biology - 'non-binary' and 'other' are not valid options.

https://t.co/CEJ0gkr6nF

'Gender identity' is not a synonym for sex.

3/13


You then ask "Does your gender identity match your sex registered at birth?"

4/13


Again, 'gender identity' is not a protected characteristic under the Equality Act 2010 and is not defined in the Act.

https://t.co/qisFhCiV1u

5/13
There is some valuable analysis in this report, but on the defense front this report is deeply flawed. There are other sections of value in report but, candidly, I don't think it helps us think through critical question of Taiwan defense issues in clear & well-grounded way. 1/


Normally as it might seem churlish to be so critical, but @cfr is so high-profile & the co-authors so distinguished I think it’s key to be clear. If not, people - including in Beijing - could get the wrong idea & this report could do real harm if influential on defense issues. 2/

BLUF: The defense discussion in this report does not engage at the depth needed to add to this critical debate. Accordingly conclusions in report are ill-founded - & in key parts harmful/misleading, esp that US shldnt be prepared defend Taiwan directly (alongside own efforts). 3/

The root of the problem is that report doesn't engage w the real debate on TWN defense issues or, frankly, the facts as knowable in public. Perhaps the most direct proof of this: The citations. There is nothing in the citations to @DeptofDefense China Military Power Report...4/

Nor to vast majority of leading informed sources on this like Ochmanek, the @RANDCorporation Scorecard, @CNAS, etc. This is esp salient b/c co-authors by their own admission have v little insight into contemporary military issues. & both last served in govt in Bush 43. 5/

You May Also Like