Skip to content

Commit

Permalink
Merge pull request #45 from slc1/feature/as-command-annotations
Browse files Browse the repository at this point in the history
Added symfony 7 and php 8.3. Annotations changed to attribute
  • Loading branch information
mcfedr authored Sep 25, 2024
2 parents 7c3633a + 86d6f90 commit 65373e2
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 111 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Test
on:
push:
pull_request:
types: [opened, synchronize, edited, reopened]

jobs:
test:
Expand All @@ -14,15 +13,16 @@ jobs:
fail-fast: false
matrix:
php-version:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
symfony-version:
- '5.4.*'
- '6.0.*'
- '7.0.*'
exclude:
- php-version: '7.4'
symfony-version: '6.0.*'
- php-version: '8.1'
symfony-version: '7.0.*'
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
25 changes: 12 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "A set of services to simplify using Aws to send push notifications",
"keywords": ["symfony", "push", "notification", "bundle", "gcm", "c2dm", "ios", "apns", "sns", "aws", "amazon", "fcm"],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-json": "*",
"aws/aws-sdk-php": "^3.0",
"symfony/framework-bundle": "^5.0|^6.0",
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
"symfony/polyfill-mbstring": "^1.1"
},
"suggest": {
Expand All @@ -34,18 +34,17 @@
"require-dev": {
"fakerphp/faker": "^1.10",
"friendsofphp/php-cs-fixer": "^3.3",
"phpunit/phpunit": "^9.5",
"sensio/framework-extra-bundle": "^5.0|^6.0",
"symfony/browser-kit": "^5.0|^6.0",
"symfony/console": "^5.0|^6.0",
"symfony/expression-language": "^5.0|^6.0",
"phpunit/phpunit": "^9.6",
"symfony/browser-kit": "^5.4|^6.0|^7.0",
"symfony/console": "^5.4|^6.0|^7.0",
"symfony/expression-language": "^5.4|^6.0|^7.0",
"symfony/monolog-bundle": "^3.0",
"symfony/phpunit-bridge": "^5.0|^6.0",
"symfony/property-info": "^5.0|^6.0",
"symfony/security-bundle": "^5.0|^6.0",
"symfony/serializer": "^5.0|^6.0",
"symfony/validator": "^5.0|^6.0",
"symfony/yaml": "^5.0|^6.0"
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0",
"symfony/property-info": "^5.4|^6.0|^7.0",
"symfony/security-bundle": "^5.4|^6.0|^7.0",
"symfony/serializer": "^5.4|^6.0|^7.0",
"symfony/validator": "^5.4|^6.0|^7.0",
"symfony/yaml": "^5.4|^6.0|^7.0"
},
"autoload": {
"psr-4": { "Mcfedr\\AwsPushBundle\\": "src/Mcfedr/AwsPushBundle" }
Expand Down
14 changes: 4 additions & 10 deletions src/Mcfedr/AwsPushBundle/Command/EnableAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

use Aws\Sns\SnsClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('kidslox:account:mcfedr:aws:enable', 'Reenable all devices')]
class EnableAllCommand extends Command
{
protected static $defaultName = 'mcfedr:aws:enable';

private SnsClient $sns;

private array $arns;

private ?LoggerInterface $logger;

public function __construct(SnsClient $sns, array $arns, LoggerInterface $logger = null)
public function __construct(SnsClient $sns, array $arns, ?LoggerInterface $logger = null)
{
parent::__construct();

Expand All @@ -29,20 +29,14 @@ public function __construct(SnsClient $sns, array $arns, LoggerInterface $logger
$this->logger = $logger;
}

protected function configure(): void
{
$this
->setDescription('Reenable all devices');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->arns as $platform => $arn) {
$this->logger && $this->logger->info("Enabling $platform");
$this->enablePlatform($platform);
}

return 0;
return Command::SUCCESS;
}

/**
Expand Down
14 changes: 4 additions & 10 deletions src/Mcfedr/AwsPushBundle/Command/RemoveDisabledCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

use Aws\Sns\SnsClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('kidslox:account:mcfedr:aws:remove', 'Remove disabled devices')]
class RemoveDisabledCommand extends Command
{
protected static $defaultName = 'mcfedr:aws:remove';

private SnsClient $sns;

private array $arns;

private ?LoggerInterface $logger;

public function __construct(SnsClient $sns, array $arns, LoggerInterface $logger = null)
public function __construct(SnsClient $sns, array $arns, ?LoggerInterface $logger = null)
{
parent::__construct();

Expand All @@ -29,20 +29,14 @@ public function __construct(SnsClient $sns, array $arns, LoggerInterface $logger
$this->logger = $logger;
}

protected function configure(): void
{
$this
->setDescription('Remove disabled devices');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->arns as $platform => $arn) {
$this->logger && $this->logger->info("Removing from $platform");
$this->removeFromPlatform($platform);
}

return 0;
return Command::SUCCESS;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/Mcfedr/AwsPushBundle/Command/SubscribeTopicsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Aws\Sns\Exception\SnsException;
use Aws\Sns\SnsClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('kidslox:account:mcfedr:aws:subscribe', 'Subscribe existing devices to the topic')]
class SubscribeTopicsCommand extends Command
{
protected static $defaultName = 'mcfedr:aws:subscribe';

private string $topicArn;

private SnsClient $sns;
Expand All @@ -24,7 +24,7 @@ class SubscribeTopicsCommand extends Command

private ?LoggerInterface $logger;

public function __construct(string $topicArn, SnsClient $sns, array $arns, LoggerInterface $logger = null)
public function __construct(string $topicArn, SnsClient $sns, array $arns, ?LoggerInterface $logger = null)
{
$this->topicArn = $topicArn;
$this->sns = $sns;
Expand All @@ -37,7 +37,6 @@ public function __construct(string $topicArn, SnsClient $sns, array $arns, Logge
protected function configure(): void
{
$this
->setDescription('Subscribe existing devices to the topic')
->addOption(
'topic',
null,
Expand All @@ -59,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
]);
}

return 0;
return Command::SUCCESS;
}

private function subscribePlatform(string $platform, string $topic): void
Expand Down
19 changes: 8 additions & 11 deletions src/Mcfedr/AwsPushBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Mcfedr\AwsPushBundle\Service\Devices;
use Mcfedr\AwsPushBundle\Service\Messages;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
Expand All @@ -24,7 +24,7 @@
* provided by this bundle.
* In some simple cases it may be enough to use this controller.
*/
class ApiController
class ApiController extends AbstractController
{
private Devices $devices;

Expand All @@ -51,9 +51,7 @@ public function __construct(Devices $devices, Messages $messages, SnsClient $sns
$this->logger = $logger;
}

/**
* @Route("/devices", name="mcfedr_aws_push.register", methods={"POST"})
*/
#[Route(path: '/devices', name: 'mcfedr_aws_push.register', methods: ['POST'])]
public function registerDeviceAction(Request $request): Response
{
/** @var DeviceRequest $deviceRequest */
Expand All @@ -65,7 +63,7 @@ public function registerDeviceAction(Request $request): Response
$device = $deviceRequest->getDevice();

try {
if (($arn = $this->devices->registerDevice($device->getDeviceId(), $device->getPlatform()))) {
if ($arn = $this->devices->registerDevice($device->getDeviceId(), $device->getPlatform())) {
$this->logger && $this->logger->info('Device registered', [
'arn' => $arn,
'device' => $device->getDeviceId(),
Expand All @@ -91,7 +89,7 @@ public function registerDeviceAction(Request $request): Response
return new Response('Unknown platform', 400);
} catch (\Exception $e) {
$this->logger && $this->logger->error('Exception registering device', [
'e' => $e,
'e' => $e,
'device' => $device->getDeviceId(),
'platform' => $device->getPlatform(),
]);
Expand All @@ -100,12 +98,11 @@ public function registerDeviceAction(Request $request): Response
return new Response('Unknown error', 500);
}

/**
* @Route("/broadcast", name="mcfedr_aws_push.broadcast", methods={"POST"})
* @Security("is_granted('ROLE_MCFEDR_AWS_BROADCAST')")
*/
#[Route(path: '/broadcast', name: 'mcfedr_aws_push.broadcast', methods: ['POST'])]
public function broadcastAction(Request $request): Response
{
$this->denyAccessUnlessGranted('ROLE_MCFEDR_AWS_BROADCAST');

/** @var BroadcastRequest $broadcastRequest */
$broadcastRequest = $this->serializer->deserialize($request->getContent(), BroadcastRequest::class, 'json');
$errors = $this->validator->validate($broadcastRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('mcfedr_aws_push');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Mcfedr\AwsPushBundle\Message\Message;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
Expand All @@ -17,9 +17,6 @@
*/
class McfedrAwsPushExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand Down Expand Up @@ -58,7 +55,7 @@ public function load(array $configs, ContainerBuilder $container): void
}

if (!isset($config['pushPlatforms'])) {
@trigger_error(sprintf('You must set mcfedr_aws_push.pushPlatforms, the default will change from \'%s\' to \'%s\' in the next version.', implode(',', Message::DEFAULT_PLATFORMS), implode('', Message::DEFAULT_PLATFORMS_NEXT)), E_USER_DEPRECATED);
@trigger_error(\sprintf('You must set mcfedr_aws_push.pushPlatforms, the default will change from \'%s\' to \'%s\' in the next version.', implode(',', Message::DEFAULT_PLATFORMS), implode('', Message::DEFAULT_PLATFORMS_NEXT)), E_USER_DEPRECATED);

$config['pushPlatforms'] = Message::DEFAULT_PLATFORMS;
}
Expand Down
11 changes: 0 additions & 11 deletions src/Mcfedr/AwsPushBundle/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ class Message implements \JsonSerializable
* @see Message::APNS_MAX_LENGTH
* @see Message::FCM_MAX_LENGTH
* @see Message::GCM_MAX_LENGTH
* @see Message::ADM_MAX_LENGTH
*/
private $allowTrimming = true;
Expand Down Expand Up @@ -767,8 +766,6 @@ private function getApnsJson(int $length, string $message): string

/**
* Get the correct apple push notification server data.
*
* @return mixed
*/
private function getApnsJsonInner(?string $text)
{
Expand Down Expand Up @@ -865,8 +862,6 @@ private function getFcmJson(): string

/**
* Gets the data part of the FCM message.
*
* @return mixed
*/
private function getFcmJsonInner(?string $text)
{
Expand Down Expand Up @@ -948,8 +943,6 @@ private function getAdmJson(): string

/**
* Gets the data part of the GCM message.
*
* @return mixed
*/
private function getAdmJsonInner(?string $text)
{
Expand Down Expand Up @@ -984,8 +977,6 @@ private function getGcmJson(): string

/**
* Gets the data part of the GCM message.
*
* @return mixed
*/
private function getGcmJsonInner(?string $text)
{
Expand Down Expand Up @@ -1050,8 +1041,6 @@ private function getAndroidJsonInner(?string $text): array
/**
* Using a inner function gets the data, and trys again if its too long by trimming the text.
*
* @return mixed
*
* @throws MessageTooLongException
*/
private function getTrimmedData(callable $inner, int $limit, string $error)
Expand Down
6 changes: 2 additions & 4 deletions src/Mcfedr/AwsPushBundle/Model/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class Broadcast
{
private string $platform;

/**
* @Valid()
* @NotBlank()
*/
#[Valid]
#[NotBlank]
private Message $message;

public function getMessage(): Message
Expand Down
6 changes: 2 additions & 4 deletions src/Mcfedr/AwsPushBundle/Model/BroadcastRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

class BroadcastRequest
{
/**
* @Assert\NotBlank()
* @Assert\Valid()
*/
#[Assert\NotBlank]
#[Assert\Valid]
private Broadcast $broadcast;

public function getBroadcast(): Broadcast
Expand Down
Loading

0 comments on commit 65373e2

Please sign in to comment.