Skip to content

Commit eeb0161

Browse files
author
Jean-François Hivert
committed
Version 2.1.2
1 parent 7351e57 commit eeb0161

10 files changed

Lines changed: 247 additions & 109 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ For more information about PCRE configuration:
3939

4040
#### REPOSITORY
4141
* git clone https://github.com/cloudwatt/php-cli-shell_base
42-
* git checkout tags/v2.1.1
42+
* git checkout tags/v2.1.2
4343

4444
#### ADDON / APPLICATION
4545
*Be careful, you have to install the same version of the addon or application as base version*

cli/shell/main.php

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
abstract class Main
99
{
10+
/**
11+
* Use same version as Composer configuration
12+
*
13+
* @var string
14+
*/
1015
const PHP_MIN_VERSION = '7.1.0';
1116

1217
/**
@@ -15,45 +20,73 @@ abstract class Main
1520
protected $_CONFIG;
1621

1722
/**
18-
* @var bool
23+
* @var bool|int
1924
*/
2025
protected $_debug = false;
2126

2227
/**
23-
* @var bool
28+
* @var bool|int
2429
*/
2530
protected $_addonDebug = false;
2631

2732
/**
28-
* @var bool
33+
* @var bool|int
2934
*/
3035
protected $_applicationDebug = false;
3136

3237

33-
public function __construct($configFilename)
38+
/**
39+
* @param string|array|Core\Config $configuration
40+
* @return $this
41+
*/
42+
public function __construct($configuration)
3443
{
3544
set_error_handler(array(static::class, 'errorHandler'));
3645

37-
if(version_compare(PHP_VERSION, self::PHP_MIN_VERSION) === -1) {
46+
if(!C\Tools::isPharRunning() && version_compare(PHP_VERSION, self::PHP_MIN_VERSION) === -1) {
3847
throw new Exception("Version PHP inférieure à ".self::PHP_MIN_VERSION.", PHP ".self::PHP_MIN_VERSION." min requis", E_USER_ERROR);
3948
}
4049

4150
$this->_initDebug();
4251

43-
$this->_CONFIG = C\Config::getInstance();
44-
$this->_CONFIG->loadConfigurations($configFilename, false);
52+
if($configuration instanceof C\Config) {
53+
$this->_CONFIG = $configuration;
54+
}
55+
else {
56+
$this->_CONFIG = C\Config::getInstance();
57+
$this->_CONFIG->loadConfigurations($configuration, false);
58+
}
4559
}
4660

4761
protected function _initDebug()
4862
{
4963
$debug = getenv('PHPCLI_DEBUG');
50-
$this->_debug = (mb_strtolower($debug) === "true" || $debug === 1);
64+
$this->_setDebug($this->_debug, $debug);
5165

5266
$debug = getenv('PHPCLI_ADDON_DEBUG');
53-
$this->_addonDebug = (mb_strtolower($debug) === "true" || $debug === 1);
67+
$this->_setDebug($this->_addonDebug, $debug);
5468

5569
$debug = getenv('PHPCLI_APPLICATION_DEBUG');
56-
$this->_applicationDebug = (mb_strtolower($debug) === "true" || $debug === 1);
70+
$this->_setDebug($this->_applicationDebug, $debug);
71+
}
72+
73+
protected function _setDebug(&$attribute, $debug)
74+
{
75+
switch(mb_strtolower($debug))
76+
{
77+
case 'on':
78+
case 'yes':
79+
case 'true': {
80+
$attribute = true;
81+
break;
82+
}
83+
default:
84+
{
85+
if(C\Tools::is('int&&>0', $debug)) {
86+
$attribute = (int) $debug;
87+
}
88+
}
89+
}
5790
}
5891

5992
protected function _throwException(Exception $exception)

cli/shell/shell.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ abstract class Shell extends Main
9999
protected $_terminalDebug = false;
100100

101101

102-
public function __construct($configFilename)
102+
/**
103+
* @param string|array|Core\Config $configuration
104+
* @return $this
105+
*/
106+
public function __construct($configuration)
103107
{
104108
/**
105109
* Tant que l'on ne connait pas le mode on bufferise
@@ -118,7 +122,7 @@ public function __construct($configFilename)
118122
echo "\033[1A";
119123
}
120124

121-
parent::__construct($configFilename);
125+
parent::__construct($configuration);
122126

123127
$this->_TERMINAL = new Terminal\Terminal($this->_commands, $this->_inlineArgCmds, $this->_outlineArgCmds, $this->_manCommands);
124128
$this->_TERMINAL->debug($this->_terminalDebug)->setHistoryFilename(static::SHELL_HISTORY_FILENAME);
@@ -300,7 +304,7 @@ protected function _postLauchingShell($goodbyeMessage = true)
300304
{
301305
if($goodbyeMessage) {
302306
$this->EOL();
303-
$this->print("Merci d'avoir utilisé TOOLS-CLI by NOC", 'blue', false, 'italic');
307+
$this->print("Merci d'avoir utilisé PHPCLI by Orange / Cloudwatt", 'blue', false, 'italic');
304308
$this->EOL();
305309
}
306310
}

core/addons/api/abstract.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ abstract class Api_Abstract implements Api_Interface
1010
const WILDCARD = '*';
1111

1212
/**
13-
* @var Core\Addon\Service
13+
* @var Service
1414
*/
1515
protected $_service = null;
1616

1717
/**
18-
* @var Core\Addon\Adapter
18+
* @var Adapter
1919
*/
2020
protected $_adapter = null;
2121

@@ -47,8 +47,8 @@ abstract class Api_Abstract implements Api_Interface
4747

4848
/**
4949
* @param mixed $objectId
50-
* @param Addon\Service $service
51-
* @return Addon\Api_Abstract
50+
* @param Service $service
51+
* @return Api_Abstract
5252
*/
5353
public function __construct($objectId = null, Service $service = null)
5454
{
@@ -446,12 +446,12 @@ public static function __callStatic($name, array $arguments)
446446
}
447447

448448
/**
449-
* @return Core\Addon\Orchestrator
449+
* @return Orchestrator
450450
*/
451451
abstract protected static function _getOrchestrator();
452452

453453
/**
454-
* @return Core\Addon\Service
454+
* @return Service
455455
*/
456456
protected static function _getService()
457457
{
@@ -474,7 +474,7 @@ protected static function _getService()
474474
}
475475

476476
/**
477-
* @return Core\Addon\Service
477+
* @return Adapter
478478
*/
479479
protected static function _getAdapter()
480480
{
@@ -484,7 +484,7 @@ protected static function _getAdapter()
484484

485485
/**
486486
* @param string $type
487-
* @param Core\Addon\Adapter $adapter
487+
* @param Adapter $adapter
488488
* @return false|array
489489
*/
490490
protected function _getThisCache($type, Adapter $adapter = null)
@@ -501,7 +501,7 @@ protected function _getThisCache($type, Adapter $adapter = null)
501501

502502
/**
503503
* @param string $type
504-
* @param Core\Addon\Adapter $adapter
504+
* @param Adapter $adapter
505505
* @return false|array
506506
*/
507507
protected static function _getSelfCache($type, Adapter $adapter = null)
@@ -517,7 +517,7 @@ protected static function _getSelfCache($type, Adapter $adapter = null)
517517
}
518518

519519
/**
520-
* @param Core\Addon\Service $service
520+
* @param Service $service
521521
* @param string $type
522522
* @return false|array
523523
*/

core/autoloader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
class Autoloader
55
{
6+
const PHP_FILE_EXT = '.php';
7+
68
protected static $_replacements = array();
79

810

@@ -48,8 +50,10 @@ protected static function _prepare($class)
4850

4951
protected static function _load($class)
5052
{
51-
if(file_exists($class.'.php')) {
52-
require_once($class.'.php');
53+
$class .= static::PHP_FILE_EXT;
54+
55+
if(file_exists($class)) {
56+
require_once($class);
5357
}
5458
}
5559
}

core/network/tools.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,24 @@ public static function binToIp($ip)
201201
return (defined('AF_INET6')) ? (inet_ntop($ip)) : (false);
202202
}
203203

204-
public static function cidrMaskToNetMask($cidrMask)
204+
/**
205+
* @param int $cidrMask
206+
* @param null|int $IPv IP version 4 or 6 (magic parameter, allow null to best IP version detection)
207+
* @return false|null|string Return false if error occured, null if IPv6 detected else return net mask
208+
*/
209+
public static function cidrMaskToNetMask($cidrMask, $IPv = null)
205210
{
206-
if($cidrMask >= 0 && $cidrMask <= 32) {
207-
return long2ip(-1 << (32 - (int) $cidrMask));
211+
if($IPv !== 6)
212+
{
213+
if($cidrMask >= 0 && $cidrMask <= 32) {
214+
return long2ip(-1 << (32 - (int) $cidrMask));
215+
}
216+
else {
217+
return false;
218+
}
208219
}
209220
else {
210-
return false;
221+
return null;
211222
}
212223
}
213224

core/soap.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55

66
class Soap
77
{
8+
/**
9+
* @var string Service name
10+
*/
811
protected $_service;
12+
13+
/**
14+
* @var string Service address
15+
*/
916
protected $_server;
10-
protected $_options;
11-
protected $_handle;
1217

18+
/**
19+
* @var array
20+
*/
21+
protected $_options = array();
22+
23+
/**
24+
* @var SoapClient
25+
*/
26+
protected $_handle = null;
27+
28+
/**
29+
* @var bool
30+
*/
1331
protected $_debug = false;
1432

1533

@@ -30,19 +48,27 @@ protected function _init()
3048

3149
public function enableTrace()
3250
{
33-
$this->_options['trace'] = 1;
51+
$this->_options['trace'] = true;
3452
return $this;
3553
}
3654

3755
public function disableTrace()
3856
{
39-
$this->_options['trace'] = 0;
57+
$this->_options['trace'] = false;
4058
return $this;
4159
}
4260

4361
public function resetOpts()
4462
{
45-
$this->_options = array('trace' => 1);
63+
$this->_options = array(
64+
'trace' => true,
65+
'exceptions' => true,
66+
'keep_alive' => true,
67+
//'connection_timeout' => 5000,
68+
'cache_wsdl' => WSDL_CACHE_NONE,
69+
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE
70+
);
71+
4672
return $this;
4773
}
4874

@@ -86,8 +112,22 @@ public function __call($name, array $arguments)
86112
{
87113
$status = $this->start();
88114

89-
if($status) {
90-
return call_user_func_array(array($this->_handle, $name), $arguments);
115+
if($status)
116+
{
117+
try {
118+
return call_user_func_array(array($this->_handle, $name), $arguments);
119+
}
120+
catch(SoapFault $e)
121+
{
122+
// Uncaught SoapFault exception: [HTTP] Error Fetching http headers
123+
if(preg_match('#\[HTTP\] Error#i', $e->getMessage())) {
124+
sleep(1);
125+
return call_user_func_array(array($this->_handle, $name), $arguments);
126+
}
127+
else {
128+
throw $e;
129+
}
130+
}
91131
}
92132
else {
93133
throw new Exception("It is not possible to execute SOAP call for ".$this->_service." service", E_USER_ERROR);

0 commit comments

Comments
 (0)