Beispiel #1
0
 /**
  * Get the specified attribute of the object
  *
  * This is one of the many ways how to access an object's attribute.
  * <h2>Example:</h2>
  * <code>
  * use ADX\Core\Object;	// Import the class into the current namespace
  * // $link is a fully configured and bound {@link Link} object
  *
  * // Retrieve or create an object
  * $object = Object::read( 'OU=admins,DC=corp,DC=company,DC=com', ['mail', 'givenname'], $link );
  *
  * // Access the object's attribute
  * print_r( $object->get( 'mail' )->value() );
  * </code>
  *
  * @param		string			The name of the attribute, as defined on the ldap server
  *
  * @return		Attribute		An instance of Attribute class, holding the attribute's value(s)
  */
 public function get($attribute)
 {
     $attribute = strtolower($attribute);
     if (isset($this->data[$attribute])) {
         return $this->data[$attribute];
     } elseif ($attribute == 'dn') {
         return $this->dn;
     } else {
         // If someone does something like $adxObject->samaccountname->set('val') but samaccountname is not
         // set in the object this will ensure that the script will not fail
         // and data modification can continue as necessary.
         // However, if we have the directory schema cached and user tries to retrieve an attribute
         // that does not exist in the schema, we want to throw an exception instead of creating
         // a new Attribute ( an exception would have been thrown during update process - AD would
         // complain about non-existent attribute ).
         if (Schema::isCached() && Schema::get($attribute) === null) {
             throw new IncorrectParameterException("Attribute {$attribute} does not exist in the Directory schema");
         }
         // Either Schema is not cached or the attribute exists in the schema - let's continue
         $attribute = Attribute::make($attribute);
         $attribute->belongs_to($this);
         $this->data["{$attribute}"] = $attribute;
         return $attribute;
     }
 }