Skip to content

Commit

Permalink
Merge pull request #11 from MarwanAlsoltany/dev
Browse files Browse the repository at this point in the history
Minor internal improvements and better documentation
  • Loading branch information
MarwanAlsoltany authored Jan 12, 2021
2 parents b5d47ea + add87b7 commit f53a0e3
Show file tree
Hide file tree
Showing 379 changed files with 5,722 additions and 2,386 deletions.
5 changes: 4 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
build:
environment:
variables:
COMPOSER_FLAGS: '--prefer-stable --prefer-dist'
nodes:
analysis:
project_setup:
Expand All @@ -10,7 +13,7 @@ filter:
excluded_paths: [build/*, docs/*, tests/*, vendor/*]

before_commands:
- "composer install --dev --prefer-source"
- "composer install $COMPOSER_FLAGS"

checks:
php:
Expand Down
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
preset: psr2
preset: psr12
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sudo: required
dist: xenial

os:
- linux

language: php

Expand All @@ -17,7 +20,7 @@ addons:
- rabbitmq-server

env:
matrix:
global:
- COMPOSER_FLAGS="--prefer-stable --prefer-dist"

cache:
Expand Down
80 changes: 72 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ All notable changes to **AMQP Agent** will be documented in this file.
## [Unreleased]


## [1.0.0] - 2020-06-15
<br />

## [[1.0.0] - 2020-06-15](https://github.com/MarwanAlsoltany/amqp-agent/commits/v1.0.0)
- Initial release.


## [1.0.1] - 2020-06-23
<br />

## [[1.0.1] - 2020-06-23](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.0.0...v1.0.1)
- Fix issue with Logger class:
- Fix additional line breaks when writing to log file.


## [1.1.0] - 2020-08-10
<br />

## [[1.1.0] - 2020-08-10](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.0.1...v1.1.0)
- Add the possibility to open multiple connection by a worker.
- Update `AbstractWorker` class:
- Add connections array and channels array.
Expand All @@ -27,7 +33,9 @@ All notable changes to **AMQP Agent** will be documented in this file.
- Rebuild documentation.


## [1.1.1] - 2020-09-14
<br />

## [[1.1.1] - 2020-09-14](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.0.1...v1.1.1)
- Update `composer.json`:
- Pump minimum **php-amqplib** version.
- Downgrade minimum php version.
Expand All @@ -46,7 +54,9 @@ All notable changes to **AMQP Agent** will be documented in this file.
- Rebuild documentation.


## [1.2.0] - 2020-09-26
<br />

## [[1.2.0] - 2020-09-26](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.1.1...v1.2.0)
- Update `composer.json`:
- Add a link for the documentation.
- Add some suggestions.
Expand Down Expand Up @@ -86,7 +96,9 @@ All notable changes to **AMQP Agent** will be documented in this file.
- Update formatting of `CHANGELOG.md`.


## [1.2.1] - 2020-09-30
<br />

## [[1.2.1] - 2020-09-30](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.2.0...v1.2.1)
- Update `composer.json`:
- Update `branch-alias` version.
- Update `Utility` class:
Expand All @@ -105,7 +117,9 @@ All notable changes to **AMQP Agent** will be documented in this file.
- Rebuild documentation.


## [1.2.2] - 2020-11-29
<br />

## [[1.2.2] - 2020-11-29](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.2.1...v1.2.2)
- Update `Config` class:
- Remove deprecated method `get()`.
- Remove `$configFlat` property and all of its references.
Expand Down Expand Up @@ -137,7 +151,9 @@ All notable changes to **AMQP Agent** will be documented in this file.
- Rebuild documentation.


## [2.0.0] - 2020-12-03
<br />

## [[2.0.0] - 2020-12-03](https://github.com/MarwanAlsoltany/amqp-agent/compare/v1.2.2...v2.0.0)
- Update `composer.json`:
- Update `branch-alias` version.
- Add RPC endpoints interfaces:
Expand Down Expand Up @@ -179,3 +195,51 @@ All notable changes to **AMQP Agent** will be documented in this file.
- Update old tests to cover the new changes.
- Update `phpunit.xml.dist` to run the new tests.
- Rebuild documentation.


<br />

## [[2.1.0] - 2021-01-12](https://github.com/MarwanAlsoltany/amqp-agent/compare/v2.0.0...v2.1.0)
- Update `composer.json`:
- Update `branch-alias` version.
- Update `scripts` field.
- Update `AbstractWorker` class
- Remove some useless code.
- Change exception type of `shutdown()` method to `AmqpAgentException`.
- Remove return value type hint `self` from methods signature due to unexpected behavior with different PHP versions.
- Update `Publisher` class
- Remove some useless code.
- Change exception type of `publish()` and `publishBatch()` methods to `AmqpAgentException`.
- Remove return value type hint `self` from methods signature due to unexpected behavior with different PHP versions.
- Update `Consumer` class
- Change `nack()` method wrong signature (remove default value from first parameter as it's useless).
- Update method signature on the corresponding interface (`ConsumerInterface`).
- Remove return value type hint `self` from methods signature due to unexpected behavior with different PHP versions.
- Update `WorkerCommandTrait`
- Remove some useless code.
- Update `WorkerMutationTrait`
- Change signature of `mutateClass()` method (remove default value from second parameter as it's useless).
- Change visibility of `mutateClass()` from protected to private (this method should never be used directly).
- Update `Config` class
- Add additional check for return value of `realpath()` function in class constructor.
- Remove return value type hint `self` from methods signature due to unexpected behavior with different PHP versions.
- Update `Utility` class
- Add additional check for script execution path in `execute()` method.
- Update `Logger` class
- Fix a wrong parameter type passed to third argument of `file_put_contents()` function.
- Update `Serializer` class
- Remove return value type hint `self` from methods signature due to unexpected behavior with different PHP versions.
- Update `ClassProxyTrait`
- Add additional check for `$fromObject` parameter of the `castObjectToClass()` method.
- Add a third parameter to the call of `AmqpAgentException::rethrow()` method.
- Update `AmqpAgentException`
- Change default value of `$wrap` parameter from `false` to `true` (this is the expected behavior according to parameter's description).
- Update tests to cover the new minor changes.
- Add `declare(strict_types=1)` to all files of the package.
- Update coding style to PSR12.
- Fix coding style issues in all files of the package.
- Fix DocBlocks in all files of the package.
- Fix typos in all files of the package.
- Update Continuous Integration config files.
- Update Development Dependencies config files.
- Rebuild documentation.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ An elegant wrapper around the famous php-amqplib for 90% use case.
</p>
</details>

<br />
<a href="https://twitter.com/intent/tweet?url=&text=Working%20with%20%23RabbitMQ%20in%20%23PHP%20has%20never%20been%20so%20easy%20and%20fun%2C%20check%20out%20AMQP%20Agent%20and%20stop%20wasting%20your%20time!%20https%3A%2F%2Fgithub.com%2FMarwanAlsoltany%2Famqp-agent%20" title="Tweet" target="_blank"><img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social" alt="Tweet"></a>
</div>

Expand Down Expand Up @@ -147,7 +146,7 @@ AMQP Agent exposes a number of concrete classes that can be directly used and ot
| [AbstractEndpoint](./src/RPC/AbstractEndpoint.php) <sup><code>*A</code></sup> | An abstract class implementing the basic functionality of an endpoint. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_RPC_AbstractEndpoint.html) |
| [ClientEndpoint](./src/RPC/ClientEndpoint.php) <sup><code>*C</code></sup> | A class specialized in requesting. Implementing only the methods needed for a client. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_RPC_ClientEndpoint.html) |
| [ServerEndpoint](./src/RPC/ServerEndpoint.php) <sup><code>*C</code></sup> | A class specialized in responding. Implementing only the methods needed for a server. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_RPC_ServerEndpoint.html) |
| [AmqpAgentParameters](./src/Config/Utility.php) <sup><code>*C\*H</code></sup> | A class that encapsulates all AMQP Agent parameters as constants. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_Config_AmqpAgentParameters.html) |
| [AmqpAgentParameters](./src/Config/Utility.php) <sup><code>*C\*H</code></sup> | A class that contains all AMQP Agent parameters as constants. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_Config_AmqpAgentParameters.html) |
| [Utility](./src/Helper/Utility.php) <sup><code>*C\*H</code></sup> | A class containing miscellaneous helper functions. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_Helper_Utility.html) |
| [Event](./src/Helper/Event.php) <sup><code>*C\*H</code></sup> | A simple class for handling events (dispatching and listening). | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_Helper_Event.html) |
| [ArrayProxy](./src/Helper/ArrayProxy.php) <sup><code>*C\*H</code></sup> | A class containing methods for for manipulating and working arrays. | [Doc](https://marwanalsoltany.github.io/amqp-agent/classes/MAKS_AmqpAgent_Helper_ArrayProxy.html) |
Expand All @@ -167,7 +166,7 @@ AMQP Agent exposes a number of concrete classes that can be directly used and ot
* <code>*A</code> **Abstract:** This class is an abstract class and cannot be instantiated directly.
* <code>*H</code> **Helper:** This class is a helper class. Third-party alternatives can be freely used instead.
* <code>*R</code> **Recommended:** This class is recommended to be used when working with AMQP Agent (best practice).
* <code>*S</code> **Singleton:** This class has a singleton version available via suffixing the class name with `Singleton` i.e. `PublisherSingleton` and can be retrieved via `*Singleton::getInstance()`.
* <code>*S</code> **Singleton:** This class has a singleton version available via suffixing the class name with `Singleton` and can be retrieved via `*Singleton::getInstance()`, i.e. `Publisher` -> `PublisherSingleton`.

![#ff6347](https://via.placeholder.com/11/f03c15/000000?text=+) **Note:** *Singleton is considered an anti-pattern, try avoiding it as much as possible, though there are use-cases for it. Use singletons only if you know what you are doing.*

Expand Down Expand Up @@ -293,7 +292,7 @@ $rpcServerB = $client->getServerEndpoint(); // or $client->get('server.endpoint'

#### Here are some examples of a publisher

1. **Variant I:** Passing parameters in workers constructor.
1. **Variant I:** Passing parameters in worker's constructor.

```php
// Publisher Demo 1
Expand Down Expand Up @@ -412,7 +411,7 @@ $publisher->disconnect();

#### Here are some examples of a consumer

1. **Variant I:** Passing parameters in workers constructor.
1. **Variant I:** Passing parameters in worker's constructor.

```php
// Consumer Demo 1
Expand Down Expand Up @@ -489,7 +488,7 @@ $consumer->queue([
'queue' => 'test.messages.queue'
]);
$consumer->qos([
'prefetch_count' => 10
'prefetch_count' => 10
]);
$consumer->consume(
[
Expand All @@ -510,7 +509,7 @@ $consumer->disconnect();

#### Here are some examples of an RPC client

1. **Variant I:** Passing parameters in workers constructor.
1. **Variant I:** Passing parameters in client's constructor.
```php
// RPC Client Demo 1

Expand Down Expand Up @@ -555,7 +554,7 @@ $rpcClient->disconnect();

#### Here are some examples of an RPC server

1. **Variant I:** Passing parameters in workers constructor.
1. **Variant I:** Passing parameters in server's constructor.
```php
// RPC Server Demo 1

Expand Down Expand Up @@ -868,7 +867,7 @@ $consumer->disconnect();
```

* **RPC Client Example:**
You will see here how you would send request to the RPC Server and add additional functionality to the endpoint by used the events it offers.
You will see here how you would send request to the RPC Server and add additional functionality to the endpoint by using the events it offers.

```php
// Advanced RPC Client Demo
Expand All @@ -880,7 +879,7 @@ use MAKS\AmqpAgent\RPC\ClientEndpoint;
$config = new Config();
$client = new Client($config);

// Retrieving a client endpoint from the client.
// Retrieving an RPC client endpoint from the client.
/** @var \MAKS\AmqpAgent\RPC\ClientEndpoint */
$rpcClient = $client->getClientEndpoint();

Expand Down Expand Up @@ -910,7 +909,7 @@ $rpcClient->disconnect();
```

* **RPC Server Example:**
You will see here how you would respond to request from the RPC Client and add additional functionality to the endpoint by used the events it offers.
You will see here how you would respond to request from the RPC Client and add additional functionality to the endpoint by using the events it offers.

```php
// Advanced RPC Server Demo
Expand All @@ -922,18 +921,19 @@ use MAKS\AmqpAgent\RPC\ServerEndpoint;
$config = new Config();
$client = new Client($config);

// Retrieving a consumer from the client.
// Retrieving an RPC server from the client.
/** @var \MAKS\AmqpAgent\RPC\ServerEndpoint */
$rpcServer = $client->getServerEndpoint();

// Attaching some additional functionality based on events emitted by the endpoint.
// See $rpcServer->on() and $rpcServer->getEvents() methods for more info.
$rpcServer->on('request.on.get', function ($response, $rpcServer, $eventName) {
printf('%s has emitted [%s] event and has just got a request!', get_class($rpcServer), $eventName);
if ($response instanceof AMQPMessage) {
printf(' The request has the following body: %s', $response->body;
}
});
$rpcServer
->on('request.on.get', function ($request, $rpcServer, $eventName) {
printf('%s has emitted [%s] event and has just got a request!', get_class($rpcServer), $eventName);
if ($request instanceof AMQPMessage) {
printf(' The request has the following body: %s', $request->body;
}
});

$rpcServer->connect();
$request = $rpcServer->respond('YourNamespace\YourClass::yourCallback');
Expand Down Expand Up @@ -980,12 +980,12 @@ Copyright (c) 2020 Marwan Al-Soltany. All rights reserved.
[styleci-icon]: https://github.styleci.io/repos/271944962/shield?branch=master

[php-href]: https://github.com/MarwanAlsoltany/amqp-agent/search?l=php
[version-href]: https://github.com/MarwanAlsoltany/amqp-agent/tree/master
[version-href]: https://packagist.org/packages/marwanalsoltany/amqp-agent
[license-href]: ./LICENSE
[maintenance-href]: https://github.com/MarwanAlsoltany/amqp-agent/graphs/commit-activity
[documentation-href]: http://marwanalsoltany.github.io/amqp-agent
[downloads-href]: https://packagist.org/packages/marwanalsoltany/amqp-agent
[travis-href]: https://travis-ci.org/MarwanAlsoltany/amqp-agent
[downloads-href]: https://packagist.org/packages/marwanalsoltany/amqp-agent/stats
[travis-href]: https://travis-ci.com/MarwanAlsoltany/amqp-agent
[scrutinizer-href]: https://scrutinizer-ci.com/g/MarwanAlsoltany/amqp-agent/build-status/master
[scrutinizer-coverage-href]: https://scrutinizer-ci.com/g/MarwanAlsoltany/amqp-agent/?branch=master
[scrutinizer-quality-href]: https://scrutinizer-ci.com/g/MarwanAlsoltany/amqp-agent/?branch=maste
Expand Down
38 changes: 21 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,30 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "2.1-dev"
}
},
"scripts": {
"sniff": "vendor/bin/phpcs --report=xml --report-file=build/phpcs/index.xml src",
"sniff-global": "phpcs --report=xml --report-file=build/phpcs/index.xml src",
"detect": "vendor/bin/phpmd src xml naming,unusedcode --reportfile build/phpmd/index.xml --strict --ignore-violations-on-exit",
"detect-global": "phpmd src xml naming,unusedcode --reportfile build/phpmd/index.xml --strict --ignore-violations-on-exit",
"test": "vendor/bin/phpunit",
"test-global": "phpunit",
"measure": "vendor/bin/phploc src --log-xml=build/phploc/index.xml",
"measure-global": "phploc src --log-xml=build/phploc/index.xml",
"document": "vendor/bin/phpdox",
"document-global": "phpdox",
"build": "composer run sniff && composer run detect && composer run test && composer run measure && composer run document",
"build-global": "composer run sniff-global && composer run detect-global && composer run test-global && composer run measure-global && composer run document-global",
"build-dev": "composer run-script --dev --verbose build && echo \"Development build completed!\"",
"build-dev-global": "composer run-script --dev --verbose build-global && echo \"Development build completed! [GLOBAL]\"",
"build-prod": "composer run-script --quiet build && echo \"Production build completed!\"",
"build-prod-global": "composer run-script --quiet build-global && echo \"Production build completed! [GLOBAL]\""
"sniff": "phpcs --report=xml --report-file=build/phpcs/index.xml src",
"detect": "phpmd src xml naming,unusedcode --reportfile build/phpmd/index.xml --strict --ignore-violations-on-exit",
"test": "phpunit",
"measure": "phploc src --log-xml=build/phploc/index.xml",
"document": "phpdox",
"build": [
"@sniff",
"@detect",
"@test",
"@measure",
"@document"
],
"build-dev": [
"composer run-script build --dev --verbose",
"echo ! && echo ! Development build completed! && echo !"
],
"build-prod": [
"composer run-script build --quiet",
"echo ! && echo ! Production build completed! && echo !"
]
},
"config": {
"optimize-autoloader": true,
Expand Down
8 changes: 4 additions & 4 deletions docs/classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h2 id="MAKS_AmqpAgent_Config">\MAKS\AmqpAgent\Config</h2>
<td>
<a href="classes/MAKS_AmqpAgent_Config_AmqpAgentParameters.html">AmqpAgentParameters</a>
</td>
<td>A class that encapsulates all AMQP Agent parameters as constants.</td>
<td>A class that contains all AMQP Agent parameters as constants.</td>
<td class="testresult-EMPTY">EMPTY
</td>
</tr>
Expand All @@ -139,7 +139,7 @@ <h2 id="MAKS_AmqpAgent_Config">\MAKS\AmqpAgent\Config</h2>
<td>
<a href="classes/MAKS_AmqpAgent_Config_RPCEndpointParameters.html">RPCEndpointParameters</a>
</td>
<td>A subset of AmqpAgentParameters class for RPC Endpoints class.</td>
<td>A subset of AmqpAgentParameters class for RPC Endpoints classes.</td>
<td class="testresult-EMPTY">EMPTY
</td>
</tr>
Expand Down Expand Up @@ -246,7 +246,7 @@ <h2 id="MAKS_AmqpAgent_Helper">\MAKS\AmqpAgent\Helper</h2>
<td>
<a href="classes/MAKS_AmqpAgent_Helper_ArrayProxy.html">ArrayProxy</a>
</td>
<td>A class containing methods for for manipulating and working arrays.</td>
<td>A class containing methods for for manipulating and working with arrays.</td>
<td class="testresult-EMPTY">EMPTY
</td>
</tr>
Expand Down Expand Up @@ -404,7 +404,7 @@ <h2 id="MAKS_AmqpAgent_Worker">\MAKS\AmqpAgent\Worker</h2>
</div>
</div>
<footer>
<span>Generated using phpDox 0.12.0-dev - Copyright (C) 2010 - 2020 by Arne Blankerts and Contributors</span>
<span>Generated using phpDox 0.12.0-dev - Copyright (C) 2010 - 2021 by Arne Blankerts and Contributors</span>
</footer>
</body>
</html>
Loading

0 comments on commit f53a0e3

Please sign in to comment.