Bolt\Storage\EntityManager::getRepository PHP Метод

getRepository() публичный Метод

public getRepository ( $className )
    public function getRepository($className)
    {
        /** @var Repository $repo */
        $repo = null;
        $className = (string) $className;
        if (array_key_exists($className, $this->aliases)) {
            $className = $this->aliases[$className];
        }
        try {
            $classMetadata = $this->getMapper()->loadMetadataForClass($className);
        } catch (StorageException $e) {
            throw new InvalidRepositoryException("Attempted to load repository for invalid class or alias: {$className}. Check that the class, alias or contenttype definition is correct.");
        }
        if (array_key_exists($classMetadata->getName(), $this->repositories)) {
            $repoClass = $this->repositories[$classMetadata->getName()];
            if (is_callable($repoClass)) {
                $repo = call_user_func_array($repoClass, [$this, $classMetadata]);
            } else {
                $repo = new $repoClass($this, $classMetadata);
            }
        }
        if ($repo === null) {
            foreach ($this->aliases as $alias => $namespace) {
                $full = str_replace($alias, $namespace, $className);
                if (array_key_exists($full, $this->repositories)) {
                    $classMetadata = $this->getMapper()->loadMetadataForClass($full);
                    $repoClass = $this->repositories[$full];
                    $repo = new $repoClass($this, $classMetadata);
                }
            }
        }
        /*
         * The metadata driver can also attempt to resolve an alias for us.
         * For now we are hardcoding the link between a content entity and
         * the content repository, but in time this should be a metadata level
         * configuration.
         */
        if ($repo === null && $this->getMapper()->resolveClassName($className) === 'Bolt\\Storage\\Entity\\Content') {
            $repo = $this->getDefaultRepositoryFactory($classMetadata);
        }
        /*
         * If the fetched metadata isn't mapped to a specific entity then we treat
         * it as a generic Content repo
         */
        if ($repo === null && in_array($className, $this->getMapper()->getUnmapped())) {
            $repo = $this->getDefaultRepositoryFactory($classMetadata);
        }
        if ($repo === null) {
            $repo = new Repository($this, $classMetadata);
        }
        if ($repo instanceof Repository\ContentRepository) {
            /** @var ContentRepository $repo */
            $repo->setLegacyService($this->legacyService);
        }
        return $repo;
    }

Usage Example

Пример #1
0
 /**
  * Modify an individual ContentType's records.
  *
  * @param string $contentTypeName ContentType slug
  * @param array  $changeRequest   Change array in the format of:
  *                                [id => [action => [field => value]]]
  */
 public function action($contentTypeName, array $changeRequest)
 {
     foreach ($changeRequest as $recordId => $actionData) {
         if ($actionData === null) {
             continue;
         }
         $repo = $this->em->getRepository($contentTypeName);
         foreach ($actionData as $action => $fieldData) {
             if (!($entity = $repo->find($recordId))) {
                 continue;
             }
             $this->modifyContentTypeRecord($repo, $entity, $action, $fieldData);
         }
     }
 }
All Usage Examples Of Bolt\Storage\EntityManager::getRepository