Esempio n. 1
0
 /**
  * @return PerformanceHelper|NULL
  * @see self::__construct()
  */
 protected function createPerformanceHelper()
 {
     if (PerformanceHelper::$keyCallback) {
         $context = $this->model->getContext();
         if ($context->hasService('performanceHelperCache')) {
             return new PerformanceHelper($this, $context->getService('performanceHelperCache', 'ArrayAccess'));
         }
     }
     return NULL;
 }
 /**
  * @param IRepositoryContainer
  * @param string MetaData::ManyToOne|MetaData::OneToOne|MetaData::ManyToMany|MetaData::OneToMany
  * @param bool
  * @param callback (RelationshipMetaData $parent, RelationshipMetaData $child)
  */
 protected function checkIntegrity(IRepositoryContainer $model, $expectedType, $requiredChildParam, $callback = NULL)
 {
     $lowerEntityName = strtolower($this->parentEntityName);
     $classes = array_values((array) $model->getRepository($this->childRepository)->getEntityClassName());
     $this->canConnectWith = array_combine(array_map('strtolower', $classes), $classes);
     if (!$this->childParam) {
         return;
     }
     foreach ($this->canConnectWith as $lowerEn => $en) {
         $meta = MetaData::getEntityRules($en, $model, $this->childParam);
         $e = NULL;
         if (isset($meta[$this->childParam])) {
             $meta = $meta[$this->childParam];
             try {
                 if ($meta['relationship'] !== $expectedType) {
                     throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neni asociace ktera by ukazovala zpet");
                 }
                 $loader = $meta['relationshipParam'];
                 if ($requiredChildParam and !$loader->childParam) {
                     throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neni vyplnen param ktery by ukazoval zpet");
                 }
                 if (!isset($loader->canConnectWith[$lowerEntityName])) {
                     do {
                         foreach ($loader->canConnectWith as $canConnectWithEntity) {
                             if (is_subclass_of($canConnectWithEntity, $lowerEntityName)) {
                                 break 2;
                                 // goto canConnect;
                             }
                         }
                         throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neukazuje zpet; ukazuje na jiny repository ({$loader->repository})");
                     } while (false);
                     // canConnect:
                 }
                 if ($loader->childParam and $loader->childParam !== $this->parentParam) {
                     throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neukazuje zpet; ukazuje na jiny parametr ({$loader->childParam})");
                 }
                 if ($callback) {
                     call_user_func($callback, $this, $loader);
                 }
                 continue;
             } catch (Exception $e) {
             }
         }
         unset($this->canConnectWith[$lowerEn]);
         if ($e) {
             throw $e;
         }
     }
     if (!$this->canConnectWith) {
         throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$this->repository}::\${$this->childParam} neni asociace ktera by ukazovala zpet");
     }
 }