Fegg Coding Guide
補足
This is the guide for Fegg 5. If your project still uses Fegg 4 (fegg/ and code/ directories), switch to Fegg 4.x in the version dropdown in the navbar.
About Fegg
Fegg is a small PHP framework, originally created by Genies, Inc. and extended by LionHeart with a CMS foundation (login, media and image management, post types).
LionHeart projects start from the skeleton repository lionheart-group/lh-fegg-skelton. It contains Fegg, the CMS, sample pages (top page, news, contact form) and the frontend build setup.
What is new in Fegg 5
- PHP 7.4 to 8.5 are supported.
- Core and site are separated.
htdocs/_fegg/core/is the core: the framework and the CMS foundation shared by every project. Do not edit it.fegg-cli core:updatereplaces it as a whole, the same way you update WordPress itself.htdocs/_fegg/site/is the site: your project's controllers, templates and settings. Updates never touch it.- To change something the core provides (a CMS template, a CMS screen, a setting), override it from
site/.
- Namespaces and autoloading. Controllers are
Site\Controller\...classes and framework classes areFegg\...(Fegg\Model,Fegg\Validation,Fegg\Tool\Mail, ...). Create classes withnew;getClass()is no longer needed. - Errors fail loudly. Database errors throw
Fegg\Database\QueryExceptionand missing templates throwFegg\Template\TemplateException. Uncaught, both become a logged HTTP 500 (the error pagesite/template/error/500.htmlcan be your own) instead of a message printed into the page.Fegg\Logwrites the application log. - Per-server settings and secrets come from
site/config/env.php(not committed) or environment variables, read withfeggEnv().FEGG_ENV(productionunless set) decides whether developers see error details. - Secure by default. Security headers on every response, sessions only when needed (
HttpOnly,SameSite=Lax, strict mode), CSRF tokens in the CMS, login throttling, upload content checks. - SQLite or MySQL.
fegg-cli migrationworks on both. - Command line tools.
fegg-clichecks templates (template:lint), lists the database schema (db:schema), manages CMS users (user:create), updates the core (core:update) and checks that_fegg/cannot be read from the web (doctor).
Fegg 4 code (MyApplication, getClass(), controllers without a namespace, Model, DB_pdo, LH_FW) still runs through a compatibility layer. Every use is logged as Fegg deprecated: ... in the PHP error log, and the layer will be removed in Fegg 6.
Where to start
- Directory structure: what lives in
core/andsite/ - Settings:
site/config/settings.php,env.phpand the database connection - fegg-cli: command line tools
- Updating the core
- Migrating a Fegg 3 / 4 project
- URL and Controller: how a request reaches your code
- Security and Logging and errors