summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-25 18:11:49 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-25 18:11:49 -0400
commita2ebc6c3b2ec3e420a03e36faf00c6e3bf3f25e7 (patch)
tree55bbe24de52dc14591033cb3f9265acfa74cdbb8 /app
parent6756ef2301a5f624941b947ec9effd34b467de9a (diff)
Move some classes to namespace Core\Http
Diffstat (limited to 'app')
-rw-r--r--app/Auth/RememberMe.php2
-rw-r--r--app/Core/Base.php8
-rw-r--r--app/Core/Http/Client.php (renamed from app/Core/HttpClient.php)56
-rw-r--r--app/Core/Http/Request.php (renamed from app/Core/Request.php)6
-rw-r--r--app/Core/Http/Response.php (renamed from app/Core/Response.php)6
-rw-r--r--app/Core/Http/Router.php (renamed from app/Core/Router.php)5
-rw-r--r--app/Core/Session.php1
-rw-r--r--app/Helper/Url.php2
-rw-r--r--app/Model/Authentication.php2
-rw-r--r--app/ServiceProvider/ClassProvider.php12
-rw-r--r--app/Subscriber/AuthSubscriber.php2
11 files changed, 66 insertions, 36 deletions
diff --git a/app/Auth/RememberMe.php b/app/Auth/RememberMe.php
index 24f30a2c..fd8ed8bb 100644
--- a/app/Auth/RememberMe.php
+++ b/app/Auth/RememberMe.php
@@ -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;
diff --git a/app/Core/Base.php b/app/Core/Base.php
index d402fb37..11f4e31b 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -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
diff --git a/app/Core/HttpClient.php b/app/Core/Http/Client.php
index 7f4ea47a..c6bf36a6 100644
--- a/app/Core/HttpClient.php
+++ b/app/Core/Http/Client.php
@@ -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;
}
}
diff --git a/app/Core/Request.php b/app/Core/Http/Request.php
index 0398760e..9f89a6e2 100644
--- a/app/Core/Request.php
+++ b/app/Core/Http/Request.php
@@ -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
diff --git a/app/Core/Response.php b/app/Core/Http/Response.php
index 6788473a..a793e58b 100644
--- a/app/Core/Response.php
+++ b/app/Core/Http/Response.php
@@ -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
diff --git a/app/Core/Router.php b/app/Core/Http/Router.php
index 843f5139..0080b23a 100644
--- a/app/Core/Router.php
+++ b/app/Core/Http/Router.php
@@ -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
diff --git a/app/Core/Session.php b/app/Core/Session.php
index a93131c7..dd1e760e 100644
--- a/app/Core/Session.php
+++ b/app/Core/Session.php
@@ -3,6 +3,7 @@
namespace Kanboard\Core;
use ArrayAccess;
+use Kanboard\Core\Http\Request;
/**
* Session class
diff --git a/app/Helper/Url.php b/app/Helper/Url.php
index e47256ba..edb26841 100644
--- a/app/Helper/Url.php
+++ b/app/Helper/Url.php
@@ -2,7 +2,7 @@
namespace Kanboard\Helper;
-use Kanboard\Core\Request;
+use Kanboard\Core\Http\Request;
use Kanboard\Core\Base;
/**
diff --git a/app/Model/Authentication.php b/app/Model/Authentication.php
index 580c1e14..11e32313 100644
--- a/app/Model/Authentication.php
+++ b/app/Model/Authentication.php
@@ -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;
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index c1a59f85..79bb734f 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -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));
};
diff --git a/app/Subscriber/AuthSubscriber.php b/app/Subscriber/AuthSubscriber.php
index 2461b52c..77a39942 100644
--- a/app/Subscriber/AuthSubscriber.php
+++ b/app/Subscriber/AuthSubscriber.php
@@ -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;