Skip to content

Commit

Permalink
Facade fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CrashSensei committed Sep 2, 2016
1 parent 28943f1 commit 357ed39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
21 changes: 1 addition & 20 deletions src/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ public function log($description)
return;
}

$activityModelClassName = $this->determineActivityModel();

$activity = new $activityModelClassName();
$activity = ActivitylogServiceProvider::getActivityModelInstance();

if ($this->performedOn) {
$activity->subject()->associate($this->performedOn);
Expand Down Expand Up @@ -202,21 +200,4 @@ protected function replacePlaceholders($description, Activity $activity)
}, $description);
}

/**
* @throws \Spatie\Activitylog\Exceptions\InvalidConfiguration
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function determineActivityModel()
{
$activityModel = config('laravel-activitylog.activity_model') != null ?
config('laravel-activitylog.activity_model') :
Activity::class;

if (! is_a($activityModel, Activity::class, true)) {
throw InvalidConfiguration::modelIsNotValid($activityModel);
}

return $activityModel;
}
}
34 changes: 31 additions & 3 deletions src/ActivitylogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Spatie\Activitylog;

use Illuminate\Support\ServiceProvider;
use Spatie\Activitylog\Exceptions\InvalidConfiguration;
use Spatie\Activitylog\Models\Activity;

class ActivitylogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -32,14 +34,40 @@ public function boot()
public function register()
{
$this->app->bind(
'laravel-activitylog',
\Spatie\Activitylog\ActivityLogger::class
);
'laravel-activitylog', function($app) {
return self::getActivityModelInstance();
});

$this->app->bind('command.activitylog:clean', CleanActivitylogCommand::class);

$this->commands([
'command.activitylog:clean',
]);
}


/**
* @throws \Spatie\Activitylog\Exceptions\InvalidConfiguration
*
* @return \Illuminate\Database\Eloquent\Model
*/
static public function determineActivityModel()
{
$activityModel = config('laravel-activitylog.activity_model') != null ?
config('laravel-activitylog.activity_model') :
Activity::class;

if (! is_a($activityModel, Activity::class, true)) {
throw InvalidConfiguration::modelIsNotValid($activityModel);
}

return $activityModel;
}

static public function getActivityModelInstance()
{
$activityModelClassName = self::determineActivityModel();

return new $activityModelClassName();
}
}

0 comments on commit 357ed39

Please sign in to comment.