Exemplo n.º 1
0
 public function validateSetup($scenario = 'create')
 {
     if (!parent::validateSetup($scenario)) {
         return false;
     }
     $data = static::fetchData($this->attributes['url'], $this->attributes['apiKey']);
     if (!$data || !empty($data['error'])) {
         if (!empty($data['responseCode']) && $data['responseCode'] === 404) {
             $this->setupErrors['url'] = 'Data provider was not found at this URL';
         } elseif (!empty($data['responseCode']) && $data['responseCode'] === 403) {
             $this->setupErrors['apiKey'] = 'API Key was rejected';
         } else {
             $this->setupErrors['url'] = 'An unknown error occurred while validating the data provider';
         }
         return false;
     }
     if (!isset($data['data']['provider']) || !isset($data['data']['provider']['class'])) {
         $this->setupErrors['url'] = 'Sensor provider did not provide a valid response.';
         return false;
     }
     if (!class_exists($data['data']['provider']['class'])) {
         $this->setupErrors['url'] = 'Sensor provider is not recognized by this sensor monitor instance.';
         return false;
     }
     if (!$this->loadObject($data['data']['provider'], PullProviderInterface::class)) {
         $this->setupErrors['url'] = 'Sensor provider could not be validated.';
         return false;
     }
     $modelClass = get_class($this->model);
     if ($modelClass::find()->where(['and', ['system_id' => $this->model->system_id], ['not', ['id' => $this->model->id]]])->count() > 0) {
         $this->setupErrors['url'] = 'Sensor provider with same ID (' . $this->model->system_id . ') already exists in the system.';
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 public function validateSetup($scenario = 'create')
 {
     if (!parent::validateSetup($scenario)) {
         return false;
     }
     $providerConfig = [];
     $providerConfig['class'] = PushProvider::class;
     $providerConfig['id'] = $this->attributes['id'];
     if (!$this->loadObject($providerConfig, PushProviderInterface::class)) {
         $this->setupErrors['url'] = 'Sensor provider could not be validated.';
         return false;
     }
     $modelClass = get_class($this->model);
     if ($modelClass::find()->where(['and', ['system_id' => $this->model->system_id], ['not', ['id' => $this->model->id]]])->count() > 0) {
         $this->setupErrors['url'] = 'Sensor provider with same ID (' . $this->model->system_id . ') already exists in the system.';
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 public static function getSensorObjectInstanceClass(\psesd\sensors\base\BaseInterface $object)
 {
     if ($object instanceof SensorInterface) {
         return SensorInstance::className();
     }
     if ($object instanceof ServiceInterface) {
         return ServiceInstance::className();
     }
     if ($object instanceof ServiceReferenceInterface) {
         return ServiceReferenceInstance::className();
     }
     if ($object instanceof ResourceInterface) {
         return ResourceInstance::className();
     }
     if ($object instanceof ResourceReferenceInterface) {
         return ResourceReferenceInstance::className();
     }
     if ($object instanceof ServerInterface) {
         return ServerInstance::className();
     }
     if ($object instanceof SiteInterface) {
         return SiteInstance::className();
     }
     if ($object instanceof ProviderInterface) {
         return ProviderInstance::className();
     }
     return false;
 }