first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
drwxr-xr-x 5 30094 users 5 Oct 6 10:16 .
drwxr-xr-x 11 30094 users 13 Oct 6 10:16 ..
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 module-lib-cache-directory-provider
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 module-lib-service-container
drwxr-xr-x 4 30094 users 10 Oct 6 10:16 prestashop-accounts-installer

View File

@@ -0,0 +1,282 @@
# Created by https://www.gitignore.io/api/vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
# Edit at https://www.gitignore.io/?templates=vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
### Composer ###
/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# network security
/network-security.data
### Linux ###
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# JetBrains templates
**___jb_tmp___
### PhpStorm Patch ###
.idea
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# Workspace files are user-specific
*.sublime-workspace
# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project
# SFTP configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
### Vuejs ###
# Recommended template: Node.gitignore
node_modules/
npm-debug.log
yarn-error.log
### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
# CS Fixer
.php_cs.cache

View File

@@ -0,0 +1,8 @@
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 .
drwxr-xr-x 5 30094 users 5 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 10364 Oct 14 2021 LICENSE
-rw-r--r-- 1 30094 users 801 Oct 14 2021 README.md
-rw-r--r-- 1 30094 users 788 Oct 14 2021 composer.json
-rw-r--r-- 1 30094 users 50450 Oct 14 2021 composer.lock
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 src
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 tests

View File

@@ -0,0 +1,170 @@
Academic Free License (“AFL”) v. 3.0
This Academic Free License (the "License") applies to any original work of
authorship (the "Original Work") whose owner (the "Licensor") has placed the
following licensing notice adjacent to the copyright notice for the Original
Work:
Licensed under the Academic Free License version 3.0
1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free,
non-exclusive, sublicensable license, for the duration of the copyright, to do
the following:
a) to reproduce the Original Work in copies, either alone or as part of a
collective work;
b) to translate, adapt, alter, transform, modify, or arrange the Original
Work, thereby creating derivative works ("Derivative Works") based upon
the Original Work;
c) to distribute or communicate copies of the Original Work and
Derivative Works to the public, under any license of your choice that
does not contradict the terms and conditions, including Licensors
reserved rights and remedies, in this Academic Free License;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2) Grant of Patent License. Licensor grants You a worldwide, royalty-free,
non-exclusive, sublicensable license, under patent claims owned or controlled
by the Licensor that are embodied in the Original Work as furnished by the
Licensor, for the duration of the patents, to make, use, sell, offer for sale,
have made, and import the Original Work and Derivative Works.
3) Grant of Source Code License. The term "Source Code" means the preferred
form of the Original Work for making modifications to it and all available
documentation describing how to modify the Original Work. Licensor agrees to
provide a machine-readable copy of the Source Code of the Original Work along
with each copy of the Original Work that Licensor distributes. Licensor
reserves the right to satisfy this obligation by placing a machine-readable
copy of the Source Code in an information repository reasonably calculated to
permit inexpensive and convenient access by You for as long as Licensor
continues to distribute the Original Work.
4) Exclusions From License Grant. Neither the names of Licensor, nor the names
of any contributors to the Original Work, nor any of their trademarks or
service marks, may be used to endorse or promote products derived from this
Original Work without express prior permission of the Licensor. Except as
expressly stated herein, nothing in this License grants any license to
Licensors trademarks, copyrights, patents, trade secrets or any other
intellectual property. No patent license is granted to make, use, sell, offer
for sale, have made, or import embodiments of any patent claims other than the
licensed claims defined in Section 2. No license is granted to the trademarks
of Licensor even if such marks are included in the Original Work. Nothing in
this License shall be interpreted to prohibit Licensor from licensing under
terms different from this License any Original Work that Licensor otherwise
would have a right to license.
5) External Deployment. The term "External Deployment" means the use,
distribution, or communication of the Original Work or Derivative Works in any
way such that the Original Work or Derivative Works may be used by anyone
other than You, whether those works are distributed or communicated to those
persons or made available as an application intended for use over a network.
As an express condition for the grants of license hereunder, You must treat
any External Deployment by You of the Original Work or a Derivative Work as a
distribution under section 1(c).
6) Attribution Rights. You must retain, in the Source Code of any Derivative
Works that You create, all copyright, patent, or trademark notices from the
Source Code of the Original Work, as well as any notices of licensing and any
descriptive text identified therein as an "Attribution Notice." You must cause
the Source Code for any Derivative Works that You create to carry a prominent
Attribution Notice reasonably calculated to inform recipients that You have
modified the Original Work.
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
the copyright in and to the Original Work and the patent rights granted herein
by Licensor are owned by the Licensor or are sublicensed to You under the
terms of this License with the permission of the contributor(s) of those
copyrights and patent rights. Except as expressly stated in the immediately
preceding sentence, the Original Work is provided under this License on an "AS
IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without
limitation, the warranties of non-infringement, merchantability or fitness for
a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK
IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this
License. No license to the Original Work is granted by this License except
under this disclaimer.
8) Limitation of Liability. Under no circumstances and under no legal theory,
whether in tort (including negligence), contract, or otherwise, shall the
Licensor be liable to anyone for any indirect, special, incidental, or
consequential damages of any character arising as a result of this License or
the use of the Original Work including, without limitation, damages for loss
of goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses. This limitation of liability shall not
apply to the extent applicable law prohibits such limitation.
9) Acceptance and Termination. If, at any time, You expressly assented to this
License, that assent indicates your clear and irrevocable acceptance of this
License and all of its terms and conditions. If You distribute or communicate
copies of the Original Work or a Derivative Work, You must make a reasonable
effort under the circumstances to obtain the express assent of recipients to
the terms of this License. This License conditions your rights to undertake
the activities listed in Section 1, including your right to create Derivative
Works based upon the Original Work, and doing so without honoring these terms
and conditions is prohibited by copyright law and international treaty.
Nothing in this License is intended to affect copyright exceptions and
limitations (including “fair use” or “fair dealing”). This License shall
terminate immediately and You may no longer exercise any of the rights granted
to You by this License upon your failure to honor the conditions in Section
1(c).
10) Termination for Patent Action. This License shall terminate automatically
and You may no longer exercise any of the rights granted to You by this
License as of the date You commence an action, including a cross-claim or
counterclaim, against Licensor or any licensee alleging that the Original Work
infringes a patent. This termination provision shall not apply for an action
alleging patent infringement by combinations of the Original Work with other
software or hardware.
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this
License may be brought only in the courts of a jurisdiction wherein the
Licensor resides or in which Licensor conducts its primary business, and under
the laws of that jurisdiction excluding its conflict-of-law provisions. The
application of the United Nations Convention on Contracts for the
International Sale of Goods is expressly excluded. Any use of the Original
Work outside the scope of this License or after its termination shall be
subject to the requirements and penalties of copyright or patent law in the
appropriate jurisdiction. This section shall survive the termination of this
License.
12) Attorneys Fees. In any action to enforce the terms of this License or
seeking damages relating thereto, the prevailing party shall be entitled to
recover its costs and expenses, including, without limitation, reasonable
attorneys' fees and costs incurred in connection with such action, including
any appeal of such action. This section shall survive the termination of this
License.
13) Miscellaneous. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent necessary
to make it enforceable.
14) Definition of "You" in This License. "You" throughout this License,
whether in upper or lower case, means an individual or a legal entity
exercising rights under, and complying with all of the terms of, this License.
For legal entities, "You" includes any entity that controls, is controlled by,
or is under common control with you. For purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the direction or
management of such entity, whether by contract or otherwise, or (ii) ownership
of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
ownership of such entity.
15) Right to Use. You may use the Original Work in all ways not otherwise
restricted or conditioned by this License or by law, and Licensor promises not
to interfere with or be responsible for such uses by You.
16) Modification of This License. This License is Copyright © 2005 Lawrence
Rosen. Permission is granted to copy, distribute, or communicate this License
without modification. Nothing in this License permits You to modify this
License as applied to the Original Work or to Derivative Works. However, You
may modify the text of this License and copy, distribute or communicate your
modified version (the "Modified License") and apply it to other original works
of authorship subject to the following conditions: (i) You may not indicate in
any way that your Modified License is the "Academic Free License" or "AFL" and
you may not use those names in the name of your Modified License; (ii) You
must replace the notice specified in the first paragraph above with the notice
"Licensed under <insert your license name here>" or with a notice of your own
that is not confusingly similar to the notice in this License; and (iii) You
may not claim that your original works are open source software unless your
Modified License has been approved by Open Source Initiative (OSI) and You
comply with its license review and certification process.

View File

@@ -0,0 +1,30 @@
# PrestaShop Cache Directory Provider for Modules
This repository provides the cache directory for PrestaShop modules.
## Pre-requisites
You should install this library only on a PrestaShop environment and with PHP 5.6.0 minimum.
## Installation
```
composer require prestashop/module-lib-cache-directory-provider
```
When this project is successfully added to your dependencies, you can add the new CacheDirectoryProvider to your module and use it.
## Usage
To use this library, it's simple :
```
$cacheDirectoryProvider = new CacheDirectoryProvider(
_PS_VERSION_,
_PS_ROOT_DIR_,
_PS_MODE_DEV_
);
```
With the getPath() function, you will retrieve the cache path of your module :
```
$cacheDirectoryProvider->getPath();
```

View File

