About “.local” files and override possibilities
Depending on how "low" you want to override, you have basically two possibilities. The first one, class aliasing, is for general use, where the second file, file override, is only some particular situations.
Using class aliasing
Class aliasing is a simple yet very powerful mecanism. It basically allows you to subsitute any class with another one when instanciated with the Factory. This substituion doesn't occur at the level of the PHP interpretor, so it avoids circularity problems.
Let's say for example, you want to override only one method of the PHPDS_core class. First you declare your class alias in the plugin.config.xml/ file:
then you define your override class in the file includes/MY_core.class.php:
class MY_core extends PHPDS_core
{
public function formatTimeDate ($time_stamp, $format_type_or_custom = 'default', $custom_timezone = false)
{
/* do my stuff */
}
}
That's it. Don't forget the re-install your plugin the first time, so the database is updated with the class alias declaration.
General File Overriding
In several places we tried to use ".local" files to allow you to override the default system files as much (where needed). For example, the starter, "index.php" (in the main phpdevshell directory) which is meant to instantiate and run the main instance of PHPDevShell, would give control to "index.local.php" if it is present. Here is a list of files that can be overridden with a .local file:
- index.php will give control to "index.local.php" if present (only wrapped in a very simple try/catch
- with every config file that is tried, a ".local" version will be tried as well (using "require_once()").
Overriding from the top
You can easily use a custom version of any of the Core Set by providing it in the appropriate method. For example, using "index.local.php" an alternate Skel:
require 'includes/PHPDS.inc.php';
require 'advanced_policy.php'; // the custom security object is defined here
class custom_PHPDS extends PHPDS
{
public function PHPDS_security ()
{
if (empty($this->security)) {
$this->security = new custom_security();
$this->security->PHPDS_dependance($this);
}
return $this->security;
}
}
$PHPDS = new custom_PHPDS;
$PHPDS->run();
The custom_security class is a daughter of PHPDS_security class with a little tweak, and now PHPDS is using it instead of the default security class. You can of course use this class method to provide parameters to your security instance if needed.
