The cumulative Assembly of ZF in a single file
the theme of the unification of PHP class in the Zend Framework (and others following the same conventions of naming and placing) publish their solution, which implements the __autoload with a storage Assembly startup classes.
It takes into account two known issues:
The solution is based on the example of implementation of __autoload from the book of Dmitry koterova on PHP5 and the idea described here.
the
Used it in this way:
1. Somewhere in the beginning of the script, but after the initialization of the library paths (set_include_path(...)) add:
2. Somewhere at the end of the script (you can put in the register_shutdown_function, but I have not tried) is added:
Of course, that it will work you must first Zend Framework e cut out all require|include
I'm using this technique:
To reset the cache should be easy to remove All.php that will create new and it will grow until users bypass all the "nooks and crannies" of the site. However, here I see one problem: because of frequent changes (in growth) All.php FastCGI processes start much shipping system, so after removal is sometimes necessary to overload the FastCGI processes manually.
the
In the case that was avtoagregatny any new files for the algorithm of the method compileTo is as follows:
autoload.zip (6 KB)
Article based on information from habrahabr.ru
It takes into account two known issues:
-
the
- In the file contains the variable __FILE__ is the substitution of this variable. the
- handle the case of parallel execution of scripts.
The solution is based on the example of implementation of __autoload from the book of Dmitry koterova on PHP5 and the idea described here.
the
Application
Used it in this way:
1. Somewhere in the beginning of the script, but after the initialization of the library paths (set_include_path(...)) add:
require_once "My/NameScheme/Autoload.php";
if (@fopen('All.php' 'r' true)) {
include_once('All.php');
}
2. Somewhere at the end of the script (you can put in the register_shutdown_function, but I have not tried) is added:
My_NameScheme_Autoload::compileTo(APP_ROOT . '/includes/All.php'); //where the file path should be relevant to your case
Of course, that it will work you must first Zend Framework e cut out all require|include
I'm using this technique:
$file = preg_replace('/((?:require|include)_once\s*\(?[\'"]Zend\/(.*)[\'"]\)?\s*;)/smiU' '//*** $1', $file);
To reset the cache should be easy to remove All.php that will create new and it will grow until users bypass all the "nooks and crannies" of the site. However, here I see one problem: because of frequent changes (in growth) All.php FastCGI processes start much shipping system, so after removal is sometimes necessary to overload the FastCGI processes manually.
the
Algorithm
In the case that was avtoagregatny any new files for the algorithm of the method compileTo is as follows:
-
the
- Block All.php the
- Check if there is already in All.php classes that were also avtoagregatny (for example, while I worked on this script in parallel another script successfully obrabotal and something disaposal in All.php). If this happens, then in order to avoid problems with dependencies of work the method will be aborted. the
- Appends to All.php new class. the
- Unlock All.php.
Download
autoload.zip (6 KB)
Комментарии
Отправить комментарий