mecha-cms / mecha

Minimalist content management system.

Home Page:https://mecha-cms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Less Folder Structure Maybe?

taufik-nurrohman opened this issue Β· comments

.\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)
.\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.

Typical extension file structure:

.\x\page\
β”œβ”€β”€ engine\
β”‚   β”œβ”€β”€ use\ πŸ‘Ž
β”‚   β”‚   β”œβ”€β”€ page.php
β”‚   β”‚   β”œβ”€β”€ pager\
β”‚   β”‚   β”œβ”€β”€ pager.php
β”‚   β”‚   └── pages.php
β”‚   └── use.php
β”œβ”€β”€ about.page
└── index.php

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.

⚠️ I’m canceling my plans.

#170