rougin/weasley

Utility belt for Slytherin micro-framework.

v0.7.0 2024-04-08 03:01 UTC

This package is auto-updated.

Last update: 2024-10-20 16:24:47 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Total Downloads

A package that provides generators, helpers, and utilities for Slytherin.

Installation

Install Weasley via Composer:

$ composer require rougin/weasley

Features

Generators

Access the generator commands through vendor/bin/weasley in the terminal/command line. To know the more the arguments and options, include the option --help to the chosen command.

HTTP Routes

NOTE: In other PHP frameworks, this is also known as Controllers.

Packages

The following classes below are using the IntegrationInterface from Slytherin:

NOTE: The mentioned integrations above needs to include their required dependencies first.

HTTP Handlers

The following classes below uses the Middleware component of Slytherin:

NOTE: In other PHP frameworks, this is also known as Middlewares.

Mutators

Mutators are classes that mutates (transforms) specified result (e.g., PSR-07 responses, API data, etc.):

NOTE: The Laravel/Paginate package must be included to use the parsing capabilities of RestMutator.

Validation

Weasley also provides a validation class on top of Valitron. Kindly create a class that extends to the Check class:

use Rougin\Weasley\Check;

class UserCheck extends Check
{
    protected $labels =
    [
        'name' => 'Name',
        'email' => 'Email',
        'age' => 'Age',
    ];

    protected $rules =
    [
        'name' => 'required',
        'setting' => 'required|email',
        'type' => 'required|numeric',
    ];
}

Once created, the data can be submitted to the said class for validation:

$check = new UserCheck;

$data = /* e.g., data from request */;

if ($check->valid($data))
{
  // $data passed from validation
}
else
{
  // Get the available errors ---
  $errors = $check->errors();
  // ----------------------------

  // Or get the first error only ---
  echo $check->firstError();
  // -------------------------------
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Credits

License

The MIT License (MIT). Please see LICENSE for more information.