<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jool Software Professionals on Medium]]></title>
        <description><![CDATA[Stories by Jool Software Professionals on Medium]]></description>
        <link>https://medium.com/@joolsoftware?source=rss-a887905f1d35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*hvfxHDxz2fNFIhEqPxqjzQ.png</url>
            <title>Stories by Jool Software Professionals on Medium</title>
            <link>https://medium.com/@joolsoftware?source=rss-a887905f1d35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:42:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joolsoftware/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Symfony Workflow component (1/3)]]></title>
            <link>https://medium.com/joolsoftware/techblog-symfony-workflow-component-1-3-3056a05dc27f?source=rss-a887905f1d35------2</link>
            <guid isPermaLink="false">https://medium.com/p/3056a05dc27f</guid>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Jool Software Professionals]]></dc:creator>
            <pubDate>Thu, 06 Apr 2017 13:47:38 GMT</pubDate>
            <atom:updated>2018-10-01T14:05:54.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*L2qsQ-Q2ihCuXiccjqAEuQ.png" /></figure><p>With the release of Symfony 3.2 a new workflow component was added that implemented a <a href="https://en.wikipedia.org/wiki/Petri_net#Workflow_nets">workflow net</a> or a <a href="https://en.wikipedia.org/wiki/Finite-state_machine">state machine</a>. This component helps to separate the business workflow logic from other application logic and can help to visualize the workflow and mark the current state it is in.</p><p>This blog post is part 1 of a small series on the workflow component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*o79K865pJ7B0vA-Mw-KkCg.png" /><figcaption>Creditcard application workflow</figcaption></figure><ol><li>Introduction to the workflow component (this blog post)</li><li>Scheduled transitions using a job scheduler, for example to send reminders.</li><li>Improve the configuration, testability and visualize the workflow</li></ol><p>For this introduction we’ll use a creditcard application usecase as example. The applicant will need to confirm the applications emailaddress, the application needs to be verified and a new creditcard needs to be created.</p><p>For the workflow component to work we need to configure a <strong>workflow definition</strong>, a <strong>marking store</strong> and a <strong>subject</strong>. A workflow definition consists of places (states), transitions between the places and guards that conditionally block transitions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66b254cb4c56f9f7a18ed56985cbfefd/href">https://medium.com/media/66b254cb4c56f9f7a18ed56985cbfefd/href</a></iframe><h3><strong>The marking store</strong></h3><p>The marking store keeps track of the place where the subject (in this case the creditcard application) is inside the workflow. By default the marking store will manipulate the ‘marking’ property on your subject. If we have a creditcard application $application in the place start and apply the transition confirm_email the marking store would set the $application-&gt;marking property to email_confirmed.</p><p>By default the marking store will manipulate the ‘marking’ property on your subject, but you can change this by supplying an arguments property to the marking_store configuration. In the following example we change the property name to ‘state’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bab57b49acdb8382a3e4f27f38f38c9d/href">https://medium.com/media/bab57b49acdb8382a3e4f27f38f38c9d/href</a></iframe><p>The marking store will only manipulate the property, but will not take care of any persistence. If we implemented a service persisting_marking_store with our own implementation of the <em>MarkingStoreInterface we could configure it using the service configuration property.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c2cb5d56b50ce37185bd36c7d47235e/href">https://medium.com/media/0c2cb5d56b50ce37185bd36c7d47235e/href</a></iframe><p>For an example of a persisting marking store see the <a href="https://github.com/GlobalTradingTechnologies/workflow-extensions-bundle/blob/master/MarkingStore/OrmPersistentMarkingStore.php">OrmPersistentMarkingStore </a>in the GTT <a href="https://github.com/GlobalTradingTechnologies/workflow-extensions-bundle">workflow-extension-bundle</a>.</p><h3><strong>Multiple-state workflow</strong></h3><p>When the workflow supports parallel processes the subject can be in multiple places at once and we’ll need to configure the <em>MultipleStateMarkingStore</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ea96f5738037a5be15c882887b90a4d/href">https://medium.com/media/8ea96f5738037a5be15c882887b90a4d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*08IC47_kHWFfQ_sPoAz6vQ.png" /><figcaption>Multiple-state workflow</figcaption></figure><p>But in our example we’ll use a state machine which always has a single place/state.</p><blockquote>The type names for marking stores were <a href="https://github.com/symfony/symfony/commit/08464c9f2c059c5292fc9bfe991d6b74437389c9">changed</a>:<br>- property_accessor -&gt; multiple_state<br>- scalar -&gt; single_state<br>You might still see examples with the old configuration names.</blockquote><p>When your workflow type is <em>state_machine a </em><em>multiple_state</em> marking store is valid but doesn’t add any extra functionality as a state machine has only a single state.</p><h3><strong>Initiate workflow</strong></h3><p>To get a hold of a specific workflow you can use the following service name syntax: $container-&gt;get(&#39;workflow.&#39; . $workflowName), or when you use a state machine: $container-&gt;get(&#39;state_machine&#39; . $workflowName). Keep in mind that while the service name differs between a normal workflow and a statemachine the prefix workflow for event names in both cases.</p><h3><strong>Apply workflow transition</strong></h3><p>You can apply a transition using $workflow-&gt;apply(&#39;confirm_email&#39;, $subject). For our example application we implement a controller that would confirm the emailaddress using a link containing a unique hash</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d25852fd058cba9aaddf8602631414b/href">https://medium.com/media/8d25852fd058cba9aaddf8602631414b/href</a></iframe><h3><strong>Transition events</strong></h3><p>Applying a transition will dispatch the following sequence of events:</p><ol><li>Guard the transition<br>workflow[.&lt;workflow_name&gt;].guard[.&lt;transition_name&gt;]<br>The guard event is used the apply conditions to a transition and can block the transition.</li><li>Leave the <em>from </em>place<br>workflow[.&lt;workflow_name&gt;].leave[.&lt;from_place_name&gt;]</li><li>Transition<br>workflow[.&lt;workflow_name&gt;].transition[.&lt;transition_name&gt;]<br>This event can be used to apply an action on this transition such as sending an email.</li><li>Enter the <em>to</em> place<br>workflow[.&lt;workflow_name&gt;].enter[.&lt;to_place_name&gt;]</li><li>Entered the to place (<a href="https://github.com/symfony/symfony/pull/20787">Only ≥ Symfony 3.3</a>)<br>workflow[.&lt;workflow_name&gt;].entered[.&lt;to_place_name&gt;]<br>This is the same as the enter event but now the marking store is updated.</li><li>Announce new applicable transitions<br>workflow[.&lt;workflow_name&gt;].transition[.&lt;transition_name&gt;]<br>Listener to this event if you want to automatically apply a transition.</li></ol><h3><strong>Listen for a transition</strong></h3><p>Using the generated workflow events we could listen for the confirm_email transition event and send an email when the user confirms his creditcard application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85807383aa25c5422cd45dfdb0a89194/href">https://medium.com/media/85807383aa25c5422cd45dfdb0a89194/href</a></iframe><h3><strong>Guard a workflow transition</strong></h3><p>To conditionally guard a workflow transition the application can listen for guard events. If any of the guard listeners set $guardEvent-&gt;setBlocked(true) the transition will not be available.</p><p>In the creditcard example we can require an additional approved credit limit when the user requests a creditcard with a limit above $ 200. We implement a Guard listener that listens for the workflow.creditcard_application_flow.guard.create_card event:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c91b10aa29daf774d07bffc93cb5e835/href">https://medium.com/media/c91b10aa29daf774d07bffc93cb5e835/href</a></iframe><p>In Symfony 3.3+ you will also be able to define the <a href="https://github.com/symfony/symfony/pull/21935">guards using an expression in the workflow definition</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fd8c0723aba0ae65c8fac7c04413c16/href">https://medium.com/media/1fd8c0723aba0ae65c8fac7c04413c16/href</a></iframe><h3>What’s next?</h3><p>In part 2 of this serie we’ll have a look at how you can schedule transitions and hook transitions to application events. We’ll build a reminder transtion that ‘ll be applied if the user hasn’t confirmed its creditcard application in 3 days.</p><h3>References</h3><ul><li><a href="https://github.com/lyrixx/SFLive-Paris2016-Workflow">https://github.com/lyrixx/SFLive-Paris2016-Workflow</a></li><li><a href="http://symfony.com/blog/new-in-symfony-3-2-workflow-component">http://symfony.com/blog/new-in-symfony-3-2-workflow-component</a></li><li><a href="https://github.com/symfony/symfony/pull/21935">https://github.com/symfony/symfony/pull/21935</a> (Guard expression support)</li><li><a href="https://github.com/symfony/symfony/pull/20787">https://github.com/symfony/symfony/pull/20787</a> (Support for the entered workflow event)</li><li><a href="https://github.com/GlobalTradingTechnologies/workflow-extensions-bundle">https://github.com/GlobalTradingTechnologies/workflow-extensions-bundle</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3056a05dc27f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/joolsoftware/techblog-symfony-workflow-component-1-3-3056a05dc27f">Symfony Workflow component (1/3)</a> was originally published in <a href="https://medium.com/joolsoftware">Jool Software Professionals</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>