-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from trsteel88/master
Add a Signer Utility to sign filters, run php-cs-fixer on bundle
- Loading branch information
Showing
16 changed files
with
318 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Imagine\Cache; | ||
|
||
class Signer implements SignerInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $secret; | ||
|
||
/** | ||
* @param string $secret | ||
*/ | ||
public function __construct($secret) | ||
{ | ||
$this->secret = $secret; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function sign($path, array $runtimeConfig = null) | ||
{ | ||
if ($runtimeConfig) { | ||
array_walk_recursive($runtimeConfig, function (&$value) { | ||
$value = (string)$value; | ||
}); | ||
} | ||
|
||
return substr(preg_replace('/[^a-zA-Z0-9-_]/', '', base64_encode(hash_hmac('sha256', ltrim($path, '/') . (null === $runtimeConfig ?: serialize($runtimeConfig)), $this->secret, true))), 0, 8); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function check($hash, $path, array $runtimeConfig = null) | ||
{ | ||
return $hash === $this->sign($path, $runtimeConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Imagine\Cache; | ||
|
||
interface SignerInterface | ||
{ | ||
/** | ||
* Return the hash for path and runtime config | ||
* | ||
* @param string $path | ||
* @param array $runtimeConfig | ||
* @return string | ||
*/ | ||
public function sign($path, array $runtimeConfig = null); | ||
|
||
/** | ||
* Check hash is correct | ||
* | ||
* @param string $hash | ||
* @param string $path | ||
* @param array $runtimeConfig | ||
* @return bool | ||
*/ | ||
public function check($hash, $path, array $runtimeConfig = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.