mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-16 23:39:54 +03:00
Added shortcode chars as an environment variable
This commit is contained in:
parent
3bb899bced
commit
aba7d3185a
4 changed files with 16 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
|||
APP_ENV=
|
||||
SHORTENED_URL_SCHEMA=
|
||||
SHORTENED_URL_HOSTNAME=
|
||||
SHORTCODE_CHARS=
|
||||
|
||||
# Database
|
||||
DB_USER=
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
return [
|
||||
|
||||
'url-shortener' => [
|
||||
'schema' => getenv('SHORTENED_URL_SCHEMA') ?: 'http',
|
||||
'hostname' => getenv('SHORTENED_URL_HOSTNAME'),
|
||||
'url_shortener' => [
|
||||
'domain' => [
|
||||
'schema' => getenv('SHORTENED_URL_SCHEMA') ?: 'http',
|
||||
'hostname' => getenv('SHORTENED_URL_HOSTNAME'),
|
||||
],
|
||||
'shortcode_chars' => getenv('SHORTCODE_CHARS'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
@ -19,20 +19,20 @@ class GenerateShortcodeMiddleware implements MiddlewareInterface
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
private $domainConfig;
|
||||
|
||||
/**
|
||||
* GenerateShortcodeMiddleware constructor.
|
||||
*
|
||||
* @param UrlShortenerInterface|UrlShortener $urlShortener
|
||||
* @param array $config
|
||||
* @param array $domainConfig
|
||||
*
|
||||
* @Inject({UrlShortener::class, "config.url-shortener"})
|
||||
* @Inject({UrlShortener::class, "config.url_shortener.domain"})
|
||||
*/
|
||||
public function __construct(UrlShortenerInterface $urlShortener, array $config)
|
||||
public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig)
|
||||
{
|
||||
$this->urlShortener = $urlShortener;
|
||||
$this->config = $config;
|
||||
$this->domainConfig = $domainConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,8 +72,8 @@ class GenerateShortcodeMiddleware implements MiddlewareInterface
|
|||
|
||||
$shortcode = $this->urlShortener->urlToShortCode(new Uri($longUrl));
|
||||
$shortUrl = (new Uri())->withPath($shortcode)
|
||||
->withScheme($this->config['schema'])
|
||||
->withHost($this->config['hostname']);
|
||||
->withScheme($this->domainConfig['schema'])
|
||||
->withHost($this->domainConfig['hostname']);
|
||||
|
||||
$response->getBody()->write(
|
||||
sprintf('Processed URL "%s".%sGenerated short URL "%s"', $longUrl, PHP_EOL, $shortUrl) . PHP_EOL
|
||||
|
|
|
@ -14,7 +14,7 @@ use Psr\Http\Message\UriInterface;
|
|||
|
||||
class UrlShortener implements UrlShortenerInterface
|
||||
{
|
||||
const DEFAULT_CHARS = 'rYHxLkXfsptbNZzKDG4hy85WFT7BRgMVdC9jvwQPnc6S32Jqm';
|
||||
const DEFAULT_CHARS = '123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ';
|
||||
|
||||
/**
|
||||
* @var ClientInterface
|
||||
|
@ -35,7 +35,7 @@ class UrlShortener implements UrlShortenerInterface
|
|||
* @param EntityManagerInterface $em
|
||||
* @param string $chars
|
||||
*
|
||||
* @Inject({"httpClient", "em"})
|
||||
* @Inject({"httpClient", "em", "config.url_shortener.shortcode_chars"})
|
||||
*/
|
||||
public function __construct(
|
||||
ClientInterface $httpClient,
|
||||
|
|
Loading…
Add table
Reference in a new issue