switch to php composer
This commit is contained in:
@@ -32,7 +32,7 @@ namespace ElixForms\Common;
|
|||||||
|
|
||||||
Le pagine importano con:
|
Le pagine importano con:
|
||||||
```php
|
```php
|
||||||
require_once __DIR__ . '/../common/ElixFormsComponent.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
use ElixForms\Common\ElixFormsComponent;
|
use ElixForms\Common\ElixFormsComponent;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ Questa struttura è l'equivalente PHP del monorepo React in `react/`.
|
|||||||
|
|
||||||
```
|
```
|
||||||
elixforms-custom-pages/
|
elixforms-custom-pages/
|
||||||
|
├── composer.json ← Configurazione Composer e autoload PSR-4
|
||||||
|
├── vendor/ ← Autoloader generato (non versionato)
|
||||||
├── react/ ← Custom pages React (esistente)
|
├── react/ ← Custom pages React (esistente)
|
||||||
└── php/ ← Custom pages PHP
|
└── php/ ← Custom pages PHP
|
||||||
├── AGENTS.md ← Regole dell'agente PHP
|
├── AGENTS.md ← Regole dell'agente PHP
|
||||||
@@ -35,7 +37,7 @@ elixforms-custom-pages/
|
|||||||
|
|
||||||
Ogni pagina (es. `scelta-carriera/`) è un file PHP autonomo che:
|
Ogni pagina (es. `scelta-carriera/`) è un file PHP autonomo che:
|
||||||
|
|
||||||
1. **Include la libreria `common/`** tramite `require_once`
|
1. **Carica l'autoloader Composer** tramite `vendor/autoload.php`
|
||||||
2. **Definisce una classe** che estende `ElixFormsComponent`
|
2. **Definisce una classe** che estende `ElixFormsComponent`
|
||||||
3. **Sovrascrive `createCustomFormFields()`** per i campi specifici
|
3. **Sovrascrive `createCustomFormFields()`** per i campi specifici
|
||||||
4. **Istanzia e renderizza** la pagina con `echo $page->render()`
|
4. **Istanzia e renderizza** la pagina con `echo $page->render()`
|
||||||
@@ -50,13 +52,10 @@ Il progetto usa **namespace PSR-4**:
|
|||||||
namespace ElixForms\Common; // Per le classi in common/
|
namespace ElixForms\Common; // Per le classi in common/
|
||||||
```
|
```
|
||||||
|
|
||||||
L'autoloading è gestito manualmente con `require_once` (non Composer):
|
L'autoloading PSR-4 è gestito da Composer:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
require_once __DIR__ . '/../common/ElixFormsComponent.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
// ElixFormsComponent.php include internamente:
|
|
||||||
// - QueryParamHelper.php
|
|
||||||
// - ElixFormsElement.php
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Requisiti PHP
|
## Requisiti PHP
|
||||||
@@ -108,7 +107,7 @@ Identica alla versione React:
|
|||||||
| **Linguaggio** | TypeScript/JSX | PHP 8.0+ |
|
| **Linguaggio** | TypeScript/JSX | PHP 8.0+ |
|
||||||
| **Rendering** | Client-side | Server-side |
|
| **Rendering** | Client-side | Server-side |
|
||||||
| **Build tool** | Vite (single bundle JS) | Nessuno (file serviti direttamente) |
|
| **Build tool** | Vite (single bundle JS) | Nessuno (file serviti direttamente) |
|
||||||
| **Dipendenze** | npm (React, Vite, plugin) | Nessuna (PHP built-in) |
|
| **Dipendenze** | npm (React, Vite, plugin) | Composer (autoload PSR-4) |
|
||||||
| **CSS loading** | `@import url()` + CSS injection plugin | `<link>` tags |
|
| **CSS loading** | `@import url()` + CSS injection plugin | `<link>` tags |
|
||||||
| **State management** | React state (`this.setState`) | Stateless (`$_GET`) |
|
| **State management** | React state (`this.setState`) | Stateless (`$_GET`) |
|
||||||
| **Deploy** | Upload del bundle `.js` | Upload dei file `.php` |
|
| **Deploy** | Upload del bundle `.js` | Upload dei file `.php` |
|
||||||
@@ -116,9 +115,10 @@ Identica alla versione React:
|
|||||||
|
|
||||||
## Deploy su Apache
|
## Deploy su Apache
|
||||||
|
|
||||||
1. Caricare la cartella `php/` sul server Apache
|
1. Eseguire `composer install --no-dev --optimize-autoloader` dalla root del repository
|
||||||
2. Configurazione Apache minima:
|
2. Caricare sul server le cartelle `php/` e `vendor/`, mantenendole allo stesso livello
|
||||||
|
3. Configurazione Apache minima:
|
||||||
- `mod_php` o `php-fpm` abilitato
|
- `mod_php` o `php-fpm` abilitato
|
||||||
- `DirectoryIndex index.php` (default Apache)
|
- `DirectoryIndex index.php` (default Apache)
|
||||||
3. La pagina è accessibile via URL: `https://server/php/nome-pagina/`
|
4. La pagina è accessibile via URL: `https://server/php/nome-pagina/`
|
||||||
4. elixForms reindirizza l'utente alla pagina passando i parametri via query string
|
5. elixForms reindirizza l'utente alla pagina passando i parametri via query string
|
||||||
|
|||||||
+2
-1
@@ -9,6 +9,7 @@ lerna-debug.log*
|
|||||||
|
|
||||||
# Dependency directories
|
# Dependency directories
|
||||||
node_modules
|
node_modules
|
||||||
|
vendor
|
||||||
|
|
||||||
# Build generated files
|
# Build generated files
|
||||||
dist
|
dist
|
||||||
@@ -54,4 +55,4 @@ obj
|
|||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
# Configuration files
|
# Configuration files
|
||||||
**/config.json
|
**/config.json
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@echo off
|
||||||
|
SETLOCAL EnableDelayedExpansion
|
||||||
|
echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1
|
||||||
|
echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1
|
||||||
|
cd /D "%~dp0"
|
||||||
|
|
||||||
|
@pwsh -NoProfile -ExecutionPolicy Bypass -Command .\scripts\composer-dump-autoload.ps1
|
||||||
|
|
||||||
|
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||||
|
ENDLOCAL
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@echo off
|
||||||
|
SETLOCAL EnableDelayedExpansion
|
||||||
|
echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1
|
||||||
|
echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1
|
||||||
|
cd /D "%~dp0"
|
||||||
|
|
||||||
|
@pwsh -NoProfile -ExecutionPolicy Bypass -Command .\scripts\composer-install.ps1
|
||||||
|
|
||||||
|
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||||
|
ENDLOCAL
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "elixforms-web-pages/pages",
|
||||||
|
"description": "Custom web pages PHP per elixForms",
|
||||||
|
"license": "proprietary",
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.0"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"ElixForms\\Common\\": "php/common/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+20
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"_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": "23a05b8814892947b8a622a763a2ace5",
|
||||||
|
"packages": [],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": {},
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": {
|
||||||
|
"php": ">=8.0"
|
||||||
|
},
|
||||||
|
"platform-dev": {},
|
||||||
|
"plugin-api-version": "2.9.0"
|
||||||
|
}
|
||||||
+5
-3
@@ -14,7 +14,8 @@ In caso di conflitti di ID (ad esempio con input `hidden`), applicare il suffiss
|
|||||||
|
|
||||||
2. **Namespace PSR-4**:
|
2. **Namespace PSR-4**:
|
||||||
- Tutte le classi nella libreria comune usano il namespace `ElixForms\Common;`.
|
- Tutte le classi nella libreria comune usano il namespace `ElixForms\Common;`.
|
||||||
- Il caricamento è manuale tramite `require_once __DIR__ . '/../common/ElixFormsComponent.php';`.
|
- L'autoload PSR-4 è gestito da Composer tramite `vendor/autoload.php`.
|
||||||
|
- Gli entry point includono `require_once __DIR__ . '/../../vendor/autoload.php';`; le classi comuni non devono includersi manualmente tra loro.
|
||||||
|
|
||||||
3. **Rendering Server-Side**:
|
3. **Rendering Server-Side**:
|
||||||
- I file PHP generano direttamente l'HTML server-side usando il design system Bootstrap Italia di UniPR.
|
- I file PHP generano direttamente l'HTML server-side usando il design system Bootstrap Italia di UniPR.
|
||||||
@@ -24,12 +25,13 @@ In caso di conflitti di ID (ad esempio con input `hidden`), applicare il suffiss
|
|||||||
- I checkbox inviano il proprio stato serializzato come stringa separata da virgole tramite un input hidden (gestito client-side da uno script JS automatico).
|
- I checkbox inviano il proprio stato serializzato come stringa separata da virgole tramite un input hidden (gestito client-side da uno script JS automatico).
|
||||||
|
|
||||||
## Deploy e Server Locale
|
## Deploy e Server Locale
|
||||||
- **Deploy**: Le cartelle vengono caricate direttamente su web server Apache.
|
- **Dipendenze**: dalla root del repository eseguire `composer install --optimize-autoloader` oppure `composer-install.bat`.
|
||||||
|
- **Deploy**: Eseguire `composer install --no-dev --optimize-autoloader` e caricare sul server sia `php/` sia `vendor/`, mantenendole allo stesso livello.
|
||||||
- **Server locale**:
|
- **Server locale**:
|
||||||
- **PHP CLI**: Avviare il server dalla cartella `php/` tramite `php -S localhost:8080` (le pagine saranno raggiungibili su `http://localhost:8080/<nome-pagina>/`).
|
- **PHP CLI**: Avviare il server dalla cartella `php/` tramite `php -S localhost:8080` (le pagine saranno raggiungibili su `http://localhost:8080/<nome-pagina>/`).
|
||||||
- **Docker**: Dalla root del repository, eseguire:
|
- **Docker**: Dalla root del repository, eseguire:
|
||||||
```bash
|
```bash
|
||||||
docker run --rm -p 8080:8080 -v "${PWD}/php:/app" -w /app php:8.2-cli php -S 0.0.0.0:8080
|
docker run --rm -p 8080:8080 -v "${PWD}:/app" -w /app/php php:8.2-cli php -S 0.0.0.0:8080
|
||||||
```
|
```
|
||||||
|
|
||||||
## Skill PHP Correlate
|
## Skill PHP Correlate
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace ElixForms\Common;
|
namespace ElixForms\Common;
|
||||||
|
|
||||||
require_once __DIR__ . '/QueryParamHelper.php';
|
|
||||||
require_once __DIR__ . '/ElixFormsElement.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe astratta base per le custom page PHP di elixForms.
|
* Classe astratta base per le custom page PHP di elixForms.
|
||||||
* Equivalente PHP di ElixFormsComponentAbstract.tsx nel progetto React.
|
* Equivalente PHP di ElixFormsComponentAbstract.tsx nel progetto React.
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: ../.docker/php/Dockerfile
|
dockerfile: ../.docker/php/Dockerfile
|
||||||
container_name: elixforms-www
|
container_name: elixforms-www
|
||||||
working_dir: /app
|
working_dir: /app/php
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
ports:
|
ports:
|
||||||
- "8080:8000"
|
- "8080:8000"
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- ..:/app
|
||||||
- ../.docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
|
- ../.docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
|
||||||
#environment:
|
#environment:
|
||||||
# XDEBUG_MODE: debug
|
# XDEBUG_MODE: debug
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
require_once __DIR__ . '/../common/ElixFormsComponent.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
require_once __DIR__ . '/../common/QueryParamHelper.php';
|
|
||||||
|
|
||||||
use ElixForms\Common\ElixFormsComponent;
|
use ElixForms\Common\ElixFormsComponent;
|
||||||
use ElixForms\Common\QueryParamHelper;
|
use ElixForms\Common\QueryParamHelper;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
require_once __DIR__ . '/../common/HttpClient.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
use ElixForms\Common\HttpClient;
|
use ElixForms\Common\HttpClient;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
require_once __DIR__ . '/../common/ElixFormsComponent.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
use ElixForms\Common\ElixFormsComponent;
|
use ElixForms\Common\ElixFormsComponent;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
& (Join-Path $PSScriptRoot 'composer-run-command.ps1') -Command dump-autoload -Arguments @('--optimize')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
& (Join-Path $PSScriptRoot 'composer-run-command.ps1') -Command install -Arguments @('--optimize-autoloader')
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
param(
|
||||||
|
[Parameter(Mandatory)][string]$Command,
|
||||||
|
[string[]]$Arguments = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$root = (Resolve-Path (Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) '..')).Path
|
||||||
|
|
||||||
|
$useDockerComposer = $false
|
||||||
|
$dockerRoot = $null
|
||||||
|
|
||||||
|
if (-not (Get-Command composer -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-Host "Composer non trovato localmente. Verifico se Docker è disponibile..."
|
||||||
|
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
||||||
|
throw "Composer non trovato e Docker mancante! Installa Composer o Docker prima di continuare."
|
||||||
|
}
|
||||||
|
|
||||||
|
$dockerRoot = $root -replace '\\', '/'
|
||||||
|
if ($dockerRoot -match '^([A-Za-z]):') {
|
||||||
|
$dockerRoot = "/$($Matches[1].ToLower())$($dockerRoot.Substring(2))"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Docker trovato. Verifico Composer tramite container..."
|
||||||
|
docker run --rm -v "$($dockerRoot):/app" -w /app composer:2 composer --version 2>&1
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "Docker presente, ma Composer non riesce ad avviarsi tramite container. Installa Composer localmente o verifica Docker."
|
||||||
|
}
|
||||||
|
|
||||||
|
$useDockerComposer = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
Push-Location $root
|
||||||
|
try {
|
||||||
|
if ($useDockerComposer) {
|
||||||
|
docker run --rm -v "$($dockerRoot):/app" -w /app composer:2 composer $Command @Arguments
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
composer $Command @Arguments
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "Composer ha restituito il codice di uscita $LASTEXITCODE."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user