Exemplo n.º 1
0
 /**
  * Parse the given tokens into a data structure
  *
  * @param  array $data
  * @param  array $tokens
  * @return void
  */
 protected function parseLdapSchemaSyntax(array &$data, array $tokens)
 {
     // tokens that have no value associated
     $noValue = array('single-value', 'obsolete', 'collective', 'no-user-modification', 'abstract', 'structural', 'auxiliary');
     // tokens that can have multiple values
     $multiValue = array('must', 'may', 'sup');
     while (count($tokens) > 0) {
         $token = strtolower(array_shift($tokens));
         if (in_array($token, $noValue)) {
             $data[$token] = true;
             // single value token
         } else {
             $data[$token] = array_shift($tokens);
             // this one follows a string or a list if it is multivalued
             if ($data[$token] == '(') {
                 // this creates the list of values and cycles through the tokens
                 // until the end of the list is reached ')'
                 $data[$token] = array();
                 $tmp = array_shift($tokens);
                 while ($tmp) {
                     if ($tmp == ')') {
                         break;
                     }
                     if ($tmp != '$') {
                         $data[$token][] = Converter\Converter::fromLdap($tmp);
                     }
                     $tmp = array_shift($tokens);
                 }
             } else {
                 $data[$token] = Converter\Converter::fromLdap($data[$token]);
             }
             // create a array if the value should be multivalued but was not
             if (in_array($token, $multiValue) && !is_array($data[$token])) {
                 $data[$token] = array($data[$token]);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @dataProvider fromLdapProvider
  */
 public function testFromLdap($expect, $value, $type, $dateTimeAsUtc)
 {
     $this->assertSame($expect, Converter::fromLdap($value, $type, $dateTimeAsUtc));
 }
Exemplo n.º 3
0
 /**
  * @param  string $value
  * @return mixed
  */
 private static function valueFromLdap($value)
 {
     try {
         $return = Converter\Converter::fromLdap($value, Converter\Converter::STANDARD, false);
         if ($return instanceof DateTime) {
             return Converter\Converter::toLdapDateTime($return, false);
         } else {
             return $return;
         }
     } catch (Exception\InvalidArgumentException $e) {
         return $value;
     }
 }