diff --git a/.env.dist b/.env.dist new file mode 100644 index 00000000..388e7e1b --- /dev/null +++ b/.env.dist @@ -0,0 +1,7 @@ +# Application +APP_ENV= + +# Database +DB_USER= +DB_PASSWORD= +DB_NAME= diff --git a/.gitignore b/.gitignore index 397e34a5..5aedee0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build composer.lock vendor/ +.env diff --git a/composer.json b/composer.json index 1d9e2ce0..652d81d1 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "squizlabs/php_codesniffer": "^2.3", "roave/security-advisories": "dev-master", "filp/whoops": "^2.0", - "symfony/var-dumper": "^3.0" + "symfony/var-dumper": "^3.0", + "vlucas/phpdotenv": "^2.2" }, "autoload": { "psr-4": { diff --git a/config/autoload/database.global.php b/config/autoload/database.global.php new file mode 100644 index 00000000..4e3b00e3 --- /dev/null +++ b/config/autoload/database.global.php @@ -0,0 +1,15 @@ + [ + 'driver' => 'pdo_mysql', + 'user' => getenv('DB_USER'), + 'password' => getenv('DB_PASSWORD'), + 'dbname' => getenv('DB_NAME') ?: 'acelaya_url_shortener', + 'charset' => 'utf8', + 'driverOptions' => [ + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' + ], + ], + +]; diff --git a/config/autoload/database.local.php.dist b/config/autoload/database.local.php.dist deleted file mode 100644 index f90c4a2e..00000000 --- a/config/autoload/database.local.php.dist +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'driver' => 'pdo_mysql', - 'user' => '', - 'password' => '', - 'dbname' => '', - 'charset' => 'utf-8', - 'driverOptions' => [ - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' - ], - ] - -]; diff --git a/config/autoload/services.global.php b/config/autoload/services.global.php index f3ac64bd..468c4a75 100644 --- a/config/autoload/services.global.php +++ b/config/autoload/services.global.php @@ -1,7 +1,9 @@ [ - 'invokables' => [ - Helper\ServerUrlHelper::class, - Router\AuraRouter::class, - ], 'factories' => [ Application::class => Container\ApplicationFactory::class, - // Url helpers + // Routes Helper\UrlHelper::class => Helper\UrlHelperFactory::class, Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class, Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class, Helper\ServerUrlHelper::class => InvokableFactory::class, Router\RouterInterface::class => InvokableFactory::class, + Router\AuraRouter::class => InvokableFactory::class, // View 'Zend\Expressive\FinalHandler' => Container\TemplatedErrorHandlerFactory::class, @@ -36,6 +35,7 @@ return [ EntityManager::class => EntityManagerFactory::class, GuzzleHttp\Client::class => InvokableFactory::class, UrlShortener::class => AnnotatedFactory::class, + Cache::class => CacheFactory::class, ], 'aliases' => [ 'em' => EntityManager::class, diff --git a/config/container.php b/config/container.php index 332023f8..5678edcb 100644 --- a/config/container.php +++ b/config/container.php @@ -1,11 +1,19 @@ load(); +} + // Build container $config = require __DIR__ . '/config.php'; $container = new ServiceManager($config['services']); diff --git a/src/Factory/CacheFactory.php b/src/Factory/CacheFactory.php new file mode 100644 index 00000000..86c88e6b --- /dev/null +++ b/src/Factory/CacheFactory.php @@ -0,0 +1,30 @@ +