mecha-cms / mecha

Minimalist content management system.

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove `Lot` Class

taufik-nurrohman opened this issue · comments

This is based on request methods and PATCH request method overview. Once upon a time, my first plan was to add all HTTP request methods to Mecha. But as 9 items is too much for the core, it made me hesitant to implement it.

class Request {}

class Connect extends Request {}
class Delete extends Request {}
class Get extends Request {}
class Head extends Request {}
class Options extends Request {}
class Patch extends Request {}
class Post extends Request {}
class Put extends Request {}
class Trace extends Request {}

I’ve been trying to limit myself for a long time by shifting my focus from the HTTP standard to the HTML form standard, so that I can only support GET and POST method with a reason: because the only accepted methods for HTML forms so far are GET and POST.

Sure, there is also a DIALOG method… but this method is interactive and not really related to PHP. Just like URL’s hash which will not affect the PHP behavior. So, it will be more suitable to be implemented in JavaScript.

Currently, we already have Get and Post class for the HTTP. This is considered enough since PHP itself only have $_GET and $_POST variables for the HTTP.

Back to the topic! Why should I delete the class Lot then?

It is because class Lot has the potential to be renamed to Head. Of course I could change the name to Head right away, but that will trigger the inner me to add Connect, Delete, Options, Patch, Put and Trace classes as well to the core, which in a PHP-based website is not required. You can still produce a complex website with just the support of GET and POST methods only to interact.

The Lot class can be removed once I get a better replacement method, probably via a static function, since editing HTTP headers is not common for extensions.

… once I get a better replacement method, probably via a static function.

Maybe a simple status function is enough, with optional HTTP headers definition next to the status code parameter:

function status(int $code = 200, array $lot = []) { … }

Usage:

if ('/feed.json' === $url->path) {
    status(200, ['content-type' => 'application/json']);
    echo json_encode($data);
    exit;
}

var_dump(status()); // `[200, [ … ]]`

Or, replace its role as a the old Anemon class:

$values = (new Lot($values))->sort([1, 'title'])->get();