/**
  * @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];
 }
Exemple #2
0
 /**
  * Check if class name of entity is valid.
  * @param string
  * @param bool
  * @return bool
  * @throws InvalidEntityException
  * @see IRepository::getEntityClassName()
  * @todo strtolower mozna bude moc pomale
  */
 private function checkEntityClassName($entityName, $throw = true)
 {
     if (!isset($this->allowedEntities[strtolower($entityName)])) {
         if ($throw) {
             $tmp = (array) $this->repository->getEntityClassName();
             $tmpLast = array_pop($tmp);
             $tmp = $tmp ? "'" . implode("', '", $tmp) . "' or '{$tmpLast}'" : "'{$tmpLast}'";
             throw new InvalidEntityException(get_class($this->repository) . " can't work with entity '{$entityName}', only with {$tmp}");
         }
         return false;
     }
     return true;
 }
Exemple #3
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)));
 }
Exemple #4
0
 /**
  * Loads collection of entities for this association.
  * @param IRepository
  * @param array of scalar
  * @return IEntityCollection
  */
 protected function loadCollection(IRepository $repository, array $ids)
 {
     if (!$ids) {
         return new ArrayCollection(array());
     }
     return $repository->getMapper()->findById($ids);
 }
 public function processRequest(IRepository &$repository, IRequest &$request, IBinaryDataRepository &$binaryRepository)
 {
     $criteria = $request->getCriteria();
     $result = $repository->find($criteria);
     return $result != null && count($result) > 0 ? $result[0] : new Page();
 }