[Gelöst] Decorate Service / Namespace Verständnis-Frage

Hallo zusammen,

ich habe eine Verständnis-Frage zu Namespaces, speziell bei einem dekorierten Service.

Und zwar habe ich ProductSearch dekoriert, das funktioniert soweit auch wunderbar:

namespace MyPlugin\Bundle\SearchBundle;

use Shopware\Bundle\SearchBundle;
use Shopware\Bundle\StoreFrontBundle;
use Shopware\Bundle\SearchBundle\ProductSearch;
use Shopware\Bundle\SearchBundle\ProductSearchInterface;

class MyProductSearch implements ProductSearchInterface
{
    private $productSearch;

    public function __construct(ProductSearchInterface $productSearch)
    {
    	$this->productSearch = $productSearch;
    }
	
    public function search(SearchBundle\Criteria $criteria, StoreFrontBundle\Struct\ProductContextInterface $context)
    {
    	return $this->productSearch->search($criteria, $context);
    }
}

Wenn ich allerdings search mit absoluten Namespaces und ohne den ersten beiden ‘use’ aufrufe, bekomme ich eine Fehlermeldung:

Declaration of …MyProductSearch::search() must be compatible with Shopware\Bundle\SearchBundle\ProductSearchInterface::search(Shopware\Bundle\SearchBundle\Criteria $criteria, Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context)

public function search(Shopware\Bundle\SearchBundle\Criteria $criteria, Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context)

Sollte das nicht auch funktionieren?

Viele Grüße

Andi

Hi Andi,

ja tut es wenn du ganz am Anfang noch einen Backslash hinzufügst  Wink

public function search(\Shopware\Bundle\SearchBundle\Criteria $criteria, \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context)
    {
        // ...
    }

Viele Grüße

1 „Gefällt mir“

Super, vielen Dank für den Hinweis Smile

Den Backslash habe ich total übersehen, bzw. vergessen…

Viele Grüße

Andi