Skip to content

Commit fba7de4

Browse files
author
Jean-François Hivert
committed
Version 2.1
1 parent 84a7883 commit fba7de4

27 files changed

Lines changed: 1401 additions & 1161 deletions

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ __*https://launchpad.net/~ondrej/+archive/ubuntu/php*__
2525
* apt update
2626

2727
You have to install a PHP version >= 7.1:
28-
* apt update
29-
* apt install php7.2-cli php7.2-soap php7.2-mbstring php7.2-readline php7.2-curl
30-
__Do not forget to install php7.2-soap__
28+
* apt install php7.3-cli php7.3-soap php7.3-mbstring php7.3-readline php7.3-curl
29+
__Do not forget to install php7.3-soap__
30+
31+
For MacOS users which use PHP 7.3, there is an issue with PCRE.
32+
You have to add this configuration in your php.ini:
33+
```ini
34+
pcre.jit=0
35+
```
36+
*To locate your php.ini, use this command: php -i | grep "Configuration File"*
3137

3238
#### REPOSITORIES
3339
* git clone https://github.com/cloudwatt/php-cli-shell_base
34-
* git checkout tags/v2.0
40+
* git checkout tags/v2.1
3541
* git clone https://github.com/cloudwatt/php-cli-shell_patchmanager
36-
* git checkout tags/v2.0
42+
* git checkout tags/v2.1
3743
* Merge these two repositories
3844

3945
#### CONFIGURATION FILE

addons/dcim/adapter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Addon\Dcim;
3+
4+
use Core as C;
5+
6+
abstract class Adapter extends C\Addon\Adapter
7+
{
8+
}

addons/dcim/api/abstract.php

Lines changed: 14 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,12 @@ abstract class Api_Abstract extends C\Addon\Api_Abstract
1111
const WILDCARD = '*';
1212
const SEPARATOR_PATH = ',';
1313

14-
/**
15-
* @var string
16-
*/
17-
protected static $_parentAdapter = __NAMESPACE__ .'\Main';
18-
19-
/**
20-
* @var Addon\Dcim\Main
21-
*/
22-
protected static $_DCIM = null; // Global DCIM (enabled)
23-
24-
/**
25-
* @var Addon\Dcim\Main[]
26-
*/
27-
protected static $_aDCIM = array(); // a = all/array/available DCIM
28-
29-
/**
30-
* @var Addon\Dcim\Main
31-
*/
32-
protected $_DCIM_ = null; // Local DCIM (for this instance)
33-
34-
35-
public function __construct($objectId = null)
36-
{
37-
parent::__construct($objectId);
38-
$this->_DCIM_ = &$this->_ownerAdapter; // /!\ A executer avant _setObjectId
39-
$this->_setObjectId($objectId); // @todo temp
40-
}
4114

4215
public static function objectIdIsValid($objectId)
4316
{
4417
return C\Tools::is('int&&>0', $objectId);
4518
}
4619

