投下一些評論我現在正在使用Doctrine 2的東西,並落在Doctrine模塊上進行驗證,如ObjectExists.php
和NoObjectExists.php
。從Doctrine 2模塊ObjectExists.php'ObjectExists.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
的實例?
有人可以提出這個問題,我正在研究這個問題,所以不要苛刻我的問題。
感謝