/**
  * @param IRepository
  * @return IManyToManyMapper
  */
 public final function getMapper(IRepository $parentRepository)
 {
     $model = $parentRepository->getModel();
     $hash = spl_object_hash($model);
     $repoClass = get_class($parentRepository);
     if (!isset($this->mappers[$hash][$repoClass])) {
         $childRepository = $model->getRepository($this->getChildRepository());
         $mapped = $this->getWhereIsMapped();
         if ($mapped === RelationshipMetaDataToMany::MAPPED_HERE or $mapped === RelationshipMetaDataToMany::MAPPED_BOTH) {
             $repoMapper = $parentRepository->getMapper();
             $mapper = $repoMapper->createManyToManyMapper($this->getParentParam(), $childRepository, $this->getChildParam());
         } else {
             if ($mapped === RelationshipMetaDataToMany::MAPPED_THERE) {
                 $repoMapper = $childRepository->getMapper();
                 $mapper = $repoMapper->createManyToManyMapper($this->getChildParam(), $parentRepository, $this->getParentParam());
             }
         }
         if (!$mapper instanceof IManyToManyMapper) {
             throw new BadReturnException(array($repoMapper, 'createManyToManyMapper', 'Orm\\IManyToManyMapper', $mapper));
         }
         $mapper->attach($this);
         $this->mappers[$hash][$repoClass] = $mapper;
     }
     return $this->mappers[$hash][$repoClass];
 }
Beispiel #2
0
 /**
  * @param IRepository
  * @return string
  */
 public function getTable(IRepository $repository)
 {
     $helper = $repository->getModel()->getContext()->getService('repositoryHelper', 'Orm\\RepositoryHelper');
     return str_replace('\\', '_', strtolower($helper->normalizeRepository($repository)));
 }