<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: dvaknheo</title>
    <description>The latest articles on DEV Community by dvaknheo (@dvaknheo).</description>
    <link>https://dev.to/dvaknheo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4252745%2F8347f6ae-8a37-4c67-ae17-03485858fb1d.jpg</url>
      <title>DEV Community: dvaknheo</title>
      <link>https://dev.to/dvaknheo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dvaknheo"/>
    <language>en</language>
    <item>
      <title>I port Symfony Demo to DuckPHP, and it be simple</title>
      <dc:creator>dvaknheo</dc:creator>
      <pubDate>Thu, 19 Nov 2026 01:09:36 +0000</pubDate>
      <link>https://dev.to/dvaknheo/i-port-symfony-demo-to-duckphp-and-it-be-simple-492d</link>
      <guid>https://dev.to/dvaknheo/i-port-symfony-demo-to-duckphp-and-it-be-simple-492d</guid>
      <description>&lt;h1&gt;
  
  
  A controller with 18 &lt;code&gt;use&lt;/code&gt; statements, cut down to 3
&lt;/h1&gt;

&lt;p&gt;I did something a bit stubborn: &lt;strong&gt;I rebuilt the official Symfony Demo, from scratch, with DuckPHP&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Not as an exercise — to test one claim: &lt;strong&gt;a lot of PHP application complexity is not business complexity, it is framework concept tax.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start with one screen of code. The original &lt;code&gt;BlogController&lt;/code&gt; header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;\&lt;span class="nc"&gt;Entity&lt;/span&gt;\&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;\&lt;span class="nc"&gt;Form&lt;/span&gt;\&lt;span class="nc"&gt;CommentType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;\&lt;span class="nc"&gt;Repository&lt;/span&gt;\&lt;span class="nc"&gt;PostRepository&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Doctrine&lt;/span&gt;\&lt;span class="no"&gt;ORM&lt;/span&gt;\&lt;span class="nc"&gt;EntityManagerInterface&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony&lt;/span&gt;\&lt;span class="nc"&gt;Bundle&lt;/span&gt;\&lt;span class="nc"&gt;FrameworkBundle&lt;/span&gt;\&lt;span class="nc"&gt;Controller&lt;/span&gt;\&lt;span class="nc"&gt;AbstractController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ... 18 lines in total&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;DuckSymfonyDemo&lt;/span&gt;\&lt;span class="nc"&gt;Business&lt;/span&gt;\&lt;span class="nc"&gt;BlogBusiness&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;DuckSymfonyDemo&lt;/span&gt;\&lt;span class="nc"&gt;Business&lt;/span&gt;\&lt;span class="nc"&gt;CommentBusiness&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;DuckSymfonyDemo&lt;/span&gt;\&lt;span class="nc"&gt;Business&lt;/span&gt;\&lt;span class="nc"&gt;MailBusiness&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;18 → 3. The missing 15 were Entity, Form, Repository, Event, Attribute, Cache — concepts DuckPHP simply does not have. The controller is left with one job: &lt;strong&gt;take input → call business → hand over to the view&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Parameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'page'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$tagName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;_tagName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$pager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BlogBusiness&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$tagName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'pager'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$pager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'tagName'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$tagName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'blog/index'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The overall footprint is smaller too: &lt;code&gt;src/&lt;/code&gt; went from &lt;strong&gt;34 files / 3424 lines to 27 files / 2777 lines&lt;/strong&gt;; templates from &lt;strong&gt;32 Twig files / 1164 lines to 19 PHP files / 648 lines&lt;/strong&gt;.&lt;br&gt;
There is exactly one call chain, and it is one-way: &lt;code&gt;System → Controller → Business → Model&lt;/code&gt;. Model is the only layer that touches SQL, Business is stateless and never reads &lt;code&gt;$_GET&lt;/code&gt;, and each layer uses only its own Helper.&lt;/p&gt;

&lt;p&gt;That said, it was not all smooth.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hard part one: the locale segment sits in the middle of the path
&lt;/h2&gt;

&lt;p&gt;The Symfony Demo puts the language in the first URL segment (&lt;code&gt;/{_locale}/blog/...&lt;/code&gt;), while DuckPHP's model is "each path segment is a controller/method" — it has no notion of a segment inserted in the middle. So I added &lt;code&gt;RouteHookSymfony&lt;/code&gt;, the only class in the project that reaches into the core: it consumes "deploy prefix + locale segment" first, then dispatches.&lt;/p&gt;

