Skip to content

Commit

Permalink
Add easy way to instantiate domains
Browse files Browse the repository at this point in the history
  • Loading branch information
kpicaza committed May 26, 2022
1 parent 6ac065e commit d867196
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions instances/example/config/configuration_files.config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php
include ROOT_PATH . '/vendor/sifophp/sifo-common-instance/config/configuration_files.config.php';
$config['locale'] = 'instances/example/config/locale.config.php';
$config['domains'] = 'instances/example/config/domains.config.php';
34 changes: 34 additions & 0 deletions instances/example/config/domains.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

$config['core_inheritance'] = array( 'Sifo' );

$config['redirections'] = array(
array( 'from' => 'www.sifo.local', 'to' => 'http://sifo.local' ),
array( 'from' => 'www2.sifo.local', 'to' => 'http://sifo.local' ),
);

$config['instance_type'] = 'instantiable';

$config['sifo.local'] = array(
'devel' => true, // Domain is marked as development
'has_debug' => true, // Domain shows the floating debug box.
'instance' => 'example',
'language' => 'en_US',
'language_domain' =>'messages',
'lang_in_subdomain' => array( 'es' => 'es_ES', 'en' => 'en_US' ),
'www_as_subdomain' => false,
'static_host' => 'http://static.sifo.local',
'media_host' => 'http://static.sifo.local', // Alternative static content (media). Comment to disable.
'database' => array(
'db_driver' => 'mysql', // To use transactions you must use mysqli driver.
'db_host' => '127.0.0.1',
'db_user' => 'root',
'db_password' => 'root',
'db_name' => 'yourdatabase',
'db_init_commands' => array( 'SET NAMES utf8' ) // Commands launched before the queries.
),
'php_ini_sets' => array( // Empty array if you don't want any php.ini overriden.
'log_errors' => 'On',
'error_log' => ROOT_PATH . '/logs/errors_' . date( 'Y-m' ) . '.log', // Store a different error file per month. For the lazy rotator :)
),
);
15 changes: 15 additions & 0 deletions src/Sifo/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ static public function getInstance()
return self::$singleton;
}

/**
* Singleton for domain calculation.
*
* @return Domains
*/
static public function getInstanceFromDomainName($domainName)
{
if ( !isset( self::$singleton ) )
{
self::$singleton = new self($domainName);
}

return self::$singleton;
}

private function __construct( $host = null )
{
$filter_server = FilterServer::getInstance();
Expand Down
19 changes: 19 additions & 0 deletions test/Sifo/DomainsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Sifo\Test\Sifo;

use PHPUnit\Framework\TestCase;
use Sifo\Domains;

class DomainsTest extends TestCase
{
private const DOMAIN_NAME = 'sifo.local';

public function testGetInstanceFromDomainName()
{
$domain = Domains::getInstanceFromDomainName(self::DOMAIN_NAME);
$this->assertSame(self::DOMAIN_NAME, $domain->getDomain());
}
}
2 changes: 2 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
if (false === defined('ROOT_PATH')) {
define('ROOT_PATH', $rootDir);
}

$_SERVER['HTTP_HOST'] = 'sifo.local';
Bootstrap::$instance = 'example';

0 comments on commit d867196

Please sign in to comment.