我现在正在使用 Doctrine 2 的东西,并使用 Doctrine 模块进行验证,例如ObjectExists.php
和NoObjectExists.php
.
我的问题是从原始代码中可以找到here。
/**
* Constructor
*
* @param array $options required keys are `object_repository`, which must be an instance of
* Doctrine\Common\Persistence\ObjectRepository, and `fields`, with either
* a string or an array of strings representing the fields to be matched by the validator.
* @throws \Zend\Validator\Exception\InvalidArgumentException
*/
public function __construct(array $options)
{
if (!isset($options['object_repository']) || !$options['object_repository'] instanceof ObjectRepository) {
if (!array_key_exists('object_repository', $options)) {
$provided = 'nothing';
} else {
if (is_object($options['object_repository'])) {
$provided = get_class($options['object_repository']);
} else {
$provided = getType($options['object_repository']);
}
}
throw new Exception\InvalidArgumentException(sprintf(
'Option "object_repository" is required and must be an instance of'
. ' Doctrine\Common\Persistence\ObjectRepository, %s given',
$provided
));
}
$this->objectRepository = $options['object_repository'];
if (!isset($options['fields'])) {
throw new Exception\InvalidArgumentException(
'Key `fields` must be provided and be a field or a list of fields to be used when searching for'
. ' existing instances'
);
}
$this->fields = $options['fields'];
$this->validateFields();
parent::__construct($options);
}
我无法理解这里提到的“$options
必需的键是object_repository
,它必须是Doctrine\Common\Persistence\ObjectRepository
”的一个实例
既然Doctrine\Common\Persistence\ObjectRepository
是接口,我应该如何解码该语句?
或者换句话说,我怎样才能调用这个ObjectsExists
类的构造函数并传递object_repository
,它必须是一个实例Doctrine\Common\Persistence\ObjectRepository
?
有人可以对此有所了解吗,我正在研究这些东西,所以不要对我的问题苛刻。
谢谢