Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'cs/part2-variable-renaming' of https://github.com/arse/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 126 deletions.
26 changes: 13 additions & 13 deletions src/Compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class Compress extends AbstractFilter
/**
* Compression adapter
*/
protected $_adapter = 'Gz';
protected $adapter = 'Gz';

/**
* Compression adapter constructor options
*/
protected $_adapterOptions = array();
protected $adapterOptions = array();

/**
* Class constructor
Expand Down Expand Up @@ -86,28 +86,28 @@ public function setOptions($options)
*/
public function getAdapter()
{
if ($this->_adapter instanceof Compress\CompressionAlgorithmInterface) {
return $this->_adapter;
if ($this->adapter instanceof Compress\CompressionAlgorithmInterface) {
return $this->adapter;
}

$adapter = $this->_adapter;
$adapter = $this->adapter;
$options = $this->getAdapterOptions();
if (!class_exists($adapter)) {
$adapter = 'Zend\\Filter\\Compress\\' . ucfirst($adapter);
if (!class_exists($adapter)) {
throw new Exception\RuntimeException(sprintf(
'%s unable to load adapter; class "%s" not found',
__METHOD__,
$this->_adapter
$this->adapter
));
}
}

$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Compress\CompressionAlgorithmInterface) {
$this->adapter = new $adapter($options);
if (!$this->adapter instanceof Compress\CompressionAlgorithmInterface) {
throw new Exception\InvalidArgumentException("Compression adapter '" . $adapter . "' does not implement Zend\\Filter\\Compress\\CompressionAlgorithmInterface");
}
return $this->_adapter;
return $this->adapter;
}

/**
Expand All @@ -130,13 +130,13 @@ public function getAdapterName()
public function setAdapter($adapter)
{
if ($adapter instanceof Compress\CompressionAlgorithmInterface) {
$this->_adapter = $adapter;
$this->adapter = $adapter;
return $this;
}
if (!is_string($adapter)) {
throw new Exception\InvalidArgumentException('Invalid adapter provided; must be string or instance of Zend\\Filter\\Compress\\CompressionAlgorithmInterface');
}
$this->_adapter = $adapter;
$this->adapter = $adapter;

return $this;
}
Expand All @@ -148,7 +148,7 @@ public function setAdapter($adapter)
*/
public function getAdapterOptions()
{
return $this->_adapterOptions;
return $this->adapterOptions;
}

/**
Expand All @@ -159,7 +159,7 @@ public function getAdapterOptions()
*/
public function setAdapterOptions(array $options)
{
$this->_adapterOptions = $options;
$this->adapterOptions = $options;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class Decrypt extends Encrypt
*/
public function filter($value)
{
return $this->_adapter->decrypt($value);
return $this->adapter->decrypt($value);
}
}
14 changes: 7 additions & 7 deletions src/Encrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Encrypt extends AbstractFilter
/**
* Encryption adapter
*/
protected $_adapter;
protected $adapter;

/**
* Class constructor
Expand All @@ -47,7 +47,7 @@ public function __construct($options = null)
*/
public function getAdapter()
{
return $this->_adapter->toString();
return $this->adapter->toString();
}

/**
Expand Down Expand Up @@ -84,8 +84,8 @@ public function setAdapter($options = null)
));
}

$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Encrypt\EncryptionAlgorithmInterface) {
$this->adapter = new $adapter($options);
if (!$this->adapter instanceof Encrypt\EncryptionAlgorithmInterface) {
throw new Exception\InvalidArgumentException(
"Encoding adapter '" . $adapter
. "' does not implement Zend\\Filter\\Encrypt\\EncryptionAlgorithmInterface");
Expand All @@ -104,11 +104,11 @@ public function setAdapter($options = null)
public function __call($method, $options)
{
$part = substr($method, 0, 3);
if ((($part != 'get') and ($part != 'set')) or !method_exists($this->_adapter, $method)) {
if ((($part != 'get') and ($part != 'set')) or !method_exists($this->adapter, $method)) {
throw new Exception\BadMethodCallException("Unknown method '{$method}'");
}

return call_user_func_array(array($this->_adapter, $method), $options);
return call_user_func_array(array($this->adapter, $method), $options);
}

/**
Expand All @@ -121,6 +121,6 @@ public function __call($method, $options)
*/
public function filter($value)
{
return $this->_adapter->encrypt($value);
return $this->adapter->encrypt($value);
}
}
68 changes: 34 additions & 34 deletions src/Encrypt/Openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Openssl implements EncryptionAlgorithmInterface
* 'envelope' => resulting envelope keys
* )
*/
protected $_keys = array(
protected $keys = array(
'public' => array(),
'private' => array(),
'envelope' => array(),
Expand All @@ -43,21 +43,21 @@ class Openssl implements EncryptionAlgorithmInterface
*
* @var string
*/
protected $_passphrase;
protected $passphrase;

/**
* Internal compression
*
* @var array
*/
protected $_compression;
protected $compression;

/**
* Internal create package
*
* @var boolean
*/
protected $_package = false;
protected $package = false;

/**
* Class constructor
Expand Down Expand Up @@ -124,7 +124,7 @@ protected function _setKeys($keys)
fclose($file);
} else {
$cert = $key;
$key = count($this->_keys[$type]);
$key = count($this->keys[$type]);
}

switch ($type) {
Expand All @@ -135,19 +135,19 @@ protected function _setKeys($keys)
}

openssl_free_key($test);
$this->_keys['public'][$key] = $cert;
$this->keys['public'][$key] = $cert;
break;
case 'private':
$test = openssl_pkey_get_private($cert, $this->_passphrase);
$test = openssl_pkey_get_private($cert, $this->passphrase);
if ($test === false) {
throw new Exception\InvalidArgumentException("Private key '{$cert}' not valid");
}

openssl_free_key($test);
$this->_keys['private'][$key] = $cert;
$this->keys['private'][$key] = $cert;
break;
case 'envelope':
$this->_keys['envelope'][$key] = $cert;
$this->keys['envelope'][$key] = $cert;
break;
default:
break;
Expand All @@ -164,7 +164,7 @@ protected function _setKeys($keys)
*/
public function getPublicKey()
{
$key = $this->_keys['public'];
$key = $this->keys['public'];
return $key;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ public function setPublicKey($key)
*/
public function getPrivateKey()
{
$key = $this->_keys['private'];
$key = $this->keys['private'];
return $key;
}

Expand Down Expand Up @@ -235,7 +235,7 @@ public function setPrivateKey($key, $passphrase = null)
*/
public function getEnvelopeKey()
{
$key = $this->_keys['envelope'];
$key = $this->keys['envelope'];
return $key;
}

Expand Down Expand Up @@ -268,7 +268,7 @@ public function setEnvelopeKey($key)
*/
public function getPassphrase()
{
return $this->_passphrase;
return $this->passphrase;
}

/**
Expand All @@ -279,7 +279,7 @@ public function getPassphrase()
*/
public function setPassphrase($passphrase)
{
$this->_passphrase = $passphrase;
$this->passphrase = $passphrase;
return $this;
}

Expand All @@ -290,7 +290,7 @@ public function setPassphrase($passphrase)
*/
public function getCompression()
{
return $this->_compression;
return $this->compression;
}

/**
Expand All @@ -301,11 +301,11 @@ public function getCompression()
*/
public function setCompression($compression)
{
if (is_string($this->_compression)) {
if (is_string($this->compression)) {
$compression = array('adapter' => $compression);
}

$this->_compression = $compression;
$this->compression = $compression;
return $this;
}

Expand All @@ -316,7 +316,7 @@ public function setCompression($compression)
*/
public function getPackage()
{
return $this->_package;
return $this->package;
}

/**
Expand All @@ -327,7 +327,7 @@ public function getPackage()
*/
public function setPackage($package)
{
$this->_package = (boolean) $package;
$this->package = (boolean) $package;
return $this;
}

Expand All @@ -344,16 +344,16 @@ public function encrypt($value)
$encrypted = array();
$encryptedkeys = array();

if (count($this->_keys['public']) == 0) {
if (count($this->keys['public']) == 0) {
throw new Exception\RuntimeException('Openssl can not encrypt without public keys');
}

$keys = array();
$fingerprints = array();
$count = -1;
foreach($this->_keys['public'] as $key => $cert) {
foreach($this->keys['public'] as $key => $cert) {
$keys[$key] = openssl_pkey_get_public($cert);
if ($this->_package) {
if ($this->package) {
$details = openssl_pkey_get_details($keys[$key]);
if ($details === false) {
$details = array('key' => 'ZendFramework');
Expand All @@ -365,8 +365,8 @@ public function encrypt($value)
}

// compress prior to encryption
if (!empty($this->_compression)) {
$compress = new Compress($this->_compression);
if (!empty($this->compression)) {
$compress = new Compress($this->compression);
$value = $compress($value);
}

Expand All @@ -379,12 +379,12 @@ public function encrypt($value)
throw new Exception\RuntimeException('Openssl was not able to encrypt your content with the given options');
}

$this->_keys['envelope'] = $encryptedkeys;
$this->keys['envelope'] = $encryptedkeys;

// Pack data and envelope keys into single string
if ($this->_package) {
$header = pack('n', count($this->_keys['envelope']));
foreach($this->_keys['envelope'] as $key => $envKey) {
if ($this->package) {
$header = pack('n', count($this->keys['envelope']));
foreach($this->keys['envelope'] as $key => $envKey) {
$header .= pack('H32n', $fingerprints[$key], strlen($envKey)) . $envKey;
}

Expand All @@ -408,19 +408,19 @@ public function decrypt($value)
$decrypted = "";
$envelope = current($this->getEnvelopeKey());

if (count($this->_keys['private']) !== 1) {
if (count($this->keys['private']) !== 1) {
throw new Exception\RuntimeException('Please give a private key for decryption with Openssl');
}

if (!$this->_package && empty($envelope)) {
if (!$this->package && empty($envelope)) {
throw new Exception\RuntimeException('Please give an envelope key for decryption with Openssl');
}

foreach($this->_keys['private'] as $key => $cert) {
foreach($this->keys['private'] as $key => $cert) {
$keys = openssl_pkey_get_private($cert, $this->getPassphrase());
}

if ($this->_package) {
if ($this->package) {
$details = openssl_pkey_get_details($keys);
if ($details !== false) {
$fingerprint = md5($details['key']);
Expand Down Expand Up @@ -453,8 +453,8 @@ public function decrypt($value)
}

// decompress after decryption
if (!empty($this->_compression)) {
$decompress = new Decompress($this->_compression);
if (!empty($this->compression)) {
$decompress = new Decompress($this->compression);
$decrypted = $decompress($decrypted);
}

Expand Down
Loading

0 comments on commit 88c4f3b

Please sign in to comment.