Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace jeremeamia/superclosure with opis/closure #37238

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/37238
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Change: Replace jeremeamia/superclosure with opis/closure

jeremeamia/superclosure library is no longer maintained.
Replace it with the recommended opis/closure library.

https://github.com/owncloud/core/pull/37238
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"php": ">=7.1",
"doctrine/dbal": "^2.8",
"phpseclib/phpseclib": "^2.0",
"jeremeamia/superclosure": "^2.4",
"opis/closure": "^3.5",
"bantu/ini-get-wrapper": "v1.0.1",
"punic/punic": "^3.1",
"pear/archive_tar": "1.4.9",
Expand Down
230 changes: 62 additions & 168 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions lib/private/Command/AsyncBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use OCP\Command\IBus;
use OCP\Command\ICommand;
use SuperClosure\Serializer;
use Opis\Closure\SerializableClosure;

/**
* Asynchronous command bus that uses the background job system as backend
Expand Down Expand Up @@ -103,8 +103,7 @@ private function getJobClass($command) {
*/
private function serializeCommand($command) {
if ($command instanceof \Closure) {
$serializer = new Serializer();
return $serializer->serialize($command);
return \serialize(new SerializableClosure($command));
} elseif (\is_callable($command) or $command instanceof ICommand) {
return \serialize($command);
} else {
Expand Down
15 changes: 8 additions & 7 deletions lib/private/Command/ClosureJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
namespace OC\Command;

use OC\BackgroundJob\QueuedJob;
use SuperClosure\Serializer;

class ClosureJob extends QueuedJob {
protected function run($serializedCallable) {
$serializer = new Serializer();
$callable = $serializer->unserialize($serializedCallable);
if (\is_callable($callable)) {
$callable();
} else {
throw new \InvalidArgumentException('Invalid serialized callable');
$serializedClosure = \unserialize($serializedCallable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare result with false to avoid getClosure() on false below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used method_exists because it is also nice to know that the unserialized "thing" is an object that has the required method. I checked that if $serializedClosure is not even an object (e.g. is false or "abc" or...) then method_exists happily returns false.

if (\method_exists($serializedClosure, 'getClosure')) {
$callable = $serializedClosure->getClosure();
if (\is_callable($callable)) {
$callable();
return;
}
}
throw new \InvalidArgumentException('Invalid serialized callable');
}
}