Skip to content

Commit

Permalink
feat(RouterInterface): fluent api for method initializers.
Browse files Browse the repository at this point in the history
  • Loading branch information
razshare committed Jun 10, 2024
1 parent 257f81b commit 6ea03a7
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 115 deletions.
117 changes: 59 additions & 58 deletions src/lib/Web/Implementations/Router/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function __construct(

/**
* Initialize a new route.
* @param string $symbolicMethod
* @param string $symbolicPath
* @param callable|Closure $function
* @param string $workDirectory
* @return Unsafe<None>
* @param string $symbolicMethod
* @param string $symbolicPath
* @param callable|Closure $function
* @param string $workDirectory
* @return Unsafe<RouterInterface>
*/
public function initialize(
string $symbolicMethod,
Expand Down Expand Up @@ -227,7 +227,8 @@ function : $function,
} catch (ReflectionException $e) {
return error($e);
}
return ok();
// @phpstan-ignore-next-line
return ok($this);
}


Expand Down Expand Up @@ -756,60 +757,60 @@ public function alias(string $originalSymbolicMethod, string $originalSymbolicPa

/**
* Define an event callback for a custom http method.
* @param string $method the name of the http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $method the name of the http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function custom(string $method, string $path, callable|Closure $function):Unsafe {
return $this->initialize($method, $path, $function);
}

/**
* Define an event callback for the "COPY" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function copy(string $path, callable|Closure $function):Unsafe {
return $this->initialize('COPY', $path, $function);
}

/**
* Define an event callback for the "DELETE" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function delete(string $path, callable|Closure $function):Unsafe {
return $this->initialize('DELETE', $path, $function);
}

/**
* Define an event callback for the "GET" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function get(string $path, callable|Closure $function):Unsafe {
return $this->initialize('GET', $path, $function);
}

/**
* Define an event callback for the "HEAD" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function head(string $path, callable|Closure $function):Unsafe {
return $this->initialize('HEAD', $path, $function);
}

/**
* Define an event callback for the "LINK" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function link(string $path, callable|Closure $function):Unsafe {
return $this->initialize('LINK', $path, $function);
Expand All @@ -818,109 +819,109 @@ public function link(string $path, callable|Closure $function):Unsafe {
/**
* Define an event callback for the "LOCK" http method.
*
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function lock(string $path, callable|Closure $function):Unsafe {
return $this->initialize('LOCK', $path, $function);
}

/**
* Define an event callback for the "OPTIONS" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function options(string $path, callable|Closure $function):Unsafe {
return $this->initialize('OPTIONS', $path, $function);
}

/**
* Define an event callback for the "PATCH" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function patch(string $path, callable|Closure $function):Unsafe {
return $this->initialize('PATCH', $path, $function);
}

/**
* Define an event callback for the "POST" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function post(string $path, callable|Closure $function):Unsafe {
return $this->initialize('POST', $path, $function);
}

/**
* Define an event callback for the "PROPFIND" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function propfind(string $path, callable|Closure $function):Unsafe {
return $this->initialize('PROPFIND', $path, $function);
}

/**
* Define an event callback for the "PURGE" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function purge(string $path, callable|Closure $function):Unsafe {
return $this->initialize('PURGE', $path, $function);
}

/**
* Define an event callback for the "PUT" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function put(string $path, callable|Closure $function):Unsafe {
return $this->initialize('PUT', $path, $function);
}

/**
* Define an event callback for the "UNKNOWN" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function unknown(string $path, callable|Closure $function):Unsafe {
return $this->initialize('UNKNOWN', $path, $function);
}

/**
* Define an event callback for the "UNLINK" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function unlink(string $path, callable|Closure $function):Unsafe {
return $this->initialize('UNLINK', $path, $function);
}

/**
* Define an event callback for the "UNLOCK" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function unlock(string $path, callable|Closure $function):Unsafe {
return $this->initialize('UNLOCK', $path, $function);
}

/**
* Define an event callback for the "VIEW" http method.
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<None>
* @param string $path the path the event should listen to.
* @param callable|Closure $function the callback to execute.
* @return Unsafe<RouterInterface>
*/
public function view(string $path, callable|Closure $function):Unsafe {
return $this->initialize('VIEW', $path, $function);
Expand Down
Loading

0 comments on commit 6ea03a7

Please sign in to comment.