Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit a7c47a0

Browse files
initial commit
0 parents  commit a7c47a0

15 files changed

+586
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea
2+
composer.lock
3+
vendor
4+
bin
5+
coverage
6+
coverage.xml
7+
gcloud-test-key.json

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7.0
6+
- 7.1
7+
- hhvm
8+
- nightly
9+
10+
before_script:
11+
- composer install

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM php:7.0-fpm
2+
MAINTAINER Superbalist <[email protected]>
3+
4+
RUN mkdir /opt/php-pubsub
5+
WORKDIR /opt/php-pubsub
6+
7+
# Packages
8+
RUN apt-get update \
9+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
10+
git \
11+
zlib1g-dev \
12+
unzip \
13+
&& rm -r /var/lib/apt/lists/*
14+
15+
# PHP Extensions
16+
RUN docker-php-ext-install -j$(nproc) zip
17+
18+
# Composer
19+
ENV COMPOSER_HOME /composer
20+
ENV PATH /composer/vendor/bin:$PATH
21+
ENV COMPOSER_ALLOW_SUPERUSER 1
22+
RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
23+
&& curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \
24+
&& php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" \
25+
&& php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --version=1.1.0 && rm -rf /tmp/composer-setup.php
26+
27+
# Install Composer Application Dependencies
28+
COPY composer.json /opt/php-pubsub/
29+
RUN composer install --no-autoloader --no-scripts --no-interaction
30+
31+
COPY src /opt/php/pubsub/
32+
COPY examples /opt/php/pubsub
33+
34+
RUN composer dump-autoload --no-interaction
35+
36+
CMD ["/bin/bash"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Superbalist.com a division of Takealot Online (Pty) Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: tests
2+
3+
up:
4+
@docker-compose rm -f
5+
@docker-compose pull
6+
@sed -e "s/HOSTIP/$$(docker-machine ip)/g" docker-compose.yml | docker-compose --file - up --build -d
7+
@docker-compose run php-pubsub-google-cloud /bin/bash
8+
9+
down:
10+
@docker-compose stop -t 1
11+
12+
tests:
13+
@./vendor/bin/phpunit --configuration phpunit.xml

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# php-pubsub-google-cloud
2+
3+
A Google Cloud adapter for the [php-pubsub](https://github.com/Superbalist/php-pubsub) package.
4+
5+
[![Author](http://img.shields.io/badge/[email protected]?style=flat-square)](https://twitter.com/superbalist)
6+
[![Build Status](https://img.shields.io/travis/Superbalist/php-pubsub-google-cloud/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/php-pubsub-google-cloud)
7+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
8+
[![Packagist Version](https://img.shields.io/packagist/v/superbalist/php-pubsub-google-cloud.svg?style=flat-square)](https://packagist.org/packages/superbalist/php-pubsub-google-cloud)
9+
[![Total Downloads](https://img.shields.io/packagist/dt/superbalist/php-pubsub-google-cloud.svg?style=flat-square)](https://packagist.org/packages/superbalist/php-pubsub-google-cloud)
10+
11+
12+
## Installation
13+
14+
```bash
15+
composer require superbalist/php-pubsub-google-cloud
16+
```
17+
18+
## Usage
19+
20+
```php
21+
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/../your-gcloud-key.json');
22+
23+
$client = new \Google\Cloud\PubSub\PubSubClient([
24+
'projectId' => 'your-project-id-here',
25+
]);
26+
27+
$adapter = new \Superbalist\PubSub\GoogleCloud\GoogleCloudPubSubAdapter($client);
28+
29+
// consume messages
30+
// note: this is a blocking call
31+
$adapter->subscribe('my_channel', function ($message) {
32+
var_dump($message);
33+
});
34+
35+
// publish messages
36+
$adapter->publish('my_channel', 'HELLO WORLD');
37+
$adapter->publish('my_channel', json_encode(['hello' => 'world']));
38+
$adapter->publish('my_channel', 1);
39+
$adapter->publish('my_channel', false);
40+
```
41+
42+
## Examples
43+
44+
The library comes with [examples](examples) for the adapter and a [Dockerfile](Dockerfile) for
45+
running the example scripts.
46+
47+
Run `make up`.
48+
49+
You will start at a `bash` prompt in the `/opt/php-pubsub` directory.
50+
51+
If you need another shell to publish a message to a blocking consumer, you can run `docker-compose run php-pubsub-google-cloud /bin/bash`
52+
53+
To run the examples:
54+
```bash
55+
$ php examples/GoogleCloudConsumerExample.php
56+
$ php examples/GoogleCloudPublishExample.php (in a separate shell)
57+
```

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 1.0.0 - 2016-09-05
4+
5+
* Initial release

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "superbalist/php-pubsub-google-cloud",
3+
"description": "A Google Cloud adapter for the php-pubsub package",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Superbalist.com a division of Takealot Online (Pty) Ltd",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"require": {
12+
"php": ">=5.6.0",
13+
"superbalist/php-pubsub": "^1.0",
14+
"google/cloud": "^0.7.0"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"Superbalist\\PubSub\\GoogleCloud\\": "src/",
19+
"Tests\\": "tests/"
20+
}
21+
},
22+
"extra": {
23+
"branch-alias": {
24+
"dev-master": "1.0-dev"
25+
}
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^5.5",
29+
"mockery/mockery": "^0.9.5"
30+
}
31+
}

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '2'
2+
services:
3+
php-pubsub-google-cloud:
4+
build: .
5+
volumes:
6+
- ./src:/opt/php-pubsub/src
7+
- ./examples:/opt/php-pubsub/examples
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
include __DIR__ . '/../vendor/autoload.php';
4+
5+
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/../your-gcloud-key.json');
6+
7+
$client = new \Google\Cloud\PubSub\PubSubClient([
8+
'projectId' => 'your-project-id-here',
9+
]);
10+
11+
$adapter = new \Superbalist\PubSub\GoogleCloud\GoogleCloudPubSubAdapter($client);
12+
13+
$adapter->subscribe('my_channel', function ($message) {
14+
var_dump($message);
15+
});

0 commit comments

Comments
 (0)