Files
kiri-core/Annotation/Route/Socket.php
T

63 lines
1.1 KiB
PHP
Raw Normal View History

2020-12-14 19:03:05 +08:00
<?php
2020-12-15 12:24:38 +08:00
namespace Annotation\Route;
2020-12-14 19:03:05 +08:00
2020-12-15 14:04:02 +08:00
use Annotation\IAnnotation;
2020-12-14 19:03:05 +08:00
use Closure;
2020-12-15 12:24:38 +08:00
use Exception;
2020-12-15 12:07:46 +08:00
use HttpServer\Route\Node;
2021-02-22 17:44:24 +08:00
use HttpServer\Route\Router;
2020-12-15 12:24:38 +08:00
use ReflectionException;
2020-12-14 19:03:05 +08:00
use Snowflake\Exception\ComponentException;
2020-12-15 12:07:46 +08:00
use Snowflake\Exception\ConfigException;
2020-12-15 12:24:38 +08:00
use Snowflake\Exception\NotFindClassException;
2020-12-14 19:03:05 +08:00
use Snowflake\Snowflake;
2020-12-15 12:24:38 +08:00
/**
* Class Socket
* @package Annotation
*/
2020-12-15 14:04:02 +08:00
#[\Attribute(\Attribute::TARGET_METHOD)] class Socket implements IAnnotation
2020-12-14 19:03:05 +08:00
{
2020-12-15 12:24:38 +08:00
const CLOSE = 'CLOSE';
const MESSAGE = 'MESSAGE';
const HANDSHAKE = 'HANDSHAKE';
2020-12-14 19:03:05 +08:00
/**
2020-12-15 12:24:38 +08:00
* Socket constructor.
* @param string $event
* @param string|null $uri
2020-12-14 19:03:05 +08:00
*/
public function __construct(
2020-12-15 12:24:38 +08:00
public string $event,
2020-12-16 15:37:23 +08:00
public ?string $uri = null
2020-12-14 19:03:05 +08:00
)
{
}
/**
2021-02-22 17:44:24 +08:00
* @param array $handler
* @return Router
2020-12-14 19:03:05 +08:00
* @throws ComponentException
2020-12-15 12:07:46 +08:00
* @throws ConfigException
2020-12-14 19:03:05 +08:00
*/
2021-02-22 17:44:24 +08:00
public function execute(array $handler): Router
2020-12-14 19:03:05 +08:00
{
// TODO: Implement setHandler() method.
2021-02-22 17:44:24 +08:00
$router = Snowflake::app()->getRouter();
2020-12-14 19:03:05 +08:00
2020-12-15 16:55:50 +08:00
$method = $this->event . '::' . (is_null($this->uri) ? 'event' : $this->uri);
2021-03-03 13:49:55 +08:00
var_dump($method);
2021-02-22 17:44:24 +08:00
$router->addRoute($method, $handler, 'sw::socket');
return $router;
2020-12-14 19:03:05 +08:00
}
}