| name | atomic-framework-data |
| description | Use when working on Atomic data layer: Model, Validator, cache drivers, Codes, Enums, Exceptions hierarchy, file exports (PDF/XLS/CSV), and Support helpers. |
| argument-hint | Model, validation, cache, enums, exceptions, PDF/XLS/CSV export |
| user-invocable | true |
Atomic Framework Data
When to Use
- Creating or editing models (Cortex ORM).
- Adding validation rules, handling validation errors.
- Using or extending cache (DB, Memcached), transient values, or code enums.
- Throwing or catching domain-specific exceptions.
- Generating PDF, XLS, or CSV files.
- Using or adding global helper functions.
Engine Files
engine/Atomic/App/Model.php, engine/Atomic/Validator/*, engine/Atomic/Cache/*, engine/Atomic/Codes/Code.php, engine/Atomic/Enums/*, engine/Atomic/Exceptions/*, engine/Atomic/Files/*, engine/Atomic/Support/helpers.php
Reference Docs
docs/model.md, docs/atomic_pdf.md, docs/atomic_xls.md, docs/database.md, docs/errorhandler.md, docs/transient.md, docs/security.md
Model
Engine\Atomic\App\Model extends F3 Cortex ORM.
use Engine\Atomic\App\Model;
final class Post extends Model
{
protected $table = 'posts';
protected $fieldConf = [
'title' => ['type' => 'VARCHAR256', 'nullable' => false],
'body' => ['type' => 'TEXT', 'nullable' => true],
];
}
$post = new Post();
$post->title = 'Hello';
if (!$post->save()) {
[$code, $vars] = $post->get_last_err_data();
$code = $post->get_last_err_code();
$vars = $post->get_last_err_vars();
}
Bulk update
$post->update_property(['status = ?', 'draft'], 'status', 'published');
Validation hook
Override before_validate() for pre-validation transforms.
Validator
Engine\Atomic\Validator\Validator runs on save().
Engine\Atomic\Validator\ValidatorModelTrait adds validation to any model.
Validation rules come from Enums\Rule (PHP 8.1 backed enum).
Enums
Role (Enums\Role)
use Engine\Atomic\Enums\Role;
Role::ADMIN->value
Role::SELLER->value
Role::BUYER->value
Role::MODERATOR->value
Role::SUPPORT->value
Role::all();
Role::is_valid('admin');
Guard::has_role(Role::ADMIN);
has_role(Role::SELLER);
Currency (Enums\Currency)
use Engine\Atomic\Enums\Currency;
Currency::USD->value;
Currency::EUR->value;
Currency::UAH->value;
Currency::RUB->value;
Currency::USD->symbol();
Currency::EUR->symbol();
Currency::UAH->symbol();
Currency::USD->display_name();
Currency::USD->to_array();
Currency::get_available();
Language (Enums\Language)
use Engine\Atomic\Enums\Language;
Language::EN->value;
Language::UK->value;
Language::RU->value;
Language::EN->display_name();
Language::UK->display_name();
Language::get_all();
LogLevel / LogChannel
use Engine\Atomic\Enums\LogLevel;
use Engine\Atomic\Enums\LogChannel;
LogLevel::EMERGENCY; LogLevel::ALERT; LogLevel::CRITICAL;
LogLevel::ERROR; LogLevel::WARNING; LogLevel::NOTICE;
LogLevel::INFO; LogLevel::DEBUG;
LogLevel::ERROR->to_int();
LogChannel::ERROR;
LogChannel::AUTH;
LogChannel::QUEUE_WORKER;
LogChannel::QUEUE_MONITOR;
Rule (Enums\Rule)
Validation rules used in fieldConf['rules'] arrays. All cases are backed strings.
use Engine\Atomic\Enums\Rule;
Rule::UUID_V4
Rule::EMAIL
Rule::URL
Rule::ENUM
Rule::REGEX
Rule::CALLBACK
Rule::NUM_MIN
Rule::NUM_MAX
Rule::STR_MIN
Rule::STR_MAX
Rule::MB_MIN
Rule::MB_MAX
Rule::PASSWORD_ENTROPY
Usage in fieldConf:
protected $fieldConf = [
'email' => [
'type' => 'VARCHAR256',
'required' => true,
'rules' => [Rule::EMAIL],
],
'slug' => [
'type' => 'VARCHAR128',
'rules' => [Rule::REGEX],
'pattern' => '/^[a-z0-9-]+$/',
],
'password' => [
'type' => 'VARCHAR256',
'rules' => [Rule::MB_MIN, Rule::PASSWORD_ENTROPY],
'min' => 8,
'min_entropy' => 20.0,
],
'status' => [
'type' => 'VARCHAR128',
'rules' => [Rule::ENUM],
'enum' => ['draft', 'published', 'archived'],
],
'user_uuid' => [
'type' => 'VARCHAR128',
'rules' => [Rule::UUID_V4],
],
];
required, nullable, and unique are not Rule cases -- they are plain fieldConf keys (booleans).
Exceptions
Hierarchy: AtomicException → domain exceptions.
AtomicException
AuthenticationException
ConfigurationException
FileProcessingException
ImportException // extends FileProcessingException
InsufficientStockException
NotFoundException
PaymentException
ValidationException
Always throw the most specific exception. Catch at the controller or middleware boundary.
use Engine\Atomic\Exceptions\NotFoundException;
use Engine\Atomic\Exceptions\ValidationException;
use Engine\Atomic\Exceptions\PaymentException;
throw new NotFoundException('Product not found');
throw new ValidationException('Invalid email format');
throw new PaymentException('Payment gateway timeout');
Codes (Codes\Code)
Engine\Atomic\Codes\Code -- string constants returned by the validator and used in API responses.
use Engine\Atomic\Codes\Code;
Code::SUCCESS
Code::BAD_REQUEST
Code::UNAUTHORIZED
Code::FORBIDDEN
Code::RATE_LIMIT
Code::NONCE_INVALID
Code::SERVER_ERROR
Code::SERVICE_UNAVAILABLE
Code::OAUTH_TOKEN_ERROR
Code::OAUTH_USER_DATA_ERROR
Code::OAUTH_ACCOUNT_ALREADY_LINKED
Code::OAUTH_NOT_CONFIGURED
Code::OAUTH_INVALID_STATE
Convention: models define field-level error constants following the pattern:
Code::{MODEL}_{FIELD}_{SUFFIX}, e.g. Code::USER_EMAIL_REQUIRED, Code::USER_EMAIL_FORMAT.
The validator auto-resolves these from field name and model class name.
Cache Drivers and CacheManager
Engine\Atomic\Core\CacheManager -- factory for all cache backends.
use Engine\Atomic\Core\CacheManager;
$cm = CacheManager::instance();
$redis = $cm->redis();
$db = $cm->db();
$memcached = $cm->memcached();
$cache = $cm->redis([
'server' => '127.0.0.1',
'port' => 6379,
'password' => 'secret',
]);
$best = $cm->cascade();
$best->set('key', $data, 3600);
$val = $best->get('key');
$best->clear('key');
Config constants for ImageOptimizer (used by built-in queue applications):
ATOMIC_JPEG_QUALITY (default 85)
ATOMIC_PNG_COMPRESSION_LEVEL (default 6)
ATOMIC_WEBP_QUALITY (default 85)
ATOMIC_AVIF_QUALITY (default 50)
Engine\Atomic\Cache\DB and Engine\Atomic\Cache\Memcached are the low-level drivers used by CacheManager.
File Export
PDF
Use Engine\Atomic\Files\PDF (TCPDF wrapper). See docs/atomic_pdf.md for full API.
XLS
Use Engine\Atomic\Files\XLS (PhpSpreadsheet wrapper). See docs/atomic_xls.md.
CSV
Engine\Atomic\Files\CSV for comma-separated exports.
Font data for PDF lives in engine/Atomic/Files/fonts/ (DejaVu Sans included).
Support Helpers
All global PHP functions used across the codebase are defined in engine/Atomic/Support/helpers.php.
Examples:
plugin_manager();
get_plugin('Monopay');
has_plugin('Google');
enable_plugin('name');
disable_plugin('name');
ai_connector('sk-...');
is_home(); is_page('/x'); is_ajax(); is_ssl(); is_mobile();
current_path(); url_segments(); get_segment(0);
mail_to('a@b.com')->set_html('<h1>Hi</h1>')->send('Subject');
mail_send('a@b.com', 'Subject', $html);
get_head(); get_header(); get_footer(); get_section('hero');
set_transient('key', $val, 3600);
get_transient('key');
delete_transient('key');
create_nonce('delete-post', 1800);
verify_nonce($_POST['nonce'] ?? '', 'delete-post');
Guardrails
- Use the most specific
Exception subclass; never throw a bare \Exception for domain errors.
- Model validation runs automatically on
save(); do not bypass it by calling raw ORM methods.
- Table names are auto-prefixed; do not hardcode full table names in queries.