Commit d6b3a2f2 authored by hj's avatar hj

更新

parent 42777c65
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Prettus\Repository\Providers\LumenRepositoryServiceProvider; use Prettus\Repository\Providers\LumenRepositoryServiceProvider;
class RepositoryServiceProvider extends LumenRepositoryServiceProvider class RepositoryServiceProvider extends LumenRepositoryServiceProvider
...@@ -21,33 +20,42 @@ class RepositoryServiceProvider extends LumenRepositoryServiceProvider ...@@ -21,33 +20,42 @@ class RepositoryServiceProvider extends LumenRepositoryServiceProvider
public function register() public function register()
{ {
parent::register(); // TODO: Change the autogenerated stub parent::register(); // TODO: Change the autogenerated stub
$this->bindRepository();
$this->bindRepository('app/Repositories/Contracts');
$this->bindRepository('app/Rhawn/Repositories/Contracts');
$this->bindRepository('app/Finance/Repositories/Contracts');
} }
protected function bindRepository($path) protected function bindRepository()
{ {
$files = app(Filesystem::class)->allFiles(base_path($path)); $fileObj = (new Filesystem());
$files = $fileObj->files(base_path('app/Repositories/Contracts'));
if($files){
collect($files)->map(function ($file){
$fileName = $file->getRelativePathname();
list($name,$extend) = explode('.',$fileName);
$class = "App\Repositories\Contracts\\".$name;
$concrete = "App\Repositories\Eloquent\\".$name."Eloquent";
$this->app->bind($class,$concrete);
});
}
$files = $fileObj->files(base_path('app/Rhawn/Repositories/Contracts'));
if($files){
collect($files)->map(function ($file){
$fileName = $file->getRelativePathname();
list($name,$extend) = explode('.',$fileName);
$class = "App\Rhawn\Repositories\Contracts\\".$name;
$concrete = "App\Rhawn\Repositories\Eloquent\\".$name."Eloquent";
$this->app->bind($class,$concrete);
});
}
$files = $fileObj->files(base_path('app/Finance/Repositories/Contracts'));
if($files){ if($files){
collect($files)->map(function ($file) use ($path){ collect($files)->map(function ($file){
$filePath = $file->getRelativePathname(); $fileName = $file->getRelativePathname();
$class = str_replace('/', '\\', $path).'\\'; list($name,$extend) = explode('.',$fileName);
if(!Str::contains($filePath, 'app')){ $class = "App\Finance\Repositories\Contracts\\".$name;
$class = 'app\\'.$class; $concrete = "App\Finance\Repositories\Eloquent\\".$name."Eloquent";
} $this->app->bind($class,$concrete);
$class = ucfirst($class);
$concrete = str_replace('Contracts', 'Eloquent', $class);
if(Str::contains($filePath,'/')){
list($directory, $file) = explode('/',$filePath);
$class .= "$directory\\";
$concrete .= "$directory\\";
$filePath = $file;
}
list($name,$extend) = explode('.',$filePath);
$this->app->bind($class.$name, $concrete.$name."Eloquent");
}); });
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment