mirror of
https://github.com/shlinkio/shlink.git
synced 2026-10-12 21:31:58 -05:00
Moved some elements in Common module to more proper locations
This commit is contained in:
1 parent
986c165815
commit
5fa4fa0225
17 files changed
+139
-108
No files matched your search
+4
-2
@@ -75,7 +75,8 @@
|
|||||||
"Shlinkio\\Shlink\\Core\\": "module/Core/src",
|
"Shlinkio\\Shlink\\Core\\": "module/Core/src",
|
||||||
"Shlinkio\\Shlink\\Common\\": "module/Common/src",
|
"Shlinkio\\Shlink\\Common\\": "module/Common/src",
|
||||||
"Shlinkio\\Shlink\\EventDispatcher\\": "module/EventDispatcher/src",
|
"Shlinkio\\Shlink\\EventDispatcher\\": "module/EventDispatcher/src",
|
||||||
"Shlinkio\\Shlink\\IpGeolocation\\": "module/IpGeolocation/src/"
|
"Shlinkio\\Shlink\\IpGeolocation\\": "module/IpGeolocation/src/",
|
||||||
|
"Shlinkio\\Shlink\\Integrations\\": "module/Integrations/src/"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"module/Common/functions/functions.php",
|
"module/Common/functions/functions.php",
|
||||||
@@ -96,7 +97,8 @@
|
|||||||
"module/Common/test-db"
|
"module/Common/test-db"
|
||||||
],
|
],
|
||||||
"ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test",
|
"ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test",
|
||||||
"ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test"
|
"ShlinkioTest\\Shlink\\IpGeolocation\\": "module/IpGeolocation/test",
|
||||||
|
"ShlinkioTest\\Shlink\\Integrations\\": "module/Integrations/test"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory;
|
|
||||||
use Zend\Expressive;
|
use Zend\Expressive;
|
||||||
use Zend\Expressive\Container;
|
use Zend\Expressive\Container;
|
||||||
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'dependencies' => [
|
'dependencies' => [
|
||||||
'factories' => [
|
|
||||||
ImplicitOptionsMiddleware::class => EmptyResponseImplicitOptionsMiddlewareFactory::class,
|
|
||||||
],
|
|
||||||
|
|
||||||
'delegators' => [
|
'delegators' => [
|
||||||
Expressive\Application::class => [
|
Expressive\Application::class => [
|
||||||
Container\ApplicationConfigInjectionDelegator::class,
|
Container\ApplicationConfigInjectionDelegator::class,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ return (new ConfigAggregator\ConfigAggregator([
|
|||||||
ExpressiveErrorHandler\ConfigProvider::class,
|
ExpressiveErrorHandler\ConfigProvider::class,
|
||||||
Common\ConfigProvider::class,
|
Common\ConfigProvider::class,
|
||||||
IpGeolocation\ConfigProvider::class,
|
IpGeolocation\ConfigProvider::class,
|
||||||
|
Integrations\ConfigProvider::class,
|
||||||
Core\ConfigProvider::class,
|
Core\ConfigProvider::class,
|
||||||
CLI\ConfigProvider::class,
|
CLI\ConfigProvider::class,
|
||||||
Rest\ConfigProvider::class,
|
Rest\ConfigProvider::class,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Common;
|
namespace Shlinkio\Shlink\Common;
|
||||||
|
|
||||||
use GeoIp2\Database\Reader;
|
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -12,7 +11,6 @@ use Symfony\Component\Filesystem\Filesystem;
|
|||||||
use Zend\I18n\Translator\Translator;
|
use Zend\I18n\Translator\Translator;
|
||||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||||
use Zend\ServiceManager\Factory\InvokableFactory;
|
use Zend\ServiceManager\Factory\InvokableFactory;
|
||||||
use Zend\ServiceManager\Proxy\LazyServiceFactory;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
@@ -20,9 +18,8 @@ return [
|
|||||||
'factories' => [
|
'factories' => [
|
||||||
GuzzleClient::class => InvokableFactory::class,
|
GuzzleClient::class => InvokableFactory::class,
|
||||||
Filesystem::class => InvokableFactory::class,
|
Filesystem::class => InvokableFactory::class,
|
||||||
Reader::class => ConfigAbstractFactory::class,
|
|
||||||
|
|
||||||
Translator::class => Factory\TranslatorFactory::class,
|
Translator::class => I18n\TranslatorFactory::class,
|
||||||
Template\Extension\TranslatorExtension::class => ConfigAbstractFactory::class,
|
Template\Extension\TranslatorExtension::class => ConfigAbstractFactory::class,
|
||||||
|
|
||||||
Middleware\LocaleMiddleware::class => ConfigAbstractFactory::class,
|
Middleware\LocaleMiddleware::class => ConfigAbstractFactory::class,
|
||||||
@@ -44,24 +41,9 @@ return [
|
|||||||
'abstract_factories' => [
|
'abstract_factories' => [
|
||||||
Factory\DottedAccessConfigAbstractFactory::class,
|
Factory\DottedAccessConfigAbstractFactory::class,
|
||||||
],
|
],
|
||||||
'delegators' => [
|
|
||||||
// The GeoLite2 db reader has to be lazy so that it does not try to load the DB file at app bootstrapping.
|
|
||||||
// By doing so, it would fail the first time shlink tries to download it.
|
|
||||||
Reader::class => [
|
|
||||||
LazyServiceFactory::class,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
|
|
||||||
'lazy_services' => [
|
|
||||||
'class_map' => [
|
|
||||||
Reader::class => Reader::class,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
|
|
||||||
ConfigAbstractFactory::class => [
|
ConfigAbstractFactory::class => [
|
||||||
Reader::class => ['config.geolite2.db_location'],
|
|
||||||
|
|
||||||
Template\Extension\TranslatorExtension::class => ['translator'],
|
Template\Extension\TranslatorExtension::class => ['translator'],
|
||||||
Middleware\LocaleMiddleware::class => ['translator'],
|
Middleware\LocaleMiddleware::class => ['translator'],
|
||||||
Middleware\CloseDbConnectionMiddleware::class => ['em'],
|
Middleware\CloseDbConnectionMiddleware::class => ['em'],
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ class DottedAccessConfigAbstractFactory implements AbstractFactoryInterface
|
|||||||
/**
|
/**
|
||||||
* Can the factory create an instance for the service?
|
* Can the factory create an instance for the service?
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
|
||||||
* @param string $requestedName
|
* @param string $requestedName
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function canCreate(ContainerInterface $container, $requestedName)
|
public function canCreate(ContainerInterface $container, $requestedName): bool
|
||||||
{
|
{
|
||||||
return substr_count($requestedName, '.') > 0;
|
return substr_count($requestedName, '.') > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\Common\Factory;
|
|
||||||
|
|
||||||
use Interop\Container\ContainerInterface;
|
|
||||||
use Interop\Container\Exception\ContainerException;
|
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
|
||||||
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
|
||||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
|
||||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
|
||||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
|
||||||
|
|
||||||
class EmptyResponseImplicitOptionsMiddlewareFactory implements FactoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create an object
|
|
||||||
*
|
|
||||||
* @param ContainerInterface $container
|
|
||||||
* @param string $requestedName
|
|
||||||
* @param null|array $options
|
|
||||||
* @return object
|
|
||||||
* @throws ServiceNotFoundException if unable to resolve the service.
|
|
||||||
* @throws ServiceNotCreatedException if an exception is raised when
|
|
||||||
* creating a service.
|
|
||||||
* @throws ContainerException if any other error occurs
|
|
||||||
*/
|
|
||||||
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
|
|
||||||
{
|
|
||||||
return new ImplicitOptionsMiddleware(function () {
|
|
||||||
return new EmptyResponse();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\Common\Factory;
|
|
||||||
|
|
||||||
use Interop\Container\ContainerInterface;
|
|
||||||
use Interop\Container\Exception\ContainerException;
|
|
||||||
use Zend\I18n\Translator\Translator;
|
|
||||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
|
||||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
|
||||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
|
||||||
|
|
||||||
class TranslatorFactory implements FactoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create an object
|
|
||||||
*
|
|
||||||
* @param ContainerInterface $container
|
|
||||||
* @param string $requestedName
|
|
||||||
* @param null|array $options
|
|
||||||
* @return object
|
|
||||||
* @throws ServiceNotFoundException if unable to resolve the service.
|
|
||||||
* @throws ServiceNotCreatedException if an exception is raised when
|
|
||||||
* creating a service.
|
|
||||||
* @throws ContainerException if any other error occurs
|
|
||||||
*/
|
|
||||||
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
|
|
||||||
{
|
|
||||||
$config = $container->get('config');
|
|
||||||
return Translator::factory($config['translator'] ?? []);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\Common\I18n;
|
||||||
|
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
use Zend\I18n\Translator\Translator;
|
||||||
|
|
||||||
|
class TranslatorFactory
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $container): Translator
|
||||||
|
{
|
||||||
|
$config = $container->get('config');
|
||||||
|
return Translator::factory($config['translator'] ?? []);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common\Factory;
|
namespace ShlinkioTest\Shlink\Common\I18n;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Shlinkio\Shlink\Common\Factory\TranslatorFactory;
|
use Shlinkio\Shlink\Common\I18n\TranslatorFactory;
|
||||||
use Zend\I18n\Translator\Translator;
|
use Zend\I18n\Translator\Translator;
|
||||||
use Zend\ServiceManager\ServiceManager;
|
use Zend\ServiceManager\ServiceManager;
|
||||||
|
|
||||||
@@ -19,11 +19,11 @@ class TranslatorFactoryTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function serviceIsCreated()
|
public function serviceIsCreated(): void
|
||||||
{
|
{
|
||||||
$instance = $this->factory->__invoke(new ServiceManager(['services' => [
|
$instance = ($this->factory)(new ServiceManager(['services' => [
|
||||||
'config' => [],
|
'config' => [],
|
||||||
]]), '');
|
]]));
|
||||||
$this->assertInstanceOf(Translator::class, $instance);
|
$this->assertInstanceOf(Translator::class, $instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,8 @@ return [
|
|||||||
Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class,
|
Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class,
|
||||||
],
|
],
|
||||||
'delegators' => [
|
'delegators' => [
|
||||||
|
// The listener provider has to be lazy, because it uses the Swoole server to generate AsyncEventListeners
|
||||||
|
// Without making this lazy, CLI commands which depend on the EventDispatcher fail
|
||||||
Psr\ListenerProviderInterface::class => [
|
Psr\ListenerProviderInterface::class => [
|
||||||
LazyServiceFactory::class,
|
LazyServiceFactory::class,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\Integrations;
|
||||||
|
|
||||||
|
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'dependencies' => [
|
||||||
|
'factories' => [
|
||||||
|
ImplicitOptionsMiddleware::class => Middleware\EmptyResponseImplicitOptionsMiddlewareFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\Integrations;
|
||||||
|
|
||||||
|
use function Shlinkio\Shlink\Common\loadConfigFromGlob;
|
||||||
|
|
||||||
|
class ConfigProvider
|
||||||
|
{
|
||||||
|
public function __invoke()
|
||||||
|
{
|
||||||
|
return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\Integrations\Middleware;
|
||||||
|
|
||||||
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
|
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
||||||
|
|
||||||
|
class EmptyResponseImplicitOptionsMiddlewareFactory
|
||||||
|
{
|
||||||
|
public function __invoke()
|
||||||
|
{
|
||||||
|
return new ImplicitOptionsMiddleware(function () {
|
||||||
|
return new EmptyResponse();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-7
@@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkioTest\Shlink\Common\Factory;
|
namespace ShlinkioTest\Shlink\Integrations\Middleware;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use ReflectionObject;
|
use ReflectionObject;
|
||||||
use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory;
|
use Shlinkio\Shlink\Integrations\Middleware\EmptyResponseImplicitOptionsMiddlewareFactory;
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
||||||
use Zend\ServiceManager\ServiceManager;
|
|
||||||
|
|
||||||
class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -21,16 +20,16 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function serviceIsCreated()
|
public function serviceIsCreated(): void
|
||||||
{
|
{
|
||||||
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
$instance = ($this->factory)();
|
||||||
$this->assertInstanceOf(ImplicitOptionsMiddleware::class, $instance);
|
$this->assertInstanceOf(ImplicitOptionsMiddleware::class, $instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function responsePrototypeIsEmptyResponse()
|
public function responsePrototypeIsEmptyResponse(): void
|
||||||
{
|
{
|
||||||
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
$instance = ($this->factory)();
|
||||||
|
|
||||||
$ref = new ReflectionObject($instance);
|
$ref = new ReflectionObject($instance);
|
||||||
$prop = $ref->getProperty('responseFactory');
|
$prop = $ref->getProperty('responseFactory');
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# IP Address Geolocation module
|
||||||
|
|
||||||
|
Shlink module with tools to locate an IP address suing different strategies.
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'geolite2' => [
|
||||||
|
'db_location' => __DIR__ . '/../../data/GeoLite2-City.mmdb',
|
||||||
|
'temp_dir' => sys_get_temp_dir(),
|
||||||
|
// 'download_from' => 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz',
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
```
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\IpGeolocation;
|
||||||
|
|
||||||
|
use GeoIp2\Database\Reader;
|
||||||
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||||
|
use Zend\ServiceManager\Proxy\LazyServiceFactory;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'dependencies' => [
|
||||||
|
'factories' => [
|
||||||
|
Reader::class => ConfigAbstractFactory::class,
|
||||||
|
],
|
||||||
|
'delegators' => [
|
||||||
|
// The GeoLite2 db reader has to be lazy so that it does not try to load the DB file at app bootstrapping.
|
||||||
|
// By doing so, it would fail the first time shlink tries to download it.
|
||||||
|
Reader::class => [
|
||||||
|
LazyServiceFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'lazy_services' => [
|
||||||
|
'class_map' => [
|
||||||
|
Reader::class => Reader::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
ConfigAbstractFactory::class => [
|
||||||
|
Reader::class => ['config.geolite2.db_location'],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
@@ -24,6 +24,9 @@
|
|||||||
<testsuite name="IpGeolocation">
|
<testsuite name="IpGeolocation">
|
||||||
<directory>./module/IpGeolocation/test</directory>
|
<directory>./module/IpGeolocation/test</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
<testsuite name="Integrations">
|
||||||
|
<directory>./module/Integrations/test</directory>
|
||||||
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
|
|||||||
Reference in new issue
Block a user