Skip to content

Commit

Permalink
Version 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-François Hivert committed Jun 3, 2019
1 parent 84a7883 commit fba7de4
Show file tree
Hide file tree
Showing 27 changed files with 1,401 additions and 1,161 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ __*https://launchpad.net/~ondrej/+archive/ubuntu/php*__
* apt update

You have to install a PHP version >= 7.1:
* apt update
* apt install php7.2-cli php7.2-soap php7.2-mbstring php7.2-readline php7.2-curl
__Do not forget to install php7.2-soap__
* apt install php7.3-cli php7.3-soap php7.3-mbstring php7.3-readline php7.3-curl
__Do not forget to install php7.3-soap__

For MacOS users which use PHP 7.3, there is an issue with PCRE.
You have to add this configuration in your php.ini:
```ini
pcre.jit=0
```
*To locate your php.ini, use this command: php -i | grep "Configuration File"*

#### REPOSITORIES
* git clone https://github.com/cloudwatt/php-cli-shell_base
* git checkout tags/v2.0
* git checkout tags/v2.1
* git clone https://github.com/cloudwatt/php-cli-shell_patchmanager
* git checkout tags/v2.0
* git checkout tags/v2.1
* Merge these two repositories

#### CONFIGURATION FILE
Expand Down
8 changes: 8 additions & 0 deletions addons/dcim/adapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Addon\Dcim;

use Core as C;

abstract class Adapter extends C\Addon\Adapter
{
}
132 changes: 14 additions & 118 deletions addons/dcim/api/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,12 @@ abstract class Api_Abstract extends C\Addon\Api_Abstract
const WILDCARD = '*';
const SEPARATOR_PATH = ',';

/**
* @var string
*/
protected static $_parentAdapter = __NAMESPACE__ .'\Main';

/**
* @var Addon\Dcim\Main
*/
protected static $_DCIM = null; // Global DCIM (enabled)

/**
* @var Addon\Dcim\Main[]
*/
protected static $_aDCIM = array(); // a = all/array/available DCIM

/**
* @var Addon\Dcim\Main
*/
protected $_DCIM_ = null; // Local DCIM (for this instance)


public function __construct($objectId = null)
{
parent::__construct($objectId);
$this->_DCIM_ = &$this->_ownerAdapter; // /!\ A executer avant _setObjectId
$this->_setObjectId($objectId); // @todo temp
}

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

public function hasObjectId()
{
return ($this->_objectId !== null);
}

public function getObjectId()
{
return $this->_objectId;
}

public function objectExists()
{
if($this->_objectExists !== null) {
Expand Down Expand Up @@ -110,8 +73,8 @@ public function getLabel()
public function getTemplateName()
{
if($this->objectExists()) {
$result = $this->_DCIM->resolvToTemplate(static::OBJECT_TYPE, $this->getObjectId());
return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);
$result = $this->_adapter->resolvToTemplate(static::OBJECT_TYPE, $this->getObjectId());
return ($this->_adapter->isValidReturn($result)) ? ($result) : (false);
}
else {
return false;
Expand All @@ -125,13 +88,13 @@ public function getTemplateName()
*/
public function getUserAttrField($category, $attribute = null)
{
if(!C\Tools::is('string&&!empty', $attribute)) {
if(!C\Tools::is('human', $attribute)) {
$attribute = $category;
$category = 'default';
$noCateg = true;
}

$attrField = $this->_DCIM->getUserAttrName($category, $attribute);
$attrField = $this->_adapter->getUserAttrName($category, $attribute);
return ($attrField === false && isset($noCateg)) ? ($attribute) : ($attrField);
}

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

if($attrField !== false) {
$result = $this->_DCIM->getUserAttrById(static::OBJECT_TYPE, $this->getObjectId(), $attrField);
return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);
$result = $this->_adapter->getUserAttrById(static::OBJECT_TYPE, $this->getObjectId(), $attrField);
return ($this->_adapter->isValidReturn($result)) ? ($result) : (false);
}
}

Expand All @@ -161,39 +124,23 @@ public function __get($name)
{
case 'dcim':
case '_DCIM': {
return self::$_DCIM;
}
case 'id': {
return $this->getObjectId();
}
case 'label': {
return $this->getObjectLabel();
return $this->_adapter;
}
case 'templateName': {
return $this->getTemplateName();
}
default: {
throw new Exception("This attribute '".$name."' does not exist", E_USER_ERROR);
return parent::__get($name);
}
}
}

public function __call($method, $parameters = null)
/**
* @return Addon\Dcim\Orchestrator
*/
protected static function _getOrchestrator()
{
if(substr($method, 0, 3) === 'get')
{
$name = substr($method, 3);
$name = mb_strtolower($name);

switch($name)
{
case 'label': {
return $this->getObjectLabel();
}
}
}

throw new Exception("Method '".$method."' does not exist", E_USER_ERROR);
return Orchestrator::getInstance();
}

/**
Expand Down Expand Up @@ -239,7 +186,7 @@ protected static function _getObjectsFromReport($reportName, array $args = null,
}

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

if(C\Tools::is('array&&count>0', $results))
{
Expand All @@ -253,55 +200,4 @@ protected static function _getObjectsFromReport($reportName, array $args = null,
throw new Exception("Unable to retrieve objects from report '".$reportName."'", E_USER_ERROR);
}
}

/**
* @param Addon\Dcim\Main|Addon\Dcim\Main[] $DCIM
* @return bool
*/
public static function setDcim($DCIM)
{
return self::setAdapter($DCIM);
}

/**
* @param Addon\Dcim\Main|Addon\Dcim\Main[] $adapter
* @throw Core\Exception
* @return bool
*/
public static function setAdapter($adapter)
{
$status = parent::setAdapter($adapter);

if($status) {
self::$_DCIM = &self::$_adapter;
self::$_aDCIM = &self::$_allAdapters;
}

return $status;
}

/**
* @return null|Addon\Dcim\Main|Addon\Dcim\Main[]
*/
public static function getDcim()
{
return self::getAdapter();
}

/**
* @param string $key
* @return bool
*/
public static function enableDcim($key)
{
return self::enableAdapter($key);
}

/**
* @return null|Addon\Dcim\Main
*/
public static function getDcimEnabled()
{
return self::getAdapterEnabled();
}
}
2 changes: 1 addition & 1 deletion addons/dcim/api/abstract/location.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getLocationApi()
$locationId = $this->getLocationId();

