mecha-cms / mecha

Minimalist content management system.

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

taufik-nurrohman opened this issue · comments

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:

  • File::exist() and Folder::exist() may be replaced by the exist() function.
  • touch() with adaptive mode input (e.g. can accept octal number in string format captured from form data). This can be replaced with a new function, probably I will give a name to it poke() or seal().
  • unlink() that can remove folder with its contents. This should be replaced with a new function. But I don’t have any idea about the function name for this kind of task. As I know, delete keyword is not reserved in PHP, and there is no PHP function named delete(). But I am still not sure. This name is too generic that probably, in the future, PHP would propose a native function named delete() anyway.

purge() for recursive file delete?

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:

  • delete()
  • move()
  • paste() (see the push() function below)
  • save()
  • seal()

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

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.

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