About Extension libraries
Fegg's goal is lightweight and less typing, so the controller base class only has the minimum required functions. Additional functions are provided as library classes in the core (htdocs/_fegg/core/src/).
How to use
Every library is a namespaced class loaded by the autoloader. Import it with use and create it with new.
Controller
<?php
namespace Site\Controller;
defined('FEGG_CORE_DIR') || exit;
use Fegg\Tool\Mail;
use Fegg\Tool\Validation;
class Contact extends Controller
{
public function post()
{
$validation = new Validation();
$validation->required('mail', $this->in('mail'), array('@required', 'Email'));
if (!$validation->isError()) {
$mail = new Mail('Mail subject', 'Mail body');
$mail->send($this->in('mail'), 'Sender name', 'from@example.com');
}
}
}
Extension Libraries
The libraries are in the Fegg\Tool\ namespace. Fegg\Model, Fegg\Database\Pdo, Fegg\Http\Client and Fegg\Log are framework classes, not in Fegg\Tool\.
| Library | Class | Description |
|---|---|---|
| Validation | Fegg\Tool\Validation | Form validation |
| Database | Fegg\Database\Pdo | Database access (PDO) |
| Model | Fegg\Model | Models: queries and rows |
| File | Fegg\Tool\File | File and directory operations |
| Upload | Fegg\Tool\Upload | Uploads and file checks |
Fegg\Tool\Mail | Sending mail (PHPMailer) | |
| RSS | Fegg\Tool\RSS | Reading RSS / Atom feeds |
| Trim | Fegg\Tool\Trim | Resizing and cropping images |
| Embed | Fegg\Tool\Embed | Embedding YouTube videos and Google Maps the way the editor does |
| Captcha | Fegg\Tool\Captcha\ReCAPTCHA, Fegg\Tool\Captcha\Turnstile | Verifying Google reCAPTCHA / Cloudflare Turnstile responses |
| Yaml | Fegg\Tool\Yaml | Reading and writing YAML files |
| HTTP client | Fegg\Http\Client | Requests to other services over HTTP |
| Log | Fegg\Log | Writing to the application log |
| Cache | Fegg\Tool\Cache | Keeping values in files for a while |
| CSV | Fegg\Tool\Csv | Writing and reading CSV for Excel |
| Rate limit | Fegg\Tool\RateLimit | Limiting how often one visitor can do something |
| Sitemap | Fegg\Tool\Sitemap | Writing sitemap.xml |
| JSON-LD | Fegg\Tool\JsonLd | Structured data for search engines |
| Feed | Fegg\Tool\Feed | Writing an RSS 2.0 feed of the site's posts |
Project libraries
Put your own classes in htdocs/_fegg/site/src/ with the Site\ namespace. They are autoloaded in the same way.
htdocs/_fegg/site/src/MyLib/Foo.php
<?php
namespace Site\MyLib;
defined('FEGG_CORE_DIR') || exit;
class Foo
{
}
Controller
use Site\MyLib\Foo;
$foo = new Foo();
External Libraries
These libraries are bundled in htdocs/_fegg/core/vendor/ and autoloaded.
- PHPMailer (7.2)
- Used by Mail. Namespace
PHPMailer\PHPMailer - A failed send throws
PHPMailer\PHPMailer\Exception
- Used by Mail. Namespace
JSON documents are handled with PHP's own json_encode and json_decode, YAML with Yaml.