Yeelight /
miot-api
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * Created by PhpStorm. |
||||||
| 4 | * User: sheldon |
||||||
| 5 | * Date: 18-6-6 |
||||||
| 6 | * Time: 下午6:25. |
||||||
| 7 | */ |
||||||
| 8 | |||||||
| 9 | namespace MiotApi\Contract\Instance; |
||||||
| 10 | |||||||
| 11 | use MiotApi\Contract\Specification\ServiceSpecification; |
||||||
| 12 | use MiotApi\Contract\Specification\Specification; |
||||||
| 13 | use MiotApi\Contract\Urn; |
||||||
| 14 | use MiotApi\Util\Collection\Collection; |
||||||
| 15 | |||||||
| 16 | class Service extends Specification |
||||||
| 17 | { |
||||||
| 18 | protected $data; |
||||||
| 19 | |||||||
| 20 | protected $propertiesNode; |
||||||
| 21 | |||||||
| 22 | /** |
||||||
| 23 | * 实例ID(Instance ID,简称iid). |
||||||
| 24 | * |
||||||
| 25 | * @var |
||||||
| 26 | */ |
||||||
| 27 | protected $iid; |
||||||
| 28 | |||||||
| 29 | /** |
||||||
| 30 | * type对象 |
||||||
| 31 | * |
||||||
| 32 | * @var |
||||||
| 33 | */ |
||||||
| 34 | protected $specification; |
||||||
| 35 | |||||||
| 36 | public function __construct($data = []) |
||||||
| 37 | { |
||||||
| 38 | $this->data = $data; |
||||||
| 39 | $this->init(); |
||||||
| 40 | } |
||||||
| 41 | |||||||
| 42 | /** |
||||||
| 43 | * @throws \MiotApi\Exception\SpecificationErrorException |
||||||
| 44 | */ |
||||||
| 45 | public function init() |
||||||
| 46 | { |
||||||
| 47 | $this->collection = new Collection($this->data); |
||||||
| 48 | $this->iid = $this->collection->get('iid'); |
||||||
| 49 | $this->urn = new Urn($this->collection->get('type')); |
||||||
| 50 | |||||||
| 51 | $this->specification = new ServiceSpecification($this->urn->getBaseUrn()); |
||||||
| 52 | $this->initProperties(); |
||||||
| 53 | } |
||||||
| 54 | |||||||
| 55 | /** |
||||||
| 56 | * @throws \MiotApi\Exception\SpecificationErrorException |
||||||
| 57 | */ |
||||||
| 58 | protected function initProperties() |
||||||
| 59 | { |
||||||
| 60 | if ($this->has('properties')) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 61 | $properties = $this->get('properties'); |
||||||
|
0 ignored issues
–
show
The method
get() does not exist on MiotApi\Contract\Instance\Service. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 62 | if (!empty($properties)) { |
||||||
| 63 | foreach ($properties as $property) { |
||||||
| 64 | $this->propertiesNode[$property['iid']] = new Property($property); |
||||||
| 65 | } |
||||||
| 66 | } |
||||||
| 67 | } |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | public function getIid() |
||||||
| 71 | { |
||||||
| 72 | return $this->iid; |
||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | public function property($piid) |
||||||
| 76 | { |
||||||
| 77 | return $this->propertiesNode[$piid]; |
||||||
| 78 | } |
||||||
| 79 | |||||||
| 80 | public function getPropertiesNode() |
||||||
| 81 | { |
||||||
| 82 | return $this->propertiesNode; |
||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | public function getSpecification() |
||||||
| 86 | { |
||||||
| 87 | return $this->specification; |
||||||
| 88 | } |
||||||
| 89 | |||||||
| 90 | public function getSpecificationContext() |
||||||
| 91 | { |
||||||
| 92 | return $this->specification->toContext(); |
||||||
| 93 | } |
||||||
| 94 | } |
||||||
| 95 |