Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
added doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bupy7 committed Sep 7, 2017
1 parent 2a56f95 commit cb3d997
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 2 deletions.
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ zf-queue
[![Build Status](https://travis-ci.org/bupy7/zf-queue.svg?branch=master)](https://travis-ci.org/bupy7/zf-queue)
[![Coverage Status](https://coveralls.io/repos/github/bupy7/zf-queue/badge.svg?branch=master)](https://coveralls.io/github/bupy7/zf-queue?branch=master)

Queue module for Zend Framework 3.
Abstract queue module for Zend Framework 3. Module contains **only** abstract layers to create
their own integrations using this module.

Installation
------------
Expand All @@ -29,10 +30,103 @@ or add

to the require section of your composer.json file.

Integration
-----------

### Ready integrations

- [Doctrine 2 ORM](example/QueueDoctrine)

### Create their own integration

TODO

Usage
-----

TODO
### Create and run task

**Let's create our first an example task for queue:**

```php
// YourModule/src/task/ExampleTask.php

namespace YourModule\Task;

use Bupy7\Queue\Task\TaskInterface;
use Zend\Stdlib\ParametersInterface;
use Chat\Service\ChatService;

class SendAccountTask implements TaskInterface
{
/**
* @var ChatService
*/
protected $mailService;

public function __construct(ChatService $chatService) {
$this->chatService = $chatService;
}

/**
* @param ParametersInterface $params
* - message (string)
* @return bool
*/
public function execute(ParametersInterface $params): bool
{
$this->chatService->send($params->get('message'));
return true;
}
}
```

**After you need to register task to queue manager**:

```php
// YouModule/config/queue.config.php

namespace YourModule;

return [
'queue_manager' => [
'factories' => [
Task\ExampleTask::class => \Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class,
],
],
];
```

**Now, add `queue.config.php` to your config list:**

```php
// YourModule/src/YourModule.php

class Module
{
public function getConfig(): array
{
return array_merge(

// another config files

require __DIR__ . '/../config/queue.config.php'
);
}
}
```

**Add the task to queue**

```php
$container->get('Bupy7\Queue\Service\TaskService')->add('YourModule\Task\ExampleTask');
```

**Run queue**

```php
$container->get('Bupy7\Queue\Service\QueueService')->run();
```

License
-------
Expand Down
38 changes: 38 additions & 0 deletions example/QueueDoctrine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
QueueDoctrine
=============

Example usage [zf-queue](https://github.com/bupy7/zf-queue) package for Doctrine 2 ORM.

Requirements
------------

- [Doctrine 2 ORM](https://github.com/doctrine/DoctrineORMModule)
- [Zend MVC](https://github.com/zendframework/zend-mvc)

Install
-------

1. Copy `QueueDoctrine` to your `module` directory.

2. Add `QueueDoctrine` to your config of module list.

4. Profit.

Usage
-----

1: [Create a task](https://github.com/bupy7/zf-queue/README.md#create-task)

2: Add the task to queue:

```php
$container->get('Bupy7\Queue\Service\TaskService')->add('Some\Task\TaskNameClass', [
'some' => 'param',
]);
```

3: Run queue:

```php
$container->get('Bupy7\Queue\Service\QueueService')->run();
```
16 changes: 16 additions & 0 deletions example/QueueDoctrine/config/cli.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace QueueDoctrine;

return [
'cli' => [
'commands' => [
Command\RunCommand::class,
],
],
'command_manager' => [
'factories' => [
Command\RunCommand::class => \Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class,
],
],
];
19 changes: 19 additions & 0 deletions example/QueueDoctrine/config/doctrine.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace QueueDoctrine;

return [
'doctrine' => [
'driver' => [
'queue_entity' => [
'class' => \Doctrine\ORM\Mapping\Driver\XmlDriver::class,
'paths' => __DIR__ . '/mapping',
],
'orm_default' => [
'drivers' => [
'QueueDoctrine\Entity' => 'queue_entity',
],
],
],
],
];
30 changes: 30 additions & 0 deletions example/QueueDoctrine/config/mapping/ExQueue.Entity.Task.dcm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="QueueDoctrine\Entity\Task" table="queue_task"
repository-class="QueueDoctrine\Repository\TaskRepository">

<indexes>
<index name="queue_task_idx_1" columns="status_id"/>
</indexes>

<lifecycle-callbacks>
<lifecycle-callback type="preFlush" method="preFlush"/>
</lifecycle-callbacks>

<id name="id" type="integer" column="id">
<generator strategy="IDENTITY"/>
</id>

<field name="name" type="string" column="name"/>
<field name="statusId" type="smallint" column="status_id"/>
<field name="createdAt" type="datetime" column="created_at"/>
<field name="runAt" type="datetime" column="run_at" nullable="true"/>
<field name="stopAt" type="datetime" column="stop_at" nullable="true"/>
<field name="numberErrors" type="smallint" column="number_errors"/>
<field name="params" type="params" column="params"/>
</entity>
</doctrine-mapping>
19 changes: 19 additions & 0 deletions example/QueueDoctrine/config/module.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace QueueDoctrine;

return [
'service_manager' => [
'factories' => [
Repository\TaskRepository::class => \ExDoctrine\Repository\RepositoryInvokableFactory::class,
Manager\EntityManager::class => \Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory::class,
\Bupy7\Queue\Service\QueueService::class => \QueueDoctrine\Service\QueueServiceFactory::class,
\Bupy7\Queue\Service\TaskService::class => \QueueDoctrine\Service\TaskServiceFactory::class,
],
],
\Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory::class => [
Manager\EntityManager::class => [
\Doctrine\ORM\EntityManager::class,
],
],
];
Loading

0 comments on commit cb3d997

Please sign in to comment.