Skip to content
Snippets Groups Projects
Commit 2eca15e7 authored by Tobias Zimmermann's avatar Tobias Zimmermann
Browse files

Remove HTTP handling from LibraryDefinitionsStream

parent bb0db591
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,8 @@
namespace Drupal\libraries\StreamWrapper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StreamWrapper\LocalStream;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
/**
* Provides a stream wrapper for library definitions.
......@@ -30,13 +27,6 @@ class LibraryDefinitionsStream extends LocalStream {
*/
protected $configFactory;
/**
* The HTTP client.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Constructs an external library registry.
*
......@@ -44,7 +34,6 @@ class LibraryDefinitionsStream extends LocalStream {
*/
public function __construct() {
$this->configFactory = \Drupal::configFactory();
$this->httpClient = \Drupal::httpClient();
}
/**
......@@ -72,39 +61,15 @@ class LibraryDefinitionsStream extends LocalStream {
* {@inheritdoc}
*/
public function getDirectoryPath() {
print 'Directory path: ' . $this->getConfig('local.path') . PHP_EOL;
return $this->getConfig('local.path');
}
/**
* {@inheritdoc}
*/
public function getExternalUrl() {
if ($this->getConfig('remote.enable')) {
$url = $this->getConfig('remote.url');
return $url . '/' . $this->uri;
function getExternalUrl() {
throw new \LogicException('Library definitions should not be public.');
}
}
public function url_stat($uri, $flags) {
$status = parent::url_stat($uri, $flags);
if (($status === FALSE) && $this->getConfig('remote.enable')) {
$url = $this->getConfig('remote.url');
try {
$response = $this->httpClient->request('GET', $url . '/' . $this->getTarget($uri));
print 'Local path: ' . $this->getLocalPath($uri) . PHP_EOL;
print 'Body: ' . $response->getBody() . PHP_EOL;
$written = file_put_contents($this->getLocalPath($uri), $response->getBody());
if ($written !== FALSE) {
$status = parent::url_stat($uri, $flags);
}
}
catch (GuzzleException $exception) {
// $status is already FALSE, nothing to do.
}
}
return $status;
}
/**
* Fetches a configuration value from the library definitions configuration.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment