Skip to content

Commit

Permalink
Merge pull request #15 from cybercog/release/5.0
Browse files Browse the repository at this point in the history
Release 5.0
  • Loading branch information
Anton Komarev authored Sep 12, 2017
2 parents 0a87009 + 49c3af1 commit ab1e142
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 85 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to `laravel-ownership` will be documented in this file.

## [5.0.0] - 2017-09-13

### Changed

- Contracts namespace changed from `Cog\Contracts\Laravel\Ownership` to `Cog\Contracts\Ownership`

### Fixed

- Service Provider auto-discovery

## [4.0.0] - 2017-09-09

### Added
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Polymorphic ownership is useful when model can belongs to owners of different ty
Use `Ownable` contract in model which will get ownership behavior and implement it or just use `HasOwner` trait.

```php
use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Cog\Laravel\Ownership\Traits\HasOwner;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -106,7 +106,7 @@ By default owner model will be the same as `config('auth.providers.users.model')
To override default owner model in strict ownership, it's primary key or foreign key extend your ownable model with additional attributes:

```php
use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Cog\Laravel\Ownership\Traits\HasOwner;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -125,7 +125,7 @@ class Article extends Model implements OwnableContract
Use `Ownable` contract in model which will get polymorphic ownership behavior and implement it or just use `HasMorphOwner` trait.

```php
use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Cog\Laravel\Ownership\Traits\HasMorphOwner;
use Illuminate\Database\Eloquent\Model;

Expand Down Expand Up @@ -249,7 +249,7 @@ Article::whereNotOwnedBy($owner)->get();
To set currently authenticated user as owner for ownable model create - extend it with attribute `withDefaultOwnerOnCreate`. It works for both strict and polymorphic ownership behavior.

