I am right now working with the Doctrine 2 stuff and landed upon the Doctrine modules for validations like ObjectExists.php and NoObjectExists.php.
My question is that from the original code which can be found 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);
}
I cannot get the fact that here it is mentioned “$options required keys are object_repository, which must be an instance of Doctrine\Common\Persistence\ObjectRepository“
Since Doctrine\Common\Persistence\ObjectRepository is an interface, how should I decode that statement?
Or in other words how can I call this constructor of ObjectsExists class and pass object_repository, which must be an instance of Doctrine\Common\Persistence\ObjectRepository?
Can somebody throw some light on this, I’m getting into this stuff, so do not be harsh on my question.
Thanks
Since
Doctrine\Common\Persistence\ObjectRepositoryis an interface you cannot instantiate it but you can implement it.Now every instance of
MyObjectRepositorywill met theobject_repositoryrequirement ofObjectsExists.More about
instanceof: