@@ -173,6 +173,10 @@ |
||
173 | 173 | }, $description); |
174 | 174 | } |
175 | 175 | |
176 | + /** |
|
177 | + * @param string $start |
|
178 | + * @param string $end |
|
179 | + */ |
|
176 | 180 | function getBetween($content,$start,$end){ |
177 | 181 | $r = explode($start, $content); |
178 | 182 | if (isset($r[1])){ |
@@ -14,7 +14,6 @@ |
||
14 | 14 | use Illuminate\Support\Traits\Macroable; |
15 | 15 | use LaiVu\ActivityLog\Exceptions\InvalidConfiguration; |
16 | 16 | use LaiVu\ActivityLog\Handlers\ActivityLogHandlerInterface; |
17 | -use LaiVu\ActivityLog\Models\Activity; |
|
18 | 17 | |
19 | 18 | class ActivityLogger |
20 | 19 | { |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | $maxAgeInDays = config('activitylog.delete_records_older_than_days'); |
152 | 152 | |
153 | - if(is_null($maxAgeInDays) || $maxAgeInDays ==''){ |
|
153 | + if (is_null($maxAgeInDays) || $maxAgeInDays == '') { |
|
154 | 154 | return false; |
155 | 155 | } |
156 | 156 | |
@@ -162,20 +162,20 @@ discard block |
||
162 | 162 | |
163 | 163 | protected function replacePlaceholders($description) |
164 | 164 | { |
165 | - return preg_replace_callback('/:[a-z0-9._-]+/i', function ($match) { |
|
165 | + return preg_replace_callback('/:[a-z0-9._-]+/i', function($match) { |
|
166 | 166 | $match = $match[0]; |
167 | - $attribute =$this->getBetween($match,':', '.'); |
|
168 | - if (! in_array($attribute, ['performedOn', 'causedBy', 'properties'])) { |
|
167 | + $attribute = $this->getBetween($match, ':', '.'); |
|
168 | + if (!in_array($attribute, ['performedOn', 'causedBy', 'properties'])) { |
|
169 | 169 | return $match; |
170 | 170 | } |
171 | 171 | $propertyName = substr($match, strpos($match, '.') + 1); |
172 | - return isset($this->{$attribute})&&isset($this->{$attribute}->{$propertyName})?$this->{$attribute}->{$propertyName}:$match; |
|
172 | + return isset($this->{$attribute}) && isset($this->{$attribute}->{$propertyName}) ? $this->{$attribute}->{$propertyName}:$match; |
|
173 | 173 | }, $description); |
174 | 174 | } |
175 | 175 | |
176 | - function getBetween($content,$start,$end){ |
|
176 | + function getBetween($content, $start, $end) { |
|
177 | 177 | $r = explode($start, $content); |
178 | - if (isset($r[1])){ |
|
178 | + if (isset($r[1])) { |
|
179 | 179 | $r = explode($end, $r[1]); |
180 | 180 | return $r[0]; |
181 | 181 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param array $properties |
21 | 21 | * @param $logName |
22 | 22 | * @param string $description |
23 | - * @return mixed |
|
23 | + * @return boolean |
|
24 | 24 | */ |
25 | 25 | function log($performOn, $causerBy, $properties = [], $logName, $description) |
26 | 26 | { |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @param $maxAgeInMonth |
36 | - * @return boolean |
|
36 | + * @return boolean|null |
|
37 | 37 | */ |
38 | 38 | function cleanLog($maxAgeInMonth) |
39 | 39 | { |
@@ -16,14 +16,14 @@ |
||
16 | 16 | { |
17 | 17 | public static function modelIsNotValid($className) |
18 | 18 | { |
19 | - return new static("The given model class `$className` does not extend `".Activity::class.'`'); |
|
19 | + return new static("The given model class `$className` does not extend `" . Activity::class . '`'); |
|
20 | 20 | } |
21 | 21 | |
22 | - public static function handlerNotFound($handlerName){ |
|
22 | + public static function handlerNotFound($handlerName) { |
|
23 | 23 | return new static("The given handler `$handlerName` does not exist"); |
24 | 24 | } |
25 | 25 | |
26 | - public static function handlerTypeNotValid($className){ |
|
27 | - return new static("The given handler class `$className` does not extend `".ActivityLogHandlerInterface::class.'`'); |
|
26 | + public static function handlerTypeNotValid($className) { |
|
27 | + return new static("The given handler class `$className` does not extend `" . ActivityLogHandlerInterface::class . '`'); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -56,7 +56,7 @@ |
||
56 | 56 | */ |
57 | 57 | public function getChangesAttribute() |
58 | 58 | { |
59 | - return collect(array_filter($this->properties->toArray(), function ($key) { |
|
59 | + return collect(array_filter($this->properties->toArray(), function($key) { |
|
60 | 60 | return in_array($key, ['attributes', 'old']); |
61 | 61 | }, ARRAY_FILTER_USE_KEY)); |
62 | 62 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | protected static function bootDetectsChanges() |
15 | 15 | { |
16 | 16 | if (static::eventsToBeRecorded()->contains('updated')) { |
17 | - static::updating(function (Model $model) { |
|
17 | + static::updating(function(Model $model) { |
|
18 | 18 | //temporary hold the original attributes on the model |
19 | 19 | //as we'll need these in the updating event |
20 | 20 | $oldValues = $model->replicate()->setRawAttributes($model->getOriginal()); |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | } |
25 | 25 | public function attributesToBeLogged() |
26 | 26 | { |
27 | - if (! isset(static::$logAttributes)) { |
|
27 | + if (!isset(static::$logAttributes)) { |
|
28 | 28 | return []; |
29 | 29 | } |
30 | 30 | return static::$logAttributes; |
31 | 31 | } |
32 | - public function attributeValuesToBeLogged( $processingEvent) |
|
32 | + public function attributeValuesToBeLogged($processingEvent) |
|
33 | 33 | { |
34 | - if (! count($this->attributesToBeLogged())) { |
|
34 | + if (!count($this->attributesToBeLogged())) { |
|
35 | 35 | return []; |
36 | 36 | } |
37 | 37 | $properties['attributes'] = static::logChanges($this); |
@@ -19,8 +19,8 @@ |
||
19 | 19 | |
20 | 20 | protected static function bootLogsActivity() |
21 | 21 | { |
22 | - static::eventsToBeRecorded()->each(function ($eventName) { |
|
23 | - return static::$eventName(function (Model $model) use ($eventName) { |
|
22 | + static::eventsToBeRecorded()->each(function($eventName) { |
|
23 | + return static::$eventName(function(Model $model) use ($eventName) { |
|
24 | 24 | if (!$model->shouldLogEvent($eventName)) { |
25 | 25 | return; |
26 | 26 | } |
@@ -15,15 +15,15 @@ |
||
15 | 15 | public function boot() |
16 | 16 | { |
17 | 17 | $this->publishes([ |
18 | - __DIR__.'/../config/activitylog.php' => config_path('activitylog.php'), |
|
18 | + __DIR__ . '/../config/activitylog.php' => config_path('activitylog.php'), |
|
19 | 19 | ], 'config'); |
20 | 20 | |
21 | - $this->mergeConfigFrom(__DIR__.'/../config/activitylog.php', 'activitylog'); |
|
21 | + $this->mergeConfigFrom(__DIR__ . '/../config/activitylog.php', 'activitylog'); |
|
22 | 22 | |
23 | - if (! class_exists('CreateActivityLogTable')) { |
|
23 | + if (!class_exists('CreateActivityLogTable')) { |
|
24 | 24 | $timestamp = date('Y_m_d_His', time()); |
25 | 25 | $this->publishes([ |
26 | - __DIR__.'/../migrations/create_activity_log_table.php.stub' => database_path("/migrations/{$timestamp}_create_activity_log_table.php"), |
|
26 | + __DIR__ . '/../migrations/create_activity_log_table.php.stub' => database_path("/migrations/{$timestamp}_create_activity_log_table.php"), |
|
27 | 27 | ], 'migrations'); |
28 | 28 | } |
29 | 29 | } |
@@ -4,35 +4,35 @@ discard block |
||
4 | 4 | define('COL_DEFAULT', 2); |
5 | 5 | |
6 | 6 | $fields = [ |
7 | - 'author_name' => ['Your name', '', ''], |
|
8 | - 'author_github_username' => ['Your Github username', '<username> in https://github.com/username', ''], |
|
9 | - 'author_email' => ['Your email address', '', ''], |
|
10 | - 'author_twitter' => ['Your twitter username', '', '@{author_github_username}'], |
|
11 | - 'author_website' => ['Your website', '', 'https://github.com/{author_github_username}'], |
|
7 | + 'author_name' => ['Your name', '', ''], |
|
8 | + 'author_github_username' => ['Your Github username', '<username> in https://github.com/username', ''], |
|
9 | + 'author_email' => ['Your email address', '', ''], |
|
10 | + 'author_twitter' => ['Your twitter username', '', '@{author_github_username}'], |
|
11 | + 'author_website' => ['Your website', '', 'https://github.com/{author_github_username}'], |
|
12 | 12 | |
13 | - 'package_vendor' => ['Package vendor', '<vendor> in https://github.com/vendor/package', '{author_github_username}'], |
|
14 | - 'package_name' => ['Package name', '<package> in https://github.com/vendor/package', ''], |
|
15 | - 'package_description' => ['Package very short description', '', ''], |
|
13 | + 'package_vendor' => ['Package vendor', '<vendor> in https://github.com/vendor/package', '{author_github_username}'], |
|
14 | + 'package_name' => ['Package name', '<package> in https://github.com/vendor/package', ''], |
|
15 | + 'package_description' => ['Package very short description', '', ''], |
|
16 | 16 | |
17 | - 'psr4_namespace' => ['PSR-4 namespace', 'usually, Vendor\\Package', '{package_vendor}\\{package_name}'], |
|
17 | + 'psr4_namespace' => ['PSR-4 namespace', 'usually, Vendor\\Package', '{package_vendor}\\{package_name}'], |
|
18 | 18 | ]; |
19 | 19 | |
20 | 20 | $values = []; |
21 | 21 | |
22 | 22 | $replacements = [ |
23 | - ':vendor\\\\:package_name\\\\' => function () use(&$values) { return str_replace('\\', '\\\\', $values['psr4_namespace']) . '\\\\'; }, |
|
24 | - ':author_name' => function () use(&$values) { return $values['author_name']; }, |
|
25 | - ':author_username' => function () use(&$values) { return $values['author_github_username']; }, |
|
26 | - ':author_website' => function () use(&$values) { return $values['author_website'] ?: ('https://github.com/' . $values['author_github_username']); }, |
|
27 | - ':author_email' => function () use(&$values) { return $values['author_email'] ?: ($values['author_github_username'] . '@example.com'); }, |
|
28 | - ':vendor' => function () use(&$values) { return $values['package_vendor']; }, |
|
29 | - ':package_name' => function () use(&$values) { return $values['package_name']; }, |
|
30 | - ':package_description' => function () use(&$values) { return $values['package_description']; }, |
|
31 | - 'League\\Skeleton' => function () use(&$values) { return $values['psr4_namespace']; }, |
|
23 | + ':vendor\\\\:package_name\\\\' => function() use(&$values) { return str_replace('\\', '\\\\', $values['psr4_namespace']) . '\\\\'; }, |
|
24 | + ':author_name' => function() use(&$values) { return $values['author_name']; }, |
|
25 | + ':author_username' => function() use(&$values) { return $values['author_github_username']; }, |
|
26 | + ':author_website' => function() use(&$values) { return $values['author_website'] ?: ('https://github.com/' . $values['author_github_username']); }, |
|
27 | + ':author_email' => function() use(&$values) { return $values['author_email'] ?: ($values['author_github_username'] . '@example.com'); }, |
|
28 | + ':vendor' => function() use(&$values) { return $values['package_vendor']; }, |
|
29 | + ':package_name' => function() use(&$values) { return $values['package_name']; }, |
|
30 | + ':package_description' => function() use(&$values) { return $values['package_description']; }, |
|
31 | + 'League\\Skeleton' => function() use(&$values) { return $values['psr4_namespace']; }, |
|
32 | 32 | ]; |
33 | 33 | |
34 | -function read_from_console ($prompt) { |
|
35 | - if ( function_exists('readline') ) { |
|
34 | +function read_from_console($prompt) { |
|
35 | + if (function_exists('readline')) { |
|
36 | 36 | $line = trim(readline($prompt)); |
37 | 37 | if (!empty($line)) { |
38 | 38 | readline_add_history($line); |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | echo "Please, provide the following information:\n"; |
69 | 69 | echo "----------------------------------------------------------------------\n"; |
70 | 70 | foreach ($fields as $f => $field) { |
71 | - $default = isset($field[COL_DEFAULT]) ? interpolate($field[COL_DEFAULT], $values): ''; |
|
71 | + $default = isset($field[COL_DEFAULT]) ? interpolate($field[COL_DEFAULT], $values) : ''; |
|
72 | 72 | $prompt = sprintf( |
73 | 73 | '%s%s%s: ', |
74 | 74 | $field[COL_DESCRIPTION], |
75 | - $field[COL_HELP] ? ' (' . $field[COL_HELP] . ')': '', |
|
76 | - $field[COL_DEFAULT] !== '' ? ' [' . $default . ']': '' |
|
75 | + $field[COL_HELP] ? ' (' . $field[COL_HELP] . ')' : '', |
|
76 | + $field[COL_DEFAULT] !== '' ? ' [' . $default . ']' : '' |
|
77 | 77 | ); |
78 | 78 | $values[$f] = read_from_console($prompt); |
79 | 79 | if (empty($values[$f])) { |