if($locationId !== false) {
$this->_locationApi = new Api_Location($locationId);
$this->_locationApi = Api_Location::factory($locationId);
}
else {
$this->_locationApi = false;
Expand Down
53 changes: 8 additions & 45 deletions addons/dcim/api/cabinet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ class Api_Cabinet extends Api_Abstract_Location
const SIDE_FRONT = 'front';
const SIDE_REAR = 'rear';

/**
* Enable or disable cache feature
* /!\ Cache must be per type
*
* @var array
*/
protected static $_cache = array(); // DCIM server ID keys, boolean value

/**
* All cabinets (cache)
* /!\ Cache must be per type
*
* @var array
*/
protected static $_objects = array(); // DCIM server ID keys, array value


public function cabinetIdIsValid($cabinetId)
{
Expand Down Expand Up @@ -72,7 +56,7 @@ protected function _getObject()
if($this->_objectDatas === null)
{
$args = array('cabinetid' => $this->getCabinetId());
$results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args);
$results = $this->_adapter->getReportResults(self::REPORT_NAMES['self'], $args);

if(count($results) === 1) {
$this->_objectDatas = $results[0];
Expand Down Expand Up @@ -102,7 +86,7 @@ public function getLocationId()
{
$equipmentId = current($equipmentIds);
$Api_Equipment = new Api_Equipment($equipmentId);
$Api_Equipment = Api_Equipment::factory($equipmentId);
$locationId = $Api_Equipment->getLocationId();
$this->_locationId = ($locationId !== false) ? ($locationId) : (false);
}
Expand All @@ -111,7 +95,7 @@ public function getLocationId()
}*/

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

if(count($results) === 1) {
$result = $results[0];
Expand Down Expand Up @@ -167,7 +151,7 @@ public function getPath($includeLabel = false, $pathSeparator = false)
public function getEquipmentIds()
{
if($this->cabinetExists()) {
return $this->_DCIM->getEquipmentIdsByCabinetId($this->getCabinetId());
return $this->_adapter->getEquipmentIdsByCabinetId($this->getCabinetId());
}
else {
return array();
Expand All @@ -177,8 +161,8 @@ public function getEquipmentIds()
public function getEquipmentId($equipmentLabel)
{
if($this->cabinetExists()) {
$result = $this->_DCIM->getEquipmentIdByCabinetIdEquipmentLabel($this->getCabinetId(), $equipmentLabel);
return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);
$result = $this->_adapter->getEquipmentIdByCabinetIdEquipmentLabel($this->getCabinetId(), $equipmentLabel);
return ($this->_adapter->isValidReturn($result)) ? ($result) : (false);
}
else {
return false;
Expand Down Expand Up @@ -293,7 +277,7 @@ public static function searchCabinets($cabinetLabel, $locationId = null, $recurs
$reportName = 'label';
}

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

if($results !== false)
{
Expand All @@ -304,30 +288,9 @@ public static function searchCabinets($cabinetLabel, $locationId = null, $recurs
$result['path'] = implode(self::SEPARATOR_PATH, $fullPath);
$result['fullpath'] = $result['path'];
}
unset($result);
}

return $results;
}

/**
* @param Addon\Dcim\Main $DCIM
* @return bool
*/
protected static function _setObjects(C\Addon\Adapter $DCIM = null)
{
if($DCIM === null) {
$DCIM = self::$_DCIM;
}

$id = $DCIM->getServerId();
$result = self::searchCabinets(self::WILDCARD);

if($result !== false) {
self::$_objects[$id] = $result;
return true;
}
else {
return false;
}
}
}
Loading

0 comments on commit fba7de4

Please sign in to comment.