From 3ddff879b150b77e21f7cb5308213d864ee59752 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sun, 28 Nov 2010 20:46:04 -0500 Subject: [PATCH] Converting IniAcl to use IniFile, this removes one of the classes responsibilities. --- cake/libs/controller/components/acl.php | 40 ++-------------- .../libs/controller/components/acl.test.php | 47 ------------------- 2 files changed, 5 insertions(+), 82 deletions(-) diff --git a/cake/libs/controller/components/acl.php b/cake/libs/controller/components/acl.php index 13173dc1e..f5d3febb8 100644 --- a/cake/libs/controller/components/acl.php +++ b/cake/libs/controller/components/acl.php @@ -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(); } /** diff --git a/cake/tests/cases/libs/controller/components/acl.test.php b/cake/tests/cases/libs/controller/components/acl.test.php index 7222aad78..b056e4842 100644 --- a/cake/tests/cases/libs/controller/components/acl.test.php +++ b/cake/tests/cases/libs/controller/components/acl.test.php @@ -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 *