icom/ framework

ຫຼາຍພາສາ ແລະກວດ input ຊັດເຈນ.

ກຳນົດ locale ຕໍ່ request ແລະຮັບພຽງຂໍ້ມູນທີ່ຜ່ານ schema.

1. Catalogues ທີ່ບໍ່ປ່ຽນ state

Translator ເກັບ catalogue ແບບ immutable ແລະຮັບ locale ໃນທຸກ trans call. ບໍ່ໃຊ້ setlocale ຫຼືປ່ຽນ global locale, ຈຶ່ງບໍ່ປົນພາສາລະຫວ່າງ request ທີ່ໃຊ້ worker ດຽວກັນ. ເລືອກ locale ຈາກ allowlist ຂອງແອັບ; unknown locale ຈະ throw.

example
use Icom\Translation\Translator;

$t = new Translator([
    'en' => ['greeting' => 'Hello, {name}!'],
    'lo' => ['greeting' => 'ສະບາຍດີ {name}!'],
], fallback: 'en');
$message = $t->trans('greeting', 'lo', ['name' => 'ນັກພັດທະນາ']);
// In an HTML template, escape this text with $e($message).

2. Fallback ແລະ escaping

ຖ້າ key ບໍ່ມີໃນ locale ທີ່ເລືອກ ຈະອ່ານ fallback; ຖ້າຍັງບໍ່ມີ ຈະຄືນ key. {name} ຖືກແທນຄ່າຄັ້ງດຽວ ແລະຜົນເປັນ plain text. ຕ້ອງ escape ຕາມ context: $e ສຳລັບ HTML ຫຼື JSON encoder ສຳລັບ JSON. ບໍ່ມີ ICU/plural/date-number formatting ຫຼື dynamic translation-file loader.

3. Rules ເພີ່ມເຕີມ

ເພີ່ມ array, list, uuid, date:YYYY-MM-DD, confirmed, same:field, different:field, present. min/max ນັບສະມາຊິກໃນ array; integer/boolean ບໍ່ cast ຈາກ string. UUID ແມ່ນ canonical hyphenated RFC9562 versions1–8 variant10xx; nil/max ບໍ່ຜ່ານ. Date ກວດປະຕິທິນ Gregorian ຈິງ years0001–9999.

example
use Icom\Validation\Validator;
use Icom\Http\Problem;

$result = (new Validator())->validate($input, [
    'id' => 'required|uuid',
    'starts_on' => 'required|date:YYYY-MM-DD',
    'tags' => 'required|array|list|min:1|max:10',
    'password' => 'required|string|min:12|confirmed',
    'previous_id' => 'present|nullable|uuid|different:id',
]);
if (!$result['valid']) {
    return Problem::response(422, 'Please check the submitted fields.', $result['errors']);
}
$validated = $result['data'];
// Authorize before persisting; validate each nested tag value separately.
// Hash passwords through the account service; never persist them as plain text.
// password_confirmation is not returned unless it has its own schema entry.

4. Schema ແລະ nested data

present ຕ້ອງມີ key; null ຕ້ອງມີ nullable. confirmed/same/different ຍັງກວດ relationship ແມ່ນແຕ່ nullable input. ຄືນພຽງ fields ທີ່ມີໃນ schema, ແຕ່ array/list ບໍ່ກວດແລະບໍ່ຕັດ nested keys ອັດຕະໂນມັດ. ກວດແຕ່ລະ nested object ດ້ວຍ schema ຂອງມັນ ແລະກຳນົດ item count ກ່ອນ loop. ບໍ່ໃຊ້ validated input ເປັນຫຼັກຖານ authorization. Malformed rule/config ຈະ throw ແມ່ນແຕ່ field ບໍ່ມີ. validate ຄືນ array {valid, data, errors}; ກວດ valid ໃຫ້ຜ່ານກ່ອນໃຊ້ data. ເມື່ອ valid=false, data ອາດມີບາງ fields ທີ່ຜ່ານ ແຕ່ຫ້າມຖືເປັນ payload ທີ່ຜ່ານທັງຊຸດ.

Developer preview — benchmark claims require reproducible evidence.

Explore the architecture