@@ -0,0 +1,34 @@
{
"name": "prestashop/module-lib-cache-directory-provider",
"description": "Cache directory provider to use on prestashop modules",
"keywords": ["prestashop", "modules", "composer", "package"],
"license": "AFL-3.0",
"authors": [
{
"name": "PrestaShop SA",
"email": "contact@prestashop.com"
}
],
"type": "project",
"config": {
"platform": {
"php": "5.6.0"
}
},
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7"
},
"autoload": {
"psr-4": {
"PrestaShop\\ModuleLibCacheDirectoryProvider\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 Cache

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 2427 Oct 14 2021 CacheDirectoryProvider.php

View File

@@ -0,0 +1,98 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\ModuleLibCacheDirectoryProvider\Cache;
/**
* Class responsible for returning cache directory path.
*/
class CacheDirectoryProvider
{
/**
* @var string PrestaShop version
*/
private $psVersion;
/**
* @var string PrestaShop path
*/
private $psPath;
/**
* @var bool PrestaShop Debug Mode
*/
private $psIsDebugMode;
/**
* @param string $psVersion
* @param string $psPath
* @param bool $psIsDebugMode
*/
public function __construct($psVersion, $psPath, $psIsDebugMode)
{
$this->psVersion = $psVersion;
$this->psPath = $psPath;
$this->psIsDebugMode = $psIsDebugMode;
}
/**
* @return string
*/
public function getPath()
{
if (defined('_PS_CACHE_DIR_')) {
return constant('_PS_CACHE_DIR_');
}
$path = '/var/cache/' . $this->getEnvName();
if (version_compare($this->psVersion, '1.7.0.0', '<')) {
$path = '/cache';
} elseif (version_compare($this->psVersion, '1.7.4.0', '<')) {
$path = '/app/cache/' . $this->getEnvName();
}
return $this->psPath . $path;
}
/**
* @return bool
*/
public function isWritable()
{
return is_writable($this->getPath());
}
/**
* @return bool
*/
public function isReadable()
{
return is_readable($this->getPath());
}
/**
* @return string
*/
private function getEnvName()
{
return $this->psIsDebugMode ? 'dev' : 'prod';
}
}

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 ..
drwxr-xr-x 3 30094 users 4 Oct 6 10:16 Unit

View File

@@ -0,0 +1,4 @@
drwxr-xr-x 3 30094 users 4 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 Cache
-rw-r--r-- 1 30094 users 180 Oct 14 2021 phpunit.xml

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 4 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 1740 Oct 14 2021 CacheDirectoryProviderTest.php

View File

@@ -0,0 +1,48 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace Tests\Unit\Cache;
use PHPUnit\Framework\TestCase;
use PrestaShop\ModuleLibCacheDirectoryProvider\Cache\CacheDirectoryProvider;
class CacheDirectoryProviderTest extends TestCase
{
public function testItIsReturnValidPathForVersionLessThan17()
{
$cacheDirectory = new CacheDirectoryProvider('1.6.1.0', __DIR__, true);
$this->assertSame(__DIR__ . '/cache', $cacheDirectory->getPath());
}
public function testItIsReturnValidPathForVersionLessThan174()
{
$cacheDirectory = new CacheDirectoryProvider('1.7.0.0', __DIR__, true);
$this->assertSame(__DIR__ . '/app/cache/dev', $cacheDirectory->getPath());
}
public function testItIsReturnValidPathForVersionGreaterThanEq174()
{
$cacheDirectory = new CacheDirectoryProvider('1.7.4.0', __DIR__, true);
$this->assertSame(__DIR__ . '/var/cache/dev', $cacheDirectory->getPath());
}
}

View File

@@ -0,0 +1,9 @@
<phpunit stopOnFailure="true"
backupGlobals="true"
>
<testsuites>
<testsuite name="Unit">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,16 @@
name-template: v$NEXT_PATCH_VERSION
tag-template: v$NEXT_PATCH_VERSION
categories:
- title: 🔨 Improvements
label: enhancement
- title: 🐛 Bug Fixes
label: bug
- title: 🚀 New Features
label: Feature
change-template: '- #$NUMBER: $TITLE by @$AUTHOR'
template: |
# Changes
$CHANGES

View File

@@ -0,0 +1,99 @@
name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 7.2|7.3|8.0|8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master
- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --config .php_cs.dist.php --diff --dry-run
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- run: composer install
working-directory: tests/Guzzle5
- run: composer install
working-directory: tests/Guzzle7
- name : Run PHPStan for Guzzle 5
run: vendor/bin/phpstan analyse -c tests/Guzzle5/phpstan.neon
- name : Run PHPStan for Guzzle 7
run: vendor/bin/phpstan analyse -c tests/Guzzle7/phpstan.neon
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- name: Run PHPUnit
run: vendor/bin/phpunit tests/unit

View File

@@ -0,0 +1 @@
/**/vendor/

View File

@@ -0,0 +1,11 @@
<?php
$config = new PrestaShop\CodingStandards\CsFixer\Config();
$config
->setUsingCache(false)
->getFinder()
->in(__DIR__)
->exclude('vendor');
return $config;

View File

@@ -0,0 +1,52 @@
# PrestaShop module library for Guzzle clients
Plug modules to the Guzzle client available on a running shop.
This library is compatible with PHP 7.2 and above.
## Installation
```
composer require prestashop/module-lib-guzzle-adapter
```
## Usage
```php
# Getting a client (Psr\Http\Client\ClientInterface)
$options = ['base_url' => 'http://some-url/'];
$client = (new Prestashop\ModuleLibGuzzleAdapter\ClientFactory())->getClient($options);
# Sending requests and receive response (Psr\Http\Message\ResponseInterface)
$response = $this->client->sendRequest(
new GuzzleHttp\Psr7\Request('POST', 'some-uri')
);
```
In this example, `base_url` is known to be a option for Guzzle 5 that has been replaced for `base_uri` on Guzzle 6+. Any of this two keys can be set, as it will be automatically modified for the other client if needed.
The automatically changed properties are:
| Guzzle 5 property | | Guzzle 7 property |
| ------------- | -- | ------------- |
| base_url | <=> | base_url |
| defaults.authorization | <=> | authorization |
| defaults.exceptions | <=> | http_errors |
| defaults.timeout | <=> | timeout |
## Why this library?
Making HTTP requests in a PrestaShop module can be done in several ways. With `file_get_contents()`, cURL or Guzzle when provided by the core.
Depending on the running version of PrestaShop, the bundled version of Guzzle can be different:
* PrestaShop 1.7: Guzzle 5
* PrestaShop 8: Guzzle 7
Having a module compatible for these two major PrestaShop versions can be tricky. The classes provided by the two Guzzle version are named the same, but their methods are different.
It is not possible for a module contributor to require its own Guzzle dependency either, because PHP cannot load different versions of a same class and he would never know which one would be loaded first.
## Implementation notes
This library reuses the idea behind [PHP-HTTP](https://docs.php-http.org), where the implementation of HTTP requests should be the same (PSR) whatever the client chosen.
The client files from [php-http/guzzle5-adapter](https://github.com/php-http/guzzle5-adapter) and [php-http/guzzle7-adapter](https://github.com/php-http/guzzle7-adapter) have been copied in this repository because these libraries both require a different version Guzzle in their dependencies to work. Requiring them together would conflict, so we duplicated the client adapters to be safe.

View File

@@ -0,0 +1,41 @@
{
"name": "prestashop/module-lib-guzzle-adapter",
"description": "Plug modules to the Guzzle client available on a running shop",
"license": "AFL-3.0",
"autoload": {
"psr-4": {
"Prestashop\\ModuleLibGuzzleAdapter\\": "src/"
}
},
"authors": [
{
"name": "PrestaShop SA",
"email": "contact@prestashop.com"
}
],
"provide": {
"php-http/client-implementation": "1.0",
"psr/http-client-implementation": "1.0"
},
"require": {
"php": "^7.2 || ^8.0",
"psr/http-client": "^1.0",
"psr/http-message": "^1.0",
"php-http/message": "^1.13",
"php-http/httplug": "^2.3",
"guzzlehttp/psr7": "^2.3.0"
},
"require-dev": {
"phpstan/phpstan": "^1.7",
"phpunit/phpunit": "^9.5",
"prestashop/php-dev-tools": "^4.2"
},
"scripts": {
"phpstan-g5": "vendor/bin/phpstan analyze -c tests/Guzzle5/phpstan.neon",
"phpstan-g7": "vendor/bin/phpstan analyze -c tests/Guzzle7/phpstan.neon",
"phpstan": [
"@phpstan-g5",
"@phpstan-g7"
]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle5\Client as Guzzle5Client;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle5\Config as Guzzle5Config;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle7\Client as Guzzle7Client;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle7\Config as Guzzle7Config;
use Psr\Http\Client\ClientInterface;
class ClientFactory
{
/**
* @var VersionDetection
*/
private $versionDetection;
/**
* @var ?ClientInterface
*/
private $client;
public function __construct(VersionDetection $versionDetection = null)
{
$this->versionDetection = $versionDetection ?: new VersionDetection();
}
/**
* @param array<string, mixed> $config
*/
public function getClient(array $config = []): ClientInterface
{
if (!$this->client) {
$this->client = $this->initClient($config);
}
return $this->client;
}
/**
* @param array<string, mixed> $config
*/
private function initClient(array $config = []): ClientInterface
{
if ($this->versionDetection->getGuzzleMajorVersionNumber() >= 7) {
return Guzzle7Client::createWithConfig(
Guzzle7Config::fixConfig($config)
);
}
return Guzzle5Client::createWithConfig(
Guzzle5Config::fixConfig($config)
);
}
public function setClient(ClientInterface $client): void
{
$this->client = $client;
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter;
interface ConfigInterface
{
/**
* When a client is created with the config of another version,
* this method makes sure the keys match.
*
* @param array<string, mixed> $config
*
* @return array<string, mixed>
*/
public static function fixConfig(array $config): array;
}

View File

@@ -0,0 +1,142 @@
<?php
namespace Prestashop\ModuleLibGuzzleAdapter\Guzzle5;
use Exception;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception as GuzzleExceptions;
use GuzzleHttp\Message\RequestInterface as GuzzleRequest;
use GuzzleHttp\Message\ResponseInterface as GuzzleResponse;
use GuzzleHttp\Psr7\Response;
use Http\Client\Exception as HttplugException;
use Psr\Http\Client\ClientInterface as ClientClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* @author GeLo <geloen.eric@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @see https://github.com/php-http/guzzle5-adapter/blob/master/src/Client.php
*/
class Client implements ClientClientInterface
{
/**
* @var ClientInterface
*/
private $client;
/**
* @param ClientInterface|null $client
*/
public function __construct(ClientInterface $client = null)
{
$this->client = $client ?: new GuzzleClient();
}
/**
* Factory method to create the Guzzle 5 adapter with custom Guzzle configuration.
* Added after duplication of adapter.
*
* @param array<string, mixed> $config
*/
public static function createWithConfig(array $config): Client
{
return new self(new GuzzleClient($config));
}
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
$guzzleRequest = $this->createRequest($request);
try {
$response = $this->client->send($guzzleRequest);
} catch (GuzzleExceptions\TransferException $e) {
throw $this->handleException($e, $request);
}
return $this->createResponse($response);
}
/**
* Converts a PSR request into a Guzzle request.
*
* @param RequestInterface $request
*
* @return GuzzleRequest
*/
private function createRequest(RequestInterface $request)
{
$options = [
'exceptions' => false,
'allow_redirects' => false,
];
$options['version'] = $request->getProtocolVersion();
$options['headers'] = $request->getHeaders();
$body = (string) $request->getBody();
$options['body'] = '' === $body ? null : $body;
return $this->client->createRequest(
$request->getMethod(),
(string) $request->getUri(),
$options
);
}
/**
* Converts a Guzzle response into a PSR response.
*
* @param GuzzleResponse $response
*
* @return ResponseInterface
*/
private function createResponse(GuzzleResponse $response)
{
$body = $response->getBody();
return new Response(
$response->getStatusCode(),
$response->getHeaders(),
isset($body) ? $body->detach() : null,
$response->getProtocolVersion()
);
}
/**
* Converts a Guzzle exception into an Httplug exception.
*
* @param GuzzleExceptions\TransferException $exception
* @param RequestInterface $request
*
* @return Exception
*/
private function handleException(GuzzleExceptions\TransferException $exception, RequestInterface $request)
{
if ($exception instanceof GuzzleExceptions\ConnectException) {
return new HttplugException\NetworkException($exception->getMessage(), $request, $exception);
}
if ($exception instanceof GuzzleExceptions\RequestException) {
// Make sure we have a response for the HttpException
if ($exception->hasResponse()) {
$psr7Response = $this->createResponse($exception->getResponse());
return new HttplugException\HttpException(
$exception->getMessage(),
$request,
$psr7Response,
$exception
);
}
return new HttplugException\RequestException($exception->getMessage(), $request, $exception);
}
return new HttplugException\TransferException($exception->getMessage(), 0, $exception);
}
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter\Guzzle5;
use Prestashop\ModuleLibGuzzleAdapter\ConfigInterface;
class Config implements ConfigInterface
{
/**
* {@inheritdoc}
*/
public static function fixConfig(array $config): array
{
if (isset($config['timeout'])) {
$config['defaults']['timeout'] = $config['timeout'];
unset($config['timeout']);
}
if (isset($config['headers'])) {
$config['defaults']['headers'] = $config['headers'];
unset($config['headers']);
}
if (isset($config['http_errors'])) {
$config['defaults']['exceptions'] = $config['http_errors'];
unset($config['http_errors']);
}
if (isset($config['base_uri'])) {
$config['base_url'] = $config['base_uri'];
unset($config['base_uri']);
}
return $config;
}
}

View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter\Guzzle7;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Utils;
use Psr\Http\Client\ClientInterface as ClientClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* HTTP Adapter for Guzzle 7.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @see https://github.com/php-http/guzzle7-adapter/blob/master/src/Client.php
*/
class Client implements ClientClientInterface
{
/**
* @var ClientInterface
*/
private $guzzle;
public function __construct(?ClientInterface $guzzle = null)
{
if (!$guzzle) {
$guzzle = self::buildClient();
}
$this->guzzle = $guzzle;
}
/**
* Factory method to create the Guzzle 7 adapter with custom Guzzle configuration.
*
* @param array<string, mixed> $config
*/
public static function createWithConfig(array $config): Client
{
return new self(self::buildClient($config));
}
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
return $this->sendAsyncRequest($request)->wait();
}
/**
* {@inheritdoc}
*/
public function sendAsyncRequest(RequestInterface $request): Promise
{
$promise = $this->guzzle->sendAsync($request);
return new Promise($promise, $request);
}
/**
* Build the Guzzle client instance.
*
* @param array<string, mixed> $config
*/
private static function buildClient(array $config = []): GuzzleClient
{
$handlerStack = new HandlerStack(Utils::chooseHandler());
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');
$config = array_merge(['handler' => $handlerStack], $config);
return new GuzzleClient($config);
}
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter\Guzzle7;
use Prestashop\ModuleLibGuzzleAdapter\ConfigInterface;
class Config implements ConfigInterface
{
/**
* {@inheritdoc}
*/
public static function fixConfig(array $config): array
{
if (isset($config['defaults'])) {
if (isset($config['defaults']['timeout'])) {
$config['timeout'] = $config['defaults']['timeout'];
}
if (isset($config['defaults']['exceptions'])) {
$config['http_errors'] = $config['defaults']['exceptions'];
}
if (isset($config['defaults']['headers'])) {
$config['headers'] = $config['defaults']['headers'];
}
unset($config['defaults']);
}
if (isset($config['base_url'])) {
$config['base_uri'] = $config['base_url'];
unset($config['base_url']);
}
return $config;
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Prestashop\ModuleLibGuzzleAdapter\Guzzle7\Exception;
use Http\Client\Exception;
final class UnexpectedValueException extends \UnexpectedValueException implements Exception
{
}

View File

@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter\Guzzle7;
use GuzzleHttp\Exception as GuzzleExceptions;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Client\Exception as HttplugException;
use Http\Promise\Promise as HttpPromise;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle7\Exception\UnexpectedValueException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Wrapper around Guzzle promises.
*
* @author Joel Wurtz <joel.wurtz@gmail.com>
*/
final class Promise implements HttpPromise
{
/**
* @var PromiseInterface
*/
private $promise;
/**
* @var string State of the promise
*/
private $state;
/**
* @var ResponseInterface
*/
private $response;
/**
* @var HttplugException
*/
private $exception;
/**
* @var RequestInterface
*/
private $request;
public function __construct(PromiseInterface $promise, RequestInterface $request)
{
$this->request = $request;
$this->state = self::PENDING;
$this->promise = $promise->then(function ($response) {
$this->response = $response;
$this->state = self::FULFILLED;
return $response;
}, function ($reason) use ($request) {
$this->state = self::REJECTED;
if ($reason instanceof HttplugException) {
$this->exception = $reason;
} elseif ($reason instanceof GuzzleExceptions\GuzzleException) {
$this->exception = $this->handleException($reason, $request);
} elseif ($reason instanceof \Throwable) {
$this->exception = new HttplugException\TransferException('Invalid exception returned from Guzzle7', 0, $reason);
} else {
$this->exception = new UnexpectedValueException('Reason returned from Guzzle7 must be an Exception');
}
throw $this->exception;
});
}
/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
return new static($this->promise->then($onFulfilled, $onRejected), $this->request);
}
/**
* {@inheritdoc}
*/
public function getState()
{
return $this->state;
}
/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
$this->promise->wait(false);
if ($unwrap) {
if (self::REJECTED == $this->getState()) {
throw $this->exception;
}
return $this->response;
}
}
/**
* Converts a Guzzle exception into an Httplug exception.
*
* @return HttplugException
*/
private function handleException(GuzzleExceptions\GuzzleException $exception, RequestInterface $request)
{
if ($exception instanceof GuzzleExceptions\ConnectException) {
return new HttplugException\NetworkException($exception->getMessage(), $exception->getRequest(), $exception);
}
if ($exception instanceof GuzzleExceptions\RequestException) {
// Make sure we have a response for the HttpException
if ($exception->hasResponse()) {
return new HttplugException\HttpException(
$exception->getMessage(),
$exception->getRequest(),
$exception->getResponse(),
$exception
);
}
return new HttplugException\RequestException($exception->getMessage(), $exception->getRequest(), $exception);
}
return new HttplugException\TransferException($exception->getMessage(), 0, $exception);
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Prestashop\ModuleLibGuzzleAdapter;
class VersionDetection
{
public function getGuzzleMajorVersionNumber(): ?int
{
// Guzzle 7 and above
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
// @phpstan-ignore-next-line
return (int) \GuzzleHttp\ClientInterface::MAJOR_VERSION;
}
// Before Guzzle 7
if (defined('\GuzzleHttp\ClientInterface::VERSION')) {
// @phpstan-ignore-next-line
return (int) \GuzzleHttp\ClientInterface::VERSION[0];
}
return null;
}
}

View File

@@ -0,0 +1,5 @@
{
"require-dev": {
"guzzlehttp/guzzle": "^5.3.4"
}
}

View File

@@ -0,0 +1,263 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "05f2fd0a83b63c86dda2ebc0cf422d8f",
"packages": [],
"packages-dev": [
{
"name": "guzzlehttp/guzzle",
"version": "5.3.4",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "b87eda7a7162f95574032da17e9323c9899cb6b2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/b87eda7a7162f95574032da17e9323c9899cb6b2",
"reference": "b87eda7a7162f95574032da17e9323c9899cb6b2",
"shasum": ""
},
"require": {
"guzzlehttp/ringphp": "^1.1",
"php": ">=5.4.0",
"react/promise": "^2.2"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/5.3"
},
"time": "2019-10-30T09:32:00+00:00"
},
{
"name": "guzzlehttp/ringphp",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/RingPHP.git",
"reference": "5e2a174052995663dd68e6b5ad838afd47dd615b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/RingPHP/zipball/5e2a174052995663dd68e6b5ad838afd47dd615b",
"reference": "5e2a174052995663dd68e6b5ad838afd47dd615b",
"shasum": ""
},
"require": {
"guzzlehttp/streams": "~3.0",
"php": ">=5.4.0",
"react/promise": "~2.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0"
},
"suggest": {
"ext-curl": "Guzzle will use specific adapters if cURL is present"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Ring\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.",
"support": {
"issues": "https://github.com/guzzle/RingPHP/issues",
"source": "https://github.com/guzzle/RingPHP/tree/1.1.1"
},
"abandoned": true,
"time": "2018-07-31T13:22:33+00:00"
},
{
"name": "guzzlehttp/streams",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/streams.git",
"reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
"reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Stream\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Provides a simple abstraction over streams of data",
"homepage": "http://guzzlephp.org/",
"keywords": [
"Guzzle",
"stream"
],
"support": {
"issues": "https://github.com/guzzle/streams/issues",
"source": "https://github.com/guzzle/streams/tree/master"
},
"abandoned": true,
"time": "2014-10-12T19:18:40+00:00"
},
{
"name": "react/promise",
"version": "v2.9.0",
"source": {
"type": "git",
"url": "https://github.com/reactphp/promise.git",
"reference": "234f8fd1023c9158e2314fa9d7d0e6a83db42910"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/reactphp/promise/zipball/234f8fd1023c9158e2314fa9d7d0e6a83db42910",
"reference": "234f8fd1023c9158e2314fa9d7d0e6a83db42910",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.36"
},
"type": "library",
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"React\\Promise\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jan Sorgalla",
"email": "jsorgalla@gmail.com",
"homepage": "https://sorgalla.com/"
},
{
"name": "Christian Lück",
"email": "christian@clue.engineering",
"homepage": "https://clue.engineering/"
},
{
"name": "Cees-Jan Kiewiet",
"email": "reactphp@ceesjankiewiet.nl",
"homepage": "https://wyrihaximus.net/"
},
{
"name": "Chris Boden",
"email": "cboden@gmail.com",
"homepage": "https://cboden.dev/"
}
],
"description": "A lightweight implementation of CommonJS Promises/A for PHP",
"keywords": [
"promise",
"promises"
],
"support": {
"issues": "https://github.com/reactphp/promise/issues",
"source": "https://github.com/reactphp/promise/tree/v2.9.0"
},
"funding": [
{
"url": "https://github.com/WyriHaximus",
"type": "github"
},
{
"url": "https://github.com/clue",
"type": "github"
}
],
"time": "2022-02-11T10:27:51+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View File

@@ -0,0 +1,10 @@
parameters:
paths:
- ../../src
excludePaths:
- ../../src/Guzzle7
bootstrapFiles:
- vendor/autoload.php
reportUnmatchedIgnoredErrors: false
level: 6

View File

@@ -0,0 +1,5 @@
{
"require-dev": {
"guzzlehttp/guzzle": "^7.4.3"
}
}

View File

@@ -0,0 +1,613 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d1b7d93a3aac7b26318ff1548d8c54ff",
"packages": [],
"packages-dev": [
{
"name": "guzzlehttp/guzzle",
"version": "7.4.4",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8",
"reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^1.5",
"guzzlehttp/psr7": "^1.8.3 || ^2.1",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"ext-curl": "*",
"php-http/client-integration-tests": "^3.0",
"phpunit/phpunit": "^8.5.5 || ^9.3.5",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"suggest": {
"ext-curl": "Required for CURL handler support",
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "7.4-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Jeremy Lindblom",
"email": "jeremeamia@gmail.com",
"homepage": "https://github.com/jeremeamia"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle is a PHP HTTP client library",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"psr-18",
"psr-7",
"rest",
"web service"
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.4.4"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
"type": "tidelift"
}
],
"time": "2022-06-09T21:39:15+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
"reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.4 || ^5.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/1.5.1"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
"type": "tidelift"
}
],
"time": "2021-10-22T20:56:57+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "83260bb50b8fc753c72d14dc1621a2dac31877ee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/83260bb50b8fc753c72d14dc1621a2dac31877ee",
"reference": "83260bb50b8fc753c72d14dc1621a2dac31877ee",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"ralouphie/getallheaders": "^3.0"
},
"provide": {
"psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"http-interop/http-factory-tests": "^0.9",
"phpunit/phpunit": "^8.5.8 || ^9.3.10"
},
"suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://sagikazarmark.hu"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"psr-7",
"request",
"response",
"stream",
"uri",
"url"
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.3.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
"type": "tidelift"
}
],
"time": "2022-06-09T08:26:02+00:00"
},
{
"name": "psr/http-client",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-client.git",
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"psr/http-message": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP clients",
"homepage": "https://github.com/php-fig/http-client",
"keywords": [
"http",
"http-client",
"psr",
"psr-18"
],
"support": {
"source": "https://github.com/php-fig/http-client/tree/master"
},
"time": "2020-06-29T06:28:15+00:00"
},
{
"name": "psr/http-factory",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-factory.git",
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
"shasum": ""
},
"require": {
"php": ">=7.0.0",
"psr/http-message": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interfaces for PSR-7 HTTP message factories",
"keywords": [
"factory",
"http",
"message",
"psr",
"psr-17",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-factory/tree/master"
},
"time": "2019-04-30T12:38:16+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-message/tree/master"
},
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/ralouphie/getallheaders.git",
"reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
"reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5 || ^6.5"
},
"type": "library",
"autoload": {
"files": [
"src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ralph Khattar",
"email": "ralph.khattar@gmail.com"
}
],
"description": "A polyfill for getallheaders.",
"support": {
"issues": "https://github.com/ralouphie/getallheaders/issues",
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
},
"time": "2019-03-08T08:55:37+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "v2.5.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66",
"reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-01-02T09:53:40+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View File

@@ -0,0 +1,10 @@
parameters:
paths:
- ../../src
excludePaths:
- ../../src/Guzzle5
bootstrapFiles:
- vendor/autoload.php
reportUnmatchedIgnoredErrors: false
level: 6

View File

@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle5\Config;
class Guzzle5ConfigTest extends TestCase
{
public function testConfigWithoutChangeNeeded()
{
$originalConfig = [
'base_url' => 'http://some-url',
'verify' => 'path/to/cert',
'defaults' => [
'timeout' => 10,
],
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals($originalConfig, $actualConfig);
}
public function testAllConfigKeys()
{
$originalConfig = [
'base_uri' => 'http://some-url',
'verify' => 'path/to/cert',
'timeout' => 10,
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'base_url' => 'http://some-url',
'verify' => 'path/to/cert',
'defaults' => [
'timeout' => 10,
],
], $actualConfig);
}
public function testBaseUri()
{
$originalConfig = [
'base_uri' => 'http://some-url',
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'base_url' => 'http://some-url',
], $actualConfig);
}
public function testTimeout()
{
$originalConfig = [
'timeout' => 10,
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'defaults' => [
'timeout' => 10,
],
], $actualConfig);
}
public function testExceptions()
{
$originalConfig = [
'http_errors' => true,
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'defaults' => [
'exceptions' => true,
],
], $actualConfig);
}
public function testAuthorization()
{
$originalConfig = [
'headers' => [
'Authorization' => 'Bearer someMegaToken',
],
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'defaults' => [
'headers' => [
'Authorization' => 'Bearer someMegaToken',
],
],
], $actualConfig);
}
}

