コード例 #1
0
ファイル: Client.php プロジェクト: avz-cmf/zaboy-async
 public function __construct(Queue\Client $queue, $data)
 {
     $store = $queue->getStore()->getMessagesStore();
     $this->promisesStore = $queue->getStore()->getPromisesStore();
     $promise = new PromiseClient($this->promisesStore);
     $data = is_null($data) ? [Store::QUEUE_ID => $queue->getId(), Store::PROMISE => $promise->getId()] : is_array($data) ? array_merge($data, [Store::QUEUE_ID => $queue->getId(), Store::PROMISE => $promise->getId()]) : $data;
     parent::__construct($store, $data);
     $this->queue = $queue;
 }
コード例 #2
0
ファイル: ViaHttp.php プロジェクト: avz-cmf/zaboy-async
 public function interrupt($value, PromiseClient $promise, callable $callback)
 {
     $url = static::DEFAULT_URL;
     $promiseId = $promise->getId();
     $arrayData = compact('callback', 'value', 'promiseId');
     $serializedData = serialize($arrayData);
     $data64 = base64_encode($serializedData);
     return $this->async_http_post($url, $data64);
 }
コード例 #3
0
ファイル: Script.php プロジェクト: avz-cmf/zaboy-async
 public function interrupt($value, PromiseClient $promise, callable $callback)
 {
     if (is_null($this->script)) {
         $this->setScriptName(self::DEFAULT_SCRIPT_NAME);
     }
     // Files names for stdout and stderr
     $stdOutFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('stdout_', 1);
     $stdErrFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('stderr_', 1);
     $cmd = $this->commandPrefix . ' ' . $this->script;
     $promiseId = $promise->getId();
     $arrayData = compact('callback', 'value', 'promiseId');
     $serializedData = serialize($arrayData);
     $data64 = base64_encode($serializedData);
     $cmd .= ' ' . $data64;
     $cmd .= " 1>{$stdOutFilename} 2>{$stdErrFilename}";
     shell_exec($cmd);
     return $promise;
 }
コード例 #4
0
 /**
  *
  * Location: http://www.example.com/users/4/
  * http://www.restapitutorial.com/lessons/httpmethods.html
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  * @throws \zaboy\rest\RestException
  * @internal param callable|null $next
  */
 public function methodPostWithoutId(ServerRequestInterface $request, ResponseInterface $response)
 {
     $promise = new Client($this->store);
     $responseBody = $promise->toArray();
     $this->request = $request->withAttribute('Response-Body', $responseBody);
     $response = $response->withStatus(201);
     $insertedPrimaryKeyValue = $promise->getId();
     $location = $request->getUri()->getPath();
     $response = $response->withHeader('Location', rtrim($location, '/') . '/' . $insertedPrimaryKeyValue);
     return $response;
 }
コード例 #5
0
ファイル: PromiseTest.php プロジェクト: avz-cmf/zaboy-async
 public function testPromiseThen__ThenRejectedByPromiseButResolved()
 {
     $result = new Client($this->store);
     $promise1 = new Client($this->store);
     $this->object = $promise1->then(null, function ($reason) {
         return $reason->getMessage() . ' was resolved';
     });
     $promise1->reject($result);
     $this->assertEquals($result->getId() . ' was resolved', $this->object->wait(false));
     $this->assertEquals(PromiseInterface::FULFILLED, $this->object->getState());
 }
コード例 #6
0
use zaboy\scheduler\FileSystem\CommandLineWorker;
use zaboy\scheduler\Callback\CallbackException;
use zaboy\async\Promise\Store;
use zaboy\async\Promise\Client as Promise;
$commandLineWorker = new CommandLineWorker();
$options = $commandLineWorker->getCallOptions($_SERVER['argv']);
if (!isset($options['rpc_callback'])) {
    throw new CallbackException("The necessary parameter \"rpc_callback\" does not exist");
}
$callbackServiceName = $options['rpc_callback'];
unset($options['rpc_callback']);
/** @var Zend\ServiceManager\ServiceManager $container */
$container = (include './config/container.php');
/** @var zaboy\scheduler\Callback\CallbackManager $callbackManager */
$callbackManager = $container->get('callback_manager');
/** @var Store $store */
$store = $container->get('Store');
$promise = new Promise($store, $options['promise']);
unset($options['promise']);
try {
    if (is_callable($callbackServiceName)) {
        $result = call_user_func($callbackServiceName, $options);
    } elseif ($callbackManager->has($callbackServiceName)) {
        $result = $callbackManager->{$callbackServiceName}($options);
    } else {
        throw new CallbackException('Specified callback "' . print_r($callbackServiceName) . '" wasn\'t found');
    }
    $promise->resolve($result);
} catch (\Exception $e) {
    $promise->reject($e);
}
コード例 #7
0
 public function test_tryToChangeFulfilledPromise()
 {
     $promiseData = $this->object->create([]);
     $promiseData[Store::STATE] = Client::FULFILLED;
     $promiseData[Store::RESULT] = 'test_result_success_fulfill';
     $this->object->update($promiseData);
     $promise = new Client($this->store, $promiseData[Store::ID]);
     $result = $promise->wait(false);
     $this->assertEquals('test_result_success_fulfill', $result);
     $this->assertEquals(Client::FULFILLED, $promise->getState());
     $promiseData[Store::STATE] = Client::REJECTED;
     $this->setExpectedExceptionRegExp('\\zaboy\\rest\\DataStore\\DataStoreException');
     $this->object->update($promiseData);
 }