Here are some additional ones that I've added for some clients, or just ideas that I've been pondering but haven't fully come to fruition:
Autoload javascript folder
Javascripts are so cool because they can be kept in their own abstract layer, without having to edit files 99% of the time. But ironically enough, to add a new script, you have to edit the code to add the script tag. Instead there should be an autoload subdirectory in the javascript folder where all script files inside this folder are automatically added as script tags to the main layout.
The layout file would then have a simple glob() call for that directory and loop through each file, adding it to the <head></head> tags of the page. Something like:
Code: Select all
<?php // Autoload Javascript ?>
<?php $files = glob(DIR_AUTOLOADJS . '*.js'); ?>
<?php if ($files) { ?>
<?php foreach ($files as $filename) { ?>
<script type="text/javascript" src="<?php echo DIR_AUTOLOADJS . $filename; ?>"></script>
<?php } ?>
<?php } ?>
Dynamic Includes for loading new Registry entries
A folder that auto-includes for the index.php page so that new helpers and libraries can be loaded. Additionally, a way to dynamically include "pre-actions" that can load before other things.
Something like:
Code: Select all
// Weight
Registry::set('measurement', new HelperMeasurement());
// Cart
Registry::set('cart', new HelperCart());
// Dynamic includes
$files = glob(DIR_INCLUDES . '*.php'); ?>
if ($files) {
foreach ($files as $filename) {
include (DIR_INCLUDES . $filename;);
}
}
On-the-fly php preg_replace/str_replace
Anytime a php is included either by include or before it is eval'd with obstart()
There could be a check for a snippet file that uses some sort of relative naming convention. Example:
The helper function loads helper files. If you wanted to add code to change one of the helper files. You could change the function from this:
Code: Select all
public function helper($helper) {
$file = DIR_SYSTEM . 'helper/' . $helper . '.php';
if (file_exists($file)) {
include_once($file);
} else {
exit('Error: Could not load helper ' . $helper . '!');
}
}
Code: Select all
public function helper($helper) {
$file = DIR_SYSTEM . 'helper/' . $helper . '.php';
$patch_find = DIR_SYSTEM . 'helper/' . $helper . '.php_find';
$patch_repl = DIR_SYSTEM . 'helper/' . $helper . '.php_repl';
if (file_exists($file)) {
if (file_exists($patch)) {
$filedata = file_get_contents($file);
$find = file_get_contents($patch_find);
$repl = file_get_contents($patch_repl);
$filedata = str_replace($find, $repl, $filedata);
file_put_contents($filedata, $helper . '_tmp');
$file = DIR_SYSTEM . 'helper/' . $helper . '_tmp.php';
}
include_once($file);
} else {
exit('Error: Could not load helper ' . $helper . '!');
}
}
private function login ($email, $pass) {
to
private function login ($email, $pass, $xxx = '') {
Then load that version of the file with the change.
This could then make core mods easier by making find/repl patches that won't actually edit any core files.