From 1b5ce4cb73422b606a9c288035c423af6f6a3b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 23 Aug 2021 14:24:18 +0200 Subject: [PATCH 1/4] composer require cache/memcached-adapter --- composer.json | 4 +- composer.lock | 516 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 417 insertions(+), 103 deletions(-) diff --git a/composer.json b/composer.json index 1ff3b12..d03fd39 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,14 @@ "LDC" ], "require": { + "ext-memcached": "^3.1", "ext-curl": "^7.3", "php": "^7.3", "kwaadpepper/enum": "^2.0", "vlucas/phpdotenv": "^5.3", "guzzlehttp/guzzle": "^7.3", - "respect/validation": "^2.2" + "respect/validation": "^2.2", + "cache/memcached-adapter": "^1.1" }, "require-dev": { "phpunit/phpunit": "~9.0", diff --git a/composer.lock b/composer.lock index fa9eac2..177cf56 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,271 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ce52e2d36e04d753ed0f376f03042c7a", + "content-hash": "9be13d218529e5e1aa6290b563b1fcda", "packages": [ + { + "name": "cache/adapter-common", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-cache/adapter-common.git", + "reference": "6b87c5cbdf03be42437b595dbe5de8e97cd1d497" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-cache/adapter-common/zipball/6b87c5cbdf03be42437b595dbe5de8e97cd1d497", + "reference": "6b87c5cbdf03be42437b595dbe5de8e97cd1d497", + "shasum": "" + }, + "require": { + "cache/tag-interop": "^1.0", + "php": "^5.6 || ^7.0 || ^8.0", + "psr/cache": "^1.0", + "psr/log": "^1.0", + "psr/simple-cache": "^1.0" + }, + "require-dev": { + "cache/integration-tests": "^0.16", + "phpunit/phpunit": "^5.7.21" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Cache\\Adapter\\Common\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Scherer", + "email": "aequasi@gmail.com", + "homepage": "https://github.com/aequasi" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/nyholm" + } + ], + "description": "Common classes for PSR-6 adapters", + "homepage": "http://www.php-cache.com/en/latest/", + "keywords": [ + "cache", + "psr-6", + "tag" + ], + "support": { + "source": "https://github.com/php-cache/adapter-common/tree/1.2.0" + }, + "time": "2020-12-14T12:17:39+00:00" + }, + { + "name": "cache/hierarchical-cache", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-cache/hierarchical-cache.git", + "reference": "ba3746c65461b17154fb855068403670fd7fa2d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-cache/hierarchical-cache/zipball/ba3746c65461b17154fb855068403670fd7fa2d3", + "reference": "ba3746c65461b17154fb855068403670fd7fa2d3", + "shasum": "" + }, + "require": { + "cache/adapter-common": "^1.0", + "php": "^5.6 || ^7.0 || ^8.0", + "psr/cache": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.21" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Cache\\Hierarchy\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Scherer", + "email": "aequasi@gmail.com", + "homepage": "https://github.com/aequasi" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/nyholm" + } + ], + "description": "A helper trait and interface to your PSR-6 cache to support hierarchical keys.", + "homepage": "http://www.php-cache.com/en/latest/", + "keywords": [ + "cache", + "hierarchical", + "hierarchy", + "psr-6" + ], + "support": { + "source": "https://github.com/php-cache/hierarchical-cache/tree/1.1.0" + }, + "time": "2020-12-14T12:17:39+00:00" + }, + { + "name": "cache/memcached-adapter", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-cache/memcached-adapter.git", + "reference": "3e2105684bc2813646c2f44ce9c403020ff2145f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-cache/memcached-adapter/zipball/3e2105684bc2813646c2f44ce9c403020ff2145f", + "reference": "3e2105684bc2813646c2f44ce9c403020ff2145f", + "shasum": "" + }, + "require": { + "cache/adapter-common": "^1.0", + "cache/hierarchical-cache": "^1.0", + "php": "^5.6 || ^7.0 || ^8.0", + "psr/cache": "^1.0", + "psr/simple-cache": "^1.0" + }, + "provide": { + "psr/cache-implementation": "^1.0", + "psr/simple-cache-implementation": "^1.0" + }, + "require-dev": { + "cache/integration-tests": "^0.16", + "phpunit/phpunit": "^5.7.21" + }, + "suggest": { + "ext-memcached": "The extension required to use this pool." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Cache\\Adapter\\Memcached\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Scherer", + "email": "aequasi@gmail.com", + "homepage": "https://github.com/aequasi" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/nyholm" + } + ], + "description": "A PSR-6 cache implementation using Memcached. This implementation supports tags", + "homepage": "http://www.php-cache.com/en/latest/", + "keywords": [ + "cache", + "memcached", + "psr-6", + "tag" + ], + "support": { + "source": "https://github.com/php-cache/memcached-adapter/tree/1.1.0" + }, + "time": "2020-12-14T12:17:39+00:00" + }, + { + "name": "cache/tag-interop", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-cache/tag-interop.git", + "reference": "909a5df87e698f1665724a9e84851c11c45fbfb9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-cache/tag-interop/zipball/909a5df87e698f1665724a9e84851c11c45fbfb9", + "reference": "909a5df87e698f1665724a9e84851c11c45fbfb9", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0 || ^8.0", + "psr/cache": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Cache\\TagInterop\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/nyholm" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com", + "homepage": "https://github.com/nicolas-grekas" + } + ], + "description": "Framework interoperable interfaces for tags", + "homepage": "https://www.php-cache.com/en/latest/", + "keywords": [ + "cache", + "psr", + "psr6", + "tag" + ], + "support": { + "issues": "https://github.com/php-cache/tag-interop/issues", + "source": "https://github.com/php-cache/tag-interop/tree/1.0.1" + }, + "time": "2020-12-04T14:11:04+00:00" + }, { "name": "graham-campbell/result-type", "version": "v1.0.1", @@ -434,6 +697,55 @@ ], "time": "2020-07-20T17:29:33+00:00" }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/master" + }, + "time": "2016-08-06T20:24:11+00:00" + }, { "name": "psr/http-client", "version": "1.0.1", @@ -594,6 +906,107 @@ }, "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/master" + }, + "time": "2017-10-23T01:57:42+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", @@ -3617,107 +4030,6 @@ }, "time": "2019-01-08T18:20:26+00:00" }, - { - "name": "psr/log", - "version": "1.1.4", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" - }, - "time": "2021-05-03T11:20:27+00:00" - }, - { - "name": "psr/simple-cache", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/simple-cache.git", - "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", - "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\SimpleCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interfaces for simple caching", - "keywords": [ - "cache", - "caching", - "psr", - "psr-16", - "simple-cache" - ], - "support": { - "source": "https://github.com/php-fig/simple-cache/tree/master" - }, - "time": "2017-10-23T01:57:42+00:00" - }, { "name": "ramsey/collection", "version": "1.1.3", From 5c2738b05e9774f0c749e9778c75c158b2b10403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 23 Aug 2021 14:25:01 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Ajout=20de=20cache=20sur=20api=5Ftoken=20po?= =?UTF-8?q?ur=20partager=20la=20cl=C3=A9=20sur=20tout=20les=20process=20du?= =?UTF-8?q?=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Transport/ApiInterface.php | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/Transport/ApiInterface.php b/src/Transport/ApiInterface.php index db4f597..bd8620a 100644 --- a/src/Transport/ApiInterface.php +++ b/src/Transport/ApiInterface.php @@ -2,6 +2,7 @@ namespace LDC\LDCCRM\Transport; +use Cache\Adapter\Memcached\MemcachedCachePool; use LDC\LDCCRM\Enums\ApiError; use LDC\LDCCRM\Enums\ApiStatus; use LDC\LDCCRM\Exceptions\ApiErrorException; @@ -60,8 +61,28 @@ class ApiInterface protected static $authentification = null; + /** + * Memcached client + * + * @var \Memcached + */ + protected static $memcachedCient = null; + + /** + * Memcached Pool + * + * @var \Cache\Adapter\Memcached\MemcachedCachePool + */ + protected static $memcachedPool = null; + public function __construct(string $endpoint = null, string $bearerToken = null, string $bearerPwd = null) { + if (!static::$memcachedCient) { + static::$memcachedCient = new \Memcached(); + static::$memcachedCient->addServer('127.0.0.1', 11211); + static::$memcachedPool = new MemcachedCachePool(static::$memcachedCient); + } + static::$endpoint = static::$endpoint ?: $endpoint; static::$bearerToken = static::$bearerToken ?: $bearerToken; static::$bearerPwd = static::$bearerPwd ?: $bearerPwd; @@ -116,6 +137,7 @@ class ApiInterface } if ($response->data and isset($response->data['api_token'])) { static::$apiToken = $response->data['api_token']; + $this->storeCacheValue('api_token', static::$apiToken); } } catch (ApiErrorException $e) { if ($e->getApiError()->equals(ApiError::needAuth()) and !$request->maxAttempted()) { @@ -169,6 +191,20 @@ class ApiInterface $data = [ 'timestamp' => \time() ]; + /** + * Api Token à partir de memcached + * permet d'eviter la génération de token à répétition entre de multiples + * process php venant du client. + * En effet les variables statiques ne sont pas partagés + * entre les process eg: apache lance 8 process pour un site. + * De plus entres les requetes elles ne sont pas partagés (logiquement) + * On se retrouverai avec en permanence ds call sur login sans jamais aboutir + * car le Api token sera régénéré en permanence + */ + $apiToken = $this->readCacheValue('api_token'); + if (static::$apiToken !== $apiToken) { + static::$apiToken = $apiToken ?: null; + } if (static::$apiToken) { $data['api_token'] = static::$apiToken; } @@ -230,4 +266,50 @@ class ApiInterface } $request->setHidden($params); } + + /** + * Generate prefix by creating a md5 hash + * using LDC_LDCCRM_CLIENTv2_MD5HASH + * where MD5HASH is static::$endpoint . static::$bearerToken . static::$bearerPwd + * + * @return string + */ + private function getMemcachedPrefix(): string + { + return sprintf( + 'LDC_LDCCRM_CLIENTv2_%s', + md5(static::$endpoint . static::$bearerToken . static::$bearerPwd) + ); + } + + /** + * Set memcached value + * + * @param string $name + * @param mixed $value + * @return void + */ + public function storeCacheValue(string $name, $value): void + { + static::$memcachedPool->setDirectValue(sprintf( + '%s_%s', + $this->getMemcachedPrefix(), + $name + ), $value); + } + + /** + * Get memcached value + * + * @param string $name + * @return mixed + */ + public function readCacheValue(string $name) + { + return static::$memcachedPool->getDirectValue(sprintf( + '%s_%s', + $this->getMemcachedPrefix(), + $name + )); + } } From 537b9f2f6195beda6b6711b7cf7b5c5d92923e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 23 Aug 2021 14:27:51 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Rollback=20de=20required=20sur=20Customer?= =?UTF-8?q?=20address,=20code=20postal=20et=20ville=20(dans=20le=20cas=20o?= =?UTF-8?q?u=20sur=20le=20projet=20on=20utilise=20pas=20forc=C3=A9ment=20M?= =?UTF-8?q?esBR)=20pour=20=C3=AAtre=20conforme=20RGPD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Customer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Models/Customer.php b/src/Models/Customer.php index 98b916c..0e7d1dd 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -272,10 +272,10 @@ class Customer extends CrmClientModel 'password' => 'required|min:8|max:255|mixedCase|containDigit|containSymbol', 'birth_date' => 'required|date_format:Y-m-d', 'phone' => 'sometimes|string|min:10|max:255', - 'address' => 'required|string|max:255', + 'address' => 'sometimes|string|max:255', 'address2' => 'sometimes|string|max:255', - 'city' => 'required|string|max:255', - 'postcode' => 'required|string|max:255', + 'city' => 'sometimes|string|max:255', + 'postcode' => 'sometimes|string|max:255', 'country' => ['sometimes'], 'opt_in' => 'required|bool', 'status' => 'required|bool', From fef0c4b603762f921c331ee349d6d2ff1d57ffd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 24 Aug 2021 08:32:12 +0200 Subject: [PATCH 4/4] bump version to 2.1.1 --- apiConfig.readonly.json | 5 +++-- composer.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apiConfig.readonly.json b/apiConfig.readonly.json index 2c91a2b..2717f24 100644 --- a/apiConfig.readonly.json +++ b/apiConfig.readonly.json @@ -1,5 +1,6 @@ { - "version": "2.1.0", + "version": "2.1.1", "tokenTimeout": 60, - "apiRequestRatePerMinute": 256 + "apiRequestRatePerMinute": 256, + "servicesDBCache": 10 } \ No newline at end of file diff --git a/composer.json b/composer.json index d03fd39..537f47e 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V2", "license": "MIT", - "version": "2.1.0", + "version": "2.1.1", "authors": [ { "name": "Jérémy Munsch",