|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Pterodactyl - Panel |
| 4 | + * Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +namespace Pterodactyl\Transformers\Admin; |
| 26 | + |
| 27 | +use Pterodactyl\Models\ServiceOption; |
| 28 | +use League\Fractal\TransformerAbstract; |
| 29 | + |
| 30 | +class OptionTransformer extends TransformerAbstract |
| 31 | +{ |
| 32 | + /** |
| 33 | + * List of resources that can be included. |
| 34 | + * |
| 35 | + * @var array |
| 36 | + */ |
| 37 | + protected $availableIncludes = [ |
| 38 | + 'service', |
| 39 | + 'packs', |
| 40 | + 'servers', |
| 41 | + 'variables', |
| 42 | + ]; |
| 43 | + |
| 44 | + /** |
| 45 | + * Return a generic transformed service option array. |
| 46 | + * |
| 47 | + * @return array |
| 48 | + */ |
| 49 | + public function transform(ServiceOption $option) |
| 50 | + { |
| 51 | + return $option->toArray(); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Return the parent service for this service option. |
| 56 | + * |
| 57 | + * @return \Leauge\Fractal\Resource\Collection |
| 58 | + */ |
| 59 | + public function includeService(ServiceOption $option) |
| 60 | + { |
| 61 | + return $this->item($option->service, new ServiceTransformer, 'service'); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Return the packs associated with this service option. |
| 66 | + * |
| 67 | + * @return \Leauge\Fractal\Resource\Collection |
| 68 | + */ |
| 69 | + public function includePacks(ServiceOption $option) |
| 70 | + { |
| 71 | + return $this->collection($option->packs, new PackTransformer, 'pack'); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Return the servers associated with this service option. |
| 76 | + * |
| 77 | + * @return \Leauge\Fractal\Resource\Collection |
| 78 | + */ |
| 79 | + public function includeServers(ServiceOption $option) |
| 80 | + { |
| 81 | + return $this->collection($option->servers, new ServerTransformer, 'server'); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Return the variables for this service option. |
| 86 | + * |
| 87 | + * @return \Leauge\Fractal\Resource\Collection |
| 88 | + */ |
| 89 | + public function includeVariables(ServiceOption $option) |
| 90 | + { |
| 91 | + return $this->collection($option->variables, new ServiceVariableTransformer, 'variable'); |
| 92 | + } |
| 93 | +} |
0 commit comments