SlideShare a Scribd company logo
1 of 40
Download to read offline
1
STATE MACHINES AND WORKFLOW
NETS ON YOUR PHP PROJECTS
DANIEL ABAD CAMBRONERO
2
PRESENTATION
▸ Daniel Abad Cambronero
▸ https://github.com/ruudy-es
▸ @Ruudy_es
▸ Senior Software Developer
WHO I IM
3
INTRODUCTION
WHY?
▸ What are the three most important ideas in programming?
1. Abstraction
2. Abstraction
3. Abstraction
4
STATE MACHINES
DEFINITION
▸ Is a computational model used to design both computer
programs and sequential logic circuits
▸ It is conceived as an abstract machine that can be in one of
a finite number of states
▸ No ambiguity is allowed, the machine does not have
human intuition and must follow instructions
▸ It can change from one state to another when triggered by
an event or condition
5
STATE MACHINES
IMPORTANT CONCEPTS
▸ STATE
▸ TRANSITION
▸ EVENT / TRANSITION CONDITIONS
▸ ENTRY ACTION
▸ EXIT ACTION
6
STATE MACHINES
THEY ARE AMONG US
This is not brand new, have decades of research behind them,
analyzing and simplifying them.
▸ Electronic design automation
▸ Communication protocol design
▸ Language parsing
▸ To describe neurological systems (biology)
▸ To describe simple parts of the grammars of natural language
(linguistics)
7
STATE MACHINES
CLOSER THAN YOU THINK
8
▸ SM can model a
large number of
problems:
STATE MACHINES
ALSO…
▸ It really helps the design process
▸ Just with a look at the drawing, most of the people will
understand what is happening there
▸ It’ll make debugging easier and help us find where the
points of failure are
9
STATE MACHINES
WOW !
10
WORKFLOW NETS
DEFINITION
▸ Try to represent a complex human task with an steps
process
▸ Is a subclass of Petri nets intending to model the workflow
of process activities.
Wait…..
11
WOKFLOW NETS
PETRI NET?
▸ Place / transition net, one of the several mathematical
modelling languages for the description of distributed
systems.
▸ Arcs run from a place to a transition or vice versa, never
between places or between transitions
▸ The model never gets stuck in a transition
12
WOKFLOW NETS
STRUCTURES
13
WORKFLOW NETS
GO BACK TO THE DEFINITION
▸ Transitions are assigned to tasks or activities
▸ Places are assigned to the pre/post conditions
▸ Have the addition of a single input (source) place with no
previous transitions, and output place (sink) with no
following transitions.
14
WORKFLOW NETS
IMPORTANT CONCEPTS
▸ Transitions
▸ Places
▸ Arcs
▸ Marking
15
WORKFLOW NETS
BENEFITS
▸ Can represent an orchestrated and repeatable pattern of business
activity
▸ It can be depicted as a sequence of operations
▸ Strongly related with how people actually work and how
organizations handle information
▸ A newcomer can easily understand a program just looking at the
Workflow Definition Graph.
▸ Even more easy to debug and notice points of failure than State
Machine
16
STATE MACHINES VS WORKFLOW NETS
SUMMARISING
STATE MACHINE
‣ Must be only on one state
‣ Has only an exclusive
gateway
‣ Can be cyclic (loop)
‣ Could have transitions
with same name
WORKFLOW NET
‣ Marking could be composed
by multiple places
‣ Has a parallel gateway,
inclusive gateway and
exclusive gateway
‣ Are usually acyclic (start to
finish)
‣ Transitions name must be
unique
17
ENOUGH THEORY
18
MAKE THIS USABLE
RECOGNIZING IT
▸ Our model have a state or status field
▸ We are using boolean fields (published, paid)
▸ We are using nullable timestamps (published_at, paid_at)
▸ Having records that are only valid for a given period in
time (subscriptions with start and end date)
▸ Approved / Rejected process depending of multiple
checks
19
MAKE THIS USABLE
HAVE YOU EVER SEEN THIS?
20
▸ You ever thought or see something like this?
MAKE THIS USABLE
OR THIS?
21
MAKE THIS USABLE
HOW TO (PHP)
▸ Encapsulate the graph logic
▸ Design a good architecture around:
▸ Models
▸ Transition conditions
▸ Movements Logic
▸ Events / Automatization
▸ Tests / Documentation
22
ENCAPSULATE THE GRAPH LOGIC
STATE MACHINES LIBRARIES
▸ https://github.com/winzou/state-machine
▸ https://github.com/winzou/StateMachineBundle
▸ https://github.com/yohang/Finite
▸ https://github.com/Metabor/Statemachine
▸ https://github.com/sebastianbergmann/state
23
ENCAPSULATE THE GRAPH LOGIC
WORKFLOW NETS LIBRARIES
▸ https://github.com/symfony/workflow (3.x)
▸ https://github.com/fduch/workflow-bundle (2.x
compatibility)
▸ https://github.com/lexik/LexikWorkflowBundle (2.x)
▸ http://www.yiiframework.com/extension/simpleworkflow/
▸ https://github.com/florianv/petrinet
24
ENCAPSULATE THE GRAPH LOGIC
JUST DO IT
25
ENCAPSULATE THE GRAPH LOGIC
LOOKS QUITE SIMPLE
26
EXAMPLE - GRAPHS
STATE MACHINE GRAPH
27
EXAMPLE - GRAPHS
WORKFLOW NET GRAPH
28
EXAMPLE - ENCAPSULATE GRAPH LOGIC
LIBRARIES CONFIGURATION
29
EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND
MODELS
‣ Not type tables (for SM and WF)
▸ Not enum columns
▸ Easy as VARCHAR or LONGTEXT
▸ Do not try to replicate the SM / WF logic in your model
▸ SM & WF will use attributes for your model
30
EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND
SCHEMA
31
EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND
TRANSITIONS CONDITIONS
▸ Constraints / Validators
▸ Repositories / Models
▸ Library Events (not recommended)
32
EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND
MOVEMENTS LOGIC
33
EXAMPLE
DEMO TIME
DESIGN A GOOD ARCHITECTURE AROUND
EVENTS / AUTOMATIZATION
▸ Crons
▸ Model changes
▸ Transitions
▸ Places / States reach / leave
▸ Logs
35
DESIGN A GOOD ARCHITECTURE AROUND
TEST & DOCUMENTATION
Is almost impossible to cover all the cases from start.
▸ What happens if an enemy die?
▸ What happens if meanwhile im evading, enemy move to
another zone?
36
FINAL TIPS
MIX IT!
37
▸ A state machine could be part of a transition in a Workflow
net
▸ The final place of a Workflow could be one of the
requirements in a State machine transaction
▸ The enemy state could be another state machine with
different reactions (kind of AI), or a second instance of the
current one, interacting each other.
FINAL TIPS
QUITE SIMILAR, WHY TO USE BOTH?
38
THE END
QUESTIONS
39
THANKS
THANK YOU!
40
Demo repository:
▸ https://github.com/ruudy-es/phpmad-phpmachine-videogame

