* @throws coding_exception
*/
public static function load($id, array $definition, $datasourceaggregate = null) {
+ global $CFG;
+
if (!array_key_exists('mode', $definition)) {
throw new coding_exception('You must provide a mode when creating a cache definition');
}
if (!is_null($overrideclass)) {
if (!is_null($overrideclassfile)) {
+ if (strpos($overrideclassfile, $CFG->dirroot) !== 0) {
+ $overrideclassfile = $CFG->dirroot.'/'.$overrideclassfile;
+ }
+ if (strpos($overrideclassfile, '../') !== false) {
+ throw new coding_exception('No path craziness allowed within override class file path.');
+ }
if (!file_exists($overrideclassfile)) {
throw new coding_exception('The override class file does not exist.');
}
if (!is_null($datasource)) {
if (!is_null($datasourcefile)) {
+ if (strpos($datasourcefile, $CFG->dirroot) !== 0) {
+ $datasourcefile = $CFG->dirroot.'/'.$datasourcefile;
+ }
+ if (strpos($datasourcefile, '../') !== false) {
+ throw new coding_exception('No path craziness allowed within data source file path.');
+ }
if (!file_exists($datasourcefile)) {
- throw new coding_exception('The override class file does not exist.');
+ throw new coding_exception('The data source class file does not exist.');
}
require_once($datasourcefile);
}
if (!class_exists($datasource)) {
- throw new coding_exception('The override class does not exist.');
+ throw new coding_exception('The data source class does not exist.');
}
if (!array_key_exists('cache_data_source', class_implements($datasource))) {
throw new coding_exception('Cache data source classes must implement the cache_data_source interface');
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'datasourcetest',
- 'datasource' => 'cache_phpunit_dummy_datasource'
+ 'datasource' => 'cache_phpunit_dummy_datasource',
+ 'datasourcefile' => 'cache/tests/fixtures/lib.php'
));
$cache = cache::make('phpunit', 'datasourcetest');
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'overridetest',
- 'overrideclass' => 'cache_phpunit_dummy_overrideclass'
+ 'overrideclass' => 'cache_phpunit_dummy_overrideclass',
+ 'overrideclassfile' => 'cache/tests/fixtures/lib.php'
));
$cache = cache::make('phpunit', 'overridetest');
$this->assertInstanceOf('cache_phpunit_dummy_overrideclass', $cache);