This repository has been archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
87 lines (77 loc) · 2.42 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Prophet plugin for GodMode
*
* Provides helpers to allow use of Iddqd in testing context to rewrite
* classes and replace them with mocks.
*
* @author Sam Schmidt <[email protected]>
* @since 2015-11-05
* @company Linus Shops
*/
namespace LinusShops\Prophet\Plugins;
use LinusShops\Prophet\Events;
use LinusShops\Prophet\Events\Options;
use LinusShops\Prophet\Plugin;
use LinusShops\Prophet\PluginRepository;
use PD;
class Iddqd implements Plugin
{
const EVENT_INJECT = 'IDDQD_EVENT_INJECT';
private $config = array();
public function load()
{
require __DIR__ . '/vendor/autoload.php';
$dir = __DIR__;
$this->config = json_decode(file_get_contents(__DIR__.'/config.json'),true);
//Use the installed version of godmode, instead of the one bundled with the plugin.
$useMagentoGodmode = isset($this->config['use_magento_godmode']) ?
$this->config['use_magento_godmode'] : false;
;
$loader = function ($classname) use ($dir, $useMagentoGodmode) {
if ($useMagentoGodmode) {
return;
}
$path = explode('_', $classname);
require $dir
. '/vendor/linusshops/iddqd/src/app/code/community/'
. implode('/', $path)
. '.php';
};
spl_autoload_register($loader);
}
public function register()
{
PD::listen(Events::PROPHET_PREMAGENTO, function(Options $options){
$options->set('config_model', 'Linus_Iddqd_Model_Config');
});
PD::listen(Events::PROPHET_POSTMAGENTO, function(Options $options){
Events::dispatch(self::EVENT_INJECT, $options);
});
}
public function injectEvent($eventName, $className, $method, $handle)
{
/** @var \Linus_Iddqd_Model_Config $config */
$config = \Mage::getConfig();
$merge = clone $config->getPrototype();
$merge->loadString("
<config>
<global>
<events>
<{$eventName}>
<observers>
<{$handle}>
<type>object</type>
<class>{$className}</class>
<method>{$method}</method>
</{$handle}>
</observers>
</{$eventName}>
</events>
</global>
</config>
");
$config->extend($merge);
}
}
return new Iddqd();