More Related Content

Similar to State Machines & Workflow Nets on Your PHP Projects

Troubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersTroubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersDocker, Inc.
 
Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018
Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018
Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018ChrisJohnsonBidler
 
Controller design-pattern-drupal-north-toronto-2018-final
Controller design-pattern-drupal-north-toronto-2018-finalController design-pattern-drupal-north-toronto-2018-final
Controller design-pattern-drupal-north-toronto-2018-finalVic Tarchenko
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsPiyush Katariya
 
Predictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformPredictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformIlia Idakiev
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xrkr10
 
How to Design a Backend for IoT
How to Design a Backend for IoTHow to Design a Backend for IoT
How to Design a Backend for IoTİbrahim Gürses
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerPôle Systematic Paris-Region
 
Meetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCMeetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCDamienCarpy
 
Gotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineGotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineAnton Babenko
 
Going deep (learning) with tensor flow and quarkus
Going deep (learning) with tensor flow and quarkusGoing deep (learning) with tensor flow and quarkus
Going deep (learning) with tensor flow and quarkusRed Hat Developers
 
BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumLiraz Shay
 
High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018Zahari Dichev
 
Ontrack - Keeping track of your CI/CD mess
Ontrack - Keeping track of your CI/CD messOntrack - Keeping track of your CI/CD mess
Ontrack - Keeping track of your CI/CD messDamien Coraboeuf
 
2017-10-24 All Day DevOps - Disposable Development Environments
2017-10-24 All Day DevOps - Disposable Development Environments2017-10-24 All Day DevOps - Disposable Development Environments
2017-10-24 All Day DevOps - Disposable Development EnvironmentsBoyd Hemphill
 

Similar to State Machines & Workflow Nets on Your PHP Projects (20)

Troubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersTroubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineers
 
Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018
Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018
Serverless Chicago - Datomic Cloud and AWS AppSync - April 26 2018
 
Controller design-pattern-drupal-north-toronto-2018-final
Controller design-pattern-drupal-north-toronto-2018-finalController design-pattern-drupal-north-toronto-2018-final
Controller design-pattern-drupal-north-toronto-2018-final
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
Predictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformPredictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platform
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
 
How to Design a Backend for IoT
How to Design a Backend for IoTHow to Design a Backend for IoT
How to Design a Backend for IoT
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
 
Software Development with PHP & Laravel
Software Development  with PHP & LaravelSoftware Development  with PHP & Laravel
Software Development with PHP & Laravel
 
Meetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCMeetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaC
 
Gotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineGotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipeline
 
Going deep (learning) with tensor flow and quarkus
Going deep (learning) with tensor flow and quarkusGoing deep (learning) with tensor flow and quarkus
Going deep (learning) with tensor flow and quarkus
 
BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and Selenium
 
Gitlab ci-cd
Gitlab ci-cdGitlab ci-cd
Gitlab ci-cd
 
Drools Workshop @JBCNCONF 2016
Drools Workshop @JBCNCONF 2016Drools Workshop @JBCNCONF 2016
Drools Workshop @JBCNCONF 2016
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018
 
Ontrack - Keeping track of your CI/CD mess
Ontrack - Keeping track of your CI/CD messOntrack - Keeping track of your CI/CD mess
Ontrack - Keeping track of your CI/CD mess
 
2017-10-24 All Day DevOps - Disposable Development Environments
2017-10-24 All Day DevOps - Disposable Development Environments2017-10-24 All Day DevOps - Disposable Development Environments
2017-10-24 All Day DevOps - Disposable Development Environments
 

Recently uploaded

Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrsaastr
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMoumonDas2
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 

Recently uploaded (20)

Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptx
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 

