2017 © Pedro Peláez
 

library weasley

Generators and helpers for the Slytherin framework.

image

rougin/weasley

Generators and helpers for the Slytherin framework.

  • Wednesday, April 25, 2018
  • by rougin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 698 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 22 % Grown

The README.md

Weasley

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-coverage] Total Downloads, (*1)

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., (*2)

Installation

Install the Weasley package via Composer:, (*3)

``` bash $ composer require rougin/weasley, (*4)


Once installed, kindly see the following features below provided by `Weasley`: ## Code generators `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: ``` bash $ vendor/bin/weasley

make:check

Creates a new check (validation) class based on Valitron., (*5)

make:handler

Creates a new HTTP Middleware class., (*6)

make:package

Creates a new Slytherin Integration class., (*7)

make:route

Creates a new HTTP route class., (*8)

HTTP routes

In creating web applications, Weasley also provides PHP classes to create HTTP routes based on the RESTful style., (*9)

[!NOTE] In other PHP frameworks, this is also known as Controllers., (*10)

HttpRoute

A simple HTTP route class for RESTful APIs., (*11)

JsonRoute

Similar with HttpRoute but the response will be returned in JSON format., (*12)

Third-party packages

To conform with the usage of IntegrationInterface from Slytherin, Weasley also provides the following third-party integrations with other PHP packages:, (*13)

Laravel\Eloquent

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:, (*14)

``` bash $ composer require illuminate/database, (*15)


### `Laravel\Blade` `Laravel\Blade` allows `Slytherin` to use [Blade](https://laravel.com/docs/blade) from `Laravel` for creating PHP templates using the `Blade` templating engine. Use the command below to install the specified package from `Composer`: ``` bash $ composer require illuminate/view

Laravel\Paginate

This 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:, (*16)

``` bash $ composer require illuminate/paginate, (*17)


### `Session` `Weasley` also provides a simple implementation of the [SessionHandlerInterface](https://secure.php.net/manual/en/class.sessionhandlerinterface.php). ## HTTP handlers `Weasley` has the following HTTP middlewares (HTTP handlers in this case) to improve the handling of HTTP requests and its respective responses: ### `AllowCrossOrigin` Adds additional headers for [Cross-origin resource sharing](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) (CORS). ### `EmptyStringToNull` Converts the empty strings from request as `null`. ### `JsonContentType` Changes content response to `application/json`. ### `MutateRequest` A middleware that can be extended to mutate/transform values from the request. ### `SpoofHttpMethod` Replaces the HTTP verb from `_method` value. ### `TrimStringValue` Trims the strings from an incoming request. ## Mutators Provided by `Weasley`, mutators are classes that mutates (transforms) to a specified result (e.g., [PSR-07](https://www.php-fig.org/psr/psr-7/) responses, API data, etc.): ### `JsonMutator` Mutates a `PSR-07` response in JSON format. ### `RestMutator` Mutates a response created from the `Laravel/Paginate` package based on [Paypal's API Style Guide](https://web.archive.org/web/20220114091735/https://github.com/paypal/api-standards/blob/master/api-style-guide.md). ## Validation `Weasley` also provides a simple validation class on top of [Valitron](https://github.com/vlucas/valitron) using the `Check` class: ``` php 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:, (*18)

``` php $check = new UserCheck;, (*19)

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

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

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


## Testing If there is a need to check the source code of `Weasley` for development purposes (e.g., creating fixes, new features, etc.), kindly clone this repository first to a local machine: ``` bash $ git clone https://github.com/rougin/weasley.git "Sample"

After cloning, use Composer to install its required packages:, (*23)

``` bash $ cd Sample $ composer update, (*24)


> [!NOTE] > Please see also the [build.yml](https://github.com/rougin/weasley/blob/master/.github/workflows/build.yml) of `Weasley` to check any packages that needs to be installed based on the PHP version. Once the required packages were installed, kindly check the following below on how to maintain the code quality and styling guide when interacting the source code of `Weasley`: ### Unit tests `Weasley` also contains unit tests that were written in [PHPUnit](https://phpunit.de/index.html): ``` bash $ composer test

When creating fixes or implementing new features, it is recommended to run the above command to always check if the updated code introduces errors during development., (*25)

Code quality

To retain the code quality of Weasley, a static code analysis code tool named PHPStan is being used during development. To start, kindly install the specified package in the global environment of Composer:, (*26)

``` bash $ composer global require phpstan/phpstan --dev, (*27)


Once installed, `PHPStan` can now be run using its namesake command: ``` bash $ cd Sample $ phpstan

[!NOTE] When running phpstan, it will use the phpstan.neon file which is already provided by Weasley., (*28)

Coding style

Aside from code quality, Weasley also uses a tool named PHP Coding Standards Fixer for maintaining an opinionated style guide. To use this tooling, it needs also to be installed in the Composer's global environment first:, (*29)

``` bash $ composer global require friendsofphp/php-cs-fixer --dev, (*30)


After its installation, kindly use the `php-cs-fixer` command in the same `Weasley` directory: ``` bash $ cd Sample $ php-cs-fixer fix --config=phpstyle.php

The phpstyle.php file provided by Weasley currently follows the PSR-12 standard as its baseline for the coding style and uses Allman as its indentation style., (*31)

[!NOTE] Installing both PHPStan and PHP Coding Standards Fixer requires a minimum version of PHP at least 7.4., (*32)

Changelog

Please see CHANGELOG for more information what has changed recently., (*33)

License

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

The Versions

25/04 2018

dev-master

9999999-dev https://github.com/rougin/weasley

Generators and helpers for the Slytherin framework.

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper code generator workflow slytherin weasley

20/04 2018

v0.6.3

0.6.3.0 https://github.com/rougin/weasley

Generators and helpers for the Slytherin framework.

  Sources   Download

MIT

The Requires

 

The Development Requires

helper generator workflow slytherin weasley

16/04 2018

v0.6.2

0.6.2.0 https://github.com/rougin/weasley

Generators and helpers for the Slytherin framework.

  Sources   Download

MIT

The Requires

 

The Development Requires

helper generator workflow slytherin weasley

13/04 2018

v0.6.1

0.6.1.0 https://github.com/rougin/weasley

Generators and helpers for the Slytherin framework.

  Sources   Download

MIT

The Requires

 

The Development Requires

helper generator workflow slytherin weasley

13/04 2018

v0.6.0

0.6.0.0 https://github.com/rougin/weasley

Generators and helpers for the Slytherin framework.

  Sources   Download

MIT

The Requires

 

The Development Requires

helper generator workflow slytherin weasley

05/01 2018

v0.4.4

0.4.4.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.5.0

0.5.0.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.4.3

0.4.3.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.4.2

0.4.2.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.4.1

0.4.1.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.4.0

0.4.0.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.3.1

0.3.1.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.3.0

0.3.0.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.2.1

0.2.1.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.2.0

0.2.0.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.1.2

0.1.2.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.1.1

0.1.1.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley

05/01 2018

v0.1.0

0.1.0.0 https://github.com/rougin/weasley

Generators and helpers for improving your Slytherin workflow

  Sources   Download

MIT

The Requires

 

The Development Requires

generators helper workflow slytherin weasley