lithium\g11n\catalog\Adapter::_prepareForWrite PHP Method

_prepareForWrite() protected method

Override this method in sublcasses if you need to i.e. escape the item's values.
protected _prepareForWrite ( array $item ) : array
$item array
return array
    protected function _prepareForWrite(array $item)
    {
        return $item;
    }

Usage Example

コード例 #1
0
ファイル: Gettext.php プロジェクト: newmight2015/Blockchain-2
 /**
  * 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.
  *
  * @link http://www.asciitable.com
  * @see lithium\g11n\catalog\Adapter::_prepareForWrite()
  * @param array $item
  * @return array
  */
 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, "..\\\"");
         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);
 }