Skip to main content
Version: Fegg 5.x

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\.

LibraryClassDescription
ValidationFegg\Tool\ValidationForm validation
DatabaseFegg\Database\PdoDatabase access (PDO)
ModelFegg\ModelModels: queries and rows
FileFegg\Tool\FileFile and directory operations
UploadFegg\Tool\UploadUploads and file checks
MailFegg\Tool\MailSending mail (PHPMailer)
RSSFegg\Tool\RSSReading RSS / Atom feeds
TrimFegg\Tool\TrimResizing and cropping images
EmbedFegg\Tool\EmbedEmbedding YouTube videos and Google Maps the way the editor does
CaptchaFegg\Tool\Captcha\ReCAPTCHA, Fegg\Tool\Captcha\TurnstileVerifying Google reCAPTCHA / Cloudflare Turnstile responses
YamlFegg\Tool\YamlReading and writing YAML files
HTTP clientFegg\Http\ClientRequests to other services over HTTP
LogFegg\LogWriting to the application log
CacheFegg\Tool\CacheKeeping values in files for a while
CSVFegg\Tool\CsvWriting and reading CSV for Excel
Rate limitFegg\Tool\RateLimitLimiting how often one visitor can do something
SitemapFegg\Tool\SitemapWriting sitemap.xml
JSON-LDFegg\Tool\JsonLdStructured data for search engines
FeedFegg\Tool\FeedWriting 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

JSON documents are handled with PHP's own json_encode and json_decode, YAML with Yaml.