I
I
IsaevDev2015-09-25 02:00:47
PHP
IsaevDev, 2015-09-25 02:00:47

How do you like this autoload for PHP?

Take a moment to bike a little for a small project
There are files
/Core.php
/Map.php
/custom/Class.php
The autoload function is defined, which will take the path to the class file from Map.php
When developed, Map.php looks like this:

<?
class Map
{
public static $inited = false;
}
?>

The essence of the approach is as follows:
After uploading files to the server, at the first start, Core.php checks the Map:: $inited variable. If it finds
false there, Core.php recursively bypasses all files and folders in /custom and compiles an array of the form
$map = [
'Class' => '/custom/'
];

Then it overwrites the Map class with $inited = true (re-saves as a file).
Thus, the next time you start, the created class map will be used.
PS. Yes, I know about composer and namespace. I want to hear your opinion on my approach from a technical point of view

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2015-09-25
@IsaevDev

Everything has already been invented for you www.php-fig.org/psr/psr-4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question