Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Identity
      • Log
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Resource
    • LoadBalancer
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
    • Queues
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • Formatter
  • RequestSubscriber
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
 1: <?php
 2: /**
 3:  * PHP OpenCloud library.
 4:  * 
 5:  * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
 6:  * @license   https://www.apache.org/licenses/LICENSE-2.0
 7:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
 8:  * @author    Glen Campbell <glen.campbell@rackspace.com>
 9:  */
10: 
11: namespace OpenCloud\Common\Http\Message;
12: 
13: use Guzzle\Common\Event;
14: use Guzzle\Http\Message\EntityEnclosingRequest;
15: use OpenCloud\Common\Constants\Header;
16: use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17: 
18: /**
19:  * Description of RequestSubscriber
20:  */
21: class RequestSubscriber implements EventSubscriberInterface
22: {
23:     
24:     public static function getInstance()
25:     {
26:         return new self();
27:     }
28:     
29:     public static function getSubscribedEvents()
30:     {
31:         return array(
32:             'request.before_send'    => 'ensureContentType',
33:             'curl.callback.progress' => 'doCurlProgress'
34:         );
35:     }
36: 
37:     public function ensureContentType(Event $event)
38:     {
39:         if ($event['request'] instanceof EntityEnclosingRequest
40:             && $event['request']->getBody()
41:             && $event['request']->getBody()->getContentLength()
42:             && !$event['request']->hasHeader(Header::CONTENT_TYPE)
43:         ) {
44:             $event['request']->setHeader(Header::CONTENT_TYPE, 'application/json');
45:         }
46:     }
47: 
48:     /**
49:      * @param $options
50:      * @return mixed
51:      * @codeCoverageIgnore
52:      */
53:     public function doCurlProgress($options)
54:     {
55:         $curlOptions = $options['request']->getCurlOptions();
56:         if ($curlOptions->hasKey('progressCallback')) {
57:             return call_user_func($curlOptions->get('progressCallback'));
58:         } else {
59:             echo sprintf(
60:                 "Download size: [%d]\nDownloaded: [%d]\nUpload size: [%d]\nUploaded: [%d]\n",
61:                 $options['download_size'],
62:                 $options['downloaded'],
63:                 $options['upload_size'],
64:                 $options['uploaded']
65:             );
66:         }
67:     }
68:     
69: }
PHP OpenCloud API API documentation generated by ApiGen 2.8.0