<?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 Alkin on Medium]]></title>
        <description><![CDATA[Stories by Alkin on Medium]]></description>
        <link>https://medium.com/@alkinbg?source=rss-71f5fd73e174------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wHGIyNmZRrw6lOal.jpg</url>
            <title>Stories by Alkin on Medium</title>
            <link>https://medium.com/@alkinbg?source=rss-71f5fd73e174------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 18:31:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alkinbg/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[Poka-Yoke in PHP: Guarding Business Operations Before They Run]]></title>
            <link>https://medium.com/@alkinbg/poka-yoke-in-php-guarding-business-operations-before-they-run-60455a799045?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/60455a799045</guid>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 07:21:37 GMT</pubDate>
            <atom:updated>2026-10-22T08:02:10.712Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fKnPPFGVxljvstm7.jpg" /></figure><p>In manufacturing, <em>Poka-Yoke</em> is a way of designing a process so that common mistakes are prevented or detected before they cause harm. An asymmetric fixture that accepts a component in only one orientation is a familiar example.</p><p>I work with software in operational environments, and I kept returning to a related question: <strong>what does mistake-proofing look like at the boundary of a PHP business operation?</strong></p><p>Not every mistake needs a new library. Most of the time, an ordinary if statement is the right answer. But when an operation depends on several independent conditions, it can become useful to make those checks explicit, collect the reasons for rejection, and keep the action itself behind a single guard.</p><p>That experiment became <a href="https://github.com/alkinbg/Novora-PokaYoke">Novora Poka-Yoke</a>, a small, framework-independent PHP 8.4+ package.</p><h3>The problem is not just validation</h3><p>Consider a shipping operation. Before dispatching, we may need to know that payment has been confirmed, a shipping address exists, and sufficient stock is available.</p><p>We can write these conditions inline. There is nothing inherently wrong with that. But a sequence of early returns often tells the user only about the <strong>first</strong> missing condition, while the same requirements can end up scattered across controllers, command handlers, and services.</p><p>For some workflows, I wanted an explicit boundary:</p><ol><li>Evaluate application-defined preconditions.</li><li>Collect understandable, machine-readable reasons if any fail.</li><li>Invoke the operation callback only when every check passes.</li></ol><p>The important distinction is that this is <strong>operation precondition checking</strong>, not a general data-validation framework, a state machine, or a transaction manager.</p><h3>A minimal API</h3><p>Install the stable package with Composer:</p><pre>composer require &quot;novora/poka-yoke:^1.0&quot;</pre><p>A rule implements one method and returns either null (allowed) or a Violation:</p><p>Order is a placeholder for an entity or DTO <strong>from your application</strong>; the package does not define an Order class.</p><p>We can combine multiple rules without hiding which ones ran:</p><p>The two additional rule classes above are application-defined examples too. By default, check() collects violations in rule order. For cases where evaluating later rules would be unnecessary, it supports stopOnFirstViolation: true.</p><h3>Put the action behind the guard</h3><p>A separate check followed by an action is useful for displaying diagnostics, but the package also offers a compact operation boundary:</p><p>The callback is not invoked if any rule rejects the operation. execute() returns the callback&#39;s value if all rules pass. Exceptions thrown by a rule or the callback are <strong>not swallowed</strong>.</p><p>One design decision here is deliberate: a rule expresses <em>why the operation cannot proceed</em>, while the application remains responsible for domain decisions and persistence.</p><h3>Where this pattern is useful</h3><p>The same narrow concept appears in quite different applications:</p><ul><li><strong>Shipping:</strong> payment, address, and stock checks before dispatch.</li><li><strong>Manufacturing:</strong> verifying a scanned part and a completed quality step before recording the next operation. Real machinery safety must remain in dedicated safety systems.</li><li><strong>Bookings:</strong> checking consent and requested capacity before submitting a booking.</li></ul><p>These are not promises of safe concurrent inventory or seat allocation. They are examples of where explicit preconditions make intent easier to understand.</p><p>The repository includes a <a href="https://github.com/alkinbg/Novora-PokaYoke/blob/v1.0.0/examples/order.php">runnable order example</a> and a <a href="https://github.com/alkinbg/Novora-PokaYoke/blob/main/docs/practical-value.md">discussion of practical scenarios and alternatives</a>.</p><h3>What Poka-Yoke cannot guarantee here</h3><p>This is the part I consider especially important.</p><p>A successful precondition check does <strong>not</strong> guarantee the state will still be valid when the callback commits its changes. Inventory, account balance, or booking capacity can change concurrently. The library does not provide database transactions, row locking, idempotency, distributed coordination, or rollback.</p><p>If correctness depends on the check and write being atomic, the application must enforce that with suitable database constraints, transactions, locks, or other domain-specific mechanisms. Likewise, rule implementations should avoid side effects, but the library cannot prevent user-supplied PHP code from mutating state.</p><p>For data shape and field constraints, an established validator is probably a better choice. For state transitions, a workflow or state-machine component is usually a better abstraction. And for one or two straightforward preconditions, plain PHP conditionals may be simpler.</p><h3>Testing the contract</h3><p>The initial v1.0.0 release was validated with <strong>15 PHPUnit tests (27 assertions)</strong>, PHPStan level 8, Composer validation, and CI on PHP 8.4 and PHP 8.5. I also installed the published package from Packagist in a separate PHP project and exercised its API.</p><p>Tests cover failing preconditions, the order of violations, fail-fast checking, invalid rule values, propagation of exceptions, falsy contexts, and the guarantee that a rejected operation does not invoke its callback.</p><p>Those checks establish the package’s <strong>documented behavior</strong>. They are not proof that every consuming application’s business rules are correct.</p><h3>A modest conclusion</h3><p>I do not think Poka-Yoke in PHP requires a large framework. Sometimes it is simply a useful design habit: <strong>make the conditions for a consequential operation explicit, and stop before the side effect when those conditions are not met</strong>.</p><p>Novora Poka-Yoke packages one small expression of that idea. It might be useful when you want structured rejection reasons and a consistent execution boundary; it is not intended to replace a validator, workflow engine, or carefully designed domain model.</p><p>If you have solved similar problems differently, I would be interested to learn what worked for you.</p><p><strong>Project links:</strong> <a href="https://github.com/alkinbg/Novora-PokaYoke">GitHub</a> · <a href="https://packagist.org/packages/novora/poka-yoke">Packagist</a> · <a href="https://github.com/alkinbg/Novora-PokaYoke/releases/tag/v1.0.0">v1.0.0 release</a></p><p><em>Originally published at </em><a href="https://dev.to/alkin/poka-yoke-in-php-guarding-business-operations-before-they-run-427a"><em>https://dev.to</em></a><em> on October 22, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60455a799045" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bulk Editing in EasyAdmin 5: A Review-and-Confirm Workflow for Doctrine Entities]]></title>
            <link>https://medium.com/@alkinbg/bulk-editing-in-easyadmin-5-a-review-and-confirm-workflow-for-doctrine-entities-b56f89165890?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/b56f89165890</guid>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 05:15:21 GMT</pubDate>
            <atom:updated>2026-10-22T08:01:42.508Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q_mKL9bPQaCsZfAc.jpg" /></figure><p>EasyAdmin is one of the reasons building administrative interfaces with Symfony can be pleasantly straightforward. It gives us CRUD pages, filters, forms, actions, and a lot of useful defaults without making every project reinvent its back office.</p><p>But there is a small workflow I have needed in real applications: <strong>select several records and change only a few explicitly chosen fields</strong>.</p><p>Imagine an administrator managing a product catalogue. Twenty products need to move from <em>draft</em> to <em>published</em>. Their titles, prices, categories, and other attributes must remain untouched. Opening twenty edit forms is tedious. A custom one-off batch action works, but each additional field or entity often means another controller method and another form.</p><p>I wanted to explore whether that common workflow could be packaged as a focused EasyAdmin extension. The result is <a href="https://github.com/alkinbg/NovoraEasyAdminBulkEditBundle">Novora EasyAdmin Bulk Edit Bundle</a>, with its latest published release, <strong>v1.1.3</strong>.</p><p>This post is about the decisions behind it, how to wire it into an EasyAdmin 5 CRUD controller, and-just as importantly-what the bundle does <strong>not</strong> attempt to solve.</p><h3>The difference between a batch action and bulk editing</h3><p>EasyAdmin already supports batch actions. You can select multiple rows and invoke a custom action. That is an excellent extension point; the bundle uses it rather than replacing EasyAdmin’s index UI.</p><p>What a generic <em>bulk edit</em> workflow needs on top of that is a little more involved:</p><ol><li>Collect the selected records from the batch action.</li><li>Let the administrator choose <strong>which fields</strong> to change, and supply their new values.</li><li>Validate those values with Symfony Forms.</li><li>Display the proposed changes before anything is written.</li><li>Check permissions again when the final confirmation arrives.</li><li>Apply the changes through Doctrine ORM within a transaction.</li></ol><p>The second point is easy to underestimate. A bulk edit form must distinguish <strong>“leave this field unchanged”</strong> from <strong>“set this field to </strong><strong>null, </strong><strong>false, an empty string, or zero.&quot;</strong> Those values can be perfectly valid updates.</p><p>For that reason, the form gives each editable field its own opt-in checkbox. The new value matters only when the checkbox is selected. Unchecked fields are omitted from the change set entirely.</p><h3>A deliberately small scope</h3><p>The bundle targets PHP 8.4+, Symfony 7.4/8.x, EasyAdmin 5.x, and Doctrine ORM 3.x. Version 1.x keeps its supported operation intentionally narrow: up to <strong>100 selected entity identifiers</strong>, with explicit handlers for scalar values ( string, int, float, bool, or null).</p><p>It is not an automatic editor for every Doctrine property. Arbitrary associations, collections, object-valued form data, and asynchronous processing are out of scope.</p><p>That constraint is a feature of the design rather than a claim that those cases are unimportant. I would rather maintain a modest public API with understandable behavior than guess how every application’s domain model should be mutated.</p><h3>Installation</h3><p>The package is listed on <a href="https://packagist.org/packages/novora/easyadmin-bulk-edit-bundle">Packagist</a>. For a project meeting its requirements:</p><pre>composer require novora/easyadmin-bulk-edit-bundle:^1.1.3</pre><p>Register the bundle if your application’s setup does not enable it automatically:</p><p>This assumes an existing, correctly configured EasyAdmin application with Symfony sessions, Twig, Doctrine, and CSRF protection. The registration snippet is for applications where the bundle is not already present in config/bundles.php; <strong>do not add it twice</strong>.</p><h3>Connecting a CRUD controller</h3><p>The following example assumes a Product entity with a setStatus(string $status) method and an application voter that understands the EDIT permission. Those are <strong>application-specific examples</strong>, not classes supplied by the bundle.</p><p>First, register an EasyAdmin batch action. BulkEditAction::new() uses EasyAdmin&#39;s normal batch-action mechanism and skips its generic preliminary confirmation <strong>for this action only</strong>; the bundle still provides its own review and final confirmation:</p><p>Then add the two custom CRUD actions. With EasyAdmin 5, the #[AdminRoute] attributes matter: they make these custom routes discoverable in its routing system.</p><p>There are several intentionally explicit decisions in this example.</p><p><strong>The trusted entity class comes from </strong><strong>AdminContext.</strong> The initial batch POST includes an entity class name, but client-supplied class names must not decide which repository is modified.</p><p><strong>The form definition and its field handler are both defined by the application.</strong> The bundle does not derive method names from HTTP field names, and checks that configured form fields match their allowed handlers before proceeding.</p><p><strong>Authorization happens at two levels.</strong> The controller checks access to each action. The callback checks each entity during execution. Your own EasyAdmin permissions and voters must still be configured correctly. Checking permissions only when the review screen is first opened would be insufficient-roles and record ownership can change before confirmation.</p><p>For the complete integration details, see the <a href="https://github.com/alkinbg/NovoraEasyAdminBulkEditBundle/blob/v1.1.3/docs/integration.md">v1.1.3 integration guide</a>.</p><h3>A small UX detail that matters</h3><p>The first iteration taught me that a correct workflow can still feel awkward. EasyAdmin may show its standard batch-action confirmation dialog before the administrator even sees the edit form. Since this bundle already has a separate review and final confirmation, that extra dialog makes the experience confusing.</p><p>BulkEditAction::new() skips that preliminary dialog <strong>only for bulk editing</strong>, while leaving other batch actions&#39; confirmations intact. I deliberately avoided disabling confirmation for the entire CRUD controller: a different batch action may delete data or perform another irreversible operation.</p><p>The edit screen also separates two decisions: <em>should this field be changed?</em> and <em>what should its new value be?</em> For example, updating an active boolean to false must not be confused with leaving the field unchanged. The current interface has English and Bulgarian translations, and the review shows boolean values as readable Yes/No equivalents. After a successful commit, it creates a localized Symfony success flash message; how it appears depends on the host application&#39;s EasyAdmin layout.</p><h3>What happens between selection and confirmation?</h3><p>The interaction is deliberately split into stages:</p><pre>EasyAdmin index | | select rows + invoke batch action v Validate action, entity class and batch CSRF | v Store selected IDs in the server-side session | v Edit form: check fields and enter new values | | Symfony Form validation v Review page: show selected count and proposed values | | separate CSRF-protected confirmation v Recheck entity permissions, update through Doctrine, commit</pre><p>The server-side selection is associated with a random token, expires after <strong>15 minutes</strong>, and is consumed when confirmation is attempted. The review values are also stored server-side; the confirmation form does not need to trust a new list of entity identifiers or mutable hidden form fields.</p><p>The review page is not a preview of every entity’s old and new values, nor does it execute domain code speculatively. It displays the <em>requested field/value changes</em> and the number of selected records. Calling that a full “dry run” would be misleading, and the review does not detect changes made by another administrator in the meantime.</p><h3>Why use Doctrine entities instead of one DQL UPDATE?</h3><p>A single database-level UPDATE can be tempting:</p><p>But a raw update is not equivalent to loading entities and calling their methods. In an application that relies on entity methods, Doctrine change tracking, and ORM lifecycle behavior, skipping the normal entity path may change application semantics.</p><p>The bundle instead loads the selected objects, authorizes each one, calls the explicitly configured field handlers, and flushes through Doctrine ORM in a transaction.</p><p>There is a trade-off: that is more work than a single SQL statement. Capping the operation at 100 selected IDs keeps the first version’s expectations reasonably clear. Database transactions also have limits: rolling back the database will not undo an email, an HTTP request, or another external side effect triggered during the operation.</p><h3>What about concurrent changes?</h3><p>This deserves an explicit answer, particularly for administrative interfaces.</p><p><strong>A transaction does not automatically prevent lost updates.</strong> Imagine someone edits a product after the bulk edit selection was made but before confirmation. Whether that conflict matters-and how it should be resolved-depends on the application. For critical data, consider optimistic versioning, appropriate row locks, or other domain-specific concurrency controls.</p><p>Similarly, <strong>a one-use token in a Symfony session is not a distributed exactly-once guarantee</strong>. Some session handlers serialize requests for a session; others may behave differently depending on configuration, infrastructure and deployment. If a bulk action causes financial, irreversible or externally visible side effects, use a shared idempotency or locking mechanism designed for that requirement.</p><p>The bundle documents these boundaries instead of presenting CSRF tokens and session state as universal concurrency protection.</p><h3>Testing the behavior, not just the helpers</h3><p>I found the most useful tests were the ones that exercised the real request flow, rather than only testing small service methods in isolation.</p><p>The project includes a Symfony integration fixture with EasyAdmin routing, Twig, forms, Doctrine, and SQLite. It checks that the batch action reaches the correct controller, the edit form renders, invalid form data does not write to the database, the review step does not write anything, and the final confirmation performs the update.</p><p>The tests also cover invalid or mismatched batch selections, forged CSRF tokens, attempts to repeat a consumed confirmation, and an access-denial scenario after the review step.</p><p>For <strong>v1.1.3</strong>, the project passed <strong>27 PHPUnit tests (90 assertions)</strong> and PHPStan level 8, with CI jobs for PHP 8.4 (minimum and latest permitted dependencies) and PHP 8.5 (latest permitted dependencies). Those checks are useful evidence of behavior-but they are not a substitute for testing your own policies and production database configuration.</p><h3>Lessons from making it reusable</h3><p>A reusable Symfony bundle does not have to make every decision for the application. In fact, I think it is healthier when it does not.</p><p>For this project, I wanted the library to own the repeatable infrastructure-selection handoff, edit/review screens, form validation, and transactional orchestration-while the application retains control of entity permissions, allowed fields, setters, and domain rules.</p><p>The scope remains modest. It will not replace every custom administrative workflow, and I do not think it should. I hope it saves someone from implementing the same careful multi-record edit flow repeatedly.</p><p>If you work with EasyAdmin and have encountered a similar case, I would be interested to hear where this approach fits-and where it does not.</p><p><strong>Links</strong></p><p>Thanks for reading.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/bulk-editing-in-easyadmin-5-a-review-and-confirm-workflow-for-doctrine-entities-5bhf"><em>https://dev.to</em></a><em> on October 22, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b56f89165890" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When Counting Overlapping Bookings Is Not Enough: Capacity-Aware Availability in PHP]]></title>
            <link>https://medium.com/@alkinbg/when-counting-overlapping-bookings-is-not-enough-capacity-aware-availability-in-php-d25f76804bf3?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/d25f76804bf3</guid>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Wed, 21 Oct 2026 10:18:45 GMT</pubDate>
            <atom:updated>2026-10-21T10:26:00.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*ymeqQwA_tWbbcRxC.jpg" /></figure><p>Imagine you’re building a scheduling feature for a loading dock, a shared workspace, or a storage area.</p><p>The resource has a maximum capacity. A reservation occupies some of it for a period of time. You need to answer a deceptively simple question:</p><blockquote><em>Can I reserve </em><strong><em>2 units for 45 minutes</em></strong><em>, and if so, when can I start?</em></blockquote><p>At first, this looks like a database query that counts overlapping reservations. I initially thought of it in similar terms. But once capacity changes throughout the day and bookings consume different amounts, counting overlaps no longer gives the right answer.</p><p>That was the starting point for <a href="https://github.com/alkinbg/CapacityAvailability">CapacityAvailability</a>, a small PHP library I recently released as version 1.0.0.</p><p>This article is about the problem and the reasoning behind the solution-not an argument that every scheduling application needs another dependency.</p><h3>The trap: overlap is not concurrency</h3><p>Suppose a resource has capacity <strong>3</strong> and already has these bookings:</p><p>A proposed reservation would use <strong>2 units</strong> from <strong>09:00 to 10:30</strong>.</p><p>All three existing bookings intersect that proposed interval. A naive approach might sum their units, get 3, and reject the request.</p><p>But the existing bookings never run simultaneously. At every instant, only one unit is occupied. Two units remain free throughout the entire 90-minute interval. The request fits.</p><p>Now add another booking for 2 units from 09:45 to 10:15. The answer changes: during part of the interval, all 3 units are occupied.</p><p>What matters is <strong>usage at each point in time</strong>, not how many reservations touch the requested interval.</p><p>And there’s another complication: the resource itself might have capacity 2 before 10:00 and capacity 3 afterwards.</p><h3>Model time explicitly</h3><p>I chose a small model:</p><ul><li>A <strong>capacity interval</strong> declares the total available units during [start, end).</li><li>A <strong>reservation</strong> consumes a positive number of units during [start, end).</li><li>A query specifies the required units and the duration for which those units must remain available.</li></ul><p>The [start, end) notation matters. The start is inclusive; the end is exclusive. A booking ending exactly at 10:00 does not conflict with another beginning at 10:00.</p><p>Capacity declarations are <strong>absolute</strong>, not additive: if a pool has capacity 3, that’s a level of 3, not another 3 units to add to an overlapping declaration. Overlapping capacity declarations are rejected. Any period without declared capacity has capacity zero.</p><p>This model also makes a deliberate trade-off: the units are interchangeable. It answers <em>whether</em> 2 places are available, not <em>which exact two places</em> to allocate. Scheduling individual machines with different capabilities is a different problem.</p><h3>Sweep-line: look only where the state changes</h3><p>The underlying approach is a <a href="https://en.wikipedia.org/wiki/Sweep_line_algorithm">sweep-line algorithm</a>.</p><p>Instead of examining every second or minute, we collect the moments at which something changes:</p><ol><li>When capacity begins, add its units.</li><li>When capacity ends, subtract its units.</li><li>When a reservation begins, increase occupied units.</li><li>When a reservation ends, decrease occupied units.</li><li>Sort the event times and apply all changes at the same instant together.</li></ol><p>Between two consecutive event times, capacity and usage are constant.</p><p>For example:</p><p>If we need 2 units for 45 minutes, the period from 09:00 to 09:30 is too short. The contiguous availability from 10:00 to 11:00 is long enough.</p><p>The result is not a predefined array of quarter-hour slots. It’s a <strong>continuous window</strong> with enough remaining capacity for the entire requested duration.</p><p>For C capacity intervals and R reservations, the calculation uses O((C + R) log(C + R)) time and O(C + R) additional memory, dominated by sorting the event boundaries.</p><h3>Trying it in PHP</h3><p>Install the package:</p><pre>composer require alkin/capacity-availability:^1.0</pre><p>Here’s the same example using the public API:</p><pre>10:00-11:00; latest start: 10:15</pre><p>That last field is worth highlighting: <strong>10:15 is a valid starting time</strong>. A 45-minute booking starting at 10:15 ends at 11:00, exactly at the exclusive boundary.</p><p>If your UI only offers 15-minute slots, it can choose to display 10:00 and 10:15. But the calculation itself shouldn’t impose that grid.</p><p>The library also exposes canBook() for an exact interval and timeline() for inspecting capacity, occupancy, and free units.</p><h3>The important distinction: available is not reserved</h3><p>So far, we’ve solved a deterministic calculation. We have <strong>not</strong> solved concurrent booking.</p><p>Imagine two requests arriving at the same time. Each reads the database and sees two free places. Each wants two places. Both call canBook(), both get true, and both insert their booking.</p><p>The calculation can be completely correct while the final database state is overbooked.</p><p>That’s why the library separates the pure algorithm from an <strong>optional Doctrine DBAL adapter</strong> for a particular MariaDB/InnoDB schema.</p><p>The adapter’s booking path is, in simplified terms:</p><pre>BEGIN TRANSACTION SELECT pool_id FROM capacity_pools WHERE pool_id = :pool FOR UPDATE -- Read capacity and overlapping bookings -- Recalculate availability while holding the pool lock -- Insert only when the request fits COMMIT</pre><p>The stable pool row acts as the synchronization point. Independent writers for the same pool must acquire that lock <strong>before</strong> reading the snapshot used for a write decision.</p><p>This comes with a serious condition: <strong>every code path that changes capacity or reservations for that pool must follow the same locking protocol</strong>. A cancellation, reschedule, import, or manual SQL update that bypasses it can invalidate the guarantee.</p><p>The adapter also intentionally does not provide idempotency, automatic deadlock retries, or arbitrary ORM mappings. It rejects nested transactions; its behavior was verified for the documented MariaDB setup, not every database engine or isolation configuration.</p><p>I would rather document these boundaries clearly than hide them behind a convenient-looking API.</p><h3>Testing two different kinds of correctness</h3><p>There were two separate questions to test:</p><p><strong>Is the algorithm giving the correct answer?</strong></p><p>Alongside ordinary unit tests, I used an independent reference implementation that samples every minute-or every second for smaller calendars-and compares all possible starts against the sweep-line result.</p><p>The release was checked using <strong>300 randomized minute-resolution calendars</strong>, <strong>80 second-resolution calendars</strong>, and <strong>77,525 reference assertions</strong>, plus unit tests and static analysis.</p><p><strong>Does the database adapter prevent the race?</strong></p><p>This needed actual concurrent processes, not two sequential method calls.</p><p>In an isolated MariaDB 11.3.2 test database, I ran scenarios with independent PHP workers. The suite includes an intentionally unsafe example that demonstrates overbooking, followed by properly locked transactions.</p><p>The recorded result was <strong>12 scenarios, 43 independent PHP processes, and 198 assertions</strong>. The unsafe test is deliberately confined to disposable test data.</p><p>Those tests are useful evidence for the documented design; they are not a promise that every application integration is automatically safe.</p><h3>Why this isn’t a Symfony bundle</h3><p>I work primarily with Symfony, and the early experiments included a real Symfony application using DoctrineBundle. It was tempting to package everything as a Symfony bundle.</p><p>But the calculation itself doesn’t need Symfony. It just takes arrays of immutable value objects and returns results.</p><p>In a Symfony application, the calculator can be registered as a normal service:</p><pre># config/services.yaml services : Alkin\CapacityAvailability\AvailabilityCalculator : ~</pre><p>That was enough to integrate the core using dependency injection. The optional Doctrine classes can be registered similarly when the application uses the documented persistence schema.</p><p>A bundle may make sense one day if it provides meaningful integration behavior. Adding one merely to wrap a service registration would increase maintenance without solving another problem.</p><h3>Where it stops</h3><p>CapacityAvailability is not a complete booking platform.</p><p>It does not handle recurring calendars, holidays, payments, user permissions, named individual resources, or multi-pool optimization. It also doesn’t magically adapt its database writer to an existing application’s schema.</p><p>What it does offer is a focused solution to one recurring question:</p><blockquote><em>Given changing capacity and overlapping usage, when does a request fit for its </em><strong><em>entire duration</em></strong><em>?</em></blockquote><p>Keeping that boundary explicit is part of the design.</p><p>The project is open source under MIT, supports PHP 8.2+, and the calculation core has no required runtime dependencies.</p><p>If you’ve solved a similar scheduling or capacity problem, I’d be interested in the edge cases you ran into-especially where the simple interchangeable-capacity model stops being sufficient.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/when-counting-overlapping-bookings-is-not-enough-capacity-aware-availability-in-php-3pam"><em>https://dev.to</em></a><em> on October 21, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d25f76804bf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unsaved Form Changes in Symfony — With and Without Turbo]]></title>
            <link>https://medium.com/@alkinbg/unsaved-form-changes-in-symfony-with-and-without-turbo-deba89bb5015?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/deba89bb5015</guid>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Mon, 19 Oct 2026 20:19:40 GMT</pubDate>
            <atom:updated>2026-10-21T10:12:29.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JEJn5I20f940cjE0.jpeg" /></figure><p>Not every form needs autosave. Sometimes the most useful thing an application can do is ask a simple question before someone navigates away:</p><blockquote><em>You have unsaved changes. Leave this page?</em></blockquote><p>It’s a small detail, but a helpful one on editing screens: account settings, product details, admin forms, or anything that may take a few minutes to fill out.</p><p>I wanted a reusable way to add that behavior to a Symfony form without creating a new form type, adding server-side infrastructure, or writing another one-off JavaScript controller for each project.</p><p>That became <a href="https://github.com/alkinbg/UnsavedFormBundle">Unsaved Form Bundle</a>, a small open-source Symfony UX bundle built around one Stimulus controller. Version <strong>1.0.0</strong> is available on <a href="https://packagist.org/packages/alkin/unsaved-form-bundle">Packagist</a>.</p><p>This post is about the convenience itself, how to use it, and some less obvious browser and Turbo behaviors worth understanding before relying on any unsaved-changes warning.</p><h3>Why beforeunload alone is not quite enough</h3><p>For a traditional page, the starting point is familiar:</p><p>That illustrates the native browser mechanism, but it isn’t a complete implementation. We still need to determine whether a form really changed, stop warning after a successful save, and avoid warnings when an ordinary submission is already in progress.</p><p>And once Turbo is involved, some navigations replace content without unloading the document at all.</p><p>For example:</p><ul><li><strong>Turbo Drive</strong> can visit a different page without a full browser reload.</li><li><strong>Turbo Back/Forward</strong> restoration doesn’t fire turbo:before-visit.</li><li><strong>Turbo Frames</strong> can replace only the part of the page containing the form.</li><li><strong>Turbo Streams</strong> can replace or remove the form without changing the URL.</li></ul><p>Those are separate events in <a href="https://turbo.hotwired.dev/reference/events">Turbo’s documented lifecycle</a>. A guard that listens only to beforeunload can miss them.</p><p>The goal wasn’t to build a form framework. It was to make this small piece of behavior reusable.</p><h3>Add it to a Symfony form</h3><p>The package requires <strong>PHP 8.2+</strong>, <strong>Symfony 7.4 or 8.x</strong>, and a supported <strong>Symfony StimulusBundle</strong> integration. It works in applications with or without Symfony UX Turbo.</p><p>Install the stable 1.x release:</p><pre>composer require &quot;alkin/unsaved-form-bundle:^1.0&quot;</pre><p>In a standard Symfony UX setup, Symfony Flex registers the bundle and the Stimulus controller. It’s worth checking config/bundles.php, assets/controllers.json, and the application&#39;s frontend configuration after installation.</p><p>Then add a controller to the <strong>form element</strong>:</p><p>That’s the basic integration. The message and indicator are optional; the form does not need an extra controller action or a database table.</p><p>The optional indicator becomes visible while the form has unsaved changes. As with other dynamic UI messages, check that its accessibility behavior fits your own form and assistive-technology setup.</p><h3>It is not limited to Symfony Forms</h3><p>The controller attaches to a regular HTML &lt;form&gt; element too:</p><p>You still need StimulusBundle and the frontend assets to be loaded. Turbo is optional.</p><h3>A change is not the same as a touched field</h3><p>An important design choice is to compare a form’s current values with its starting values rather than remember whether an input event happened at some point.</p><p>Consider this simple sequence:</p><p>The form should be considered clean again.</p><p>The controller takes a snapshot of relevant form values and compares against that baseline. It accounts for ordinary text fields, checkboxes, radio buttons, selects, textareas, and selected files. It also reacts to resets and detects changes made programmatically when it checks the form before navigation.</p><p>Sometimes a value should not affect the warning, such as a purely client-side helper field. It can be excluded:</p><p>The attribute can also be placed on a wrapper around fields that should be ignored.</p><h3>What happens with Turbo?</h3><p>For normal Turbo Drive visits, the controller can ask for confirmation before the visit begins. For native browser navigation, it relies on the browser’s beforeunload dialog.</p><p>History restoration needs different handling. Turbo explicitly does <strong>not</strong> emit turbo:before-visit for Back/Forward navigation, so that event alone cannot protect an edited form. The bundle also uses browser history information where available and keeps the original form state in page memory so a cached Turbo render does not simply turn an unsaved form into a new, apparently clean one.</p><p>Frames and Streams are another case: they can remove or replace an edited form <em>without leaving the page</em>. The bundle listens to their render lifecycle and asks for confirmation when the pending update would affect that form. Unrelated frame or stream updates can continue.</p><p>There’s one more detail that’s easy to overlook: <strong>validation failures</strong>.</p><p>A Symfony form submitted through Turbo may return an HTTP <strong>422</strong> response containing validation errors and re-rendered form markup. That is not a successful save. The new form should still be treated as containing unsaved edits, rather than resetting its baseline just because new HTML appeared.</p><p>These behaviors are why the controller grew beyond a short beforeunload snippet. They are also why I would not judge a navigation guard only by a couple of happy-path unit tests.</p><h3>Submission and custom JavaScript</h3><p>A regular form submission should not trigger an unnecessary leave-page warning simply because the browser is submitting the form.</p><p>For Turbo submissions, the controller follows Turbo’s submission lifecycle. A successful response can mark the current state clean; an unsuccessful one should keep the unsaved state. For an application that saves via custom AJAX code outside that lifecycle, the controller exposes a small method, <strong>markClean()</strong>, which the application can call after the server has confirmed a successful save.</p><p>This is deliberate: the bundle does <strong>not</strong> guess that a click on a Save button means data was persisted.</p><p>It also emits an alkin--unsaved-form-bundle--guard:change event with event.detail.dirty if you want to update other UI elements when the dirty state changes.</p><h3>What this does not promise</h3><p>It’s important to keep the scope clear.</p><p><strong>It is a navigation warning, not a draft storage system.</strong> It does not store edits in a database or localStorage, automatically save to the server, or guarantee recovery after a tab or browser process disappears. The temporary state used during Turbo restoration lives in the page&#39;s JavaScript memory.</p><p>Browsers also control native unload dialogs. They may require prior user interaction, they choose the dialog text, and on some mobile or OS-initiated termination paths they may not show a prompt at all. This is a browser constraint, not something a Symfony bundle can override. <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event">MDN’s </a><a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event">beforeunload documentation</a> explains the limitations.</p><p>Similarly, the history behavior depends on modern browser APIs being available. And if unrelated application code deliberately destroys a form outside the supported navigation and Turbo lifecycle, that code needs to coordinate with the guard.</p><p>Those boundaries matter more than a claim that it can “never lose changes.” If an application needs guaranteed draft recovery, it should implement actual persistence or autosave separately.</p><h3>Testing beyond a single browser</h3><p>For the <strong>v1.0.0</strong> release, the project includes <strong>29 JavaScript unit tests</strong> and real-browser navigation scenarios using Playwright and Turbo 8. Its CI checks <strong>Chromium, Firefox, and WebKit</strong>, alongside PHP 8.2/8.4 checks.</p><p>The browser scenarios exercise ordinary and Turbo navigation, rejected and approved Back/Forward visits, Frames, destructive Streams, form submission, and an HTTP 422 validation response. The file-input scenario checks that declining a history navigation doesn’t discard a selected file in the tested browser behavior.</p><p>That doesn’t prove every browser version or integration is perfect. It does make regressions in those specific paths easier to detect.</p><p>If you’re evaluating this for your own project, I would still test it against the way your application uses Turbo, especially if you have custom morphing, unusual form markup, or JavaScript that replaces parts of the DOM.</p><h3>A small convenience, not another form framework</h3><p>Symfony already gives us excellent form, validation, and frontend tools. I didn’t want another layer around them just to display one warning.</p><p>Unsaved Form Bundle is meant to stay narrow: <strong>one opt-in Stimulus controller for a behavior that can be useful in many editing screens</strong>. It won’t suit every application, and it doesn’t need to.</p><p>The source, usage notes, limitations, and tests are available on <a href="https://github.com/alkinbg/UnsavedFormBundle">GitHub</a>. The package is on <a href="https://packagist.org/packages/alkin/unsaved-form-bundle">Packagist</a>.</p><p>If you try it and run into a reproducible edge case, a small example and the browser/Turbo versions would be especially helpful. That’s often more useful than a long feature wishlist.</p><p><em>Cover photo: </em><a href="https://www.pexels.com/photo/close-up-of-programmer-typing-code-on-laptop-36496927/"><em>Jakub Zerdzicki on Pexels</em></a><em>, used under the </em><a href="https://www.pexels.com/license/"><em>Pexels License</em></a><em>.</em></p><p><em>Originally published at </em><a href="https://dev.to/alkin/unsaved-form-changes-in-symfony-with-and-without-turbo-2ob5"><em>https://dev.to</em></a><em> on October 19, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=deba89bb5015" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One Symfony Form, Two Views: Read-Only Summaries Without Duplication]]></title>
            <link>https://medium.com/@alkinbg/one-symfony-form-two-views-read-only-summaries-without-duplication-8520a8307fc1?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/8520a8307fc1</guid>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Wed, 14 Oct 2026 12:21:21 GMT</pubDate>
            <atom:updated>2026-10-14T13:13:39.826Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ax9mVWRDwta3IPeb.png" /></figure><p>A form often has a second life.</p><p>First, someone uses it to enter or update information. Then, somewhere else in the application, someone needs to <em>read</em> that same information: on a confirmation screen, an internal detail page, or a review step before submitting a request.</p><p>The editable form is already there. Yet the read-only version frequently becomes another Twig template, with another list of fields, another set of labels, and sometimes another set of rules for displaying their values.</p><p>This is not a serious architectural failure. Writing a dedicated template is perfectly reasonable. But when an application contains many structured forms, a small amount of repeated presentation code can become a surprisingly persistent maintenance task.</p><p>I wanted to explore a modest alternative: <strong>what if a read-only view could reuse the information we have already given to Symfony’s Form component?</strong></p><p>That question led to <a href="https://github.com/alkinbg/FormSummaryBundle">FormSummaryBundle</a>, a small open-source bundle with a deliberately limited purpose.</p><h3>The duplication is easy to miss</h3><p>Consider a delivery form with a carrier, status, pallet count, and a confirmation checkbox. The status field might be defined like this:</p><p>The stored value is ready, but the label shown to the user is <strong>Ready to load</strong>.</p><p>Now imagine a separate read-only Twig template:</p><p>There is nothing inherently wrong with this template. The problem is that part of the form’s presentation contract now exists in two places.</p><p>If the status labels change, someone has to remember to update the detail view. If the form gains a field, the read-only version might need a matching change. If the application supports multiple languages, the two views must agree on translation domains and parameters. Formatting an empty value, a date, or a monetary amount introduces similar decisions.</p><p>This matters less for a single form. It matters more when you repeat the pattern across many forms and screens.</p><h3>Symfony already gives us most of the ingredients</h3><p>Symfony Forms are not simply a collection of HTML inputs. They hold information about field types, labels, choices, translation settings, and transformations between application data and values used for display.</p><p>When we call createView(), Symfony produces a FormView containing the information its rendering layer needs. And Symfony already exposes helpers such as <a href="https://symfony.com/doc/current/form/form_customization.html">field_label() and </a><a href="https://symfony.com/doc/current/form/form_customization.html">field_value()</a>, along with an established <a href="https://symfony.com/doc/current/form/form_themes.html">form-theming system</a>.</p><p>That distinction is important. <strong>FormSummaryBundle does not invent a new form model, replace Symfony’s rendering system, or claim that this information was previously inaccessible.</strong></p><p>It provides a convenience on top of those capabilities: a complete read-only representation, with common field types handled consistently, without manually mapping every field into a second template.</p><p>The entire basic API is one Twig call:</p><p>The interesting part is not the line itself. It is how much existing form information that line can reuse.</p><h3>A complete example</h3><p>Here is a small form type using only standard Symfony fields.</p><p>For this demonstration, the form is populated with an array. A real application could use its normal entity, DTO, or other data structure instead.</p><p>And the view is just:</p><p>The default output is a semantic HTML description list, conceptually equivalent to:</p><p>Notice four things:</p><ol><li><strong>The choice label is preserved.</strong> The summary displays <em>Ready to load</em>, not the underlying ready value.</li><li><strong>Zero stays zero.</strong> A pallet count of 0 is not treated as missing data.</li><li><strong>False is meaningful.</strong> The unchecked checkbox becomes <em>No</em> in the default English translation.</li><li><strong>Labels have a single source.</strong> The summary reuses the labels already configured on the form.</li></ol><p>These are small details, but they are exactly the details that tend to diverge when we maintain separate representations by hand.</p><h3>Why this is more than a loop over fields</h3><p>A simple Twig loop could handle text fields quite well. Real Symfony forms, however, contain values whose display representation is not always their raw value.</p><h3>Choice fields</h3><p>A ChoiceType has its own mapping between submitted values and user-facing labels. A multiple-choice field may contain several selected values, grouped choices, or preferred choices. The summary uses existing choice views rather than inventing another label map.</p><p>This also applies to standard choice-derived types, including enum choices.</p><h3>Dates and times</h3><p>Symfony can render dates and times as single-text widgets or as compound fields containing individual components. The bundle works with those view representations. It respects the configured date pattern for supported compound dates and preserves the transformed view value for single-text fields.</p><p>It does <strong>not</strong> promise to localize every date into a new, independently chosen format. That is a responsibility worth keeping explicit.</p><h3>Nested forms and collections</h3><p>A form can contain a nested form or a collection of fields. The summary follows the existing FormView children and produces nested description lists. It summarizes the entries already in the form view, not collection prototypes intended for client-side additions.</p><h3>Missing values</h3><p>By default, an absent text value is displayed as an em dash. The caller can choose another placeholder:</p><p>The same placeholder is used for missing components of partial compound dates and times. Values such as 0 and false remain distinct from an empty string or null.</p><p>The aim is consistency, not magic.</p><h3>You do not have to summarize the whole form</h3><p>Sometimes a full description list is unnecessary. Perhaps a card only needs one label/value pair, or a sentence needs the human-readable label of a selected choice.</p><p>Two smaller helpers are available:</p><p>form_summary_row() renders one labeled row; form_summary_value() renders only the value.</p><p>Another useful detail: rendering a summary does not mark the original form view’s fields as rendered. An application can still render editable widgets from the same view, before or after showing the summary.</p><p>That makes the approach useful for review panels alongside editable forms, without turning a read-only representation into a set of disabled inputs.</p><h3>Two kinds of customization</h3><p>I wanted customization to remain close to the conventions Symfony developers already know, rather than introduce another configuration language.</p><h3>1. Control the value at the form level</h3><p>For a field whose ordinary view value is not what we want to display, the bundle provides a summary_value option:</p><p>The callback runs when the value is summarized. It should be deterministic and free of side effects, because rendering the same summary again evaluates it again.</p><p>The default theme treats the result as text and escapes it. A custom scalar value is not a shortcut for injecting raw HTML.</p><h3>2. Control the markup with a form theme</h3><p>Symfony already has a mechanism for overriding how field types are rendered. The bundle adds summary-specific blocks to that mechanism.</p><p>For example, an application can provide a Twig form theme:</p><p>And apply it to the view:</p><p>Summary-specific blocks include form_summary, form_summary_row, form_summary_value, and type-specific variations such as choice_summary_value.</p><p>The default theme does not load a stylesheet or replace normal editable widget blocks. A project can style the provided classes or override the markup to fit its design system.</p><p>There is no requirement to adopt Bootstrap, Tailwind, or another UI framework.</p><h3>The security boundary is worth stating clearly</h3><p>A read-only summary is <strong>not</strong> an authorization mechanism.</p><p>The bundle omits types such as password, hidden, file, repeated, and button fields. This keeps tokens, file inputs, and other inappropriate controls out of the default summary.</p><p>An application can also exclude a regular field:</p><p>But a field containing sensitive data may still be an ordinary TextType. No general-purpose form renderer can determine who is entitled to see that data.</p><p>The application must continue to enforce access control, select the correct data for the user, and decide what should appear on each page. Likewise, displaying a submitted form does not make its data valid: confirmation flows still need the application’s normal submission and validation checks.</p><p>The default summary theme escapes text and choice labels. Custom themes remain application code, so developers should preserve escaping and avoid applying raw to untrusted data.</p><p>It is better to describe this boundary clearly than to promise safety a presentation package cannot provide.</p><h3>When I would use it — and when I would not</h3><p>I find this abstraction useful when a read-only screen closely follows the structure of an existing form: confirmation pages, internal inspection views, structured administrative details, or review sections in operational software.</p><p>It can also reduce routine maintenance. When a label or a choice changes in the form, the summary continues to use the form’s current metadata, rather than a separately maintained mapping.</p><p>But I would <strong>not</strong> use it automatically on every detail page.</p><p>A dashboard with calculated KPIs, a domain-specific timeline, or a carefully designed customer-facing profile may deserve its own view model and template. A screen that combines data from several sources may not correspond to a form at all. Even for a simple form, five explicit lines of Twig may be more understandable than introducing a dependency.</p><p>The question is not whether the bundle can render the data. The question is whether <strong>the form’s existing structure is the right structure for the read-only presentation</strong>.</p><p>If the answer is yes, reuse makes sense. If the answer is no, a dedicated template is often the cleaner design.</p><p>That trade-off is intentional.</p><h3>What the bundle deliberately does not do</h3><p>To keep its responsibilities narrow, FormSummaryBundle does not:</p><ul><li>validate submissions or enforce authorization;</li><li>query entities to build a separate read model;</li><li>persist or modify data;</li><li>generate PDFs or send emails;</li><li>implement a multi-step workflow; or</li><li>automatically understand every possible custom compound field.</li></ul><p>It renders from an already created FormView. Creating that form view may still involve normal Symfony transformations or choice loading, and a more specialized field can use summary_value or a custom summary theme block.</p><p>This is a small convenience layer, not another application framework.</p><h3>Installation and compatibility</h3><p>The package is published on <a href="https://packagist.org/packages/alkin/form-summary-bundle">Packagist</a>:</p><pre>composer require &quot;alkin/form-summary-bundle:^1.0&quot;</pre><p>If your application does not register the bundle automatically, add it to config/bundles.php:</p><p>There is no separate summary schema to configure. Create your Symfony form as usual, pass its FormView to Twig, and use form_summary().</p><p>Version <strong>1.0.0</strong> targets PHP 8.2+ and compatible Symfony 6.4, 7.4, and 8.x applications. The repository’s CI matrix covers combinations of PHP 8.2–8.5 and Symfony 6.4, 7.4, 8.0, and 8.1, as well as lower supported dependency versions and installation of the exported package without development dependencies.</p><p>The test suite includes 94 PHPUnit tests with 214 assertions. Among the tested behaviors are escaping, translated choice labels, excluded fields, zero and false values, compound dates, and compatibility with editable form themes.</p><p>Tests cannot guarantee that every custom form behaves identically, but they provide a useful baseline for maintaining a small public API.</p><p>For the full option reference, supported field types, theme overrides, and known limitations, see the <a href="https://github.com/alkinbg/FormSummaryBundle#readme">README</a>.</p><h3>A final thought</h3><p>The most satisfying part of this project was not creating a new rendering system. It was realizing that Symfony already gives us much of what we need.</p><p>There is a place for dedicated, carefully designed templates. There is also a place for a small utility that removes a repeated task without changing how the rest of an application works.</p><p><strong>When the form already describes the information we want to show, reusing that description can be simpler than writing it all again.</strong></p><p>That is the entire idea behind FormSummaryBundle.</p><p>The source is available on <a href="https://github.com/alkinbg/FormSummaryBundle">GitHub</a>, and the package is available on <a href="https://packagist.org/packages/alkin/form-summary-bundle">Packagist</a>. Feedback is welcome, particularly from developers working with nested forms and custom field types. Those are often the places where a small abstraction reveals both its value and its limits.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/one-symfony-form-two-views-read-only-summaries-without-duplication-1458"><em>https://dev.to</em></a><em> on October 14, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8520a8307fc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Kaizen Thinking to Symfony Debugging]]></title>
            <link>https://medium.com/@alkinbg/applying-kaizen-thinking-to-symfony-debugging-0d12ce9fcfd2?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d12ce9fcfd2</guid>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Sat, 10 Oct 2026 07:13:27 GMT</pubDate>
            <atom:updated>2026-10-10T12:49:25.900Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-3TvePH1LtIigmbL.png" /></figure><p><em>Introducing Novora KaizenBundle 1.0 — a small, Lean-inspired approach to investigating recurring application issues.</em></p><p>When working on a Symfony application, logs are often the first place we look when something goes wrong.</p><p>We find an exception, investigate it, make a correction, and move on.</p><p>But sometimes the same issue returns. Or we discover that a particular warning has been appearing for days without anyone noticing how frequently it occurs.</p><p>That made me interested in a simple question:</p><p><strong>Could we make the process of identifying, investigating, and reviewing recurring problems a little more structured, without introducing another monitoring platform?</strong></p><p>This question led to <strong>Novora KaizenBundle</strong>, a small open-source package for Symfony.</p><p>Version 1.0 is now available on <a href="https://packagist.org/packages/novora/kaizen-bundle">Packagist</a>.</p><h3>The idea behind the bundle</h3><p>In Lean thinking, <em>Kaizen</em> describes continuous improvement through observation, analysis, and incremental changes.</p><p>These principles are not new, and neither are the techniques used in this bundle.</p><p>Pareto analysis, Ishikawa diagrams, the 5 Whys, and PDCA have existed for a long time. Error grouping and monitoring are also well-established areas of software engineering.</p><p>The intention here is not to reinvent them or replace existing tools.</p><p>Instead, I wanted to explore how a few of these ideas might fit into an everyday Symfony troubleshooting workflow.</p><p>The result is a deliberately small application-level tool with three main steps.</p><h3>1. Identify recurring patterns</h3><p>Novora KaizenBundle reads existing Monolog log files and groups records using fingerprints derived from their severity, channel, and message.</p><p>It applies limited normalization to certain dynamic values, such as UUIDs and timestamps, before grouping.</p><p>The dashboard uses a Pareto-style chart to show which patterns occur most frequently within the available log sample.</p><p>This can help answer a modest but useful question:</p><p><strong>Which recurring technical symptoms might deserve attention first?</strong></p><p>Frequency is not the same as importance. A rarely occurring exception may have a far greater impact than a frequently logged warning.</p><p>The chart is a starting point for investigation, not an automatic priority decision.</p><h3>2. Document the investigation</h3><p>Once a recurring pattern looks worth examining, a developer can open an investigation.</p><p>The bundle provides a small workspace inspired by familiar Lean techniques:</p><ul><li><strong>Gemba:</strong> record what was actually observed.</li><li><strong>Ishikawa:</strong> organize possible contributing causes.</li><li><strong>5 Whys:</strong> explore the reasoning behind a problem.</li><li><strong>PDCA:</strong> document the intended change, its implementation, observations, and follow-up actions.</li></ul><p>These methods are aids, not mandatory rituals.</p><p>A small issue does not necessarily need a complete Ishikawa analysis or five written explanations.</p><p>One design decision I consider important is that <strong>a hypothesis cannot be marked as confirmed without supporting evidence</strong>.</p><p>The bundle does not discover root causes automatically. The developer remains responsible for determining whether the evidence is sufficient.</p><h3>3. Review what happened after a change</h3><p>Fixing an exception and observing that it no longer appears are two different things.</p><p>For investigations linked to a log fingerprint, the bundle allows a correction timestamp to be recorded.</p><p>It can then compare matching log-event counts over equal periods before and after that timestamp, using at most a 24-hour comparison window.</p><p>It also checks for later occurrences still present in the available sample.</p><p>This does not prove that a problem has been permanently resolved.</p><p>A quiet log might mean the correction helped. It might also mean the relevant operation was not executed again, or that older logs have already been rotated.</p><p>The bundle therefore reports the observed counts and limitations rather than automatically declaring success.</p><h3>A small example</h3><p>Consider this simplified, entirely synthetic log entry:</p><pre>[2026-10-10T08:00:00+00:00] app.ERROR: Cache directory is not writable [] []</pre><p>Suppose the same message appears repeatedly.</p><p>The dashboard can group those matching entries and make their frequency visible.</p><p>A developer may then open an investigation, check the actual filesystem permissions and process identity, and record the findings.</p><p>If the evidence supports a permission problem, the developer can document a corrective action.</p><p>After applying the correction, the developer records when it was made and reviews the matching log entries before and after that point.</p><p>If the same fingerprint appears again, there is a concrete reason to investigate further.</p><p>If it does not appear, the observation is recorded — but the case is not automatically considered resolved.</p><p>This example illustrates the intended workflow. <strong>It is not a production case study or evidence of measured time savings.</strong></p><h3>Keeping the implementation small</h3><p>The bundle is built for PHP 8.2+ and Symfony 7.4 or 8.x.</p><p>It works with existing supported Monolog file formats, provides a small administrator interface, and stores investigations in local JSON files.</p><p>It does not require its own database schema, external APM server, or hosted telemetry service.</p><p>An optional correlation feature can attach execution identifiers to new HTTP, CLI, and Messenger log records, provided the host application has the appropriate Monolog integration.</p><p>Existing log entries are not retroactively correlated.</p><p>Installation is available through Composer:</p><pre>composer require novora/kaizen-bundle:^1.0</pre><p>The bundle must then be registered and configured in the Symfony application. The administrator routes require authentication and ROLE_ADMIN access, and the configured log and investigation directories need appropriate filesystem permissions.</p><p>The complete setup instructions are available in the <a href="https://github.com/alkinbg/Novora-KaizenBundle#readme">README</a>.</p><h3>What version 1.0 does not do</h3><p>There are important limitations worth making clear.</p><p>The bundle reads a bounded portion of a configured log file — 2 MiB by default — rather than collecting complete application history.</p><p>Its fingerprinting is heuristic. Different errors may occasionally be grouped together, while variations of the same underlying problem may form separate groups.</p><p>Its before-and-after comparison uses observed log counts, not traffic-normalized failure rates.</p><p>It does not provide distributed tracing, automatic root-cause analysis, alerting, or multi-server monitoring.</p><p>Investigation storage is local and intended for a single shared-writer environment. Display redaction is best-effort and should never be treated as permission to log credentials or personal information.</p><p>These are conscious limitations of the first version, not capabilities hidden behind a configuration option.</p><p>For many applications, an established monitoring or error-tracking platform will be the more appropriate choice.</p><h3>Why release it?</h3><p>There is no shortage of debugging tools, dashboards, or methodologies.</p><p>I do not expect this bundle to change that landscape.</p><p>The idea is simply to offer another small option for Symfony developers who already have application logs and would like a structured way to move from recurring technical symptoms to documented investigations.</p><p>Version 1.0 has automated tests and has been exercised in separate Symfony 7.4/PHP 8.2 and Symfony 8.1/PHP 8.4 test applications.</p><p>That verifies specific behavior and compatibility scenarios. It does not establish how much time the tool saves in real-world development teams.</p><p>I would rather learn that from actual users than make claims I cannot support.</p><p>If the bundle proves useful, it can improve incrementally. If parts of the workflow feel unnecessary, simplifying them may be more valuable than adding new features.</p><p>That, to me, is very much in the spirit of Kaizen.</p><h3>Open source</h3><p><strong>Novora KaizenBundle 1.0</strong> is available under the MIT License.</p><p>The source code, documentation, and tests are public:</p><p><strong>GitHub:</strong> <a href="https://github.com/alkinbg/Novora-KaizenBundle">https://github.com/alkinbg/Novora-KaizenBundle</a></p><p><strong>Packagist:</strong> <a href="https://packagist.org/packages/novora/kaizen-bundle">https://packagist.org/packages/novora/kaizen-bundle</a></p><p>Feedback, bug reports, and focused contributions are welcome.</p><p>The goal is not to build the biggest tool — just something small enough to understand and useful enough to keep around.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/applying-kaizen-thinking-to-symfony-debugging-36pb"><em>https://dev.to</em></a><em> on October 10, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d12ce9fcfd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lean Software Development in Practice: Finding Muda in Four PHP Projects]]></title>
            <link>https://medium.com/@alkinbg/lean-software-development-in-practice-finding-muda-in-four-php-projects-e29a18e7245a?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/e29a18e7245a</guid>
            <category><![CDATA[lean]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[muda]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 11:25:30 GMT</pubDate>
            <atom:updated>2026-09-28T11:43:07.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xoakjxOtCaiXsI9a.png" /></figure><p>Lean has one word that I like because it is brutally simple: <strong>Muda</strong>.</p><p>Waste.</p><p>In a factory, waste is often visible. Extra movement. Waiting. Too much inventory. Producing something before it is needed.</p><p>In software, it is much better at hiding.</p><p>An unused abstraction does not block a corridor. A feature nobody asked for does not sit on a pallet. A public API that became too large does not look like inventory.</p><p>But all of them still cost something.</p><p>They have to be designed, written, tested, documented and maintained. And once other developers start depending on them, removing them becomes much harder than adding them.</p><p>That made me look at four of my own open-source PHP projects from a slightly different angle.</p><p>Three are Symfony bundles:</p><p>The fourth is a standalone CLI tool:</p><p>I have already written separate technical articles about all four projects:</p><p>This time, I do not want to explain again how the packages work.</p><p>The more interesting question is:</p><blockquote><strong><em>What did I deliberately choose not to build?</em></strong></blockquote><p>That is where the Lean part becomes interesting.</p><h3>Muda is not the same as “more code”</h3><p>This was the first thing I had to be careful about.</p><p>Lean software development does <strong>not</strong> mean deleting code until everything is small.</p><p>Sometimes more code is exactly what prevents a real failure.</p><p>For example, in HttpIdempotencyBundle the idempotency record is read again after acquiring the lock.</p><p>That is extra work.</p><p>It is also necessary.</p><p>Another request may have completed the operation between the first read and the moment the lock was acquired. Skipping the second read would make the code shorter, but also wrong.</p><p>The same happens in OptimisticConcurrencyBundle.</p><p>The HTTP layer checks If-Match, but Doctrine still performs its own optimistic-lock check during flush().</p><p>Two checks.</p><p>Two different race windows.</p><p>Both useful.</p><p>So the question is not:</p><blockquote><em>How can this be done with fewer lines?</em></blockquote><p>A better question is:</p><blockquote><strong><em>Does this complexity protect something real, or does it exist only because it might be useful one day?</em></strong></blockquote><p>That difference matters.</p><h3>OptimisticConcurrencyBundle: do not build concurrency twice</h3><p>Repository: <a href="https://github.com/alkinbg/optimistic-concurrency-bundle">github.com/alkinbg/optimistic-concurrency-bundle</a></p><p>Earlier article: <a href="https://dev.to/alkin/preventing-lost-updates-in-symfony-apis-with-etags-and-doctrine-1h57">Preventing Lost Updates in Symfony APIs with ETags and Doctrine</a></p><p>The bundle solves a specific problem: preventing stale clients from silently overwriting newer data.</p><p>A resource can expose an ETag:</p><p>and a write can require the client to send the same representation version back:</p><p>There is an obvious temptation here.</p><p>Once you start solving concurrency, it is easy to keep going.</p><p>The bundle could maintain its own entity versions.</p><p>It could introduce its own locking mechanism.</p><p>It could control transactions.</p><p>It could call flush().</p><p>It could become “the concurrency layer”.</p><p>But Doctrine already has optimistic locking through #[ORM\Version].</p><p>So the bundle does not replace it.</p><p>The HTTP layer answers:</p><blockquote><em>Is the representation used by this client stale?</em></blockquote><p>Doctrine answers:</p><blockquote><em>Did the entity change before the database write completed?</em></blockquote><p>That division is useful.</p><p>Building a second persistence-level concurrency system would not remove the need for Doctrine’s protection. It would mostly add another implementation to understand and another set of failure cases to maintain.</p><p>That is a form of Muda I see quite often in software:</p><p><strong>rebuilding something that another layer already does well.</strong></p><p>There is another small detail in this project that I now appreciate more.</p><p>The supported public API is intentionally small.</p><p>Most implementation classes are internal, and there is an architecture test that protects that boundary.</p><p>Why care?</p><p>Because every public class is a promise.</p><p>If someone starts depending on it, changing it later becomes a backward-compatibility problem.</p><p>A large public API can easily become a kind of inventory: things you now have to keep carrying even when you no longer want them.</p><p>Sometimes the Lean choice is not removing code.</p><p>Sometimes it is simply <strong>not exposing it</strong>.</p><h3>MaskedBundle: do not try to detect every secret in the universe</h3><p>Repository: <a href="https://github.com/alkinbg/masked-bundle">github.com/alkinbg/masked-bundle</a></p><p>Earlier article: <a href="https://dev.to/alkin/i-made-a-symfony-bundle-for-masking-sensitive-data-3b1f">I Made a Symfony Bundle for Masking Sensitive Data</a></p><p>MaskedBundle started from a practical problem.</p><p>Sensitive data can end up in logs.</p><p>Once you start thinking about automatic detection, the feature list grows very quickly.</p><p>Passwords.</p><p>API tokens.</p><p>JWTs.</p><p>Session IDs.</p><p>Private keys.</p><p>Database credentials.</p><p>Cloud access keys.</p><p>Payment data.</p><p>It is very easy to imagine a “smart” detector for all of them.</p><p>It is also very easy to create a large pile of heuristics.</p><p>The bundle takes a narrower approach.</p><p>Automatic detection is conservative and currently focuses on payment-card candidates where there is enough structure to make a reasonably confident decision.</p><p>When the application already knows a value is sensitive, it can pass it explicitly:</p><p>That design looks simple, but the reason behind it matters.</p><p>If the application already knows that $token is sensitive, the masking library does not need another complicated heuristic to rediscover that fact.</p><p>Trying to detect everything automatically would mean more regexes, more edge cases and, probably, more false confidence.</p><p>There is also another important choice in the implementation: detection work is bounded.</p><p>If a safety budget is exhausted, masking fails closed instead of continuing an expensive scan forever.</p><p>That is not “less code”.</p><p>It is extra defensive code with a clear purpose.</p><p>The Muda would be adding twenty more speculative detectors just because the architecture allows it.</p><p>This is one of the traps I have started to notice more often:</p><p>A good abstraction makes new features easy.</p><p>And when new features are easy, it becomes very tempting to add them.</p><p>But “easy to add” and “worth adding” are not the same thing.</p><h3>Doctrine Migration Guard: “I don’t know” can be a valid result</h3><p>Repository: <a href="https://github.com/alkinbg/doctrine-migration-guard">github.com/alkinbg/doctrine-migration-guard</a></p><p>Earlier article: <a href="https://dev.to/alkin/catching-risky-doctrine-migrations-before-production-dc">Catching Risky Doctrine Migrations Before Production</a></p><p>Doctrine Migration Guard is probably the clearest example of scope control in these four projects.</p><p>Its job is simple to describe:</p><p>Check Doctrine migration files for risky MySQL and MariaDB operations before they reach production.</p><p>The dangerous part is everything that could be added around that idea.</p><p>The tool could connect to the database.</p><p>It could inspect table size.</p><p>It could understand server versions.</p><p>It could discover pending migrations.</p><p>It could support PostgreSQL.</p><p>It could have a plugin system.</p><p>It could read Git history.</p><p>It could rewrite dangerous SQL.</p><p>Every one of those ideas sounds reasonable.</p><p>That does not mean they belong in version 0.1.</p><p>The first release intentionally understands a narrow migration shape.</p><p>This is straightforward:</p><p>The tool does not try to guess what dynamic PHP code will do.</p><p>It reports the result as incomplete.</p><p>The same happens with SQL constructs that the current analyzer cannot classify safely.</p><p>They become UNANALYZED.</p><p>At first glance, this looks like weakness.</p><p>I think it is the opposite.</p><p>A static analyzer that understands only part of a construct and still returns green is more dangerous than one that says:</p><p>This is where Lean and safety meet quite nicely.</p><p>Supporting every possible migration shape would require much more parsing, much more testing and many more edge cases.</p><p>If the actual value of the first release is catching common risky migrations in CI, then building everything else before that idea proves useful is simply overproduction.</p><p>Software people often call that future-proofing.</p><p>Sometimes it really is.</p><p>Sometimes it is just work arriving too early.</p><h3>HttpIdempotencyBundle: do not promise exactly-once when you cannot deliver it</h3><p>Repository: <a href="https://github.com/alkinbg/http-idempotency-bundle">github.com/alkinbg/http-idempotency-bundle</a></p><p>Earlier article: <a href="https://dev.to/alkin/when-http-retries-become-dangerous-idempotency-in-symfony-without-the-fairy-tales-10l5">When HTTP Retries Become Dangerous: Idempotency in Symfony Without the Fairy Tales</a></p><p>Idempotency is another area where it is very easy to over-promise.</p><p>The bundle protects selected controller actions from accidental duplicate execution when clients retry HTTP requests.</p><p>Protection is explicit:</p><p>It could have been automatic.</p><p>For example:</p><p>“Every POST, PUT and PATCH should be idempotent.”</p><p>That sounds convenient.</p><p>It is also a huge assumption.</p><p>Not every endpoint has the same semantics. Automatically changing every write request would make the bundle responsible for application behavior it cannot fully understand.</p><p>So the controller has to opt in.</p><p>More importantly, the bundle does <strong>not</strong> claim exactly-once execution.</p><p>Because it cannot guarantee it.</p><p>Imagine this:</p><p>A controller calls an external payment provider.</p><p>The payment succeeds.</p><p>Before the completed idempotency record is saved, the PHP process crashes.</p><p>The side effect has already happened.</p><p>No Symfony event subscriber can travel back in time and undo that payment.</p><p>Adding more internal machinery does not change this fundamental failure window.</p><p>So the bundle handles the part it can actually control:</p><p>request identity, fingerprints, shared state, locking and response replay.</p><p>Other guarantees remain where they belong:</p><p>database constraints, transactions, provider-side idempotency, outbox patterns and domain-specific protection.</p><p>For me, this is another form of Lean thinking:</p><p><strong>do not spend complexity trying to create a guarantee your layer cannot honestly provide.</strong></p><p>More code would not make the promise true.</p><p>It would only make the implementation bigger.</p><h3>The interesting part was not what the projects contain</h3><p>After looking at the four repositories this way, something surprised me.</p><p>I expected the best examples of Muda to be dead code, duplicated methods or unnecessary classes.</p><p>Those things matter.</p><p>But the more interesting waste appears earlier.</p><p>It appears when deciding what the software should become.</p><p>In OptimisticConcurrencyBundle, the important decision was not to replace Doctrine.</p><p>In MaskedBundle, it was not to pretend every type of secret can be detected automatically.</p><p>In Doctrine Migration Guard, it was not to support every migration shape in the first release.</p><p>In HttpIdempotencyBundle, it was not to enable idempotency everywhere and not to claim exactly-once execution.</p><p>None of those decisions look impressive in an architecture diagram.</p><p>That may be exactly why they are easy to miss.</p><p>Sometimes avoiding waste does not result in a clever class.</p><p>Sometimes the result is that <strong>the class never gets written</strong>.</p><h3>A small checklist before adding “just one more thing”</h3><p>These are the questions I now try to ask before adding another feature, abstraction or extension point:</p><ol><li>Is there a real use case now, or only a possible future one?</li><li>Does another layer already solve this problem?</li><li>Am I adding an abstraction before I have a second real case for it?</li><li>Am I making the public API larger than necessary?</li><li>If I cannot know something safely, is “unknown” better than a guess?</li><li>Will this feature create enough value to justify its tests, documentation and future compatibility cost?</li></ol><p>I do not always get this right.</p><p>Building things is enjoyable. That is part of the problem.</p><p>A generic solution feels elegant.</p><p>A new extension point feels flexible.</p><p>Another supported scenario makes the README look stronger.</p><p>But every feature creates work after it is merged.</p><p>That part is much less exciting, and much easier to forget.</p><h3>One final thought</h3><p>Lean and software development are not a perfect translation of each other.</p><p>Code is not a production line, and forcing every programming problem into one of the classic Lean wastes would not be very useful.</p><p>But the basic idea behind Muda translates extremely well:</p><p><strong>Effort is not the same as value.</strong></p><p>A complicated solution can be necessary.</p><p>A simple solution can be wrong.</p><p>The goal is not minimal code.</p><p><strong>The goal is to spend complexity where it protects something real.</strong></p><p>That changed one question for me.</p><p>Instead of always asking:</p><blockquote><em>What else should this support?</em></blockquote><p>there is another question that is often more useful:</p><blockquote><em>What happens if this is not built?</em></blockquote><p>Sometimes the answer is:</p><p>Nothing.</p><p>And sometimes that is the best possible result.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/lean-software-development-in-practice-finding-muda-in-four-php-projects-3m7c"><em>https://dev.to</em></a><em> on September 28, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e29a18e7245a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When HTTP Retries Become Dangerous: Idempotency in Symfony Without the Fairy Tales]]></title>
            <link>https://medium.com/@alkinbg/when-http-retries-become-dangerous-idempotency-in-symfony-without-the-fairy-tales-595c9cf81c23?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/595c9cf81c23</guid>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 21:12:35 GMT</pubDate>
            <atom:updated>2026-08-31T05:49:07.033Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-UdXe9FwM7T_elXr.jpg" /></figure><h3>Retries, Race Conditions, and the Limits of HTTP Idempotency in Symfony</h3><p><em>What it really takes to recognize a retry, prevent duplicate execution, and be clear about the guarantees you cannot make.</em></p><p>Retries are one of those things that look harmless until the first time they duplicate a real business operation.</p><p>A request times out, so the client retries it.</p><p>Reasonable.</p><p>But what if the first request actually reached the server?</p><p>What if the application already created the order, reserved the stock, sent the message, or called a payment provider — and only the response was lost?</p><p>From the client’s point of view, the request failed.</p><p>From the application’s point of view, it may already be finished.</p><p>Send the same request again and you can get the worst kind of bug: one that is technically understandable, difficult to reproduce, and very expensive in production.</p><p>This is the problem that pushed me to build <a href="https://github.com/alkinbg/http-idempotency-bundle">HttpIdempotencyBundle</a>, a small Symfony bundle for explicit HTTP request idempotency.</p><p>But the interesting part is not the bundle itself.</p><p>The interesting part is everything that has to be true before we can safely say:</p><blockquote>“This request is a retry of the same operation, so we should not execute it again.”</blockquote><p>And just as importantly, what we <strong>cannot</strong> guarantee.</p><h3>A timeout does not mean the operation failed</h3><p>Consider a simple endpoint:</p><pre>#[Route(&#39;/orders&#39;, methods: [&#39;POST&#39;])]<br>public function createOrder(): JsonResponse<br>{<br>    $order = $this-&gt;orderService-&gt;create();</pre><pre>    return new JsonResponse([<br>        &#39;id&#39; =&gt; $order-&gt;getId(),<br>    ], 201);<br>}</pre><p>Now imagine this sequence:</p><pre>Client -&gt; POST /orders<br>Server -&gt; creates order #742<br>Server -&gt; sends 201 response<br>Network -&gt; connection dies<br>Client -&gt; sees timeout<br>Client -&gt; retries POST /orders</pre><p>Nothing unusual happened.</p><p>The client did exactly what clients often do after a timeout.</p><p>The server did exactly what it was asked to do.</p><p>And yet, unless we have another mechanism in place, we may now create order #743 as well.</p><p>The key idea is simple:</p><p><strong>transport failure and business-operation failure are not the same thing.</strong></p><p>HTTP cannot always tell the client whether the operation happened.</p><h3>Give the operation an identity</h3><p>A common solution is an Idempotency-Key.</p><p>The client generates a unique value for one logical operation and sends it with every retry:</p><pre>POST /orders HTTP/1.1<br>Content-Type: application/json<br>Idempotency-Key: order-7f98b773</pre><pre>{&quot;sku&quot;:&quot;ABC-42&quot;,&quot;quantity&quot;:1}</pre><p>If the request must be retried, the same key is reused.</p><p>That gives the server a stable identity to work with.</p><p>At first, the implementation seems obvious:</p><pre>if ($store-&gt;has($key)) {<br>    return $store-&gt;get($key);<br>}</pre><pre>$response = $controller();</pre><pre>$store-&gt;save($key, $response);</pre><pre>return $response;</pre><p>Unfortunately, this is not enough.</p><p>There are several traps hiding inside those few lines.</p><h3>A key alone is not enough</h3><p>What should happen if a client accidentally reuses the same key for a different request?</p><p>First request:</p><pre>Idempotency-Key: order-7f98b773</pre><pre>{&quot;sku&quot;:&quot;ABC-42&quot;,&quot;quantity&quot;:1}</pre><p>Later:</p><pre>Idempotency-Key: order-7f98b773</pre><pre>{&quot;sku&quot;:&quot;XYZ-99&quot;,&quot;quantity&quot;:10}</pre><p>If we only store the key, the second request might receive the response from the first one.</p><p>That would be worse than simply failing.</p><p>The server must therefore know not only <strong>which key</strong> was used, but also <strong>which request</strong> that key belongs to.</p><p>This is where request fingerprinting becomes important.</p><h3>Fingerprint the request, not just the key</h3><p>A deterministic fingerprint can describe the concrete request.</p><p>For HttpIdempotencyBundle, the default fingerprint includes the important parts of the request, such as:</p><ul><li>HTTP method</li><li>logical operation</li><li>path</li><li>normalized query parameters</li><li>normalized Content-Type</li><li>raw request body</li></ul><p>The result is represented as a SHA-256 digest.</p><p>Conceptually:</p><pre>POST<br>/orders<br>application/json<br>{&quot;sku&quot;:&quot;ABC-42&quot;,&quot;quantity&quot;:1}</pre><p>becomes:</p><pre>sha256(...)</pre><p>Now there are two very different cases.</p><h3>Same key, same fingerprint</h3><p>This is the same logical request again.</p><p>If the first request already completed, we can replay its stored response.</p><h3>Same key, different fingerprint</h3><p>The key is being reused for another request.</p><p>That should not silently replay anything.</p><p>In the bundle, this becomes:</p><pre>422 Unprocessable Content</pre><p>This is an important detail.</p><p>Idempotency should protect us from duplicate execution, not hide application bugs.</p><h3>The race condition in the obvious solution</h3><p>Now we get to the part that makes idempotency a concurrency problem.</p><p>Imagine two identical requests arrive at almost the same time.</p><p>Worker A:</p><pre>read -&gt; no record</pre><p>Worker B:</p><pre>read -&gt; no record</pre><p>Worker A executes the controller.</p><p>Worker B executes the controller too.</p><p>Both workers followed the logic correctly.</p><p>The result is still wrong.</p><p>A cache lookup alone cannot serialize concurrent execution.</p><p>We need coordination.</p><h3>Shared state and a shared lock</h3><p>The bundle uses two separate pieces:</p><ol><li>shared idempotency state</li><li>Symfony Lock</li></ol><p>Both must really be shared across the application.</p><p>That distinction matters in production.</p><p>If you run multiple PHP workers, containers, or application nodes, a local in-memory cache or a local filesystem lock cannot coordinate all of them.</p><p>Redis is one practical option:</p><pre>framework:<br>    cache:<br>        pools:<br>            cache.http_idempotency:<br>                adapter: cache.adapter.redis<br>                provider: &#39;%env(REDIS_URL)%&#39;</pre><pre>    lock:<br>        http_idempotency: &#39;%env(REDIS_URL)%&#39;</pre><pre>http_idempotency:<br>    cache_pool: cache.http_idempotency<br>    lock_factory: lock.http_idempotency.factory</pre><p>Redis itself is not the requirement.</p><p><strong>Shared visibility is the requirement.</strong></p><p>Every application instance participating in the same operation must see the same idempotency state and the same locking mechanism.</p><h3>The second read is easy to miss</h3><p>There is a subtler race condition.</p><p>Suppose request A and request B both perform their first read before either one obtains the lock.</p><pre>A: read -&gt; no record<br>B: read -&gt; no record</pre><p>A gets the lock first.</p><p>It executes the controller, stores the completed response, and releases the lock.</p><p>B then acquires the lock.</p><p>If B trusts its old read, it still believes there is no record.</p><p>So it could execute the controller again.</p><p>The fix is small but essential:</p><blockquote><strong>Read the idempotency record again after acquiring the lock.</strong></blockquote><p>The simplified flow becomes:</p><pre>read record</pre><pre>completed + same fingerprint<br> -&gt; replay</pre><pre>completed + different fingerprint<br> -&gt; 422</pre><pre>try to acquire lock</pre><pre>lock unavailable<br> -&gt; 409</pre><pre>lock acquired</pre><pre>read record again</pre><pre>completed + same fingerprint<br> -&gt; replay</pre><pre>completed + different fingerprint<br> -&gt; 422</pre><pre>still no record<br> -&gt; save processing marker<br> -&gt; execute controller<br> -&gt; store completed response<br> -&gt; release lock</pre><p>That second read closes the race between the initial lookup and lock acquisition.</p><p>It is only one extra read.</p><p>It is also one of the most important reads in the whole implementation.</p><h3>Why the lock is non-blocking</h3><p>There is another design choice: should a duplicate request wait until the first request finishes?</p><p>It can.</p><p>But that also means tying up a worker while another request is running, with latency controlled by somebody else’s operation.</p><p>HttpIdempotencyBundle uses non-blocking lock acquisition.</p><p>If another request is already processing the same idempotency identity, the duplicate request gets:</p><pre>409 Conflict</pre><p>The client can then decide whether and when to retry.</p><p>I prefer this because the behavior is explicit and request latency remains predictable.</p><h3>“Same key” should not mean “same key globally”</h3><p>Suppose two authenticated users both happen to send:</p><pre>Idempotency-Key: request-123</pre><p>They should not collide with each other.</p><p>So the real identity cannot be just the raw idempotency key.</p><p>Conceptually, the bundle derives an identity from:</p><pre>scope + operation + key</pre><p>The <strong>operation</strong> tells us which protected application action this belongs to.</p><p>The <strong>scope</strong> separates independent principals.</p><p>For authenticated Symfony users, the default scope includes the user identity.</p><p>Anonymous requests use a shared anonymous scope by default.</p><p>Applications that need a different definition can provide their own scope resolver.</p><p>This matters especially for endpoints where authentication happens somewhere else in the stack or where multiple logical principals share the same anonymous HTTP context.</p><h3>Response replay is more complicated than serialization</h3><p>Suppose the first execution returns:</p><pre>HTTP/1.1 201 Created<br>Content-Type: application/json</pre><pre>{&quot;id&quot;:742}</pre><p>An identical retry should be able to receive that application result without running the controller again.</p><p>But an HTTP response contains more than application data.</p><p>Some headers belong to the original connection or original request environment.</p><p>For example:</p><ul><li>Connection</li><li>Content-Length</li><li>Date</li><li>Server</li><li>Transfer-Encoding</li><li>Set-Cookie</li></ul><p>Blindly storing and replaying the whole response would copy things that should be generated again.</p><p>Cookies are particularly sensitive here.</p><p>A response cookie from the original request should not accidentally become part of a cached idempotency replay.</p><p>The bundle therefore stores a controlled response snapshot rather than serializing the entire Symfony Response object.</p><p>On replay, normal Symfony response listeners still get a chance to generate fresh request-specific behavior.</p><p>This keeps the idempotency layer focused on the reusable application result.</p><h3>What about application errors?</h3><p>Here is another question that does not have an obvious answer at first:</p><p>If the controller runs and returns a 4xx or 5xx response, should a retry execute the controller again?</p><p>Not necessarily.</p><p>The important distinction is whether the <strong>application operation completed</strong> versus whether the <strong>idempotency infrastructure failed</strong>.</p><p>If the controller genuinely executed and returned an application response, the bundle treats that as a completed execution that can be replayed.</p><p>That avoids turning every application error into another execution attempt.</p><p>Infrastructure failures are different.</p><p>If the idempotency store or lock backend fails before the controller can safely run, the bundle fails closed:</p><pre>503 Service Unavailable</pre><p>If an endpoint explicitly requires idempotency protection, silently continuing without that protection would be a dangerous fallback.</p><h3>A processing marker is useful after crashes</h3><p>A lock protects concurrent execution while the process is alive.</p><p>But processes crash.</p><p>The application can die after marking the operation as in progress and before storing the completed response.</p><p>For that reason, the bundle also uses a processing marker with a TTL.</p><p>The marker is intentionally not eagerly removed during abnormal cleanup.</p><p>Its expiration creates a bounded recovery window.</p><p>During that period, retries do not immediately re-execute an operation whose previous execution may still have produced an external side effect.</p><p>This does not eliminate every failure mode.</p><p>It makes the failure behavior more controlled.</p><h3>The part that should never be hidden: this is not exactly-once</h3><p>This is the most important limitation in the whole design.</p><p>Imagine:</p><pre>1. controller calls an external payment provider<br>2. payment succeeds<br>3. PHP process crashes<br>4. completed idempotency response is never stored</pre><p>The business side effect happened.</p><p>The HTTP idempotency layer did not get the chance to record completion.</p><p>After the processing marker eventually expires, a retry may execute the operation again.</p><p>That failure window exists.</p><p>A middleware, bundle, cache, or distributed lock cannot simply wish it away.</p><p>So HTTP idempotency should not be sold as “exactly-once execution”.</p><p>For important writes, it should be combined with domain-level guarantees such as:</p><ul><li>database unique constraints</li><li>transactions</li><li>provider-level idempotency</li><li>transactional outbox patterns</li><li>durable jobs</li><li>domain-specific deduplication</li></ul><p>For example, if a payment provider supports its own idempotency key, use it.</p><p>The HTTP idempotency layer and the provider-level guarantee solve related but different parts of the problem.</p><p>This is one reason I wanted the limitation to be prominent in the documentation rather than hidden in a footnote.</p><h3>Making the choice explicit in Symfony</h3><p>I also did not want the bundle to automatically change every POST, PUT, or PATCH endpoint.</p><p>Idempotency is an application decision.</p><p>It should be visible in the controller:</p><pre>use Alkin\HttpIdempotencyBundle\Attribute\Idempotent;</pre><pre>#[Route(&#39;/orders&#39;, methods: [&#39;POST&#39;])]<br>#[Idempotent]<br>public function createOrder(): JsonResponse<br>{<br>    // Perform the application operation.</pre><pre>    return new JsonResponse([<br>        &#39;created&#39; =&gt; true,<br>    ], 201);<br>}</pre><p>Unmarked controllers are not touched.</p><p>That makes the behavior easy to discover during code review.</p><p>You can look at the endpoint and immediately see that retries are part of its contract.</p><h3>Failure behavior should be boring</h3><p>One of my goals was to make the failure model small enough to reason about.</p><p>For protected controllers, the bundle uses a few clear outcomes:</p><ul><li>400 Bad Request — Missing or invalid idempotency key</li><li>409 Conflict — The same operation is already processing, or its lock cannot be acquired</li><li>422 Unprocessable Content — The key was reused for a different request fingerprint</li><li>503 Service Unavailable — The idempotency storage or locking infrastructure cannot safely protect the operation</li></ul><p>The interesting thing is not the exact status code list.</p><p>It is that the implementation tries to fail <strong>explicitly</strong> rather than silently weakening the guarantee.</p><h3>Why I turned this into a bundle</h3><p>The original problem sounds small:</p><blockquote>“Do not execute the same retried HTTP request twice.”</blockquote><p>But following it far enough touches:</p><ul><li>request identity</li><li>request fingerprinting</li><li>concurrency</li><li>distributed locking</li><li>shared state</li><li>response replay</li><li>HTTP headers</li><li>authenticated scope</li><li>process crashes</li><li>failure recovery</li><li>the boundary between transport guarantees and business guarantees</li></ul><p>That made it a useful problem to isolate into a small Symfony component.</p><p>The first stable release is now available as:</p><pre>composer require alkinbg/http-idempotency-bundle</pre><p>It supports:</p><pre>PHP &gt;= 8.2<br>Symfony 7.4 or 8.1</pre><p>The public repository is here:</p><p><a href="https://github.com/alkinbg/http-idempotency-bundle">github.com/alkinbg/http-idempotency-bundle</a></p><p>And the package is on Packagist:</p><p><a href="https://packagist.org/packages/alkinbg/http-idempotency-bundle">packagist.org/packages/alkinbg/http-idempotency-bundle</a></p><h3>Final thought</h3><p>Retries are not the enemy.</p><p>They are a normal part of distributed systems.</p><p>The dangerous part is pretending that a timeout tells us what happened on the other side.</p><p>A good idempotency mechanism gives the server enough information to recognize the same logical request, enough coordination to stop concurrent duplicate execution, and a clear enough failure model that we still understand what can go wrong.</p><p>That last part matters.</p><p>Because in distributed systems, the most useful guarantee is often not the one that sounds strongest.</p><p>It is the one whose limits you can explain.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/when-http-retries-become-dangerous-idempotency-in-symfony-without-the-fairy-tales-10l5"><em>https://dev.to</em></a><em> on August 30, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=595c9cf81c23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Catching Risky Doctrine Migrations Before Production]]></title>
            <link>https://medium.com/@alkinbg/catching-risky-doctrine-migrations-before-production-6f1af21a8b8d?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f1af21a8b8d</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[doctrine]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[symfony]]></category>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Fri, 28 Aug 2026 07:29:38 GMT</pubDate>
            <atom:updated>2026-08-28T08:37:29.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GOypyU6-Uvp-WH2f.png" /></figure><p>Database migrations are one of those things that often look harmless during code review.</p><p>A migration may contain only a few lines of SQL, the application tests are green, and everything seems ready to deploy.</p><p>But a small migration can still contain something like this:</p><p>Both are valid migrations.</p><p>They may even be intentional.</p><p>But they are also operations that deserve more attention before they reach production.</p><p>That is the problem I wanted to make easier to catch in CI.</p><h3>The gap between valid and safe-looking</h3><p>Doctrine Migrations does its job well: it gives us a structured way to manage database changes.</p><p>But Doctrine does not try to decide whether our SQL is risky.</p><p>And normal PHP static analysis is usually not interested in the meaning of SQL inside:</p><p>So a migration can be perfectly valid PHP and still contain a database change that should stop a deployment for review.</p><p>For example:</p><p>Adding a NOT NULL column without a default may be completely reasonable in one situation and problematic in another.</p><p>The important point is not to automatically declare it “unsafe”.</p><p>The important point is to <strong>notice it before deployment</strong>.</p><p>That idea became <strong>Doctrine Migration Guard</strong>.</p><h3>What Doctrine Migration Guard does</h3><p>Doctrine Migration Guard is a small standalone CLI tool for static analysis of Doctrine migrations targeting MySQL and MariaDB.</p><p>It does not boot Symfony.</p><p>It does not connect to your database.</p><p>It does not execute your migrations.</p><p>It parses the migration source code, looks at supported addSql() calls inside up(), and classifies recognized SQL operations by risk.</p><p>Install it as a development dependency:</p><pre>composer require --dev alkinbg/doctrine-migration-guard</pre><p>Then analyze your migrations:</p><p>You can also analyze one migration:</p><pre>vendor/bin/doctrine-migration-guard \ migrations/Version20260828090000.php</pre><p>Or several files:</p><pre>vendor/bin/doctrine-migration-guard \ migrations/A.php \ migrations/B.php</pre><h3>Risk levels instead of a simple yes/no</h3><p>I did not want the tool to pretend that database migration safety can be reduced to a boolean.</p><p>Instead, findings have different levels:</p><p>The last one is especially important.</p><h3>Fail closed instead of guessing</h3><p>Static analysis becomes dangerous when the tool starts pretending it understands code that it actually does not understand.</p><p>Doctrine Migration Guard cannot know what getMigrationSql() returns without executing application code.</p><p>So it does not guess.</p><p>The migration becomes INCOMPLETE.</p><p>The same principle applies to unsupported control flow and ambiguous SQL.</p><p>For example, a multi-action statement like this is intentionally not partially classified:</p><p>It would be easy to inspect the first action and produce a result.</p><p>It would also be misleading.</p><p>For the first release, I prefer a conservative answer:</p><blockquote><em>I cannot analyze this reliably.</em></blockquote><p>That is much more useful in CI than a false green result.</p><h3>Doctrine lifecycle hooks need the same treatment</h3><p>Doctrine migrations can also contain lifecycle methods such as:</p><p>Version 0.1 does not analyze preUp() or postUp().</p><p>If one of these hooks is overridden, the migration becomes INCOMPLETE.</p><p>Supported SQL inside up() is still analyzed and reported, but the complete migration cannot be considered fully analyzed.</p><p>Again, the goal is not to pretend that unsupported code does not exist.</p><h3>Useful exit codes for CI</h3><p>The CLI uses deterministic exit codes:</p><p>FAILED means at least one HIGH or CRITICAL finding was detected.</p><p>INCOMPLETE has higher priority because some part of the input could not be analyzed reliably.</p><p>That makes it easy to add the tool to CI.</p><p>For example, to analyze migrations changed on a branch:</p><pre>git diff --name-only origin/main...HEAD -- &#39;migrations/*.php&#39; \ | xargs -r vendor/bin/doctrine-migration-guard</pre><p>Or, if the number of migrations is reasonable, simply scan the entire directory:</p><p>There is also JSON output for automation:</p><pre>vendor/bin/doctrine-migration-guard \ --format =json \ migrations/</pre><p>The JSON format currently uses schema version 1.</p><h3>What it deliberately does not do</h3><p>This part matters.</p><p>Doctrine Migration Guard does <strong>not</strong> know your table size, production workload, MySQL configuration, MariaDB version, execution plan, lock duration, or deployment strategy.</p><p>It also does not inspect a live database.</p><p>does not mean:</p><p>It means that the migration was fully analyzed under the supported static rules and no blocking finding was detected.</p><p>That is a much narrower promise, but it is one I am comfortable making.</p><h3>Why I started small</h3><p>It would be easy to add database connections, configuration files, suppression systems, custom plugins, Git integration, automatic fixes, PostgreSQL support, and many other features.</p><p>I intentionally did not start there.</p><p>For the first version I wanted something that is:</p><p>small, deterministic, CI-friendly, easy to understand, and conservative when it is uncertain.</p><p>The tool currently supports PHP 8.1 through PHP 8.5 and has no Symfony runtime dependency.</p><p>Symfony developers can use it, but it remains a standalone CLI tool.</p><h3>Try it</h3><p>The first public release is now available:</p><p><strong>GitHub:</strong></p><p><a href="https://github.com/alkinbg/doctrine-migration-guard">https://github.com/alkinbg/doctrine-migration-guard</a></p><p><strong>Packagist:</strong></p><p><a href="https://packagist.org/packages/alkinbg/doctrine-migration-guard">https://packagist.org/packages/alkinbg/doctrine-migration-guard</a></p><p>Install it with:</p><pre>composer require --dev alkinbg/doctrine-migration-guard</pre><p>This is still an early 0.x project, so feedback is very welcome - especially real Doctrine migrations where the current rules produce an unexpected result.</p><p>For me, the interesting part is not trying to make migrations magically safe.</p><p>It is adding one more useful review step <strong>before risky database changes reach production</strong>.</p><p><em>Originally published at </em><a href="https://dev.to/alkin/catching-risky-doctrine-migrations-before-production-dc"><em>https://dev.to</em></a><em> on August 28, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f1af21a8b8d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Symfony Logs Know More Than You Think]]></title>
            <link>https://medium.com/@alkinbg/your-symfony-logs-know-more-than-you-think-0dd6eca0f95a?source=rss-71f5fd73e174------2</link>
            <guid isPermaLink="false">https://medium.com/p/0dd6eca0f95a</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Alkin]]></dc:creator>
            <pubDate>Thu, 27 Aug 2026 05:40:55 GMT</pubDate>
            <atom:updated>2026-08-27T05:40:55.614Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3cWW5_wKfYRTNyy5" /><figcaption>Photo by <a href="https://unsplash.com/@juanjodev02?utm_source=medium&amp;utm_medium=referral">Juanjo Jaramillo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Your Symfony Logs Know More Than You Think</h3><p><em>Designing fail-closed sensitive data masking for Symfony, Monolog and structured application data.</em></p><p>Logs are supposed to help when something goes wrong.</p><p>Unfortunately, they are also very good at remembering things we never intended to keep.</p><p>Consider a perfectly ordinary log entry:</p><pre>$logger-&gt;warning(<br>    &#39;Payment failed&#39;,<br>    [<br>        &#39;customer&#39; =&gt; $customerId,<br>        &#39;card&#39; =&gt; $cardNumber,<br>        &#39;request&#39; =&gt; $requestData,<br>    ],<br>);</pre><p>At first glance, nothing unusual is happening.</p><p>Then the log gets shipped to a centralized system.</p><p>It is indexed.</p><p>Replicated.</p><p>Backed up.</p><p>Accessible to developers, operations teams and perhaps third-party tooling.</p><p>Months later, someone notices that the card field contained a full payment-card number.</p><p>Or an authentication token ended up in an exception message.</p><p>Or a structured API response was copied into diagnostic context and contained credentials nobody realized were there.</p><p>At that point, deleting one line from one server is no longer the problem.</p><p>The sensitive value may already exist in several systems.</p><p>That led me to a simple rule:</p><blockquote><em>Sensitive data should preferably be removed before it becomes part of diagnostic output.</em></blockquote><p>But implementing that safely turned out to be more interesting than replacing a few strings with asterisks.</p><h3>The obvious solution is not enough</h3><p>The first idea most developers have is some form of regular expression:</p><pre>$log = preg_replace(<br>    &#39;/\b\d{16}\b/&#39;,<br>    &#39;****************&#39;,<br>    $log,<br>);</pre><p>It looks reasonable.</p><p>It also breaks almost immediately.</p><p>Payment-card numbers are not always written as sixteen uninterrupted digits:</p><pre>4111111111111111<br>4111 1111 1111 1111<br>4111-1111-1111-1111</pre><p>And not every sixteen-digit number is a payment card.</p><p>A timestamp, identifier, order number or other application value can have the same shape.</p><p>At the same time, secrets such as these are impossible to identify reliably from syntax alone:</p><pre>b036fc5c284...<br>my-internal-api-token<br>refresh-token-123<br>correct-horse-battery-staple</pre><p>The application knows that a password or token is sensitive.</p><p>A generic detector often does not.</p><p>This suggests two different problems:</p><pre>detectable sensitive data<br>        +<br>known sensitive values</pre><p>They should not be treated as the same thing.</p><h3>Automatic detection and explicit knowledge</h3><p>This became one of the central design decisions behind <a href="https://github.com/alkinbg/masked-bundle">MaskedBundle</a>.</p><p>The bundle supports two complementary approaches.</p><p>The first is <strong>automatic detection</strong> for data that can be identified with sufficiently high confidence.</p><p>The current detector focuses deliberately on payment-card numbers.</p><p>The second is <strong>explicit masking</strong> for secrets the application already knows about.</p><p>For example:</p><pre>$token = &#39;secret-access-token&#39;;</pre><pre>$masked = $sensitiveDataMasker-&gt;mask(<br>    &#39;Authentication failed for token &#39;.$token,<br>    sensitiveValues: [$token],<br>);</pre><p>The result becomes:</p><pre>Authentication failed for token ███████████████████</pre><p>This is far safer than trying to invent a universal “API token regex”.</p><p>If the application created the token, received it from a credential store or just authenticated with it, it already knows the exact value that must not appear in diagnostic output.</p><p>There is no reason to rediscover it heuristically.</p><p>And the values are scoped to the current operation.</p><p>MaskedBundle does not maintain a process-wide mutable registry of secrets.</p><p>That matters particularly in long-running PHP applications.</p><h3>Payment-card detection needs more than a digit count</h3><p>For automatic payment-card detection, simply finding between 13 and 19 digits would produce too many false positives.</p><p>So candidate strings go through additional validation.</p><p>A candidate may contain separators such as spaces or hyphens:</p><pre>4111 1111 1111 1111<br>4111-1111-1111-1111</pre><p>But after normalization it must contain an appropriate number of ASCII digits and pass the <strong>Luhn algorithm</strong>.</p><p>Repeated-digit candidates are rejected as well.</p><p>This still doesn’t turn detection into magic.</p><p>MaskedBundle does not attempt to identify the card brand, BIN or IIN, and the detector is intentionally described as a conservative heuristic.</p><p>That distinction is important.</p><p>A security component should be explicit about what it can recognize rather than pretending to recognize every secret imaginable.</p><h3>Strings are the easy part</h3><p>Masking this:</p><pre>$masker-&gt;mask(<br>    &#39;Card: 4111111111111111&#39;,<br>);</pre><p>is straightforward.</p><p>Real application data looks more like this:</p><pre>[<br>    &#39;request&#39; =&gt; [<br>        &#39;customer&#39; =&gt; [<br>            &#39;id&#39; =&gt; 42,<br>            &#39;payment&#39; =&gt; [<br>                &#39;card&#39; =&gt; &#39;4111111111111111&#39;,<br>            ],<br>        ],<br>    ],<br>]</pre><p>So MaskedBundle also provides structured masking:</p><pre>$masked = $structuredDataMasker-&gt;mask([<br>    &#39;customer&#39; =&gt; [<br>        &#39;card&#39; =&gt; &#39;4111111111111111&#39;,<br>    ],<br>]);</pre><p>Strings and integers are processed recursively.</p><p>Array keys are checked as well.</p><p>But arbitrary objects are intentionally not traversed or mutated.</p><p>That may sound like an incomplete solution until you look at a logging pipeline.</p><p>Objects have identity and behavior.</p><p>An exception object may later be inspected by another Monolog processor.</p><p>A JsonSerializable object may have application-specific normalization.</p><p>A Stringable implementation may render itself differently depending on how it is used.</p><p>Mutating or replacing these objects early in the pipeline can change behavior far beyond masking.</p><p>So the processor preserves them.</p><p>The important question then becomes:</p><blockquote><em>What happens when those objects are eventually rendered?</em></blockquote><p>That is where formatters enter the picture.</p><h3>Masking a LogRecord is not necessarily masking the final log line</h3><p>A Monolog processor can sanitize the message, context and extra fields before the record continues through the pipeline.</p><p>MaskedBundle provides such a processor.</p><p>This is useful for ordinary data:</p><pre>$logger-&gt;info(<br>    &#39;Processing card 4111111111111111&#39;,<br>    [<br>        &#39;backup_card&#39; =&gt; &#39;5555555555554444&#39;,<br>    ],<br>);</pre><p>The detectable values are masked before the record reaches the next stage.</p><p>But suppose the context contains an exception.</p><p>The processor deliberately preserves the exception object.</p><p>Later, a formatter converts that object into text.</p><p>That formatted representation may contain sensitive data that was never visible as a plain scalar during the processor stage.</p><p>So processor-only masking cannot make a universal promise about the final output.</p><p>Instead, MaskedBundle also provides formatter-aware protection.</p><p>For line-oriented logs:</p><pre>monolog:<br>    handlers:<br>        main:<br>            type: stream<br>            path: &#39;%kernel.logs_dir%/%kernel.environment%.log&#39;<br>            formatter: &#39;Masked\Bundle\Monolog\SensitiveLineFormatter&#39;</pre><p>SensitiveLineFormatter lets Monolog perform its normal rendering and then masks the resulting line.</p><p>For JSON:</p><pre>monolog:<br>    handlers:<br>        main:<br>            type: stream<br>            path: &#39;%kernel.logs_dir%/%kernel.environment%.json&#39;<br>            formatter: &#39;Masked\Bundle\Monolog\SensitiveJsonFormatter&#39;</pre><p>The JSON formatter masks normalized data <strong>before</strong> the complete record is encoded.</p><p>That last detail matters.</p><p>Running arbitrary replacements against already encoded JSON is risky.</p><p>Masking structured values before serialization preserves valid JSON and lets the formatter reason about values and keys rather than manipulating an opaque encoded string.</p><h3>Known secrets belong close to the logging call</h3><p>There is another case where an automatic Monolog processor is not enough.</p><p>Imagine an authentication operation:</p><pre>final class AuthenticationService<br>{<br>    public function __construct(<br>        private readonly LoggerInterface $logger,<br>        private readonly SensitiveLogger $sensitiveLogger,<br>    ) {<br>    }</pre><pre>    public function reportFailure(<br>        string $token,<br>        string $username,<br>    ): void {<br>        $this-&gt;sensitiveLogger-&gt;log(<br>            $this-&gt;logger,<br>            &#39;warning&#39;,<br>            &#39;Authentication failed for token &#39;.$token,<br>            [<br>                &#39;token&#39; =&gt; $token,<br>                &#39;user&#39; =&gt; $username,<br>            ],<br>            sensitiveValues: [$token],<br>        );<br>    }<br>}</pre><p>Here the application already knows exactly which value is sensitive.</p><p>SensitiveLogger masks both the message and structured context before delegating to the underlying PSR-3 logger.</p><p>The secret exists only for that operation.</p><p>No shared logger state is modified.</p><p>This is a property I wanted to preserve from the beginning: masking a token in one request should not require registering that token globally in a worker that may continue processing thousands of unrelated requests or messages.</p><h3>Then came the uncomfortable question: what about pathological input?</h3><p>Security code often looks trivial until an attacker controls part of the input.</p><p>Consider explicit secret masking.</p><p>In the simplest implementation, you could search every input string for every supplied sensitive value.</p><p>Now imagine:</p><pre>1,000 sensitive values<br>×<br>large structured payload<br>×<br>many nested values<br>×<br>many repeated substring searches</pre><p>The masking component itself can become a resource-exhaustion problem.</p><p>The same issue exists for automatic candidate detection.</p><p>An enormous input containing huge numbers of numeric-looking sequences could force an unbounded number of validations.</p><p>So detection work has to be bounded.</p><p>But adding a budget creates a new security question.</p><p>What should happen when the budget runs out?</p><h3>Fail open or fail closed?</h3><p>Suppose a masking operation is halfway through a value when its search budget is exhausted.</p><p>One option is to stop detecting and return the remaining text unchanged.</p><p>That is operationally convenient.</p><p>It is also <strong>fail open</strong>.</p><p>The component whose purpose is to prevent sensitive output would effectively say:</p><blockquote><em>This input is too expensive to inspect, so I’ll log it anyway.</em></blockquote><p>I didn’t like that contract.</p><p>MaskedBundle instead moves into a fail-closed state.</p><p>If continuing exact-value detection would exceed its bounded search budget while scanning a string, the current string is treated as sensitive.</p><p>And if the shared budget for the operation has been exhausted, later supported values are treated as sensitive rather than being given a brand-new budget.</p><p>The same principle applies to payment-card candidate validation.</p><p>Once that budget is exhausted within a shared masking operation, the current input is treated as sensitive.</p><p>The output may lose diagnostic detail.</p><p>But it does not respond to excessive work by exposing the data it failed to inspect.</p><p>For a redaction component, that trade-off feels much safer.</p><h3>Why the budget must be shared</h3><p>There is a subtle trap here.</p><p>Imagine a structured payload with hundreds of fields.</p><p>You could impose a limit of 10,000 candidate checks <strong>per field</strong>.</p><p>Technically, every individual field is bounded.</p><p>The complete operation is not.</p><p>An attacker simply supplies more fields.</p><p>So MaskedBundle shares detection context across the entire logical operation.</p><p>For structured masking, one payment-card detection budget is shared across supported values and keys during the traversal.</p><p>The same applies to explicit-value search work.</p><p>For SensitiveLogger, the message and context share the same detection context.</p><p>For a complete Monolog LogRecord, message, context and extra data share the payment-card candidate-validation budget.</p><p>And the JSON formatter shares its budget across everything processed by one format() or formatBatch() operation.</p><p>This closes an easy resource-limit bypass:</p><pre>budget per value<br>    × unlimited values<br>    =<br>not actually bounded</pre><p>A limit only means something if its scope matches the operation you are trying to protect.</p><h3>Structured data needs limits too</h3><p>Recursive masking has another class of pathological inputs.</p><p>Deep nesting.</p><p>Huge arrays.</p><p>Recursive structures.</p><p>Massive numbers of entries.</p><p>MaskedBundle therefore bounds structured traversal as well.</p><p>Individual arrays have processing limits, and the complete masking operation has a total work limit.</p><p>If a limit is reached, unprocessed raw input is not simply copied into the result.</p><p>Instead, the remaining data is omitted and replaced with a safe placeholder.</p><p>Again, this is the same principle:</p><blockquote><em>Reaching a defensive limit must not become a shortcut around redaction.</em></blockquote><p>JSON formatting applies similar defensive limits independently from Monolog’s own normalization.</p><p>The goal is not to accept arbitrarily complex diagnostic structures.</p><p>The goal is to produce bounded, safe diagnostic output.</p><h3>Masking characters have security properties too</h3><p>Even the replacement character deserves some thought.</p><p>By default, MaskedBundle uses:</p><pre>█</pre><p>It can be configured:</p><pre>masked:<br>    mask_character: &#39;*&#39;</pre><p>But the value cannot be an arbitrary Unicode character.</p><p>Control characters, separators, combining marks and invisible format characters are rejected.</p><p>Otherwise a configuration intended only to change the appearance of redaction could introduce newlines, invisible spacing or other surprising output into logs.</p><p>For valid UTF-8 input, masking normally preserves the number of characters.</p><p>There is also a small edge case: if masking would accidentally produce exactly the same non-empty string as the original sensitive value, an additional masking character is prepended.</p><p>A value that has been redacted should never be returned unchanged.</p><p>It’s a tiny detail.</p><p>Security code tends to be full of tiny details.</p><h3>Masking is not encryption</h3><p>This boundary is worth stating explicitly.</p><p>A redaction library is not:</p><ul><li>encryption;</li><li>tokenization;</li><li>a secrets vault;</li><li>access control;</li><li>a payment-card vault;</li><li>a shortcut to PCI DSS compliance.</li></ul><p>It reduces the risk that sensitive values accidentally propagate into logs and diagnostic output.</p><p>It does not make storing sensitive data safe.</p><p>It does not fix an application that logs too much information by design.</p><p>And automatic detection is necessarily heuristic.</p><p>If your application knows that a password, refresh token or credential is sensitive, supply that value explicitly rather than hoping a detector recognizes it.</p><h3>There is no universal “sanitize my logs” switch</h3><p>Logging pipelines are extensible.</p><p>That is one of Monolog’s strengths.</p><p>It also means no library inserted at one point in the pipeline can guarantee what arbitrary code will do afterward.</p><p>A custom processor can introduce new values.</p><p>A custom formatter can serialize objects differently.</p><p>A handler can transform records again.</p><p>That is why MaskedBundle does not automatically replace every formatter in the application.</p><p>It provides integrations, but the application still decides which handlers use them.</p><p>Security guarantees should have visible boundaries.</p><p>A magical global switch would be easier to advertise.</p><p>It would also be much harder to defend technically.</p><h3>Keeping PHP exception traces in mind</h3><p>There is one more leakage path that is easy to forget.</p><p>Function arguments may appear in exception traces.</p><p>MaskedBundle marks package-owned parameters that may contain unmasked sensitive values using PHP’s #[SensitiveParameter] attribute.</p><p>That protects those values in the relevant stack frames.</p><p>But the attribute only applies where it is declared.</p><p>Applications requiring exception traces to contain no function arguments at all should additionally consider:</p><pre>zend.exception_ignore_args=1</pre><p>Log masking and stack-trace protection are related, but they are not the same mechanism.</p><h3>Why I built MaskedBundle</h3><p>MaskedBundle owes an important part of its origin to <a href="https://github.com/fuko-php/masked">Fuko\Masked</a>, created by <a href="https://github.com/kktsvetkov">Kaloyan K. Tsvetkov</a>.</p><p>The original project introduced a simple and practical idea: sensitive values should be easy to declare and safely removed from diagnostic output before they accidentally reach logs, dumps, or other places where they do not belong.</p><p>That idea stayed with me.</p><p>While contributing automatic payment-card detection to Fuko\Masked, I started thinking about how the same principle could be approached today in a modern Symfony application.</p><p>What would it look like with dependency injection instead of global state?</p><p>With explicit service boundaries.</p><p>With automatic detection only where it can be trusted.</p><p>With per-operation known secrets.</p><p>With structured data, Monolog 3, long-running workers, bounded detection work, and failure behavior designed specifically for a security-sensitive component.</p><p>MaskedBundle grew from that thought.</p><p>It is not a drop-in port of Fuko\Masked and does not attempt to preserve its API. Its Symfony-facing architecture was designed independently around modern dependency injection, stateless operation, and contemporary logging pipelines.</p><p>At the same time, the lineage should be explicit.</p><p>The payment-card detection work has clear roots in the earlier work I contributed to Fuko\Masked, and the original project was an important part of the path that eventually led to MaskedBundle.</p><p>That provenance, together with the relevant MIT licensing information, is documented in <a href="https://github.com/alkinbg/masked-bundle/blob/main/THIRD_PARTY_NOTICES.md">THIRD_PARTY_NOTICES.md</a>.</p><p>My sincere thanks to <strong>Kaloyan K. Tsvetkov</strong> for creating Fuko\Masked, for the original idea, and — more importantly — for the inspiration that eventually led me to build this project.</p><h3>Using it</h3><p>The package currently targets PHP 8.4.1+ and Symfony 8.1+.</p><p>Installation is intentionally simple:</p><pre>composer require alkinbg/masked-bundle</pre><p>No configuration is required for the basic services.</p><p>The application-level API centers around:</p><pre>SensitiveDataMasker<br>StructuredDataMasker<br>SensitiveLogger</pre><p>and the optional Monolog integration provides:</p><pre>SensitiveDataProcessor<br>SensitiveLineFormatter<br>SensitiveJsonFormatter</pre><p>The project is available on <a href="https://github.com/alkinbg/masked-bundle">GitHub</a> under the MIT license and can also be installed from <a href="https://packagist.org/packages/alkinbg/masked-bundle">Packagist</a>.</p><h3>The lesson I took from building it</h3><p>At first, sensitive-data masking looked like a string replacement problem.</p><p>It turned into a boundary problem.</p><p>Where does the sensitive value first become diagnostic data?</p><p>What information can be detected reliably?</p><p>What information does the application already know?</p><p>What happens to objects later in the logging pipeline?</p><p>How much work can an attacker force the detector to perform?</p><p>And, most importantly:</p><p><strong>what happens when the protection mechanism itself reaches its limit?</strong></p><p>For me, that last question defined the design.</p><p>When a component exists to prevent sensitive data from escaping, exhausting its defensive budget should not suddenly make the sensitive data safe to emit.</p><p>Sometimes the safest log entry is the one that tells you less.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0dd6eca0f95a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>