An extensive utility belt for Slytherin

Provides utilities for rapid prototyping Slytherin projects.

View source code on Github

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.

CommandDescription
make:checkCreates a new check (validation) class based on Valitron.
make:handlerCreates a new Slytherin Middleware class.
make:packageCreates a new Slytherin Integration class.
make:routeCreates a new HTTP route class.

HTTP Routes

ControllerDescription
HttpRouteA simple HTTP route class for RESTful APIs.
JsonRouteProvides methods for RESTful APIs in JSON format.

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

Packages

The following classes below are using the IntegrationInterface from Slytherin:

PackageDescription
Laravel/EloquentBased on the illuminate/database (Eloquent).
Laravel/BladeBased on the illuminate/view (Blade).
Laravel/PaginateBased on the illuminate/pagination.
SessionA simple implementation of the SessionHandlerInterface.

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

HTTP Handlers

The following classes below uses the Middleware component of Slytherin:

HandlerDescription
AllowCrossOriginAdds additional headers for Cross-origin resource sharing (CORS).
EmptyStringToNullConverts the empty strings from request as null.
JsonContentTypeChanges content response to application/json.
MutateRequestA middleware that can be extended to mutate/transform values from the request.
SpoofHttpMethodReplaces the HTTP verb from _method value.
TrimStringValueTrims the strings from an incoming request.

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.):

HandlerDescription
JsonMutatorMutates the PSR-07 response in JSON format.
RestMutatorMutates the result created from Laravel/Paginate based on Paypal's API Style Guide.

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();
  // -------------------------------
}