mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Converting IniAcl to use IniFile, this removes one of the classes responsibilities.
This commit is contained in:
parent
35611d50c3
commit
3ddff879b1
2 changed files with 5 additions and 82 deletions
|
@ -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.
|
* 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
|
* @return array INI section structure
|
||||||
*/
|
*/
|
||||||
public function readConfigFile($fileName) {
|
public function readConfigFile($filename) {
|
||||||
$fileLineArray = file($fileName);
|
App::import('Core', 'config/IniFile');
|
||||||
|
$iniFile = new IniFile($filename);
|
||||||
foreach ($fileLineArray as $fileLine) {
|
return $iniFile->asArray();
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -260,53 +260,6 @@ class AclComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
class IniAclTest 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
|
* testIniCheck method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue