File tree Expand file tree Collapse file tree
src/Model/TemplateEngine/Decorator Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55namespace OpenForgeProject \MageForge \Model \TemplateEngine \Decorator ;
66
7- use Magento \Framework \App \ObjectManager ;
87use Magento \Framework \Math \Random ;
98use Magento \Framework \View \Element \AbstractBlock ;
109use Magento \Framework \View \Element \BlockInterface ;
@@ -21,23 +20,23 @@ class InspectorHints implements TemplateEngineInterface
2120
2221 private bool $ showBlockHints ;
2322
24- private ? Random $ random = null ;
23+ private Random $ random ;
2524
2625 private string $ magentoRoot ;
2726
2827 /**
2928 * @param TemplateEngineInterface $subject
3029 * @param bool $showBlockHints
31- * @param Random|null $random
30+ * @param Random $random
3231 */
3332 public function __construct (
3433 TemplateEngineInterface $ subject ,
3534 bool $ showBlockHints ,
36- ? Random $ random = null
35+ Random $ random
3736 ) {
3837 $ this ->subject = $ subject ;
3938 $ this ->showBlockHints = $ showBlockHints ;
40- $ this ->random = $ random ?? ObjectManager:: getInstance ()-> get (Random::class) ;
39+ $ this ->random = $ random ;
4140
4241 // Get Magento root directory - try multiple strategies
4342 // 1. Try from BP constant (most reliable)
Original file line number Diff line number Diff line change 44
55namespace OpenForgeProject \MageForge \Model \TemplateEngine \Decorator ;
66
7- use Magento \Framework \ObjectManagerInterface ;
7+ use Magento \Framework \Math \Random ;
8+ use Magento \Framework \View \TemplateEngineInterface ;
89use OpenForgeProject \MageForge \Model \TemplateEngine \Decorator \InspectorHints ;
910
1011/**
1314class InspectorHintsFactory
1415{
1516 /**
16- * @param ObjectManagerInterface $objectManager
17+ * @param Random $random
1718 */
1819 public function __construct (
19- private readonly ObjectManagerInterface $ objectManager
20+ private readonly Random $ random
2021 ) {
2122 }
2223
@@ -28,8 +29,19 @@ public function __construct(
2829 */
2930 public function create (array $ data = []): InspectorHints
3031 {
31- /** @var InspectorHints $instance */
32- $ instance = $ this ->objectManager ->create (InspectorHints::class, $ data );
33- return $ instance ;
32+ $ subject = $ data ['subject ' ] ?? null ;
33+ $ showBlockHints = $ data ['showBlockHints ' ] ?? false ;
34+
35+ if (!$ subject instanceof TemplateEngineInterface) {
36+ throw new \InvalidArgumentException (
37+ 'Instance of " ' . TemplateEngineInterface::class . '" is expected. '
38+ );
39+ }
40+
41+ return new InspectorHints (
42+ $ subject ,
43+ (bool )$ showBlockHints ,
44+ $ this ->random
45+ );
3446 }
3547}
You can’t perform that action at this time.
0 commit comments