protected function SidecarMetadataDestinationTrait::_INIToArray in Backup and Migrate 8.4
Parse an INI file's contents.
For simplification this function only parses the simple subset of INI syntax generated by SidecarMetadataDestinationTrait::_arrayToINI();
Parameters
$ini:
Return value
array
1 call to SidecarMetadataDestinationTrait::_INIToArray()
- SidecarMetadataDestinationTrait::_loadFileMetadataArray in lib/
backup_migrate_core/ src/ Destination/ SidecarMetadataDestinationTrait.php
File
- lib/
backup_migrate_core/ src/ Destination/ SidecarMetadataDestinationTrait.php, line 70
Class
- SidecarMetadataDestinationTrait
- Class SidecarMetadataDestinationTrait.
Namespace
BackupMigrate\Core\DestinationCode
protected function _INIToArray($ini) {
$out = [];
$lines = explode("\n", $ini);
foreach ($lines as $line) {
$line = trim($line);
// Skip comments (even though there probably won't be any.
if (substr($line, 0, 1) == ';') {
continue;
}
// Match the key and value using a simplified syntax.
$matches = [];
if (preg_match('/^([^=]+)\\s?=\\s?"(.*)"$/', $line, $matches)) {
$key = $matches[1];
$val = $matches[2];
// Break up a key in the form a[b][c]
$keys = explode('[', $key);
$insert =& $out;
foreach ($keys as $part) {
$part = trim($part, ' ]');
$insert[$part] = '';
$insert =& $insert[$part];
}
$insert = $val;
}
}
return $out;
}