Move some classes to namespace Core\Http
This commit is contained in:
parent
6756ef2301
commit
a2ebc6c3b2
|
|
@ -3,7 +3,7 @@
|
|||
namespace Kanboard\Auth;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Core\Request;
|
||||
use Kanboard\Core\Http\Request;
|
||||
use Kanboard\Event\AuthEvent;
|
||||
use Kanboard\Core\Security\Token;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Kanboard\Helper;
|
||||
|
||||
use Kanboard\Core\Request;
|
||||
use Kanboard\Core\Http\Request;
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use Kanboard\Core\Request;
|
||||
use Kanboard\Core\Http\Request;
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use Kanboard\Core\ObjectStorage\FileStorage;
|
|||
use Kanboard\Core\Paginator;
|
||||
use Kanboard\Core\OAuth2;
|
||||
use Kanboard\Core\Tool;
|
||||
use Kanboard\Core\Http\Client as HttpClient;
|
||||
use Kanboard\Model\UserNotificationType;
|
||||
use Kanboard\Model\ProjectNotificationType;
|
||||
|
||||
|
|
@ -81,13 +82,14 @@ class ClassProvider implements ServiceProviderInterface
|
|||
'Core' => array(
|
||||
'DateParser',
|
||||
'Helper',
|
||||
'HttpClient',
|
||||
'Lexer',
|
||||
'Session',
|
||||
'Template',
|
||||
),
|
||||
'Core\Http' => array(
|
||||
'Request',
|
||||
'Response',
|
||||
'Router',
|
||||
'Session',
|
||||
'Template',
|
||||
),
|
||||
'Core\Cache' => array(
|
||||
'MemoryCache',
|
||||
|
|
@ -117,6 +119,10 @@ class ClassProvider implements ServiceProviderInterface
|
|||
return new OAuth2($c);
|
||||
});
|
||||
|
||||
$container['httpClient'] = function ($c) {
|
||||
return new HttpClient($c);
|
||||
};
|
||||
|
||||
$container['htmlConverter'] = function () {
|
||||
return new HtmlConverter(array('strip_tags' => true));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Kanboard\Subscriber;
|
||||
|
||||
use Kanboard\Core\Request;
|
||||
use Kanboard\Core\Http\Request;
|
||||
use Kanboard\Event\AuthEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Router;
|
||||
use Kanboard\Core\Http\Router;
|
||||
|
||||
class RouterTest extends Base
|
||||
{
|
||||
Loading…
Reference in New Issue