```php
use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Cog\Laravel\Ownership\Traits\HasOwner;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -264,7 +264,7 @@ class Article extends Model implements OwnableContract
To override strategy of getting default owner extend ownable model with `resolveDefaultOwner` method:

```php
use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Cog\Laravel\Ownership\Traits\HasOwner;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -277,7 +277,7 @@ class Article extends Model implements OwnableContract
/**
* Resolve entity default owner.
*
* @return \Cog\Contracts\Laravel\Ownership\CanBeOwner|null
* @return null|\Cog\Contracts\Ownership\CanBeOwner
*/
public function resolveDefaultOwner()
{
Expand Down
8 changes: 7 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Upgrade Guide

- [Upgrading From 4.0 To 5.0](#upgrade-5.0)
- [Upgrading From 3.0 To 4.0](#upgrade-4.0)
- [Upgrading From 2.0 To 3.0](#upgrade-3.0)

<a name="upgrade-3.0"></a>
<a name="upgrade-5.0"></a>
## Upgrading From 4.0 To 5.0

- Find all `Cog\Contracts\Laravel\Ownership` and replace with `Cog\Contracts\Ownership`

<a name="upgrade-4.0"></a>
## Upgrading From 3.0 To 4.0

- Find all `Cog\Ownership\Contracts\HasOwner` and replace with `Cog\Contracts\Laravel\Ownership\Ownable`
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"autoload": {
"psr-4": {
"Cog\\Contracts\\Laravel\\Ownership\\": "contracts/",
"Cog\\Contracts\\Ownership\\": "contracts/",
"Cog\\Laravel\\Ownership\\": "src/"
}
},
Expand All @@ -71,7 +71,7 @@
"extra": {
"laravel": {
"providers": [
"Cog\\Ownership\\Providers\\OwnershipServiceProvider"
"Cog\\Laravel\\Ownership\\Providers\\OwnershipServiceProvider"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions contracts/CanBeOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/

namespace Cog\Contracts\Laravel\Ownership;
namespace Cog\Contracts\Ownership;

/**
* Interface CanBeOwner.
*
* @package Cog\Contracts\Laravel\Ownership
* @package Cog\Contracts\Ownership
*/
interface CanBeOwner
{
Expand Down
8 changes: 4 additions & 4 deletions contracts/Exceptions/InvalidDefaultOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
* file that was distributed with this source code.
*/

namespace Cog\Contracts\Laravel\Ownership\Exceptions;
namespace Cog\Contracts\Ownership\Exceptions;

use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Exception;

/**
* Class InvalidDefaultOwner.
*
* @package Cog\Contracts\Laravel\Ownership\Exceptions
* @package Cog\Contracts\Ownership\Exceptions
*/
class InvalidDefaultOwner extends Exception
{
/**
* Default owner for ownable model is null.
*
* @param \Cog\Contracts\Laravel\Ownership\Ownable $ownable
* @param \Cog\Contracts\Ownership\Ownable $ownable
* @return static
*/
public static function isNull(OwnableContract $ownable)
Expand Down
12 changes: 6 additions & 6 deletions contracts/Exceptions/InvalidOwnerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
* file that was distributed with this source code.
*/

namespace Cog\Contracts\Laravel\Ownership\Exceptions;
namespace Cog\Contracts\Ownership\Exceptions;

use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\CanBeOwner as CanBeOwnerContract;
use Exception;
use Cog\Contracts\Laravel\Ownership\CanBeOwner as CanBeOwnerContract;

/**
* Class InvalidOwnerType.
*
* @package Cog\Contracts\Laravel\Ownership\Exceptions
* @package Cog\Contracts\Ownership\Exceptions
*/
class InvalidOwnerType extends Exception
{
/**
* Owner of the provided type is not allowed to own this model.
*
* @param \Cog\Contracts\Laravel\Ownership\Ownable $ownable
* @param \Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @param \Cog\Contracts\Ownership\Ownable $ownable
* @param \Cog\Contracts\Ownership\CanBeOwner $owner
* @return static
*/
public static function notAllowed(OwnableContract $ownable, CanBeOwnerContract $owner)
Expand Down
32 changes: 16 additions & 16 deletions contracts/Ownable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Cog\Contracts\Laravel\Ownership;
namespace Cog\Contracts\Ownership;

use Cog\Contracts\Ownership\CanBeOwner as CanBeOwnerContract;
use Illuminate\Database\Eloquent\Builder;
use Cog\Contracts\Laravel\Ownership\CanBeOwner as CanBeOwnerContract;

/**
* Interface Ownable.
*
* @package Cog\Contracts\Laravel\Ownership
* @package Cog\Contracts\Ownership
*/
interface Ownable
{
Expand All @@ -38,29 +38,29 @@ public function owner();
/**
* Get the model owner.
*
* @return \Cog\Contracts\Laravel\Ownership\CanBeOwner
* @return \Cog\Contracts\Ownership\CanBeOwner
*/
public function getOwner();

/**
* Get default owner.
*
* @return null|\Cog\Contracts\Laravel\Ownership\CanBeOwner
* @return null|\Cog\Contracts\Ownership\CanBeOwner
*/
public function defaultOwner();

/**
* Set owner as default for entity.
*
* @param null|\Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @return \Cog\Contracts\Laravel\Ownership\Ownable
* @param null|\Cog\Contracts\Ownership\CanBeOwner $owner
* @return \Cog\Contracts\Ownership\Ownable
*/
public function withDefaultOwner(CanBeOwnerContract $owner = null);

/**
* Remove default owner for entity.
*
* @return \Cog\Contracts\Laravel\Ownership\Ownable
* @return \Cog\Contracts\Ownership\Ownable
*/
public function withoutDefaultOwner();

Expand All @@ -74,22 +74,22 @@ public function isDefaultOwnerOnCreateRequired();
/**
* Resolve entity default owner.
*
* @return null|\Cog\Contracts\Laravel\Ownership\CanBeOwner
* @return null|\Cog\Contracts\Ownership\CanBeOwner
*/
public function resolveDefaultOwner();

/**
* Changes owner of the model.
*
* @param \Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @return \Cog\Contracts\Laravel\Ownership\Ownable
* @param \Cog\Contracts\Ownership\CanBeOwner $owner
* @return \Cog\Contracts\Ownership\Ownable
*/
public function changeOwnerTo(CanBeOwnerContract $owner);

/**
* Abandons owner of the model.
*
* @return \Cog\Contracts\Laravel\Ownership\Ownable
* @return \Cog\Contracts\Ownership\Ownable
*/
public function abandonOwner();

Expand All @@ -103,15 +103,15 @@ public function hasOwner();
/**
* Checks if model owned by given owner.
*
* @param \Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @param \Cog\Contracts\Ownership\CanBeOwner $owner
* @return bool
*/
public function isOwnedBy(CanBeOwnerContract $owner);

/**
* Checks if model not owned by given owner.
*
* @param \Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @param \Cog\Contracts\Ownership\CanBeOwner $owner
* @return bool
*/
public function isNotOwnedBy(CanBeOwnerContract $owner);
Expand All @@ -120,7 +120,7 @@ public function isNotOwnedBy(CanBeOwnerContract $owner);
* Scope a query to only include models by owner.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @param \Cog\Contracts\Ownership\CanBeOwner $owner
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeWhereOwnedBy(Builder $query, CanBeOwnerContract $owner);
Expand All @@ -129,7 +129,7 @@ public function scopeWhereOwnedBy(Builder $query, CanBeOwnerContract $owner);
* Scope a query to only include models by owner.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Cog\Contracts\Laravel\Ownership\CanBeOwner $owner
* @param \Cog\Contracts\Ownership\CanBeOwner $owner
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeWhereNotOwnedBy(Builder $query, CanBeOwnerContract $owner);
Expand Down
4 changes: 2 additions & 2 deletions src/Observers/OwnableObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Cog\Laravel\Ownership\Observers;

use Cog\Contracts\Laravel\Ownership\Ownable as OwnableContract;
use Cog\Contracts\Ownership\Ownable as OwnableContract;

/**
* Class OwnableObserver.
Expand All @@ -23,7 +23,7 @@ class OwnableObserver
/**
* Handle the deleted event for the model.
*
* @param \Cog\Contracts\Laravel\Ownership\Ownable $ownable
* @param \Cog\Contracts\Ownership\Ownable $ownable
* @return void
*/
public function creating(OwnableContract $ownable)
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/OwnershipServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Support\ServiceProvider;
use Cog\Contracts\Laravel\Ownership\CanBeOwner as CanBeOwnerContract;
use Cog\Contracts\Ownership\CanBeOwner as CanBeOwnerContract;

/**
* Class OwnershipServiceProvider.
Expand Down
Loading

0 comments on commit ab1e142

Please sign in to comment.