Register a repository with the manager.

@param ManagedRepository $repository     Manageable repository.

@throws RepositoryException              If the manager already contains a repository for the same model class.
517599
public function addRepository($repository)
    {
        $class = $repository->getModelClass();
        if ($this->getByClass($class)) {
            throw new RepositoryException("The manager already contains a repository for the model class '$class'");
        }
        
        $repository->setManager($this);
        $this->repositories[$class] = $repository;
    }
527169
public function handle(ManagerRegistry $registry)
    {
        $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames();

        foreach ($names as $name) {
            /** @var EntityManagerInterface $em */
            $em = $registry->getManager($name);

            $this->comment('');
            $this->message('Generating repositories for <info>' . $name . '</info> entity manager...', 'blue');

            $metadatas = $em->getMetadataFactory()->getAllMetadata();
            $metadatas = MetadataFilter::filter($metadatas, $this->option('filter'));

            $repositoryName = $em->getConfiguration()->getDefaultRepositoryClassName();

            $destPath = base_path($this->argument('dest-path') ?:'app/Repositories');

            if (!is_dir($destPath)) {
                mkdir($destPath, 0777, true);
            }

            $destPath = realpath($destPath);

            if (!file_exists($destPath)) {
                throw new InvalidArgumentException(
                    sprintf("Repositories destination directory '<info>%s</info>' does not exist.",
                        $em->getConfiguration()->getProxyDir())
                );
            }

            if (!is_writable($destPath)) {
                throw new InvalidArgumentException(
                    sprintf("Repositories destination directory '<info>%s</info>' does not have write permissions.",
                        $destPath)
                );
            }

            if (empty($metadatas)) {
                $this->error('No Metadata Classes to process.');

                return;
            }

            $numRepositories = 0;
            $generator       = new EntityRepositoryGenerator();

            $generator->setDefaultRepositoryName($repositoryName);

            foreach ($metadatas as $metadata) {
                if ($metadata->customRepositoryClassName) {
                    $this->comment(
                        sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName)
                    );

                    $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath);

                    ++$numRepositories;
                }
            }

            if ($numRepositories === 0) {
                $this->error('No Repository classes were found to be processed.');

                return;
            }

            $this->comment(sprintf('Repository classes generated to "<info>%s</info>"', $destPath));
        }
    }
1208751
private function registerServiceProvider(Repository $repository, $module)
    {
        $location        = $repository->location;
        $provider        = config("modules.location.$location.provider", 'Providers\\ModuleServiceProvider');
        $serviceProvider = module_class($module['slug'], $provider, $location);

        if (class_exists($serviceProvider)) {
            $this->app->register($serviceProvider);
        }
    }
1324102
protected function registerGroupRepository()
    {
        $this->app->singleton('grouprepository', function ($app) {
            $model = $app['config']['sentry.groups.model'];
            $group = new $model();

            $validator = $app['validator'];

            return new GroupRepository($group, $validator);
        });

        $this->app->alias('grouprepository', GroupRepository::class);
    }
606700
public static function fromRepository($repository)
    {
        $message = sprintf(
            'Could not add invalid OptionRepository of type "%1$s" to AggregateOptionRepository.',
            is_object($repository)
                ? get_class($repository)
                : gettype($repository)
        );

        return new static($message);
    }
1244943
protected function registerMultiSiteTenancy(Repository $config)
    {
        if (!$config->get('tenancy.multi_site.enabled', false)) {
            return;
        }

        if (!$this->app instanceof TenantAwareApplication) {
            throw new \RuntimeException(
                'Multi-site requires updating your bootstrap/app.php to use TenantAwareApplication'
            );
        }

        /*
         * @todo Need a way to detect if RouteServiceProvider (or at least an instance of
         *       Foundation\RouteServiceProvider) has been registered and to fail with a
         *       warning if so.
         */

        $this->registerMultiSiteParticipantRepository($config);
        $this->registerMultiSiteConsoleCommands();
        $this->registerTenantParticipantMappings($config->get('tenancy.multi_site.participant.mappings'));
    }
1023636
public void addRepository(Repository repo) throws GreenPepperServerException
    {
        if (findRepositoryByName(repo.getName()) != null)
        {
            throw new GreenPepperServerException( GreenPepperServerErrorKey.REPOSITORY_ALREADY_EXISTS, "Repository already exists");
        }

        repo.setProject(this);
        repositories.add(repo);
    }
