@@ -26,22 +26,6 @@ class Api_Address extends Api_Abstract
2626 const RESERVED = 'reserved ' ;
2727 const DHCP = 'DHCP ' ;
2828
29- /**
30- * Enable or disable cache feature
31- * /!\ Cache must be per type
32- *
33- * @var array
34- */
35- protected static $ _cache = array (); // IPAM server ID keys, boolean value
36-
37- /**
38- * All sections (cache)
39- * /!\ Cache must be per type
40- *
41- * @var array
42- */
43- protected static $ _objects = array (); // IPAM server ID keys, array value
44-
4529 /**
4630 * @var int
4731 */
@@ -98,7 +82,7 @@ protected function _getObject()
9882 if ($ this ->_objectExists === null || $ this ->objectExists ())
9983 {
10084 if ($ this ->_objectDatas === null ) {
101- $ this ->_objectDatas = $ this ->_IPAM ->getAddress ($ this ->getAddressId ());
85+ $ this ->_objectDatas = $ this ->_adapter ->getAddress ($ this ->getAddressId ());
10286 }
10387
10488 return $ this ->_objectDatas ;
@@ -174,7 +158,7 @@ public function getSubnet()
174158 $ subnetId = $ this ->getSubnetId ();
175159
176160 if ($ subnetId !== false ) {
177- return $ this ->_IPAM ->getSubnet ($ subnetId );
161+ return $ this ->_adapter ->getSubnet ($ subnetId );
178162 }
179163 else {
180164 return false ;
@@ -254,7 +238,7 @@ public function getAddress()
254238 }
255239 }
256240
257- public function create ($ description = '' , $ note = '' , $ port = '' , $ tag = self ::ONLINE )
241+ public function create ($ description = '' , $ note = '' , $ port = '' , $ tag = self ::ONLINE , $ autoRegisterToStore = true )
258242 {
259243 $ this ->_errorMessage = null ;
260244
@@ -271,7 +255,7 @@ public function create($description = '', $note = '', $port = '', $tag = self::O
271255 }
272256
273257 try {
274- $ status = $ this ->_IPAM ->createAddress ($ this ->getSubnetId (), $ this ->getAddress (), $ this ->getHostname (), $ description , $ note , $ port , $ tag );
258+ $ status = $ this ->_adapter ->createAddress ($ this ->getSubnetId (), $ this ->getAddress (), $ this ->getHostname (), $ description , $ note , $ port , $ tag );
275259 }
276260 catch (E \Message $ e ) {
277261 $ this ->_errorMessage = $ e ->getMessage ();
@@ -282,10 +266,15 @@ public function create($description = '', $note = '', $port = '', $tag = self::O
282266 {
283267 $ addresses = $ this ->findIpAddresses ($ this ->getAddress (), $ this ->getSubnetId (), true );
284268
285- if ($ addresses !== false && count ($ addresses ) === 1 ) {
269+ if ($ addresses !== false && count ($ addresses ) === 1 )
270+ {
286271 $ addressId = $ addresses [0 ][self ::FIELD_ID ];
287272 $ this ->_hardReset (false );
288273 $ this ->_setObjectId ($ addressId );
274+
275+ if ($ autoRegisterToStore ) {
276+ $ this ->_registerToStore ();
277+ }
289278 }
290279 else {
291280 $ status = false ;
@@ -362,7 +351,7 @@ protected function _updateInfos($label, $description)
362351 if ($ this ->addressExists ())
363352 {
364353 try {
365- $ status = $ this ->_IPAM ->modifyAddress ($ this ->getAddressId (), $ label , $ description );
354+ $ status = $ this ->_adapter ->modifyAddress ($ this ->getAddressId (), $ label , $ description );
366355 }
367356 catch (E \Message $ e ) {
368357 $ this ->_errorMessage = $ e ->getMessage ();
@@ -385,13 +374,14 @@ public function remove()
385374 if ($ this ->addressExists ())
386375 {
387376 try {
388- $ status = $ this ->_IPAM ->removeAddress ($ this ->getAddressId ());
377+ $ status = $ this ->_adapter ->removeAddress ($ this ->getAddressId ());
389378 }
390379 catch (E \Message $ e ) {
391380 $ this ->_errorMessage = $ e ->getMessage ();
392381 $ status = false ;
393382 }
394383
384+ $ this ->_unregisterFromStore ();
395385 $ this ->_hardReset ();
396386 return $ status ;
397387 }
@@ -514,7 +504,7 @@ public function getAddresses($address = '*', $IPv = null, $strict = false)
514504 public function findAddresses ($ address , $ IPv = null , $ strict = false )
515505 {
516506 if ($ this ->hasAddressId ()) {
517- return self ::_searchAddresses ($ this ->_IPAM , $ address , $ IPv , $ this ->getSubnetId (), $ strict );
507+ return self ::_searchAddresses ($ this ->_adapter , $ address , $ IPv , $ this ->getSubnetId (), $ strict );
518508 }
519509 else {
520510 return false ;
@@ -538,14 +528,14 @@ public static function searchAddresses($address, $IPv = null, $subnetId = null,
538528 /**
539529 * Return all addresses matches request
540530 *
541- * @param Addon\Ipam\Main $IPAM IPAM connector
531+ * @param Addon\Ipam\Adapter $IPAM IPAM adapter
542532 * @param string $address Address IP or name, wildcard * is allowed
543533 * @param int $IPv IP version, 4 or 6
544534 * @param int $subnetId Subnet ID
545535 * @param bool $strict
546536 * @return false|array
547537 */
548- protected static function _searchAddresses (Main $ IPAM = null , $ address = '* ' , $ IPv = null , $ subnetId = null , $ strict = false )
538+ protected static function _searchAddresses (Adapter $ IPAM = null , $ address = '* ' , $ IPv = null , $ subnetId = null , $ strict = false )
549539 {
550540 if (Tools::isIP ($ address )) {
551541 return self ::_searchIpAddresses ($ IPAM , $ address , $ subnetId , $ strict );
@@ -564,7 +554,7 @@ protected static function _searchAddresses(Main $IPAM = null, $address = '*', $I
564554
565555 public function findIpAddresses ($ ip , $ subnetId = null , $ strict = false )
566556 {
567- return self ::_searchIpAddresses ($ this ->_IPAM , $ ip , $ subnetId , $ strict );
557+ return self ::_searchIpAddresses ($ this ->_adapter , $ ip , $ subnetId , $ strict );
568558 }
569559
570560 public static function searchIpAddresses ($ ip , $ subnetId = null , $ strict = false )
@@ -573,29 +563,29 @@ public static function searchIpAddresses($ip, $subnetId = null, $strict = false)
573563 }
574564
575565 // $strict for future use
576- protected static function _searchIpAddresses (Main $ IPAM = null , $ ip = '* ' , $ subnetId = null , $ strict = false )
566+ protected static function _searchIpAddresses (Adapter $ IPAM = null , $ ip = '* ' , $ subnetId = null , $ strict = false )
577567 {
578568 if ($ IPAM === null ) {
579- $ IPAM = self ::$ _IPAM ;
569+ $ IPAM = self ::_getAdapter () ;
580570 }
581571
582572 return $ IPAM ->searchAddressIP ($ ip , $ subnetId , $ strict );
583573 }
584574
585575 public function findAddressNames ($ name , $ IPv = null , $ subnetId = null , $ strict = false )
586576 {
587- return self ::_searchAddressNames ($ this ->_IPAM , $ name , $ IPv , $ subnetId , $ strict );
577+ return self ::_searchAddressNames ($ this ->_adapter , $ name , $ IPv , $ subnetId , $ strict );
588578 }
589579
590580 public static function searchAddressNames ($ name , $ IPv = null , $ subnetId = null , $ strict = false )
591581 {
592582 return self ::_searchAddressNames (null , $ name , $ IPv , $ subnetId , $ strict );
593583 }
594584
595- protected static function _searchAddressNames (Main $ IPAM = null , $ name = '* ' , $ IPv = null , $ subnetId = null , $ strict = false )
585+ protected static function _searchAddressNames (Adapter $ IPAM = null , $ name = '* ' , $ IPv = null , $ subnetId = null , $ strict = false )
596586 {
597587 if ($ IPAM === null ) {
598- $ IPAM = self ::$ _IPAM ;
588+ $ IPAM = self ::_getAdapter () ;
599589 }
600590
601591 if ($ name === null ) {
@@ -610,7 +600,7 @@ protected static function _searchAddressNames(Main $IPAM = null, $name = '*', $I
610600 $ separator = preg_quote (self ::SEPARATOR_SECTION , '# ' );
611601 $ status = preg_match ('#(?: ' .$ separator .'(?<section>.+?) ' .$ separator .')?(?<name>.+)#i ' , $ name , $ nameParts );
612602
613- if ($ status && C \Tools::is ('string&&!empty ' , $ nameParts ['section ' ]) && C \Tools::is ('string&&!empty ' , $ descParts ['name ' ])) {
603+ if ($ status && C \Tools::is ('string&&!empty ' , $ nameParts ['section ' ]) && C \Tools::is ('string&&!empty ' , $ nameParts ['name ' ])) {
614604 $ sectionNameFilter = $ nameParts ['section ' ];
615605 $ name = $ nameParts ['name ' ];
616606 }
@@ -624,18 +614,18 @@ protected static function _searchAddressNames(Main $IPAM = null, $name = '*', $I
624614
625615 public function findAddressDescs ($ desc , $ IPv = null , $ subnetId = null , $ strict = false )
626616 {
627- return self ::_searchAddressDescs ($ this ->_IPAM , $ desc , $ IPv , $ subnetId , $ strict );
617+ return self ::_searchAddressDescs ($ this ->_adapter , $ desc , $ IPv , $ subnetId , $ strict );
628618 }
629619
630620 public static function searchAddressDescs ($ desc , $ IPv = null , $ subnetId = null , $ strict = false )
631621 {
632622 return self ::_searchAddressDescs (null , $ desc , $ IPv , $ subnetId , $ strict );
633623 }
634624
635- protected static function _searchAddressDescs (Main $ IPAM = null , $ desc = '* ' , $ IPv = null , $ subnetId = null , $ strict = false )
625+ protected static function _searchAddressDescs (Adapter $ IPAM = null , $ desc = '* ' , $ IPv = null , $ subnetId = null , $ strict = false )
636626 {
637627 if ($ IPAM === null ) {
638- $ IPAM = self ::$ _IPAM ;
628+ $ IPAM = self ::_getAdapter () ;
639629 }
640630
641631 if ($ desc === null ) {
@@ -666,7 +656,7 @@ protected static function _filterAddressOnSectionName(array $addresses, $field,
666656 {
667657 if (C \Tools::is ('string&&!empty ' , $ sectionNameFilter ))
668658 {
669- $ sections = Api_Section::searchSections ($ nameParts [ ' section ' ] , null , true );
659+ $ sections = Api_Section::searchSections ($ sectionNameFilter , null , true );
670660
671661 if ($ sections !== false && count ($ sections ) === 1 )
672662 {
0 commit comments