Skip to content

Commit

Permalink
Small idiot-resistant fixes in Configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxist committed Jul 9, 2011
1 parent 7db9085 commit 7f08f8e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Opl/Autoloader/Toolset/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
namespace Opl\Autoloader\Toolset;
use Opl\Autoloader\Exception\FileFormatException;
use Opl\Autoloader\Exception\FileNotFoundException;
use OutOfBoundsException;

/**
Expand Down Expand Up @@ -52,13 +53,14 @@ class Configuration
/**
* Imports the configuration file content into the memory.
*
* @throws FileNotFoundException
* @throws FileFormatException
* @param type $configFile
*/
public function __construct($configFile)
{
libxml_use_internal_errors(true);
$document = \simplexml_load_file($configFile);
$document = \simplexml_load_file($configFile);
foreach (libxml_get_errors() as $error)
{
if($error->level != LIBXML_ERR_WARNING)
Expand All @@ -67,6 +69,10 @@ public function __construct($configFile)
throw new FileFormatException('An error occured while parsing \''.$configFile.'\': '.$error->message.' on line '.($error->line - 1));
}
}
if(!is_object($document))
{
throw new FileNotFoundException('Cannot open the file: '.$configFile);
}

if(isset($document->{'file-header'}))
{
Expand All @@ -88,9 +94,12 @@ public function __construct($configFile)
$this->processFileTag($file);
}
}
foreach($document->separator as $separatorTag)
if(isset($document->separator))
{
$this->processSeparatorTag($separatorTag);
foreach($document->separator as $separatorTag)
{
$this->processSeparatorTag($separatorTag);
}
}
} // end __construct();

Expand Down

0 comments on commit 7f08f8e

Please sign in to comment.