Skip to content

Commit

Permalink
Improve code documentation for Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Dec 10, 2023
1 parent 11f464b commit c3eec72
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 42 deletions.
15 changes: 8 additions & 7 deletions src/Http/HttpIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Rougin\Slytherin\Http\ServerRequest;
use Rougin\Slytherin\Integration\Configuration;
use Rougin\Slytherin\Integration\IntegrationInterface;
use Rougin\Slytherin\System;
use Zend\Diactoros\Response as ZendResponse;
use Zend\Diactoros\ServerRequestFactory;

Expand Down Expand Up @@ -124,26 +125,26 @@ protected function headers(array $server)
*/
protected function resolve(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response)
{
$empty = $this->preferred === null;
$class = 'Zend\Diactoros\ServerRequestFactory';

$hasDiactoros = class_exists('Zend\Diactoros\ServerRequestFactory');
$empty = $this->preferred === null;

$wantDiactoros = $this->preferred === 'diactoros';
$wantZend = $this->preferred === 'diactoros';

if (($empty || $wantDiactoros) && $hasDiactoros)
if (($empty || $wantZend) && class_exists($class))
{
$response = new ZendResponse;

$request = ServerRequestFactory::fromGlobals();
}

$container->set('Psr\Http\Message\ServerRequestInterface', $request);
$container->set(System::REQUEST, $request);

return $container->set('Psr\Http\Message\ResponseInterface', $response);
return $container->set(System::RESPONSE, $response);
}

/**
* Returns a sample $_SERVER values.
* Returns a sample of $_SERVER values.
*
* @return array<string, string>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Http/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2004-2018 Fabien Potencier
Copyright (c) 2004-2023 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 0 additions & 2 deletions src/Integration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ public function get($key, $default = null)
/** @var string */
$index = $keys[(int) $i];

// TODO: Need to refactor ------
/** @phpstan-ignore-next-line */
$data = &$data[$index];
// -----------------------------
}

return $data !== null ? $data : $default;
Expand Down
4 changes: 3 additions & 1 deletion src/Middleware/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Converts callables into Slytherin middlewares.
* Callback
*
* A class that converts callables into Slytherin middlewares.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/Delegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Rougin\Slytherin\Middleware;

