Skip to main content
Version: Fegg 5.x (next)

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 that is 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\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');
}
}
}
note

Fegg 4 code such as $this->getClass('Tool/Mail') still works in Fegg 5 through Fegg\Legacy, but every use is written to the PHP error log as Fegg deprecated: ... and it will be removed in Fegg 6. Replace it with new.

Fegg 4Fegg 5
$this->getClass('Validation')new \Fegg\Validation()
$this->getClass('Tool/Mail', $subject, $body)new \Fegg\Tool\Mail($subject, $body)
$this->getClass('Tool/Upload')new \Fegg\Tool\Upload()
$this->getClass('ReCAPTCHA', $secret)new \Fegg\Captcha\ReCAPTCHA($secret)
$this->getClass('DB_pdo')new \Fegg\Database\Pdo()

The same applies to the other Tool/... classes (Tool/Date, Tool/File, Tool/OEmbed, Tool/RSS, Tool/Trim), which became Fegg\Tool\Date and so on.

Extension Libraries​

LibraryClassDescription
ValidationFegg\ValidationProviding some functions for validation
DatabaseFegg\Database\PdoProviding necessary functions for using database
ModelFegg\ModelExtended Database Library for LH project
FileFegg\Tool\FileProviding some functions for managing files/directories
UploadFegg\Tool\UploadProviding some functions for uploading/validating files
MailFegg\Tool\MailProviding some functions for sending email (PHPMailer wrapper)
RSSFegg\Tool\RSSProviding some functions for analyzing RSS document
TrimFegg\Tool\TrimProviding some functions for processing image (especially image crop)
DateFegg\Tool\DateProviding some functions for calculating dates
OEmbedFegg\Tool\OEmbedGetting the embed URL of a YouTube video etc. through oEmbed
CaptchaFegg\Captcha\ReCAPTCHA, Fegg\Captcha\TurnstileVerifying Google reCAPTCHA / Cloudflare Turnstile responses

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.0)
    • Used by Mail. Namespace PHPMailer\PHPMailer
    • A failed send throws PHPMailer\PHPMailer\Exception
  • Spyc
    • YAML document loader (global class Spyc)
    • Used by the database migration (fegg-cli migration)

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