/** * This inserts a value into bagInfoData. * * @param string $key This is the key to insert into the data. * @param string $value This is the value to associate with the key. * * @return void * @author Eric Rochester <*****@*****.**> **/ public function setBagInfoData($key, $value) { $this->_ensureBagInfoData(); $this->bagInfoData[$key] = BagIt_getAccumulatedValue($this->bagInfoData, $key, $value); }
/** * Parse bag info file. * * @param array $lines An array of lines from the file. * * @return array The parsed bag-info data. */ function BagIt_parseBagInfo($lines) { $bagInfo = array(); $prevKey = null; foreach ($lines as $line) { if (strlen($line) <= 1) { // Skip. } else { if ($line[0] == ' ' || $line[0] == "\t") { // Continued line. $val = $bagInfo[$prevKey]; if (is_array($val)) { $val[count($val) - 1] .= ' ' . trim($line); } else { $val .= ' ' . trim($line); } $bagInfo[$prevKey] = $val; } else { list($key, $val) = preg_split('/:\\s*/', $line, 2); $val = trim($val); $prevKey = $key; $bagInfo[$prevKey] = BagIt_getAccumulatedValue($bagInfo, $prevKey, $val); } } } return $bagInfo; }