Chevere PHP Framework

website·Indexed 34 days ago

https://chevere.org/

A collection of PHP libraries and tools including Workflow for multi-step procedures, Parameter for type-safe validation, a minimalist PSR-11 Container, and various utility packages for HTTP routing, filesystem management, and data structures. The ecosystem includes a dedicated integration for Laravel and follows strict standards for immutability, coding quality, and testing.

Tokens
49.6K
Snippets
324
Records
352
Agent score
69%

What's inside Chevere

  1. Overview of the Chevere PHP library

    Chevere is a PHP development library designed for building high-quality, enterprise-grade applications. It is the supporting library for the Chevereto project and focuses on clean code principles, robust type safety, strictness, and full immutability. The library is built specifically for PHP 8 and emphasizes maintainability, scalability, and reliability over convenience.
  2. Overview of xrDebug debug utility

    xrDebug is a lightweight, portable debug utility consisting of a central debugger server component and multiple client implementations for different environments. Available clients include PHP, Laravel, and WordPress.
  3. Dump variables using vd and vdd helpers

    VarDump provides two primary global helpers for quick variable introspection in both CLI and HTTP contexts:

    • vd(): A drop-in replacement for var_dump() that prints information about one or more variables to the output stream.
    • vdd(): Performs the same action as vd() but immediately halts execution via die(0) (similar to dd in other frameworks).
    vd($myVar); // var dump
    vdd($myVar); // var dump and die
  4. Meet Chevere software quality standards

    To minimize technical debt and ensure usability, all software delivered by Chevere must adhere to the following four quality pillars: continuous integration (CI build), extensive testing, comprehensive documentation, and PHPStan Level 9 compliance.
  5. Validate integer values

    Use the int() function to create an IntParameter. It supports range constraints (min, max), whitelists (accept), and blacklists (reject). For attribute-based validation, use #[_int].
    use function Chevere\Parameter\int;
    
    // Ranged
    $int = int(min: 0, max: 100);
    
    // Whitelist
    $int = int(accept: [1, 2, 3]);
    
    // Blacklist
    $int = int(reject: [0, -1]);
    
    // Attribute notation
    use Chevere\Parameter\Attributes\_int;
    #[_int(min: 0, max: 100)]
  6. Apply Chevere naming conventions (Casing)

    Follow these casing rules to ensure cohesive syntax across the project:

    • PascalCase: Classes and interfaces
    • SCREAMING_SNAKE_CASE: Constants
    • snake_case: HTTP parameters and database columns
    • camelCase: All other identifiers
  7. Discover and cache workflow providers and dependencies

    Use WorkflowDiscovery to scan directories for WorkflowProviderInterface implementations and their job dependencies. Results can be persisted to PHP files via build() for faster runtime loading via fromBuild().
    use Chevere
    Workflow
    WorkflowDiscovery;
    
    // Scan directory
    $discovery = WorkflowDiscovery::fromDirectory('/path/to/src');
    $providers = $discovery->providers();
    $dependencies = $discovery->dependencies();
    
    // Persist to cache files
    $discovery->build('/path/to/build');
    
    // Load from cache
    $discovery = WorkflowDiscovery::fromBuild('/path/to/build');
  8. Create a Regex instance

    Initialize a Chevere\Regex\Regex object by passing a regular expression pattern as a string to the constructor.
    use Chevere\Regex\Regex;
    
    $regex = new Regex('/^Hello World!$/');
  9. Cast loosely-typed input using castArguments and castValues

    When dealing with loosely-typed input (like query strings), use castArguments to cast values to match defined parameter types and return an Arguments instance, or castValues to return a plain array of casted values.
    use function Chevere\Parameter\castArguments;
    use function Chevere\Parameter\castValues;
    use function Chevere\Parameter\parameters;
    use function Chevere\Parameter\int;
    use function Chevere\Parameter\bool;
    
    $parameters = parameters(
        page: int(min: 1),
        active: bool(),
    );
    
    // Returns an Arguments instance
    $arguments = castArguments($parameters, [
        'page' => '3',     // cast to int
        'active' => '1',   // cast to bool
    ]);
    
    // Returns ['page' => 3, 'active' => true]
    $values = castValues($parameters, ['page' => '3', 'active' => '1']);
  10. Use Dependency Injection in Workflow Action classes

    The Laravel integration automatically passes the Laravel service container to Chevere Workflow. This allows Action classes to use standard constructor injection for any service registered in the container (e.g., Payment Gateways, Loggers, or Eloquent models) without additional configuration.
    use Chevere\Action\Action;
    use App\Services\PaymentGateway;
    use Illuminate\Log\LogManager;
    
    class ChargePayment extends Action
    {
        public function __construct(
            private PaymentGateway $gateway,  // auto-injected from Laravel
            private LogManager $logger,       // auto-injected from Laravel
        ) {}
    
        public function __invoke(int $orderId, float $amount): array
        {
            $this->logger->info("Charging order {$orderId}: \"${$amount}");
            $result = $this->gateway->charge($amount);
    
            return ['transactionId' => $result->id, 'status' => $result->status];
        }
    }