State Machines & Workflow Nets on Your PHP Projects

  • 1. 1
  • 2. STATE MACHINES AND WORKFLOW NETS ON YOUR PHP PROJECTS DANIEL ABAD CAMBRONERO 2
  • 3. PRESENTATION ▸ Daniel Abad Cambronero ▸ https://github.com/ruudy-es ▸ @Ruudy_es ▸ Senior Software Developer WHO I IM 3
  • 4. INTRODUCTION WHY? ▸ What are the three most important ideas in programming? 1. Abstraction 2. Abstraction 3. Abstraction 4
  • 5. STATE MACHINES DEFINITION ▸ Is a computational model used to design both computer programs and sequential logic circuits ▸ It is conceived as an abstract machine that can be in one of a finite number of states ▸ No ambiguity is allowed, the machine does not have human intuition and must follow instructions ▸ It can change from one state to another when triggered by an event or condition 5
  • 6. STATE MACHINES IMPORTANT CONCEPTS ▸ STATE ▸ TRANSITION ▸ EVENT / TRANSITION CONDITIONS ▸ ENTRY ACTION ▸ EXIT ACTION 6
  • 7. STATE MACHINES THEY ARE AMONG US This is not brand new, have decades of research behind them, analyzing and simplifying them. ▸ Electronic design automation ▸ Communication protocol design ▸ Language parsing ▸ To describe neurological systems (biology) ▸ To describe simple parts of the grammars of natural language (linguistics) 7
  • 8. STATE MACHINES CLOSER THAN YOU THINK 8 ▸ SM can model a large number of problems:
  • 9. STATE MACHINES ALSO… ▸ It really helps the design process ▸ Just with a look at the drawing, most of the people will understand what is happening there ▸ It’ll make debugging easier and help us find where the points of failure are 9
  • 11. WORKFLOW NETS DEFINITION ▸ Try to represent a complex human task with an steps process ▸ Is a subclass of Petri nets intending to model the workflow of process activities. Wait….. 11
  • 12. WOKFLOW NETS PETRI NET? ▸ Place / transition net, one of the several mathematical modelling languages for the description of distributed systems. ▸ Arcs run from a place to a transition or vice versa, never between places or between transitions ▸ The model never gets stuck in a transition 12
  • 14. WORKFLOW NETS GO BACK TO THE DEFINITION ▸ Transitions are assigned to tasks or activities ▸ Places are assigned to the pre/post conditions ▸ Have the addition of a single input (source) place with no previous transitions, and output place (sink) with no following transitions. 14
  • 15. WORKFLOW NETS IMPORTANT CONCEPTS ▸ Transitions ▸ Places ▸ Arcs ▸ Marking 15
  • 16. WORKFLOW NETS BENEFITS ▸ Can represent an orchestrated and repeatable pattern of business activity ▸ It can be depicted as a sequence of operations ▸ Strongly related with how people actually work and how organizations handle information ▸ A newcomer can easily understand a program just looking at the Workflow Definition Graph. ▸ Even more easy to debug and notice points of failure than State Machine 16
  • 17. STATE MACHINES VS WORKFLOW NETS SUMMARISING STATE MACHINE ‣ Must be only on one state ‣ Has only an exclusive gateway ‣ Can be cyclic (loop) ‣ Could have transitions with same name WORKFLOW NET ‣ Marking could be composed by multiple places ‣ Has a parallel gateway, inclusive gateway and exclusive gateway ‣ Are usually acyclic (start to finish) ‣ Transitions name must be unique 17
  • 19. MAKE THIS USABLE RECOGNIZING IT ▸ Our model have a state or status field ▸ We are using boolean fields (published, paid) ▸ We are using nullable timestamps (published_at, paid_at) ▸ Having records that are only valid for a given period in time (subscriptions with start and end date) ▸ Approved / Rejected process depending of multiple checks 19
  • 20. MAKE THIS USABLE HAVE YOU EVER SEEN THIS? 20 ▸ You ever thought or see something like this?
  • 22. MAKE THIS USABLE HOW TO (PHP) ▸ Encapsulate the graph logic ▸ Design a good architecture around: ▸ Models ▸ Transition conditions ▸ Movements Logic ▸ Events / Automatization ▸ Tests / Documentation 22
  • 23. ENCAPSULATE THE GRAPH LOGIC STATE MACHINES LIBRARIES ▸ https://github.com/winzou/state-machine ▸ https://github.com/winzou/StateMachineBundle ▸ https://github.com/yohang/Finite ▸ https://github.com/Metabor/Statemachine ▸ https://github.com/sebastianbergmann/state 23
  • 24. ENCAPSULATE THE GRAPH LOGIC WORKFLOW NETS LIBRARIES ▸ https://github.com/symfony/workflow (3.x) ▸ https://github.com/fduch/workflow-bundle (2.x compatibility) ▸ https://github.com/lexik/LexikWorkflowBundle (2.x) ▸ http://www.yiiframework.com/extension/simpleworkflow/ ▸ https://github.com/florianv/petrinet 24
  • 25. ENCAPSULATE THE GRAPH LOGIC JUST DO IT 25
  • 26. ENCAPSULATE THE GRAPH LOGIC LOOKS QUITE SIMPLE 26
  • 27. EXAMPLE - GRAPHS STATE MACHINE GRAPH 27
  • 29. EXAMPLE - ENCAPSULATE GRAPH LOGIC LIBRARIES CONFIGURATION 29
  • 30. EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND MODELS ‣ Not type tables (for SM and WF) ▸ Not enum columns ▸ Easy as VARCHAR or LONGTEXT ▸ Do not try to replicate the SM / WF logic in your model ▸ SM & WF will use attributes for your model 30
  • 31. EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND SCHEMA 31
  • 32. EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND TRANSITIONS CONDITIONS ▸ Constraints / Validators ▸ Repositories / Models ▸ Library Events (not recommended) 32
  • 33. EXAMPLE - DESIGN A GOOD ARCHITECTURE AROUND MOVEMENTS LOGIC 33
  • 35. DESIGN A GOOD ARCHITECTURE AROUND EVENTS / AUTOMATIZATION ▸ Crons ▸ Model changes ▸ Transitions ▸ Places / States reach / leave ▸ Logs 35
  • 36. DESIGN A GOOD ARCHITECTURE AROUND TEST & DOCUMENTATION Is almost impossible to cover all the cases from start. ▸ What happens if an enemy die? ▸ What happens if meanwhile im evading, enemy move to another zone? 36
  • 37. FINAL TIPS MIX IT! 37 ▸ A state machine could be part of a transition in a Workflow net ▸ The final place of a Workflow could be one of the requirements in a State machine transaction ▸ The enemy state could be another state machine with different reactions (kind of AI), or a second instance of the current one, interacting each other.
  • 38. FINAL TIPS QUITE SIMILAR, WHY TO USE BOTH? 38
  • 40. THANKS THANK YOU! 40 Demo repository: ▸ https://github.com/ruudy-es/phpmad-phpmachine-videogame