diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7eaf90c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab +indent_size = 4 + +[*.{txt,md}] +trim_trailing_whitespace = false + +[{*.txt}] +end_of_line = crlf + +[{*.json}] +indent_style = space +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8a7f78e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Directories +/.git export-ignore + +# Files +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/composer.lock export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f3be40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Directories +/.vscode +/report +/vendor + +# Files +.DS_Store +Thumbs.db diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..7459eb6 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,5 @@ +{ + "ul-indent": { "indent": 4 }, + "line-length": false, + "no-hard-tabs": false +} diff --git a/README.md b/README.md new file mode 100755 index 0000000..5f068bd --- /dev/null +++ b/README.md @@ -0,0 +1,169 @@ +# AutoWPOptions + +Allows to manage a set of options in WordPress. + +Requires **php 5.4** and **WordPress 4.4**. + +## What you will be able to do + +* Decide if your set of options is network-wide or site-wide in a multisite environment, +* Obviously, get/set/delete values, +* Provide default and reset values, +* Cast, sanitize, and validate values automatically, +* Create an upgrade process. + +## How to install + +With composer: + +```json +"require": { + "screenfeed/autowpoptions": "*" +}, +``` + +## How to use + +Create one class that extends *Sanitization\AbstractSanitization*. +This class will contain the following: + +### Default values + +**Required**. They are used when an option has no value yet. Their type is used to decide how to cast the values. + +### Reset values + +**Optional**. Reset values are used if the whole set of options does not exist yet: sometimes you may want them to be different from the default values. Default values are used for the missing reset values. +You could also use them in a "Reset Options" process for example. + +### A sanitization method + +**Required**. It is run for each option, when getting/updating it. + +### A validation method + +**Required** (but can simply return the entry if not needed). It is run once for all options on update. It allows to edit some values, depending on others for example. + +### Two keywords as class properties + +**Required**. They are used in hook names. + +### Example + +How to create an option that is stored as an array in the WordPress' options table: + +* The option name is `myplugin_settings`, +* The current plugin version is `2.3`, +* The option must be network-wide on a multisite install. + +```php +use Screenfeed\AutoWPOptions\Storage\WpOption; +use Screenfeed\AutoWPOptions\Options; + +$option_name = 'myplugin_settings'; +$network_wide = true; +$plugin_version = '2.3'; + +$options_sanitization = new MyOptionsSanitization( $plugin_version ); +$options_storage = new WpOption( $option_name, $network_wide ); +$options = new Options( $options_storage, $options_sanitization ); + +$foobar = $options->get( 'foobar' ); // Returns an array of positive integers. +``` + +The `MyOptionsSanitization` class: + +* The two keywords `myplugin` and `settings` are used in hook names, like the filter `get_myplugin_settings_foobar`. + +```php +use Screenfeed\AutoWPOptions\Sanitization\AbstractSanitization; + +class OptionSanitization extends AbstractSanitization { + + /** + * Prefix used in hook names. + * + * @var string + */ + protected $prefix = 'myplugin'; + + /** + * Suffix used in hook names. + * + * @var string + */ + protected $identifier = 'settings'; + + /** + * The default values. + * These are the "zero state" values. + * Don't use null as value. + * + * @var array + */ + protected $default_values = [ + 'foobar' => [], + 'barbaz' => 0, + ]; + + /** + * Sanitizes and validates an option value. Basic casts have been made. + * + * @param string $key The option key. + * @param mixed $value The value. + * @param mixed $default The default value. + * @return mixed + */ + protected function sanitize_and_validate_value( $key, $value, $default ) { + switch ( $key ) { + case 'foobar': + return is_array( $value ) ? array_unique( array_map( 'absint', $value ) ) : []; + case 'barbaz': + return absint( $value ); + } + + return false; + } + + /** + * Validates all options before storing them. Basic sanitization and validation have been made, row by row. + * + * @param array $values The option value. + * @return array + */ + protected function validate_values_on_update( array $values ) { + if ( ! in_array( $values['barbaz'], $values['foobar'], true ) ) { + $values['barbaz'] = $this->default_values['barbaz']; + } + return $values; + } +} + +``` + +### An "upgrade process"? + +The plugin version used when instanciating `MyOptionsSanitization` is stored in the option and can be used in a future plugin release for an upgrade process. +For example: + +```php +$site_version = $options->get( 'version' ); + +if ( version_compare( $site_version, '1.2' ) < 0 ) { + $options->set( [ 'barbaz', 8 ] ); +} + +$options->set( [ 'version', '2.5' ] ); +``` + +### Reserved keyworks + +Don't use the following keywords as option keys, they are used internally: + +* cached +* version + +## Extending + +You may want to store your options elsewhere than the WordPress' options table, maybe in configuration file (heck, why not). This package is built in such a way that it is possible. +To do so, you need to create a class that will replace `Screenfeed\AutoWPOptions\Storage\WpOption`, and implement `Screenfeed\AutoWPOptions\Storage\StorageInterface`. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cbe3bc7 --- /dev/null +++ b/composer.json @@ -0,0 +1,53 @@ +{ + "name": "screenfeed/autowpoptions", + "description": "Manage a set of WordPress options.", + "keywords": [ + "wordpress", + "options" + ], + "homepage": "https://github.com/Screenfeed/autowpoptions", + "license": "GPL-2.0", + "authors": [ + { + "name": "Grégory Viguier", + "role": "Developer" + } + ], + "type": "library", + "config": { + "sort-packages": true + }, + "support": { + "issues": "https://github.com/Screenfeed/autowpoptions/issues", + "source": "https://github.com/Screenfeed/autowpoptions" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "php": "^7.0", + "automattic/phpcs-neutron-standard": "*", + "dealerdirect/phpcodesniffer-composer-installer": "*", + "phpcompatibility/phpcompatibility-wp": "*", + "phpmetrics/phpmetrics": "*", + "roave/security-advisories": "dev-master", + "squizlabs/php_codesniffer": "*", + "szepeviktor/phpstan-wordpress": "*", + "wp-coding-standards/wpcs": "*" + }, + "autoload": { + "psr-4": { + "Screenfeed\\AutoWPOptions\\": "src/" + } + }, + "scripts": { + "cs": "phpcs", + "stan": "\"vendor/bin/phpstan\" analyze --memory-limit=200M", + "metrics": "phpmetrics --config=phpmetrics.json", + "run-lints": [ + "@cs", + "@stan", + "@metrics" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..f556ffd --- /dev/null +++ b/composer.lock @@ -0,0 +1,1055 @@ +{ + "_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": "d0d89bdf7622d7933c7095d8f308e74c", + "packages": [], + "packages-dev": [ + { + "name": "automattic/phpcs-neutron-standard", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/phpcs-neutron-standard.git", + "reference": "ecfaff20035751c1e3aab08483a2f11013d58cad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/phpcs-neutron-standard/zipball/ecfaff20035751c1e3aab08483a2f11013d58cad", + "reference": "ecfaff20035751c1e3aab08483a2f11013d58cad", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "limedeck/phpunit-detailed-printer": "^3.1", + "phpunit/phpunit": "^6.4", + "sirbrillig/phpcs-variable-analysis": "^2.0.1", + "squizlabs/php_codesniffer": "3.3.0" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "NeutronStandard\\": "NeutronStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A set of phpcs sniffs for modern php development.", + "time": "2020-05-25T22:07:24+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.1", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "time": "2020-12-07T18:04:37+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.10.4", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2020-12-20T10:01:03+00:00" + }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v5.6.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "ed446cce304cd49f13900274b3ed60d1b526297e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/ed446cce304cd49f13900274b3ed60d1b526297e", + "reference": "ed446cce304cd49f13900274b3ed60d1b526297e", + "shasum": "" + }, + "replace": { + "giacocorsiglia/wordpress-stubs": "*" + }, + "require-dev": { + "giacocorsiglia/stubs-generator": "^0.5.0", + "php": "~7.1" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "time": "2020-12-09T00:38:16+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "b862bc32f7e860d0b164b199bd995e690b4b191c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/b862bc32f7e860d0b164b199bd995e690b4b191c", + "reference": "b862bc32f7e860d0b164b199bd995e690b4b191c", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards" + ], + "time": "2019-11-04T15:17:54+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "41bef18ba688af638b7310666db28e1ea9158b2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/41bef18ba688af638b7310666db28e1ea9158b2f", + "reference": "41bef18ba688af638b7310666db28e1ea9158b2f", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "wordpress" + ], + "time": "2019-08-28T14:22:28+00:00" + }, + { + "name": "phpmetrics/phpmetrics", + "version": "v2.7.4", + "source": { + "type": "git", + "url": "https://github.com/phpmetrics/PhpMetrics.git", + "reference": "e6a7aee0e0948e363eb78ce9d58573cd5af2cdec" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpmetrics/PhpMetrics/zipball/e6a7aee0e0948e363eb78ce9d58573cd5af2cdec", + "reference": "e6a7aee0e0948e363eb78ce9d58573cd5af2cdec", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "nikic/php-parser": "^3|^4", + "php": ">=5.5" + }, + "replace": { + "halleck45/php-metrics": "*", + "halleck45/phpmetrics": "*" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14", + "sebastian/comparator": ">=1.2.3", + "squizlabs/php_codesniffer": "^3.5" + }, + "bin": [ + "bin/phpmetrics" + ], + "type": "library", + "autoload": { + "psr-0": { + "Hal\\": "./src/" + }, + "files": [ + "./src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean-François Lépine", + "email": "lepinejeanfrancois@yahoo.fr", + "homepage": "http://www.lepine.pro", + "role": "Copyright Holder" + } + ], + "description": "Static analyzer tool for PHP : Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more !", + "homepage": "http://www.phpmetrics.org", + "keywords": [ + "analysis", + "qa", + "quality", + "testing" + ], + "time": "2020-06-30T20:33:55+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "0.12.66", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "4110a2425c6bd53acbdfcda07885e87b66e9ba3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4110a2425c6bd53acbdfcda07885e87b66e9ba3e", + "reference": "4110a2425c6bd53acbdfcda07885e87b66e9ba3e", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-01-11T16:43:15+00:00" + }, + { + "name": "roave/security-advisories", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Roave/SecurityAdvisories.git", + "reference": "a2c04f857299a7119e96448249a9dd5954e099c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/a2c04f857299a7119e96448249a9dd5954e099c1", + "reference": "a2c04f857299a7119e96448249a9dd5954e099c1", + "shasum": "" + }, + "conflict": { + "3f/pygmentize": "<1.2", + "adodb/adodb-php": "<5.20.12", + "alterphp/easyadmin-extension-bundle": ">=1.2,<1.2.11|>=1.3,<1.3.1", + "amphp/artax": "<1.0.6|>=2,<2.0.6", + "amphp/http": "<1.0.1", + "amphp/http-client": ">=4,<4.4", + "api-platform/core": ">=2.2,<2.2.10|>=2.3,<2.3.6", + "asymmetricrypt/asymmetricrypt": ">=0,<9.9.99", + "aws/aws-sdk-php": ">=3,<3.2.1", + "bagisto/bagisto": "<0.1.5", + "barrelstrength/sprout-base-email": "<1.2.7", + "barrelstrength/sprout-forms": "<3.9", + "baserproject/basercms": ">=4,<=4.3.6|>=4.4,<4.4.1", + "bolt/bolt": "<3.7.1", + "brightlocal/phpwhois": "<=4.2.5", + "buddypress/buddypress": "<5.1.2", + "bugsnag/bugsnag-laravel": ">=2,<2.0.2", + "cakephp/cakephp": ">=1.3,<1.3.18|>=2,<2.4.99|>=2.5,<2.5.99|>=2.6,<2.6.12|>=2.7,<2.7.6|>=3,<3.5.18|>=3.6,<3.6.15|>=3.7,<3.7.7", + "cart2quote/module-quotation": ">=4.1.6,<=4.4.5|>=5,<5.4.4", + "cartalyst/sentry": "<=2.1.6", + "centreon/centreon": "<18.10.8|>=19,<19.4.5", + "cesnet/simplesamlphp-module-proxystatistics": "<3.1", + "codeigniter/framework": "<=3.0.6", + "composer/composer": "<=1-alpha.11", + "contao-components/mediaelement": ">=2.14.2,<2.21.1", + "contao/core": ">=2,<3.5.39", + "contao/core-bundle": ">=4,<4.4.52|>=4.5,<4.9.6|= 4.10.0", + "contao/listing-bundle": ">=4,<4.4.8", + "datadog/dd-trace": ">=0.30,<0.30.2", + "david-garcia/phpwhois": "<=4.3.1", + "derhansen/sf_event_mgt": "<4.3.1|>=5,<5.1.1", + "doctrine/annotations": ">=1,<1.2.7", + "doctrine/cache": ">=1,<1.3.2|>=1.4,<1.4.2", + "doctrine/common": ">=2,<2.4.3|>=2.5,<2.5.1", + "doctrine/dbal": ">=2,<2.0.8|>=2.1,<2.1.2", + "doctrine/doctrine-bundle": "<1.5.2", + "doctrine/doctrine-module": "<=0.7.1", + "doctrine/mongodb-odm": ">=1,<1.0.2", + "doctrine/mongodb-odm-bundle": ">=2,<3.0.1", + "doctrine/orm": ">=2,<2.4.8|>=2.5,<2.5.1", + "dolibarr/dolibarr": "<11.0.4", + "dompdf/dompdf": ">=0.6,<0.6.2", + "drupal/core": ">=7,<7.74|>=8,<8.8.11|>=8.9,<8.9.9|>=9,<9.0.8", + "drupal/drupal": ">=7,<7.74|>=8,<8.8.11|>=8.9,<8.9.9|>=9,<9.0.8", + "endroid/qr-code-bundle": "<3.4.2", + "enshrined/svg-sanitize": "<0.13.1", + "erusev/parsedown": "<1.7.2", + "ezsystems/demobundle": ">=5.4,<5.4.6.1", + "ezsystems/ez-support-tools": ">=2.2,<2.2.3", + "ezsystems/ezdemo-ls-extension": ">=5.4,<5.4.2.1", + "ezsystems/ezfind-ls": ">=5.3,<5.3.6.1|>=5.4,<5.4.11.1|>=2017.12,<2017.12.0.1", + "ezsystems/ezplatform": ">=1.7,<1.7.9.1|>=1.13,<1.13.5.1|>=2.5,<2.5.4", + "ezsystems/ezplatform-admin-ui": ">=1.3,<1.3.5|>=1.4,<1.4.6", + "ezsystems/ezplatform-admin-ui-assets": ">=4,<4.2.1|>=5,<5.0.1|>=5.1,<5.1.1", + "ezsystems/ezplatform-kernel": ">=1,<1.0.2.1", + "ezsystems/ezplatform-user": ">=1,<1.0.1", + "ezsystems/ezpublish-kernel": ">=5.3,<5.3.12.1|>=5.4,<5.4.14.2|>=6,<6.7.9.1|>=6.8,<6.13.6.3|>=7,<7.2.4.1|>=7.3,<7.3.2.1|>=7.5,<7.5.7.1", + "ezsystems/ezpublish-legacy": ">=5.3,<5.3.12.6|>=5.4,<5.4.14.2|>=2011,<2017.12.7.3|>=2018.6,<2018.6.1.4|>=2018.9,<2018.9.1.3|>=2019.3,<2019.3.5.1", + "ezsystems/platform-ui-assets-bundle": ">=4.2,<4.2.3", + "ezsystems/repository-forms": ">=2.3,<2.3.2.1", + "ezyang/htmlpurifier": "<4.1.1", + "firebase/php-jwt": "<2", + "fooman/tcpdf": "<6.2.22", + "fossar/tcpdf-parser": "<6.2.22", + "friendsofsymfony/oauth2-php": "<1.3", + "friendsofsymfony/rest-bundle": ">=1.2,<1.2.2", + "friendsofsymfony/user-bundle": ">=1.2,<1.3.5", + "friendsoftypo3/mediace": ">=7.6.2,<7.6.5", + "fuel/core": "<1.8.1", + "getgrav/grav": "<1.7-beta.8", + "getkirby/cms": ">=3,<3.4.5", + "getkirby/panel": "<2.5.14", + "gos/web-socket-bundle": "<1.10.4|>=2,<2.6.1|>=3,<3.3", + "gree/jose": "<=2.2", + "gregwar/rst": "<1.0.3", + "guzzlehttp/guzzle": ">=4-rc.2,<4.2.4|>=5,<5.3.1|>=6,<6.2.1", + "illuminate/auth": ">=4,<4.0.99|>=4.1,<=4.1.31|>=4.2,<=4.2.22|>=5,<=5.0.35|>=5.1,<=5.1.46|>=5.2,<=5.2.45|>=5.3,<=5.3.31|>=5.4,<=5.4.36|>=5.5,<5.5.10", + "illuminate/cookie": ">=4,<=4.0.11|>=4.1,<=4.1.99999|>=4.2,<=4.2.99999|>=5,<=5.0.99999|>=5.1,<=5.1.99999|>=5.2,<=5.2.99999|>=5.3,<=5.3.99999|>=5.4,<=5.4.99999|>=5.5,<=5.5.49|>=5.6,<=5.6.99999|>=5.7,<=5.7.99999|>=5.8,<=5.8.99999|>=6,<6.18.31|>=7,<7.22.4", + "illuminate/database": ">=4,<4.0.99|>=4.1,<4.1.29|>=5.5,<=5.5.44|>=6,<6.18.34|>=7,<7.23.2", + "illuminate/encryption": ">=4,<=4.0.11|>=4.1,<=4.1.31|>=4.2,<=4.2.22|>=5,<=5.0.35|>=5.1,<=5.1.46|>=5.2,<=5.2.45|>=5.3,<=5.3.31|>=5.4,<=5.4.36|>=5.5,<5.5.40|>=5.6,<5.6.15", + "illuminate/view": ">=7,<7.1.2", + "ivankristianto/phpwhois": "<=4.3", + "james-heinrich/getid3": "<1.9.9", + "joomla/session": "<1.3.1", + "jsmitty12/phpwhois": "<5.1", + "kazist/phpwhois": "<=4.2.6", + "kitodo/presentation": "<3.1.2", + "kreait/firebase-php": ">=3.2,<3.8.1", + "la-haute-societe/tcpdf": "<6.2.22", + "laravel/framework": ">=4,<4.0.99|>=4.1,<=4.1.99999|>=4.2,<=4.2.99999|>=5,<=5.0.99999|>=5.1,<=5.1.99999|>=5.2,<=5.2.99999|>=5.3,<=5.3.99999|>=5.4,<=5.4.99999|>=5.5,<=5.5.49|>=5.6,<=5.6.99999|>=5.7,<=5.7.99999|>=5.8,<=5.8.99999|>=6,<6.18.34|>=7,<7.23.2", + "laravel/socialite": ">=1,<1.0.99|>=2,<2.0.10", + "league/commonmark": "<0.18.3", + "librenms/librenms": "<1.53", + "livewire/livewire": ">2.2.4,<2.2.6", + "magento/community-edition": ">=2,<2.2.10|>=2.3,<2.3.3", + "magento/magento1ce": "<1.9.4.3", + "magento/magento1ee": ">=1,<1.14.4.3", + "magento/product-community-edition": ">=2,<2.2.10|>=2.3,<2.3.2-p.2", + "marcwillmann/turn": "<0.3.3", + "mediawiki/core": ">=1.27,<1.27.6|>=1.29,<1.29.3|>=1.30,<1.30.2|>=1.31,<1.31.9|>=1.32,<1.32.6|>=1.32.99,<1.33.3|>=1.33.99,<1.34.3|>=1.34.99,<1.35", + "mittwald/typo3_forum": "<1.2.1", + "monolog/monolog": ">=1.8,<1.12", + "namshi/jose": "<2.2", + "nette/application": ">=2,<2.0.19|>=2.1,<2.1.13|>=2.2,<2.2.10|>=2.3,<2.3.14|>=2.4,<2.4.16|>=3,<3.0.6", + "nette/nette": ">=2,<2.0.19|>=2.1,<2.1.13", + "nystudio107/craft-seomatic": "<3.3", + "nzo/url-encryptor-bundle": ">=4,<4.3.2|>=5,<5.0.1", + "october/backend": ">=1.0.319,<1.0.470", + "october/cms": "= 1.0.469|>=1.0.319,<1.0.469", + "october/october": ">=1.0.319,<1.0.466", + "october/rain": ">=1.0.319,<1.0.468", + "onelogin/php-saml": "<2.10.4", + "oneup/uploader-bundle": "<1.9.3|>=2,<2.1.5", + "openid/php-openid": "<2.3", + "openmage/magento-lts": "<19.4.8|>=20,<20.0.4", + "orchid/platform": ">=9,<9.4.4", + "oro/crm": ">=1.7,<1.7.4", + "oro/platform": ">=1.7,<1.7.4", + "padraic/humbug_get_contents": "<1.1.2", + "pagarme/pagarme-php": ">=0,<3", + "paragonie/random_compat": "<2", + "passbolt/passbolt_api": "<2.11", + "paypal/merchant-sdk-php": "<3.12", + "pear/archive_tar": "<1.4.11", + "personnummer/personnummer": "<3.0.2", + "phpfastcache/phpfastcache": ">=5,<5.0.13", + "phpmailer/phpmailer": "<6.1.6", + "phpmussel/phpmussel": ">=1,<1.6", + "phpmyadmin/phpmyadmin": "<4.9.6|>=5,<5.0.3", + "phpoffice/phpexcel": "<1.8.2", + "phpoffice/phpspreadsheet": "<1.16", + "phpunit/phpunit": ">=4.8.19,<4.8.28|>=5.0.10,<5.6.3", + "phpwhois/phpwhois": "<=4.2.5", + "phpxmlrpc/extras": "<0.6.1", + "pimcore/pimcore": "<6.3", + "pocketmine/pocketmine-mp": "<3.15.4", + "prestashop/autoupgrade": ">=4,<4.10.1", + "prestashop/contactform": ">1.0.1,<4.3", + "prestashop/gamification": "<2.3.2", + "prestashop/productcomments": ">=4,<4.2", + "prestashop/ps_facetedsearch": "<3.4.1", + "privatebin/privatebin": "<1.2.2|>=1.3,<1.3.2", + "propel/propel": ">=2-alpha.1,<=2-alpha.7", + "propel/propel1": ">=1,<=1.7.1", + "pterodactyl/panel": "<0.7.19|>=1-rc.0,<=1-rc.6", + "pusher/pusher-php-server": "<2.2.1", + "rainlab/debugbar-plugin": "<3.1", + "robrichards/xmlseclibs": "<3.0.4", + "sabberworm/php-css-parser": ">=1,<1.0.1|>=2,<2.0.1|>=3,<3.0.1|>=4,<4.0.1|>=5,<5.0.9|>=5.1,<5.1.3|>=5.2,<5.2.1|>=6,<6.0.2|>=7,<7.0.4|>=8,<8.0.1|>=8.1,<8.1.1|>=8.2,<8.2.1|>=8.3,<8.3.1", + "sabre/dav": ">=1.6,<1.6.99|>=1.7,<1.7.11|>=1.8,<1.8.9", + "scheb/two-factor-bundle": ">=0,<3.26|>=4,<4.11", + "sensiolabs/connect": "<4.2.3", + "serluck/phpwhois": "<=4.2.6", + "shopware/core": "<=6.3.4", + "shopware/platform": "<=6.3.4", + "shopware/shopware": "<5.6.9", + "silverstripe/admin": ">=1.0.3,<1.0.4|>=1.1,<1.1.1", + "silverstripe/assets": ">=1,<1.4.7|>=1.5,<1.5.2", + "silverstripe/cms": "<4.3.6|>=4.4,<4.4.4", + "silverstripe/comments": ">=1.3,<1.9.99|>=2,<2.9.99|>=3,<3.1.1", + "silverstripe/forum": "<=0.6.1|>=0.7,<=0.7.3", + "silverstripe/framework": "<4.4.7|>=4.5,<4.5.4", + "silverstripe/graphql": ">=2,<2.0.5|>=3,<3.1.2|>=3.2,<3.2.4", + "silverstripe/registry": ">=2.1,<2.1.2|>=2.2,<2.2.1", + "silverstripe/restfulserver": ">=1,<1.0.9|>=2,<2.0.4", + "silverstripe/subsites": ">=2,<2.1.1", + "silverstripe/taxonomy": ">=1.3,<1.3.1|>=2,<2.0.1", + "silverstripe/userforms": "<3", + "simple-updates/phpwhois": "<=1", + "simplesamlphp/saml2": "<1.10.6|>=2,<2.3.8|>=3,<3.1.4", + "simplesamlphp/simplesamlphp": "<1.18.6", + "simplesamlphp/simplesamlphp-module-infocard": "<1.0.1", + "simplito/elliptic-php": "<1.0.6", + "slim/slim": "<2.6", + "smarty/smarty": "<3.1.33", + "socalnick/scn-social-auth": "<1.15.2", + "spoonity/tcpdf": "<6.2.22", + "squizlabs/php_codesniffer": ">=1,<2.8.1|>=3,<3.0.1", + "ssddanbrown/bookstack": "<0.29.2", + "stormpath/sdk": ">=0,<9.9.99", + "studio-42/elfinder": "<2.1.49", + "sulu/sulu": "<1.6.34|>=2,<2.0.10|>=2.1,<2.1.1", + "swiftmailer/swiftmailer": ">=4,<5.4.5", + "sylius/admin-bundle": ">=1,<1.0.17|>=1.1,<1.1.9|>=1.2,<1.2.2", + "sylius/grid": ">=1,<1.1.19|>=1.2,<1.2.18|>=1.3,<1.3.13|>=1.4,<1.4.5|>=1.5,<1.5.1", + "sylius/grid-bundle": ">=1,<1.1.19|>=1.2,<1.2.18|>=1.3,<1.3.13|>=1.4,<1.4.5|>=1.5,<1.5.1", + "sylius/resource-bundle": "<1.3.14|>=1.4,<1.4.7|>=1.5,<1.5.2|>=1.6,<1.6.4", + "sylius/sylius": "<1.6.9|>=1.7,<1.7.9|>=1.8,<1.8.3", + "symbiote/silverstripe-multivaluefield": ">=3,<3.0.99", + "symbiote/silverstripe-versionedfiles": "<=2.0.3", + "symfony/cache": ">=3.1,<3.4.35|>=4,<4.2.12|>=4.3,<4.3.8", + "symfony/dependency-injection": ">=2,<2.0.17|>=2.7,<2.7.51|>=2.8,<2.8.50|>=3,<3.4.26|>=4,<4.1.12|>=4.2,<4.2.7", + "symfony/error-handler": ">=4.4,<4.4.4|>=5,<5.0.4", + "symfony/form": ">=2.3,<2.3.35|>=2.4,<2.6.12|>=2.7,<2.7.50|>=2.8,<2.8.49|>=3,<3.4.20|>=4,<4.0.15|>=4.1,<4.1.9|>=4.2,<4.2.1", + "symfony/framework-bundle": ">=2,<2.3.18|>=2.4,<2.4.8|>=2.5,<2.5.2|>=2.7,<2.7.51|>=2.8,<2.8.50|>=3,<3.4.26|>=4,<4.1.12|>=4.2,<4.2.7", + "symfony/http-foundation": ">=2,<2.8.52|>=3,<3.4.35|>=4,<4.2.12|>=4.3,<4.3.8|>=4.4,<4.4.7|>=5,<5.0.7", + "symfony/http-kernel": ">=2,<2.8.52|>=3,<3.4.35|>=4,<4.2.12|>=4.3,<4.4.13|>=5,<5.1.5", + "symfony/intl": ">=2.7,<2.7.38|>=2.8,<2.8.31|>=3,<3.2.14|>=3.3,<3.3.13", + "symfony/mime": ">=4.3,<4.3.8", + "symfony/phpunit-bridge": ">=2.8,<2.8.50|>=3,<3.4.26|>=4,<4.1.12|>=4.2,<4.2.7", + "symfony/polyfill": ">=1,<1.10", + "symfony/polyfill-php55": ">=1,<1.10", + "symfony/proxy-manager-bridge": ">=2.7,<2.7.51|>=2.8,<2.8.50|>=3,<3.4.26|>=4,<4.1.12|>=4.2,<4.2.7", + "symfony/routing": ">=2,<2.0.19", + "symfony/security": ">=2,<2.7.51|>=2.8,<2.8.50|>=3,<3.4.26|>=4,<4.1.12|>=4.2,<4.2.7|>=4.4,<4.4.7|>=5,<5.0.7", + "symfony/security-bundle": ">=2,<2.7.48|>=2.8,<2.8.41|>=3,<3.3.17|>=3.4,<3.4.11|>=4,<4.0.11", + "symfony/security-core": ">=2.4,<2.6.13|>=2.7,<2.7.9|>=2.7.30,<2.7.32|>=2.8,<2.8.37|>=3,<3.3.17|>=3.4,<3.4.7|>=4,<4.0.7", + "symfony/security-csrf": ">=2.4,<2.7.48|>=2.8,<2.8.41|>=3,<3.3.17|>=3.4,<3.4.11|>=4,<4.0.11", + "symfony/security-guard": ">=2.8,<2.8.41|>=3,<3.3.17|>=3.4,<3.4.11|>=4,<4.0.11", + "symfony/security-http": ">=2.3,<2.3.41|>=2.4,<2.7.51|>=2.8,<2.8.50|>=3,<3.4.26|>=4,<4.2.12|>=4.3,<4.3.8|>=4.4,<4.4.7|>=5,<5.0.7", + "symfony/serializer": ">=2,<2.0.11", + "symfony/symfony": ">=2,<2.8.52|>=3,<3.4.35|>=4,<4.2.12|>=4.3,<4.4.13|>=5,<5.1.5", + "symfony/translation": ">=2,<2.0.17", + "symfony/validator": ">=2,<2.0.24|>=2.1,<2.1.12|>=2.2,<2.2.5|>=2.3,<2.3.3", + "symfony/var-exporter": ">=4.2,<4.2.12|>=4.3,<4.3.8", + "symfony/web-profiler-bundle": ">=2,<2.3.19|>=2.4,<2.4.9|>=2.5,<2.5.4", + "symfony/yaml": ">=2,<2.0.22|>=2.1,<2.1.7", + "t3g/svg-sanitizer": "<1.0.3", + "tecnickcom/tcpdf": "<6.2.22", + "thelia/backoffice-default-template": ">=2.1,<2.1.2", + "thelia/thelia": ">=2.1-beta.1,<2.1.3", + "theonedemon/phpwhois": "<=4.2.5", + "titon/framework": ">=0,<9.9.99", + "truckersmp/phpwhois": "<=4.3.1", + "twig/twig": "<1.38|>=2,<2.7", + "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.38|>=9,<9.5.23|>=10,<10.4.10", + "typo3/cms-core": ">=8,<8.7.38|>=9,<9.5.23|>=10,<10.4.10", + "typo3/flow": ">=1,<1.0.4|>=1.1,<1.1.1|>=2,<2.0.1|>=2.3,<2.3.16|>=3,<3.0.10|>=3.1,<3.1.7|>=3.2,<3.2.7|>=3.3,<3.3.5", + "typo3/neos": ">=1.1,<1.1.3|>=1.2,<1.2.13|>=2,<2.0.4", + "typo3/phar-stream-wrapper": ">=1,<2.1.1|>=3,<3.1.1", + "typo3fluid/fluid": ">=2,<2.0.8|>=2.1,<2.1.7|>=2.2,<2.2.4|>=2.3,<2.3.7|>=2.4,<2.4.4|>=2.5,<2.5.11|>=2.6,<2.6.10", + "ua-parser/uap-php": "<3.8", + "usmanhalalit/pixie": "<1.0.3|>=2,<2.0.2", + "verot/class.upload.php": "<=1.0.3|>=2,<=2.0.4", + "wallabag/tcpdf": "<6.2.22", + "willdurand/js-translation-bundle": "<2.1.1", + "yii2mod/yii2-cms": "<1.9.2", + "yiisoft/yii": ">=1.1.14,<1.1.15", + "yiisoft/yii2": "<2.0.38", + "yiisoft/yii2-bootstrap": "<2.0.4", + "yiisoft/yii2-dev": "<2.0.15", + "yiisoft/yii2-elasticsearch": "<2.0.5", + "yiisoft/yii2-gii": "<2.0.4", + "yiisoft/yii2-jui": "<2.0.4", + "yiisoft/yii2-redis": "<2.0.8", + "yourls/yourls": "<1.7.4", + "zendframework/zend-cache": ">=2.4,<2.4.8|>=2.5,<2.5.3", + "zendframework/zend-captcha": ">=2,<2.4.9|>=2.5,<2.5.2", + "zendframework/zend-crypt": ">=2,<2.4.9|>=2.5,<2.5.2", + "zendframework/zend-db": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.2,<2.2.10|>=2.3,<2.3.5", + "zendframework/zend-developer-tools": ">=1.2.2,<1.2.3", + "zendframework/zend-diactoros": ">=1,<1.8.4", + "zendframework/zend-feed": ">=1,<2.10.3", + "zendframework/zend-form": ">=2,<2.2.7|>=2.3,<2.3.1", + "zendframework/zend-http": ">=1,<2.8.1", + "zendframework/zend-json": ">=2.1,<2.1.6|>=2.2,<2.2.6", + "zendframework/zend-ldap": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.2,<2.2.8|>=2.3,<2.3.3", + "zendframework/zend-mail": ">=2,<2.4.11|>=2.5,<2.7.2", + "zendframework/zend-navigation": ">=2,<2.2.7|>=2.3,<2.3.1", + "zendframework/zend-session": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.2,<2.2.9|>=2.3,<2.3.4", + "zendframework/zend-validator": ">=2.3,<2.3.6", + "zendframework/zend-view": ">=2,<2.2.7|>=2.3,<2.3.1", + "zendframework/zend-xmlrpc": ">=2.1,<2.1.6|>=2.2,<2.2.6", + "zendframework/zendframework": "<2.5.1", + "zendframework/zendframework1": "<1.12.20", + "zendframework/zendopenid": ">=2,<2.0.2", + "zendframework/zendxml": ">=1,<1.0.1", + "zetacomponents/mail": "<1.8.2", + "zf-commons/zfc-user": "<1.2.2", + "zfcampus/zf-apigility-doctrine": ">=1,<1.0.3", + "zfr/zfr-oauth2-server-module": "<0.1.2" + }, + "type": "metapackage", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "role": "maintainer" + }, + { + "name": "Ilya Tribusean", + "email": "slash3b@gmail.com", + "role": "maintainer" + } + ], + "description": "Prevents installation of composer packages with known security vulnerabilities: no API, simply require it", + "funding": [ + { + "url": "https://github.com/Ocramius", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/roave/security-advisories", + "type": "tidelift" + } + ], + "time": "2020-12-31T19:24:22+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.5.8", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2020-10-23T02:01:07+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.22.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "a678b42e92f86eca04b7fa4c0f6f19d097fb69e2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/a678b42e92f86eca04b7fa4c0f6f19d097fb69e2", + "reference": "a678b42e92f86eca04b7fa4c0f6f19d097fb69e2", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "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": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "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": "2021-01-07T16:49:33+00:00" + }, + { + "name": "szepeviktor/phpstan-wordpress", + "version": "v0.7.2", + "source": { + "type": "git", + "url": "https://github.com/szepeviktor/phpstan-wordpress.git", + "reference": "191eafa7283497645de920d262133cf17de5353f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/191eafa7283497645de920d262133cf17de5353f", + "reference": "191eafa7283497645de920d262133cf17de5353f", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0", + "phpstan/phpstan": "^0.12.26", + "symfony/polyfill-php73": "^1.12.0" + }, + "require-dev": { + "composer/composer": "^1.8.6", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpstan/phpstan-strict-rules": "^0.12", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.4.3" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\WordPress\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress extensions for PHPStan", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "static analysis", + "wordpress" + ], + "funding": [ + { + "url": "https://www.paypal.me/szepeviktor", + "type": "custom" + } + ], + "time": "2021-01-03T13:45:42+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "7da1894633f168fe244afc6de00d141f27517b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", + "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.3.1" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2020-05-13T23:57:56+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "roave/security-advisories": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.3.0" + }, + "platform-dev": { + "php": "^7.0" + }, + "plugin-api-version": "1.1.0" +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..62e5f28 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "autowpoptions", + "description": "Manage a set of WordPress options.", + "version": "1.0.0", + "homepage": "https://github.com/Screenfeed/autowpoptions", + "license": "GPL-2.0", + "private": true, + "author": { + "name": "Grégory Viguier", + "url": "https://www.screenfeed.fr/" + } +} diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..575cdd4 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,37 @@ + + + Manage a set of WordPress options. + + + + . + + bin/* + report/* + tests/* + vendor/* + + + + + + + + *\.php$ + + + + + + + + + + + + + + + + + diff --git a/phpmetrics.json b/phpmetrics.json new file mode 100644 index 0000000..94ca331 --- /dev/null +++ b/phpmetrics.json @@ -0,0 +1,9 @@ +{ + "includes": [ + "src" + ], + "report": { + "html": "report" + }, + "extensions": [ "php" ] +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..cbddf00 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,16 @@ +includes: + - phar://phpstan.phar/conf/bleedingEdge.neon + - vendor/szepeviktor/phpstan-wordpress/extension.neon +parameters: + level: max + inferPrivatePropertyTypeFromConstructor: true + paths: + - %currentWorkingDirectory%/src/ + excludes_analyse: + - %currentWorkingDirectory%/.git/* + - %currentWorkingDirectory%/bin/* + - %currentWorkingDirectory%/report/* + - %currentWorkingDirectory%/Tests/* + - %currentWorkingDirectory%/vendor/* + ignoreErrors: + - '#^Function apply_filters(_ref_array)? invoked with \d parameters, \d required\.$#' diff --git a/src/Options.php b/src/Options.php new file mode 100644 index 0000000..a9aa117 --- /dev/null +++ b/src/Options.php @@ -0,0 +1,211 @@ +storage = $storage; + $this->sanitization = $sanitization; + } + + /** + * Launches the hooks. + * + * @since 1.0.0 + * + * @return void + */ + public function init() { + add_filter( 'sanitize_option_' . $this->storage->get_full_name(), [ $this->sanitization, 'sanitize_and_validate_on_update' ], 50 ); + } + + /** + * Returns the storage instance. + * + * @since 1.0.0 + * + * @return StorageInterface + */ + public function get_storage() { + return $this->storage; + } + + /** ----------------------------------------------------------------------------------------- */ + /** GET/SET/DELETE OPTION(S) ================================================================ */ + /** ----------------------------------------------------------------------------------------- */ + + /** + * Returns an option. + * + * @since 1.0.0 + * + * @param string $key The option name. + * @return mixed The option value. Null if the key does not exist. + */ + public function get( $key ) { + $default_values = $this->sanitization->get_default_values(); + + if ( ! isset( $default_values[ $key ] ) ) { + return null; + } + + $default = $default_values[ $key ]; + $prefix = $this->sanitization->get_prefix(); + $identifier = $this->sanitization->get_identifier(); + + /** + * Pre-filters any option before read. + * + * @since 1.0.0 + * + * @param mixed $value Value to return instead of the option value. Default null to skip it. + * @param mixed $default The default value. + */ + $value = apply_filters( "pre_get_{$prefix}_{$identifier}_{$key}", null, $default ); + + if ( isset( $value ) ) { + return $value; + } + + // Get all values. + $values = $this->get_all(); + + // Sanitize and validate the value. + $value = $this->sanitization->sanitize_and_validate( $key, $values[ $key ], $default ); + + /** + * Filters any option after read. + * + * @since 1.0.0 + * + * @param mixed $value Value of the option. + * @param mixed $default The default value. Default false. + */ + return apply_filters( "get_{$prefix}_{$identifier}_{$key}", $value, $default ); + } + + /** + * Returns all options (no cast, no sanitization, no validation). + * Reset values are returned if the whole option does not exist. + * Default values are added for the keys that are missing. + * + * @since 1.0.0 + * + * @return array The options. + */ + public function get_all() { + $values = $this->storage->get(); + + if ( empty( $values ) ) { + return $this->sanitization->get_reset_values(); + } + + $default = $this->sanitization->get_default_values(); + $values = array_merge( $default, $values ); + return array_intersect_key( $values, $default ); + } + + /** + * Sets one or multiple options. + * Empty fields are not deleted. + * + * @since 1.0.0 + * + * @param array $values An array of option name / option value pairs. + * @return void + */ + public function set( array $values ) { + $values = array_merge( $this->get_all(), $values ); + $values = array_intersect_key( $values, $this->sanitization->get_default_values() ); + + $this->storage->set( $values ); + } + + /** + * Deletes one or multiple options. + * + * @since 1.0.0 + * + * @param array|string $keys An array of option names or a single option name. + * @return void + */ + public function delete( $keys ) { + $values = $this->storage->get(); + + if ( ! $values ) { + if ( false !== $values ) { + $this->storage->delete(); + } + return; + } + + $keys = array_flip( (array) $keys ); + $values = array_diff_key( $values, $keys ); + + $this->storage->set( $values ); + } + + /** + * Deletes all options. + * + * @since 1.0.0 + * + * @return void + */ + public function delete_all() { + $this->storage->delete(); + } + + /** + * Checks if the option with the given name exists. + * + * @since 1.0.0 + * + * @param string $key The option name. + * @return bool + */ + public function has( $key ) { + return null !== $this->get( $key ); + } +} diff --git a/src/Sanitization/AbstractSanitization.php b/src/Sanitization/AbstractSanitization.php new file mode 100644 index 0000000..8a4ee86 --- /dev/null +++ b/src/Sanitization/AbstractSanitization.php @@ -0,0 +1,313 @@ + + * @since 1.0.0 + */ + protected $default_values; + + /** + * The values used when they are set the first time or reset. + * Values identical to default values are not listed. + * `cached` and `version` are reserved keys, do not use them. + * + * @var array + * @since 1.0.0 + */ + protected $reset_values = []; + + /** + * The constructor. + * + * @since 1.0.0 + * + * @param string $version Current plugin version. + * @return void + */ + public function __construct( $version ) { + $this->version = $version; + $this->default_values = array_merge( + [ + 'version' => '', + ], + $this->default_values + ); + } + + /** + * Returns the prefix used in hook names. + * + * @since 1.0.0 + * + * @return string + */ + public function get_prefix() { + return $this->prefix; + } + + /** + * Returns the identifier used in the hook names. + * + * @since 1.0.0 + * + * @return string + */ + public function get_identifier() { + return $this->identifier; + } + + /** ----------------------------------------------------------------------------------------- */ + /** DEFAULT + RESET VALUES ================================================================== */ + /** ----------------------------------------------------------------------------------------- */ + + /** + * Returns default option values. + * + * @since 1.0.0 + * + * @return array + */ + public function get_default_values() { + $default_values = $this->default_values; + + if ( ! empty( $default_values['cached'] ) ) { + unset( $default_values['cached'] ); + return $default_values; + } + + $prefix = $this->get_prefix(); + $identifier = $this->get_identifier(); + + /** + * Allows to add more default option values. + * + * @since 1.0.0 + * + * @param array $new_values New default option values. + * @param array $default_values Plugin default option values. + */ + $new_values = apply_filters( "{$prefix}_default_{$identifier}_values", [], $default_values ); + $new_values = is_array( $new_values ) ? $new_values : []; + + if ( ! empty( $new_values ) ) { + // Don't allow new values to overwrite the plugin values. + $new_values = array_diff_key( $new_values, $default_values ); + } + + if ( ! empty( $new_values ) ) { + $default_values = array_merge( $default_values, $new_values ); + $this->default_values = $default_values; + } + + $this->default_values['cached'] = 1; + + return $default_values; + } + + /** + * Returns the values used when the option is empty. + * + * @since 1.0.0 + * + * @return array + */ + public function get_reset_values() { + $reset_values = $this->reset_values; + + if ( ! empty( $reset_values['cached'] ) ) { + unset( $reset_values['cached'] ); + return $reset_values; + } + + $default_values = $this->get_default_values(); + $reset_values = array_merge( $default_values, $reset_values ); + $prefix = $this->get_prefix(); + $identifier = $this->get_identifier(); + + /** + * Allows to filter the "reset" option values. + * + * @since 1.0.0 + * + * @param array $reset_values Plugin reset option values. + */ + $new_values = apply_filters( "{$prefix}_reset_{$identifier}_values", $reset_values ); + + if ( ! empty( $new_values ) && is_array( $new_values ) ) { + $reset_values = array_merge( $reset_values, $new_values ); + } + + $this->reset_values = $reset_values; + $this->reset_values['cached'] = 1; + + return $reset_values; + } + + /** ----------------------------------------------------------------------------------------- */ + /** SANITIZATION, VALIDATION ================================================================ */ + /** ----------------------------------------------------------------------------------------- */ + + /** + * Sanitizes and validates an option value. + * This is used when getting the value from storage, and also before storing. + * + * @since 1.0.0 + * + * @param string $key The option key. + * @param mixed $value The value. + * @param mixed $default The default value. + * @return mixed + */ + public function sanitize_and_validate( $key, $value, $default = null ) { + if ( ! isset( $default ) ) { + $default_values = $this->get_default_values(); + $default = $default_values[ $key ]; + } + + // Cast the value. + $value = $this->cast( $value, $default ); + + if ( $value === $default ) { + return $value; + } + + // Version. + if ( 'version' === $key ) { + return sanitize_text_field( $value ); + } + + return $this->sanitize_and_validate_value( $key, $value, $default ); + } + + /** + * Sanitizes and validates an option value. Basic casts have been made. + * + * @since 1.0.0 + * + * @param string $key The option key. + * @param mixed $value The value. + * @param mixed $default The default value. + * @return mixed + */ + abstract protected function sanitize_and_validate_value( $key, $value, $default ); + + /** + * Sanitizes and validates the options. + * This is used before storing them. + * + * @since 1.0.0 + * + * @param array $values The option values. + * @return array + */ + public function sanitize_and_validate_on_update( array $values ) { + $default_values = $this->get_default_values(); + + if ( ! empty( $values ) ) { + foreach ( $default_values as $key => $default ) { + if ( isset( $values[ $key ] ) ) { + $values[ $key ] = $this->sanitize_and_validate( $key, $values[ $key ], $default ); + } + } + } + + $values = array_intersect_key( $values, $default_values ); + + // Version. + if ( empty( $values['version'] ) ) { + $values['version'] = $this->version; + } + + return $this->validate_values_on_update( $values ); + } + + /** + * Validates the options before storing the values. + * Basic sanitization and validation have been made, value by value. + * It is useful when we want to change a value depending on another one. + * + * @since 1.0.0 + * + * @param array $values The option value. + * @return array + */ + abstract protected function validate_values_on_update( array $values ); + + /** ----------------------------------------------------------------------------------------- */ + /** TOOLS =================================================================================== */ + /** ----------------------------------------------------------------------------------------- */ + + /** + * Casts a value, depending on its default value type. + * + * @since 1.0.0 + * + * @param mixed $value The value to cast. + * @param mixed $default The default value. + * @return mixed + */ + protected function cast( $value, $default ) { + if ( is_array( $default ) ) { + return is_array( $value ) ? $value : []; + } + + if ( is_int( $default ) ) { + return (int) $value; + } + + if ( is_bool( $default ) ) { + return (bool) $value; + } + + if ( is_float( $default ) ) { + return round( (float) $value, 3 ); + } + + return $value; + } +} diff --git a/src/Sanitization/SanitizationInterface.php b/src/Sanitization/SanitizationInterface.php new file mode 100644 index 0000000..972348e --- /dev/null +++ b/src/Sanitization/SanitizationInterface.php @@ -0,0 +1,87 @@ + + */ + public function get_default_values(); + + /** + * Returns the values used when the option is empty. + * + * @since 1.0.0 + * + * @return array + */ + public function get_reset_values(); + + /** ----------------------------------------------------------------------------------------- */ + /** SANITIZATION, VALIDATION ================================================================ */ + /** ----------------------------------------------------------------------------------------- */ + + /** + * Sanitizes and validates an option value. + * This is used when getting the value from storage, and also before storing. + * + * @since 1.0.0 + * + * @param string $key The option key. + * @param mixed $value The value. + * @param mixed $default The default value. + * @return mixed + */ + public function sanitize_and_validate( $key, $value, $default = null ); + + /** + * Validates the options before storing the values. + * Basic sanitization and validation have been made, value by value. + * It is useful when we want to change a value depending on another one. + * + * @since 1.0.0 + * + * @param array $values The option values. + * @return array + */ + public function sanitize_and_validate_on_update( array $values ); +} diff --git a/src/Storage/StorageInterface.php b/src/Storage/StorageInterface.php new file mode 100644 index 0000000..932d3b2 --- /dev/null +++ b/src/Storage/StorageInterface.php @@ -0,0 +1,84 @@ +|false The options. False if not set yet. An empty array if invalid. + */ + public function get(); + + /** + * Updates the options. + * + * @since 1.0.0 + * + * @param array $values An array of option name / option value pairs. + * + * @return bool True if the value was updated, false otherwise. + */ + public function set( array $values ); + + /** + * Deletes all options. + * + * @since 1.0.0 + * + * @return bool True if the option was deleted, false otherwise. + */ + public function delete(); +} diff --git a/src/Storage/WpOption.php b/src/Storage/WpOption.php new file mode 100644 index 0000000..f012163 --- /dev/null +++ b/src/Storage/WpOption.php @@ -0,0 +1,171 @@ + $args { + * Optionnal arguments. + * + * @type bool $autoload True if the option must be autoloaded. False otherwise. Not used for network options. Default value is true. + * @type int $network_id ID of the network. Used only for network options. Can be `0` to default to the current network ID. Default value is the current network ID. + * } + * @return void + */ + public function __construct( $option_name, $network_option, array $args = [] ) { + $this->option_name = (string) $option_name; + $this->network_option = (bool) $network_option; + $this->autoload = ! empty( $args['autoload'] ) && 'no' !== $args['autoload'] ? 'yes' : 'no'; + $this->network_id = ! empty( $args['network_id'] ) && is_numeric( $args['network_id'] ) ? absint( $args['network_id'] ) : null; + } + + /** + * Returns the type of the storage. + * + * @since 1.0.0 + * + * @return string + */ + public function get_type() { + return 'wp_option'; + } + + /** + * Returns the "name" of the option that stores the settings. + * + * @since 1.0.0 + * + * @return string + */ + public function get_full_name() { + return $this->option_name; + } + + /** + * Returns the network ID of the option. + * + * @since 1.0.0 + * + * @return int + */ + public function get_network_id() { + if ( ! isset( $this->network_id ) ) { + $this->network_id = get_current_network_id(); + } + return $this->network_id; + } + + /** + * Tells if the option is a network option. + * + * @since 1.0.0 + * + * @return bool + */ + public function is_network_option() { + return (bool) $this->network_option; + } + + /** + * Returns the value of all options. + * + * @since 1.0.0 + * + * @return array|false The options. False if not set yet. An empty array if invalid. + */ + public function get() { + $values = $this->is_network_option() ? get_network_option( $this->get_network_id(), $this->get_full_name() ) : get_option( $this->get_full_name() ); + + if ( false !== $values && ! is_array( $values ) ) { + return []; + } + + return $values; + } + + /** + * Updates the options. + * + * @since 1.0.0 + * + * @param array $values An array of option name / option value pairs. + * + * @return bool True if the value was updated, false otherwise. + */ + public function set( array $values ) { + if ( empty( $values ) ) { + // The option is empty: delete it. + return $this->delete(); + } + if ( $this->is_network_option() ) { + // Network option. + return update_network_option( $this->get_network_id(), $this->get_full_name(), $values ); + } + // Site option. + return update_option( $this->get_full_name(), $values, $this->autoload ); + } + + /** + * Deletes all options. + * + * @since 1.0.0 + * + * @return bool True if the option was deleted, false otherwise. + */ + public function delete() { + return $this->is_network_option() ? delete_network_option( $this->get_network_id(), $this->get_full_name() ) : delete_option( $this->get_full_name() ); + } +}