public static function checkPermission($userId = false)
    {
        $user = \Phramework\Phramework::getUser();

        //If user is not authenticated throw an \Exception
        if (!$user) {
            throw new \Phramework\Exceptions\UnauthorizedException();
        }

        //Check if speficied user is same as current user
        if ($userId !== false && $user->id != $userId) {
            throw new PermissionException(
                'Insufficient permissions'
            );
        }

        return $user;
    }
public static function checkPermission($userId = false)
    {
        $user = \Phramework\Phramework::getUser();

        //If user is not authenticated throw an \Exception
        if (!$user) {
            throw new \Phramework\Exceptions\UnauthorizedException();
        }

        //Check if speficied user is same as current user
        if ($userId !== false && $user->id != $userId) {
            throw new PermissionException(
                'Insufficient permissions'
            );
        }

        return $user;
    }
public static function checkPermission ( $ userId = false ) { $ user = \ Phramework \ Phramework :: getUser ( ) ; //If user is not authenticated throw an \Exception if ( ! $ user ) { throw new \ Phramework \ Exceptions \ UnauthorizedException ( ) ; } //Check if speficied user is same as current user if ( $ userId !== false && $ user -> id != $ userId ) { throw new PermissionException ( 'Insufficient permissions' ) ; } return $ user ; }
Check if current request is authenticated

Optionaly it checks the authenticated user has a specific user_id
@param integer $userId *[Optional]* Check if current user has the same id with $userId
@return object Returns the user object
@throws \Phramework\Exceptions\PermissionException
@throws \Phramework\Exceptions\UnauthorizedException
Check if current request is authenticated