linslin\yii2\curl\Curl::setOption PHP Method

setOption() public method

Set curl option
public setOption ( string $key, mixed $value )
$key string
$value mixed
    public function setOption($key, $value)
    {
        //set value
        if (array_key_exists($key, $this->_defaultOptions) && $key !== CURLOPT_WRITEFUNCTION) {
            $this->_defaultOptions[$key] = $value;
        } else {
            $this->_options[$key] = $value;
        }
        //return self
        return $this;
    }

Usage Example

 public function actionSend()
 {
     if (Yii::$app->request->post("recipient_id")) {
         $recipient_id = Yii::$app->request->post("recipient_id");
         $text = Yii::$app->request->post("message");
         $sender_id = Yii::$app->request->post("sender_id");
         $recipientUser = Salamiuser::find()->where(['id' => $recipient_id])->one();
         $senderUser = Salamiuser::find()->where(['id' => $sender_id])->one();
         $message = new Messages();
         $message->sender_id = $senderUser->id;
         $message->recipient_id = $recipientUser->id;
         $message->text = $text;
         $message->state = "new";
         $saved = $message->save();
         $data = array('user_ids' => array($recipientUser->facebook_id), 'notification' => array("alert" => $text, "android" => array('payload' => array("sender" => $senderUser->facebook_id))));
         $ionicAppId = "70f2a984";
         $ionicApiSecret = "ec4839bfb9ea2daa2271b0149a0c18003a3672178f4e6485";
         $url = "https://push.ionic.io/api/v1/push";
         $content = json_encode($data);
         $curl = new curl\Curl();
         $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
         $curl->setOption(CURLOPT_POSTFIELDS, $content);
         $curl->setOption(CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Ionic-Application-Id: ' . $ionicAppId, 'Content-Length: ' . strlen($content), 'Authorization: Basic ' . base64_encode($ionicApiSecret)));
         $response = $curl->post('https://push.ionic.io/api/v1/push');
         return $response;
     }
     return '{"error": "Invalid request parameters"}';
 }
All Usage Examples Of linslin\yii2\curl\Curl::setOption