114584
protected function registerReminderRepository()
	{
		$this->app->bindShared('auth.reminder.repository', function($app)
		{
			$connection = $app['db']->connection();

			// The database reminder repository is an implementation of the reminder repo
			// interface, and is responsible for the actual storing of auth tokens and
			// their e-mail addresses. We will inject this table and hash key to it.
			$table = $app['config']['auth.reminder.table'];

			$key = $app['config']['app.key'];

			$expire = $app['config']->get('auth.reminder.expire', 60);

			return new DbRepository($connection, $table, $key, $expire);
		});
	}
708809
public function registerRepository(string $name, RepositoryInterface $repository)
    {
        if (isset($this->repositories[$name])) {
            throw new \LogicException(sprintf('Links\' Repository "%s" is already registered.', $name));
        }

        $this->repositories[$name] = $repository;
    }
805267
protected function registerMultiSiteParticipantRepository(Repository $config)
    {
        $repository = $config->get('tenancy.multi_site.participant.repository');
        $entity     = $config->get('tenancy.multi_site.participant.class');

        $this->app->singleton(DomainTenantRepositoryContract::class,
            function ($app) use ($repository, $entity) {
                return new DomainAwareTenantParticipantRepository(
                    new $repository($app['em'], $app['em']->getClassMetaData($entity))
                );
            }
        );

        $this->app->alias(DomainTenantRepositoryContract::class, 'auth.tenant.site_repository');
    }
1175877
public void addRemoteRepository(RemoteRepository remoteRepository) {
        if (this.repositoryIds.add(remoteRepository.getId()) ) {
            getRemoteRepositories().add(remoteRepository);
        }
    }
971450
public function withRepository(Repository $repository) : TransactionalBusesBuilder
    {
        $this->repository = $repository;
        $this->useDirectCommandBus();
        return $this;
    }
606773
public function apply($model, Repository $repository)
    {
        $model = $model->where('pid', 0)
            ->orderBy('sort', 'desc')
            ->orderBy('id', 'desc');

        return $model;
    }
976687
public function register()
    {
        /**
         * Override the binding for data repository contract and implementation
         */
        $this->app->bind(
            \ActualReports\PDFGeneratorAPILaravel\Contracts\DataRepository::class,
            \App\Repositories\DataRepository::class
        );
    }
