protected function SidecarMetadataDestinationTrait::iniToArray in Backup and Migrate 5.0.x
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 src/
Core/ Destination/ SidecarMetadataDestinationTrait.php
File
- src/
Core/ Destination/ SidecarMetadataDestinationTrait.php, line 70
Class
- SidecarMetadataDestinationTrait
- Store extended meta data in a sidecar file.
Namespace
Drupal\backup_migrate\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;
}