예제 #1
0
 /**
  * Loads Hostname models based on request.
  *
  * @param HostnameRepositoryContract $hostname
  *
  * @return \Hyn\MultiTenant\Models\Hostname
  */
 public static function hostname(HostnameRepositoryContract $hostname)
 {
     $tenant_hostname = null;
     try {
         if (!App::runningInConsole()) {
             $tenant_hostname = $hostname->findByHostname(Request::getHttpHost());
         }
         if (!$tenant_hostname) {
             $tenant_hostname = $hostname->getDefault();
         }
     } catch (QueryException $e) {
         // table not found, set up not yet done
         if (preg_match('/\\Qtable or view not found\\E/', $e->getMessage())) {
             return;
         }
     }
     return $tenant_hostname;
 }
예제 #2
0
 /**
  * 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.');
     }
 }
 /**
  * @param HostnameRepositoryContract $hostname
  * @param ResponseFactory            $response
  * @return \Illuminate\Http\JsonResponse
  */
 public function ajax(HostnameRepositoryContract $hostname, ResponseFactory $response)
 {
     return $response->json($hostname->ajaxQuery('hostname'));
 }
예제 #4
0
 /**
  * Return default website.
  *
  * @return \Hyn\MultiTenant\Models\Website
  */
 public function getDefault()
 {
     return $this->hostname->getDefault()->website;
 }