<?php
/**
 * Configuration Provider Base Implementation
 * 
 * Basic implementation of the Configuration Provider Interface. Should not be used
 * in real projects, purely demonstrational
 * 
 * @author Visual Media 
 */

namespace VisualM\MediaManagerBundle\Configuration;

/**
 * Configuration Provider Base Implementation
 * 
 * @author Visual Media 
 */
class ConfigurationProviderBaseImpl implements ConfigurationProviderInterface
{
    /**
     * Base Path
     * @var string
     */
    private $base_path;
    
    /**
     * Constructor
     * 
     * @param string $base_path Base path
     */
    function __construct($base_path)
    {
        $this->base_path = realpath($base_path);
        if (substr($this->base_path, -1, 1) !== DIRECTORY_SEPARATOR) {
            $this->base_path .= DIRECTORY_SEPARATOR;
        }
    }   
    
    /**
     * Retrieve Configuration for given key
     * 
     * Note: Altrough not enforced in any way, the key
     * should only contain characters a-z and 0-9 becouse it's used in 
     * the URL's
     * 
     * @param string $key Key
     * 
     * @return ConfigurationInterface Configuration
     */
    public function getConfiguration($key) {        
        if ($key !== 'default') {
            throw new \InvalidArgumentException(sprintf('Unknown configuration key: %s', $key));
        } 
        
        return new ConfigurationBaseImpl($this->base_path);        
    }
}