/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->factory = $factory; // Moved to outside environment folder so that it doesn't get wiped on each config update $this->cacheFile = $this->factory->getSystemPath('cache') . '/../languageList.txt'; $this->connector = HttpFactory::getHttp(); }
/** * Construct * * @param $ip * @param $auth * @param $logger */ public function __construct($ip, $auth = null, Logger $logger = null) { $this->ip = $ip; $this->connector = HttpFactory::getHttp(); $this->logger = $logger; $this->auth = $auth; }
/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->factory = $factory; $options = array('transport.curl' => array(CURLOPT_SSL_VERIFYPEER => false)); // Moved to outside environment folder so that it doesn't get wiped on each config update $this->cacheFile = $this->factory->getSystemPath('cache') . '/../languageList.txt'; $this->connector = HttpFactory::getHttp($options); }
/** * Download remote data store * * Used by the mautic:iplookup:update_data command and form fetch button (if applicable) to update local IP data stores * * @return bool */ public function downloadRemoteDataStore() { $connector = HttpFactory::getHttp(); $package = $this->getRemoteDateStoreDownloadUrl(); try { $data = $connector->get($package); } catch (\Exception $exception) { $this->logger->error('Failed to fetch remote IP data: ' . $exception->getMessage()); } $tempTarget = $this->cacheDir . '/' . basename($package); $tempExt = strtolower(pathinfo($package, PATHINFO_EXTENSION)); $localTarget = $this->getLocalDataStoreFilepath(); $localTargetExt = strtolower(pathinfo($localTarget, PATHINFO_EXTENSION)); try { $success = false; switch (true) { case $localTargetExt === $tempExt: $success = (bool) file_put_contents($localTarget, $data->body); break; case 'gz' == $tempExt: if (function_exists('gzdecode')) { $success = (bool) file_put_contents($localTarget, gzdecode($data->body)); } elseif (function_exists('gzopen')) { if (file_put_contents($tempTarget, $data->body)) { $bufferSize = 4096; // read 4kb at a time $file = gzopen($tempTarget, 'rb'); $outFile = fopen($localTarget, 'wb'); while (!gzeof($file)) { fwrite($outFile, gzread($file, $bufferSize)); } fclose($outFile); gzclose($file); @unlink($tempTarget); $success = true; } } break; case 'zip' == $tempExt: file_put_contents($tempTarget, $data->body); $zipper = new \ZipArchive(); $zipper->open($tempTarget); $success = $zipper->extractTo($localTarget); $zipper->close(); @unlink($tempTarget); break; } } catch (\Exception $exception) { error_log($exception); $success = false; } return $success; }
/** * @param string $url * @param bool $jsondecode * * @return mixed|string */ private function getRemoteIpData($url, $jsondecode = true) { static $connector; if (empty($connector)) { $connector = HttpFactory::getHttp(); } try { $response = $connector->get($url); $data = $jsondecode ? json_decode($response->body) : $response->body; } catch (\Exception $exception) { $data = false; } return $data; }
/** * Make a basic call using cURL to get the data * * @param $url * @param array $parameters * @param string $method * @param array $settings * * @return mixed|string */ public function makeRequest($url, $parameters = array(), $method = 'GET', $settings = array()) { $method = strtoupper($method); $authType = empty($settings['auth_type']) ? $this->getAuthenticationType() : $settings['auth_type']; list($parameters, $headers) = $this->prepareRequest($url, $parameters, $method, $settings, $authType); if (empty($settings['ignore_event_dispatch'])) { $event = $this->dispatcher->dispatch(PluginEvents::PLUGIN_ON_INTEGRATION_REQUEST, new PluginIntegrationRequestEvent($this, $url, $parameters, $headers, $method, $settings, $authType)); $headers = $event->getHeaders(); $parameters = $event->getParameters(); } if (!isset($settings['query'])) { $settings['query'] = array(); } if (isset($parameters['append_to_query'])) { $settings['query'] = array_merge($settings['query'], $parameters['append_to_query']); unset($parameters['append_to_query']); } if (!$this->isConfigured()) { return array('error' => array('message' => $this->factory->getTranslator()->trans('mautic.integration.missingkeys'))); } if ($method == 'GET' && !empty($parameters)) { $parameters = array_merge($settings['query'], $parameters); $query = http_build_query($parameters); $url .= strpos($url, '?') === false ? '?' . $query : '&' . $query; } elseif (!empty($settings['query'])) { $query = http_build_query($settings['query']); $url .= strpos($url, '?') === false ? '?' . $query : '&' . $query; } // Check for custom content-type header if (!empty($settings['content_type'])) { $settings['encoding_headers_set'] = true; $headers[] = "Content-type: {$settings['content_type']}"; } if ($method !== 'GET') { if (!empty($parameters)) { if ($authType == 'oauth1a') { $parameters = http_build_query($parameters); } if (!empty($settings['encode_parameters'])) { if ($settings['encode_parameters'] == 'json') { //encode the arguments as JSON $parameters = json_encode($parameters); if (empty($settings['encoding_headers_set'])) { $headers[] = 'Content-Type: application/json'; } } } } } $options = array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_HEADER => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 0, CURLOPT_REFERER => $this->getRefererUrl(), CURLOPT_USERAGENT => $this->getUserAgent()); if (isset($settings['curl_options'])) { $options = array_merge($options, $settings['curl_options']); } if (isset($settings['ssl_verifypeer'])) { $options[CURLOPT_SSL_VERIFYPEER] = $settings['ssl_verifypeer']; } $connector = HttpFactory::getHttp(array('transport.curl' => $options)); $parseHeaders = isset($settings['headers']) ? array_merge($headers, $settings['headers']) : $headers; // HTTP library requires that headers are in key => value pairs $headers = array(); if (is_array($parseHeaders)) { foreach ($parseHeaders as $key => $value) { if (strpos($value, ':') !== false) { list($key, $value) = explode(':', $value); $key = trim($key); $value = trim($value); } $headers[$key] = $value; } } try { switch ($method) { case 'GET': $result = $connector->get($url, $headers, 10); break; case 'POST': case 'PUT': case 'PATCH': $connectorMethod = strtolower($method); $result = $connector->{$connectorMethod}($url, $parameters, $headers, 10); break; case 'DELETE': $result = $connector->delete($url, $headers, 10); break; } } catch (\Exception $exception) { return array('error' => array('message' => $exception->getMessage(), 'code' => $exception->getCode())); } if (empty($settings['ignore_event_dispatch'])) { $event->setResponse($result); $this->dispatcher->dispatch(PluginEvents::PLUGIN_ON_INTEGRATION_RESPONSE, $event); } if (!empty($settings['return_raw'])) { return $result; } else { $response = $this->parseCallbackResponse($result->body, !empty($settings['authorize_session'])); return $response; } }
/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->factory = $factory; $this->connector = HttpFactory::getHttp(); }
/** * @param MauticFactory $factory */ public function __construct(MauticFactory $factory) { $this->factory = $factory; $options = array('transport.curl' => array(CURLOPT_SSL_VERIFYPEER => false)); $this->connector = HttpFactory::getHttp($options); }
/** * Tests the getHttp method. * * @return void * * @covers Joomla\Http\HttpFactory::getHttp * @expectedException RuntimeException * @since 1.1.4 */ public function testGetHttpException() { $this->assertInstanceOf('Joomla\\Http\\Http', HttpFactory::getHttp(array(), array())); }
protected function getMautic_Http_ConnectorService() { return $this->services['mautic.http.connector'] = \Joomla\Http\HttpFactory::getHttp(); }
/** * @param Http $http */ public function __construct(Http $http = null) { $this->http = null !== $http ? $http : HttpFactory::getHttp(); }
/** * Tests the getHttp method. * * @return void * * @since 1.0 */ public function testGetHttp() { $this->assertThat(HttpFactory::getHttp(), $this->isInstanceOf('Joomla\\Http\\Http')); }