Skip to content

Commit

Permalink
Merge pull request #45 from php-enqueue/add-psr-prefix-to-classes
Browse files Browse the repository at this point in the history
[transport] Add Psr prefix to transport interfaces. Deprecates old ones.
  • Loading branch information
makasim authored Apr 7, 2017
2 parents c6281e9 + ec0c0be commit a845c7a
Show file tree
Hide file tree
Showing 138 changed files with 1,046 additions and 986 deletions.
36 changes: 18 additions & 18 deletions docs/bundle/job_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ Guaranty that there is only single job running with such name.

```php
<?php
use Enqueue\Psr\Message;
use Enqueue\Psr\Processor;
use Enqueue\Psr\Context;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Psr\PsrContext;
use Enqueue\Util\JSON;
use Enqueue\JobQueue\JobRunner;
use Enqueue\JobQueue\Job;

class ReindexProcessor implements Processor
class ReindexProcessor implements PsrProcessor
{
/**
* @var JobRunner
*/
private $jobRunner;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$data = JSON::decode($message->getBody());

Expand Down Expand Up @@ -57,11 +57,11 @@ use Enqueue\JobQueue\JobRunner;
use Enqueue\JobQueue\Job;
use Enqueue\Client\ProducerInterface;
use Enqueue\Util\JSON;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrProcessor;

class Step1Processor implements Processor
class Step1Processor implements PsrProcessor
{
/**
* @var JobRunner
Expand All @@ -73,7 +73,7 @@ class Step1Processor implements Processor
*/
private $producer;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$data = JSON::decode($message->getBody());

Expand Down Expand Up @@ -104,14 +104,14 @@ class Step1Processor implements Processor
}
}

class Step2Processor implements Processor
class Step2Processor implements PsrProcessor
{
/**
* @var JobRunner
*/
private $jobRunner;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$data = JSON::decode($message->getBody());

Expand All @@ -124,7 +124,7 @@ class Step2Processor implements Processor
}
);

return $result ? Result::ACK : Result::REJECT;
return $result ? self::ACK : self::REJECT;
}
}
```
Expand All @@ -140,11 +140,11 @@ use Enqueue\JobQueue\JobRunner;
use Enqueue\JobQueue\Job;
use Enqueue\JobQueue\DependentJobService;
use Enqueue\Util\JSON;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrProcessor;

