centralapps / application-context
Useful set of tools for working with subdomain based web applications
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-11-09 13:48:47 UTC
README
This component is designed for use in application which make use of subdomains to segregate data / accounts.
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.
Installation
Add the project to your composer.json file
{
"require": {
"centralapps/application-context": "dev-master"
}
}
Install the project
php composer.phar update
Usage
-
Create an account factory, which implements LookupInterface, this is used to take an account reference and create an account object. Application specific code.
-
Create an account context object, pass the server name, the domain name and the account factory
-
The context will then setup, and store a reference for the account
$account_context = new \CentralApps\ApplicationContext\Context($_SERVER['SERVER_NAME'], 'mydomain.com', $account_factory);
-
You can check to see if the application is being ran as an 'account context'
$account_context->isAccountContext(); // returns true or false
-
You can also check to see if the account context is valid (that the subdomain matches a real account)
$account_context->isValidReference();
-
Finally, you can get the account object, which is retrieved via your pre-defined account factory
$account = $account_context->getAccount(); // null if not valid