Open Journal Systems  3.3.0
CommandContentMd5Plugin.php
1 <?php
2 
3 namespace Guzzle\Plugin\Md5;
4 
8 
14 {
16  protected $contentMd5Param;
17 
19  protected $validateMd5Param;
20 
25  public function __construct($contentMd5Param = 'ContentMD5', $validateMd5Param = 'ValidateMD5')
26  {
27  $this->contentMd5Param = $contentMd5Param;
28  $this->validateMd5Param = $validateMd5Param;
29  }
30 
31  public static function getSubscribedEvents()
32  {
33  return array('command.before_send' => array('onCommandBeforeSend', -255));
34  }
35 
36  public function onCommandBeforeSend(Event $event)
37  {
38  $command = $event['command'];
39  $request = $command->getRequest();
40 
41  // Only add an MD5 is there is a MD5 option on the operation and it has a payload
42  if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()
43  && $command->getOperation()->hasParam($this->contentMd5Param)) {
44  // Check if an MD5 checksum value should be passed along to the request
45  if ($command[$this->contentMd5Param] === true) {
46  if (false !== ($md5 = $request->getBody()->getContentMd5(true, true))) {
47  $request->setHeader('Content-MD5', $md5);
48  }
49  }
50  }
51 
52  // Check if MD5 validation should be used with the response
53  if ($command[$this->validateMd5Param] === true) {
54  $request->addSubscriber(new Md5ValidatorPlugin(true, false));
55  }
56  }
57 }
Guzzle\Plugin\Md5
Definition: CommandContentMd5Plugin.php:3
Guzzle\Plugin\Md5\CommandContentMd5Plugin
Definition: CommandContentMd5Plugin.php:13
Guzzle\Plugin\Md5\CommandContentMd5Plugin\onCommandBeforeSend
onCommandBeforeSend(Event $event)
Definition: CommandContentMd5Plugin.php:42
Symfony\Component\EventDispatcher\EventSubscriberInterface
Definition: lib/vendor/symfony/event-dispatcher/EventSubscriberInterface.php:25
Guzzle\Http\Message\EntityEnclosingRequestInterface
Definition: EntityEnclosingRequestInterface.php:12
Guzzle\Plugin\Md5\CommandContentMd5Plugin\__construct
__construct($contentMd5Param='ContentMD5', $validateMd5Param='ValidateMD5')
Definition: CommandContentMd5Plugin.php:31
Guzzle\Plugin\Md5\Md5ValidatorPlugin
Definition: Md5ValidatorPlugin.php:14
Guzzle\Plugin\Md5\CommandContentMd5Plugin\$validateMd5Param
$validateMd5Param
Definition: CommandContentMd5Plugin.php:25
Guzzle\Common\Event
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Event.php:10
Guzzle\Plugin\Md5\CommandContentMd5Plugin\getSubscribedEvents
static getSubscribedEvents()
Definition: CommandContentMd5Plugin.php:37
Guzzle\Plugin\Md5\CommandContentMd5Plugin\$contentMd5Param
$contentMd5Param
Definition: CommandContentMd5Plugin.php:19
Guzzle\Http\Message\EntityEnclosingRequestInterface\getBody
getBody()