Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
20 / 20
CRAP
100.00% covered (success)
100.00%
48 / 48
Configuration
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
20 / 20
22
100.00% covered (success)
100.00%
48 / 48
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 databaseConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 httpConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 templateConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 filesystemRoot
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 orm
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 ormConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 ormWrappers
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 httpProcessor
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 httpRouteResolver
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 templateLocator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 instance
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 buildDatabaseConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildHttpConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildTemplateConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildOrm
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 buildHttpProcessor
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 buildHttpRouteResolver
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 buildTemplateLocator
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
13 / 13
 configStorage
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
namespace PHPixie\BundleFramework;
class Configuration implements \PHPixie\Framework\Configuration
{
    protected $builder;
    protected $instances = array();
    
    public function __construct($builder)
    {
        $this->builder = $builder;
    }
    
    public function databaseConfig()
    {
        return $this->instance('databaseConfig');
    }
    
    public function httpConfig()
    {
        return $this->instance('httpConfig');
    }
    
    public function templateConfig()
    {
        return $this->instance('templateConfig');
    }
    
    public function filesystemRoot()
    {
        return $this->builder->assets()->root();
    }
    
    public function orm()
    {
        return $this->instance('orm');
    }
    
    public function ormConfig()
    {
        return $this->orm()->configData();
    }
    
    public function ormWrappers()
    {
        return $this->orm()->wrappers();
    }
    
    public function httpProcessor()
    {
        return $this->instance('httpProcessor');
    }
    
    public function httpRouteResolver()
    {
        return $this->instance('httpRouteResolver');
    }
    
    public function templateLocator()
    {
        return $this->instance('templateLocator');
    }
    
    protected function instance($name)
    {
        if(!array_key_exists($name, $this->instances)) {
            $method = 'build'.ucfirst($name);
            $this->instances[$name] = $this->$method();
        }
        
        return $this->instances[$name];
    }
    
    protected function buildDatabaseConfig()
    {
        return $this->configStorage()->slice('database');
    }
    
    protected function buildHttpConfig()
    {
        return $this->configStorage()->slice('http');
    }
    
    protected function buildTemplateConfig()
    {
        return $this->configStorage()->slice('template');
    }
    
    protected function buildOrm()
    {
        $components = $this->builder->components();
        
        return new Configuration\ORM(
            $components->slice(),
            $components->bundles()->orm()
        );
    }
    
    protected function buildHttpProcessor()
    {
        $components = $this->builder->components();
        
        return $components->httpProcessors()->attributeRegistryDispatcher(
            $components->bundles()->httpProcessors(),
            'bundle'
        );
    }
    
    protected function buildHttpRouteResolver()
    {
        $components = $this->builder->components();
        
        return $components->route()->buildResolver(
            $this->configStorage()->slice('http.resolver'),
            $components->bundles()->routeResolvers()
        );
    }
    
    protected function buildTemplateLocator()
    {
        $components = $this->builder->components();
        $bundleLocators = $components->bundles()->templateLocators();
        
        $overridesLocator = null;
        
        $overridesConfig = $this->configStorage()->slice('template.locator');
        if($overridesConfig->get('type') !== null) {
            $overridesLocator = $components->filesystem()->buildLocator(
                $overridesConfig,
                $bundleLocators
            );
        }
        
        return new Configuration\FilesystemLocator\Template(
            $bundleLocators,
            $this->builder->assets(),
            $overridesLocator    
        );
    }
    
    protected function configStorage()
    {
        return $this->builder->assets()->configStorage();
    }
}