Created Rest module

This commit is contained in:
Alejandro Celaya 2016-07-19 17:07:59 +02:00
parent 95d0beea3c
commit 55f954f50f
22 changed files with 127 additions and 86 deletions

View file

@ -1,5 +1,4 @@
<?php
use Acelaya\UrlShortener\Middleware;
use Zend\Expressive\Container\ApplicationFactory;
use Zend\Expressive\Helper;
@ -20,15 +19,6 @@ return [
'priority' => 10,
],
'rest' => [
'path' => '/rest',
'middleware' => [
Middleware\CheckAuthenticationMiddleware::class,
Middleware\CrossDomainMiddleware::class,
],
'priority' => 5,
],
'post-routing' => [
'middleware' => [
Helper\UrlHelperMiddleware::class,

View file

@ -1,6 +1,5 @@
<?php
use Acelaya\UrlShortener\Middleware\Routable;
use Acelaya\UrlShortener\Middleware\Rest;
return [
@ -11,38 +10,6 @@ return [
'middleware' => Routable\RedirectMiddleware::class,
'allowed_methods' => ['GET'],
],
// Rest
[
'name' => 'rest-authenticate',
'path' => '/rest/authenticate',
'middleware' => Rest\AuthenticateMiddleware::class,
'allowed_methods' => ['POST', 'OPTIONS'],
],
[
'name' => 'rest-create-shortcode',
'path' => '/rest/short-codes',
'middleware' => Rest\CreateShortcodeMiddleware::class,
'allowed_methods' => ['POST', 'OPTIONS'],
],
[
'name' => 'rest-resolve-url',
'path' => '/rest/short-codes/{shortCode}',
'middleware' => Rest\ResolveUrlMiddleware::class,
'allowed_methods' => ['GET', 'OPTIONS'],
],
[
'name' => 'rest-list-shortened-url',
'path' => '/rest/short-codes',
'middleware' => Rest\ListShortcodesMiddleware::class,
'allowed_methods' => ['GET'],
],
[
'name' => 'rest-get-visits',
'path' => '/rest/visits/{shortCode}',
'middleware' => Rest\GetVisitsMiddleware::class,
'allowed_methods' => ['GET', 'OPTIONS'],
],
],
];

View file

@ -51,13 +51,6 @@ return [
// Middleware
Middleware\Routable\RedirectMiddleware::class => AnnotatedFactory::class,
Middleware\Rest\AuthenticateMiddleware::class => AnnotatedFactory::class,
Middleware\Rest\CreateShortcodeMiddleware::class => AnnotatedFactory::class,
Middleware\Rest\ResolveUrlMiddleware::class => AnnotatedFactory::class,
Middleware\Rest\GetVisitsMiddleware::class => AnnotatedFactory::class,
Middleware\Rest\ListShortcodesMiddleware::class => AnnotatedFactory::class,
Middleware\CrossDomainMiddleware::class => InvokableFactory::class,
Middleware\CheckAuthenticationMiddleware::class => AnnotatedFactory::class,
],
'aliases' => [
'em' => EntityManager::class,

View file

@ -1,5 +1,6 @@
<?php
use Shlinkio\Shlink\CLI;
use Shlinkio\Shlink\Rest;
use Zend\Expressive\ConfigManager\ConfigManager;
use Zend\Expressive\ConfigManager\ZendConfigProvider;
@ -14,7 +15,8 @@ use Zend\Expressive\ConfigManager\ZendConfigProvider;
return call_user_func(function () {
$configManager = new ConfigManager([
CLI\Config\ConfigProvider::class,
CLI\ConfigProvider::class,
Rest\ConfigProvider::class,
new ZendConfigProvider('config/autoload/{{,*.}global,{,*.}local}.php')
], 'data/cache/app_config.php');

View file

@ -1,13 +0,0 @@
<?php
namespace Shlinkio\Shlink\CLI\Config;
use Zend\Config\Factory;
use Zend\Stdlib\Glob;
class ConfigProvider
{
public function __invoke()
{
return Factory::fromFiles(Glob::glob(__DIR__ . '/../../config/{,*.}config.php', Glob::GLOB_BRACE));
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Shlinkio\Shlink\CLI;
use Zend\Config\Factory;
use Zend\Stdlib\Glob;
class ConfigProvider
{
public function __invoke()
{
return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE));
}
}

View file

@ -0,0 +1,16 @@
<?php
use Shlinkio\Shlink\Rest\Middleware;
return [
'middleware_pipeline' => [
'rest' => [
'path' => '/rest',
'middleware' => [
Middleware\CheckAuthenticationMiddleware::class,
Middleware\CrossDomainMiddleware::class,
],
'priority' => 5,
],
],
];

View file

@ -0,0 +1,39 @@
<?php
use Shlinkio\Shlink\Rest\Action;
return [
'routes' => [
[
'name' => 'rest-authenticate',
'path' => '/rest/authenticate',
'middleware' => Action\AuthenticateMiddleware::class,
'allowed_methods' => ['POST', 'OPTIONS'],
],
[
'name' => 'rest-create-shortcode',
'path' => '/rest/short-codes',
'middleware' => Action\CreateShortcodeMiddleware::class,
'allowed_methods' => ['POST', 'OPTIONS'],
],
[
'name' => 'rest-resolve-url',
'path' => '/rest/short-codes/{shortCode}',
'middleware' => Action\ResolveUrlMiddleware::class,
'allowed_methods' => ['GET', 'OPTIONS'],
],
[
'name' => 'rest-lActionist-shortened-url',
'path' => '/rest/short-codes',
'middleware' => Action\ListShortcodesMiddleware::class,
'allowed_methods' => ['GET'],
],
[
'name' => 'rest-get-visits',
'path' => '/rest/visits/{shortCode}',
'middleware' => Action\GetVisitsMiddleware::class,
'allowed_methods' => ['GET', 'OPTIONS'],
],
],
];

View file

@ -0,0 +1,22 @@
<?php
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
use Shlinkio\Shlink\Rest\Action;
use Shlinkio\Shlink\Rest\Middleware;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'services' => [
'factories' => [
Action\AuthenticateMiddleware::class => AnnotatedFactory::class,
Action\CreateShortcodeMiddleware::class => AnnotatedFactory::class,
Action\ResolveUrlMiddleware::class => AnnotatedFactory::class,
Action\GetVisitsMiddleware::class => AnnotatedFactory::class,
Action\ListShortcodesMiddleware::class => AnnotatedFactory::class,
Middleware\CrossDomainMiddleware::class => InvokableFactory::class,
Middleware\CheckAuthenticationMiddleware::class => AnnotatedFactory::class,
],
],
];

View file

@ -1,5 +1,5 @@
<?php
namespace Acelaya\UrlShortener\Middleware\Rest;
namespace Shlinkio\Shlink\Rest\Action;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

View file

@ -1,13 +1,13 @@
<?php
namespace Acelaya\UrlShortener\Middleware\Rest;
namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\UrlShortener\Exception\AuthenticationException;
use Acelaya\UrlShortener\Service\RestTokenService;
use Acelaya\UrlShortener\Service\RestTokenServiceInterface;
use Acelaya\UrlShortener\Util\RestUtils;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Rest\Service\RestTokenService;
use Shlinkio\Shlink\Rest\Service\RestTokenServiceInterface;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse;
class AuthenticateMiddleware extends AbstractRestMiddleware

View file

@ -1,13 +1,13 @@
<?php
namespace Acelaya\UrlShortener\Middleware\Rest;
namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\UrlShortener\Exception\InvalidUrlException;
use Acelaya\UrlShortener\Service\UrlShortener;
use Acelaya\UrlShortener\Service\UrlShortenerInterface;
use Acelaya\UrlShortener\Util\RestUtils;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\Uri;

View file

@ -1,13 +1,13 @@
<?php
namespace Acelaya\UrlShortener\Middleware\Rest;
namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\UrlShortener\Exception\InvalidArgumentException;
use Acelaya\UrlShortener\Service\VisitsTracker;
use Acelaya\UrlShortener\Service\VisitsTrackerInterface;
use Acelaya\UrlShortener\Util\RestUtils;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse;
class GetVisitsMiddleware extends AbstractRestMiddleware

View file

@ -1,15 +1,14 @@
<?php
namespace Acelaya\UrlShortener\Middleware\Rest;
namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\UrlShortener\Paginator\Util\PaginatorUtilsTrait;
use Acelaya\UrlShortener\Service\ShortUrlService;
use Acelaya\UrlShortener\Service\ShortUrlServiceInterface;
use Acelaya\UrlShortener\Util\RestUtils;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Stdlib\ArrayUtils;
class ListShortcodesMiddleware extends AbstractRestMiddleware
{

View file

@ -1,13 +1,13 @@
<?php
namespace Acelaya\UrlShortener\Middleware\Rest;
namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\UrlShortener\Exception\InvalidShortCodeException;
use Acelaya\UrlShortener\Service\UrlShortener;
use Acelaya\UrlShortener\Service\UrlShortenerInterface;
use Acelaya\UrlShortener\Util\RestUtils;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse;
class ResolveUrlMiddleware extends AbstractRestMiddleware

View file

@ -0,0 +1,13 @@
<?php
namespace Shlinkio\Shlink\Rest;
use Zend\Config\Factory;
use Zend\Stdlib\Glob;
class ConfigProvider
{
public function __invoke()
{
return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE));
}
}

View file

@ -1,13 +1,13 @@
<?php
namespace Acelaya\UrlShortener\Middleware;
namespace Shlinkio\Shlink\Rest\Middleware;
use Acelaya\UrlShortener\Exception\InvalidArgumentException;
use Acelaya\UrlShortener\Service\RestTokenService;
use Acelaya\UrlShortener\Service\RestTokenServiceInterface;
use Acelaya\UrlShortener\Util\RestUtils;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Rest\Service\RestTokenService;
use Shlinkio\Shlink\Rest\Service\RestTokenServiceInterface;
use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\Router\RouteResult;
use Zend\Stratigility\MiddlewareInterface;

View file

@ -1,5 +1,5 @@
<?php
namespace Acelaya\UrlShortener\Middleware;
namespace Shlinkio\Shlink\Rest\Middleware;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

View file

@ -1,5 +1,5 @@
<?php
namespace Acelaya\UrlShortener\Service;
namespace Shlinkio\Shlink\Rest\Service;
use Acelaya\UrlShortener\Entity\RestToken;
use Acelaya\UrlShortener\Exception\AuthenticationException;

View file

@ -1,5 +1,5 @@
<?php
namespace Acelaya\UrlShortener\Service;
namespace Shlinkio\Shlink\Rest\Service;
use Acelaya\UrlShortener\Entity\RestToken;
use Acelaya\UrlShortener\Exception\AuthenticationException;

View file

@ -1,5 +1,5 @@
<?php
namespace Acelaya\UrlShortener\Util;
namespace Shlinkio\Shlink\Rest\Util;
use Acelaya\UrlShortener\Exception;