當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。