diff --git a/app/Console/Commands/InstallCommand.php b/app/Console/Commands/InstallCommand.php index ad0384193..e86d9b566 100644 --- a/app/Console/Commands/InstallCommand.php +++ b/app/Console/Commands/InstallCommand.php @@ -117,7 +117,7 @@ public function handle() $this->info("3. Generating .env file..."); - $dotenv = new \App\Libs\DotEnvGenerator(); + $dotenv = new \App\Services\DotEnvGenerator(); $dotenv->addEnvVar('DB_HOST', '127.0.0.1'); $dotenv->addEnvVar('DB_CONNECTION', $database['driver']); $dotenv->addEnvVar('DB_USERNAME', $database['username']); diff --git a/app/Controllers/InstallController.php b/app/Controllers/InstallController.php index bf372cbfe..15a104cf4 100644 --- a/app/Controllers/InstallController.php +++ b/app/Controllers/InstallController.php @@ -179,7 +179,7 @@ public function step4() { if (!Session::has('error')) { - $dotenv = new \App\Libs\DotEnvGenerator(); + $dotenv = new \App\Services\DotEnvGenerator(); //TODO Inject $dotenv->addEnvVar('DB_HOST', Session::get('step2.server')); $dotenv->addEnvVar('DB_CONNECTION', Session::get('step2.db_driver')); $dotenv->addEnvVar('DB_USERNAME', Session::get('step2.username')); diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 66111f173..a1fe3de83 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -55,7 +55,7 @@ public function create(Request $request) return view('pages.form', [ 'all_page' => Page::all(), - 'page_templates' => (new \App\Libs\Theme($request->settings['theme']))->templates(), + 'page_templates' => (new \App\Services\Theme($request->settings['theme']))->templates(), ]); } @@ -112,7 +112,7 @@ public function edit(Request $request, Page $page) return view('pages.form', [ 'page' => $page, 'all_page' => Page::all(), - 'page_templates' => (new \App\Libs\Theme($request->settings['theme']))->templates(), + 'page_templates' => (new \App\Services\Theme($request->settings['theme']))->templates(), ]); } diff --git a/app/Controllers/SearchController.php b/app/Controllers/SearchController.php index 759208379..8820a2888 100644 --- a/app/Controllers/SearchController.php +++ b/app/Controllers/SearchController.php @@ -4,7 +4,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use App\Libs\SearchEngine; +use App\Services\SearchEngine; class SearchController extends Controller { diff --git a/app/Controllers/ThemeController.php b/app/Controllers/ThemeController.php index 5b98a3501..5bbeaaaa2 100644 --- a/app/Controllers/ThemeController.php +++ b/app/Controllers/ThemeController.php @@ -5,6 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use App\Services\Theme; use App\Model\Settings; class ThemeController extends Controller @@ -19,9 +20,9 @@ class ThemeController extends Controller public function index(Request $request) { return view("theme.index", [ - 'active_theme' => new \App\Libs\Theme($request->settings['theme']), + 'active_theme' => new Theme($request->settings['theme']), 'all_themes' => collect(array_slice(scandir("themes"), 2))->map(function ($theme) { - return new \App\Libs\Theme($theme); + return new Theme($theme); }) ]); } @@ -48,15 +49,15 @@ public function config($slug) $websiteController = new \App\Controllers\WebsiteController(request()); $websiteController->before(); - $theme_engine = new \App\Libs\ThemeEngine(request()); - $theme_engine->setTheme(new \App\Libs\Theme(request()->settings['theme'])); + $theme_engine = new \App\Services\ThemeEngine(request()); + $theme_engine->setTheme(new Theme(request()->settings['theme'])); $theme_engine->boot(); \Website::initalize($theme_engine); return view("theme.config", [ - 'active_theme' => new \App\Libs\Theme(request()->settings['theme']), + 'active_theme' => new Theme(request()->settings['theme']), 'website_content' => $websiteController->index(request()->input('page')), ]); } @@ -73,7 +74,7 @@ public function options($theme) $theme_css->save(); } - $theme = new \App\Libs\Theme($theme == null ? request()->settings['theme'] : $theme); + $theme = new Theme($theme == null ? request()->settings['theme'] : $theme); $translations = []; @@ -90,7 +91,7 @@ public function updateTranslations($theme) if (request()->isMethod('POST')) { try { - $theme = new \App\Libs\Theme($theme == null ? request()->settings['theme'] : $theme); + $theme = new Theme($theme == null ? request()->settings['theme'] : $theme); $translations = []; diff --git a/app/Controllers/WebsiteController.php b/app/Controllers/WebsiteController.php index c89107aef..0a520f0a3 100644 --- a/app/Controllers/WebsiteController.php +++ b/app/Controllers/WebsiteController.php @@ -12,14 +12,14 @@ class WebsiteController extends Controller private $request; private $engines = [ - 'hcms' => \App\Libs\ThemeEngine::class, - 'blade' => \App\Libs\BladeThemeEngine::class, - //'twig' => \App\Libs\TwigThemeEngine::class, + 'hcms' => \App\Services\ThemeEngine::class, + 'blade' => \App\Services\BladeThemeEngine::class, + //'twig' => \App\Services\TwigThemeEngine::class, ]; private $theme; - public function __construct(Request $request, \App\Libs\Theme $theme){ + public function __construct(Request $request, \App\Services\Theme $theme){ $this->request = $request; $this->theme = $theme; } @@ -140,7 +140,7 @@ public function search() } - $search_engine = new \App\Libs\SearchEngine(); + $search_engine = new \App\Services\SearchEngine(); $search_engine->registerModel(\App\Model\Blogpost::class); $search_engine->registerModel(\App\Model\Page::class); diff --git a/app/Http/Middleware/WebsiteMiddleware.php b/app/Http/Middleware/WebsiteMiddleware.php index 2dd98b710..b97fd94e1 100644 --- a/app/Http/Middleware/WebsiteMiddleware.php +++ b/app/Http/Middleware/WebsiteMiddleware.php @@ -11,7 +11,7 @@ class WebsiteMiddleware private $widgets; - public function __construct(\App\Libs\ShortCode $shortcode_engine){ + public function __construct(\App\Services\ShortCode $shortcode_engine){ $this->widgets = $shortcode_engine; } diff --git a/app/Libs/PluginInterface.php b/app/Interfaces/PluginInterface.php similarity index 95% rename from app/Libs/PluginInterface.php rename to app/Interfaces/PluginInterface.php index 839eab0f8..c892a5607 100644 --- a/app/Libs/PluginInterface.php +++ b/app/Interfaces/PluginInterface.php @@ -1,6 +1,6 @@ request = $request; - } - - public function getTheme(){ - return $this->theme; - } - - public function setTheme(\App\Libs\Theme $theme){ - $this->theme = $theme; - } - - public function pageTemplate($page_template){ - $this->page_template = $page_template; - } - - public function defaultTemplateExists($template){ - return file_exists($this->theme->getPath().$template.'.blade.php'); - } - - public function templateExists($template){ - return file_exists($this->theme->getPath()."page_templates".DIRECTORY_SEPARATOR.$template); - } - - - public function render(array $data){ - - $default_data = [ - '_THEME_PATH' => str_replace(DIRECTORY_SEPARATOR,'/',$this->theme->getPath()), - ]; - - - \View::addNamespace('theme', base_path($this->theme->getPath())); - - - return view('theme::'.str_replace('.blade.php','',$this->page_template),array_merge($default_data,$data)); - - } - - - public function runScript($script_name){ - if($this->theme->getConfig($script_name)){ - return call_user_func($this->theme->getConfig($script_name)); - } - - return NULL; - } - - - public function render404(){ - - if($this->theme->has404Template()){ - $this->page_template = "404"; - }else{ - $this->page_template = "default.404"; - } - - } - - public function renderWebsiteDown(){ - if($this->theme->hasWebsiteDownTemplate()){ - $this->page_template = "website_down"; - }else{ - $this->page_template = "default.website_down"; - } - } - - - -} \ No newline at end of file diff --git a/app/Libs/Controller.php b/app/Libs/Controller.php deleted file mode 100644 index ff26b9811..000000000 --- a/app/Libs/Controller.php +++ /dev/null @@ -1,52 +0,0 @@ -request = $request; - - $this->view = $viewResolver; - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function redirect($location){ - return redirect($location); - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function redirectToSelf(){ - return redirect()->back(); - } - -} diff --git a/app/Libs/ViewResolver.php b/app/Libs/ViewResolver.php deleted file mode 100644 index fe703fb97..000000000 --- a/app/Libs/ViewResolver.php +++ /dev/null @@ -1,61 +0,0 @@ -data['title'] = null; - $this->data['css'] = Config::get('horizontcms.css'); - $this->data['js'] = Config::get('horizontcms.js'); - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function title($title) - { - $this->data['title'] = $title; - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function render($view_file, array $data = []) - { - - return view($view_file, array_merge($this->data, $data)); - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function css($file) - { - $this->data['css'][] = $file; - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function js($file) - { - $this->data['js'][] = $file; - } - -} diff --git a/app/Model/Plugin.php b/app/Model/Plugin.php index 24efd0c2d..c469bd0ef 100644 --- a/app/Model/Plugin.php +++ b/app/Model/Plugin.php @@ -181,7 +181,7 @@ public function getRegister($register, $default = null) $instance = new $plugin_namespace(); - if ($instance instanceof \App\Libs\PluginInterface) { + if ($instance instanceof \App\Interfaces\PluginInterface) { return $instance->$register(); } } diff --git a/app/Providers/ThemeServiceProvider.php b/app/Providers/ThemeServiceProvider.php index 22d09b404..232b1ca31 100644 --- a/app/Providers/ThemeServiceProvider.php +++ b/app/Providers/ThemeServiceProvider.php @@ -4,7 +4,7 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Route; -use \App\Libs\Theme; +use \App\Services\Theme; class ThemeServiceProvider extends ServiceProvider { diff --git a/app/Services/BladeThemeEngine.php b/app/Services/BladeThemeEngine.php new file mode 100644 index 000000000..2ad2516de --- /dev/null +++ b/app/Services/BladeThemeEngine.php @@ -0,0 +1,86 @@ +request = $request; + } + + public function getTheme() + { + return $this->theme; + } + + public function setTheme(\App\Services\Theme $theme) + { + $this->theme = $theme; + } + + public function pageTemplate($page_template) + { + $this->page_template = $page_template; + } + + public function defaultTemplateExists($template) + { + return file_exists($this->theme->getPath() . $template . '.blade.php'); + } + + public function templateExists($template) + { + return file_exists($this->theme->getPath() . "page_templates" . DIRECTORY_SEPARATOR . $template); + } + + + public function render(array $data) + { + + $default_data = [ + '_THEME_PATH' => str_replace(DIRECTORY_SEPARATOR, '/', $this->theme->getPath()), + ]; + + + \View::addNamespace('theme', base_path($this->theme->getPath())); + + + return view('theme::' . str_replace('.blade.php', '', $this->page_template), array_merge($default_data, $data)); + } + + + public function runScript($script_name) + { + if ($this->theme->getConfig($script_name)) { + return call_user_func($this->theme->getConfig($script_name)); + } + + return NULL; + } + + + public function render404() + { + + if ($this->theme->has404Template()) { + $this->page_template = "404"; + } else { + $this->page_template = "default.404"; + } + } + + public function renderWebsiteDown() + { + if ($this->theme->hasWebsiteDownTemplate()) { + $this->page_template = "website_down"; + } else { + $this->page_template = "default.website_down"; + } + } +} diff --git a/app/Libs/DotEnvGenerator.php b/app/Services/DotEnvGenerator.php similarity index 95% rename from app/Libs/DotEnvGenerator.php rename to app/Services/DotEnvGenerator.php index 6e7027a76..3e7e6b76f 100644 --- a/app/Libs/DotEnvGenerator.php +++ b/app/Services/DotEnvGenerator.php @@ -1,6 +1,6 @@ theme; } - public function setTheme(\App\Libs\Theme $theme){ + public function setTheme(\App\Services\Theme $theme){ $this->theme = $theme; } diff --git a/app/Helpers/Website.php b/app/Services/Website.php similarity index 99% rename from app/Helpers/Website.php rename to app/Services/Website.php index 6a0d4877e..c6405b010 100644 --- a/app/Helpers/Website.php +++ b/app/Services/Website.php @@ -1,5 +1,7 @@ Lavary\Menu\Facade::class, 'Settings' => \App\Model\Settings::class, + 'Website' => \App\Services\Website::class, 'Zipper' => Madnest\Madzipper\Madzipper::class, ], diff --git a/resources/tests/unit/SearchEngineTest.php b/resources/tests/unit/SearchEngineTest.php index 1ef388fff..df74146bf 100644 --- a/resources/tests/unit/SearchEngineTest.php +++ b/resources/tests/unit/SearchEngineTest.php @@ -13,7 +13,7 @@ class SearchEngineTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->engine = new \App\Libs\SearchEngine(); + $this->engine = new \App\Services\SearchEngine(); } /** @@ -25,7 +25,7 @@ public function testSearchEngineInitiation() { - $this->assertInstanceOf(\App\Libs\SearchEngine::class, $this->engine); + $this->assertInstanceOf(\App\Services\SearchEngine::class, $this->engine); $this->assertObjectHasProperty('searchModels', $this->engine); $this->assertObjectHasProperty('searchKey', $this->engine); @@ -56,7 +56,7 @@ public function testGetterAndSetterModel() $this->engine->registerModel(\App\Model\Page::class); $this->assertEquals(1, count($this->engine->getRegisteredModels())); - $this->assertEquals(0, count($this->engine->getResultsFor(\App\Libs\Page::class))); + $this->assertEquals(0, count($this->engine->getResultsFor(\App\Model\Page::class))); } public function testExecuteSearch() diff --git a/resources/tests/unit/WidgetResolverTest.php b/resources/tests/unit/WidgetResolverTest.php index 879606283..92519dc5f 100644 --- a/resources/tests/unit/WidgetResolverTest.php +++ b/resources/tests/unit/WidgetResolverTest.php @@ -7,7 +7,7 @@ class WidgetResolverTest extends TestCase public function testSetterAndGetter() { - $widgetResolver = new \App\Libs\ShortCode(); + $widgetResolver = new \App\Services\ShortCode(); $widgetResolver->addWidget('{[TestingWidget]}', 'WidgetResolved'); @@ -20,7 +20,7 @@ public function testWidgetResolving() $content = "Some sample text for testing the {[TestingWidget1]} and {[TestingWidget2]} resolving"; - $widgetResolver = new \App\Libs\ShortCode(); + $widgetResolver = new \App\Services\ShortCode(); $widgetResolver->addWidget('{[TestingWidget1]}', 'WidgetResolved1'); diff --git a/themes/TheWright/app/Controllers/StartController.php b/themes/TheWright/app/Controllers/StartController.php index 8a4218a7d..277558710 100644 --- a/themes/TheWright/app/Controllers/StartController.php +++ b/themes/TheWright/app/Controllers/StartController.php @@ -3,15 +3,13 @@ namespace Theme\TheWright\App\Controllers; use Illuminate\Http\Request; -use App\Libs\Controller; +use Illuminate\Routing\Controller; -class StartController extends Controller{ +class StartController extends Controller +{ - public function index(){ - dd("It's a theme controller!"); + public function index() + { + dd("It's a theme controller!"); } - - - - -} \ No newline at end of file +} diff --git a/themes/TheWright/header.php b/themes/TheWright/header.php index c48322fc0..c9a19cef3 100644 --- a/themes/TheWright/header.php +++ b/themes/TheWright/header.php @@ -27,7 +27,7 @@ } ?> - + \ No newline at end of file