File manager - Edit - /home/opticamezl/www/newok/templates/yootheme/packages/graphql/src/Directive/SliceDirective.php
Back
<?php namespace YOOtheme\GraphQL\Directive; use YOOtheme\GraphQL\Type\Definition\Directive; use YOOtheme\GraphQL\Type\Definition\Type; class SliceDirective extends Directive { /** * Constructor. */ public function __construct() { parent::__construct([ 'name' => 'slice', 'args' => [ [ 'name' => 'offset', 'type' => Type::int(), ], [ 'name' => 'limit', 'type' => Type::int(), ], ], 'locations' => ['FIELD', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT'], ]); } /** * Directive callback. * * @param array $params * * @return \Closure */ public function __invoke(array $params) { return function ($root, $args, $context, $info, callable $next) use ($params) { $offset = $params['offset'] ?? 0; $limit = $params['limit'] ?? null; $value = $next($root, $args, $context, $info); // TODO 2.4 no need to check for $offset && $limit ? if (is_array($value) && ($offset || $limit)) { return array_slice($value, (int) $offset, (int) $limit ?: null); } return $value; }; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings