From f1d7f5190ce27425b8444c8cfc0474cd180a3f01 Mon Sep 17 00:00:00 2001 From: Erika Heidi Date: Wed, 16 Mar 2022 23:21:23 +0100 Subject: [PATCH] Restructured configuration Adjusted config loader CS Fixer --- .php-cs-fixer.php | 2 +- app/Command/Web/CoverController.php | 70 ----------------------------- app/helpers.php | 22 +++++++++ composer.json | 5 ++- config/devto.php | 11 +++++ config/minicli.php | 18 ++++++++ config/tests.php | 11 +++++ config_sample.php | 39 ++-------------- librarian | 2 +- tests/Helpers.php | 7 +-- web/index.php | 2 +- 11 files changed, 75 insertions(+), 114 deletions(-) delete mode 100644 app/Command/Web/CoverController.php create mode 100644 app/helpers.php create mode 100644 config/devto.php create mode 100644 config/minicli.php create mode 100644 config/tests.php diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 078f9b4..2314e19 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,7 +1,7 @@ in([__DIR__ . '/app', __DIR__ . '/tests']) + ->in([__DIR__ . '/app', __DIR__ . '/tests', __DIR__ . '/config']) ->name('*.php') ; diff --git a/app/Command/Web/CoverController.php b/app/Command/Web/CoverController.php deleted file mode 100644 index 61dc639..0000000 --- a/app/Command/Web/CoverController.php +++ /dev/null @@ -1,70 +0,0 @@ -getApp()->twig; - /** @var ContentServiceProvider $content_provider */ - $content_provider = $this->getApp()->content; - - $request = $this->getRequest(); - - $content_slug = str_replace('-', '/', $request->getSlug()); - - try { - $content = $content_provider->fetch($content_slug); - - if ($content === null) { - echo "null content"; - Response::redirect('/notfound'); - } - } catch (\Exception $exception) { - Response::redirect('/notfound'); - } - - - $title = $content->frontMatterGet('title'); - $description = $content->frontMatterGet('description'); - $author = $content->frontMatterGet('author') ?? $this->getApp()->config->site_author; - $author_avatar = $content->frontMatterGet('author_avatar'); - - if (!$author_avatar) { - //tries to get user avatar with gravatar - if ($this->getApp()->config->has('author_email')) { - $email = $this->config->author_email; - $default = "https://librarianphp.dev/img/default_author.png"; - $size = 60; - $author_avatar = "https://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?d=" . urlencode($default) . "&s=" . $size; - } else { - $author_avatar = "/img/default_author.png"; - } - } - - $cover_width = 1000; - $cover_height = 420; - $font = __DIR__ . '/../../Resources/fonts/AbrilFatface-Regular.otf'; - $image = imagecreatetruecolor($cover_width, $cover_height); - - $color_black = imagecolorallocate($image, 0, 0, 0); - $color_white = imagecolorallocate($image, 255, 255, 255); - $text_color = imagecolorallocate($image, 233, 14, 91); - - imagefill($image, 0, 0, $color_white); - - //imagestring($image, 1, 5, 5, $title, $text_color); - imagettftext($image, 20, 0, 10, 20, $color_black, $font, $title); - - header('Content-Type: image/png'); - imagepng($image); - imagedestroy($image); - } -} diff --git a/app/helpers.php b/app/helpers.php new file mode 100644 index 0000000..01b2969 --- /dev/null +++ b/app/helpers.php @@ -0,0 +1,22 @@ +=8.0", diff --git a/config/devto.php b/config/devto.php new file mode 100644 index 0000000..73900bc --- /dev/null +++ b/config/devto.php @@ -0,0 +1,11 @@ + getenv('DEVTO_USER'), + 'devto_datadir' => '_to', +]; diff --git a/config/minicli.php b/config/minicli.php new file mode 100644 index 0000000..ae05599 --- /dev/null +++ b/config/minicli.php @@ -0,0 +1,18 @@ + __DIR__ . '/../app/Command', + 'theme' => 'unicorn', + 'templates_path' => __DIR__ . '/../app/Resources/themes/default', + 'data_path' => __DIR__ . '/../app/Resources/data', + 'cache_path' => __DIR__ . '/../var/cache', + 'stencil_dir' => __DIR__ . '/../app/Resources/stencil', + 'stencil_locations' => [ + 'post' => __DIR__ . '/../app/Resources/data/_p' + ] +]; diff --git a/config/tests.php b/config/tests.php new file mode 100644 index 0000000..4fec2d5 --- /dev/null +++ b/config/tests.php @@ -0,0 +1,11 @@ + 'http://localhost', # Regular LEMP/LAMP/PHP built-in server + #'app_testing_url' => 'http://nginx', # Docker Compose w/ separate Nginx service + +]; diff --git a/config_sample.php b/config_sample.php index 1df81f5..48a3caa 100644 --- a/config_sample.php +++ b/config_sample.php @@ -1,15 +1,12 @@ getenv('SITE_NAME') ?: 'Librarian', 'site_author' => getenv('SITE_AUTHOR') ?: '@erikaheidi', - 'author_email' => getenv('SITE_AUTHOR') ?: 'erika@erikaheidi.com', 'site_description' => getenv('SITE_DESC') ?: 'Minimalist file-based CMS in PHP', 'site_url' => getenv('SITE_URL') ?: 'http://localhost:8000', 'site_root' => getenv('SITE_ROOT') ?: '/', @@ -23,34 +20,6 @@ 'Twitch' => getenv('LINK_TWITCH'), ], 'app_debug' => getenv('APP_DEBUG') ?: true, - - /***************************************************************************** - * End-to-end tests require you to set here the app url for testing. - * For Docker Compose setups, this should be where Nginx is running. - ******************************************************************************/ - #'app_testing_url' => getenv('TEST_BASE_URL') ?: 'http://localhost', # Regular LEMP/LAMP/PHP built-in server - 'app_testing_url' => getenv('TEST_BASE_URL') ?: 'http://nginx', # Docker Compose w/ separate Nginx service - - /***************************************************************************** - * Dev.to Settings - * Set Up your dev.to username here or via ENV var. - * This is required if you want to import your posts from the dev.to platform. - ******************************************************************************/ + 'app_testing_url' => getenv('TEST_BASE_URL') ?: 'http://nginx', 'devto_username' => getenv('DEVTO_USER'), - 'devto_datadir' => '_to', - - /**************************************************************************** - * Other Settings - * You shouldn't need to change the next settings, - * but you are free to do so at your own risk. - *****************************************************************************/ - 'app_path' => __DIR__ . '/app/Command', - 'theme' => 'unicorn', - 'templates_path' => __DIR__ . '/app/Resources/themes/default', - 'data_path' => __DIR__ . '/app/Resources/data', - 'cache_path' => __DIR__ . '/var/cache', - 'stencil_dir' => __DIR__ . '/app/Resources/stencil', - 'stencil_locations' => [ - 'post' => __DIR__ . '/app/Resources/data/_p' - ] -]; \ No newline at end of file +]; diff --git a/librarian b/librarian index 1b3580f..794bf21 100755 --- a/librarian +++ b/librarian @@ -11,7 +11,7 @@ use Minicli\App; use Librarian\Provider\ContentServiceProvider; use Librarian\Provider\DevtoServiceProvider; -$app = new App(require __DIR__ . '/config.php'); +$app = new App(load_config()); $app->setSignature(' _ ____ ____ ____ ____ ____ ____ ____ ____ | | | || \ | \ / || \ | | / || \ diff --git a/tests/Helpers.php b/tests/Helpers.php index 56212bd..bbd0776 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -14,10 +14,7 @@ function getCommandsPath(): string function getApp(): App { - return new App(array_merge(include __DIR__ . '/../config.php', [ - 'data_path' => __DIR__ . '/resources', - 'cache_path' => __DIR__ . '/resources' - ])); + return new App(load_config(__DIR__ . '/../config')); } function getWebApp(): App @@ -33,7 +30,7 @@ function getWebApp(): App function getConfigValue(string $key): mixed { - $config = include __DIR__ . '/../config.php'; + $config = load_config(__DIR__ . '/../config'); return $config[$key] ?: null; } diff --git a/web/index.php b/web/index.php index c15adc7..b09e23e 100755 --- a/web/index.php +++ b/web/index.php @@ -11,7 +11,7 @@ use Librarian\Provider\LibrarianServiceProvider; use Librarian\Response; -$app = new App(require __DIR__ . '/../config.php'); +$app = new App(load_config()); $app->addService('twig', new TwigServiceProvider()); $app->addService('router', new RouterServiceProvider());