Yeelight /
miot-api
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: sheldon |
||
| 5 | * Date: 18-6-8 |
||
| 6 | * Time: 下午3:43. |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace MiotApi\Contract\Specification; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * 设备是一个独立的有意义的设备,比如:灯泡、插座、风扇。 |
||
| 13 | * 描述一个设备,需要说清楚:是什么设备?有哪些服务可用? |
||
| 14 | * |
||
| 15 | * Class DeviceSpecification |
||
| 16 | */ |
||
| 17 | class DeviceSpecification extends Specification |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * 必选服务 |
||
| 21 | * |
||
| 22 | * @var |
||
| 23 | */ |
||
| 24 | protected $requiredServices; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * 可选服务 |
||
| 28 | * |
||
| 29 | * @var |
||
| 30 | */ |
||
| 31 | protected $optionalServices; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @throws \MiotApi\Exception\SpecificationErrorException |
||
| 35 | */ |
||
| 36 | public function init() |
||
| 37 | { |
||
| 38 | parent::init(); |
||
| 39 | |||
| 40 | if ($this->has('required-services')) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | $requiredServices = $this->__get('required-services'); |
||
| 42 | if (!empty($requiredServices)) { |
||
| 43 | foreach ($requiredServices as $index => $service) { |
||
| 44 | $this->requiredServices[] = new ServiceSpecification($service); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($this->has('required-services')) { |
||
| 50 | $optionalServices = $this->__get('optional-services'); |
||
| 51 | if (!empty($optionalServices)) { |
||
| 52 | foreach ($optionalServices as $index => $service) { |
||
| 53 | $this->optionalServices[] = new ServiceSpecification($service); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * 获取 必选服务 |
||
| 61 | * |
||
| 62 | * @return mixed |
||
| 63 | */ |
||
| 64 | public function getRequiredServices() |
||
| 65 | { |
||
| 66 | return $this->requiredServices; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * 获取 可选服务 |
||
| 71 | * |
||
| 72 | * @return mixed |
||
| 73 | */ |
||
| 74 | public function getOptionalServices() |
||
| 75 | { |
||
| 76 | return $this->optionalServices; |
||
| 77 | } |
||
| 78 | } |
||
| 79 |