Move some classes to namespace Core\Http
This commit is contained in:
@@ -12,18 +12,20 @@ use Pimple\Container;
|
||||
*
|
||||
* @property \Kanboard\Core\Helper $helper
|
||||
* @property \Kanboard\Core\Mail\Client $emailClient
|
||||
* @property \Kanboard\Core\HttpClient $httpClient
|
||||
* @property \Kanboard\Core\Paginator $paginator
|
||||
* @property \Kanboard\Core\Request $request
|
||||
* @property \Kanboard\Core\Http\Client $httpClient
|
||||
* @property \Kanboard\Core\Http\Request $request
|
||||
* @property \Kanboard\Core\Http\Router $router
|
||||
* @property \Kanboard\Core\Http\Response $response
|
||||
* @property \Kanboard\Core\Session $session
|
||||
* @property \Kanboard\Core\Template $template
|
||||
* @property \Kanboard\Core\OAuth2 $oauth
|
||||
* @property \Kanboard\Core\Router $router
|
||||
* @property \Kanboard\Core\Lexer $lexer
|
||||
* @property \Kanboard\Core\ObjectStorage\ObjectStorageInterface $objectStorage
|
||||
* @property \Kanboard\Core\Cache\Cache $memoryCache
|
||||
* @property \Kanboard\Core\Plugin\Hook $hook
|
||||
* @property \Kanboard\Core\Plugin\Loader $pluginLoader
|
||||
* @property \Kanboard\Core\Security\Token $token
|
||||
* @property \Kanboard\Integration\BitbucketWebhook $bitbucketWebhook
|
||||
* @property \Kanboard\Integration\GithubWebhook $githubWebhook
|
||||
* @property \Kanboard\Integration\GitlabWebhook $gitlabWebhook
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core;
|
||||
namespace Kanboard\Core\Http;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* HTTP client
|
||||
*
|
||||
* @package core
|
||||
* @package http
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class HttpClient extends Base
|
||||
class Client extends Base
|
||||
{
|
||||
/**
|
||||
* HTTP connection timeout in seconds
|
||||
@@ -99,6 +101,36 @@ class HttpClient extends Base
|
||||
return '';
|
||||
}
|
||||
|
||||
$stream = @fopen(trim($url), 'r', false, stream_context_create($this->getContext($method, $content, $headers)));
|
||||
$response = '';
|
||||
|
||||
if (is_resource($stream)) {
|
||||
$response = stream_get_contents($stream);
|
||||
} else {
|
||||
$this->logger->error('HttpClient: request failed');
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
$this->logger->debug('HttpClient: url='.$url);
|
||||
$this->logger->debug('HttpClient: payload='.$content);
|
||||
$this->logger->debug('HttpClient: metadata='.var_export(@stream_get_meta_data($stream), true));
|
||||
$this->logger->debug('HttpClient: response='.$response);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stream context
|
||||
*
|
||||
* @access private
|
||||
* @param string $method
|
||||
* @param string $content
|
||||
* @param string[] $headers
|
||||
* @return array
|
||||
*/
|
||||
private function getContext($method, $content, array $headers)
|
||||
{
|
||||
$default_headers = array(
|
||||
'User-Agent: '.self::HTTP_USER_AGENT,
|
||||
'Connection: close',
|
||||
@@ -126,22 +158,6 @@ class HttpClient extends Base
|
||||
$context['http']['request_fulluri'] = true;
|
||||
}
|
||||
|
||||
$stream = @fopen(trim($url), 'r', false, stream_context_create($context));
|
||||
$response = '';
|
||||
|
||||
if (is_resource($stream)) {
|
||||
$response = stream_get_contents($stream);
|
||||
} else {
|
||||
$this->container['logger']->error('HttpClient: request failed');
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
$this->container['logger']->debug('HttpClient: url='.$url);
|
||||
$this->container['logger']->debug('HttpClient: payload='.$content);
|
||||
$this->container['logger']->debug('HttpClient: metadata='.var_export(@stream_get_meta_data($stream), true));
|
||||
$this->container['logger']->debug('HttpClient: response='.$response);
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core;
|
||||
namespace Kanboard\Core\Http;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Request class
|
||||
*
|
||||
* @package core
|
||||
* @package http
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Request extends Base
|
||||
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core;
|
||||
namespace Kanboard\Core\Http;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Response class
|
||||
*
|
||||
* @package core
|
||||
* @package http
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Response extends Base
|
||||
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core;
|
||||
namespace Kanboard\Core\Http;
|
||||
|
||||
use RuntimeException;
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Router class
|
||||
*
|
||||
* @package core
|
||||
* @package http
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Router extends Base
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Kanboard\Core;
|
||||
|
||||
use ArrayAccess;
|
||||
use Kanboard\Core\Http\Request;
|
||||
|
||||
/**
|
||||
* Session class
|
||||
|
||||
Reference in New Issue
Block a user