Esempio n. 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]);
 }
Esempio n. 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]);
 }
Esempio n. 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]);
 }
Esempio n. 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]);
 }
Esempio n. 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;
 }
Esempio n. 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);
 }
Esempio n. 7
0
 /**
  * @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]);
 }
Esempio n. 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]);
 }
Esempio n. 9
0
 /**
  * @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]);
 }
Esempio n. 10
0
 /**
  * @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]);
 }
Esempio n. 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);
 }
Esempio n. 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());
 }
Esempio n. 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;
 }
Esempio n. 15
0
 /**
  * @inheritDoc
  */
 public function body(PayloadInterface $payload)
 {
     return json_encode($payload->getOutput(), $this->options());
 }
Esempio n. 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();
 }
Esempio n. 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']);
 }
Esempio n. 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);
 }
Esempio n. 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']);
 }
Esempio n. 22
0
 /**
  * @param Template $template
  * @param PayloadInterface $payload
  * @return string
  */
 protected function render(Template $template, PayloadInterface $payload)
 {
     return $template->render($payload->getOutput());
 }