Skip to content

Commit fa9581c

Browse files
committed
for laminas/config and php 7.1 above
1 parent b78f04b commit fa9581c

39 files changed

+132
-56
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
language: php
22

33
php:
4-
- "5.6"
5-
- "7.0"
64
- "7.1"
75
- "7.2"
86
- "7.3"
9-
- hhvm
7+
- "7.4"
108

119
before_script:
1210
- composer install --prefer-dist --dev

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## Requirement
1010

11-
* PHP 5.6 above
11+
* PHP 7.1 above
1212
* Modern PHP
1313

1414
### About Phystrix
@@ -21,14 +21,15 @@ In case of a service failing way too often, to not make the situation worse, Phy
2121

2222
### Differences from [older version(upwork/phystrix)](https://github.com/upwork/phystrix)
2323

24-
* Use PHP 5.6 and PHP 7 above
24+
* Use PHP 7.1 above
2525
* Change from 'Zend DI' to 'PSR DI', DI is optional. (for using Your framework)
2626
* Add [phystrix dashboard](https://github.com/upwork/phystrix-dashboard) library, and fix more.
2727
* Add Libraries of APCU
28-
* PSR-2: Coding Style is default.
28+
* PSR-12: Coding Style is default.
2929
* PSR-3: Logger Interface(coming soon)
3030
* PSR-16: Common Interface for Caching Libraries
3131

32+
3233
### Understanding Phystrix
3334

3435
Not only Phystrix was heavily inspired by the amazing [Hystrix library](https://github.com/Netflix/Hystrix) for Java by Netflix, it also attempts to follow the best practices set by the library. You will notice that configuration parameters are the same as well as much of how it works internally.
@@ -41,7 +42,7 @@ Recommended way to install Phystrix is by using [Composer](https://getcomposer.o
4142

4243
```json
4344
"require": {
44-
"yupmin/modern-phystrix": "~3.0"
45+
"yupmin/modern-phystrix": "~4.0"
4546
},
4647

4748
```
@@ -96,7 +97,7 @@ Notice, the extra parameters you pass to the factory’s getCommand method are f
9697
The factory is instantiated as follows:
9798

9899
```php
99-
use Zend\Config\Config;
100+
use Laminas\Config\Config;
100101
use Odesk\Phystrix\ApcStateStorage;
101102
use Odesk\Phystrix\CircuitBreakerFactory;
102103
use Odesk\Phystrix\CommandMetricsFactory;
@@ -120,7 +121,7 @@ $phystrix = new CommandFactory(
120121
);
121122
```
122123

123-
The way you store the configuration files is up to you. Phystrix relies on [Zend\Config](https://github.com/zendframework/Component_ZendConfig) to manage configurations. In this case, __phystrix-config.php__ is a PHP array:
124+
The way you store the configuration files is up to you. Phystrix relies on [Laminas\Config](https://github.com/zendframework/Component_ZendConfig) to manage configurations. In this case, __phystrix-config.php__ is a PHP array:
124125

125126
```php
126127
return array(
@@ -188,7 +189,7 @@ Phystrix only works with the command keys. If you have two different commands wi
188189
Sometimes, you may need to change a parameter when a command is used in a particular context:
189190

190191
```php
191-
use Zend\Config\Config;
192+
use Laminas\Config\Config;
192193
$myCommand = $phystrix->getCommand('MyCommand', 'Alex');
193194
$myCommand->setConfig(new Config(array('requestCache' => array('enabled' => false))));
194195
$result = $myCommand->execute();

composer.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@
1212
}
1313
},
1414
"require": {
15-
"php": ">=5.6",
16-
"ext-json": "*",
15+
"php": ">=7.1",
1716
"psr/container": "^1.0",
18-
"zendframework/zend-config": "^3.2",
19-
"psr/simple-cache": "^1.0"
17+
"laminas/laminas-config": "^3.3"
2018
},
2119
"require-dev": {
22-
"php-di/php-di": "~5.4",
2320
"phpunit/phpunit": "~5.7",
24-
"squizlabs/php_codesniffer": "^3.4"
21+
"squizlabs/php_codesniffer": "^3.4",
22+
"php-di/php-di": "^6.0"
2523
},
2624
"extra": {
2725
"branch-alias": {
28-
"dev-master": "3.0-dev"
26+
"dev-master": "2.0-dev"
2927
}
3028
}
3129
}

library/Odesk/Phystrix/AbstractCommand.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,29 +17,30 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
use Odesk\Phystrix\Exception\BadRequestException;
2224
use Odesk\Phystrix\Exception\FallbackNotAvailableException;
2325
use Odesk\Phystrix\Exception\RuntimeException;
2426
use Psr\Container\ContainerInterface;
2527
use Psr\SimpleCache\CacheInterface;
26-
use Zend\Config\Config;
28+
use Laminas\Config\Config;
2729
use Exception;
2830

2931
/**
3032
* All Phystrix commands must extend this class
3133
*/
3234
abstract class AbstractCommand
3335
{
34-
const EVENT_SUCCESS = 'SUCCESS';
35-
const EVENT_FAILURE = 'FAILURE';
36-
const EVENT_TIMEOUT = 'TIMEOUT';
37-
const EVENT_SHORT_CIRCUITED = 'SHORT_CIRCUITED';
38-
const EVENT_FALLBACK_SUCCESS = 'FALLBACK_SUCCESS';
39-
const EVENT_FALLBACK_FAILURE = 'FALLBACK_FAILURE';
40-
const EVENT_EXCEPTION_THROWN = 'EXCEPTION_THROWN';
41-
const EVENT_RESPONSE_FROM_CACHE = 'RESPONSE_FROM_CACHE';
36+
public const EVENT_SUCCESS = 'SUCCESS';
37+
public const EVENT_FAILURE = 'FAILURE';
38+
public const EVENT_TIMEOUT = 'TIMEOUT';
39+
public const EVENT_SHORT_CIRCUITED = 'SHORT_CIRCUITED';
40+
public const EVENT_FALLBACK_SUCCESS = 'FALLBACK_SUCCESS';
41+
public const EVENT_FALLBACK_FAILURE = 'FALLBACK_FAILURE';
42+
public const EVENT_EXCEPTION_THROWN = 'EXCEPTION_THROWN';
43+
public const EVENT_RESPONSE_FROM_CACHE = 'RESPONSE_FROM_CACHE';
4244

4345
/**
4446
* Command Key, used for grouping Circuit Breakers

library/Odesk/Phystrix/ApcStateStorage.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,20 +17,21 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
/**
2224
* APC cache driven storage for Circuit Breaker metrics statistics
2325
*/
2426
class ApcStateStorage implements StateStorageInterface
2527
{
26-
const BUCKET_EXPIRE_SECONDS = 120;
28+
public const BUCKET_EXPIRE_SECONDS = 120;
2729

28-
const CACHE_PREFIX = 'phystrix_cb_';
30+
public const CACHE_PREFIX = 'phystrix_cb_';
2931

30-
const OPENED_NAME = 'opened';
32+
public const OPENED_NAME = 'opened';
3133

32-
const SINGLE_TEST_BLOCKED = 'single_test_blocked';
34+
public const SINGLE_TEST_BLOCKED = 'single_test_blocked';
3335

3436
/**
3537
* Constructor
@@ -129,7 +131,7 @@ public function allowSingleTest($commandKey, $sleepingWindowInMilliseconds)
129131
// using 'add' enforces thread safety.
130132
$sleepingWindowInSeconds = ceil($sleepingWindowInMilliseconds / 1000);
131133
// another APC limitation is that within the current request variables will never expire.
132-
return (boolean) apc_add($singleTestFlagKey, true, $sleepingWindowInSeconds);
134+
return (bool)apc_add($singleTestFlagKey, true, $sleepingWindowInSeconds);
133135
}
134136

135137
/**
@@ -141,7 +143,7 @@ public function allowSingleTest($commandKey, $sleepingWindowInMilliseconds)
141143
public function isCircuitOpen($commandKey)
142144
{
143145
$openedKey = $this->prefix($commandKey . self::OPENED_NAME);
144-
return (boolean) apc_fetch($openedKey);
146+
return (bool)apc_fetch($openedKey);
145147
}
146148

147149
/**

library/Odesk/Phystrix/ArrayStateStorage.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
/**

library/Odesk/Phystrix/CircuitBreaker.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,9 +17,10 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

21-
use Zend\Config\Config;
23+
use Laminas\Config\Config;
2224

2325
/**
2426
* Circuit-breaker logic that is hooked into AbstractCommand execution and will stop allowing executions

library/Odesk/Phystrix/CircuitBreakerFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,9 +17,10 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

21-
use Zend\Config\Config;
23+
use Laminas\Config\Config;
2224

2325
/**
2426
* Factory to keep track of and instantiate new circuit breakers when needed

library/Odesk/Phystrix/CircuitBreakerInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
/**

library/Odesk/Phystrix/CommandFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,13 +17,14 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
use Psr\SimpleCache\CacheInterface;
2224
use ReflectionClass;
2325
use ReflectionException;
2426
use Psr\Container\ContainerInterface;
25-
use Zend\Config\Config;
27+
use Laminas\Config\Config;
2628

2729
/**
2830
* All commands must be created through this factory.

library/Odesk/Phystrix/CommandMetrics.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
/**
@@ -140,8 +142,9 @@ public function getHealthCounts()
140142
// current time in milliseconds
141143
$now = microtime(true) * 1000;
142144
// we should make a new snapshot in case there isn't one yet or when the snapshot interval time has passed
143-
if (!$this->lastSnapshot
144-
|| $now - $this->lastSnapshot->getTime() >= $this->healthSnapshotIntervalInMilliseconds) {
145+
if (
146+
!$this->lastSnapshot || $now - $this->lastSnapshot->getTime() >= $this->healthSnapshotIntervalInMilliseconds
147+
) {
145148
$this->lastSnapshot = new HealthCountsSnapshot(
146149
$now,
147150
$this->getRollingCount(MetricsCounter::SUCCESS),

library/Odesk/Phystrix/CommandMetricsFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,9 +17,10 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

21-
use Zend\Config\Config;
23+
use Laminas\Config\Config;
2224

2325
/**
2426
* Factory to keep track of and instantiate new command metrics objects when needed

library/Odesk/Phystrix/Exception/ApcNotLoadedException.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix\Exception;
2022

2123
/**

library/Odesk/Phystrix/Exception/BadRequestException.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix\Exception;
2022

2123
/**

library/Odesk/Phystrix/Exception/FallbackNotAvailableException.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix\Exception;
2022

2123
/**

library/Odesk/Phystrix/Exception/RuntimeException.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix\Exception;
2022

2123
use Exception;

library/Odesk/Phystrix/HealthCountsSnapshot.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is a part of the Phystrix library
45
*
@@ -16,6 +17,7 @@
1617
* See the License for the specific language governing permissions and
1718
* limitations under the License.
1819
*/
20+
1921
namespace Odesk\Phystrix;
2022

2123
/**

0 commit comments

Comments
 (0)