Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from mediapart/v2.0
Browse files Browse the repository at this point in the history
V2.0
  • Loading branch information
methylbro authored Nov 17, 2017
2 parents 007a99e + 2fb07d5 commit a689339
Show file tree
Hide file tree
Showing 28 changed files with 600 additions and 87 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/coverage/
/vendor/
/composer.lock
/phpunit.xml
/tests/Functional/App/cache
/tests/Functional/App/logs
56 changes: 50 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Load the bundle into your Kernel:

$bundles = array(
// ...
new Meup\Bundle\LaPresseLibreBundle\MediapartLaPresseLibreBundle(),
new Mediapart\Bundle\LaPresseLibreBundle\MediapartLaPresseLibreBundle(),
);
```

Expand All @@ -26,20 +26,22 @@ Configure your App with your [LaPresseLibre partner credentials](https://partena
```yaml
# app/config/config.yml

mediapart_lapresselibre:
mediapart_la_presse_libre:
public_key: %lapresselibre_publickey%
secret_key: %lapresselibre_secretkey%
aes_password: %lapresselibre_aespassword%
aes_iv: %lapresselibre_aesiv%
```
### WebServices
Configure the routing:
```yaml
# app/config/routing.yml

MediapartLaPresseLibre:
resource: "@MediapartLaPresseLibreBundle/Resources/config/routing.php"
MediapartLaPresseLibreWebServices:
resource: "@MediapartLaPresseLibreBundle/Resources/config/routing/webservices.php"
#prefix: lapresselibre/
```

Expand Down Expand Up @@ -89,6 +91,48 @@ services:
class: 'AppBundle\LaPresseLibre\Verification'
arguments:
- '%lapresselibre_publickey%'
tags:
- { name: 'lapresselibre', route: 'lapresselibre_verification', operation: 'Mediapart\LaPresseLibre\Operation\Verification', method: 'alwaysVerifiedAccounts' }
tags:
- { name: 'lapresselibre', route: 'lapresselibre_verification', operation: 'Mediapart\LaPresseLibre\Operation\Verification', method: 'alwaysVerifiedAccounts' }
```
### Link Account
https://github.com/NextINpact/LaPresseLibreSDK/wiki/Liaison-de-compte-utilisateur-par-redirection
Configure the routing:
```yaml
# app/config/routing.yml

MediapartLaPresseLibreLinkAccount:
resource: "@MediapartLaPresseLibreBundle/Resources/config/routing/link-account.php"
#prefix: lapresselibre/
```

Implements `Mediapart/LaPresseLibre/Account/Repository` and `Mediapart\Bundle\LaPresseLibreBundle\Account\AccountProvider` interfaces.

