Prepares an item before it is being written and escapes fields.
All characters from \000 to \037 (this includes new line and tab characters) as well as the backslash (`\`) and the double quote (`"`) are escaped. Literal Windows CRLFs (`\r\n`) are converted to LFs (`\n`) to improve cross platform compatibility. Escaped single quotes (`'`) are unescaped as they should not need to be. Double escaped characters are maintained and not escaped once again.

Parameters

  • array $item

Returns

array

Source

						protected function _prepareForWrite(array $item) {
		$filter = function ($value) use (&$filter) {
			if (is_array($value)) {
				return array_map($filter, $value);
			}
			$value = strtr($value, array("\\'" => "'", "\\\\" => "\\", "\r\n" => "\n"));
			$value = addcslashes($value, "\0..\37\\\"");
			return $value;
		};
		$fields = array('id', 'ids', 'translated');

		foreach ($fields as $field) {
			if (isset($item[$field])) {
				$item[$field] = $filter($item[$field]);
			}
		}
		if (!isset($item['ids']['singular'])) {
			$item['ids']['singular'] = $item['id'];
		}
		if (isset($item['occurrences'])) {
			foreach ($item['occurrences'] as &$occurrence) {
				$occurrence['file'] = str_replace(LITHIUM_APP_PATH, '', $occurrence['file']);
			}
		}
		return parent::_prepareForWrite($item);
	}