Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
PHP 7 support & cleanup (#4)
Browse files Browse the repository at this point in the history
* PHP 7.1 support & cleanup

* Idea files should be in global .gitignore

* Add return type to getSubscribedEvents method

* Remove redundant paragraph

* Link to license file

* Remove redundant composer install flag

* Use proper PHP 7.1 requirement

"proper"

* Remove redundant Composer config option

* Fix indents in phpunit xml file

* Don't use bootstrap file to autoload annotations

* Fix docblocks

* Further improve annotation loading

* Remove unnecessary method

* Add upgrading guide

* Remove type-hints from EncryptorInterface

* Make PHP 7.0 the new minimum version

* Re-add docblocks
  • Loading branch information
driesvints authored and powturns committed Mar 12, 2017
1 parent 1407d7e commit eac8f36
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 261 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
composer.lock
vendor
.idea
13 changes: 3 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1

before_script:
- composer --prefer-source install
- composer install

script:
- ./vendor/bin/phpunit -c tests/phpunit.xml.dist

matrix:
allow_failures:
- php: hhvm
- ./vendor/bin/phpunit
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# DoctrineEncrypt
[![Build Status](https://travis-ci.org/51systems/doctrine-encrypt.svg?branch=master)](https://travis-ci.org/51systems/doctrine-encrypt)
# DoctrineEncrypt [![Build Status](https://travis-ci.org/51systems/doctrine-encrypt.svg?branch=master)](https://travis-ci.org/51systems/doctrine-encrypt)

Package encrypts and decrypts Doctrine fields through life cycle events. This version of the Doctrine Encrypt package
distinguishes itself with the following features:
Expand All @@ -8,40 +7,44 @@ distinguishes itself with the following features:
- Totally transparent field encryption: the value will only be encrypted in the database, never in the value
- Unit testing

## Integrations

The package supports the following integrations:

- Laravel

## Upgrading

If you're upgrading from a previous version you can find some help with that in [the upgrading guide](UPGRADING.md).

## Installation
Add `51systems/doctrine-encrypt` to your Composer manifest.

```js
{
"require": {
"51systems/doctrine-encrypt": "~5.0"
}
}
```bash
composer require 51systems/doctrine-encrypt
```

## Configuration
### Using ZF2
Check out the doctrine-encrypt-module at https://github.com/51systems/doctrine-encrypt-module

### Manually
Add the event subscriber to your entity manager's event manager. Assuming `$em` is your configured entity manager:
### Laravel

Add the subscriber in the `boot` method of a service provider.

```php
<?php

//You should pick your own hexadecimal secret
$secret = pack("H*", "dda8e5b978e05346f08b312a8c2eac03670bb5661097f8bc13212c31be66384c");
$encrypter = $this->app->make(\Illuminate\Contracts\Encryption\Encrypter::class);

$subscriber = new DoctrineEncryptSubscriber(
new \Doctrine\Common\Annotations\AnnotationReader,
new \DoctrineEncrypt\Encryptors\AES256Encryptor($secret)
new \DoctrineEncrypt\Encryptors\LaravelEncryptor($encrypter)
);

$eventManager = $em->getEventManager();
$eventManager->addEventSubscriber($subscriber);
```

## Usage

```php
<?php

Expand All @@ -62,20 +65,20 @@ class Entity
* @ORM\Column(type="integer")
* @var int
*/
protected $id;
private $id;

/**
* @ORM\Column(type="text")
* @Encrypted
* @var string
*/
protected $secret_data;
private $secretData;
}
```

## License

This bundle is under the MIT license. See the complete license in the bundle
This bundle is under [the MIT license](LICENSE.md).

## Versions

Expand Down
7 changes: 7 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Upgrading

## 5.x to 6.x

When upgrading to 6.x it is important to know that this library now requires PHP 7.0 as a minimum version.

Because of the new minimum PHP version the old `AES256Encryptor` class has been removed since Mcrypt is no longer supported. If you want to keep using this library you'll need to write your own implementation of the `EncryptorInterface` or use the new `LaravelEncryptor` if you use the Laravel framework.
29 changes: 20 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
"keywords": ["doctrine", "aes256", "encrypt", "decrypt"],
"license": "MIT",
"description": "Package encrypts and decrypts Doctrine fields through life cycle events.",

"require": {
"php": ">=5.3.2",
"doctrine/orm": "~2.0",
"ext-mcrypt": "*"
"php": "^7.0",
"doctrine/orm": "^2.5"
},

"require-dev": {
"phpunit/phpunit": "~3.7"
"illuminate/encryption": "^5.4",
"phpunit/phpunit": "^5.7"
},

"autoload": {
"psr-0": { "DoctrineEncrypt": "src" }
"psr-4": {
"DoctrineEncrypt\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"DoctrineEncrypt\\Tests\\": "tests"
}
},
"authors": [
{
Expand All @@ -26,6 +30,13 @@
{
"name": "Dustin Thomson",
"email": "[email protected]"
},
{
"name": "Dries Vints",
"email": "[email protected]"
}
]
],
"config": {
"sort-packages": true
}
}
15 changes: 10 additions & 5 deletions tests/phpunit.xml.dist → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="TestInit.php"
colors="true"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="DoctrineEncrypt Test Suite">
<directory>./DoctrineEncrypt</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
72 changes: 0 additions & 72 deletions src/DoctrineEncrypt/Encryptors/AES256Encryptor.php

This file was deleted.

34 changes: 34 additions & 0 deletions src/Encryptors/LaravelEncryptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace DoctrineEncrypt\Encryptors;

use Illuminate\Contracts\Encryption\Encrypter;

class LaravelEncryptor implements EncryptorInterface
{
/**
* @var Encrypter
*/
private $encrypter;

public function __construct(Encrypter $encrypter)
{
$this->encrypter = $encrypter;
}

/**
* {@inheritdoc}
*/
public function encrypt($data)
{
return $this->encrypter->encrypt($data);
}

/**
* {@inheritdoc}
*/
public function decrypt($data)
{
return $this->encrypter->decrypt($data);
}
}
Loading

0 comments on commit eac8f36

Please sign in to comment.