我只是按照自定义指南操作,我遇到了ProductFactoryInterface(http://docs.sylius.org/en/1.0/customization/factory.html)的自定义示例问题
我总是得到同样的错误:
编译错误:AppBundle \ Factory \ ProductFactory :: createWithVariant()的声明: Sylius \ Component \ Core \ Model \ ProductInterface必须兼容 Sylius \分量\产品\厂\ ProductFactoryInterface :: createWithVariant(): Sylius \组件\产品\型号\ ProductInterface
我做错了什么?这是我的代码:
namespace AppBundle\Factory;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Product\Factory\ProductFactoryInterface;
class ProductFactory implements ProductFactoryInterface
{
/**
* @var ProductFactoryInterface
*/
private $decoratedFactory;
/**
* @param ProductFactoryInterface $factory
*/
public function __construct(ProductFactoryInterface $factory)
{
$this->decoratedFactory = $factory;
}
/**
* {@inheritdoc}
*/
public function createNew(): ProductInterface
{
return $this->decoratedFactory->createNew();
}
/**
* {@inheritdoc}
*/
public function createWithVariant(): ProductInterface
{
return $this->decoratedFactory->createWithVariant();
}
/**
* @return ProductInterface
*/
public function createDisabled(): ProductInterface
{
/** @var ProductInterface $product */
$product = $this->decoratedFactory->createNew();
$product->setEnabled(false);
return $product;
}
}
答案 0 :(得分:0)
如果您在顶部更改此使用声明:
use Sylius\Component\Core\Model\ProductInterface;
使用:
use Sylius\Component\Product\Model\ProductInterface;
有些接口在1.0.0发布之前就已经改变了,似乎并非所有文档都相应地反映了这些变化。