|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +## Project |
| 4 | + |
| 5 | +Smarty v5 — PHP template engine. Single Composer package (`smarty/smarty`), namespace `Smarty\`, source in `src/`, autoloaded via PSR-4. Supports PHP 7.2–8.5. |
| 6 | + |
| 7 | +## Commands |
| 8 | + |
| 9 | +```bash |
| 10 | +# Install dependencies |
| 11 | +composer install |
| 12 | + |
| 13 | +# Regenerate lexers and parsers (required before tests; CI runs this) |
| 14 | +make -B |
| 15 | + |
| 16 | +# Run all tests |
| 17 | +php ./vendor/phpunit/phpunit/phpunit |
| 18 | + |
| 19 | +# Run a single test file |
| 20 | +php ./vendor/phpunit/phpunit/phpunit tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php |
| 21 | + |
| 22 | +# Run tests matching a PHPUnit group |
| 23 | +php ./vendor/phpunit/phpunit/phpunit --group 20221124 |
| 24 | + |
| 25 | +# Run tests excluding slow group |
| 26 | +php ./vendor/phpunit/phpunit/phpunit --exclude-group slow |
| 27 | +``` |
| 28 | + |
| 29 | +There is no linter or static analysis configured. No typecheck step. |
| 30 | + |
| 31 | +## Generated code — do not hand-edit |
| 32 | + |
| 33 | +Four files are generated from grammar/lexer definitions via `make`: |
| 34 | + |
| 35 | +| Source (edit this) | Generated (do not edit) | |
| 36 | +|---|---| |
| 37 | +| `src/Lexer/TemplateLexer.plex` | `src/Lexer/TemplateLexer.php` | |
| 38 | +| `src/Lexer/ConfigfileLexer.plex` | `src/Lexer/ConfigfileLexer.php` | |
| 39 | +| `src/Parser/TemplateParser.y` | `src/Parser/TemplateParser.php` | |
| 40 | +| `src/Parser/ConfigfileParser.y` | `src/Parser/ConfigfileParser.php` | |
| 41 | + |
| 42 | +After editing a `.plex` or `.y` file, run `make -B` to regenerate. The generators require the `smarty/smarty-lexer` dev dependency. |
| 43 | + |
| 44 | +## Architecture |
| 45 | + |
| 46 | +- `src/Smarty.php` — main class, extends `TemplateBase`. Version constant: `Smarty::SMARTY_VERSION`. |
| 47 | +- `src/Compile/`, `src/Compiler/` — template compilation pipeline. |
| 48 | +- `src/Lexer/`, `src/Parser/` — lexer/parser (generated, see above). |
| 49 | +- `src/Extension/` — extension system (`ExtensionInterface`, `CoreExtension`, `DefaultExtension`, `BCPluginsAdapter`). |
| 50 | +- `src/Runtime/` — runtime helpers (foreach, capture, inheritance, tpl functions). |
| 51 | +- `src/Resource/`, `src/Cacheresource/` — template resource and cache resource handlers. |
| 52 | +- `src/BlockHandler/`, `src/FunctionHandler/`, `src/Filter/` — built-in tags, functions, and filters. |
| 53 | +- `libs/Smarty.class.php` — non-Composer autoload stub. Points to `src/`. Not the main source. |
| 54 | +- `src/functions.php` — global helper functions, always loaded via Composer `files` autoload. |
| 55 | + |
| 56 | +## Tests |
| 57 | + |
| 58 | +- Framework: PHPUnit 7.5/8.5 (bootstrap: `tests/Bootstrap.php`). |
| 59 | +- All tests extend `PHPUnit_Smarty` (defined in `tests/PHPUnit_Smarty.php`), which provides `setUpSmarty($dir)`. |
| 60 | +- Test suite root: `tests/UnitTests/`. Typical test `setUp()` calls `$this->setUpSmarty(__DIR__)`. |
| 61 | +- Each test directory may have its own `templates/`, `configs/` subdirectories. Compiled output goes to `templates_c/` and `cache/` (auto-created by the test harness). |
| 62 | +- Three test files are excluded in `phpunit.xml`: Memcache, APC, and HttpModifiedSince tests (require external services). |
| 63 | +- Tests needing MySQL/PDO are gated by constants in `tests/Config.php` (disabled by default). |
| 64 | + |
| 65 | +## CI |
| 66 | + |
| 67 | +GitHub Actions (`.github/workflows/ci.yml`): matrix of PHP 7.2–8.5 on ubuntu + windows. Steps: `composer install` → `make -B` → `phpunit`. No deploy step. |
| 68 | + |
| 69 | +## Docs |
| 70 | + |
| 71 | +Markdown in `docs/`, built with mkdocs + Material theme. Preview: `mkdocs serve`. Published via `mike deploy 5.x`. |
| 72 | + |
| 73 | +## Release |
| 74 | + |
| 75 | +`./make-release.sh <version>` — only v5.x.x. Updates changelog and version constant, creates a merge commit and tag on `master`. |
0 commit comments