class ReindexProcessor implements Processor
class ReindexProcessor implements PsrProcessor
{
/**
* @var JobRunner
Expand All @@ -156,7 +156,7 @@ class ReindexProcessor implements Processor
*/
private $dependentJob;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$data = JSON::decode($message->getBody());

Expand Down
8 changes: 4 additions & 4 deletions docs/bundle/message_processor.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ It allows to keep subscription login and process logic closer to each other.
namespace AppBundle\Async;
use Enqueue\Client\TopicSubscriberInterface;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrProcessor;
class SayHelloProcessor implements Processor, TopicSubscriberInterface
class SayHelloProcessor implements PsrProcessor, TopicSubscriberInterface
{
public static function getSubscribedTopics()
{
Expand All @@ -51,9 +51,9 @@ On the topic subscriber you can also define queue and processor name:
```php
<?php
use Enqueue\Client\TopicSubscriberInterface;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrProcessor;
class SayHelloProcessor implements Processor, TopicSubscriberInterface
class SayHelloProcessor implements PsrProcessor, TopicSubscriberInterface
{
public static function getSubscribedTopics()
{
Expand Down
10 changes: 5 additions & 5 deletions docs/bundle/quick_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ To consume messages you have to first create a message processor:

```php
<?php
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Client\TopicSubscriberInterface;

class FooProcessor implements Processor, TopicSubscriberInterface
class FooProcessor implements PsrProcessor, TopicSubscriberInterface
{
public function process(Message $message, Context $session)
public function process(PsrMessage $message, PsrContext $session)
{
echo $message->getBody();

Expand Down
52 changes: 26 additions & 26 deletions docs/consumption/message_processor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Here's example:

```php
<?php
use Enqueue\Psr\Processor;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;

class SendMailProcessor implements Processor
class SendMailProcessor implements PsrProcessor
{
public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$this->mailer->send('[email protected]', $message->getBody());

Expand All @@ -26,14 +26,14 @@ Sometimes you have to reject messages explicitly.

```php
<?php
use Enqueue\Psr\Processor;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Util\JSON;

class SendMailProcessor implements Processor
class SendMailProcessor implements PsrProcessor
{
public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$data = JSON::decode($message->getBody());
if ($user = $this->userRepository->find($data['userId'])) {
Expand All @@ -53,13 +53,13 @@ If it returns true than there was attempt to process message.

```php
<?php
use Enqueue\Psr\Processor;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;

class SendMailProcessor implements Processor
class SendMailProcessor implements PsrProcessor
{
public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
if ($message->isRedelivered()) {
return self::REQUEUE;
Expand All @@ -76,13 +76,13 @@ The second argument is your context. You can use it to send messages to other qu

```php
<?php
use Enqueue\Psr\Processor;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;

class SendMailProcessor implements Processor
class SendMailProcessor implements PsrProcessor
{
public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$this->mailer->send('[email protected]', $message->getBody());

Expand All @@ -99,17 +99,17 @@ The consumption component provide some useful extensions, for example there is a

```php
<?php
use Enqueue\Psr\Processor;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Consumption\ChainExtension;
use Enqueue\Consumption\QueueConsumer;
use Enqueue\Consumption\Extension\ReplyExtension;
use Enqueue\Consumption\Result;

class SendMailProcessor implements Processor
class SendMailProcessor implements PsrProcessor
{
public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$this->mailer->send('[email protected]', $message->getBody());

Expand All @@ -119,7 +119,7 @@ class SendMailProcessor implements Processor
}
}

/** @var \Enqueue\Psr\Context $psrContext */
/** @var \Enqueue\Psr\PsrContext $psrContext */

$queueConsumer = new QueueConsumer($psrContext, new ChainExtension([
new ReplyExtension()
Expand Down
16 changes: 8 additions & 8 deletions docs/job_queue/run_sub_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ They will be executed in parallel.
```php
<?php
use Enqueue\Client\ProducerInterface;
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrProcessor;
use Enqueue\JobQueue\JobRunner;
use Enqueue\JobQueue\Job;
use Enqueue\Util\JSON;

class RootJobProcessor implements Processor
class RootJobProcessor implements PsrProcessor
{
/** @var JobRunner */
private $jobRunner;

/** @var ProducerInterface */
private $producer;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$result = $this->jobRunner->runUnique($message->getMessageId(), 'aJobName', function (JobRunner $runner) {
$runner->createDelayed('aSubJobName1', function (JobRunner $runner, Job $childJob) {
Expand All @@ -39,12 +39,12 @@ class RootJobProcessor implements Processor
}
}

class SubJobProcessor implements Processor
class SubJobProcessor implements PsrProcessor
{
/** @var JobRunner */
private $jobRunner;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$data = JSON::decode($message->getBody());

Expand All @@ -54,7 +54,7 @@ class SubJobProcessor implements Processor
return true;
});

return $result ? Result::ACK : Result::REJECT;
return $result ? self::ACK : self::REJECT;
}
}
```
Expand Down
10 changes: 5 additions & 5 deletions docs/job_queue/run_unique_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ It shows how you can run unique job using job queue (The configuration is descri

```php
<?php
use Enqueue\Psr\Message;
use Enqueue\Psr\Context;
use Enqueue\Psr\Processor;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrProcessor;
use Enqueue\JobQueue\JobRunner;

class UniqueJobProcessor implements Processor
class UniqueJobProcessor implements PsrProcessor
{
/** @var JobRunner */
private $jobRunner;

public function process(Message $message, Context $context)
public function process(PsrMessage $message, PsrContext $context)
{
$result = $this->jobRunner->runUnique($message->getMessageId(), 'aJobName', function () {
// do your job, there is no any other processes executing same job,
Expand Down
Loading

0 comments on commit a845c7a

Please sign in to comment.