generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f7a84a
commit c72247d
Showing
5 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
* This is the name of the table that will be created by the migration and | ||
* used by the Activity model shipped with this package. | ||
*/ | ||
'token_table_name' => 'satusehat_tokens', | ||
|
||
/* | ||
* This is the database connection that will be used by the migration and | ||
* the Activity model shipped with this package. In case it's not set | ||
* Laravel database.default will be used instead. | ||
*/ | ||
'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'), | ||
|
||
]; |
32 changes: 32 additions & 0 deletions
32
database/migrations/create_satusehat_tokens_table.php.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateSatusehatTokensTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create(config('satusehatintegration.token_table_name'), function (Blueprint $table) { | ||
$table->string('environment'); | ||
$table->longText('token'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists(config('satusehatintegration.token_table_name')); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Ivanwilliammd\SatusehatIntegration; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ActivitylogServiceProvider extends ServiceProvider | ||
{ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__.'/../config/satusehatintegration.php' => config_path('satusehatintegration.php'), | ||
], 'config'); | ||
|
||
$this->mergeConfigFrom(__DIR__.'/../config/satusehatintegration.php', 'satusehatintegration'); | ||
|
||
if (! class_exists('CreateActivityLogTable')) { | ||
$timestamp = date('Y_m_d_His', time()); | ||
|
||
$this->publishes([ | ||
__DIR__.'/../migrations/create_activity_log_table.php.stub' => database_path("/migrations/{$timestamp}_create_activity_log_table.php"), | ||
], 'migrations'); | ||
} | ||
} | ||
|
||
public function register() | ||
{ | ||
$this->app->bind('command.activitylog:clean', CleanActivitylogCommand::class); | ||
|
||
$this->commands([ | ||
'command.activitylog:clean', | ||
]); | ||
|
||
$this->app->bind(ActivityLogger::class); | ||
|
||
$this->app->singleton(ActivityLogStatus::class); | ||
} | ||
|
||
public static function determineActivityModel(): string | ||
{ | ||
$activityModel = config('activitylog.activity_model') ?? ActivityModel::class; | ||
|
||
if (! is_a($activityModel, Activity::class, true) | ||
|| ! is_a($activityModel, Model::class, true)) { | ||
throw InvalidConfiguration::modelIsNotValid($activityModel); | ||
} | ||
|
||
return $activityModel; | ||
} | ||
|
||
public static function getActivityModelInstance(): ActivityContract | ||
{ | ||
$activityModelClassName = self::determineActivityModel(); | ||
|
||
return new $activityModelClassName(); | ||
} | ||
} |