コード例 #1
0
ファイル: SetupCommand.php プロジェクト: Mobytes/multi-tenant
 /**
  * Handles the set up.
  */
 public function handle()
 {
     $this->configuration = config('webserver');
     $name = $this->option('tenant');
     $email = $this->option('email');
     $hostname = $this->option('hostname');
     if (empty($name)) {
         throw new TenantPropertyException('No tenant name given; use --tenant');
     }
     if (empty($email)) {
         throw new TenantPropertyException('No tenant email given; use --email');
     }
     if (empty($hostname)) {
         throw new TenantPropertyException('No tenant hostname given; use --hostname');
     }
     $this->comment('Welcome to hyn multi tenancy.');
     // If the dashboard is installed we need to prevent default laravel migrations
     // so we run the dashboard setup command before running any migrations
     if (class_exists('Hyn\\ManagementInterface\\ManagementInterfaceServiceProvider')) {
         $this->info('The management interface will be installed first.');
         $this->call('dashboard:setup');
     }
     // now we will run all migrations
     $this->comment('First off, migrations for the packages will run.');
     $this->runMigrations();
     $tenantDirectory = config('multi-tenant.tenant-directory') ? config('multi-tenant.tenant-directory') : storage_path('multi-tenant');
     if (!File::isDirectory($tenantDirectory) && File::makeDirectory($tenantDirectory, 0755, true)) {
         $this->comment("The directory to hold your tenant websites has been created under {$tenantDirectory}.");
     }
     $webserver = null;
     // Setup webserver
     if ($this->helper) {
         // creates directories
         $this->helper->createDirectories();
         $webserver = $this->option('webserver') ?: 'no';
         if ($webserver != 'no') {
             $webserverConfiguration = array_get($this->configuration, $webserver);
             $webserverClass = array_get($webserverConfiguration, 'class');
         } else {
             $webserver = null;
         }
         // Create the first tenant configurations
         $tenant = $this->tenant->create(compact('name', 'email'));
         $identifier = substr(str_replace(['.'], '-', $hostname), 0, 10);
         $website = $this->website->create(['tenant_id' => $tenant->id, 'identifier' => $identifier]);
         $host = $this->hostname->create(['hostname' => $hostname, 'website_id' => $website->id, 'tenant_id' => $tenant->id]);
         // hook into the webservice of choice once object creation succeeded
         if ($webserver) {
             (new $webserverClass($website))->register();
         }
         if ($tenant->exists && $website->exists && $host->exists) {
             $this->info('Configuration successful');
         }
     } else {
         $this->error('The hyn/webserver package is not installed. Visit http://hyn.me/packages/webserver for more information.');
     }
 }
コード例 #2
0
 /**
  * Loads tenants for select2 fields and such.
  *
  * @param TenantRepositoryContract $tenant
  * @param ResponseFactory          $response
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function ajax(TenantRepositoryContract $tenant, ResponseFactory $response)
 {
     return $response->json($tenant->ajaxQuery('name'));
 }