47-
public function hasObjectId()
48-
{
49-
return ($this->_objectId !== null);
50-
}
51-
52-
public function getObjectId()
53-
{
54-
return $this->_objectId;
55-
}
56-
5720
public function objectExists()
5821
{
5922
if($this->_objectExists !== null) {
@@ -110,8 +73,8 @@ public function getLabel()
11073
public function getTemplateName()
11174
{
11275
if($this->objectExists()) {
113-
$result = $this->_DCIM->resolvToTemplate(static::OBJECT_TYPE, $this->getObjectId());
114-
return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);
76+
$result = $this->_adapter->resolvToTemplate(static::OBJECT_TYPE, $this->getObjectId());
77+
return ($this->_adapter->isValidReturn($result)) ? ($result) : (false);
11578
}
11679
else {
11780
return false;
@@ -125,13 +88,13 @@ public function getTemplateName()
12588
*/
12689
public function getUserAttrField($category, $attribute = null)
12790
{
128-
if(!C\Tools::is('string&&!empty', $attribute)) {
91+
if(!C\Tools::is('human', $attribute)) {
12992
$attribute = $category;
13093
$category = 'default';
13194
$noCateg = true;
13295
}
13396

134-
$attrField = $this->_DCIM->getUserAttrName($category, $attribute);
97+
$attrField = $this->_adapter->getUserAttrName($category, $attribute);
13598
return ($attrField === false && isset($noCateg)) ? ($attribute) : ($attrField);
13699
}
137100

@@ -147,8 +110,8 @@ public function getUserAttribute($category, $attribute = null)
147110
$attrField = $this->getUserAttrField($category, $attribute);
148111

149112
if($attrField !== false) {
150-
$result = $this->_DCIM->getUserAttrById(static::OBJECT_TYPE, $this->getObjectId(), $attrField);
151-
return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);
113+
$result = $this->_adapter->getUserAttrById(static::OBJECT_TYPE, $this->getObjectId(), $attrField);
114+
return ($this->_adapter->isValidReturn($result)) ? ($result) : (false);
152115
}
153116
}
154117

@@ -161,39 +124,23 @@ public function __get($name)
161124
{
162125
case 'dcim':
163126
case '_DCIM': {
164-
return self::$_DCIM;
165-
}
166-
case 'id': {
167-
return $this->getObjectId();
168-
}
169-
case 'label': {
170-
return $this->getObjectLabel();
127+
return $this->_adapter;
171128
}
172129
case 'templateName': {
173130
return $this->getTemplateName();
174131
}
175132
default: {
176-
throw new Exception("This attribute '".$name."' does not exist", E_USER_ERROR);
133+
return parent::__get($name);
177134
}
178135
}
179136
}
180137

181-
public function __call($method, $parameters = null)
138+
/**
139+
* @return Addon\Dcim\Orchestrator
140+
*/
141+
protected static function _getOrchestrator()
182142
{
183-
if(substr($method, 0, 3) === 'get')
184-
{
185-
$name = substr($method, 3);
186-
$name = mb_strtolower($name);
187-
188-
switch($name)
189-
{
190-
case 'label': {
191-
return $this->getObjectLabel();
192-
}
193-
}
194-
}
195-
196-
throw new Exception("Method '".$method."' does not exist", E_USER_ERROR);
143+
return Orchestrator::getInstance();
197144
}
198145

199146
/**
@@ -239,7 +186,7 @@ protected static function _getObjectsFromReport($reportName, array $args = null,
239186
}
240187

241188
// @todo use _getReportName
242-
$results = self::$_DCIM->getReportResults(static::REPORT_NAMES[$reportName], $args);
189+
$results = static::_getAdapter()->getReportResults(static::REPORT_NAMES[$reportName], $args);
243190

244191
if(C\Tools::is('array&&count>0', $results))
245192
{
@@ -253,55 +200,4 @@ protected static function _getObjectsFromReport($reportName, array $args = null,
253200
throw new Exception("Unable to retrieve objects from report '".$reportName."'", E_USER_ERROR);
254201
}
255202
}
256-
257-
/**
258-
* @param Addon\Dcim\Main|Addon\Dcim\Main[] $DCIM
259-
* @return bool
260-
*/
261-
public static function setDcim($DCIM)
262-
{
263-
return self::setAdapter($DCIM);
264-
}
265-
266-
/**
267-
* @param Addon\Dcim\Main|Addon\Dcim\Main[] $adapter
268-
* @throw Core\Exception
269-
* @return bool
270-
*/
271-
public static function setAdapter($adapter)
272-
{
273-
$status = parent::setAdapter($adapter);
274-
275-
if($status) {
276-
self::$_DCIM = &self::$_adapter;
277-
self::$_aDCIM = &self::$_allAdapters;
278-
}
279-
280-
return $status;
281-
}
282-
283-
/**
284-
* @return null|Addon\Dcim\Main|Addon\Dcim\Main[]
285-
*/
286-
public static function getDcim()
287-
{
288-
return self::getAdapter();
289-
}
290-
291-
/**
292-
* @param string $key
293-
* @return bool
294-
*/
295-
public static function enableDcim($key)
296-
{
297-
return self::enableAdapter($key);
298-
}
299-
300-
/**
301-
* @return null|Addon\Dcim\Main
302-
*/
303-
public static function getDcimEnabled()
304-
{
305-
return self::getAdapterEnabled();
306-
}
307203
}

addons/dcim/api/abstract/location.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getLocationApi()
4141
$locationId = $this->getLocationId();
4242

4343
if($locationId !== false) {
44-
$this->_locationApi = new Api_Location($locationId);
44+
$this->_locationApi = Api_Location::factory($locationId);
4545
}
4646
else {
4747
$this->_locationApi = false;

addons/dcim/api/cabinet.php

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@ class Api_Cabinet extends Api_Abstract_Location
2323
const SIDE_FRONT = 'front';
2424
const SIDE_REAR = 'rear';
2525

26-
/**
27-
* Enable or disable cache feature
28-
* /!\ Cache must be per type
29-
*
30-
* @var array
31-
*/
32-
protected static $_cache = array(); // DCIM server ID keys, boolean value
33-
34-
/**
35-
* All cabinets (cache)
36-
* /!\ Cache must be per type
37-
*
38-
* @var array
39-
*/
40-
protected static $_objects = array(); // DCIM server ID keys, array value
41-
4226

4327
public function cabinetIdIsValid($cabinetId)
4428
{
@@ -72,7 +56,7 @@ protected function _getObject()
7256
if($this->_objectDatas === null)
7357
{
7458
$args = array('cabinetid' => $this->getCabinetId());
75-
$results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args);
59+
$results = $this->_adapter->getReportResults(self::REPORT_NAMES['self'], $args);
7660

7761
if(count($results) === 1) {
7862
$this->_objectDatas = $results[0];
@@ -102,7 +86,7 @@ public function getLocationId()
10286
{
10387
$equipmentId = current($equipmentIds);
10488
105-
$Api_Equipment = new Api_Equipment($equipmentId);
89+
$Api_Equipment = Api_Equipment::factory($equipmentId);
10690
$locationId = $Api_Equipment->getLocationId();
10791
$this->_locationId = ($locationId !== false) ? ($locationId) : (false);
10892
}
@@ -111,7 +95,7 @@ public function getLocationId()
11195
}*/
11296

11397
$args = array('cabinetid' => $this->getCabinetId());
114-
$results = self::$_DCIM->getReportResults(self::REPORT_NAMES['self'], $args);
98+
$results = self::_getAdapter()->getReportResults(self::REPORT_NAMES['self'], $args);
11599

116100
if(count($results) === 1) {
117101
$result = $results[0];
@@ -167,7 +151,7 @@ public function getPath($includeLabel = false, $pathSeparator = false)
167151
public function getEquipmentIds()
168152
{
169153
if($this->cabinetExists()) {
170-
return $this->_DCIM->getEquipmentIdsByCabinetId($this->getCabinetId());
154+
return $this->_adapter->getEquipmentIdsByCabinetId($this->getCabinetId());
171155
}
172156
else {
173157
return array();
@@ -177,8 +161,8 @@ public function getEquipmentIds()
177161
public function getEquipmentId($equipmentLabel)
178162
{
179163
if($this->cabinetExists()) {
180-
$result = $this->_DCIM->getEquipmentIdByCabinetIdEquipmentLabel($this->getCabinetId(), $equipmentLabel);
181-
return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);
164+
$result = $this->_adapter->getEquipmentIdByCabinetIdEquipmentLabel($this->getCabinetId(), $equipmentLabel);
165+
return ($this->_adapter->isValidReturn($result)) ? ($result) : (false);
182166
}
183167
else {
184168
return false;
@@ -293,7 +277,7 @@ public static function searchCabinets($cabinetLabel, $locationId = null, $recurs
293277
$reportName = 'label';
294278
}
295279

296-
$results = self::$_DCIM->getReportResults(self::REPORT_NAMES[$reportName], $args);
280+
$results = self::_getAdapter()->getReportResults(self::REPORT_NAMES[$reportName], $args);
297281

298282
if($results !== false)
299283
{
@@ -304,30 +288,9 @@ public static function searchCabinets($cabinetLabel, $locationId = null, $recurs
304288
$result['path'] = implode(self::SEPARATOR_PATH, $fullPath);
305289
$result['fullpath'] = $result['path'];
306290
}
291+
unset($result);
307292
}
308293

309294
return $results;
310295
}
311-
312-
/**
313-
* @param Addon\Dcim\Main $DCIM
314-
* @return bool
315-
*/
316-
protected static function _setObjects(C\Addon\Adapter $DCIM = null)
317-
{
318-
if($DCIM === null) {
319-
$DCIM = self::$_DCIM;
320-
}
321-
322-
$id = $DCIM->getServerId();
323-
$result = self::searchCabinets(self::WILDCARD);
324-
325-
if($result !== false) {
326-
self::$_objects[$id] = $result;
327-
return true;
328-
}
329-
else {
330-
return false;
331-
}
332-
}
333296
}

0 commit comments

Comments
 (0)