{"id":16423604,"url":"https://github.com/rougin/weasley","last_synced_at":"2025-10-05T20:56:27.810Z","repository":{"id":62537435,"uuid":"63803636","full_name":"rougin/weasley","owner":"rougin","description":"Helpers and utilities for Slytherin.","archived":false,"fork":false,"pushed_at":"2025-07-29T06:32:15.000Z","size":460,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-30T10:55:19.432Z","etag":null,"topics":["php-generator","php-helpers","slytherin","weasley","workflow"],"latest_commit_sha":null,"homepage":"https://roug.in/weasley/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rougin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-20T18:09:56.000Z","updated_at":"2025-07-29T06:28:44.000Z","dependencies_parsed_at":"2024-03-28T13:39:51.505Z","dependency_job_id":"e1789ea9-4bfd-4c4b-9839-4c637f05e2a3","html_url":"https://github.com/rougin/weasley","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/rougin/weasley","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fweasley","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fweasley/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fweasley/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fweasley/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rougin","download_url":"https://codeload.github.com/rougin/weasley/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fweasley/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278518899,"owners_count":26000177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php-generator","php-helpers","slytherin","weasley","workflow"],"created_at":"2024-10-11T07:40:23.805Z","updated_at":"2025-10-05T20:56:27.803Z","avatar_url":"https://github.com/rougin.png","language":"PHP","readme":"# Weasley\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]][link-license]\n[![Build Status][ico-build]][link-build]\n[![Coverage Status][ico-coverage]][link-coverage]\n[![Total Downloads][ico-downloads]][link-downloads]\n\n`Weasley` is a PHP package that provides generators, helpers, and utility classes for the [Slytherin](https://roug.in/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](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete).\n\n## Installation\n\nInstall the `Weasley` package via [Composer](https://getcomposer.org/):\n\n``` bash\n$ composer require rougin/weasley\n```\n\n\u003e [!NOTE]\n\u003e When using the `weasley` command, the [Symfony Console](https://symfony.com/doc/current/components/console.html) must be installed first.\n\nOnce installed, kindly see the following features below provided by `Weasley`:\n\n## Code generators\n\n`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.\n\nTo access the list of available commands, kindly run its namesake command from the terminal:\n\n``` bash\n$ vendor/bin/weasley\n```\n\n### `make:check`\n\nCreates a new check (validation) class based on [Valitron](https://github.com/vlucas/valitron).\n\n### `make:handler`\n\nCreates a new [HTTP Middleware](https://github.com/rougin/slytherin/wiki/Middleware) class.\n\n### `make:package`\n\nCreates a new [Slytherin Integration](https://github.com/rougin/slytherin/wiki/IntegrationInterface-Implementation) class.\n\n### `make:route`\n\nCreates a new [HTTP route](https://github.com/rougin/slytherin/wiki/Defining-HTTP-Routes) class.\n\n## HTTP routes\n\nIn creating web applications, `Weasley` also provides PHP classes to create HTTP routes based on the [RESTful](https://en.wikipedia.org/wiki/REST) style.\n\n\u003e [!NOTE]\n\u003e In other PHP frameworks, this is also known as `Controllers`.\n\n### `HttpRoute`\n\nA simple HTTP route class for RESTful APIs.\n\n### `JsonRoute`\n\nSimilar with `HttpRoute` but the response will be returned in [JSON](https://en.wikipedia.org/wiki/JSON) format.\n\n## Third-party packages\n\nTo conform with the usage of [`IntegrationInterface`](https://github.com/rougin/slytherin/wiki/IntegrationInterface-Implementation) from `Slytherin`, `Weasley` also provides the following third-party integrations with other PHP packages:\n\n### `Laravel\\Eloquent`\n\nThis package enables the usage of [Eloquent](https://laravel.com/docs/eloquent) to `Slytherin` which is an [Object-relational mapper (ORM)](https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping) from [Laravel](https://laravel.com). To use this package, kindly install its required package first in `Composer`:\n\n``` bash\n$ composer require illuminate/database\n```\n\n### `Laravel\\Blade`\n\n`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`:\n\n``` bash\n$ composer require illuminate/view\n```\n\n### `Laravel\\Paginate`\n\nThis 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:\n\n``` bash\n$ composer require illuminate/paginate\n```\n\n### `Session`\n\n`Weasley` also provides a simple implementation of the [SessionHandlerInterface](https://secure.php.net/manual/en/class.sessionhandlerinterface.php).\n\n## HTTP handlers\n\n`Weasley` has the following HTTP middlewares (HTTP handlers in this case) to improve the handling of HTTP requests and its respective responses:\n\n### `AllowCrossOrigin`\n\nAdds additional headers for [Cross-origin resource sharing](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) (CORS).\n\n### `EmptyStringToNull`\n\nConverts the empty strings from request as `null`.\n\n### `JsonContentType`\n\nChanges content response to `application/json`.\n\n### `MutateRequest`\n\nA middleware that can be extended to mutate/transform values from the request.\n\n### `SpoofHttpMethod`\n\nReplaces the HTTP verb  from `_method` value.\n\n### `TrimStringValue`\n\nTrims the strings from an incoming request.\n\n## Mutators\n\nProvided 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.):\n\n### `JsonMutator`\n\nMutates a `PSR-07` response in JSON format.\n\n### `RestMutator`\n\nMutates 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).\n\n## Validation\n\n`Weasley` also provides a simple validation class on top of [Valitron](https://github.com/vlucas/valitron) using the `Check` class:\n\n``` php\nuse Rougin\\Weasley\\Check;\n\nclass UserCheck extends Check\n{\n    protected $labels =\n    [\n        'name' =\u003e 'Name',\n        'email' =\u003e 'Email',\n        'age' =\u003e 'Age',\n    ];\n\n    protected $rules =\n    [\n        'name' =\u003e 'required',\n        'setting' =\u003e 'required|email',\n        'type' =\u003e 'required|numeric',\n    ];\n}\n```\n\nOnce created, the data can be submitted to the said class for validation:\n\n``` php\n$check = new UserCheck;\n\n$data = /* e.g., data from request */;\n\nif ($check-\u003evalid($data))\n{\n  // $data passed from validation\n}\nelse\n{\n  // Get the available errors ---\n  $errors = $check-\u003eerrors();\n  // ----------------------------\n\n  // Or get the first error only ---\n  echo $check-\u003efirstError();\n  // -------------------------------\n}\n```\n\n## Testing\n\nIf 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:\n\n``` bash\n$ git clone https://github.com/rougin/weasley.git \"Sample\"\n```\n\nAfter cloning, use `Composer` to install its required packages:\n\n``` bash\n$ cd Sample\n$ composer update\n```\n\n\u003e [!NOTE]\n\u003e 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.\n\nOnce 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`:\n\n### Unit tests\n\n`Weasley` also contains unit tests that were written in [PHPUnit](https://phpunit.de/index.html):\n\n``` bash\n$ composer test\n```\n\nWhen 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.\n\n### Code quality\n\nTo retain the code quality of `Weasley`, a static code analysis code tool named [PHPStan](https://phpstan.org/) is being used during development. To start, kindly install the specified package in the global environment of `Composer`:\n\n``` bash\n$ composer global require phpstan/phpstan --dev\n```\n\nOnce installed, `PHPStan` can now be run using its namesake command:\n\n``` bash\n$ cd Sample\n$ phpstan\n```\n\n\u003e [!NOTE]\n\u003e When running `phpstan`, it will use the `phpstan.neon` file which is already provided by `Weasley`.\n\n### Coding style\n\nAside from code quality, `Weasley` also uses a tool named [PHP Coding Standards Fixer](https://cs.symfony.com/) for maintaining an opinionated style guide. To use this tooling, it needs also to be installed in the `Composer`'s global environment first:\n\n``` bash\n$ composer global require friendsofphp/php-cs-fixer --dev\n```\n\nAfter its installation, kindly use the `php-cs-fixer` command in the same `Weasley` directory:\n\n``` bash\n$ cd Sample\n$ php-cs-fixer fix --config=phpstyle.php\n```\n\nThe `phpstyle.php` file provided by `Weasley` currently follows the [PSR-12](https://www.php-fig.org/psr/psr-12/) standard as its baseline for the coding style and uses [Allman](https://en.wikipedia.org/wiki/Indentation_style#Allman_style) as its indentation style.\n\n\u003e [!NOTE]\n\u003e Installing both `PHPStan` and `PHP Coding Standards Fixer` requires a minimum version of PHP at least `7.4`.\n\n## Changelog\n\nPlease see [CHANGELOG][link-changelog] for more information what has changed recently.\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE][link-license] for more information.\n\n[ico-build]: https://img.shields.io/github/actions/workflow/status/rougin/weasley/build.yml?style=flat-square\n[ico-coverage]: https://img.shields.io/codecov/c/github/rougin/weasley?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/rougin/weasley.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-version]: https://img.shields.io/packagist/v/rougin/weasley.svg?style=flat-square\n\n[link-build]: https://github.com/rougin/weasley/actions\n[link-changelog]: https://github.com/rougin/weasley/blob/master/CHANGELOG.md\n[link-contributors]: https://github.com/rougin/weasley/contributors\n[link-coverage]: https://app.codecov.io/gh/rougin/weasley\n[link-downloads]: https://packagist.org/packages/rougin/weasley\n[link-license]: https://github.com/rougin/weasley/blob/master/LICENSE.md\n[link-packagist]: https://packagist.org/packages/rougin/weasley\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Fweasley","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frougin%2Fweasley","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Fweasley/lists"}