Skip to content

Commit

Permalink
Merge pull request #3 from challgren/cake-4.x
Browse files Browse the repository at this point in the history
Cake 4.x
bcrowe authored Dec 30, 2019
2 parents 3ee4c91 + 9e05fdf commit 905b110
Showing 7 changed files with 27 additions and 25 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -6,9 +6,8 @@ env:
- RUN_TESTS=1

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@

All notable changes to `cakephp-encrypted-type` will be documented in this file.

## 2.0.0 - TBA
- Supports CakePHP 4.x

## 1.0.0 - 2017-09-09

- First stable release.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]

This plugin provides a CakePHP 3 encrypted database type for application-level
This plugin provides a CakePHP 4 encrypted database type for application-level
encryption. Before using this plugin you may want to weigh your options
between [full-disk, database-level, and application-level encryption](https://www.percona.com/blog/2016/04/08/mysql-data-at-rest-encryption/).
This plugin was born out of Amazon Aurora not supporting encryption with cross
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -16,10 +16,11 @@
}
],
"require": {
"cakephp/cakephp": "^3.4.0"
"php": ">=7.2",
"cakephp/cakephp": "4.x-dev as 4.0.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"phpunit/phpunit": "^8.0",
"scrutinizer/ocular": "~1.1"
},
"autoload": {
@@ -40,8 +41,5 @@
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"conflict": {
"phpunit/phpunit": "<5.7"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
27 changes: 14 additions & 13 deletions src/Database/Type/EncryptedType.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
declare(strict_types=1);

namespace BryanCrowe\EncryptedType\Database\Type;

use Cake\Core\Configure;
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use Cake\Database\DriverInterface;
use Cake\Database\Type\BaseType;
use Cake\Database\Type\OptionalConvertInterface;
use Cake\Utility\Security;
use InvalidArgumentException;
@@ -13,7 +14,7 @@
/**
* Encrypted BLOB converter. Used to encrypt and decrypt stored data.
*/
class EncryptedType extends Type implements OptionalConvertInterface, TypeInterface
class EncryptedType extends BaseType implements OptionalConvertInterface
{

/**
@@ -38,10 +39,10 @@ public function __construct($name = null)
* Convert encrypted values to PHP strings or null.
*
* @param mixed $value The value to convert.
* @param \Cake\Database\Driver $driver The driver instance to convert with.
* @return mixed
* @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
* @return string|null
*/
public function toPHP($value, Driver $driver)
public function toPHP($value, DriverInterface $driver)
{
if ($value === null) {
return null;
@@ -73,10 +74,10 @@ public function marshal($value)
* Convert PHP values into the database format.
*
* @param mixed $value The value to convert.
* @param \Cake\Database\Driver $driver The driver instance to convert with.
* @return string
* @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
* @return string|null
*/
public function toDatabase($value, Driver $driver)
public function toDatabase($value, DriverInterface $driver): ?string
{
if ($value === null) {
return null;
@@ -101,10 +102,10 @@ public function toDatabase($value, Driver $driver)
* Get the correct PDO binding type for string data.
*
* @param mixed $value The value being bound.
* @param \Cake\Database\Driver $driver The driver.
* @param \Cake\Database\DriverInterface $driver The driver.
* @return int
*/
public function toStatement($value, Driver $driver)
public function toStatement($value, DriverInterface $driver)
{
if ($value === null) {
return PDO::PARAM_NULL;
@@ -118,7 +119,7 @@ public function toStatement($value, Driver $driver)
*
* @return boolean True as database results are returned as encrypted strings.
*/
public function requiresToPhpCast()
public function requiresToPhpCast(): bool
{
return true;
}
5 changes: 3 additions & 2 deletions tests/TestCase/Database/Type/EncryptedTypeTest.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ class EncryptedTypeTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->type = Type::build('encrypted');
@@ -56,11 +56,11 @@ public function testToDatabase()
/**
* Tests that passing an invalid value will throw an exception
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testToDatabaseInvalidArray()
{
$this->expectException('InvalidArgumentException');
$this->type->toDatabase([1, 2, 3], $this->driver);
}

@@ -85,6 +85,7 @@ public function testMarshal()
public function testToStatement()
{
$this->assertEquals(PDO::PARAM_STR, $this->type->toStatement('', $this->driver));
$this->assertEquals(PDO::PARAM_NULL, $this->type->toStatement(null, $this->driver));
}

/**

0 comments on commit 905b110

Please sign in to comment.