Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84cd22d

Browse files
committed
new branch for DDC-753
1 parent 2b3bee1 commit 84cd22d

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

lib/Doctrine/ORM/Configuration.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,31 @@ public function getClassMetadataFactoryName()
516516
}
517517
return $this->_attributes['classMetadataFactoryName'];
518518
}
519+
520+
/**
521+
* Set default repository class.
522+
*
523+
* @since 2.2
524+
* @param string $className
525+
* @throws ORMException If not implements Doctrine\Common\Persistence\ObjectRepository
526+
*/
527+
public function setDefaultRepositoryClassName($className)
528+
{
529+
if (!is_subclass_of($className, 'Doctrine\Common\Persistence\ObjectRepository')) {
530+
throw ORMException::invalidObjectRepository($className);
531+
}
532+
$this->_attributes['defaultRepositoryClassName'] = $className;
533+
}
534+
535+
/**
536+
* Get default repository class.
537+
*
538+
* @since 2.2
539+
* @return string
540+
*/
541+
public function getDefaultRepositoryClassName()
542+
{
543+
return isset($this->_attributes['defaultRepositoryClassName']) ?
544+
$this->_attributes['defaultRepositoryClassName'] : 'Doctrine\ORM\EntityRepository';
545+
}
519546
}

lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,12 +1519,17 @@ protected function _storeAssociationMapping(array $assocMapping)
15191519
* Registers a custom repository class for the entity class.
15201520
*
15211521
* @param string $mapperClassName The class name of the custom mapper.
1522+
* @throws MappingException If not implements Doctrine\Common\Persistence\ObjectRepository
15221523
*/
15231524
public function setCustomRepositoryClass($repositoryClassName)
15241525
{
15251526
if ($repositoryClassName !== null && strpos($repositoryClassName, '\\') === false
15261527
&& strlen($this->namespace) > 0) {
15271528
$repositoryClassName = $this->namespace . '\\' . $repositoryClassName;
1529+
1530+
if (!is_subclass_of($repositoryClassName, 'Doctrine\Common\Persistence\ObjectRepository')) {
1531+
throw MappingException::invalidObjectRepository($repositoryClassName);
1532+
}
15281533
}
15291534
$this->customRepositoryClassName = $repositoryClassName;
15301535
}

lib/Doctrine/ORM/ORMException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ public static function unknownEntityNamespace($entityNamespaceAlias)
130130
"Unknown Entity namespace alias '$entityNamespaceAlias'."
131131
);
132132
}
133+
134+
public static function invalidObjectRepository($className) {
135+
return new self("Invalid repository class '".$className."'. ".
136+
"it must implement Doctrine\Common\Persistence\ObjectRepository.");
137+
}
133138
}

0 commit comments

Comments
 (0)