Discussion:
[22868] standard/branches/user/zf-ldap-dev: added Zend_Ldap_Converter subcomponent provided by Andreas Heigl
sgehrig
2010-08-21 13:26:42 UTC
Permalink
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[framework-svn][22868] standard/branches/user/zf-ldap-dev: added Zend_Ldap_Converter subcomponent provided by Andreas Heigl</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd>22868</dd>
<dt>Author</dt> <dd>sgehrig</dd>
<dt>Date</dt> <dd>2010-08-21 06:26:42 -0700 (Sat, 21 Aug 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>added Zend_Ldap_Converter subcomponent provided by Andreas Heigl
adjusted to fit coding-guidelines and coding-style
modified to be usabale as a replacement for the conversion methods of Zend_Ldap_Attribute in a backwards-compatible way

NOTICE: This revision is not passing all unit tests introducing a backwards-compatibility breakage. Not to be used!</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#standardbranchesuserzfldapdevlibraryZendLdapAttributephp">standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Attribute.php</a></li>
<li><a href="#standardbranchesuserzfldapdevlibraryZendLdapConverterphp">standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Converter.php</a></li>
<li><a href="#standardbranchesuserzfldapdevtestsZendLdapConverterTestphp">standard/branches/user/zf-ldap-dev/tests/Zend/Ldap/ConverterTest.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Converter/</li>
<li><a href="#standardbranchesuserzfldapdevlibraryZendLdapConverterExceptionphp">standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Converter/Exception.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="standardbranchesuserzfldapdevlibraryZendLdapAttributephp"></a>
<div class="modfile"><h4>Modified: standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Attribute.php (22867 => 22868)</h4>
<pre class="diff"><span>
<span class="info">--- standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Attribute.php 2010-08-21 13:23:27 UTC (rev 22867)
+++ standard/branches/user/zf-ldap-dev/library/Zend/Ldap/Attribute.php 2010-08-21 13:26:42 UTC (rev 22868)
</span><span class="lines">@@ -20,6 +20,11 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * @see Zend_Ldap_Converter
+ */
+require_once 'Zend/Ldap/Converter.php';
+
+/**
</ins><span class="cx"> * Zend_Ldap_Attribute is a collection of LDAP attribute related functions.
</span><span class="cx"> *
</span><span class="cx"> * @category Zend
</span><span class="lines">@@ -185,32 +190,33 @@
</span><span class="cx"> */
</span><span class="cx"> private static function _valueToLdap($value)
</span><span class="cx"> {
</span><del>- if (is_string($value)) return $value;
- else if (is_int($value) || is_float($value)) return (string)$value;
- else if (is_bool($value)) return ($value === true) ? 'TRUE' : 'FALSE';
- else if (is_object($value) || is_array($value)) return serialize($value);
- else if (is_resource($value) &amp;&amp; get_resource_type($value) === 'stream')
- return stream_get_contents($value);
- else return null;
</del><ins>+ return Zend_Ldap_Converter::toLdap($value);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @param string $value
</span><del>- * @return string|boolean
</del><ins>+ * @return mixed
</ins><span class="cx"> */
</span><span class="cx"> private static function _valueFromLdap($value)
</span><span class="cx"> {
</span><del>- $value = (string)$value;
- if ($value === 'TRUE') return true;
- else if ($value === 'FALSE') return false;
- else return $value;
</del><ins>+ try {
+ $return = Zend_Ldap_Converter::fromLdap($value, Zend_Ldap_Converter::STANDARD, false);
+ if ($return instanceof DateTime) {
+ return Zend_Ldap_Converter::toLdapDateTime($return, false);
+ } else {
+ return $return;
+ }
+ } catch (InvalidArgumentException $e) {
+ return $value;
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Converts a PHP data type into its LDAP representation
</span><span class="cx"> *
</span><del>- * @param mixed $value
- * @return string|null - null if the PHP data type cannot be converted.
</del><ins>+ * @deprected use Zend_Ldap_Converter instead
+ * @param mixed $value
+ * @return string|null - null if the PHP data type cannot be converted.
</ins><span class="cx"> */
</span><span class="cx"> public static function convertToLdapValue($value)
</span><span class="cx"> {
</span><span class="lines">@@ -220,8 +226,9 @@
</span><span class="cx"> /**
</span><span class="cx"> * Converts an LDAP value into its PHP data type
</span><span class="cx"> *
</span><del>- * @param string $value
- * @return mixed
</del><ins>+ * @deprected use Zend_Ldap_Converter instead
+ * @param string $value
+ * @return mixed
</ins><span class="cx"> */
</span><span class="cx"> public static function convertFromLdapValue($value)
</span><span class="cx"> {
</span><span class="lines">@@ -362,8 +369,7 @@
</span><span class="cx"> private static function _valueToLdapDateTime($value, $utc)
</span><span class="cx"> {
</span><span class="cx"> if (is_int($value)) {
</span><del>- if ($utc === true) return gmdate('YmdHis', $value) . 'Z';
- else return date('YmdHisO', $value);
</del><ins>+ return Zend_Ldap_Converter::toLdapDateTime($value, $utc);
</ins><span class="cx"> }
</span><span class="cx"> else return null;
</span><span class="cx"> }
</span><span class="lines">@@ -393,31 +399,19 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * @param string $value
</del><ins>+ * @param string|DateTime $value
</ins><span class="cx"> * @return integer|null
</span><span class="cx"> */
</span><span class="cx"> private static function _valueFromLdapDateTime($value)
</span><span class="cx"> {
</span><del>- $matches = array();
- if (preg_match('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:\.0)?([+-]\d{4}|Z)$/', $value, $matches)) {
- $year = $matches[1];
- $month = $matches[2];
- $day = $matches[3];
- $hour = $matches[4];
- $minute = $matches[5];
- $second = $matches[6];
- $timezone = $matches[7];
- $date = gmmktime($hour, $minute, $second, $month, $day, $year);
- if ($timezone !== 'Z') {
- $tzDirection = substr($timezone, 0, 1);
- $tzOffsetHour = substr($timezone, 1, 2);
- $tzOffsetMinute = substr($timezone, 3, 2);
- $tzOffset = ($tzOffsetHour*60*60) + ($tzOffsetMinute*60);
- if ($tzDirection == '+') $date -= $tzOffset;
- else if ($tzDirection == '-') $date += $tzOffset;
</del><ins>+ if ($value instanceof DateTime) {
+ return $value-&gt;format('U');
+ } else if (is_string($value)) {
+ try {
+ return Zend_Ldap_Converter::fromLdapDateTime($value, false)-&gt;format('U');
+ } catch (InvalidArgumentException $e) {
+ return null;
</ins><span class="cx"> }
</span><del>- return $date;
- }
- else return null;
</del><span class="lines">@@ Diff output truncated at 4096 characters. @@
</span></span></pre>
</div>
</div>

</body>
</html>

Loading...