Skip to content

Commit a419850

Browse files
authored
Merge pull request #129 from jobbyphp/closure
replace: jeremeamia/superclosure with opis/closure
2 parents e57e905 + 39cbad6 commit a419850

File tree

7 files changed

+19
-59
lines changed

7 files changed

+19
-59
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
"require": {
1818
"php": ">=5.6",
1919
"dragonmantank/cron-expression": "^3.0",
20-
"jeremeamia/superclosure": "^2.2",
20+
"opis/closure": "^3.5",
2121
"swiftmailer/swiftmailer": "^5.4|^6.0",
2222
"symfony/process": "^2.7|^3.0|^4.0|^5.0"
2323
},
2424
"require-dev": {
25+
"mp091689/dump-die": "^1.0",
2526
"phpunit/phpunit": "^4.6",
2627
"symfony/filesystem": "^2.7|^3.0|^4.0|^5.0"
2728
},

src/BackgroundJob.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Jobby;
44

5+
use Opis\Closure\SerializableClosure;
6+
57
class BackgroundJob
68
{
7-
use SerializerTrait;
8-
99
/**
1010
* @var Helper
1111
*/
@@ -233,7 +233,7 @@ protected function log($message, $output = 'stdout')
233233

234234
protected function runFunction()
235235
{
236-
$command = $this->getSerializer()->unserialize($this->config['closure']);
236+
$command = unserialize($this->config['closure']);
237237

238238
ob_start();
239239
try {

src/Jobby.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
use Closure;
66
use DateTimeImmutable;
7-
use SuperClosure\SerializableClosure;
7+
use Opis\Closure\SerializableClosure;
88
use Symfony\Component\Process\PhpExecutableFinder;
99

1010
class Jobby
1111
{
12-
use SerializerTrait;
13-
1412
/**
1513
* @var array
1614
*/
@@ -207,7 +205,8 @@ protected function runWindows($job, array $config)
207205
protected function getExecutableCommand($job, array $config)
208206
{
209207
if (isset($config['closure'])) {
210-
$config['closure'] = $this->getSerializer()->serialize($config['closure']);
208+
$wrapper = new SerializableClosure($config['closure']);
209+
$config['closure'] = serialize($wrapper);
211210
}
212211

213212
if (strpos(__DIR__, 'phar://') === 0) {

src/SerializerTrait.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/BackgroundJobTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44

55
use Jobby\BackgroundJob;
66
use Jobby\Helper;
7-
use Jobby\SerializerTrait;
7+
use Opis\Closure\SerializableClosure;
88
use Symfony\Component\Filesystem\Filesystem;
99

1010
/**
1111
* @coversDefaultClass Jobby\BackgroundJob
1212
*/
1313
class BackgroundJobTest extends \PHPUnit_Framework_TestCase
1414
{
15-
use SerializerTrait;
16-
1715
const JOB_NAME = 'name';
1816

1917
/**
@@ -370,7 +368,8 @@ private function getJobConfig(array $config)
370368
$helper = new Helper();
371369

372370
if (isset($config['closure'])) {
373-
$config['closure'] = $this->getSerializer()->serialize($config['closure']);
371+
$wrapper = new SerializableClosure($config['closure']);
372+
$config['closure'] = serialize($wrapper);
374373
}
375374

376375
return array_merge(

tests/JobbyTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Jobby\Helper;
66
use Jobby\Jobby;
7-
use SuperClosure\SerializableClosure;
7+
use Opis\Closure\SerializableClosure;
88

99
/**
1010
* @coversDefaultClass Jobby\Jobby
@@ -97,7 +97,7 @@ public function testBackgroundProcessIsNotSpawnedIfJobIsNotDueToBeRun()
9797
* @covers ::add
9898
* @covers ::run
9999
*/
100-
public function testSuperClosure()
100+
public function testOpisClosure()
101101
{
102102
$fn = static function () {
103103
echo 'Another function!';
@@ -106,10 +106,15 @@ public function testSuperClosure()
106106
};
107107

108108
$jobby = new Jobby();
109+
$wrapper = new SerializableClosure($fn);
110+
$serialized = serialize($wrapper);
111+
$wrapper = unserialize($serialized);
112+
$closure = $wrapper->getClosure();
113+
109114
$jobby->add(
110115
'HelloWorldClosure',
111116
[
112-
'command' => new SerializableClosure($fn),
117+
'command' => $closure,
113118
'schedule' => '* * * * *',
114119
'output' => $this->logFile,
115120
]

tests/SerializerTraitTest.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)