1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-22 18:28:47 +02:00
phorge-phorge/src/applications/tokens/conduit/TokenGiveConduitAPIMethod.php

45 lines
1,013 B
PHP
Raw Normal View History

<?php
final class TokenGiveConduitAPIMethod extends TokenConduitAPIMethod {
public function getAPIMethodName() {
return 'token.give';
}
public function getMethodDescription() {
return pht('Give or change a token.');
}
public function defineParamTypes() {
return array(
'tokenPHID' => 'phid|null',
'objectPHID' => 'phid',
);
}
public function defineErrorTypes() {
return array();
}
public function defineReturnType() {
return 'void';
}
public function execute(ConduitAPIRequest $request) {
$content_source = PhabricatorContentSource::newFromConduitRequest($request);
$editor = id(new PhabricatorTokenGivenEditor())
->setActor($request->getUser())
->setContentSource($content_source);
if ($request->getValue('tokenPHID')) {
$editor->addToken(
$request->getValue('objectPHID'),
$request->getValue('tokenPHID'));
} else {
$editor->deleteToken($request->getValue('objectPHID'));
}
}
}