diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2f918ea --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +name: Release + +on: + push: + tags: + - '*.*.*' + +jobs: + release: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + + # @see https://github.com/actions/create-release/issues/38#issuecomment-715327220 + # @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files + - name: Prepare the changelog from the tag message + id: prepare_changelog + run: | + PRERELEASE=false + # Check release type + if [[ $GITHUB_REF_NAME =~ 'alpha' || $GITHUB_REF_NAME =~ 'beta' || $GITHUB_REF_NAME =~ 'rc' ]]; then + echo "This is a prerelease." + PRERELEASE=true + fi + echo "is_prerelease=$PRERELEASE" >> $GITHUB_ENV + + # @see https://github.com/actions/create-release + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: v${{ github.ref_name }} + body: Please refer to [CHANGELOG.md](https://github.com/studiometa/wp-toolkit/blob/${{ github.ref_name }}/CHANGELOG.md) for details. + draft: false + prerelease: ${{ env.is_prerelease }} diff --git a/CHANGELOG.md b/CHANGELOG.md index c665759..858a61e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,4 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added +- **Helpers:** + + Add a `RequestHelper` class ([#25](https://github.com/studiometa/wp-toolkit/pull/25)) + + Add a `request(): Request` function based on [symfony/http-foundation](https://github.com/symfony/http-foundation) ([#25](https://github.com/studiometa/wp-toolkit/pull/25)) + + Add an `EnvHelper` class ([#25](https://github.com/studiometa/wp-toolkit/pull/25)) + + Add an `env( string $key ): string` function ([#25](https://github.com/studiometa/wp-toolkit/pull/25)) - **CleanupManager:** Disable XML-RPC by default ([#21](https://github.com/studiometa/wp-toolkit/pull/21)) diff --git a/composer.json b/composer.json index e5d392e..132d74a 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ "require": { "php": "^7.3|^8.0", "symfony/yaml": "^5.1", - "studiometa/webpack-config": "^4.0" + "studiometa/webpack-config": "^4.0|^5.0", + "symfony/http-foundation": "^5.4|^6.3" }, "require-dev": { "squizlabs/php_codesniffer": "^3.4", @@ -21,7 +22,10 @@ "autoload": { "psr-4": { "Studiometa\\WPToolkit\\": "src/" - } + }, + "files": [ + "src/functions.php" + ] }, "scripts": { "phpcs": "phpcs -s --colors --standard=./phpcs.xml", diff --git a/composer.lock b/composer.lock index 25b7749..9ab6df3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3673c457682ecd22e94f372b339a4700", + "content-hash": "10e1bff29546b78d4a3481121e3101fa", "packages": [ { "name": "anahkiasen/html-object", @@ -54,16 +54,16 @@ }, { "name": "studiometa/webpack-config", - "version": "4.0.6", + "version": "5.3.0", "source": { "type": "git", "url": "https://github.com/studiometa/webpack-config.git", - "reference": "58c20fcecb52d832ef72cc98baa5db40d2c237d4" + "reference": "e7f09bc56d43a257937183e6be8a124408b248eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/studiometa/webpack-config/zipball/58c20fcecb52d832ef72cc98baa5db40d2c237d4", - "reference": "58c20fcecb52d832ef72cc98baa5db40d2c237d4", + "url": "https://api.github.com/repos/studiometa/webpack-config/zipball/e7f09bc56d43a257937183e6be8a124408b248eb", + "reference": "e7f09bc56d43a257937183e6be8a124408b248eb", "shasum": "" }, "require": { @@ -95,9 +95,9 @@ "description": "PHP Helpers for @studiometa/webpack-config", "support": { "issues": "https://github.com/studiometa/webpack-config/issues", - "source": "https://github.com/studiometa/webpack-config/tree/4.0.6" + "source": "https://github.com/studiometa/webpack-config/tree/5.3.0" }, - "time": "2022-10-25T22:39:10+00:00" + "time": "2023-10-26T20:50:18+00:00" }, { "name": "symfony/deprecation-contracts", @@ -166,6 +166,82 @@ ], "time": "2022-01-02T09:53:40+00:00" }, + { + "name": "symfony/http-foundation", + "version": "v5.4.28", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-foundation.git", + "reference": "365992c83a836dfe635f1e903ccca43ee03d3dd2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/365992c83a836dfe635f1e903ccca43ee03d3dd2", + "reference": "365992c83a836dfe635f1e903ccca43ee03d3dd2", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-mbstring": "~1.1", + "symfony/polyfill-php80": "^1.16" + }, + "require-dev": { + "predis/predis": "~1.0", + "symfony/cache": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^5.4.12|^6.0.12|^6.1.4", + "symfony/mime": "^4.4|^5.0|^6.0", + "symfony/rate-limiter": "^5.2|^6.0" + }, + "suggest": { + "symfony/mime": "To use the file extension guesser" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpFoundation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Defines an object-oriented layer for the HTTP specification", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/http-foundation/tree/v5.4.28" + }, + "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": "2023-08-21T07:23:18+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.26.0", @@ -2871,5 +2947,5 @@ "php": "^7.3|^8.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Helpers/EnvHelper.php b/src/Helpers/EnvHelper.php new file mode 100644 index 0000000..a9ce915 --- /dev/null +++ b/src/Helpers/EnvHelper.php @@ -0,0 +1,32 @@ + + * @copyright 2021 Studio Meta + * @license https://opensource.org/licenses/MIT + * @since 1.1.0 + */ + +namespace Studiometa\WPToolkit\Helpers; + +/** + * Request helper class. + */ +class EnvHelper { + /** + * Get an environment variable value. + * + * @param string $key The variable name. + * @return string + */ + public static function get( string $key ): string { + // phpcs:ignore + /** @var array Good type. */ + $env = $_ENV; + // In some environment, values are not available in the `$_ENV` variables, + // so we use `getenv` as a fallback to try and get the value. + return $env[ $key ] ?? (string) getenv( $key ); + } +} diff --git a/src/Helpers/PluginHelper.php b/src/Helpers/PluginHelper.php index e26564e..4a2ac44 100644 --- a/src/Helpers/PluginHelper.php +++ b/src/Helpers/PluginHelper.php @@ -7,7 +7,6 @@ * @copyright 2021 Studio Meta * @license https://opensource.org/licenses/MIT * @since 1.0.0 - * @version 1.0.0 */ namespace Studiometa\WPToolkit\Helpers; diff --git a/src/Helpers/RequestHelper.php b/src/Helpers/RequestHelper.php new file mode 100644 index 0000000..7481a4e --- /dev/null +++ b/src/Helpers/RequestHelper.php @@ -0,0 +1,42 @@ + + * @copyright 2021 Studio Meta + * @license https://opensource.org/licenses/MIT + * @since 1.1.0 + */ + +namespace Studiometa\WPToolkit\Helpers; + +use Symfony\Component\HttpFoundation\HeaderBag; +use Symfony\Component\HttpFoundation\InputBag; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\ParameterBag; + +/** + * Request helper class. + */ +class RequestHelper { + /** + * Request instance. + * + * @var Request|null + */ + private static $request = null; + + /** + * Get the Request instance. + * + * @return Request + */ + public static function get(): Request { + if ( is_null( self::$request ) ) { + self::$request = Request::createFromGlobals(); + } + + return self::$request; + } +} diff --git a/src/functions.php b/src/functions.php new file mode 100644 index 0000000..4b4124e --- /dev/null +++ b/src/functions.php @@ -0,0 +1,35 @@ + + * @copyright 2023 Studio Meta + * @license https://opensource.org/licenses/MIT + * @since 1.1.0 + */ + +namespace Studiometa\WPToolkit; + +use Symfony\Component\HttpFoundation\Request; +use Studiometa\WPToolkit\Helpers\RequestHelper; +use Studiometa\WPToolkit\Helpers\EnvHelper; + +/** + * Get the Request instance. + * + * @return Request + */ +function request(): Request { + return RequestHelper::get(); +} + +/** + * Get an environment variable value. + * + * @param string $key The variable name. + * @return string + */ +function env( string $key ): string { + return EnvHelper::get( $key ); +}