Skip to content

Commit

Permalink
Merge pull request #67 from sadikoff/master
Browse files Browse the repository at this point in the history
Bundle restructuration and composer 2.0 fix
  • Loading branch information
laupiFrpar authored Sep 24, 2020
2 parents 02d8950 + 3c17d17 commit 2421948
Show file tree
Hide file tree
Showing 29 changed files with 688 additions and 382 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ xcuserdata
# svn & cvs
.svn
CVS

.php_cs.cache
vendor

composer.lock
*.sublime-workspace
.phpunit.result.cache
phpunit.xml
29 changes: 29 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

if (!file_exists(__DIR__.'/src') || !file_exists(__DIR__.'/tests')) {
exit(0);
}

$finder = PhpCsFixer\Finder::create()
->in([__DIR__.'/src', __DIR__.'/tests'])
;

return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false,
'semicolon_after_instruction' => false,
'phpdoc_to_comment' => false,
'header_comment' => [
'header' => <<<EOF
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF
]
))
->setRiskyAllowed(true)
->setFinder($finder)
;
26 changes: 14 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ language: php
php:
- 7.2
- 7.3
- hhvm
- 7.4

matrix:
allow_failures:
- php: hhvm
include:
- php: 7.2
env: SYMFONY_VERSION=4.2.*
- php: 7.3
env: SYMFONY_VERSION=4.2.*
env: SYMFONY_REQUIRE=4.4.*
- php: 7.4
env: SYMFONY_REQUIRE=5.1.*

env:
- SYMFONY_VERSION=3.4.*
- SYMFONY_REQUIRE=3.4.*

before_script:
before_install:
- find ~/.phpenv -name xdebug.ini -delete
- composer self-update
- composer require symfony/config:${SYMFONY_VERSION} --no-update
- composer require symfony/dependency-injection:${SYMFONY_VERSION} --no-update
- composer require symfony/http-kernel:${SYMFONY_VERSION} --no-update
- composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master
- composer update --prefer-source

script: phpunit
install:
- vendor/bin/simple-phpunit install

script:
- vendor/bin/simple-phpunit
- vendor/bin/php-cs-fixer fix --dry-run --diff

notifications:
email: laupi.frpar@gmail.com
113 changes: 0 additions & 113 deletions Controller/AuthController.php

This file was deleted.

53 changes: 0 additions & 53 deletions DependencyInjection/PusherFactory.php

This file was deleted.

66 changes: 35 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ Use [composer](http://getcomposer.org) to install this bundle.
composer require laupifrpar/pusher-bundle
```

Then update your `AppKernel.php` file to register the new bundle:
If you're not using Symfony Flex, then you will also need to enable
`Lopi\Bundle\PusherBundle\LopiPusherBundle` in your `config/bundles.php` file.

```php
// in app/AppKernel::registerBundles()
<?php

$bundles = array(
return [
// ...
new Lopi\Bundle\PusherBundle\LopiPusherBundle(),
// ...
);
];
```

## Configuration
Expand Down Expand Up @@ -66,14 +67,14 @@ lopi_pusher:

It will parse the URL and set, or replace the default value if exists, the various parameters `scheme`, `key`, `secret`, `host`, `port` and `app_id`

Or you can set the various parameters separately :
Or you can set the various parameters separately:

```yml
# app/config/config.yml
lopi_pusher:
app_id: <app-id>
key: <key>
secret: <secret>
app_id: <app-id>
key: <key>
secret: <secret>
```

By default, calls will be made over a non-encrypted connection. To change this to
Expand All @@ -83,7 +84,7 @@ make calls over HTTPS, simply:
# app/config/config.yml
lopi_pusher:
# ...
scheme: https
scheme: https
port: 443
```

Expand All @@ -92,31 +93,36 @@ If you want to use private or presence channels, set the parameter `auth_service
```yml
# app/config/config.yml
lopi_pusher:
# ...
auth_service_id: <the_auth_service_id>
```

See the section about "Private and Presense channel auth" below

## Usage!

Once you've configured the bundle, you will have access to a `lopi_pusher.pusher`
service. From inside a controller, you can use it like this:
Once you've configured the bundle, you will have access to a pusher service,
which can be autowired by `Pusher\Pusher` typehint.
From inside a controller, you can use it like this:

```php
public function triggerPusherAction()
{
/** @var \Pusher $pusher */
$pusher = $this->container->get('lopi_pusher.pusher');
use Pusher\Pusher;
$data['message'] = 'hello world';
$pusher->trigger('test_channel', 'my_event', $data);
// ...
class SampleController
{
public function triggerPusherAction(Pusher $pusher)
{
// ...
$data['message'] = 'hello world';
$pusher->trigger('test_channel', 'my_event', $data);
// ...
}
}
```

The `lopi_pusher.pusher` returns an instance of the `\Pusher` class from the official
Pusher SDK. You can find out all about it on
This code will autowire `\Pusher\Pusher` class from the official Pusher SDK. You can find out all about it on
[pusher's documentation](https://github.com/pusher/pusher-php-server#publishingtriggering-events).

## Private and Presence channel authentication (optional)
Expand All @@ -127,9 +133,9 @@ First, create an authorization service that implements `Lopi\Bundle\PusherBundle

```php
<?php
// src/AppBundle/Pusher/ChannelAuthenticator.php
// src/Pusher/ChannelAuthenticator.php
namespace AppBundle\Pusher
namespace App\Pusher;
use Lopi\Bundle\PusherBundle\Authenticator\ChannelAuthenticatorInterface;
Expand All @@ -147,29 +153,27 @@ class ChannelAuthenticator implements ChannelAuthenticatorInterface
Next, register it as service like normal:

```yml
# app/config/services.yml
# config/services.yml
services:
my_channel_authenticator:
class: AppBundle\Pusher\ChannelAuthenticator
arguments: []
my_channel_authenticator: AppBundle\Pusher\ChannelAuthenticator
```

Then include its **service id** in the lopi_pusher `auth_service_id` configuration
parameter:

```yml
# app/config/config.yml
# config/packagers/lopi_pusher.yml
lopi_pusher:
# ...
auth_service_id: my_channel_authenticator
auth_service_id: 'my_channel_authenticator'
```

Additionally, enable the route by adding the following to your `app\config\routing.yml`
Additionally, enable the route by adding the following to your `config\routing.yml`
configuration:

```yml
# app\config\routing.yml
# config\routing.yml
lopi_pusher:
resource: "@LopiPusherBundle/Resources/config/routing.xml"
prefix: /pusher
Expand Down
Loading

0 comments on commit 2421948

Please sign in to comment.