You are here

class ListenerPageController in Evercurrent 8

Same name and namespace in other branches
  1. 8.2 src/Controller/ListenerPageController.php \Drupal\evercurrent\Controller\ListenerPageController

Creates a callback for listening to the server.

Hierarchy

Expanded class hierarchy of ListenerPageController

File

src/Controller/ListenerPageController.php, line 19
Contains \Drupal\example\Controller\ExamleController.

Namespace

Drupal\evercurrent\Controller
View source
class ListenerPageController {

  /**
   * Check for page access. Only if listening is set to true.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   * @return \Drupal\Core\Access\AccessResult
   */
  public function access(AccountInterface $account) {
    $config = \Drupal::config('evercurrent.admin_config');
    $listen = $config
      ->get('listen');
    return $listen ? AccessResult::allowed() : AccessResult::forbidden();
  }
  public function content() {
    $received = json_decode($_POST['data'], TRUE);
    $updateHelper = \Drupal::service('evercurrent.update_helper');

    // No key equals error response.
    if (!isset($received['key'])) {
      $severity = RMH_STATUS_ERROR;
      $message = 'Received an invalid request in listening mode.';
      $updateHelper
        ->writeStatus($severity, $message, $output = FALSE);
      return $this
        ->jsonResponse('Malformed data.', 'error');
    }
    $key = $received['key'];
    $result = $updateHelper
      ->testUpdate($key);
    if ($result == TRUE) {
      $this
        ->jsonResponse('Success.', 'status');
    }
    else {
      $this
        ->jsonResponse('Unknown error.', 'error');
    }
    return $this
      ->jsonResponse('Can you see this message?', 'error');
  }
  public function jsonResponse($message, $type) {
    return new JsonResponse([
      'data' => [
        'message' => $message,
        'type' => $type,
      ],
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ListenerPageController::access public function Check for page access. Only if listening is set to true.
ListenerPageController::content public function
ListenerPageController::jsonResponse public function