本文整理匯總了PHP中League\Fractal\Resource\Collection::setData方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::setData方法的具體用法?PHP Collection::setData怎麽用?PHP Collection::setData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類League\Fractal\Resource\Collection
的用法示例。
在下文中一共展示了Collection::setData方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
*/
public function __invoke(array $input)
{
//Authorize user to be able to view shifts
$this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'view', 'shifts');
//Validate input
$inputValidator = v::key('startDateTime', v::stringType())->key('endDateTime', v::stringType());
$inputValidator->assert($input);
//Retrieve shifts between in time period
$shifts = $this->shiftRepository->getShiftsBetween(Carbon::parse($input['startDateTime']), Carbon::parse($input['endDateTime']));
$this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->collection)->toArray());
}
示例2: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
* @throws UserNotAuthorized
*/
public function __invoke(array $input)
{
//Make sure requested user matches auth user
//todo: figure out if managers can access all employees' hours
if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) {
throw new UserNotAuthorized();
}
//Get hours and transform to more readable collection
$employee = $this->userRepository->getOneByIdOrFail($input['id']);
$hours = $this->shiftRepository->getHoursCountGroupedByWeekFor($employee);
$this->collection->setData($hours)->setTransformer($this->hoursTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->collection)->toArray());
}
示例3: __invoke
/**
* @param array $input
* @return PayloadInterface
* @throws UserNotAuthorized
*/
public function __invoke(array $input)
{
//Don't allow employees to view other employee's shifts
//todo: figure out if managers can access all employees' shifts
if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) {
throw new UserNotAuthorized();
}
//Validate input
$inputValidator = v::key('id', v::intVal());
$inputValidator->assert($input);
//Get shifts and transform
$employee = $this->userRepository->getOneByIdOrFail($input['id']);
$shifts = $this->shiftRepository->getByEmployee($employee);
$this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
$include = array_key_exists('include', $input) ? $input['include'] : '';
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes($include)->createData($this->collection)->toArray());
}
示例4: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
* @throws UserNotAuthorized
*/
public function __invoke(array $input)
{
//Check that the auth user matches the requested user
//todo: determine if manager's should have access
if ($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('id') != $input['id']) {
throw new UserNotAuthorized();
}
$employee = $this->userRepository->getOneByIdOrFail($input['id']);
$shifts = $this->shiftRepository->getByEmployee($employee);
//Loop over shifts getting employees that work at the same time for each shift
foreach ($shifts as $shift) {
$coworkers = $this->userRepository->getEmployeesWorkingBetween($shift->getStartTime(), $shift->getEndTime(), [$employee]);
$shift->setCoworkers($coworkers);
}
$this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes('coworkers')->createData($this->collection)->toArray());
}