Created Common module

This commit is contained in:
Alejandro Celaya 2016-07-19 17:38:41 +02:00
parent 8fc88171ee
commit ba06ad44bd
17 changed files with 57 additions and 26 deletions

View File

@ -1,11 +1,7 @@
<?php <?php
use Acelaya\UrlShortener\Factory\CacheFactory;
use Acelaya\UrlShortener\Factory\EntityManagerFactory;
use Acelaya\UrlShortener\Middleware; use Acelaya\UrlShortener\Middleware;
use Acelaya\UrlShortener\Service; use Acelaya\UrlShortener\Service;
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory; use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
use Doctrine\Common\Cache\Cache;
use Doctrine\ORM\EntityManager;
use Zend\Expressive; use Zend\Expressive;
use Zend\Expressive\Container; use Zend\Expressive\Container;
use Zend\Expressive\Helper; use Zend\Expressive\Helper;
@ -32,21 +28,15 @@ return [
Template\TemplateRendererInterface::class => Twig\TwigRendererFactory::class, Template\TemplateRendererInterface::class => Twig\TwigRendererFactory::class,
// Services // Services
EntityManager::class => EntityManagerFactory::class,
GuzzleHttp\Client::class => InvokableFactory::class,
Service\UrlShortener::class => AnnotatedFactory::class, Service\UrlShortener::class => AnnotatedFactory::class,
Service\VisitsTracker::class => AnnotatedFactory::class, Service\VisitsTracker::class => AnnotatedFactory::class,
Service\ShortUrlService::class => AnnotatedFactory::class, Service\ShortUrlService::class => AnnotatedFactory::class,
Cache::class => CacheFactory::class,
// Middleware // Middleware
Middleware\Routable\RedirectMiddleware::class => AnnotatedFactory::class, Middleware\Routable\RedirectMiddleware::class => AnnotatedFactory::class,
], ],
'aliases' => [ 'aliases' => [
'em' => EntityManager::class,
'httpClient' => GuzzleHttp\Client::class,
Router\RouterInterface::class => Router\FastRouteRouter::class, Router\RouterInterface::class => Router\FastRouteRouter::class,
AnnotatedFactory::CACHE_SERVICE => Cache::class,
], ],
], ],

View File

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

View File

@ -1,11 +1,11 @@
<?php <?php
namespace Shlinkio\Shlink\CLI\Command; namespace Shlinkio\Shlink\CLI\Command;
use Acelaya\UrlShortener\Paginator\Adapter\PaginableRepositoryAdapter;
use Acelaya\UrlShortener\Paginator\Util\PaginatorUtilsTrait;
use Acelaya\UrlShortener\Service\ShortUrlService; use Acelaya\UrlShortener\Service\ShortUrlService;
use Acelaya\UrlShortener\Service\ShortUrlServiceInterface; use Acelaya\UrlShortener\Service\ShortUrlServiceInterface;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject; use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Shlinkio\Shlink\Common\Paginator\Adapter\PaginableRepositoryAdapter;
use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\Table;

View File

@ -0,0 +1,25 @@
<?php
use Acelaya\UrlShortener\Middleware;
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
use Doctrine\Common\Cache\Cache;
use Doctrine\ORM\EntityManager;
use Shlinkio\Shlink\Common\Factory\CacheFactory;
use Shlinkio\Shlink\Common\Factory\EntityManagerFactory;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'services' => [
'factories' => [
EntityManager::class => EntityManagerFactory::class,
GuzzleHttp\Client::class => InvokableFactory::class,
Cache::class => CacheFactory::class,
],
'aliases' => [
'em' => EntityManager::class,
'httpClient' => GuzzleHttp\Client::class,
AnnotatedFactory::CACHE_SERVICE => Cache::class,
],
],
];

View File

