Weasley is a PHP package that provides generators, helpers, and utility classes for the Slytherin. Its goal is to improve the overall productivity when writing web applications based on Slytherin by reducing in writing code related to CRUD operations.
Install the Weasley package via Composer:
$ composer require rougin/weasleyNote
When using the weasley command, the Symfony Console must be installed first.
Once installed, kindly see the following features below provided by Weasley:
Weasley provides commands that generates code based on the specified type (e.g., Check, Route, etc.). These commands allow Slytherin to be a rapid prototyping tool in creating web-based applications.
To access the list of available commands, kindly run its namesake command from the terminal:
$ vendor/bin/weasleyCreates a new check (validation) class based on Valitron.
Creates a new HTTP Middleware class.
Creates a new Slytherin Integration class.
Creates a new HTTP route class.
In creating web applications, Weasley also provides PHP classes to create HTTP routes based on the RESTful style.
Note
In other PHP frameworks, this is also known as Controllers.
A simple HTTP route class for RESTful APIs.
Similar with HttpRoute but the response will be returned in JSON format.
To conform with the usage of IntegrationInterface from Slytherin, Weasley also provides the following third-party integrations with other PHP packages:
This package enables the usage of Eloquent to Slytherin which is an Object-relational mapper (ORM) from Laravel. To use this package, kindly install its required package first in Composer:
$ composer require illuminate/databaseLaravel\Blade allows Slytherin to use Blade from Laravel for creating PHP templates using the Blade templating engine. Use the command below to install the specified package from Composer:
$ composer require illuminate/viewThis is a simple third-party package that allows Eloquent to generate pagination links based on its models. Kindly use the command below to install this third-party package:
$ composer require illuminate/paginateWeasley also provides a simple implementation of the SessionHandlerInterface.
Weasley has the following HTTP middlewares (HTTP handlers in this case) to improve the handling of HTTP requests and its respective responses:
Adds additional headers for Cross-origin resource sharing (CORS).
Converts the empty strings from request as null.
Changes content response to application/json.
A middleware that can be extended to mutate/transform values from the request.
Replaces the HTTP verb from _method value.
Trims the strings from an incoming request.
Provided by Weasley, mutators are classes that mutates (transforms) to a specified result (e.g., PSR-07 responses, API data, etc.):
Mutates a PSR-07 response in JSON format.
Mutates a response created from the Laravel/Paginate package based on Paypal's API Style Guide.
Weasley also provides a simple validation class on top of Valitron using 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();
// -------------------------------
}Please see CHANGELOG for more recent changes.
See CONTRIBUTING on how to contribute.
The MIT License (MIT). Please see LICENSE for more information.