yearnwilling / Repository-Services by yearnwilling

the Repository-Service for laravel 5.5+
17
2
1
Package Data
Maintainer Username: yearnwilling
Maintainer Contact: weixianwei4@126.com (willingwei)
Package Create Date: 2017-04-14
Package Last Update: 2017-05-26
Language: PHP
License: MIT
Last Refreshed: 2024-12-19 03:01:36
Package Statistics
Total Downloads: 17
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 2
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Repository-Services

这个packagist主要是为laravel服务的。 使用方法可以参照我自己写的开源demo

https://github.com/yearnwilling/community

###使用方法:

#####Repository


    //对应需要访问的model
    protected $modelName = 'App\\Models\\User';
    
    public function model()
    {
        return $this->modelName;
    }
    

#####Service

     /**
      * @param $RepositoryName string Repository名称
      * @param $Repository class Repository类对象
      */
     public function getRepository($RepositoryName, $Repository) {
         $this->registerRepository($RepositoryName, $Repository);
         return $this->repositories[$RepositoryName];
     }
     
     /**
       * @param $RepositoryName string Repository名称
       * @param $Repository class Repository类对象
       */
      public function getService($serviceName, $service) {
         $this->registerService($serviceName, $service);
         return $this->services[$serviceName];
     }
     

#####Controller.php

    use Repository_services\Rsc\Service\Service;

    ...
    
    protected $baseServices;
    
    protected $resourcesNames = array(
        'UserService' => 'App\Services\User\UserServices',
    );
    
    public function __construct(Service $baseServices)
    {
        $this->baseServices =  $baseServices;
    }
    
    public function getService($serviceName) {
        $this->bootService($serviceName);
        return $this->baseServices->services[$serviceName];
    }

    protected function bootService($serviceName) {
        if (empty($this->resourcesNames[$serviceName])) {
            throw new \Exception("the $serviceName is not register in resourcesNames");
        }
        $this->baseServices->registerService($serviceName, $this->resourcesNames[$serviceName]);
    }