本文整理汇总了PHP中League\Fractal\Manager::createData方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::createData方法的具体用法?PHP Manager::createData怎么用?PHP Manager::createData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Manager
的用法示例。
在下文中一共展示了Manager::createData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: respondCollection
public function respondCollection($collection, $callback, $resource_key, $meta = [])
{
$resource = new Collection($collection, $callback, $resource_key);
$data = $this->fractal->createData($resource)->toArray();
$response = array_merge($data, $meta);
return $this->respond($response);
}
示例2: cursorCollection
/**
* @param $data
* @param \League\Fractal\TransformerAbstract $transformer
* @param \League\Fractal\Pagination\Cursor|int $cursor
* @param string $resourceKey
* @return \League\Fractal\Scope
*/
public function cursorCollection($data, $transformer = null, $cursor = null, $resourceKey = null)
{
$transformer = $this->getTransformer($transformer);
$resource = new Collection($data, $transformer, $resourceKey);
$resource->setCursor($this->makeCursor($cursor, $data));
return $this->manager->createData($resource);
}
示例3: __invoke
/**
* @param array $input
* @return PayloadInterface
*/
public function __invoke(array $input)
{
$employee = $this->userRepository->getOneById($input['id']);
$shifts = $this->shiftRepository->getByEmployee($employee);
$shiftsCollection = new Collection($shifts, new ShiftTransformer());
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($shiftsCollection)->toArray());
}
示例4: convertResource
/**
* @param mixed $resource
* @param null|string|array $includes
* @return array
*/
private function convertResource($resource, $includes = null)
{
if ($includes !== null) {
$this->manager->parseIncludes($includes);
}
return $this->manager->createData($resource)->toArray();
}
示例5: lessons
/**
* Returns only the lessons from the
* current feed from Laracasts in JSON.
*/
public function lessons()
{
$lessons = $this->lissandra->getLessons();
$resource = new Collection($lessons, new LessonTransformer($lessons));
$data = $this->fractal->createData($resource)->toArray()['data'];
return $this->respondWithCORS($data);
}
示例6: createCollectionResponse
protected function createCollectionResponse($collection, $transformer, $resourceKey, $meta = null)
{
$resource = new Collection($collection, $transformer, $resourceKey);
$data = $this->fractal->createData($resource)->toArray();
$response = array_merge($data, $meta ? $meta : []);
return $this->createResponse($response);
}
示例7: respondWithCollection
/**
* @param $collection
* @param $callback
* @param array|string|null $includes
*
* @return \Illuminate\Http\JsonResponse
*/
protected function respondWithCollection($collection, $callback, $includes = null)
{
$resource = new Collection($collection, $callback);
$this->addParseIncludes($includes);
$rootScope = $this->fractal->createData($resource);
return $this->respondWithArray($rootScope->toArray());
}
示例8: paginatedCollection
public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null)
{
$paginator->appends(\Request::query());
$resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->manager->createData($resource)->toArray();
}
示例9: respondWithPaginate
protected function respondWithPaginate($paginator, $callback)
{
$collection = $paginator->getCollection();
$resource = new Collection($collection, $callback);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
$rootScope = $this->fractal->createData($resource);
return $this->respondWithArray($rootScope->toArray());
}
示例10: transform
public function transform(Recipe $recipe)
{
$fractal = new Manager();
$ingredients = $recipe->ingredients;
$categories = $recipe->categories;
$instructions = $recipe->instructions;
return ['id' => $recipe->id, 'type' => 'recipe', 'attributes' => ['title' => $recipe->title, 'preparationTime' => $recipe->preparationTime, 'cookingTime' => $recipe->cookingTime], 'relationships' => ['categories' => $fractal->createData($this->collection($categories, new CategoryTransformer()))->toArray(), 'ingredients' => $fractal->createData($this->collection($ingredients, new IngredientTransformer()))->toArray(), 'instructions' => $fractal->createData($this->collection($instructions, new InstructionTransformer()))->toArray()]];
}
示例11: present
/**
* @param $data
*
* @return array
*/
public function present($data)
{
if ($data instanceof EloquentCollection) {
$this->resource = $this->transformCollection($data);
} elseif ($data instanceof AbstractPaginator) {
$this->resource = $this->transformPaginator($data);
} else {
$this->resource = $this->transformItem($data);
}
return $this->fractal->createData($this->resource)->toArray();
}
示例12: find
/**
* @param Request $request
* @param array $params
* @return JsonResponse\Ok
*/
public function find(Request $request, array $params)
{
$post = $this->getPost($params["id"]);
// if the post is empty, return a 404
if (empty($post)) {
return new JsonResponse\NoContent();
}
//
$post = new Item($this->getPost($params["id"]), new PostTransformer(), "posts");
return new JsonResponse\Ok($this->fractal->createData($post)->toArray());
}
示例13: handle
public function handle($request, Closure $next)
{
$response = $next($request);
if (!isset($response->original)) {
return $response;
}
if (!is_callable($response)) {
return $response;
}
$response->setContent($this->fractal->createData($response())->toJson());
return $response;
}
示例14: __invoke
/**
* 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());
}
示例15: make
/**
* Create Ember Data friendly response
*
* @param $data
* @param $model
* @param array $includes
* @return array
* @throws Exceptions\SerializerTranslatorException
*/
public function make($data, $model, $includes = [])
{
if (!$data || empty($data)) {
return [];
}
$transformer = app($this->translator->toTranslatorHandler($model));
$resource = $this->createResource($data, $transformer, $model);
if (!empty($includes)) {
$this->manager->parseIncludes($includes);
}
return $this->manager->createData($resource)->toArray();
}