|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Gitlab API library. |
| 7 | + * |
| 8 | + * (c) Matt Humphrey <matth@windsor-telecom.co.uk> |
| 9 | + * (c) Graham Campbell <graham@alt-three.com> |
| 10 | + * |
| 11 | + * For the full copyright and license information, please view the LICENSE |
| 12 | + * file that was distributed with this source code. |
| 13 | + */ |
| 14 | + |
| 15 | +namespace Gitlab\Api; |
| 16 | + |
| 17 | +use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; |
| 18 | +use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; |
| 19 | +use Symfony\Component\OptionsResolver\Options; |
| 20 | + |
| 21 | +class Search extends AbstractApi |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @param array $parameters { |
| 25 | + * |
| 26 | + * @var string $scope The scope to search in |
| 27 | + * @var string $search The search query |
| 28 | + * @var string $state Filter by state. Issues and merge requests are supported; it is ignored for other scopes. |
| 29 | + * @var bool $confidential Filter by confidentiality. Issues scope is supported; it is ignored for other scopes. |
| 30 | + * @var string $order_by Allowed values are created_at only. If this is not set, the results are either sorted by created_at in descending order for basic search, or by the most relevant documents when using advanced search. |
| 31 | + * @var string $sort Return projects sorted in asc or desc order (default is desc) |
| 32 | + * } |
| 33 | + * |
| 34 | + * @throws UndefinedOptionsException If an option name is undefined |
| 35 | + * @throws InvalidOptionsException If an option doesn't fulfill the |
| 36 | + * specified validation rules |
| 37 | + * |
| 38 | + * @return mixed |
| 39 | + */ |
| 40 | + public function all(array $parameters = []) |
| 41 | + { |
| 42 | + $resolver = $this->createOptionsResolver(); |
| 43 | + $booleanNormalizer = function (Options $resolver, $value): string { |
| 44 | + return $value ? 'true' : 'false'; |
| 45 | + }; |
| 46 | + $resolver->setDefined('confidential') |
| 47 | + ->setAllowedTypes('confidential', 'bool') |
| 48 | + ->setNormalizer('confidential', $booleanNormalizer); |
| 49 | + $scope = [ |
| 50 | + 'projects', |
| 51 | + 'issues', |
| 52 | + 'merge_requests', |
| 53 | + 'milestones', |
| 54 | + 'snippet_titles', |
| 55 | + 'wiki_blobs', |
| 56 | + 'commits', |
| 57 | + 'blobs', |
| 58 | + 'notes', |
| 59 | + 'users', |
| 60 | + ]; |
| 61 | + $resolver->setRequired('scope') |
| 62 | + ->setAllowedValues('scope', $scope); |
| 63 | + $resolver->setRequired('search'); |
| 64 | + $resolver->setDefined('order_by') |
| 65 | + ->setAllowedValues('order_by', ['created_at']); |
| 66 | + $resolver->setDefined('sort') |
| 67 | + ->setAllowedValues('sort', ['asc', 'desc']); |
| 68 | + $resolver->setDefined('state') |
| 69 | + ->setAllowedValues('state', ['opened', 'closed']); |
| 70 | + |
| 71 | + return $this->get('search', $resolver->resolve($parameters)); |
| 72 | + } |
| 73 | +} |
0 commit comments