&lt;p&gt;The price: once the prefix is stripped up front, three framework components that assume the original path all get out of sync (&lt;code&gt;Route&lt;/code&gt; strips the prefix, &lt;code&gt;RouteMap&lt;/code&gt; only validates it, &lt;code&gt;Resource&lt;/code&gt; rebuilds it). Measured: touch none of them and everything under &lt;code&gt;/demo/&lt;/code&gt; returns 404. So the component also has to compensate for all three copies inside its own &lt;code&gt;initOptions()&lt;/code&gt; — and only when a deploy prefix exists. I wrote three screens of comments there, because without them a future reader will read it as a pile of hacks.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hard part two: the whole site can move into a subdirectory
&lt;/h2&gt;

&lt;p&gt;What added another layer was a second requirement: the app must run at the site root &lt;code&gt;/&lt;/code&gt;, &lt;em&gt;and&lt;/em&gt; be movable into &lt;code&gt;/demo/&lt;/code&gt; as a whole — &lt;strong&gt;without touching a line of business code&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On the DuckPHP side that is one option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'controller_url_prefix'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'demo/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// flip this line and the site moves from / to /demo/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every link, static asset and 302 redirect picks up &lt;code&gt;/demo&lt;/code&gt; automatically. Sounds cheap — but stacked with the locale segment above it becomes &lt;code&gt;/demo/zh_CN/blog/...&lt;/code&gt;: both prefixes must be consumed by the same hook before routing, which is where the third piece of compensation (prefixes for static asset URLs) comes from.&lt;/p&gt;

&lt;p&gt;In other words: &lt;strong&gt;"the deploy shape is configurable" is itself a cost. DuckPHP squeezes it down to one line of config, but not to zero.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Was it worth it? 40 A/B comparisons
&lt;/h2&gt;

&lt;p&gt;I wrote a comparison script that hits both sites on the same machine and compares status codes case by case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;blog paginated   page/4 out of range   200  200  OK
blog_post        missing slug          404  404  OK
blog tag filter  ?tag=lorem            200  200  OK
logout           no token              403  403  OK
diff: 0 / 27
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Plus 8 authenticated checks: 17 posts in the admin list, 403 for someone else's post, 200 for the create/edit forms. The data is the original fixtures too: 30 posts, 150 comments, 9 tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  The nicer part: embeddable, and overridable
&lt;/h2&gt;

&lt;p&gt;There is one design I like a lot but never had a chance to mention: &lt;strong&gt;DuckPHP treats a project as a composable unit&lt;/strong&gt;, not a closed application.&lt;/p&gt;

&lt;p&gt;Which means two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;projects can embed each other: a big system mounts a subsystem, each with its own namespace;&lt;/li&gt;
&lt;li&gt;a project can be overridden &lt;strong&gt;without touching a single line of the child project&lt;/strong&gt;: swap components, change options, replace hooks, replace views.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is exactly how this version's route hook is written: it registers itself in &lt;code&gt;ext&lt;/code&gt;, picks up the App options in its own &lt;code&gt;initOptions()&lt;/code&gt; and compensates the three copies on the way, while the App layer only carries a declaration. In an earlier iteration I had jammed those 20 lines of compensation into &lt;code&gt;App::onInited()&lt;/code&gt; and later moved them into the component — that is what "componentisation" actually feels like: &lt;strong&gt;change a component, and you do not have to patch the main flow.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try it&lt;/strong&gt;: mount this Demo as a sub-application of another DuckPHP app, then rewrite its homepage or admin a bit — without touching any file inside &lt;code&gt;Duck/&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;After finishing this version, my feeling comes down to one sentence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Complexity is not because the business is complex; it is because the framework transfers the cost of its concepts onto the business code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Which complexity is real, and which is just habit?&lt;/strong&gt; That question deserves a serious answer, one day, from anyone maintaining a PHP project that keeps getting heavier.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/dvaknheo/symfony-demo-duckphp" rel="noopener noreferrer"&gt;https://github.com/dvaknheo/symfony-demo-duckphp&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>php</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
