\Dewdrop\MultiInstanceManager

Class Manager This class can be used for many database related functions, primarily detecting the default database, as well as instance creation and management.

Example use cases:

Defining db in your Bootstrap.php $this->application['db'] = $this->application->share( function() { $manager = new Manager($configForManageDb, 'offices', 'office_%d');

    return $manager->getCurrent();
}

);

Creating a new up-to-date app instance $manager->createInstance(4, 'some_subdomain');

Summary

Methods
Properties
Constants
__construct()
register()
boot()
getManageDbAdapter()
getManageDbConfig()
setInstanceUsername()
setInstancePassword()
setInstanceHost()
getIdColumn()
getSubdomainColumn()
getAll()
fetchInstanceMetadataById()
fetchInstanceMetadataBySubdomain()
getById()
getBySubdomain()
setCurrent()
getCurrent()
getDatabaseNameForInstance()
getDatabaseNameForId()
createAdapterForInstance()
modifySilexDbConfigForInstance()
createInstance()
copyUsersToInstance()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
createAdapterFromConfig()
detectIdColumn()
detectSubdomainColumn()
databaseExists()
$currentInstance
$manageDbAdapter
$manageDbConfig
$instanceTableName
$instanceUsername
$instancePassword
$instanceHost
$databaseNameTemplate
$idColumn
$subdomainColumn
$silex
N/A

Properties

$manageDbConfig

$manageDbConfig : array

Type

array

$instanceTableName

$instanceTableName : string

Type

string

$instanceUsername

$instanceUsername : string

Type

string

$instancePassword

$instancePassword : string

Type

string

$instanceHost

$instanceHost : string

Type

string

$databaseNameTemplate

$databaseNameTemplate : string

Type

string

$idColumn

$idColumn : string

Type

string

$subdomainColumn

$subdomainColumn : string

Type

string

$silex

$silex : \Silex\Application

Type

\Silex\Application

Methods

__construct()

__construct(array  $dbConfig, string  $instanceTableName, string  $databaseNameTemplate, null  $idColumn = null, null  $subdomainColumn = null) 

Manager constructor.

Parameters

array $dbConfig

Array of username, password, host, name, type

string $instanceTableName

Name of table that keeps application instance records. eg. offices

string $databaseNameTemplate

Sprintf format containing exactly 1 specifier for the id column. eg. gtoffice%d

null $idColumn

Manually specify primary key column of the instance table.

null $subdomainColumn

Manually specify subdomain column of the instance table.

Throws

\Dewdrop\MultiInstance\Exception
\Dewdrop\Exception

register()

register(\Silex\Application  $app) 

Parameters

\Silex\Application $app

boot()

boot(\Silex\Application  $app) 

Parameters

\Silex\Application $app

getManageDbConfig()

getManageDbConfig() : array

Returns

array

setInstanceUsername()

setInstanceUsername(  $instanceUsername) : $this

Parameters

$instanceUsername

Returns

$this

setInstancePassword()

setInstancePassword(  $instancePassword) : $this

Parameters

$instancePassword

Returns

$this

setInstanceHost()

setInstanceHost(  $instanceHost) : $this

Parameters

$instanceHost

Returns

$this

getIdColumn()

getIdColumn() : string

Returns

string

getSubdomainColumn()

getSubdomainColumn() : string

Returns

string

getAll()

getAll() : array

Returns

array

fetchInstanceMetadataById()

fetchInstanceMetadataById(  $id) : array

Parameters

$id

Returns

array

fetchInstanceMetadataBySubdomain()

fetchInstanceMetadataBySubdomain(string  $subdomain) : array

Parameters

string $subdomain

Returns

array

getBySubdomain()

getBySubdomain(string  $subdomain) : \Dewdrop\MultiInstance\Instance

Parameters

string $subdomain

Returns

\Dewdrop\MultiInstance\Instance

getDatabaseNameForInstance()

getDatabaseNameForInstance(\Dewdrop\MultiInstance\Instance  $instance) : string

Parameters

\Dewdrop\MultiInstance\Instance $instance

Throws

\Dewdrop\MultiInstance\Exception

Returns

string

getDatabaseNameForId()

getDatabaseNameForId(  $id) : string

Parameters

$id

Returns

string

modifySilexDbConfigForInstance()

modifySilexDbConfigForInstance(\Dewdrop\MultiInstance\Instance  $instance) : $this

Parameters

\Dewdrop\MultiInstance\Instance $instance

Throws

\Dewdrop\MultiInstance\Exception

Returns

$this

createInstance()

createInstance(  $id, string  $subdomain, boolean  $copyUsers = true) : \Dewdrop\MultiInstance\Instance

Create an instance, the schema should have all db migrations.

Parameters

$id
string $subdomain
boolean $copyUsers

Throws

\Dewdrop\MultiInstance\Exception

Returns

\Dewdrop\MultiInstance\Instance

copyUsersToInstance()

copyUsersToInstance(  $users, \Dewdrop\MultiInstance\Instance  $instance) 

Copy users from the Manage application to an instance.

Parameters

$users
\Dewdrop\MultiInstance\Instance $instance

createAdapterFromConfig()

createAdapterFromConfig(array  $config) : \Dewdrop\Db\Adapter

Parameters

array $config

Returns

\Dewdrop\Db\Adapter

detectIdColumn()

detectIdColumn() : string

Throws

\Dewdrop\MultiInstance\Exception
\Dewdrop\Exception

Returns

string —

Detected id column name.

detectSubdomainColumn()

detectSubdomainColumn() : string

Throws

\Dewdrop\MultiInstance\Exception
\Dewdrop\Exception

Returns

string —

Detected subdomain column name.

databaseExists()

databaseExists(  $databaseName) : mixed

Parameters

$databaseName

Returns

mixed