View File

@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Prestashop\ModuleLibGuzzleAdapter\Guzzle7\Config;
class Guzzle7ConfigTest extends TestCase
{
public function testConfigWithoutChangeNeeded()
{
$originalConfig = [
'base_uri' => 'http://some-url',
'verify' => 'path/to/cert',
'timeout' => 10,
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals($originalConfig, $actualConfig);
}
public function testAllConfigKeys()
{
$originalConfig = [
'base_url' => 'http://some-url',
'verify' => 'path/to/cert',
'defaults' => [
'timeout' => 10,
],
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'base_uri' => 'http://some-url',
'verify' => 'path/to/cert',
'timeout' => 10,
], $actualConfig);
}
public function testBaseUri()
{
$originalConfig = [
'base_url' => 'http://some-url',
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'base_uri' => 'http://some-url',
], $actualConfig);
}
public function testTimeout()
{
$originalConfig = [
'defaults' => [
'timeout' => 10,
],
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'timeout' => 10,
], $actualConfig);
}
public function testExceptions()
{
$originalConfig = [
'defaults' => [
'exceptions' => true,
],
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'http_errors' => true,
], $actualConfig);
}
public function testAuthorization()
{
$originalConfig = [
'defaults' => [
'headers' => [
'Authorization' => 'Bearer someMegaToken',
],
],
];
$actualConfig = Config::fixConfig($originalConfig);
$this->assertEquals([
'headers' => [
'Authorization' => 'Bearer someMegaToken',
],
], $actualConfig);
}
}

