Multiple applications
It's possible to define multiple applications in a single project. These applications will then share a single CMS and database. To do so, replace your application property in your settings.php file with an applications property, containing an array of applications.
'applications' => [
[
'name' => 'My Website',
'email' => 'info@example.org',
'domain' => 'example.org',
'prefer_www' => true,
'production' => true,
'secure' => true,
],[
'id' => 'blog',
'domain' => 'blog.example.org',
'secure' => true,
'prefer_www' => false,
]
],
The primary application will still look for controllers within the application subdirectory. Secondary applications should contain an id property. This id identifies which subdirectory contains the controllers for this application.
Dynamically handling domains
You can handle multiple domains for an application by using the Core\Helpers\Format class. This class takes a string with placeholders as argument.
'applications' => [
[
'name' => 'My Website',
'email' => 'info@example.org',
'domain' => 'example.org',
'prefer_www' => true,
'production' => true,
'secure' => true,
],[
'id' => 'clients',
'domain' => new \Core\Helpers\Format('{client}.example.org'),
'secure' => true,
'prefer_www' => false,
]
],
This will trigger the secondary application for any matching subdomain. If you wish to only trigger the application in certain conditions, you can customise the application determination logic by creating a class extending from Core\Application. Saturn will look for this class in your application subdirectory, with a filename matching the application id. You can then override the validate() method to handle application matching. Returning false from this method tells Saturn not to fire the application.
<?php
namespace Clients;
class Clients extends \Core\Application
{
protected $client;
protected function validate()
{
$client_slug = $this->domain->match();
$this->client = get('client')->where('slug = %s', $client_slug);
if (!$this->client->exists()) return false;
}
}