/ * library / Zend / Loader.php * /
public static function loadClass ($ class, $ dirs = null)
{
if (class_exists ($ class, false) || interface_exists ($ class, false)) {
return;
}
if ((null! == $ dirs) &&! is_string ($ dirs) &&! is_array ($ dirs)) {
// require_once 'Zend / Exception.php';
throw new Zend_Exception ('Directory argument must be a string or an array');
}
// autodiscover the path from the class name
$ file = str_replace ('_', DIRECTORY_SEPARATOR, $ class). '.php';
if (! empty ($ dirs)) {
// use the autodiscovered path
$ dirPath = dirname ($ file);
if (is_string ($ dirs)) {
$ dirs = explode (PATH_SEPARATOR, $ dirs);
}
foreach ($ dirs as $ key => $ dir) {
if ($ dir == '.') {
$ dirs [$ key] = $ dirPath;
} else {
$ dir = rtrim ($ dir, '\\ /');
$ dirs [$ key] = $ dir. DIRECTORY_SEPARATOR. $ dirPath;
}
}
$ file = basename ($ file);
self :: loadFile ($ file, $ dirs, true);
} else {
self :: _ securityCheck ($ file);
include $ file;
}
// add from here
$ files = file (APPLICATION_PATH. '/../data/files.txt');
$ files [] = $ file;
$ files = array_unique ($ files);
file_put_contents (APPLICATION_PATH. '/../data/files.txt', implode ("\ n", $ files));
// get here
if (! class_exists ($ class, false) &&! interface_exists ($ class, false)) {
// require_once 'Zend / Exception.php';
throw new Zend_Exception ("File \" $ file \ "does not exist or class \" $ class \ "was not found in the file");
}
}
<?
$ skip = array (
T_COMMENT, T_OPEN_TAG, T_CLOSE_TAG, T_DOC_COMMENT, T_ML_COMMENT // See comments from HotPlug! and all sorts of <? and?> also nafig
);
$ dir = "d: \ work \ undefeasibility \ library \\";
$ files = file ('d: \ work \ undefeatable \ app \ data \ files.txt');
$ res = '<?';
foreach ($ files as $ file) {
if (substr (trim ($ file), -4)! = '.php')
$ file = str_replace ('_', '\\', trim ($ file)). ".php"; // if there is a class name, not a file name, we modify it
if (is_file ($ fileName = trim ($ dir. $ file))) {
$ res. = "\ n / * $ file * / \ n";
$ tokens = token_get_all (file_get_contents ($ fileName));
$ was_require_once = 0;
$ was_shit_require_once = 0;
foreach ($ tokens as $ token) {
if (is_array ($ token)) {
if (in_array ($ token [0], $ skip))
continue;
if ($ token [0] == T_WHITESPACE) {
$ res. = ''; // less space on any tabs
continue;
}
if ($ was_require_once) {
if ($ token [0] == T_CONSTANT_ENCAPSED_STRING) {// skip require_once, followed by a string in quotes. if something like $ file then goes - no need to skip! too dirty method, you should think
$ was_shit_require_once = 1;
} else {
$ res. = 'require_once'. $ token [1];
}
$ was_require_once = 0;
continue;
}
if ($ token [0] == T_REQUIRE_ONCE) {
$ was_require_once = 1;
} else {
$ res. = $ token [1];
}
} else {
if (! $ was_shit_require_once) // to ";" after require_once removed delete
$ res. = $ token;
$ was_shit_require_once = 0;
}
}
$ res. = "\ n";
}
}
file_put_contents ("d: \ work \ undefeatable \ app \ data \ HotPlug.php", $ res);
<?
function getDirectoryTree ($ outerDir) {
$ dirs = array_diff (scandir ($ outerDir), Array (".", ".."));
$ dir_array = Array ();
foreach ($ dirs as $ d) {
if (is_dir ($ outerDir. "/". $ d)) $ dir_array [$ d] = getDirectoryTree ($ outerDir. "/". $ d);
else $ dir_array [$ d] = $ d;
}
return $ dir_array;
}
$ dirs = getDirectoryTree ("d: \ work \ test \ library \ Zend");
function gotcha ($ fname, $ key, $ dir) {
if (is_array ($ fname)) {
array_walk ($ fname, 'gotcha', $ dir. DIRECTORY_SEPARATOR. $ key);
return;
}
$ fname = $ dir. DIRECTORY_SEPARATOR. $ fname;
file_put_contents ($ fname, preg_replace ("/ require_once \\ s + \ 'Zend /", "// require_once \' Zend", file_get_contents ($ fname))); // it would be worth writing / (require | include) _once \\ s + (\ '| \ ") / or something like that, but I was - well, you guessed it - I had to test this preg and I ran the script 4 times in a row. Fortunately, after that he is no longer needed at all :)
}
array_walk ($ dirs, 'gotcha', "d: \ work \ pysch \ library \ Zend");
// Somewhere in Bootstrap.php, or - for me - in /library/R00/Bootstrap.php, from which my project's bootstraps are inherited Zend_Loader_PluginLoader :: setIncludeFileCache (APPLICATION_PATH. '/../Data/cache.php');
Zend_Loader_PluginLoader :: setIncludeFileCache (APPLICATION_PATH. '/../Data/files.txt');
protected static function _appendIncFile ($ incFile)
{
if (! file_exists (self :: $ _ includeFileCache)) {
$ file = ''; // change time
} else {
$ file = file_get_contents (self :: $ _ includeFileCache);
}
if (! strstr ($ file, $ incFile)) {
$ file. = "\ n $ incFile \ n"; // two change
file_put_contents (self :: $ _ includeFileCache, $ file);
}
}
Source: https://habr.com/ru/post/73273/
All Articles