Skip to content
This repository has been archived by the owner on Jun 1, 2019. It is now read-only.

Commit

Permalink
small refactor + adhere to psr-2
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 21, 2015
1 parent 4e9b148 commit c60a7ea
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

All Notable changes to `activitylog` will be documented in this file

### 2.1.0
- Added option to specify a default user id

### 2.0.0
- Added logging of model events
4 changes: 3 additions & 1 deletion src/Spatie/Activitylog/ActivitylogFacade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Spatie\Activitylog;
<?php

namespace Spatie\Activitylog;

use Illuminate\Support\Facades\Facade;

Expand Down
4 changes: 3 additions & 1 deletion src/Spatie/Activitylog/ActivitylogServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Spatie\Activitylog;
<?php

namespace Spatie\Activitylog;

use Illuminate\Support\ServiceProvider;

Expand Down
32 changes: 18 additions & 14 deletions src/Spatie/Activitylog/ActivitylogSupervisor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Spatie\Activitylog;
<?php

namespace Spatie\Activitylog;

use Illuminate\Config\Repository;
use Illuminate\Auth\Guard;
Expand All @@ -20,8 +22,8 @@ class ActivitylogSupervisor
* Also register Laravels Log Handler if needed.
*
* @param Handlers\ActivitylogHandlerInterface $handler
* @param Repository $config
* @param Guard $auth
* @param Repository $config
* @param Guard $auth
*/
public function __construct(Handlers\ActivitylogHandlerInterface $handler, Repository $config, Guard $auth)
{
Expand Down Expand Up @@ -70,22 +72,24 @@ public function cleanLog()
/**
* Normalize the user id.
*
* @param object|int $userId
* @param object|int $userId
*
* @return int
*/
public function normalizeUserId($userId)
{
if (is_numeric($userId)) {
return $userId;
}

if (is_object($userId)) {
// User model provided.
$userId = $userId->id;
} else if ($userId === '') {
// No user id provided, either get the logged in user or fallback to default.
if ($this->auth->check()) {
$userId = $this->auth->user()->id;
} else {
$userId = Config::get('activitylog.defaultUserId');
}
return $userId->id;
}
return $userId;

if ($this->auth->check()) {
return $this->auth->user()->id;
}

return Config::get('activitylog.defaultUserId');
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Spatie\Activitylog\Handlers;
<?php

namespace Spatie\Activitylog\Handlers;

interface ActivitylogHandlerInterface
{
Expand All @@ -9,7 +11,7 @@ interface ActivitylogHandlerInterface
* @param string $user
* @param array $attributes
*
* @return boolean
* @return bool
*/
public function log($text, $user = '', $attributes = []);

Expand All @@ -18,7 +20,7 @@ public function log($text, $user = '', $attributes = []);
*
* @param int $maxAgeInMonths
*
* @return boolean
* @return bool
*/
public function cleanLog($maxAgeInMonths);
}
4 changes: 2 additions & 2 deletions src/Spatie/Activitylog/Handlers/DefaultLaravelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DefaultLaravelHandler implements ActivitylogHandlerInterface
* @param $userId
* @param array $attributes
*
* @return boolean
* @return bool
*/
public function log($text, $userId = '', $attributes = [])
{
Expand All @@ -31,7 +31,7 @@ public function log($text, $userId = '', $attributes = [])
*
* @param int $maxAgeInMonths
*
* @return boolean
* @return bool
*/
public function cleanLog($maxAgeInMonths)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Spatie/Activitylog/Handlers/EloquentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class EloquentHandler implements ActivitylogHandlerInterface
* @param $userId
* @param array $attributes
*
* @return boolean
* @return bool
*/
public function log($text, $userId = '', $attributes = [])
{
Activity::create(
[
'text' => $text,
'user_id' => ($userId == '' ? null : $userId),
'text' => $text,
'user_id' => ($userId == '' ? null : $userId),
'ip_address' => $attributes['ipAddress'],
]
);
Expand All @@ -34,7 +34,7 @@ public function log($text, $userId = '', $attributes = [])
*
* @param int $maxAgeInMonths
*
* @return boolean
* @return bool
*/
public function cleanLog($maxAgeInMonths)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Spatie/Activitylog/LogsActivity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Spatie\Activitylog;
<?php

namespace Spatie\Activitylog;

use Activity;

Expand Down Expand Up @@ -35,4 +37,3 @@ protected static function getRecordActivityEvents()
];
}
}

6 changes: 4 additions & 2 deletions src/Spatie/Activitylog/LogsActivityInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace Spatie\Activitylog;
<?php

interface logsActivityInterface
namespace Spatie\Activitylog;

interface LogsActivityInterface
{
/**
* Get the message that needs to be logged for the given event.
Expand Down
4 changes: 3 additions & 1 deletion src/Spatie/Activitylog/Models/Activity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Spatie\Activitylog\Models;
<?php

namespace Spatie\Activitylog\Models;

use Eloquent;
use Config;
Expand Down
6 changes: 4 additions & 2 deletions src/config/activitylog.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

return [

/*
Expand Down Expand Up @@ -28,8 +29,9 @@
| Fallback user id if no user is logged in
|--------------------------------------------------------------------------
|
| When no user is logged in we fall back to this value.
| If you don't specify a user id when logging some activity and no
| user is logged in, this id will be used.
|
*/
'defaultUserId' => '',
];
];

0 comments on commit c60a7ea

Please sign in to comment.