Routines as events
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
The proposal centers on Request::routineCall, AbstractRoute::appendRoutine, and a new RoutineDispatcher, but it does not name repository files or tests. First inspect the existing routine and route implementations and discuss the incomplete design before coding. Done would require an agreed dispatcher design and verified support for multiple handlers per type.
Written by the indexing model from the issue text.
Description
What if routines were events? Since they
At first purely cosmetic refactor imploring the use of a Dispatcher pattern instead of Abstract Routine doing the work.
<?php
namespace Respect\Rest\Routines;
class RoutineDispatcher
{
private static $handlers = array();
public static function addHandler(string $type, Routinable $routine)
{
if (!is_array(static::$handlers[$type]))
static::$handlers[$type] = array();
static::$handlers[$type][] = $routine;
}
public static function dispatch(string $type, string $method, array $args) {
foreach (static::$handler[$type] as $routine)
call_user_func_array(array($routine, $method), $args);
}
}
class Request
{
/** ... */
public function routineCall($type, $method, AbstractRoutinable $routine, &$routeParamsValues)
{
/** ... */
$callbackParameters = $routeParamsValues;
return RoutineDispatcher::dispatch($type, $method, array($this, $callbackParameters));
}
}
class AbstractRoute
{
public function appendRoutine(Routinable $routine)
{
RoutineDispatcher::addHandler(get_class($routine), $routine);
return $this;
}
}
Making things a tad more structured, understandable logical and already adding the benefit of multiple handlers per type which will allow for this:
$r3->get('/about', function() {
return array('v' => 2.0);
})->accept(array(
'text/html' => function($data) {
list($k,$v)=each($data);
return "<strong>$k</strong>: $v";
}
))->accept(array(
'application/json' => 'json_encode'
));
- Dominant language
- PHP
- Stars
- 605
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Respect/Rest
-
Project Status Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
-
New Roadmap Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Solved site promotion gate fails on runner PHP patch drift (expects 8.2.33, runner installs 8.2.34) Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Automattic/blocks-engine#2161 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/static-site-importer#1824 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
0. Needs triage 35-feedback bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100