composer package updates
[openemr.git] / vendor / adldap2 / adldap2 / src / Models / Factory.php
blob9d612517f3ce4f8e9443c465cac3762b98f6cb6e
1 <?php
3 namespace Adldap\Models;
5 use Adldap\Query\Builder;
6 use Adldap\Schemas\ActiveDirectory;
7 use Adldap\Schemas\SchemaInterface;
9 /**
10 * Class Factory
12 * Constructs and scopes LDAP queries.
14 * @package Adldap\Models
16 class Factory
18 /**
19 * @var Builder
21 protected $query;
23 /**
24 * @var SchemaInterface
26 protected $schema;
28 /**
29 * Constructor.
31 * @param Builder $builder
33 public function __construct(Builder $builder)
35 $this->setQuery($builder)
36 ->setSchema($builder->getSchema());
39 /**
40 * Sets the current query builder.
42 * @param Builder $builder
44 * @return $this
46 public function setQuery(Builder $builder)
48 $this->query = $builder;
50 return $this;
53 /**
54 * Sets the current schema.
56 * @param SchemaInterface|null $schema
58 * @return $this
60 public function setSchema(SchemaInterface $schema = null)
62 $this->schema = $schema ?: new ActiveDirectory();
64 return $this;
67 /**
68 * Creates a new generic LDAP entry instance.
70 * @param array $attributes
72 * @return Entry
74 public function entry(array $attributes = [])
76 $model = $this->schema->entryModel();
78 return (new $model($attributes, $this->query));
81 /**
82 * Creates a new user instance.
84 * @param array $attributes
86 * @return User
88 public function user(array $attributes = [])
90 $model = $this->schema->userModel();
92 return (new $model($attributes, $this->query))
93 ->setAttribute($this->schema->objectClass(), [
94 $this->schema->top(),
95 $this->schema->person(),
96 $this->schema->organizationalPerson(),
97 $this->schema->user(),
98 ]);
102 * Creates a new organizational unit instance.
104 * @param array $attributes
106 * @return OrganizationalUnit
108 public function ou(array $attributes = [])
110 $model = $this->schema->organizationalUnitModel();
112 return (new $model($attributes, $this->query))
113 ->setAttribute($this->schema->objectClass(), [
114 $this->schema->top(),
115 $this->schema->organizationalUnit(),
120 * Creates a new group instance.
122 * @param array $attributes
124 * @return Group
126 public function group(array $attributes = [])
128 $model = $this->schema->groupModel();
130 return (new $model($attributes, $this->query))
131 ->setAttribute($this->schema->objectClass(), [
132 $this->schema->top(),
133 $this->schema->objectCategoryGroup(),
138 * Creates a new organizational unit instance.
140 * @param array $attributes
142 * @return Container
144 public function container(array $attributes = [])
146 $model = $this->schema->containerModel();
148 return (new $model($attributes, $this->query))
149 ->setAttribute($this->schema->objectClass(), $this->schema->organizationalUnit());
153 * Creates a new user instance as a contact.
155 * @param array $attributes
157 * @return User
159 public function contact(array $attributes = [])
161 $model = $this->schema->contactModel();
163 return (new $model($attributes, $this->query))
164 ->setAttribute($this->schema->objectClass(), [
165 $this->schema->top(),
166 $this->schema->person(),
167 $this->schema->organizationalPerson(),
168 $this->schema->contact(),
173 * Creates a new computer instance.
175 * @param array $attributes
177 * @return Computer
179 public function computer(array $attributes = [])
181 $model = $this->schema->computerModel();
183 return (new $model($attributes, $this->query))
184 ->setAttribute($this->schema->objectClass(), [
185 $this->schema->top(),
186 $this->schema->person(),
187 $this->schema->organizationalPerson(),
188 $this->schema->user(),
189 $this->schema->computer(),