mecha-cms / mecha

Minimalist content management system.
https://mecha-cms.com
GNU General Public License v3.0
175 stars 23 forks source link

Less Folder Structure Maybe? #158

Closed taufik-nurrohman closed 2 years ago

taufik-nurrohman commented 2 years ago
.\engine\
├── use\ 👎
│   ├── anemone.php
│   ├── file.php
│   ├── folder.php
│   ├── from.php
│   ├── genome.php
│   ├── hook.php
│   ├── is.php
│   ├── state.php
│   ├── time.php
│   ├── to.php
│   └── u-r-l.php
└── use.php 👎

Rationales

  1. Using use as the folder name to store classes because of the native PHP syntax for importing classes (and functions, and constants). 👎

    namespace Foo\Bar;
    use Baz, Qux;
  2. Using use as the folder name to store classes because of the use property used to list the dependencies of an extension or a layout as written in the about.page file 👎. This practice was last performed and maintained until Mecha version 2.6.4:

    ---
    title: Comment
    description: Built-in commenting system.
    version: 1.0.0
    use:
      '.\lot\x\alert': 1
      '.\lot\x\asset': 1
      '.\lot\x\form': 0
      '.\lot\x\page': 1
    ...
    
    Lorem ipsum dolor sit amet.
  3. Renaming Anemon class to Anemone or simply rename it to another term if it is too long because when I search for it, the correct result is always directed to anemone.

    Screenshot 2021-11-15 at 20-39-27 ANEMON Synonyms Antonyms Thesaurus com

  4. Removing Cookie, Get, Post, Request, Server and Session class. It is better to optimize the automatic value evaluation from the first time the request is made. Using native $_GET and $_POST variable is not that bad. You can still use the function get(), let() and set() if you like the dot notation syntax.

    https://github.com/mecha-cms/mecha/blob/v2.6.4/engine/fire.php#L24-L45

    Working with cookies is still quite difficult, because determining the expiration time on cookies is not user friendly. It is also not possible to store cookie data other than as strings, except with the help of functions to encode data from/to strings. So a helper function may still be needed:

    if ('POST' === $_SERVER['REQUEST_METHOD'] && 0 === get($_POST, 'foo.bar')) {
        cookie('foo', [1, 2, 3], '1 week');
    }
  5. Removing Files class, to get rid of the assumption that this class is an optimizer for the global variable $_FILES, as Get class was for optimizing $_GET and Post class was for optimizing $_POST.

  6. Removing Folders class. This class is useless.

  7. Removing Guard class.

  8. Removing Lot class.

  9. Removing Route class.

  10. Removing Cache class. Might be more suitable as an extension.

  11. Removing Client class.

  12. Moving HTML and SGML class to layout extension.

  13. Removing Path class. This class is like a group of static functions hosted under namespace Path. Useless. There are better functions, including the native ones:

    • Path::B($path)basename($path)
    • Path::D($path, 2)dirname($path, 2) … FYI, PHP already support directory traversal with configurable levels.
    • Path::F($path)dirname($path) . DS . pathinfo($path, PATHINFO_FILENAME)
    • Path::N($path)basename($path, '.txt')
    • Path::R($path, ROOT)strtr($path, [ROOT . DS => ""])
    • Path::X($path)pathinfo($path, PATHINFO_EXTENSION)
taufik-nurrohman commented 2 years ago
.\lot\x\
├── alert\
├── asset\
├── layout\
├── link\
├── markdown\
├── page\
└── y-a-m-l\
  1. Removing art and form extension from the core, and make alert extension optional. The default layout does not need any alert message and cache manager to work. Simply by removing $alert variable from layout files, it will automatically remove alert extension from the dependency list.
taufik-nurrohman commented 2 years ago

Typical extension file structure:

.\x\page\
├── engine\
│   ├── use\ 👎
│   │   ├── page.php
│   │   ├── pager\
│   │   ├── pager.php
│   │   └── pages.php
│   └── use.php
├── about.page
└── index.php
taufik-nurrohman commented 2 years ago

To make alert extension becomes optional, replace all $alert variable with layout part:

<form method="post">
  <?= self::alert(); ?>
  <p>
    <button type="submit">
      Save
    </button>
  </p>
</form>

And in the alert extension, add a layout register that returns default HTML markup for alert(s) if there is no .\lot\layout\alert.php file:

if (!is_file(LOT . DS . 'layout' . DS . 'alert.php')) {
    Layout::set('alert', '.\path\to\alert.php');
}

The advantage of this technique is that authors can create their own custom alert markup by creating an alert.php file in the .\lot\layout folder. This will be useful if the author wants to use Mecha for certain design frameworks like Bootstrap or TailwindCSS.

Other extensions involving layout should also follow this change. For example, the default comment list layout can be declared in the comment extension only if the .\lot\layout\comments.php file does not exist.

taufik-nurrohman commented 2 years ago

⚠️ I’m canceling my plans.

170