本文整理汇总了PHP中League\Fractal\Manager::parseIncludes方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::parseIncludes方法的具体用法?PHP Manager::parseIncludes怎么用?PHP Manager::parseIncludes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Manager
的用法示例。
在下文中一共展示了Manager::parseIncludes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: includeRelated
/**
* Include the selected relationships in the Fractal Transformer
*
* @param string
* @return $this
*/
public function includeRelated($includes)
{
if ($includes != null) {
$this->fractal->parseIncludes($includes);
}
return $this;
}
示例3: includes
/**
* includes sub level data transformer.
* @param array $includes
* @return $this
*/
public function includes(array $includes)
{
// when autoload is enable, we need to merge user requested includes with the predefined includes.
if ($this->autoload and $this->request->get($this->input_key)) {
$includes = array_merge($includes, explode(',', $this->request->get($this->input_key)));
}
$this->manager->parseIncludes($includes);
return $this;
}
示例4: parseIncludes
/**
* @return $this
*/
protected function parseIncludes()
{
$request = app('Illuminate\\Http\\Request');
$paramIncludes = config('warehouse.fractal.params.include', 'include');
if ($request->has($paramIncludes)) {
$this->fractal->parseIncludes($request->get($paramIncludes));
}
return $this;
}
示例5: parseIncludes
/**
* @return $this
*/
protected function parseIncludes()
{
$request = $this->application->make('Illuminate\\Http\\Request');
$paramIncludes = Config::get('reloquent.fractal.params.include', 'include');
if ($request->has($paramIncludes)) {
$this->fractal->parseIncludes($request->get($paramIncludes));
}
return $this;
}
示例6:
function __construct(Manager $fractal)
{
// Need to do Authentication HERE!
$this->beforeFilter('auth');
// Check if the request is from allowable hosts
$this->checkAllowables();
$this->fractal = $fractal;
if (Request::has('include')) {
$this->fractal->parseIncludes(Request::get('include'));
}
}
示例7: __construct
/**
* Constructor.
*
* @param Request $request
*/
public function __construct(Request $request)
{
$this->model = $this->model();
$this->transformer = $this->transformer();
$this->fractal = new Manager();
$this->request = $request;
$this->fractal->setSerializer($this->serializer());
if ($this->request->has('include')) {
$this->fractal->parseIncludes(camel_case($this->request->input('include')));
}
}
示例8: testRecursionLimiting
public function testRecursionLimiting()
{
$manager = new Manager();
// Should limit to 10 by default
$manager->parseIncludes('a.b.c.d.e.f.g.h.i.j.NEVER');
$this->assertEquals(array('a', 'a.b', 'a.b.c', 'a.b.c.d', 'a.b.c.d.e', 'a.b.c.d.e.f', 'a.b.c.d.e.f.g', 'a.b.c.d.e.f.g.h', 'a.b.c.d.e.f.g.h.i', 'a.b.c.d.e.f.g.h.i.j'), $manager->getRequestedIncludes());
// Try setting to 3 and see what happens
$manager->setRecursionLimit(3);
$manager->parseIncludes('a.b.c.NEVER');
$this->assertEquals(array('a', 'a.b', 'a.b.c'), $manager->getRequestedIncludes());
}
示例9: __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());
}
示例10: 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();
}
示例11: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
*/
public function __invoke(array $input)
{
//Check that user has permission to edit this resource
$this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'edit', 'shifts');
//Validate input
$inputValidator = v::key('id', v::intVal())->key('employee_id', v::intVal());
$inputValidator->assert($input);
//Execute command to update employee on shift
$shift = $this->commandBus->handle(new AssignShiftCommand($input['id'], $input['employee_id']));
$shiftItem = new Item($shift, new ShiftTransformer());
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($shiftItem)->toArray());
}
示例12: it_should_transform_item_with_includes
/** @test */
public function it_should_transform_item_with_includes()
{
$this->manager->parseIncludes('workplace');
$userWorkplace = new UserWorkplaceEntityStub();
$userWorkplace->setName('Doe\'s Constructions');
$user = new UserEntityStub();
$user->setName('John Doe');
$user->setEmail('johndoe@example.com');
$user->setWorkplace($userWorkplace);
$scope = $this->transformer->transformItem($user);
$this->assertInstanceOf(\League\Fractal\Scope::class, $scope);
$this->assertEquals(['data' => ['name' => 'John Doe', 'email' => 'johndoe@example.com', 'workplace' => ['data' => ['name' => 'Doe\'s Constructions']]]], $scope->toArray());
}
示例13: register
/**
* 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();
}
示例14: index
public function index(Request $request, Manager $fractal)
{
if ($requestedEmbeds = $request->get('include')) {
$fractal->parseIncludes($requestedEmbeds);
}
return $this->response->item($this->user, UserTransformer::class);
}
示例15: __construct
/**
* @param Manager $fractal
*/
public function __construct(Manager $fractal)
{
$this->fractal = $fractal;
if (isset($_GET['include'])) {
$fractal->parseIncludes($_GET['include']);
}
}