Skip to content

Commit

Permalink
Converting IniAcl to use IniFile, this removes one of the classes res…
Browse files Browse the repository at this point in the history
…ponsibilities.
  • Loading branch information
markstory committed Nov 29, 2010
1 parent 35611d5 commit 3ddff87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 82 deletions.
40 changes: 5 additions & 35 deletions cake/libs/controller/components/acl.php
Expand Up @@ -645,43 +645,13 @@ public function check($aro, $aco, $aco_action = null) {
/**
* 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();
}

/**
Expand Down
47 changes: 0 additions & 47 deletions cake/tests/cases/libs/controller/components/acl.test.php
Expand Up @@ -260,53 +260,6 @@ function testAdapterException() {
*/
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
*
Expand Down

0 comments on commit 3ddff87

Please sign in to comment.