1179805
public function apply($model, RepositoryInterface $repository)
    {
        $fieldsSearchable = $repository->getFieldsSearchable();
        $search = $this->request->get(config('repository.criteria.params.search', 'search'), null);
        $searchFields = $this->request->get(config('repository.criteria.params.searchFields', 'searchFields'), null);
        $filter = $this->request->get(config('repository.criteria.params.filter', 'filter'), null);
        $orderBy = $this->request->get(config('repository.criteria.params.orderBy', 'orderBy'), null);
        $sortedBy = $this->request->get(config('repository.criteria.params.sortedBy', 'sortedBy'), 'asc');
        $with = $this->request->get(config('repository.criteria.params.with', 'with'), null);
        $sortedBy = !empty($sortedBy) ? $sortedBy : 'asc';

        if ($search && is_array($fieldsSearchable) && count($fieldsSearchable)) {

            $searchFields = is_array($searchFields) || is_null($searchFields) ? $searchFields : explode(';', $searchFields);
            $fields = $this->parserFieldsSearch($fieldsSearchable, $searchFields);
            $isFirstField = true;
            $searchData = $this->parserSearchData($search);
            $search = $this->parserSearchValue($search);
            $modelForceAndWhere = method_exists($repository, 'getIsSearchableForceAndWhere') ? $repository->getIsSearchableForceAndWhere() : false;

            $model = $model->where(function ($query) use ($fields, $search, $searchData, $isFirstField, $modelForceAndWhere) {
                /** @var Builder $query */

                foreach ($fields as $field => $condition) {

                    if (is_numeric($field)) {
                        $field = $condition;
                        $condition = "=";
                    }

                    $value = null;

                    $condition = trim(strtolower($condition));

                    if (isset($searchData[$field])) {
                        if ($condition == "like_raw") {
                            $condition = "like";
                            $value = $searchData[$field];
                        } else if ($condition == "like_safe") {
                            $condition = "like";
                            if (str_contains_ascii_only($searchData[$field])) {
                                $value = "%{$searchData[$field]}%";
                            } else {
                                $value = null;
                            }
                        } else {
                            $value = ($condition == "like" || $condition == "ilike") ? "%{$searchData[$field]}%" : $searchData[$field];
                        }
                    } else {
                        if (!is_null($search)) {
                            if ($condition == "like_raw") {
                                $condition = "like";
                                $value = $searchData[$field];
                            } else if ($condition == "like_safe") {
                                $condition = "like";
                                if (str_contains_ascii_only($search)) {
                                    $value = "%{$search}%";
                                } else {
                                    $value = null;
                                }
                            } else {
                                $value = ($condition == "like" || $condition == "ilike") ? "%{$search}%" : $search;
                            }
                        }
                    }

                    $relation = null;
                    if (stripos($field, '.')) {
                        $explode = explode('.', $field);
                        $field = array_pop($explode);
                        $relation = implode('.', $explode);
                    }
                    $modelTableName = $query->getModel()->getTable();
                    if ($isFirstField || $modelForceAndWhere) {
                        if (!is_null($value)) {
                            if (!is_null($relation)) {
                                $query->whereHas($relation, function ($query) use ($field, $condition, $value) {
                                    $query->where($field, $condition, $value);
                                });
                            } else {
                                $query->where($modelTableName . '.' . $field, $condition, $value);
                            }
                            $isFirstField = false;
                        }
                    } else {
                        if (!is_null($value)) {
                            if (!is_null($relation)) {
                                $query->orWhereHas($relation, function ($query) use ($field, $condition, $value) {
                                    $query->where($field, $condition, $value);
                                });
                            } else {
                                $query->orWhere($modelTableName . '.' . $field, $condition, $value);
                            }
                        }
                    }
                }
            });
        }

        if (isset($orderBy) && !empty($orderBy)) {
            $orderBys = explode(';', $orderBy); // products:product_id:product_id|products.name;updated_at,desc
            $originSortedBy = $sortedBy;
            foreach ($orderBys as $orderBy) {
                // split sorted by
                $splitSortedBy = explode(',', $orderBy);
                if (count($splitSortedBy) > 1) {
                    $sortedBy = $splitSortedBy[1];
                } else {
                    $sortedBy = $originSortedBy;
                }
                $orderBy = $splitSortedBy[0];

                // split joint
                $split = explode('|', $orderBy);
                if (count($split) > 1) {
                    /*
                     * ex.
                     * products|description -> join products on current_table.product_id = products.id order by description
                     *
                     * products:custom_id|products.description -> join products on current_table.custom_id = products.id order
                     * by products.description (in case both tables have same column name)
                     */
                    $table = $model->getModel()->getTable();
                    $sortTable = $split[0];
                    $sortColumn = $split[1];

                    $sortTableKeyName = 'id';
                    $split = explode(':', $sortTable);
                    if (count($split) > 2) { //    products:custom_id:products_table_custom_id|products.description
                        $sortTable = $split[0];
                        $keyName = $table . '.' . $split[1];
                        $sortTableKeyName = $split[2];
                    } else if (count($split) > 1) {
                        $sortTable = $split[0];
                        $keyName = $table . '.' . $split[1];
                    } else {
                        /*
                         * If you do not define which column to use as a joining column on current table, it will
                         * use a singular of a join table appended with _id
                         *
                         * ex.
                         * products -> product_id
                         */
                        $prefix = rtrim($sortTable, 's');
                        $keyName = $table . '.' . $prefix . '_id';
                    }

                    $model = $model
                        ->leftJoin($sortTable, $keyName, '=', $sortTable . '.' . $sortTableKeyName)
                        ->orderBy($sortColumn, $sortedBy)
                        ->groupBy($keyName) // Prevent SQL Error: SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxx' which is not functionally dependent on columns in GROUP BY clause;
                        ->addSelect($table . '.*');
                } else {
                    $model = $model->orderBy($orderBy, $sortedBy);
                }
            }
        }

        if (isset($filter) && !empty($filter)) {
            if (is_string($filter)) {
                $filter = explode(';', $filter);
            }

            $model = $model->select($filter);
        }

        if ($with) {
            $with = explode(';', $with);
            $model = $model->with($with);
        }

        return $model;
    }
36857
protected function registerMakeCommand()
    {
        $this->app->singleton('command.repository.make', function ($app) {
            $prefix = $app['config']['repository.prefix'];
            $suffix = $app['config']['repository.suffix'];
            $contract = $app['config']['repository.contract'];
            $namespace = $app['config']['repository.namespace'];
            $creator = $app['repository.creator'];
            $files = $app['files'];

            return new RepositoryMakeCommand($creator, $prefix, $suffix, $contract, $namespace, $files);
        });

        $this->commands('command.repository.make');
    }
362248
public function setCustomRepositoryClass(?string $repositoryClassName) : void
    {
        if ($this->isEmbeddedDocument || $this->isQueryResultDocument) {
            return;
        }

        $this->customRepositoryClassName = $repositoryClassName;
    }