当前位置: 首页>>代码示例>>PHP>>正文


PHP Manager::setSerializer方法代码示例

本文整理汇总了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'));
 }
开发者ID:gdgfoz,项目名称:codelab-todo-api,代码行数:7,代码来源:ResponseFractal.php

示例2: getFractal

 /**
  * @return Manager $fractal
  */
 public function getFractal()
 {
     if (!isset($this->fractal)) {
         $this->fractal = new Manager();
         $this->fractal->setSerializer(new ArraySerializer());
     }
     return $this->fractal;
 }
开发者ID:eventhomes,项目名称:laravel-fractalhelper,代码行数:11,代码来源:FractalHelper.php

示例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());
 }
开发者ID:hedii,项目名称:php-crawler,代码行数:13,代码来源:ApiController.php

示例4: setupSerializer

 /**
  * @return $this
  */
 protected function setupSerializer()
 {
     $serializer = $this->serializer();
     if ($serializer instanceof SerializerAbstract) {
         $this->fractal->setSerializer($serializer);
     }
     return $this;
 }
开发者ID:osvaldino,项目名称:warehouse,代码行数:11,代码来源:FractalPresenter.php

示例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']);
     }
 }
开发者ID:giadc,项目名称:json-api-response,代码行数:14,代码来源:Response.php

示例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;
 }
开发者ID:artesaos,项目名称:warehouse,代码行数:14,代码来源:Factory.php

示例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')));
     }
 }
开发者ID:NewwayLibs,项目名称:laravel-api-generator,代码行数:16,代码来源:BaseController.php

示例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);
 }
开发者ID:ashbreeze,项目名称:OmniChain-API,代码行数:7,代码来源:ApiKeyController.php

示例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);
 }
开发者ID:ashbreeze,项目名称:OmniChain-API,代码行数:7,代码来源:UserController.php

示例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;
     }
 }
开发者ID:ssteinerx,项目名称:release-belt,代码行数:31,代码来源:Application.php

示例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);
 }
开发者ID:pmill,项目名称:doctrine-rest-api,代码行数:11,代码来源:Response.php

示例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();
 }
开发者ID:yajra,项目名称:laravel-datatables-oracle,代码行数:31,代码来源:DatatablesServiceProvider.php

示例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);
 }
开发者ID:JennySwift,项目名称:dental,代码行数:11,代码来源:Controller.php

示例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');
 }
开发者ID:cyvelnet,项目名称:laravel5-fractal,代码行数:35,代码来源:Laravel5FractalServiceProvider.php

示例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;
 }
开发者ID:cvele,项目名称:fondacija,代码行数:30,代码来源:RestResponse.php


注:本文中的League\Fractal\Manager::setSerializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。