# sw52 Namespace in der neuen Pluginstruktur

**URL:** <https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728>\
**Category:** Programmierung\
**Created:** [5. Juli 2017 um 11:29 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728 "2017-07-05T11:29:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandy](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sandy](https://forum.shopware.com/u/Sandy)\
**Post date:** [5. Juli 2017 um 11:29 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/1 "2017-07-05T11:29:18Z")

</div>

Es geht um den Namespace in der sw52 Pluginstruktur.

Wir haben eine Core-Trait den wir in unseren Plugins per Trait-use nutzen möchten. Liegt der Trait in der alten Struktur unter Shopware\Plugins\Local\ funktioniert das so:

```
# custom/plugins/ExamplePlugin/ExamplePlugin.php
namespace ExamplePlugin;

use Shopware\Plugins\Local\NfCore\NfPluginCore;

class ExamplePlugin extends Plugin
{
    use NfPluginCore;
		...
}

#Shopware\Plugins\Local\NfCore\NfPluginCore.php
namespace Shopware\Plugins\Local\NfCore;

trait NfPluginCore
{...}

```

`Nun hätte ich den Trait aber auch gerne unter \custom\plugins\ , dort bekomme ich es aber nicht zu laufen. Hat jemand eine Idee wie dort der Namespace lauten muss?`

---

<div class="post-metadata">

**Author:** ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)\
**Post date:** [5. Juli 2017 um 11:46 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/2 "2017-07-05T11:46:05Z")

</div>

Die Plugins aus dem neuen Pluginsystem werden viel früher bereits im Kernel gebootet. Dort sind die “alten” Plugins noch nicht initalisiert worden. Ich würde an deiner Stelle das Plugin einfach in das neue Pluginsystem migrieren…

---

<div class="post-metadata">

**Author:** ![Sandy](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sandy](https://forum.shopware.com/u/Sandy)\
**Post date:** [5. Juli 2017 um 12:14 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/3 "2017-07-05T12:14:00Z")

</div>

Bei meinem Beispiel liegt das ExamplePlugin ja unter `custom/plugins/ExamplePlugin/ExamplePlugin.php` und nutze einen Trait in der alten Struktur, da dieses funktioniert. Jetzt möchte ich diesen Trait von `engine/Shopware/Plugins/Local/NfCore/NfPluginCore.php` verschieben nach `custom/plugins/NfCore/NfPluginCore.php` und in `custom/plugins/ExamplePlugin/ExamplePlugin.php` nutzen.

Also wie muss der Namespace lauten? Gibt es keinen Namespace für die Plugins an der neuen Stellen? Leider habe ich keinen Plan wie ich das mit den Namespaces debuggen kann ☹

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [5. Juli 2017 um 12:18 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/4 "2017-07-05T12:18:11Z")

</div>

Hast du denn den namespace registriert&nbsp;für den autoloader Oder hast du&nbsp;da einfach die Datei in den Ordner gepackt?

viele Grüße&nbsp;

---

<div class="post-metadata">

**Author:** ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)\
**Post date:** [5. Juli 2017 um 12:48 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/5 "2017-07-05T12:48:18Z")

</div>

Der Namespace müsste&nbsp;NfCore/NfPluginCore sein. Der PluginOrdner wird immer als Namespace erstellt siehe&nbsp;[shopware/PluginInitializer.php at 5fc10f63095a475e980c29db4ac476a271c6d5cd · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/5fc10f63095a475e980c29db4ac476a271c6d5cd/engine/Shopware/Bundle/PluginInstallerBundle/Service/PluginInitializer.php#L81)

---

<div class="post-metadata">

**Author:** ![Sandy](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sandy](https://forum.shopware.com/u/Sandy)\
**Post date:** [5. Juli 2017 um 13:41 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/6 "2017-07-05T13:41:33Z")

</div>

Ja das ist korrekt, jedoch will ich ja von `ExamplePlugin/ExamplePlugin` auf `NfCore/NfPluginCore` zugreifen. Und anscheinend ist zu diesem Zeitpunkt der Namespace NfCore/ noch nicht da. So das `use Shopware\Plugins\Local\NfCore\NfPluginCore` funktioniert, `NfCore\NfPluginCore` jedoch nicht.

---

<div class="post-metadata">

**Author:** ![Sandy](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sandy](https://forum.shopware.com/u/Sandy)\
**Post date:** [5. Juli 2017 um 15:11 UTC](https://forum.shopware.com/t/sw52-namespace-in-der-neuen-pluginstruktur/46728/7 "2017-07-05T15:11:45Z")

</div>

Sehr komisches verhalten, lasse ich mir in `vendor/symfony/class-loader/Psr4ClassLoader.php:44` die prefixe ausgeben. So bekomme ich bei `use Shopware\Plugins\Local\NfCore\NfPluginCore;` die 3 installierten Plugins unter `/custom/plugins/`. Mache ich `use NfCore\NfPluginCore` enthält prefixes nur das ExamplePlugin was ich über die console mit `console sw:plugin:reinstall ExamplePlugin` aufrufe. Nicht wirklich nachvollziehbar.
