Closed taufik-nurrohman closed 2 years ago
.\lot\x\
├── alert\
├── asset\
├── layout\
├── link\
├── markdown\
├── page\
└── y-a-m-l\
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.
Rationales
Using
use
as the folder name to store classes because of the native PHP syntax for importing classes (and functions, and constants). 👎Using
use
as the folder name to store classes because of theuse
property used to list the dependencies of an extension or a layout as written in theabout.page
file 👎. This practice was last performed and maintained until Mecha version 2.6.4:Renaming
Anemon
class toAnemone
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.Removing
Cookie
,Get
,Post
,Request
,Server
andSession
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 functionget()
,let()
andset()
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:
Removing
Files
class, to get rid of the assumption that this class is an optimizer for the global variable$_FILES
, asGet
class was for optimizing$_GET
andPost
class was for optimizing$_POST
.Removing
Folders
class. This class is useless.Removing
Guard
class.Removing
Lot
class.Removing
Route
class.Removing
Cache
class. Might be more suitable as an extension.Removing
Client
class.Moving
HTML
andSGML
class tolayout
extension.Removing
Path
class. This class is like a group of static functions hosted under namespacePath
. 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)