├── .gitignore ├── DependencyInjection ├── Configuration.php └── MinishlinkWebPushExtension.php ├── LICENSE ├── MinishlinkWebPushBundle.php ├── README.md ├── Resources └── config │ └── web_push.yml ├── Tests └── DependencyInjection │ └── MinishlinkWebPushExtensionTest.php ├── composer.json └── phpunit.xml.dist /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | .vscode/ -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | getRootNode() 18 | ->children() 19 | ->arrayNode('VAPID') 20 | ->children() 21 | ->scalarNode('subject') 22 | ->end() 23 | ->scalarNode('publicKey') 24 | ->end() 25 | ->scalarNode('privateKey') 26 | ->end() 27 | ->scalarNode('pemFile') 28 | ->end() 29 | ->scalarNode('pem') 30 | ->end() 31 | ->end() 32 | ->end() 33 | ->integerNode('ttl') 34 | ->defaultValue(2419200) 35 | ->end() 36 | ->scalarNode('topic') 37 | ->defaultNull() 38 | ->end() 39 | ->scalarNode('urgency') 40 | ->defaultNull() 41 | ->end() 42 | ->integerNode('timeout') 43 | ->defaultValue(30) 44 | ->end() 45 | ->booleanNode('automatic_padding') 46 | ->defaultValue(true) 47 | ->end() 48 | ->end() 49 | ; 50 | 51 | return $treeBuilder; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DependencyInjection/MinishlinkWebPushExtension.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | class MinishlinkWebPushExtension extends Extension 16 | { 17 | public function load(array $configs, ContainerBuilder $container): void 18 | { 19 | $configuration = $this->getConfiguration($configs, $container); 20 | $config = $this->processConfiguration($configuration, $configs); 21 | 22 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); 23 | $loader->load('web_push.yml'); 24 | 25 | $defaultOptions = array( 26 | 'TTL' => $config['ttl'], 27 | 'urgency' => $config['urgency'], 28 | 'topic' => $config['topic'], 29 | ); 30 | 31 | $container->setParameter('minishlink_web_push.auth', isset($config['VAPID']) ? ['VAPID' => $config['VAPID']] : []); 32 | $container->setParameter('minishlink_web_push.default_options', $defaultOptions); 33 | $container->setParameter('minishlink_web_push.timeout', $config['timeout']); 34 | $container->setParameter('minishlink_web_push.automatic_padding', $config['automatic_padding']); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Louis Lagrange 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /MinishlinkWebPushBundle.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class MinishlinkWebPushBundle extends Bundle 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MinishlinkWebPushBundle 2 | This bundle provides a simple integration of the [WebPush library](https://github.com/Minishlink/web-push). 3 | 4 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/0c2947f7-f173-4d00-b0bb-da26613d52a2/mini.png)](https://insight.sensiolabs.com/projects/0c2947f7-f173-4d00-b0bb-da26613d52a2) 5 | 6 | ## Usage 7 | Web Push sends notifications to endpoints which server delivers web push notifications as described in 8 | the [Web Push API specification](http://www.w3.org/TR/push-api/). 9 | 10 | ```php 11 | container->get('minishlink_web_push'); 14 | ``` 15 | 16 | The bundle provides a new `minishlink_web_push` service that returns an instance of `Minishlink\WebPush\WebPush`. 17 | 18 | For more info on what you can do with `$webPush`, check [Minishlink/web-push](https://github.com/Minishlink/web-push). 19 | 20 | ## Installation 21 | 22 | 1. `composer require minishlink/web-push-bundle` 23 | 2. Enable the bundle in your `app/AppKernel.php`. 24 | 25 | ```php 26 | 15 | */ 16 | class MinishlinkWebPushExtensionTest extends AbstractExtensionTestCase 17 | { 18 | 19 | protected function getContainerExtensions(): array 20 | { 21 | return array( 22 | new MinishlinkWebPushExtension() 23 | ); 24 | } 25 | 26 | public function testWithoutConfiguration() { 27 | $this->load(); 28 | 29 | $this->assertContainerBuilderHasParameter('minishlink_web_push.auth'); 30 | $this->assertContainerBuilderHasParameter('minishlink_web_push.default_options'); 31 | $this->assertContainerBuilderHasParameter('minishlink_web_push.timeout'); 32 | $this->assertContainerBuilderHasParameter('minishlink_web_push.automatic_padding'); 33 | $this->assertContainerBuilderHasService('minishlink_web_push'); 34 | $this->assertContainerBuilderHasService('Minishlink\WebPush\WebPush'); 35 | $this->assertInstanceOf(WebPush::class, $this->container->get('minishlink_web_push')); 36 | $this->assertInstanceOf(WebPush::class, $this->container->get('Minishlink\WebPush\WebPush')); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minishlink/web-push-bundle", 3 | "type": "symfony-bundle", 4 | "description": "Symfony Bundle around the WebPush library", 5 | "keywords": [ 6 | "push", 7 | "notifications", 8 | "web", 9 | "WebPush" 10 | ], 11 | "homepage": "https://github.com/minishlink/web-push-bundle", 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Louis Lagrange", 16 | "email": "lagrange.louis@gmail.com", 17 | "homepage": "https://github.com/Minishlink" 18 | } 19 | ], 20 | "require": { 21 | "php": "^7.2 || ^8.0", 22 | "minishlink/web-push": "^6.0|^7.0|^8.0" 23 | }, 24 | "require-dev": { 25 | "symfony/framework-bundle": "^4.2|^5.0", 26 | "phpunit/phpunit": "^9.3.0", 27 | "symfony/phpunit-bridge": "^5.0", 28 | "matthiasnoback/symfony-dependency-injection-test": "^4.2.1" 29 | }, 30 | "target-dir": "Minishlink/Bundle/WebPushBundle", 31 | "autoload": { 32 | "psr-0": { 33 | "Minishlink\\Bundle\\WebPushBundle": "", 34 | "Tests\\Minishlink\\WebPushBundle": "Tests" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ./Tests 15 | 16 | 17 | 18 | 19 | 20 | ./ 21 | 22 | ./Tests 23 | ./Resources 24 | ./vendor 25 | 26 | 27 | 28 | --------------------------------------------------------------------------------