Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#4766] Config makes include_path usage op…
Browse files Browse the repository at this point in the history
…t-in only

- You must pass the `$useIncludePath` to either `fromFile()` or
  `fromFiles()` for it to be used. Constants were created with boolean
  values for those using IDEs.
  • Loading branch information
weierophinney committed Jul 1, 2013
1 parent 3b631dc commit d043eca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@

class Factory
{
/**@+
* Constants defining rules for whether or not to use the include_path;
* used with fromFile() and fromFiles().
*/
const NO_USE_INCLUDE_PATH = false;
const USE_INCLUDE_PATH = true;
/**@-*/

/**
* Plugin manager for loading readers
*
Expand Down Expand Up @@ -59,14 +67,22 @@ class Factory
*
* @param string $filename
* @param bool $returnConfigObject
* @param bool $useIncludePath
* @return array|Config
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public static function fromFile($filename, $returnConfigObject = false)
public static function fromFile($filename, $returnConfigObject = false, $useIncludePath = self::NO_USE_INCLUDE_PATH)
{
$filepath = $filename;
if (!file_exists($filename)) {
if (!$useIncludePath) {
throw new Exception\RuntimeException(sprintf(
'Filename "%s" cannot be found relative to the working directory',
$filename
));
}

$fromIncludePath = stream_resolve_include_path($filename);
if (!$fromIncludePath) {
throw new Exception\RuntimeException(sprintf(
Expand Down Expand Up @@ -122,14 +138,15 @@ public static function fromFile($filename, $returnConfigObject = false)
*
* @param array $files
* @param bool $returnConfigObject
* @param bool $useIncludePath
* @return array|Config
*/
public static function fromFiles(array $files, $returnConfigObject = false)
public static function fromFiles(array $files, $returnConfigObject = false, $useIncludePath = self::NO_USE_INCLUDE_PATH)
{
$config = array();

foreach ($files as $file) {
$config = ArrayUtils::merge($config, static::fromFile($file));
$config = ArrayUtils::merge($config, static::fromFile($file, false, $useIncludePath));
}

return ($returnConfigObject) ? new Config($config) : $config;
Expand Down
2 changes: 1 addition & 1 deletion test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testFromIniAndXmlAndPhpFilesFromIncludePath()
'Xml/include-base2.xml',
'Php/include-base3.php',
);
$config = Factory::fromFiles($files, Factory::USE_INCLUDE_PATH);
$config = Factory::fromFiles($files, false, Factory::USE_INCLUDE_PATH);

$this->assertEquals('bar', $config['base']['foo']);
$this->assertEquals('baz', $config['test']['bar']);
Expand Down

0 comments on commit d043eca

Please sign in to comment.