Skip to content

Commit

Permalink
Merge 5c02c04 into 65e942a
Browse files Browse the repository at this point in the history
  • Loading branch information
ackintosh committed Feb 15, 2020
2 parents 65e942a + 5c02c04 commit 6bac7f4
Show file tree
Hide file tree
Showing 33 changed files with 332 additions and 235 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly

env:
Expand All @@ -23,8 +22,7 @@ services:
- mongodb

before_install:
- ./install_memcached.sh
- phpenv config-add .travis.php.ini
- ./ci/install_dependencies.sh

before_script:
- travis_retry composer self-update
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,7 @@ $ docker-compose run --rm -w /tmp/ganesha -u ganesha client vendor/bin/phpunit

## [Requirements](#table-of-contents)

- Ganesha supports PHP 5.6 or higher.
- Note: We are planning to drop the support for PHP 5.6. Please see [here](https://github.com/ackintosh/ganesha/issues/43) to track the status of the issue.
- Ganesha supports PHP 7.1 or higher.
- An extension or client library which is used by [the storage adapter](https://github.com/ackintosh/ganesha#adapters) you've choice will be required. Please check the [Adapters](https://github.com/ackintosh/ganesha#adapters) section for details.

## [Author](#table-of-contents)
Expand Down
14 changes: 14 additions & 0 deletions ci/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

php --version | cut -d ' ' -f 2 | head -n 1 | grep -e '^7\.[12]\.'
RESULT=$?

set -eu

if [ $RESULT = 0 ]; then
yes '' | pecl install memcached-3.1.5
yes '' | pecl install redis-5.1.0
yes '' | pecl install mongodb-1.6.0
else
phpenv config-add .travis.php.ini
fi
25 changes: 19 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@
"email": "sora.akatsuki@gmail.com"
}
],
"repositories": [
{
"type": "git",
"url": "https://github.com/morozov/php-vcr"
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.1.0",
"psr/http-message": "~1.0"
},
"suggest": {
"guzzlehttp/guzzle": "Allows the usage of the Guzzle Middleware"
"guzzlehttp/guzzle": "Allows the usage of the Guzzle Middleware",
"ext-redis": "Allows the usage of RedisAdapter with Redis, RedisArray and RedisCluster",
"ext-memcached": "Allows the usage of MemcachedAdapter",
"ext-mongodb": "Allows the usage of MongoDBAdapter"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27",
"php-vcr/php-vcr": "~1.0",
"php-vcr/phpunit-testlistener-vcr": "~2.0",
"phpunit/phpunit": "^7.5.19",
"symfony/yaml": "^3.0|^4.0",
"php-vcr/php-vcr": "dev-issues/289 as 1.4.5",
"php-vcr/phpunit-testlistener-vcr": "~3.2.1",
"php-coveralls/php-coveralls": "~2.0",
"predis/predis": "^1.1",
"guzzlehttp/guzzle": "~6.3"
"guzzlehttp/guzzle": "~6.5",
"ext-redis": "~5.1",
"ext-memcached": "~3.1",
"ext-mongodb": "~1.6"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 7 additions & 2 deletions examples/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
FROM php:7.2-cli
FROM php:7.4-cli

RUN apt-get update \
&& apt-get install -y git \
&& apt-get install -y libmemcached-dev \
&& apt-get install -y zlib1g-dev \
&& apt-get install -y unzip \
&& apt-get install -y libzip-dev \
&& apt-get install -y git \
&& yes '' | pecl install zip \
&& echo 'extension=zip.so' >> /usr/local/etc/php/php.ini \
&& yes '' | pecl install memcached \
&& echo 'extension=memcached.so' >> /usr/local/etc/php/php.ini \
&& yes '' | pecl install redis \
&& echo 'extension=redis.so' >> /usr/local/etc/php/php.ini \
&& yes '' | pecl install xdebug-2.6.0beta1 \
&& yes '' | pecl install xdebug-2.9.0 \
&& echo 'zend_extension=xdebug.so' >> /usr/local/etc/php/php.ini \
&& yes '' | pecl install mongodb \
&& echo 'extension=mongodb.so' >> /usr/local/etc/php/php.ini \
Expand Down
4 changes: 0 additions & 4 deletions install_memcached.sh

This file was deleted.

2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</whitelist>
</filter>
<listeners>
<listener class="PHPUnit_Util_Log_VCR" file="vendor/php-vcr/phpunit-testlistener-vcr/PHPUnit/Util/Log/VCR.php" />
<listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php" />
</listeners>
</phpunit>
21 changes: 11 additions & 10 deletions src/Ganesha.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Ackintosh;

use Ackintosh\Ganesha\Exception\StorageException;
use Ackintosh\Ganesha\StrategyInterface;

class Ganesha
{
Expand Down Expand Up @@ -33,7 +34,7 @@ class Ganesha
const STATUS_TRIPPED = 2;

/**
* @var \Ackintosh\Ganesha\StrategyInterface
* @var StrategyInterface
*/
private $strategy;

Expand All @@ -50,7 +51,7 @@ class Ganesha
/**
* Ganesha constructor.
*
* @param \Ackintosh\Ganesha\StrategyInterface $strategy
* @param StrategyInterface $strategy
*/
public function __construct($strategy)
{
Expand All @@ -63,7 +64,7 @@ public function __construct($strategy)
* @param string $service
* @return void
*/
public function failure($service)
public function failure($service): void
{
try {
if ($this->strategy->recordFailure($service) === self::STATUS_TRIPPED) {
Expand All @@ -80,7 +81,7 @@ public function failure($service)
* @param string $service
* @return void
*/
public function success($service)
public function success($service): void
{
try {
if ($this->strategy->recordSuccess($service) === self::STATUS_CALMED_DOWN) {
Expand All @@ -95,7 +96,7 @@ public function success($service)
* @param string $service
* @return bool
*/
public function isAvailable($service)
public function isAvailable($service): bool
{
if (self::$disabled) {
return true;
Expand All @@ -114,7 +115,7 @@ public function isAvailable($service)
* @param callable $callable
* @return void
*/
public function subscribe(callable $callable)
public function subscribe(callable $callable): void
{
$this->subscribers[] = $callable;
}
Expand All @@ -125,7 +126,7 @@ public function subscribe(callable $callable)
* @param string $message
* @return void
*/
private function notify($event, $service, $message)
private function notify(string $event, string $service, string $message): void
{
foreach ($this->subscribers as $s) {
call_user_func_array($s, [$event, $service, $message]);
Expand All @@ -137,7 +138,7 @@ private function notify($event, $service, $message)
*
* @return void
*/
public static function disable()
public static function disable(): void
{
self::$disabled = true;
}
Expand All @@ -147,7 +148,7 @@ public static function disable()
*
* @return void
*/
public static function enable()
public static function enable(): void
{
self::$disabled = false;
}
Expand All @@ -157,7 +158,7 @@ public static function enable()
*
* @return void
*/
public function reset()
public function reset(): void
{
$this->strategy->reset();
}
Expand Down
10 changes: 6 additions & 4 deletions src/Ganesha/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha;
use InvalidArgumentException;

class Builder
{
/**
* @param array $params
* @return Ganesha
*/
public static function build(array $params)
public static function build(array $params): Ganesha
{
$params['strategyClass'] = '\Ackintosh\Ganesha\Strategy\Rate';
return self::perform($params);
Expand All @@ -19,17 +20,18 @@ public static function build(array $params)
* @param array $params
* @return Ganesha
*/
public static function buildWithCountStrategy(array $params)
public static function buildWithCountStrategy(array $params): Ganesha
{
$params['strategyClass'] = '\Ackintosh\Ganesha\Strategy\Count';
return self::perform($params);
}

/**
* @param array $params
* @return Ganesha
* @throws \Exception
* @throws InvalidArgumentException
*/
private static function perform($params)
private static function perform(array $params): Ganesha
{
call_user_func([$params['strategyClass'], 'validate'], $params);

Expand Down
2 changes: 1 addition & 1 deletion src/Ganesha/GuzzleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
* @param callable $handler
* @return \Closure
*/
public function __invoke(callable $handler)
public function __invoke(callable $handler): \Closure
{
return function (RequestInterface $request, array $options) use ($handler) {
$serviceName = $this->serviceNameExtractor->extract($request, $options);
Expand Down

0 comments on commit 6bac7f4

Please sign in to comment.