From 8f4f4e71b9aadda936f5a72baa16cbaf20574bae Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 2 Aug 2026 14:40:02 +0200 Subject: [PATCH 1/3] Provide devcontainers for GitHub contributors --- .devcontainer/Dockerfile | 17 +++++++++++++++++ .devcontainer/devcontainer.json | 26 ++++++++++++++++++++++++++ README.md | 16 ++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..95f8c1453 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,17 @@ +FROM mcr.microsoft.com/devcontainers/php:1-8.4-bookworm + +# The base image ships a broken yarn apt source (missing signing key) which +# makes `apt-get update` fail; drop it since this project doesn't need node/yarn. +RUN rm -f /etc/apt/sources.list.d/yarn.list + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends jq \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# ds is pinned to v1, since v2 (the only version building against PHP 8.4 via +# PECL/docker-php-ext-install) dropped Vector/Deque/Stack/Queue/PriorityQueue. +RUN curl -L -o install-php-extensions \ + https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions \ + && chmod +x install-php-extensions \ + && ./install-php-extensions gmp ds-^1@stable intl \ + && rm install-php-extensions diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..2ec3339fa --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +{ + "name": "Exercism PHP", + "build": { + "dockerfile": "Dockerfile" + }, + "containerEnv": { + "XDEBUG_MODE": "off" + }, + "postCreateCommand": "composer install", + "customizations": { + "vscode": { + "extensions": [ + "bmewburn.vscode-intelephense-client", + "recca0120.vscode-phpunit", + "obliviousharmony.vscode-php-codesniffer" + ], + "settings": { + // intelephense replaces VS Code's built-in PHP language features; leaving both + // enabled causes duplicate/conflicting suggestions. + "php.suggest.basic": false, + // Required for the phpcs extension to pick up this repo's phpcs.xml at all. + "phpCodeSniffer.standard": "Automatic" + } + } + } +} diff --git a/README.md b/README.md index 73d530b65..f06afdb09 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,26 @@ Exercism exercises in PHP Follow these instructions to contribute to the PHP track. To solve the exercises, head to the [PHP track][exercism-track-home] and check the [documentation][exercism-track-installation]. +## Quick Start with Dev Containers + +This repo includes a [dev container](.devcontainer) that provides PHP 8.4, Composer, `jq` and all other dependencies out of the box. +Open the repo in [VS Code][vscode-devcontainers] (or [GitHub Codespaces][github-codespaces]) and select "Reopen in Container" - `composer install` runs automatically once it starts. + ## Install Dependencies The following system dependencies are required: - `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer]. - [`bash` shell][gnu-bash]. -- PHP V8.4+ CLI. +- PHP V8.4+ CLI, with the following extensions: + - `ds` (V1.x) + - `intl` + - Default modules: `Core`, `ctype`, `date`, `dom`, `fileinfo`, `filter`, `hash`, `iconv`, `json`, `libxml`, `mbstring`, `pcre`, `random`, `Reflection`, `SimpleXML`, `sodium`, `SPL`, `standard`, `tokenizer`, `xml`, `xmlreader`, `xmlwriter`, `zlib` - An active Internet connection for installing required tools / composer packages. - [`jq`][jq], if you change the difficulty or add a practice exercise. +The [dev container](.devcontainer) already provides all of the above. + Run the following command to get started with this project: ```shell @@ -98,7 +108,9 @@ Run `bin/order-exercises.sh` when you set the exercise difficulty to a sensible [exercism-track-home]: https://exercism.org/docs/tracks/php [exercism-track-installation]: https://exercism.org/docs/tracks/php/installation [exercism-track-installation-composer]: https://exercism.org/docs/tracks/php/installation#h-install-composer +[github-codespaces]: https://docs.github.com/en/codespaces/overview [gnu-bash]: https://www.gnu.org/software/bash/ +[jq]: https://jqlang.org/ [local-file-phpcs-config]: phpcs.xml [psr-12]: https://www.php-fig.org/psr/psr-12 -[jq]: https://jqlang.org/ +[vscode-devcontainers]: https://code.visualstudio.com/docs/devcontainers/containers From a6bd0b250de9b5be9be96591cdcf521434f4b5b3 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 2 Aug 2026 15:10:01 +0200 Subject: [PATCH 2/3] PHPUnit / PHPCS VSCode extensions unusable PHPUnit cannot be used directly, the extension does not work for us. PHPCS extension requires advanced setup to be used in a container, so don't provide it. --- .devcontainer/devcontainer.json | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2ec3339fa..f087f6828 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,16 +10,10 @@ "customizations": { "vscode": { "extensions": [ - "bmewburn.vscode-intelephense-client", - "recca0120.vscode-phpunit", - "obliviousharmony.vscode-php-codesniffer" + "bmewburn.vscode-intelephense-client" ], "settings": { - // intelephense replaces VS Code's built-in PHP language features; leaving both - // enabled causes duplicate/conflicting suggestions. - "php.suggest.basic": false, - // Required for the phpcs extension to pick up this repo's phpcs.xml at all. - "phpCodeSniffer.standard": "Automatic" + "php.suggest.basic": false } } } From 54c331fa550dde5b787a4c27cf3aad732080cc8b Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 2 Aug 2026 15:43:19 +0200 Subject: [PATCH 3/3] Update base image --- .devcontainer/Dockerfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 95f8c1453..12d9112ca 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,4 @@ -FROM mcr.microsoft.com/devcontainers/php:1-8.4-bookworm - -# The base image ships a broken yarn apt source (missing signing key) which -# makes `apt-get update` fail; drop it since this project doesn't need node/yarn. -RUN rm -f /etc/apt/sources.list.d/yarn.list +FROM mcr.microsoft.com/devcontainers/php:4-8.4-bookworm RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install --no-install-recommends jq \