View File

@@ -0,0 +1,16 @@
name-template: v$NEXT_PATCH_VERSION
tag-template: v$NEXT_PATCH_VERSION
categories:
- title: 🔨 Improvements
label: enhancement
- title: 🐛 Bug Fixes
label: bug
- title: 🚀 New Features
label: Feature
change-template: '- #$NUMBER: $TITLE by @$AUTHOR'
template: |
# Changes
$CHANGES

View File

@@ -0,0 +1,78 @@
name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|7.3|8.0|8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master
- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master
- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- run: composer install
working-directory: tests/Symfony3
- run: composer install
working-directory: tests/Symfony4
- name : Run PHPStan for Symfony 3
run: composer run phpstan-sf3
- name : Run PHPStan for Symfony 4
run: composer run phpstan-sf4
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- name: Run PHPUnit
run: vendor/bin/phpunit tests/Unit

View File

@@ -0,0 +1,282 @@
# Created by https://www.gitignore.io/api/vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
# Edit at https://www.gitignore.io/?templates=vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
### Composer ###
/**/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# network security
/network-security.data
### Linux ###
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# JetBrains templates
**___jb_tmp___
### PhpStorm Patch ###
.idea
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# Workspace files are user-specific
*.sublime-workspace
# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project
# SFTP configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
### Vuejs ###
# Recommended template: Node.gitignore
node_modules/
npm-debug.log
yarn-error.log
### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
# CS Fixer
.php_cs.cache

