for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Copyright (c) Flipbox Digital Limited
* @license https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
* @link https://github.com/flipboxfactory/craft-ember/
*/
namespace flipbox\craft\ember\actions;
use Craft;
* @author Flipbox Factory <[email protected]>
* @since 2.0.0
trait ManageTrait
{
use CheckAccessTrait;
* HTTP success response code
*
* @var int|null
public $statusCodeSuccess;
* HTTP fail response code
public $statusCodeFail;
* @param mixed $data
* @return bool
abstract protected function performAction($data): bool;
* @param $data
* @return mixed
* @throws \yii\web\HttpException
protected function runInternal($data)
// Check access
if (($access = $this->checkAccess($data)) !== true) {
return $access;
}
if (!$this->performAction($data)) {
return $this->handleFailResponse($data);
return $this->handleSuccessResponse($data);
* @return int
protected function statusCodeSuccess(): int
return $this->statusCodeSuccess ?: 200;
protected function statusCodeFail(): int
return $this->statusCodeFail ?: 400;
protected function handleSuccessResponse($data)
// Success status code
Craft::$app->getResponse()->setStatusCode($this->statusCodeSuccess());
return $data;
protected function handleFailResponse($data)
Craft::$app->getResponse()->setStatusCode($this->statusCodeFail());