first upload all files
This commit is contained in:
91
Modules/Core/Providers/AssetServiceProvider.php
Normal file
91
Modules/Core/Providers/AssetServiceProvider.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Core\Foundation\Asset\Manager\AssetManager;
|
||||
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
|
||||
use Modules\Core\Foundation\Asset\Manager\FleetCartAssetManager;
|
||||
use Modules\Core\Foundation\Asset\Pipeline\FleetCartAssetPipeline;
|
||||
use Modules\Core\Foundation\Asset\Types\AssetTypeFactory as AssetFactory;
|
||||
|
||||
class AssetServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (! config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addThemesAssets();
|
||||
$this->addModulesAssets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton(AssetManager::class, FleetCartAssetManager::class);
|
||||
|
||||
$this->app->singleton(AssetPipeline::class, function ($app) {
|
||||
return new FleetCartAssetPipeline($app[AssetManager::class]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add themes assets to the asset manager.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addThemesAssets()
|
||||
{
|
||||
$theme = strtolower(setting('active_theme'));
|
||||
|
||||
if (! is_null($assets = config("fleetcart.themes.{$theme}.assets"))) {
|
||||
$this->addAssets($assets);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add modules assets to the asset manager.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addModulesAssets()
|
||||
{
|
||||
foreach ($this->app['modules']->allEnabled() as $module) {
|
||||
$assets = config("fleetcart.modules.{$module->get('alias')}.assets");
|
||||
|
||||
if (! is_null($assets)) {
|
||||
$this->addAssets($assets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the assets from the config file on the asset manager.
|
||||
*
|
||||
* @param array $allAssets
|
||||
* @return void
|
||||
*/
|
||||
private function addAssets($assets)
|
||||
{
|
||||
// Add all assets to the AssetManager
|
||||
foreach (array_get($assets, 'all_assets', []) as $assetName => $assetPath) {
|
||||
$url = $this->app[AssetFactory::class]->make($assetPath)->url();
|
||||
|
||||
$this->app[AssetManager::class]->addAsset($assetName, $url);
|
||||
}
|
||||
|
||||
// Add required assets directly to the AssetPipeline
|
||||
$this->app[AssetPipeline::class]->requireAssets(array_get($assets, 'required_assets', []));
|
||||
}
|
||||
}
|
||||
203
Modules/Core/Providers/CoreServiceProvider.php
Normal file
203
Modules/Core/Providers/CoreServiceProvider.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Exception;
|
||||
use Modules\Support\Locale;
|
||||
use Modules\Setting\Entities\Setting;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Setting\Repository as SettingRepository;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class CoreServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Core module specific middleware.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
'auth' => \Modules\Core\Http\Middleware\Authenticate::class,
|
||||
'admin' => \Modules\Core\Http\Middleware\AdminMiddleware::class,
|
||||
'guest' => \Modules\Core\Http\Middleware\GuestMiddleware::class,
|
||||
'can' => \Modules\Core\Http\Middleware\Authorization::class,
|
||||
'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
|
||||
'locale_session_redirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
|
||||
'localization_redirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (! config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setupSupportedLocales();
|
||||
$this->registerSetting();
|
||||
$this->setupAppLocale();
|
||||
$this->setupAppCacheDriver();
|
||||
$this->hideDefaultLocaleInURL();
|
||||
$this->setupAppTimezone();
|
||||
$this->setupMailConfig();
|
||||
$this->registerMiddleware();
|
||||
$this->registerInAdminPanelState();
|
||||
$this->blacklistAdminRoutesOnFrontend();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup supported locales.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setupSupportedLocales()
|
||||
{
|
||||
$supportedLocales = [];
|
||||
|
||||
foreach ($this->getSupportedLocales() as $locale) {
|
||||
$supportedLocales[$locale]['name'] = Locale::name($locale);
|
||||
}
|
||||
|
||||
$this->app['config']->set('laravellocalization.supportedLocales', $supportedLocales);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported locales from database.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSupportedLocales()
|
||||
{
|
||||
try {
|
||||
return Setting::get('supported_locales', [config('app.locale')]);
|
||||
} catch (Exception $e) {
|
||||
return [config('app.locale')];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide default locale in url for non multi-locale mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function hideDefaultLocaleInURL()
|
||||
{
|
||||
if (! is_multilingual()) {
|
||||
$this->app['config']->set('laravellocalization.hideDefaultLocaleInURL', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register setting binding.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function registerSetting()
|
||||
{
|
||||
$this->app->singleton('setting', function () {
|
||||
return new SettingRepository(Setting::allCached());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup application locale.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function setupAppLocale()
|
||||
{
|
||||
$this->app['config']->set('app.locale', $defaultLocale = Setting::get('default_locale'));
|
||||
$this->app['config']->set('app.fallback_locale', $defaultLocale);
|
||||
|
||||
$locale = is_null(LaravelLocalization::setLocale()) ? $defaultLocale : null;
|
||||
|
||||
LaravelLocalization::setLocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup application cache driver.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setupAppCacheDriver()
|
||||
{
|
||||
$this->app['config']->set('cache.default', config('app.cache') ? 'file' : 'array');
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup application timezone.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setupAppTimezone()
|
||||
{
|
||||
$timezone = setting('default_timezone') ?? config('app.timezone');
|
||||
|
||||
date_default_timezone_set($timezone);
|
||||
|
||||
$this->app['config']->set('app.timezone', $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup application mail config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setupMailConfig()
|
||||
{
|
||||
$this->app['config']->set('mail.default', 'smtp');
|
||||
$this->app['config']->set('mail.from.address', setting('mail_from_address'));
|
||||
$this->app['config']->set('mail.from.name', setting('mail_from_name'));
|
||||
$this->app['config']->set('mail.mailers.smtp.host', setting('mail_host'));
|
||||
$this->app['config']->set('mail.mailers.smtp.port', setting('mail_port'));
|
||||
$this->app['config']->set('mail.mailers.smtp.username', setting('mail_username'));
|
||||
$this->app['config']->set('mail.mailers.smtp.password', setting('mail_password'));
|
||||
$this->app['config']->set('mail.mailers.smtp.encryption', setting('mail_encryption'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function registerMiddleware()
|
||||
{
|
||||
foreach ($this->middleware as $name => $middleware) {
|
||||
$this->app['router']->aliasMiddleware($name, $middleware);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register inAdminPanel state to the IoC container.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function registerInAdminPanelState()
|
||||
{
|
||||
if ($this->app->runningInConsole()) {
|
||||
return $this->app['inAdminPanel'] = false;
|
||||
}
|
||||
|
||||
$index = in_array($this->app['request']->segment(1), setting('supported_locales'))
|
||||
? 2
|
||||
: 1;
|
||||
|
||||
$this->app['inAdminPanel'] = $this->app['request']->segment($index) === 'admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklist admin routes on frontend for ziggy package.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function blacklistAdminRoutesOnFrontend()
|
||||
{
|
||||
if (! $this->app['inAdminPanel']) {
|
||||
$this->app['config']->set('ziggy.blacklist', ['admin.*']);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Modules/Core/Providers/ModuleServiceProvider.php
Normal file
91
Modules/Core/Providers/ModuleServiceProvider.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Nwidart\Modules\Module;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Eloquent\Factory as ModelFactory;
|
||||
|
||||
class ModuleServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
foreach ($this->app['modules']->allEnabled() as $module) {
|
||||
$this->loadViews($module);
|
||||
$this->loadTranslations($module);
|
||||
$this->loadConfigs($module);
|
||||
$this->loadMigrations($module);
|
||||
$this->loadModelFactories($module);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load views for the given module.
|
||||
*
|
||||
* @param \Nwidart\Modules\Module $module
|
||||
* @return void
|
||||
*/
|
||||
private function loadViews(Module $module)
|
||||
{
|
||||
$this->loadViewsFrom("{$module->getPath()}/Resources/views", $module->get('alias'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translations for the given module.
|
||||
*
|
||||
* @param \Nwidart\Modules\Module $module
|
||||
* @return void
|
||||
*/
|
||||
private function loadTranslations(Module $module)
|
||||
{
|
||||
$this->loadTranslationsFrom("{$module->getPath()}/Resources/lang", $module->get('alias'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load migrations for the given module.
|
||||
*
|
||||
* @param \Nwidart\Modules\Module $module
|
||||
* @return void
|
||||
*/
|
||||
private function loadConfigs(Module $module)
|
||||
{
|
||||
collect([
|
||||
'config' => "{$module->getPath()}/Config/config.php",
|
||||
'assets' => "{$module->getPath()}/Config/assets.php",
|
||||
'permissions' => "{$module->getPath()}/Config/permissions.php",
|
||||
])->filter(function ($path) {
|
||||
return file_exists($path);
|
||||
})->each(function ($path, $filename) use ($module) {
|
||||
$this->mergeConfigFrom($path, "fleetcart.modules.{$module->get('alias')}.{$filename}");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load migrations for the given module.
|
||||
*
|
||||
* @param \Nwidart\Modules\Module $module
|
||||
* @return void
|
||||
*/
|
||||
private function loadMigrations(Module $module)
|
||||
{
|
||||
$this->loadMigrationsFrom("{$module->getPath()}/Database/Migrations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load model factories for the given module.
|
||||
*
|
||||
* @param \Nwidart\Modules\Module $module
|
||||
* @return void
|
||||
*/
|
||||
private function loadModelFactories(Module $module)
|
||||
{
|
||||
$this->callAfterResolving(ModelFactory::class, function (ModelFactory $factory) use ($module) {
|
||||
$factory->load("{$module->getPath()}/Database/Factories");
|
||||
});
|
||||
}
|
||||
}
|
||||
121
Modules/Core/Providers/RouteServiceProvider.php
Normal file
121
Modules/Core/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
if (config('app.installed')) {
|
||||
$this->mapModuleRoutes();
|
||||
$this->mapThemeRoutes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map routes from all enabled modules.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function mapModuleRoutes()
|
||||
{
|
||||
foreach ($this->app['modules']->allEnabled() as $module) {
|
||||
$this->groupRoutes("Modules\\{$module->getName()}\\Http\\Controllers", function () use ($module) {
|
||||
$this->mapAdminRoutes("{$module->getPath()}/Routes/admin.php");
|
||||
$this->mapPublicRoutes("{$module->getPath()}/Routes/public.php");
|
||||
$this->mapApiRoutes("{$module->getPath()}/Routes/api.php");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map routes from active theme.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function mapThemeRoutes()
|
||||
{
|
||||
$theme = $this->app['stylist']->get(setting('active_theme'));
|
||||
|
||||
$this->groupRoutes("Themes\\{$theme->getName()}\\Http\\Controllers", function () use ($theme) {
|
||||
$this->mapAdminRoutes("{$theme->getPath()}/routes/admin.php");
|
||||
$this->mapPublicRoutes("{$theme->getPath()}/routes/public.php");
|
||||
$this->mapApiRoutes("{$theme->getPath()}/routes/api.php");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Group routes to common prefix and middleware.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
private function groupRoutes($namespace, $callback)
|
||||
{
|
||||
Route::group([
|
||||
'namespace' => $namespace,
|
||||
'prefix' => LaravelLocalization::setLocale(),
|
||||
'middleware' => ['localize', 'locale_session_redirect', 'localization_redirect', 'web'],
|
||||
], function () use ($callback) {
|
||||
$callback();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Map admin routes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function mapAdminRoutes($path)
|
||||
{
|
||||
if (! file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Route::group([
|
||||
'namespace' => 'Admin',
|
||||
'prefix' => 'admin',
|
||||
'middleware' => ['admin'],
|
||||
], function () use ($path) {
|
||||
require_once $path;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Map public routes.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
private function mapPublicRoutes($path)
|
||||
{
|
||||
if (file_exists($path)) {
|
||||
require_once $path;
|
||||
}
|
||||
}
|
||||
|
||||
private function mapApiRoutes($path)
|
||||
{
|
||||
if (! file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Route::group([
|
||||
'namespace' => 'Api',
|
||||
'prefix' => 'api',
|
||||
'middleware' => ['api'],
|
||||
], function () use ($path) {
|
||||
require_once $path;
|
||||
});
|
||||
}
|
||||
}
|
||||
34
Modules/Core/Providers/SearchEngineServiceProvider.php
Normal file
34
Modules/Core/Providers/SearchEngineServiceProvider.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SearchEngineServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (! config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->app['config']->set([
|
||||
'scout' => [
|
||||
'driver' => setting('search_engine', 'mysql'),
|
||||
'algolia' => [
|
||||
'id' => setting('algolia_app_id'),
|
||||
'secret' => setting('algolia_secret'),
|
||||
],
|
||||
'meilisearch' => [
|
||||
'host' => setting('meilisearch_host'),
|
||||
'key' => setting('meilisearch_key'),
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
111
Modules/Core/Providers/ThemeServiceProvider.php
Normal file
111
Modules/Core/Providers/ThemeServiceProvider.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Mehedi\Stylist\Theme\Json;
|
||||
use Mehedi\Stylist\Theme\Theme;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ThemeServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (! config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$activeTheme = setting('active_theme');
|
||||
|
||||
if (is_null($activeTheme)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->app['stylist']->activate($activeTheme);
|
||||
|
||||
$this->bootTheme($this->app['stylist']->get($activeTheme));
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the given theme.
|
||||
*
|
||||
* @param \Mehedi\Stylist\Theme\Theme $theme
|
||||
* @return void
|
||||
*/
|
||||
private function bootTheme(Theme $theme)
|
||||
{
|
||||
$themeJson = new Json($theme->getPath());
|
||||
|
||||
$providers = $themeJson->getJsonAttribute('providers') ?? [];
|
||||
$themeAlias = $themeJson->getJsonAttribute('alias');
|
||||
$files = $themeJson->getJsonAttribute('files') ?? [];
|
||||
|
||||
$this->registerProviders($providers);
|
||||
$this->loadTranslations($theme, $themeAlias);
|
||||
$this->loadConfigs($theme, $themeAlias);
|
||||
$this->requireFiles($theme, $files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register given service providers.
|
||||
*
|
||||
* @param array $providers
|
||||
* @return void
|
||||
*/
|
||||
private function registerProviders($providers = [])
|
||||
{
|
||||
foreach ($providers as $provider) {
|
||||
$this->app->register($provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translations for the given theme.
|
||||
*
|
||||
* @param string $themeAlias
|
||||
* @param \Mehedi\Stylist\Theme\Theme $theme
|
||||
* @return void
|
||||
*/
|
||||
private function loadTranslations(Theme $theme, $themeAlias)
|
||||
{
|
||||
$this->loadTranslationsFrom("{$theme->getPath()}/resources/lang", $themeAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configs for the given theme.
|
||||
*
|
||||
* @param string $themeAlias
|
||||
* @param \Mehedi\Stylist\Theme\Theme $theme
|
||||
* @return void
|
||||
*/
|
||||
private function loadConfigs(Theme $theme, $themeAlias)
|
||||
{
|
||||
collect([
|
||||
'config' => "{$theme->getPath()}/config/config.php",
|
||||
'assets' => "{$theme->getPath()}/config/assets.php",
|
||||
'permissions' => "{$theme->getPath()}/config/permissions.php",
|
||||
])->filter(function ($path) {
|
||||
return file_exists($path);
|
||||
})->each(function ($path, $filename) use ($themeAlias) {
|
||||
$this->mergeConfigFrom($path, "fleetcart.themes.{$themeAlias}.{$filename}");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Require the given files.
|
||||
*
|
||||
* @param \Mehedi\Stylist\Theme\Theme $theme
|
||||
* @param array $files
|
||||
* @return void
|
||||
*/
|
||||
private function requireFiles(Theme $theme, $files = [])
|
||||
{
|
||||
foreach ($files as $file) {
|
||||
require_once "{$theme->getPath()}/{$file}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user