Download the PHP package mario-legenda/code-workflow without Composer
On this page you can find all versions of the php package mario-legenda/code-workflow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mario-legenda/code-workflow
More information about mario-legenda/code-workflow
Files in mario-legenda/code-workflow
Package code-workflow
Short Description Uniform design pattern for object execution
License MIT
Homepage https://github.com/MarioLegenda/control-flow-compiler
Informations about the package code-workflow
Php code workflow
For the last few months, I've been working on a SPA project written in Symfony2 on the server and Angular on the client. Most of the code revolves on calling a controller from the browser. The controller then fetches the data from the database and returns it to the client. I tried to make it uniformed with some design patterns, but different data sent from the client had to be processed with different design patterns. Some were uniformed and easy to read but some were messy and hard to read. So I decided to create a workflow design pattern that will be the same for every code execution.
I got the idea from ASP.NET world, mainly Microsoft Workflow Foundation. By no means is this project anything even remotly similar to Workflow Foundation but it made me think. Why not make something similar for Php? Most of you will think this is totally unnecessary + overkill. I actually agree. With this design pattern, there is a lot more code to be written but there are some benefits.
For example, Code Workflow checks for returns types of methods that you want to execute, so when some method does not return the desired type, error is thrown. But that could also be an overkill since PHP is not designed to be a strongly typed programming language. All things aside, this could be the most pointless project ever created but after I started working on it, I became stuborn and had to make it work. Someone might like it, most of you will hate it. That is the way of the samurai :).
Everything will be clear from the examples below, so continue reading.
The example objects are in src/Demo directory.
The basic way
In the examples in src/Demo directory, you can find the Company and Person object. Basic way of using these objects would be like this...
And this is just fine. It's readable and maintable. But what happens when you have to fetch company data from the database based on some JSON data sent by the client? What happens when you have to create a Factory that creates Person object based on database data? Even with pristine usage of design patterns, this code could become unreadable.
With Code workflow, the same code above could be rewritten to this code...
This is the same code executed but with human readable code. This could be read as follows:
NOTE
What happens when you wish to view the returned value of a method? That is also possible...
If you wish to get the the return value of a method in the success anonymous function then use this...
You can chain as much objects as you like and the workflow compiler will work.
That is it. I'm not going to make a detailed documentation on this beacuse I don't know if this will be of any use to anyone. If only ONE developers likes this, I will make a detailed documentation with phpdocumentator and the full documentation on github. I will also thoroughly comment all the code so you can see how it works.
Cheers and good life to everyone.