View File

@@ -0,0 +1,8 @@
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 .
drwxr-xr-x 5 30094 users 5 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 10364 Oct 14 2021 LICENSE
-rw-r--r-- 1 30094 users 1887 Oct 14 2021 README.md
-rw-r--r-- 1 30094 users 995 Oct 14 2021 composer.json
-rw-r--r-- 1 30094 users 74315 Oct 14 2021 composer.lock
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 src
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 tests

View File

@@ -0,0 +1,170 @@
Academic Free License (“AFL”) v. 3.0
This Academic Free License (the "License") applies to any original work of
authorship (the "Original Work") whose owner (the "Licensor") has placed the
following licensing notice adjacent to the copyright notice for the Original
Work:
Licensed under the Academic Free License version 3.0
1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free,
non-exclusive, sublicensable license, for the duration of the copyright, to do
the following:
a) to reproduce the Original Work in copies, either alone or as part of a
collective work;
b) to translate, adapt, alter, transform, modify, or arrange the Original
Work, thereby creating derivative works ("Derivative Works") based upon
the Original Work;
c) to distribute or communicate copies of the Original Work and
Derivative Works to the public, under any license of your choice that
does not contradict the terms and conditions, including Licensors
reserved rights and remedies, in this Academic Free License;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2) Grant of Patent License. Licensor grants You a worldwide, royalty-free,
non-exclusive, sublicensable license, under patent claims owned or controlled
by the Licensor that are embodied in the Original Work as furnished by the
Licensor, for the duration of the patents, to make, use, sell, offer for sale,
have made, and import the Original Work and Derivative Works.
3) Grant of Source Code License. The term "Source Code" means the preferred
form of the Original Work for making modifications to it and all available
documentation describing how to modify the Original Work. Licensor agrees to
provide a machine-readable copy of the Source Code of the Original Work along
with each copy of the Original Work that Licensor distributes. Licensor
reserves the right to satisfy this obligation by placing a machine-readable
copy of the Source Code in an information repository reasonably calculated to
permit inexpensive and convenient access by You for as long as Licensor
continues to distribute the Original Work.
4) Exclusions From License Grant. Neither the names of Licensor, nor the names
of any contributors to the Original Work, nor any of their trademarks or
service marks, may be used to endorse or promote products derived from this
Original Work without express prior permission of the Licensor. Except as
expressly stated herein, nothing in this License grants any license to
Licensors trademarks, copyrights, patents, trade secrets or any other
intellectual property. No patent license is granted to make, use, sell, offer
for sale, have made, or import embodiments of any patent claims other than the
licensed claims defined in Section 2. No license is granted to the trademarks
of Licensor even if such marks are included in the Original Work. Nothing in
this License shall be interpreted to prohibit Licensor from licensing under
terms different from this License any Original Work that Licensor otherwise
would have a right to license.
5) External Deployment. The term "External Deployment" means the use,
distribution, or communication of the Original Work or Derivative Works in any
way such that the Original Work or Derivative Works may be used by anyone
other than You, whether those works are distributed or communicated to those
persons or made available as an application intended for use over a network.
As an express condition for the grants of license hereunder, You must treat
any External Deployment by You of the Original Work or a Derivative Work as a
distribution under section 1(c).
6) Attribution Rights. You must retain, in the Source Code of any Derivative
Works that You create, all copyright, patent, or trademark notices from the
Source Code of the Original Work, as well as any notices of licensing and any
descriptive text identified therein as an "Attribution Notice." You must cause
the Source Code for any Derivative Works that You create to carry a prominent
Attribution Notice reasonably calculated to inform recipients that You have
modified the Original Work.
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
the copyright in and to the Original Work and the patent rights granted herein
by Licensor are owned by the Licensor or are sublicensed to You under the
terms of this License with the permission of the contributor(s) of those
copyrights and patent rights. Except as expressly stated in the immediately
preceding sentence, the Original Work is provided under this License on an "AS
IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without
limitation, the warranties of non-infringement, merchantability or fitness for
a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK
IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this
License. No license to the Original Work is granted by this License except
under this disclaimer.
8) Limitation of Liability. Under no circumstances and under no legal theory,
whether in tort (including negligence), contract, or otherwise, shall the
Licensor be liable to anyone for any indirect, special, incidental, or
consequential damages of any character arising as a result of this License or
the use of the Original Work including, without limitation, damages for loss
of goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses. This limitation of liability shall not
apply to the extent applicable law prohibits such limitation.
9) Acceptance and Termination. If, at any time, You expressly assented to this
License, that assent indicates your clear and irrevocable acceptance of this
License and all of its terms and conditions. If You distribute or communicate
copies of the Original Work or a Derivative Work, You must make a reasonable
effort under the circumstances to obtain the express assent of recipients to
the terms of this License. This License conditions your rights to undertake
the activities listed in Section 1, including your right to create Derivative
Works based upon the Original Work, and doing so without honoring these terms
and conditions is prohibited by copyright law and international treaty.
Nothing in this License is intended to affect copyright exceptions and
limitations (including “fair use” or “fair dealing”). This License shall
terminate immediately and You may no longer exercise any of the rights granted
to You by this License upon your failure to honor the conditions in Section
1(c).
10) Termination for Patent Action. This License shall terminate automatically
and You may no longer exercise any of the rights granted to You by this
License as of the date You commence an action, including a cross-claim or
counterclaim, against Licensor or any licensee alleging that the Original Work
infringes a patent. This termination provision shall not apply for an action
alleging patent infringement by combinations of the Original Work with other
software or hardware.
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this
License may be brought only in the courts of a jurisdiction wherein the
Licensor resides or in which Licensor conducts its primary business, and under
the laws of that jurisdiction excluding its conflict-of-law provisions. The
application of the United Nations Convention on Contracts for the
International Sale of Goods is expressly excluded. Any use of the Original
Work outside the scope of this License or after its termination shall be
subject to the requirements and penalties of copyright or patent law in the
appropriate jurisdiction. This section shall survive the termination of this
License.
12) Attorneys Fees. In any action to enforce the terms of this License or
seeking damages relating thereto, the prevailing party shall be entitled to
recover its costs and expenses, including, without limitation, reasonable
attorneys' fees and costs incurred in connection with such action, including
any appeal of such action. This section shall survive the termination of this
License.
13) Miscellaneous. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent necessary
to make it enforceable.
14) Definition of "You" in This License. "You" throughout this License,
whether in upper or lower case, means an individual or a legal entity
exercising rights under, and complying with all of the terms of, this License.
For legal entities, "You" includes any entity that controls, is controlled by,
or is under common control with you. For purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the direction or
management of such entity, whether by contract or otherwise, or (ii) ownership
of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
ownership of such entity.
15) Right to Use. You may use the Original Work in all ways not otherwise
restricted or conditioned by this License or by law, and Licensor promises not
to interfere with or be responsible for such uses by You.
16) Modification of This License. This License is Copyright © 2005 Lawrence
Rosen. Permission is granted to copy, distribute, or communicate this License
without modification. Nothing in this License permits You to modify this
License as applied to the Original Work or to Derivative Works. However, You
may modify the text of this License and copy, distribute or communicate your
modified version (the "Modified License") and apply it to other original works
of authorship subject to the following conditions: (i) You may not indicate in
any way that your Modified License is the "Academic Free License" or "AFL" and
you may not use those names in the name of your Modified License; (ii) You
must replace the notice specified in the first paragraph above with the notice
"Licensed under <insert your license name here>" or with a notice of your own
that is not confusingly similar to the notice in this License; and (iii) You
may not claim that your original works are open source software unless your
Modified License has been approved by Open Source Initiative (OSI) and You
comply with its license review and certification process.

View File

@@ -0,0 +1,67 @@
# PrestaShop Service Container for Modules
This repository includes the service container from Symfony that you can use in your PrestaShop Module.
## Pre-requisites
You should install this library only on a PrestaShop environment and with PHP 5.6.0 minimum.
## Installation
```bash
# PrestaShop 1.7+
composer require prestashop/module-lib-service-container
# PrestaShop 1.6
composer require prestashop/module-lib-service-container
composer require symfony/config:^3.4 symfony/dependency-injection:^3.4 symfony/expression-language:^3.4 symfony/yaml:^3.4
```
When this project is successfully added to your dependencies, you can add the new ServiceContainer to your module and use it.
PrestaShop runs with Symfony components from version 1.7, so dependancies are not required anymore here. I you plan to run your module on PrestaShop, Symfony dependencies must be required separately.
## Usage
To use this library, it's simple :
- First, declare your new service Container in your root module PHP file (like mymodule.php at your root project folder) :
```
/**
* @var ServiceContainer
*/
private $serviceContainer;
```
- And instantiate it in the constructor with the module name and its local path :
```
$this->serviceContainer = new ServiceContainer($this->name, $this->getLocalPath());
```
- You can add a new function on your root module PHP file, like getService, to retrieve your service name in the new service container :
```
/**
* @param string $serviceName
*
* @return mixed
*/
public function getService($serviceName)
{
return $this->serviceContainer->getService($serviceName);
}
```
- Then, you have to declare your service in the services.yml file. You must declare your services in the config/ folder. From Symfony 4, services must be explicitely declared as public to be loaded with the method `getService()`;
We split the services in two folders in the config : /front and /admin folders. So the tree should be like :
```
/mymodule
/config
/front
services.yml
/admin
services.yml
common.yml
```
- Of course, you can include a common file, with common services that are use in front and admin project by an import in the services.yml file :
```
imports:
- { resource: ../common.yml }
```
Now you can add your services in the services.yml like you were in a Symfony project ;)

