diff --git a/.editorconfig b/.editorconfig index 045a248..c48d880 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.{php,twig,yml}] +[*.{php,twig,yaml,json}] indent_style = space indent_size = 4 diff --git a/README.md b/README.md index 6e7e747..0f1c4fe 100644 --- a/README.md +++ b/README.md @@ -289,16 +289,13 @@ declare(strict_types=1); namespace App\EventListener; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; -/** - * @Hook(DoSomething::HOOK, priority=DoSomething::PRIORITY) - */ + #[AsHook(DoSomething::HOOK, priority: 1200)] final class DoSomething { public const HOOK = 'calEvtBookingPostBooking'; - public const PRIORITY = 1200; /** * @var EventRegistration diff --git a/composer.json b/composer.json index ad9380b..23c973b 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,12 @@ } ], "require": { - "php": "^7.4 || ^8.0", - "contao/core-bundle": "^4.9", - "contao/calendar-bundle": "^4.9", + "php": "^8.1", + "contao/core-bundle": "^4.13 || ^5.0", + "contao/calendar-bundle": "^4.13 || ^5.0", "markocupic/export_table": "^5.1", "ramsey/uuid": "^3.0 || ^4.0", - "codefog/contao-haste": "^4.23", + "codefog/contao-haste": "^5.0", "terminal42/notification_center": "^1.5" }, "require-dev": { diff --git a/config/services.yml b/config/services.yml deleted file mode 100644 index 5b5e325..0000000 --- a/config/services.yml +++ /dev/null @@ -1,11 +0,0 @@ -services: - _defaults: - autowire: true - autoconfigure: true - public: true - bind: - $projectDir: '%kernel.project_dir%' - - Markocupic\CalendarEventBookingBundle\: - resource: ../src/ - exclude: ../src/{Event,Model,DependencyInjection} diff --git a/contao/config/config.php b/contao/config/config.php index ee5e6c1..a8fef05 100644 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. @@ -24,28 +24,28 @@ * Notification center */ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['calendar-event-booking-bundle'] = [ - 'booking-notification' => [ - 'email_sender_name' => ['organizer_name'], + 'booking-notification' => [ + 'email_sender_name' => ['organizer_name'], 'email_sender_address' => ['organizer_email', 'admin_email'], - 'recipients' => ['organizer_email', 'member_email', 'admin_email'], - 'email_recipient_cc' => ['organizer_email', 'member_email', 'admin_email'], - 'email_recipient_bcc' => ['organizer_email', 'member_email', 'admin_email'], - 'email_replyTo' => ['organizer_email', 'member_email', 'admin_email'], - 'email_subject' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], - 'email_text' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], - 'email_html' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], - 'attachment_tokens' => [], + 'recipients' => ['organizer_email', 'member_email', 'admin_email'], + 'email_recipient_cc' => ['organizer_email', 'member_email', 'admin_email'], + 'email_recipient_bcc' => ['organizer_email', 'member_email', 'admin_email'], + 'email_replyTo' => ['organizer_email', 'member_email', 'admin_email'], + 'email_subject' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], + 'email_text' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], + 'email_html' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], + 'attachment_tokens' => [], ], 'event-unsubscribe-notification' => [ - 'email_sender_name' => ['organizer_name'], + 'email_sender_name' => ['organizer_name'], 'email_sender_address' => ['organizer_email', 'admin_email'], - 'recipients' => ['organizer_email', 'member_email', 'admin_email'], - 'email_recipient_cc' => ['organizer_email', 'member_email', 'admin_email'], - 'email_recipient_bcc' => ['organizer_email', 'member_email', 'admin_email'], - 'email_replyTo' => ['organizer_email', 'member_email', 'admin_email'], - 'email_subject' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], - 'email_text' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], - 'email_html' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], - 'attachment_tokens' => [], + 'recipients' => ['organizer_email', 'member_email', 'admin_email'], + 'email_recipient_cc' => ['organizer_email', 'member_email', 'admin_email'], + 'email_recipient_bcc' => ['organizer_email', 'member_email', 'admin_email'], + 'email_replyTo' => ['organizer_email', 'member_email', 'admin_email'], + 'email_subject' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], + 'email_text' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], + 'email_html' => ['event_*', 'event_title', 'event_unsubscribeLimitTstamp', 'event_unsubscribeHref', 'member_*', 'member_dateOfBirth', 'member_salutation', 'organizer_*', 'organizer_name', 'organizer_email', 'admin_email'], + 'attachment_tokens' => [], ], ]; diff --git a/contao/dca/tl_calendar.php b/contao/dca/tl_calendar.php index 4f03b36..44ec17c 100644 --- a/contao/dca/tl_calendar.php +++ b/contao/dca/tl_calendar.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_calendar_events.php b/contao/dca/tl_calendar_events.php index 3f1f454..ad59427 100644 --- a/contao/dca/tl_calendar_events.php +++ b/contao/dca/tl_calendar_events.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_calendar_events_member.php b/contao/dca/tl_calendar_events_member.php index 4b97394..f0c5575 100644 --- a/contao/dca/tl_calendar_events_member.php +++ b/contao/dca/tl_calendar_events_member.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_form.php b/contao/dca/tl_form.php index c97fc3c..43d3f5f 100644 --- a/contao/dca/tl_form.php +++ b/contao/dca/tl_form.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/dca/tl_module.php b/contao/dca/tl_module.php index ef8c78d..80100ba 100644 --- a/contao/dca/tl_module.php +++ b/contao/dca/tl_module.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/default.php b/contao/languages/en/default.php index 134e995..0378a84 100644 --- a/contao/languages/en/default.php +++ b/contao/languages/en/default.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/modules.php b/contao/languages/en/modules.php index 2070c23..e46dac1 100644 --- a/contao/languages/en/modules.php +++ b/contao/languages/en/modules.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_calendar.php b/contao/languages/en/tl_calendar.php index 7f2c5da..59168ea 100644 --- a/contao/languages/en/tl_calendar.php +++ b/contao/languages/en/tl_calendar.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_calendar_events.php b/contao/languages/en/tl_calendar_events.php index bf68f2b..020ca35 100644 --- a/contao/languages/en/tl_calendar_events.php +++ b/contao/languages/en/tl_calendar_events.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_calendar_events_member.php b/contao/languages/en/tl_calendar_events_member.php index 4f38969..6e87a96 100644 --- a/contao/languages/en/tl_calendar_events_member.php +++ b/contao/languages/en/tl_calendar_events_member.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_form.php b/contao/languages/en/tl_form.php index 28e57c8..2bcf4f8 100644 --- a/contao/languages/en/tl_form.php +++ b/contao/languages/en/tl_form.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_module.php b/contao/languages/en/tl_module.php index 7b6302b..1b7a99f 100644 --- a/contao/languages/en/tl_module.php +++ b/contao/languages/en/tl_module.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/contao/languages/en/tl_nc_notification.php b/contao/languages/en/tl_nc_notification.php index fff80a9..2841c3d 100644 --- a/contao/languages/en/tl_nc_notification.php +++ b/contao/languages/en/tl_nc_notification.php @@ -5,7 +5,7 @@ /* * This file is part of Calendar Event Booking Bundle. * - * (c) Marko Cupic 2022 + * (c) Marko Cupic 2023 * @license MIT * For the full copyright and license information, * please view the LICENSE file that was distributed with this source code. diff --git a/src/Controller/FrontendModule/CalendarEventBookingEventBookingModuleController.php b/src/Controller/FrontendModule/CalendarEventBookingEventBookingModuleController.php index 649951d..1356859 100644 --- a/src/Controller/FrontendModule/CalendarEventBookingEventBookingModuleController.php +++ b/src/Controller/FrontendModule/CalendarEventBookingEventBookingModuleController.php @@ -14,13 +14,15 @@ namespace Markocupic\CalendarEventBookingBundle\Controller\FrontendModule; +use Codefog\HasteBundle\Form\Form; +use Codefog\HasteBundle\UrlParser; use Contao\CalendarEventsModel; use Contao\Config; use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; +use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule; use Contao\CoreBundle\Exception\PageNotFoundException; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Routing\ScopeMatcher; -use Contao\CoreBundle\ServiceAnnotation\FrontendModule; use Contao\Date; use Contao\Environment; use Contao\FormModel; @@ -31,8 +33,6 @@ use Contao\StringUtil; use Contao\System; use Contao\Template; -use Haste\Form\Form; -use Haste\Util\Url; use Markocupic\CalendarEventBookingBundle\Helper\EventRegistration; use Markocupic\CalendarEventBookingBundle\Model\CalendarEventsMemberModel; use Ramsey\Uuid\Uuid; @@ -43,9 +43,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * @FrontendModule(type=CalendarEventBookingEventBookingModuleController::TYPE, category="events") - */ +#[AsFrontendModule(CalendarEventBookingEventBookingModuleController::TYPE, category:'events', template: 'mod_calendar_event_booking_event_booking_module')] class CalendarEventBookingEventBookingModuleController extends AbstractFrontendModuleController { public const TYPE = 'calendar_event_booking_event_booking_module'; @@ -56,84 +54,23 @@ class CalendarEventBookingEventBookingModuleController extends AbstractFrontendM public const CASE_BOOKING_NO_LONGER_POSSIBLE = 'bookingNoLongerPossible'; public const CASE_BOOKING_NOT_YET_POSSIBLE = 'bookingNotYetPossible'; - /** - * @var ModuleModel - */ - private $model; - - /** - * @var ContaoFramework - */ - private $framework; - - /** - * @var EventRegistration - */ - private $eventRegistration; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var ScopeMatcher - */ - private $scopeMatcher; - - /** - * @var RequestStack - */ - private $requestStack; - - /** - * @var EventDispatcherInterface - */ - private $eventDispather; - - /** - * @var Template; - */ - private $template; - - /** - * @var CalendarEventsModel - */ - private $objEvent; - - /** - * @var array - */ - private $disabledHooks = []; - - /** - * @var string - */ - private $case; - - /** - * @var CalendarEventsMemberModel - */ - private $objEventMember; - - /** - * @var Form - */ - private $objForm; - - /** - * @var PageModel - */ - private $objPage; - - public function __construct(ContaoFramework $framework, EventRegistration $eventRegistration, TranslatorInterface $translator, ScopeMatcher $scopeMatcher, RequestStack $requestStack, EventDispatcherInterface $eventDispatcher) - { - $this->framework = $framework; - $this->eventRegistration = $eventRegistration; - $this->translator = $translator; - $this->scopeMatcher = $scopeMatcher; - $this->requestStack = $requestStack; - $this->eventDispatcher = $eventDispatcher; + private ?CalendarEventsMemberModel $objEventMember = null; + private ?CalendarEventsModel $objEvent = null; + private ?Form $objForm = null; + private ?ModuleModel $model = null; + private ?PageModel$objPage = null; + private ?string $case = null; + private array $disabledHooks = []; + + public function __construct( + private readonly ContaoFramework $framework, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly EventRegistration $eventRegistration, + private readonly RequestStack $requestStack, + private readonly ScopeMatcher $scopeMatcher, + private readonly TranslatorInterface $translator, + private readonly UrlParser $urlParser, + ) { } public function __invoke(Request $request, ModuleModel $model, string $section, array $classes = null, PageModel $page = null): Response @@ -166,10 +103,8 @@ public function __invoke(Request $request, ModuleModel $model, string $section, /** * @throws \Exception - * - * @return mixed */ - public function getProperty(string $key) + public function getProperty(string $key): mixed { if (!property_exists($this, $key)) { throw new \Exception(sprintf('Property "%s" not found.', $key)); @@ -179,11 +114,9 @@ public function getProperty(string $key) } /** - * @param mixed $varValue - * * @throws \Exception */ - public function setProperty(string $key, $varValue): bool + public function setProperty(string $key, mixed $varValue): bool { if (property_exists($this, $key)) { $this->$key = $varValue; @@ -223,13 +156,10 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ $environmentAdapter = $this->framework->getAdapter(Environment::class); $stringUtilAdapter = $this->framework->getAdapter(StringUtil::class); $pageModelAdapter = $this->framework->getAdapter(PageModel::class); - $urlAdapter = $this->framework->getAdapter(Url::class); $messageAdapter = $this->framework->getAdapter(Message::class); $dateAdapter = $this->framework->getAdapter(Date::class); $configAdapter = $this->framework->getAdapter(Config::class); - $this->template = $template; - // Load language file $systemAdapter->loadLanguageFile(self::EVENT_SUBSCRIPTION_TABLE); @@ -307,7 +237,7 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ } } - // Trigger pre booking hook: add your custom code here. + // Trigger pre-booking hook: add your custom code here. if (isset($GLOBALS['TL_HOOKS']['calEvtBookingPreBooking']) && \is_array($GLOBALS['TL_HOOKS']['calEvtBookingPreBooking'])) { foreach ($GLOBALS['TL_HOOKS']['calEvtBookingPreBooking'] as $callback) { $systemAdapter->importStatic($callback[0])->{$callback[1]}($this, $this->disabledHooks); @@ -330,31 +260,29 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ $objPageModel = $pageModelAdapter->findByPk($objFormGeneratorModel->jumpTo); if (null !== $objPageModel) { - $strRedirectUrl = $urlAdapter - ->addQueryString( - 'bookingToken='.$this->objEventMember->bookingToken, - $objPageModel->getAbsoluteUrl() - ) - ; + $strRedirectUrl = $this->urlParser->addQueryString( + 'bookingToken='.$this->objEventMember->bookingToken, + $objPageModel->getAbsoluteUrl() + ); return new RedirectResponse($strRedirectUrl); } } } } - $this->template->form = $this->objForm; + $template->form = $this->objForm->generate(); } } - $this->template->case = $this->case; - $this->template->countBookings = $this->template->bookingCount = $this->eventRegistration->getBookingCount($this->objEvent); - $this->template->bookingMin = $this->eventRegistration->getBookingMin($this->objEvent); - $this->template->bookingMax = $this->eventRegistration->getBookingMax($this->objEvent); - $this->template->event = $this->objEvent; - $this->template->model = $this->model; - $this->template->messages = $messageAdapter->hasMessages() ? $messageAdapter->generate('FE') : null; + $template->case = $this->case; + $template->countBookings = $template->bookingCount = $this->eventRegistration->getBookingCount($this->objEvent); + $template->bookingMin = $this->eventRegistration->getBookingMin($this->objEvent); + $template->bookingMax = $this->eventRegistration->getBookingMax($this->objEvent); + $template->event = $this->objEvent; + $template->model = $this->model; + $template->messages = $messageAdapter->hasMessages() ? $messageAdapter->generate('FE') : null; - return $this->template->getResponse(); + return $template->getResponse(); } protected function setForm(FormModel $objFormGeneratorModel): void @@ -370,14 +298,12 @@ protected function setForm(FormModel $objFormGeneratorModel): void // Bind the event member model to the form input $this->objEventMember = new CalendarEventsMemberModel(); - $this->objForm->bindModel($this->objEventMember); + $this->objForm->setBoundModel($this->objEventMember); // Add fields from form generator $this->objForm->addFieldsFromFormGenerator( $objFormGeneratorModel->id, function (&$strField, &$arrDca) use ($systemAdapter) { - $blnShow = true; - // Trigger add field hook if (isset($GLOBALS['TL_HOOKS']['calEvtBookingAddField']) && \is_array($GLOBALS['TL_HOOKS']['calEvtBookingAddField'])) { foreach ($GLOBALS['TL_HOOKS']['calEvtBookingAddField'] as $callback) { diff --git a/src/Controller/FrontendModule/CalendarEventBookingMemberListModuleController.php b/src/Controller/FrontendModule/CalendarEventBookingMemberListModuleController.php index f844fbc..06b35cf 100644 --- a/src/Controller/FrontendModule/CalendarEventBookingMemberListModuleController.php +++ b/src/Controller/FrontendModule/CalendarEventBookingMemberListModuleController.php @@ -17,62 +17,34 @@ use Contao\CalendarEventsModel; use Contao\Controller; use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; +use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Routing\ScopeMatcher; -use Contao\CoreBundle\ServiceAnnotation\FrontendModule; use Contao\FrontendTemplate; use Contao\ModuleModel; use Contao\PageModel; use Contao\Template; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\PDOStatement; -use Doctrine\DBAL\Query\QueryBuilder; +use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Result; use Markocupic\CalendarEventBookingBundle\Helper\EventRegistration; use Markocupic\CalendarEventBookingBundle\Model\CalendarEventsMemberModel; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -/** - * @FrontendModule(type=CalendarEventBookingMemberListModuleController::TYPE, category="events") - */ +#[AsFrontendModule(CalendarEventBookingMemberListModuleController::TYPE, category:'events', template: 'mod_calendar_event_booking_member_list_module')] class CalendarEventBookingMemberListModuleController extends AbstractFrontendModuleController { public const TYPE = 'calendar_event_booking_member_list_module'; - /** - * @var ContaoFramework - */ - private $framework; - - /** - * @var ScopeMatcher - */ - private $scopeMatcher; - - /** - * @var Connection - */ - private $connection; - - /** - * @var EventRegistration - */ - private $eventRegistration; - - /** - * @var CalendarEventsModel - */ - private $objEvent; + private ?CalendarEventsModel $objEvent = null; - /** - * CalendarEventBookingMemberListModuleController constructor. - */ - public function __construct(ContaoFramework $framework, ScopeMatcher $scopeMatcher, Connection $connection, EventRegistration $eventRegistration) - { - $this->framework = $framework; - $this->scopeMatcher = $scopeMatcher; - $this->connection = $connection; - $this->eventRegistration = $eventRegistration; + public function __construct( + private readonly ContaoFramework $framework, + private readonly ScopeMatcher $scopeMatcher, + private readonly Connection $connection, + private readonly EventRegistration $eventRegistration, + ) { } public function __invoke(Request $request, ModuleModel $model, string $section, array $classes = null, PageModel $page = null): Response @@ -99,7 +71,10 @@ public function __invoke(Request $request, ModuleModel $model, string $section, return parent::__invoke($request, $model, $section, $classes); } - protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response + /** + * @throws Exception + */ + protected function getResponse(Template $template, ModuleModel $model, Request $request): Response { $calendarEventsMemberModelAdapter = $this->framework->getAdapter(CalendarEventsMemberModel::class); $controllerAdapter = $this->framework->getAdapter(Controller::class); @@ -107,15 +82,13 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ // Load language $controllerAdapter->loadLanguageFile(CalendarEventBookingEventBookingModuleController::EVENT_SUBSCRIPTION_TABLE); - /** @var PDOStatement $results */ $results = $this->getSignedUpMembers((int) ($this->objEvent->id)); $intRowCount = $results->rowCount(); $i = 0; $strRows = ''; - while (false !== ($arrEventMember = $results->fetch())) { - /** @var FrontendTemplate $partial */ + while (false !== ($arrEventMember = $results->fetchAssociative())) { $partial = new FrontendTemplate($model->calendarEventBookingMemberListPartialTemplate); /** @var CalendarEventsMemberModel $calendarEventsMemberModel */ @@ -140,12 +113,15 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ /** * Get signed up members of current event. + * + * @throws Exception + * + * @return Result */ protected function getSignedUpMembers(int $id) { $t = CalendarEventBookingEventBookingModuleController::EVENT_SUBSCRIPTION_TABLE; - /** @var QueryBuilder $qb */ $qb = $this->connection->createQueryBuilder(); $qb->select('id') ->from($t, 't') @@ -156,7 +132,7 @@ protected function getSignedUpMembers(int $id) ->setParameter('pid', $id) ; - return $qb->execute(); + return $qb->executeQuery(); } protected function getRowClass(int $i, int $intRowsTotal): string diff --git a/src/Controller/FrontendModule/CalendarEventBookingUnsubscribeFromEventModuleController.php b/src/Controller/FrontendModule/CalendarEventBookingUnsubscribeFromEventModuleController.php index 5395915..7aadf55 100644 --- a/src/Controller/FrontendModule/CalendarEventBookingUnsubscribeFromEventModuleController.php +++ b/src/Controller/FrontendModule/CalendarEventBookingUnsubscribeFromEventModuleController.php @@ -17,9 +17,9 @@ use Contao\CalendarEventsModel; use Contao\Controller; use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; +use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Routing\ScopeMatcher; -use Contao\CoreBundle\ServiceAnnotation\FrontendModule; use Contao\ModuleModel; use Contao\PageModel; use Contao\StringUtil; @@ -31,30 +31,24 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * @FrontendModule(type=CalendarEventBookingUnsubscribeFromEventModuleController::TYPE, category="events") - */ +#[AsFrontendModule(CalendarEventBookingUnsubscribeFromEventModuleController::TYPE, category:'events', template: 'mod_calendar_event_booking_unsubscribe_from_event_module')] class CalendarEventBookingUnsubscribeFromEventModuleController extends AbstractFrontendModuleController { public const TYPE = 'calendar_event_booking_unsubscribe_from_event_module'; - protected ContaoFramework $framework; - protected ScopeMatcher $scopeMatcher; - protected NotificationHelper $notificationHelper; - protected TranslatorInterface $translator; - protected ?CalendarEventsModel $objEvent = null; protected ?CalendarEventsMemberModel $objEventMember = null; + protected ?CalendarEventsModel $objEvent = null; protected ?PageModel $objPage = null; - protected bool $hasError = false; protected array $errorMsg = []; protected bool $blnHasUnsubscribed = false; + protected bool $hasError = false; - public function __construct(ContaoFramework $framework, ScopeMatcher $scopeMatcher, NotificationHelper $notificationHelper, TranslatorInterface $translator) - { - $this->framework = $framework; - $this->scopeMatcher = $scopeMatcher; - $this->notificationHelper = $notificationHelper; - $this->translator = $translator; + public function __construct( + private readonly ContaoFramework $framework, + private readonly NotificationHelper $notificationHelper, + private readonly ScopeMatcher $scopeMatcher, + private readonly TranslatorInterface $translator, + ) { } /** @@ -189,9 +183,7 @@ protected function notify(CalendarEventsMemberModel $objEventMember, CalendarEve foreach ($arrNotifications as $notificationId) { $objNotification = $notificationAdapter->findByPk($notificationId); - if (null !== $objNotification) { - $objNotification->send($arrTokens, $this->objPage->language); - } + $objNotification?->send($arrTokens, $this->objPage->language); } } } diff --git a/src/DataContainer/Module.php b/src/DataContainer/Module.php index 53158e5..b900850 100644 --- a/src/DataContainer/Module.php +++ b/src/DataContainer/Module.php @@ -19,11 +19,9 @@ class Module { - private ContaoFramework $framework; - - public function __construct(ContaoFramework $framework) - { - $this->framework = $framework; + public function __construct( + private readonly ContaoFramework $framework, + ) { } public function getCalendarEventBookingMemberListPartialTemplate(): array diff --git a/src/EventListener/DataContainer/ContentOnLoadCallbackListener.php b/src/EventListener/DataContainer/ContentOnLoadCallbackListener.php index 9a32d96..cbf4a00 100644 --- a/src/EventListener/DataContainer/ContentOnLoadCallbackListener.php +++ b/src/EventListener/DataContainer/ContentOnLoadCallbackListener.php @@ -14,11 +14,9 @@ namespace Markocupic\CalendarEventBookingBundle\EventListener\DataContainer; -use Contao\CoreBundle\ServiceAnnotation\Callback; +use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; -/** - * @Callback(target="config.onload", table="tl_calendar_events_member") - */ +#[AsCallback(table: 'tl_calendar_events_member', target: 'config.onload')] class ContentOnLoadCallbackListener { public function __invoke(): void diff --git a/src/Helper/AddTemplateData.php b/src/Helper/AddTemplateData.php index ff387cd..2110f68 100644 --- a/src/Helper/AddTemplateData.php +++ b/src/Helper/AddTemplateData.php @@ -20,11 +20,9 @@ class AddTemplateData { - private EventRegistration $eventRegistration; - - public function __construct(EventRegistration $evenRegistration) - { - $this->eventRegistration = $evenRegistration; + public function __construct( + private readonly EventRegistration $evenRegistration, + ) { } /** diff --git a/src/Helper/EventRegistration.php b/src/Helper/EventRegistration.php index 360a455..98ae8f5 100644 --- a/src/Helper/EventRegistration.php +++ b/src/Helper/EventRegistration.php @@ -14,6 +14,7 @@ namespace Markocupic\CalendarEventBookingBundle\Helper; +use Codefog\HasteBundle\Form\Form; use Contao\CalendarEventsModel; use Contao\Config; use Contao\CoreBundle\Framework\ContaoFramework; @@ -22,7 +23,6 @@ use Contao\Input; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; -use Haste\Form\Form; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Model\CalendarEventsMemberModel; use Symfony\Component\HttpFoundation\RequestStack; @@ -32,17 +32,12 @@ class EventRegistration { public const FLASH_KEY = '_event_registration'; - protected ContaoFramework $framework; - private Connection $connection; - private Security $security; - private RequestStack $requestStack; - - public function __construct(ContaoFramework $framework, Connection $connection, Security $security, RequestStack $requestStack) - { - $this->framework = $framework; - $this->connection = $connection; - $this->security = $security; - $this->requestStack = $requestStack; + public function __construct( + private readonly ContaoFramework $framework, + private readonly Connection $connection, + private readonly Security $security, + private readonly RequestStack $requestStack, + ) { } public function hasLoggedInFrontendUser(): bool @@ -84,6 +79,9 @@ public function getEventFromCurrentUrl(): ?CalendarEventsModel return null; } + /** + * @throws Exception + */ public function getRegistrationState(?CalendarEventsModel $objEvent): string { if (!$objEvent->addBookingForm) { @@ -101,6 +99,9 @@ public function getRegistrationState(?CalendarEventsModel $objEvent): string return $state; } + /** + * @throws Exception + */ public function canRegister(CalendarEventsModel $objEvent): bool { return CalendarEventBookingEventBookingModuleController::CASE_BOOKING_POSSIBLE === $this->getRegistrationState($objEvent); @@ -126,8 +127,8 @@ public function isFullyBooked(CalendarEventsModel $objEvent): bool */ public function getBookingCount(CalendarEventsModel $objEvent): int { - $calendarEventsMemberModelAdaper = $this->framework->getAdapter(CalendarEventsMemberModel::class); - $memberCount = (int) $calendarEventsMemberModelAdaper->countBy('pid', $objEvent->id); + $calendarEventsMemberModelAdapter = $this->framework->getAdapter(CalendarEventsMemberModel::class); + $memberCount = (int) $calendarEventsMemberModelAdapter->countBy('pid', $objEvent->id); if ($objEvent->includeEscortsWhenCalculatingRegCount) { $query = 'SELECT SUM(escorts) FROM tl_calendar_events_member WHERE pid = ?'; @@ -151,10 +152,7 @@ public function getBookingMin(CalendarEventsModel $objEvent): int return (int) $objEvent->minMembers; } - /** - * @return int|string - */ - public function getBookingStartDate(CalendarEventsModel $objEvent, string $format = 'timestamp') + public function getBookingStartDate(CalendarEventsModel $objEvent, string $format = 'timestamp'): int|string { $dateAdapter = $this->framework->getAdapter(Date::class); $configAdapter = $this->framework->getAdapter(Config::class); @@ -174,10 +172,7 @@ public function getBookingStartDate(CalendarEventsModel $objEvent, string $forma return $varValue; } - /** - * @return int|string - */ - public function getBookingEndDate(CalendarEventsModel $objEvent, string $format = 'timestamp') + public function getBookingEndDate(CalendarEventsModel $objEvent, string $format = 'timestamp'): int|string { $dateAdapter = $this->framework->getAdapter(Date::class); $configAdapter = $this->framework->getAdapter(Config::class); diff --git a/src/Helper/Formatter.php b/src/Helper/Formatter.php index c1fd5eb..7d817d6 100644 --- a/src/Helper/Formatter.php +++ b/src/Helper/Formatter.php @@ -20,14 +20,17 @@ class Formatter { - private ContaoFramework $framework; - - public function __construct(ContaoFramework $framework) - { - $this->framework = $framework; + public function __construct( + private readonly ContaoFramework $framework, + ) { } - public function convertDateFormatsToTimestamps($varValue, string $strTable, string $strFieldName) + /** + * @param $varValue + * + * @throws \Exception + */ + public function convertDateFormatsToTimestamps($varValue, string $strTable, string $strFieldName): mixed { /** @var Date $dateAdapter */ $dateAdapter = $this->framework->getAdapter(Date::class); @@ -39,7 +42,7 @@ public function convertDateFormatsToTimestamps($varValue, string $strTable, stri try { $objDate = new Date($varValue, $dateAdapter->getFormatFromRgxp($rgxp)); $varValue = $objDate->tstamp; - } catch (\OutOfBoundsException $e) { + } catch (\OutOfBoundsException) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $varValue)); } } diff --git a/src/Helper/NotificationHelper.php b/src/Helper/NotificationHelper.php index df1ece2..0efe960 100644 --- a/src/Helper/NotificationHelper.php +++ b/src/Helper/NotificationHelper.php @@ -14,6 +14,7 @@ namespace Markocupic\CalendarEventBookingBundle\Helper; +use Codefog\HasteBundle\Formatter; use Contao\CalendarEventsModel; use Contao\Controller; use Contao\CoreBundle\Framework\ContaoFramework; @@ -21,17 +22,15 @@ use Contao\StringUtil; use Contao\System; use Contao\UserModel; -use Haste\Util\Format; use Markocupic\CalendarEventBookingBundle\Model\CalendarEventsMemberModel; use NotificationCenter\Model\Notification; class NotificationHelper { - private ContaoFramework $framework; - - public function __construct(ContaoFramework $framework) - { - $this->framework = $framework; + public function __construct( + private readonly ContaoFramework $framework, + private readonly Formatter $formatter, + ) { } /** @@ -47,7 +46,6 @@ public function getNotificationTokens(CalendarEventsMemberModel $objEventMember) $userModelAdapter = $this->framework->getAdapter(UserModel::class); $pageModelAdapter = $this->framework->getAdapter(PageModel::class); $systemAdapter = $this->framework->getAdapter(System::class); - $formatAdapter = $this->framework->getAdapter(Format::class); // Load language file $controllerAdapter->loadLanguageFile('tl_calendar_events_member'); @@ -62,7 +60,7 @@ public function getNotificationTokens(CalendarEventsMemberModel $objEventMember) foreach ($row as $k => $v) { if (isset($GLOBALS['TL_DCA']['tl_calendar_events_member']['fields'][$k])) { - $arrTokens['member_'.$k] = $formatAdapter->dcaValue('tl_calendar_events_member', $k, $v); + $arrTokens['member_'.$k] = $this->formatter->dcaValue('tl_calendar_events_member', $k, $v); } else { $arrTokens['member_'.$k] = html_entity_decode((string) $v); } @@ -74,7 +72,7 @@ public function getNotificationTokens(CalendarEventsMemberModel $objEventMember) $row = $objEvent->row(); foreach ($row as $k => $v) { - $arrTokens['event_'.$k] = $formatAdapter->dcaValue('tl_calendar_events', $k, $v); + $arrTokens['event_'.$k] = $this->formatter->dcaValue('tl_calendar_events', $k, $v); } // Prepare tokens for organizer_* (sender) @@ -87,7 +85,7 @@ public function getNotificationTokens(CalendarEventsMemberModel $objEventMember) if ('password' === $k || 'session' === $k) { continue; } - $arrTokens['organizer_'.$k] = $formatAdapter->dcaValue('tl_user', $k, $v); + $arrTokens['organizer_'.$k] = $this->formatter->dcaValue('tl_user', $k, $v); } // deprecated since version 4.2, to be removed in 5.0 Use organizer_name instead of organizer_senderName */ @@ -107,8 +105,7 @@ public function getNotificationTokens(CalendarEventsMemberModel $objEventMember) $objPage = $pageModelAdapter->findByPk($objCalendar->eventUnsubscribePage); if (null !== $objPage) { - $url = $objPage->getFrontendUrl().'?bookingToken='.$objEventMember->bookingToken; - $arrTokens['event_unsubscribeHref'] = $controllerAdapter->replaceInsertTags('{{env::url}}/').$url; + $arrTokens['event_unsubscribeHref'] = $objPage->getAbsoluteUrl().'?bookingToken='.$objEventMember->bookingToken; } } } @@ -148,9 +145,7 @@ public function notify(CalendarEventsMemberModel $objEventMember, CalendarEvents foreach ($arrNotifications as $notificationId) { $objNotification = $notificationAdapter->findByPk($notificationId); - if (null !== $objNotification) { - $objNotification->send($arrTokens, $objPage->language); - } + $objNotification?->send($arrTokens, $objPage->language); } } } diff --git a/src/Listener/ContaoHooks/AddField/Escort.php b/src/Listener/ContaoHooks/AddField/Escort.php index a3272d1..4ca1f0a 100644 --- a/src/Listener/ContaoHooks/AddField/Escort.php +++ b/src/Listener/ContaoHooks/AddField/Escort.php @@ -14,28 +14,18 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\AddField; +use Codefog\HasteBundle\Form\Form; use Contao\CalendarEventsModel; -use Contao\CoreBundle\ServiceAnnotation\Hook; -use Haste\Form\Form; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; -use Symfony\Contracts\Translation\TranslatorInterface; /** * Codefog haste "Add field Hook". - * - * @Hook(Escort::HOOK, priority=Escort::PRIORITY) */ +#[AsHook(Escort::HOOK, priority: 1000)] final class Escort { public const HOOK = 'calEvtBookingAddField'; - public const PRIORITY = 1000; - - private TranslatorInterface $translator; - - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } public function __invoke(Form $objForm, string $strField, array $arrDca, CalendarEventsModel $objEvent, CalendarEventBookingEventBookingModuleController $moduleInstance): bool { diff --git a/src/Listener/ContaoHooks/ExportTable.php b/src/Listener/ContaoHooks/ExportTable.php index deed666..2c3dc61 100644 --- a/src/Listener/ContaoHooks/ExportTable.php +++ b/src/Listener/ContaoHooks/ExportTable.php @@ -15,25 +15,21 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks; use Contao\CalendarEventsModel; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Framework\ContaoFramework; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Markocupic\ExportTable\Config\Config; use Markocupic\ExportTable\Listener\ContaoHooks\ListenerInterface; -/** - * @Hook(ExportTable::HOOK, priority=ExportTable::PRIORITY) - */ +#[AsHook(ExportTable::HOOK, priority: 1000)] final class ExportTable implements ListenerInterface { public const HOOK = 'exportTable'; - public const PRIORITY = 1000; public static bool $disableHook = false; - private ContaoFramework $framework; - public function __construct(ContaoFramework $framework) - { - $this->framework = $framework; + public function __construct( + private readonly ContaoFramework $framework, + ) { } /** diff --git a/src/Listener/ContaoHooks/LoadFormField.php b/src/Listener/ContaoHooks/LoadFormField.php index 8991e09..e4e3cff 100644 --- a/src/Listener/ContaoHooks/LoadFormField.php +++ b/src/Listener/ContaoHooks/LoadFormField.php @@ -16,28 +16,22 @@ use Contao\Config; use Contao\Controller; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Framework\ContaoFramework; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Date; use Contao\Form; use Contao\Widget; use Markocupic\CalendarEventBookingBundle\Helper\EventRegistration; -/** - * @Hook(LoadFormField::HOOK, priority=LoadFormField::PRIORITY) - */ +#[AsHook(LoadFormField::HOOK, priority: 1000)] final class LoadFormField { public const HOOK = 'loadFormField'; - public const PRIORITY = 1000; - - private ContaoFramework $framework; - private EventRegistration $eventRegistration; - public function __construct(ContaoFramework $framework, EventRegistration $eventRegistration) - { - $this->framework = $framework; - $this->eventRegistration = $eventRegistration; + public function __construct( + private readonly ContaoFramework $framework, + private readonly EventRegistration $eventRegistration, + ) { } public function __invoke(Widget $objWidget, string $strForm, array $arrForm, Form $objForm): Widget diff --git a/src/Listener/ContaoHooks/ParseTemplate.php b/src/Listener/ContaoHooks/ParseTemplate.php index 973b874..5cddc06 100644 --- a/src/Listener/ContaoHooks/ParseTemplate.php +++ b/src/Listener/ContaoHooks/ParseTemplate.php @@ -16,26 +16,20 @@ use Contao\CalendarEventsModel; use Contao\CalendarModel; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Framework\ContaoFramework; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Template; use Markocupic\CalendarEventBookingBundle\Helper\AddTemplateData; -/** - * @Hook(ParseTemplate::HOOK, priority=ParseTemplate::PRIORITY) - */ +#[AsHook(ParseTemplate::HOOK, priority: 1000)] final class ParseTemplate { public const HOOK = 'parseTemplate'; - public const PRIORITY = 1000; - - private ContaoFramework $framework; - private AddTemplateData $addTemplateData; - public function __construct(ContaoFramework $framework, AddTemplateData $addTemplateData) - { - $this->framework = $framework; - $this->addTemplateData = $addTemplateData; + public function __construct( + private readonly ContaoFramework $framework, + private readonly AddTemplateData $addTemplateData, + ) { } /** @@ -45,7 +39,7 @@ public function __invoke(Template $template): void { $calendarEventsModelAdapter = $this->framework->getAdapter(CalendarEventsModel::class); - if (empty($template->calendar) || 0 !== strpos($template->getName(), 'event')) { + if (empty($template->calendar) || !str_starts_with($template->getName(), 'event')) { return; } diff --git a/src/Listener/ContaoHooks/PostBooking/AddToSession.php b/src/Listener/ContaoHooks/PostBooking/AddToSession.php index 4af8dea..d806c03 100644 --- a/src/Listener/ContaoHooks/PostBooking/AddToSession.php +++ b/src/Listener/ContaoHooks/PostBooking/AddToSession.php @@ -14,23 +14,18 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\PostBooking; -use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Helper\EventRegistration; -/** - * @Hook(AddToSession::HOOK, priority=AddToSession::PRIORITY) - */ +#[AsHook(AddToSession::HOOK, priority: 1200)] final class AddToSession { public const HOOK = 'calEvtBookingPostBooking'; - public const PRIORITY = 1200; - - private EventRegistration $eventRegistration; - public function __construct(EventRegistration $eventRegistration) - { - $this->eventRegistration = $eventRegistration; + public function __construct( + private readonly EventRegistration $eventRegistration, + ) { } /** diff --git a/src/Listener/ContaoHooks/PostBooking/ContaoLog.php b/src/Listener/ContaoHooks/PostBooking/ContaoLog.php index 90b6fea..75600f3 100644 --- a/src/Listener/ContaoHooks/PostBooking/ContaoLog.php +++ b/src/Listener/ContaoHooks/PostBooking/ContaoLog.php @@ -15,25 +15,20 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\PostBooking; use Contao\CalendarEventsModel; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Monolog\ContaoContext; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Logger\Logger; use Psr\Log\LogLevel; -/** - * @Hook(ContaoLog::HOOK, priority=ContaoLog::PRIORITY) - */ +#[AsHook(ContaoLog::HOOK, priority: 1100)] final class ContaoLog { public const HOOK = 'calEvtBookingPostBooking'; - public const PRIORITY = 1100; - - private Logger $logger; - public function __construct(Logger $logger) - { - $this->logger = $logger; + public function __construct( + private readonly ?Logger $logger = null, + ) { } /** @@ -50,6 +45,9 @@ public function __invoke(CalendarEventBookingEventBookingModuleController $modul $strText = 'New booking for event with title "'.$objEvent->title.'"'; $level = LogLevel::INFO; - $this->logger->log($strText, $level, ContaoContext::GENERAL); + + if (null !== $this->logger) { + $this->logger->log($strText, $level, ContaoContext::GENERAL); + } } } diff --git a/src/Listener/ContaoHooks/PostBooking/Notification.php b/src/Listener/ContaoHooks/PostBooking/Notification.php index 7f9eca0..b3d2a17 100644 --- a/src/Listener/ContaoHooks/PostBooking/Notification.php +++ b/src/Listener/ContaoHooks/PostBooking/Notification.php @@ -14,23 +14,18 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\PostBooking; -use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Helper\NotificationHelper; -/** - * @Hook(Notification::HOOK, priority=Notification::PRIORITY) - */ +#[AsHook(Notification::HOOK, priority: 1000)] final class Notification { public const HOOK = 'calEvtBookingPostBooking'; - public const PRIORITY = 1000; - - private NotificationHelper $notificationHelper; - public function __construct(NotificationHelper $notificationHelper) - { - $this->notificationHelper = $notificationHelper; + public function __construct( + private readonly NotificationHelper $notificationHelper, + ) { } /** diff --git a/src/Listener/ContaoHooks/PrepareFormData/FormatInput.php b/src/Listener/ContaoHooks/PrepareFormData/FormatInput.php index eeb556a..6e460a4 100644 --- a/src/Listener/ContaoHooks/PrepareFormData/FormatInput.php +++ b/src/Listener/ContaoHooks/PrepareFormData/FormatInput.php @@ -14,25 +14,20 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\PrepareFormData; -use Contao\CoreBundle\ServiceAnnotation\Hook; -use Haste\Form\Form; +use Codefog\HasteBundle\Form\Form; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Helper\Formatter; use Markocupic\CalendarEventBookingBundle\Model\CalendarEventsMemberModel; -/** - * @Hook(FormatInput::HOOK, priority=FormatInput::PRIORITY) - */ +#[AsHook(FormatInput::HOOK, priority: 1000)] final class FormatInput { public const HOOK = 'calEvtBookingPrepareFormData'; - public const PRIORITY = 1000; - - private Formatter $formatter; - public function __construct(Formatter $formatter) - { - $this->formatter = $formatter; + public function __construct( + private readonly Formatter $formatter, + ) { } /** diff --git a/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEmailAddress.php b/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEmailAddress.php index 5eab5ac..23e7660 100644 --- a/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEmailAddress.php +++ b/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEmailAddress.php @@ -14,30 +14,24 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\ValidateBookingRequest; +use Codefog\HasteBundle\Form\Form; use Contao\CalendarEventsModel; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Framework\ContaoFramework; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Input; -use Haste\Form\Form; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Model\CalendarEventsMemberModel; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * @Hook(ValidateEmailAddress::HOOK, priority=ValidateEmailAddress::PRIORITY) - */ +#[AsHook(ValidateEmailAddress::HOOK, priority: 1000)] final class ValidateEmailAddress { public const HOOK = 'calEvtBookingValidateBookingRequest'; - public const PRIORITY = 1000; - - private ContaoFramework $framework; - private TranslatorInterface $translator; - public function __construct(ContaoFramework $framework, TranslatorInterface $translator) - { - $this->framework = $framework; - $this->translator = $translator; + public function __construct( + private readonly ContaoFramework $framework, + private readonly TranslatorInterface $translator, + ) { } /** diff --git a/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEscorts.php b/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEscorts.php index 6b694b6..8db4261 100644 --- a/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEscorts.php +++ b/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateEscorts.php @@ -14,28 +14,22 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\ValidateBookingRequest; +use Codefog\HasteBundle\Form\Form; use Contao\CalendarEventsModel; -use Contao\CoreBundle\ServiceAnnotation\Hook; -use Haste\Form\Form; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Helper\EventRegistration; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * @Hook(ValidateEscorts::HOOK, priority=ValidateEscorts::PRIORITY) - */ +#[AsHook(ValidateEscorts::HOOK, priority: 1200)] final class ValidateEscorts { public const HOOK = 'calEvtBookingValidateBookingRequest'; - public const PRIORITY = 1200; - - private TranslatorInterface $translator; - private EventRegistration $eventRegistration; - public function __construct(TranslatorInterface $translator, EventRegistration $eventRegistration) - { - $this->translator = $translator; - $this->eventRegistration = $eventRegistration; + public function __construct( + private readonly TranslatorInterface $translator, + private readonly EventRegistration $eventRegistration, + ) { } /** diff --git a/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateNumberOfParticipants.php b/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateNumberOfParticipants.php index 4502abc..677bd0e 100644 --- a/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateNumberOfParticipants.php +++ b/src/Listener/ContaoHooks/ValidateBookingRequest/ValidateNumberOfParticipants.php @@ -14,33 +14,26 @@ namespace Markocupic\CalendarEventBookingBundle\Listener\ContaoHooks\ValidateBookingRequest; +use Codefog\HasteBundle\Form\Form; use Contao\CalendarEventsModel; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\CoreBundle\Framework\ContaoFramework; -use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Message; use Doctrine\DBAL\Exception; -use Haste\Form\Form; use Markocupic\CalendarEventBookingBundle\Controller\FrontendModule\CalendarEventBookingEventBookingModuleController; use Markocupic\CalendarEventBookingBundle\Helper\EventRegistration; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * @Hook(ValidateNumberOfParticipants::HOOK, priority=ValidateNumberOfParticipants::PRIORITY) - */ +#[AsHook(ValidateNumberOfParticipants::HOOK, priority: 1100)] final class ValidateNumberOfParticipants { public const HOOK = 'calEvtBookingValidateBookingRequest'; - public const PRIORITY = 1100; - - private ContaoFramework $framework; - private TranslatorInterface $translator; - private EventRegistration $eventRegistration; - public function __construct(ContaoFramework $framework, TranslatorInterface $translator, EventRegistration $eventRegistration) - { - $this->framework = $framework; - $this->translator = $translator; - $this->eventRegistration = $eventRegistration; + public function __construct( + private readonly ContaoFramework $framework, + private readonly TranslatorInterface $translator, + private readonly EventRegistration $eventRegistration, + ) { } /** diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index bf1b224..94d2a1f 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -19,11 +19,9 @@ class Logger { - private ?LoggerInterface$logger; - - public function __construct(LoggerInterface $logger = null) - { - $this->logger = $logger; + public function __construct( + private readonly ?LoggerInterface $logger = null, + ) { } public function log(string $strText, string $strLevel, $strContaoLevel): void diff --git a/src/Migration/AutogenerateBookingForm.php b/src/Migration/AutogenerateBookingForm.php index bd5bdc7..8e09ae6 100644 --- a/src/Migration/AutogenerateBookingForm.php +++ b/src/Migration/AutogenerateBookingForm.php @@ -28,15 +28,11 @@ class AutogenerateBookingForm extends AbstractMigration { private const MIGRATION_TEXT = 'Auto generated event booking form sample. Please check out the form generator in the contao backend.'; - private ContaoFramework $framework; - private Connection $connection; - private string $projectDir; - - public function __construct(ContaoFramework $framework, Connection $connection, string $projectDir) - { - $this->framework = $framework; - $this->connection = $connection; - $this->projectDir = $projectDir; + public function __construct( + private readonly ContaoFramework $framework, + private readonly Connection $connection, + private readonly string $projectDir, + ) { } /** diff --git a/src/Migration/Version500/AutoGenerateBookingToken.php b/src/Migration/Version500/AutoGenerateBookingToken.php index a388165..5162d62 100644 --- a/src/Migration/Version500/AutoGenerateBookingToken.php +++ b/src/Migration/Version500/AutoGenerateBookingToken.php @@ -24,11 +24,9 @@ class AutoGenerateBookingToken extends AbstractMigration { private const MIGRATION_TEXT = "Auto generate missing booking tokens in data table 'tl_calendar_events_member'."; - private Connection $connection; - - public function __construct(Connection $connection) - { - $this->connection = $connection; + public function __construct( + private readonly Connection $connection, + ) { } /** diff --git a/src/Migration/Version500/RenameFrontendModuleType.php b/src/Migration/Version500/RenameFrontendModuleType.php index a0b4bcf..a7ea2c7 100644 --- a/src/Migration/Version500/RenameFrontendModuleType.php +++ b/src/Migration/Version500/RenameFrontendModuleType.php @@ -24,11 +24,9 @@ class RenameFrontendModuleType extends AbstractMigration { - private Connection $connection; - - public function __construct(Connection $connection) - { - $this->connection = $connection; + public function __construct( + private readonly Connection $connection, + ) { } /**