2017 © Pedro Peláez
 

library losdomain

Middleware for use php configuration based on domain or subdomain

image

los/losdomain

Middleware for use php configuration based on domain or subdomain

  • Thursday, September 7, 2017
  • by Lansoweb
  • Repository
  • 2 Watchers
  • 4 Stars
  • 1,888 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 25 % Grown

The README.md

LosDomain

Build Status Latest Stable Version Total Downloads Coverage Status Scrutinizer Code Quality SensioLabs Insight Dependency Status, (*1)

Introduction

This module provides php configuration files based on the domain (or subdomain) being accessed., (*2)

For Zend Framework 2/3 framework.zend.com, please use version 1.0., (*3)

Todo

Todo

  • Option to manually disable a domain, redirecting it to a page. (eg. expired subscription)
  • Integration with LosLicense (in development) to check the availibity of a domain and automatically disable it.
  • Storages to retrieve options for domains (interface, file, pdo, so on)

Instalation

composer require los/losdomain:^2.0

Usage

For example, in Zend Expressive, add the following code to your config/config.php:, (*4)

foreach (\LosDomain\DomainService::configFiles('config/autoload/domains') as $file) {
    $config = ArrayUtils::merge($config, include $file);
}

Because the included files cannot be cached, it's better to include the code after the cache read/write. So a complete config.php will looks like:, (*5)

<?php

use Laminas\Stdlib\ArrayUtils;
use Laminas\Stdlib\Glob;

/**
 * Configuration files are loaded in a specific order. First ``global.php``, then ``*.global.php``.
 * then ``local.php`` and finally ``*.local.php``. This way local settings overwrite global settings.
 *
 * The configuration can be cached. This can be done by setting ``config_cache_enabled`` to ``true``.
 *
 * Obviously, if you use closures in your config you can't cache it.
 */

require __DIR__.'/env.php';

$cachedConfigFile = 'data/cache/app_config.php';

$config = [];
if (is_file($cachedConfigFile)) {
    // Try to load the cached config
    $config = include $cachedConfigFile;
} else {
    // Load configuration from autoload path
    foreach (Glob::glob('config/autoload/{{,*.}global,{,*.}local}.php', Glob::GLOB_BRACE) as $file) {
        $config = ArrayUtils::merge($config, include $file);
    }

    // Cache config if enabled
    if (isset($config['config_cache_enabled']) && $config['config_cache_enabled'] === true) {
        file_put_contents($cachedConfigFile, '<?php return ' . var_export($config, true) . ';');
    }
}

foreach (\LosDomain\DomainService::configFiles('config/autoload/domains') as $file) {
    $config = ArrayUtils::merge($config, include $file);
}

// Return an ArrayObject so we can inject the config as a service in Aura.Di
// and still use array checks like ``is_array``.
return new ArrayObject($config, ArrayObject::ARRAY_AS_PROPS);

The service will look into the folder 'config/autoload/domains' for your domains. If there is a folder named identically as your domain, it will be imported., (*6)

For example, assume these domains: - test.local - client1.test.local - client2.test.local - www.test.local, (*7)

Each domain (or subdomain) can have a different configuration (factories, database configurations, so on): - config/autoload/domains/test.local/domain.global.php - config/autoload/domains/client1.test.local/domain.global.php - config/autoload/domains/www.test.local/domain.global.php - config/autoload/domains/www.test.local/domain.local.php, (*8)

Since the client2.test.local does not have it's configuration, it will use the default from the project., (*9)

Domain Alias

It's possible to assign an alias to a domain. Supose you have two domains that share the same configuration: - test.local - www.test.local, (*10)

The first one you create as usual (creating the config files inside config/autoload/domain/test.local/global.php) and the alias is configured in a file config/autoload/domains/config.php, (*11)

<?php
return [
    'los_domain' => [
        'aliases' => [
            'www.test.local' => 'test.local',
        ],
    ],
];

With this configuration, when the project is access through 'www.test.local', the service will load the 'test.local' files., (*12)

The Versions

07/09 2017

dev-master

9999999-dev http://github.com/Lansoweb/LosDomain

Middleware for use php configuration based on domain or subdomain

  Sources   Download

MIT BSD-3-Clause

The Requires

 

The Development Requires

middleware domain configuration zf2 module zf3 expressive los

07/09 2017

2.0.0

2.0.0.0 http://github.com/Lansoweb/LosDomain

Middleware for use php configuration based on domain or subdomain

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware domain configuration expressive

07/09 2017

dev-develop

dev-develop http://github.com/Lansoweb/LosDomain

Middleware for use php configuration based on domain or subdomain

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware domain configuration zf2 module zf3 expressive

14/08 2017

1.0.0

1.0.0.0 http://github.com/Lansoweb/LosDomain

ZF2/ZF3 module for use configuration, layout, database, etc per domain or subdomain

  Sources   Download

MIT

The Requires

 

The Development Requires

domain zf2 module zf3

17/04 2015

0.9.4

0.9.4.0 http://github.com/Lansoweb/LosDomain

ZF2 module for use configuration, layout, database, etc per domain or subdomain

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

domain zf2 module los

01/04 2015

0.9.3

0.9.3.0 http://github.com/Lansoweb/LosDomain

ZF2 module for use configuration, layout, database, etc per domain or subdomain

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

domain zf2 module los

28/01 2015

0.9.2

0.9.2.0 http://github.com/Lansoweb/LosDomain

ZF2 module for use configuration, layout, database, etc per domain or subdomain

  Sources   Download

BSD-3

The Requires

 

domain zf2 module los

26/12 2014

0.9.1

0.9.1.0 http://github.com/Lansoweb/LosDomain

ZF2 module for use configuration, layout, database, etc per domain or subdomain

  Sources   Download

BSD-3

The Requires

 

domain zf2 module los