mecha-cms / mecha

Minimalist content management system.

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`__` to `.` Convention

taufik-nurrohman opened this issue Β· comments

I must be crazy! Just another breaking changes idea that still floating around my head.

  1. The p2f() function converts __ prefix into . character but that applies only if __ character exists in the first property name. Looks tricky and too strict for me because the rest of __ are not converted into dots.
  2. This breaks a lot because most of namespaced functions are started with _\lot\x where in this case _\lot\x is better to be compatible with ./lot/x return value. So, it is likely I will rename them into __\lot\x.

What I want to do:

  1. RENAME ALL EXTENSION FUNCTION NAMESPACES FROM _\lot\x\* TO __\lot\x\* 😱
  2. DO NOT CONVERT \ INTO . BUT INTO / πŸ”₯

What will happen if these changes applied:

  1. No more repeated replacement like this.

  2. As \ will be changed into /, so namespaced functions will be easier to be converted into file path. This would change the way class auto-loader works. To load namespaced classes, you will need to put them under certain directory name, which is, in my opinion, looks pretty neat:

    // Before
    .\
    └── engine\
        └── kernel\
            β”œβ”€β”€ pager.php
            β”œβ”€β”€ pager.page.php
            └── pager.pages.php
    
    // After
    .\
    └── engine\
        └── kernel\
            β”œβ”€β”€ pager\
            β”‚   β”œβ”€β”€ page.php
            β”‚   └── pages.php
            └── pager.php

Seems to have more benefits. Nice issue number by the way.

To simplify the namespace specification, and to prevent me from experimenting with new ideas to create namespace according to the exact folder position, I decided to simply give namespace x for extension-related functions and layout for layout-related functions.

namespace layout\autumn;

function recent_comment_hooks() {}
function recent_page_hooks() {}
namespace x\panel;

function type() {}
function route() {}

You don’t have to provide namespace if your functions are unique enough and may be used as a feature enhancer for layouts and extensions, globally.

There may be various possible namespace specifications for special features as well, based on the existence of certain folders under .\lot. For example, users may add custom route using functions instead of files:

namespace route\ajax;

function image_upload() {} // `http://127.0.0.1/route/ajax/image-upload`

Fixed on the main branch.