From 0aa344dc247c77376fcbf2112191f9f8b3dfc846 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 24 Dec 2015 15:22:56 +0100 Subject: Update url & service name Prefix ur with service namel: [service]_[route name] Add comment in Interface --- .../ImportBundle/Controller/PocketController.php | 15 ++++++---- .../ImportBundle/Import/ImportInterface.php | 33 ++++++++++++++++++++++ src/Wallabag/ImportBundle/Import/PocketImport.php | 9 +++++- .../ImportBundle/Resources/config/services.yml | 8 +++--- .../Resources/views/Import/index.html.twig | 2 +- .../Resources/views/Pocket/index.html.twig | 2 +- 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index f851c81c..2ab062e7 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -8,7 +8,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class PocketController extends Controller { /** - * @Route("/import/pocket", name="pocket") + * @Route("/import/pocket", name="pocket_import") */ public function indexAction() { @@ -16,22 +16,25 @@ class PocketController extends Controller } /** - * @Route("/import/pocket/auth", name="authpocket") + * @Route("/import/pocket/auth", name="pocket_auth") */ public function authAction() { - $pocket = $this->get('wallabag_import.import.pocket_import'); - $authUrl = $pocket->oAuthRequest($this->generateUrl('import', array(), true), $this->generateUrl('callbackpocket', array(), true)); + $pocket = $this->get('wallabag_import.pocket.import'); + $authUrl = $pocket->oAuthRequest( + $this->generateUrl('import', array(), true), + $this->generateUrl('pocket_callback', array(), true) + ); return $this->redirect($authUrl, 301); } /** - * @Route("/import/pocket/callback", name="callbackpocket") + * @Route("/import/pocket/callback", name="pocket_callback") */ public function callbackAction() { - $pocket = $this->get('wallabag_import.import.pocket_import'); + $pocket = $this->get('wallabag_import.pocket.import'); $accessToken = $pocket->oAuthAuthorize(); $pocket->import($accessToken); diff --git a/src/Wallabag/ImportBundle/Import/ImportInterface.php b/src/Wallabag/ImportBundle/Import/ImportInterface.php index f07a120c..0f9b3256 100644 --- a/src/Wallabag/ImportBundle/Import/ImportInterface.php +++ b/src/Wallabag/ImportBundle/Import/ImportInterface.php @@ -4,9 +4,42 @@ namespace Wallabag\ImportBundle\Import; interface ImportInterface { + /** + * Name of the import. + * + * @return string + */ public function getName(); + + /** + * Description of the import. + * + * @return string + */ public function getDescription(); + + /** + * Return the oauth url to authenticate the client. + * + * @param string $redirectUri Redirect url in case of error + * @param string $callbackUri Url when the authentication is complete + * + * @return string + */ public function oAuthRequest($redirectUri, $callbackUri); + + /** + * Usually called by the previous callback to authorize the client. + * Then it return a token that can be used for next requests. + * + * @return string + */ public function oAuthAuthorize(); + + /** + * Import content using the user token. + * + * @param string $accessToken User access token + */ public function import($accessToken); } diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index ef8f9eb5..85bab0db 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Import; use Doctrine\ORM\EntityManager; use GuzzleHttp\Client; use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Tools\Utils; @@ -18,7 +19,7 @@ class PocketImport implements ImportInterface private $skippedEntries = 0; private $importedEntries = 0; - public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey) + public function __construct(TokenStorageInterface $tokenStorage, Session $session, EntityManager $em, $consumerKey) { $this->user = $tokenStorage->getToken()->getUser(); $this->session = $session; @@ -26,11 +27,17 @@ class PocketImport implements ImportInterface $this->consumerKey = $consumerKey; } + /** + * {@inheritdoc} + */ public function getName() { return 'Pocket'; } + /** + * {@inheritdoc} + */ public function getDescription() { return 'This importer will import all your Pocket data.'; diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index 82628f08..d77779eb 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml @@ -1,8 +1,8 @@ services: - wallabag_import.import.pocket_import: + wallabag_import.pocket.import: class: Wallabag\ImportBundle\Import\PocketImport arguments: - - @security.token_storage - - @session - - @doctrine.orm.entity_manager + - "@security.token_storage" + - "@session" + - "@doctrine.orm.entity_manager" - %pocket_consumer_key% diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig index bdd57e5e..fda21f2d 100644 --- a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig +++ b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig @@ -8,7 +8,7 @@
{% trans %}Welcome on wallabag importer. Please select your previous service that you want to migrate.{% endtrans %}
diff --git a/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig index e6abc17b..df64e472 100644 --- a/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig +++ b/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig @@ -7,7 +7,7 @@
{% trans %}You can import your data from your Pocket account. You just have to click on the below button and authorize the application to connect to getpocket.com.{% endtrans %} -
+
-- cgit v1.2.3