$val) $ret[$key] = json_encode($this -> parseValue($val)); return $ret; } /** * Return the values for saving * * @param mixed $data Array of timestamp * * @return mixed LDAP attribute values */ public function getUpdateData($data) { $ret = array(); foreach(ensureIsArray($data) as $key => $val) $ret[$key] = $this -> encodeValue(json_decode($val, true)); return $ret; } public function parseValue($value) { $parts = explode('#', $value); if (!is_array($parts) || count($parts) != 4) { self :: log_warning($this."->parseValue($value): Invalid value (parts count != 4)."); return; } $datetime = date_create_from_format('YmdHisO', $parts[0]); if ($datetime instanceof DateTime) { $datetime -> setTimezone(timezone_open(date_default_timezone_get())); $time = $datetime -> format($this -> getFormat()); } else { self :: log_warning($this."->parseValue($value): Fail to parse time '".$parts[0]."'."); $time = getFData(_('Unknown (%{raw_value})'), $parts[0]); } return array( "time" => $time, "syntaxOID" => $parts[1], "length" => intval($parts[2]), "hashed_password" => $parts[3], ); } /** * Encode a value * @param array $value The value to encode * @return string The encoded value */ public function encodeValue($value) { if (!is_array($value)) { self :: log_warning($this."->encodeValue($value): Provided value is not an array."); return; } $datetime = date_create_from_format('YmdHisO', $value['time']); if (!is_a($datetime, 'DateTime')) { self :: log_warning($this."->encodeValue(".varDump($value)."): Fail to create DateTime object from timestamp '".varDump($value['time'])."'."); return; } $datetime -> setTimezone('UTC'); $datetime_string = $datetime -> format('YmdHisO'); $datetime_string = preg_replace('/[\+\-]0000$/', 'Z', $datetime_string); return implode( "#", array ( $datetime_string, $value['syntaxOID'], $value['length'], $value['hashed_password'], ) ); } /** * Return date format * * @return string The date format (as accept by Datetime :: format() and date_create_from_format()) **/ public function getFormat() { return $this -> getConfig('ldap_options.date_format', 'Y/m/d H:i:s'); } }