Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.dockerignore
.editorconfig
.env
.git
.gitattributes
.gitignore
.htaccess
.idea
*.md
*.txt

vendor
composer.lock

tests/_output/*.*
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{xml,sh}]
indent_size = 2

[.travis.yml]
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10

- package-ecosystem: "docker"
directory: "/resources/docker"
schedule:
interval: "weekly"
37 changes: 37 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Docker build"

on:
push:
paths:
- 'resources/docker/**'
- 'docker-compose.yml'
- '.github/workflows/docker-build.yml'
pull_request:
paths:
- 'resources/docker/**'
- 'docker-compose.yml'
workflow_dispatch:

permissions: { }

jobs:
build:
name: "Build image (PHP ${{ matrix.php }})"
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4']
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: "Build the v5 image"
run: |
docker build \
--file resources/docker/Dockerfile \
--build-arg PHP_VERSION=${{ matrix.php }} \
--build-arg PHALCON_VARIANT=v5 \
--tag tutorial:php${{ matrix.php }}-v5 \
.
110 changes: 110 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: "Tutorial CI"

on:
push:
paths-ignore:
- '**.md'
- '**.txt'
pull_request:
workflow_dispatch:

env:
# Phalcon v5 C extension constraint (installed from source via PIE)
PHALCON_CONSTRAINT: "^5.0"
EXTENSIONS: "mbstring, intl, json, pdo_mysql"

permissions: { }

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
quality:
name: "Code quality"
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 1

- name: "Setup PHP"
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: '8.3'
extensions: ${{ env.EXTENSIONS }}
tools: composer:v2

- name: "Validate composer"
run: composer validate --no-check-all --no-check-publish

- name: "Install dependencies"
uses: ramsey/composer-install@26d8a556604053a9612623447203a691f406fbe6 # v4
with:
composer-options: "--prefer-dist"

- name: "PHPCS"
run: composer cs

- name: "PHPStan"
run: composer analyze

- name: "PHP CS Fixer (dry-run)"
run: composer cs-fixer

tests:
name: "Tests (PHP ${{ matrix.php }}, Phalcon ${{ matrix.variant }})"
permissions:
contents: read
runs-on: ubuntu-latest
needs:
- quality
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
variant: ['v5', 'v6']
services:
mysql:
image: mysql:8.0
ports:
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: tutorial
options: >-
--health-cmd "mysqladmin ping --silent"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 1

- name: "Setup PHP"
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.EXTENSIONS }}
tools: composer:v2

- name: "Install Phalcon v5 (cphalcon) via PIE"
if: matrix.variant == 'v5'
run: |
curl -fsSL https://github.com/php/pie/releases/latest/download/pie.phar -o pie.phar
sudo "$(which php)" pie.phar install --no-interaction "phalcon/cphalcon:${{ env.PHALCON_CONSTRAINT }}"
php -m | grep -i phalcon

- name: "Install dependencies"
uses: ramsey/composer-install@26d8a556604053a9612623447203a691f406fbe6 # v4
with:
composer-options: "--prefer-dist"

- name: "Load database schema"
run: mysql -h 127.0.0.1 -uroot -psecret tutorial < resources/schemas/tutorial.sql

- name: "Tests"
run: composer test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.env
.idea
.DS_Store
public/.DS_Store
vendor/
tests/_output/*
!tests/_output/.gitignore
Empty file removed .phalcon/.gitkeep
Empty file.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

All notable changes are documented here. The format is based on [Keep a Changelog][keep_a_changelog] and this project adheres to [Semantic Versioning][semantic_versioning].

## [Unreleased]

### Added

- PSR-4 namespaced source under `src/` (`Tutorial\`)
- Composer scripts and tooling: PHPCS + PHP-CS-Fixer (PSR-12), PHPStan (level 6), Talon functional smoke test
- Dual-variant Docker image (Phalcon v5 extension / v6 Composer package) via `PHALCON_VARIANT`
- GitHub Actions CI (quality + test matrix) and Dependabot
- `.editorconfig`, `.gitattributes`, `.dockerignore`

### Changed

- Restructured to the PDS skeleton; tooling config centralized under `resources/`
- Bootstrap uses Composer autoloading and reads the database connection from environment variables
- Docker refreshed to a single `PHP_VERSION`-parameterized image on `mysql:8.0`, served from `/srv`
- Local styling replaces the removed Bootstrap CDN link

### Fixed

- Database name unified to `tutorial` (schema, app, and compose were inconsistent)

### Removed

- Per-version Docker folders (`8.0`–`8.3`), `bin/import_db.sh`, and Vökuró copy-paste leftovers

## [5.6.0](https://github.com/phalcon/tutorial/releases/tag/v5.6.0) (2024-01-14)

### Changed
Expand Down
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Vökuró is an open source project and a volunteer effort.
# Contributing

*We only accept bug reports, new feature requests and pull requests in GitHub*.
The Phalcon Tutorial is an open source project and a volunteer effort.

Vökuró does not have human resources fully dedicated to the maintenance of this software.
If you want something to be improved or you want a new feature please submit a Pull Request.
*We only accept bug reports, new feature requests and pull requests on GitHub.*

If you want something improved or you want a new feature, please submit a Pull Request.

Thanks!

Thanks! <br />
Phalcon Team
95 changes: 48 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
# Phalcon Tutorial

Phalcon is a web framework for PHP delivered as a C extension providing high
performance and lower resource consumption.
This is a small sample application for the [Phalcon PHP Framework][phalcon]: a
simple registration form built as an MVC app. It is the companion code for the
[Basic Tutorial][tutorial] documentation page and runs on **both Phalcon 5**
(the C extension) and **Phalcon 6** (the `phalcon/phalcon` Composer package).

This is a very simple tutorial to understand the basis of work with Phalcon.
## Requirements

Check out an [explanation article][1].
- PHP >= 8.1
- Phalcon 5 (C extension) **or** Phalcon 6 (Composer package)
- MySQL 8.0
- Docker (recommended for local development)

## Get Started
## Quick start (Docker)

### Requirements

To run this application on your machine, you need at least:

* PHP >= 8.0+
* Server Any of the following
* [Apache][2] Web Server with [mod_rewrite][3] enabled
* [Nginx][4] Web Server
* Latest stable [Phalcon Framework release][5] extension enabled
```shell
cp resources/.env.example .env
docker compose up -d --build
```

## Running the application locally
Then open <http://localhost:8080>. The database schema and a seed user are
loaded automatically on first boot.

* Clone the repository to a folder on your machine
* Navigate to that folder
* Run `docker compose up -d`
* After the build process is completed, you will have the following:
* PHP 8.0 (`tutorial-8.0`)
* PHP 8.1 (`tutorial-8.1`)
* PHP 8.2 (`tutorial-8.2`)
* PHP 8.3 (`tutorial-8.3`)
* You can check the application on your local browser by finding the IP address of the chosen environment and launching it. For example, if you wish to check the PHP 8.3 environment, type the following in your terminal:
To run on Phalcon 6 instead of 5, set `PHALCON_VARIANT=v6` in `.env` (or export
it) and rebuild:

```shell
docker inspect tutorial-8.3
PHALCON_VARIANT=v6 docker compose up -d --build
```
This will output a JSON file, where you can find the IP address of the container on your local machine.

To open a shell in the app container:

```shell
...
"EndpointID": "563ba90563ffb7ad5c30689f1216ec4c2e1625d170eb0279e78c001973464691",
"Gateway": "172.29.0.1",
"IPAddress": "172.29.0.5",
"IPPrefixLen": 16,
...
docker compose exec app bash
```

Launch a browser and visit the site using that IP address (`http://172.29.0.5`)
## Composer scripts

To enter an environment and run different commands, such as populating the database:
| Script | What it does |
|---------------------------|-----------------------------------------------|
| `composer cs` | Check coding standard (PSR-12) with PHPCS |
| `composer cs-fix` | Auto-fix coding standard with PHPCBF |
| `composer cs-fixer` | Check style with PHP-CS-Fixer (dry-run) |
| `composer cs-fixer-fix` | Apply PHP-CS-Fixer changes |
| `composer analyze` | Static analysis with PHPStan (level 6) |
| `composer test` | Run the functional smoke test (Talon) |

## Project layout

This project follows the [PDS skeleton][pds]:

```shell
docker exec -it tutorial-8.3 /bin/bash
```
docs/ documentation
public/ web root (index.php, css)
resources/ tooling configs, docker, schema, .env.example
src/ application source (PSR-4 Tutorial\)
tests/ Talon functional test
```

## License

Phalcon Tutorial is open-sourced software licensed under the [MIT][6]. © Phalcon Framework Team and
contributors

[1]: https://docs.phalcon.io/latest/tutorial-basic
[2]: http://httpd.apache.org/
[3]: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
[4]: http://nginx.org/
[5]: https://github.com/phalcon/cphalcon/releases
[6]: https://github.com/phalcon/tutorial/blob/master/docs/LICENSE
[7]: https://github.com/phalcon/phalcon-devtools
[8]: https://docker.com
The Phalcon Tutorial is open-sourced software licensed under the [MIT license][mit].
© Phalcon Framework Team and contributors.

[phalcon]: https://phalcon.io
[tutorial]: https://docs.phalcon.io/latest/tutorial-basic
[pds]: https://github.com/php-pds/skeleton
[mit]: https://github.com/phalcon/tutorial/blob/master/LICENSE
6 changes: 0 additions & 6 deletions bin/import_db.sh

This file was deleted.

Loading