Skip to content

Commit

Permalink
bridge to sunrise router
Browse files Browse the repository at this point in the history
  • Loading branch information
fenric committed Oct 12, 2021
1 parent 8b8193d commit 609c932
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/Bridge/Sunrise/SunriseRouteProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php declare(strict_types=1);

/**
* It's free open-source software released under the MIT License.
*
* @author Anatoly Fenric <anatoly@fenric.ru>
* @copyright Copyright (c) 2019, Anatoly Fenric
* @license https://github.com/sunrise-php/http-router-openapi/blob/master/LICENSE
* @link https://github.com/sunrise-php/http-router-openapi
*/

namespace Sunrise\Http\Router\OpenApi\Bridge\Sunrise;

/**
* Import classes
*/
use Sunrise\Http\Router\OpenApi\RouteInterface as OpenapiRouteInterface;
use Sunrise\Http\Router\RequestHandler\CallableRequestHandler as SunriseCallableRequestHandler;
use Sunrise\Http\Router\RouteInterface as SunriseRouteInterface;
use ReflectionClass;
use ReflectionMethod;
use Reflector;

/**
* Import functions
*/
use function is_array;
use function Sunrise\Http\Router\path_parse;
use function Sunrise\Http\Router\path_plain;

/**
* Sunrise Route Proxy
*/
final class SunriseRouteProxy implements OpenapiRouteInterface
{

/**
* Proxied Sunrise Route
*
* @var SunriseRouteInterface
*/
private $route;

/**
* Constructor of the class
*
* @param SunriseRouteInterface $route
*/
public function __construct(SunriseRouteInterface $route)
{
$this->route = $route;
}

/**
* {@inheritdoc}
*/
public function getName() : string
{
return $this->route->getName();
}

/**
* {@inheritdoc}
*/
public function getMethods() : array
{
return $this->route->getMethods();
}

/**
* {@inheritdoc}
*/
public function getPlainPath() : string
{
return path_plain($this->route->getPath());
}

/**
* {@inheritdoc}
*/
public function getPathAttributes() : array
{
return path_parse($this->route->getPath());
}

/**
* {@inheritdoc}
*/
public function getSummary() : string
{
return $this->route->getSummary();
}

/**
* {@inheritdoc}
*/
public function getDescription() : string
{
return $this->route->getDescription();
}

/**
* {@inheritdoc}
*/
public function getTags() : array
{
return $this->route->getTags();
}

/**
* {@inheritdoc}
*/
public function getHolder() : ?Reflector
{
$handler = $this->route->getRequestHandler();
if (!($handler instanceof SunriseCallableRequestHandler)) {
return new ReflectionClass($handler);
}

$callback = $handler->getCallback();
if (is_array($callback)) {
return new ReflectionMethod(...$callback);
}

return null;
}
}

0 comments on commit 609c932

Please sign in to comment.