/**
* Calls the callback with a specified HTTP request.
* Delegate
*
* NOTE: To be removed in v1.0.0. Use "Handler" instead.
*
* @package Slytherin
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use Rougin\Slytherin\Http\Response;

/**
* Dispatcher
*
* A sample implementation of the middleware dispatcher.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
Expand Down
5 changes: 4 additions & 1 deletion src/Middleware/Doublepass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Doublepass
*
* A backward compatible handler to double-pass middlewares.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
*/
class Doublepass implements HandlerInterface
{
Expand Down
5 changes: 4 additions & 1 deletion src/Middleware/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Handler
*
* A default route for handling the application logic.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
*/
class Handler implements HandlerInterface
{
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/Handlers/Handler030.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use Rougin\Slytherin\Middleware\HandlerInterface;

/**
* PSR-15 Handler (v0.3.0)
*
* A handler that is backward compatible for the v0.3.0 version of "http-interop".
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/Handlers/Handler041.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Rougin\Slytherin\Middleware\HandlerInterface;

/**
* PSR-15 Handler (v0.4.1)
*
* A handler that is backward compatible for the v0.4.1 version of "http-interop".
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/Handlers/Handler050.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Rougin\Slytherin\Middleware\HandlerInterface;

/**
* PSR-15 Handler (v0.5.0)
*
* A handler that is backward compatible for the v0.5.0 version of "http-interop".
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/Handlers/Handler100.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use Rougin\Slytherin\Middleware\HandlerInterface;

/**
* PSR-15 Handler (v1.0.0)
*
* A handler that is backward compatible for the official implementation of PSR-15.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/Interop.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
use Rougin\Slytherin\Middleware\Handlers\Handler100;

/**
* Interop Handler
*
* A handler that allows all "http-interop" middlewares to interact with Slytherin.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @codeCoverageIgnore
Expand Down
3 changes: 1 addition & 2 deletions src/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
/**
* Middleware
*
* A simple implementation of a middleware dispatcher.
* NOTE: To be removed in v1.0.0. Use "Middleware\Dispatcher" instead.
* NOTE: To be removed in v1.0.0. Use "Dispatcher" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
Expand Down
6 changes: 2 additions & 4 deletions src/Middleware/Stratigility/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

namespace Rougin\Slytherin\Middleware\Stratigility;

use Rougin\Slytherin\Middleware\StratigilityMiddleware;
use Rougin\Slytherin\Middleware\StratigilityDispatcher;

/**
* Stratigility Middleware
*
* A simple implementation of middleware that is built on top of Stratigility.
* NOTE: To be removed in v1.0.0. Use "Middleware\StratigilityDispatcher" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @link https://github.com/zendframework/zend-stratigility
*/
class Middleware extends StratigilityMiddleware
class Middleware extends StratigilityDispatcher
{
}
3 changes: 2 additions & 1 deletion src/Middleware/StratigilityDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @link https://github.com/zendframework/zend-stratigility
*
* @link https://github.com/zendframework/zend-stratigility
*/
class StratigilityDispatcher extends Dispatcher
{
Expand Down
6 changes: 2 additions & 4 deletions src/Middleware/StratigilityMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
/**
* Stratigility Middleware
*
* A simple implementation of middleware that is built on top of Zend's Stratigility.
* NOTE: To be removed in v1.0.0. Use "Middleware\StratigilityDispatcher" instead.
* NOTE: To be removed in v1.0.0. Use "Stratigility\Middleware" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @link https://github.com/zendframework/zend-stratigility
*/
class StratigilityMiddleware extends StratigilityDispatcher
class StratigilityMiddleware extends Stratigility\Middleware
{
}
8 changes: 3 additions & 5 deletions src/Middleware/Vanilla/Delegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

namespace Rougin\Slytherin\Middleware\Vanilla;

use Rougin\Slytherin\Middleware\VanillaDelegate;
use Rougin\Slytherin\Middleware\Delegate as Slytherin;

/**
* Delegate
*
* Calls the callback with a specified HTTP request.
* NOTE: To be removed in v1.0.0. Use "Middleware\Delegate" instead.
* NOTE: To be removed in v1.0.0. Use "Delegate" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @author Rasmus Schultz <rasmus@mindplay.dk>
*/
class Delegate extends VanillaDelegate
class Delegate extends Slytherin
{
}
8 changes: 3 additions & 5 deletions src/Middleware/Vanilla/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

namespace Rougin\Slytherin\Middleware\Vanilla;

use Rougin\Slytherin\Middleware\VanillaMiddleware;
use Rougin\Slytherin\Middleware\Middleware as Slytherin;

/**
* Middleware
*
* A simple implementation of a middleware on PSR-15.
* NOTE: To be removed in v1.0.0. Use "Middleware\Dispatcher" instead.
* NOTE: To be removed in v1.0.0. Use "Middleware" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
* @author Rasmus Schultz <rasmus@mindplay.dk>
*/
class Middleware extends VanillaMiddleware
class Middleware extends Slytherin
{
}
7 changes: 4 additions & 3 deletions src/Middleware/VanillaDelegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Rougin\Slytherin\Middleware;

/**
* Calls the callback with a specified HTTP request.
* NOTE: To be removed in v1.0.0. Use "Middleware\Delegate" instead.
* Delegate
*
* NOTE: To be removed in v1.0.0. Use "Vanilla\Delegate" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class VanillaDelegate extends Delegate
class VanillaDelegate extends Vanilla\Delegate
{
}
5 changes: 2 additions & 3 deletions src/Middleware/VanillaMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
/**
* Middleware
*
* A simple implementation of a middleware.
* NOTE: To be removed in v1.0.0. Use "Middleware\Dispatcher" instead.
* NOTE: To be removed in v1.0.0. Use "Vanilla\Middleware" instead.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class VanillaMiddleware extends Middleware
class VanillaMiddleware extends Vanilla\Middleware
{
}
4 changes: 4 additions & 0 deletions src/Middleware/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Rougin\Slytherin\Middleware;

/**
* Version
*
* A simple class for getting the current installed version of "http-interop".
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Middleware/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Converts various middlewares into Slytherin counterparts.
* Wrapper
*
* A middleware that converts various middlewares into its Slytherin counterpart.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
Expand Down
4 changes: 4 additions & 0 deletions src/Routing/RouteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Rougin\Slytherin\Routing;

/**
* Route Interface
*
* An interface for handling the HTTP routes.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
Expand Down
4 changes: 4 additions & 0 deletions src/System/Endofline.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Rougin\Slytherin\Middleware\HandlerInterface;

/**
* End of Line (EOL)
*
* A handler that only returns an empty HTTP response.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
Expand Down
2 changes: 2 additions & 0 deletions src/System/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Rougin\Slytherin\System;

/**
* Callback Handler
*
* Builds the final callback after handling from application.
*
* @package Slytherin
Expand Down
4 changes: 4 additions & 0 deletions src/System/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use Rougin\Slytherin\Container\ReflectionContainer;

/**
* Resolver
*
* Resolves the identifier from the container.
*
* @package Slytherin
* @author Rougin Gutib <rougingutib@gmail.com>
*/
Expand Down

0 comments on commit c3eec72

Please sign in to comment.