diff --git a/composer.json b/composer.json index 72f57a1..e8f6b75 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,23 @@ } ], "require": { - "php": ">=5.4.0", - "illuminate/support": "~5.0" + "php": "^8.2", + "illuminate/support": "^12.0" }, "autoload": { "classmap": [ "src/migrations" ], - "psr-0": { - "Snowfire\\App\\": "src/" + "psr-4": { + "Snowfire\\App\\": "src/Snowfire/App/" } }, - "minimum-stability": "stable" + "minimum-stability": "stable", + "extra": { + "laravel": { + "providers": [ + "Snowfire\\App\\SnowfireServiceProvider" + ] + } + } } diff --git a/readme.md b/readme.md index 3a30a0e..e7bbefc 100644 --- a/readme.md +++ b/readme.md @@ -1,21 +1,43 @@ ## Snowfire App -This packages makes it possible to connect your Laravel app to Snowfire. +This package makes it possible to connect your Laravel app to Snowfire. + +## Laravel Compatibility + +This package is compatible with Laravel 5 through Laravel 12. ## Install the package Add this to your composer.json - "snowfire/snowfire-app": "dev-master" +```json +"snowfire/snowfire-app": "dev-master" +``` + +Or install via Composer: + +```bash +composer require snowfire/snowfire-app +``` + +### Laravel 5 Add this to your service providers in `config/app.php` - 'Snowfire\App\SnowfireServiceProvider' +```php +'Snowfire\App\SnowfireServiceProvider' +``` + +### Laravel 6+ + +Service providers are auto-discovered in Laravel 6+. Add this to your route middlewares in `app/Http/Kernel.php` - 'snowfire' => 'Snowfire\App\Middleware\SnowfireMiddleware', - 'snowfireAdmin' => 'Snowfire\App\Middleware\SnowfireAdminMiddleware', +```php +'snowfire' => \Snowfire\App\Middleware\SnowfireMiddleware::class, +'snowfireAdmin' => \Snowfire\App\Middleware\SnowfireAdminMiddleware::class, +``` Publish the config file diff --git a/src/Snowfire/App/Middleware/SnowfireAdminMiddleware.php b/src/Snowfire/App/Middleware/SnowfireAdminMiddleware.php index 528e03b..9487c67 100644 --- a/src/Snowfire/App/Middleware/SnowfireAdminMiddleware.php +++ b/src/Snowfire/App/Middleware/SnowfireAdminMiddleware.php @@ -1,6 +1,12 @@ -route()->getParameter('snowfireAppId'); + $id = $request->route()->parameter('snowfireAppId'); $accountsRepository = app()->make('\Snowfire\App\Repositories\AccountsRepository'); $app = $accountsRepository->getById($id); - if ( ! \Snowfire::authorized($id)) { + if ( ! Snowfire::authorized($id)) { if ($app) { - return \Redirect::to($app->site_url . 'a;applications/application/moduleTab/' . \Snowfire::parameter('id')); + return Redirect::to($app->site_url . 'a;applications/application/moduleTab/' . Snowfire::parameter('id')); } else { - return \Response::make('Not authorized, please login again through Snowfire', 403); + return Response::make('Not authorized, please login again through Snowfire', 403); } } diff --git a/src/Snowfire/App/Middleware/SnowfireMiddleware.php b/src/Snowfire/App/Middleware/SnowfireMiddleware.php index fc3420e..a776e1e 100644 --- a/src/Snowfire/App/Middleware/SnowfireMiddleware.php +++ b/src/Snowfire/App/Middleware/SnowfireMiddleware.php @@ -1,6 +1,12 @@ -make('\Snowfire\App\Repositories\AccountsRepository'); - if (config('snowfire.debug')) { + if (Config::get('snowfire.debug')) { // In debug mode, use the first account id $app = $accountsRepository->first(); diff --git a/src/Snowfire/App/SnowfireServiceProvider.php b/src/Snowfire/App/SnowfireServiceProvider.php index a0a1beb..52550f2 100644 --- a/src/Snowfire/App/SnowfireServiceProvider.php +++ b/src/Snowfire/App/SnowfireServiceProvider.php @@ -1,8 +1,11 @@ -loadRoutesFrom(__DIR__ . '/../../routes.php'); + // Config publishing $this->publishes([ __DIR__ . '/../../config/snowfire.php' => config_path('snowfire.php'), - ]); + ], 'snowfire-config'); + // Migrations publishing $this->publishes([ - __DIR__.'/../../migrations/' => base_path('/database/migrations') - ], 'migrations'); + __DIR__.'/../../migrations/' => database_path('migrations') + ], 'snowfire-migrations'); } /** @@ -42,7 +47,7 @@ public function register() __DIR__ . '/../../config/snowfire.php', 'snowfire' ); - $this->app['snowfire'] = $this->app->share(function($app) + $this->app->singleton('snowfire', function($app) { $defaultConfig = [ 'acceptUrl' => route('snowfire.accept'), @@ -69,7 +74,7 @@ public function register() */ public function provides() { - return array('snowfire'); + return ['snowfire']; } } diff --git a/src/routes.php b/src/routes.php index e124a87..6e89611 100644 --- a/src/routes.php +++ b/src/routes.php @@ -1,12 +1,19 @@ 'snowfire'], function() { +use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\Response; +use Illuminate\Support\Facades\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Redirect; +use Snowfire\App\Facades\Snowfire; - Route::get('/install', ['as' => 'snowfire.install', function() { +Route::group(['prefix' => 'snowfire', 'middleware' => ['web']], function() { + + Route::get('/install', function() { return Response::make(Snowfire::xml(), 200, ['content-type' => 'text/xml']); - }]); + })->name('snowfire.install'); - Route::post('/accept', ['as' => 'snowfire.accept', function() + Route::post('/accept', function() { $storage = \Snowfire\App\Storage\AccountStorage::where('site_url', '=', Request::get('domain'))->first(); @@ -23,9 +30,9 @@ //Log::info('sfapp/accept', [$_GET, $_POST]); return Response::make(Snowfire::response(true), 200, ['content-type' => 'text/xml']); - }]); + })->name('snowfire.accept'); - Route::post('/uninstall', ['as' => 'snowfire.uninstall', function() + Route::post('/uninstall', function() { //Log::info('sfapp/uninstall', [$_GET, $_POST]); $account = \Snowfire\App\Storage\AccountStorage::whereAppKey(Request::get('appKey'))->first(); @@ -33,10 +40,10 @@ $account->save(); return Response::make(Snowfire::response(true), 200, ['content-type' => 'text/xml']); - }]); + })->name('snowfire.uninstall'); // Admin tab - Route::get('/tab-proxy', ['as' => 'snowfire.tab', function() + Route::get('/tab-proxy', function() { $accountsRepository = app('Snowfire\App\Repositories\AccountsRepository'); $appKey = Request::get('snowfireAppKey'); @@ -55,10 +62,10 @@ return Redirect::route(Snowfire::parameter('tabRedirectRoute'), [$app->id]); - }]); + })->name('snowfire.tab'); // Proxy an URL to send a user between core domain and snowfire loaded app - Route::get('snowfire/proxy/{hash}', ['as' => 'snowfire.proxy', function($hash) + Route::get('proxy/{hash}', function($hash) { $proxy = \Snowfire\App\Proxy::getByHash($hash); @@ -71,6 +78,6 @@ \Snowfire\App\Proxy::cleanup(); return Redirect::to($proxy->to_url); - }]); + })->name('snowfire.proxy'); }); \ No newline at end of file