Skip to content

Commit

Permalink
Add ResolvedContactIdOptionalTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Tubach committed Aug 7, 2023
1 parent 0e4e5ce commit f71a65e
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Civi/RemoteTools/Api4/Action/AbstractRemoteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
use Civi\Api4\Generic\AbstractAction;
use Civi\RemoteTools\Api4\Action\Traits\ActionHandlerRunTrait;
use Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait;

abstract class AbstractRemoteAction extends AbstractAction implements RemoteActionInterface {

use ActionHandlerRunTrait;

use RemoteContactIdParameterOptionalTrait;

use ResolvedContactIdTrait;
use ResolvedContactIdOptionalTrait;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Civi\Api4\Generic\BasicGetFieldsAction;
use Civi\RemoteTools\Api4\Action\Traits\ActionHandlerRunTrait;
use Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait;

/**
* @todo: Filter information not relevant for remote API?
Expand All @@ -33,6 +33,6 @@ abstract class AbstractRemoteGetFieldsAction extends BasicGetFieldsAction {

use RemoteContactIdParameterOptionalTrait;

use ResolvedContactIdTrait;
use ResolvedContactIdOptionalTrait;

}
2 changes: 1 addition & 1 deletion Civi/RemoteTools/Api4/Action/RemoteActionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @see \Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterTrait
* @see \Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait
* @see \Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait
* @see \Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait
*/
interface RemoteActionInterface {

Expand Down
4 changes: 2 additions & 2 deletions Civi/RemoteTools/Api4/Action/RemoteCheckAccessAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Civi\RemoteTools\Api4\Action\Traits\ActionHandlerRunTrait;
use Civi\RemoteTools\Api4\Action\Traits\ProfileParameterTrait;
use Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait;
use Civi\RemoteTools\Exception\ActionHandlerNotFoundException;

final class RemoteCheckAccessAction extends CheckAccessAction implements ProfileAwareRemoteActionInterface {
Expand All @@ -35,7 +35,7 @@ final class RemoteCheckAccessAction extends CheckAccessAction implements Profile

use RemoteContactIdParameterOptionalTrait;

use ResolvedContactIdTrait;
use ResolvedContactIdOptionalTrait;

public function _run(Result $result): void {
parent::_run($result);
Expand Down
4 changes: 2 additions & 2 deletions Civi/RemoteTools/Api4/Action/RemoteDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Civi\RemoteTools\Api4\Action\Traits\ActionHandlerRunTrait;
use Civi\RemoteTools\Api4\Action\Traits\ProfileParameterTrait;
use Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait;

class RemoteDeleteAction extends AbstractQueryAction implements ProfileAwareRemoteActionInterface {

Expand All @@ -33,7 +33,7 @@ class RemoteDeleteAction extends AbstractQueryAction implements ProfileAwareRemo

use RemoteContactIdParameterOptionalTrait;

use ResolvedContactIdTrait;
use ResolvedContactIdOptionalTrait;

/**
* Make where parameter required.
Expand Down
4 changes: 2 additions & 2 deletions Civi/RemoteTools/Api4/Action/RemoteGetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Civi\RemoteTools\Api4\Action\Traits\ActionHandlerRunTrait;
use Civi\RemoteTools\Api4\Action\Traits\ProfileParameterTrait;
use Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait;
use Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait;

class RemoteGetAction extends AbstractGetAction implements ProfileAwareRemoteActionInterface {

Expand All @@ -33,6 +33,6 @@ class RemoteGetAction extends AbstractGetAction implements ProfileAwareRemoteAct

use RemoteContactIdParameterOptionalTrait;

use ResolvedContactIdTrait;
use ResolvedContactIdOptionalTrait;

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
/**
* @method string|null getRemoteContactId()
* @method $this setRemoteContactId(string $remoteContactId)
*
* @see \Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdOptionalTrait
*/
trait RemoteContactIdParameterOptionalTrait {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
/**
* @method string getRemoteContactId()
* @method $this setRemoteContactId(string $remoteContactId)
*
* @see \Civi\RemoteTools\Api4\Action\Traits\ResolvedContactIdTrait
*/
trait RemoteContactIdParameterTrait {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
* Copyright (C) 2023 SYSTOPIA GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types = 1);

namespace Civi\RemoteTools\Api4\Action\Traits;

use Civi\RemoteTools\RequestContext\RequestContextInterface;

/**
* @see \Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterOptionalTrait
*/
trait ResolvedContactIdOptionalTrait {

protected ?RequestContextInterface $_requestContext = NULL;

public function getResolvedContactId(): ?int {
// @phpstan-ignore-next-line
$this->_requestContext ??= \Civi::service(RequestContextInterface::class);

// @phpstan-ignore-next-line
return $this->_requestContext->getResolvedContactId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@

use Civi\RemoteTools\RequestContext\RequestContextInterface;

/**
* @see \Civi\RemoteTools\Api4\Action\Traits\RemoteContactIdParameterTrait
*/
trait ResolvedContactIdTrait {

protected ?RequestContextInterface $_requestContext = NULL;

public function getResolvedContactId(): ?int {
public function getResolvedContactId(): int {
// @phpstan-ignore-next-line
$this->_requestContext ??= \Civi::service(RequestContextInterface::class);

Expand Down

0 comments on commit f71a65e

Please sign in to comment.