Added shortcode chars as an environment variable

This commit is contained in:
Alejandro Celaya
2016-05-01 11:21:54 +02:00
parent 3bb899bced
commit aba7d3185a
4 changed files with 16 additions and 12 deletions

View File

@@ -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

View File

@@ -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,