Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
24 / 24
CRAP
100.00% covered (success)
100.00%
63 / 63
Builder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
24 / 24
34
100.00% covered (success)
100.00%
63 / 63
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 frameworkBuilder
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 components
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 config
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
 routeResolver
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
 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
 filesystemRoot
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 assetsRoot
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 webRoot
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
 buildHttpProcessor
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildConfig
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 buildRouteResolver
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
7 / 7
 buildTemplateLocator
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
10 / 10
 buildFilesystemRoot
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 buildOrmConfig
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 buildOrmWrappers
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildWebRoot
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildAssetsRoot
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 buildPathRoot
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
8 / 8
 getRootDirectory
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
namespace PHPixie\DefaultBundle;
abstract class Builder
{
    protected $frameworkBuilder;
    
    protected $instances = array();
    
    public function __construct($frameworkBuilder)
    {
        $this->frameworkBuilder = $frameworkBuilder;
    }
    
    public function frameworkBuilder()
    {
        return $this->frameworkBuilder;
    }
    
    public function components()
    {
        return $this->frameworkBuilder->components();
    }
    
    public function config()
    {
        return $this->instance('config');
    }
    
    public function httpProcessor()
    {
        return $this->instance('httpProcessor');
    }
    
    public function routeResolver()
    {
        return $this->instance('routeResolver');
    }
    
    public function templateLocator()
    {
        return $this->instance('templateLocator');
    }
    
    public function ormConfig()
    {
        return $this->instance('ormConfig');
    }
    
    public function ormWrappers()
    {
        return $this->instance('ormWrappers');
    }
    
    public function filesystemRoot()
    {
        return $this->instance('filesystemRoot');
    }
    
    public function assetsRoot()
    {
        return $this->instance('assetsRoot');
    }
    
    public function webRoot()
    {
        return $this->instance('webRoot');
    }
    
    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 buildHttpProcessor()
    {
        return null;
    }
    
    protected function buildConfig()
    {
        $assetsRoot = $this->assetsRoot();
        if($assetsRoot === null) {
            return null;
        }
        
        return $this->components()->config()->directory(
            $assetsRoot->path(),
            'config'
        );
    }
    
    
    protected function buildRouteResolver()
    {
        $config = $this->config();
        if($config === null) {
            return null;
        }
        
        $configData = $config->slice('routeResolver');
        if($configData->get('type') === null) {
            return null;
        }
        
        return $this->components()->route()->buildResolver($configData);
    }
    
    protected function buildTemplateLocator()
    {
        $config = $this->config();
        if($config === null) {
            return null;
        }
        
        $configData = $config->slice('templateLocator');
        if($configData->get('type') === null) {
            return null;
        }
        
        return $this->components()->filesystem()->buildLocator(
            $configData,
            $this->assetsRoot()
        );
    }
    
    protected function buildFilesystemRoot()
    {
        $directory = $this->getRootDirectory();
        
        if($directory === null) {
            return null;
        }
        
        return $this->components()->filesystem()->root(
            $directory
        );
    }
    
    protected function buildOrmConfig()
    {
        $config = $this->config();
        if($config === null) {
            return null;
        }
        
        return $config->slice('orm');
    }
    
    protected function buildOrmWrappers()
    {
        return null;
    }
    
    protected function buildWebRoot()
    {
        return $this->buildPathRoot('web');
    }
    
    protected function buildAssetsRoot()
    {
        return $this->buildPathRoot('assets');
    }
    
    protected function buildPathRoot($path)
    {
        $filesystemRoot = $this->filesystemRoot();
        if($filesystemRoot === null) {
            return null;
        }
        
        $directory = $this->filesystemRoot()->path($path);
        
        if(!is_dir($directory)) {
            return null;
        }
        
        return $this->components()->filesystem()->root(
            $directory
        );
    }
    
    protected function getRootDirectory()
    {
        return null;
    }
}