/** * @param $projectId * @param Manager $fractal * @param ProjectTransformer $projectTransformer * @return \Illuminate\Http\JsonResponse */ public function show($projectId, Manager $fractal, ProjectTransformer $projectTransformer) { $project = $this->project->findOrFail($projectId); $item = new Item($project, $projectTransformer); $data = $fractal->createData($item)->toArray(); return $this->respond($data); }
/** * @VP: * I'm trying to pass a second parameter to my transformer but don't know how. * @param $resource */ function transform($resource) { $manager = new Manager(); $manager->setSerializer(new DataArraySerializer()); $manager->parseIncludes(request()->get('includes', [])); return $manager->createData($resource)->toArray(); }
/** * Register the service provider. * * @return void */ public function register() { if ($this->isLumen()) { require_once 'fallback.php'; } $this->registerRequiredProviders(); $this->app->bind('datatables.html', function () { return $this->app->make(Html\Builder::class); }); $this->app->singleton('datatables.fractal', function () { $fractal = new Manager(); $config = $this->app['config']; $request = $this->app['request']; $includesKey = $config->get('datatables.fractal.includes', 'include'); if ($request->get($includesKey)) { $fractal->parseIncludes($request->get($includesKey)); } $serializer = $config->get('datatables.fractal.serializer', DataArraySerializer::class); $fractal->setSerializer(new $serializer()); return $fractal; }); $this->app->singleton('datatables', function () { return new Datatables($this->app->make(Request::class)); }); $this->registerAliases(); }
/** * Include Content * * @param BaseElementModel $element Element * * @return League\Fractal\Resource\Item Content */ public function includeContent(BaseElementModel $element) { $content = []; if ($this->depth > \Craft\craft()->config->get('contentRecursionLimit', 'httpMessagesRestMiddleware') - 1) { return; } foreach ($element->getFieldLayout()->getFields() as $fieldLayoutField) { $field = $fieldLayoutField->getField(); $value = $element->getFieldValue($field->handle); if (get_class($field->getFieldType()) === 'Craft\\RichTextFieldType') { $value = $value->getRawContent(); } if (is_object($value) && get_class($value) === 'Craft\\ElementCriteriaModel') { $class = get_class($value->getElementType()); $element_type = $this->element_service->getElementTypeByClass($class); $manager = new Manager(); $manager->parseIncludes(array_merge(['content'], explode(',', \Craft\craft()->request->getParam('include')))); $manager->setSerializer(new ArraySerializer()); $transformer = $this->config_service->getTransformer($element_type); $value = $value->find(); $body = new Collection($value, new $transformer($this->depth + 1)); $value = $manager->createData($body)->toArray(); $value = !empty($value['data']) ? $value['data'] : null; } $content[$field->handle] = $value; } if ($content) { return $this->item($content, new ContentTransformer($this->depth), 'content'); } }
public function byLoan($id, Manager $fractal, LoancropTransformer $loancropTransformer) { $loancrops = Loancrop::where('loan_id', $id)->get(); $collection = new Collection($loancrops, $loancropTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respond($data); }
/** * 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); }
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); }
/** * Check if the object exists * * @param Request $request Request object * @param string $id Unique identifier for the object * @return ResponseInterface Response for object */ public function head(Request $request, Fractal $fractal) { $this->beforeRequest($request, func_get_args()); $id = $this->parseObjectId($request); $model = $this->loadAuthorizeObject($id, 'read'); return $this->respondWithEmptyItem($fractal->createData($this->getFractalItem($model))); }
public function response($data, $totalCount = false, $query = false, $statusCode = 200) { if ($this->transformer) { $fractal = new Manager(); if ($totalCount === false) { $resource = new Item($data, $this->transformer); } else { $resource = new Collection($data, $this->transformer); } $response = $fractal->createData($resource)->toArray(); } else { $response = ['data' => $data]; } if ($totalCount !== false) { $response['totalCount'] = (int) $totalCount; } if ($query !== false) { $response['search'] = $query; } $response = json_encode($response, JSON_UNESCAPED_UNICODE); if ($response === false) { InternalServerError500::throwException("Response couldn't encoded as JSON"); } $this->app->response->status($statusCode); $this->app->response->body($response); }
/** * @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); }
public function __construct(Manager $fractal) { $this->fractal = $fractal; if (Input::get('include')) { $fractal->parseIncludes(Input::get('include')); } }
/** * @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(); }
public function index(Request $request, Manager $fractal) { if ($requestedEmbeds = $request->get('include')) { $fractal->parseIncludes($requestedEmbeds); } return $this->response->item($this->user, UserTransformer::class); }
public function index(Manager $fractal, SupportTransformer $transformer, $customerID) { $ac = ArticleCategory::where('id', '>=', 64)->take(10)->get(); $resource = new Collection($ac, $transformer); $data = $fractal->createData($resource)->toArray(); return $this->respondWithSuccess($data); }
public static function listing() { $fractal = new Manager(); $data = new Collection(parent::all(), new GenreTransformer()); $list = $fractal->createData($data)->toArray()['data']; return $list; }
/** * @param $resource * @return mixed */ public function responseWithTransformer($resource, $code) { $manager = new Manager(); $manager->setSerializer(new DataArraySerializer()); $manager->parseIncludes(request()->get('includes', [])); return response()->json($manager->createData($resource)->toArray(), $code); }
/** * Serializes the original content * * @param Fractal\ResourceAbstract $resource * @return $this */ protected function serialize($resource) { $manager = new Fractal\Manager(); $data = $manager->createData($resource)->toArray()['data']; $serialized = json_encode($data); return parent::setContent($serialized); }
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); }
public function respondWithCollection($collection, $callback) { $fractal = new Manager(); $resource = new Collection($collection, $callback); $rootScope = $fractal->createData($resource); return $rootScope->toArray()['data']; }
/** * @param Manager $fractal */ public function __construct(Manager $fractal) { $this->fractal = $fractal; if (isset($_GET['include'])) { $fractal->parseIncludes($_GET['include']); } }
/** * @param Manager $fractal * @param UserTransformer $projectTransformer * @return mixed */ public function index(Manager $fractal, UserTransformer $projectTransformer) { $projects = $this->user->with(['posts'])->get(); $collection = new Collection($projects, $projectTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respondWithCORS($data); }
public function byLoan($id, Manager $fractal, AphdbTransformer $aphdbTransformer) { $records = Aphdb::with('farms', 'inspols', 'loan')->get(); $collection = new Collection($records, $aphdbTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respond($data); }
/** * Register the service provider. * * @return void */ public function register() { $source_config = __DIR__ . '/../../config/fractal.php'; $this->mergeConfigFrom($source_config, 'fractal'); $this->app->singleton('fractal', function ($app) { // retrieves configurations $autoload = $app['config']->get('fractal.autoload'); $input_key = $app['config']->get('fractal.input_key'); $exclude_key = $app['config']->get('fractal.exclude_key'); $serializer = $app['config']->get('fractal.serializer'); // creating fractal manager instance $manager = new Manager(); $factalNamespace = 'League\\Fractal\\Serializer\\'; $loadSerializer = class_exists($factalNamespace . $serializer) ? $factalNamespace . $serializer : $serializer; $manager->setSerializer(new $loadSerializer()); if ($autoload === true and $includes = $app['request']->input($input_key)) { $manager->parseIncludes($includes); } if ($app['request']->has($exclude_key)) { $manager->parseExcludes($app['request']->input($exclude_key)); } return new FractalServices($manager, $app['app']); }); $this->app->alias('fractal', FractalServices::class); // register our command here $this->app['command.transformer.generate'] = $this->app->share(function ($app) { return new TransformerGeneratorCommand($app['config'], $app['view'], $app['files'], $app); }); $this->commands('command.transformer.generate'); }
/** * @param ResourceAbstract $resource * @return SymfonyResponse */ protected function createFractalResponse(ResourceAbstract $resource) { $fractal = new Manager(); $fractal->setSerializer(new ArraySerializer()); $data = $fractal->createData($resource)->toArray(); return $this->createJsonResponse($data); }
/** * @param Manager $fractal * @param PlaceTransformer $placeTransformer * @param $placeId * @return \Illuminate\Http\JsonResponse */ public function getCheckins(Manager $fractal, PlaceTransformer $placeTransformer, $placeId) { $place = $this->place->with(['checkins'])->get(); $collection = new Collection($place, $placeTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respond($data); }
/** * @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()); }
/** * @param Manager $fractal * @param FellowTransformer $fellowTransformer * @return \Illuminate\Http\JsonResponse */ public function index(Manager $fractal, FellowTransformer $fellowTransformer) { $fellows = $this->fellow->with(['group.tutor'])->get(); $collection = new Collection($fellows, $fellowTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respond($data); }
public function getListContact($userId, Manager $fractal, ContactTransformer $contactTransformer) { $contacts = $this->contact->where('user_id', $userId)->get(); $collection = new Collection($contacts, $contactTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respond($data); }
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(); }
public function index(Manager $fractal, Request $request, ApiKeyTransformer $apiKeyTransformer) { $apiKeys = $request->user()->apiKeys; $collection = new Collection($apiKeys, $apiKeyTransformer); $data = $fractal->setSerializer(new ArraySerializer())->createData($collection)->toArray(); return $this->respond($data); }