/**
  * Send the array data to the api server.
  *
  * @param array $data The array to be sent to the server.
  * @return boolean|null true/false if data has been sent to the api successfull or not, null if the transfer is disabled.
  */
 private function apiServerSendData(array $data)
 {
     if ($this->transferException) {
         $curl = new Curl();
         $curl->post(Url::ensureHttp(rtrim($this->api, '/')) . '/create', ['error_json' => Json::encode($data)]);
         return !$curl->error;
     }
     return null;
 }
Exemple #2
0
 public function testEnsureHttp()
 {
     $this->assertEquals('http://luya.io', Url::ensureHttp('luya.io'));
     $this->assertEquals('http://www.luya.io', Url::ensureHttp('www.luya.io'));
     $this->assertEquals('http://luya.io', Url::ensureHttp('http://luya.io'));
     $this->assertEquals('http://www.luya.io', Url::ensureHttp('http://www.luya.io'));
     $this->assertEquals('https://luya.io', Url::ensureHttp('luya.io', true));
     $this->assertEquals('https://www.luya.io', Url::ensureHttp('www.luya.io', true));
     $this->assertEquals('https://luya.io', Url::ensureHttp('https://luya.io', true));
     $this->assertEquals('https://www.luya.io', Url::ensureHttp('https://www.luya.io', true));
 }
Exemple #3
0
 /**
  * Generate the Link Tag.
  *
  * @param string $value The Brackets value `[]`.
  * @param string $sub The optional Parentheses value `()`
  * @see \luya\tag\TagInterface::parse()
  * @return string The parser tag.
  */
 public function parse($value, $sub)
 {
     if (substr($value, 0, 2) == '//') {
         $value = StringHelper::replaceFirst('//', Url::base(true) . '/', $value);
         $external = false;
     } else {
         $external = true;
     }
     $value = Url::ensureHttp($value);
     $label = empty($sub) ? $value : $sub;
     return Html::a($label, $value, ['class' => $external ? 'link-external' : 'link-internal', 'target' => $external ? '_blank' : null]);
 }
 public function getRemote()
 {
     $url = Url::trailing($this->url);
     $url = Url::ensureHttp($url);
     $data = Yii::$app->cache->get($url);
     if ($data === false) {
         $curl = new \Curl\Curl();
         if ($this->auth_is_enabled) {
             $curl->setBasicAuthentication($this->auth_user, $this->auth_pass);
         }
         $curl->get($url . 'admin/api-admin-remote?token=' . sha1($this->token));
         if ($curl->error) {
             $data = false;
         } else {
             $data = json_decode($curl->response, true);
         }
         Yii::$app->cache->set($url, $data, 60 * 2);
     }
     return $data;
 }
Exemple #5
0
 /**
  * Set the href value for an external link resource.
  *
  * @param string $href The external link href value, the http protcol will be ensured.
  */
 public function setHref($href)
 {
     $this->_href = Url::ensureHttp($href);
 }