ryannerd / willow Goto Github PK
View Code? Open in Web Editor NEWWillow Framework for quickly creating ORM/RESTful APIs
Home Page: https://www.notion.so/ryannerd/Get-Started-bf56317580884ccd95ed8d3889f83c72
License: MIT License
Willow Framework for quickly creating ORM/RESTful APIs
Home Page: https://www.notion.so/ryannerd/Get-Started-bf56317580884ccd95ed8d3889f83c72
License: MIT License
Example:
/**
* @property integer $Id
* @property integer $ResidentId
* @property string $Drug
* @property string $Strength
* @property string $Barcode
* @property string $Directions
* @property string $Notes
* @property integer $FillDateDay
* @property integer $FillDateMonth
* @property integer $FillDateYear
* @property boolean $OTC
* @property DateTime $Created
* @property DateTime $Updated
* @property DateTime $deleted_at
*
* @mixin Builder
*/
class Medicine extends ModelBase
{
public const FIELDS = [
'Id' => 'integer',
'ResidentId' => 'integer',
'UserId' => 'integer',
'Drug' => 'string',
'Strength' => 'string',
'Barcode' => 'string',
'Directions' => 'string',
'Notes' => 'string',
'FillDateMonth' => 'tinyint',
'FillDateDay' => 'tinyint',
'FillDateYear' => 'integer',
'OTC' => 'boolean',
'Created' => 'datetime',
'Updated' => 'datetime',
'deleted_at' => 'datetime'
];
}
Error message:
PHP Warning: unlink(/home/ryan/Projects/test-willow/app/Robo/Plugin/Commands/../../../Controllers/Sample):
Is a directory in /home/ryan/Projects/test-willow/app/Robo/Plugin/Commands/MakeCommands.php on line 259
<?php
declare(strict_types=1);
namespace Willow\Controllers;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Respect\Validation\Validator as V;
use Willow\Middleware\ResponseBody;
abstract class WriteValidatorBase
{
public function __invoke(Request $request, RequestHandler $handler): ResponseInterface
{
$responseBody = $this->processValidation($request->getAttribute('response_body'));
// If there are any missing or required data points then we short circuit and return invalid request.
if ($responseBody->hasMissingRequiredOrInvalid()) {
$responseBody = $responseBody
->setStatus(ResponseBody::HTTP_BAD_REQUEST)
->setMessage('Missing or invalid request');
return $responseBody();
}
return $handler->handle($request);
}
/**
* You should override this function to perform the validations
* @param ResponseBody $responseBody
* @return ResponseBody
*/
protected function processValidation(ResponseBody $responseBody): ResponseBody {
return $responseBody;
}
/**
* Default processValidation() for generic validations
* @param ResponseBody $responseBody
* @param array $fields
* @return ResponseBody
*/
protected function defaultValidation(ResponseBody $responseBody, array $fields): ResponseBody {
$parsedRequest = $responseBody->getParsedRequest();
// Iterate all the model fields
foreach($fields as $field => $dataType) {
$protectedField = $dataType[0] === '*';
// Is the model field NOT in the request?
if (!V::key($field)->validate($parsedRequest)) {
// Any dataType proceeded with an * are protected fields and can not be changed (e.g. password_hash)
if ($protectedField) {
continue;
}
// If the request is missing this field so register it as optional
$responseBody->registerParam('optional', $field, $dataType);
} else {
// If Datatype is proceeded with an * it means the field is protected and can not be changed (e.g. password_hash)
if ($protectedField) {
$responseBody->registerParam('invalid', $field, null);
}
// Don't allow emoji characters -- this prevents SQL Errors
if ($dataType === 'string') {
$fieldValue = $parsedRequest[$field];
if (V::notEmpty()->validate($fieldValue) && !V::notEmoji()->validate($fieldValue)) {
$responseBody->registerParam('invalid', $field, 'alpha-numeric. Value given: ' . $fieldValue);
}
}
}
}
return $responseBody;
}
}
In theory the following databases are supported (by Eloquent ORM):
Need some help testing these.
Update better describes what the action is. POST
is used to write the data but the operation can be both an Insert and an Update.
See: https://php-di.org/doc/frameworks/slim.html
Possibility of using DI for response_body attribute injection via the constructor.
Add PHPUnit as a dev dependency and create some unit tests:
Middleware:
Short answer is simplicity.
See: https://dev.to/mehmehmehlol/put-vs-patch-put-vs-post-56i9
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.