1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/app/Policies/GenericEntityPolicy.php
Holger Lösken 0fbda85a59 Code Refactoring
- Removed unused uses
- Type hinting for method parameters
- Removed commented code
- Introduced comments for classes and methods
- Short array syntax
2016-07-03 16:19:22 +00:00

60 lines
1.6 KiB
PHP

<?php
namespace App\Policies;
use App\Models\User;
use Utils;
use Illuminate\Auth\Access\HandlesAuthorization;
/**
* Class GenericEntityPolicy
*/
class GenericEntityPolicy
{
use HandlesAuthorization;
/**
* @param User $user
* @param $itemType
* @param $ownerUserId
* @return bool|mixed
*/
public static function editByOwner(User $user, $itemType, $ownerUserId) {
$itemType = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$itemType}Policy", 'editByOwner')) {
return call_user_func(["App\\Policies\\{$itemType}Policy", 'editByOwner'], $user, $ownerUserId);
}
return false;
}
/**
* @param User $user
* @param $itemType
* @param $ownerUserId
* @return bool|mixed
*/
public static function viewByOwner(User $user, $itemType, $ownerUserId) {
$itemType = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$itemType}Policy", 'viewByOwner')) {
return call_user_func(["App\\Policies\\{$itemType}Policy", 'viewByOwner'], $user, $ownerUserId);
}
return false;
}
/**
* @param User $user
* @param $itemType
* @return bool|mixed
*/
public static function create(User $user, $itemType) {
$itemType = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$itemType}Policy", 'create')) {
return call_user_func(["App\\Policies\\{$itemType}Policy", 'create'], $user);
}
return false;
}
}