File manager - Edit - /home/opticamezl/www/newok/http-server.zip
Back
PK c��\(�a� � bootstrap.phpnu �[��� <?php use YOOtheme\BodyMiddleware; use YOOtheme\CsrfMiddleware; use YOOtheme\Router; use YOOtheme\RouterMiddleware; use YOOtheme\Routes; use YOOtheme\UrlResolver; return [ 'events' => [ 'app.request' => [ BodyMiddleware::class => ['parseJson', 10], CsrfMiddleware::class => ['@handle', 10], RouterMiddleware::class => [['@handleRoute', 30], ['@handleStatus', 20]], ], 'app.error' => [RouterMiddleware::class => ['@handleError', 10]], 'url.resolve' => [UrlResolver::class => 'resolve'], ], 'aliases' => [ Routes::class => 'routes', ], 'services' => [ Routes::class => '', Router::class => '', RouterMiddleware::class => '', ], ]; PK c��\;��� � src/Route.phpnu �[��� <?php namespace YOOtheme; class Route { /** * @var string */ protected $name; /** * @var string */ protected $path; /** * @var string|callable */ protected $callable; /** * @var array */ protected $methods = []; /** * @var array */ protected $attributes = []; /** * Constructor. * * @param string $path * @param string|callable $callable * @param string|string[] $methods */ public function __construct($path, $callable, $methods = []) { $this->setPath($path); $this->setMethods($methods); $this->callable = $callable; } /** * Gets the path. * * @return string */ public function getPath() { return $this->path; } /** * Sets the path. * * @param string $path * * @return $this */ public function setPath($path) { $this->path = '/' . trim($path, '/'); return $this; } /** * Gets the callable. * * @return string|callable */ public function getCallable() { return $this->callable; } /** * Gets the methods. * * @return string[] */ public function getMethods() { return $this->methods; } /** * Sets the methods. * * @param string|string[] $methods * * @return $this */ public function setMethods($methods) { $this->methods = array_map('strtoupper', (array) $methods); return $this; } /** * Gets an attribute. * * @param string $name * @param mixed $default * * @return mixed */ public function getAttribute($name, $default = null) { return $this->attributes[$name] ?? $default; } /** * Sets an attribute. * * @param string $name * @param mixed $value * * @return $this */ public function setAttribute($name, $value) { $this->attributes[$name] = $value; return $this; } /** * Gets the attributes. * * @return array */ public function getAttributes() { return $this->attributes; } /** * Sets the attributes. * * @param array $attributes * * @return $this */ public function setAttributes(array $attributes) { $this->attributes = $attributes; return $this; } } PK c��\�1�� � src/RouterMiddleware.phpnu �[��� <?php namespace YOOtheme; use YOOtheme\Http\Request; use YOOtheme\Http\Response; class RouterMiddleware { public const FOUND = 1; public const NOT_FOUND = 0; public const METHOD_NOT_ALLOWED = 2; /** * @var Router */ protected $router; /** * Constructor. * * @param Router $router */ public function __construct(Router $router) { $this->router = $router; } /** * Handles the route dispatch. * * @param Request $request * @param callable $next * * @return Response */ public function handleRoute($request, callable $next) { return $next($this->router->dispatch($request)); } /** * Handles the route status. * * @param Request $request * @param callable $next * * @return Response */ public function handleStatus($request, callable $next) { $status = $request->getAttribute('routeStatus'); // Not found if ($status === static::NOT_FOUND) { $request->abort(404); } // Method not allowed if ($status === static::METHOD_NOT_ALLOWED) { $request->abort(405); } return $next($request); } /** * Handles an error. * * @param Response $response * @param \Exception $exception * * @return Response */ public function handleError($response, $exception) { if ($exception instanceof Http\Exception) { return $response->withStatus($exception->getCode(), $exception->getMessage()); } return $response->withStatus(500, $exception->getMessage()); } } PK c��\<�yݐ � src/UrlResolver.phpnu �[��� <?php namespace YOOtheme; class UrlResolver { public static function resolve(Config $config, $path, $parameters, $secure, callable $next) { $root = $config('app.rootDir'); $path = Path::resolveAlias($path); if (Path::isBasePath($root, $path)) { $path = Path::relative($root, $path); } return $next($path, $parameters, $secure); } } PK c��\�y�> src/Routes.phpnu �[��� <?php namespace YOOtheme; class Routes implements \IteratorAggregate { /** * @var Route[] */ protected $index = []; /** * @var Route[] */ protected $routes = []; /** * Adds a route. * * @param string|string[] $method * @param string $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function map($method, $path, $handler, array $attributes = []) { $route = new Route($path, $handler, $method); $route->setAttributes($attributes); if ($this->index) { $this->index = []; } return $this->routes[] = $route; } /** * Adds a GET route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function get($path, $handler, array $attributes = []) { return $this->map('GET', $path, $handler, $attributes); } /** * Adds a POST route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function post($path, $handler, array $attributes = []) { return $this->map('POST', $path, $handler, $attributes); } /** * Adds a PUT route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function put($path, $handler, array $attributes = []) { return $this->map('PUT', $path, $handler, $attributes); } /** * Adds a PATCH route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function patch($path, $handler, array $attributes = []) { return $this->map('PATCH', $path, $handler, $attributes); } /** * Adds a DELETE route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function delete($path, $handler, array $attributes = []) { return $this->map('DELETE', $path, $handler, $attributes); } /** * Adds a HEAD route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function head($path, $handler, array $attributes = []) { return $this->map('HEAD', $path, $handler, $attributes); } /** * Adds a OPTIONS route. * * @param string|string[] $path * @param string|callable $handler * @param array $attributes * * @return Route */ public function options($path, $handler, array $attributes = []) { return $this->map('OPTIONS', $path, $handler, $attributes); } /** * Adds a group of routes. * * @param string $prefix * @param callable $group * * @return self */ public function group($prefix, callable $group) { $routes = new self(); $group($routes); return $this->mount($prefix, $routes); } /** * Mounts a route collection. * * @param string $prefix * @param Routes $routes * * @return $this */ public function mount($prefix, Routes $routes) { $prefix = trim($prefix, '/'); foreach ($routes as $route) { $this->routes[] = $route->setPath($prefix . $route->getPath()); } return $this; } /** * Gets a route by name. * * @param string $name * * @return Route|null */ public function getRoute($name) { $index = $this->getIndex(); return $index[$name] ?? null; } /** * Gets an index of routes. * * @return Route[] */ public function getIndex() { if (!$this->index) { foreach ($this->routes as $index => $route) { $this->index[$route->getAttribute('name', "route_{$index}")] = $route; } } return $this->index; } /** * Implements the IteratorAggregate. * * @return \ArrayIterator */ #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayIterator($this->routes); } } PK c��\�a�9� � src/CsrfMiddleware.phpnu �[��� <?php namespace YOOtheme; use YOOtheme\Http\Request; use YOOtheme\Http\Response; class CsrfMiddleware { /** * Current token. * * @var string */ protected $token; /** * Verify callable. * * @var callable */ protected $verify; /** * Constructor. * * @param string $token * @param ?callable $verify */ public function __construct($token, ?callable $verify = null) { $this->token = $token; $this->verify = $verify ?: [$this, 'verifyToken']; } /** * Handles CSRF token from request. * * @param Request $request * @param callable $next * * @return Response */ public function handle($request, callable $next) { $csrf = $request->getAttribute('csrf', in_array($request->getMethod(), ['POST', 'DELETE'])); if ($csrf && !($this->verify)($request->getHeaderLine('X-XSRF-Token'))) { $request->abort(401, 'Invalid CSRF token.'); } return $next($request); } /** * Verifies a CSRF token. */ public function verifyToken(string $token): bool { return $this->token === $token; } } PK c��\�,%0 0 src/BodyMiddleware.phpnu �[��� <?php namespace YOOtheme; use YOOtheme\Http\Request; use YOOtheme\Http\Response; class BodyMiddleware { /** * Handles JSON requests. * * @param Request $request * @param callable $next * * @return Response */ public static function parseJson($request, callable $next) { if (stripos($request->getHeaderLine('Content-Type'), 'application/json') === 0) { $request = $request->withParsedBody(json_decode((string) $request->getBody(), true)); } return $next($request); } } PK c��\�oҋ � src/HttpClientInterface.phpnu �[��� <?php namespace YOOtheme; interface HttpClientInterface { /** * Execute a GET HTTP request. * * @param string $url * @param array $options * * @return mixed */ public function get($url, $options = []); /** * Execute a POST HTTP request. * * @param string $url * @param string $data * @param array $options * * @return mixed */ public function post($url, $data = null, $options = []); /** * Execute a PUT HTTP request. * * @param string $url * @param string $data * @param array $options * * @return mixed */ public function put($url, $data = null, $options = []); /** * Execute a DELETE HTTP request. * * @param string $url * @param array $options * * @return mixed */ public function delete($url, $options = []); } PK c��\�� c c src/Router.phpnu �[��� <?php namespace YOOtheme; use YOOtheme\Http\Request; class Router { /** * @var Routes */ protected $routes; /** * Constructor. * * @param Routes $routes */ public function __construct(Routes $routes) { $this->routes = $routes; } /** * Dispatches router for a request. * * @param Request $request * * @return Request */ public function dispatch(Request $request) { $path = '/' . trim($request->getQueryParam('p', ''), '/'); foreach ($this->routes->getIndex() as $route) { if ($route->getMethods() && !in_array($request->getMethod(), $route->getMethods())) { continue; } if (preg_match($this->getPattern($route), $path, $matches)) { $params = []; foreach ($matches as $key => $value) { if (is_string($key)) { $params[$key] = urldecode($value); } } foreach ($route->getAttributes() as $name => $value) { $request = $request->withAttribute($name, $value); } return $request ->withAttribute('route', $route) ->withAttribute('routeParams', $params) ->withAttribute('routeStatus', 1); } } return $request->withAttribute('routeStatus', 0); } /** * Gets the route regex pattern. * * @param Route $route * * @return string */ protected function getPattern(Route $route) { return '#^' . preg_replace_callback( '#\{(\w+)\}#', fn($matches) => '(?P<' . $matches[1] . '>[^/]+)', $route->getPath(), ) . '$#'; } } PK c��\(�a� � bootstrap.phpnu �[��� PK c��\;��� � 3 src/Route.phpnu �[��� PK c��\�1�� � V src/RouterMiddleware.phpnu �[��� PK c��\<�yݐ � J src/UrlResolver.phpnu �[��� PK c��\�y�> src/Routes.phpnu �[��� PK c��\�a�9� � b( src/CsrfMiddleware.phpnu �[��� PK c��\�,%0 0 j- src/BodyMiddleware.phpnu �[��� PK c��\�oҋ � �/ src/HttpClientInterface.phpnu �[��� PK c��\�� c c �3 src/Router.phpnu �[��� PK � W;
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings