composer package updates
[openemr.git] / vendor / adldap2 / adldap2 / docs / quick-start.md
blob6656ab4477652565f6df38582dba09dcd10de686
1 ## Quick Start
3 ### Installation
5 Adldap2 requires [Composer](https://getcomposer.org/) for installation.
7 Once you have composer installed, run the following command in the root directory of your project:
9 ```
10 composer require adldap2/adldap2
11 ```
13 You're all set!
15 ### Usage
17 ```php
18 // Construct new Adldap instance.
19 $ad = new \Adldap\Adldap();
21 // Create a configuration array.
22 $config = [  
23   // The domain controllers option is an array of your LDAP hosts. You can
24   // use the either the host name or the IP address of your host.
25   'domain_controllers'    => ['ACME-DC01.corp.acme.org', '192.168.1.1'],
26   
27   // The base distinguished name of your domain.
28   'base_dn'               => 'dc=corp,dc=acme,dc=org',
29   
30   // The account to use for querying / modifying LDAP records. This
31   // does not need to be an actual admin account. This can also
32   // be a full distinguished name of the user account.
33   'admin_username'        => 'admin@corp.acme.org',
34   'admin_password'        => 'password',
37 // Add a connection provider to Adldap.
38 $ad->addProvider($config);
40 try {
41     // If a successful connection is made to your server, the provider will be returned.
42     $provider = $ad->connect();
44     // Performing a query.
45     $results = $provider->search()->where('cn', '=', 'John Doe')->get();
46     
47     // Finding a record.
48     $user = $provider->search()->find('jdoe');
50     // Creating a new LDAP entry. You can pass in attributes into the make methods.
51     $user =  $provider->make()->user([
52         'cn'          => 'John Doe',
53         'title'       => 'Accountant',
54         'description' => 'User Account',
55     ]);
57     // Setting a model's attribute.
58     $user->cn = 'John Doe';
60     // Saving the changes to your LDAP server.
61     if ($user->save()) {
62         // User was saved!
63     }
64 } catch (\Adldap\Auth\BindException $e) {
66     // There was an issue binding / connecting to the server.
69 ```