Skip to content

Commit

Permalink
use attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevster committed Jan 13, 2025
1 parent 5931a4c commit 9f8f36d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 21 deletions.
File renamed without changes.
18 changes: 18 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
_defaults:
autoconfigure: true

Pdir\SocialFeedBundle\Controller\FacebookController:
public: true
arguments:
- '@database_connection'
- '@router'

Pdir\SocialFeedBundle\Controller\InstagramController:
public: true

Pdir\SocialFeedBundle\Controller\LinkedinController:
public: true
arguments:
- '@database_connection'
- '@router'
6 changes: 4 additions & 2 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pdir_social_feed.controller:
resource: ../src/Controller
pdir_social_feed.controllers:
resource:
path: ../src/Controller/
namespace: Pdir\SocialFeedBundle\Controller
type: attribute
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public function getRouteCollection(LoaderResolverInterface $resolver, KernelInte
return $resolver
->resolve(__DIR__.'/../../config/routes.yaml')
->load(__DIR__.'/../../config/routes.yaml')
;
;
}
}
12 changes: 7 additions & 5 deletions src/Controller/FacebookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Attributes\Route;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;

#[Route('/_facebook', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])]
#[Route('_facebook', defaults: ['_scope' => 'backend', '_token_check' => false])]
class FacebookController
{
private Connection $db;
Expand All @@ -51,13 +51,15 @@ public function __construct(Connection $db, RouterInterface $router)
$this->session = System::getContainer()->get('request_stack')->getCurrentRequest()->getSession();
}

/**
* @Route("/auth", name="facebook_auth", methods={"GET"})
*/
#[Route('/auth', name: 'facebook_auth', methods: ['GET'])]
public function authAction(Request $request): Response
{
$sessionData = $this->session->get(SocialFeedListener::SESSION_KEY);

if (empty($sessionData['backUrl'])) {
return new Response(Response::$statusTexts[Response::HTTP_BAD_REQUEST], Response::HTTP_BAD_REQUEST);
}

$data = [
'client_id' => $sessionData['clientId'],
'client_secret' => $sessionData['clientSecret'],
Expand Down
8 changes: 3 additions & 5 deletions src/Controller/InstagramController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

#[Route('/_instagram', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])]
#[Route('_instagram', defaults: ['_scope' => 'backend', '_token_check' => false])]
class InstagramController
{
/**
Expand Down Expand Up @@ -73,9 +73,7 @@ public function __construct(InstagramClient $client, Connection $db, RouterInter
$this->tokenStorage = $tokenStorage;
}

/**
* @Route("/auth", name="instagram_auth", methods={"GET"})
*/
#[Route('/auth', name: 'instagram_auth', methods: ['GET'])]
public function authAction(Request $request): Response
{
// Missing code query parameter
Expand Down
11 changes: 5 additions & 6 deletions src/Controller/LinkedinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

namespace Pdir\SocialFeedBundle\Controller;

use Contao\CoreBundle\Monolog\ContaoContext;
use Contao\System;
use Doctrine\DBAL\Connection;
use Pdir\SocialFeedBundle\EventListener\DataContainer\SocialFeedListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;

#[Route('/auth', name: ExampleController::class, defaults: ['_scope' => 'backend', '_token_check' => false])]
#[Route('auth', defaults: ['_scope' => 'backend', '_token_check' => false])]
class LinkedinController
{
private Connection $db;
Expand All @@ -49,9 +50,7 @@ public function __construct(Connection $db, RouterInterface $router)
$this->session = System::getContainer()->get('request_stack')->getCurrentRequest()->getSession();
}

/**
* @Route("/linkedin", name="auth_linkedin", methods={"GET"})
*/
#[Route('/linkedin', name: 'auth_linkedin', methods: ['GET'])]
public function authAction(Request $request): Response
{
$sessionData = $this->session->get(SocialFeedListener::SESSION_KEY);
Expand All @@ -76,7 +75,7 @@ public function authAction(Request $request): Response
$this->db->update('tl_social_feed', ['linkedin_access_token' => $token->access_token, 'access_token_expires' => time() + $token->expires_in, 'linkedin_refresh_token' => $token->refresh_token, 'linkedin_refresh_token_expires' => time() + $token->refresh_token_expires_in], ['id' => $sessionData['socialFeedId']]);
$this->session->remove(SocialFeedListener::SESSION_KEY);
} catch (\Exception $e) {
System::log($e->getMessage(), __METHOD__, TL_GENERAL);
System::log($e->getMessage(), __METHOD__, ContaoContext::GENERAL);
}

return new RedirectResponse($sessionData['backUrl']);
Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/PdirSocialFeedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
new FileLocator(__DIR__.'/../../config')
);

$loader->load('commands.yml');
$loader->load('services.yml');
$loader->load('commands.yaml');
$loader->load('controller.yaml');
$loader->load('services.yaml');

$container->getDefinition(InstagramRequestCache::class)->setArgument(1, (int) $mergedConfig['cache_ttl']);
}
Expand Down

0 comments on commit 9f8f36d

Please sign in to comment.