From 7f058a8c3ec9f6adca07caad661ca3e85c781039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szekeres=20Ba=CC=81lint?= Date: Tue, 20 Feb 2018 15:44:35 +0100 Subject: [PATCH] isLumen() fixes --- src/Concerns/Shortcodes.php | 2 +- src/Corcel.php | 3 ++- src/Laravel/CorcelServiceProvider.php | 4 ++-- src/Model.php | 2 +- src/Model/Post.php | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Concerns/Shortcodes.php b/src/Concerns/Shortcodes.php index dfedd9b4..69955013 100644 --- a/src/Concerns/Shortcodes.php +++ b/src/Concerns/Shortcodes.php @@ -71,7 +71,7 @@ private function parseClassShortcodes(ShortcodeFacade $facade) */ private function parseConfigShortcodes(ShortcodeFacade $facade) { - if (Corcel::isLaravel()) { + if (Corcel::isLaravel() || Corcel::isLumen()) { $shortcodes = config('corcel.shortcodes', []); foreach ($shortcodes as $tag => $class) { $facade->addHandler($tag, [new $class, 'render']); diff --git a/src/Corcel.php b/src/Corcel.php index a39549cf..afad4f6a 100644 --- a/src/Corcel.php +++ b/src/Corcel.php @@ -26,6 +26,7 @@ public static function isLaravel() */ public static function isLumen() { - return preg_match('/Lumen', app()->version()) === 1; + return function_exists('app') && + preg_match('/^Lumen/', app()->version()) === 1; } } diff --git a/src/Laravel/CorcelServiceProvider.php b/src/Laravel/CorcelServiceProvider.php index 151f9c5e..4535cf83 100644 --- a/src/Laravel/CorcelServiceProvider.php +++ b/src/Laravel/CorcelServiceProvider.php @@ -30,7 +30,7 @@ public function boot() $this->registerAuthProvider(); $this->registerMorphMaps(); } - + /** * @return void */ @@ -46,7 +46,7 @@ private function publishConfigFile() */ private function registerAuthProvider() { - if (Corcel::isLaravel()) { + if (Corcel::isLaravel() || Corcel::isLumen()) { Auth::provider('corcel', function ($app, array $config) { return new AuthUserProvider($config); }); diff --git a/src/Model.php b/src/Model.php index 2e1c6986..dd2ca13f 100644 --- a/src/Model.php +++ b/src/Model.php @@ -175,7 +175,7 @@ protected function setRelationConnection($model) */ public function getConnectionName() { - if (!isset($this->connection) && Corcel::isLaravel()) { + if (!isset($this->connection) && (Corcel::isLaravel() || Corcel::isLumen())) { if ($connection = config('corcel.connection')) { $this->connection = $connection; } diff --git a/src/Model/Post.php b/src/Model/Post.php index 250f1b2b..cf4a7c7f 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -143,7 +143,7 @@ protected function getPostInstance(array $attributes) if (isset($attributes['post_type']) && $attributes['post_type']) { if (isset(static::$postTypes[$attributes['post_type']])) { $class = static::$postTypes[$attributes['post_type']]; - } elseif (Corcel::isLaravel()) { + } elseif (Corcel::isLaravel() || Corcel::isLumen()) { $postTypes = config('corcel.post_types'); if (is_array($postTypes) && isset($postTypes[$attributes['post_type']])) { $class = $postTypes[$attributes['post_type']];