@ -0,0 +1,13 @@
<?php
namespace Shlinkio\Shlink\Common;
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,5 +1,5 @@
<?php <?php
namespace Acelaya\UrlShortener\Factory; namespace Shlinkio\Shlink\Common\Factory;
use Doctrine\Common\Cache\ApcuCache; use Doctrine\Common\Cache\ApcuCache;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Acelaya\UrlShortener\Factory; namespace Shlinkio\Shlink\Common\Factory;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\Cache;

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Acelaya\UrlShortener\Paginator\Adapter; namespace Shlinkio\Shlink\Common\Paginator\Adapter;
use Acelaya\UrlShortener\Repository\PaginableRepositoryInterface; use Shlinkio\Shlink\Common\Repository\PaginableRepositoryInterface;
use Zend\Paginator\Adapter\AdapterInterface; use Zend\Paginator\Adapter\AdapterInterface;
class PaginableRepositoryAdapter implements AdapterInterface class PaginableRepositoryAdapter implements AdapterInterface

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Acelaya\UrlShortener\Paginator\Util; namespace Shlinkio\Shlink\Common\Paginator\Util;
use Zend\Paginator\Paginator; use Zend\Paginator\Paginator;
use Zend\Stdlib\ArrayUtils; use Zend\Stdlib\ArrayUtils;

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Acelaya\UrlShortener\Repository; namespace Shlinkio\Shlink\Common\Repository;
interface PaginableRepositoryInterface interface PaginableRepositoryInterface
{ {

View File

@ -1,5 +1,5 @@
<?php <?php
namespace Acelaya\UrlShortener\Util; namespace Shlinkio\Shlink\Common\Util;
trait StringUtilsTrait trait StringUtilsTrait
{ {

View File

@ -1,10 +1,10 @@
<?php <?php
namespace AcelayaTest\UrlShortener\Factory; namespace ShlinkioTest\Shlink\Common\Factory;
use Acelaya\UrlShortener\Factory\CacheFactory;
use Doctrine\Common\Cache\ApcuCache; use Doctrine\Common\Cache\ApcuCache;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use PHPUnit_Framework_TestCase as TestCase; use PHPUnit_Framework_TestCase as TestCase;
use Shlinkio\Shlink\Common\Factory\CacheFactory;
use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManager;
class CacheFactoryTest extends TestCase class CacheFactoryTest extends TestCase

View File

@ -1,9 +1,9 @@
<?php <?php
namespace AcelayaTest\UrlShortener\Factory; namespace ShlinkioTest\Shlink\Common\Factory;
use Acelaya\UrlShortener\Factory\EntityManagerFactory;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use PHPUnit_Framework_TestCase as TestCase; use PHPUnit_Framework_TestCase as TestCase;
use Shlinkio\Shlink\Common\Factory\EntityManagerFactory;
use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManager;
class EntityManagerFactoryTest extends TestCase class EntityManagerFactoryTest extends TestCase

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Shlinkio\Shlink\Rest\Action; namespace Shlinkio\Shlink\Rest\Action;
use Acelaya\UrlShortener\Paginator\Util\PaginatorUtilsTrait;
use Acelaya\UrlShortener\Service\ShortUrlService; use Acelaya\UrlShortener\Service\ShortUrlService;
use Acelaya\UrlShortener\Service\ShortUrlServiceInterface; use Acelaya\UrlShortener\Service\ShortUrlServiceInterface;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject; use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;

View File

@ -1,8 +1,8 @@
<?php <?php
namespace Acelaya\UrlShortener\Entity; namespace Acelaya\UrlShortener\Entity;
use Acelaya\UrlShortener\Util\StringUtilsTrait;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
/** /**
* Class RestToken * Class RestToken

View File

@ -2,6 +2,7 @@
namespace Acelaya\UrlShortener\Repository; namespace Acelaya\UrlShortener\Repository;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository;
use Shlinkio\Shlink\Common\Repository\PaginableRepositoryInterface;
interface ShortUrlRepositoryInterface extends ObjectRepository, PaginableRepositoryInterface interface ShortUrlRepositoryInterface extends ObjectRepository, PaginableRepositoryInterface
{ {

View File

@ -2,10 +2,10 @@
namespace Acelaya\UrlShortener\Service; namespace Acelaya\UrlShortener\Service;
use Acelaya\UrlShortener\Entity\ShortUrl; use Acelaya\UrlShortener\Entity\ShortUrl;
use Acelaya\UrlShortener\Paginator\Adapter\PaginableRepositoryAdapter;
use Acelaya\UrlShortener\Repository\ShortUrlRepository; use Acelaya\UrlShortener\Repository\ShortUrlRepository;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject; use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Common\Paginator\Adapter\PaginableRepositoryAdapter;
use Zend\Paginator\Paginator; use Zend\Paginator\Paginator;
class ShortUrlService implements ShortUrlServiceInterface class ShortUrlService implements ShortUrlServiceInterface