<?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 Vlad Gregurco on Medium]]></title>
        <description><![CDATA[Stories by Vlad Gregurco on Medium]]></description>
        <link>https://medium.com/@gregurco.vlad?source=rss-18c4dc169ae6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ddWoQwuQ7rUviiCE_BfvBQ.jpeg</url>
            <title>Stories by Vlad Gregurco on Medium</title>
            <link>https://medium.com/@gregurco.vlad?source=rss-18c4dc169ae6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:09:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gregurco.vlad/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[Upgrade Symfony to 4.3: Messenger Component changes]]></title>
            <link>https://medium.com/@gregurco.vlad/upgrade-symfony-to-4-3-messenger-component-changes-fabf8ef71ff3?source=rss-18c4dc169ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fabf8ef71ff3</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[symfony4]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Vlad Gregurco]]></dc:creator>
            <pubDate>Sat, 15 Jun 2019 13:08:25 GMT</pubDate>
            <atom:updated>2019-06-15T13:08:25.122Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K4WK0QzhwhEB3XK_.jpg" /><figcaption>Long road of upgrade…</figcaption></figure><p>Symfony 4.3 was released on <a href="https://symfony.com/blog/symfony-4-3-0-released">30 May</a> and community started to upgrade their projects (I hope). It’s not a major release, but it includes a lot of <a href="https://symfony.com/blog/symfony-4-3-0-beta1-released">changes</a> and it’s one step closer to LTS version (4.4).</p><h3>Upgrade</h3><p>Generally it’s quite easy to upgrade a minor version. There is a special guide posted by Symfony: <a href="https://symfony.com/doc/current/setup/upgrade_minor.html">link</a>. First you change versions in composer.json and run composer command. Voilà, you’re upgraded, but after that the game begins.</p><h3>Problem</h3><p>I met a strange behavior in Messenger component. Some of my handlers in specific cases throw exceptions. For example, <a href="https://github.com/symfony/symfony/blob/4.3/src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php">NotFoundHttpException</a> in case some data is not found in DB. Usually these exceptions are catched by <a href="https://github.com/symfony/http-kernel/blob/4.3/EventListener/ExceptionListener.php">ExceptionListener</a> and responses with 500 status code are transformed in user-friendly ones. In case of NotFoundHttpException it is 404 status code, but not after update! After update all handlers started to throw 500 error.</p><p>I found a small mention in <a href="https://github.com/symfony/symfony/blob/4.3/src/Symfony/Component/Messenger/CHANGELOG.md#430">CHANGELOG</a>:</p><blockquote>[BC BREAK] A HandlerFailedException exception will be thrown if one or more handler fails.</blockquote><p>This change was created in PR <a href="https://github.com/symfony/symfony/pull/30020">#30020 [Messenger] Ensure message is handled only once per handler</a>. The idea of PR is clear from the title. Seeing the code we can observe that they enveloped execution of handlers in try/catch block (line <a href="https://github.com/symfony/symfony/blob/4.3/src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php#L68">68</a>) and if at least one handler threw exception, new HandlerFailedException is thrown (line <a href="https://github.com/symfony/symfony/blob/4.3/src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php#L82">82</a>). All the time all exceptions are replaced by this new one.</p><h3>Solution</h3><p>The solution is quite simple. We have to create new middleware, that will be executed after HandleMessageMiddleware and reproduce the old behavior:</p><pre>&lt;?php<br><br>namespace App\Middleware;<br><br>use Symfony\Component\Messenger\Envelope;<br>use Symfony\Component\Messenger\Exception\HandlerFailedException;<br>use Symfony\Component\Messenger\Middleware\MiddlewareInterface;<br>use Symfony\Component\Messenger\Middleware\StackInterface;<br><br>class FailureCatcherMiddleware implements MiddlewareInterface<br>{<br>    <em>/**<br>     * </em><strong><em>@param </em></strong><em>Envelope $envelope<br>     * </em><strong><em>@param </em></strong><em>StackInterface $stack<br>     *<br>     * </em><strong><em>@return </em></strong><em>Envelope<br>     */<br>    </em>public function handle(Envelope $envelope, StackInterface $stack): Envelope<br>    {<br>        try {<br>            $returnedEnvelope = $stack-&gt;next()-&gt;handle($envelope, $stack);<br>        } catch (HandlerFailedException $e) {<br>            throw $e-&gt;getNestedExceptions()[0];<br>        }<br><br>        return $returnedEnvelope;<br>    }<br>}</pre><p>and configure it in <em>config/packages/messenger.yaml:</em></p><pre>framework:<br>    messenger:<br>        buses:<br>            messenger.bus.default:<br>                middleware:<br>                    - &#39;App\Middleware\FailureCatcherMiddleware&#39;</pre><p>After these changes NotFoundHttpException will continue to cause 404 response!</p><h3>Note</h3><p>This solution perfectly works for synchronous messages handled during request/response flow. You have to adjust the middleware in case of async operations handled from console.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fabf8ef71ff3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Symfony Validation Trick: Dependent Validation]]></title>
            <link>https://medium.com/@gregurco.vlad/symfony-validation-trick-dependent-validation-eb48bc5e3d81?source=rss-18c4dc169ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb48bc5e3d81</guid>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Vlad Gregurco]]></dc:creator>
            <pubDate>Mon, 24 Dec 2018 11:11:22 GMT</pubDate>
            <atom:updated>2018-12-24T21:06:09.228Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xDVddr9j75s4oaM0cYC_Q.jpeg" /></figure><p>It’s quite common case to have in projects dependent fields and we should somehow to validate them. Classic example is validation between start and end date, for example, booking.</p><p>Let’s suppose we have a Booking entity:</p><pre><strong>namespace </strong>App\Entity;<br><br><strong>use </strong>Doctrine\ORM\Mapping <strong>as </strong>ORM;<br><br><em>/**<br> * </em><strong><em>@ORM\Entity</em></strong><em>()<br> */<br></em><strong>class </strong>Booking<br>{<br>    <em>/**<br>     * </em><strong><em>@ORM\Column</em></strong><em>(type=&quot;integer&quot;)<br>     * </em><strong><em>@ORM\Id<br>     </em></strong><em>* </em><strong><em>@ORM\GeneratedValue</em></strong><em>(strategy=&quot;AUTO&quot;)<br>     */<br>    </em><strong>private </strong>$id;<br><br>    <em>/**<br>     * </em><strong><em>@ORM\Column</em></strong><em>(type=&quot;datetime&quot;)<br>     */<br>    </em><strong>private </strong>$startDate;<br><br>    <em>/**<br>     * </em><strong><em>@ORM\Column</em></strong><em>(type=&quot;datetime&quot;)<br>     */<br>    </em><strong>private </strong>$endDate;<br><br>    <strong>public function </strong>getId()<br>    {<br>        <strong>return </strong>$this-&gt;id;<br>    }<br><br>    <strong>public function </strong>getStartDate()<br>    {<br>        <strong>return </strong>$this-&gt;startDate;<br>    }<br><br>    <strong>public function </strong>setStartDate(\DateTime $startDate)<br>    {<br>        $this-&gt;startDate = $startDate;<br>    }<br><br>    <strong>public function </strong>getEndDate()<br>    {<br>        <strong>return </strong>$this-&gt;endDate;<br>    }<br><br>    <strong>public function </strong>setEndDate(\DateTime $endDate)<br>    {<br>        $this-&gt;endDate = $endDate;<br>    }<br>}</pre><p>It’s very small one. Just fields we need for this type of validation.</p><p>Next step is to create a Form Type class for this entity:</p><pre><strong>namespace </strong>App\Form;<br><br><strong>use </strong>App\Entity\Booking;<br><strong>use </strong>Symfony\Component\Form\AbstractType;<br><strong>use </strong>Symfony\Component\Form\Extension\Core\Type\DateType;<br><strong>use </strong>Symfony\Component\Form\FormBuilderInterface;<br><strong>use </strong>Symfony\Component\OptionsResolver\OptionsResolver;<br><strong>use </strong>Symfony\Component\Validator\Constraints\NotBlank;<br><strong>use </strong>Symfony\Component\Validator\Constraints\Date;<br><br><strong>class </strong>BookingType <strong>extends </strong>AbstractType<br>{<em><br>    </em><strong>public function </strong>buildForm(FormBuilderInterface $builder, <strong>array </strong>$options)<br>    {<br>        $builder<br>            -&gt;add(&#39;endDate&#39;, DateType::<strong>class</strong>, [<br>                &#39;constraints&#39; =&gt; [<br>                    <strong>new </strong>NotBlank(),<br>                    <strong>new </strong>Date(),<br>                ]<br>            ])<br>            -&gt;add(&#39;startDate&#39;, DateType::<strong>class</strong>, [<br>                &#39;constraints&#39; =&gt; [<br>                    <strong>new </strong>NotBlank(),<br>                    <strong>new </strong>Date(),<br>                ]<br>            ]);<br>    }<br><em><br>    </em><strong>public function </strong>configureOptions(OptionsResolver $resolver)<br>    {<br>        $resolver-&gt;setDefaults([<br>            &#39;data_class&#39; =&gt; Booking::<strong>class</strong>,<br>        ]);<br>    }<br>}</pre><p>As you can notice, we have generic validation rules: both fields are required and should have valid date value. But how to restrict the user not to mix the dates? It’s should not be acceptable to finish the booking before to start it, it’s obvious!</p><p>In this case Symfony provides us <a href="https://symfony.com/doc/current/reference/constraints/GreaterThan.html">GreaterThan</a> constraint. The trick happens here: we have to use this constraint not with static value, but with another field:</p><pre><strong>namespace </strong>App\Form;<br><br><strong>use </strong>App\Entity\Booking;<br><strong>use </strong>Symfony\Component\Form\AbstractType;<br><strong>use </strong>Symfony\Component\Form\Extension\Core\Type\DateType;<br><strong>use </strong>Symfony\Component\Form\FormBuilderInterface;<br><strong>use </strong>Symfony\Component\OptionsResolver\OptionsResolver;<br><strong>use </strong>Symfony\Component\Validator\Constraints\GreaterThan;<br><strong>use </strong>Symfony\Component\Validator\Constraints\NotBlank;<br><strong>use </strong>Symfony\Component\Validator\Constraints\Date;<br><br><strong>class </strong>BookingType <strong>extends </strong>AbstractType<br>{<em><br>    </em><strong>public function </strong>buildForm(FormBuilderInterface $builder, <strong>array </strong>$options)<br>    {<br>        $builder<br>            -&gt;add(&#39;endDate&#39;, DateType::<strong>class</strong>, [<br>                &#39;constraints&#39; =&gt; [<br>                    <strong>new </strong>NotBlank(),<br>                    <strong>new </strong>Date(),<br>                ]<br>            ])<br>            -&gt;add(&#39;startDate&#39;, DateType::<strong>class</strong>, [<br>                &#39;constraints&#39; =&gt; [<br>                    <strong>new </strong>NotBlank(),<br>                    <strong>new </strong>Date(),<br>                    <strong>new </strong>GreaterThan([<br>                        &#39;propertyPath&#39; =&gt; &#39;parent.all[endDate].data&#39;<br>                    ]),<br>                ]<br>            ]);<br>    }<br><em><br>    </em><strong>public function </strong>configureOptions(OptionsResolver $resolver)<br>    {<br>        $resolver-&gt;setDefaults([<br>            &#39;data_class&#39; =&gt; Booking::<strong>class</strong>,<br>        ]);<br>    }<br>}</pre><p>Render the form and try to enter wrong value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*a7sRRqogWvhNIwW1Q9VR1Q.png" /></figure><p>This trick is applicable only for Form Types and in case you are writing validation rules directly in entities, then follow example from <a href="https://symfony.com/doc/current/reference/constraints/GreaterThan.html#propertypath">official documentation</a>.</p><p>Read more about Forms in special article in <a href="https://jobeet-tutorial.readthedocs.io/en/latest/days/day-8/"><strong>Jobeet Tutorial</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb48bc5e3d81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a single-file plugin for Guzzle Bundle]]></title>
            <link>https://medium.com/@gregurco.vlad/how-to-create-a-single-file-plugin-for-guzzle-bundle-5960bedf2fe3?source=rss-18c4dc169ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5960bedf2fe3</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[http-request]]></category>
            <dc:creator><![CDATA[Vlad Gregurco]]></dc:creator>
            <pubDate>Wed, 05 Sep 2018 12:06:19 GMT</pubDate>
            <atom:updated>2018-09-05T12:06:19.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9EWaP8Ozi-3hEfzz.jpg" /></figure><p>The possibility of creating plugins was introduced in version <a href="https://github.com/8p/EightPointsGuzzleBundle/releases/tag/v7.0.0">7.0</a> of <a href="https://github.com/8p/EightPointsGuzzleBundle"><strong>Guzzle Bundle</strong></a> and <a href="https://github.com/8p/EightPointsGuzzleBundle#known-and-supported-plugins">several plugins</a> have already been published and downloaded thousands of times.</p><p>Let’s see how easy it is to create your own single-file plugin!</p><p>First install <a href="https://github.com/8p/EightPointsGuzzleBundle"><strong>Guzzle Bundle</strong></a>, if you have not already done so:</p><pre>composer require eightpoints/guzzle-bundle</pre><p>Don’t worry, it will not take too much time. We prepared a <a href="https://flex.symfony.com/">recipe</a> to speed up the installation process.</p><h3>Middleware</h3><blockquote><em>If you are not familiar with </em><em>middleware definition, then first read this great article provided by Guzzle team: </em><a href="http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#middleware"><em>here</em></a><em>.</em></blockquote><p>The primary goal of plugins is to provide possibility of configuration of middlewares for each guzzle client individually.</p><p>So, first we need a middleware. Suppose we have one that adds some “magic header” with “magic value” to all the requests:</p><pre>// src/GuzzleMiddleware/MagicHeaderMiddleware.php</pre><pre>namespace App\GuzzleMiddleware;</pre><pre>use Psr\Http\Message\RequestInterface;</pre><pre>class MagicHeaderMiddleware<br>{<br>    private $magicHeaderValue;</pre><pre>    /**<br>     * @param $magicHeaderValue<br>     */<br>    public function __construct($magicHeaderValue)<br>    {<br>        $this-&gt;magicHeaderValue = $magicHeaderValue;<br>    }</pre><pre>    /**<br>     * @param callable $handler<br>     *<br>     * @return \Closure<br>     */<br>    public function __invoke(callable $handler) : \Closure<br>    {<br>        return function (<br>            RequestInterface $request,<br>            array $options<br>        ) use ($handler) {<br>            $request = $request-&gt;withHeader(&#39;magic-header&#39;, $this-&gt;magicHeaderValue);</pre><pre>            // Continue the handler chain.<br>            return $handler($request, $options);<br>        };<br>    }<br>}</pre><h3>Client</h3><p>Also we need a guzzle client, that will be used to perform requests:</p><pre># config/packages/eight_points_guzzle.yaml</pre><pre>eight_points_guzzle:<br>    clients:<br>        httpbin_client:<br>            base_url: &quot;http://httpbin.org&quot;</pre><pre>            plugin: ~</pre><p>Now it’s time to connect middleware with the client through plugin system!</p><pre># config/packages/eight_points_guzzle.yaml</pre><pre>eight_points_guzzle:<br>    clients:<br>        httpbin_client:<br>            base_url: &quot;http://httpbin.org&quot;</pre><pre>            plugin:<br>                magic_header:<br>                    header_value: magic-value</pre><p>Adjust your configuration file and try to clear cache using command bin/console cache:clear and you will observe an error:</p><pre>In ArrayNode.php line 311:<br>Unrecognized option &quot;magic_header&quot; under &quot;eight_points_guzzle.clients.httpbin_client.plugin&quot;</pre><p>It’s OK, because Guzzle Bundle does not know anything about magic_header plugin and such a configuration. The plugin we plan to make will help Guzzle Bundle to do it.</p><h3>Plugin</h3><p>Create plugin file:</p><pre>// src/GuzzlePlugin/MagicHeaderPlugin.php</pre><pre>namespace App\GuzzlePlugin;</pre><pre>use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin;<br>use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;<br>use Symfony\Component\DependencyInjection\ContainerBuilder;<br>use Symfony\Component\DependencyInjection\Definition;<br>use Symfony\Component\HttpKernel\Bundle\Bundle;</pre><pre>class MagicHeaderPlugin extends Bundle implements EightPointsGuzzleBundlePlugin<br>{<br>    /**<br>     * @return string<br>     */<br>    public function getPluginName() : string<br>    {</pre><pre>    }</pre><pre>    /**<br>     * @param ArrayNodeDefinition $pluginNode<br>     */<br>    public function addConfiguration(ArrayNodeDefinition $pluginNode)<br>    {</pre><pre>    }</pre><pre>    /**<br>     * @param array $config<br>     * @param ContainerBuilder $container<br>     * @param string $clientName<br>     * @param Definition $handler<br>     */<br>    public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler)<br>    {</pre><pre>    }</pre><pre>    /**<br>     * @param array $configs<br>     * @param ContainerBuilder $container<br>     */<br>    public function load(array $configs, ContainerBuilder $container)<br>    {</pre><pre>    }<br>}</pre><p>Note that we implemented EightPointsGuzzleBundlePlugin interface and defined 4 methods:</p><ul><li>load - used to load xml/yaml/etc configuration</li><li>loadForClient - called after clients services are defined in container builder</li><li>addConfiguration - called when configuration tree of Guzzle Bundle is being built</li><li>getPluginName - called to get plugin identifier <em>(plugin name)</em></li></ul><p>First define plugin name:</p><pre>// ...</pre><pre>class MagicHeaderPlugin extends Bundle implements EightPointsGuzzleBundlePlugin<br>{    <br>    /**<br>     * @return string<br>     */<br>    public function getPluginName() : string<br>    {<br>        return &#39;magic_header&#39;;<br>    }<br>    <br>    // ...<br>}</pre><p>Next add possibility to configure header_value value in configuration file:</p><pre>// ...</pre><pre>class MagicHeaderPlugin extends Bundle implements EightPointsGuzzleBundlePlugin<br>{<br>    // ...</pre><pre>    /**<br>     * @param ArrayNodeDefinition $pluginNode<br>     */<br>    public function addConfiguration(ArrayNodeDefinition $pluginNode)<br>    {<br>        $pluginNode<br>            -&gt;addDefaultsIfNotSet()<br>            -&gt;children()<br>                -&gt;scalarNode(&#39;header_value&#39;)-&gt;defaultNull()-&gt;end()<br>            -&gt;end();<br>    }<br>    <br>    // ...<br>}</pre><p>During the construction of configuration tree of Guzzle Bundle the node is created for each plugin and this node is passed to each plugin in addConfiguration method. Here you have possibility to add any nodes you want. In out case we added just one scalar and nullable node with key header_value.</p><p>You can read more about configuration <a href="https://symfony.com/doc/current/components/config/definition.html">here</a>.</p><h3>Connect Plugin with Guzzle Bundle</h3><p>The plugin does not do anything significant, but it is ready to be connected to Guzzle Bundle.</p><p>Find next lines in <strong>src/Kernel.php</strong> file:</p><pre>foreach ($contents as $class =&gt; $envs) {<br>    if (isset($envs[&#39;all&#39;]) || isset($envs[$this-&gt;environment])) {<br>        yield new $class();<br>    }<br>}</pre><p>and replace them by:</p><pre>use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle;<br>use App\GuzzlePlugin\MagicHeaderPlugin\MagicHeaderPlugin;</pre><pre>// ...</pre><pre>foreach ($contents as $class =&gt; $envs) {<br>    if (isset($envs[&#39;all&#39;]) || isset($envs[$this-&gt;environment])) {<br>        if ($class === EightPointsGuzzleBundle::class) {<br>            yield new $class([<br>                new MagicHeaderPlugin(),<br>            ]);<br>        } else {<br>            yield new $class();<br>        }<br>    }<br>}</pre><p>Clearing of cache will end with success.</p><h3>Connect Plugin with Middleware</h3><p>To connect the plugin and middleware we need to modify loadForClient method from MagicHeaderPlugin class. At this stage we get control over the process of building the container. Having the value of header_value option provided from configuration file we can define middleware as a service and inject it to handler stack of the client:</p><pre>// ...<br>use Symfony\Component\ExpressionLanguage\Expression;<br>use App\GuzzleMiddleware\MagicHeaderMiddleware;</pre><pre>class MagicHeaderPlugin extends Bundle implements EightPointsGuzzleBundlePlugin<br>{<br>    // ...<br>    <br>    /**<br>     * @param array $config<br>     * @param ContainerBuilder $container<br>     * @param string $clientName<br>     * @param Definition $handler<br>     */<br>    public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler)<br>    {<br>        if ($config[&#39;header_value&#39;]) {<br>            // Create DI definition of middleware<br>            $middleware = new Definition(MagicHeaderMiddleware::class);<br>            $middleware-&gt;setArguments([$config[&#39;header_value&#39;]]);<br>            $middleware-&gt;setPublic(true);</pre><pre>            // Register Middleware as a Service<br>            $middlewareServiceName = sprintf(&#39;guzzle_bundle_magic_header_plugin.middleware.magic_header.%s&#39;, $clientName);<br>            $container-&gt;setDefinition($middlewareServiceName, $middleware);</pre><pre>            // Inject this service to given Handler Stack<br>            $middlewareExpression = new Expression(sprintf(&#39;service(&quot;%s&quot;)&#39;, $middlewareServiceName));<br>            $handler-&gt;addMethodCall(&#39;unshift&#39;, [$middlewareExpression]);<br>        }<br>    }<br>    <br>    // ...<br>}</pre><p>Note that loadForClient method is executed for each client defined in eight_points_guzzle configuration file.</p><p>Read more about handler stack <a href="http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html#handlerstack">here</a>.</p><h3>Testing</h3><p>It’s time to test!</p><p>Just call anywhere the client and execute GET request:</p><pre>$this-&gt;get(&#39;eight_points_guzzle.client.httpbin_client&#39;)-&gt;get(&#39;&#39;);</pre><p>Trigger this action and open Symfony Profiler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t9wvQQglQd101TqA.png" /></figure><p>Note in the request information the header with name magic-header and value provided from configuration: magic-value.</p><h3>Conclusion</h3><p>In this article we found out how easy it is to create single-file plugin and to extend base functionality provided by Guzzle Bundle.</p><p>In the next article, we’ll figure out how to create standalone plugin ready to be published on <a href="https://packagist.org/">packagist.org</a>.</p><h3>Additional information</h3><ul><li><a href="https://github.com/8p/EightPointsGuzzleBundle#known-and-supported-plugins">Known and Supported Guzzle Bundle Plugins</a></li><li><a href="https://packagist.org/?query=middleware&amp;tags=guzzle%7Emiddleware">More Guzzle Middlewares</a></li><li><a href="https://medium.com/@gregurco.vlad/how-do-we-track-request-time-with-guzzle-and-guzzle-bundle-cbde4148310">How do we track request time with Guzzle and Guzzle Bundle?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5960bedf2fe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do we track request time with Guzzle and Guzzle Bundle?]]></title>
            <link>https://medium.com/@gregurco.vlad/how-do-we-track-request-time-with-guzzle-and-guzzle-bundle-cbde4148310?source=rss-18c4dc169ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbde4148310</guid>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Vlad Gregurco]]></dc:creator>
            <pubDate>Wed, 08 Aug 2018 20:42:39 GMT</pubDate>
            <atom:updated>2018-09-05T12:06:22.154Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bv3RrzLeD_-VnA_t.png" /></figure><p>With confidence I can say that requests are not the fastest part of any application and for “unknown” reasons, one day you will want to check the time it takes and it will spoil your day.</p><p>Let’s create a guzzle client, that will be used, to perform request:</p><pre><strong>use </strong>GuzzleHttp\Client;<strong><br>use</strong> GuzzleHttp\TransferStats;<br><br>$client <strong>=</strong> <strong>new</strong> Client();</pre><p>And just add <a href="http://docs.guzzlephp.org/en/stable/request-options.html#on-stats"><strong>on_stats</strong></a><strong> </strong>option to the request:</p><pre>$client<strong>-&gt;</strong>request(&#39;GET&#39;, &#39;http://httpbin.org&#39;, [<br>    &#39;on_stats&#39; <strong>=&gt;</strong> <strong>function</strong> (TransferStats $stats) {<br>        // <em>Estimated time the request was being transferred</em><br>        // $stats-&gt;getTransferTime();<br>    }<br>]);</pre><p>Your callback will be called by guzzle and useful information will be passed through <a href="https://github.com/guzzle/guzzle/blob/master/src/TransferStats.php"><strong>TransferStats</strong></a><strong> </strong>object.</p><p>Things become even easier if you’re using <strong>Symfony</strong>:</p><p><strong>Step 1</strong>: Install <a href="https://github.com/8p/EightPointsGuzzleBundle">GuzzleBundle</a></p><pre>composer require eightpoints/guzzle-bundle</pre><p><strong>Step 2</strong>: Configure client</p><pre>eight_points_guzzle:<br>    clients:<br>        httpbin:<br>            base_url: &quot;http://httpbin.org&quot;</pre><p><strong>Step 3</strong>: Do a request</p><pre>$container-&gt;get(&#39;eight_points_guzzle.client.httpbin&#39;)-&gt;get(&#39;/204&#39;);</pre><p><strong>Step 4</strong>: Track request time in Profiler</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oFTHfaxb5oOmy4ei.png" /></figure><p>Guzzle Bundle tracks the time of all requests and shows all the information in a convenient form.</p><p>Read more here: <a href="https://github.com/8p/EightPointsGuzzleBundle">https://github.com/8p/EightPointsGuzzleBundle</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbde4148310" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Symfony 4.1 Jobeet Day 1: Starting up the Project with Docker]]></title>
            <link>https://medium.com/@gregurco.vlad/symfony-4-1-jobeet-day-1-starting-up-the-project-with-docker-ff6c5e686ca4?source=rss-18c4dc169ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff6c5e686ca4</guid>
            <category><![CDATA[symfony4]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Vlad Gregurco]]></dc:creator>
            <pubDate>Sat, 28 Jul 2018 07:24:14 GMT</pubDate>
            <atom:updated>2018-07-28T19:25:53.101Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-LFb1mBMpByTSF1sc4DfA.png" /></figure><p><strong>Jobeet Tutorial</strong> was published more than <a href="https://symfony.com/blog/do-you-know-jobeet">10 years ago</a>. Many things have changed during this time, but we do not have a goal to touch all of them. Let’s discuss about evolution in development environment.</p><p>There was a time, when people developed projects locally. Perhaps it was normal with one project and one developer, but it became a problem when number of projects developed simultaneously or number of developers was increased. Developers did not have a choice.</p><p>After that appeared <strong>Vagrant</strong>. It gave possibility to build the same environment for all developers on project and it was really cool. But some problems still remained: Vagrant was not designed for production environment.</p><p><strong>Docker</strong> appeared in 2013 and it was like a breath of fresh air: lightweight, suitable for all environments (for production too) and easy to learn. Many companies started to use it: Netflix, PayPal, eBay, Spotify, Uber, etc.</p><p>Let’s not lag behind technology and learn how to setup new Symfony project using Docker: <a href="https://jobeet-tutorial.rtfd.io/en/latest/days/day-1/"><strong>https://jobeet-tutorial.rtfd.io/en/latest/days/day-1/</strong></a></p><p>See the tutorial here:<strong> </strong><a href="https://jobeet-tutorial.rtfd.io/">https://jobeet-tutorial.rtfd.io</a></p><p>or on GitHub: <a href="https://github.com/gregurco/jobeet-tutorial">https://github.com/gregurco/jobeet-tutorial</a></p><p>Feel free to write a feedback, star our repository on <a href="https://github.com/gregurco/jobeet-tutorial">GitHub</a> and we are opened for contributions!</p><p>I want to thank everyone who already contributed: <a href="https://github.com/gregurco/jobeet-tutorial/graphs/contributors">https://github.com/gregurco/jobeet-tutorial/graphs/contributors</a> and <a href="https://github.com/gregurco/jobeet/graphs/contributors">https://github.com/gregurco/jobeet/graphs/contributors</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff6c5e686ca4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Symfony 4.1 Jobeet Tutorial]]></title>
            <link>https://medium.com/@gregurco.vlad/symfony-4-1-jobeet-tutorial-c57be646a788?source=rss-18c4dc169ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c57be646a788</guid>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[jobeet]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[symfony4]]></category>
            <dc:creator><![CDATA[Vlad Gregurco]]></dc:creator>
            <pubDate>Sat, 21 Jul 2018 13:18:44 GMT</pubDate>
            <atom:updated>2018-07-21T13:39:48.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7ySOtfY-Lajz30d-arBOA.png" /></figure><p><strong>Jobeet</strong> is a great tutorial on how to build a fully functional job board website. It was written by the <a href="https://symfony.com/">Symfony</a> team for Symfony 1.x version and I want to adapt it for <strong>Symfony 4.1</strong>.</p><p>I reorganized a little bit original content: removed some themes and added another ones. The list of days is next:</p><blockquote>Jobeet Day 1: Starting up the Project</blockquote><blockquote>Jobeet Day 2: The Project</blockquote><blockquote>Jobeet Day 3: The Data Model</blockquote><blockquote>Jobeet Day 4: The Controller and the View</blockquote><blockquote>Jobeet Day 5: The Routing</blockquote><blockquote>Jobeet Day 6: More with the Entity</blockquote><blockquote>Jobeet Day 7: Playing with the Category Page</blockquote><blockquote>Jobeet Day 8: The Forms</blockquote><blockquote>Jobeet Day 9: Console Commands</blockquote><blockquote>Jobeet Day 10: The Admin</blockquote><blockquote>Jobeet Day 11: The User</blockquote><blockquote>Jobeet Day 12: The Mailer</blockquote><blockquote>Jobeet Day 13: Translations</blockquote><blockquote>Jobeet Day 14: API</blockquote><blockquote>Jobeet Day 15: The Unit Tests</blockquote><blockquote>Jobeet Day 16: The Functional Tests</blockquote><blockquote>Jobeet Day 17: The Cache</blockquote><blockquote>Jobeet Day 18: The Deployment</blockquote><p>The work is still in progress, but most of the days have already been published.</p><p><strong>See the tutorial here: </strong><a href="https://jobeet-tutorial.rtfd.io/">https://jobeet-tutorial.rtfd.io</a></p><p>or on GitHub: <a href="https://github.com/gregurco/jobeet-tutorial">https://github.com/gregurco/jobeet-tutorial</a></p><p>Feel free to write a feedback, star our repository on <a href="https://github.com/gregurco/jobeet-tutorial">GitHub</a> and we are opened for contributions!</p><p>I want to thank everyone who already contributed: <a href="https://github.com/gregurco/jobeet-tutorial/graphs/contributors">https://github.com/gregurco/jobeet-tutorial/graphs/contributors</a> and <a href="https://github.com/gregurco/jobeet/graphs/contributors">https://github.com/gregurco/jobeet/graphs/contributors</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c57be646a788" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>