<?php
namespace Bidcoz\Bundle\CoreBundle;
use Bidcoz\Bundle\CoreBundle\Entity\Campaign;
use Bidcoz\Bundle\CoreBundle\Entity\User;
use Bidcoz\Bundle\CoreBundle\Factory\TransactionFactory;
use Bidcoz\Bundle\CoreBundle\Form\DataTransformer\EntityTransformerFactory;
use Bidcoz\Bundle\CoreBundle\Services\ActiveCampaignManager;
use Bidcoz\Bundle\CoreBundle\Services\AuctionManager;
use Bidcoz\Bundle\CoreBundle\Services\AuctionPermissionManager;
use Bidcoz\Bundle\CoreBundle\Services\BidManager;
use Bidcoz\Bundle\CoreBundle\Services\BidNumberManager;
use Bidcoz\Bundle\CoreBundle\Services\CampaignManager;
use Bidcoz\Bundle\CoreBundle\Services\CampaignStatsManager;
use Bidcoz\Bundle\CoreBundle\Services\CompanyImportManager;
use Bidcoz\Bundle\CoreBundle\Services\CompanyManager;
use Bidcoz\Bundle\CoreBundle\Services\ContactImportManager;
use Bidcoz\Bundle\CoreBundle\Services\ContactManager;
use Bidcoz\Bundle\CoreBundle\Services\CreditCardManager;
use Bidcoz\Bundle\CoreBundle\Services\CustomMessagesManager;
use Bidcoz\Bundle\CoreBundle\Services\DisplayFeedManager;
use Bidcoz\Bundle\CoreBundle\Services\DonationManager;
use Bidcoz\Bundle\CoreBundle\Services\EmailManager;
use Bidcoz\Bundle\CoreBundle\Services\ErrorMessageManager;
use Bidcoz\Bundle\CoreBundle\Services\FinancialCalculator;
use Bidcoz\Bundle\CoreBundle\Services\FreshdeskManager;
use Bidcoz\Bundle\CoreBundle\Services\ItemCategoryManager;
use Bidcoz\Bundle\CoreBundle\Services\ItemImportManager;
use Bidcoz\Bundle\CoreBundle\Services\ItemManager;
use Bidcoz\Bundle\CoreBundle\Services\JobManager;
use Bidcoz\Bundle\CoreBundle\Services\KindfulJobManager;
use Bidcoz\Bundle\CoreBundle\Services\LinkManager;
use Bidcoz\Bundle\CoreBundle\Services\LoggedInUserProvider;
use Bidcoz\Bundle\CoreBundle\Services\LoginLinkManager;
use Bidcoz\Bundle\CoreBundle\Services\LogManager;
use Bidcoz\Bundle\CoreBundle\Services\MandrillManager;
use Bidcoz\Bundle\CoreBundle\Services\MediaManager;
use Bidcoz\Bundle\CoreBundle\Services\MessageManager;
use Bidcoz\Bundle\CoreBundle\Services\NotificationManager;
use Bidcoz\Bundle\CoreBundle\Services\OrganizationManager;
use Bidcoz\Bundle\CoreBundle\Services\OrganizationStatsManager;
use Bidcoz\Bundle\CoreBundle\Services\PaymentGatewayManager;
use Bidcoz\Bundle\CoreBundle\Services\PayPalManager;
use Bidcoz\Bundle\CoreBundle\Services\PdfManager;
use Bidcoz\Bundle\CoreBundle\Services\PermissionManager;
use Bidcoz\Bundle\CoreBundle\Services\PurchaseManager;
use Bidcoz\Bundle\CoreBundle\Services\QuestionManager;
use Bidcoz\Bundle\CoreBundle\Services\RaffleManager;
use Bidcoz\Bundle\CoreBundle\Services\RegistrationManager;
use Bidcoz\Bundle\CoreBundle\Services\ReportManager;
use Bidcoz\Bundle\CoreBundle\Services\ReservedSeatUploadManager;
use Bidcoz\Bundle\CoreBundle\Services\SMSManager;
use Bidcoz\Bundle\CoreBundle\Services\SponsorshipManager;
use Bidcoz\Bundle\CoreBundle\Services\StripeManager;
use Bidcoz\Bundle\CoreBundle\Services\TagManager;
use Bidcoz\Bundle\CoreBundle\Services\TicketManager;
use Bidcoz\Bundle\CoreBundle\Services\TicketPermissionManager;
use Bidcoz\Bundle\CoreBundle\Services\TicketUploadManager;
use Bidcoz\Bundle\CoreBundle\Services\TransactionManager;
use Bidcoz\Bundle\CoreBundle\Services\UserManager as BidcozUserManager;
use Bidcoz\Bundle\CoreBundle\Services\VolunteerManager;
use Bidcoz\Bundle\CoreBundle\Services\WatchListManager;
use Bidcoz\Bundle\CoreBundle\SMS\Conversation\ConversationFactory;
use Bidcoz\Bundle\CoreBundle\SMS\SMSSenderFactory;
use Bidcoz\Bundle\FrontendBundle\Twig\Extension\TicketExtension;
use Bidcoz\Bundle\KindfulBundle\Service\ContactsService;
use Bidcoz\Bundle\KindfulBundle\Service\KindfulService;
use Bidcoz\Bundle\UserBundle\PhoneNumberAssociationManager;
use Doctrine\ORM\EntityManagerInterface;
use Faker\Factory;
use Faker\Generator;
use FOS\UserBundle\Form\Factory\FactoryInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use GuzzleHttp\Client;
use JMS\Serializer\SerializerInterface;
use Knp\Component\Pager\PaginatorInterface;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Lexik\Bundle\FormFilterBundle\Filter\FilterBuilderUpdaterInterface;
use Psr\Log\LoggerInterface;
use RS\DiExtraBundle\Annotation as DI;
use Stripe\Stripe;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
trait BidcozCoreServices
{
protected ContainerInterface $locator;
/**
* @DI\InjectParams({
* "locator" = @DI\Inject("service_container"),
* })
*/
public function __construct(ContainerInterface $locator)
{
$this->locator = $locator;
}
public static function getSubscribedServices(): array
{
$services = [
'active_campaign_manager' => ActiveCampaignManager::class,
'auction_manager' => AuctionManager::class,
'auction_permission_manager' => AuctionPermissionManager::class,
'bid_manager' => BidManager::class,
'bidcoz.form.entity_transformer_factory' => EntityTransformerFactory::class,
ContactsService::class => ContactsService::class,
KindfulService::class => KindfulService::class,
TicketExtension::class => TicketExtension::class,
'bidnumber_manager' => BidNumberManager::class,
'campaign_manager' => CampaignManager::class,
'campaign_stats_manager' => CampaignStatsManager::class,
'company_import_manager' => CompanyImportManager::class,
'company_manager' => CompanyManager::class,
'contact_import_manager' => ContactImportManager::class,
'contact_manager' => ContactManager::class,
'conversation_factory' => ConversationFactory::class,
'credit_card_manager' => CreditCardManager::class,
'custom_messages_manager' => CustomMessagesManager::class,
'display_feed_manager' => DisplayFeedManager::class,
'doctrine.orm.default_entity_manager' => EntityManagerInterface::class,
'donation_manager' => DonationManager::class,
'email_manager' => EmailManager::class,
'error_message_manager' => ErrorMessageManager::class,
'event_dispatcher' => EventDispatcherInterface::class,
'financial_calculator' => FinancialCalculator::class,
'form.factory' => FormFactoryInterface::class,
'fos_user.user_manager' => UserManagerInterface::class,
'freshdesk_manager' => FreshdeskManager::class,
'item_category_manager' => ItemCategoryManager::class,
'item_import_manager' => ItemImportManager::class,
'item_manager' => ItemManager::class,
'jms_serializer' => SerializerInterface::class,
'job_manager' => JobManager::class,
'kindful_job_manager' => KindfulJobManager::class,
'knp_paginator' => PaginatorInterface::class,
'knpu.oauth2.registry' => ClientRegistry::class,
'lexik_form_filter.query_builder_updater' => FilterBuilderUpdaterInterface::class,
'link_manager' => LinkManager::class,
'log_manager' => LogManager::class,
'logger' => LoggerInterface::class,
'login_link_manager' => LoginLinkManager::class,
'mandrill_manager' => MandrillManager::class,
'media_manager' => MediaManager::class,
'message_manager' => MessageManager::class,
'monolog.logger.paypal' => LoggerInterface::class,
'notification_manager' => NotificationManager::class,
'organization_manager' => OrganizationManager::class,
'organization_stats_manager' => OrganizationStatsManager::class,
'payment_gateway_manager' => PaymentGatewayManager::class,
'paypal_manager' => PayPalManager::class,
'pdf_manager' => PdfManager::class,
'permission_manager' => PermissionManager::class,
'phone_number_association_manager' => PhoneNumberAssociationManager::class,
'purchase_manager' => PurchaseManager::class,
'question_manager' => QuestionManager::class,
'raffle_manager' => RaffleManager::class,
'registration_manager' => RegistrationManager::class,
'report_manager' => ReportManager::class,
'request_stack' => RequestStack::class,
'reserved_seat_upload_manager' => ReservedSeatUploadManager::class,
'router' => RouterInterface::class,
'sms_manager' => SMSManager::class,
'sms_sender_factory' => SMSSenderFactory::class,
'security.authorization_checker' => AuthorizationCheckerInterface::class,
'sponsorship_manager' => SponsorshipManager::class,
'stripe_manager' => StripeManager::class,
'tag_manager' => TagManager::class,
'ticket_manager' => TicketManager::class,
'ticket_permission_manager' => TicketPermissionManager::class,
'ticket_upload_manager' => TicketUploadManager::class,
'transaction_factory' => TransactionFactory::class,
'transaction_manager' => TransactionManager::class,
'user_manager' => BidcozUserManager::class,
'user_provider' => LoggedInUserProvider::class,
'validator' => ValidatorInterface::class,
'volunteer_manager' => VolunteerManager::class,
'watchlist_manager' => WatchListManager::class,
];
if (method_exists(parent::class, 'getSubscribedServices')) {
return array_merge(parent::getSubscribedServices(), $services);
}
return $services;
}
protected function get($service): object
{
return $this->locator->get($service);
}
protected function getEntityManager(): EntityManagerInterface
{
return $this->locator->get('doctrine.orm.default_entity_manager');
}
protected function getRepository($class, $fullPath = false)
{
$className = $fullPath
? $class
: sprintf('\\Bidcoz\\Bundle\\CoreBundle\\Entity\\%s', $class);
return $this->getEntityManager()->getRepository($className);
}
protected function getEntityReference($class, $id, $fullPath = false)
{
$className = $fullPath
? $class
: sprintf('\\Bidcoz\\Bundle\\CoreBundle\\Entity\\%s', $class);
return $this->getEntityManager()->getReference($className, $id);
}
protected function getUserManager(): UserManagerInterface
{
return $this->get('fos_user.user_manager');
}
protected function getBidcozUserManager(): BidcozUserManager
{
return $this->get('user_manager');
}
protected function getRaffleManager(): RaffleManager
{
return $this->get('raffle_manager');
}
protected function getEventDispatcher(): EventDispatcherInterface
{
return $this->get('event_dispatcher');
}
protected function getOrganizationManager(): OrganizationManager
{
return $this->get('organization_manager');
}
protected function getCampaignManager(): CampaignManager
{
return $this->get('campaign_manager');
}
protected function getCampaignStatsManager(): CampaignStatsManager
{
return $this->get('campaign_stats_manager');
}
protected function getOrganizationStatsManager(): OrganizationStatsManager
{
return $this->get('organization_stats_manager');
}
protected function getJobManager(): JobManager
{
return $this->get('job_manager');
}
protected function getTransactionManager(): TransactionManager
{
return $this->get('transaction_manager');
}
protected function getVolunteerManager(): VolunteerManager
{
return $this->get('volunteer_manager');
}
protected function getTransactionFactory(): TransactionFactory
{
return $this->get('transaction_factory');
}
protected function getTicketManager(): TicketManager
{
return $this->get('ticket_manager');
}
protected function getTicketUploadManager(): TicketUploadManager
{
return $this->get('ticket_upload_manager');
}
protected function getReservedSeatsUploadManager(Campaign $campaign): ReservedSeatUploadManager
{
$manager = $this->get('reserved_seat_upload_manager');
$manager->setCampaign($campaign);
return $manager;
}
protected function getRegistrationManager(): RegistrationManager
{
return $this->get('registration_manager');
}
protected function getTagManager(): TagManager
{
return $this->get('tag_manager');
}
protected function getContactManager(): ContactManager
{
return $this->get('contact_manager');
}
protected function getContactImportManager(): ContactImportManager
{
return $this->get('contact_import_manager');
}
protected function getPurchaseManager(): PurchaseManager
{
return $this->get('purchase_manager');
}
protected function getDonationManager(): DonationManager
{
return $this->get('donation_manager');
}
protected function getCcManager(): CreditCardManager
{
return $this->get('credit_card_manager');
}
protected function getMediaManager(): MediaManager
{
return $this->get('media_manager');
}
protected function getAuctionManager(): AuctionManager
{
return $this->get('auction_manager');
}
protected function getBidManager(): BidManager
{
return $this->get('bid_manager');
}
protected function getPaymentGatewayManager(): PaymentGatewayManager
{
return $this->get('payment_gateway_manager');
}
protected function getBidNumberManager(): BidNumberManager
{
return $this->get('bidnumber_manager');
}
protected function getItemManager(): ItemManager
{
return $this->get('item_manager');
}
protected function getItemCategoryManager(): ItemCategoryManager
{
return $this->get('item_category_manager');
}
protected function getItemImportManager(): ItemImportManager
{
return $this->get('item_import_manager');
}
protected function getWatchListManager(): WatchListManager
{
return $this->get('watchlist_manager');
}
protected function getSponsorshipManager(): SponsorshipManager
{
return $this->get('sponsorship_manager');
}
protected function getPermissionManager(): PermissionManager
{
return $this->get('permission_manager');
}
protected function getAuctionPermissionManager(): AuctionPermissionManager
{
return $this->get('auction_permission_manager');
}
protected function getTicketPermissionManager(): TicketPermissionManager
{
return $this->get('ticket_permission_manager');
}
protected function getReportManager(): ReportManager
{
return $this->get('report_manager');
}
protected function getQuestionManager(): QuestionManager
{
return $this->get('question_manager');
}
protected function getPaginator(): PaginatorInterface
{
return $this->get('knp_paginator');
}
protected function getQueryBuilderFilter(): FilterBuilderUpdaterInterface
{
return $this->get('lexik_form_filter.query_builder_updater');
}
protected function getSerializer(): SerializerInterface
{
return $this->get('jms_serializer');
}
protected function getSession(): SessionInterface
{
return $this->getRequestStack()->getSession();
}
protected function getRouter(): RouterInterface
{
return $this->get('router');
}
protected function getLogger(): LoggerInterface
{
return $this->get('logger');
}
protected function getPaypalLogger(): LoggerInterface
{
return $this->get('monolog.logger.paypal');
}
protected function getValidator(): ValidatorInterface
{
return $this->get('validator');
}
protected function getPayPalManager(): PayPalManager
{
return $this->get('paypal_manager');
}
protected function getCompanyManager(): CompanyManager
{
return $this->get('company_manager');
}
protected function getCompanyImportManager(): CompanyImportManager
{
return $this->get('company_import_manager');
}
protected function getTransformerFactory(): EntityTransformerFactory
{
return $this->get('bidcoz.form.entity_transformer_factory');
}
protected function getEmailManager(): EmailManager
{
return $this->get('email_manager');
}
protected function getSMSManager(): SMSManager
{
return $this->get('sms_manager');
}
protected function getSMSSenderFactory(): SMSSenderFactory
{
return $this->get('sms_sender_factory');
}
protected function getFinancialCalculator(): FinancialCalculator
{
return $this->get('financial_calculator');
}
protected function getFormFactory(): FormFactoryInterface
{
return $this->get('form.factory');
}
protected function getLinkManager(): LinkManager
{
return $this->get('link_manager');
}
protected function getLoggedInUserProvider(): LoggedInUserProvider
{
return $this->get('user_provider');
}
protected function getLoggedInUser()
{
return $this->getLoggedInUserProvider()->getLoggedInUser();
}
protected function getUserTimezone(Campaign $campaign = null)
{
$user = $this->getLoggedInUser();
if ($user) {
return $user->getTimezone();
} else {
return $campaign
? $campaign->getTimezone()
: 'America/Chicago';
}
}
protected function getEntityTransformer($class, $fullPath = false)
{
$className = $fullPath
? $class
: sprintf('Bidcoz\Bundle\CoreBundle\Entity\%s', $class);
return $this->getTransformerFactory()->create($className);
}
protected function getActiveConfiguration()
{
return $this->getRepository('Config')->findActiveConfig();
}
protected function getFaker($seed = null): Generator
{
$faker = Factory::create();
if ($seed) {
$faker->seed($seed);
}
return $faker;
}
protected function getGuzzleClient(): Client
{
return new Client();
}
protected function getStripeManager(): StripeManager
{
return $this->get('stripe_manager');
}
protected function getFreshdeskManager(): FreshdeskManager
{
return $this->get('freshdesk_manager');
}
protected function getLoginLinkManager(): LoginLinkManager
{
return $this->get('login_link_manager');
}
protected function getMandrillManager(): MandrillManager
{
return $this->get('mandrill_manager');
}
protected function getStripeCredentials()
{
return $this->getContainerParameter('stripe');
}
protected function getContainerParameter(string $parameter)
{
return $this->locator->getParameter($parameter);
}
protected function setupStripe()
{
$apiKey = $this->getStripeCredentials()['secret_key'];
Stripe::setApiKey($apiKey);
}
protected function getLogManager(): LogManager
{
return $this->get('log_manager');
}
protected function createLog(User $user, Campaign $campaign, $message, array $data = []): void
{
$this->getLogManager()->createLog($user, $campaign, $message, $data);
}
protected function getNotificationManager(): NotificationManager
{
return $this->get('notification_manager');
}
protected function getKindfulManager(): KindfulService
{
return $this->get(KindfulService::class);
}
protected function getKindfulJobManager(): KindfulJobManager
{
return $this->get('kindful_job_manager');
}
protected function getMessageManager(): MessageManager
{
return $this->get('message_manager');
}
protected function getCustomMessagesManager(): CustomMessagesManager
{
return $this->get('custom_messages_manager');
}
protected function getActiveCampaignManager(): ActiveCampaignManager
{
return $this->get('active_campaign_manager');
}
protected function getPdfManager(): PdfManager
{
return $this->get('pdf_manager');
}
protected function getDisplayFeedManager(): DisplayFeedManager
{
return $this->get('display_feed_manager');
}
protected function getErrorMessageManager(): ErrorMessageManager
{
return $this->get('error_message_manager');
}
protected function getRequestStack(): RequestStack
{
return $this->get('request_stack');
}
protected function getOauthRegistry(): ClientRegistry
{
return $this->get('knpu.oauth2.registry');
}
protected function getKindfulContacts(): ContactsService
{
return $this->get(ContactsService::class);
}
protected function getTicketExtension(): TicketExtension
{
return $this->get(TicketExtension::class);
}
protected function getAuthorizationChecker(): AuthorizationCheckerInterface
{
return $this->get('security.authorization_checker');
}
protected function getRegistrationFormFactory(): FactoryInterface
{
return $this->get('fos_user.registration.form.factory');
}
}