Пример #1
0
 /**
  * Returns the models memberOf names only.
  *
  * @return array
  */
 public function getMemberOfNames()
 {
     $names = [];
     $dns = $this->getAttribute(ActiveDirectory::MEMBER_OF);
     if (is_array($dns)) {
         foreach ($dns as $dn) {
             $exploded = Utilities::explodeDn($dn);
             if (array_key_exists(0, $exploded)) {
                 $names[] = $exploded[0];
             }
         }
     }
     return $names;
 }
Пример #2
0
 /**
  * Returns a new LDAP Entry instance.
  *
  * @param array $attributes
  *
  * @return Entry
  */
 public function newLdapEntry(array $attributes = [])
 {
     $attribute = ActiveDirectory::OBJECT_CATEGORY;
     if (array_key_exists($attribute, $attributes) && array_key_exists(0, $attributes[$attribute])) {
         // We'll explode the DN so we can grab it's object category.
         $category = Utilities::explodeDn($attributes[$attribute][0]);
         // Make sure the category string exists in the attribute array
         if (array_key_exists(0, $category)) {
             $category = strtolower($category[0]);
             if (array_key_exists($category, $this->mappings)) {
                 $model = $this->mappings[$category];
                 return (new $model([], $this))->setRawAttributes($attributes);
             }
         }
     }
     // A default entry object if the object category isn't found
     return (new Entry([], $this))->setRawAttributes($attributes);
 }
Пример #3
0
 /**
  * Returns the model's object category DN in an exploded array.
  *
  * @return array
  */
 public function getObjectCategoryArray()
 {
     return Utilities::explodeDn($this->getObjectCategoryDn());
 }
Пример #4
0
 /**
  * Sets the base DB string.
  *
  * @param string $base
  *
  * @return $this
  */
 public function setBase($base)
 {
     if (!is_null($base)) {
         // If the base DN isn't null we'll try to explode it.
         $base = Utilities::explodeDn($base, false);
         // Since exploding a DN returns false on failure,
         // we'll double check to make sure it's an array
         if (is_array($base)) {
             // We need to reverse the base to keep the order in tact since RDNs
             // are already reversed to follow the right to left pattern
             $base = array_reverse($base);
             foreach ($base as $key => $rdn) {
                 // We'll avoid going through the count key as it's
                 // automatically created when exploding a DN
                 if ($key !== 'count') {
                     // We'll break the RDN into pieces
                     $pieces = explode('=', $rdn);
                     // If there's exactly 2 pieces, then we can work with it.
                     if (count($pieces) === 2) {
                         // We see what type of RDN it is and add each accordingly
                         switch (strtoupper($pieces[0])) {
                             case 'DC':
                                 $this->addDc($pieces[1]);
                                 break;
                             case 'OU':
                                 $this->addOu($pieces[1]);
                                 break;
                             case 'CN':
                                 $this->addCn($pieces[1]);
                                 break;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Пример #5
0
 /**
  * Returns a new LDAP Entry instance.
  *
  * @param array $attributes
  *
  * @return Entry
  */
 public function newLdapEntry(array $attributes)
 {
     $attribute = ActiveDirectory::OBJECT_CATEGORY;
     if (array_key_exists($attribute, $attributes) && array_key_exists(0, $attributes[$attribute])) {
         // We'll explode the DN so we can grab it's object category.
         $category = Utilities::explodeDn($attributes[$attribute][0]);
         // We'll create a new object depending on the object category of the LDAP entry.
         switch (strtolower($category[0])) {
             case ActiveDirectory::OBJECT_CATEGORY_COMPUTER:
                 return (new Computer([], $this->connection))->setRawAttributes($attributes);
             case ActiveDirectory::OBJECT_CATEGORY_PERSON:
                 return (new User([], $this->connection))->setRawAttributes($attributes);
             case ActiveDirectory::OBJECT_CATEGORY_GROUP:
                 return (new Group([], $this->connection))->setRawAttributes($attributes);
             case ActiveDirectory::MS_EXCHANGE_SERVER:
                 return (new ExchangeServer([], $this->connection))->setRawAttributes($attributes);
             case ActiveDirectory::OBJECT_CATEGORY_CONTAINER:
                 return (new Container([], $this->connection))->setRawAttributes($attributes);
             case ActiveDirectory::OBJECT_CATEGORY_PRINTER:
                 return (new Printer($attributes, $this->connection))->setRawAttributes();
         }
     }
     // A default entry object if the object category isn't recognized.
     return (new Entry($attributes, $this->connection))->setRawAttributes($attributes);
 }