本文整理汇总了PHP中League\Fractal\Manager::setSerializer方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::setSerializer方法的具体用法?PHP Manager::setSerializer怎么用?PHP Manager::setSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Manager
的用法示例。
在下文中一共展示了Manager::setSerializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(SerializerAbstract $serializer, Request $request)
{
$this->request = $request;
$this->manager = new Manager();
$this->manager->setSerializer($serializer);
$this->parseIncludes($this->request->get('include'));
}
示例2: getFractal
/**
* @return Manager $fractal
*/
public function getFractal()
{
if (!isset($this->fractal)) {
$this->fractal = new Manager();
$this->fractal->setSerializer(new ArraySerializer());
}
return $this->fractal;
}
示例3: __construct
/**
* ApiController constructor.
*
* @param \League\Fractal\Manager $fractal
*/
public function __construct(Manager $fractal)
{
if (config('crawler.api.use_auth')) {
$this->middleware('Hedii\\Crawler\\Api\\Middleware\\ErrorIfNotCorrectUser');
}
$this->fractal = $fractal;
$this->fractal->setSerializer(new ArraySerializer());
}
示例4: setupSerializer
/**
* @return $this
*/
protected function setupSerializer()
{
$serializer = $this->serializer();
if ($serializer instanceof SerializerAbstract) {
$this->fractal->setSerializer($serializer);
}
return $this;
}
示例5: __construct
/**
* @param Manager $fractal
* @param ResponseFactory $response
* @param RequestParams $requestParams
*/
public function __construct(Manager $fractal, RequestParams $requestParams)
{
$this->fractal = $fractal;
$this->requestParams = $requestParams;
$this->fractal->setSerializer(new JsonApiSerializer());
if (isset($_GET['include'])) {
$fractal->parseIncludes($_GET['include']);
}
}
示例6: getFractalFactory
/**
* @return FractalFactory
*/
protected function getFractalFactory()
{
if (!$this->fractal) {
$this->fractal = new LeagueFractalFactory();
$serializer = $this->app['config']->get('warehouse.fractal.serializer', null);
if (!empty($serializer)) {
$this->fractal->setSerializer($this->app->make($serializer));
}
}
return $this->fractal;
}
示例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: index
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);
}
示例9: show
public function show(Manager $fractal, Request $request, UserTransformer $userTransformer)
{
$user = $request->user();
$item = new Item($user, $userTransformer);
$data = $fractal->setSerializer(new ArraySerializer())->createData($item)->toArray();
return $this->respond($data);
}
示例10: __construct
public function __construct(array $values = [])
{
parent::__construct();
$app = $this;
$this['release.dir'] = __DIR__ . '/../releases';
$this['finder'] = function () {
$finder = new Finder();
return $finder->files()->in($this['release.dir']);
};
$this['parser'] = function () use($app) {
return new ReleaseParser($app['finder']);
};
$this['fractal'] = function () {
$fractal = new Manager();
$fractal->setSerializer(new PackageSerializer());
return $fractal;
};
$this['transformer'] = function () use($app) {
/** @var Request $request */
$request = $app['request'];
$transformer = new ReleaseTransformer();
$transformer->setHost($request->getHttpHost());
return $transformer;
};
$this->get('/', 'Rarst\\ReleaseBelt\\Controller::getHtml');
$this->get('/packages.json', 'Rarst\\ReleaseBelt\\Controller::getJson');
$this->get('/{vendor}/{file}', 'Rarst\\ReleaseBelt\\Controller::getFile');
foreach ($values as $key => $value) {
$this[$key] = $value;
}
}
示例11: createFractalResponse
/**
* @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);
}
示例12: 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();
}
示例13: responseWithTransformer
/**
* @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);
}
示例14: register
/**
* 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');
}
示例15: createResponseArray
public function createResponseArray($data, $entity, Request $request)
{
$this->request = $request;
$fractal = new Manager();
$fractal->parseIncludes($request->query->get('include', []));
$fractal->setSerializer(new ArraySerializer());
$transformer = $this->transformerFactory->get($entity);
if ($data instanceof Pagerfanta) {
$pager = $data;
$pager->setMaxPerPage($request->query->get('limit', 10));
$pager->setCurrentPage($request->query->get('page', 1));
$results = $pager->getCurrentPageResults();
$resource = new Collection($results, $transformer);
$resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
} elseif ($data instanceof DoctrineQuery) {
$ormAdapter = new DoctrineORMAdapter($data);
$pager = new Pagerfanta($ormAdapter);
$pager->setMaxPerPage($request->query->get('limit', 10));
$pager->setCurrentPage($request->query->get('page', 1));
$results = $pager->getCurrentPageResults();
$resource = new Collection($results, $transformer);
$resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
} elseif (is_array($data)) {
$resource = new Collection($data, $transformer);
} else {
$resource = new Item($data, $transformer);
}
$data = $fractal->createData($resource)->toArray();
return $data;
}