1. Go to this page and download the library: Download ray/query-module library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class Todo
{
/**
* @var callable
*/
private $createTodo;
/**
* @var callable
*/
private $todo;
/**
* @Named("createTodo=todo_insert, todo=todo_item_by_id")
*/
public function __construct(
callable $createTodo,
callable $todo
){
$this->createTodo = $createTodo;
$this->todo = $todo;
}
public function get(string $uuid)
{
return ($this->todo)(['id' => $uuid]);
}
public function create(string $uuid, string $title)
{
($this->createTodo)([
'id' => $uuid,
'title' => $title
]);
}
}
use Ray\Query\RowInterface;
class Todo
{
/**
* @Named("todo_item_by_id")
*/
public function __construct(RowInterface $todo)
{
$this->todo = $todo;
}
public function get(string $uuid)
{
$todo = ($this->todo)(['id' => $uuid]); // single row data
}
}
use Ray\Query\RowListInterface;
class Todos
{
/**
* @Named("todos")
*/
public function __construct(RowListInterface $todos)
{
$this->todos = $todos;
}
public function get(string $uuid)
{
$todos = ($this->todos)(); // multiple row data
}
}
class Foo
{
/**
* @Query(id="todo_item_by_id")
*/
public function get(string $id)
{
}
}
class FooTempalted
{
/**
* @Query(id="todo_item_by_id?id={a}", templated=true)
*/
public function get(string $a)
{
}
}
class FooRow
{
/**
* @Query(id="ticket_item_by_id", type="row")
*/
public function onGet(string $id) : ResourceObject
{
}
}
use Ray\Di\AbstractModule;
use Ray\Query\SqlQueryModule;
class AppModule extends AbstractModule
{
protected function configure()
{
// WebQueryModuleインストール
$webQueryConfig = [
'todo_post' => ['POST', 'https://httpbin.org/todo'],
'todo_get' => ['GET', 'https://httpbin.org/todo']
];
$guzzleConfig = [];
$this->install(new WebQueryModule($webQueryConfig, $guzzleConfig));
}
}
/**
* @Named("createTodo=todo_post, todo=todo_get")
*/
public function __construct(
callable $createTodo,
callable $todo
){
$this->createTodo = $createTodo;
$this->todo = $todo;
}
// POST
($this->createTodo)([
'id' => $uuid,
'title' => $title
]);
// GET
($this->todo)(['id' => $uuid]);
class CreateTodo implements QueryInterface
{
private $pdo;
private $builder;
public function __construct(PdoInterface $pdo, QueryBuilderInferface $builder)
{
$this->pdo = $pdo;
$this->builder = $builder;
}
public function __invoke(array $query)
{
// Query execution using $pdo and $builder
return $result;
}
}