rougin / weasley
Utility belt for Slytherin micro-framework.
Installs: 1 248
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- rougin/slytherin: ~0.9
- symfony/console: ~2.8|~3.0|~4.0|~5.0|~6.0
- vlucas/valitron: ~1.4
Requires (Dev)
- phpunit/phpunit: ~4.2|~5.7|~6.0|~7.0|~8.0|~9.0
- sanmai/phpunit-legacy-adapter: ~6.1|~8.0
README
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.