This file provides guidance to Agents when working with code in this repository.
Prado is a component-based, event-driven PHP web framework. All framework source lives under framework/ (PSR-4 namespace Prado\). Tests mirror that structure under tests/unit/. Current version: 4.3.3; next release: 4.4.0.
# Code style check (dry-run)
vendor/bin/php-cs-fixer fix --dry-run framework/
# Code style fix (apply)
vendor/bin/php-cs-fixer fix framework/
# Static analysis
vendor/bin/phpstan analyse --memory-limit=1G
# Run all unit tests
vendor/bin/phpunit --testsuite unit
# Run tests for a specific class, function, or directory
vendor/bin/phpunit --testsuite unit --filter <test function, class, or directory>
# Code coverage (phpunit.xml declares framework/ as the source; the script sets XDEBUG_MODE)
composer coverage # text summary
composer coverage-html # HTML report in build/coverage
composer coverage -- --filter <class> --coverage-filter <path> # narrow a run
# javascript commands
composer jsfix # js code style fix
composer jstest # vitest unit test
# Generate API documentation
composer gendoc
# Playwright functional tests (PHP server on port 8037 starts automatically)
composer functest # Chromium only (faster for local iteration)
composer functionaltest # all three browsers (Chromium, Firefox, WebKit)Run these four checks in order — all must pass:
- PHP compile check (
php -l) vendor/bin/php-cs-fixer fix --dry-run framework/vendor/bin/phpstan analyse --memory-limit=1Gvendor/bin/phpunit --testsuite unit
Never add or change phpunit command options when unit testing — only run project unit tests as specified above. When testing a single class or cluster, only run tests for that class/directory. Measuring coverage is the exception: use the
composer coveragescripts, narrowing a run with--filterand--coverage-filter.
TComponent(framework/TComponent.php) — base class for nearly everything. Implements the property system (getters/setters via magic__get/__set), event system (attachEventHandler/raiseEvent), priority based behavior attachment,__clone,__sleep/__wakeup, and_getZappableSleepProps.TApplication(framework/TApplication.php) — top-level service container. Modules and services register with it via XML (or PHP) configuration; tests bootstrap one viatests/test_tools/phpunit_bootstrap.php.TModule/TService— pluggable units registered withTApplication.
TApplication
└─ Web Layer framework/Web/
THttpRequest, THttpResponse, THttpSession
TUrlManager / TUrlMapping (routing)
TAssetManager
Services/ (TPageService, TJsonService, TFeedService, TSoapService)
UI/ (TControl, TPage, TTemplateControl, WebControls/, ActiveControls/, JuiControls/)
└─ Data Layer framework/Data/
TDbConnection (PDO wrapper)
DataGateway/
└─ Caching framework/Caching/ (APC, Database, Etcd, Memcached, Redis, file-based)
└─ Security framework/Security/ (RBAC, TAuthManager, TSecurityManager, TPermissionsManager)
└─ I18N framework/I18N/ (TGlobalization, MessageSource, CultureInfo)
└─ Xml framework/Xml/ (TXmlDocument/TXmlElement with XPath, DOM compat, ArrayAccess)
└─ Util framework/Util/ (logging, behaviors, cron, mutexes, helpers, TCallChain, TVarDumper)
└─ PHPStan framework/PHPStan/ (custom static-analysis extensions for dynamic Prado properties)
onConfiguration → onInitComplete → onBeginRequest → onLoadState → onLoadStateComplete → onAuthentication → onAuthenticationComplete → onAuthorization → onAuthorizationComplete → onPreRunService → runService → onSaveState → onSaveStateComplete → onPreFlushOutput → flushOutput → onEndRequest / onError
onPreInit → initRecursive → onInitComplete → loadPageState (POST/Callback) → processPostData (POST/Callback) → onPreLoad → loadRecursive → processPostData (POST/Callback) → raiseChangedEvents (POST/Callback) → raisePostBackEvent (POST-only) → processCallbackEvent (Callback-only) → onLoadComplete → preRenderRecursive → onPreRenderComplete → savePageState → onSaveStateComplete → renderControl (GET/POST) / renderCallbackResponse (Callback-only) → unloadRecursive
- Properties: defined via
getXxx()/setXxx()— no public fields. - Events:
onprefix —onEventName(TEventParameter $param)raised with$this->raiseEvent('OnEventName', $this, $param).dyprefix — dynamic events called on attached/active Behaviors (e.g.,dyShouldContinue,dyClone,dyValidate).fxprefix — global events, auto-registered depending ongetAutoGlobalListen()(e.g.,fxAttachClassBehavior).
- Behaviors and
onevents are called in specified Collections Priority order. @methodPHPDoc tags document dynamicdy-events on classes.
framework/PHPStan/DynamicMethodsClassReflectionExtension and TComponentIsaTypeSpecifyingExtension teach PHPStan about the dynamic property/event/behavior system. Update these when adding new dynamic accessors.
| Thing | Convention | Example |
|---|---|---|
| Classes | TPascalCase |
TComponent, TApplication |
| Methods | camelCase |
getComponent |
| Variables | camelCase |
$componentName |
| Class Constants | SCREAMING_SNAKE_CASE |
MAX_RETRY_COUNT |
| Enumerated Constants | PascalCase |
DeepSkyBlue |
| Class properties | _camelCase |
_propertyOfClass, _styleFieldNames |
| Namespaces | Prado\{Module} |
Prado\Web\UI\TControl |
| Unit test namespaces | Prado\Test\Unit\{Directory} |
Prado\Test\Unit\Web\UI\TControlTest |
| Web Page templates | .page with .php backing |
Home.page, Home.php |
| MasterClass and Template files | .tpl with .php backing |
MyPortlet.tpl, MyPortlet.php |
| TControl tag prefix | <com: |
<com:TMain /> |
framework/classes.php— must be updated whenever a new class is added to the framework.ifstatements always use a block ({}), never a single-line body.@error suppression —Prado::phpErrorHandlerthrowsTPhpErrorExceptionfor every unmasked warning. Keep@on a call whose failure is expected and whose return value is checked; see Error Suppression.- Optional extensions —
composer.jsonrequiresctype,dom,intl,json,pcreandspl; every other extension,mbstringandiconvincluded, is only suggested and may be absent. Never callmb_*directly: measure, cut, and case-map UTF-8 text throughPrado\Util\TMultibyteString, which uses mbstring when loaded andpcreandintlotherwise. Never calliconv*directly: convert encodings throughPrado\Util\TUtf8Converter, which uses iconv when loaded and intl's\UConverterotherwise. Any other suggested extension (iconv,openssl,zlib, ...) is checked withextension_loaded()once and has a fallback or a clear exception. - Error codes for PRADO exceptions are defined in
framework/Exceptions/messages/messages.txt(English master). Framework messages are English;messages-<lang>.txtin the same directory holds only the keys thrown asTHttpException, which the visitor sees (IUserExceptionmarks visitor-facing exceptions). Translations of the developer-facing messages are thepradosoft/prado-dev-errormessagespackage. In this repository, create, update, and delete keys in the English master only; the package is synced in one batch before each PRADO tag and release, never per change. - Exception placement —
Prado\Exceptionsholds exception kinds: classes that classify an error (TInvalidDataValueException,TConfigurationException,THttpException,TIOException) and that code across the framework throws or catches without knowing which component raised it. An exception that belongs to one component lives in that component's namespace beside the class that throws it: its name carries the component's name, only that component throws it, or it carries the component's data (THttpClientException,TMutexException,TRestException,TInputValidationException). Every exception extends the closest kind inPrado\Exceptions, never\Exceptiondirectly. No per-directoryException/subfolders. See Placement. - Backward compatibility — all changes must be backward compatible for point releases. Minor releases can have breaking changes, but minimize the breaks.
HISTORY.mdentries — an entry's length is proportional to the change's importance. A bug fix or a small or internal change is one short sentence; a major feature takes a few sentences naming its main classes and properties. Keep issue numbers, removed or renamed API, and UPGRADE.md pointers; implementation reasoning belongs in docblocks andagents/.@sincetag — use the next release version (4.4.0) when adding new methods or classes; omit the method tag when it matches the class tag.- Uniform Access Principal - Self Encapsulation is required; for an example see framework/TApplication.php
- **Extract Method → Predicate/Guard Clause (Fowler) is suggested
- Method Doc Blocks must be tight, and have at minimum one sentence in the description.
- Documentation additions/changes/removals should be integrated into the whole, at each level (of detail).
- The per directory "<dir_path>/CLAUDE.md" is found at "agents/<dir_path>/INDEX.md" to keep the framework uncluttered.
- All new and changed WebControls must be audited for accessibility at least once during development.
Tests require a running TApplication.
The bootstrap (tests/test_tools/phpunit_bootstrap.php) instantiates one from tests/unit/Security/app/; it may change through the unit tests.
Database tests need MySQL/PostgreSQL initialized from tests/initdb_mysql.sql / tests/initdb_pgsql.sql.
- Unit test classes use the
Prado\Test\Unit\namespace, autoloaded by Composer (autoload-devPSR-4 →tests/unit/).- The namespace follows the directory:
tests/unit/Web/UI/TControlTest.php→Prado\Test\Unit\Web\UI\TControlTest. - A class used by another file lives in its own file named after the class. Fixtures used only by one test file stay in that file.
- Directories holding classes use PascalCase, except where they mirror a lowercase framework namespace (
I18N/core). - Class names in strings, templates (
<com:…>), and XML configuration are fully qualified; useFoo::classin PHP. - Global-namespace fixtures (
Security/app/prado3stubs/,Exceptions/TErrorHandlerTestGlobalClass.php) andPHPStan/Fixtures/are excluded from the classmap and are not autoloaded. - Test classes are inside
Prado\*: a default log category is the test class, and a record fixture needsconst TABLE. - Helper classes in their own file must not end in
Test; phpunit collects*Test.phpfiles as tests.
- The namespace follows the directory:
- Use
Prado\Test\Unit\PradoUnitinfrastructure for:- access to an object's protected/private properties
- invoking protected/private methods
- restore global variables to their initial state
- save and restore all of an object's properties
Harness/(Prado\Test\Unit\Harness\) holds test classes designed for reuse across the Prado tests- Traits for unit test classes are in
Harness/Traits/
- Indentation: tabs (not spaces)
- Line endings: Unix (
\n) - PHP minimum: 8.2 (CI tests 8.2, 8.3, 8.4, 8.5, 8.6)
- PSR-12 enforced via php-cs-fixer
- Use
?for single nullable types and in doc blocks
Docblocks are technical documentation written with direct technical statements. Language and National Variety: English - American Qualities of the writing: clear, thorough, easy to comprehend, not verbose (brevity), timeless/always was, integrated, wholistic Tense: Present - tune for ease of comprehension Banned constructions:
- Antithesis / "not merely X — it Ys": no "does not just X, it Ys", "is not a Y, it's a Z", "rather than X, it Ys". State what it does, once.
- Em-dash dramatic asides used for emphasis or reveal ("— and that's the point", "— never stronger"). Use a period or plain clause.
- Editorializing / filler is unnecessary.
- Rule-of-three rhetorical lists and build-up sentences. One fact per sentence.
Prefer: subject–verb–object declaratives, tables and bullet lists of condition → result where appropriate.
Docblocks inform and describe; it is not persuasive writing.
Working Knowledge (agents/)
framework/ directory hierarchy maps to agents/framework/ for documentation and knowledge files. The typical CLAUDE.md file is named "INDEX.md". Classes have class knowledge files named ".md" in the same relative directory. Brief summaries of directories are named "SUMMARY.md". Scan documentation with find agents/ -type f -name '*.md' for relevant context. There may be other useful ".md" files.
- Never run
rmon any path without developer approval first; except to clean up prior work. - Never remove
composer --devdependencies. - Never erase or overwrite files during unit testing — the file changes being tested must be preserved.