Move some classes to namespace Core\Http
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
namespace Kanboard\Auth;
|
namespace Kanboard\Auth;
|
||||||
|
|
||||||
use Kanboard\Core\Base;
|
use Kanboard\Core\Base;
|
||||||
use Kanboard\Core\Request;
|
use Kanboard\Core\Http\Request;
|
||||||
use Kanboard\Event\AuthEvent;
|
use Kanboard\Event\AuthEvent;
|
||||||
use Kanboard\Core\Security\Token;
|
use Kanboard\Core\Security\Token;
|
||||||
|
|
||||||
|
|||||||
@@ -12,18 +12,20 @@ use Pimple\Container;
|
|||||||
*
|
*
|
||||||
* @property \Kanboard\Core\Helper $helper
|
* @property \Kanboard\Core\Helper $helper
|
||||||
* @property \Kanboard\Core\Mail\Client $emailClient
|
* @property \Kanboard\Core\Mail\Client $emailClient
|
||||||
* @property \Kanboard\Core\HttpClient $httpClient
|
|
||||||
* @property \Kanboard\Core\Paginator $paginator
|
* @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\Session $session
|
||||||
* @property \Kanboard\Core\Template $template
|
* @property \Kanboard\Core\Template $template
|
||||||
* @property \Kanboard\Core\OAuth2 $oauth
|
* @property \Kanboard\Core\OAuth2 $oauth
|
||||||
* @property \Kanboard\Core\Router $router
|
|
||||||
* @property \Kanboard\Core\Lexer $lexer
|
* @property \Kanboard\Core\Lexer $lexer
|
||||||
* @property \Kanboard\Core\ObjectStorage\ObjectStorageInterface $objectStorage
|
* @property \Kanboard\Core\ObjectStorage\ObjectStorageInterface $objectStorage
|
||||||
* @property \Kanboard\Core\Cache\Cache $memoryCache
|
* @property \Kanboard\Core\Cache\Cache $memoryCache
|
||||||
* @property \Kanboard\Core\Plugin\Hook $hook
|
* @property \Kanboard\Core\Plugin\Hook $hook
|
||||||
* @property \Kanboard\Core\Plugin\Loader $pluginLoader
|
* @property \Kanboard\Core\Plugin\Loader $pluginLoader
|
||||||
|
* @property \Kanboard\Core\Security\Token $token
|
||||||
* @property \Kanboard\Integration\BitbucketWebhook $bitbucketWebhook
|
* @property \Kanboard\Integration\BitbucketWebhook $bitbucketWebhook
|
||||||
* @property \Kanboard\Integration\GithubWebhook $githubWebhook
|
* @property \Kanboard\Integration\GithubWebhook $githubWebhook
|
||||||
* @property \Kanboard\Integration\GitlabWebhook $gitlabWebhook
|
* @property \Kanboard\Integration\GitlabWebhook $gitlabWebhook
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Kanboard\Core;
|
namespace Kanboard\Core\Http;
|
||||||
|
|
||||||
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP client
|
* HTTP client
|
||||||
*
|
*
|
||||||
* @package core
|
* @package http
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class HttpClient extends Base
|
class Client extends Base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* HTTP connection timeout in seconds
|
* HTTP connection timeout in seconds
|
||||||
@@ -99,6 +101,36 @@ class HttpClient extends Base
|
|||||||
return '';
|
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(
|
$default_headers = array(
|
||||||
'User-Agent: '.self::HTTP_USER_AGENT,
|
'User-Agent: '.self::HTTP_USER_AGENT,
|
||||||
'Connection: close',
|
'Connection: close',
|
||||||
@@ -126,22 +158,6 @@ class HttpClient extends Base
|
|||||||
$context['http']['request_fulluri'] = true;
|
$context['http']['request_fulluri'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream = @fopen(trim($url), 'r', false, stream_context_create($context));
|
return $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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Kanboard\Core;
|
namespace Kanboard\Core\Http;
|
||||||
|
|
||||||
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request class
|
* Request class
|
||||||
*
|
*
|
||||||
* @package core
|
* @package http
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Request extends Base
|
class Request extends Base
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Kanboard\Core;
|
namespace Kanboard\Core\Http;
|
||||||
|
|
||||||
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response class
|
* Response class
|
||||||
*
|
*
|
||||||
* @package core
|
* @package http
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Response extends Base
|
class Response extends Base
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Kanboard\Core;
|
namespace Kanboard\Core\Http;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router class
|
* Router class
|
||||||
*
|
*
|
||||||
* @package core
|
* @package http
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class Router extends Base
|
class Router extends Base
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Kanboard\Core;
|
namespace Kanboard\Core;
|
||||||
|
|
||||||
use ArrayAccess;
|
use ArrayAccess;
|
||||||
|
use Kanboard\Core\Http\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session class
|
* Session class
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Kanboard\Helper;
|
namespace Kanboard\Helper;
|
||||||
|
|
||||||
use Kanboard\Core\Request;
|
use Kanboard\Core\Http\Request;
|
||||||
use Kanboard\Core\Base;
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Kanboard\Model;
|
namespace Kanboard\Model;
|
||||||
|
|
||||||
use Kanboard\Core\Request;
|
use Kanboard\Core\Http\Request;
|
||||||
use SimpleValidator\Validator;
|
use SimpleValidator\Validator;
|
||||||
use SimpleValidator\Validators;
|
use SimpleValidator\Validators;
|
||||||
use Gregwar\Captcha\CaptchaBuilder;
|
use Gregwar\Captcha\CaptchaBuilder;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use Kanboard\Core\ObjectStorage\FileStorage;
|
|||||||
use Kanboard\Core\Paginator;
|
use Kanboard\Core\Paginator;
|
||||||
use Kanboard\Core\OAuth2;
|
use Kanboard\Core\OAuth2;
|
||||||
use Kanboard\Core\Tool;
|
use Kanboard\Core\Tool;
|
||||||
|
use Kanboard\Core\Http\Client as HttpClient;
|
||||||
use Kanboard\Model\UserNotificationType;
|
use Kanboard\Model\UserNotificationType;
|
||||||
use Kanboard\Model\ProjectNotificationType;
|
use Kanboard\Model\ProjectNotificationType;
|
||||||
|
|
||||||
@@ -81,13 +82,14 @@ class ClassProvider implements ServiceProviderInterface
|
|||||||
'Core' => array(
|
'Core' => array(
|
||||||
'DateParser',
|
'DateParser',
|
||||||
'Helper',
|
'Helper',
|
||||||
'HttpClient',
|
|
||||||
'Lexer',
|
'Lexer',
|
||||||
|
'Session',
|
||||||
|
'Template',
|
||||||
|
),
|
||||||
|
'Core\Http' => array(
|
||||||
'Request',
|
'Request',
|
||||||
'Response',
|
'Response',
|
||||||
'Router',
|
'Router',
|
||||||
'Session',
|
|
||||||
'Template',
|
|
||||||
),
|
),
|
||||||
'Core\Cache' => array(
|
'Core\Cache' => array(
|
||||||
'MemoryCache',
|
'MemoryCache',
|
||||||
@@ -117,6 +119,10 @@ class ClassProvider implements ServiceProviderInterface
|
|||||||
return new OAuth2($c);
|
return new OAuth2($c);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$container['httpClient'] = function ($c) {
|
||||||
|
return new HttpClient($c);
|
||||||
|
};
|
||||||
|
|
||||||
$container['htmlConverter'] = function () {
|
$container['htmlConverter'] = function () {
|
||||||
return new HtmlConverter(array('strip_tags' => true));
|
return new HtmlConverter(array('strip_tags' => true));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Kanboard\Subscriber;
|
namespace Kanboard\Subscriber;
|
||||||
|
|
||||||
use Kanboard\Core\Request;
|
use Kanboard\Core\Http\Request;
|
||||||
use Kanboard\Event\AuthEvent;
|
use Kanboard\Event\AuthEvent;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__.'/../Base.php';
|
require_once __DIR__.'/../../Base.php';
|
||||||
|
|
||||||
use Kanboard\Core\Router;
|
use Kanboard\Core\Http\Router;
|
||||||
|
|
||||||
class RouterTest extends Base
|
class RouterTest extends Base
|
||||||
{
|
{
|
||||||
Reference in New Issue
Block a user