diff --git a/examples/partial-updates/async-client.php b/examples/partial-updates/async-client.php index 6852423..e6865fc 100644 --- a/examples/partial-updates/async-client.php +++ b/examples/partial-updates/async-client.php @@ -14,20 +14,23 @@ // on successful creation function (ClientInterface $client) { $hosts = ['google.com', 'facebook.com', 'github.com', 'wikipedia.org']; - $client->submit("ping", $hosts)->then(function (TaskInterface $task) { - printf("Pinging: %s [handle:%s]\n", - implode(", ", $task->getWorkload()), + $client->submit("ping", serialize($hosts))->then(function (TaskInterface $task) { + printf( + "Pinging: %s [handle:%s]\n", + implode(", ", unserialize($task->getWorkload())), $task->getHandle() ); $task->on('data', function (TaskDataEvent $event) { echo "Partial update:\n"; - print_r($event->getData()); + print_r(unserialize($event->getData())); + echo "\n"; }); $task->on('complete', function (TaskDataEvent $event, ClientInterface $client) { echo "Final result: \n"; - print_r($event->getData()); + print_r(unserialize($event->getData())); + echo "\n"; $client->disconnect(); }); }); diff --git a/examples/partial-updates/async-worker.php b/examples/partial-updates/async-worker.php index aba13d1..671d711 100644 --- a/examples/partial-updates/async-worker.php +++ b/examples/partial-updates/async-worker.php @@ -18,7 +18,7 @@ function (WorkerInterface $worker) use ($factory) { $worker->setId('Test-Client/' . getmypid()); $worker->register('ping', function (JobInterface $job) { $result = []; - $hosts = $job->getWorkload(); + $hosts = unserialize($job->getWorkload()); $pingHost = function () use (&$hosts, &$result, $job, &$pingHost) { $host = array_shift($hosts); diff --git a/examples/partial-updates/traditional-worker.php b/examples/partial-updates/traditional-worker.php index 7752ded..4825681 100644 --- a/examples/partial-updates/traditional-worker.php +++ b/examples/partial-updates/traditional-worker.php @@ -26,8 +26,8 @@ if (!@$worker->wait()) { if ($worker->returnCode() == GEARMAN_NO_ACTIVE_FDS) { # We are not connected to any servers, so wait a bit before - # trying to reconnect. - sleep(5); + # trying to reconnect. + sleep(5); continue; } break; diff --git a/examples/simple/async-client.php b/examples/simple/async-client.php index acfafc3..a816780 100644 --- a/examples/simple/async-client.php +++ b/examples/simple/async-client.php @@ -5,7 +5,7 @@ use Zikarsky\React\Gearman\TaskInterface; use Zikarsky\React\Gearman\Factory; -require_once __DIR__ . "/../vendor/autoload.php"; +require_once __DIR__ . "/../../vendor/autoload.php"; // use default options $factory = new Factory(); @@ -14,7 +14,8 @@ // on successful creation function (ClientInterface $client) { $client->submit("reverse", "Hallo Welt!")->then(function (TaskInterface $task) { - printf("Submitted: %s with \"%s\" [handle: %s]\n", + printf( + "Submitted: %s with \"%s\" [handle: %s]\n", $task->getFunction(), $task->getWorkload(), $task->getHandle() diff --git a/examples/simple/async-worker.php b/examples/simple/async-worker.php index 638fa62..2c1937f 100644 --- a/examples/simple/async-worker.php +++ b/examples/simple/async-worker.php @@ -5,7 +5,7 @@ use Zikarsky\React\Gearman\JobInterface; use Zikarsky\React\Gearman\Factory; -require_once __DIR__ . "/../vendor/autoload.php"; +require_once __DIR__ . "/../../vendor/autoload.php"; // use default options $factory = new Factory(); diff --git a/examples/simple/traditional-worker.php b/examples/simple/traditional-worker.php index 44eecde..9b54fcb 100644 --- a/examples/simple/traditional-worker.php +++ b/examples/simple/traditional-worker.php @@ -28,8 +28,8 @@ if (!@$worker->wait()) { if ($worker->returnCode() == GEARMAN_NO_ACTIVE_FDS) { # We are not connected to any servers, so wait a bit before - # trying to reconnect. - sleep(5); + # trying to reconnect. + sleep(5); continue; } break; diff --git a/src/Command/Binary/Command.php b/src/Command/Binary/Command.php index 9416645..a7865cc 100644 --- a/src/Command/Binary/Command.php +++ b/src/Command/Binary/Command.php @@ -46,14 +46,10 @@ public function set($key, $value) throw new InvalidArgumentException($this->type->getName() . " does not have a $key argument"); } - if (!is_scalar($value)) { - $value = serialize($value); - } - $this->data[$key] = $value; } - public function get($key, $default = null, $serialized = false) + public function get($key, $default = null) { if (!$this->type->hasArgument($key)) { throw new InvalidArgumentException($this->type->getName() . " does not have a $key argument"); @@ -61,18 +57,14 @@ public function get($key, $default = null, $serialized = false) $data = isset($this->data[$key]) ? $this->data[$key] : $default; - if (false === $serialized && $key == self::DATA && self::isSerialized($data)) { - $data = unserialize($data); - } - return $data; } - public function getAll($default = null, $serialized = false) + public function getAll($default = null) { $args = []; foreach ($this->type->getArguments() as $arg) { - $args[$arg] = $this->get($arg, $default, $serialized); + $args[$arg] = $this->get($arg, $default); } return $args; @@ -92,9 +84,4 @@ public function getMagic() { return $this->magic; } - - private static function isSerialized($data) - { - return $data == serialize(false) || @unserialize($data) !== false; - } } diff --git a/src/Command/Binary/ReadBuffer.php b/src/Command/Binary/ReadBuffer.php index 0f165ad..c9ec168 100644 --- a/src/Command/Binary/ReadBuffer.php +++ b/src/Command/Binary/ReadBuffer.php @@ -122,8 +122,8 @@ protected function handleBuffer($buffer) { $len = strlen($buffer); - // @codeCoverageIgnoreStart - // This is an internal safeguard which is not testable + // @codeCoverageIgnoreStart + // This is an internal safeguard which is not testable if ($len != $this->requiredBytes) { throw new InvalidArgumentException("Expected a string with length of $this->requiredBytes. Got $len bytes"); } diff --git a/src/JobInterface.php b/src/JobInterface.php index e1f82f7..ff30211 100644 --- a/src/JobInterface.php +++ b/src/JobInterface.php @@ -19,11 +19,11 @@ interface JobInterface const STATUS_FAILED = "failed"; - /** - * Get the function-name of this job - * - * @return string - */ + /** + * Get the function-name of this job + * + * @return string + */ public function getFunction(); /**