PHP code example of vivait / tenant-bundle

1. Go to this page and download the library: Download vivait/tenant-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vivait / tenant-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Vivait\TenantBundle\VivaitTenantBundle(),
        );

        // ...
    }

    // ...
}


// app/AppKernel.php

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Vivait\TenantBundle\Kernel\TenantKernel;
use Vivait\TenantBundle\Locator\HostnameLocator;
use Vivait\TenantBundle\Provider\ConfigProvider;
use Vivait\TenantBundle\Provider\TenantProvider;

// ...
class AppKernel extends TenantKernel
{
	// ...

    /**
     * Provides an array of all Tenants
     *
     * @return Tenant[]
     */
    protected function getAllTenants()
    {
       $configProvider = new ConfigProvider( __DIR__ . '/config/' );
       return $configProvider->loadTenants();
    }

    /**
     * Provides the current tenant's key
     * @param Request $request
     * @return string The current tenant's key
     */
    protected function getCurrentTenantKey( Request $request )
    {
        return HostnameLocator::getTenantFromRequest( $request );
    }
}