Restructured StandardMethod Namespaces
This commit is contained in:
parent
d6e397247a
commit
1e10e761db
38 changed files with 72 additions and 82 deletions
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\StandardException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\ContactManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\PeerAddress;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
class AddressBookDeleteContact extends Method
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if(!$rpcRequest->containsParameter('peer'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required \'peer\' parameter');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new StandardException('Invalid peer address', StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Check if the contact already exists
|
||||
$peer = $request->getPeer();
|
||||
if(!ContactManager::isContact($peer, $address))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
|
||||
}
|
||||
|
||||
// Create the contact
|
||||
ContactManager::deleteContact($peer, $address);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException('Failed to remove contact', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Return success
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue