Skip to content

Commit

Permalink
Merge branch 'develop' into feature/larger-decimals
Browse files Browse the repository at this point in the history
* develop:
  Remove paypal plugin dependency (schmittjoh#220)
  Replace abandoned project by most advanced fork
  Test for symfony 3.3
  No longer build for HHVM
  Avoid reliance on kernel version
  Prepare release 1.3.0
  Deprecate usage of mcrypt (schmittjoh#200)
  Add command for generating encryption keys (schmittjoh#208)
  Make defuse the default encryption provider (schmittjoh#207)
  Add encryption provider for defuse/php-encryption (schmittjoh#206)
  Allow custom encryption providers (schmittjoh#205)
  Make encryption optional (schmittjoh#204)
  Deprecate payment.encryption_service in favor of payment.crypto.mcrypt (schmittjoh#203)
  Refactor ExtendedDataType (schmittjoh#202)
  Fix tests (schmittjoh#199)
  • Loading branch information
derekclaphamfm committed Jul 27, 2018
2 parents 9ff8d37 + 6982285 commit f845118
Show file tree
Hide file tree
Showing 57 changed files with 924 additions and 234 deletions.
24 changes: 14 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@ branches:
only:
- master

cache:
directories:
- vendor
- venv

before_install: ./.travis/before_install.php
install: ./.travis/install.php
script: ./.travis/script.php

matrix:
include:
# old PHP versions with latest Symfony version
- php: 5.3
- php: 5.4
env: SYMFONY_VERSION=2.8.* # Symfony 3 doesn't support PHP 5.3
- php: 5.6
env: SYMFONY_VERSION=3.1.*
# HHVM
- php: hhvm
env: SYMFONY_VERSION=3.1.*
# current PHP with all relevant Symfony versions
env: SYMFONY_VERSION=3.2.*
- php: 7.0
env: SYMFONY_VERSION=3.2.*
# current PHP with all relevant Symfony versions
- php: 7.1
env: SYMFONY_VERSION=2.3.*
- php: 7.0
- php: 7.1
env: SYMFONY_VERSION=2.8.*
- php: 7.0
env: SYMFONY_VERSION=3.1.*
- php: 7.0
- php: 7.1
env: SYMFONY_VERSION=3.3.*
- php: 7.1
env: SYMFONY_VERSION=dev-master
allow_failures:
- env: SYMFONY_VERSION=dev-master
6 changes: 2 additions & 4 deletions .travis/before_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@

include_once 'common.php';

if (!isHhvm()) {
// Disable XDebug
run('phpenv config-rm xdebug.ini');
}
// Disable XDebug
run('phpenv config-rm xdebug.ini');
9 changes: 2 additions & 7 deletions .travis/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ function shouldBuildDocs()
return isLatestPhp() && isLatestSymfony();
}

function isHhvm()
{
return getPhpVersion() === 'hhvm';
}

function isLatestPhp()
{
return getPhpVersion() === '7.0';
return getPhpVersion() === '7.1';
}

function isLatestSymfony()
{
return getSymfonyVersion() === '3.1.*';
return getSymfonyVersion() === '3.3.*';
}

function getSymfonyVersion()
Expand Down
7 changes: 0 additions & 7 deletions .travis/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@

include_once 'common.php';

run('composer self-update');

if (isLatestPhp() && isLatestSymfony()) {
// Make sure composer.json references all necessary components by having one
// job run a `composer update`. Since `composer update` will install the
// latest Symfony, this should be done for the job corresponding to the
// latest symfony version.
run('composer update --prefer-dist');
} else {
if (getPhpVersion() === '5.3') {
// Prevent Travis throwing an out of memory error
run('echo "memory_limit=-1" >> ~/.phpenv/versions/5.3/etc/conf.d/travis.ini');
}

run('composer require --prefer-dist symfony/symfony:'.getSymfonyVersion());
}

Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.3.0] - 2017-01-22
### Changed
- `JMS\Payment\CoreBundle\Model\ExtendedDataInterface` has changed. If any of your classes implement this interface, you need to update them accordingly:
- Added missing `mayBePersisted` method
- Added missing `$persist` parameter to `set` method
- `JMS\Payment\CoreBundle\EntityExtendedDataType::convertToDatabaseValue` now throws an exception when attempting to convert an object which does not implement `JMS\Payment\CoreBundle\Model\ExtendedDataInterface`.
- Encryption is now optional and disabled by default, unless the `secret` or `encryption.secret` configuration options are set.
- `defuse_php_encryption` is now the default encryption provider, unless when using the `secret` configuration option, in which case the default is set to `mcrypt`.
- The EntityManager is no longer closed when an Exception is thrown (#145)

### Deprecated
- The service `payment.encryption_service` has been deprecated and is now an alias to `payment.encryption.mcrypt`. Parameters specified for `payment.encryption_service` are automatically set for `payment.encryption.mcrypt` so no changes are required in service configuration until `payment.encryption_service` is removed in 2.0.
- The `secret` configuration option has been deprecated in favor of `encryption.secret` and will be removed in 2.0. Please note that if you start using `encryption.secret` you also need to set `encryption.provider` to `mcrypt` since mcrypt is not the default when using the `encryption.*` options.
- `JMS\Payment\CoreBundle\Cryptography\MCryptEncryptionService` has been deprecated and will be removed in 2.0 (`mcrypt` has been deprecated in PHP 7.1 and is removed in PHP 7.2). Refer to http://jmspaymentcorebundle.readthedocs.io/en/stable/guides/mcrypt.html for instructions on how to migrate away from `mcrypt`.

### Added
- Added ``method_options`` and ``choice_options`` to form. See the [documentation](http://jmspaymentcorebundle.readthedocs.io/en/stable/payment_form.html#choice-options) for more information.
- Added a guides section to the documentation
- Added support for custom encryption providers.
- Added support for data encryption with [defuse/php-encryption](https://github.com/defuse/php-encryption).
- Added console command to generate an encryption key for use with `defuse_php_encryption`.
- Added ability to configure which encryption provider should be used. Current available options are `mcrypt` (not recommended since it will be removed in PHP 7.2) and `defuse_php_encryption`.

### Removed
- Removed support for PHP 5.3. If you're still using PHP 5.3, please consider upgrading since it reached End Of Life in August 2014. Otherwise, use `1.2.*`.

## [1.2.0] - 2016-10-03
### Added
- Added support for Symfony 3.0. Note that Symfony 3.0 introduces BC breaks. This means that you'll probably need to do more than simply updating to version `1.2.0` of this bundle for your code to keep working under Symfony 3.0. Please see Symfony's [Upgrade Guide](https://github.com/symfony/symfony/blob/master/UPGRADE-3.0.md) for information on what you need to change.
Expand Down
24 changes: 24 additions & 0 deletions Command/GenerateKeyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace JMS\Payment\CoreBundle\Command;

use Defuse\Crypto\Key;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateKeyCommand extends Command
{
protected function configure()
{
$this
->setName('jms_payment_core:generate-key')
->setDescription('Generate an encryption key')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(Key::createNewRandomKey()->saveToAsciiSafeString());
}
}
26 changes: 26 additions & 0 deletions Cryptography/DefusePhpEncryptionService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace JMS\Payment\CoreBundle\Cryptography;

use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;

class DefusePhpEncryptionService implements EncryptionServiceInterface
{
private $key;

public function __construct($secret)
{
$this->key = Key::loadFromAsciiSafeString($secret);
}

public function decrypt($encryptedValue)
{
return Crypto::decrypt($encryptedValue, $this->key);
}

public function encrypt($rawValue)
{
return Crypto::encrypt($rawValue, $this->key);
}
}
8 changes: 5 additions & 3 deletions Cryptography/MCryptEncryptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public function __construct($secret, $cipher = 'rijndael-256', $mode = 'ctr')
throw new \RuntimeException('The mcrypt extension must be loaded.');
}

if (!in_array($cipher, mcrypt_list_algorithms(), true)) {
@trigger_error('mcrypt has been deprecated in PHP 7.1 and is removed in PHP 7.2. Refer to http://jmspaymentcorebundle.readthedocs.io/en/stable/guides/mcrypt.html for instructions on how to migrate away from mcrypt', E_USER_DEPRECATED);

if (!in_array($cipher, @mcrypt_list_algorithms(), true)) {
throw new \InvalidArgumentException(sprintf('The cipher "%s" is not supported.', $cipher));
}

if (!in_array($mode, mcrypt_list_modes(), true)) {
if (!in_array($mode, @mcrypt_list_modes(), true)) {
throw new \InvalidArgumentException(sprintf('The mode "%s" is not supported.', $mode));
}

Expand All @@ -62,7 +64,7 @@ public function __construct($secret, $cipher = 'rijndael-256', $mode = 'ctr')
}

$key = hash('sha256', $secret, true);
if (strlen($key) > $size = mcrypt_get_key_size($this->cipher, $this->mode)) {
if (strlen($key) > $size = @mcrypt_get_key_size($this->cipher, $this->mode)) {
$key = substr($key, 0, $size);
}
$this->key = $key;
Expand Down
14 changes: 7 additions & 7 deletions DependencyInjection/Compiler/AddPaymentMethodFormTypesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ public function process(ContainerBuilder $container)
}

$paymentMethodFormTypes = array();
foreach ($container->findTaggedServiceIds('payment.method_form_type') as $id => $attributes) {
foreach ($container->findTaggedServiceIds('payment.method_form_type') as $id => $attrs) {
$definition = $container->getDefinition($id);

// check that this definition is also registered as a form type
$attributes = $definition->getTag('form.type');
if (!$attributes) {
$attrs = $definition->getTag('form.type');
if (!$attrs) {
throw new \RuntimeException(sprintf('The service "%s" is marked as payment method form type (tagged with "payment.method_form_type"), but is not registered as a form type with the Form Component. Please also add a "form.type" tag.', $id));
}

if (!isset($attributes[0]['alias'])) {
if (!isset($attrs[0]['alias'])) {
throw new \RuntimeException(sprintf('Please define an alias attribute for tag "form.type" of service "%s".', $id));
}

$paymentMethodFormTypes[$attributes[0]['alias']] = Legacy::supportsFormTypeName()
? $attributes[0]['alias']
: $definition->getClass()
$paymentMethodFormTypes[$attrs[0]['alias']] = Legacy::supportsFormTypeClass()
? $definition->getClass()
: $attrs[0]['alias']
;
}

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/AddPaymentPluginsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function process(ContainerBuilder $container)
}

$def = $container->findDefinition('payment.plugin_controller');
foreach ($container->findTaggedServiceIds('payment.plugin') as $id => $attr) {
foreach ($container->findTaggedServiceIds('payment.plugin') as $id => $attrs) {
$def->addMethodCall('addPlugin', array(new Reference($id)));
}
}
Expand Down
34 changes: 34 additions & 0 deletions DependencyInjection/Compiler/ConfigureEncryptionPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace JMS\Payment\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class ConfigureEncryptionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->getParameter('payment.encryption.enabled')) {
return;
}

$providers = array();

foreach ($container->findTaggedServiceIds('payment.encryption') as $id => $attrs) {
if (!isset($attrs[0]['alias'])) {
throw new \RuntimeException("Please define an alias attribute for tag 'payment.encryption' of service '$id'");
}

$providers[$attrs[0]['alias']] = $id;
}

$configuredProvider = $container->getParameter('payment.encryption');

if (!array_key_exists($configuredProvider, $providers)) {
throw new \RuntimeException("The configured encryption provider ($configuredProvider) must match the alias of one of the services tagged with 'payment.encryption'");
}

$container->setAlias('payment.encryption', $providers[$configuredProvider]);
}
}
56 changes: 56 additions & 0 deletions DependencyInjection/Compiler/LegacyEncryptionPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace JMS\Payment\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* The service `payment.encryption_service` has been deprecated in favor of
* `payment.encryption.mcrypt`. This compiler pass makes sure parameters specified
* for `payment.encryption_service` are instead set for `payment.encryption.mcrypt`.
*
* @deprecated 1.3 Will be removed in 2.0
*/
class LegacyEncryptionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->has('payment.encryption_service')) {
return;
}

if (!$container->has('payment.encryption.mcrypt')) {
return;
}

$parameters = array(
'class' => 'JMS\Payment\CoreBundle\Cryptography\MCryptEncryptionService',
'secret' => '',
'cipher' => 'rijndael-256',
'mode' => 'ctr',
);

foreach ($parameters as $parameter => $defaultValue) {
if (!$container->hasParameter('payment.encryption_service.'.$parameter)) {
continue;
}

if (!$container->hasParameter('payment.encryption.mcrypt.'.$parameter)) {
continue;
}

$legacyValue = $container->getParameter('payment.encryption_service.'.$parameter);
$modernValue = $container->getParameter('payment.encryption.mcrypt.'.$parameter);

// Parameters set for payment.encryption.mcrypt take precedence over
// ones set for payment.encryption_service
if ($modernValue !== $defaultValue) {
$container->setParameter('payment.encryption.mcrypt.'.$parameter, $modernValue);
} elseif ($legacyValue !== $defaultValue) {
$container->setParameter('payment.encryption.mcrypt.'.$parameter, $legacyValue);
@trigger_error('payment.encryption_service.'.$parameter.' has been deprecated in favor of payment.encryption.mcrypt.'.$parameter.' and will be removed in 2.0', E_USER_DEPRECATED);
}
}
}
}
Loading

0 comments on commit f845118

Please sign in to comment.