/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface */ public function __invoke(array $input) { //Check that user is authorized to edit this resource $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'), 'edit', 'shifts'); //Validate input $inputValidator = v::key('break', v::floatVal())->key('start_time', v::stringType())->key('end_time', v::stringType())->key('id', v::intVal()); $inputValidator->assert($input); //Update shift data $shift = $this->commandBus->handle(new UpdateShiftCommand($input['id'], $input['break'], $input['start_time'], $input['end_time'])); $shiftItem = new Item($shift, new ShiftTransformer()); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($shiftItem)->toArray()); }
public function __construct(array $options) { $options = ['baseUri' => Arr::get($options, 'baseUri', $this->baseUri), 'timeout' => Arr::get($options, 'timeout', $this->timeout), 'proxy' => Arr::get($options, 'proxy', $this->proxy), 'auth' => Arr::get($options, 'auth', $this->auth), 'logger' => Arr::get($options, 'logger')]; try { V::arrayVal()->key('baseUri', V::url()->notEmpty())->key('timeout', V::floatVal()->min(0))->key('proxy', V::optional(V::url()))->key('auth', V::arrayVal()->key('user', V::stringType())->key('pass', V::stringType()))->key('logger', V::instance('\\Psr\\Log\\LoggerInterface'))->assert($options); } catch (\InvalidArgumentException $e) { $errors = array_filter($e->findMessages(['baseUri' => 'Required correct baseUri', 'timeout' => 'Required correct timeout', 'proxy' => 'Required correct proxy', 'auth' => 'Required correct authuser', 'logger' => 'Required a logger instance of psr\\log'])); $errmsg = array_shift($errors); throw new Exception($errmsg); } $this->baseUri = $options['baseUri']; $this->timeout = $options['timeout']; $this->proxy = $options['proxy']; $this->auth = $options['auth']; $this->logger = $options['logger']; }
/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface */ public function __invoke(array $input) { //Ensure that the use has permission to create shifts $user = $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'); $this->authorizeUser($user, 'create', 'shifts'); //If no manager_id is specified in request, default to user creating shift if (!array_key_exists('manager_id', $input)) { $input['manager_id'] = $user->getId(); } //Validate input $inputValidator = v::key('break', v::floatVal())->key('start_time', v::date())->key('end_time', v::date()->min($input['start_time']))->key('manager_id', v::intVal()); $inputValidator->assert($input); //Execute command to create shift $shift = $this->commandBus->handle(new CreateShift($input['manager_id'], $input['employee_id'], $input['break'], $input['start_time'], $input['end_time'])); $this->item->setData($shift)->setTransformer($this->shiftTransformer); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->item)->toArray()); }
public function value($fltValue) { if (!Validator::floatVal()->min(0, true)->validate($fltValue)) { $this->objLogger->addError('Value must be a floating point number'); throw new SMSMessageException('Value must be a floating point number'); } $this->fltValue = (double) $fltValue; $this->objLogger->addDebug('Value has been set to ' . $fltValue); return $this; }