mecha-cms / mecha

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

Remove CRUD Utility from `File` and `Folder` Class #153

Closed taufik-nurrohman closed 3 years ago

taufik-nurrohman commented 3 years ago

File class and its derivative classes such as Page, Tag and User should be read-only. This also includes the Folder class.

I realized that native PHP functions aren’t that bad. Adding and removing files/folders using native PHP functions should increase the performance.

file_get_contents() and file_put_contents() are quite common. Even, we have the short function equivalent named content(). The content() function should be enough to do a quick CRUD task. The missing functions in my opinion are:

taufik-nurrohman commented 3 years ago

purge() for recursive file delete?

taufik-nurrohman commented 3 years ago

Look like it is okay to use delete:

There is no delete keyword or function in the PHP language. If you arrived at this page seeking to delete a file, try unlink(). To delete a variable from the local scope, check out unset().

So, the CRUD functions proposal would be:

content() function should be read only after this, as create task will be managed by save().

taufik-nurrohman commented 3 years ago

Need a replacement for File::push(). push() is not the candidate here as File::pull() accept private file path, while File::push() accept $_FILES array.

Maybe store() would be appropriate.

taufik-nurrohman commented 3 years ago

However, push() is still considered useful, as if it can accept either private file path or a public file URL. If it uses private file path, it will behaves like PHP copy() function with the benefit of automatic folder creation if it does not exist. If it uses public file URL, it will behaves like PHP curl() that stores the result to the server (e.g. can be used to make an upload functionality with URL input).