1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Policies/GenericEntityPolicy.php
2016-10-27 11:57:51 +03:00

76 lines
2.0 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) {
$entityName = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$entityName}Policy", 'create')) {
return call_user_func(["App\\Policies\\{$entityName}Policy", 'create'], $user, $itemType);
}
return false;
}
/**
* @param User $user
* @param $itemType
* @return bool|mixed
*/
public static function view(User $user, $itemType) {
$entityName = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$entityName}Policy", 'view')) {
return call_user_func(["App\\Policies\\{$entityName}Policy", 'view'], $user, $itemType);
}
return false;
}
}