View File

@@ -0,0 +1,49 @@
{
"name": "prestashop/module-lib-service-container",
"description": "Service container to use on prestashop modules",
"keywords": ["prestashop", "modules", "composer", "package"],
"license": "AFL-3.0",
"authors": [
{
"name": "PrestaShop SA",
"email": "contact@prestashop.com"
}
],
"type": "library",
"config": {
"platform": {
"php": "5.6.0"
}
},
"require": {
"php": ">=5.6.0",
"prestashop/module-lib-cache-directory-provider": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7"
},
"suggest": {
"symfony/config": "Needed when the running PrestaShop does not already run with Symfony",
"symfony/dependency-injection": "Needed when the running PrestaShop does not already run with Symfony",
"symfony/expression-language": "Needed when the running PrestaShop does not already run with Symfony",
"symfony/yaml": "Needed when the running PrestaShop does not already run with Symfony"
},
"autoload": {
"psr-4": {
"PrestaShop\\ModuleLibServiceContainer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"phpstan-sf3": "tests/Symfony3/vendor/bin/phpstan analyze -c tests/Symfony3/phpstan.neon",
"phpstan-sf4": "tests/Symfony4/vendor/bin/phpstan analyze -c tests/Symfony4/phpstan.neon",
"phpstan": [
"@phpstan-sf3",
"@phpstan-sf4"
]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 4 Oct 6 10:16 DependencyInjection

View File

@@ -0,0 +1,4 @@
drwxr-xr-x 2 30094 users 4 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 3281 Oct 14 2021 ContainerProvider.php
-rw-r--r-- 1 30094 users 2328 Oct 14 2021 ServiceContainer.php

View File

@@ -0,0 +1,100 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\ModuleLibServiceContainer\DependencyInjection;
use PrestaShop\ModuleLibCacheDirectoryProvider\Cache\CacheDirectoryProvider;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class ContainerProvider
{
/**
* @var string Module Name
*/
private $moduleName;
/**
* @var string Module Local Path
*/
private $moduleLocalPath;
/**
* @var CacheDirectoryProvider
*/
private $cacheDirectory;
/**
* @param string $moduleName
* @param string $moduleLocalPath
* @param CacheDirectoryProvider $cacheDirectory
*/
public function __construct($moduleName, $moduleLocalPath, CacheDirectoryProvider $cacheDirectory)
{
$this->moduleName = $moduleName;
$this->moduleLocalPath = $moduleLocalPath;
$this->cacheDirectory = $cacheDirectory;
}
/**
* @param string $containerName
*
* @return ContainerInterface
*/
public function get($containerName)
{
$containerClassName = ucfirst($this->moduleName)
. ucfirst($containerName)
. 'Container'
;
$containerFilePath = $this->cacheDirectory->getPath() . '/' . $containerClassName . '.php';
$containerConfigCache = new ConfigCache($containerFilePath, constant('_PS_MODE_DEV_'));
if ($containerConfigCache->isFresh()) {
require_once $containerFilePath;
return new $containerClassName();
}
$containerBuilder = new ContainerBuilder();
$containerBuilder->set(
$this->moduleName . '.cache.directory',
$this->cacheDirectory
);
$moduleConfigPath = $this->moduleLocalPath
. 'config/'
. $containerName
;
$loader = new YamlFileLoader($containerBuilder, new FileLocator($moduleConfigPath));
$loader->load('services.yml');
$containerBuilder->compile();
$dumper = new PhpDumper($containerBuilder);
$containerConfigCache->write(
$dumper->dump(['class' => $containerClassName]),
$containerBuilder->getResources()
);
return $containerBuilder;
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\ModuleLibServiceContainer\DependencyInjection;
use PrestaShop\ModuleLibCacheDirectoryProvider\Cache\CacheDirectoryProvider;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ServiceContainer
{
/**
* @var string Module Name
*/
private $moduleName;
/**
* @var string Module Local Path
*/
private $moduleLocalPath;
/**
* @var ContainerInterface
*/
private $container;
/**
* @param string $moduleName
* @param string $moduleLocalPath
*/
public function __construct($moduleName, $moduleLocalPath)
{
$this->moduleName = $moduleName;
$this->moduleLocalPath = $moduleLocalPath;
}
/**
* @param string $serviceName
*
* @return object|null
*/
public function getService($serviceName)
{
if (null === $this->container) {
$this->initContainer();
}
return $this->container->get($serviceName);
}
/**
* Instantiate a new ContainerProvider
*
* @return void
*/
private function initContainer()
{
$cacheDirectory = new CacheDirectoryProvider(
constant('_PS_VERSION_'),
constant('_PS_ROOT_DIR_'),
constant('_PS_MODE_DEV_')
);
$containerProvider = new ContainerProvider($this->moduleName, $this->moduleLocalPath, $cacheDirectory);
$this->container = $containerProvider->get(defined('_PS_ADMIN_DIR_') || defined('PS_INSTALLATION_IN_PROGRESS') || PHP_SAPI === 'cli' ? 'admin' : 'front');
}
}

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 8 Oct 6 10:16 ..
drwxr-xr-x 3 30094 users 4 Oct 6 10:16 Unit

View File

@@ -0,0 +1,9 @@
{
"require-dev": {
"phpstan/phpstan": "^1.7",
"symfony/config": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/expression-language": "^3.4",
"symfony/yaml": "^3.4"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
parameters:
paths:
- ../../src
excludePaths:
- ../../src/Symfony4
bootstrapFiles:
- vendor/autoload.php
- ../../vendor/autoload.php
reportUnmatchedIgnoredErrors: false
dynamicConstantNames:
- _PS_VERSION_
- _PS_ROOT_DIR_
- _PS_MODE_DEV_
level: 6

View File

@@ -0,0 +1,9 @@
{
"require-dev": {
"phpstan/phpstan": "^1.7",
"symfony/config": "^4.4",
"symfony/dependency-injection": "^4.4",
"symfony/expression-language": "^4.4",
"symfony/yaml": "^4.4"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
parameters:
paths:
- ../../src
excludePaths:
- ../../src/Symfony3
bootstrapFiles:
- vendor/autoload.php
- ../../vendor/autoload.php
reportUnmatchedIgnoredErrors: false
dynamicConstantNames:
- _PS_VERSION_
- _PS_ROOT_DIR_
- _PS_MODE_DEV_
level: 6

View File

@@ -0,0 +1,4 @@
drwxr-xr-x 3 30094 users 4 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 4 Oct 6 10:16 DependencyInjection
-rw-r--r-- 1 30094 users 180 Oct 14 2021 phpunit.xml

View File

@@ -0,0 +1,4 @@
drwxr-xr-x 2 30094 users 4 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 4 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 1464 Oct 14 2021 ContainerProviderTest.php
-rw-r--r-- 1 30094 users 1229 Oct 14 2021 ServiceContainerTest.php

View File

@@ -0,0 +1,36 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace Tests\Unit\DependencyInjection;
use PHPUnit\Framework\TestCase;
use PrestaShop\ModuleLibCacheDirectoryProvider\Cache\CacheDirectoryProvider;
use PrestaShop\ModuleLibServiceContainer\DependencyInjection\ContainerProvider;
class ContainerProviderTest extends TestCase
{
public function testItIsReturnValidInstance()
{
/** @var CacheDirectoryProvider $cacheDirectory */
$cacheDirectory = $this->createMock(CacheDirectoryProvider::class);
$containerProvider = new ContainerProvider('test', __DIR__, $cacheDirectory);
$this->assertInstanceOf(ContainerProvider::class, $containerProvider);
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace Tests\Unit\DependencyInjection;
use PHPUnit\Framework\TestCase;
use PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer;
class ServiceContainerTest extends TestCase
{
public function testItIsReturnValidInstance()
{
$serviceContainer = new ServiceContainer('test', __DIR__);
$this->assertInstanceOf(ServiceContainer::class, $serviceContainer);
}
}

View File

@@ -0,0 +1,9 @@
<phpunit stopOnFailure="true"
backupGlobals="true"
>
<testsuites>
<testsuite name="Unit">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,91 @@
name: PsAccountsInstaller Quality Control PHP
on: [push]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|7.3
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.0.0
- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master
- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
- name: PHP syntax checker 7.3
uses: prestashop/github-action-php-lint/7.3@master
php-cs-fixer:
name: PHP-CS-FIXER
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.0.0
- name: Run PHP-CS-Fixer
uses: prestashopcorp/github-action-php-cs-fixer@master
phpstan:
name: PHPSTAN
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: ['latest', '1.7.0.3', '1.6.1.21','1.6.1.0']
steps:
- name: Checkout
uses: actions/checkout@v2.0.0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Cache vendor folder
uses: actions/cache@v1
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-composer-cache
- name: git clone ps_accounts
run: |
git clone https://${{ secrets.ACCESS_TOKEN }}@github.com/PrestaShopCorp/ps_accounts.git ~/ps_accounts
cd ~/ps_accounts
- name: composer install
run: composer install && cd ~/ps_accounts && composer install
- name: Pull PrestaShop files (Tag ${{ matrix.presta-versions }})
run: docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:${{ matrix.presta-versions }}
- name: Select .neon file to run with PHPStan
id: neon
run: |
PS_VERSION=$(docker exec temp-ps bash -c 'echo "$PS_VERSION"')
[[ "${PS_VERSION:0:3}" != '1.7' ]] && echo ::set-output name=filename::phpstan-PS-1.6.neon || echo ::set-output name=filename::phpstan-PS-1.7.neon
- name : Run PHPStan
run: docker run --rm --volumes-from temp-ps -v $PWD:/web/module -v ~/ps_accounts:/web/ps_accounts -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module phpstan/phpstan:0.12 analyse --configuration=/web/module/tests/phpstan/${{steps.neon.outputs.filename}}
phpunit:
name: PHPUNIT
runs-on: ubuntu-latest
steps:
- name: checkout project
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: composer install missing files
run: composer install
- name: PHPUnit tests
run: composer test

View File

@@ -0,0 +1,7 @@
### IDE ###
.idea
### composer ###
vendor
composer-dev.json
composer-dev.lock

View File

@@ -0,0 +1,10 @@
drwxr-xr-x 4 30094 users 10 Oct 6 10:16 .
drwxr-xr-x 5 30094 users 5 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 203 Oct 14 2021 .php_cs.dist
-rw-r--r-- 1 30094 users 1071 Oct 14 2021 LICENSE
-rw-r--r-- 1 30094 users 2420 Oct 14 2021 README.md
-rw-r--r-- 1 30094 users 812 Oct 14 2021 composer.json
-rw-r--r-- 1 30094 users 113939 Oct 14 2021 composer.lock
-rw-r--r-- 1 30094 users 310 Oct 14 2021 phpunit.xml
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 src
drwxr-xr-x 4 30094 users 6 Oct 6 10:16 tests

View File

@@ -0,0 +1,12 @@
<?php
$config = new PrestaShop\CodingStandards\CsFixer\Config();
$config
->setUsingCache(false)
->getFinder()
->in(__DIR__)
->exclude('vendor')
->exclude('tests');
return $config;

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 PrestaShopCorp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,90 @@
# prestashop-accounts-installer
Utility package to install `ps_accounts` module or present data to trigger manual install from psx configuration page.
This module also give you access to `ps_accounts` services through its module service container dealing with the installation status of the module.
## Installation
This package is available on [Packagist](https://packagist.org/packages/prestashop/prestashop-accounts-installer),
you can install it via [Composer](https://getcomposer.org).
```shell script
composer require prestashop/prestashop-accounts-installer
```
## Register as a service in your PSx container (recommended)
Example :
```yaml
services:
ps_accounts.installer:
class: 'PrestaShop\PsAccountsInstaller\Installer\Installer'
arguments:
- '4.0.0'
ps_accounts.facade:
class: 'PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts'
arguments:
- '@ps_accounts.installer'
```
## How to use it
### Installer
In your module main class `install` method. (Will only do something on PrestaShop 1.7 and above)
```php
$this->getService('ps_accounts.installer')->install();
```
### Presenter
For example in your main module's class `getContent` method.
```php
Media::addJsDef([
'contextPsAccounts' => $this->getService('ps_accounts.facade')
->getPsAccountsPresenter()
->present($this->name),
]);
```
This presenter will serve as default minimal presenter and switch to PsAccountsPresenter data when `ps_accounts` module is installed.
### Accessing PsAccounts Services
Installer class includes accessors to get instances of services from PsAccounts Module :
* getPsAccountsService
* getPsBillingService
The methods above will throw an exception in case `ps_accounts` module is not installed.
Example :
```php
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleVersionException;
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException;
try {
$psAccountsService = $this->getService('ps_accounts.facade')->getPsAccountsService();
$shopJwt = $psAccountsService->getOrRefreshToken();
$shopUuid = $psAccountsService->getShopUuidV4();
$apiUrl = $psAccountsService->getAdminAjaxUrl();
// Your code here
} catch (ModuleNotInstalledException $e) {
// You handle exception here
} catch (ModuleVersionException $e) {
// You handle exception here
}
```

View File

@@ -0,0 +1,28 @@
{
"name": "prestashop/prestashop-accounts-installer",
"type": "library",
"description": "Utility package to install `ps_accounts` module or present data to trigger manual install from psx configuration page.",
"license": "MIT",
"autoload": {
"psr-4": {
"PrestaShop\\PsAccountsInstaller\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PrestaShop\\PsAccountsInstaller\\Tests\\": "tests/"
}
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"prestashop/php-dev-tools": "3.*",
"friendsofphp/php-cs-fixer": "^2.16",
"fzaninotto/faker": "^1.9"
},
"scripts": {
"test": "./vendor/phpunit/phpunit/phpunit --configuration './phpunit.xml' --bootstrap './tests/bootstrap.php' --test-suffix 'Test.php,.phpt'"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php" colors="true" stopOnFailure="false">
<testsuites>
<testsuite name="prestashop-accounts-installer tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 10 Oct 6 10:16 ..
drwxr-xr-x 5 30094 users 6 Oct 6 10:16 Installer

View File

@@ -0,0 +1,6 @@
drwxr-xr-x 5 30094 users 6 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 5 Oct 6 10:16 Exception
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 Facade
-rw-r--r-- 1 30094 users 5384 Oct 14 2021 Installer.php
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 Presenter

View File

@@ -0,0 +1,5 @@
drwxr-xr-x 2 30094 users 5 Oct 6 10:16 .
drwxr-xr-x 5 30094 users 6 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 118 Oct 14 2021 InstallerException.php
-rw-r--r-- 1 30094 users 135 Oct 14 2021 ModuleNotInstalledException.php
-rw-r--r-- 1 30094 users 130 Oct 14 2021 ModuleVersionException.php

View File

@@ -0,0 +1,7 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Installer\Exception;
class InstallerException extends \Exception
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Installer\Exception;
class ModuleNotInstalledException extends InstallerException
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Installer\Exception;
class ModuleVersionException extends InstallerException
{
}

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 5 30094 users 6 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 2673 Oct 14 2021 PsAccounts.php

View File

@@ -0,0 +1,93 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Installer\Facade;
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException;
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleVersionException;
use PrestaShop\PsAccountsInstaller\Installer\Installer;
use PrestaShop\PsAccountsInstaller\Installer\Presenter\InstallerPresenter;
class PsAccounts
{
/**
* Available services class names
*/
const PS_ACCOUNTS_PRESENTER = 'PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter';
const PS_ACCOUNTS_SERVICE = 'PrestaShop\Module\PsAccounts\Service\PsAccountsService';
const PS_BILLING_SERVICE = 'PrestaShop\Module\PsAccounts\Service\PsBillingService';
/**
* @var Installer
*/
private $installer;
/**
* PsAccounts constructor.
*
* @param Installer $installer
*/
public function __construct(Installer $installer)
{
$this->installer = $installer;
}
/**
* @param string $serviceName
*
* @return mixed
*
* @throws ModuleNotInstalledException
* @throws ModuleVersionException
*/
public function getService($serviceName)
{
if ($this->installer->isModuleInstalled()) {
if ($this->installer->checkModuleVersion()) {
return \Module::getInstanceByName($this->installer->getModuleName())
->getService($serviceName);
}
throw new ModuleVersionException('Module version expected : ' . $this->installer->getModuleVersion());
}
throw new ModuleNotInstalledException('Module not installed : ' . $this->installer->getModuleName());
}
/**
* @return mixed
*
* @throws ModuleNotInstalledException
* @throws ModuleVersionException
*/
public function getPsAccountsService()
{
return $this->getService(self::PS_ACCOUNTS_SERVICE);
}
/**
* @return mixed
*
* @throws ModuleNotInstalledException
* @throws ModuleVersionException
*/
public function getPsBillingService()
{
return $this->getService(self::PS_BILLING_SERVICE);
}
/**
* @return mixed
*
* @throws ModuleNotInstalledException
* @throws ModuleVersionException
*/
public function getPsAccountsPresenter()
{
if ($this->installer->isModuleInstalled() &&
$this->installer->checkModuleVersion() &&
$this->installer->isModuleEnabled()
) {
return $this->getService(self::PS_ACCOUNTS_PRESENTER);
} else {
return new InstallerPresenter($this->installer);
}
}
}

View File

@@ -0,0 +1,234 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Installer;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
class Installer
{
const PS_ACCOUNTS_MODULE_NAME = 'ps_accounts';
/**
* @var string required version
*/
private $moduleVersion;
/**
* @var string
*/
private $moduleName = self::PS_ACCOUNTS_MODULE_NAME;
/**
* @var \Link
*/
private $link;
/**
* @var mixed
*/
private $moduleManager;
/**
* Installer constructor.
*
* @param string $psAccountsVersion
* @param \Link|null $link
*/
public function __construct($psAccountsVersion, \Link $link = null)
{
$this->moduleVersion = $psAccountsVersion;
if (null === $link) {
$link = new \Link();
}
$this->link = $link;
if (true === $this->isShopVersion17()) {
$moduleManagerBuilder = ModuleManagerBuilder::getInstance();
$this->moduleManager = $moduleManagerBuilder->build();
}
}
/**
* Install ps_accounts module if not installed
* Method to call in every psx modules during the installation process
*
* @return bool
*
* @throws \Exception
*/
public function install()
{
if (true === $this->isModuleInstalled()) {
return true;
}
if (false === $this->isShopVersion17()) {
return true;
}
return $this->moduleManager->install($this->getModuleName());
}
/**
* @return bool
*/
public function isModuleInstalled()
{
if (false === $this->isShopVersion17()) {
return \Module::isInstalled($this->getModuleName());
}
return $this->moduleManager->isInstalled($this->getModuleName());
}
/**
* @return bool
*/
public function isModuleEnabled()
{
if (false === $this->isShopVersion17()) {
return \Module::isEnabled($this->getModuleName());
}
return $this->moduleManager->isEnabled($this->getModuleName());
}
/**
* @return string | null
*
* @throws \PrestaShopException
*/
public function getInstallLink()
{
if ($this->isShopVersion17()) {
$router = SymfonyContainer::getInstance()->get('router');
return \Tools::getHttpHost(true) . $router->generate('admin_module_manage_action', [
'action' => 'install',
'module_name' => $this->moduleName,
]);
}
return $this->getAdminLink('AdminModules', true, [], [
'module_name' => $this->moduleName,
'install' => $this->moduleName,
]);
}
/**
* @return string | null
*
* @throws \PrestaShopException
*/
public function getEnableLink()
{
if ($this->isShopVersion17()) {
$router = SymfonyContainer::getInstance()->get('router');
return \Tools::getHttpHost(true) . $router->generate('admin_module_manage_action', [
'action' => 'enable',
'module_name' => $this->moduleName,
]);
}
return $this->getAdminLink('AdminModules', true, [], [
'module_name' => $this->moduleName,
'enable' => 1,
]);
}
/**
* @return string | null
*
* @throws \PrestaShopException
*/
public function getUpgradeLink()
{
if ($this->isShopVersion17()) {
$router = SymfonyContainer::getInstance()->get('router');
return \Tools::getHttpHost(true) . $router->generate('admin_module_manage_action', [
'action' => 'upgrade',
'module_name' => $this->moduleName,
]);
}
return $this->getAdminLink('AdminModules', true, [], [
'module_name' => $this->moduleName,
'upgrade' => $this->moduleName,
]);
}
/**
* @return bool
*/
public function isShopVersion17()
{
return version_compare(_PS_VERSION_, '1.7.0.0', '>=');
}
/**
* @return bool
*/
public function checkModuleVersion()
{
$module = \Module::getInstanceByName($this->getModuleName());
if ($module instanceof \Ps_accounts) {
return version_compare(
$module->version,
$this->moduleVersion,
'>='
);
}
return false;
}
/**
* @return string
*/
public function getModuleVersion()
{
return $this->moduleVersion;
}
/**
* @return string
*/
public function getModuleName()
{
return $this->moduleName;
}
/**
* Adapter for getAdminLink from prestashop link class
*
* @param string $controller controller name
* @param bool $withToken include or not the token in the url
* @param array $sfRouteParams
* @param array $params
*
* @return string
*
* @throws \PrestaShopException
*/
protected function getAdminLink($controller, $withToken = true, $sfRouteParams = [], $params = [])
{
if ($this->isShopVersion17()) {
return $this->link->getAdminLink($controller, $withToken, $sfRouteParams, $params);
}
$paramsAsString = '';
foreach ($params as $key => $value) {
$paramsAsString .= "&$key=$value";
}
return \Tools::getShopDomainSsl(true)
. __PS_BASE_URI__
. basename(_PS_ADMIN_DIR_)
. '/' . $this->link->getAdminLink($controller, $withToken)
. $paramsAsString;
}
}

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 5 30094 users 6 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 1926 Oct 14 2021 InstallerPresenter.php

View File

@@ -0,0 +1,75 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Installer\Presenter;
use PrestaShop\PsAccountsInstaller\Installer\Installer;
class InstallerPresenter
{
/**
* @var Installer
*/
private $installer;
/**
* @var \Context
*/
private $context;
/**
* InstallerPresenter constructor.
*
* @param Installer $installer
* @param \Context|null $context
*/
public function __construct(Installer $installer, \Context $context = null)
{
$this->installer = $installer;
if (null === $context) {
$context = \Context::getContext();
}
$this->context = $context;
}
/**
* @return array
*
* @throws \Exception
*/
public function present()
{
// Fallback minimal Presenter
return [
'psIs17' => $this->installer->isShopVersion17(),
'psAccountsInstallLink' => $this->installer->getInstallLink(),
'psAccountsEnableLink' => $this->installer->getEnableLink(),
'psAccountsUpdateLink' => $this->installer->getUpgradeLink(),
'psAccountsIsInstalled' => $this->installer->isModuleInstalled(),
'psAccountsIsEnabled' => $this->installer->isModuleEnabled(),
'psAccountsIsUptodate' => $this->installer->checkModuleVersion(),
'onboardingLink' => null,
'user' => [
'email' => null,
'emailIsValidated' => false,
'isSuperAdmin' => $this->isEmployeeSuperAdmin(),
],
'currentShop' => null,
'shops' => [],
'superAdminEmail' => null,
'ssoResendVerificationEmail' => null,
'manageAccountLink' => null,
];
}
/**
* @return bool
*/
public function isEmployeeSuperAdmin()
{
return $this->context->employee->isSuperAdmin();
}
}

View File

@@ -0,0 +1,6 @@
drwxr-xr-x 4 30094 users 6 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 10 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 345 Oct 14 2021 TestCase.php
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 Unit
-rw-r--r-- 1 30094 users 102 Oct 14 2021 bootstrap.php
drwxr-xr-x 2 30094 users 4 Oct 6 10:16 phpstan

View File

@@ -0,0 +1,23 @@
<?php
namespace PrestaShop\PsAccountsInstaller\Tests;
use Faker\Generator;
class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* @var Generator
*/
public $faker;
/**
* @return void
*/
protected function setUp()
{
parent::setUp();
$this->faker = \Faker\Factory::create();
}
}

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 6 Oct 6 10:16 ..
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 Installer

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 Presenter

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 InstallerPresenter

View File

@@ -0,0 +1,3 @@
drwxr-xr-x 2 30094 users 3 Oct 6 10:16 .
drwxr-xr-x 3 30094 users 3 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 3263 Oct 14 2021 PresentTest.php

View File

@@ -0,0 +1,86 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\PsAccountsInstaller\Tests\Unit\Installer\Presenter\InstallerPresenter;
use PrestaShop\PsAccountsInstaller\Installer\Installer;
use PrestaShop\PsAccountsInstaller\Installer\Presenter\InstallerPresenter;
use PrestaShop\PsAccountsInstaller\Tests\TestCase;
class PresentTest extends TestCase
{
/**
* @test
*
* @throws \Exception
*/
public function itShouldBeCompliantWithPsAccountsPresenter()
{
$expected = [
'psIs17' => $this->faker->boolean,
'psAccountsInstallLink' => $this->faker->url,
'psAccountsEnableLink' => $this->faker->url,
'psAccountsUpdateLink' => $this->faker->url,
'psAccountsIsInstalled' => $this->faker->boolean,
'psAccountsIsEnabled' => $this->faker->boolean,
'psAccountsIsUptodate' => $this->faker->boolean,
'onboardingLink' => null,
'user' => [
'email' => null,
'emailIsValidated' => false,
'isSuperAdmin' => true,
],
'currentShop' => null,
'shops' => [],
'superAdminEmail' => null,
'ssoResendVerificationEmail' => null,
'manageAccountLink' => null,
];
$installer = $this->createConfiguredMock(Installer::class, [
'isShopVersion17' => $expected['psIs17'],
'isModuleInstalled' => $expected['psAccountsIsInstalled'],
'getInstallLink' => $expected['psAccountsInstallLink'],
'isModuleEnabled' => $expected['psAccountsIsEnabled'],
'getEnableLink' => $expected['psAccountsEnableLink'],
'checkModuleVersion' => $expected['psAccountsIsUptodate'],
'getUpgradeLink' => $expected['psAccountsUpdateLink'],
]);
$presenter = $this->getMockBuilder(InstallerPresenter::class)
//->disableOriginalConstructor()
->setConstructorArgs([$installer, new \Context()])
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
->setMethods([
'isEmployeeSuperAdmin',
])
->getMock();
$presenter->method('isEmployeeSuperAdmin')
->willReturn(true);
/** @var InstallerPresenter $presenter */
$presenterData = $presenter->present();
$this->assertArraySubset($expected, $presenterData);
}
}

View File

@@ -0,0 +1,6 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
// Empty shell for mocking
class Context {}

View File

@@ -0,0 +1,4 @@
drwxr-xr-x 2 30094 users 4 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 6 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 1629 Oct 14 2021 phpstan-PS-1.6.neon
-rw-r--r-- 1 30094 users 977 Oct 14 2021 phpstan-PS-1.7.neon

View File

@@ -0,0 +1,27 @@
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
parameters:
autoload_files:
- /web/ps_accounts/vendor/autoload.php
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
paths:
- ../../src
dynamicConstantNames:
- _PS_VERSION_
ignoreErrors:
- '#Result of \|\| is always false.#'
- '#Strict comparison using === between false and string will always evaluate to false.#'
- '#Access to an undefined property Language::\$locale.#'
- '#Call to static method getInstance\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\SymfonyContainer.#'
- '#Call to static method getInstance\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Addon\\Module\\ModuleManagerBuilder.#'
- '#Call to method get\(\) on an unknown class Symfony\\Component\\DependencyInjection\\ContainerInterface.#'
- '#Property PrestaShop\\AccountsAuth\\Service\\PsAccountsService::\$container has unknown class Symfony\\Component\\DependencyInjection\\ContainerInterface as its type.#'
- '#Property PrestaShop\\AccountsAuth\\Service\\PsBillingService::\$container has unknown class Symfony\\Component\\DependencyInjection\\ContainerInterface as its type.#'
- '#Method LinkCore::getAdminLink\(\) invoked with 4 parameters, 1-2 required.#'
- '#Cannot call method getService\(\) on Module\|false.#'
- '#Class PrestaShop\\Module\\PsAccounts\\Presenter\\PsAccountsPresenter not found.#'
- '#Call to method get\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\SymfonyContainer.#'
- '#Call to an undefined method object::generate\(\).#'
level: 7

View File

@@ -0,0 +1,22 @@
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
parameters:
autoload_files:
- /web/ps_accounts/vendor/autoload.php
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
paths:
- ../../src
dynamicConstantNames:
- _PS_VERSION_
ignoreErrors:
- '#Result of \|\| is always false.#'
- '#Strict comparison using === between false and string will always evaluate to false.#'
- '#Call to static method getInstance\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\SymfonyContainer.#'
- '#Method LinkCore::getAdminLink\(\) invoked with 4 parameters, 1-2 required.#'
- '#Cannot call method getService\(\) on Module\|false.#'
- '#Class PrestaShop\\Module\\PsAccounts\\Presenter\\PsAccountsPresenter not found.#'
- '#Call to method get\(\) on an unknown class PrestaShop\\PrestaShop\\Adapter\\SymfonyContainer.#'
- '#Call to an undefined method object::generate\(\).#'
level: 7