Skip to content

Commit 12fd281

Browse files
committed
fix: getting class loader, fixes #51
1 parent ab570a0 commit 12fd281

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Component/Generator/Definition/EntityLoader.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PhpParser\NodeFinder;
1212
use PhpParser\ParserFactory;
1313
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry;
14+
use Shopware\Core\Kernel;
1415
use Symfony\Component\Console\Style\SymfonyStyle;
1516
use Symfony\Component\Filesystem\Filesystem;
1617

@@ -25,9 +26,12 @@ class EntityLoader
2526
*/
2627
private $instanceRegistry;
2728

28-
public function __construct(DefinitionInstanceRegistry $instanceRegistry)
29+
private Kernel $kernel;
30+
31+
public function __construct(DefinitionInstanceRegistry $instanceRegistry, Kernel $kernel)
2932
{
3033
$this->instanceRegistry = $instanceRegistry;
34+
$this->kernel = $kernel;
3135
}
3236

3337
public function load(string $class, SymfonyStyle $io): Definition
@@ -194,8 +198,7 @@ private function normalizeName(string $class): string
194198

195199
private function getNewEntityFolder(string $namespace): string
196200
{
197-
global $classLoader;
198-
$prefixes = $classLoader->getPrefixesPsr4();
201+
$prefixes = $this->kernel->getPluginLoader()->getClassLoader()->getPrefixesPsr4();
199202

200203
$namespaceSplit = explode('\\', $namespace);
201204
unset($namespaceSplit[count($namespaceSplit) -1 ]);

src/Resources/config/services.xml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<defaults>
1616
</defaults>
1717

18+
<service id="Shopware\Core\Kernel" alias="kernel"/>
19+
1820
<instanceof id="Frosh\DevelopmentHelper\Component\Generator\QuestionHandler\QuestionHandlerInterface">
1921
<tag name="frosh_development_helper.question_helper"/>
2022
</instanceof>

0 commit comments

Comments
 (0)