Skip to content
Snippets Groups Projects

Issue #3254077: Exception: Serialization of 'Closure' is not allowed in serialize()

Files
5
@@ -67,6 +67,13 @@ class InstallableLibrary extends AnnotationObject {
*/
protected $versionUrls = [];
/**
* The directory where metadata about the library will be stored.
*
* @var string
*/
protected $directory;
/**
* The last exception thrown when attempting to initiate a request.
*
@@ -94,6 +101,27 @@ class InstallableLibrary extends AnnotationObject {
}
}
/**
* {@inheritdoc}
*/
public function __sleep() {
$vars = parent::__sleep();
// Exclude some variables from serializing.
$remove = [
'requestException',
'httpClient'
];
foreach ($remove as $key) {
$index = array_search($key, $vars);
if ($index !== FALSE) {
unset($vars[$index]);
}
}
return $vars;
}
public function createObjectRequirement(InstallablePlugin $definition = NULL) {
if ($this->object) {
$name = $this->getLink($this->customLabel) ?: $this->getId();
@@ -433,6 +461,30 @@ class InstallableLibrary extends AnnotationObject {
return $version && Semver::satisfies($version, '@stable');
}
/**
* Sets the directory where metadata about the library will be stored.
*
* @param string $directory
* The directory to set.
*/
public function setLibDirectory(string $directory) {
$this->directory = $directory;
}
/**
* Returns the directory where metadata about the library will be stored.
*
* @return string
* The directory to use.
*/
public function getLibDirectory(): string {
if (isset($this->directory)) {
return $this->directory;
}
// If not set, return a default.
return 'public://installable_plugins/library';
}
/**
* Requests a URL.
*
@@ -460,7 +512,7 @@ class InstallableLibrary extends AnnotationObject {
// Prepare the request.
$content = NULL;
$options = [];
$directory = 'public://installable_plugins/library';
$directory = $this->getLibDirectory();
\Drupal::service('file_system')->prepareDirectory(
$directory,
FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS
@@ -475,7 +527,7 @@ class InstallableLibrary extends AnnotationObject {
// Make the request.
try {
$response = static::httpClient()->get($url, $options);
$response = $this->getHttpClient()->request('GET', $url, $options);
$statusCode = $response->getStatusCode();
// New content.
Loading