1 | <?php |
||
11 | abstract class TenantKernel extends Kernel { |
||
12 | /** |
||
13 | * @var TenantRegistry |
||
14 | */ |
||
15 | private $tenantRegistry; |
||
16 | |||
17 | /** |
||
18 | * @var bool Enable tenanting? |
||
19 | */ |
||
20 | public $enableTenanting; |
||
21 | |||
22 | public function __construct($environment, $debug) |
||
23 | { |
||
24 | $this->enableTenanting = !$debug; |
||
25 | |||
26 | parent::__construct($environment, $debug); |
||
27 | } |
||
28 | |||
29 | protected function initializeContainer() |
||
30 | { |
||
31 | parent::initializeContainer(); |
||
32 | |||
33 | // Inject the registry to the container |
||
34 | $this->getContainer()->set( |
||
35 | 'vivait_tenant.registry', |
||
36 | $this->getTenantRegistry() |
||
37 | ); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Provides an array of all Tenants |
||
42 | * |
||
43 | * For example: |
||
44 | * <code> |
||
45 | * <?php |
||
46 | * $configProvider = new \Vivait\TenantBundle\Provider\ConfigProvider( __DIR__ . '/config/' ); |
||
47 | * return $configProvider->loadTenants(); |
||
48 | * ?> |
||
49 | * </code> |
||
50 | * @return \Vivait\TenantBundle\Model\Tenant[] |
||
51 | */ |
||
52 | abstract protected function getAllTenants(); |
||
53 | |||
54 | public function getTenantRegistry() { |
||
55 | if ($this->tenantRegistry === null) { |
||
56 | $tenants = $this->getAllTenants(); |
||
57 | |||
58 | $this->tenantRegistry = new TenantRegistry( |
||
59 | $tenants |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | return $this->tenantRegistry; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Provides the current tenant's key |
||
68 | * @param Request $request |
||
69 | * @return string The current tenant's key |
||
70 | */ |
||
71 | abstract protected function getCurrentTenantKey(Request $request); |
||
72 | |||
73 | public function handle( |
||
74 | Request $request, |
||
75 | $type = HttpKernelInterface::MASTER_REQUEST, |
||
100 | } |
||
101 |