11<?php
22 abstract class Ipam_Api_Abstract
33 {
4- protected static $ _IPAM = null ;
4+ protected static $ _IPAM = null ; // Global IPAM (enabled)
5+ protected static $ _aIPAM = array (); // a = all/array/available IPAM
6+
7+ protected $ _IPAM_ = null ; // Local IPAM (for this instance)
58
69 protected $ _errorMessage = null ;
710
@@ -14,6 +17,12 @@ abstract class Ipam_Api_Abstract
1417
1518 public function __construct ($ objectId = null )
1619 {
20+ /**
21+ * Permet de garder la référence de l'IPAM actuellement activé
22+ * pour cette instance d'Ipam_Api_Abstract
23+ */
24+ $ this ->_IPAM_ = self ::$ _IPAM ;
25+
1726 if ($ this ->objectIdIsValid ($ objectId )) {
1827 $ this ->_objectId = (int ) $ objectId ;
1928 $ this ->objectExists ();
@@ -123,15 +132,16 @@ protected function _getSubObjects($objects, $fieldName, $name)
123132 }
124133 }
125134
126- static protected function _searchObjects (array $ objects , $ fieldName , $ name )
135+ protected static function _searchObjects (array $ objects , $ fieldName , $ name, $ strict = false )
127136 {
128137 $ results = array ();
129138 $ name = preg_quote ($ name , '# ' );
130139 $ name = str_replace ('\* ' , '.* ' , $ name );
140+ $ name = ($ strict ) ? ('^( ' .$ name .')$ ' ) : ('( ' .$ name .') ' );
131141
132142 foreach ($ objects as $ object )
133143 {
134- if (preg_match ('#( ' .$ name .') #i ' , $ object [$ fieldName ])) {
144+ if (preg_match ('# ' .$ name .'#i ' , $ object [$ fieldName ])) {
135145 $ results [] = $ object ;
136146 }
137147 }
@@ -143,9 +153,14 @@ public function __get($name)
143153 {
144154 switch (mb_strtolower ($ name ))
145155 {
156+ case 'name ' :
157+ case 'label ' : {
158+ return $ this ->getObjectLabel ();
159+ }
146160 case 'ipam ' :
147- case '_ipam ' : {
148- return self ::$ _IPAM ;
161+ case '_ipam ' :
162+ case '_ipam_ ' : {
163+ return $ this ->_IPAM_ ;
149164 }
150165 default : {
151166 throw new Exception ("This attribute ' " .$ name ."' does not exist " , E_USER_ERROR );
@@ -155,16 +170,60 @@ public function __get($name)
155170
156171 public function __call ($ method , $ parameters = null )
157172 {
158- throw new Exception (' Method ' .$ method .' does not exist ' , E_USER_ERROR );
173+ throw new Exception (" Method ' " .$ method ." ' does not exist " , E_USER_ERROR );
159174 }
160175
161176 public function getErrorMessage ()
162177 {
163178 return $ this ->_errorMessage ;
164179 }
165180
166- public static function setIpam (IPAM_Main $ IPAM )
181+ public static function setIpam ($ IPAM )
182+ {
183+ if ($ IPAM instanceof IPAM_Main) {
184+ self ::$ _IPAM = $ IPAM ;
185+ return true ;
186+ }
187+ elseif (Tools::is ('array&&count>0 ' , $ IPAM ))
188+ {
189+ $ check = true ;
190+
191+ foreach ($ IPAM as $ _IPAM )
192+ {
193+ if (!($ _IPAM instanceof IPAM_Main)) {
194+ $ check = false ;
195+ break ;
196+ }
197+ }
198+
199+ if ($ check ) {
200+ self ::$ _IPAM = current ($ IPAM );
201+ self ::$ _aIPAM = $ IPAM ;
202+ return true ;
203+ }
204+ }
205+
206+ throw new Exception ("Unable to set IPAM object(s), it is not IPAM_Main instance or an array of it " , E_USER_ERROR );
207+ }
208+
209+ public static function getIpam ()
210+ {
211+ return (count (self ::$ _aIPAM ) > 0 ) ? (self ::$ _aIPAM ) : (self ::$ _IPAM );
212+ }
213+
214+ public static function enableIpam ($ key )
215+ {
216+ if (array_key_exists ($ key , self ::$ _aIPAM )) {
217+ self ::$ _IPAM = self ::$ _aIPAM [$ key ];
218+ return true ;
219+ }
220+ else {
221+ return false ;
222+ }
223+ }
224+
225+ public static function getIpamEnabled ()
167226 {
168- self ::$ _IPAM = $ IPAM ;
227+ return self ::$ _IPAM -> getServerId () ;
169228 }
170229 }
0 commit comments