6
6
namespace Magento \Log \Console \Command ;
7
7
8
8
use Symfony \Component \Console \Command \Command ;
9
- use Magento \Store \ Model \ StoreManager ;
10
- use Magento \Framework \App \DeploymentConfig ;
11
- use Magento \Framework \App \ObjectManagerFactory ;
12
- use Magento \Framework \App \ ObjectManager ;
9
+ use Magento \Backend \ App \ Area \ FrontNameResolver ;
10
+ use Magento \Framework \App \ObjectManager \ ConfigLoader ;
11
+ use Magento \Framework \App \State ;
12
+ use Magento \Framework \ObjectManagerInterface ;
13
13
14
14
/**
15
15
* Abstract class for commands related to manage Magento logs
@@ -19,29 +19,51 @@ abstract class AbstractLogCommand extends Command
19
19
/**
20
20
* Object Manager
21
21
*
22
- * @var ObjectManager
22
+ * @var ObjectManagerInterface
23
23
*/
24
24
protected $ objectManager ;
25
25
26
+ /**
27
+ * Config loader
28
+ *
29
+ * @var ConfigLoader
30
+ */
31
+ private $ configLoader ;
32
+
33
+ /**
34
+ * Application state
35
+ *
36
+ * @var State
37
+ */
38
+ private $ state ;
39
+
26
40
/**
27
41
* Constructor
28
42
*
29
- * @param ObjectManagerFactory $objectManagerFactory
43
+ * @param ObjectManagerInterface $objectManager
44
+ * @param ConfigLoader $configLoader
45
+ * @param State $state
30
46
*/
31
- public function __construct (ObjectManagerFactory $ objectManagerFactory )
32
- {
33
- $ params = $ _SERVER ;
34
- $ params [StoreManager::PARAM_RUN_CODE ] = 'admin ' ;
35
- $ params [StoreManager::PARAM_RUN_TYPE ] = 'store ' ;
36
- $ this ->objectManager = $ objectManagerFactory ->create ($ params );
47
+ public function __construct (
48
+ ObjectManagerInterface $ objectManager ,
49
+ ConfigLoader $ configLoader ,
50
+ State $ state
51
+ ) {
52
+ $ this ->objectManager = $ objectManager ;
53
+ $ this ->configLoader = $ configLoader ;
54
+ $ this ->state = $ state ;
37
55
parent ::__construct ();
38
56
}
39
57
40
58
/**
41
- * {@inheritdoc}
59
+ * Reinitialise object manager with correct area
60
+ *
61
+ * @return void
42
62
*/
43
- protected function configure ()
63
+ protected function initApplicationArea ()
44
64
{
45
- parent ::configure ();
65
+ $ area = FrontNameResolver::AREA_CODE ;
66
+ $ this ->state ->setAreaCode ($ area );
67
+ $ this ->objectManager ->configure ($ this ->configLoader ->load ($ area ));
46
68
}
47
69
}
0 commit comments