Converting IniAcl to use IniFile, this removes one of the classes responsibilities.

This commit is contained in:
Mark Story 2010-11-28 20:46:04 -05:00
parent 35611d50c3
commit 3ddff879b1
2 changed files with 5 additions and 82 deletions

View file

@ -645,43 +645,13 @@ class IniAcl extends Object implements AclInterface {
/**
* Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
*
* @param string $fileName File
* @param string $filename File
* @return array INI section structure
*/
public function readConfigFile($fileName) {
$fileLineArray = file($fileName);
foreach ($fileLineArray as $fileLine) {
$dataLine = trim($fileLine);
$firstChar = substr($dataLine, 0, 1);
if ($firstChar != ';' && $dataLine != '') {
if ($firstChar == '[' && substr($dataLine, -1, 1) == ']') {
$sectionName = preg_replace('/[\[\]]/', '', $dataLine);
} else {
$delimiter = strpos($dataLine, '=');
if ($delimiter > 0) {
$key = strtolower(trim(substr($dataLine, 0, $delimiter)));
$value = trim(substr($dataLine, $delimiter + 1));
if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
$value = substr($value, 1, -1);
}
$iniSetting[$sectionName][$key] = stripcslashes($value);
} else {
if (!isset($sectionName)) {
$sectionName = '';
}
$iniSetting[$sectionName][strtolower(trim($dataLine))] = '';
}
}
}
}
return $iniSetting;
public function readConfigFile($filename) {
App::import('Core', 'config/IniFile');
$iniFile = new IniFile($filename);
return $iniFile->asArray();
}
/**

View file

@ -260,53 +260,6 @@ class AclComponentTest extends CakeTestCase {
*/
class IniAclTest extends CakeTestCase {
/**
* testIniReadConfigFile
*
* @access public
* @return void
*/
function testReadConfigFile() {
$Ini = new IniAcl();
$iniFile = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
$result = $Ini->readConfigFile($iniFile);
$expected = array(
'admin' => array(
'groups' => 'administrators',
'allow' => '',
'deny' => 'ads',
),
'paul' => array(
'groups' => 'users',
'allow' =>'',
'deny' => '',
),
'jenny' => array(
'groups' => 'users',
'allow' => 'ads',
'deny' => 'images, files',
),
'nobody' => array(
'groups' => 'anonymous',
'allow' => '',
'deny' => '',
),
'administrators' => array(
'deny' => '',
'allow' => 'posts, comments, images, files, stats, ads',
),
'users' => array(
'allow' => 'posts, comments, images, files',
'deny' => 'stats, ads',
),
'anonymous' => array(
'allow' => '',
'deny' => 'posts, comments, images, files, stats, ads',
),
);
$this->assertEqual($result, $expected);
}
/**
* testIniCheck method
*