Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: backwards compatibility
Browse files Browse the repository at this point in the history
joelbutcher committed Oct 27, 2023
1 parent dd399fd commit 3b74d46
Showing 5 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
],
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.7",
"illuminate/contracts": "^10",
"laravel/prompts": "^0.1.10",
"laravel/socialite": "^5.9",
15 changes: 15 additions & 0 deletions src/Installer/Drivers/Driver.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use JoelButcher\Socialstream\Concerns\InteractsWithComposer;
use JoelButcher\Socialstream\Installer\Enums\InstallOptions;
use JoelButcher\Socialstream\Installer\Enums\TestRunner;
@@ -134,6 +135,9 @@ protected function ensureDirectoriesExist(array $directories): static
protected function installServiceProviders(): static
{
copy(__DIR__.'/../../../stubs/app/Providers/AuthServiceProvider.php', app_path('Providers/AuthServiceProvider.php'));
copy(__DIR__.'/../../../stubs/app/Providers/SocialstreamServiceProvider.php', app_path('Providers/SocialstreamServiceProvider.php'));

$this->installServiceProviderAfter('JetstreamServiceProvider', 'SocialstreamServiceProvider');

return $this;
}
@@ -251,6 +255,17 @@ protected function replaceInFile(string $search, string $replace, string $path):
file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));
}

protected function installServiceProviderAfter(string $after, string $name)
{
if (! Str::contains($appConfig = file_get_contents(config_path('app.php')), 'App\\Providers\\'.$name.'::class')) {
file_put_contents(config_path('app.php'), str_replace(
'App\\Providers\\'.$after.'::class,',
'App\\Providers\\'.$after.'::class,'.PHP_EOL.' App\\Providers\\'.$name.'::class,',
$appConfig
));
}
}

/**
* Remove any dark classes, if dark mode has not been specified.
*/
4 changes: 4 additions & 0 deletions src/Installer/Drivers/Jetstream/JetstreamDriver.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace JoelButcher\Socialstream\Installer\Drivers\Jetstream;

use Illuminate\Filesystem\Filesystem;
use JoelButcher\Socialstream\Installer\Drivers\Driver;
use JoelButcher\Socialstream\Installer\Enums\InstallOptions;
use JoelButcher\Socialstream\Installer\Enums\JetstreamInstallStack;
@@ -109,5 +110,8 @@ protected function ensureTeamsCompatibility(InstallOptions ...$options): static
protected function postInstall(string $composerBinary, InstallOptions ...$options): void
{
$this->ensureTeamsCompatibility(...$options);

// This action is added when actions are published, this needs to be removed
(new Filesystem())->delete(app_path('Actions/Socialstream/CreateUserWithTeamsFromProvider.php'));
}
}
2 changes: 1 addition & 1 deletion src/SocialstreamServiceProvider.php
Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ protected function bootLaravelBreeze(): void
*/
protected function bootLaravelJetstream(): void
{
if ($this->hasComposerPackage('laravel/jetstream') || ! class_exists(Jetstream::class)) {
if (! $this->hasComposerPackage('laravel/jetstream') || ! class_exists(Jetstream::class)) {
return;
}

36 changes: 36 additions & 0 deletions stubs/app/Providers/SocialstreamServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Providers;

use App\Actions\Socialstream\CreateConnectedAccount;
use App\Actions\Socialstream\CreateUserFromProvider;
use App\Actions\Socialstream\GenerateRedirectForProvider;
use App\Actions\Socialstream\HandleInvalidState;
use App\Actions\Socialstream\ResolveSocialiteUser;
use App\Actions\Socialstream\UpdateConnectedAccount;
use Illuminate\Support\ServiceProvider;
use JoelButcher\Socialstream\Socialstream;

class SocialstreamServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}

/**
* Bootstrap any application services.
*/
public function boot(): void
{
Socialstream::resolvesSocialiteUsersUsing(ResolveSocialiteUser::class);
Socialstream::createUsersFromProviderUsing(CreateUserFromProvider::class);
Socialstream::createConnectedAccountsUsing(CreateConnectedAccount::class);
Socialstream::updateConnectedAccountsUsing(UpdateConnectedAccount::class);
Socialstream::handlesInvalidStateUsing(HandleInvalidState::class);
Socialstream::generatesProvidersRedirectsUsing(GenerateRedirectForProvider::class);
}
}

0 comments on commit 3b74d46

Please sign in to comment.