Useful set of tools for working with subdomain based web applications
This component is designed for use in application which make use of subdomains to segregate data / accounts., (*1)
For example, if you have the domain mydomain.com and one of your customers logs in and uses the application via customername.mydomain.com, this component makes it easy to lookup those customers details, and to determine what "context" the application is running in (account context or not). This lets you route and manage the application correctly., (*2)
Add the project to your composer.json file, (*3)
{ "require": { "centralapps/application-context": "dev-master" } }
Install the project, (*4)
php composer.phar update
The context will then setup, and store a reference for the account, (*5)
$account_context = new \CentralApps\ApplicationContext\Context($_SERVER['SERVER_NAME'], 'mydomain.com', $account_factory);, (*6)
You can check to see if the application is being ran as an 'account context', (*7)
$account_context->isAccountContext(); // returns true or false, (*8)
You can also check to see if the account context is valid (that the subdomain matches a real account), (*9)
$account_context->isValidReference();, (*10)
Finally, you can get the account object, which is retrieved via your pre-defined account factory, (*11)
$account = $account_context->getAccount(); // null if not valid, (*12)