- Lean's API WIP on forms and ApiRenderer
This commit is contained in:
1 parent
3ce356e1f2
commit
4d7053a9cb
30 files changed
+1003
-56
No files matched your search
+42
-8
@@ -5,22 +5,27 @@ namespace Lean\Api;
|
||||
use Lean\Factory\HttpFactory;
|
||||
use Notes\ObjectReflection;
|
||||
use Notes\Route\Attribute\Method\Route;
|
||||
use Notes\Security\SecurityHandler;
|
||||
use Picea\Extension\UrlExtension;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Taxus\Taxus;
|
||||
|
||||
class RouteDescriptor
|
||||
{
|
||||
public string $routeLine = <<<HTML
|
||||
<li>
|
||||
<span><a href='%s' title="%s" style='font-family:monospace;font-size:.85em'>%s</a> - %s</span>
|
||||
<span style='color:#ac1b1b'>%s</span>
|
||||
<small style="color:#374300">%s</small>
|
||||
</li>
|
||||
HTML;
|
||||
protected SecurityHandler $securityHandler;
|
||||
|
||||
protected Taxus $taxus;
|
||||
|
||||
public function __construct(
|
||||
public object $controller,
|
||||
protected UrlExtension $urlExtension,
|
||||
) {}
|
||||
ContainerInterface $container
|
||||
) {
|
||||
if ($container->has(SecurityHandler::class) && $container->has(Taxus::class)) {
|
||||
$this->securityHandler = $container->get(SecurityHandler::class);
|
||||
$this->taxus = $container->get(Taxus::class);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRoutes() : array
|
||||
{
|
||||
@@ -47,6 +52,7 @@ HTML;
|
||||
'description'=> $route->description,
|
||||
#'methods' =>implode(', ', (array)$route->method),
|
||||
'methods' => (array) $route->method,
|
||||
'privileges' => $this->getPrivilegeFromRoute($method->name),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -66,4 +72,32 @@ HTML;
|
||||
|
||||
return implode('/', $paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method Which method are we inspecting
|
||||
* @return false|array|null Returns NULL when securityHandler is undefined, FALSE when no security applies for this method and else an array of ['admin' => [ 'status' => true, 'description' => "' ], ...].
|
||||
*/
|
||||
protected function getPrivilegeFromRoute(string $method) : null|false|array
|
||||
{
|
||||
if ( isset($this->securityHandler) ){
|
||||
$list = [];
|
||||
|
||||
if ( $this->securityHandler->isLocked($this->controller::class, $method) ) {
|
||||
foreach($this->taxus->list as $name => $definition) {
|
||||
if ($definition[0]->testableArguments !== null) {
|
||||
if ( $this->securityHandler->hasGrantPermission($this->controller::class, $method, ...$definition[0]->testableArguments) ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user