From 616a4e3ea42a2a350ec870c63012f5e2c07b732d Mon Sep 17 00:00:00 2001 From: Colin Hutchinson Date: Tue, 6 Feb 2024 15:47:47 +0000 Subject: [PATCH] feat(php): adjust the template for PHP projects (#1) --- .dockerignore | 8 + .github/dependabot.yml | 15 +- .github/labeler.yml | 4 +- .github/settings.yml | 2 +- .github/template-sync.yml | 16 - .github/workflows/pre-commit.yml | 5 + .github/workflows/sync.yml | 21 -- .gitignore | 567 ++++++++++++++++++++++++------- .pre-commit-config.yaml | 14 +- Dockerfile | 39 +++ Makefile | 17 + composer.json | 21 ++ index.php | 3 + 13 files changed, 559 insertions(+), 173 deletions(-) create mode 100644 .dockerignore delete mode 100644 .github/template-sync.yml delete mode 100644 .github/workflows/sync.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 composer.json create mode 100644 index.php diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..01aa813 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.gitignore +Dockerfile +docker-compose.yml +README.md +vendor/ +node_modules/ +.php-cs-fixer.cache diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bdf8371..05a5f9a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,6 @@ --- version: 2 updates: -- package-ecosystem: pip - directory: / - schedule: - interval: daily - - package-ecosystem: docker directory: / schedule: @@ -16,15 +11,7 @@ updates: schedule: interval: daily -- package-ecosystem: npm - directory: /frontend/ - ignore: - - dependency-name: '*' - update-types: [version-update:semver-major] - schedule: - interval: daily - -- package-ecosystem: gitsubmodule +- package-ecosystem: composer directory: / schedule: interval: daily diff --git a/.github/labeler.yml b/.github/labeler.yml index dfc1d0b..c3cb4bc 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -5,5 +5,5 @@ docs: - '**/*.md' github_actions: - .github/** -python: -- '**/*.py' +php: +- '**/*.php' diff --git a/.github/settings.yml b/.github/settings.yml index 3e68873..597bcc7 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -130,7 +130,7 @@ branches: # Required. Require branches to be up to date before merging. strict: true # Required. The list of status checks to require in order to merge into this branch - contexts: [pre-commit, sync] + contexts: [pre-commit] # Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. enforce_admins: null # Prevent merge commits from being pushed to matching branches diff --git a/.github/template-sync.yml b/.github/template-sync.yml deleted file mode 100644 index 752e2f3..0000000 --- a/.github/template-sync.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -additional: -- template-docker -- template-github-release - -files: -- '!README.md' -- '!.gitignore' -- '!.pre-commit-config.yaml' -- '!.yamllint' -- '!.secrets.baseline' -- '!.github/pull.yml' -- '!.github/dependabot.yml' -- '!.github/template-sync.yml' -- '!.github/workflows/pre-commit-update.yml' -- '!.github/settings.yml' diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 1d86f80..8e958c5 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -18,6 +18,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4.1.1 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + tools: phpunit, phpcs, phpcbf, php-cs-fixer, phpstan + coverage: none - uses: actions/setup-python@v5.0.0 with: python-version: '3.8' diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml deleted file mode 100644 index 85d0f97..0000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: Sync the template repository - -on: # yamllint disable-line rule:truthy - pull_request: - push: - branches: main - -jobs: - sync: - runs-on: ubuntu-latest - - steps: - - name: Queue - uses: ahmadnassri/action-workflow-queue@v1.2 - - name: Checkout - uses: actions/checkout@v4.1.1 - - name: Sync - uses: ahmadnassri/action-template-repository-sync@v2.5.0 - with: - github-token: ${{ secrets.GH_TOKEN }} diff --git a/.gitignore b/.gitignore index a81c8ee..fd4958a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,138 +1,475 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class +##### Windows +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db -# C extensions -*.so +# Dump file +*.stackdump -# Distribution / packaging -.Python +# 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 + +##### 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 + +##### Backup +*.bak +*.gho +*.ori +*.orig +*.tmp + +##### GPG +secring.* + +##### Dropbox +# Dropbox settings and caches +.dropbox +.dropbox.attr +.dropbox.cache + +##### SynopsysVCS +# Waveform formats +*.vcd +*.vpd +*.evcd +*.fsdb + +# Default name of the simulation executable. A different name can be +# specified with this switch (the associated daidir database name is +# also taken from here): -o / +simv + +# Generated for Verilog and VHDL top configs +simv.daidir/ +simv.db.dir/ + +# Infrastructure necessary to co-simulate SystemC models with +# Verilog/VHDL models. An alternate directory may be specified with this +# switch: -Mdir= +csrc/ + +# Log file - the following switch allows to specify the file that will be +# used to write all messages from simulation: -l +*.log + +# Coverage results (generated with urg) and database location. The +# following switch can also be used: urg -dir .vdb +simv.vdb/ +urgReport/ + +# DVE and UCLI related files. +DVEfiles/ +ucli.key + +# When the design is elaborated for DirectC, the following file is created +# with declarations for C/C++ functions. +vc_hdrs.h + +##### SVN +.svn/ + +##### Mercurial +.hg/ +.hgignore +.hgsigs +.hgsub +.hgsubstate +.hgtags + +##### Bazaar +.bzr/ +.bzrignore + +##### CVS +/CVS/* +**/CVS/* +.cvsignore +*/.cvsignore + +##### TortoiseGit +# Project-level settings +/.tgitconfig + +##### PuTTY +# Private key +*.ppk + +##### Vim +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +##### 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 + +##### 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 +sftp-config-alt*.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 + +##### Notepad++ +# Notepad++ backups # +*.bak + +##### TextMate +*.tmproj +*.tmproject +tmtags + +##### VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +##### NetBeans +**/nbproject/private/ +**/nbproject/Makefile-*.mk +**/nbproject/Package-*.bash build/ -develop-eggs/ +nbbuild/ dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal +nbdist/ +.nb-gradle/ + +##### JetBrains +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# 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/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# 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 + +##### Eclipse +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target -# Flask stuff: -instance/ -.webassets-cache +# Tern plugin +.tern-project -# Scrapy stuff: -.scrapy +# TeXlipse plugin +.texlipse -# Sphinx documentation -docs/_build/ +# STS (Spring Tool Suite) +.springBeans -# PyBuilder -.pybuilder/ -target/ +# Code Recommenders +.recommenders/ -# Jupyter Notebook -.ipynb_checkpoints +# Annotation Processing +.apt_generated/ +.apt_generated_test/ -# IPython -profile_default/ -ipython_config.py +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock +##### Dreamweaver +# DW Dreamweaver added files +_notes +_compareTemp +configs/ +dwsync.xml +dw_php_codehinting.config +*.mno -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ +##### CodeKit +# General CodeKit files to ignore +config.codekit +config.codekit3 +/min -# Celery stuff -celerybeat-schedule -celerybeat.pid +##### Gradle +.gradle +**/build/ +!src/**/build/ -# SageMath parsed files -*.sage.py +# Ignore Gradle GUI config +gradle-app.setting -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar -# Spyder project settings -.spyderproject -.spyproject +# Cache of project +.gradletasknamecache -# Rope project settings -.ropeproject +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties -# mkdocs documentation -/site +##### Composer +composer.phar +/vendor/ -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json +# 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 +.php-cs-fixer.cache -# Pyre type checker -.pyre/ +##### PHP CodeSniffer +# gitignore for the PHP Codesniffer framework +# website: https://github.com/squizlabs/PHP_CodeSniffer +# +# Recommended template: PHP.gitignore -# pytype static type analyzer -.pytype/ +/wpcs/* -# Cython debug symbols -cython_debug/ +##### SASS +.sass-cache/ +*.css.map +*.sass.map +*.scss.map diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95169f6..3aea17b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,10 +16,6 @@ repos: - id: debug-statements - id: requirements-txt-fixer - id: fix-encoding-pragma -- repo: https://github.com/psf/black - rev: 24.1.1 - hooks: - - id: black - repo: https://github.com/PyCQA/bandit rev: 1.7.7 hooks: @@ -31,3 +27,13 @@ repos: - id: remove-crlf - id: forbid-tabs - id: remove-tabs +- repo: https://github.com/digitalpulp/pre-commit-php + rev: 1.4.0 + hooks: + - id: php-lint-all + - id: php-lint + - id: php-unit + # - id: php-cs + - id: php-cbf + - id: php-cs-fixer + - id: php-stan diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b57fe4c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# Use an official PHP image with Apache +FROM php:8.1-apache + +# Arguments to be passed at build time +ARG UID=1000 +ARG GID=1000 + +# Install system dependencies for Composer and required PHP extensions +RUN apt-get update && apt-get install -y \ + git \ + unzip \ + libzip-dev \ + zip \ + && docker-php-ext-install zip pdo pdo_mysql + +# Enable Apache mod_rewrite +RUN a2enmod rewrite + +# Install Composer globally +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Create a group and user with host's UID/GID +RUN groupadd -g $GID appuser && \ + useradd -u $UID -g appuser -m appuser + +# Change ownership of the web root and logs to the new user +RUN chown -R appuser:appuser /var/www /var/log/apache2 + +# Switch to the new user +USER appuser + +# Set the working directory in the container +WORKDIR /var/www/html + +# Copy the application source code +COPY --chown=appuser:appuser . . + +# Use Composer to install PHP dependencies +RUN composer install --no-interaction --optimize-autoloader --no-dev diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..248450f --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +# Define the Docker image name +IMAGE_NAME=template-php +# Define the container name +CONTAINER_NAME=template-php + +.PHONY: build run clean + +build: + docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) -t $(IMAGE_NAME) . + +run: build + docker stop $(CONTAINER_NAME) + docker run -d --rm --name $(CONTAINER_NAME) -p 8080:80 --user "$(shell id -u):$(shell id -g)" $(IMAGE_NAME) + +clean: + docker stop $(CONTAINER_NAME) || true && docker rm $(CONTAINER_NAME) || true + docker rmi $(IMAGE_NAME) || true diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8845c21 --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "hutchic-org/template", + "type": "library", + "autoload": { + "psr-4": { + "HutchicOrg\\Template\\": "src/" + } + }, + "authors": [ + { + "name": "Colin Hutchinson" + } + ], + "minimum-stability": "stable", + "require-dev": { + "phpunit/phpunit": "^9", + "squizlabs/php_codesniffer": "^3.6", + "friendsofphp/php-cs-fixer": "^3.49", + "phpstan/phpstan": "^1.10" + } +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..2c6ebd2 --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ +