Routines as events
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 605
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
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'
));
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.
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.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100