```yaml
# app/config/services.yml

services:
#
your_account_repository:
class: 'AppBundle\LaPresseLibre\AccountRepository'
your_account_provider:
class: 'AppBundle\LaPresseLibre\AccountProvider'
```
Update the config :
```yaml
# app/config/config.yml

mediapart_lapresselibre:
#
account:
repository: 'your_account_repository'
provider: 'your_account_provider'
```
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
],
"autoload": {
"psr-4": {
"Mediapart\\Bundle\\LaPresseLibreBundle\\": "src/",
"Mediapart\\Bundle\\LaPresseLibreBundle\\Test\\": "tests/"
"Mediapart\\Bundle\\LaPresseLibreBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Mediapart\\Bundle\\LaPresseLibreBundle\\Test\\": "tests/"
}
},
"require": {
"php": "^5.6|^7.0",
"mediapart/lapresselibre": "^1.0",
"mediapart/lapresselibre": "^2.0",
"symfony/psr-http-message-bridge": "^1.0",
"symfony/options-resolver": "^2.8|^3.3",
"zendframework/zend-diactoros": "^1.4"
Expand Down
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@
</whitelist>
</filter>

<php>
<env name="lapresselibre_publickey" value="2" />
<env name="lapresselibre_secretkey" value="mGoMuzoX8u" />
<env name="lapresselibre_aespassword" value="UKKzV7sxiGx3uc0auKrUO2kJTT2KSCeg" />
<env name="lapresselibre_aesiv" value="7405589013321961" />
<env name="lapresselibre_aesoptions" value="0" />
</php>

</phpunit>
22 changes: 22 additions & 0 deletions src/Account/AccountProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* This file is part of the Mediapart LaPresseLibre Bundle.
*
* CC BY-NC-SA <https://github.com/mediapart/lapresselibre-bundle>
*
* For the full license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Mediapart\Bundle\LaPresseLibreBundle\Account;

use Mediapart\LaPresseLibre\Account\Account;

interface AccountProvider
{
/**
* @return Account
*/
public function __invoke();
}
63 changes: 63 additions & 0 deletions src/Controller/LinkAccountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* This file is part of the Mediapart LaPresseLibre Bundle.
*
* CC BY-NC-SA <https://github.com/mediapart/lapresselibre-bundle>
*
* For the full license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Mediapart\Bundle\LaPresseLibreBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Mediapart\Bundle\LaPresseLibreBundle\Factory\RedirectionFactory;

/**
* Use to link an account
*/
class LinkAccountController
{
/**
* @var RedirectionFactory
*/
private $redirectionFactory;

/**
* @param RedirectionFactory $redirectionFactory
*/
public function __construct(RedirectionFactory $redirectionFactory)
{
$this->redirectionFactory = $redirectionFactory;
}

/**
* @param Request $request
*
* @return Response
*
* @throws HttpException
*/
public function __invoke(Request $request)
{
try {
$redirection = $this
->redirectionFactory
->generate($request)
;
$response = new RedirectResponse($redirection);
} catch (\Exception $exception) {
throw new HttpException(
Response::HTTP_INTERNAL_SERVER_ERROR,
'Internal Error',
$exception
);
}

return $response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Use to respond to the La Presse Libre requests.
*/
class LaPresseLibreController
class WebServicesController
{
/**
* @var Handler
Expand All @@ -41,7 +41,7 @@ public function __construct(Handler $handler)
*
* @throws HttpException
*/
public function executeAction(Request $request)
public function __invoke(Request $request)
{
$headers = array_merge(
$this->handler->getHttpResponseHeaders(),
Expand Down Expand Up @@ -87,8 +87,8 @@ public function executeAction(Request $request)
*
* @throws HttpException
*/
private function throwHttpException($code, $message = '', \Exception $exception, array $headers = [])
protected function throwHttpException($code, $message = '', \Exception $exception, array $headers = [])
{
throw new HttpException($code, $message, $exception, $headers);
}
}
}
6 changes: 6 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public function getConfigTreeBuilder()
->scalarNode('aes_options')
->defaultValue(OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING)
->end()
->arrayNode('account')
->children()
->scalarNode('repository')->end()
->scalarNode('provider')->end()
->end()
->end()

->end()
;
Expand Down
73 changes: 64 additions & 9 deletions src/DependencyInjection/MediapartLaPresseLibreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Mediapart\LaPresseLibre\Transaction;
use Mediapart\LaPresseLibre\Registration;
use Mediapart\LaPresseLibre\Account\Link;
use Mediapart\LaPresseLibre\Security\Encryption;
use Mediapart\LaPresseLibre\Security\Identity;
use Mediapart\Bundle\LaPresseLibreBundle\Controller\LaPresseLibreController as Controller;
use Mediapart\Bundle\LaPresseLibreBundle\Controller;
use Mediapart\Bundle\LaPresseLibreBundle\Handler;
use Mediapart\Bundle\LaPresseLibreBundle\Factory\EndpointFactory;
use Mediapart\Bundle\LaPresseLibreBundle\Factory\TransactionFactory;
use Mediapart\Bundle\LaPresseLibreBundle\Factory;

/**
* This is the class that loads and manages your bundle configuration
Expand All @@ -48,11 +48,14 @@ public function load(array $configs, ContainerBuilder $container)
->loadIdentity($config, $container)
->loadEncryption($config, $container)
->loadTransactionFactory($config, $container)
->loadRedirectionFactory($config, $container)
->loadEndpointFactory($container)
->loadPsr7Factory($container)
->loadHandler($container)
->loadController($container)
->loadWebServicesController($container)
->loadLinkAccountController($config, $container)
->loadRegistration($config, $container)
->loadLink($config, $container)
;
}

Expand Down Expand Up @@ -105,7 +108,7 @@ private function loadTransactionFactory(array $config, ContainerBuilder $contain
return $this->setDefinition(
$container,
'mediapart_lapresselibre.transaction_factory',
TransactionFactory::class,
Factory\TransactionFactory::class,
[
$config['public_key'],
new Reference('mediapart_lapresselibre.identity'),
Expand All @@ -125,12 +128,32 @@ private function loadEndpointFactory(ContainerBuilder $container)
return $this->setDefinition(
$container,
'mediapart_lapresselibre.endpoint_factory',
EndpointFactory::class,
Factory\EndpointFactory::class,
[],
self::PRIVATE_SERVICE
);
}

/**
* @param array $config
* @param ContainerBuilder $container
*
* @return self
*/
private function loadRedirectionFactory(array $config, ContainerBuilder $container)
{
return $this->setDefinition(
$container,
'mediapart_lapresselibre.redirection_factory',
Factory\RedirectionFactory::class,
[
new Reference('mediapart_lapresselibre.link'),
new Reference($config['account']['provider'])
],
self::PRIVATE_SERVICE
);
}

/**
* @param ContainerBuilder $container
*
Expand Down Expand Up @@ -172,18 +195,36 @@ private function loadHandler(ContainerBuilder $container)
*
* @return self
*/
private function loadController(ContainerBuilder $container)
private function loadWebServicesController(ContainerBuilder $container)
{
return $this->setDefinition(
$container,
'mediapart_lapresselibre.controller',
Controller::class,
'mediapart_lapresselibre.webservices_controller',
Controller\WebServicesController::class,
[
new Reference('mediapart_lapresselibre.handler'),
]
);
}

/**
* @param array $config
* @param ContainerBuilder $container
*
* @return self
*/
private function loadLinkAccountController(array $config, ContainerBuilder $container)
{
return $this->setDefinition(
$container,
'mediapart_lapresselibre.linkaccount_controller',
Controller\LinkAccountController::class,
[
new Reference('mediapart_lapresselibre.redirection_factory'),
]
);
}

/**
* @param array $config
* @param ContainerBuilder $container
Expand All @@ -203,6 +244,20 @@ private function loadRegistration(array $config, ContainerBuilder $container)
);
}

private function loadLink(array $config, ContainerBuilder $container)
{
return $this->setDefinition(
$container,
'mediapart_lapresselibre.link',
Link::class,
[
new Reference('mediapart_lapresselibre.encryption'),
new Reference($config['account']['repository']),
$config['public_key'],
]
);
}

/**
* @param ContainerBuilder $container
* @param string $id
Expand Down
Loading

0 comments on commit a689339

Please sign in to comment.