Example #1
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     /* @var Token $token */
     $token = $input[AuthHandler::TOKEN_ATTRIBUTE];
     $user = $this->user_repository->getFromInputToken($input);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['token' => $token->getToken(), 'user' => $user]);
 }
Example #2
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->user_repository->getFromInputToken($input);
     if ($user->role !== 'manager') {
         throw new AuthException('Only managers have access to do that');
     }
     if (empty($input['id'])) {
         throw new \DomainException('You must supply the shift id');
     }
     if (!empty($input['start_time'])) {
         $input['start_time'] = date('Y-m-d G:i:s', strtotime($input['start_time']));
         if ($input['start_time'] === false) {
             throw new \DomainException("Could not parse 'start time'");
         }
     }
     if (!empty($input['end_time'])) {
         $input['end_time'] = date('Y-m-d G:i:s', strtotime($input['end_time']));
         if ($input['end_time'] === false) {
             throw new \DomainException("Could not parse 'end time'");
         }
     }
     // only grab the necessary fields
     $values = array_intersect_key($input, array_flip(['id', 'manager_id', 'employee_id', 'break', 'start_time', 'end_time']));
     $shift = $this->shift_repository->update($input['id'], $values);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$shift]);
 }
Example #3
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     if (empty($input['text'])) {
         return $this->payload->withStatus(PayloadInterface::INVALID)->withOutput(['error' => 'Missing `text` field on input']);
     }
     $wordCounts = $this->wordCount->countWords($input['text']);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['wordcounts' => $wordCounts]);
 }
Example #4
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $name = 'world';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     return $this->payload->withStatus(PayloadInterface::STATUS_OK)->withOutput(['hello' => $name]);
 }
Example #5
0
 /**
  * @inheritDoc
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, PayloadInterface $payload)
 {
     $location = $payload->getSetting('redirect');
     if (!empty($location)) {
         $response = $response->withHeader('Location', $location);
     }
     return $response;
 }
Example #6
0
 function __invoke(array $input)
 {
     if (!empty($input['id'])) {
         $users = $this->user_repository->find($input['id']);
         $users = [$users];
     } else {
         $users = $this->user_repository->findBy([]);
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($users);
 }
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         throw new AuthException('This action is not available to employees.');
     } else {
         $employee = User::load($input['employee'])->jsonSerialize();
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["employee", $employee]);
 }
Example #8
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         $shifts = $this->getEmployeeShifts($token->getMetadata('id'));
     } else {
         $shifts = $this->getManagerShifts($input);
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["shifts", $shifts]);
 }
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         throw new AuthException('This action is not available to employees.');
     } else {
         $shift = $this->updateShift($input);
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["shift", $shift]);
 }
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         $coworkers = $this->getCoworkers($input['shift']);
     } else {
         throw new AuthException('This action is not available to managers.');
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["coworkers", $coworkers]);
 }
Example #11
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->user_repository->getFromInputToken($input);
     if ($user->role === 'employee') {
         $shifts = $this->shift_repository->getShiftsForEmployee($user->id, $input);
     } elseif ($user->role === 'manager') {
         $shifts = $this->shift_repository->getShiftsForManager($input);
     } else {
         throw new \DomainException('Unknown user role');
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($shifts);
 }
Example #12
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $return_obj = $this->_validateUserRequest($input);
     if ($return_obj) {
         return $return_obj;
     }
     if ($this->_user_role != self::ROLE_MANAGER) {
         return $this->_returnAuthError($this->payload);
     }
     $id = $input['id'];
     $user = new \Equip\Project\DAL\User($id);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($user->toArray());
 }
Example #13
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $token = $input['spark/auth:token'];
     $role = $token->getMetadata('role');
     $isEmployee = strcmp($role, 'employee') === 0;
     if ($isEmployee) {
         $user_id = $token->getMetadata('id');
         $summary = $this->getSummary($user_id);
     } else {
         throw new AuthException('This action is not available to managers.');
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["summary", $summary]);
 }
 /**
  * Get the response status from the payload.
  *
  * @param PayloadInterface $payload
  *
  * @return integer
  */
 public function status(PayloadInterface $payload)
 {
     $status = $payload->getStatus();
     if ($status >= PayloadInterface::OK && $status < PayloadInterface::ERROR) {
         return 200;
     }
     if ($status >= PayloadInterface::ERROR && $status < PayloadInterface::INVALID) {
         return 500;
     }
     if ($status >= PayloadInterface::INVALID && $status < PayloadInterface::UNKNOWN) {
         return 400;
     }
     return 520;
 }
 /**
  * @inheritDoc
  */
 public function body(PayloadInterface $payload)
 {
     return json_encode($payload->getOutput(), $this->options());
 }
Example #16
0
 /**
  * @param PayloadInterface $payload
  *
  * @return string
  */
 private function render(PayloadInterface $payload)
 {
     $template = $payload->getSetting('template');
     $output = $payload->getOutput();
     return $this->engine->render($template, $output);
 }
 /**
  * Determine if the payload has usable output
  *
  * @param PayloadInterface $payload
  *
  * @return boolean
  */
 protected function hasOutput(PayloadInterface $payload)
 {
     return (bool) $payload->getOutput();
 }
Example #18
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $composer = __DIR__ . '/../../composer.json';
     $composer = json_decode(file_get_contents($composer), true);
     return $this->payload->withStatus(PayloadInterface::STATUS_OK)->withOutput(['appName' => $composer['name'], 'equipVersion' => $composer['require']['equip/framework'], 'hello' => '/hello/:name']);
 }
Example #19
0
 /**
  * Get the response with the status code from the payload.
  *
  * @param ResponseInterface $response
  * @param PayloadInterface $payload
  *
  * @return ResponseInterface
  */
 private function status(ResponseInterface $response, PayloadInterface $payload)
 {
     $status = $payload->getStatus();
     $code = $this->http_status->getStatusCode($status);
     return $response->withStatus($code);
 }
Example #20
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  *
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->user_repository->getFromInputToken($input);
     $data = $this->shift_repository->getEmployeeShiftSummary($user->id, !empty($input['year']) ? $input['year'] : null);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($data);
 }
 /**
  * Check if the payload contains a redirect
  *
  * @param PayloadInterface $payload
  *
  * @return boolean
  */
 private function hasRedirect(PayloadInterface $payload)
 {
     $messages = $payload->getMessages();
     return !empty($messages['redirect']);
 }
 /**
  * @param Template $template
  * @param PayloadInterface $payload
  * @return string
  */
 protected function render(Template $template, PayloadInterface $payload)
 {
     return $template->render($payload->getOutput());
 }