add enhancement

This commit is contained in:
Nicolas Le Goff
2011-12-28 19:31:38 +01:00
parent 5e07d736e2
commit bcd6719845
3 changed files with 36 additions and 12 deletions

View File

@@ -38,11 +38,11 @@ class Application implements Specification
*/ */
public function getConfFileFromEnvName($name) public function getConfFileFromEnvName($name)
{ {
if($name === self::EXTENDED_MAIN_KEYWORD) if ($name === self::EXTENDED_MAIN_KEYWORD)
{ {
return $this->getMainFile(); return $this->getMainConfigurationFile();
} }
return new \SplFileObject(sprintf("%s/config_%s.%s" return new \SplFileObject(sprintf("%s/config_%s.%s"
, $this->getConfigurationFilePath() , $this->getConfigurationFilePath()
, $name , $name
@@ -58,8 +58,12 @@ class Application implements Specification
{ {
return __DIR__ . '/../../../../../config'; return __DIR__ . '/../../../../../config';
} }
public function getMainFile() /**
*
* {@inheritdoc}
*/
public function getMainConfigurationFile()
{ {
$path = __DIR__ . '/../../../../../config/config.yml'; $path = __DIR__ . '/../../../../../config/config.yml';
return new \SplFileObject($path); return new \SplFileObject($path);

View File

@@ -40,20 +40,38 @@ class Handler
* @param ConfigurationSpecification $configSpec * @param ConfigurationSpecification $configSpec
* @param Parser\ParserInterface $parser * @param Parser\ParserInterface $parser
*/ */
public function __construct(Application $configSpec, Parser $parser) public function __construct(Specification $configSpec, Parser $parser)
{ {
$this->confSpecification = $configSpec; $this->confSpecification = $configSpec;
$this->parser = $parser; $this->parser = $parser;
} }
/** /**
* Getter
* @return Specification
*/
public function getSpecification()
{
return $this->confSpecification;
}
/**
* Getter
* @return Parser
*/
public function getParser()
{
return $this->parser;
}
/**
* Stacks all envrironnement in $env that extends the loaded configuration file * Stacks all envrironnement in $env that extends the loaded configuration file
* *
* @param SplFileObject $file File of the current loaded config file * @param SplFileObject $file File of the current loaded config file
* @param array $envs A stack of conf environnments * @param array $envs A stack of conf environnments
* @return array * @return array
*/ */
private function retrieveExtendedEnvFromFile(\SplFileObject $file, Array $allEnvs = array()) public function retrieveExtendedEnvFromFile(\SplFileObject $file, Array $allEnvs = array())
{ {
$env = $this->parser->parse($file); $env = $this->parser->parse($file);
@@ -119,7 +137,6 @@ class Handler
*/ */
public function handle($name) public function handle($name)
{ {
//get the corresepondant file //get the corresepondant file
$file = $this->confSpecification->getConfFileFromEnvName($name); $file = $this->confSpecification->getConfFileFromEnvName($name);
@@ -171,10 +188,6 @@ class Handler
$searchArray[$k] = $value; $searchArray[$k] = $value;
break; //quit break; //quit
} }
else
{
continue;
}
} }
} }
}; };

View File

@@ -29,6 +29,13 @@ interface Specification
*/ */
const EXTENDED_MAIN_KEYWORD = 'main'; const EXTENDED_MAIN_KEYWORD = 'main';
/**
* Return the main configuration file
*
* @return \SplFileObject
*/
public function getMainConfigurationFile();
/** /**
* Return an array of paths that CAN'T be extended by ONLY one or more of their value * Return an array of paths that CAN'T be extended by ONLY one or more of their value
* but must be fully replaced with new values * but must be fully replaced with new values