enmaboya / strictness-for-laravel
more strictness for laravel
Package info
github.com/enmaboya/strictness-for-laravel
pkg:composer/enmaboya/strictness-for-laravel
Requires
- laravel/framework: ^11.0|^12.0
This package is auto-updated.
Last update: 2026-03-30 17:43:54 UTC
README
A small Laravel package that adds strict, validated accessors for configuration values. It complements Laravel’s config layer - where values are usually defined in config/*.php and filled from environment variables - so mistakes surface as clear InvalidArgumentExceptions instead of subtle type or shape bugs later.
Requirements
- PHP 8.2+
- Laravel
^11.0or^12.0
Installation
composer require enmaboya/strictness-for-laravel
Usage
Config keys work as usual; strict methods read those keys and enforce types and optional constraints.
Strings (Enmaboya\StrictnessForLaravel\Enums\StringType):
DEFAULT- value must be astringNON_EMPTY- non-empty aftertrimNON_FALSY- non-empty string that is truthy in a PHP boolean senseLOWERCASE/UPPERCASE- exact case match
Integers (Enmaboya\StrictnessForLaravel\Enums\IntType):
DEFAULT- value must be anintPOSITIVE/NEGATIVE/NON_ZERO/NON_NEGATIVE/NON_POSITIVE- as named
use Enmaboya\StrictnessForLaravel\Enums\StringType; use Enmaboya\StrictnessForLaravel\Enums\IntType; use Enmaboya\StrictnessForLaravel\Facades\StrictConfig; // Facade (same underlying `config` binding after extend) $apiUrl = StrictConfig::string('services.api.url', type: StringType::NON_EMPTY); $timeout = StrictConfig::integer('services.api.timeout', default: 30, type: IntType::NON_NEGATIVE); // Helper (PHPDoc assumes StrictConfigRepository) $region = strict_config()->string('app.region', type: StringType::LOWERCASE);
Values like config('app.name') populated from env('APP_NAME') are read through the same keys; the strict layer only cares that the resolved config value matches the expected type and constraint.
Feature checklist
- Strict
string()reads with optionalStringTypevalidation - Strict
integer()reads with optionalIntTypevalidation - Strict
validatedString()reads with optionalIntTypevalidation - Strict
validatedInteger()reads with optionalIntTypevalidation - Strict
env()
License
MIT