<?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: Desmond Chin</title>
    <description>The latest articles on DEV Community by Desmond Chin (@desmondchoon).</description>
    <link>https://dev.to/desmondchoon</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F552942%2F86b40804-d45e-49be-8bb5-98c2105bff4a.jpeg</url>
      <title>DEV Community: Desmond Chin</title>
      <link>https://dev.to/desmondchoon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/desmondchoon"/>
    <language>en</language>
    <item>
      <title>MightyPHP - Not just another PHP Framework</title>
      <dc:creator>Desmond Chin</dc:creator>
      <pubDate>Mon, 04 Jan 2021 07:25:08 +0000</pubDate>
      <link>https://dev.to/desmondchoon/mightyphp-not-just-another-php-framework-14l</link>
      <guid>https://dev.to/desmondchoon/mightyphp-not-just-another-php-framework-14l</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Plenty of times, I had come into projects that uses the typical PHP frameworks, ranging from CodeIgniter, to Symfony, and mostly Laravel. From experiences of using such frameworks, I grew tiresome of having to dive into complexed features; which in my opinion is great for full fledged frameworks, but it takes away the joy.&lt;/p&gt;

&lt;p&gt;There were times I wish I could port some nice features or concepts from other frameworks or languages, such as how &lt;strong&gt;middlewares&lt;/strong&gt; were used in &lt;strong&gt;ExpressJS&lt;/strong&gt;, the &lt;code&gt;Include&lt;/code&gt; method of &lt;strong&gt;Entity Framework Core&lt;/strong&gt; from &lt;strong&gt;.NET Core&lt;/strong&gt; and many more, while at the same time wishing some features from existing frameworks to be gone.&lt;/p&gt;

&lt;p&gt;That is how I had decided to build a solution to my problem; &lt;strong&gt;MightyPHP&lt;/strong&gt;. What started as a tiny hobby project, slowly grew into something I think could go further.&lt;/p&gt;

&lt;p&gt;In this article, I will be &lt;strong&gt;highlighting briefly&lt;/strong&gt; on the concepts and features of MightyPHP as of current version, v1.0.0, released just recently. &lt;strong&gt;See it, as if it is some sort of a trailer&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Philosophy / Concepts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Designed to Be Bare
&lt;/h3&gt;

&lt;p&gt;A lot of frameworks out there tend to overcomplicate things; not intentionally, but done so to help you achieve more. However, I prefer many things better, bare. MightyPHP aims at not having you to configure a whole lot. Things are there as it is. There will always be only one method for a purpose, and it stays as it is.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clean &amp;amp; Neat
&lt;/h3&gt;

&lt;p&gt;When we write too much, not only do we introduce bugs, we mess up the readability of the code. What takes up most estate in our editors or IDEs? In my opinion; variables.&lt;/p&gt;

&lt;p&gt;An example of &lt;strong&gt;class initialization&lt;/strong&gt; in MightyPHP&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FooController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;UserModel&lt;/span&gt; &lt;span class="nv"&gt;$userModel&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$userModel&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&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;Reduce variable declaration for classes, get it on the get go!&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlights
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ExpressJS-liked Middlewares
&lt;/h3&gt;

&lt;p&gt;I like how middlewares are used in routes in ExpressJS; clean, readable, straight to the point.&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="nv"&gt;$index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"VerifyCsrf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Foo"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Want middlewares only at certain routes? Why not.&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="nv"&gt;$index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'UserController@profile'&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;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'CheckAuth'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Query Builders
&lt;/h3&gt;

&lt;p&gt;Nothing fancy, here just for the sake of being mainstream. A common but crucial feature for any framework!&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UsersModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&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;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'age'&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;get&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;Want to include child(ren) item(s) into your model objects? Use include!&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UsersModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&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;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'age'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;include&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserProfiles&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;get&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;h3&gt;
  
  
  Console Commands
&lt;/h3&gt;

&lt;p&gt;Like Laravel's &lt;code&gt;artisan&lt;/code&gt;? We have &lt;code&gt;mighty&lt;/code&gt;. This feature is still under development. Usable, but not pretty.&lt;/p&gt;

&lt;p&gt;Example: to scaffold a controller,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php mighty make:controller UserController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Migration &amp;amp; Seeding
&lt;/h3&gt;

&lt;p&gt;Ease of maintaining databases and tables. Example of seeding:&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="kn"&gt;use&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nc"&gt;Application\Models\UsersModel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;seed_user&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;plant&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="nv"&gt;$date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;password_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'admin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PASSWORD_DEFAULT&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UsersModel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
            &lt;span class="s2"&gt;"users_email"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"admin@admin.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"users_password"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"users_createdAt"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"users_modifiedAt"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$date&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;h2&gt;
  
  
  What else? What's to come?
&lt;/h2&gt;

&lt;p&gt;MightyPHP's first version has just been released. Efforts will be going into growing it, and making it better; in hopes that it would grow into an alternative for the bunch of PHP frameworks out there that is offering different sets of solutions.&lt;/p&gt;

&lt;p&gt;As of currently, MightyPHP does not support cross-database query builder or ORM, but is indeed in the pipelines of what is to come. Support is currently only for &lt;strong&gt;MySQL&lt;/strong&gt; or &lt;strong&gt;MariaDB&lt;/strong&gt; databases. Even currently, there are already development on-going for &lt;code&gt;Schematics&lt;/code&gt; which will be catering for &lt;strong&gt;cross-database migrations&lt;/strong&gt; in the future; which now still heavily relies on raw MySQL queries in that aspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where or how to try out MightyPHP?
&lt;/h2&gt;

&lt;p&gt;Head over to the official site at &lt;a href="https://mightyphp.com"&gt;https://mightyphp.com&lt;/a&gt; or go straight to the documentations at &lt;a href="https://docs.mightyphp.com"&gt;https://docs.mightyphp.com&lt;/a&gt; (Documentations are still in progress but at least 75% of the required contents are there)&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>mightyphp</category>
      <category>framework</category>
    </item>
  </channel>
</rss>
