|
| 1 | +<?php namespace App\Http\Controllers; |
| 2 | +/** |
| 3 | + * Copyright 2017 OpenStack Foundation |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + **/ |
| 14 | +use App\Models\Foundation\Marketplace\IDriverRepository; |
| 15 | +use models\oauth2\IResourceServerContext; |
| 16 | +use models\utils\IBaseRepository; |
| 17 | +use ModelSerializers\SerializerRegistry; |
| 18 | + |
| 19 | +/** |
| 20 | + * Class DriversApiController |
| 21 | + * @package App\Http\Controllers |
| 22 | + */ |
| 23 | +final class DriversApiController extends JsonController |
| 24 | +{ |
| 25 | + use ParametrizedGetAll; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var IDriverRepository |
| 29 | + */ |
| 30 | + private $repository; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var IResourceServerContext |
| 34 | + */ |
| 35 | + private $resource_server_context; |
| 36 | + |
| 37 | + /** |
| 38 | + * DriversApiController constructor. |
| 39 | + * @param IDriverRepository $repository |
| 40 | + * @param IResourceServerContext $resource_server_context |
| 41 | + */ |
| 42 | + public function __construct(IDriverRepository $repository, IResourceServerContext $resource_server_context) |
| 43 | + { |
| 44 | + parent::__construct(); |
| 45 | + $this->repository = $repository; |
| 46 | + $this->resource_server_context = $resource_server_context; |
| 47 | + } |
| 48 | + |
| 49 | + protected function getResourceServerContext(): IResourceServerContext |
| 50 | + { |
| 51 | + return $this->resource_server_context; |
| 52 | + } |
| 53 | + |
| 54 | + protected function getRepository(): IBaseRepository |
| 55 | + { |
| 56 | + return $this->repository; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return mixed |
| 61 | + */ |
| 62 | + public function getAll() |
| 63 | + { |
| 64 | + return $this->_getAll( |
| 65 | + function () { |
| 66 | + return [ |
| 67 | + 'name' => ['=@', '==', '@@'], |
| 68 | + 'project' => ['=@', '==', '@@'], |
| 69 | + 'vendor' => ['=@', '==', '@@'], |
| 70 | + 'release' => ['=@', '==', '@@'], |
| 71 | + ]; |
| 72 | + }, |
| 73 | + function () { |
| 74 | + return [ |
| 75 | + 'name' => 'sometimes|string', |
| 76 | + 'project' => 'sometimes|string', |
| 77 | + 'vendor' => 'sometimes|string', |
| 78 | + 'release' => 'sometimes|string', |
| 79 | + ]; |
| 80 | + }, |
| 81 | + function () { |
| 82 | + return [ |
| 83 | + 'id', |
| 84 | + 'name', |
| 85 | + 'project', |
| 86 | + 'vendor', |
| 87 | + ]; |
| 88 | + }, |
| 89 | + function ($filter) { |
| 90 | + return $filter; |
| 91 | + }, |
| 92 | + function () { |
| 93 | + return SerializerRegistry::SerializerType_Public; |
| 94 | + } |
| 95 | + ); |
| 96 | + } |
| 97 | +} |
0 commit comments