-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Showing
13 changed files
with
15 additions
and
119 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
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
return [ | ||
/* | ||
* Keep versions, you can redefine in target model. | ||
|
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
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 |
---|---|---|
@@ -1,18 +1,7 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Overtrue\LaravelVersionable; | ||
|
||
/** | ||
* Class ServiceProvider. | ||
*/ | ||
class ServiceProvider extends \Illuminate\Support\ServiceProvider | ||
{ | ||
public function boot() | ||
|
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Overtrue\LaravelVersionable; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
@@ -16,8 +8,6 @@ | |
use SebastianBergmann\Diff\Differ; | ||
|
||
/** | ||
* Class Version. | ||
* | ||
* @property Model $versionable | ||
* @property array $contents | ||
*/ | ||
|
@@ -51,7 +41,7 @@ public function user() | |
/** | ||
* @return \Illuminate\Database\Eloquent\Relations\MorphTo | ||
*/ | ||
public function versionable() | ||
public function versionable(): \Illuminate\Database\Eloquent\Relations\MorphTo | ||
{ | ||
return $this->morphTo('versionable'); | ||
} | ||
|
@@ -62,8 +52,9 @@ public function versionable() | |
* | ||
* @return \Overtrue\LaravelVersionable\Version | ||
*/ | ||
public static function createForModel(Model $model, array $attributes = []) | ||
public static function createForModel(Model $model, array $attributes = []): Version | ||
{ | ||
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */ | ||
$versionClass = $model->getVersionModel(); | ||
|
||
$version = new $versionClass(); | ||
|
@@ -85,22 +76,23 @@ public function revert() | |
{ | ||
return $this->versionable->fill($this->contents)->save(); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Model|null $model | ||
*/ | ||
public function revertWithoutSaving() | ||
public function revertWithoutSaving(): ?Model | ||
{ | ||
return $this->versionable->fill($this->contents); | ||
return $this->versionable->fill($this->contents); | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Database\Eloquent\Model|null $model | ||
* | ||
* @return string | ||
*/ | ||
public function diff(Model $model = null) | ||
public function diff(Model $model = null): string | ||
{ | ||
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */ | ||
$model || $model = $this->versionable; | ||
|
||
if ($model instanceof Version) { | ||
|
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 |
---|---|---|
@@ -1,18 +1,7 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Overtrue\LaravelVersionable; | ||
|
||
/** | ||
* Class VersionStrategy. | ||
*/ | ||
class VersionStrategy | ||
{ | ||
public const DIFF = 'diff'; | ||
|
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Overtrue\LaravelVersionable; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
@@ -34,6 +26,7 @@ function (Model $model) { | |
|
||
static::deleted( | ||
function (Model $model) { | ||
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */ | ||
if ($model->forceDeleting) { | ||
$model->forceRemoveAllVersions(); | ||
} else { | ||
|
@@ -45,6 +38,7 @@ function (Model $model) { | |
|
||
private static function createVersionForModel(Model $model): void | ||
{ | ||
/* @var \Overtrue\LaravelVersionable\Versionable|Model $model */ | ||
if (static::$versioning && $model->shouldVersioning()) { | ||
Version::createForModel($model); | ||
$model->removeOldVersions($model->getKeepVersionsCount()); | ||
|
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 |
---|---|---|
@@ -1,20 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
use Overtrue\LaravelVersionable\VersionStrategy; | ||
|
||
/** | ||
* Class FeatureTest. | ||
*/ | ||
class FeatureTest extends TestCase | ||
{ | ||
protected $user; | ||
|
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 |
---|---|---|
@@ -1,22 +1,11 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Overtrue\LaravelVersionable\Versionable; | ||
use Overtrue\LaravelVersionable\VersionStrategy; | ||
|
||
/** | ||
* Class Post. | ||
*/ | ||
class Post extends Model | ||
{ | ||
use Versionable; | ||
|
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
use Overtrue\LaravelVersionable\ServiceProvider; | ||
|
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 |
---|---|---|
@@ -1,18 +1,7 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Tests; | ||
|
||
/** | ||
* Class User. | ||
*/ | ||
class User extends \Illuminate\Foundation\Auth\User | ||
{ | ||
protected $fillable = ['name']; | ||
|
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
|
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 |
---|---|---|
@@ -1,13 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/laravel-versionable. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
|